Esempio n. 1
0
 public static function constructFromArray($props)
 {
     $name = $props['name'];
     $measures = array();
     if (isset($props['measures'])) {
         foreach ($props['measures'] as $measure) {
             if ($measure instanceof Measure) {
                 $measures[] = $measure;
             } else {
                 $measures[] = Measure::constructFromArray($measure);
             }
         }
     }
     return new Part($name, $measures);
 }
Esempio n. 2
0
 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;
 }
Esempio n. 3
0
 public function __construct(Measure $measure)
 {
     $this->measure = clone $measure;
     $this->measure->setTrack($measure->getTrack());
 }
Esempio n. 4
0
								<td><u><?php 
    echo LangUtil::$generalTerms['VALUES'];
    ?>
</u><?php 
    $page_elems->getAsterisk();
    ?>
</td>
								<td><u><?php 
    echo LangUtil::$generalTerms['UNIT'];
    ?>
 /Default Value</u>[<a href='#unit_help' rel='facebox'>?</a>]</td>
							</tr>
							<?php 
    $max_num_measures = count($measure_list);
    for ($i = 1; $i <= $max_num_measures; $i += 1) {
        $curr_measure = Measure::getById($measure_list[$i - 1]);
        if ($curr_measure != NULL) {
            $ref_ranges = $curr_measure->getReferenceRanges($_SESSION['lab_config_id']);
            ?>
								<input type='hidden' name='m_id[]' value='<?php 
            echo $measure_list[$i - 1];
            ?>
'></input>
								<?php 
            echo "<tr valign='top' id='mrow_{$i}' ";
            echo ">";
            echo "<td align='center'>";
            echo "<input type=checkbox name='delete_" . $curr_measure->measureId . "'  />";
            echo "</td><td>";
            echo "<input type='text' name='measure[]' value='{$curr_measure->name}' />";
            echo "</td>";
Esempio n. 5
0
 function getElapsedTime()
 {
     return $this->measure->getElapsedTime();
 }
 /**
  * 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);
 }
Esempio n. 7
0
 /**
  * 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');
 }
Esempio n. 8
0
<?php

#
# Returns token input values for "autocomplete" type measure
# Called via Ajax from results_entry.php
#
include "../includes/ajax_lib.php";
include "../includes/db_lib.php";
function find_matched($list, $search_string)
{
    $retval = array();
    foreach ($list as $value) {
        if (strcasecmp(substr($value, 0, strlen($search_string)), $search_string) == 0) {
            $retval[] = $value;
        }
    }
    return $retval;
}
$measure_id = $_REQUEST['id'];
$q = $_REQUEST['q'];
$measure = Measure::getById($measure_id);
$value_map = array();
$range_values = $measure->getRangeValues();
$matched_range_values = find_matched($range_values, $q);
foreach ($matched_range_values as $range_value) {
    $value_map[$range_value] = $range_value;
}
$json_params = array('id', 'name');
echo list_to_json($value_map, $json_params);
 /**
  * Tests the update funtion in the MeasureController
  * 
  * @return void
  */
 public function testIfDeleteWorks()
 {
     //Save again because teardown() dropped the db :(
     $this->runStore($this->inputNumeric);
     $measurestored = Measure::orderBy('id', 'desc')->take(1)->get()->toArray();
     $id = $measurestored[0]['id'];
     //To Do:: Delete for measureranges
     $measureController = new MeasureController();
     $measureController->delete($id);
     $measureidone = Measure::withTrashed()->find($id);
     $this->assertNotNull($measureidone->deleted_at);
 }
Esempio n. 10
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     // Get measures list
     $measures = Measure::lists('name', 'id');
     //Get the critical
     $critical = Critical::find($id);
     //Open the Edit View and pass to it the $critical
     return view('critical.edit')->with('critical', $critical)->with('measures', $measures);
 }
Esempio n. 11
0
            $pitch->transpose(-12);
            $note = new Note(array('pitch' => $p, 'duration' => 4, 'type' => 'quarter'));
            $chord->addNote($note);
        }
        $layer->addChord($chord);
    } else {
        $pitch = new Pitch($pitch);
        $pitch->transpose(-12);
        $note = new Note(array('pitch' => $pitch, 'duration' => 4, 'type' => 'quarter'));
        $layer->addNote($note);
    }
}
$measure->addLayer($layer);
$part->addMeasure($measure);
// 3nd measure
$measure = new Measure($measureOptions);
$layer = new Layer();
$note = new Note(array('pitch' => new Pitch('F2'), 'duration' => 8, 'type' => 'half'));
$layer->addNote($note);
$note = new Note(array('pitch' => new Pitch('G2'), 'duration' => 8, 'type' => 'half'));
$layer->addNote($note);
$measure->addLayer($layer);
$layer = new Layer();
$note = new Note(array('pitch' => new Pitch('G3'), 'duration' => 8, 'type' => 'half'));
$layer->addNote($note);
$note = new Note(array('pitch' => new Pitch('C#3'), 'duration' => 8, 'type' => 'half'));
$layer->addNote($note);
$measure->addLayer($layer);
$part->addMeasure($measure);
$score->addPart($part);
$xml2 = $score->toXML();
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     //Get the testtype
     $testtype = TestType::find($id);
     $measures = Measure::all();
     $measuretype = MeasureType::all()->sortBy('id');
     $specimentypes = SpecimenType::orderBy('name')->get();
     $testcategory = TestCategory::all();
     $organisms = Organism::orderBy('name')->get();
     //Open the Edit View and pass to it the $testtype
     return View::make('testtype.edit')->with('testtype', $testtype)->with('testcategory', $testcategory)->with('measures', $measures)->with('measuretype', $measuretype)->with('specimentypes', $specimentypes)->with('organisms', $organisms);
 }
Esempio n. 13
0
 /**
  * @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;
 }
 /**
  * Helper method used in update, create and andmin actions for 
  * extracting select boxes data for manifacturer, category and measure.
  *
  * @return array
  */
 private function getNeededDataLists()
 {
     return array('manifacturers' => Manifacturer::model()->listData, 'categories' => Category::model()->listData, 'measures' => Measure::model()->listData);
 }
