Build modified streamline images

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
This commit is contained in:
2024-03-10 16:17:50 -07:00
parent 2ffc3c408a
commit a424394109
13506 changed files with 1860172 additions and 6 deletions
@@ -0,0 +1,126 @@
<?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();
}
}
}
}
}
@@ -0,0 +1,144 @@
<?php
namespace Streamline\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class ImportCsvItemsCommand extends Command {
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'import:csv {id}';
/**
* 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 mixed
*/
public function handle() {
$id = $this->argument('id');
$record = DB::table('csv_imports_processes')->where('id', $id)->first();
$data = file(base_path('public/' . $record->csv_path));
$account_id = $record->account_id;
$inventory_account = $record->inventory_account;
$cost_of_goods_account = $record->cost_of_goods_account;
$data_count = count($data);
$counter = 0;
foreach($data as $item) {
$split_item = explode(',', $item);
if ($record->tag_id == 3) {
try {
DB::table('drugs')->insert([
"code" => str_replace('"', '', $split_item[0]),
"name" => str_replace('"', '', $split_item[1]),
"cost_price" => str_replace('"', '', $split_item[2]),
"non_insured_price" => str_replace('"', '', $split_item[3]),
"account_id" => $account_id,
"inventory_account" => $inventory_account,
"cost_of_goods_account" => $cost_of_goods_account,
"opening_cost_price" => str_replace('"', '', $split_item[2]),
"category_id" => 1,
"pack" => 1,
"strength" => $split_item[6],
"form_id" => $split_item[5],
"unit_id" => $split_item[4],
"created_at" => now(),
"updated_at" => now()
]);
} catch (\Exception $exception) {}
} else if ($record->tag_id == 2) {
try {
DB::table('investigations')->insert([
"code" => str_replace('"', '', $split_item[0]),
"name" => str_replace('"', '', $split_item[1]),
"non_insured_price" => str_replace('"', '', $split_item[2]),
"category" => 2,
"account_id" => $account_id,
"created_at" => now(),
"updated_at" => now()
]);
} catch (\Exception $exception) {}
} else if ($record->tag_id == 4) {
try {
DB::table('procedures')->insert([
"code" => str_replace('"', '', $split_item[0]),
"name" => str_replace('"', '', $split_item[1]),
"non_insured_price" => str_replace('"', '', $split_item[2]),
"category_id" => 1,
"account_id" => $account_id,
"created_at" => now()
]);
} catch (\Exception $exception) {}
} else if ($record->tag_id == 5) {
try {
DB::table('sundries')->insert([
"code" => str_replace('"', '', $split_item[0]),
"name" => str_replace('"', '', $split_item[1]),
"cost_price" => str_replace('"', '', $split_item[2]),
"non_insured_price" => str_replace('"', '', $split_item[3]),
"account_id" => $account_id,
"inventory_account" => $inventory_account,
"cost_of_goods_account" => $cost_of_goods_account,
"created_at" => now(),
"updated_at" => now()
]);
} catch (\Exception $exception) {}
} else if ($record->tag_id == 6) {
try {
DB::table('services')->insert([
"code" => str_replace('"', '', $split_item[0]),
"name" => str_replace('"', '', $split_item[1]),
"non_insured_price" => str_replace('"', '', $split_item[2]),
"account_id" => $account_id,
"created_at" => now(),
"updated_at" => now()
]);
} catch (\Exception $exception) {}
}
$counter++;
$percentage = round((($counter / $data_count) * 100));
$is_run_complete = 0;
if ($counter == $data_count) {
$is_run_complete = 1;
} elseif ($percentage == 100) {
// because of the round(), 100% is reached before completion
$percentage = 99;
}
DB::table('csv_imports_processes')
->where('id', $id)
->update([
"records_completed" => $percentage,
"is_complete" => $is_run_complete
]);
}
}
}
@@ -0,0 +1,159 @@
<?php
namespace Streamline\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class ImportCsvPriceListsCommand extends Command {
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'import:price_list {id}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Import items price lists';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct() {
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle() {
$id = $this->argument('id');
$record = DB::table('csv_imports_processes')->where('id', $id)->first();
$data = file(base_path('public/' . $record->csv_path));
$data_count = count($data);
$counter = 0;
$price_list_category = "";
foreach($data as $item) {
$split_item = explode(',', $item);
$item_id = 0;
// check if this is the first row and get ids
if ($counter == 0) {
$category_id_arr = [];
for ($i = 1; $i < count($split_item); $i++){
$category_id = get_name(get_name(trim($split_item[$i]), 'name', 'id', 'patient_categories'),
'patient_category_id', 'id', 'price_list_categories');
$category_id_arr[] = $category_id != 'N/A' ? $category_id : 0;
}
$price_list_category = implode(",", $category_id_arr);
$counter++;
continue;
} else {
$category_price = [];
// get the item id
if ($record->tag_id == 3) {
$item_id = get_name($split_item[0], 'name', 'id', 'drugs');
} else if ($record->tag_id == 2) {
$item_id = get_name($split_item[0], 'name', 'id', 'investigations');
} else if ($record->tag_id == 4) {
$item_id = get_name($split_item[0], 'name', 'id', 'procedures');
} else if ($record->tag_id == 5) {
$item_id = get_name($split_item[0], 'name', 'id', 'sundries');
} else if ($record->tag_id == 6) {
$item_id = get_name($split_item[0], 'name', 'id', 'services');
}
if (!is_numeric($item_id)) {
continue;
}
for ($i = 1; $i < count($split_item); $i++){
try {
// catch non numeric error for some cases
$category_price[] = +trim($split_item[$i]);
} catch (\Exception $exception) {
$category_price[] = 0;
}
}
$price_list_price = implode(",", $category_price);
}
if ($record->tag_id == 3) {
try {
DB::table('drugs')->where('id', $item_id)->update([
"price_list_category" => $price_list_category,
"price_list_price" => $price_list_price,
"updated_at" => now()
]);
} catch (\Exception $exception) {}
} else if ($record->tag_id == 2) {
try {
DB::table('investigations')->where('id', $item_id)->update([
"price_list_category" => $price_list_category,
"price_list_price" => $price_list_price,
"updated_at" => now()
]);
} catch (\Exception $exception) {}
} else if ($record->tag_id == 4) {
try {
DB::table('procedures')->where('id', $item_id)->update([
"price_list_category" => $price_list_category,
"price_list_price" => $price_list_price,
"updated_at" => now()
]);
} catch (\Exception $exception) {}
} else if ($record->tag_id == 5) {
try {
DB::table('sundries')->where('id', $item_id)->update([
"price_list_category" => $price_list_category,
"price_list_price" => $price_list_price,
"updated_at" => now()
]);
} catch (\Exception $exception) {}
} else if ($record->tag_id == 6) {
try {
DB::table('services')->where('id', $item_id)->update([
"price_list_category" => $price_list_category,
"price_list_price" => $price_list_price,
"updated_at" => now()
]);
} catch (\Exception $exception) {}
}
$counter++;
$percentage = round((($counter / $data_count) * 100));
$is_run_complete = 0;
if ($counter == $data_count) {
$is_run_complete = 1;
} elseif ($percentage == 100) {
// because of the round(), 100% is reached before completion
$percentage = 99;
}
DB::table('csv_imports_processes')
->where('id', $id)
->update([
"records_completed" => $percentage,
"is_complete" => $is_run_complete
]);
}
}
}
@@ -0,0 +1,186 @@
<?php
namespace Streamline\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class MigrateInsuranceExpenditureCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'migrate:insurance_expenditure';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Migrate insurance expenditure to new CHI model';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct() {
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle() {
DB::beginTransaction();
$grouped_episodes = [];
echo "Fetching OPD insurance expenditure... \n";
$expenditures = DB::table('insurance_expenditure')->whereNull('deleted_at')->get();
foreach ($expenditures as $expenditure) {
$grouped_episodes[$expenditure->episode_id . "-" . $expenditure->tag_id . '-' . $expenditure->patient_id][] = [
"item" => $expenditure->item_id, "created_by" => $expenditure->created_by, "created_on" => $expenditure->created_at,
"amount" => $expenditure->insurance_amount, "account" => $expenditure->income_account
];
}
try {
echo "Creating new claim records... \n";
foreach ($grouped_episodes as $episode_key => $details) {
$explode_key = explode("-", $episode_key);
$item_type = $explode_key[1];
// convert to insurance tags
switch ($item_type) {
case 2:
$item_type = 3;
break;
case 3:
$item_type = 4;
break;
case 4:
$item_type = 2;
break;
case 6:
case 7:
case 8:
$item_type = 1;
break;
}
$details_collection = collect($details);
$item_ids = $details_collection->implode('item', ',');
$item_amounts = $details_collection->implode('amount', ',');
$item_amount_sum = $details_collection->sum('amount');
$item_accounts = $details_collection->implode('account', ',');
$count = $details_collection->count();
$array_of_zero = implode(",", array_fill(0, $count, 0));
$array_of_ones = implode(",", array_fill(0, $count, 1));
DB::table('insurance_claims')->insert([
"patient_id" => $explode_key[2], "episode_id" => $explode_key[0], "claim_status" => 6,
"plan_id" => 1, "benefit_ids" => $array_of_ones, "inpatient_outpatient" => 0,
"primary_plan_claim_total" => $item_amount_sum, "item_type" => $item_type, "item_ids" => $item_ids,
"item_quantities" => $array_of_ones, "tariff_ids" => $array_of_zero, "tariff_amounts" => $item_amounts,
"co_payment_amounts" => $array_of_zero, "item_cash_amounts" => $item_amounts, "current_chart_of_accounts" => $item_accounts,
"order_id" => 0, "is_item_authorisation_required" => $array_of_zero, "is_authorisation_required" => 0,
"created_by" => $details[0]['created_by'], "updated_by" => $details[0]['created_by'], "created_at" => $details[0]['created_on'], "updated_at" => $details[0]['created_on']
]);
}
echo "Fetching IPD insurance expenditure... \n";
$bills = DB::table('inpatient_bills')->whereNull('deleted_at')->get();
echo "Creating new claim records... \n";
foreach ($bills as $bill) {
if ($bill->insurance_treatment_cost > 0 || $bill->insurance_tta_cost > 0) {
$total_cost = $bill->insurance_treatment_cost + $bill->insurance_tta_cost;
DB::table('insurance_claims')->insert([
"patient_id" => $bill->patient_id, "episode_id" => $bill->episode_id, "claim_status" => 6,
"plan_id" => 1, "benefit_ids" => 1, "inpatient_outpatient" => 1,
"primary_plan_claim_total" => $total_cost, "item_type" => 4, "item_ids" => 0,
"item_quantities" => 1, "tariff_ids" => 0, "tariff_amounts" => $total_cost,
"co_payment_amounts" => 0, "item_cash_amounts" => $total_cost, "current_chart_of_accounts" => 0,
"order_id" => $bill->inpatient_info_id, "is_item_authorisation_required" => 0, "is_authorisation_required" => 0,
"created_by" => $bill->created_by, "updated_by" => $bill->updated_by, "created_at" => $bill->created_at, "updated_at" => $bill->updated_at
]);
}
if ($bill->insurance_sundries_cost > 0) {
DB::table('insurance_claims')->insert([
"patient_id" => $bill->patient_id, "episode_id" => $bill->episode_id, "claim_status" => 6,
"plan_id" => 1, "benefit_ids" => 1, "inpatient_outpatient" => 1,
"primary_plan_claim_total" => $bill->insurance_sundries_cost, "item_type" => 5, "item_ids" => 0,
"item_quantities" => 1, "tariff_ids" => 0, "tariff_amounts" => $bill->insurance_sundries_cost,
"co_payment_amounts" => 0, "item_cash_amounts" => $bill->insurance_sundries_cost, "current_chart_of_accounts" => 0,
"order_id" => $bill->inpatient_info_id, "is_item_authorisation_required" => 0, "is_authorisation_required" => 0,
"created_by" => $bill->created_by, "updated_by" => $bill->updated_by, "created_at" => $bill->created_at, "updated_at" => $bill->updated_at
]);
}
/*if ($bill->insurance_services_cost > 0) {
DB::table('insurance_claims')->insert([
"patient_id" => $bill->patient_id, "episode_id" => $bill->episode_id, "claim_status" => 6,
"plan_id" => 1, "benefit_ids" => 1, "inpatient_outpatient" => 1,
"primary_plan_claim_total" => $bill->insurance_services_cost, "item_type" => 1, "item_ids" => 0,
"item_quantities" => 1, "tariff_ids" => 0, "tariff_amounts" => $bill->insurance_services_cost,
"co_payment_amounts" => 0, "item_cash_amounts" => $bill->insurance_services_cost, "current_chart_of_accounts" => 0,
"order_id" => $bill->inpatient_info_id, "is_item_authorisation_required" => 0, "is_authorisation_required" => 0,
"created_by" => $bill->created_by, "updated_by" => $bill->updated_by, "created_at" => $bill->created_at, "updated_at" => $bill->updated_at
]);
}*/
if ($bill->insurance_procedures_cost > 0) {
DB::table('insurance_claims')->insert([
"patient_id" => $bill->patient_id, "episode_id" => $bill->episode_id, "claim_status" => 6,
"plan_id" => 1, "benefit_ids" => 1, "inpatient_outpatient" => 1,
"primary_plan_claim_total" => $bill->insurance_procedures_cost, "item_type" => 2, "item_ids" => 0,
"item_quantities" => 1, "tariff_ids" => 0, "tariff_amounts" => $bill->insurance_procedures_cost,
"co_payment_amounts" => 0, "item_cash_amounts" => $bill->insurance_procedures_cost, "current_chart_of_accounts" => 0,
"order_id" => $bill->inpatient_info_id, "is_item_authorisation_required" => 0, "is_authorisation_required" => 0,
"created_by" => $bill->created_by, "updated_by" => $bill->updated_by, "created_at" => $bill->created_at, "updated_at" => $bill->updated_at
]);
}
if ($bill->insurance_investigation_cost > 0) {
DB::table('insurance_claims')->insert([
"patient_id" => $bill->patient_id, "episode_id" => $bill->episode_id, "claim_status" => 6,
"plan_id" => 1, "benefit_ids" => 1, "inpatient_outpatient" => 1,
"primary_plan_claim_total" => $bill->insurance_investigation_cost, "item_type" => 3, "item_ids" => 0,
"item_quantities" => 1, "tariff_ids" => 0, "tariff_amounts" => $bill->insurance_investigation_cost,
"co_payment_amounts" => 0, "item_cash_amounts" => $bill->insurance_investigation_cost, "current_chart_of_accounts" => 0,
"order_id" => $bill->inpatient_info_id, "is_item_authorisation_required" => 0, "is_authorisation_required" => 0,
"created_by" => $bill->created_by, "updated_by" => $bill->updated_by, "created_at" => $bill->created_at, "updated_at" => $bill->updated_at
]);
}
if ($bill->insurance_hospital_stay_cost > 0) {
DB::table('insurance_claims')->insert([
"patient_id" => $bill->patient_id, "episode_id" => $bill->episode_id, "claim_status" => 6,
"plan_id" => 1, "benefit_ids" => 1, "inpatient_outpatient" => 1,
"primary_plan_claim_total" => $bill->insurance_hospital_stay_cost, "item_type" => 6, "item_ids" => 0,
"item_quantities" => 1, "tariff_ids" => 0, "tariff_amounts" => $bill->insurance_hospital_stay_cost,
"co_payment_amounts" => 0, "item_cash_amounts" => $bill->insurance_hospital_stay_cost, "current_chart_of_accounts" => 0,
"order_id" => $bill->inpatient_info_id, "is_item_authorisation_required" => 0, "is_authorisation_required" => 0,
"created_by" => $bill->created_by, "updated_by" => $bill->updated_by, "created_at" => $bill->created_at, "updated_at" => $bill->updated_at
]);
}
}
DB::commit();
} catch (\Exception $e) {
echo $e->getMessage() . "\n";
DB::rollback();
}
return 0;
}
}
@@ -0,0 +1,57 @@
<?php
namespace Streamline\Console\Commands;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Streamline\Http\Controllers\SMSController;
class SendAppointmentRemaindersCommand extends Command {
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'appointment:remainders';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Send sms alerts to remind patients of appointments a day before';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct() {
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle() {
$tomorrow_start = Carbon::now()->startOfDay()->addDay();
$tomorrow_end = Carbon::now()->endOfDay()->addDay();
$appointments = DB::table('patient_appointments')
->whereBetween('appointment_date', [$tomorrow_start, $tomorrow_end])
->get();
foreach ($appointments as $appointment) {
if (is_sms_enabled()) {
// send sms alert to the patient
$sms = "This is a reminder that your appointment at " . get_name(1, 'id', 'name', 'hospital_information') .
" is scheduled for tomorrow the " . streamline_date($appointment->appointment_date) . " at " . $appointment->appointment_time;
(new SMSController)->send_appointments_alert($appointment->patient_id, $sms);
}
}
}
}
@@ -0,0 +1,275 @@
<?php
namespace Streamline\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class SetupCHICommand extends Command {
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'setup:chi';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Used to migrate old CHI data to the new Ubuntu model to setup CHI faster';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct() {
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle() {
DB::beginTransaction();
$hospital_info = DB::table('hospital_information')->where('id', 1)->first();
$hospital_name = $hospital_info->name;
$hospital_prefix = $hospital_info->patient_number_abbr;
$today = now();
try {
echo "Creating new plan... \n";
$plan_id = DB::table('community_health_insurance_plans')
->insertGetId(['name' => $hospital_name . ' Plan', 'plan_fee' => 0, 'plan_start_date' => $today, 'plan_end_date' => now()->addYear(),
'member_annual_limit' => 0, 'family_annual_limit' => 0, 'is_authorized_required' => 0,
'membership_card_color' => 'blue', 'created_by' => 1, 'created_at' => $today, 'updated_at' => $today]);
echo "Creating new benefit... \n";
$benefit_id = DB::table('insurance_benefits')
->insertGetId(['name' => $hospital_name . ' Benefit', 'waiting_period' => 0, 'fee' => 0, 'annual_member_limit' => 0,
'annual_family_limit' => 0, 'created_by' => 1, 'created_at' => $today, 'updated_at' => $today, 'plan_id' => $plan_id]);
// array to hold insurance benefit items
$insurance_benefit_items = [];
echo "Fetching insured drugs \n";
$drugs = DB::table('drugs')->where('insurance_coverage', 1)->whereNull('deleted_at')
->get(['id', 'insured_price', 'non_insured_price']);
echo "Creating drug benefit items \n";
foreach ($drugs as $drug) {
$insurance_benefit_items[4][] = $drug->id;
$json_array = [$benefit_id => [
"co_payment" => $drug->insured_price, "ipd_co_payment" => $drug->insured_price,
"capitation_fee" => 0, "annual_member_limit" => 0,
"annual_family_limit" => 0, "authorisation" => 0,
"apply_opd_percentage" => 0, "apply_ipd_percentage" => 0,
]];
DB::table('drugs')->where('id', $drug->id)->update(['insurance_benefit_details' => json_encode($json_array)]);
}
echo "Fetching insured sundries \n";
$sundries = DB::table('sundries')->where('insurance', 1)->whereNull('deleted_at')
->get(['id', 'insured_price', 'non_insured_price']);
echo "Creating sundries benefit items \n";
foreach ($sundries as $sundry) {
$insurance_benefit_items[5][] = $sundry->id;
$json_array = [$benefit_id => [
"co_payment" => $sundry->insured_price, "ipd_co_payment" => $sundry->insured_price,
"capitation_fee" => 0, "annual_member_limit" => 0,
"annual_family_limit" => 0, "authorisation" => 0,
"apply_opd_percentage" => 0, "apply_ipd_percentage" => 0,
]];
DB::table('sundries')->where('id', $sundry->id)->update(['insurance_benefit_details' => json_encode($json_array)]);
}
echo "Fetching insured investigations \n";
$investigations = DB::table('investigations')->where('insurance_coverage', 1)->whereNull('deleted_at')
->get(['id', 'insured_price', 'non_insured_price']);
echo "Creating investigation benefit items \n";
foreach ($investigations as $investigation) {
$insurance_benefit_items[3][] = $investigation->id;
$json_array = [$benefit_id => [
"co_payment" => $investigation->insured_price, "ipd_co_payment" => $investigation->insured_price,
"capitation_fee" => 0, "annual_member_limit" => 0,
"annual_family_limit" => 0, "authorisation" => 0,
"apply_opd_percentage" => 0, "apply_ipd_percentage" => 0,
]];
DB::table('investigations')->where('id', $investigation->id)->update(['insurance_benefit_details' => json_encode($json_array)]);
}
echo "Fetching insured procedures \n";
$procedures = DB::table('procedures')->where('insurance', 1)->whereNull('deleted_at')
->get(['id', 'insured_price', 'non_insured_price']);
echo "Creating procedures benefit items \n";
foreach ($procedures as $procedure) {
$insurance_benefit_items[2][] = $procedure->id;
$json_array = [$benefit_id => [
"co_payment" => $procedure->insured_price, "ipd_co_payment" => $procedure->insured_price,
"capitation_fee" => 0, "annual_member_limit" => 0,
"annual_family_limit" => 0, "authorisation" => 0,
"apply_opd_percentage" => 0, "apply_ipd_percentage" => 0,
]];
DB::table('procedures')->where('id', $procedure->id)->update(['insurance_benefit_details' => json_encode($json_array)]);
}
echo "Fetching insured services \n";
$services = DB::table('services')->where('insurance_coverage', 1)->whereNull('deleted_at')
->get(['id', 'insured_price', 'non_insured_price']);
echo "Creating services benefit items \n";
foreach ($services as $service) {
$insurance_benefit_items[1][] = $service->id;
$json_array = [$benefit_id => [
"co_payment" => $service->insured_price, "ipd_co_payment" => $service->insured_price,
"capitation_fee" => 0, "annual_member_limit" => 0,
"annual_family_limit" => 0, "authorisation" => 0,
"apply_opd_percentage" => 0, "apply_ipd_percentage" => 0,
]];
DB::table('services')->where('id', $service->id)->update(['insurance_benefit_details' => json_encode($json_array)]);
}
echo "Creating new benefit items... \n";
foreach ($insurance_benefit_items as $item_type => $benefit_items) {
DB::table('insurance_benefit_items')
->insert(['plan_id' => $plan_id, 'benefit_id' => $benefit_id, 'item_type' => $item_type,
'item_id' => implode(",", $benefit_items), 'created_by' => 1]);
}
// begin shifting the patients to new CHI model
echo "Fetching heads of family and updating... \n";
$heads = DB::table('insurance_heads_of_family')->whereNull('deleted_at')->get();
foreach ($heads as $head) {
// fetch the family members ignoring those who have been deleted
$family_members_arr = [];
$family_members_amount_arr = [];
$family_subscription_id = false;
$family_members = DB::table('insurance_members')->join('patients', 'patients.id', '=', 'insurance_members.patient_id')
->whereNull('insurance_members.deleted_at')
->whereNull('patients.deleted_at')
->where('insurance_members.family_id', $head->id)
->get(['insurance_members.patient_id', 'insurance_members.group_id', 'insurance_members.id', 'patients.gender']);
$family_subs = DB::table('insurance_subscriptions')->whereNull('deleted_at')
->whereRaw('FIND_IN_SET(' . $head->id . ',family_heads)')->orderBy('end_date', 'desc')
->first(['id', 'family_heads', 'family_amount', 'start_date', 'end_date', 'payment_date', 'covered_member_ids', 'covered_member_premiums_paid']);
if ($family_subs) {
$temp_family_heads = explode(",", $family_subs->family_heads);
$temp_family_amounts = explode(",", $family_subs->family_amount);
$family_premium = $temp_family_amounts[array_search($head->id, $temp_family_heads)] ?? 0;
$family_start_date = $family_subs->start_date;
$family_end_date = $family_subs->end_date;
$family_payment_date = $family_subs->payment_date;
$family_subscription_id = $family_subs->id;
} else {
$family_premium = 0;
$family_start_date = NULL;
$family_end_date = NULL;
$family_payment_date = NULL;
}
$number_of_family_members = count($family_members);
$last_member_premium = 0;
// avoid 0 division
if ($family_premium != 0 && $number_of_family_members != 0) {
// check if money can be shared equally, else force it
if ($family_premium % $number_of_family_members == 0) {
$individual_premium = $family_premium / $number_of_family_members;
} else {
$individual_premium = (int)floor($family_premium / $number_of_family_members);;
// get any remainder and give it to the last member
$last_member_premium = $family_premium - ($individual_premium * ($number_of_family_members - 1));
// confirm the amount not negative else just return 0
$last_member_premium = ($last_member_premium > 0) ? $last_member_premium : 0;
}
} else {
$individual_premium = 0;
}
// loop through the family members to get valid ones
foreach ($family_members as $family_member) {
$title = (empty($family_member->gender) || $family_member->gender == 1) ? 1 : 2;
$member_account_number = $hospital_prefix . "/" . date('Y') . "/" . $family_member->group_id. "/" . sprintf("%04d", $family_member->id);
// check if this is the last person
if ((count($family_members_arr) + 1) == $number_of_family_members && $number_of_family_members != 1) {
$individual_premium = $last_member_premium;
}
$family_members_arr[] = $family_member->id;
$family_members_amount_arr[] = $individual_premium;
DB::table('insurance_members')->where('id', $family_member->id)
->update(['title' => $title, 'premium' => $individual_premium, 'chi_plan' => $plan_id,
'membership_start_date' => $family_start_date, 'member_account_number' => $member_account_number, 'membership_registration_date' => $family_payment_date,
'existing_premium_start_date' => $family_start_date, 'existing_premium_end_date' => $family_end_date]);
}
// if the subscription table is available then update
if ($family_subscription_id && $family_subs) {
$exploded_covered_member_ids = is_null($family_subs->covered_member_ids) ? [] : explode(",", $family_subs->covered_member_ids);
$exploded_covered_member_premiums = is_null($family_subs->covered_member_premiums_paid) ? [] : explode(",", $family_subs->covered_member_premiums_paid);
$exploded_covered_member_ids = array_merge($exploded_covered_member_ids, $family_members_arr);
$exploded_covered_member_premiums = array_merge($exploded_covered_member_premiums, $family_members_amount_arr);
DB::table('insurance_subscriptions')->where('id', $family_subscription_id)
->update(['covered_member_ids' => implode(",", $exploded_covered_member_ids),
'covered_member_premiums_paid' => implode(",", $exploded_covered_member_premiums)]);
}
// update the family listing
DB::table('insurance_heads_of_family')->where('id', $head->id)
->update(['family_members_ids' => implode(",", $family_members_arr),
'family_member_premiums' => implode(",", $family_members_amount_arr)]);
}
// fetch number of insurance members with null
$member_count = DB::table('insurance_members')->whereNull(['deleted_at', 'chi_plan'])->count();
echo "Insurance members with null are " . $member_count . "\n";
// fetch number of insurance heads with null
$heads_count = DB::table('insurance_heads_of_family')->whereNull(['deleted_at', 'family_members_ids'])->count();
echo "Insurance heads of family with null are " . $heads_count . "\n";
// fetch number of insurance subscriptions with null
$subs_count = DB::table('insurance_subscriptions')->whereNull(['deleted_at', 'covered_member_ids'])->count();
echo "Insurance subscriptions with null are " . $subs_count . "\n";
echo "Migration complete \n";
DB::commit();
} catch (\Exception $e) {
echo $e->getMessage() . "\n";
DB::rollback();
}
return 0;
}
}
+49
View File
@@ -0,0 +1,49 @@
<?php
namespace Streamline\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use Streamline\Console\Commands\CorrectFinanceCommand;
use Streamline\Console\Commands\ImportCsvPriceListsCommand;
use Streamline\Console\Commands\MigrateInsuranceExpenditureCommand;
use Streamline\Console\Commands\SendAppointmentRemaindersCommand;
use Streamline\Console\Commands\ImportCsvItemsCommand;
use Streamline\Console\Commands\SetupCHICommand;
class Kernel extends ConsoleKernel {
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
// Publishing commands
SendAppointmentRemaindersCommand::class,
ImportCsvItemsCommand::class,
ImportCsvPriceListsCommand::class,
CorrectFinanceCommand::class,
SetupCHICommand::class,
MigrateInsuranceExpenditureCommand::class,
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule) {
$schedule->command('appointment:remainders')->dailyAt('09:00');
}
/**
* Register the Closure based commands for the application.
*
* @return void
*/
protected function commands() {
require base_path('routes/console.php');
}
}