mirror of
https://gitlab.com/signalytic/client-external/streamline/streamline-emr.git
synced 2026-09-11 18:51:31 +00:00
resolved conflicts
This commit is contained in:
@@ -0,0 +1,735 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Cancer\Http\Controllers;
|
||||
|
||||
use Barryvdh\Snappy\Facades\SnappyPdf;
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Illuminate\Contracts\Support\Renderable;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Routing\Redirector;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Modules\ClinicalData\Services\Drugs\DrugRoutesService;
|
||||
use Modules\ClinicalData\Services\Drugs\DrugsService;
|
||||
use Modules\ClinicalData\Services\Drugs\DrugUnitsService;
|
||||
use Streamline\Models\CancerProtocol;
|
||||
use Streamline\Models\HospitalInformation;
|
||||
use Streamline\Models\OrderedCancerProtocols;
|
||||
use Streamline\Models\Patient;
|
||||
|
||||
class CancerProtocolController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
protected DrugsService $drugsService,
|
||||
protected DrugRoutesService $drugRoutesService,
|
||||
protected DrugUnitsService $drugUnitsService
|
||||
) {}
|
||||
|
||||
public static array $factors = [0 => 'Standard', 1 => 'BSA', 2 => 'Weight'];
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
* @return Renderable
|
||||
*/
|
||||
public function index() {
|
||||
$cancer_protocols = CancerProtocol::all();
|
||||
|
||||
$drugs = $this->drugsService->pluckAvailableDrugs('name');
|
||||
$drug_with_units = $this->drugsService->pluckAvailableDrugs('unit_id');
|
||||
$drug_units = $this->drugUnitsService->pluckAvailableDrugUnits('name');
|
||||
$drug_routes = $this->drugRoutesService->pluckAvailableDrugRoutes('name');
|
||||
|
||||
$factors = static::$factors;
|
||||
|
||||
return view('cancer::cancer_protocol.index', compact('cancer_protocols', 'drugs', 'drug_routes',
|
||||
'factors', 'drug_units', 'drug_with_units'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
* @return Renderable
|
||||
*/
|
||||
public function create() {
|
||||
$drugs = $this->drugsService->pluckAvailableDrugs('name')->prepend('-- select drugs --', '');
|
||||
$drug_routes = $this->drugRoutesService->pluckAvailableDrugRoutes('name')->prepend('-- select routes --', '');
|
||||
|
||||
$factors = static::$factors;
|
||||
|
||||
$option_drugs = "";
|
||||
foreach ($drugs as $key => $value){
|
||||
$drug_name = str_replace("'", '', $value);
|
||||
$drug_name = str_replace("\"", '', $drug_name);
|
||||
$drug_name = str_replace("+", '', $drug_name);
|
||||
$option_drugs .= "<option value='$key'>$drug_name</option>";
|
||||
}
|
||||
|
||||
$option_drug_routes = "";
|
||||
foreach ($drug_routes as $key => $value){
|
||||
$option_drug_routes .= "<option value='$key'>$value</option>";
|
||||
}
|
||||
|
||||
$option_factors = "<option value=''>-select-</option>";
|
||||
foreach ($factors as $key => $value){
|
||||
$option_factors .= "<option value='$key'>$value</option>";
|
||||
}
|
||||
|
||||
return view('cancer::cancer_protocol.create', compact('drugs', 'factors', 'drug_routes',
|
||||
'option_drugs', 'option_drug_routes', 'option_factors'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
* @param Request $request
|
||||
* @return Application|\Illuminate\Foundation\Application|RedirectResponse|Redirector
|
||||
*/
|
||||
public function store(Request $request) {
|
||||
$request->validate([
|
||||
"name" => "required",
|
||||
"protocol_billing_type" => "required"
|
||||
]);
|
||||
|
||||
$protocol_billing_type = $request->protocol_billing_type;
|
||||
$protocol_cost = $request->protocol_cost;
|
||||
|
||||
if ($protocol_billing_type == 0 && !is_numeric($protocol_cost)) {
|
||||
flash("Please add a protocol cost when billing type is umbrella")->error();
|
||||
return back()->withInput();
|
||||
}
|
||||
|
||||
/* Pre Chemo Section */
|
||||
$pre_chemo_row_counter_arr = $request->pre_chemo_row_counter;
|
||||
$pre_chemo_drug_id_arr = $request->pre_chemo_drug_id;
|
||||
$pre_chemo_drug_route_arr = $request->pre_chemo_drug_route;
|
||||
$pre_chemo_drug_factor_id_arr = $request->pre_chemo_drug_factor_id;
|
||||
$pre_chemo_drug_weight_range_arr = $request->pre_chemo_drug_weight_range;
|
||||
$pre_chemo_drug_dose_arr = $request->pre_chemo_drug_dose;
|
||||
$pre_chemo_drug_duration_arr = $request->pre_chemo_drug_duration;
|
||||
$pre_chemo_drug_instructions_arr = $request->pre_chemo_drug_instructions;
|
||||
$pre_chemo_child_row_id_arr = $request->pre_chemo_child_row_id;
|
||||
$pre_chemo_child_drug_weight_range_arr = $request->pre_chemo_child_drug_weight_range;
|
||||
$pre_chemo_child_drug_dose_arr = $request->pre_chemo_child_drug_dose;
|
||||
$pre_chemo_child_drug_duration_arr = $request->pre_chemo_child_drug_duration;
|
||||
$pre_chemo_child_drug_instructions_arr = $request->pre_chemo_child_drug_instructions;
|
||||
|
||||
$pre_chemo_drugs = [];
|
||||
|
||||
for ($x = 0; $x < count($pre_chemo_drug_id_arr); $x++) {
|
||||
$pre_chemo_drugs[$pre_chemo_row_counter_arr[$x]] = [
|
||||
"drug_id" => $pre_chemo_drug_id_arr[$x],
|
||||
"drug_route" => $pre_chemo_drug_route_arr[$x],
|
||||
"drug_factor" => $pre_chemo_drug_factor_id_arr[$x],
|
||||
"dose" => [[
|
||||
"weight_range" => $pre_chemo_drug_weight_range_arr[$x] ?? '',
|
||||
"dose" => $pre_chemo_drug_dose_arr[$x] ?? '',
|
||||
"duration" => $pre_chemo_drug_duration_arr[$x] ?? '',
|
||||
"instructions" => $pre_chemo_drug_instructions_arr[$x] ?? '',
|
||||
]],
|
||||
];
|
||||
}
|
||||
|
||||
if (is_array($pre_chemo_child_row_id_arr)) {
|
||||
for ($x = 0; $x < count($pre_chemo_child_row_id_arr); $x++) {
|
||||
if(isset($pre_chemo_drugs[$pre_chemo_child_row_id_arr[$x]])) {
|
||||
$pre_chemo_drugs[$pre_chemo_child_row_id_arr[$x]]["dose"][] = [
|
||||
"weight_range" => $pre_chemo_child_drug_weight_range_arr[$x] ?? '',
|
||||
"dose" => $pre_chemo_child_drug_dose_arr[$x] ?? '',
|
||||
"duration" => $pre_chemo_child_drug_duration_arr[$x] ?? '',
|
||||
"instructions" => $pre_chemo_child_drug_instructions_arr[$x] ?? '',
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Chemo Section */
|
||||
$chemo_row_counter_arr = $request->chemo_row_counter;
|
||||
$chemo_drug_id_arr = $request->chemo_drug_id;
|
||||
$chemo_drug_route_arr = $request->chemo_drug_route;
|
||||
$chemo_drug_factor_id_arr = $request->chemo_drug_factor_id;
|
||||
$chemo_drug_weight_range_arr = $request->chemo_drug_weight_range;
|
||||
$chemo_drug_dose_arr = $request->chemo_drug_dose;
|
||||
$chemo_drug_duration_arr = $request->chemo_drug_duration;
|
||||
$chemo_drug_instructions_arr = $request->chemo_drug_instructions;
|
||||
$chemo_child_row_id_arr = $request->chemo_child_row_id;
|
||||
$chemo_child_drug_weight_range_arr = $request->chemo_child_drug_weight_range;
|
||||
$chemo_child_drug_dose_arr = $request->chemo_child_drug_dose;
|
||||
$chemo_child_drug_duration_arr = $request->chemo_child_drug_duration;
|
||||
$chemo_child_drug_instructions_arr = $request->chemo_child_drug_instructions;
|
||||
|
||||
$chemo_drugs = [];
|
||||
|
||||
for ($x = 0; $x < count($chemo_drug_id_arr); $x++) {
|
||||
$chemo_drugs[$chemo_row_counter_arr[$x]] = [
|
||||
"drug_id" => $chemo_drug_id_arr[$x],
|
||||
"drug_route" => $chemo_drug_route_arr[$x],
|
||||
"drug_factor" => $chemo_drug_factor_id_arr[$x],
|
||||
"dose" => [[
|
||||
"weight_range" => $chemo_drug_weight_range_arr[$x] ?? '',
|
||||
"dose" => $chemo_drug_dose_arr[$x] ?? '',
|
||||
"duration" => $chemo_drug_duration_arr[$x] ?? '',
|
||||
"instructions" => $chemo_drug_instructions_arr[$x] ?? '',
|
||||
]],
|
||||
];
|
||||
}
|
||||
|
||||
if (is_array($chemo_child_row_id_arr)) {
|
||||
for ($x = 0; $x < count($chemo_child_row_id_arr); $x++) {
|
||||
if(isset($chemo_drugs[$chemo_child_row_id_arr[$x]])) {
|
||||
$chemo_drugs[$chemo_child_row_id_arr[$x]]["dose"][] = [
|
||||
"weight_range" => $chemo_child_drug_weight_range_arr[$x] ?? '',
|
||||
"dose" => $chemo_child_drug_dose_arr[$x] ?? '',
|
||||
"duration" => $chemo_child_drug_duration_arr[$x] ?? '',
|
||||
"instructions" => $chemo_child_drug_instructions_arr[$x] ?? '',
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Post Chemo Section */
|
||||
$post_chemo_row_counter_arr = $request->post_chemo_row_counter;
|
||||
$post_chemo_drug_id_arr = $request->post_chemo_drug_id;
|
||||
$post_chemo_drug_route_arr = $request->post_chemo_drug_route;
|
||||
$post_chemo_drug_factor_id_arr = $request->post_chemo_drug_factor_id;
|
||||
$post_chemo_drug_weight_range_arr = $request->post_chemo_drug_weight_range;
|
||||
$post_chemo_drug_dose_arr = $request->post_chemo_drug_dose;
|
||||
$post_chemo_drug_duration_arr = $request->post_chemo_drug_duration;
|
||||
$post_chemo_drug_instructions_arr = $request->post_chemo_drug_instructions;
|
||||
$post_chemo_child_row_id_arr = $request->post_chemo_child_row_id;
|
||||
$post_chemo_child_drug_weight_range_arr = $request->post_chemo_child_drug_weight_range;
|
||||
$post_chemo_child_drug_dose_arr = $request->post_chemo_child_drug_dose;
|
||||
$post_chemo_child_drug_duration_arr = $request->post_chemo_child_drug_duration;
|
||||
$post_chemo_child_drug_instructions_arr = $request->post_chemo_child_drug_instructions;
|
||||
|
||||
$post_chemo_drugs = [];
|
||||
|
||||
for ($x = 0; $x < count($post_chemo_drug_id_arr); $x++) {
|
||||
$post_chemo_drugs[$post_chemo_row_counter_arr[$x]] = [
|
||||
"drug_id" => $post_chemo_drug_id_arr[$x],
|
||||
"drug_route" => $post_chemo_drug_route_arr[$x],
|
||||
"drug_factor" => $post_chemo_drug_factor_id_arr[$x],
|
||||
"dose" => [[
|
||||
"weight_range" => $post_chemo_drug_weight_range_arr[$x] ?? '',
|
||||
"dose" => $post_chemo_drug_dose_arr[$x] ?? '',
|
||||
"duration" => $post_chemo_drug_duration_arr[$x] ?? '',
|
||||
"instructions" => $post_chemo_drug_instructions_arr[$x] ?? '',
|
||||
]],
|
||||
];
|
||||
}
|
||||
|
||||
if (is_array($post_chemo_child_row_id_arr)) {
|
||||
for ($x = 0; $x < count($post_chemo_child_row_id_arr); $x++) {
|
||||
if(isset($post_chemo_drugs[$post_chemo_child_row_id_arr[$x]])) {
|
||||
$post_chemo_drugs[$post_chemo_child_row_id_arr[$x]]["dose"][] = [
|
||||
"weight_range" => $post_chemo_child_drug_weight_range_arr[$x] ?? '',
|
||||
"dose" => $post_chemo_child_drug_dose_arr[$x] ?? '',
|
||||
"duration" => $post_chemo_child_drug_duration_arr[$x] ?? '',
|
||||
"instructions" => $post_chemo_child_drug_instructions_arr[$x] ?? '',
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$cancer_protocol = new CancerProtocol();
|
||||
$cancer_protocol->name = $request->name;
|
||||
$cancer_protocol->protocol_billing_type = $protocol_billing_type;
|
||||
$cancer_protocol->protocol_cost = $protocol_cost;
|
||||
$cancer_protocol->pre_chemo_comments = $request->pre_chemo_comments;
|
||||
$cancer_protocol->pre_chemo_drugs = json_encode(array_values($pre_chemo_drugs));
|
||||
$cancer_protocol->chemo_comments = $request->chemo_comments;
|
||||
$cancer_protocol->chemo_drugs = json_encode(array_values($chemo_drugs));
|
||||
$cancer_protocol->post_chemo_comments = $request->post_chemo_comments;
|
||||
$cancer_protocol->post_chemo_drugs = json_encode(array_values($post_chemo_drugs));
|
||||
$cancer_protocol->created_by = Auth::id();
|
||||
|
||||
try {
|
||||
$cancer_protocol->save();
|
||||
return redirect('/cancer_protocol/');
|
||||
} catch (QueryException $exception) {
|
||||
flash("An error occurred. Please try again later")->error();
|
||||
return back()->withInput();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the specified resource.
|
||||
* @param int $id
|
||||
* @return Renderable
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
return view('cancer::show');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
* @param int $id
|
||||
* @return Renderable
|
||||
*/
|
||||
public function edit($id) {
|
||||
$drugs = DB::table('drugs')->whereNull('deleted_at')
|
||||
->where('available', 1)
|
||||
->pluck('name', 'id')->prepend('-- select drugs --', '');
|
||||
|
||||
$drug_routes = DB::table('drug_routes')->whereNull('deleted_at')
|
||||
->where('available', 1)
|
||||
->pluck('name', 'id')->prepend('-- select routes --', '');
|
||||
|
||||
$factors = static::$factors;
|
||||
|
||||
$option_drugs = "";
|
||||
foreach ($drugs as $key => $value){
|
||||
$drug_name = str_replace("'", '', $value);
|
||||
$drug_name = str_replace("\"", '', $drug_name);
|
||||
$drug_name = str_replace("+", '', $drug_name);
|
||||
$option_drugs .= "<option value='$key'>$drug_name</option>";
|
||||
}
|
||||
|
||||
$option_drug_routes = "";
|
||||
foreach ($drug_routes as $key => $value){
|
||||
$option_drug_routes .= "<option value='$key'>$value</option>";
|
||||
}
|
||||
|
||||
$option_factors = "<option value=''>-select-</option>";
|
||||
foreach ($factors as $key => $value){
|
||||
$option_factors .= "<option value='$key'>$value</option>";
|
||||
}
|
||||
|
||||
$cancer_protocol = CancerProtocol::find($id);
|
||||
|
||||
return view('cancer::cancer_protocol.edit', compact('drugs', 'factors', 'drug_routes',
|
||||
'option_drugs', 'option_drug_routes', 'option_factors', 'cancer_protocol'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
* @param Request $request
|
||||
* @param int $id
|
||||
* @return Renderable
|
||||
*/
|
||||
public function update(Request $request, $id) {
|
||||
$request->validate([
|
||||
"name" => "required",
|
||||
"protocol_billing_type" => "required"
|
||||
]);
|
||||
|
||||
$protocol_billing_type = $request->protocol_billing_type;
|
||||
$protocol_cost = $request->protocol_cost;
|
||||
|
||||
if ($protocol_billing_type == 0 && !is_numeric($protocol_cost)) {
|
||||
flash("Please add a protocol cost when billing type is umbrella")->error();
|
||||
return back()->withInput();
|
||||
}
|
||||
|
||||
/* Pre Chemo Section */
|
||||
$pre_chemo_row_counter_arr = $request->pre_chemo_row_counter;
|
||||
$pre_chemo_drug_id_arr = $request->pre_chemo_drug_id;
|
||||
$pre_chemo_drug_route_arr = $request->pre_chemo_drug_route;
|
||||
$pre_chemo_drug_factor_id_arr = $request->pre_chemo_drug_factor_id;
|
||||
$pre_chemo_drug_weight_range_arr = $request->pre_chemo_drug_weight_range;
|
||||
$pre_chemo_drug_dose_arr = $request->pre_chemo_drug_dose;
|
||||
$pre_chemo_drug_duration_arr = $request->pre_chemo_drug_duration;
|
||||
$pre_chemo_drug_instructions_arr = $request->pre_chemo_drug_instructions;
|
||||
$pre_chemo_child_row_id_arr = $request->pre_chemo_child_row_id;
|
||||
$pre_chemo_child_drug_weight_range_arr = $request->pre_chemo_child_drug_weight_range;
|
||||
$pre_chemo_child_drug_dose_arr = $request->pre_chemo_child_drug_dose;
|
||||
$pre_chemo_child_drug_duration_arr = $request->pre_chemo_child_drug_duration;
|
||||
$pre_chemo_child_drug_instructions_arr = $request->pre_chemo_child_drug_instructions;
|
||||
|
||||
$pre_chemo_drugs = [];
|
||||
|
||||
for ($x = 0; $x < count($pre_chemo_drug_id_arr); $x++) {
|
||||
$pre_chemo_drugs[$pre_chemo_row_counter_arr[$x]] = [
|
||||
"drug_id" => $pre_chemo_drug_id_arr[$x],
|
||||
"drug_route" => $pre_chemo_drug_route_arr[$x],
|
||||
"drug_factor" => $pre_chemo_drug_factor_id_arr[$x],
|
||||
"dose" => [[
|
||||
"weight_range" => $pre_chemo_drug_weight_range_arr[$x] ?? '',
|
||||
"dose" => $pre_chemo_drug_dose_arr[$x] ?? '',
|
||||
"duration" => $pre_chemo_drug_duration_arr[$x] ?? '',
|
||||
"instructions" => $pre_chemo_drug_instructions_arr[$x] ?? '',
|
||||
]],
|
||||
];
|
||||
}
|
||||
|
||||
if (is_array($pre_chemo_child_row_id_arr)) {
|
||||
for ($x = 0; $x < count($pre_chemo_child_row_id_arr); $x++) {
|
||||
if(isset($pre_chemo_drugs[$pre_chemo_child_row_id_arr[$x]])) {
|
||||
$pre_chemo_drugs[$pre_chemo_child_row_id_arr[$x]]["dose"][] = [
|
||||
"weight_range" => $pre_chemo_child_drug_weight_range_arr[$x] ?? '',
|
||||
"dose" => $pre_chemo_child_drug_dose_arr[$x] ?? '',
|
||||
"duration" => $pre_chemo_child_drug_duration_arr[$x] ?? '',
|
||||
"instructions" => $pre_chemo_child_drug_instructions_arr[$x] ?? '',
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Chemo Section */
|
||||
$chemo_row_counter_arr = $request->chemo_row_counter;
|
||||
$chemo_drug_id_arr = $request->chemo_drug_id;
|
||||
$chemo_drug_route_arr = $request->chemo_drug_route;
|
||||
$chemo_drug_factor_id_arr = $request->chemo_drug_factor_id;
|
||||
$chemo_drug_weight_range_arr = $request->chemo_drug_weight_range;
|
||||
$chemo_drug_dose_arr = $request->chemo_drug_dose;
|
||||
$chemo_drug_duration_arr = $request->chemo_drug_duration;
|
||||
$chemo_drug_instructions_arr = $request->chemo_drug_instructions;
|
||||
$chemo_child_row_id_arr = $request->chemo_child_row_id;
|
||||
$chemo_child_drug_weight_range_arr = $request->chemo_child_drug_weight_range;
|
||||
$chemo_child_drug_dose_arr = $request->chemo_child_drug_dose;
|
||||
$chemo_child_drug_duration_arr = $request->chemo_child_drug_duration;
|
||||
$chemo_child_drug_instructions_arr = $request->chemo_child_drug_instructions;
|
||||
|
||||
$chemo_drugs = [];
|
||||
|
||||
for ($x = 0; $x < count($chemo_drug_id_arr); $x++) {
|
||||
$chemo_drugs[$chemo_row_counter_arr[$x]] = [
|
||||
"drug_id" => $chemo_drug_id_arr[$x],
|
||||
"drug_route" => $chemo_drug_route_arr[$x],
|
||||
"drug_factor" => $chemo_drug_factor_id_arr[$x],
|
||||
"dose" => [[
|
||||
"weight_range" => $chemo_drug_weight_range_arr[$x] ?? '',
|
||||
"dose" => $chemo_drug_dose_arr[$x] ?? '',
|
||||
"duration" => $chemo_drug_duration_arr[$x] ?? '',
|
||||
"instructions" => $chemo_drug_instructions_arr[$x] ?? '',
|
||||
]],
|
||||
];
|
||||
}
|
||||
|
||||
if (is_array($chemo_child_row_id_arr)) {
|
||||
for ($x = 0; $x < count($chemo_child_row_id_arr); $x++) {
|
||||
if(isset($chemo_drugs[$chemo_child_row_id_arr[$x]])) {
|
||||
$chemo_drugs[$chemo_child_row_id_arr[$x]]["dose"][] = [
|
||||
"weight_range" => $chemo_child_drug_weight_range_arr[$x] ?? '',
|
||||
"dose" => $chemo_child_drug_dose_arr[$x] ?? '',
|
||||
"duration" => $chemo_child_drug_duration_arr[$x] ?? '',
|
||||
"instructions" => $chemo_child_drug_instructions_arr[$x] ?? '',
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Post Chemo Section */
|
||||
$post_chemo_row_counter_arr = $request->post_chemo_row_counter;
|
||||
$post_chemo_drug_id_arr = $request->post_chemo_drug_id;
|
||||
$post_chemo_drug_route_arr = $request->post_chemo_drug_route;
|
||||
$post_chemo_drug_factor_id_arr = $request->post_chemo_drug_factor_id;
|
||||
$post_chemo_drug_weight_range_arr = $request->post_chemo_drug_weight_range;
|
||||
$post_chemo_drug_dose_arr = $request->post_chemo_drug_dose;
|
||||
$post_chemo_drug_duration_arr = $request->post_chemo_drug_duration;
|
||||
$post_chemo_drug_instructions_arr = $request->post_chemo_drug_instructions;
|
||||
$post_chemo_child_row_id_arr = $request->post_chemo_child_row_id;
|
||||
$post_chemo_child_drug_weight_range_arr = $request->post_chemo_child_drug_weight_range;
|
||||
$post_chemo_child_drug_dose_arr = $request->post_chemo_child_drug_dose;
|
||||
$post_chemo_child_drug_duration_arr = $request->post_chemo_child_drug_duration;
|
||||
$post_chemo_child_drug_instructions_arr = $request->post_chemo_child_drug_instructions;
|
||||
|
||||
$post_chemo_drugs = [];
|
||||
|
||||
for ($x = 0; $x < count($post_chemo_drug_id_arr); $x++) {
|
||||
$post_chemo_drugs[$post_chemo_row_counter_arr[$x]] = [
|
||||
"drug_id" => $post_chemo_drug_id_arr[$x],
|
||||
"drug_route" => $post_chemo_drug_route_arr[$x],
|
||||
"drug_factor" => $post_chemo_drug_factor_id_arr[$x],
|
||||
"dose" => [[
|
||||
"weight_range" => $post_chemo_drug_weight_range_arr[$x] ?? '',
|
||||
"dose" => $post_chemo_drug_dose_arr[$x] ?? '',
|
||||
"duration" => $post_chemo_drug_duration_arr[$x] ?? '',
|
||||
"instructions" => $post_chemo_drug_instructions_arr[$x] ?? '',
|
||||
]],
|
||||
];
|
||||
}
|
||||
|
||||
if (is_array($post_chemo_child_row_id_arr)) {
|
||||
for ($x = 0; $x < count($post_chemo_child_row_id_arr); $x++) {
|
||||
if(isset($post_chemo_drugs[$post_chemo_child_row_id_arr[$x]])) {
|
||||
$post_chemo_drugs[$post_chemo_child_row_id_arr[$x]]["dose"][] = [
|
||||
"weight_range" => $post_chemo_child_drug_weight_range_arr[$x] ?? '',
|
||||
"dose" => $post_chemo_child_drug_dose_arr[$x] ?? '',
|
||||
"duration" => $post_chemo_child_drug_duration_arr[$x] ?? '',
|
||||
"instructions" => $post_chemo_child_drug_instructions_arr[$x] ?? '',
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$cancer_protocol = CancerProtocol::find($id);
|
||||
$cancer_protocol->name = $request->name;
|
||||
$cancer_protocol->protocol_billing_type = $protocol_billing_type;
|
||||
$cancer_protocol->protocol_cost = $protocol_cost;
|
||||
$cancer_protocol->pre_chemo_comments = $request->pre_chemo_comments;
|
||||
$cancer_protocol->pre_chemo_drugs = json_encode(array_values($pre_chemo_drugs));
|
||||
$cancer_protocol->chemo_comments = $request->chemo_comments;
|
||||
$cancer_protocol->chemo_drugs = json_encode(array_values($chemo_drugs));
|
||||
$cancer_protocol->post_chemo_comments = $request->post_chemo_comments;
|
||||
$cancer_protocol->post_chemo_drugs = json_encode(array_values($post_chemo_drugs));
|
||||
$cancer_protocol->updated_by = Auth::id();
|
||||
|
||||
try {
|
||||
$cancer_protocol->save();
|
||||
return redirect('/cancer_protocol/');
|
||||
} catch (QueryException $exception) {
|
||||
flash("An error occurred. Please try again later")->error();
|
||||
return back()->withInput();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
* @param int $id
|
||||
*/
|
||||
public function destroy($id) {
|
||||
$protocol = CancerProtocol::find($id);
|
||||
|
||||
if ($protocol->delete()){
|
||||
flash("Protocol has been deleted.")->success();
|
||||
return redirect('/cancer_protocol/');
|
||||
} else {
|
||||
flash("An error occurred. Please try again later")->error();
|
||||
return back()->withInput();
|
||||
}
|
||||
}
|
||||
|
||||
public function inactive() {
|
||||
$cancer_protocols = CancerProtocol::onlyTrashed()->get();
|
||||
|
||||
return view('cancer::cancer_protocol.inactive', compact('cancer_protocols'));
|
||||
}
|
||||
|
||||
public function activate($id) {
|
||||
$protocol = CancerProtocol::withTrashed()->find($id);
|
||||
|
||||
if ($protocol->restore()){
|
||||
flash("Protocol has been activated")->success();
|
||||
return redirect('/cancer_protocol/');
|
||||
} else {
|
||||
flash("An error occurred. Please try again later")->error();
|
||||
return back()->withInput();
|
||||
}
|
||||
}
|
||||
|
||||
public function print_all_protocols() {
|
||||
$cancer_protocols = CancerProtocol::all();
|
||||
$hospital_information = HospitalInformation::find(1);
|
||||
|
||||
$drugs = $this->drugsService->pluckAvailableDrugs('name');
|
||||
$drug_with_units = $this->drugsService->pluckAvailableDrugs('unit_id');
|
||||
$drug_units = $this->drugUnitsService->pluckAvailableDrugUnits('name');
|
||||
$drug_routes = $this->drugRoutesService->pluckAvailableDrugRoutes('name');
|
||||
|
||||
$factors = static::$factors;
|
||||
|
||||
$data = [
|
||||
'drugs' => $drugs,
|
||||
'hospitalInfo' => $hospital_information,
|
||||
'cancer_protocols' => $cancer_protocols,
|
||||
'drug_with_units' => $drug_with_units,
|
||||
'drug_units' => $drug_units,
|
||||
'drug_routes' => $drug_routes,
|
||||
'factors' => $factors
|
||||
];
|
||||
|
||||
$print_footer = (!is_null($hospital_information->print_footer)) ? '     <i>' . $hospital_information->print_footer . '</i>' : '';
|
||||
|
||||
$pdf = SnappyPDF::loadView("cancer::cancer_protocol/print_all_protocols", $data)
|
||||
->setOrientation('portrait')
|
||||
->setPaper('a4')
|
||||
->setOption('margin-bottom', 5)
|
||||
->setOption('margin-top', 5)
|
||||
->setOption('footer-html', '<i>© ' . date('Y') . ' Stre@mline</i>' . $print_footer);
|
||||
|
||||
|
||||
return $pdf->inline('Cancer Protocols' . date(" d-m-y h:ia") . '.pdf');
|
||||
}
|
||||
|
||||
public function order_protocol(Request $request) {
|
||||
$patient_id = session()->get('patient_id');
|
||||
$episode_id = session()->get('episode_id');
|
||||
$inpatient_info_id = session()->get('inpatient_info_id');
|
||||
$selected_protocols = [];
|
||||
|
||||
if (isset($request->cancer_protocols) && is_array($request->cancer_protocols)) {
|
||||
$selected_protocols = CancerProtocol::whereIn('id', $request->cancer_protocols)->get();
|
||||
}
|
||||
|
||||
$patient = Patient::find($patient_id);
|
||||
|
||||
$cancer_protocols = CancerProtocol::pluck('name', 'id');
|
||||
|
||||
$drugs = $this->drugsService->pluckAvailableDrugs('name');
|
||||
$drug_with_units = $this->drugsService->pluckAvailableDrugs('unit_id');
|
||||
$drug_units = $this->drugUnitsService->pluckAvailableDrugUnits('name');
|
||||
$drug_routes = $this->drugRoutesService->pluckAvailableDrugRoutes('name');
|
||||
|
||||
$factors = static::$factors;
|
||||
|
||||
return view('cancer::cancer_protocol.order_protocol', compact('patient_id', 'episode_id', 'inpatient_info_id',
|
||||
'cancer_protocols', 'patient', 'selected_protocols', 'drugs', 'drug_routes', 'drug_units', 'drug_with_units', 'factors'));
|
||||
}
|
||||
|
||||
public function save_protocol_order(Request $request) {
|
||||
$protocol_ids = $request->protocol_id;
|
||||
$inpatient_id = $request->inpatient_info_id;
|
||||
$patient_id = $request->patient_id;
|
||||
$episode_id = $request->episode_id;
|
||||
$adjusted_dose = $request->adjusted_dose;
|
||||
$adjusted_dose_reason = $request->adjusted_dose_reason;
|
||||
$count = 0;
|
||||
|
||||
foreach ($protocol_ids as $protocol_id) {
|
||||
$pre_chemo_drugs_to_save = [];
|
||||
$chemo_drugs_to_save = [];
|
||||
$post_chemo_drugs_to_save = [];
|
||||
$cancer_protocol = CancerProtocol::find($protocol_id);
|
||||
|
||||
$pre_chemo_drugs = json_decode($cancer_protocol->pre_chemo_drugs, true);
|
||||
$chemo_drugs = json_decode($cancer_protocol->chemo_drugs, true);
|
||||
$post_chemo_drugs = json_decode($cancer_protocol->post_chemo_drugs, true);
|
||||
|
||||
for($x = 0; $x < count($pre_chemo_drugs); $x++) {
|
||||
$drug_doses = [];
|
||||
|
||||
for($i = 0; $i < count($pre_chemo_drugs[$x]['dose']); $i++){
|
||||
$duration_array = explode(",", $pre_chemo_drugs[$x]['dose'][$i]['duration']);
|
||||
$duration_array_to_store = [];
|
||||
|
||||
foreach ($duration_array as $duration) {
|
||||
$duration_array_to_store[] = [
|
||||
"name" => $duration,
|
||||
"given_by" => NULL,
|
||||
"given_on" => NULL,
|
||||
"quantity_given" => 0,
|
||||
];
|
||||
}
|
||||
|
||||
$drug_doses[] = [
|
||||
"dose" => (!empty($adjusted_dose[$count]) && is_numeric($adjusted_dose[$count])) ? $adjusted_dose[$count] : $pre_chemo_drugs[$x]['dose'][$i]['dose'],
|
||||
"weight_range" => $pre_chemo_drugs[$x]['dose'][$i]['weight_range'],
|
||||
"duration" => $duration_array_to_store,
|
||||
"instructions" => $pre_chemo_drugs[$x]['dose'][$i]['instructions'],
|
||||
"adjusted_dose_reason" => (!empty($adjusted_dose[$count]) && is_numeric($adjusted_dose[$count])) ? $adjusted_dose_reason[$count] : NULL
|
||||
];
|
||||
|
||||
$count++;
|
||||
}
|
||||
|
||||
$pre_chemo_drugs_to_save[] = [
|
||||
"protocol_id" => $protocol_id,
|
||||
"drug_id" => $pre_chemo_drugs[$x]['drug_id'],
|
||||
"drug_route" => $pre_chemo_drugs[$x]['drug_route'],
|
||||
"drug_factor" => $pre_chemo_drugs[$x]['drug_factor'],
|
||||
"dose" => $drug_doses
|
||||
];
|
||||
}
|
||||
|
||||
for($x = 0; $x < count($chemo_drugs); $x++) {
|
||||
$drug_doses = [];
|
||||
|
||||
for($i = 0; $i < count($chemo_drugs[$x]['dose']); $i++){
|
||||
$duration_array = explode(",", $chemo_drugs[$x]['dose'][$i]['duration']);
|
||||
$duration_array_to_store = [];
|
||||
|
||||
foreach ($duration_array as $duration) {
|
||||
$duration_array_to_store[] = [
|
||||
"name" => $duration,
|
||||
"given_by" => NULL,
|
||||
"given_on" => NULL,
|
||||
"quantity_given" => 0,
|
||||
];
|
||||
}
|
||||
|
||||
$drug_doses[] = [
|
||||
"dose" => (!empty($adjusted_dose[$count]) && is_numeric($adjusted_dose[$count])) ? $adjusted_dose[$count] : $chemo_drugs[$x]['dose'][$i]['dose'],
|
||||
"weight_range" => $chemo_drugs[$x]['dose'][$i]['weight_range'],
|
||||
"duration" => $duration_array_to_store,
|
||||
"instructions" => $chemo_drugs[$x]['dose'][$i]['instructions'],
|
||||
"adjusted_dose_reason" => (!empty($adjusted_dose[$count]) && is_numeric($adjusted_dose[$count])) ? $adjusted_dose_reason[$count] : NULL
|
||||
];
|
||||
|
||||
$count++;
|
||||
}
|
||||
|
||||
$chemo_drugs_to_save[] = [
|
||||
"protocol_id" => $protocol_id,
|
||||
"drug_id" => $chemo_drugs[$x]['drug_id'],
|
||||
"drug_route" => $chemo_drugs[$x]['drug_route'],
|
||||
"drug_factor" => $chemo_drugs[$x]['drug_factor'],
|
||||
"dose" => $drug_doses
|
||||
];
|
||||
}
|
||||
|
||||
for($x = 0; $x < count($post_chemo_drugs); $x++) {
|
||||
$drug_doses = [];
|
||||
|
||||
for($i = 0; $i < count($post_chemo_drugs[$x]['dose']); $i++){
|
||||
$duration_array = explode(",", $post_chemo_drugs[$x]['dose'][$i]['duration']);
|
||||
$duration_array_to_store = [];
|
||||
|
||||
foreach ($duration_array as $duration) {
|
||||
$duration_array_to_store[] = [
|
||||
"name" => $duration,
|
||||
"given_by" => NULL,
|
||||
"given_on" => NULL,
|
||||
"quantity_given" => 0,
|
||||
];
|
||||
}
|
||||
|
||||
$drug_doses[] = [
|
||||
"dose" => (!empty($adjusted_dose[$count]) && is_numeric($adjusted_dose[$count])) ? $adjusted_dose[$count] : $post_chemo_drugs[$x]['dose'][$i]['dose'],
|
||||
"weight_range" => $post_chemo_drugs[$x]['dose'][$i]['weight_range'],
|
||||
"duration" => $duration_array_to_store,
|
||||
"instructions" => $post_chemo_drugs[$x]['dose'][$i]['instructions'],
|
||||
"adjusted_dose_reason" => (!empty($adjusted_dose[$count]) && is_numeric($adjusted_dose[$count])) ? $adjusted_dose_reason[$count] : NULL
|
||||
];
|
||||
|
||||
$count++;
|
||||
}
|
||||
|
||||
$post_chemo_drugs_to_save[] = [
|
||||
"protocol_id" => $protocol_id,
|
||||
"drug_id" => $post_chemo_drugs[$x]['drug_id'],
|
||||
"drug_route" => $post_chemo_drugs[$x]['drug_route'],
|
||||
"drug_factor" => $post_chemo_drugs[$x]['drug_factor'],
|
||||
"dose" => $drug_doses
|
||||
];
|
||||
}
|
||||
|
||||
$ordered_cancer_protocol = new OrderedCancerProtocols();
|
||||
$ordered_cancer_protocol->protocol_id = $protocol_id;
|
||||
$ordered_cancer_protocol->patient_id = $patient_id;
|
||||
$ordered_cancer_protocol->episode_id = $episode_id;
|
||||
$ordered_cancer_protocol->inpatient_id = $inpatient_id;
|
||||
$ordered_cancer_protocol->pre_chemo_drugs = json_encode($pre_chemo_drugs_to_save);
|
||||
$ordered_cancer_protocol->chemo_drugs = json_encode($chemo_drugs_to_save);
|
||||
$ordered_cancer_protocol->post_chemo_drugs = json_encode($post_chemo_drugs_to_save);
|
||||
$ordered_cancer_protocol->created_by = Auth::id();
|
||||
|
||||
try {
|
||||
$ordered_cancer_protocol->save();
|
||||
flash("Cancer protocol ordering successful")->success();
|
||||
} catch (QueryException $e) {
|
||||
flash("An error occurred when adding cancer protocols")->error();
|
||||
}
|
||||
}
|
||||
|
||||
return redirect('in_patient_sheet');
|
||||
}
|
||||
|
||||
public function cancel_protocol_order($id) {
|
||||
$protocol = OrderedCancerProtocols::find($id);
|
||||
|
||||
// check if any drugs have been dispensed
|
||||
|
||||
if ($protocol && $protocol->pre_chemo_status == 0 && $protocol->chemo_status == 0 && $protocol->post_chemo_status == 0) {
|
||||
if ($protocol->delete()){
|
||||
flash("Protocol has been deleted.")->success();
|
||||
} else {
|
||||
flash("An error occurred. Please try again later")->error();
|
||||
}
|
||||
} else {
|
||||
flash("Drugs in the protocol have already been dispensed")->error();
|
||||
}
|
||||
|
||||
return redirect('in_patient_sheet');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user