Esempio n. 15
0
 /**
  * Import CSV file
  *
  * @param report_file_path The file path to import.
  * @param test_session_id The session's id.
  */
 public static function import_csv($report_file_path, $test_session_id, $conn, $merge_flag)
 {
     $qa_generic = sfConfig::get("app_table_qa_generic");
     // Retrieve table_name_id from table_name table
     $table_name_test_result = Doctrine_Core::getTable("TableName")->findOneByName("test_result");
     $table_name_test_result_id = $table_name_test_result->getId();
     $test_result_exists_flag = false;
     // Open the file
     $csv_report_file = @fopen($report_file_path, 'r');
     if ($csv_report_file) {
         // Get file first line
         $first_line = fgets($csv_report_file);
         // Detect delimiter
         if (preg_match("#,#", $first_line)) {
             $delimiter = ',';
         } else {
             if (preg_match("#;#", $first_line)) {
                 $delimiter = ';';
             } else {
                 return 2001;
             }
         }
         // Detect structure type
         // CSV old
         if (preg_match("#(?=.*Feature)(?=.*Check ?points)(?=.*Notes ?\\(bugs\\))(?=.*Status)#i", $first_line)) {
             // Return at the beginning of file
             fseek($csv_report_file, 0);
             // Determine order between different fields on the first line
             $idx = 0;
             $ref_tab = array();
             foreach (fgetcsv($csv_report_file, 0, $delimiter) as $element) {
                 if (preg_match("#^ ?Feature.?\$#i", $element)) {
                     $ref_tab[0] = $idx;
                 } elseif (preg_match("#^ ?Check ?points.?\$#i", $element)) {
                     $ref_tab[1] = $idx;
                 } elseif (preg_match("#^ ?Notes ?\\(bugs\\).?\$#i", $element)) {
                     $ref_tab[2] = $idx;
                 } elseif (preg_match("#^ ?Status.?\$#i", $element)) {
                     $ref_tab[3] = $idx;
                 } elseif (preg_match("#^ ?Duration.?\$#i", $element)) {
                     $ref_tab[4] = $idx;
                 } elseif (preg_match("#^ ?Bug.?\$#i", $element)) {
                     $ref_tab[5] = $idx;
                 }
                 $idx++;
             }
             // Go through file and fill datas
             $data_tab = array();
             while ($data_tab = fgetcsv($csv_report_file, 0, $delimiter)) {
                 if (count($data_tab) > 3) {
                     // Check if feature is not empty
                     if (empty($data_tab[$ref_tab[0]])) {
                         return 2101;
                     } else {
                         $feature = $data_tab[$ref_tab[0]];
                     }
                     // Check if check points is not empty
                     if (empty($data_tab[$ref_tab[1]])) {
                         return 2102;
                     } else {
                         $case_id = $data_tab[$ref_tab[1]];
                     }
                     // Check if status is not empty
                     if (empty($data_tab[$ref_tab[3]])) {
                         return 2103;
                     } else {
                         $status = $data_tab[$ref_tab[3]];
                     }
                     // Check if execution time is not empty
                     if (!empty($data_tab[$ref_tab[4]])) {
                         $executionTime = $data_tab[$ref_tab[4]];
                     } else {
                         $executionTime = 0;
                     }
                     // Check if bug list is not empty
                     if (!empty($data_tab[$ref_tab[5]])) {
                         $bugs = $data_tab[$ref_tab[5]];
                     } else {
                         $bugs = "";
                     }
                     // Write datas into qa_generic database
                     if (preg_match("#^ ?pass(ed)? ?\$#i", $status)) {
                         $decision_criteria_id = -1;
                     } else {
                         if (preg_match("#^ ?fail(ed)? ?\$#i", $status)) {
                             $decision_criteria_id = -2;
                         } else {
                             if (preg_match("#^ ?block(ed)? ?\$#i", $status)) {
                                 $decision_criteria_id = -3;
                             } else {
                                 if (preg_match("#^ ?defer(red)? ?\$#i", $status)) {
                                     $decision_criteria_id = -4;
                                 } else {
                                     if (preg_match("#^ ?not ?run ?\$#i", $status) || preg_match("#^ ?not_run ?\$#i", $status)) {
                                         $decision_criteria_id = -5;
                                     } else {
                                         return 2104;
                                     }
                                 }
                             }
                         }
                     }
                     // Status hard coded
                     $resultStatus = 0;
                     if ($merge_flag) {
                         // Retrieve test result id relying on test name and feature label, if it exists
                         $query = "SELECT tr.id tr_id\n\t\t\t\t\t\t\t\t\tFROM " . $qa_generic . ".test_result tr\n\t\t\t\t\t\t\t\t\t\tJOIN " . $qa_generic . ".table_name tn ON tn.name = 'test_result'\n\t\t\t\t\t\t\t\t\t\tJOIN " . $qa_generic . ".complementary_tool_relation ctr ON ctr.table_name_id = tn.id\n\t\t\t\t\t\t\t\t\t\t\tAND ctr.table_entry_id = tr.id\n\t\t\t\t\t\t\t\t\t\t\tAND ctr.label = '" . addslashes($feature) . "'\n\t\t\t\t\t\t\t\t\tWHERE tr.test_session_id = " . $test_session_id . "\n\t\t\t\t\t\t\t\t\t\tAND tr.name = '" . addslashes($case_id) . "'";
                         $result = Doctrine_Manager::getInstance()->getCurrentConnection()->execute($query)->fetch(PDO::FETCH_ASSOC);
                         if (!empty($result)) {
                             $test_result_exists_flag = true;
                             $testResultId = $result['tr_id'];
                         }
                     }
                     // Write into test_result table
                     if ($test_result_exists_flag) {
                         $testResult = Doctrine_Core::getTable("TestResult")->findOneById($testResultId);
                     } else {
                         $testResult = new TestResult();
                         $testResult->setName($case_id);
                         $testResult->setTestSessionId($test_session_id);
                     }
                     $testResult->setDecisionCriteriaId($decision_criteria_id);
                     $testResult->setComplement($test_case);
                     $testResult->setComment($comment);
                     $testResult->setStatus($resultStatus);
                     $testResult->setExecutionTime($executionTime);
                     $testResult->setBugs($bugs);
                     $testResult->save($conn);
                     // Retrieve test_result id created
                     $test_result_id = $testResult->getId();
                     // Category = Feature = 1
                     $category = 1;
                     // Write into complementary_tool_relation table
                     if (!$test_result_exists_flag) {
                         $complementaryToolRelation = new ComplementaryToolRelation();
                         $complementaryToolRelation->setLabel($feature);
                         $complementaryToolRelation->setTableNameId($table_name_test_result_id);
                         $complementaryToolRelation->setTableEntryId($test_result_id);
                         $complementaryToolRelation->setCategory($category);
                         $complementaryToolRelation->save($conn);
                     }
                 }
                 $data_tab = array();
                 $test_result_exists_flag = false;
             }
         } elseif (preg_match("#(?=.*Feature)(?=.*Check ?points)(?=.*Notes ?\\(bugs\\))(?=.*Pass)(?=.*Fail)(?=.*N/A)#i", $first_line)) {
             // Return at the beginning of file
             fseek($csv_report_file, 0);
             // Determine order between different fields on the first line
             $idx = 0;
             $ref_tab = array();
             foreach (fgetcsv($csv_report_file, 0, $delimiter) as $element) {
                 if (preg_match("#^ ?Feature.?\$#i", $element)) {
                     $ref_tab[0] = $idx;
                 } elseif (preg_match("#^ ?Check ?points.?\$#i", $element)) {
                     $ref_tab[1] = $idx;
                 } elseif (preg_match("#^ ?Notes ?\\(bugs\\).?\$#i", $element)) {
                     $ref_tab[2] = $idx;
                 } elseif (preg_match("#^ ?Pass.?\$#i", $element)) {
                     $ref_tab[3] = $idx;
                 } elseif (preg_match("#^ ?Fail.?\$#i", $element)) {
                     $ref_tab[4] = $idx;
                 } elseif (preg_match("#^ ?N/?A.?\$#i", $element)) {
                     $ref_tab[5] = $idx;
                 } elseif (preg_match("#^ ?Defer(red)?.?\$#i", $element)) {
                     $ref_tab[8] = $idx;
                 } elseif (preg_match("#^ ?Not ?run.?\$#i", $element) || preg_match("#^ ?Not_run.?\$#i", $element)) {
                     $ref_tab[9] = $idx;
                 } elseif (preg_match("#^ ?Duration.?\$#i", $element)) {
                     $ref_tab[6] = $idx;
                 } elseif (preg_match("#^ ?Bug.?\$#i", $element)) {
                     $ref_tab[7] = $idx;
                 }
                 $idx++;
             }
             // Go through file and fill datas
             $data_tab = array();
             while ($data_tab = fgetcsv($csv_report_file, 0, $delimiter)) {
                 if (count($data_tab) > 5) {
                     // Check if feature is not empty
                     if (empty($data_tab[$ref_tab[0]])) {
                         return 2201;
                     } else {
                         $feature = $data_tab[$ref_tab[0]];
                     }
                     // Check if case_id is not empty
                     if (empty($data_tab[$ref_tab[1]])) {
                         return 2202;
                     } else {
                         $case_id = $data_tab[$ref_tab[1]];
                     }
                     // Check if bug list is not empty
                     if (empty($data_tab[$ref_tab[7]])) {
                         $bugs = "";
                     } else {
                         $bugs = $data_tab[$ref_tab[7]];
                     }
                     $comment = empty($data_tab[$ref_tab[2]]) ? " " : $data_tab[$ref_tab[2]];
                     if (!($data_tab[$ref_tab[3]] == "1" or $data_tab[$ref_tab[4]] == "1" or $data_tab[$ref_tab[5]] == "1" or $data_tab[$ref_tab[8]] == "1" or $data_tab[$ref_tab[9]] == "1")) {
                         return 2203;
                     }
                     $pass = empty($data_tab[$ref_tab[3]]) ? "" : $data_tab[$ref_tab[3]];
                     $fail = empty($data_tab[$ref_tab[4]]) ? "" : $data_tab[$ref_tab[4]];
                     $block = empty($data_tab[$ref_tab[5]]) ? "" : $data_tab[$ref_tab[5]];
                     $deferred = empty($data_tab[$ref_tab[8]]) ? "" : $data_tab[$ref_tab[8]];
                     $notrun = empty($data_tab[$ref_tab[9]]) ? "" : $data_tab[$ref_tab[9]];
                     if ($pass == "1") {
                         $decision_criteria_id = -1;
                     } elseif ($fail == "1") {
                         $decision_criteria_id = -2;
                     } elseif ($block == "1") {
                         $decision_criteria_id = -3;
                     } elseif ($deferred == "1") {
                         $decision_criteria_id = -4;
                     } elseif ($notrun == "1") {
                         $decision_criteria_id = -5;
                     }
                     if (!empty($data_tab[$ref_tab[6]])) {
                         $executionTime = $data_tab[$ref_tab[6]];
                     } else {
                         $executionTime = 0;
                     }
                     // Status hard coded
                     $status = 0;
                     if ($merge_flag) {
                         // Retrieve test result id relying on test name and feature label, if it exists
                         $query = "SELECT tr.id tr_id\n\t\t\t\t\t\t\t\t\tFROM " . $qa_generic . ".test_result tr\n\t\t\t\t\t\t\t\t\t\tJOIN " . $qa_generic . ".table_name tn ON tn.name = 'test_result'\n\t\t\t\t\t\t\t\t\t\tJOIN " . $qa_generic . ".complementary_tool_relation ctr ON ctr.table_name_id = tn.id\n\t\t\t\t\t\t\t\t\t\t\tAND ctr.table_entry_id = tr.id\n\t\t\t\t\t\t\t\t\t\t\tAND ctr.label = '" . addslashes($feature) . "'\n\t\t\t\t\t\t\t\t\tWHERE tr.test_session_id = " . $test_session_id . "\n\t\t\t\t\t\t\t\t\t\tAND tr.name = '" . addslashes($case_id) . "'";
                         $result = Doctrine_Manager::getInstance()->getCurrentConnection()->execute($query)->fetch(PDO::FETCH_ASSOC);
                         if (!empty($result)) {
                             $test_result_exists_flag = true;
                             $testResultId = $result['tr_id'];
                         }
                     }
                     // Write into test_result table
                     if ($test_result_exists_flag) {
                         $testResult = Doctrine_Core::getTable("TestResult")->findOneById($testResultId);
                     } else {
                         $testResult = new TestResult();
                         $testResult->setName($case_id);
                         $testResult->setTestSessionId($test_session_id);
                     }
                     $testResult->setDecisionCriteriaId($decision_criteria_id);
                     $testResult->setComplement($test_case);
                     $testResult->setComment($comment);
                     $testResult->setStatus($status);
                     $testResult->setExecutionTime($executionTime);
                     $testResult->setBugs($bugs);
                     $testResult->save($conn);
                     // Retrieve test_result id created
                     $test_result_id = $testResult->getId();
                     // Category = Feature = 1
                     $category = 1;
                     // Write into complementary_tool_relation table
                     if (!$test_result_exists_flag) {
                         $complementaryToolRelation = new ComplementaryToolRelation();
                         $complementaryToolRelation->setLabel($feature);
                         $complementaryToolRelation->setTableNameId($table_name_test_result_id);
                         $complementaryToolRelation->setTableEntryId($test_result_id);
                         $complementaryToolRelation->setCategory($category);
                         $complementaryToolRelation->save($conn);
                     }
                 }
                 $data_tab = array();
                 $test_result_exists_flag = false;
             }
         } elseif (preg_match("#(?=.*Feature)(?=.*Case ?id)(?=.*Check ?points)(?=.*Notes)(?=.*Pass)(?=.*Fail)(?=.*N/A)#i", $first_line)) {
             // Return at the beginning of file
             fseek($csv_report_file, 0);
             // Determine order between different fields on the first line
             $idx = 0;
             $ref_tab = array();
             foreach (fgetcsv($csv_report_file, 0, $delimiter) as $element) {
                 if (preg_match("#^ ?Feature.?\$#i", $element)) {
                     $ref_tab[0] = $idx;
                 } elseif (preg_match("#^ ?Case ?id.?\$#i", $element)) {
                     $ref_tab[1] = $idx;
                 } elseif (preg_match("#^ ?Check ?points.?\$#i", $element)) {
                     $ref_tab[2] = $idx;
                 } elseif (preg_match("#^ ?Notes.?\$#i", $element)) {
                     $ref_tab[3] = $idx;
                 } elseif (preg_match("#^ ?Pass.?\$#i", $element)) {
                     $ref_tab[4] = $idx;
                 } elseif (preg_match("#^ ?Fail.?\$#i", $element)) {
                     $ref_tab[5] = $idx;
                 } elseif (preg_match("#^ ?N/?A.?\$#i", $element)) {
                     $ref_tab[6] = $idx;
                 } elseif (preg_match("#^ ?Defer(red)?.?\$#i", $element)) {
                     $ref_tab[9] = $idx;
                 } elseif (preg_match("#^ ?Not ?run.?\$#i", $element) || preg_match("#^ ?Not_run.?\$#i", $element)) {
                     $ref_tab[10] = $idx;
                 } elseif (preg_match("#^ ?Duration.?\$#i", $element)) {
                     $ref_tab[7] = $idx;
                 } elseif (preg_match("#^ ?Bug.?\$#i", $element)) {
                     $ref_tab[8] = $idx;
                 }
                 $idx++;
             }
             // Go through file and fill datas
             $data_tab = array();
             while ($data_tab = fgetcsv($csv_report_file, 0, $delimiter)) {
                 if (count($data_tab) > 6) {
                     // Check if feature is not empty
                     if (empty($data_tab[$ref_tab[0]])) {
                         return 2301;
                     } else {
                         $feature = $data_tab[$ref_tab[0]];
                     }
                     // Check if case_id is not empty
                     if (empty($data_tab[$ref_tab[1]])) {
                         return 2302;
                     } else {
                         $case_id = $data_tab[$ref_tab[1]];
                     }
                     $test_case = empty($data_tab[$ref_tab[2]]) ? " " : $data_tab[$ref_tab[2]];
                     $comment = empty($data_tab[$ref_tab[3]]) ? " " : $data_tab[$ref_tab[3]];
                     if (!($data_tab[$ref_tab[4]] == "1" or $data_tab[$ref_tab[5]] == "1" or $data_tab[$ref_tab[6]] == "1")) {
                         return 2303;
                     }
                     $pass = empty($data_tab[$ref_tab[4]]) ? "" : $data_tab[$ref_tab[4]];
                     $fail = empty($data_tab[$ref_tab[5]]) ? "" : $data_tab[$ref_tab[5]];
                     $block = empty($data_tab[$ref_tab[6]]) ? "" : $data_tab[$ref_tab[6]];
                     $deferred = empty($data_tab[$ref_tab[9]]) ? "" : $data_tab[$ref_tab[9]];
                     $notrun = empty($data_tab[$ref_tab[10]]) ? "" : $data_tab[$ref_tab[10]];
                     if ($pass == "1") {
                         $decision_criteria_id = -1;
                     } elseif ($fail == "1") {
                         $decision_criteria_id = -2;
                     } elseif ($block == "1") {
                         $decision_criteria_id = -3;
                     } elseif ($deferred == "1") {
                         $decision_criteria_id = -4;
                     } elseif ($notrun == "1") {
                         $decision_criteria_id = -5;
                     }
                     // Check if execution time is not empty
                     if (!empty($data_tab[$ref_tab[7]])) {
                         $executionTime = $data_tab[$ref_tab[7]];
                     } else {
                         $executionTime = 0;
                     }
                     // Check if bug list is not empty
                     if (empty($data_tab[$ref_tab[8]])) {
                         $bugs = "";
                     } else {
                         $bugs = $data_tab[$ref_tab[8]];
                     }
                     // Status hard coded
                     $status = 0;
                     if ($merge_flag) {
                         // Retrieve test result id relying on test name and feature label, if it exists
                         $query = "SELECT tr.id tr_id\n\t\t\t\t\t\t\t\t\tFROM " . $qa_generic . ".test_result tr\n\t\t\t\t\t\t\t\t\t\tJOIN " . $qa_generic . ".table_name tn ON tn.name = 'test_result'\n\t\t\t\t\t\t\t\t\t\tJOIN " . $qa_generic . ".complementary_tool_relation ctr ON ctr.table_name_id = tn.id\n\t\t\t\t\t\t\t\t\t\t\tAND ctr.table_entry_id = tr.id\n\t\t\t\t\t\t\t\t\t\t\tAND ctr.label = '" . addslashes($feature) . "'\n\t\t\t\t\t\t\t\t\tWHERE tr.test_session_id = " . $test_session_id . "\n\t\t\t\t\t\t\t\t\t\tAND tr.name = '" . addslashes($case_id) . "'";
                         $result = Doctrine_Manager::getInstance()->getCurrentConnection()->execute($query)->fetch(PDO::FETCH_ASSOC);
                         if (!empty($result)) {
                             $test_result_exists_flag = true;
                             $testResultId = $result['tr_id'];
                         }
                     }
                     // Write into test_result table
                     if ($test_result_exists_flag) {
                         $testResult = Doctrine_Core::getTable("TestResult")->findOneById($testResultId);
                     } else {
                         $testResult = new TestResult();
                         $testResult->setName($case_id);
                         $testResult->setTestSessionId($test_session_id);
                     }
                     $testResult->setDecisionCriteriaId($decision_criteria_id);
                     $testResult->setComplement($test_case);
                     $testResult->setComment($comment);
                     $testResult->setStatus($status);
                     $testResult->setExecutionTime($executionTime);
                     $testResult->setBugs($bugs);
                     $testResult->save($conn);
                     // Retrieve test_result id created
                     $test_result_id = $testResult->getId();
                     // Category = Feature = 1
                     $category = 1;
                     // Write into complementary_tool_relation table
                     if (!$test_result_exists_flag) {
                         $complementaryToolRelation = new ComplementaryToolRelation();
                         $complementaryToolRelation->setLabel($feature);
                         $complementaryToolRelation->setTableNameId($table_name_test_result_id);
                         $complementaryToolRelation->setTableEntryId($test_result_id);
                         $complementaryToolRelation->setCategory($category);
                         $complementaryToolRelation->save($conn);
                     }
                 }
                 $data_tab = array();
                 $test_result_exists_flag = false;
             }
         } elseif (preg_match("#(?=.*Feature)(?=.*Case ?Id)(?=.*Test ?Case)(?=.*Pass)(?=.*Fail)(?=.*N/A)(?=.*Comment)#i", $first_line)) {
             // Return at the beginning of file
             fseek($csv_report_file, 0);
             // Determine order between different fields on the first line
             $idx = 0;
             $ref_tab = array();
             foreach (fgetcsv($csv_report_file, 0, $delimiter) as $element) {
                 if (preg_match("#^ ?Feature.?\$#i", $element)) {
                     $ref_tab[0] = $idx;
                 } elseif (preg_match("#^ ?Case ?Id.?\$#i", $element)) {
                     $ref_tab[1] = $idx;
                 } elseif (preg_match("#^ ?Test ?Case.?\$#i", $element)) {
                     $ref_tab[2] = $idx;
                 } elseif (preg_match("#^ ?Pass.?\$#i", $element)) {
                     $ref_tab[3] = $idx;
                 } elseif (preg_match("#^ ?Fail.?\$#i", $element)) {
                     $ref_tab[4] = $idx;
                 } elseif (preg_match("#^ ?N/?A.?\$#i", $element)) {
                     $ref_tab[5] = $idx;
                 } elseif (preg_match("#^ ?Measured.?\$#i", $element)) {
                     $ref_tab[6] = $idx;
                 } elseif (preg_match("#^ ?Comment.?\$#i", $element)) {
                     $ref_tab[7] = $idx;
                 } elseif (preg_match("#^ ?Measurement ?Name.?\$#i", $element)) {
                     $ref_tab[8] = $idx;
                 } elseif (preg_match("#^ ?Value.?\$#i", $element)) {
                     $ref_tab[9] = $idx;
                 } elseif (preg_match("#^ ?Unit.?\$#i", $element)) {
                     $ref_tab[10] = $idx;
                 } elseif (preg_match("#^ ?Target.?\$#i", $element)) {
                     $ref_tab[11] = $idx;
                 } elseif (preg_match("#^ ?Failure.?\$#i", $element)) {
                     $ref_tab[12] = $idx;
                 } elseif (preg_match("#^ ?Duration.?\$#i", $element)) {
                     $ref_tab[13] = $idx;
                 } elseif (preg_match("#^ ?Bug.?\$#i", $element)) {
                     $ref_tab[14] = $idx;
                 }
                 $idx++;
             }
             // Go through file and fill datas
             $data_tab = array();
             while ($data_tab = fgetcsv($csv_report_file, 0, $delimiter)) {
                 if (count($data_tab) > 6) {
                     // Check if feature is not empty
                     if (empty($data_tab[$ref_tab[0]])) {
                         return 2401;
                     } else {
                         $feature = $data_tab[$ref_tab[0]];
                     }
                     // Check if case_id is not empty
                     if (empty($data_tab[$ref_tab[1]])) {
                         return 2402;
                     } else {
                         $case_id = $data_tab[$ref_tab[1]];
                     }
                     if (!($data_tab[$ref_tab[3]] == "1" or $data_tab[$ref_tab[4]] == "1" or $data_tab[$ref_tab[5]] == "1" or $data_tab[$ref_tab[6]] == "1")) {
                         return 2403;
                     }
                     $test_case = empty($data_tab[$ref_tab[2]]) ? " " : $data_tab[$ref_tab[2]];
                     $pass = empty($data_tab[$ref_tab[3]]) ? "" : $data_tab[$ref_tab[3]];
                     $fail = empty($data_tab[$ref_tab[4]]) ? "" : $data_tab[$ref_tab[4]];
                     $block = empty($data_tab[$ref_tab[5]]) ? "" : $data_tab[$ref_tab[5]];
                     $deferred = empty($data_tab[$ref_tab[15]]) ? "" : $data_tab[$ref_tab[15]];
                     $notrun = empty($data_tab[$ref_tab[16]]) ? "" : $data_tab[$ref_tab[16]];
                     $measured = empty($data_tab[$ref_tab[6]]) ? "" : $data_tab[$ref_tab[6]];
                     $comment = empty($data_tab[$ref_tab[7]]) ? " " : $data_tab[$ref_tab[7]];
                     $measurement_name = empty($data_tab[$ref_tab[8]]) ? "" : $data_tab[$ref_tab[8]];
                     $value = empty($data_tab[$ref_tab[9]]) ? "" : preg_replace('#(,)#', '.', $data_tab[$ref_tab[9]]);
                     $unit = empty($data_tab[$ref_tab[10]]) ? " " : $data_tab[$ref_tab[10]];
                     $target = empty($data_tab[$ref_tab[11]]) ? "" : preg_replace('#(,)#', '.', $data_tab[$ref_tab[11]]);
                     $failure = empty($data_tab[$ref_tab[12]]) ? "" : preg_replace('#(,)#', '.', $data_tab[$ref_tab[12]]);
                     $executionTime = empty($data_tab[$ref_tab[13]]) ? 0 : $data_tab[$ref_tab[13]];
                     $bugs = empty($data_tab[$ref_tab[14]]) ? "" : $data_tab[$ref_tab[14]];
                     preg_replace('#(,)#', '.', $data_tab[$ref_tab[9]]);
                     // Write datas into qa_generic database
                     if ($pass == "1") {
                         $decision_criteria_id = -1;
                     } elseif ($fail == "1") {
                         $decision_criteria_id = -2;
                     } elseif ($block == "1") {
                         $decision_criteria_id = -3;
                     } elseif ($deferred == "1") {
                         $decision_criteria_id = -4;
                     } elseif ($notrun == "1") {
                         $decision_criteria_id = -5;
                     } elseif ($measured == "1") {
                         if (empty($failure)) {
                             if ($value < $target) {
                                 $decision_criteria_id = -2;
                             } else {
                                 $decision_criteria_id = -1;
                             }
                         } else {
                             if ($failure > $target) {
                                 if ($value < $failure) {
                                     $decision_criteria_id = -1;
                                 } else {
                                     $decision_criteria_id = -2;
                                 }
                             } elseif ($failure < $target) {
                                 if ($value > $failure) {
                                     $decision_criteria_id = -1;
                                 } else {
                                     $decision_criteria_id = -2;
                                 }
                             } else {
                                 if ($value < $target) {
                                     $decision_criteria_id = -2;
                                 } else {
                                     $decision_criteria_id = -1;
                                 }
                             }
                         }
                     }
                     // Status hard coded
                     $status = 0;
                     if ($merge_flag) {
                         // Retrieve test result id relying on test name and feature label, if it exists
                         $query = "SELECT tr.id tr_id\n\t\t\t\t\t\t\t\t\tFROM " . $qa_generic . ".test_result tr\n\t\t\t\t\t\t\t\t\t\tJOIN " . $qa_generic . ".table_name tn ON tn.name = 'test_result'\n\t\t\t\t\t\t\t\t\t\tJOIN " . $qa_generic . ".complementary_tool_relation ctr ON ctr.table_name_id = tn.id\n\t\t\t\t\t\t\t\t\t\t\tAND ctr.table_entry_id = tr.id\n\t\t\t\t\t\t\t\t\t\t\tAND ctr.label = '" . addslashes($feature) . "'\n\t\t\t\t\t\t\t\t\tWHERE tr.test_session_id = " . $test_session_id . "\n\t\t\t\t\t\t\t\t\t\tAND tr.name = '" . addslashes($case_id) . "'";
                         $result = Doctrine_Manager::getInstance()->getCurrentConnection()->execute($query)->fetch(PDO::FETCH_ASSOC);
                         if (!empty($result)) {
                             $test_result_exists_flag = true;
                             $testResultId = $result['tr_id'];
                         }
                     }
                     // Write into test_result table
                     if ($test_result_exists_flag) {
                         $measures = Doctrine_Query::create()->select('*')->from('Measure')->where('test_result_id = ?', $testResultId)->execute();
                         foreach ($measures as $measure) {
                             $measure->delete($conn);
                         }
                         $testResult = Doctrine_Core::getTable("TestResult")->findOneById($testResultId);
                     } else {
                         $testResult = new TestResult();
                         $testResult->setName($case_id);
                         $testResult->setTestSessionId($test_session_id);
                     }
                     $testResult->setDecisionCriteriaId($decision_criteria_id);
                     $testResult->setComplement($test_case);
                     $testResult->setComment($comment);
                     $testResult->setStatus($status);
                     $testResult->setExecutionTime($executionTime);
                     $testResult->setBugs($bugs);
                     $testResult->save($conn);
                     // Retrieve test_result id created
                     $test_result_id = $testResult->getId();
                     // Category = Feature = 1
                     $category = 1;
                     // Write into complementary_tool_relation table
                     if (!$test_result_exists_flag) {
                         $complementaryToolRelation = new ComplementaryToolRelation();
                         $complementaryToolRelation->setLabel($feature);
                         $complementaryToolRelation->setTableNameId($table_name_test_result_id);
                         $complementaryToolRelation->setTableEntryId($test_result_id);
                         $complementaryToolRelation->setCategory($category);
                         $complementaryToolRelation->save($conn);
                     }
                     // Write into measure table
                     if (!empty($measurement_name) and !empty($value)) {
                         $measureObject = new Measure();
                         $measureObject->setTestResultId($test_result_id);
                         $measureObject->setValue($value);
                         $measureObject->setUnit($unit);
                         $measureObject->setDescription($measurement_name);
                         $measureObject->setCategory(1);
                         $measureObject->setOperator(1);
                         $measureObject->save($conn);
                         if (!empty($target)) {
                             $measureObject = new Measure();
                             $measureObject->setTestResultId($test_result_id);
                             $measureObject->setValue($target);
                             $measureObject->setUnit($unit);
                             $measureObject->setDescription($measurement_name);
                             $measureObject->setCategory(2);
                             $measureObject->setOperator(1);
                             $measureObject->save($conn);
                         }
                         if (!empty($failure)) {
                             $measureObject = new Measure();
                             $measureObject->setTestResultId($test_result_id);
                             $measureObject->setValue($failure);
                             $measureObject->setUnit($unit);
                             $measureObject->setDescription($measurement_name);
                             $measureObject->setCategory(3);
                             $measureObject->setOperator(1);
                             $measureObject->save($conn);
                         }
                     }
                 }
                 $data_tab = array();
                 $test_result_exists_flag = false;
             }
         } elseif (preg_match("#(?=.*Name)(?=.*\\b ?Status ?\\b)#i", $first_line)) {
             // Return at the beginning of file
             fseek($csv_report_file, 0);
             // Determine order between different fields on the first line
             $idx = 0;
             $ref_tab = array();
             $entityTypeFound = false;
             foreach (fgetcsv($csv_report_file, 0, $delimiter) as $element) {
                 if (preg_match("#^ ?Component.?\$#i", $element)) {
                     $ref_tab[0] = $idx;
                 } elseif (preg_match("#^ ?Name.?\$#i", $element)) {
                     $ref_tab[1] = $idx;
                 } elseif (preg_match("#^ ?Status.?\$#i", $element)) {
                     $ref_tab[2] = $idx;
                 } elseif (preg_match("#^ ?Feature.?\$#i", $element)) {
                     $ref_tab[3] = $idx;
                 } elseif (preg_match("#^ ?Description.?\$#i", $element)) {
                     $ref_tab[4] = $idx;
                 } elseif (preg_match("#^ ?Comment.?\$#i", $element)) {
                     $ref_tab[5] = $idx;
                 } elseif (preg_match("#^ ?Bug.?\$#i", $element)) {
                     $ref_tab[6] = $idx;
                 } elseif (preg_match("#^ ?Package.?\$#i", $element)) {
                     $ref_tab[7] = $idx;
                 } elseif (preg_match("#^ ?Measurement ?Name.?\$#i", $element)) {
                     $ref_tab[8] = $idx;
                 } elseif (preg_match("#^ ?Value.?\$#i", $element)) {
                     $ref_tab[9] = $idx;
                 } elseif (preg_match("#^ ?Unit.?\$#i", $element)) {
                     $ref_tab[10] = $idx;
                 } elseif (preg_match("#^ ?Target.?\$#i", $element)) {
                     $ref_tab[11] = $idx;
                 } elseif (preg_match("#^ ?Failure.?\$#i", $element)) {
                     $ref_tab[12] = $idx;
                 } elseif (preg_match("#^ ?StepActualResult.?\$#i", $element)) {
                     $ref_tab[13] = $idx;
                 } elseif (preg_match("# ?EntityType.?#i", $element)) {
                     $ref_tab[14] = $idx;
                     $entityTypeFound = true;
                 } elseif (preg_match("#^ ?Duration.?\$#i", $element)) {
                     $ref_tab[15] = $idx;
                 } elseif (preg_match("#^ ?StepNotes.?\$#i", $element)) {
                     $ref_tab[16] = $idx;
                 }
                 $idx++;
             }
             if (!isset($ref_tab[1])) {
                 return 2501;
             }
             if (!isset($ref_tab[2])) {
                 return 2502;
             }
             if (!isset($ref_tab[0]) && !isset($ref_tab[7])) {
                 return 2509;
             }
             // Go through file and fill datas
             $data_tab = array();
             while ($data_tab = fgetcsv($csv_report_file, 0, $delimiter)) {
                 if (count($data_tab) > 2) {
                     // If 'EntityType' label is found, pass over 'StepRunResult' lines
                     if ($entityTypeFound) {
                         if (empty($data_tab[$ref_tab[14]])) {
                             return 2503;
                         } elseif (!preg_match("#^ ?TestScriptAssignment.?\$#i", $data_tab[$ref_tab[14]])) {
                             continue;
                         }
                     }
                     // Check if feature is not empty
                     if (empty($data_tab[$ref_tab[0]]) and empty($data_tab[$ref_tab[7]])) {
                         return 2504;
                     } else {
                         if (!empty($data_tab[$ref_tab[0]])) {
                             $feature = $data_tab[$ref_tab[0]];
                         } else {
                             $feature = $data_tab[$ref_tab[7]];
                         }
                     }
                     // If 'EntityType' label is found, keep last two string (delimited by '|') in the feature label
                     if ($entityTypeFound) {
                         $feat_delimiter = '|';
                         $feature_tab = explode($feat_delimiter, $feature);
                         $tab_length = count($feature_tab);
                         $feature = $feature_tab[$tab_length - 2] . $feat_delimiter . $feature_tab[$tab_length - 1];
                     }
                     // Check if case_id is not empty
                     if (empty($data_tab[$ref_tab[1]])) {
                         return 2506;
                     } else {
                         $case_id = $data_tab[$ref_tab[1]];
                     }
                     // Check if status is not empty
                     if (empty($data_tab[$ref_tab[2]])) {
                         return 2507;
                     } else {
                         $status = $data_tab[$ref_tab[2]];
                     }
                     $test_case = empty($data_tab[$ref_tab[4]]) ? " " : $data_tab[$ref_tab[4]];
                     $comment = empty($data_tab[$ref_tab[5]]) ? "" : $data_tab[$ref_tab[5]];
                     // $bug = (empty($data_tab[$ref_tab[6]])) ? "" : $data_tab[$ref_tab[6]];
                     $step_actual_result = empty($data_tab[$ref_tab[13]]) ? "" : $data_tab[$ref_tab[13]];
                     $step_notes = empty($data_tab[$ref_tab[16]]) ? "" : $data_tab[$ref_tab[16]];
                     $measurement_name = empty($data_tab[$ref_tab[8]]) ? "" : $data_tab[$ref_tab[8]];
                     $value = empty($data_tab[$ref_tab[9]]) ? "" : preg_replace('#(,)#', '.', $data_tab[$ref_tab[9]]);
                     $unit = empty($data_tab[$ref_tab[10]]) ? " " : $data_tab[$ref_tab[10]];
                     $target = empty($data_tab[$ref_tab[11]]) ? "" : preg_replace('#(,)#', '.', $data_tab[$ref_tab[11]]);
                     $failure = empty($data_tab[$ref_tab[12]]) ? "" : preg_replace('#(,)#', '.', $data_tab[$ref_tab[12]]);
                     $executionTime = empty($data_tab[$ref_tab[15]]) ? 0 : $data_tab[$ref_tab[12]];
                     // Concatenate notes
                     if (empty($comment)) {
                         if (empty($step_notes)) {
                             $notes = "";
                         } else {
                             $notes = $step_notes;
                         }
                     } else {
                         if (empty($step_notes)) {
                             $notes = $comment;
                         } else {
                             $notes = $comment . " " . $step_notes;
                         }
                     }
                     // Check if step_actual_result is not empty
                     if (empty($data_tab[$ref_tab[13]])) {
                         $bugs = "";
                     } else {
                         $bugs = $data_tab[$ref_tab[13]];
                     }
                     // Write datas into qa_generic database
                     if (preg_match("#^ ?pass(ed)? ?\$#i", $status)) {
                         $decision_criteria_id = -1;
                     } elseif (preg_match("#^ ?fail(ed)? ?\$#i", $status)) {
                         $decision_criteria_id = -2;
                     } elseif (preg_match("#^ ?block(ed)? ?\$#i", $status)) {
                         $decision_criteria_id = -3;
                     } elseif (preg_match("#^ ?defer(red)? ?\$#i", $status)) {
                         $decision_criteria_id = -4;
                     } elseif (preg_match("#^ ?not_run ?\$#i", $status) || preg_match("#^ ?not ?run ?\$#i", $status)) {
                         $decision_criteria_id = -5;
                     } elseif (preg_match("#^ ?measured ?\$#i", $status)) {
                         if (empty($failure)) {
                             if ($value < $target) {
                                 $decision_criteria_id = -2;
                             } else {
                                 $decision_criteria_id = -1;
                             }
                         } else {
                             if ($failure > $target) {
                                 if ($value < $failure) {
                                     $decision_criteria_id = -1;
                                 } else {
                                     $decision_criteria_id = -2;
                                 }
                             } elseif ($failure < $target) {
                                 if ($value > $failure) {
                                     $decision_criteria_id = -1;
                                 } else {
                                     $decision_criteria_id = -2;
                                 }
                             } else {
                                 if ($value < $target) {
                                     $decision_criteria_id = -2;
                                 } else {
                                     $decision_criteria_id = -1;
                                 }
                             }
                         }
                     } else {
                         if (preg_match("#^ ?in ?progress ?\$#i", $status)) {
                             $decision_criteria_id = -5;
                         } else {
                             return 2508;
                         }
                     }
                     // Status hard coded
                     $resultStatus = 0;
                     if ($merge_flag) {
                         // Retrieve test result id relying on test name and feature label, if it exists
                         $query = "SELECT tr.id tr_id\n\t\t\t\t\t\t\t\t\tFROM " . $qa_generic . ".test_result tr\n\t\t\t\t\t\t\t\t\t\tJOIN " . $qa_generic . ".table_name tn ON tn.name = 'test_result'\n\t\t\t\t\t\t\t\t\t\tJOIN " . $qa_generic . ".complementary_tool_relation ctr ON ctr.table_name_id = tn.id\n\t\t\t\t\t\t\t\t\t\t\tAND ctr.table_entry_id = tr.id\n\t\t\t\t\t\t\t\t\t\t\tAND ctr.label = '" . addslashes($feature) . "'\n\t\t\t\t\t\t\t\t\tWHERE tr.test_session_id = " . $test_session_id . "\n\t\t\t\t\t\t\t\t\t\tAND tr.name = '" . addslashes($case_id) . "'";
                         $result = Doctrine_Manager::getInstance()->getCurrentConnection()->execute($query)->fetch(PDO::FETCH_ASSOC);
                         if (!empty($result)) {
                             $test_result_exists_flag = true;
                             $testResultId = $result['tr_id'];
                         }
                     }
                     // Write into test_result table
                     if ($test_result_exists_flag) {
                         $measures = Doctrine_Query::create()->select('*')->from('Measure')->where('test_result_id = ?', $testResultId)->execute();
                         foreach ($measures as $measure) {
                             $measure->delete($conn);
                         }
                         $testResult = Doctrine_Core::getTable("TestResult")->findOneById($testResultId);
                     } else {
                         $testResult = new TestResult();
                         $testResult->setName($case_id);
                         $testResult->setTestSessionId($test_session_id);
                     }
                     $testResult->setDecisionCriteriaId($decision_criteria_id);
                     $testResult->setComplement($test_case);
                     $testResult->setStatus($resultStatus);
                     $testResult->setExecutionTime($executionTime);
                     $testResult->setBugs($bugs);
                     $testResult->setComment($notes);
                     $testResult->save($conn);
                     // Retrieve test_result id created
                     $test_result_id = $testResult->getId();
                     // Category = Feature = 1
                     $category = 1;
                     // Write into complementary_tool_relation table
                     if (!$test_result_exists_flag) {
                         $complementaryToolRelation = new ComplementaryToolRelation();
                         $complementaryToolRelation->setLabel($feature);
                         $complementaryToolRelation->setTableNameId($table_name_test_result_id);
                         $complementaryToolRelation->setTableEntryId($test_result_id);
                         $complementaryToolRelation->setCategory($category);
                         $complementaryToolRelation->save($conn);
                     }
                     // Write into measure table
                     if (!empty($measurement_name) and !empty($value)) {
                         $measureObject = new Measure();
                         $measureObject->setTestResultId($test_result_id);
                         $measureObject->setValue($value);
                         $measureObject->setUnit($unit);
                         $measureObject->setDescription($measurement_name);
                         $measureObject->setCategory(1);
                         $measureObject->setOperator(1);
                         $measureObject->save($conn);
                         if (!empty($target)) {
                             $measureObject = new Measure();
                             $measureObject->setTestResultId($test_result_id);
                             $measureObject->setValue($target);
                             $measureObject->setUnit($unit);
                             $measureObject->setDescription($measurement_name);
                             $measureObject->setCategory(2);
                             $measureObject->setOperator(1);
                             $measureObject->save($conn);
                         }
                         if (!empty($failure)) {
                             $measureObject = new Measure();
                             $measureObject->setTestResultId($test_result_id);
                             $measureObject->setValue($failure);
                             $measureObject->setUnit($unit);
                             $measureObject->setDescription($measurement_name);
                             $measureObject->setCategory(3);
                             $measureObject->setOperator(1);
                             $measureObject->save($conn);
                         }
                     }
                 }
                 $data_tab = array();
                 $test_result_exists_flag = false;
             }
         } else {
             // Close the file
             fclose($csv_report_file);
             return 2000;
         }
         // Close the file
         fclose($csv_report_file);
         return 0;
     } else {
         return 10;
     }
 }
