コード例 #1
0
ファイル: Measure.php プロジェクト: BaobabHealthTrust/iBLIS
 public function getResultInterpretation($result)
 {
     $measure = Measure::find($result['measureid']);
     try {
         $measurerange = MeasureRange::where('measure_id', '=', $result['measureid']);
         if ($measure->isNumeric()) {
             $birthDate = new DateTime($result['birthdate']);
             $now = new DateTime();
             $interval = $birthDate->diff($now);
             $seconds = $interval->days * 24 * 3600 + $interval->h * 3600 + $interval->i * 60 + $interval->s;
             $age = $seconds / (365 * 24 * 60 * 60);
             $measurerange = $measurerange->where('gender', '=', $result['gender'])->where('age_min', '<=', $age)->where('age_max', '>=', $age)->where('range_lower', '<=', $result['measurevalue'])->where('range_upper', '>=', $result['measurevalue']);
         } else {
             $measurerange = $measurerange->where('alphanumeric', '=', $result['measurevalue']);
         }
         $measurerange = $measurerange->get()->toArray();
         $interpretation = $measurerange[0]['interpretation'];
     } catch (Exception $e) {
         $interpretation = null;
     }
     return $interpretation;
 }
コード例 #2
0
 /**
  * Retrieves the results and creates a JSON string
  *
  * @param testId the id of the test to send
  * @param 
  */
 public function createJsonString($testId)
 {
     //if($comments==null or $comments==''){$comments = 'No Comments';
     //We use curl to send the requests
     $httpCurl = curl_init(Config::get('kblis.sanitas-url'));
     curl_setopt($httpCurl, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($httpCurl, CURLOPT_POST, true);
     //If testID is null we cannot handle this test as we cannot know the results
     if ($testId == null) {
         return null;
     }
     //Get the test and results
     $test = Test::find($testId);
     $testResults = $test->testResults;
     //Measures
     $testTypeId = $test->testType()->get()->lists('id')[0];
     $testType = TestType::find($testTypeId);
     $testMeasures = $testType->measures;
     //Get external requests and all its children
     $externalDump = new ExternalDump();
     $externRequest = ExternalDump::where('test_id', '=', $testId)->get();
     if (!$externRequest->first()) {
         //Not a request we can send back
         return null;
     }
     $labNo = $externRequest->lists('lab_no')[0];
     $externlabRequestTree = $externalDump->getLabRequestAndMeasures($labNo);
     $interpretation = "";
     //IF the test has no children prepend the status to the result
     if ($externlabRequestTree->isEmpty()) {
         if ($test->test_status_id == Test::COMPLETED) {
             $interpretation = "Done: " . $test->interpretation;
         } elseif ($test->test_status_id == Test::VERIFIED) {
             $interpretation = "Tested and verified: " . $test->interpretation;
         }
     } else {
         if ($test->test_status_id == Test::COMPLETED) {
             $interpretation = "Done " . $test->interpretation;
         } elseif ($test->test_status_id == Test::VERIFIED) {
             $interpretation = "Tested and verified " . $test->interpretation;
         }
     }
     //TestedBy
     $tested_by = ExternalUser::where('internal_user_id', '=', $test->tested_by)->get()->first();
     if ($tested_by == null) {
         $tested_by = "59";
     } else {
         if ($tested_by->external_user_id == null) {
             $tested_by = "59";
         } else {
             $tested_by = $tested_by->external_user_id;
         }
     }
     if ($test->verified_by == 0 || $test->verified_by == null) {
         $verified_by = "59";
     } else {
         $verified_by = ExternalUser::where('internal_user_id', '=', $test->verified_by)->get()->first();
         if ($verified_by == null) {
             $verified_by = "59";
         } else {
             if ($verified_by->external_user_id == null) {
                 $verified_by = "59";
             } else {
                 $verified_by = $verified_by->external_user_id;
             }
         }
     }
     //TODO - relate measure to test-result
     $range = Measure::getRange($test->visit->patient, $testResults->first()->measure_id);
     $unit = Measure::find($testResults->first()->measure_id)->unit;
     $result = $testResults->first()->result . " " . $range . " " . $unit;
     $jsonResponseString = sprintf('{"labNo": "%s","requestingClinician": "%s", "result": "%s", "verifiedby": "%s", "techniciancomment": "%s"}', $labNo, $tested_by, $result, $verified_by, trim($interpretation));
     $this->sendRequest($httpCurl, urlencode($jsonResponseString), $labNo);
     //loop through labRequests and foreach of them get the result and put in an array
     foreach ($externlabRequestTree as $key => $externlabRequest) {
         $mKey = array_search($externlabRequest->investigation, $testMeasures->lists('name'));
         if ($mKey === false) {
             Log::error("MEASURE NOT FOUND: Measure {$externlabRequest->investigation} not found in our system");
         } else {
             $measureId = $testMeasures->get($mKey)->id;
             $rKey = array_search($measureId, $testResults->lists('measure_id'));
             $matchingResult = $testResults->get($rKey);
             $range = Measure::getRange($test->visit->patient, $measureId);
             $unit = Measure::find($measureId)->unit;
             $result = $matchingResult->result . " " . $range . " " . $unit;
             $jsonResponseString = sprintf('{"labNo": "%s","requestingClinician": "%s", "result": "%s", "verifiedby": "%s", "techniciancomment": "%s"}', $externlabRequest->lab_no, $tested_by, $result, $verified_by, "");
             $this->sendRequest($httpCurl, urlencode($jsonResponseString), $externlabRequest->lab_no);
         }
     }
     curl_close($httpCurl);
 }
コード例 #3
0
ファイル: TestType.php プロジェクト: BaobabHealthTrust/iBLIS
 /**
  * Get TestTypes that support prevalence counts
  *
  * @return Collection TestTypes
  */
 public static function supportPrevalenceCounts()
 {
     $testTypes = new Illuminate\Database\Eloquent\Collection();
     // Get ALPHANUMERIC measures whose possible results (or their interpretation) can be
     // reduced to either Positive or Negative
     $measures = DB::table('measures')->select(DB::raw('measures.id, measures.name'))->join('measure_ranges', 'measures.id', '=', 'measure_ranges.measure_id')->where('measures.measure_type_id', '=', Measure::ALPHANUMERIC)->where(function ($query) {
         $query->where('measure_ranges.alphanumeric', '=', 'Positive')->orWhere('measure_ranges.alphanumeric', '=', 'Negative')->orWhere('measure_ranges.interpretation', '=', 'Positive')->orWhere('measure_ranges.interpretation', '=', 'Negative');
     })->get();
     foreach ($measures as $measure) {
         $measureORM = Measure::find($measure->id);
         $objArray = $measureORM->testTypes()->first();
         if (!empty($objArray)) {
             foreach ($measureORM->testTypes()->get() as $tType) {
                 if ($tType->measures()->count() == 1) {
                     $testTypes->add($tType);
                 }
             }
         }
     }
     return $testTypes->unique()->sortBy('name');
 }
コード例 #4
0
 /**
  * Tests the update funtion in the MeasureController
  * 
  * @return void
  */
 public function testIfUpdateWorks()
 {
     //Save again because teardown() dropped the db :(
     $this->runStore($this->inputNumeric);
     $this->runStore($this->inputAlphanumeric);
     $this->runStore($this->inputAutocomplete);
     $this->runStore($this->inputFreetext);
     $measurestored = Measure::orderBy('id', 'desc')->take(4)->get()->toArray();
     $measureUricAcid = Measure::where('name', 'LIKE', '%uric%')->orderBy('id', 'desc')->first();
     $uricMeasureRanges = array();
     $alphanumericRanges = array();
     $autoCompleteRanges = array();
     foreach ($measureUricAcid->measureRanges as $range) {
         $uricMeasureRanges[] = $range->id;
     }
     foreach (Measure::find($measurestored[2]['id'])->measureRanges as $range) {
         $alphanumericRanges[] = $range->id;
     }
     foreach (Measure::find($measurestored[1]['id'])->measureRanges as $range) {
         $autoCompleteRanges[] = $range->id;
     }
     // Update the Measure Types
     // The second argument is the test type ID
     $this->runUpdate($this->inputNumericUpdate, $measureUricAcid->id, $uricMeasureRanges);
     $this->runUpdate($this->inputAlphanumericUpdate, $measurestored[2]['id'], $alphanumericRanges);
     $this->runUpdate($this->inputAutocompleteUpdate, $measurestored[1]['id'], $autoCompleteRanges);
     $this->runUpdate($this->inputFreetextUpdate, $measurestored[0]['id'], 0);
     $measureupdated = Measure::orderBy('id', 'desc')->take(4)->get()->toArray();
     $measureNewUricAcid = Measure::find($measureUricAcid->id);
     // Check that the measure values for the uric acid measure were updated
     $this->assertEquals($measureNewUricAcid->name, $this->inputNumericUpdate[0]['name']);
     $this->assertEquals($measureNewUricAcid->measure_type_id, $this->inputNumericUpdate[0]['measure_type_id']);
     $this->assertEquals($measureNewUricAcid->unit, $this->inputNumericUpdate[0]['unit']);
     $this->assertEquals($measureNewUricAcid->description, $this->inputNumericUpdate[0]['description']);
     $this->assertEquals($measureupdated[2]['name'], $this->inputAlphanumericUpdate[0]['name']);
     $this->assertEquals($measureupdated[2]['measure_type_id'], $this->inputAlphanumericUpdate[0]['measure_type_id']);
     $this->assertEquals($measureupdated[2]['description'], $this->inputAlphanumericUpdate[0]['description']);
     $this->assertEquals($measureupdated[1]['name'], $this->inputAutocompleteUpdate[0]['name']);
     $this->assertEquals($measureupdated[1]['measure_type_id'], $this->inputAutocompleteUpdate[0]['measure_type_id']);
     $this->assertEquals($measureupdated[1]['description'], $this->inputAutocompleteUpdate[0]['description']);
     $this->assertEquals($measureupdated[0]['name'], $this->inputFreetextUpdate[0]['name']);
     $this->assertEquals($measureupdated[0]['measure_type_id'], $this->inputFreetextUpdate[0]['measure_type_id']);
     $this->assertEquals($measureupdated[0]['description'], $this->inputFreetextUpdate[0]['description']);
     $measurerangeupdated = MeasureRange::orderBy('id', 'desc')->take(6)->get()->toArray();
     $this->assertEquals($measurerangeupdated[5]['age_min'], $this->inputNumericUpdate[0]['agemin'][0]);
     $this->assertEquals($measurerangeupdated[5]['age_max'], $this->inputNumericUpdate[0]['agemax'][0]);
     $this->assertEquals($measurerangeupdated[5]['gender'], $this->inputNumericUpdate[0]['gender'][0]);
     $this->assertEquals($measurerangeupdated[5]['range_lower'], $this->inputNumericUpdate[0]['rangemin'][0]);
     $this->assertEquals($measurerangeupdated[5]['range_upper'], $this->inputNumericUpdate[0]['rangemax'][0]);
     $this->assertEquals($measurerangeupdated[4]['age_min'], $this->inputNumericUpdate[0]['agemin'][1]);
     $this->assertEquals($measurerangeupdated[4]['age_max'], $this->inputNumericUpdate[0]['agemax'][1]);
     $this->assertEquals($measurerangeupdated[4]['gender'], $this->inputNumericUpdate[0]['gender'][1]);
     $this->assertEquals($measurerangeupdated[4]['range_lower'], $this->inputNumericUpdate[0]['rangemin'][1]);
     $this->assertEquals($measurerangeupdated[4]['range_upper'], $this->inputNumericUpdate[0]['rangemax'][1]);
     $this->assertEquals($measurerangeupdated[3]['alphanumeric'], $this->inputAlphanumericUpdate[0]['val'][0]);
     $this->assertEquals($measurerangeupdated[2]['alphanumeric'], $this->inputAlphanumericUpdate[0]['val'][1]);
     $this->assertEquals($measurerangeupdated[1]['alphanumeric'], $this->inputAutocompleteUpdate[0]['val'][0]);
     $this->assertEquals($measurerangeupdated[0]['alphanumeric'], $this->inputAutocompleteUpdate[0]['val'][1]);
 }
コード例 #5
0
ファイル: ReportController.php プロジェクト: echiteri/iBLIS
    /**
     * MOH 706
     *
     */
    public function moh706()
    {
        //	Variables definition
        $date = date('Y-m-d');
        $from = Input::get('start');
        if (!$from) {
            $from = date('Y-m-01');
        }
        $end = Input::get('end');
        if (!$end) {
            $end = $date;
        }
        $toPlusOne = date_add(new DateTime($end), date_interval_create_from_date_string('1 day'));
        $to = date_add(new DateTime($end), date_interval_create_from_date_string('1 day'))->format('Y-m-d');
        $ageRanges = array('0-5', '5-14', '14-120');
        $sex = array(Patient::MALE, Patient::FEMALE);
        $ranges = array('Low', 'Normal', 'High');
        $specimen_types = array('Urine', 'Pus', 'HVS', 'Throat', 'Stool', 'Blood', 'CSF', 'Water', 'Food', 'Other fluids');
        $isolates = array('Naisseria', 'Klebsiella', 'Staphylococci', 'Streptoccoci' . 'Proteus', 'Shigella', 'Salmonella', 'V. cholera', 'E. coli', 'C. neoformans', 'Cardinella vaginalis', 'Haemophilus', 'Bordotella pertusis', 'Pseudomonas', 'Coliforms', 'Faecal coliforms', 'Enterococcus faecalis', 'Total viable counts-22C', 'Total viable counts-37C', 'Clostridium', 'Others');
        //	Get specimen_types for microbiology
        $labSecId = TestCategory::getTestCatIdByName('microbiology');
        $specTypeIds = DB::select(DB::raw("select distinct(specimen_types.id) as spec_id from testtype_specimentypes" . " join test_types on test_types.id=testtype_specimentypes.test_type_id" . " join specimen_types on testtype_specimentypes.specimen_type_id=specimen_types.id" . "  where test_types.test_category_id=?"), array($labSecId));
        //	Referred out specimen
        $referredSpecimens = DB::select(DB::raw("SELECT specimen_type_id, specimen_types.name as spec, count(specimens.id) as tot," . " facility_id, facilities.name as facility FROM iblis.specimens" . " join referrals on specimens.referral_id=referrals.id" . " join specimen_types on specimen_type_id=specimen_types.id" . " join facilities on referrals.facility_id=facilities.id" . " where referral_id is not null and status=1" . " and time_accepted between ? and ?" . " group by facility_id;"), array($from, $toPlusOne));
        $table = '<!-- URINALYSIS -->
			<div class="col-sm-12">
				<strong>URINE ANALYSIS</strong>
				<table class="table table-condensed report-table-border">
					<thead>
						<tr>
							<th rowspan="2">Urine Chemistry</th>
							<th colspan="2">No. Exam</th>
							<th colspan="4"> Number positive</th>
						</tr>
						<tr>
							<th>M</th>
							<th>F</th>
							<th>Total</th>
							<th>&lt;5yrs</th>
							<th>5-14yrs</th>
							<th>&gt;14yrs</th>
						</tr>
					</thead>';
        $urinaId = TestType::getTestTypeIdByTestName('Urinalysis');
        $urinalysis = TestType::find($urinaId);
        $urineChem = TestType::getTestTypeIdByTestName('Urine Chemistry');
        $urineChemistry = TestType::find($urineChem);
        $measures = TestTypeMeasure::where('test_type_id', $urinaId)->orderBy('measure_id', 'DESC')->get();
        $table .= '<tbody>
						<tr>
							<td>Totals</td>';
        foreach ($sex as $gender) {
            $table .= '<td>' . ($this->getGroupedTestCounts($urinalysis, [$gender], null, $from, $toPlusOne) + $this->getGroupedTestCounts($urineChemistry, [$gender], null, $from, $toPlusOne)) . '</td>';
        }
        $table .= '<td>' . ($this->getGroupedTestCounts($urinalysis, null, null, $from, $toPlusOne) + $this->getGroupedTestCounts($urineChemistry, null, null, $from, $toPlusOne)) . '</td>';
        foreach ($ageRanges as $ageRange) {
            $table .= '<td>' . ($this->getGroupedTestCounts($urinalysis, [Patient::MALE, Patient::FEMALE], $ageRange, $from, $toPlusOne) + $this->getGroupedTestCounts($urineChemistry, [Patient::MALE, Patient::FEMALE], $ageRange, $from, $toPlusOne)) . '</td>';
        }
        $table .= '</tr>';
        foreach ($measures as $measure) {
            $tMeasure = Measure::find($measure->measure_id);
            if (in_array($tMeasure->name, ['ph', 'Epithelial cells', 'Pus cells', 'S. haematobium', 'T. vaginalis', 'Yeast cells', 'Red blood cells', 'Bacteria', 'Spermatozoa'])) {
                continue;
            }
            $table .= '<tr>
								<td>' . $tMeasure->name . '</td>';
            foreach ($sex as $gender) {
                $table .= '<td>' . $this->getTotalTestResults($tMeasure, [$gender], null, $from, $toPlusOne, null, null) . '</td>';
            }
            $table .= '<td>' . $this->getTotalTestResults($tMeasure, $sex, null, $from, $toPlusOne, null, 1) . '</td>';
            foreach ($ageRanges as $ageRange) {
                $table .= '<td>' . $this->getTotalTestResults($tMeasure, null, $ageRange, $from, $toPlusOne, null, 1) . '</td>';
            }
            $table .= '</tr>';
        }
        $table .= '<tr>
							<td>Others</td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
					</tbody>
				</table>
				<table class="table table-condensed report-table-border">
					<thead>
						<tr>
							<th rowspan="2">Urine Microscopy</th>
							<th colspan="2">No. Exam</th>
							<th colspan="4"> Number positive</th>
						</tr>
						<tr>
							<th>M</th>
							<th>F</th>
							<th>Total</th>
							<th>&lt;5yrs</th>
							<th>5-14yrs</th>
							<th>&gt;14yrs</th>
						</tr>
					</thead>

					<tbody>
						<tr>
							<td>Totals</td>';
        $urineMic = TestType::getTestTypeIdByTestName('Urine Microscopy');
        $urineMicroscopy = TestType::find($urineMic);
        $measures = TestTypeMeasure::where('test_type_id', $urinaId)->orderBy('measure_id', 'DESC')->get();
        foreach ($sex as $gender) {
            $table .= '<td>' . ($this->getGroupedTestCounts($urinalysis, [$gender], null, $from, $toPlusOne) + $this->getGroupedTestCounts($urineMicroscopy, [$gender], null, $from, $toPlusOne)) . '</td>';
        }
        $table .= '<td>' . ($this->getGroupedTestCounts($urinalysis, null, null, $from, $toPlusOne) + $this->getGroupedTestCounts($urineMicroscopy, null, null, $from, $toPlusOne)) . '</td>';
        foreach ($ageRanges as $ageRange) {
            $table .= '<td>' . ($this->getGroupedTestCounts($urinalysis, [Patient::MALE, Patient::FEMALE], $ageRange, $from, $toPlusOne) + $this->getGroupedTestCounts($urineMicroscopy, [Patient::MALE, Patient::FEMALE], $ageRange, $from, $toPlusOne)) . '</td>';
        }
        $table .= '</tr>';
        foreach ($measures as $measure) {
            $tMeasure = Measure::find($measure->measure_id);
            if (in_array($tMeasure->name, ['Leucocytes', 'Nitrites', 'Glucose', 'pH', 'Bilirubin', 'Ketones', 'Proteins', 'Blood', 'Urobilinogen Phenlpyruvic acid'])) {
                continue;
            }
            $table .= '<tr>
								<td>' . $tMeasure->name . '</td>';
            foreach ($sex as $gender) {
                $table .= '<td>' . $this->getTotalTestResults($tMeasure, [$gender], null, $from, $toPlusOne, null, null) . '</td>';
            }
            $table .= '<td>' . $this->getTotalTestResults($tMeasure, $sex, null, $from, $toPlusOne, null, 1) . '</td>';
            foreach ($ageRanges as $ageRange) {
                $table .= '<td>' . $this->getTotalTestResults($tMeasure, null, $ageRange, $from, $toPlusOne, null, 1) . '</td>';
            }
            $table .= '</tr>';
        }
        $table .= '<tr>
							<td>Others</td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
					</tbody>
				</table>
				<table class="table table-condensed report-table-border">
					<thead>
						<tr>
							<th rowspan="2">Blood Chemistry</th>
							<th colspan="2">No. Exam</th>
							<th colspan="4"> Number positive</th>
						</tr>
						<tr>
							<th>M</th>
							<th>F</th>
							<th>Total</th>
							<th>Low</th>
							<th>Normal</th>
							<th>High</th>
						</tr>
					</thead>
					<tbody>';
        $bloodChem = TestType::getTestTypeIdByTestName('Blood Sugar');
        $bloodChemistry = TestType::find($bloodChem);
        $measures = TestTypeMeasure::where('test_type_id', $bloodChem)->orderBy('measure_id', 'DESC')->get();
        $table .= '<tr>
							<td>Totals</td>';
        foreach ($sex as $gender) {
            $table .= '<td>' . $this->getGroupedTestCounts($bloodChemistry, [$gender], null, $from, $toPlusOne) . '</td>';
        }
        $table .= '<td>' . $this->getGroupedTestCounts($bloodChemistry, null, null, $from, $toPlusOne) . '</td>';
        foreach ($ageRanges as $ageRange) {
            $table .= '<td>' . $this->getGroupedTestCounts($bloodChemistry, [Patient::MALE, Patient::FEMALE], $ageRange, $from, $toPlusOne) . '</td>';
        }
        foreach ($measures as $measure) {
            $tMeasure = Measure::find($measure->measure_id);
            $table .= '<tr>
								<td>' . $tMeasure->name . '</td>';
            foreach ($sex as $gender) {
                $table .= '<td>' . $this->getTotalTestResults($tMeasure, [$gender], null, $from, $toPlusOne, null, null) . '</td>';
            }
            $table .= '<td>' . $this->getTotalTestResults($tMeasure, $sex, null, $from, $toPlusOne, ['Low', 'Normal', 'High'], null) . '</td>';
            foreach ($ranges as $range) {
                $table .= '<td>' . $this->getTotalTestResults($tMeasure, null, null, $from, $toPlusOne, [$range], 1) . '</td>';
            }
            $table .= '</tr>';
        }
        $table .= '<tr>
							<td>OGTT</td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
					</tbody>
				</table>
				<table class="table table-condensed report-table-border">
					<thead>
						<tr>
							<th rowspan="2">Renal function tests</th>
							<th colspan="2">No. Exam</th>
							<th colspan="4"> Number positive</th>
						</tr>
						<tr>
							<th>M</th>
							<th>F</th>
							<th>Total</th>
							<th>Low</th>
							<th>Normal</th>
							<th>High</th>
						</tr>
					</thead>
					<tbody>';
        $rfts = TestType::getTestTypeIdByTestName('RFTS');
        $rft = TestType::find($rfts);
        $measures = TestTypeMeasure::where('test_type_id', $rfts)->orderBy('measure_id', 'DESC')->get();
        $table .= '<tr>
						<td>Totals</td>';
        foreach ($sex as $gender) {
            $table .= '<td>' . $this->getGroupedTestCounts($rft, [$gender], null, $from, $toPlusOne) . '</td>';
        }
        $table .= '<td>' . $this->getGroupedTestCounts($rft, null, null, $from, $toPlusOne) . '</td>';
        foreach ($ageRanges as $ageRange) {
            $table .= '<td>' . $this->getGroupedTestCounts($rft, [Patient::MALE, Patient::FEMALE], $ageRange, $from, $toPlusOne) . '</td>';
        }
        $table .= '</tr>';
        foreach ($measures as $measure) {
            $name = Measure::find($measure->measure_id)->name;
            if ($name == 'Electrolytes') {
                continue;
            }
            $tMeasure = Measure::find($measure->measure_id);
            $table .= '<tr>
								<td>' . $tMeasure->name . '</td>';
            foreach ($sex as $gender) {
                $table .= '<td>' . $this->getTotalTestResults($tMeasure, [$gender], null, $from, $toPlusOne, null, null) . '</td>';
            }
            $table .= '<td>' . $this->getTotalTestResults($tMeasure, $sex, null, $from, $toPlusOne, null, 1) . '</td>';
            foreach ($ranges as $range) {
                $table .= '<td>' . $this->getTotalTestResults($tMeasure, null, null, $from, $toPlusOne, [$range], 1) . '</td>';
            }
            $table .= '</tr>';
        }
        $table .= '</tbody>
				</table>
				<table class="table table-condensed report-table-border">
					<thead>
						<tr>
							<th rowspan="2">Liver Function Tests</th>
							<th colspan="2">No. Exam</th>
							<th colspan="4"> Number positive</th>
						</tr>
						<tr>
							<th>M</th>
							<th>F</th>
							<th>Total</th>
							<th>Low</th>
							<th>Normal</th>
							<th>High</th>
						</tr>
					</thead>
					<tbody>';
        $lfts = TestType::getTestTypeIdByTestName('LFTS');
        $lft = TestType::find($lfts);
        $measures = TestTypeMeasure::where('test_type_id', $lfts)->orderBy('measure_id', 'DESC')->get();
        $table .= '<tr>
						<td>Totals</td>';
        foreach ($sex as $gender) {
            $table .= '<td>' . $this->getGroupedTestCounts($lft, [$gender], null, $from, $toPlusOne) . '</td>';
        }
        $table .= '<td>' . $this->getGroupedTestCounts($lft, null, null, $from, $toPlusOne) . '</td>';
        foreach ($ageRanges as $ageRange) {
            $table .= '<td>' . $this->getGroupedTestCounts($lft, [Patient::MALE, Patient::FEMALE], $ageRange, $from, $toPlusOne) . '</td>';
        }
        $table .= '</tr>';
        foreach ($measures as $measure) {
            $name = Measure::find($measure->measure_id)->name;
            if ($name == 'SGOT') {
                $name = 'ASAT (SGOT)';
            }
            if ($name == 'ALAT') {
                $name = 'ASAT (SGPT)';
            }
            if ($name == 'Total Proteins') {
                $name = 'Serum Protein';
            }
            $tMeasure = Measure::find($measure->measure_id);
            $table .= '<tr>
								<td>' . $tMeasure->name . '</td>';
            foreach ($sex as $gender) {
                $table .= '<td>' . $this->getTotalTestResults($tMeasure, [$gender], null, $from, $toPlusOne, null, null) . '</td>';
            }
            $table .= '<td>' . $this->getTotalTestResults($tMeasure, $sex, null, $from, $toPlusOne, null, 1) . '</td>';
            foreach ($ranges as $range) {
                $table .= '<td>' . $this->getTotalTestResults($tMeasure, null, null, $from, $toPlusOne, [$range], 1) . '</td>';
            }
            $table .= '</tr>';
        }
        $table .= '<tr>
							<td>Gamma GT</td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
					</tbody>
				</table>
				<table class="table table-condensed report-table-border">
					<thead>
						<tr>
							<th rowspan="2">Lipid Profile</th>
							<th colspan="2">No. Exam</th>
							<th colspan="4"> Number positive</th>
						</tr>
						<tr>
							<th>M</th>
							<th>F</th>
							<th>Total</th>
							<th>Low</th>
							<th>Normal</th>
							<th>High</th>
						</tr>
					</thead>
					<tbody>
						<tr>
							<td>Totals</td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
						</tr><tr>
							<td>Amylase</td>';
        $tMeasure = Measure::find(Measure::getMeasureIdByName('Serum Amylase'));
        foreach ($sex as $gender) {
            $table .= '<td>' . $this->getTotalTestResults($tMeasure, [$gender], null, $from, $toPlusOne, null, null) . '</td>';
        }
        $table .= '<td>' . $this->getTotalTestResults($tMeasure, $sex, null, $from, $toPlusOne, null, 1) . '</td>';
        foreach ($ranges as $range) {
            $table .= '<td>' . $this->getTotalTestResults($tMeasure, null, $ageRange, $from, $toPlusOne, [$range], 1) . '</td>';
        }
        $table .= '</tr><tr>
							<td>Total cholestrol</td>';
        $tMeasure = Measure::find(Measure::getMeasureIdByName('cholestrol'));
        foreach ($sex as $gender) {
            $table .= '<td>' . $this->getTotalTestResults($tMeasure, [$gender], null, $from, $toPlusOne, null, null) . '</td>';
        }
        $table .= '<td>' . $this->getTotalTestResults($tMeasure, $sex, null, $from, $toPlusOne, null, 1) . '</td>';
        foreach ($ranges as $range) {
            $table .= '<td>' . $this->getTotalTestResults($tMeasure, null, null, $from, $toPlusOne, [$range], 1) . '</td>';
        }
        $table .= '</tr><tr>
							<td>Tryglycerides</td>';
        $tMeasure = Measure::find(Measure::getMeasureIdByName('Tryglycerides'));
        foreach ($sex as $gender) {
            $table .= '<td>' . $this->getTotalTestResults($tMeasure, [$gender], null, $from, $toPlusOne, null, null) . '</td>';
        }
        $table .= '<td>' . $this->getTotalTestResults($tMeasure, $sex, null, $from, $toPlusOne, null, 1) . '</td>';
        foreach ($ranges as $range) {
            $table .= '<td>' . $this->getTotalTestResults($tMeasure, null, null, $from, $toPlusOne, [$range], 1) . '</td>';
        }
        $table .= '</tr><tr>
							<td>HDL</td>';
        $tMeasure = Measure::find(Measure::getMeasureIdByName('HDL'));
        foreach ($sex as $gender) {
            $table .= '<td>' . $this->getTotalTestResults($tMeasure, [$gender], null, $from, $toPlusOne, null, null) . '</td>';
        }
        $table .= '<td>' . $this->getTotalTestResults($tMeasure, $sex, null, $from, $toPlusOne, null, 1) . '</td>';
        foreach ($ranges as $range) {
            $table .= '<td>' . $this->getTotalTestResults($tMeasure, null, null, $from, $toPlusOne, [$range], 1) . '</td>';
        }
        $table .= '</tr><tr>
							<td>LDL</td>';
        $tMeasure = Measure::find(Measure::getMeasureIdByName('LDL'));
        foreach ($sex as $gender) {
            $table .= '<td>' . $this->getTotalTestResults($tMeasure, [$gender], null, $from, $toPlusOne, null, null) . '</td>';
        }
        $table .= '<td>' . $this->getTotalTestResults($tMeasure, $sex, null, $from, $toPlusOne, null, 1) . '</td>';
        foreach ($ranges as $range) {
            $table .= '<td>' . $this->getTotalTestResults($tMeasure, null, null, $from, $toPlusOne, [$range], 1) . '</td>';
        }
        $table .= '</tr>
					</tbody>
				</table>
				<table class="table table-condensed report-table-border">
					<thead>
						<tr>
							<th rowspan="2">CSF Chemistry</th>
							<th colspan="2">No. Exam</th>
							<th colspan="4"> Number positive</th>
						</tr>
						<tr>
							<th>M</th>
							<th>F</th>
							<th>Total</th>
							<th>Low</th>
							<th>Normal</th>
							<th>High</th>
						</tr>
					</thead>
					<tbody>';
        $csf = TestType::getTestTypeIdByTestName('CSF for biochemistry');
        $bioCsf = TestType::find($csf);
        $table .= '<tr>
					<td>Totals</td>';
        foreach ($sex as $gender) {
            $table .= '<td>' . $this->getGroupedTestCounts($bioCsf, [$gender], null, $from, $toPlusOne) . '</td>';
        }
        $table .= '<td>' . $this->getGroupedTestCounts($bioCsf, null, null, $from, $toPlusOne) . '</td>';
        foreach ($ageRanges as $ageRange) {
            $table .= '<td>' . $this->getGroupedTestCounts($bioCsf, [Patient::MALE, Patient::FEMALE], $ageRange, $from, $toPlusOne) . '</td>';
        }
        $table .= '</tr>';
        $measures = TestTypeMeasure::where('test_type_id', $csf)->orderBy('measure_id', 'DESC')->get();
        foreach ($measures as $measure) {
            $name = Measure::find($measure->measure_id)->name;
            $table .= '<tr>
							<td>' . $name . '</td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>';
        }
        $table .= '</tbody>
				</table>
				<table class="table table-condensed report-table-border">
					<thead>
						<tr>
							<th rowspan="2">Body Fluids</th>
							<th colspan="2">No. Exam</th>
							<th colspan="4"> Number positive</th>
						</tr>
						<tr>
							<th>M</th>
							<th>F</th>
							<th>Total</th>
							<th>Low</th>
							<th>Normal</th>
							<th>High</th>
						</tr>
					</thead>
					<tbody>
						<tr>
							<td>Totals</td>
							<td>0</td>
							<td>0</td>
							<td>0</td>
							<td>0</td>
							<td>0</td>
							<td>0</td>
						</tr>
						<tr>
							<td>Proteins</td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
						<tr>
							<td>Glucose</td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
						<tr>
							<td>Acid phosphatase</td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
						<tr>
							<td>Bence jones protein</td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
					</tbody>
				</table>
				<table class="table table-condensed report-table-border">
					<thead>
						<tr>
							<th rowspan="2">Thyroid Function Tests</th>
							<th colspan="2">No. Exam</th>
							<th colspan="4"> Number positive</th>
						</tr>
						<tr>
							<th>M</th>
							<th>F</th>
							<th>Total</th>
							<th>Low</th>
							<th>Normal</th>
							<th>High</th>
						</tr>
					</thead>
					<tbody>';
        $tfts = TestType::getTestTypeIdByTestName('TFT');
        $tft = TestType::find($tfts);
        $table .= '<tr>
					<td>Totals</td>';
        foreach ($sex as $gender) {
            $table .= '<td>' . $this->getGroupedTestCounts($tft, [$gender], null, $from, $toPlusOne) . '</td>';
        }
        $table .= '<td>' . $this->getGroupedTestCounts($tft, null, null, $from, $toPlusOne) . '</td>';
        foreach ($ageRanges as $ageRange) {
            $table .= '<td>' . $this->getGroupedTestCounts($tft, [Patient::MALE, Patient::FEMALE], $ageRange, $from, $toPlusOne) . '</td>';
        }
        $table .= '</tr>';
        $measures = TestTypeMeasure::where('test_type_id', $tfts)->orderBy('measure_id', 'ASC')->get();
        foreach ($measures as $measure) {
            $tMeasure = Measure::find($measure->measure_id);
            $table .= '<tr>
						<td>' . $tMeasure->name . '</td>';
            foreach ($sex as $gender) {
                $table .= '<td>' . $this->getTotalTestResults($tMeasure, [$gender], null, $from, $toPlusOne, null, null) . '</td>';
            }
            $table .= '<td>' . $this->getTotalTestResults($tMeasure, $sex, null, $from, $toPlusOne, null, 1) . '</td>';
            foreach ($ranges as $range) {
                $table .= '<td>' . $this->getTotalTestResults($tMeasure, null, null, $from, $toPlusOne, [$range]) . '</td>';
            }
            $table .= '</tr>';
        }
        $table .= '<tr>
							<td>Others</td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
					</tbody>
				</table>
			</div>
			<!-- URINALYSIS -->
			<!-- PARASITOLOGY -->
			<div class="col-sm-12">
				<strong>PARASITOLOGY</strong>
				<table class="table table-condensed report-table-border">
					<thead>
						<tr>
							<th colspan="5">Blood Smears</th>
						</tr>
						<tr>
							<th rowspan="2">Malaria</th>
							<th colspan="4">Positive</th>
						</tr>
						<tr>
							<th>Total Done</th>
							<th>&lt;5yrs</th>
							<th>5-14yrs</th>
							<th>&gt;14yrs</th>
						</tr>
					</thead>';
        $bs = TestType::getTestTypeIdByTestName('Bs for mps');
        $bs4mps = TestType::find($bs);
        $table .= '<tbody>
						<tr>
							<td></td>
							<td>' . $this->getGroupedTestCounts($bs4mps, null, null, $from, $toPlusOne) . '</td>';
        foreach ($ageRanges as $ageRange) {
            $table .= '<td>' . $this->getGroupedTestCounts($bs4mps, null, $ageRange, $from, $toPlusOne) . '</td>';
        }
        $table .= '</tr>
						<tr style="text-align:right;">
							<td>Falciparum</td>
							<td style="background-color: #CCCCCC;"></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
						<tr style="text-align:right;">
							<td>Ovale</td>
							<td style="background-color: #CCCCCC;"></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
						<tr style="text-align:right;">
							<td>Malariae</td>
							<td style="background-color: #CCCCCC;"></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
						<tr style="text-align:right;">
							<td>Vivax</td>
							<td style="background-color: #CCCCCC;"></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
						<tr>
							<td><strong>Borrelia</strong></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
						<tr>
							<td><strong>Microfilariae</strong></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
						<tr>
							<td><strong>Trypanosomes</strong></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
						<tr>
							<td colspan="5"><strong>Genital Smears</strong></td>
						</tr>
						<tr>
							<td>Total</td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
						<tr>
							<td>T. vaginalis</td>
							<td style="background-color: #CCCCCC;"></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
						<tr>
							<td>S. haematobium</td>
							<td style="background-color: #CCCCCC;"></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
						<tr>
							<td>Yeast cells</td>
							<td style="background-color: #CCCCCC;"></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
						<tr>
							<td>Others</td>
							<td style="background-color: #CCCCCC;"></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
						<tr>
							<td colspan="5"><strong>Spleen/bone marrow</strong></td>
						</tr>
						<tr>
							<td>Total</td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
						<tr>
							<td>L. donovani</td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
						<tr>';
        $stool = TestType::getTestTypeIdByTestName('Stool for O/C');
        $stoolForOc = TestType::find($stool);
        $measures = TestTypeMeasure::where('test_type_id', $stool)->orderBy('measure_id', 'DESC')->get();
        $table .= '<td colspan="5"><strong>Stool</strong></td>
						</tr>
						<tr>
							<td>Total</td>
							<td>' . $this->getGroupedTestCounts($stoolForOc, null, null, $from, $toPlusOne) . '</td>';
        foreach ($ageRanges as $ageRange) {
            $table .= '<td>' . $this->getGroupedTestCounts($stoolForOc, null, $ageRange, $from, $toPlusOne) . '</td>';
        }
        $table .= '</tr>';
        foreach ($measures as $measure) {
            $tMeasure = Measure::find($measure->measure_id);
            foreach ($tMeasure->measureRanges as $range) {
                if ($range->alphanumeric == 'O#C not seen') {
                    continue;
                }
                $table .= '<tr>
									<td>' . $range->alphanumeric . '</td>';
                $table .= '<td style="background-color: #CCCCCC;"></td>';
                foreach ($ageRanges as $ageRange) {
                    $table .= '<td>' . $this->getTotalTestResults($tMeasure, null, $ageRange, $from, $toPlusOne, [$range->alphanumeric]) . '</td>';
                }
                $table .= '</tr>';
            }
        }
        $table .= '<tr>
							<td colspan="5"><strong>Lavages</strong></td>
						</tr>
						<tr>
							<td>Total</td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
					</tbody>
				</table>
			</div>
			<!-- PARASITOLOGY -->
			<!-- BACTERIOLOGY -->
			<div class="col-sm-12">
				<strong>BACTERIOLOGY</strong>
				<div class="row">
					<div class="col-sm-4">
						<table class="table table-condensed report-table-border" style="padding-right:5px;">
							<tbody style="text-align:right;">
								<tr>
									<td>Total examinations done</td>
									<td></td>
								</tr>';
        foreach ($specTypeIds as $key) {
            if (in_array(SpecimenType::find($key->spec_id)->name, ['Aspirate', 'Pleural Tap', 'Synovial Fluid', 'Sputum', 'Ascitic Tap', 'S***n', 'Skin'])) {
                continue;
            }
            $totalCount = DB::select(DB::raw("select count(specimen_id) as per_spec_count from tests" . " join specimens on tests.specimen_id=specimens.id" . " join test_types on tests.test_type_id=test_types.id" . " where specimens.specimen_type_id=?" . " and test_types.test_category_id=?" . " and test_status_id in(?,?)" . " and tests.time_created BETWEEN ? and ?;"), [$key->spec_id, $labSecId, Test::COMPLETED, Test::VERIFIED, $from, $toPlusOne]);
            $table .= '<tr>
									<td>' . SpecimenType::find($key->spec_id)->name . '</td>
									<td>' . $totalCount[0]->per_spec_count . '</td>
								</tr>';
        }
        $table .= '</tr>
									<td>Rectal swab</td>
									<td>0</td>
								</tr>
								</tr>
									<td>Water</td>
									<td>0</td>
								</tr>
								</tr>
									<td>Food</td>
									<td>0</td>
								</tr>
								</tr>
									<td>Other (specify)....</td>
									<td></td>
								</tr>
							</tbody>
						</table>
					</div>
					<div class="col-sm-8">
						<table class="table table-condensed report-table-border">
							<tbody>
								<tr>
									<td colspan="3">Drugs</td>
									<td></td>
									<td></td>
									<td></td>
									<td></td>
									<td></td>
								</tr>
								<tr>
									<td colspan="3">Sensitivity (Total done)</td>
									<td></td>
									<td></td>
									<td></td>
									<td></td>
									<td></td>
								</tr>
								<tr>
									<td colspan="3">Resistance per drug</td>
									<td></td>
									<td></td>
									<td></td>
									<td></td>
									<td></td>
								</tr>
								<tr>
									<td rowspan="3">KOH Preparations</td>
									<td>Fungi</td>
									<td></td>
									<td></td>
									<td></td>
									<td></td>
									<td colspan="2">Others (specify)</td>
								</tr>
								<tr>
									<td>Others</td>
									<td></td>
									<td></td>
									<td></td>
									<td></td>
									<td>...</td>
									<td></td>
								</tr>
								<tr>
									<td>Total</td>
									<td></td>
									<td></td>
									<td></td>
									<td></td>
									<td>...</td>
									<td></td>
								</tr>
							</tbody>
						</table>
						<p>SPUTUM</p>
						<table class="table table-condensed report-table-border">
							<tbody>
								<tr>
									<td></td>
									<td>Total</td>
									<td>Positive</td>
								</tr>
								<tr>
									<td>TB new suspects</td>
									<td></td>
									<td></td>
								</tr>
								<tr>
									<td>Followup</td>
									<td></td>
									<td></td>
								</tr>
								<tr>
									<td>TB smears</td>
									<td></td>
									<td></td>
								</tr>
								<tr>
									<td>MDR</td>
									<td></td>
									<td></td>
								</tr>
							</tbody>
						</table>
					</div>
				</div>
				<table class="table table-condensed report-table-border">
					<tbody>
						<tr><td></td>';
        foreach ($specimen_types as $spec) {
            $table .= '<td>' . $spec . '</td>';
        }
        $table .= '</tr>';
        foreach ($isolates as $isolate) {
            $table .= '<tr>
							<td>' . $isolate . '</td>';
            foreach ($specimen_types as $spec) {
                $table .= '<td>' . TestResult::microCounts($isolate, $spec, $from, $toPlusOne)[0]->total . '</td>';
            }
            $table .= '</tr>';
        }
        $table .= '<tr>
							<td colspan="11">Specify species of each isolate</td>
						</tr>
					</tbody>
				</table>
				<div class="row">
					<div class="col-sm-12">
						<strong>HEMATOLOGY REPORT</strong>
						<table class="table table-condensed report-table-border">
							<thead>
								<tr>
									<th colspan="2">Type of examination</th>
									<th>No. of Tests</th>
									<th>Controls</th>
								</tr>
							</thead>
							<tbody>
								<tr>
									<td colspan="2">Full blood count</td>
									<td>' . $this->getGroupedTestCounts(TestType::find(TestType::getTestTypeIdByTestName('Full haemogram')), null, null, $from, $toPlusOne) . '</td>
									<td></td>
								</tr>
								<tr>
									<td colspan="2">Manual WBC counts</td>
									<td></td>
									<td></td>
								</tr>
								<tr>
									<td colspan="2">Peripheral blood films</td>
									<td></td>
									<td></td>
								</tr>
								<tr>
									<td colspan="2">Erythrocyte Sedimentation rate</td>
									<td>' . $this->getGroupedTestCounts(TestType::find(TestType::getTestTypeIdByTestName('ESR')), null, null, $from, $toPlusOne) . '</td>
									<td></td>
								</tr>
								<tr>
									<td colspan="2">Sickling test</td>
									<td>' . $this->getGroupedTestCounts(TestType::find(TestType::getTestTypeIdByTestName('Sickling test')), null, null, $from, $toPlusOne) . '</td>
									<td></td>
								</tr>
								<tr>
									<td colspan="2">HB electrophoresis</td>
									<td></td>
									<td></td>
								</tr>
								<tr>
									<td colspan="2">G6PD screening</td>
									<td></td>
									<td></td>
								</tr>
								<tr>
									<td colspan="2">Bleeding time</td>
									<td>' . $this->getGroupedTestCounts(TestType::find(TestType::getTestTypeIdByTestName('Bleeding time test')), null, null, $from, $toPlusOne) . '</td>
									<td></td>
								</tr>
								<tr>
									<td colspan="2">Clotting time</td>
									<td>' . $this->getGroupedTestCounts(TestType::find(TestType::getTestTypeIdByTestName('Clotting time test')), null, null, $from, $toPlusOne) . '</td>
									<td></td>
								</tr>
								<tr>
									<td colspan="2">Prothrombin test</td>
									<td></td>
									<td></td>
								</tr>
								<tr>
									<td colspan="2">Partial prothrombin time</td>
									<td></td>
									<td></td>
								</tr>
								<tr>
									<td colspan="2">Bone Marrow Aspirates</td>
									<td></td>
									<td style="background-color: #CCCCCC;"></td>
								</tr>
								<tr>
									<td colspan="2">Reticulocyte counts</td>
									<td></td>
									<td style="background-color: #CCCCCC;"></td>
								</tr>
								<tr>
									<td colspan="2">Others</td>
									<td></td>
									<td style="background-color: #CCCCCC;"></td>
								</tr>
								<tr>
									<td rowspan="2">Haemoglobin</td>
									<td>No. Tests</td>
									<td>&lt;5</td>
									<td>5&lt;Hb&lt;10</td>
								</tr>
								<tr>
									<td>' . $this->getGroupedTestCounts(TestType::find(TestType::getTestTypeIdByTestName('HB')), null, null, $from, $toPlusOne) . '</td>
									<td></td>
									<td></td>
								</tr>
								<tr>
									<td rowspan="2">CD4/CD8</td>
									<td>No. Tests</td>
									<td>&lt;200</td>
									<td>200-350</td>
								</tr>
								<tr>
									<td></td>
									<td></td>
									<td></td>
								</tr>
								<tr>
									<td rowspan="2">CD4%</td>
									<td>No. Tests</td>
									<td>&lt;25%</td>
									<td>&gt;25%</td>
								</tr>
								<tr>
									<td></td>
									<td></td>
									<td></td>
								</tr>
								<tr>
									<td rowspan="2">Peripheral Blood Films</td>
									<td>Parasites</td>
									<td colspan="2">No. smears with inclusions</td>
								</tr>
								<tr>
									<td></td>
									<td></td>
									<td colspan="2"></td>
								</tr>
							</tbody>
						</table>
					</div>
					<div class="col-sm-12">
						<strong>BLOOD GROUPING AND CROSSMATCH REPORT</strong>
						<div class="row">
							<div class="col-sm-6">
								<table class="table table-condensed report-table-border">
									<tbody>
										<tr>
											<td>Total groupings done</td>
											<td>' . $this->getGroupedTestCounts(TestType::find(TestType::getTestTypeIdByTestName('GXM')), null, null, $from, $toPlusOne) . '</td>
										</tr>
										<tr>
											<td>Blood units grouped</td>
											<td>' . $this->getGroupedTestCounts(TestType::find(TestType::getTestTypeIdByTestName('Blood Grouping')), null, null, $from, $toPlusOne) . '</td>
										</tr>
										<tr>
											<td>Total transfusion reactions</td>
											<td></td>
										</tr>
										<tr>
											<td>Blood cross matches</td>
											<td>' . $this->getGroupedTestCounts(TestType::find(TestType::getTestTypeIdByTestName('Cross Match')), null, null, $from, $toPlusOne) . '</td>
										</tr>
									</tbody>
								</table>
							</div>
							<div class="col-sm-6">
								<strong>Blood safety</strong>
								<table class="table table-condensed report-table-border">
									<tbody>
										<tr>
											<td>Measure</td>
											<td>Number</td>
										</tr>
										<tr>
											<td>A. Blood units collected from regional blood transfusion centres</td>
											<td></td>
										</tr>
										<tr>
											<td>Blood units collected from other centres and screened at health facility</td>
											<td></td>
										</tr>
										<tr>
											<td>Blood units screened at health facility that are HIV positive</td>
											<td></td>
										</tr>
										<tr>
											<td>Blood units screened at health facility that are Hepatitis positive</td>
											<td></td>
										</tr>
										<tr>
											<td>Blood units positive for other infections</td>
											<td></td>
										</tr>
										<tr>
											<td>Blood units transfered</td>
											<td></td>
										</tr>
										<tr>
											<td rowspan="2">General remarks .............................</td>
											<td rowspan="2"></td>
										</tr>
									</tbody>
								</table>
							</div>
						</div>
					</div>
				</div>
			</div>
			<!-- BACTERIOLOGY -->
			<!-- HISTOLOGY AND CYTOLOGY -->
			<div class="col-sm-12">
				<strong>HISTOLOGY AND CYTOLOGY REPORT</strong>
				<table class="table table-condensed report-table-border">
					<thead>
						<tr>
							<th rowspan="2"></th>
							<th rowspan="2">Total</th>
							<th rowspan="2">Normal</th>
							<th rowspan="2">Infective</th>
							<th colspan="2">Non-infective</th>
							<th colspan="3">Positive findings</th>
						</tr>
						<tr>
							<th>Benign</th>
							<th>Malignant</th>
							<th>&lt;5 yrs</th>
							<th>5-14 yrs</th>
							<th>&gt;14 yrs</th>
						</tr>
					</thead>
					<tbody>
						<tr>
							<td colspan="9">SMEARS</td>
						</tr>
						<tr>
							<td>Pap Smear</td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
						<tr>
							<td>Tissue Impressions</td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
						<tr>
							<td colspan="9">TISSUE ASPIRATES (FNA)</td>
						</tr>
						<tr>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
						<tr>
							<td colspan="9">FLUID CYTOLOGY</td>
						</tr>
						<tr>
							<td>Ascitic fluid</td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
						<tr>
							<td>CSF</td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
						<tr>
							<td>Pleural fluid</td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
						<tr>
							<td>Others</td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
						<tr>
							<td colspan="9">TISSUE HISTOLOGY</td>
						</tr>
						<tr>
							<td>Cervix</td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
						<tr>
							<td>Prostrate</td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
						<tr>
							<td>Breast</td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
						<tr>
							<td>Ovarian cyst</td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
						<tr>
							<td>Fibroids</td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
						<tr>
							<td>Lymph nodes</td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
						<tr>
							<td>Others</td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
					</tbody>
				</table>
				<strong>SEROLOGY REPORT</strong>
				<table class="table table-condensed report-table-border">
					<thead>
						<tr>
							<th rowspan="2">Serological test</th>
							<th colspan="2">Total</th>
							<th colspan="2">&lt;5 yrs</th>
							<th colspan="2">5-14 yrs</th>
							<th colspan="2">&gt;14 yrs</th>
						</tr>
						<tr>
							<th>Tested</th>
							<th>No. +ve</th>
							<th>Tested</th>
							<th>No. +ve</th>
							<th>Tested</th>
							<th>No. +ve</th>
							<th>Tested</th>
							<th>No. +ve</th>
						</tr>
					</thead>
					<tbody>
						<tr>
							<td>Rapid Plasma Region</td>';
        if (count(TestType::getPrevalenceCounts($from, $to, TestType::getTestTypeIdByTestName('VDRL'))) == 0) {
            $table .= '<td>0</td>
									<td>0</td>';
        } else {
            foreach (TestType::getPrevalenceCounts($from, $to, TestType::getTestTypeIdByTestName('VDRL')) as $count) {
                if (count($count) == 0) {
                    $count->total = 0;
                    $count->positive = 0;
                }
                $table .= '<td>' . $count->total . '</td>
									<td>' . $count->positive . '</td>';
            }
        }
        foreach ($ageRanges as $ageRange) {
            if (count(TestType::getPrevalenceCounts($from, $to, TestType::getTestTypeIdByTestName('VDRL'), $ageRange)) == 0) {
                $table .= '<td>0</td>
									<td>0</td>';
            } else {
                foreach (TestType::getPrevalenceCounts($from, $to, TestType::getTestTypeIdByTestName('VDRL'), $ageRange) as $count) {
                    $table .= '<td>' . $count->total . '</td>
										<td>' . $count->positive . '</td>';
                }
            }
        }
        $table .= '</tr>
						<tr>
							<td>TPHA</td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
						<tr>
							<td>ASO Test</td>';
        if (count(TestType::getPrevalenceCounts($from, $to, TestType::getTestTypeIdByTestName('Asot'))) == 0) {
            $table .= '<td>0</td>
									<td>0</td>';
        } else {
            foreach (TestType::getPrevalenceCounts($from, $to, TestType::getTestTypeIdByTestName('Asot')) as $count) {
                if (count($count) == 0) {
                    $count->total = 0;
                    $count->positive = 0;
                }
                $table .= '<td>' . $count->total . '</td>
									<td>' . $count->positive . '</td>';
            }
        }
        foreach ($ageRanges as $ageRange) {
            $data = TestType::getPrevalenceCounts($from, $to, TestType::getTestTypeIdByTestName('Asot'), $ageRange);
            if (count($data) == 0) {
                $table .= '<td>0</td>
									<td>0</td>';
            } else {
                foreach ($data as $count) {
                    $table .= '<td>' . $count->total . '</td>
										<td>' . $count->positive . '</td>';
                }
            }
        }
        $table .= '</tr>
						<tr>
							<td>HIV Test</td>';
        if (count(TestType::getPrevalenceCounts($from, $to, TestType::getTestTypeIdByTestName('Rapid HIV test'))) == 0) {
            $table .= '<td>0</td>
									<td>0</td>';
        } else {
            foreach (TestType::getPrevalenceCounts($from, $to, TestType::getTestTypeIdByTestName('Rapid HIV test')) as $count) {
                if (count($count) == 0) {
                    $count->total = 0;
                    $count->positive = 0;
                }
                $table .= '<td>' . $count->total . '</td>
									<td>' . $count->positive . '</td>';
            }
        }
        foreach ($ageRanges as $ageRange) {
            $data = TestType::getPrevalenceCounts($from, $to, TestType::getTestTypeIdByTestName('Rapid HIV test'), $ageRange);
            if (count($data) == 0) {
                $table .= '<td>0</td>
									<td>0</td>';
            } else {
                foreach ($data as $count) {
                    $table .= '<td>' . $count->total . '</td>
										<td>' . $count->positive . '</td>';
                }
            }
        }
        $table .= '</tr>
						<tr>
							<td>Widal Test</td>';
        if (count(TestType::getPrevalenceCounts($from, $to, TestType::getTestTypeIdByTestName('Widal'))) == 0) {
            $table .= '<td>0</td>
									<td>0</td>';
        } else {
            foreach (TestType::getPrevalenceCounts($from, $to, TestType::getTestTypeIdByTestName('Widal')) as $count) {
                if (count($count) == 0) {
                    $count->total = 0;
                    $count->positive = 0;
                }
                $table .= '<td>' . $count->total . '</td>
									<td>' . $count->positive . '</td>';
            }
        }
        foreach ($ageRanges as $ageRange) {
            $data = TestType::getPrevalenceCounts($from, $to, TestType::getTestTypeIdByTestName('Widal'), $ageRange);
            if (count($data) == 0) {
                $table .= '<td>0</td>
									<td>0</td>';
            } else {
                foreach ($data as $count) {
                    $table .= '<td>' . $count->total . '</td>
										<td>' . $count->positive . '</td>';
                }
            }
        }
        $table .= '</tr>
						<tr>
							<td>Brucella Test</td>';
        if (count(TestType::getPrevalenceCounts($from, $to, TestType::getTestTypeIdByTestName('Brucella'))) == 0) {
            $table .= '<td>0</td>
									<td>0</td>';
        } else {
            foreach (TestType::getPrevalenceCounts($from, $to, TestType::getTestTypeIdByTestName('Brucella')) as $count) {
                if (count($count) == 0) {
                    $count->total = 0;
                    $count->positive = 0;
                }
                $table .= '<td>' . $count->total . '</td>
									<td>' . $count->positive . '</td>';
            }
        }
        foreach ($ageRanges as $ageRange) {
            $data = TestType::getPrevalenceCounts($from, $to, TestType::getTestTypeIdByTestName('Brucella'), $ageRange);
            if (count($data) == 0) {
                $table .= '<td>0</td>
									<td>0</td>';
            } else {
                foreach ($data as $count) {
                    $table .= '<td>' . $count->total . '</td>
										<td>' . $count->positive . '</td>';
                }
            }
        }
        $table .= '</tr>
						<tr>
							<td>Rheumatoid Factor Tests</td>';
        if (count(TestType::getPrevalenceCounts($from, $to, TestType::getTestTypeIdByTestName('RF'))) == 0) {
            $table .= '<td>0</td>
									<td>0</td>';
        } else {
            foreach (TestType::getPrevalenceCounts($from, $to, TestType::getTestTypeIdByTestName('RF')) as $count) {
                if (count($count) == 0) {
                    $count->total = 0;
                    $count->positive = 0;
                }
                $table .= '<td>' . $count->total . '</td>
									<td>' . $count->positive . '</td>';
            }
        }
        foreach ($ageRanges as $ageRange) {
            $data = TestType::getPrevalenceCounts($from, $to, TestType::getTestTypeIdByTestName('RF'), $ageRange);
            if (count($data) == 0) {
                $table .= '<td>0</td>
									<td>0</td>';
            } else {
                foreach ($data as $count) {
                    $table .= '<td>' . $count->total . '</td>
										<td>' . $count->positive . '</td>';
                }
            }
        }
        $table .= '</tr>
						<tr>
							<td>Cryptococcal Antigen</td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
						<tr>
							<td>Helicobacter pylori test</td>';
        if (count(TestType::getPrevalenceCounts($from, $to, TestType::getTestTypeIdByTestName('H pylori'))) == 0) {
            $table .= '<td>0</td>
									<td>0</td>';
        } else {
            foreach (TestType::getPrevalenceCounts($from, $to, TestType::getTestTypeIdByTestName('H pylori')) as $count) {
                if (count($count) == 0) {
                    $count->total = 0;
                    $count->positive = 0;
                }
                $table .= '<td>' . $count->total . '</td>
									<td>' . $count->positive . '</td>';
            }
        }
        foreach ($ageRanges as $ageRange) {
            $data = TestType::getPrevalenceCounts($from, $to, TestType::getTestTypeIdByTestName('H pylori'), $ageRange);
            if (count($data) == 0) {
                $table .= '<td>0</td>
									<td>0</td>';
            } else {
                foreach ($data as $count) {
                    $table .= '<td>' . $count->total . '</td>
										<td>' . $count->positive . '</td>';
                }
            }
        }
        $table .= '</tr>
						<tr>
							<td>Hepatitis A test</td>
							<td>0</td>
							<td>0</td>
							<td>0</td>
							<td>0</td>
							<td>0</td>
							<td>0</td>
							<td>0</td>
							<td>0</td>';
        $table .= '</tr>
						<tr>
							<td>Hepatitis B test</td>';
        if (count(TestType::getPrevalenceCounts($from, $to, TestType::getTestTypeIdByTestName('Hepatitis B'))) == 0) {
            $table .= '<td>0</td>
									<td>0</td>';
        } else {
            foreach (TestType::getPrevalenceCounts($from, $to, TestType::getTestTypeIdByTestName('Hepatitis B')) as $count) {
                if (count($count) == 0) {
                    $count->total = 0;
                    $count->positive = 0;
                }
                $table .= '<td>' . $count->total . '</td>
									<td>' . $count->positive . '</td>';
            }
        }
        foreach ($ageRanges as $ageRange) {
            $data = TestType::getPrevalenceCounts($from, $to, TestType::getTestTypeIdByTestName('Hepatitis B'), $ageRange);
            if (count($data) == 0) {
                $table .= '<td>0</td>
									<td>0</td>';
            } else {
                foreach ($data as $count) {
                    $table .= '<td>' . $count->total . '</td>
										<td>' . $count->positive . '</td>';
                }
            }
        }
        $table .= '</tr>
						<tr>
							<td>Hepatitis C test</td>';
        if (count(TestType::getPrevalenceCounts($from, $to, TestType::getTestTypeIdByTestName('Hepatitis C'))) == 0) {
            $table .= '<td>0</td>
									<td>0</td>';
        } else {
            foreach (TestType::getPrevalenceCounts($from, $to, TestType::getTestTypeIdByTestName('Hepatitis C')) as $count) {
                if (count($count) == 0) {
                    $count->total = 0;
                    $count->positive = 0;
                }
                $table .= '<td>' . $count->total . '</td>
									<td>' . $count->positive . '</td>';
            }
        }
        foreach ($ageRanges as $ageRange) {
            $data = TestType::getPrevalenceCounts($from, $to, TestType::getTestTypeIdByTestName('Hepatitis C'), $ageRange);
            if (count($data) == 0) {
                $table .= '<td>0</td>
									<td>0</td>';
            } else {
                foreach ($data as $count) {
                    $table .= '<td>' . $count->total . '</td>
										<td>' . $count->positive . '</td>';
                }
            }
        }
        $table .= '</tr>
						<tr>
							<td>Viral Load</td>';
        if (count(TestType::getPrevalenceCounts($from, $to, TestType::getTestTypeIdByTestName('Viral load'))) == 0) {
            $table .= '<td>0</td>
									<td style="background-color: #CCCCCC;"></td>';
        } else {
            foreach (TestType::getPrevalenceCounts($from, $to, TestType::getTestTypeIdByTestName('Viral load')) as $count) {
                if (count($count) == 0) {
                    $count->total = 0;
                    $count->positive = 0;
                }
                $table .= '<td>' . $count->total . '</td>
									<td style="background-color: #CCCCCC;"></td>';
            }
        }
        foreach ($ageRanges as $ageRange) {
            $data = TestType::getPrevalenceCounts($from, $to, TestType::getTestTypeIdByTestName('Viral load'), $ageRange);
            if (count($data) == 0) {
                $table .= '<td>0</td>
									<td style="background-color: #CCCCCC;"></td>';
            } else {
                foreach ($data as $count) {
                    $table .= '<td>' . $count->total . '</td>
										<td style="background-color: #CCCCCC;"></td>';
                }
            }
        }
        $table .= '</tr>
						<tr>
							<td>Formal Gel Test</td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
						<tr>
							<td>Other Tests</td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
					</tbody>
				</table>
				<br />
				<table class="table table-condensed report-table-border">
					<thead>
						<tr>
							<th>Dried Blood Spots</th>
							<th>Tested</th>
							<th># +ve</th>
							<th>Discrepant</th>
						</tr>
					</thead>
					<tbody>
						<tr>
							<td>Early Infant Diagnosis of HIV</td>';
        if (count(TestType::getPrevalenceCounts($from, $to, TestType::getTestTypeIdByTestName('eid of hiv'))) == 0) {
            $table .= '<td>0</td>
									<td>0</td>';
        } else {
            foreach (TestType::getPrevalenceCounts($from, $to, TestType::getTestTypeIdByTestName('eid of hiv')) as $count) {
                if (count($count) == 0) {
                    $count->total = 0;
                    $count->positive = 0;
                }
                $table .= '<td>' . $count->total . '</td>
									<td>' . $count->positive . '</td>';
            }
        }
        $table .= '<td></td>
						</tr>
						<tr>
							<td>Quality Assurance</td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
						<tr>
							<td>Discordant couples</td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
						<tr>
							<td>Others</td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
					</tbody>
				</table>
				<p><strong>Specimen referral to higher levels</strong></p>
				<table class="table table-condensed report-table-border">
					<thead>
						<tr>
							<th>Specimen</th>
							<th>No</th>
							<th>Sent to</th>
							<th>No. of Reports/results received</th>
						</tr>
					</thead>
					<tbody>';
        if ($referredSpecimens) {
            foreach ($referredSpecimens as $referredSpecimen) {
                $table .= '<tr>
								<td>' . $referredSpecimen->spec . '</td>
								<td>' . $referredSpecimen->tot . '</td>
								<td>' . $referredSpecimen->facility . '</td>
								<td></td>
							</tr>';
            }
        } else {
            $table .= '<tr>
								<td colspan="4">' . trans('messages.no-records-found') . '</td>
							</tr>';
        }
        $table .= '</tbody>
				</table>
			</div>
			<!-- HISTOLOGY AND CYTOLOGY -->';
        if (Input::has('excel')) {
            $date = date("Ymdhi");
            $fileName = "MOH706_" . $date . ".xls";
            $headers = array("Content-type" => "text/html", "Content-Disposition" => "attachment;Filename=" . $fileName);
            $content = $table;
            return Response::make($content, 200, $headers);
        } else {
            //return View::make('reports.moh.706');
            return View::make('reports.moh.index')->with('table', $table)->with('from', $from)->with('end', $end);
        }
    }
コード例 #6
0
ファイル: Test.php プロジェクト: BaobabHealthTrust/iBLIS
 /**
  * @param  Measure IDs $measureIds array()
  * @return Ranges whose interpretation is positive $positiveRanges array()
  */
 public static function getPositiveRangesByMeasureIds($measureIds)
 {
     $positiveRanges = array();
     foreach ($measureIds as $measureId) {
         $measure = Measure::find($measureId);
         $measureRanges = $measure->measureRanges;
         foreach ($measureRanges as $measureRange) {
             if ($measureRange->interpretation == Test::POSITIVE) {
                 $positiveRanges[] = $measureRange->alphanumeric;
             }
         }
     }
     return $positiveRanges;
 }
コード例 #7
0
 /**
  * Remove the specified resource from storage (soft delete).
  *
  * @param  int  $id
  * @return Response
  */
 public function delete($id)
 {
     //Soft delete the measure
     $measure = Measure::find($id);
     $inUseByTesttype = $measure->testTypes->toArray();
     if (empty($inUseByTesttype)) {
         // The measure is not in use
         $measure->delete();
     } else {
         // The measure is in use
         return Redirect::route('measure.index')->with('message', trans('messages.failure-test-measure-in-use'));
     }
     // redirect
     return Redirect::route('measure.index')->with('message', trans('messages.success-deleting-measure'));
 }