Ejemplo n.º 1
0
 /**
  * Display a test((un)grouped) and specimen((un)grouped) counts.
  *
  */
 public function countReports()
 {
     $date = date('Y-m-d');
     $from = Input::get('start');
     if (!$from) {
         $from = date('Y-m-01');
     }
     $to = Input::get('end');
     if (!$to) {
         $to = $date;
     }
     $toPlusOne = date_add(new DateTime($to), date_interval_create_from_date_string('1 day'));
     $counts = Input::get('counts');
     $accredited = array();
     //  Begin grouped test counts
     if ($counts == trans('messages.grouped-test-counts')) {
         $testCategories = TestCategory::all();
         $testTypes = TestType::all();
         $ageRanges = array('0-5', '5-15', '15-120');
         //  Age ranges - will definitely change in configurations
         $gender = array(Patient::MALE, Patient::FEMALE);
         //  Array for gender - male/female
         $perAgeRange = array();
         // array for counts data for each test type and age range
         $perTestType = array();
         //  array for counts data per testype
         if (strtotime($from) > strtotime($to) || strtotime($from) > strtotime($date) || strtotime($to) > strtotime($date)) {
             Session::flash('message', trans('messages.check-date-range'));
         }
         foreach ($testTypes as $testType) {
             $countAll = $this->getGroupedTestCounts($testType, null, null, $from, $toPlusOne->format('Y-m-d H:i:s'));
             $countMale = $this->getGroupedTestCounts($testType, [Patient::MALE], null, $from, $toPlusOne->format('Y-m-d H:i:s'));
             $countFemale = $this->getGroupedTestCounts($testType, [Patient::FEMALE], null, $from, $toPlusOne->format('Y-m-d H:i:s'));
             $perTestType[$testType->id] = ['countAll' => $countAll, 'countMale' => $countMale, 'countFemale' => $countFemale];
             foreach ($ageRanges as $ageRange) {
                 $maleCount = $this->getGroupedTestCounts($testType, [Patient::MALE], $ageRange, $from, $toPlusOne->format('Y-m-d H:i:s'));
                 $femaleCount = $this->getGroupedTestCounts($testType, [Patient::FEMALE], $ageRange, $from, $toPlusOne->format('Y-m-d H:i:s'));
                 $perAgeRange[$testType->id][$ageRange] = ['male' => $maleCount, 'female' => $femaleCount];
             }
         }
         return view('reports.counts.groupedTestCount')->with('testCategories', $testCategories)->with('ageRanges', $ageRanges)->with('gender', $gender)->with('perTestType', $perTestType)->with('perAgeRange', $perAgeRange)->with('accredited', $accredited)->withInput(Input::all());
     } else {
         if ($counts == trans('messages.ungrouped-specimen-counts')) {
             if (strtotime($from) > strtotime($to) || strtotime($from) > strtotime($date) || strtotime($to) > strtotime($date)) {
                 Session::flash('message', trans('messages.check-date-range'));
             }
             $ungroupedSpecimen = array();
             foreach (SpecimenType::all() as $specimenType) {
                 $rejected = $specimenType->countPerStatus([Specimen::REJECTED], $from, $toPlusOne->format('Y-m-d H:i:s'));
                 $accepted = $specimenType->countPerStatus([Specimen::ACCEPTED], $from, $toPlusOne->format('Y-m-d H:i:s'));
                 $total = $rejected + $accepted;
                 $ungroupedSpecimen[$specimenType->id] = ["total" => $total, "rejected" => $rejected, "accepted" => $accepted];
             }
             // $data = $data->groupBy('test_type_id')->paginate(Config::get('kblis.page-items'));
             return view('reports.counts.ungroupedSpecimenCount')->with('ungroupedSpecimen', $ungroupedSpecimen)->with('accredited', $accredited)->withInput(Input::all());
         } else {
             if ($counts == trans('messages.grouped-specimen-counts')) {
                 $ageRanges = array('0-5', '5-15', '15-120');
                 //  Age ranges - will definitely change in configurations
                 $gender = array(Patient::MALE, Patient::FEMALE);
                 //  Array for gender - male/female
                 $perAgeRange = array();
                 // array for counts data for each test type and age range
                 $perSpecimenType = array();
                 //  array for counts data per testype
                 if (strtotime($from) > strtotime($to) || strtotime($from) > strtotime($date) || strtotime($to) > strtotime($date)) {
                     Session::flash('message', trans('messages.check-date-range'));
                 }
                 $specimenTypes = SpecimenType::all();
                 foreach ($specimenTypes as $specimenType) {
                     $countAll = $specimenType->groupedSpecimenCount([Patient::MALE, Patient::FEMALE], null, $from, $toPlusOne->format('Y-m-d H:i:s'));
                     $countMale = $specimenType->groupedSpecimenCount([Patient::MALE], null, $from, $toPlusOne->format('Y-m-d H:i:s'));
                     $countFemale = $specimenType->groupedSpecimenCount([Patient::FEMALE], null, $from, $toPlusOne->format('Y-m-d H:i:s'));
                     $perSpecimenType[$specimenType->id] = ['countAll' => $countAll, 'countMale' => $countMale, 'countFemale' => $countFemale];
                     foreach ($ageRanges as $ageRange) {
                         $maleCount = $specimenType->groupedSpecimenCount([Patient::MALE], $ageRange, $from, $toPlusOne->format('Y-m-d H:i:s'));
                         $femaleCount = $specimenType->groupedSpecimenCount([Patient::FEMALE], $ageRange, $from, $toPlusOne->format('Y-m-d H:i:s'));
                         $perAgeRange[$specimenType->id][$ageRange] = ['male' => $maleCount, 'female' => $femaleCount];
                     }
                 }
                 return view('reports.counts.groupedSpecimenCount')->with('specimenTypes', $specimenTypes)->with('ageRanges', $ageRanges)->with('gender', $gender)->with('perSpecimenType', $perSpecimenType)->with('perAgeRange', $perAgeRange)->with('accredited', $accredited)->withInput(Input::all());
             } else {
                 if (strtotime($from) > strtotime($to) || strtotime($from) > strtotime($date) || strtotime($to) > strtotime($date)) {
                     Session::flash('message', trans('messages.check-date-range'));
                 }
                 $ungroupedTests = array();
                 foreach (TestType::all() as $testType) {
                     $pending = $testType->countPerStatus([Test::PENDING, Test::STARTED], $from, $toPlusOne->format('Y-m-d H:i:s'));
                     $complete = $testType->countPerStatus([Test::COMPLETED, Test::VERIFIED], $from, $toPlusOne->format('Y-m-d H:i:s'));
                     $ungroupedTests[$testType->id] = ["complete" => $complete, "pending" => $pending];
                 }
                 // $data = $data->groupBy('test_type_id')->paginate(Config::get('kblis.page-items'));
                 return view('reports.counts.ungroupedTestCount')->with('ungroupedTests', $ungroupedTests)->with('accredited', $accredited)->withInput(Input::all());
             }
         }
     }
 }