Esempio n. 16
0
function update_remarks_xml($langdata_path, $updated_remarks)
{
    # Updates the XML file after changes made to a test measure (indicator)
    # updated_remarks[measure_id] = {[range]=>[interpretation]}
    global $VERSION;
    $new_version = $VERSION;
    $file_name = $langdata_path . "remarks.xml";
    $dest_file_name = $langdata_path . "remarks.xml";
    $xml_doc = new DOMDocument();
    $xml_doc->load($file_name);
    $xpath = new DOMXpath($xml_doc);
    $root_node = $xml_doc->getElementsByTagName("measures");
    $root_node->item(0)->setAttribute("version", $new_version);
    foreach ($updated_remarks as $key => $value) {
        $measure_id = $key;
        $remarks_map = $value;
        $measure = Measure::getById($measure_id);
        # Remove old measure node
        $old_measure_node = $xpath->query("//measures/measure[@id='" . $measure_id . "']");
        $old_measure_node = $root_node->item(0)->removeChild($old_measure_node->item(0));
        # Create new measure node based on supplied values
        $new_measure_node = $xml_doc->createElement("measure");
        $new_measure_node->setAttribute("id", $measure_id);
        $new_measure_node->setAttribute("descr", $measure->name);
        foreach ($remarks_map as $key2 => $value2) {
            $range = $key2;
            $remark = $value2;
            $new_range_node = $xml_doc->createElement("range");
            $new_key_node = $xml_doc->createElement("key", $range);
            $new_value_node = $xml_doc->createElement("value", $remark);
            $new_range_node->appendChild($new_key_node);
            $new_range_node->appendChild($new_value_node);
            $new_measure_node->appendChild($new_range_node);
        }
        # Append updated measure node to XML root node
        $root_node->item(0)->appendChild($new_measure_node);
    }
    # Save changes back into XML file
    $xml_doc->formatOutput = true;
    $xml_doc->preserveWhiteSpace = true;
    $xml_doc->save($dest_file_name);
}
Esempio n. 17
0
error_reporting(E_ALL);
ini_set('display_errors', 1);
//require_once SITE_ROOT . '/current/vendor/autoload.php';
require_once '../PHPMusicXML.php';
$score = new Score();
$part = new Part('Viola');
$scale = new Scale(array('root' => new Pitch('D4'), 'mode' => 'lydian augmented'));
$pitches = $scale->getPitches();
$measure = new Measure();
foreach ($pitches as $pitch) {
    $measure->addNote(new Note(array('pitch' => $pitch, 'duration' => 4)));
}
$part->addMeasure($measure);
$scale->setProperty('mode', 'bebop dominant');
$pitches = $scale->getPitches();
$measure = new Measure();
foreach ($pitches as $pitch) {
    $measure->addNote(new Note(array('pitch' => $pitch, 'duration' => 4)));
}
$part->addMeasure($measure);
$score->addPart($part);
$part->addMeasure($measure);
$xml2 = $score->toXML('partwise');
?>
<html>
<head>
    <meta name="viewport" content="initial-scale = 1.0, minimum-scale = 1.0, maximum-scale = 1.0, user-scalable = no">

<script src="vexflow/jquery.js"></script>
<script src="vexflow/vexflow-debug.js"></script>
Esempio n. 18
0
 /**
  * Returns test result intepretation
  * @param
  * @return
  */
 public function getResultInterpretation()
 {
     $result = array();
     //save if it is available
     if (Input::get('age')) {
         $result['birthdate'] = Input::get('age');
         $result['gender'] = Input::get('gender');
     }
     $result['measureid'] = Input::get('measureid');
     $result['measurevalue'] = Input::get('measurevalue');
     $measure = new Measure();
     return $measure->getResultInterpretation($result);
 }
Esempio n. 19
0
<?php

use ianring\PHPMusicXML;
error_reporting(E_ALL);
ini_set('display_errors', 1);
//require_once SITE_ROOT . '/current/vendor/autoload.php';
require_once '../PHPMusicXML.php';
$score = new Score();
$part = new Part('Viola');
$measure = new Measure(array('divisions' => 24));
$measure->addNotes(array(new Note(array('pitch' => 'C4', 'duration' => 4)), new Note(array('pitch' => 'D4', 'duration' => 4)), new Note(array('pitch' => 'E4', 'duration' => 4)), new Note(array('pitch' => 'F4', 'duration' => 4))));
$part->addMeasure($measure);
$measure = new Measure();
$measure->addNotes(array(new Note(array('pitch' => 'G4', 'duration' => 4)), new Note(array('pitch' => 'A4', 'duration' => 4)), new Note(array('pitch' => 'B4', 'duration' => 4)), new Note(array('pitch' => 'C5', 'duration' => 4))));
$part->addMeasure($measure);
$score->addPart($part);
$part->addMeasure($measure);
$xml2 = $score->toXML('partwise');
?>
<html>
<head>
    <meta name="viewport" content="initial-scale = 1.0, minimum-scale = 1.0, maximum-scale = 1.0, user-scalable = no">

