/** * Display a view of the daily patient records. * */ public function dailyLog() { $from = Input::get('start'); $to = Input::get('end'); $pendingOrAll = Input::get('pending_or_all'); $error = ''; $accredited = array(); // Check radiobutton for pending/all tests is checked and assign the 'true' value if (Input::get('tests') === '1') { $pending = 'true'; } $date = date('Y-m-d'); if (!$to) { $to = $date; } $toPlusOne = date_add(new DateTime($to), date_interval_create_from_date_string('1 day')); $records = Input::get('records'); $testCategory = Input::get('section_id'); $testType = Input::get('test_type'); $labSections = ['' => trans('messages.select-lab-section')] + TestCategory::lists('name', 'id')->all(); if ($testCategory) { $testTypes = TestCategory::find($testCategory)->testTypes->lists('name', 'id'); } else { $testTypes = array("" => ""); } if ($records == 'patients') { if ($from || $to) { if (strtotime($from) > strtotime($to) || strtotime($from) > strtotime($date) || strtotime($to) > strtotime($date)) { $error = trans('messages.check-date-range'); } else { $visits = Visit::whereBetween('created_at', array($from, $toPlusOne))->get(); } if (count($visits) == 0) { Session::flash('message', trans('messages.no-match')); } } else { $visits = Visit::where('created_at', 'LIKE', $date . '%')->orderBy('patient_id')->get(); } if (Input::has('word')) { $date = date("Ymdhi"); $fileName = "daily_visits_log_" . $date . ".doc"; $headers = array("Content-type" => "text/html", "Content-Disposition" => "attachment;Filename=" . $fileName); $content = view('reports.daily.exportPatientLog')->with('visits', $visits)->with('accredited', $accredited)->withInput(Input::all()); return Response::make($content, 200, $headers); } else { return view('reports.daily.patient')->with('visits', $visits)->with('error', $error)->with('accredited', $accredited)->withInput(Input::all()); } } else { if ($records == 'rejections') { $specimens = Specimen::where('specimen_status_id', '=', Specimen::REJECTED); /*Filter by test category*/ if ($testCategory && !$testType) { $specimens = $specimens->join('tests', 'specimens.id', '=', 'tests.specimen_id')->join('test_types', 'tests.test_type_id', '=', 'test_types.id')->where('test_types.test_category_id', '=', $testCategory); } /*Filter by test type*/ if ($testCategory && $testType) { $specimens = $specimens->join('tests', 'specimens.id', '=', 'tests.specimen_id')->where('tests.test_type_id', '=', $testType); } /*Filter by date*/ if ($from || $to) { if (strtotime($from) > strtotime($to) || strtotime($from) > strtotime($date) || strtotime($to) > strtotime($date)) { $error = trans('messages.check-date-range'); } else { $specimens = $specimens->whereBetween('time_rejected', array($from, $toPlusOne))->get(array('specimens.*')); } } else { $specimens = $specimens->where('time_rejected', 'LIKE', $date . '%')->orderBy('id')->get(array('specimens.*')); } if (Input::has('word')) { $date = date("Ymdhi"); $fileName = "daily_rejected_specimen_" . $date . ".doc"; $headers = array("Content-type" => "text/html", "Content-Disposition" => "attachment;Filename=" . $fileName); $content = view('reports.daily.exportSpecimenLog')->with('specimens', $specimens)->with('testCategory', $testCategory)->with('testType', $testType)->with('accredited', $accredited)->withInput(Input::all()); return Response::make($content, 200, $headers); } else { return view('reports.daily.specimen')->with('labSections', $labSections)->with('testTypes', $testTypes)->with('specimens', $specimens)->with('testCategory', $testCategory)->with('testType', $testType)->with('error', $error)->with('accredited', $accredited)->withInput(Input::all()); } } else { $tests = Test::whereNotIn('test_status_id', [Test::NOT_RECEIVED]); /*Filter by test category*/ if ($testCategory && !$testType) { $tests = $tests->join('test_types', 'tests.test_type_id', '=', 'test_types.id')->where('test_types.test_category_id', '=', $testCategory); } /*Filter by test type*/ if ($testType) { $tests = $tests->where('test_type_id', '=', $testType); } /*Filter by all tests*/ if ($pendingOrAll == 'pending') { $tests = $tests->whereIn('test_status_id', [Test::PENDING, Test::STARTED]); } else { if ($pendingOrAll == 'all') { $tests = $tests->whereIn('test_status_id', [Test::PENDING, Test::STARTED, Test::COMPLETED, Test::VERIFIED]); } else { $tests = $tests->whereIn('test_status_id', [Test::COMPLETED, Test::VERIFIED]); } } /*Get collection of tests*/ /*Filter by date*/ if ($from || $to) { if (strtotime($from) > strtotime($to) || strtotime($from) > strtotime($date) || strtotime($to) > strtotime($date)) { $error = trans('messages.check-date-range'); } else { $tests = $tests->whereBetween('time_created', array($from, $toPlusOne))->get(array('tests.*')); } } else { $tests = $tests->where('time_created', 'LIKE', $date . '%')->get(array('tests.*')); } if (Input::has('word')) { $date = date("Ymdhi"); $fileName = "daily_test_records_" . $date . ".doc"; $headers = array("Content-type" => "text/html", "Content-Disposition" => "attachment;Filename=" . $fileName); $content = view('reports.daily.exportTestLog')->with('tests', $tests)->with('testCategory', $testCategory)->with('testType', $testType)->with('pendingOrAll', $pendingOrAll)->with('accredited', $accredited)->withInput(Input::all()); return Response::make($content, 200, $headers); } else { return view('reports.daily.test')->with('labSections', $labSections)->with('testTypes', $testTypes)->with('tests', $tests)->with('accredited', $this->accredited($tests))->with('counts', $tests->count())->with('testCategory', $testCategory)->with('testType', $testType)->with('pendingOrAll', $pendingOrAll)->with('accredited', $accredited)->with('error', $error)->withInput(Input::all()); } } } }
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); }
public function testMultipleVisitTypes() { App\Api\Facades\Interfacer::retrieve($this->labRequestJsonSimpleTestTwoVisits[0]); App\Api\Facades\Interfacer::retrieve($this->labRequestJsonSimpleTestTwoVisits[1]); App\Api\Facades\Interfacer::retrieve($this->labRequestJsonSimpleTestTwoVisits[2]); App\Api\Facades\Interfacer::retrieve($this->labRequestJsonSimpleTestTwoVisits[3]); App\Api\Facades\Interfacer::retrieve($this->labRequestJsonSimpleTestTwoVisits[4]); $externalDump = ExternalDump::where('lab_no', '=', $this->labRequestJsonSimpleTestTwoVisits[0]->labNo)->get(); $this->assertTrue(count($externalDump) == 1); $this->assertEquals($this->labRequestJsonSimpleTestTwoVisits[0]->patientVisitNumber, $externalDump->first()->patient_visit_number); $externalDump = ExternalDump::where('lab_no', '=', $this->labRequestJsonSimpleTestTwoVisits[1]->labNo)->get(); $this->assertTrue(count($externalDump) == 1); $this->assertEquals($this->labRequestJsonSimpleTestTwoVisits[1]->patientVisitNumber, $externalDump->first()->patient_visit_number); $externalDump = ExternalDump::where('lab_no', '=', $this->labRequestJsonSimpleTestTwoVisits[2]->labNo)->get(); $this->assertTrue(count($externalDump) == 1); $this->assertEquals($this->labRequestJsonSimpleTestTwoVisits[2]->patientVisitNumber, $externalDump->first()->patient_visit_number); $externalDump = ExternalDump::where('lab_no', '=', $this->labRequestJsonSimpleTestTwoVisits[3]->labNo)->get(); $this->assertTrue(count($externalDump) == 1); $this->assertEquals($this->labRequestJsonSimpleTestTwoVisits[3]->patientVisitNumber, $externalDump->first()->patient_visit_number); $externalDump = ExternalDump::where('lab_no', '=', $this->labRequestJsonSimpleTestTwoVisits[4]->labNo)->get(); $this->assertTrue(count($externalDump) == 1); $this->assertEquals($this->labRequestJsonSimpleTestTwoVisits[4]->patientVisitNumber, $externalDump->first()->patient_visit_number); // Is there a Visit for this new patient? $visit = Visit::where('visit_number', '=', $this->labRequestJsonSimpleTestTwoVisits[0]->patientVisitNumber)->get(); //var_dump($visit); //Two records inserted for same external visit $this->assertEquals(2, count($visit)); //First is IP $this->assertEquals('Out-patient', $visit->first()->visit_type); //Second is OP $this->assertEquals('In-patient', $visit[1]->visit_type); //Two distinct internal visit id's $this->assertTrue($visit->first()->id != $visit[1]->id); //Check visit number is the same $this->assertEquals($visit->first()->visit_number, $visit[1]->visit_number); }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $date) { $date = Carbon::createFromFormat('U', $date)->format('Y-m-d'); $visit = Visit::where('date', '=', $date)->with('place')->first(); $input = $request->all(); $visit->fill($input)->save(); return redirect('/'); }
/** * 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); }