mirror of
https://gitlab.com/signalytic/client-external/streamline/streamline-emr.git
synced 2026-09-11 10:41:32 +00:00
The official image from streamline does not currently work for the arm64 platform. As a temporary measure, the source code and docker build scripts have been lifted from the official images and are used to build locally. Some additional modifications are made to reduce overall image size, these are documented in docker/README.md
127 lines
6.0 KiB
PHP
127 lines
6.0 KiB
PHP
<?php
|
|
|
|
namespace Streamline\Console\Commands;
|
|
|
|
use Carbon\Carbon;
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Streamline\Models\Equity;
|
|
use Streamline\Models\Journal;
|
|
use Streamline\Models\PatientCategoryInvoice;
|
|
|
|
class CorrectFinanceCommand extends Command {
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'correct:finance';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Command description';
|
|
|
|
/**
|
|
* Create a new command instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct() {
|
|
parent::__construct();
|
|
}
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return int
|
|
*/
|
|
public function handle() {
|
|
$start = "2020-01-01";
|
|
$end = "2023-09-16";
|
|
$patient_category_invoices = DB::table('patient_category_invoices')->whereBetween('created_at', [$start, $end])->get();
|
|
if (count($patient_category_invoices)) {
|
|
foreach ($patient_category_invoices as $single_record) {
|
|
|
|
$items_array = explode(",", $single_record->items_ids);
|
|
$tag_id = $single_record->tag_id;
|
|
$income_accounts_array = $cost_of_goods_account_array = $inventory_account_array = [];
|
|
|
|
for ($i = 0; $i < count($items_array); $i++) {
|
|
//Consultations / Services
|
|
if ($tag_id == 6 || $tag_id == 8 || $tag_id == 7 || $tag_id == 10) {
|
|
$income_account = get_name($items_array[$i], 'id', 'account_id', 'services');
|
|
$income_account = is_numeric($income_account) ? $income_account : 7;
|
|
$income_accounts_array[] = $income_account;
|
|
}
|
|
//Drugs / Treatments
|
|
elseif ($tag_id == 3 || $tag_id == 1) {
|
|
$income_account = get_name($items_array[$i], 'id', 'account_id', 'drugs');
|
|
$income_account = is_numeric($income_account) ? $income_account : 4;
|
|
$income_accounts_array[] = $income_account;
|
|
$inventory_account = get_name($items_array[$i], 'id', 'inventory_account', 'drugs');
|
|
$inventory_account_array[] = $inventory_account;
|
|
$cost_of_goods_account = get_name($items_array[$i], 'id', 'cost_of_goods_account', 'drugs');
|
|
$cost_of_goods_account_array[] = $cost_of_goods_account;
|
|
$cost_price_array[$i] = get_latest_inventory_cost_price($items_array[$i], 1, Carbon::today()->toDateString());
|
|
}
|
|
//Sundries
|
|
elseif ($tag_id == 5) {
|
|
$income_account = get_name($items_array[$i], 'id', 'account_id', 'sundries');
|
|
$income_account = is_numeric($income_account) ? $income_account : 12;
|
|
$income_accounts_array[] = $income_account;
|
|
$inventory_account = get_name($items_array[$i], 'id', 'inventory_account', 'sundries');
|
|
$inventory_account_array[] = $inventory_account;
|
|
$cost_of_goods_account = get_name($items_array[$i], 'id', 'cost_of_goods_account', 'sundries');
|
|
$cost_of_goods_account_array[] = $cost_of_goods_account;
|
|
$cost_price_array[$i] = get_latest_inventory_cost_price($items_array[$i], 2, Carbon::today()->toDateString());
|
|
}
|
|
//Investigations
|
|
elseif ($tag_id == 2) {
|
|
$income_account = get_name($items_array[$i], 'id', 'account_id', 'investigations');
|
|
$income_account = is_numeric($income_account) ? $income_account : 11;
|
|
$income_accounts_array[] = $income_account;
|
|
}
|
|
//Procedures
|
|
elseif ($tag_id == 4) {
|
|
$income_account = get_name($items_array[$i], 'id', 'account_id', 'procedures');
|
|
$income_account = is_numeric($income_account) ? $income_account : 8;
|
|
$income_accounts_array[] = $income_account;
|
|
}
|
|
}
|
|
|
|
$income_accounts_string = is_null($income_accounts_array) ? "" : implode(',', $income_accounts_array);
|
|
$cost_of_goods_accounts_string = is_null($cost_of_goods_account_array) ? null : implode(',', $cost_of_goods_account_array);
|
|
$inventory_accounts_string = is_null($inventory_account_array) ? null : implode(',', $inventory_account_array);
|
|
|
|
$existing_patient_category_invoice = PatientCategoryInvoice::withTrashed()->find($single_record->id);
|
|
$existing_patient_category_invoice->income_account = $income_accounts_string;
|
|
if ($tag_id == 3 || $tag_id == 1 || $tag_id == 5) {
|
|
$existing_patient_category_invoice->cost_of_goods_account = $cost_of_goods_accounts_string;
|
|
$existing_patient_category_invoice->inventory_account = $inventory_accounts_string;
|
|
}
|
|
$existing_patient_category_invoice->update();
|
|
}
|
|
}
|
|
|
|
$equities = Equity::all();
|
|
foreach ($equities as $equity) {
|
|
$equity->transaction_date = $equity->created_at;
|
|
$equity->update();
|
|
|
|
//pick the equity and update it with the journal date if it was journaled
|
|
if (str_contains($equity, 'Journal (')) {
|
|
$journal_number = getStringBetweenCharacters($equity->name,"(",")");
|
|
$journal = Journal::find($journal_number);
|
|
if($journal){
|
|
//update the equity record's transaction date with the date it was journaled
|
|
$equity->transaction_date = $journal->journal_date;
|
|
$equity->update();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|