<script src="vexflow/jquery.js"></script>
<script src="vexflow/vexflow-debug.js"></script>

    <script>
	$(document).ready(function() {

		var xml2 = '<?php 
echo $xml2;
Esempio n. 20
0
<?php

use ianring\PHPMusicXML;
error_reporting(E_ALL);
ini_set('display_errors', 1);
//require_once SITE_ROOT . '/current/vendor/autoload.php';
require_once '../PHPMusicXML.php';
$score = new Score();
$measure = new Measure(array('divisions' => 24, 'direction' => array('placement' => 'below', 'direction-type' => array('words' => array('default-x' => 0, 'default-y' => 15, 'font-size' => 10, 'font-weight' => 'bold', 'font-style' => 'italic', 'text' => 'Andantino')), 'staff' => 1, 'sound-dynamics' => 40), 'barline' => array(array('location' => 'left', 'bar-style' => 'light-heavy', 'repeat' => 'forward', 'ending' => array('type' => 'stop', 'number' => 1)), array('location' => 'right', 'bar-style' => 'heavy-light', 'repeat' => 'backward', 'ending' => array('type' => 'stop', 'number' => 1))), 'implicit' => true, 'number' => 1, 'width' => 180));
// pitch can be any of the following
// C4, c+4, C+4, C#4, c#4, c-4, C-4, Cb4,
// array('step'=>'C','alter'=>-1,'octave'=>4)
$note = new Note(array('pitch' => 'C4', 'duration' => 4, 'type' => 'whole'));
$note = new Note(array('rest' => true, 'dot' => true, 'staccato' => true, 'chord' => false, 'voice' => 1, 'staff' => 1, 'pitch' => 'C4', 'duration' => 4, 'type' => 'quarter', 'tied' => 'stop', 'tuplet' => array('bracket' => 'no', 'number' => 1, 'placement' => 'above', 'type' => 'start'), 'stem' => array('default-y' => 3, 'direction' => 'up'), 'beam' => array(array('number' => 1, 'type' => 'begin'), array('number' => 1, 'type' => 'begin')), 'accidental' => array('courtesy' => true, 'editorial' => null, 'bracket' => false, 'parentheses' => true, 'size' => false, 'type' => 'natural')));
// a quarter-note triplet
$note = new Note(array('chord' => false, 'dot' => false, 'pitch' => 'E4', 'duration' => 8, 'type' => 'quarter', 'time-modification' => array('actual-notes' => 3, 'normal-notes' => 2, 'normal-type' => 'eighth')));
$measure->addNote($note);
$note->transpose(2);
// transposes the note down 4 semitones
$measure->addNote($note);
$note->transpose(2);
// transposes the note down 4 semitones
$measure->addNote($note);
$note = new Note(array('rest' => array('measure' => true), 'duration' => 8, 'voice' => 1));
$note = new Note(array('chord' => true, 'pitch' => 'C4', 'duration' => 4, 'type' => 'whole'));
$direction = new Direction(array('placement' => 'above', 'direction-type' => array('wedge' => array('default-y' => 20, 'spread' => 0, 'type' => 'crescendo')), 'offset' => -8));
$direction = new Direction(array('placement' => 'above', 'direction-type' => array('words' => array('default-x' => 15, 'default-y' => 15, 'font-size' => 9, 'font-style' => 'italic', 'words' => 'dolce')), 'offset' => -8));
// many direction-types can go together into one direction
$direction = new Direction(array('placement' => 'above', 'direction-type' => array(array('words' => array('default-x' => 15, 'default-y' => 15, 'font-size' => 9, 'font-style' => 'italic', 'words' => 'dolce')), array('wedge' => array())), 'offset' => -8));
$measure->addNote($note);
$note = new Note(array('pitch' => array('step' => 'C', 'alter' => -1, 'octave' => 4), 'duration' => 4, 'tie' => 'start', 'type' => 'whole', 'lyric' => array('syllabic' => 'end', 'text' => 'meil', 'extend' => true)));
Esempio n. 21
0
    /**
     * 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);
        }
    }
Esempio n. 22
0
error_reporting(E_ALL);
ini_set('display_errors', 1);
?>
<html>
<head>
    <meta name="viewport" content="initial-scale = 1.0, minimum-scale = 1.0, maximum-scale = 1.0, user-scalable = no">

<?php 
require_once '../PHPMusicXML.php';
$scale = new Scale(array('root' => new Pitch('C4'), 'mode' => 'prometheus'));
$measureOptions = array('divisions' => 4, 'key' => new Key('C major'), 'time' => array('beats' => 6, 'beat-type' => 8), 'clef' => array(new Clef('treble'), new Clef('bass')), 'barline' => array(new Barline(array('location' => 'left', 'bar-style' => 'light-heavy', 'repeat' => array('direction' => 'forward', 'winged' => 'none'), 'ending' => array('type' => 'stop', 'number' => 1))), new Barline(array('location' => 'right', 'bar-style' => 'heavy-light', 'repeat' => array('direction' => 'backward'), 'ending' => array('type' => 'stop', 'number' => 2)))), 'implicit' => false, 'non-controlling' => false, 'number' => 1, 'width' => 180);
$pitches = $scale->getPitches();
//var_dump($pitches);
$score = new Score();
$part = new Part('Piano');
$measure = new Measure($measureOptions);
$layer = new Layer();
foreach ($pitches as $pitch) {
    $note = new Note(array('pitch' => $pitch, 'duration' => 4, 'type' => 'quarter'));
    $layer->addNote($note);
    // this essentially adds a chord with only one note in it.
}
$measure->addLayer($layer);
$newlayer = clone $layer;
$newlayer->transpose(-12);
$measure->addLayer($newlayer);
// puts this layer in staff two
$newlayer->setStaff(2);
for ($i = 0; $i < 12; $i++) {
    $newmeasure = clone $measure;
    $newmeasure->transpose($i, -1);
Esempio n. 23
0
 public function addMeasure(Measure $measure)
 {
     $measure->setTrack($this);
     $this->measures[] = $measure;
 }
                         $range_string .= "_";
                     }
                 }
                 if ($options_entered === false) {
                     # Error: Autocomplete values not entered properly.
                     # TODO:
                 }
                 # Truncate trailing "_"
                 $range_string = substr($range_string, 0, -1);
             }
         }
     }
     $unit = $units[$i];
     # Existing measure
     # Update measure to DB
     $measure = Measure::getById($measure_ids[$i]);
     $measure->name = $measure_name;
     $measure->range = $range_string;
     $measure->unit = $unit;
     # Update measure entry DB
     $measure->updateToDb();
     $measures_to_retain[] = $measure_ids[$i];
 }
 # Non-panel test. Collect all newly added measures
 $count_ref = count($reference_ranges_list);
 $new_measures_list = array();
 $measure_names = $_REQUEST['new_measure'];
 $measure_types = $_REQUEST['new_mtype'];
 $ranges_lower = $_REQUEST['new_range_l'];
 $ranges_upper = $_REQUEST['new_range_u'];
 $units = $_REQUEST['new_unit'];
Esempio n. 25
0
 public function __clone()
 {
     $measure = new Measure($this->getHeader());
     $measure->copyFrom($this);
     return $measure;
 }
Esempio n. 26
0
 public static function getById($measure_id)
 {
     # Returns a test measure by ID
     global $con;
     $measure_id = mysql_real_escape_string($measure_id, $con);
     if ($measure_id == null || $measure_id < 0) {
         return null;
     }
     $query_string = "SELECT * FROM measure WHERE measure_id={$measure_id} LIMIT 1";
     $saved_db = DbUtil::switchToLabConfigRevamp();
     $record = query_associative_one($query_string);
     DbUtil::switchRestore($saved_db);
     return Measure::getObject($record);
 }
Esempio n. 27
0
    query_delete($query_string);
    # Remove entries from test_type_measure
    $query_string = "DELETE FROM test_type_measure WHERE test_type_id={$test_type_id}";
    query_delete($query_string);
    # Remove entries from specimen_test
    $query_string = "DELETE FROM specimen_test WHERE test_type_id={$test_type_id}";
    query_delete($query_string);
    # Remove entry from test_type
    $query_string = "DELETE FROM test_type WHERE test_type_id={$test_type_id}";
    query_delete($query_string);
}
$query_string = "SELECT * FROM measure";
$resultset = query_associative_all($query_string, $row_count);
$measure_list = array();
foreach ($resultset as $record) {
    $measure_list[] = Measure::getObject($record);
}
# For each measure:
foreach ($measure_list as $measure) {
    $measure_id = $measure->measureId;
    # Remove entries from test_type_measure
    $query_string = "DELETE FROM test_type_measure WHERE measure_id={$measure_id}";
    query_delete($query_string);
    # Remove entry from measure
    $query_string = "DELETE FROM measure WHERE measure_id={$measure_id}";
    query_delete($query_string);
}
$query_string = "SELECT * FROM specimen_type";
$resultset = query_associative_all($query_string, $row_count);
$specimen_list = array();
foreach ($resultset as $record) {
Esempio n. 28
0
 public function run()
 {
     /* Users table */
     $usersData = array(array("username" => "administrator", "password" => Hash::make("password"), "email" => "*****@*****.**", "name" => "kBLIS Administrator", "designation" => "Programmer"), array("username" => "external", "password" => Hash::make("password"), "email" => "*****@*****.**", "name" => "External System User", "designation" => "Administrator", "image" => "/i/users/user-2.jpg"), array("username" => "lmorena", "password" => Hash::make("password"), "email" => "*****@*****.**", "name" => "L. Morena", "designation" => "Lab Technologist", "image" => "/i/users/user-3.png"), array("username" => "abumeyang", "password" => Hash::make("password"), "email" => "*****@*****.**", "name" => "A. Abumeyang", "designation" => "Doctor"));
     foreach ($usersData as $user) {
         $users[] = User::create($user);
     }
     $this->command->info('users seeded');
     /* Specimen Types table */
     $specTypesData = array(array("name" => "Ascitic Tap"), array("name" => "Aspirate"), array("name" => "CSF"), array("name" => "Dried Blood Spot"), array("name" => "High Vaginal Swab"), array("name" => "Nasal Swab"), array("name" => "Plasma"), array("name" => "Plasma EDTA"), array("name" => "Pleural Tap"), array("name" => "Pus Swab"), array("name" => "Rectal Swab"), array("name" => "S***n"), array("name" => "Serum"), array("name" => "Skin"), array("name" => "Sputum"), array("name" => "Stool"), array("name" => "Synovial Fluid"), array("name" => "Throat Swab"), array("name" => "Urethral Smear"), array("name" => "Urine"), array("name" => "Vaginal Smear"), array("name" => "Water"), array("name" => "Whole Blood"));
     foreach ($specTypesData as $specimenType) {
         $specTypes[] = SpecimenType::create($specimenType);
     }
     $this->command->info('specimen_types seeded');
     /* Test Categories table - These map on to the lab sections */
     $test_categories = TestCategory::create(array("name" => "PARASITOLOGY", "description" => ""));
     $lab_section_microbiology = TestCategory::create(array("name" => "MICROBIOLOGY", "description" => ""));
     $this->command->info('test_categories seeded');
     /* Measure Types */
     $measureTypes = array(array("id" => "1", "name" => "Numeric Range"), array("id" => "2", "name" => "Alphanumeric Values"), array("id" => "3", "name" => "Autocomplete"), array("id" => "4", "name" => "Free Text"));
     foreach ($measureTypes as $measureType) {
         MeasureType::create($measureType);
     }
     $this->command->info('measure_types seeded');
     /* Measures table */
     $measureBSforMPS = Measure::create(array("measure_type_id" => "2", "name" => "BS for mps", "unit" => ""));
     $measure1 = Measure::create(array("measure_type_id" => "2", "name" => "Grams stain", "unit" => ""));
     $measure2 = Measure::create(array("measure_type_id" => "2", "name" => "SERUM AMYLASE", "unit" => ""));
     $measure3 = Measure::create(array("measure_type_id" => "2", "name" => "calcium", "unit" => ""));
     $measure4 = Measure::create(array("measure_type_id" => "2", "name" => "SGOT", "unit" => ""));
     $measure5 = Measure::create(array("measure_type_id" => "2", "name" => "Indirect COOMBS test", "unit" => ""));
     $measure6 = Measure::create(array("measure_type_id" => "2", "name" => "Direct COOMBS test", "unit" => ""));
     $measure7 = Measure::create(array("measure_type_id" => "2", "name" => "Du test", "unit" => ""));
     MeasureRange::create(array("measure_id" => $measureBSforMPS->id, "alphanumeric" => "No mps seen", "interpretation" => "Negative"));
     MeasureRange::create(array("measure_id" => $measureBSforMPS->id, "alphanumeric" => "+", "interpretation" => "Positive"));
     MeasureRange::create(array("measure_id" => $measureBSforMPS->id, "alphanumeric" => "++", "interpretation" => "Positive"));
     MeasureRange::create(array("measure_id" => $measureBSforMPS->id, "alphanumeric" => "+++", "interpretation" => "Positive"));
     MeasureRange::create(array("measure_id" => $measure1->id, "alphanumeric" => "Negative"));
     MeasureRange::create(array("measure_id" => $measure1->id, "alphanumeric" => "Positive"));
     MeasureRange::create(array("measure_id" => $measure2->id, "alphanumeric" => "Low"));
     MeasureRange::create(array("measure_id" => $measure2->id, "alphanumeric" => "High"));
     MeasureRange::create(array("measure_id" => $measure2->id, "alphanumeric" => "Normal"));
     MeasureRange::create(array("measure_id" => $measure3->id, "alphanumeric" => "High"));
     MeasureRange::create(array("measure_id" => $measure3->id, "alphanumeric" => "Low"));
     MeasureRange::create(array("measure_id" => $measure3->id, "alphanumeric" => "Normal"));
     MeasureRange::create(array("measure_id" => $measure4->id, "alphanumeric" => "High"));
     MeasureRange::create(array("measure_id" => $measure4->id, "alphanumeric" => "Low"));
     MeasureRange::create(array("measure_id" => $measure4->id, "alphanumeric" => "Normal"));
     MeasureRange::create(array("measure_id" => $measure5->id, "alphanumeric" => "Positive"));
     MeasureRange::create(array("measure_id" => $measure5->id, "alphanumeric" => "Negative"));
     MeasureRange::create(array("measure_id" => $measure6->id, "alphanumeric" => "Positive"));
     MeasureRange::create(array("measure_id" => $measure6->id, "alphanumeric" => "Negative"));
     MeasureRange::create(array("measure_id" => $measure7->id, "alphanumeric" => "Positive"));
     MeasureRange::create(array("measure_id" => $measure7->id, "alphanumeric" => "Negative"));
     $measures = array(array("measure_type_id" => "1", "name" => "URIC ACID", "unit" => "mg/dl"), array("measure_type_id" => "4", "name" => "CSF for biochemistry", "unit" => ""), array("measure_type_id" => "4", "name" => "PSA", "unit" => ""), array("measure_type_id" => "1", "name" => "Total", "unit" => "mg/dl"), array("measure_type_id" => "1", "name" => "Alkaline Phosphate", "unit" => "u/l"), array("measure_type_id" => "1", "name" => "Direct", "unit" => "mg/dl"), array("measure_type_id" => "1", "name" => "Total Proteins", "unit" => ""), array("measure_type_id" => "4", "name" => "LFTS", "unit" => "NULL"), array("measure_type_id" => "1", "name" => "Chloride", "unit" => "mmol/l"), array("measure_type_id" => "1", "name" => "Potassium", "unit" => "mmol/l"), array("measure_type_id" => "1", "name" => "Sodium", "unit" => "mmol/l"), array("measure_type_id" => "4", "name" => "Electrolytes", "unit" => ""), array("measure_type_id" => "1", "name" => "Creatinine", "unit" => "mg/dl"), array("measure_type_id" => "1", "name" => "Urea", "unit" => "mg/dl"), array("measure_type_id" => "4", "name" => "RFTS", "unit" => ""), array("measure_type_id" => "4", "name" => "TFT", "unit" => ""));
     foreach ($measures as $measure) {
         Measure::create($measure);
     }
     $measureGXM = Measure::create(array("measure_type_id" => "4", "name" => "GXM", "unit" => ""));
     $measureBG = Measure::create(array("measure_type_id" => "2", "name" => "Blood Grouping", "unit" => ""));
     MeasureRange::create(array("measure_id" => $measureBG->id, "alphanumeric" => "O-"));
     MeasureRange::create(array("measure_id" => $measureBG->id, "alphanumeric" => "O+"));
     MeasureRange::create(array("measure_id" => $measureBG->id, "alphanumeric" => "A-"));
     MeasureRange::create(array("measure_id" => $measureBG->id, "alphanumeric" => "A+"));
     MeasureRange::create(array("measure_id" => $measureBG->id, "alphanumeric" => "B-"));
     MeasureRange::create(array("measure_id" => $measureBG->id, "alphanumeric" => "B+"));
     MeasureRange::create(array("measure_id" => $measureBG->id, "alphanumeric" => "AB-"));
     MeasureRange::create(array("measure_id" => $measureBG->id, "alphanumeric" => "AB+"));
     $measureHB = Measure::create(array("measure_type_id" => Measure::NUMERIC, "name" => "HB", "unit" => "g/dL"));
     $measuresUrinalysisData = array(array("measure_type_id" => "4", "name" => "Urine microscopy", "unit" => ""), array("measure_type_id" => "4", "name" => "Pus cells", "unit" => ""), array("measure_type_id" => "4", "name" => "S. haematobium", "unit" => ""), array("measure_type_id" => "4", "name" => "T. vaginalis", "unit" => ""), array("measure_type_id" => "4", "name" => "Yeast cells", "unit" => ""), array("measure_type_id" => "4", "name" => "Red blood cells", "unit" => ""), array("measure_type_id" => "4", "name" => "Bacteria", "unit" => ""), array("measure_type_id" => "4", "name" => "Spermatozoa", "unit" => ""), array("measure_type_id" => "4", "name" => "Epithelial cells", "unit" => ""), array("measure_type_id" => "4", "name" => "ph", "unit" => ""), array("measure_type_id" => "4", "name" => "Urine chemistry", "unit" => ""), array("measure_type_id" => "4", "name" => "Glucose", "unit" => ""), array("measure_type_id" => "4", "name" => "Ketones", "unit" => ""), array("measure_type_id" => "4", "name" => "Proteins", "unit" => ""), array("measure_type_id" => "4", "name" => "Blood", "unit" => ""), array("measure_type_id" => "4", "name" => "Bilirubin", "unit" => ""), array("measure_type_id" => "4", "name" => "Urobilinogen Phenlpyruvic acid", "unit" => ""), array("measure_type_id" => "4", "name" => "pH", "unit" => ""));
     foreach ($measuresUrinalysisData as $measureU) {
         $measuresUrinalysis[] = Measure::create($measureU);
     }
     $measuresWBCData = array(array("measure_type_id" => Measure::NUMERIC, "name" => "WBC", "unit" => "x10³/µL"), array("measure_type_id" => Measure::NUMERIC, "name" => "Lym", "unit" => "L"), array("measure_type_id" => Measure::NUMERIC, "name" => "Mon", "unit" => "*"), array("measure_type_id" => Measure::NUMERIC, "name" => "Neu", "unit" => "*"), array("measure_type_id" => Measure::NUMERIC, "name" => "Eos", "unit" => ""), array("measure_type_id" => Measure::NUMERIC, "name" => "Baso", "unit" => ""));
     foreach ($measuresWBCData as $value) {
         $measuresWBC[] = Measure::create($value);
     }
     $measureRangesWBC = array(array("measure_id" => $measuresWBC[0]->id, "age_min" => 0, "age_max" => 100, "gender" => MeasureRange::BOTH, "range_lower" => 4, "range_upper" => 11), array("measure_id" => $measuresWBC[1]->id, "age_min" => 0, "age_max" => 100, "gender" => MeasureRange::BOTH, "range_lower" => 1.5, "range_upper" => 4), array("measure_id" => $measuresWBC[2]->id, "age_min" => 0, "age_max" => 100, "gender" => MeasureRange::BOTH, "range_lower" => 0.1, "range_upper" => 9), array("measure_id" => $measuresWBC[3]->id, "age_min" => 0, "age_max" => 100, "gender" => MeasureRange::BOTH, "range_lower" => 2.5, "range_upper" => 7), array("measure_id" => $measuresWBC[4]->id, "age_min" => 0, "age_max" => 100, "gender" => MeasureRange::BOTH, "range_lower" => 0, "range_upper" => 6), array("measure_id" => $measuresWBC[5]->id, "age_min" => 0, "age_max" => 100, "gender" => MeasureRange::BOTH, "range_lower" => 0, "range_upper" => 2));
     foreach ($measureRangesWBC as $value) {
         MeasureRange::create($value);
     }
     $this->command->info('measures seeded');
     /* Test Types table */
     $testTypeBS = TestType::create(array("name" => "BS for mps", "test_category_id" => $test_categories->id, "orderable_test" => 1));
     $testTypeStoolCS = TestType::create(array("name" => "Stool for C/S", "test_category_id" => $lab_section_microbiology->id));
     $testTypeGXM = TestType::create(array("name" => "GXM", "test_category_id" => $test_categories->id));
     $testTypeHB = TestType::create(array("name" => "HB", "test_category_id" => $test_categories->id, "orderable_test" => 1));
     $testTypeUrinalysis = TestType::create(array("name" => "Urinalysis", "test_category_id" => $test_categories->id));
     $testTypeWBC = TestType::create(array("name" => "WBC", "test_category_id" => $test_categories->id));
     $this->command->info('test_types seeded');
     /* TestType Measure table */
     TestTypeMeasure::create(array("test_type_id" => $testTypeBS->id, "measure_id" => $measureBSforMPS->id));
     TestTypeMeasure::create(array("test_type_id" => $testTypeGXM->id, "measure_id" => $measureGXM->id));
     TestTypeMeasure::create(array("test_type_id" => $testTypeGXM->id, "measure_id" => $measureBG->id));
     TestTypeMeasure::create(array("test_type_id" => $testTypeHB->id, "measure_id" => $measureHB->id));
     foreach ($measuresUrinalysis as $value) {
         TestTypeMeasure::create(array("test_type_id" => $testTypeUrinalysis->id, "measure_id" => $value->id));
     }
     foreach ($measuresWBC as $value) {
         TestTypeMeasure::create(array("test_type_id" => $testTypeWBC->id, "measure_id" => $value->id));
     }
     $this->command->info('testtype_measures seeded');
     /* testtype_specimentypes table */
     DB::table('testtype_specimentypes')->insert(array("test_type_id" => $testTypeBS->id, "specimen_type_id" => $specTypes[count($specTypes) - 1]->id));
     DB::table('testtype_specimentypes')->insert(array("test_type_id" => $testTypeGXM->id, "specimen_type_id" => $specTypes[count($specTypes) - 1]->id));
     DB::table('testtype_specimentypes')->insert(array("test_type_id" => $testTypeHB->id, "specimen_type_id" => $specTypes[count($specTypes) - 1]->id));
     DB::table('testtype_specimentypes')->insert(array("test_type_id" => $testTypeHB->id, "specimen_type_id" => $specTypes[6]->id));
     DB::table('testtype_specimentypes')->insert(array("test_type_id" => $testTypeHB->id, "specimen_type_id" => $specTypes[7]->id));
     DB::table('testtype_specimentypes')->insert(array("test_type_id" => $testTypeHB->id, "specimen_type_id" => $specTypes[12]->id));
     DB::table('testtype_specimentypes')->insert(array("test_type_id" => $testTypeUrinalysis->id, "specimen_type_id" => $specTypes[19]->id));
     DB::table('testtype_specimentypes')->insert(array("test_type_id" => $testTypeUrinalysis->id, "specimen_type_id" => $specTypes[20]->id));
     DB::table('testtype_specimentypes')->insert(array("test_type_id" => $testTypeWBC->id, "specimen_type_id" => $specTypes[count($specTypes) - 1]->id));
     $this->command->info('testtype_specimentypes seeded');
     /* Patients table */
     $patients_array = array(array("name" => "Jam Felicia", "email" => "*****@*****.**", "patient_number" => "1002", "dob" => "2000-01-01", "gender" => "1", "created_by" => "2"), array("name" => "Emma Wallace", "email" => "*****@*****.**", "patient_number" => "1003", "dob" => "1990-03-01", "gender" => "1", "created_by" => "2"), array("name" => "Jack Tee", "email" => "*****@*****.**", "patient_number" => "1004", "dob" => "1999-12-18", "gender" => "0", "created_by" => "1"), array("name" => "Hu Jintao", "email" => "*****@*****.**", "patient_number" => "1005", "dob" => "1956-10-28", "gender" => "0", "created_by" => "2"), array("name" => "Lance Opiyo", "email" => "*****@*****.**", "patient_number" => "2150", "dob" => "2012-01-01", "gender" => "0", "created_by" => "1"));
     foreach ($patients_array as $pat) {
         $patients[] = Patient::create($pat);
     }
     $this->command->info('patients seeded');
     /* Test Phase table */
     $test_phases = array(array("id" => "1", "name" => "Pre-Analytical"), array("id" => "2", "name" => "Analytical"), array("id" => "3", "name" => "Post-Analytical"));
     foreach ($test_phases as $test_phase) {
         TestPhase::create($test_phase);
     }
     $this->command->info('test_phases seeded');
     /* Test Status table */
     $test_statuses = array(array("id" => "1", "name" => "not-received", "test_phase_id" => "1"), array("id" => "2", "name" => "pending", "test_phase_id" => "1"), array("id" => "3", "name" => "started", "test_phase_id" => "2"), array("id" => "4", "name" => "completed", "test_phase_id" => "3"), array("id" => "5", "name" => "verified", "test_phase_id" => "3"));
     foreach ($test_statuses as $test_status) {
         TestStatus::create($test_status);
     }
     $this->command->info('test_statuses seeded');
     /* Specimen Status table */
     $specimen_statuses = array(array("id" => "1", "name" => "specimen-not-collected"), array("id" => "2", "name" => "specimen-accepted"), array("id" => "3", "name" => "specimen-rejected"));
     foreach ($specimen_statuses as $specimen_status) {
         SpecimenStatus::create($specimen_status);
     }
     $this->command->info('specimen_statuses seeded');
     /* Visits table */
     for ($i = 0; $i < 7; $i++) {
         $visits[] = Visit::create(array("patient_id" => $patients[rand(0, count($patients) - 1)]->id));
     }
     $this->command->info('visits seeded');
     /* Rejection Reasons table */
     $rejection_reasons_array = array(array("reason" => "Poorly labelled"), array("reason" => "Over saturation"), array("reason" => "Insufficient Sample"), array("reason" => "Scattered"), array("reason" => "Clotted Blood"), array("reason" => "Two layered spots"), array("reason" => "Serum rings"), array("reason" => "Scratched"), array("reason" => "Haemolysis"), array("reason" => "Spots that cannot elute"), array("reason" => "Leaking"), array("reason" => "Broken Sample Container"), array("reason" => "Mismatched sample and form labelling"), array("reason" => "Missing Labels on container and tracking form"), array("reason" => "Empty Container"), array("reason" => "Samples without tracking forms"), array("reason" => "Poor transport"), array("reason" => "Lipaemic"), array("reason" => "Wrong container/Anticoagulant"), array("reason" => "Request form without samples"), array("reason" => "Missing collection date on specimen / request form."), array("reason" => "Name and signature of requester missing"), array("reason" => "Mismatched information on request form and specimen container."), array("reason" => "Request form contaminated with specimen"), array("reason" => "Duplicate specimen received"), array("reason" => "Delay between specimen collection and arrival in the laboratory"), array("reason" => "Inappropriate specimen packing"), array("reason" => "Inappropriate specimen for the test"), array("reason" => "Inappropriate test for the clinical condition"), array("reason" => "No Label"), array("reason" => "Leaking"), array("reason" => "No Sample in the Container"), array("reason" => "No Request Form"), array("reason" => "Missing Information Required"));
     foreach ($rejection_reasons_array as $rejection_reason) {
         $rejection_reasons[] = RejectionReason::create($rejection_reason);
     }
     $this->command->info('rejection_reasons seeded');
     /* Specimen table */
     $this->command->info('specimens seeded');
     $now = new DateTime();
     /* Test table */
     Test::create(array("visit_id" => $visits[rand(0, count($visits) - 1)]->id, "test_type_id" => $testTypeBS->id, "specimen_id" => $this->createSpecimen(Test::NOT_RECEIVED, Specimen::NOT_COLLECTED, SpecimenType::all()->last()->id, $users[rand(0, count($users) - 1)]->id), "test_status_id" => Test::NOT_RECEIVED, "requested_by" => "Dr. Abou Meyang", "created_by" => $users[rand(0, count($users) - 1)]->id));
     Test::create(array("visit_id" => $visits[rand(0, count($visits) - 1)]->id, "test_type_id" => $testTypeHB->id, "specimen_id" => $this->createSpecimen(Test::PENDING, Specimen::NOT_COLLECTED, SpecimenType::all()->last()->id, $users[rand(0, count($users) - 1)]->id), "test_status_id" => Test::PENDING, "requested_by" => "Dr. Abou Meyang", "created_by" => $users[rand(0, count($users) - 1)]->id));
     Test::create(array("visit_id" => $visits[rand(0, count($visits) - 1)]->id, "test_type_id" => $testTypeGXM->id, "specimen_id" => $this->createSpecimen(Test::PENDING, Specimen::NOT_COLLECTED, SpecimenType::all()->last()->id, $users[rand(0, count($users) - 1)]->id), "test_status_id" => Test::PENDING, "requested_by" => "Dr. Abou Meyang", "created_by" => $users[rand(0, count($users) - 1)]->id));
     Test::create(array("visit_id" => $visits[rand(0, count($visits) - 1)]->id, "test_type_id" => $testTypeBS->id, "specimen_id" => $this->createSpecimen(Test::PENDING, Specimen::ACCEPTED, SpecimenType::all()->last()->id, $users[rand(0, count($users) - 1)]->id), "test_status_id" => Test::PENDING, "created_by" => $users[rand(0, count($users) - 1)]->id, "requested_by" => "Dr. Abou Meyang"));
     $test_gxm_accepted_completed = Test::create(array("visit_id" => $visits[rand(0, count($visits) - 1)]->id, "test_type_id" => $testTypeGXM->id, "specimen_id" => $this->createSpecimen(Test::COMPLETED, Specimen::ACCEPTED, SpecimenType::all()->last()->id, $users[rand(0, count($users) - 1)]->id), "interpretation" => "Perfect match.", "test_status_id" => Test::COMPLETED, "created_by" => $users[rand(0, count($users) - 1)]->id, "tested_by" => $users[rand(0, count($users) - 1)]->id, "requested_by" => "Dr. Abou Meyang", "time_started" => $now->format('Y-m-d H:i:s'), "time_completed" => $now->add(new DateInterval('PT12M8S'))->format('Y-m-d H:i:s')));
     $test_hb_accepted_completed = Test::create(array("visit_id" => $visits[rand(0, count($visits) - 1)]->id, "test_type_id" => $testTypeHB->id, "specimen_id" => $this->createSpecimen(Test::COMPLETED, Specimen::ACCEPTED, SpecimenType::all()->last()->id, $users[rand(0, count($users) - 1)]->id), "interpretation" => "Do nothing!", "test_status_id" => Test::COMPLETED, "created_by" => $users[rand(0, count($users) - 1)]->id, "tested_by" => $users[rand(0, count($users) - 1)]->id, "requested_by" => "Genghiz Khan", "time_started" => $now->format('Y-m-d H:i:s'), "time_completed" => $now->add(new DateInterval('PT5M23S'))->format('Y-m-d H:i:s')));
     $tests_accepted_started = Test::create(array("visit_id" => $visits[rand(0, count($visits) - 1)]->id, "test_type_id" => $testTypeGXM->id, "specimen_id" => $this->createSpecimen(Test::STARTED, Specimen::ACCEPTED, SpecimenType::all()->last()->id, $users[rand(0, count($users) - 1)]->id), "test_status_id" => Test::STARTED, "requested_by" => "Dr. Abou Meyang", "created_by" => $users[rand(0, count($users) - 1)]->id, "time_started" => $now->format('Y-m-d H:i:s')));
     $tests_accepted_completed = Test::create(array("visit_id" => $visits[rand(0, count($visits) - 1)]->id, "test_type_id" => $testTypeBS->id, "specimen_id" => $this->createSpecimen(Test::COMPLETED, Specimen::ACCEPTED, SpecimenType::all()->last()->id, $users[rand(0, count($users) - 1)]->id), "interpretation" => "Positive", "test_status_id" => Test::COMPLETED, "created_by" => $users[rand(0, count($users) - 1)]->id, "tested_by" => $users[rand(0, count($users) - 1)]->id, "requested_by" => "Ariel Smith", "time_started" => $now->format('Y-m-d H:i:s'), "time_completed" => $now->add(new DateInterval('PT7M34S'))->format('Y-m-d H:i:s')));
     $tests_accepted_verified = Test::create(array("visit_id" => $visits[rand(0, count($visits) - 1)]->id, "test_type_id" => $testTypeBS->id, "specimen_id" => $this->createSpecimen(Test::VERIFIED, Specimen::ACCEPTED, SpecimenType::all()->last()->id, $users[rand(0, count($users) - 1)]->id), "interpretation" => "Very high concentration of parasites.", "test_status_id" => Test::VERIFIED, "created_by" => $users[rand(0, count($users) - 1)]->id, "tested_by" => $users[rand(0, count($users) - 1)]->id, "verified_by" => $users[rand(0, count($users) - 1)]->id, "requested_by" => "Genghiz Khan", "time_started" => $now, "time_completed" => $now->add(new DateInterval('PT5M17S'))->format('Y-m-d H:i:s'), "time_verified" => $now->add(new DateInterval('PT112M33S'))->format('Y-m-d H:i:s')));
     $tests_rejected_pending = Test::create(array("visit_id" => $visits[rand(0, count($visits) - 1)]->id, "test_type_id" => $testTypeBS->id, "specimen_id" => $this->createSpecimen(Test::PENDING, Specimen::REJECTED, SpecimenType::all()->last()->id, $users[rand(0, count($users) - 1)]->id, $users[rand(0, count($users) - 1)]->id, $rejection_reasons[rand(0, count($rejection_reasons) - 1)]->id), "test_status_id" => Test::PENDING, "requested_by" => "Dr. Abou Meyang", "created_by" => $users[rand(0, count($users) - 1)]->id, "time_started" => $now->format('Y-m-d H:i:s')));
     //  WBC Started
     Test::create(array("visit_id" => $visits[rand(0, count($visits) - 1)]->id, "test_type_id" => $testTypeWBC->id, "specimen_id" => $this->createSpecimen(Test::STARTED, Specimen::ACCEPTED, SpecimenType::all()->last()->id, $users[rand(0, count($users) - 1)]->id), "test_status_id" => Test::PENDING, "requested_by" => "Fred Astaire", "created_by" => $users[rand(0, count($users) - 1)]->id));
     $tests_rejected_started = Test::create(array("visit_id" => $visits[rand(0, count($visits) - 1)]->id, "test_type_id" => $testTypeBS->id, "specimen_id" => $this->createSpecimen(Test::STARTED, Specimen::REJECTED, SpecimenType::all()->last()->id, $users[rand(0, count($users) - 1)]->id, $users[rand(0, count($users) - 1)]->id, $rejection_reasons[rand(0, count($rejection_reasons) - 1)]->id), "test_status_id" => Test::STARTED, "created_by" => $users[rand(0, count($users) - 1)]->id, "requested_by" => "Bony Em", "time_started" => $now->format('Y-m-d H:i:s')));
     $tests_rejected_completed = Test::create(array("visit_id" => $visits[rand(0, count($visits) - 1)]->id, "test_type_id" => $testTypeBS->id, "specimen_id" => $this->createSpecimen(Test::COMPLETED, Specimen::REJECTED, SpecimenType::all()->last()->id, $users[rand(0, count($users) - 1)]->id, $users[rand(0, count($users) - 1)]->id, $rejection_reasons[rand(0, count($rejection_reasons) - 1)]->id), "interpretation" => "Budda Boss", "test_status_id" => Test::COMPLETED, "created_by" => $users[rand(0, count($users) - 1)]->id, "tested_by" => $users[rand(0, count($users) - 1)]->id, "requested_by" => "Ed Buttler", "time_started" => $now->format('Y-m-d H:i:s'), "time_completed" => $now->add(new DateInterval('PT30M4S'))->format('Y-m-d H:i:s')));
     Test::create(array("visit_id" => $visits[rand(0, count($visits) - 1)]->id, "test_type_id" => $testTypeUrinalysis->id, "specimen_id" => $this->createSpecimen(Test::PENDING, Specimen::NOT_COLLECTED, SpecimenType::all()->last()->id, $users[rand(0, count($users) - 1)]->id), "test_status_id" => Test::PENDING, "requested_by" => "Dr. Abou Meyang", "created_by" => $users[rand(0, count($users) - 1)]->id));
     Test::create(array("visit_id" => $visits[rand(0, count($visits) - 1)]->id, "test_type_id" => $testTypeWBC->id, "specimen_id" => $this->createSpecimen(Test::PENDING, Specimen::NOT_COLLECTED, SpecimenType::all()->last()->id, $users[rand(0, count($users) - 1)]->id), "test_status_id" => Test::PENDING, "requested_by" => "Dr. Abou Meyang", "created_by" => $users[rand(0, count($users) - 1)]->id));
     $test_urinalysis_accepted_completed = Test::create(array("visit_id" => $visits[rand(0, count($visits) - 1)]->id, "test_type_id" => $testTypeUrinalysis->id, "specimen_id" => $this->createSpecimen(Test::COMPLETED, Specimen::ACCEPTED, SpecimenType::all()->last()->id, $users[rand(0, count($users) - 1)]->id), "interpretation" => "Whats this !!!! ###%%% ^ *() /", "test_status_id" => Test::COMPLETED, "created_by" => $users[rand(0, count($users) - 1)]->id, "tested_by" => $users[rand(0, count($users) - 1)]->id, "requested_by" => "Dr. Abou Meyang", "time_started" => $now->format('Y-m-d H:i:s'), "time_completed" => $now->add(new DateInterval('PT12M8S'))->format('Y-m-d H:i:s'), "external_id" => 596699));
     $this->command->info('tests seeded');
     /* Test Results table */
     $testResults = array(array("test_id" => $tests_accepted_verified->id, "measure_id" => $measureBSforMPS->id, "result" => "+++"), array("test_id" => $tests_accepted_completed->id, "measure_id" => $measureBSforMPS->id, "result" => "++"), array("test_id" => $test_gxm_accepted_completed->id, "measure_id" => $measureGXM->id, "result" => "COMPATIBLE WITH 061832914 B/G A POS.EXPIRY19/8/14"), array("test_id" => $test_gxm_accepted_completed->id, "measure_id" => $measureBG->id, "result" => "A+"), array("test_id" => $test_hb_accepted_completed->id, "measure_id" => $measureHB->id, "result" => "13.7"), array("test_id" => $tests_rejected_completed->id, "measure_id" => $measureBSforMPS->id, "result" => "No mps seen"));
     foreach ($measuresUrinalysis as $key => $measure) {
         $testResults[] = array("test_id" => $test_urinalysis_accepted_completed->id, "measure_id" => $measure->id, "result" => $key . "50");
     }
     foreach ($testResults as $testResult) {
         TestResult::create($testResult);
     }
     $this->command->info('test results seeded');
     /* Permissions table */
     $permissions = array(array("name" => "view_names", "display_name" => "Can view patient names"), array("name" => "manage_patients", "display_name" => "Can add patients"), array("name" => "receive_external_test", "display_name" => "Can receive test requests"), array("name" => "request_test", "display_name" => "Can request new test"), array("name" => "accept_test_specimen", "display_name" => "Can accept test specimen"), array("name" => "reject_test_specimen", "display_name" => "Can reject test specimen"), array("name" => "change_test_specimen", "display_name" => "Can change test specimen"), array("name" => "start_test", "display_name" => "Can start tests"), array("name" => "enter_test_results", "display_name" => "Can enter tests results"), array("name" => "edit_test_results", "display_name" => "Can edit test results"), array("name" => "verify_test_results", "display_name" => "Can verify test results"), array("name" => "send_results_to_external_system", "display_name" => "Can send test results to external systems"), array("name" => "refer_specimens", "display_name" => "Can refer specimens"), array("name" => "manage_users", "display_name" => "Can manage users"), array("name" => "manage_test_catalog", "display_name" => "Can manage test catalog"), array("name" => "manage_lab_configurations", "display_name" => "Can manage lab configurations"), array("name" => "view_reports", "display_name" => "Can view reports"), array("name" => "manage_inventory", "display_name" => "Can manage inventory"), array("name" => "request_topup", "display_name" => "Can request top-up"), array("name" => "manage_qc", "display_name" => "Can manage Quality Control"));
     foreach ($permissions as $permission) {
         Permission::create($permission);
     }
     $this->command->info('Permissions table seeded');
     /* Roles table */
     $roles = array(array("name" => "Superadmin"), array("name" => "Technologist"), array("name" => "Receptionist"));
     foreach ($roles as $role) {
         Role::create($role);
     }
     $this->command->info('Roles table seeded');
     $user1 = User::find(1);
     $role1 = Role::find(1);
     $permissions = Permission::all();
     //Assign all permissions to role administrator
     foreach ($permissions as $permission) {
         $role1->attachPermission($permission);
     }
     //Assign role Administrator to user 1 administrator
     $user1->attachRole($role1);
     /* Instruments table */
     $instrumentsData = array("name" => "Celltac F Mek 8222", "description" => "Automatic analyzer with 22 parameters and WBC 5 part diff Hematology Analyzer", "driver_name" => "KBLIS\\Plugins\\CelltacFMachine", "ip" => "192.168.1.12", "hostname" => "HEMASERVER");
     $instrument = Instrument::create($instrumentsData);
     $instrument->testTypes()->attach(array($testTypeWBC->id));
     $this->command->info('Instruments table seeded');
     $labRequestUrinalysis[] = json_decode('{"cost":null,"receiptNumber":null,"receiptType":null,"labNo":596699,"parentLabNo":0,"requestingClinician":"frankenstein Dr",
     "investigation":"Urinalysis","requestDate":"2014-10-14 10:20:35","orderStage":"ip","patientVisitNumber":643660,"patient":{"id":326983,
     "fullName":"Macau Macau","dateOfBirth":"1996-10-09 00:00:00","gender":"Female"},"address":{"address":null,"postalCode":null,"phoneNumber":"","city":null}}');
     $labRequestUrinalysis[] = json_decode('{"cost":null,"receiptNumber":null,"receiptType":null,"labNo":596700,"parentLabNo":596699,"requestingClinician":"frankenstein Dr",
     "investigation":"Urine microscopy","requestDate":"2014-10-14 10:20:35","orderStage":"ip","patientVisitNumber":643660,"patient":{"id":326983,
     "fullName":"Macau Macau","dateOfBirth":"1996-10-09 00:00:00","gender":"Female"},"address":{"address":null,"postalCode":null,"phoneNumber":"","city":null}}');
     $labRequestUrinalysis[] = json_decode('{"cost":null,"receiptNumber":null,"receiptType":null,"labNo":596701,"parentLabNo":596700,"requestingClinician":"frankenstein Dr",
     "investigation":"Pus cells","requestDate":"2014-10-14 10:20:35","orderStage":"ip","patientVisitNumber":643660,"patient":{"id":326983,
     "fullName":"Macau Macau","dateOfBirth":"1996-10-09 00:00:00","gender":"Female"},"address":{"address":null,"postalCode":null,"phoneNumber":"","city":null}}');
     $labRequestUrinalysis[] = json_decode('{"cost":null,"receiptNumber":null,"receiptType":null,"labNo":596702,"parentLabNo":596700,"requestingClinician":"frankenstein Dr",
     "investigation":"S. haematobium","requestDate":"2014-10-14 10:20:35","orderStage":"ip","patientVisitNumber":643660,"patient":{"id":326983,
     "fullName":"Macau Macau","dateOfBirth":"1996-10-09 00:00:00","gender":"Female"},"address":{"address":null,"postalCode":null,"phoneNumber":"","city":null}}');
     $labRequestUrinalysis[] = json_decode('{"cost":null,"receiptNumber":null,"receiptType":null,"labNo":596703,"parentLabNo":596700,"requestingClinician":"frankenstein Dr",
     "investigation":"T. vaginalis","requestDate":"2014-10-14 10:20:35","orderStage":"ip","patientVisitNumber":643660,"patient":{"id":326983,
     "fullName":"Macau Macau","dateOfBirth":"1996-10-09 00:00:00","gender":"Female"},"address":{"address":null,"postalCode":null,"phoneNumber":"","city":null}}');
     $labRequestUrinalysis[] = json_decode('{"cost":null,"receiptNumber":null,"receiptType":null,"labNo":596704,"parentLabNo":596700,"requestingClinician":"frankenstein Dr",
     "investigation":"Yeast cells","requestDate":"2014-10-14 10:20:35","orderStage":"ip","patientVisitNumber":643660,"patient":{"id":326983,
     "fullName":"Macau Macau","dateOfBirth":"1996-10-09 00:00:00","gender":"Female"},"address":{"address":null,"postalCode":null,"phoneNumber":"","city":null}}');
     $labRequestUrinalysis[] = json_decode('{"cost":null,"receiptNumber":null,"receiptType":null,"labNo":596705,"parentLabNo":596700,"requestingClinician":"frankenstein Dr",
     "investigation":"Red blood cells","requestDate":"2014-10-14 10:20:35","orderStage":"ip","patientVisitNumber":643660,"patient":{"id":326983,
     "fullName":"Macau Macau","dateOfBirth":"1996-10-09 00:00:00","gender":"Female"},"address":{"address":null,"postalCode":null,"phoneNumber":"","city":null}}');
     $labRequestUrinalysis[] = json_decode('{"cost":null,"receiptNumber":null,"receiptType":null,"labNo":596706,"parentLabNo":596700,"requestingClinician":"frankenstein Dr",
     "investigation":"Bacteria","requestDate":"2014-10-14 10:20:36","orderStage":"ip","patientVisitNumber":643660,"patient":{"id":326983,
     "fullName":"Macau Macau","dateOfBirth":"1996-10-09 00:00:00","gender":"Female"},"address":{"address":null,"postalCode":null,"phoneNumber":"","city":null}}');
     $labRequestUrinalysis[] = json_decode('{"cost":null,"receiptNumber":null,"receiptType":null,"labNo":596707,"parentLabNo":596700,"requestingClinician":"frankenstein Dr",
     "investigation":"Spermatozoa","requestDate":"2014-10-14 10:20:36","orderStage":"ip","patientVisitNumber":643660,"patient":{"id":326983,
     "fullName":"Macau Macau","dateOfBirth":"1996-10-09 00:00:00","gender":"Female"},"address":{"address":null,"postalCode":null,"phoneNumber":"","city":null}}');
     $labRequestUrinalysis[] = json_decode('{"cost":null,"receiptNumber":null,"receiptType":null,"labNo":596708,"parentLabNo":596700,"requestingClinician":"frankenstein Dr",
     "investigation":"Epithelial cells","requestDate":"2014-10-14 10:20:36","orderStage":"ip","patientVisitNumber":643660,"patient":{"id":326983,
     "fullName":"Macau Macau","dateOfBirth":"1996-10-09 00:00:00","gender":"Female"},"address":{"address":null,"postalCode":null,"phoneNumber":"","city":null}}');
     $labRequestUrinalysis[] = json_decode('{"cost":null,"receiptNumber":null,"receiptType":null,"labNo":596709,"parentLabNo":596700,"requestingClinician":"frankenstein Dr",
     "investigation":"ph","requestDate":"2014-10-14 10:20:36","orderStage":"ip","patientVisitNumber":643660,"patient":{"id":326983,
     "fullName":"Macau Macau","dateOfBirth":"1996-10-09 00:00:00","gender":"Female"},"address":{"address":null,"postalCode":null,"phoneNumber":"","city":null}}');
     $labRequestUrinalysis[] = json_decode('{"cost":null,"receiptNumber":null,"receiptType":null,"labNo":596710,"parentLabNo":596699,"requestingClinician":"frankenstein Dr",
     "investigation":"Urine chemistry","requestDate":"2014-10-14 10:20:36","orderStage":"ip","patientVisitNumber":643660,"patient":{"id":326983,
     "fullName":"Macau Macau","dateOfBirth":"1996-10-09 00:00:00","gender":"Female"},"address":{"address":null,"postalCode":null,"phoneNumber":"","city":null}}');
     $labRequestUrinalysis[] = json_decode('{"cost":null,"receiptNumber":null,"receiptType":null,"labNo":596711,"parentLabNo":596710,"requestingClinician":"frankenstein Dr",
     "investigation":"Glucose","requestDate":"2014-10-14 10:20:36","orderStage":"ip","patientVisitNumber":643660,"patient":{"id":326983,
     "fullName":"Macau Macau","dateOfBirth":"1996-10-09 00:00:00","gender":"Female"},"address":{"address":null,"postalCode":null,"phoneNumber":"","city":null}}');
     $labRequestUrinalysis[] = json_decode('{"cost":null,"receiptNumber":null,"receiptType":null,"labNo":596712,"parentLabNo":596710,"requestingClinician":"frankenstein Dr",
     "investigation":"Ketones","requestDate":"2014-10-14 10:20:36","orderStage":"ip","patientVisitNumber":643660,"patient":{"id":326983,
     "fullName":"Macau Macau","dateOfBirth":"1996-10-09 00:00:00","gender":"Female"},"address":{"address":null,"postalCode":null,"phoneNumber":"","city":null}}');
     $labRequestUrinalysis[] = json_decode('{"cost":null,"receiptNumber":null,"receiptType":null,"labNo":596713,"parentLabNo":596710,"requestingClinician":"frankenstein Dr",
     "investigation":"Proteins","requestDate":"2014-10-14 10:20:36","orderStage":"ip","patientVisitNumber":643660,"patient":{"id":326983,
     "fullName":"Macau Macau","dateOfBirth":"1996-10-09 00:00:00","gender":"Female"},"address":{"address":null,"postalCode":null,"phoneNumber":"","city":null}}');
     $labRequestUrinalysis[] = json_decode('{"cost":null,"receiptNumber":null,"receiptType":null,"labNo":596714,"parentLabNo":596710,"requestingClinician":"frankenstein Dr",
     "investigation":"Blood","requestDate":"2014-10-14 10:20:36","orderStage":"ip","patientVisitNumber":643660,"patient":{"id":326983,
     "fullName":"Macau Macau","dateOfBirth":"1996-10-09 00:00:00","gender":"Female"},"address":{"address":null,"postalCode":null,"phoneNumber":"","city":null}}');
     $labRequestUrinalysis[] = json_decode('{"cost":null,"receiptNumber":null,"receiptType":null,"labNo":596715,"parentLabNo":596710,"requestingClinician":"frankenstein Dr",
     "investigation":"Bilirubin","requestDate":"2014-10-14 10:20:36","orderStage":"ip","patientVisitNumber":643660,"patient":{"id":326983,
     "fullName":"Macau Macau","dateOfBirth":"1996-10-09 00:00:00","gender":"Female"},"address":{"address":null,"postalCode":null,"phoneNumber":"","city":null}}');
     $labRequestUrinalysis[] = json_decode('{"cost":null,"receiptNumber":null,"receiptType":null,"labNo":596716,"parentLabNo":596710,"requestingClinician":"frankenstein Dr",
     "investigation":"Urobilinogen Phenlpyruvic acid","requestDate":"2014-10-14 10:20:37","orderStage":"ip","patientVisitNumber":643660,"patient":{"id":326983,
     "fullName":"Macau Macau","dateOfBirth":"1996-10-09 00:00:00","gender":"Female"},"address":{"address":null,"postalCode":null,"phoneNumber":"","city":null}}');
     $labRequestUrinalysis[] = json_decode('{"cost":null,"receiptNumber":null,"receiptType":null,"labNo":596717,"parentLabNo":596710,"requestingClinician":"frankenstein Dr",
     "investigation":"pH","requestDate":"2014-10-14 10:20:37","orderStage":"ip","patientVisitNumber":643660,"patient":{"id":326983,
     "fullName":"Macau Macau","dateOfBirth":"1996-10-09 00:00:00","gender":"Female"},"address":{"address":null,"postalCode":null,"phoneNumber":"","city":null}}');
     for ($i = 0; $i < count($labRequestUrinalysis); $i++) {
         $dumper = new ExternalDump();
         $dumper->lab_no = $labRequestUrinalysis[$i]->labNo;
         $dumper->parent_lab_no = $labRequestUrinalysis[$i]->parentLabNo;
         $dumper->test_id = $i == 0 ? $test_urinalysis_accepted_completed->id : null;
         $dumper->requesting_clinician = $labRequestUrinalysis[$i]->requestingClinician;
         $dumper->investigation = $labRequestUrinalysis[$i]->investigation;
         $dumper->provisional_diagnosis = '';
         $dumper->request_date = $labRequestUrinalysis[$i]->requestDate;
         $dumper->order_stage = $labRequestUrinalysis[$i]->orderStage;
         $dumper->patient_visit_number = $labRequestUrinalysis[$i]->patientVisitNumber;
         $dumper->patient_id = $labRequestUrinalysis[$i]->patient->id;
         $dumper->full_name = $labRequestUrinalysis[$i]->patient->fullName;
         $dumper->dob = $labRequestUrinalysis[$i]->patient->dateOfBirth;
         $dumper->gender = $labRequestUrinalysis[$i]->patient->gender;
         $dumper->address = $labRequestUrinalysis[$i]->address->address;
         $dumper->postal_code = '';
         $dumper->phone_number = $labRequestUrinalysis[$i]->address->phoneNumber;
         $dumper->city = $labRequestUrinalysis[$i]->address->city;
         $dumper->cost = $labRequestUrinalysis[$i]->cost;
         $dumper->receipt_number = $labRequestUrinalysis[$i]->receiptNumber;
         $dumper->receipt_type = $labRequestUrinalysis[$i]->receiptType;
         $dumper->waiver_no = '';
         $dumper->system_id = "sanitas";
         $dumper->save();
     }
     $this->command->info('ExternalDump table seeded');
     //  Begin seed for prevalence rates report
     /* Test Categories table - These map on to the lab sections */
     $lab_section_hematology = TestCategory::create(array("name" => "HEMATOLOGY", "description" => ""));
     $lab_section_serology = TestCategory::create(array("name" => "SEROLOGY", "description" => ""));
     $lab_section_trans = TestCategory::create(array("name" => "BLOOD TRANSFUSION", "description" => ""));
     $this->command->info('Lab Sections seeded');
     /* Test Types for prevalence */
     $test_types_salmonella = TestType::create(array("name" => "Salmonella Antigen Test", "test_category_id" => $test_categories->id));
     $test_types_direct = TestType::create(array("name" => "Direct COOMBS Test", "test_category_id" => $lab_section_trans->id));
     $test_types_du = TestType::create(array("name" => "DU Test", "test_category_id" => $lab_section_trans->id));
     $test_types_sickling = TestType::create(array("name" => "Sickling Test", "test_category_id" => $lab_section_hematology->id));
     $test_types_borrelia = TestType::create(array("name" => "Borrelia", "test_category_id" => $test_categories->id));
     $test_types_vdrl = TestType::create(array("name" => "VDRL", "test_category_id" => $lab_section_serology->id));
     $test_types_pregnancy = TestType::create(array("name" => "Pregnancy Test", "test_category_id" => $lab_section_serology->id));
     $test_types_brucella = TestType::create(array("name" => "Brucella", "test_category_id" => $lab_section_serology->id));
     $test_types_pylori = TestType::create(array("name" => "H. Pylori", "test_category_id" => $lab_section_serology->id));
     $this->command->info('Test Types seeded');
     /* Test Types and specimen types relationship for prevalence */
     DB::insert('INSERT INTO testtype_specimentypes (test_type_id, specimen_type_id) VALUES (?, ?)', array($test_types_salmonella->id, "13"));
     DB::insert('INSERT INTO testtype_specimentypes (test_type_id, specimen_type_id) VALUES (?, ?)', array($test_types_direct->id, "23"));
     DB::insert('INSERT INTO testtype_specimentypes (test_type_id, specimen_type_id) VALUES (?, ?)', array($test_types_du->id, "23"));
     DB::insert('INSERT INTO testtype_specimentypes (test_type_id, specimen_type_id) VALUES (?, ?)', array($test_types_sickling->id, "23"));
     DB::insert('INSERT INTO testtype_specimentypes (test_type_id, specimen_type_id) VALUES (?, ?)', array($test_types_borrelia->id, "23"));
     DB::insert('INSERT INTO testtype_specimentypes (test_type_id, specimen_type_id) VALUES (?, ?)', array($test_types_vdrl->id, "13"));
     DB::insert('INSERT INTO testtype_specimentypes (test_type_id, specimen_type_id) VALUES (?, ?)', array($test_types_pregnancy->id, "20"));
     DB::insert('INSERT INTO testtype_specimentypes (test_type_id, specimen_type_id) VALUES (?, ?)', array($test_types_brucella->id, "13"));
     DB::insert('INSERT INTO testtype_specimentypes (test_type_id, specimen_type_id) VALUES (?, ?)', array($test_types_pylori->id, "13"));
     DB::insert('INSERT INTO testtype_specimentypes (test_type_id, specimen_type_id) VALUES (?, ?)', array($testTypeStoolCS->id, "16"));
     $this->command->info('TestTypes/SpecimenTypes seeded');
     /*New measures for prevalence*/
     $measure_salmonella = Measure::create(array("measure_type_id" => "2", "name" => "Salmonella Antigen Test", "unit" => ""));
     $measure_direct = Measure::create(array("measure_type_id" => "2", "name" => "Direct COOMBS Test", "unit" => ""));
     $measure_du = Measure::create(array("measure_type_id" => "2", "name" => "Du Test", "unit" => ""));
     $measure_sickling = Measure::create(array("measure_type_id" => "2", "name" => "Sickling Test", "unit" => ""));
     $measure_borrelia = Measure::create(array("measure_type_id" => "2", "name" => "Borrelia", "unit" => ""));
     $measure_vdrl = Measure::create(array("measure_type_id" => "2", "name" => "VDRL", "unit" => ""));
     $measure_pregnancy = Measure::create(array("measure_type_id" => "2", "name" => "Pregnancy Test", "unit" => ""));
     $measure_brucella = Measure::create(array("measure_type_id" => "2", "name" => "Brucella", "unit" => ""));
     $measure_pylori = Measure::create(array("measure_type_id" => "2", "name" => "H. Pylori", "unit" => ""));
     MeasureRange::create(array("measure_id" => $measure_salmonella->id, "alphanumeric" => "Positive"));
     MeasureRange::create(array("measure_id" => $measure_salmonella->id, "alphanumeric" => "Negative"));
     MeasureRange::create(array("measure_id" => $measure_direct->id, "alphanumeric" => "Positive"));
     MeasureRange::create(array("measure_id" => $measure_direct->id, "alphanumeric" => "Negative"));
     MeasureRange::create(array("measure_id" => $measure_du->id, "alphanumeric" => "Positive"));
     MeasureRange::create(array("measure_id" => $measure_du->id, "alphanumeric" => "Negative"));
     MeasureRange::create(array("measure_id" => $measure_sickling->id, "alphanumeric" => "Positive"));
     MeasureRange::create(array("measure_id" => $measure_sickling->id, "alphanumeric" => "Negative"));
     MeasureRange::create(array("measure_id" => $measure_borrelia->id, "alphanumeric" => "Positive"));
     MeasureRange::create(array("measure_id" => $measure_borrelia->id, "alphanumeric" => "Negative"));
     MeasureRange::create(array("measure_id" => $measure_vdrl->id, "alphanumeric" => "Positive"));
     MeasureRange::create(array("measure_id" => $measure_vdrl->id, "alphanumeric" => "Negative"));
     MeasureRange::create(array("measure_id" => $measure_pregnancy->id, "alphanumeric" => "Positive"));
     MeasureRange::create(array("measure_id" => $measure_pregnancy->id, "alphanumeric" => "Negative"));
     MeasureRange::create(array("measure_id" => $measure_brucella->id, "alphanumeric" => "Positive"));
     MeasureRange::create(array("measure_id" => $measure_brucella->id, "alphanumeric" => "Negative"));
     MeasureRange::create(array("measure_id" => $measure_pylori->id, "alphanumeric" => "Positive"));
     MeasureRange::create(array("measure_id" => $measure_pylori->id, "alphanumeric" => "Negative"));
     $this->command->info('Measures seeded again');
     /* TestType Measure for prevalence */
     $testtype_measure = TestTypeMeasure::create(array("test_type_id" => $test_types_salmonella->id, "measure_id" => $measure_salmonella->id));
     $testtype_measure = TestTypeMeasure::create(array("test_type_id" => $test_types_direct->id, "measure_id" => $measure_direct->id));
     $testtype_measure = TestTypeMeasure::create(array("test_type_id" => $test_types_du->id, "measure_id" => $measure_du->id));
     $testtype_measure = TestTypeMeasure::create(array("test_type_id" => $test_types_sickling->id, "measure_id" => $measure_sickling->id));
     $testtype_measure = TestTypeMeasure::create(array("test_type_id" => $test_types_borrelia->id, "measure_id" => $measure_borrelia->id));
     $testtype_measure = TestTypeMeasure::create(array("test_type_id" => $test_types_vdrl->id, "measure_id" => $measure_vdrl->id));
     $testtype_measure = TestTypeMeasure::create(array("test_type_id" => $test_types_pregnancy->id, "measure_id" => $measure_pregnancy->id));
     $testtype_measure = TestTypeMeasure::create(array("test_type_id" => $test_types_brucella->id, "measure_id" => $measure_brucella->id));
     $testtype_measure = TestTypeMeasure::create(array("test_type_id" => $test_types_pylori->id, "measure_id" => $measure_pylori->id));
     $this->command->info('Test Type Measures seeded again');
     /*  Tests for prevalence rates  */
     $tests_completed_one = Test::create(array("visit_id" => "1", "test_type_id" => $test_types_salmonella->id, "specimen_id" => "4", "interpretation" => "Budda Boss", "test_status_id" => Test::COMPLETED, "created_by" => "2", "tested_by" => "3", "requested_by" => "Ariel Smith", "time_created" => "2014-07-23 15:16:15", "time_started" => "2014-07-23 16:07:15", "time_completed" => "2014-07-23 16:17:19"));
     $tests_completed_two = Test::create(array("visit_id" => "2", "test_type_id" => $test_types_direct->id, "specimen_id" => "3", "interpretation" => "Budda Boss", "test_status_id" => Test::COMPLETED, "created_by" => "2", "tested_by" => "3", "requested_by" => "Ariel Smith", "time_created" => "2014-07-26 10:16:15", "time_started" => "2014-07-26 13:27:15", "time_completed" => "2014-07-26 13:57:01"));
     $tests_completed_three = Test::create(array("visit_id" => "3", "test_type_id" => $test_types_du->id, "specimen_id" => "2", "interpretation" => "Budda Boss", "test_status_id" => Test::COMPLETED, "created_by" => "2", "tested_by" => "3", "requested_by" => "Ariel Smith", "time_created" => "2014-08-13 09:16:15", "time_started" => "2014-08-13 10:07:15", "time_completed" => "2014-08-13 10:18:11"));
     $tests_completed_four = Test::create(array("visit_id" => "4", "test_type_id" => $test_types_sickling->id, "specimen_id" => "1", "interpretation" => "Budda Boss", "test_status_id" => Test::COMPLETED, "created_by" => "2", "tested_by" => "3", "requested_by" => "Ariel Smith", "time_created" => "2014-08-16 09:06:53", "time_started" => "2014-08-16 09:09:15", "time_completed" => "2014-08-16 09:23:37"));
     $tests_completed_five = Test::create(array("visit_id" => "5", "test_type_id" => $test_types_borrelia->id, "specimen_id" => "1", "interpretation" => "Budda Boss", "test_status_id" => Test::COMPLETED, "created_by" => "2", "tested_by" => "3", "requested_by" => "Ariel Smith", "time_created" => "2014-08-23 10:16:15", "time_started" => "2014-08-23 11:54:39", "time_completed" => "2014-08-23 12:07:18"));
     $tests_completed_six = Test::create(array("visit_id" => "6", "test_type_id" => $test_types_vdrl->id, "specimen_id" => "2", "interpretation" => "Budda Boss", "test_status_id" => Test::COMPLETED, "created_by" => "2", "tested_by" => "3", "requested_by" => "Ariel Smith", "time_created" => "2014-09-07 07:23:15", "time_started" => "2014-09-07 08:07:20", "time_completed" => "2014-09-07 08:41:13"));
     $tests_completed_seven = Test::create(array("visit_id" => "7", "test_type_id" => $test_types_pregnancy->id, "specimen_id" => "3", "interpretation" => "Budda Boss", "test_status_id" => Test::COMPLETED, "created_by" => "2", "tested_by" => "3", "requested_by" => "Ariel Smith", "time_created" => "2014-10-03 11:52:15", "time_started" => "2014-10-03 12:31:04", "time_completed" => "2014-10-03 12:45:18"));
     $tests_completed_eight = Test::create(array("visit_id" => "1", "test_type_id" => $test_types_brucella->id, "specimen_id" => "4", "interpretation" => "Budda Boss", "test_status_id" => Test::COMPLETED, "created_by" => "2", "tested_by" => "3", "requested_by" => "Ariel Smith", "time_created" => "2014-10-15 17:01:15", "time_started" => "2014-10-15 17:05:24", "time_completed" => "2014-10-15 18:07:15"));
     $tests_completed_nine = Test::create(array("visit_id" => "2", "test_type_id" => $test_types_pylori->id, "specimen_id" => "4", "interpretation" => "Budda Boss", "test_status_id" => Test::COMPLETED, "created_by" => "2", "tested_by" => "3", "requested_by" => "Ariel Smith", "time_created" => "2014-10-23 16:06:15", "time_started" => "2014-10-23 16:07:15", "time_completed" => "2014-10-23 16:39:02"));
     $tests_completed_ten = Test::create(array("visit_id" => "4", "test_type_id" => $test_types_salmonella->id, "specimen_id" => "3", "interpretation" => "Budda Boss", "test_status_id" => Test::COMPLETED, "created_by" => "2", "tested_by" => "3", "requested_by" => "Ariel Smith", "time_created" => "2014-10-21 19:16:15", "time_started" => "2014-10-21 19:17:15", "time_completed" => "2014-10-21 19:52:40"));
     $tests_verified_one = Test::create(array("visit_id" => "3", "test_type_id" => $test_types_direct->id, "specimen_id" => "2", "interpretation" => "Budda Boss", "test_status_id" => Test::VERIFIED, "created_by" => "3", "tested_by" => "2", "verified_by" => "3", "requested_by" => "Genghiz Khan", "time_created" => "2014-07-21 19:16:15", "time_started" => "2014-07-21 19:17:15", "time_completed" => "2014-07-21 19:52:40", "time_verified" => "2014-07-21 19:53:48"));
     $tests_verified_two = Test::create(array("visit_id" => "2", "test_type_id" => $test_types_du->id, "specimen_id" => "1", "interpretation" => "Budda Boss", "test_status_id" => Test::VERIFIED, "created_by" => "3", "tested_by" => "2", "verified_by" => "3", "requested_by" => "Genghiz Khan", "time_created" => "2014-08-21 19:16:15", "time_started" => "2014-08-21 19:17:15", "time_completed" => "2014-08-21 19:52:40", "time_verified" => "2014-08-21 19:53:48"));
     $tests_verified_three = Test::create(array("visit_id" => "3", "test_type_id" => $test_types_sickling->id, "specimen_id" => "4", "interpretation" => "Budda Boss", "test_status_id" => Test::VERIFIED, "created_by" => "3", "tested_by" => "2", "verified_by" => "3", "requested_by" => "Genghiz Khan", "time_created" => "2014-08-26 19:16:15", "time_started" => "2014-08-26 19:17:15", "time_completed" => "2014-08-26 19:52:40", "time_verified" => "2014-08-26 19:53:48"));
     $tests_verified_four = Test::create(array("visit_id" => "4", "test_type_id" => $test_types_borrelia->id, "specimen_id" => "2", "interpretation" => "Budda Boss", "test_status_id" => Test::VERIFIED, "created_by" => "3", "tested_by" => "2", "verified_by" => "3", "requested_by" => "Genghiz Khan", "time_created" => "2014-09-21 19:16:15", "time_started" => "2014-09-21 19:17:15", "time_completed" => "2014-09-21 19:52:40", "time_verified" => "2014-09-21 19:53:48"));
     $tests_verified_five = Test::create(array("visit_id" => "1", "test_type_id" => $test_types_vdrl->id, "specimen_id" => "3", "interpretation" => "Budda Boss", "test_status_id" => Test::VERIFIED, "created_by" => "3", "tested_by" => "2", "verified_by" => "3", "requested_by" => "Genghiz Khan", "time_created" => "2014-09-22 19:16:15", "time_started" => "2014-09-22 19:17:15", "time_completed" => "2014-09-22 19:52:40", "time_verified" => "2014-09-22 19:53:48"));
     $tests_verified_six = Test::create(array("visit_id" => "1", "test_type_id" => $test_types_pregnancy->id, "specimen_id" => "4", "interpretation" => "Budda Boss", "test_status_id" => Test::VERIFIED, "created_by" => "3", "tested_by" => "2", "verified_by" => "3", "requested_by" => "Genghiz Khan", "time_created" => "2014-09-23 19:16:15", "time_started" => "2014-09-23 19:17:15", "time_completed" => "2014-09-23 19:52:40", "time_verified" => "2014-09-23 19:53:48"));
     $tests_verified_seven = Test::create(array("visit_id" => "1", "test_type_id" => $test_types_brucella->id, "specimen_id" => "2", "interpretation" => "Budda Boss", "test_status_id" => Test::VERIFIED, "created_by" => "3", "tested_by" => "2", "verified_by" => "3", "requested_by" => "Genghiz Khan", "time_created" => "2014-09-27 19:16:15", "time_started" => "2014-09-27 19:17:15", "time_completed" => "2014-09-27 19:52:40", "time_verified" => "2014-09-27 19:53:48"));
     $tests_verified_eight = Test::create(array("visit_id" => "3", "test_type_id" => $test_types_pylori->id, "specimen_id" => "4", "interpretation" => "Budda Boss", "test_status_id" => Test::VERIFIED, "created_by" => "3", "tested_by" => "2", "verified_by" => "3", "requested_by" => "Genghiz Khan", "time_created" => "2014-10-22 19:16:15", "time_started" => "2014-10-22 19:17:15", "time_completed" => "2014-10-22 19:52:40", "time_verified" => "2014-10-22 19:53:48"));
     $tests_verified_nine = Test::create(array("visit_id" => "4", "test_type_id" => $test_types_pregnancy->id, "specimen_id" => "3", "interpretation" => "Budda Boss", "test_status_id" => Test::VERIFIED, "created_by" => "3", "tested_by" => "2", "verified_by" => "3", "requested_by" => "Genghiz Khan", "time_created" => "2014-10-17 19:16:15", "time_started" => "2014-10-17 19:17:15", "time_completed" => "2014-10-17 19:52:40", "time_verified" => "2014-10-17 19:53:48"));
     $tests_verified_ten = Test::create(array("visit_id" => "2", "test_type_id" => $test_types_pregnancy->id, "specimen_id" => "1", "interpretation" => "Budda Boss", "test_status_id" => Test::VERIFIED, "created_by" => "3", "tested_by" => "2", "verified_by" => "3", "requested_by" => "Genghiz Khan", "time_created" => "2014-10-02 19:16:15", "time_started" => "2014-10-02 19:17:15", "time_completed" => "2014-10-02 19:52:40", "time_verified" => "2014-10-02 19:53:48"));
     $this->command->info('Tests seeded again');
     //  Test results for prevalence
     $results = array(array("test_id" => $tests_completed_one->id, "measure_id" => $measure_salmonella->id, "result" => "Positive"), array("test_id" => $tests_completed_two->id, "measure_id" => $measure_direct->id, "result" => "Positive"), array("test_id" => $tests_completed_three->id, "measure_id" => $measure_du->id, "result" => "Positive"), array("test_id" => $tests_completed_four->id, "measure_id" => $measure_sickling->id, "result" => "Positive"), array("test_id" => $tests_completed_five->id, "measure_id" => $measure_borrelia->id, "result" => "Positive"), array("test_id" => $tests_completed_six->id, "measure_id" => $measure_vdrl->id, "result" => "Positive"), array("test_id" => $tests_completed_seven->id, "measure_id" => $measure_pregnancy->id, "result" => "Positive"), array("test_id" => $tests_completed_eight->id, "measure_id" => $measure_brucella->id, "result" => "Positive"), array("test_id" => $tests_completed_nine->id, "measure_id" => $measure_pylori->id, "result" => "Positive"), array("test_id" => $tests_completed_ten->id, "measure_id" => $measure_salmonella->id, "result" => "Positive"), array("test_id" => $tests_verified_one->id, "measure_id" => $measure_direct->id, "result" => "Negative"), array("test_id" => $tests_verified_two->id, "measure_id" => $measure_du->id, "result" => "Positive"), array("test_id" => $tests_verified_three->id, "measure_id" => $measure_sickling->id, "result" => "Positive"), array("test_id" => $tests_verified_four->id, "measure_id" => $measure_borrelia->id, "result" => "Negative"), array("test_id" => $tests_verified_five->id, "measure_id" => $measure_vdrl->id, "result" => "Negative"), array("test_id" => $tests_verified_six->id, "measure_id" => $measure_pregnancy->id, "result" => "Negative"), array("test_id" => $tests_verified_seven->id, "measure_id" => $measure_brucella->id, "result" => "Positive"), array("test_id" => $tests_verified_eight->id, "measure_id" => $measure_pylori->id, "result" => "Positive"), array("test_id" => $tests_verified_nine->id, "measure_id" => $measure_pregnancy->id, "result" => "Negative"), array("test_id" => $tests_verified_ten->id, "measure_id" => $measure_pregnancy->id, "result" => "Positive"));
     foreach ($results as $result) {
         TestResult::create($result);
     }
     $this->command->info('Test results seeded again');
     //  End prevalence rates seed
     //Seed for facilities
     $facilitiesSeed = array(array('name' => "WALTER REED"), array('name' => "AGA KHAN UNIVERSITY HOSPITAL"), array('name' => "TEL AVIV GENERAL HOSPITAL"), array('name' => "GK PRISON DISPENSARY"), array('name' => "KEMRI ALUPE"), array('name' => "AMPATH"));
     foreach ($facilitiesSeed as $facility) {
         Facility::create($facility);
     }
     $this->command->info('Facilities table seeded');
     //Seed for suppliers
     $supplier = Supplier::create(array("name" => "UNICEF", "phone_no" => "0775112233", "email" => "*****@*****.**", "physical_address" => "un-hqtr"));
     $this->command->info('Suppliers table seeded');
     //Seed for metrics
     $metric = Metric::create(array("name" => "mg", "description" => "milligram"));
     $this->command->info('Metrics table seeded');
     //Seed for commodities
     $commodity = Commodity::create(array("name" => "Ampicillin", "description" => "Capsule 250mg", "metric_id" => $metric->id, "unit_price" => "500", "item_code" => "no clue", "storage_req" => "no clue", "min_level" => "100000", "max_level" => "400000"));
     $this->command->info('Commodities table seeded');
     //Seed for receipts
     $receipt = Receipt::create(array("commodity_id" => $commodity->id, "supplier_id" => $supplier->id, "quantity" => "130000", "batch_no" => "002720", "expiry_date" => "2018-10-14", "user_id" => "1"));
     $this->command->info('Receipts table seeded');
     //Seed for Top Up Request
     $topUpRequest = TopupRequest::create(array("commodity_id" => $commodity->id, "test_category_id" => 1, "order_quantity" => "1500", "user_id" => 1, "remarks" => "-"));
     $this->command->info('Top Up Requests table seeded');
     //Seed for Issues
     Issue::create(array("receipt_id" => $receipt->id, "topup_request_id" => $topUpRequest->id, "quantity_issued" => "1700", "issued_to" => 1, "user_id" => 1, "remarks" => "-"));
     $this->command->info('Issues table seeded');
     //Seed for diseases
     $malaria = Disease::create(array('name' => "Malaria"));
     $typhoid = Disease::create(array('name' => "Typhoid"));
     $dysentry = Disease::create(array('name' => "Shigella Dysentry"));
     $this->command->info("Dieases table seeded");
     $reportDiseases = array(array("test_type_id" => $testTypeBS->id, "disease_id" => $malaria->id), array("test_type_id" => $test_types_salmonella->id, "disease_id" => $typhoid->id), array("test_type_id" => $testTypeStoolCS->id, "disease_id" => $dysentry->id));
     foreach ($reportDiseases as $reportDisease) {
         ReportDisease::create($reportDisease);
     }
     $this->command->info("Report Disease table seeded");
     //Seeding for QC
     $lots = array(array('number' => '0001', 'description' => 'First lot', 'expiry' => date('Y-m-d H:i:s', strtotime("+6 months")), 'instrument_id' => 1), array('number' => '0002', 'description' => 'Second lot', 'expiry' => date('Y-m-d H:i:s', strtotime("+7 months")), 'instrument_id' => 1));
     foreach ($lots as $lot) {
         $lot = Lot::create($lot);
     }
     $this->command->info("Lot table seeded");
     //Control seeding
     $controls = array(array('name' => 'Humatrol P', 'description' => 'HUMATROL P control serum has been designed to provide a suitable basis for the quality control (imprecision, inaccuracy) in the clinical chemical laboratory.', 'lot_id' => 1), array('name' => 'Full Blood Count', 'description' => 'Né pas touchér', 'lot_id' => 1));
     foreach ($controls as $control) {
         Control::create($control);
     }
     $this->command->info("Control table seeded");
     //Control measures
     $controlMeasures = array(array('name' => 'ca', 'unit' => 'mmol', 'control_id' => 1, 'control_measure_type_id' => 1), array('name' => 'pi', 'unit' => 'mmol', 'control_id' => 1, 'control_measure_type_id' => 1), array('name' => 'mg', 'unit' => 'mmol', 'control_id' => 1, 'control_measure_type_id' => 1), array('name' => 'na', 'unit' => 'mmol', 'control_id' => 1, 'control_measure_type_id' => 1), array('name' => 'K', 'unit' => 'mmol', 'control_id' => 1, 'control_measure_type_id' => 1), array('name' => 'WBC', 'unit' => 'x 103/uL', 'control_id' => 2, 'control_measure_type_id' => 1), array('name' => 'RBC', 'unit' => 'x 106/uL', 'control_id' => 2, 'control_measure_type_id' => 1), array('name' => 'HGB', 'unit' => 'g/dl', 'control_id' => 2, 'control_measure_type_id' => 1), array('name' => 'HCT', 'unit' => '%', 'control_id' => 2, 'control_measure_type_id' => 1), array('name' => 'MCV', 'unit' => 'fl', 'control_id' => 2, 'control_measure_type_id' => 1), array('name' => 'MCH', 'unit' => 'pg', 'control_id' => 2, 'control_measure_type_id' => 1), array('name' => 'MCHC', 'unit' => 'g/dl', 'control_id' => 2, 'control_measure_type_id' => 1), array('name' => 'PLT', 'unit' => 'x 103/uL', 'control_id' => 2, 'control_measure_type_id' => 1));
     foreach ($controlMeasures as $controlMeasure) {
         ControlMeasure::create($controlMeasure);
     }
     $this->command->info("Control Measure table seeded");
     //Control measure ranges
     $controlMeasureRanges = array(array('upper_range' => '2.63', 'lower_range' => '7.19', 'control_measure_id' => 1), array('upper_range' => '11.65', 'lower_range' => '15.43', 'control_measure_id' => 2), array('upper_range' => '12.13', 'lower_range' => '19.11', 'control_measure_id' => 3), array('upper_range' => '15.73', 'lower_range' => '25.01', 'control_measure_id' => 4), array('upper_range' => '17.63', 'lower_range' => '20.12', 'control_measure_id' => 5), array('upper_range' => '6.5', 'lower_range' => '7.5', 'control_measure_id' => 6), array('upper_range' => '4.36', 'lower_range' => '5.78', 'control_measure_id' => 7), array('upper_range' => '13.8', 'lower_range' => '17.3', 'control_measure_id' => 8), array('upper_range' => '81.0', 'lower_range' => '95.0', 'control_measure_id' => 9), array('upper_range' => '1.99', 'lower_range' => '2.63', 'control_measure_id' => 10), array('upper_range' => '27.6', 'lower_range' => '33.0', 'control_measure_id' => 11), array('upper_range' => '32.8', 'lower_range' => '36.4', 'control_measure_id' => 12), array('upper_range' => '141', 'lower_range' => ' 320.0', 'control_measure_id' => 13));
     foreach ($controlMeasureRanges as $controlMeasureRange) {
         ControlMeasureRange::create($controlMeasureRange);
     }
     $this->command->info("Control Measure ranges table seeded");
     //Control Tests
     $controlTests = array(array('entered_by' => 3, 'control_id' => 1, 'created_at' => date('Y-m-d', strtotime('-10 days'))), array('entered_by' => 3, 'control_id' => 1, 'created_at' => date('Y-m-d', strtotime('-9 days'))), array('entered_by' => 3, 'control_id' => 1, 'created_at' => date('Y-m-d', strtotime('-8 days'))), array('entered_by' => 3, 'control_id' => 1, 'created_at' => date('Y-m-d', strtotime('-7 days'))), array('entered_by' => 3, 'control_id' => 1, 'created_at' => date('Y-m-d', strtotime('-6 days'))), array('entered_by' => 3, 'control_id' => 1, 'created_at' => date('Y-m-d', strtotime('-5 days'))), array('entered_by' => 3, 'control_id' => 1, 'created_at' => date('Y-m-d', strtotime('-4 days'))), array('entered_by' => 1, 'control_id' => 2, 'created_at' => date('Y-m-d', strtotime('-3 days'))), array('entered_by' => 1, 'control_id' => 2, 'created_at' => date('Y-m-d', strtotime('-2 days'))));
     foreach ($controlTests as $controltest) {
         ControlTest::create($controltest);
     }
     $this->command->info("Control test table seeded");
     //Control results
     $controlResults = array(array('results' => '2.78', 'control_measure_id' => 1, 'control_test_id' => 1, 'created_at' => date('Y-m-d', strtotime('-10 days'))), array('results' => '13.56', 'control_measure_id' => 2, 'control_test_id' => 1, 'created_at' => date('Y-m-d', strtotime('-10 days'))), array('results' => '14.77', 'control_measure_id' => 3, 'control_test_id' => 1, 'created_at' => date('Y-m-d', strtotime('-10 days'))), array('results' => '25.92', 'control_measure_id' => 4, 'control_test_id' => 1, 'created_at' => date('Y-m-d', strtotime('-10 days'))), array('results' => '18.87', 'control_measure_id' => 5, 'control_test_id' => 1, 'created_at' => date('Y-m-d', strtotime('-10 days'))), array('results' => '6.78', 'control_measure_id' => 1, 'control_test_id' => 2, 'created_at' => date('Y-m-d', strtotime('-9 days'))), array('results' => '15.56', 'control_measure_id' => 2, 'control_test_id' => 2, 'created_at' => date('Y-m-d', strtotime('-9 days'))), array('results' => '18.77', 'control_measure_id' => 3, 'control_test_id' => 2, 'created_at' => date('Y-m-d', strtotime('-9 days'))), array('results' => '30.92', 'control_measure_id' => 4, 'control_test_id' => 2, 'created_at' => date('Y-m-d', strtotime('-9 days'))), array('results' => '17.87', 'control_measure_id' => 5, 'control_test_id' => 2, 'created_at' => date('Y-m-d', strtotime('-9 days'))), array('results' => '8.78', 'control_measure_id' => 1, 'control_test_id' => 3, 'created_at' => date('Y-m-d', strtotime('-8 days'))), array('results' => '17.56', 'control_measure_id' => 2, 'control_test_id' => 3, 'created_at' => date('Y-m-d', strtotime('-8 days'))), array('results' => '21.77', 'control_measure_id' => 3, 'control_test_id' => 3, 'created_at' => date('Y-m-d', strtotime('-8 days'))), array('results' => '27.92', 'control_measure_id' => 4, 'control_test_id' => 3, 'created_at' => date('Y-m-d', strtotime('-8 days'))), array('results' => '22.87', 'control_measure_id' => 5, 'control_test_id' => 3, 'created_at' => date('Y-m-d', strtotime('-8 days'))), array('results' => '6.78', 'control_measure_id' => 1, 'control_test_id' => 4, 'created_at' => date('Y-m-d', strtotime('-7 days'))), array('results' => '18.56', 'control_measure_id' => 2, 'control_test_id' => 4, 'created_at' => date('Y-m-d', strtotime('-7 days'))), array('results' => '19.77', 'control_measure_id' => 3, 'control_test_id' => 4, 'created_at' => date('Y-m-d', strtotime('-7 days'))), array('results' => '12.92', 'control_measure_id' => 4, 'control_test_id' => 4, 'created_at' => date('Y-m-d', strtotime('-7 days'))), array('results' => '22.87', 'control_measure_id' => 5, 'control_test_id' => 4, 'created_at' => date('Y-m-d', strtotime('-7 days'))), array('results' => '3.78', 'control_measure_id' => 1, 'control_test_id' => 5, 'created_at' => date('Y-m-d', strtotime('-6 days'))), array('results' => '16.56', 'control_measure_id' => 2, 'control_test_id' => 5, 'created_at' => date('Y-m-d', strtotime('-6 days'))), array('results' => '17.77', 'control_measure_id' => 3, 'control_test_id' => 5, 'created_at' => date('Y-m-d', strtotime('-6 days'))), array('results' => '28.92', 'control_measure_id' => 4, 'control_test_id' => 5, 'created_at' => date('Y-m-d', strtotime('-6 days'))), array('results' => '19.87', 'control_measure_id' => 5, 'control_test_id' => 5, 'created_at' => date('Y-m-d', strtotime('-6 days'))), array('results' => '5.78', 'control_measure_id' => 1, 'control_test_id' => 6, 'created_at' => date('Y-m-d', strtotime('-5 days'))), array('results' => '15.56', 'control_measure_id' => 2, 'control_test_id' => 6, 'created_at' => date('Y-m-d', strtotime('-5 days'))), array('results' => '11.77', 'control_measure_id' => 3, 'control_test_id' => 6, 'created_at' => date('Y-m-d', strtotime('-5 days'))), array('results' => '29.92', 'control_measure_id' => 4, 'control_test_id' => 6, 'created_at' => date('Y-m-d', strtotime('-5 days'))), array('results' => '14.87', 'control_measure_id' => 5, 'control_test_id' => 6, 'created_at' => date('Y-m-d', strtotime('-5 days'))), array('results' => '9.78', 'control_measure_id' => 1, 'control_test_id' => 7, 'created_at' => date('Y-m-d', strtotime('-4 days'))), array('results' => '11.56', 'control_measure_id' => 2, 'control_test_id' => 7, 'created_at' => date('Y-m-d', strtotime('-4 days'))), array('results' => '19.77', 'control_measure_id' => 3, 'control_test_id' => 7, 'created_at' => date('Y-m-d', strtotime('-4 days'))), array('results' => '32.92', 'control_measure_id' => 4, 'control_test_id' => 7, 'created_at' => date('Y-m-d', strtotime('-4 days'))), array('results' => '29.87', 'control_measure_id' => 5, 'control_test_id' => 7, 'created_at' => date('Y-m-d', strtotime('-4 days'))), array('results' => '5.45', 'control_measure_id' => 6, 'control_test_id' => 8, 'created_at' => date('Y-m-d', strtotime('-3 days'))), array('results' => '5.01', 'control_measure_id' => 7, 'control_test_id' => 8, 'created_at' => date('Y-m-d', strtotime('-3 days'))), array('results' => '12.3', 'control_measure_id' => 8, 'control_test_id' => 8, 'created_at' => date('Y-m-d', strtotime('-3 days'))), array('results' => '89.7', 'control_measure_id' => 9, 'control_test_id' => 8, 'created_at' => date('Y-m-d', strtotime('-3 days'))), array('results' => '2.15', 'control_measure_id' => 10, 'control_test_id' => 8, 'created_at' => date('Y-m-d', strtotime('-3 days'))), array('results' => '34.0', 'control_measure_id' => 11, 'control_test_id' => 8, 'created_at' => date('Y-m-d', strtotime('-3 days'))), array('results' => '37.2', 'control_measure_id' => 12, 'control_test_id' => 8, 'created_at' => date('Y-m-d', strtotime('-3 days'))), array('results' => '141.5', 'control_measure_id' => 13, 'control_test_id' => 8, 'created_at' => date('Y-m-d', strtotime('-3 days'))), array('results' => '7.45', 'control_measure_id' => 6, 'control_test_id' => 9, 'created_at' => date('Y-m-d', strtotime('-2 days'))), array('results' => '9.01', 'control_measure_id' => 7, 'control_test_id' => 9, 'created_at' => date('Y-m-d', strtotime('-2 days'))), array('results' => '9.3', 'control_measure_id' => 8, 'control_test_id' => 9, 'created_at' => date('Y-m-d', strtotime('-2 days'))), array('results' => '94.7', 'control_measure_id' => 9, 'control_test_id' => 9, 'created_at' => date('Y-m-d', strtotime('-2 days'))), array('results' => '12.15', 'control_measure_id' => 10, 'control_test_id' => 9, 'created_at' => date('Y-m-d', strtotime('-2 days'))), array('results' => '37.0', 'control_measure_id' => 11, 'control_test_id' => 9, 'created_at' => date('Y-m-d', strtotime('-2 days'))), array('results' => '30.2', 'control_measure_id' => 12, 'control_test_id' => 9, 'created_at' => date('Y-m-d', strtotime('-2 days'))), array('results' => '121.5', 'control_measure_id' => 13, 'control_test_id' => 9, 'created_at' => date('Y-m-d', strtotime('-2 days'))));
     foreach ($controlResults as $controlResult) {
         ControlMeasureResult::create($controlResult);
     }
     $this->command->info("Control results table seeded");
 }
 /**
  * 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'));
 }