mirror of
https://gitlab.com/signalytic/client-external/streamline/streamline-emr.git
synced 2026-09-11 18:51:31 +00:00
187 lines
10 KiB
PHP
187 lines
10 KiB
PHP
<?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;
|
|
}
|
|
}
|