Ejemplo n.º 1
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function edit($id)
 {
     $lesson = CourseLesson::findOrFail($id);
     $course = $lesson->course;
     $userId = Auth::user()->id;
     $tests = Test::where('user_id', '=', $userId)->get();
     return view('course.lesson.edit', ['lesson' => $lesson, 'tests' => $tests, 'course' => $course]);
 }
Ejemplo n.º 2
0
 /**
  * @param  Count tests for a particular time of day and status
  * @return Total count
  */
 public static function perHour($status, $from)
 {
     $counter = 0;
     $cloned = clone $from;
     $liked = clone $from;
     $hour = $cloned->hour;
     if (strlen($hour) == 1) {
         $hour = '0' . $hour;
     }
     $liker = $cloned->toDateString() . ' ' . $hour;
     $counter = Test::where('test_status_id', $status)->where('time_created', 'like', '%' . $liker . '%')->count();
     return $counter;
 }
Ejemplo n.º 3
0
 public function testGetTurnAroundTime()
 {
     $testIDs = Test::where('test_status_id', '=', Test::COMPLETED)->orWhere('test_status_id', '=', Test::VERIFIED)->lists('id');
     if (count($testIDs) == 0) {
         $this->assertTrue(false);
     }
     foreach ($testIDs as $id) {
         $test = Test::find($id);
         $this->assertTrue($test->getTurnaroundTime() >= 0);
     }
 }
Ejemplo n.º 4
0
 /**
  * Display a both chart and table on load.
  *
  * @return Response
  */
 public function prevalenceRates()
 {
     $from = Input::get('start');
     $to = Input::get('end');
     $today = date('Y-m-d');
     $year = date('Y');
     $testTypeID = Input::get('test_type');
     //  Apply filters if any
     if (Input::has('filter')) {
         if (!$to) {
             $to = $today;
         }
         if (strtotime($from) > strtotime($to) || strtotime($from) > strtotime($today) || strtotime($to) > strtotime($today)) {
             Session::flash('message', trans('messages.check-date-range'));
         }
         $months = json_decode(self::getMonths($from, $to));
         $data = TestType::getPrevalenceCounts($from, $to, $testTypeID);
         $chart = self::getPrevalenceRatesChart($testTypeID);
     } else {
         // Get all tests for the current year
         $test = Test::where('time_created', 'LIKE', date('Y') . '%');
         $periodStart = $test->min('time_created');
         //Get the minimum date
         $periodEnd = $test->max('time_created');
         //Get the maximum date
         $data = TestType::getPrevalenceCounts($periodStart, $periodEnd);
         $chart = self::getPrevalenceRatesChart();
     }
     return view('reports.prevalence.index')->with('data', $data)->with('chart', $chart)->withInput(Input::all());
 }
Ejemplo n.º 5
0
 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);
 }
Ejemplo n.º 6
0
 public function testPaymentRequest()
 {
     $this->withoutMiddleware();
     // Invoke API URL making a single test request (presumed successful)
     $this->json('POST', 'api/receiver', [$this->labRequestJsonSimpleTest]);
     $labR = $this->labRequestJsonSimpleTest;
     if (strpos($labR, '=') !== false && strpos($labR, 'labRequest') !== false) {
         $labR = str_replace(['labRequest', '='], ['', ''], $labR);
         $labR = json_decode($labR);
     }
     // Was the data stored in the external dump?
     $externalDump = ExternalDump::where('lab_no', '=', $labR->labNo)->get();
     $this->assertTrue(count($externalDump) > 0);
     // Was a new patient created?
     $patient = Patient::where('external_patient_number', '=', $externalDump->first()->patient_id)->get();
     $this->assertTrue(count($patient) > 0);
     // Is there a Visit for this new patient?
     $visit = Visit::where('patient_id', '=', $patient->first()->id)->get();
     $this->assertTrue(count($visit) > 0);
     // Is there a Test for this visit?
     $test = Test::where('visit_id', '=', $visit->first()->id)->get();
     $this->assertTrue(count($visit) > 0);
     // Is there a Specimen for this new Test?
     $specimen = $test->first()->specimen;
     $this->assertTrue(count($specimen) > 0);
     $labRPR = json_decode($this->labRequestJsonSimpleTestPayMentRequest);
     //Second request similar to first but with payment details
     App\Api\Facades\Interfacer::retrieve($labRPR);
     // Was the data stored in the external dump?
     // There should only be one record. The second only updates the first
     $externalDumpPayment = ExternalDump::where('lab_no', '=', $labR->labNo)->get();
     $this->assertTrue(count($externalDumpPayment) == 1);
     $this->assertEquals($labRPR->receiptNumber, $externalDumpPayment->first()->receipt_number);
 }
Ejemplo n.º 7
0
 /**
  * Returns grouped test Counts with optional gender, age range, date range
  *
  * @param $testStatusID, $from, $to
  */
 public function groupedTestCount($gender = null, $ageRange = null, $from = null, $to = null)
 {
     $tests = Test::where('test_type_id', $this->id)->whereIn('test_status_id', [Test::PENDING, Test::STARTED, Test::COMPLETED, Test::VERIFIED]);
     if ($to && $from) {
         $tests = $tests->whereBetween('time_created', [$from, $to]);
     }
     if ($ageRange || $gender) {
         $tests = $tests->join('visits', 'tests.visit_id', '=', 'visits.id')->join('patients', 'visits.patient_id', '=', 'patients.id');
         if ($gender) {
             $tests = $tests->whereIn('gender', $gender);
         }
         if ($ageRange) {
             $age = explode('-', $ageRange);
             $ageStart = $age[0];
             $ageEnd = $age[1];
             $now = new DateTime('now');
             $clonedDate = clone $now;
             $finishDate = $clonedDate->sub(new DateInterval('P' . $ageStart . 'Y'))->format('Y-m-d');
             $clonedDate = clone $now;
             $startDate = $clonedDate->sub(new DateInterval('P' . $ageEnd . 'Y'))->format('Y-m-d');
             $tests = $tests->whereBetween('dob', [$startDate, $finishDate]);
         }
     }
     return $tests->count();
 }
Ejemplo n.º 8
0
 /**
  * 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);
 }