/** * Display prevalence rates chart * * @return Response */ public static function getPrevalenceRatesChart($testTypeID = 0) { $from = Input::get('start'); $to = Input::get('end'); $months = json_decode(self::getMonths($from, $to)); $testTypes = new Illuminate\Database\Eloquent\Collection(); if ($testTypeID == 0) { $testTypes = TestType::supportPrevalenceCounts(); } else { $testTypes->add(TestType::find($testTypeID)); } $options = '{ "chart": { "type": "spline" }, "title": { "text":"' . trans('messages.prevalence-rates') . '" }, "subtitle": { "text":'; if ($from == $to) { $options .= '"' . trans('messages.for-the-year') . ' ' . date('Y') . '"'; } else { $options .= '"' . trans('messages.from') . ' ' . $from . ' ' . trans('messages.to') . ' ' . $to . '"'; } $options .= '}, "credits": { "enabled": false }, "navigation": { "buttonOptions": { "align": "right" } }, "series": ['; $counts = count($testTypes); foreach ($testTypes as $testType) { $options .= '{ "name": "' . $testType->name . '","data": ['; $counter = count($months); foreach ($months as $month) { $data = $testType->getPrevalenceCount($month->annum, $month->months); if ($data->isEmpty()) { $options .= '0.00'; if ($counter == 1) { $options .= ''; } else { $options .= ','; } } else { foreach ($data as $datum) { $options .= $datum->rate; if ($counter == 1) { $options .= ''; } else { $options .= ','; } } } $counter--; } $options .= ']'; if ($counts == 1) { $options .= '}'; } else { $options .= '},'; } $counts--; } $options .= '], "xAxis": { "categories": ['; $count = count($months); foreach ($months as $month) { $options .= '"' . $month->label . " " . $month->annum; if ($count == 1) { $options .= '" '; } else { $options .= '" ,'; } $count--; } $options .= '] }, "yAxis": { "title": { "text": "' . trans('messages.prevalence-rates-label') . '" }, "min": "0", "max": "100" } }'; return $options; }
$subtitle = trans("messages.for") . ' ' . date('Y'); } if ($interval == 'M') { $subtitle .= ' (' . trans("messages.monthly") . ') '; } else { if ($interval == 'D') { $subtitle .= ' (' . trans("messages.daily") . ') '; } else { $subtitle .= ' (' . trans("messages.weekly") . ') '; } } if ($testCategory) { $subtitle .= ' - ' . TestCategory::find($testCategory)->name; } if ($testType) { $subtitle .= '(' . TestType::find($testType)->name . ')'; } echo '"' . $subtitle . '"'; ?> }, credits: { enabled: 'false' }, xAxis: { type: 'datetime', dateTimeLabelFormats: { month: '%e. %b', year: '%b' }, }, yAxis: {
/** * Function for processing the requests we receive from the external system * and putting the data into our system. * * @var array lab_requests */ public function process($labRequest) { //First: Check if patient exists, if true dont save again $patient = Patient::where('external_patient_number', '=', $labRequest->patient->id)->get(); if (!$patient->first()) { $patient = new Patient(); $patient->external_patient_number = $labRequest->patient->id; $patient->patient_number = $labRequest->patient->id; $patient->name = $labRequest->patient->fullName; $gender = array('Male' => Patient::MALE, 'Female' => Patient::FEMALE); $patient->gender = $gender[$labRequest->patient->gender]; $patient->dob = $labRequest->patient->dateOfBirth; $patient->address = $labRequest->address->address; $patient->phone_number = $labRequest->address->phoneNumber; $patient->created_by = User::EXTERNAL_SYSTEM_USER; $patient->save(); } else { $patient = $patient->first(); } //We check if the test exists in our system if not we just save the request in stagingTable if ($labRequest->parentLabNo == '0') { $testTypeId = TestType::getTestTypeIdByTestName($labRequest->investigation); } else { $testTypeId = null; } if (is_null($testTypeId) && $labRequest->parentLabNo == '0') { $this->saveToExternalDump($labRequest, ExternalDump::TEST_NOT_FOUND); return; } //Check if visit exists, if true dont save again $visitType = array('ip' => 'In-patient', 'op' => 'Out-patient'); //Should be a constant $visit = Visit::where('visit_number', '=', $labRequest->patientVisitNumber)->where('visit_type', '=', $visitType[$labRequest->orderStage])->get(); if (!$visit->first()) { $visit = new Visit(); $visit->patient_id = $patient->id; $visit->visit_type = $visitType[$labRequest->orderStage]; $visit->visit_number = $labRequest->patientVisitNumber; // We'll save Visit in a transaction a little bit below } else { $visit = $visit->first(); if (strcmp($visitType[$labRequest->orderStage], $visit->visit_type) != 0) { $visit = new Visit(); $visit->patient_id = $patient->id; $visit->visit_type = $visitType[$labRequest->orderStage]; $visit->visit_number = $labRequest->patientVisitNumber; } } $test = null; //Check if parentLabNO is 0 thus its the main test and not a measure if ($labRequest->parentLabNo == '0') { //Check via the labno, if this is a duplicate request and we already saved the test $test = Test::where('external_id', '=', $labRequest->labNo)->get(); if (!$test->first()) { //Specimen $specimen = new Specimen(); $specimen->specimen_type_id = TestType::find($testTypeId)->specimenTypes->lists('id')[0]; // We'll save the Specimen in a transaction a little bit below $test = new Test(); $test->test_type_id = $testTypeId; $test->test_status_id = Test::NOT_RECEIVED; $test->created_by = User::EXTERNAL_SYSTEM_USER; //Created by external system 0 $test->requested_by = $labRequest->requestingClinician; $test->external_id = $labRequest->labNo; DB::transaction(function () use($visit, $specimen, $test) { $visit->save(); $specimen->save(); $test->visit_id = $visit->id; $test->specimen_id = $specimen->id; $test->save(); }); $this->saveToExternalDump($labRequest, $test->id); return; } } $this->saveToExternalDump($labRequest, null); }
/** * Pull test results from an instrument as JSON. * * @return Response */ public function getTestResult() { //Get Instrument Interface Class file $testTypeID = Input::get("test_type_id"); $testType = TestType::find($testTypeID); $instrument = $testType->instruments->first(); // Fetch the results return $instrument->fetchResult($testType); }
public function testCountPerStatus() { Input::replace($this->testTypeData); $testType = new TestTypeController(); $testType->store(); $testTypestored = TestType::orderBy('id', 'desc')->take(1)->get()->toArray(); $testTypeSaved = TestType::find($testTypestored[0]['id']); $count = $testTypeSaved->countPerStatus([Test::NOT_RECEIVED, Test::STARTED, Test::PENDING, Test::COMPLETED, Test::VERIFIED]); $this->assertEquals($testTypeSaved->tests->count(), $count); }
/** * Display data after applying the filters on the report uses patient ID * * @return Response */ public function cd4() { // check if accredited $accredited = array(); $from = Input::get('start'); $to = Input::get('end'); $pending = Input::get('pending'); $date = date('Y-m-d'); $error = ''; // Check dates if (!$from) { $from = date('Y-m-01'); } if (!$to) { $to = $date; } // Get columns $columns = array(Lang::choice('messages.cd4-less', 1), Lang::choice('messages.cd4-greater', 1)); $rows = array(Lang::choice('messages.baseline', 1), Lang::choice('messages.follow-up', 1)); // Get test $test = TestType::find(TestType::getTestTypeIdByTestName('cd4')); $counts = array(); foreach ($columns as $column) { foreach ($rows as $row) { if ($test != null) { $counts[$column][$row] = $test->cd4($from, $to, $column, $row); } else { $counts[$column][$row] = 0; } } } if (Input::has('word')) { $date = date("Ymdhi"); $fileName = "cd4_report_" . $date . ".doc"; $headers = array("Content-type" => "text/html", "Content-Disposition" => "attachment;Filename=" . $fileName); $content = View::make('reports.cd4.export')->with('columns', $columns)->with('rows', $rows)->with('accredited', $accredited)->with('test', $test)->with('counts', $counts)->withInput(Input::all()); return Response::make($content, 200, $headers); } else { if (Input::has('excel')) { $date = date("Ymdhi"); $fileName = "cd4_report_" . $date . ".xls"; $headers = array("Content-type" => "text/html", "Content-Disposition" => "attachment;Filename=" . $fileName); $content = View::make('reports.cd4.export')->with('columns', $columns)->with('rows', $rows)->with('accredited', $accredited)->with('test', $test)->with('counts', $counts)->withInput(Input::all()); return Response::make($content, 200, $headers); } else { return View::make('reports.cd4.index')->with('columns', $columns)->with('rows', $rows)->with('accredited', $accredited)->with('test', $test)->with('counts', $counts)->withInput(Input::all()); } } }
/** * Save a new Test. * * @return Response */ public function saveNewTest() { //Create New Test $rules = array('visit_type' => 'required', 'physician' => 'required', 'testtypes' => 'required'); $validator = Validator::make(Input::all(), $rules); // process the login if ($validator->fails()) { return Redirect::route('test.create', array(Input::get('patient_id')))->withInput()->withErrors($validator); } else { $visitType = ['Out-patient', 'In-patient']; $activeTest = array(); /* * - Create a visit * - Fields required: visit_type, patient_id */ $visit = new Visit(); $visit->patient_id = Input::get('patient_id'); $visit->visit_type = $visitType[Input::get('visit_type')]; $visit->save(); /* * - Create tests requested * - Fields required: visit_id, test_type_id, specimen_id, test_status_id, created_by, requested_by */ $testTypes = Input::get('testtypes'); if (is_array($testTypes)) { foreach ($testTypes as $value) { $testTypeID = (int) $value; // Create Specimen - specimen_type_id, accepted_by, referred_from, referred_to $specimen = new Specimen(); $specimen->specimen_type_id = TestType::find($testTypeID)->specimenTypes->lists('id')[0]; $specimen->accepted_by = Auth::user()->id; $specimen->save(); $test = new Test(); $test->visit_id = $visit->id; $test->test_type_id = $testTypeID; $test->specimen_id = $specimen->id; $test->test_status_id = Test::PENDING; $test->created_by = Auth::user()->id; $test->requested_by = Input::get('physician'); $test->save(); $activeTest[] = $test->id; } } $url = Session::get('SOURCE_URL'); return Redirect::to($url)->with('message', 'messages.success-creating-test')->with('activeTest', $activeTest); } }
/** * Remove the specified resource from storage (soft delete). * * @param int $id * @return Response */ public function delete($id) { //Soft delete the testtype $testtype = TestType::find($id); $inUseByTests = $testtype->tests->toArray(); if (empty($inUseByTests)) { // The test type is not in use $testtype->delete(); } else { // The test type is in use return Redirect::route('testtype.index')->with('message', 'messages.failure-test-type-in-use'); } // redirect return Redirect::route('testtype.index')->with('message', trans('messages.success-deleting-test-type')); }
/** * @param Test Type IDs $testTypeIds array() * @return Measure IDs $measureIds array() */ public static function getMeasureIdsByTestTypeIds($testTypeIds) { $measureIds = array(); foreach ($testTypeIds as $testTypeId) { $testType = TestType::find($testTypeId); $measureIds = array_merge($measureIds, $testType->measures->lists('id')); } return $measureIds; }
public function process($labRequest) { //First: Check if patient exists, if true dont save again $patient = Patient::where('external_patient_number', '=', $labRequest->PatientNumber)->get(); if (!$patient->first()) { $patient = new Patient(); $patient->external_patient_number = $labRequest->PatientNumber; $patient->patient_number = $labRequest->PatientNumber; $patient->name = $labRequest->FullNames; $gender = array('M' => Patient::MALE, 'F' => Patient::FEMALE, 'U' => Patient::UNKNOWN); $patient->gender = $gender[$labRequest->Sex]; $patient->dob = $this->getDobFromAge($labRequest->Age); $patient->address = $labRequest->PoBox; $patient->phone_number = $labRequest->PatientsContact; $patient->created_by = User::EXTERNAL_SYSTEM_USER; } else { $patient = $patient->first(); } //We check if the test exists in our system if not we just save the request in stagingTable $testTypeId = TestType::getTestTypeIdByTestName($labRequest->investigation); if (is_null($testTypeId) && $labRequest->parentLabNo == '0') { $this->saveToExternalDump($labRequest, ExternalDump::TEST_NOT_FOUND); return; } //Check if visit exists, if true dont save again $visit = Visit::where('visit_number', '=', $labRequest->RevisitNumber)->get(); if (!$visit->first()) { $visit = new Visit(); $visit->visit_type = 'Out-patient'; // We'll save Visit in a transaction a little bit below } else { $visit = $visit->first(); } $test = null; //Check via the labno, if this is a duplicate request and we already saved the test $test = Test::where('external_id', '=', $labRequest->RequestID)->get(); if (!$test->first()) { //Specimen $specimen = new Specimen(); $specimen->specimen_type_id = TestType::find($testTypeId)->specimenTypes->lists('id')[0]; // We'll save the Specimen in a transaction a little bit below $test = new Test(); $test->test_type_id = $testTypeId; $test->test_status_id = Test::NOT_RECEIVED; $test->created_by = User::EXTERNAL_SYSTEM_USER; //Created by external system 0 $test->requested_by = $labRequest->DoctorRequesting; $test->external_id = $labRequest->RequestID; DB::transaction(function () use($visit, $specimen, $test, $patient) { $patient->save(); $visit->patient_id = $patient->id; $visit->visit_number = Visit::orderBy('id', 'desc')->first()->id + 1; //$labRequest->RevisitNumber; $visit->save(); $specimen->save(); $test->visit_id = $visit->id; $test->specimen_id = $specimen->id; $test->save(); }); $this->saveToExternalDump($labRequest, $test->id); return; } $this->saveToExternalDump($labRequest, null); mssql_close($connection); }