Ejemplo n.º 1
0
 /**
  * Display data after applying the filters on the report uses patient ID
  *
  * @return Response
  */
 public function viewPatientReport($id, $visit = null, $testId = null)
 {
     $from = Input::get('start');
     $to = Input::get('end');
     $pending = Input::get('pending');
     $date = date('Y-m-d');
     $error = '';
     $visitId = Input::get('visit_id');
     //  Check checkbox if checked and assign the 'checked' value
     if (Input::get('tests') === '1') {
         $pending = 'checked';
     }
     //  Query to get tests of a particular patient
     if (($visit || $visitId) && $id && $testId) {
         $tests = Test::where('id', '=', $testId);
     } else {
         if (($visit || $visitId) && $id) {
             $tests = Test::where('visit_id', '=', $visit ? $visit : $visitId);
         } else {
             $tests = Test::join('visits', 'visits.id', '=', 'tests.visit_id')->where('patient_id', '=', $id);
         }
     }
     //  Begin filters - include/exclude pending tests
     if ($pending) {
         $tests = $tests->where('tests.test_status_id', '!=', Test::NOT_RECEIVED);
     } else {
         $tests = $tests->whereIn('tests.test_status_id', [Test::COMPLETED, Test::VERIFIED]);
     }
     //  Date filters
     if ($from || $to) {
         if (!$to) {
             $to = $date;
         }
         if (strtotime($from) > strtotime($to) || strtotime($from) > strtotime($date) || strtotime($to) > strtotime($date)) {
             $error = trans('messages.check-date-range');
         } else {
             $toPlusOne = date_add(new DateTime($to), date_interval_create_from_date_string('1 day'));
             $tests = $tests->whereBetween('time_created', array($from, $toPlusOne->format('Y-m-d H:i:s')));
         }
     }
     //  Get tests collection
     $tests = $tests->get(array('tests.*'));
     //  Get patient details
     $patient = Patient::find($id);
     //  Check if tests are accredited
     $accredited = $this->accredited($tests);
     $verified = array();
     foreach ($tests as $test) {
         if ($test->isVerified()) {
             array_push($verified, $test->id);
         } else {
             continue;
         }
     }
     if (Input::has('word')) {
         $date = date("Ymdhi");
         $fileName = "blispatient_" . $id . "_" . $date . ".doc";
         $headers = array("Content-type" => "text/html", "Content-Disposition" => "attachment;Filename=" . $fileName);
         $content = view('reports.patient.export')->with('patient', $patient)->with('tests', $tests)->with('from', $from)->with('to', $to)->with('visit', $visit)->with('accredited', $accredited);
         return Response::make($content, 200, $headers);
     } else {
         return view('reports.patient.report')->with('patient', $patient)->with('tests', $tests)->with('pending', $pending)->with('error', $error)->with('visit', $visit)->with('accredited', $accredited)->with('verified', $verified)->withInput(Input::all());
     }
 }