Beispiel #1
0
 /**
  * Returns grouped specimen Counts with optional gender, age range, date range
  *
  * @param $gender, $ageRange, $from, $to
  */
 public function groupedSpecimenCount($gender = null, $ageRange = null, $from = null, $to = null)
 {
     $specimens = Specimen::where('specimen_type_id', $this->id)->whereIn('specimen_status_id', [Specimen::ACCEPTED]);
     if ($to && $from) {
         $specimens = $specimens->whereBetween('time_accepted', [$from, $to]);
     }
     if ($gender) {
         $specimens = $specimens->join('tests', 'specimens.id', '=', 'tests.specimen_id')->join('visits', 'tests.visit_id', '=', 'visits.id')->join('patients', 'visits.patient_id', '=', 'patients.id')->whereIn('gender', $gender);
     }
     if ($ageRange) {
         $ageRange = explode('-', $ageRange);
         $ageStart = $ageRange[0];
         $ageEnd = $ageRange[1];
         $now = new DateTime('now');
         $finishDate = $now->sub(new DateInterval('P' . $ageStart . 'Y'))->format('Y-m-d');
         $startDate = $now->sub(new DateInterval('P' . $ageEnd . 'Y'))->format('Y-m-d');
         $specimens = $specimens->whereBetween('dob', [$startDate, $finishDate]);
     }
     return $specimens->count();
 }
Beispiel #2
0
 public function testWaitTime()
 {
     $specIDs = Specimen::where('specimen_status_id', '!=', Specimen::NOT_COLLECTED)->lists('id');
     if (count($specIDs) == 0) {
         $this->assertTrue(false);
     }
     foreach ($specIDs as $id) {
         $test = Specimen::find($id)->test()->first();
         $this->assertTrue($test->getWaitTime() >= 0);
     }
 }
Beispiel #3
0
 public function testIsNotRejected()
 {
     $specimenRejected = Specimen::where('specimen_status_id', '!=', Specimen::REJECTED)->first();
     $this->assertEquals($specimenRejected->isRejected(), false);
 }
Beispiel #4
0
 /**
  * Display specimen rejection chart
  *
  * @return Response
  */
 public static function specimenRejectionChart($testTypeID = 0)
 {
     $from = Input::get('start');
     $to = Input::get('end');
     $spec_type = Input::get('specimen_type');
     $months = json_decode(self::getMonths($from, $to));
     //  Get specimen rejection reasons available in the time period
     $rr = Specimen::select(DB::raw('DISTINCT(reason) AS rr, rejection_reason_id'))->join('rejection_reasons', 'rejection_reasons.id', '=', 'specimens.rejection_reason_id')->whereBetween('time_rejected', [$from, $to])->groupBy('rr')->get();
     $options = '{
         "chart": {
             "type": "spline"
         },
         "title": {
             "text":"Rejected Specimen per Reason Overtime"
         },
         "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($rr);
     foreach ($rr as $rrr) {
         $options .= '{
                         "name": "' . $rrr->rr . '","data": [';
         $counter = count($months);
         foreach ($months as $month) {
             $data = Specimen::where('rejection_reason_id', $rrr->rejection_reason_id)->whereRaw('MONTH(time_rejected)=' . $month->months);
             if ($spec_type) {
                 $data = $data->where('specimen_type_id', $spec_type);
             }
             $data = $data->count();
             $options .= $data;
             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": "No. of Rejected Specimen"
             }
         }
     }';
     return view('reports.rejection.index')->with('options', $options)->withInput(Input::all());
 }