mirror of
https://gitlab.com/signalytic/client-external/streamline/streamline-emr.git
synced 2026-09-11 18:51:31 +00:00
507 lines
20 KiB
PHP
Executable File
507 lines
20 KiB
PHP
Executable File
<?php
|
|
|
|
namespace Modules\Investigations\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Streamline\Models\Investigation;
|
|
use Streamline\Models\OrderedInvestigation;
|
|
use Streamline\Models\InvestigationResults;
|
|
use Streamline\Models\HospitalInformation;
|
|
use Barryvdh\Snappy\Facades\SnappyPdf;
|
|
use Barryvdh\DomPDF\Facade\Pdf as DomPDF;
|
|
use Streamline\Models\Patient;
|
|
use Streamline\Models\ObstetricUltrasoundReports;
|
|
|
|
class InvestigationPrintController extends Controller {
|
|
|
|
public function __construct() {
|
|
$this->middleware('auth');
|
|
}
|
|
|
|
public function print_lab_result_details($id) {
|
|
$ordered_investigation = OrderedInvestigation::find($id);
|
|
$hospital_information = HospitalInformation::find(1);
|
|
$investigation_ids = [];
|
|
|
|
|
|
$patient = Patient::find($ordered_investigation->patient_id);
|
|
|
|
|
|
$results = [];
|
|
|
|
$investigation_results = InvestigationResults::where('order_id', '=', $id)->get();
|
|
|
|
foreach ($investigation_results as $result) {
|
|
$investigations = explode(",", $result->investigation_id);
|
|
$values = explode(",", $result->value);
|
|
$comments = explode(",", $result->comment);
|
|
$per_investigation = explode(",", $result->per_investigation);
|
|
$count_two = 0;
|
|
|
|
foreach ($investigations as $investigation) {
|
|
$investigation_ids[] = $investigation;
|
|
$results[$count_two]['name'] = get_name($investigation, 'id', 'name', 'investigations');
|
|
|
|
if(get_name($investigation, 'id', 'range_type', 'investigations') == 1) {
|
|
$results[$count_two]['range'] = get_dynamic_normal_range($investigation, get_patient_age_group($patient->id), get_name($patient->id, 'id', 'gender', 'patients'));
|
|
} else {
|
|
$results[$count_two]['range'] = get_name($investigation, 'id', 'normal_ranges', 'investigations');
|
|
}
|
|
|
|
//$results[$count_two]['range'] = get_name($investigation, 'id', 'normal_ranges', 'investigations');
|
|
$results[$count_two]['type'] = get_name($investigation, 'id', 'type', 'investigations');
|
|
$results[$count_two]['units'] = get_name($investigation, 'id', 'units', 'investigations');
|
|
$results[$count_two]['result'] = isset($values[$count_two]) ? $values[$count_two] : "";
|
|
$results[$count_two]['comment'] = isset($comments[$count_two]) ? $comments[$count_two] : "";
|
|
$results[$count_two]['authenticated'] = isset($per_investigation[$count_two]) ? $per_investigation[$count_two] : "";
|
|
$count_two++;
|
|
}
|
|
}
|
|
|
|
$data = [
|
|
'ordered_investigation' => $ordered_investigation,
|
|
'results' => $results,
|
|
'hospitalInfo' => $hospital_information,
|
|
'id' => $id,
|
|
'patient' => $patient,
|
|
'investigation_ids' => $investigation_ids,
|
|
];
|
|
|
|
$print_footer = (!is_null($hospital_information->print_footer)) ? '     <i>' . $hospital_information->print_footer . '</i>' : '';
|
|
|
|
$pdf = SnappyPDF::loadView("investigations::investigations/print/print-lab-result-details", $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('Investigation Details' . date(" d-m-y h:ia") . '.pdf');
|
|
}
|
|
|
|
public function print_historical_results_labs(Request $request) {
|
|
$patient_id = $request->patient_id;
|
|
|
|
$hospital_information = HospitalInformation::first();
|
|
|
|
//prepare the arrays
|
|
$dates = array();
|
|
$invs_array = array();
|
|
$values = array();
|
|
|
|
$patients = InvestigationResults::where('patient_id', '=', $patient_id)
|
|
->where('result_type', '=', 'Lab')
|
|
->where('all_authenticated', '=', 1)
|
|
->limit(7)
|
|
->get();
|
|
|
|
foreach ($patients as $patient) {
|
|
$dates[] = streamline_date($patient->created_at);
|
|
|
|
$investigations = explode(",", $patient->investigation_id);
|
|
|
|
foreach ($investigations as $investigation) {
|
|
|
|
if (!in_array($investigation, $invs_array)) {
|
|
$invs_array[] = $investigation;
|
|
}
|
|
}
|
|
}
|
|
|
|
//loop through the investigation ids to add values
|
|
for ($i = 0; $i < count($invs_array); $i++) {
|
|
|
|
//count for the returnInvestigations
|
|
$count = 0;
|
|
|
|
foreach ($patients as $patient) {
|
|
//get values from csv to array
|
|
$investigations = explode(",", $patient->investigation_id);
|
|
|
|
$return_values = explode(",", $patient->value);
|
|
|
|
$comments = explode(",", $patient->comment);
|
|
|
|
//check if current investigation is in array
|
|
if (in_array($invs_array[$i], $investigations)) {
|
|
|
|
//get key of that investigation which exists
|
|
$key = array_search($invs_array[$i], $investigations);
|
|
|
|
if ($patient->result_type == 'Ultrasound_Obstetric') {
|
|
//assign real$return_values value
|
|
$values[$i][$count] = array($return_values[$key], $patient->order_id, $patient_id, $patient->episode_id);
|
|
} elseif (get_name($invs_array[$i], 'id', 'type', 'investigations') == 1) {
|
|
// assign real value representing id
|
|
$values[$i][$count] = $return_values[$key] ?? "";
|
|
} else {
|
|
//assign real value
|
|
$values[$i][$count] = ($return_values[$key] ?? "") . " - (" . ($comments[$key] ?? "") . ")";
|
|
}
|
|
} else {
|
|
//assign N/A
|
|
$values[$i][$count] = "N/A";
|
|
}
|
|
|
|
$count++;
|
|
}
|
|
}
|
|
|
|
$patient = Patient::find($patient_id);
|
|
|
|
$data = [
|
|
'patient_id' => $patient_id,
|
|
'patient' => $patient,
|
|
'dates' => $dates,
|
|
'invs_array' => $invs_array,
|
|
'values' => $values,
|
|
'hospitalInfo' => $hospital_information
|
|
];
|
|
|
|
|
|
$pdf = SnappyPDF::loadView("investigations::investigations/print/print-historical-results-labs", $data)
|
|
->setOrientation('portrait')
|
|
->setPaper('a4')
|
|
->setOption('margin-bottom', 5)
|
|
->setOption('margin-top', 5)
|
|
->setOption('footer-html', '<i>© ' . date('Y') . ' Stre@mline</i>');
|
|
|
|
|
|
return $pdf->inline($patient->first_name . ' ' . $patient->last_name . 'Historical Results' . date(" d-m-y h:ia") . '.pdf');
|
|
}
|
|
|
|
public function print_historical_results_imaging(Request $request) {
|
|
$patient_id = $request->patient_id;
|
|
|
|
$hospital_information = HospitalInformation::first();
|
|
|
|
//prepare the arrays
|
|
$dates = array();
|
|
$invs_array = array();
|
|
$values = array();
|
|
|
|
$patients = InvestigationResults::where('patient_id', '=', $patient_id)
|
|
->whereIn('investigation_results.result_type', ['Imaging', 'Ultrasound', 'Ultrasound_Obstetric'])
|
|
->where('all_authenticated', '=', 1)
|
|
->limit(7)
|
|
->get();
|
|
|
|
foreach ($patients as $patient) {
|
|
$dates[] = streamline_date($patient->created_at);
|
|
|
|
$investigations = explode(",", $patient->investigation_id);
|
|
|
|
foreach ($investigations as $investigation) {
|
|
|
|
if (!in_array($investigation, $invs_array)) {
|
|
$invs_array[] = $investigation;
|
|
}
|
|
}
|
|
}
|
|
|
|
//loop through the investigation ids to add values
|
|
for ($i = 0; $i < count($invs_array); $i++) {
|
|
|
|
//count for the returnInvestigations
|
|
$count = 0;
|
|
|
|
foreach ($patients as $patient) {
|
|
//get values from csv to array
|
|
$investigations = explode(",", $patient->investigation_id);
|
|
|
|
$return_values = explode(",", $patient->value);
|
|
|
|
$comments = explode(",", $patient->comment);
|
|
|
|
//check if current investigation is in array
|
|
if (in_array($invs_array[$i], $investigations)) {
|
|
|
|
//get key of that investigation which exists
|
|
$key = array_search($invs_array[$i], $investigations);
|
|
|
|
if ($patient->result_type == 'Ultrasound_Obstetric') {
|
|
//assign real$return_values value
|
|
$values[$i][$count] = array($return_values[$key], $patient->order_id, $patient_id, $patient->episode_id);
|
|
} elseif (get_name($invs_array[$i], 'id', 'type', 'investigations') == 1) {
|
|
// assign real value representing id
|
|
$values[$i][$count] = $return_values[$key] ?? "";
|
|
} else {
|
|
//assign real value
|
|
$values[$i][$count] = ($return_values[$key] ?? "") . " - (" . ($comments[$key] ?? "") . ")";
|
|
}
|
|
} else {
|
|
//assign N/A
|
|
$values[$i][$count] = "N/A";
|
|
}
|
|
|
|
$count++;
|
|
}
|
|
}
|
|
|
|
$patient = Patient::find($patient_id);
|
|
|
|
$data = [
|
|
'patient_id' => $patient_id,
|
|
'patient' => $patient,
|
|
'dates' => $dates,
|
|
'invs_array' => $invs_array,
|
|
'values' => $values,
|
|
'hospitalInfo' => $hospital_information
|
|
];
|
|
|
|
|
|
$pdf = SnappyPDF::loadView("investigations::investigations/print/print-historical-results-labs", $data)
|
|
->setOrientation('portrait')
|
|
->setPaper('a4')
|
|
->setOption('margin-bottom', 5)
|
|
->setOption('margin-top', 5)
|
|
->setOption('footer-html', '<i>© ' . date('Y') . ' Stre@mline</i>');
|
|
|
|
|
|
return $pdf->inline($patient->first_name . ' ' . $patient->last_name . 'Historical Results' . date(" d-m-y h:ia") . '.pdf');
|
|
}
|
|
|
|
public function print_patient_investigation_results($result_id) {
|
|
$result = InvestigationResults::find($result_id);
|
|
|
|
$patient_id = $result->patient_id;
|
|
|
|
$hospital_information = HospitalInformation::first();
|
|
$patient = Patient::where(['id' => $patient_id])->first();
|
|
|
|
$inv = [];
|
|
|
|
$inv['episode_id'] = $result->episode_id;
|
|
$inv['date'] = streamline_date(get_name($result->episode_id, 'id', 'created_at', 'patient_episodes'));
|
|
$created_by = is_null($result->updated_by) ? $result->created_by : $result->updated_by;
|
|
|
|
$investigations = explode(",", $result->investigation_id);
|
|
$values = explode(",", $result->value);
|
|
$comments = explode(",", $result->comment);
|
|
|
|
$data = [];
|
|
$count = 0;
|
|
|
|
foreach ($investigations as $investigation) {
|
|
$investigation_details = Investigation::find($investigation);
|
|
|
|
if ($investigation_details) {
|
|
$data[$count]['name'] = $investigation_details->name;
|
|
$data[$count]['range'] = $investigation_details->normal_ranges;
|
|
$data[$count]['slug'] = $investigation_details->slug;
|
|
$data[$count]['result'] = $values[$count];
|
|
$data[$count]['comment'] = $comments[$count];
|
|
$data[$count]['type'] = $investigation_details->type;
|
|
$count++;
|
|
}
|
|
}
|
|
|
|
$inv['data'] = $data;
|
|
|
|
$data = [
|
|
'inv' => $inv,
|
|
'patient' => $patient,
|
|
'hospitalInfo' => $hospital_information,
|
|
'created_at' => $result->created_at,
|
|
'created_by' => $created_by,
|
|
'performed_at' => streamline_date_time($result->created_at),
|
|
'requested_at' => streamline_date_time(get_name($result->order_id, 'id', 'created_at', 'ordered_investigations'))
|
|
];
|
|
|
|
$pdf = SnappyPDF::loadView("investigations::investigations/print/print_patient_investigation_results", $data)
|
|
->setOrientation('portrait')
|
|
->setPaper('a4')
|
|
->setOption('margin-bottom', 5)
|
|
->setOption('margin-top', 5)
|
|
->setOption('footer-html', '<i>© ' . date('Y') . ' Stre@mline</i>');
|
|
|
|
return $pdf->inline($patient->first_name . ' ' . $patient->last_name . ' Investigation results' . date(" d-m-y h:ia") . '.pdf');
|
|
}
|
|
|
|
public function print_ultrasound_results_obstetric($obstetric_result_id) {
|
|
$report = ObstetricUltrasoundReports::where(['id' => $obstetric_result_id])->first();
|
|
|
|
// for old kisiizi records which use the order_id
|
|
if (!$report) {
|
|
$report = ObstetricUltrasoundReports::where(['order_id' => $obstetric_result_id])->first();
|
|
}
|
|
|
|
$invs_order = OrderedInvestigation::find($report->order_id);
|
|
|
|
if ($invs_order) {
|
|
$patient_id = $invs_order->patient_id;
|
|
$episode_id = $invs_order->episode_id;
|
|
|
|
$patient = Patient::find($patient_id);
|
|
|
|
$anc_details = DB::table('ante_natal_clinic_registrations')->where('episode_id', $episode_id)->first();
|
|
|
|
$data = [
|
|
'patient_id' => $patient_id,
|
|
'episode_id' => $episode_id,
|
|
'patient' => $patient,
|
|
'report' => $report,
|
|
'anc_details' => $anc_details,
|
|
'invs_order' => $invs_order
|
|
];
|
|
|
|
|
|
//dompdf
|
|
$pdf_obstetric = new DomPDF();
|
|
$html = view("investigations::investigations/print/print_ultrasound_results_obstetric", $data)->render();
|
|
$pdf_obstetric = DomPDF::loadHtml($html);
|
|
$pdf_obstetric->setPaper('A4', 'potrait');
|
|
$options = [
|
|
'isPhpEnabled' => true,
|
|
'isHtml5ParserEnabled' => true,
|
|
// Add more options
|
|
];
|
|
DomPDF::setOptions($options);
|
|
return $pdf_obstetric->stream($patient->first_name . ' ' . $patient->last_name . ' ' . 'Ultrasound Obstetric results' . date(" d-m-y h:ia") . '.pdf', array('Attachment' => false));
|
|
} else {
|
|
flash("Unable to find obstetric results")->error();
|
|
return redirect('/home');
|
|
}
|
|
}
|
|
|
|
public function print_selective_lab_result_details(Request $request) {
|
|
$invs_to_print = $request->invs_to_print;
|
|
|
|
if (is_null($invs_to_print)) {
|
|
flash("Please select investigations to print")->error();
|
|
return redirect('/home');
|
|
}
|
|
|
|
$id = $request->id;
|
|
$investigation_ids = [];
|
|
$ordered_investigation = OrderedInvestigation::find($id);
|
|
$hospital_information = HospitalInformation::find(1);
|
|
|
|
|
|
$patient = Patient::find($ordered_investigation->patient_id);
|
|
|
|
|
|
$results = [];
|
|
|
|
$investigation_results = InvestigationResults::where('order_id', '=', $id)->get();
|
|
|
|
foreach ($investigation_results as $result) {
|
|
$investigations = explode(",", $result->investigation_id);
|
|
$values = explode(",", $result->value);
|
|
$comments = explode(",", $result->comment);
|
|
$per_investigation = explode(",", $result->per_investigation);
|
|
$count_two = 0;
|
|
|
|
foreach ($investigations as $investigation) {
|
|
if (in_array($investigation, $invs_to_print)) {
|
|
$investigation_ids[] = $investigation;
|
|
|
|
$results[$count_two]['name'] = get_name($investigation, 'id', 'name', 'investigations');
|
|
|
|
if(get_name($investigation, 'id', 'range_type', 'investigations') == 1) {
|
|
$results[$count_two]['range'] = get_dynamic_normal_range($investigation, get_patient_age_group($patient->id), get_name($patient->id, 'id', 'gender', 'patients'));
|
|
} else {
|
|
$results[$count_two]['range'] = get_name($investigation, 'id', 'normal_ranges', 'investigations');
|
|
}
|
|
|
|
$results[$count_two]['type'] = get_name($investigation, 'id', 'type', 'investigations');
|
|
$results[$count_two]['units'] = get_name($investigation, 'id', 'units', 'investigations');
|
|
$results[$count_two]['result'] = $values[$count_two] ?? "";
|
|
$results[$count_two]['comment'] = $comments[$count_two] ?? "";
|
|
$results[$count_two]['authenticated'] = $per_investigation[$count_two] ?? "";
|
|
}
|
|
$count_two++;
|
|
}
|
|
}
|
|
|
|
$data = [
|
|
'ordered_investigation' => $ordered_investigation,
|
|
'results' => $results,
|
|
'hospitalInfo' => $hospital_information,
|
|
'id' => $id,
|
|
'patient' => $patient,
|
|
'investigation_ids' => count($investigation_ids) > 0 ? $investigation_ids : explode(",", $ordered_investigation->investigation_id),
|
|
];
|
|
|
|
$pdf = SnappyPDF::loadView("investigations::investigations/print/print-lab-result-details", $data)
|
|
->setOrientation('portrait')
|
|
->setPaper('a4')
|
|
->setOption('margin-bottom', 5)
|
|
->setOption('margin-top', 5)
|
|
->setOption('footer-html', '<i>© ' . date('Y') . ' Stre@mline</i>');
|
|
|
|
|
|
return $pdf->inline('Investigation Details' . date(" d-m-y h:ia") . '.pdf');
|
|
}
|
|
|
|
public function print_selective_patient_investigation_results(Request $request) {
|
|
$invs_to_print = $request->invs_to_print;
|
|
|
|
if (is_null($invs_to_print)) {
|
|
flash("Please select investigations to print")->error();
|
|
return redirect('/home');
|
|
}
|
|
|
|
$result_id = $request->result_id;
|
|
|
|
$result = InvestigationResults::find($result_id);
|
|
|
|
$patient_id = $result->patient_id;
|
|
|
|
$hospital_information = HospitalInformation::first();
|
|
$patient = Patient::where(['id' => $patient_id])->first();
|
|
|
|
$inv = [];
|
|
|
|
$inv['episode_id'] = $result->episode_id;
|
|
$inv['date'] = streamline_date(get_name($result->episode_id, 'id', 'created_at', 'patient_episodes'));
|
|
$created_by = is_null($result->updated_by) ? $result->created_by : $result->updated_by;
|
|
|
|
$investigations = explode(",", $result->investigation_id);
|
|
$values = explode(",", $result->value);
|
|
$comments = explode(",", $result->comment);
|
|
|
|
$data = [];
|
|
$count = 0;
|
|
|
|
foreach ($investigations as $investigation) {
|
|
if (in_array($investigation, $invs_to_print)) {
|
|
$investigation_details = Investigation::find($investigation);
|
|
|
|
if ($investigation_details) {
|
|
$data[$count]['name'] = $investigation_details->name;
|
|
$data[$count]['range'] = $investigation_details->normal_ranges;
|
|
$data[$count]['slug'] = $investigation_details->slug;
|
|
$data[$count]['result'] = $values[$count];
|
|
$data[$count]['comment'] = $comments[$count];
|
|
$data[$count]['type'] = $investigation_details->type;
|
|
$count++;
|
|
}
|
|
}
|
|
}
|
|
|
|
$inv['data'] = $data;
|
|
|
|
$data = [
|
|
'inv' => $inv,
|
|
'patient' => $patient,
|
|
'hospitalInfo' => $hospital_information,
|
|
'created_by' => $created_by,
|
|
'performed_at' => streamline_date_time($result->created_at),
|
|
'requested_at' => streamline_date_time(get_name($result->order_id, 'id', 'created_at', 'ordered_investigations'))
|
|
];
|
|
|
|
$pdf = SnappyPDF::loadView("investigations::investigations/print/print_patient_investigation_results", $data)
|
|
->setOrientation('portrait')
|
|
->setPaper('a4')
|
|
->setOption('margin-bottom', 5)
|
|
->setOption('margin-top', 5)
|
|
->setOption('footer-html', '<i>© ' . date('Y') . ' Stre@mline</i>');
|
|
|
|
return $pdf->inline($patient->first_name . ' ' . $patient->last_name . ' Investigation results' . date(" d-m-y h:ia") . '.pdf');
|
|
}
|
|
|
|
}
|