/** * Display the specified patient. * * @param int $id * @return Response */ public function show($id) { $patient = Patient::findOrFail($id); $tests = Test::select('tests.id', 'test', 'result', 'diagnosis', 'tests.created_at', 'item')->where('patient_id', '=', $id)->join('billings', 'billings.id', '=', 'tests.test')->get(); $medications = Medication::select('medications.id', 'prescription', 'dosage', 'start_date', 'end_date', 'item')->where('patient_id', '=', $id)->join('billings', 'billings.id', '=', 'medications.prescription')->get(); $visit = Visit::where('patient_id', '=', $id)->first(); return View::make('patients.show', compact('patient', 'tests', 'medications', 'visit')); }
/** * Store a newly created resource in storage. * POST /registrations * * @return Response */ public function store(Patient $patient) { $visits = Visit::where('patient_id', '=', $patient->id)->get(); if (isset($visits) && $visits->count()) { foreach ($visits as $visit) { if ($visit->done == 1) { $visit = ['patient_id' => $patient->id, 'done' => 0]; Visit::create($visit); return Redirect::route('patient-chart-get', $patient->id)->with('global', "New Visit Started"); } elseif ($visit->done == 0) { return Redirect::route('patient-chart-get', $patient->id)->with('global', "Visit in progress"); } } } $visit = ['patient_id' => $patient->id, 'done' => 0]; Visit::create($visit); return Redirect::route('patient-chart-get', $patient->id)->with('global', "New Visit Started"); }
/** * 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 = ''; // 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 = TestCategory::lists('name', 'id'); 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::make('reports.daily.exportPatientLog')->with('visits', $visits)->withInput(Input::all()); return Response::make($content, 200, $headers); } else { return View::make('reports.daily.patient')->with('visits', $visits)->with('error', $error)->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::make('reports.daily.exportSpecimenLog')->with('specimens', $specimens)->with('testCategory', $testCategory)->with('testType', $testType)->withInput(Input::all()); return Response::make($content, 200, $headers); } else { return View::make('reports.daily.specimen')->with('labSections', $labSections)->with('testTypes', $testTypes)->with('specimens', $specimens)->with('testCategory', $testCategory)->with('testType', $testType)->with('error', $error)->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::make('reports.daily.exportTestLog')->with('tests', $tests)->with('testCategory', $testCategory)->with('testType', $testType)->with('pendingOrAll', $pendingOrAll)->withInput(Input::all()); return Response::make($content, 200, $headers); } else { return View::make('reports.daily.test')->with('labSections', $labSections)->with('testTypes', $testTypes)->with('tests', $tests)->with('counts', $tests->count())->with('testCategory', $testCategory)->with('testType', $testType)->with('pendingOrAll', $pendingOrAll)->with('error', $error)->withInput(Input::all()); } } } }
/** * Visit helper function * * @return array */ public function getVisit($id) { return Visit::where('patient_id', '=', $id)->where('done', '=', 0)->first(); }
/** * 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); }
public function getVisit($BranchId) { return View::make('branch.visit')->with('branch', Branch::find($BranchId))->with('visit', Visit::where('branch_id', '=', $BranchId)->orderBy('visit_at', 'desc')->paginate())->with('count', Visit::where('branch_id', '=', $BranchId)->count()); }
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() { Interfacer::retrieve($this->labRequestJsonSimpleTestTwoVisits[0]); Interfacer::retrieve($this->labRequestJsonSimpleTestTwoVisits[1]); Interfacer::retrieve($this->labRequestJsonSimpleTestTwoVisits[2]); Interfacer::retrieve($this->labRequestJsonSimpleTestTwoVisits[3]); 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); }
public function server_sysnc() { /** * online server connection(mysql) */ // $conn=mysqli_connect("162.243.26.128","root","softmed","cancer") ; //// Check connection // if (mysqli_connect_errno()) { // echo "Failed to connect to MySQL: " . mysqli_connect_error(); // }else{ // echo "connection successfull"; // } // echo count(ServerPatient::all())."<br>";exit; //querying all visit that have not been sent to server if (count(Visit::where('server_status', "not")->get()) == 0) { echo "<h4 class=text-danger>All Visits has been transferred</h4>"; } else { $vis = Visit::where('server_status', "not")->first(); echo "Moving Visit for " . $vis->patient->first_name . " " . $vis->patient->last_name . "........"; if ($vis->patient) { try { $pat = $vis->patient; //check if patient is on server or not, if not synchronize if ($pat->server_status == "not") { $patient = ServerPatient::create(array("first_name" => $pat->first_name, "middle_name" => $pat->middle_name, "last_name" => $pat->last_name, "birth_date" => $pat->birth_date, "hospital_id" => $pat->hospital_id, "phone" => $pat->phone, "facility_id" => $pat->facility_id, "uid" => $pat->uid)); $patient->created_at = $pat->created_at; $patient->updated_at = $pat->updated_at; $patient->save(); $pat->server_status = 'transferred'; $pat->save(); $report = ServerPatientReport::create(array("patient_id" => $patient->id, "bitrh_date" => $pat->birth_date, "region" => $vis->info->region, "district" => $vis->info->district, "parity" => $vis->gynecology->parity, "number_of_pregnancy" => $vis->gynecology->number_of_pregnancy, "menarche" => $vis->gynecology->menarche, "age_at_sexual_debut" => $vis->gynecology->age_at_sexual_debut, "marital_status" => $vis->gynecology->marital_status, "first_marriage" => $vis->gynecology->age_at_first_marriage, "partners" => $vis->gynecology->sexual_partner, "partners_partner" => $vis->gynecology->partner_sexual_partner, "contraceptive_status" => $vis->contraceptive->current_status, "contraceptive_type" => $vis->contraceptive->current_contraceptive_id, "HIV_status" => $vis->hiv->status, "facility_id" => $pat->facility_id)); $report->cd4_count = $vis->hiv->pitc_cd4_count; $report->cd4_count = $vis->hiv->prev_cd4_count; $report->save(); } else { $patient = ServerPatient::where('uid', $pat->uid); $report = ServerPatientReport::where('patient_id', $patient->id)->first(); $report->region = $vis->info->region; $report->district = $vis->info->district; $report->number_of_pregnancy = $vis->gynecology->number_of_pregnancy; $report->marital_status = $vis->gynecology->marital_status; $report->first_marriage = $vis->gynecology->age_at_first_marriage; $report->partners = $vis->gynecology->sexual_partner; $report->partners_partner = $vis->gynecology->partner_sexual_partner; $report->contraceptive_status = $vis->contraceptive->current_status; $report->contraceptive_type = $vis->contraceptive->current_contraceptive_id; $report->HIV_status = $vis->hiv->status; $report->cd4_count = $vis->hiv->pitc_cd4_count; $report->cd4_count = $vis->hiv->prev_cd4_count; $report->save(); } $visit = ServerVisit::create(array("patient_id" => $patient->id, "visit_date" => $vis->visit_date, "server_status" => 'derlivered', "user" => $vis->user)); $visit->created_at = $vis->created_at; $visit->updated_at = $vis->updated_at; $visit->save(); //adding address information $patinfo = ServerPatientInfo::create(array("patient_id" => $patient->id, "visit_id" => $visit->id, "hospital_id" => $vis->info->hospital_id, "region" => $vis->info->region, "district" => $vis->info->district, "ward" => $vis->info->ward, "ten_cell_leader" => $vis->info->ten_cell_leader)); $patinfo->created_at = $vis->info->created_at; $patinfo->updated_at = $vis->info->updated_at; $patinfo->save(); //adding gynecological history inforamtion for a visit $gyno = ServerGynecologicalHistory::create(array("patient_id" => $patient->id, "visit_id" => $visit->id, "parity" => $vis->gynecology->parity, "number_of_pregnancy" => $vis->gynecology->number_of_pregnancy, "menarche" => $vis->gynecology->menarche, "age_at_sexual_debut" => $vis->gynecology->age_at_sexual_debut, "marital_status" => $vis->gynecology->marital_status, "age_at_first_marriage" => $vis->gynecology->age_at_first_marriage, "sexual_partner" => $vis->gynecology->sexual_partner, "partner_sexual_partner" => $vis->gynecology->partner_sexual_partner)); $gyno->created_at = $vis->gynecology->created_at; $gyno->updated_at = $vis->gynecology->updated_at; $gyno->save(); //adding contraceptive history $contra = ServerContraceptiveHistory::create(array("patient_id" => $patient->id, "visit_id" => $visit->id, "previous_status" => $vis->contraceptive->previous_status, "current_status" => $vis->contraceptive->current_status, "previous_contraceptive_id" => $vis->contraceptive->previous_contraceptive_id, "current_contraceptive_id" => $vis->contraceptive->current_contraceptive_id)); $contra->created_at = $vis->contraceptive->created_at; $contra->updated_at = $vis->contraceptive->updated_at; $contra->save(); //adding HIV status $hiv = ServerHivStatus::create(array("patient_id" => $patient->id, "visit_id" => $visit->id, "status" => $vis->hiv->status, "test_status" => $vis->hiv->test_status, "unknown_reason" => $vis->hiv->unknown_reason, "years_since_first_diagnosis" => $vis->hiv->years_since_first_diagnosis, "year_of_last_test" => $vis->hiv->year_of_last_test, "art_status" => $vis->hiv->art_status, "current_art_status" => $vis->hiv->current_art_status, "pitc_offered" => $vis->hiv->pitc_offered, "pitc_agreed" => $vis->hiv->pitc_agreed, "pitc_result" => $vis->hiv->pitc_result, "pitc_cd4_count" => $vis->hiv->pitc_cd4_count, "prev_cd4_count" => $vis->hiv->prev_cd4_count)); $hiv->created_at = $vis->hiv->created_at; $hiv->updated_at = $vis->hiv->updated_at; $hiv->save(); //adding VIA Status $via = ServerViaStatus::create(array("patient_id" => $patient->id, "visit_id" => $visit->id, "via_counselling_status" => $vis->via->via_counselling_status, "via_test_status" => $vis->via->via_test_status, "reject_reason" => $vis->via->reject_reason, "via_result" => $vis->via->via_result)); $via->created_at = $vis->via->created_at; $via->updated_at = $vis->via->updated_at; $via->save(); //adding colposcopy $col = ServerColposcopyStatus::create(array("patient_id" => $patient->id, "visit_id" => $visit->id, "status" => $vis->colposcopy->status, "result_id" => $vis->colposcopy->result_id)); $col->created_at = $vis->colposcopy->created_at; $col->updated_at = $vis->colposcopy->updated_at; $col->save(); //adding Pap smear result $pap = ServerPapsmearStatus::create(array("patient_id" => $patient->id, "visit_id" => $visit->id, "status" => $vis->papsmea->status, "result_id" => $vis->papsmea->result_id)); $pap->created_at = $vis->papsmea->created_at; $pap->updated_at = $vis->papsmea->updated_at; $pap->save(); //adding intervetion status $interv = ServerIntervention::create(array("patient_id" => $patient->id, "visit_id" => $visit->id, "type_id" => $vis->intervention->type_id, "indicator_id" => $vis->intervention->indicator_id, "histology_id" => $vis->intervention->histology_id, "cancer_id" => $vis->intervention->cancer_id, "grade" => $vis->intervention->grade, "stages" => $vis->intervention->stages, "differentiation" => $vis->intervention->differentiation)); $interv->created_at = $vis->intervention->created_at; $interv->updated_at = $vis->intervention->updated_at; $interv->save(); if ($vis->notification) { ServerNotification::create(array("patient_id" => $patient->id, "message" => $vis->notification->message, "status" => $vis->notification->status, "phone_number" => $vis->notification->phone_number, "next_visit" => $vis->notification->next_visit)); } $vis->server_status = "transferred"; $vis->save(); echo " <span class='text-success'> done.<i class='fa fa-check'></i></span> " . count(Visit::where('server_status', 'not')->get()) . " Remaining visit(s) to be transferred<br>"; } catch (Exception $e) { echo $vis->patient->first_name . " " . $vis->patient->last_name . " not tranfsfered because " . $e->getMessage(); } //send the visit online a bundle } } }