public static function getTestsDoneStats($lab_config, $date_from, $date_to) { # Returns a list of {test_type, number of tests performed} for the given time period $retval = array(); # Fetch all test types in this lab configuration $test_type_list = get_lab_config_test_types($lab_config->id); # Count number of tests performed for each type $saved_db = DbUtil::switchToLabConfig($lab_config->id); $tests_done_list = array(); $tests_list = array(); foreach ($test_type_list as $test_type_id) { $count_value = get_tests_done_count($lab_config, $test_type_id, $date_from, $date_to); $test_count = get_test_count($lab_config, $test_type_id, $date_from, $date_to); $tests_done_count_list[] = $count_value; $tests_pending_list[] = $test_count - $count_value; } for ($i = 0; $i < count($test_type_list); $i++) { # Add to return value if test count not zero if ($tests_pending_list[$i] != 0) { $retval[$test_type_list[$i]] = array($tests_done_count_list[$i], $tests_pending_list[$i]); } } DbUtil::switchRestore($saved_db); return $retval; }
function update_lab_config($updated_entry, $updated_specimen_list = null, $updated_test_list = null) { # Updates a lab configuration record $saved_db = DbUtil::switchToGlobal(); $query_string = "UPDATE lab_config " . "SET name='{$updated_entry->name}', " . "location='{$updated_entry->location}', " . "admin_user_id={$updated_entry->adminUserId}, " . "id_mode={$updated_entry->idMode} " . "WHERE lab_config_id={$updated_entry->id}"; query_blind($query_string); DbUtil::switchRestore($saved_db); $saved_db = DbUtil::switchToLabConfigRevamp(); if ($updated_specimen_list != null) { # Update specimen types $existing_specimen_list = get_lab_config_specimen_types($updated_entry->id); ## Add new specimen types foreach ($updated_specimen_list as $specimen_type_id) { if (in_array($specimen_type_id, $existing_specimen_list)) { # Entry already present # Continue } else { # Add specimen type entry in mapping table $query_ins = "INSERT INTO lab_config_specimen_type(lab_config_id, specimen_type_id) " . "VALUES ({$updated_entry->id}, {$specimen_type_id})"; query_blind($query_ins); } } ## Remove specimen types marked as deleted foreach ($existing_specimen_list as $specimen_type_id) { if (in_array($specimen_type_id, $updated_specimen_list)) { # Not marked for removal # Continue } else { # Remove specimen type entry from mapping table $query_del = "DELETE FROM lab_config_specimen_type " . "WHERE lab_config_id={$updated_entry->id} " . "AND specimen_type_id={$specimen_type_id}"; query_blind($query_del); } } } if ($updated_test_list != null) { # Update test types $existing_test_list = get_lab_config_test_types($updated_entry->id); ## Add new test types foreach ($updated_test_list as $test_type_id) { if (in_array($test_type_id, $existing_test_list)) { # Entry already present # Continue } else { # Add test type entry in mapping table $query_ins = "INSERT INTO lab_config_test_type(lab_config_id, test_type_id) " . "VALUES ({$updated_entry->id}, {$test_type_id})"; query_blind($query_ins); } } ## Remove test types marked as deleted foreach ($existing_test_list as $test_type_id) { if (in_array($test_type_id, $updated_test_list)) { # Not marked for removal # Continue } else { # Remove test type entry from mapping table $query_del = "DELETE FROM lab_config_test_type " . "WHERE lab_config_id={$updated_entry->id} " . "AND test_type_id={$test_type_id}"; query_blind($query_del); # Remove worksheet config for this test type if ($test_type_id != 0) { $saved_db2 = DbUtil::switchToLabConfig($updated_entry->id); $query_del2 = "DELETE FROM report_config WHERE test_type_id={$test_type_id}"; query_delete($query_del2); DbUtil::switchRestore($saved_db2); } } } } DbUtil::switchRestore($saved_db); }
public function getTestTypeCheckboxes_dir($lab_config_id=null, $allCompatibleCheckingOn=true) { # Returns a set of checkboxes with existing test types checked, if allCompatibleCheckingOn is set to true, # else only returns checkboxes with available test tpe names $lab_config = get_lab_config_by_id($lab_config_id); if($lab_config == null && $lab_config_id != "") { ?> <div class='sidetip_nopos'> ERROR: Lab configuration not found </div> <?php return; } # Fetch all test types //if($lab_config_id == "") //{ //$test_list = get_test_types_catalog(true); // $reff = 1; // $test_list = get_test_types_catalog($lab_config_id, $reff); //} // else //{ //NC3065 $reff = 2; $test_list = get_test_types_catalog($lab_config_id, $reff ); //-NC3065 // } $current_test_list = array(); if($lab_config_id != "") $current_test_list = get_lab_config_test_types($lab_config_id) # For each test type, create a check box. Check it if test already in lab configuration ?> <table class='hor-minimalist-b' style='width:700px;'> <tbody> <tr> <?php $count = 0; foreach($test_list as $key=>$value) { $test_type_id = $key; $test_name = $value; $count++; ?> <td><input type='checkbox' class='ttype_entry' name='t_type_<?php echo $key; ?>' id='t_type_<?php echo $key; ?>' <?php if($allCompatibleCheckingOn==true) { if(in_array($test_type_id, $current_test_list)) { echo " checked ><span class='clean-ok'>$test_name</span>"; } else echo ">$test_name"; } else echo ">$test_name"; ?> </input></td> <?php if($count % 3 == 0) echo "</tr><tr>"; } ?> </tbody> </table> <?php }
return $retval; } $page_elems = new PageElems(); $script_elems = new ScriptElems(); $script_elems->enableJQuery(); $script_elems->enableTableSorter(); $script_elems->enableDragTable(); $date_from = $_REQUEST['yf'] . "-" . $_REQUEST['mf'] . "-" . $_REQUEST['df']; $date_to = $_REQUEST['yt'] . "-" . $_REQUEST['mt'] . "-" . $_REQUEST['dt']; $lab_config_id = $_REQUEST['l']; $cat_code = $_REQUEST['c']; $ttype = $_REQUEST['t']; $uiinfo = "from=" . $date_from . "&to=" . $date_to . "&ct=" . $cat_code . "&tt=" . $ttype; putUILog('daily_log_specimens', $uiinfo, basename($_SERVER['REQUEST_URI'], ".php"), 'X', 'X', 'X'); $lab_config = get_lab_config_by_id($lab_config_id); $test_types = get_lab_config_test_types($lab_config_id); $report_id = $REPORT_ID_ARRAY['reports_dailyspecimens.php']; $report_config = $lab_config->getReportConfig($report_id); $margin_list = $report_config->margins; for ($i = 0; $i < count($margin_list); $i++) { $margin_list[$i] = $SCREEN_WIDTH * $margin_list[$i] / 100; } if ($ttype != 0) { # Single test type selected $test_types = array(); $test_types[] = $ttype; } else { if ($cat_code != 0) { # Fetch all tests belonging to this category (aka lab section) $cat_test_types = TestType::getByCategory($cat_code); $cat_test_ids = array();
} } else { echo "<th ></th>"; } if ($byAge == 1 && $byGender == 1) { echo "<th ></th>"; } if ($byAge == 1 || $byGender == 1) { echo "<th ></th>"; } ?> </tr> </thead> <tbody> <?php $test_type_list = get_lab_config_test_types($lab_config->id); // to get test type ids /*$cat_test_types = TestType::getByCategory($cat_codes[$cc]); $cat_test_ids = array(); $selected_test_ids = $lab_config->getTestTypeIds(); foreach($cat_test_types as $test_type) $cat_test_ids[] = $test_type->testTypeId; $matched_test_ids = array_intersect($cat_test_ids, $selected_test_ids); $selected_test_ids = array_values($matched_test_ids); $test_type_list = $selected_test_ids; */ $saved_db = DbUtil::switchToLabConfig($lab_config->id); $tests_done_list = array(); $tests_list = array(); $summ = 0;
function add_specimens_random($num_specimens, $user_list = array()) { # Adds random specimen entries with some tests scheduled global $MAX_NUM_SPECIMENS, $SPECIMEN_ID_START, $TESTS_ADDED, $NUM_SPECIMENS; global $MIN_COLLECTION_DATE, $MAX_COLLECTION_DATE, $P_NEW_TEST; $doctorNames = array('Buck', 'Harrel', 'Knight', 'Myers', 'Guzman', 'Jones', 'Fox', 'Hood', 'Sweeney', 'Dillards'); $lab_config_id = $_SESSION['lab_config_id']; $min_date = $MIN_COLLECTION_DATE; $max_date = $MAX_COLLECTION_DATE; list($y_start, $m_start, $d_start) = explode("-", $min_date); list($y_end, $m_end, $d_end) = explode("-", $max_date); $ts_start = mktime(0, 0, 0, $m_start, $d_start, $y_start); $ts_end = mktime(0, 0, 0, $m_end, $d_end, $y_end); if ($num_specimens > $MAX_NUM_SPECIMENS) { $num_specimens = $MAX_NUM_SPECIMENS; } $specimen_type_list = get_lab_config_specimen_types($lab_config_id); $test_type_list = get_lab_config_test_types($lab_config_id); $count = 0; $specimen_id_count = $SPECIMEN_ID_START; while ($count < $num_specimens) { $user_id = 0; if (count($user_list) != 0) { $random_user_index = rand(1, count($user_list)); $random_user = $user_list[$random_user_index - 1]; $user_id = $random_user->userId; } $specimen_type_id = get_random_element($specimen_type_list); $patient_id = get_random_patient_id(); # Create a new specimen entry $specimen = new Specimen(); $specimen->specimenId = $specimen_id_count; $specimen->specimenTypeId = $specimen_type_id; $specimen->patientId = $patient_id; $specimen->userId = $user_id; # Alternatively, above userId can be linked to $_SESSION['user_id'] $randomDate = get_random_date($ts_start, $ts_end); $specimen->dateCollected = $randomDate; $specimen->dateRecvd = $specimen->dateCollected; $specimen->statusCodeId = Specimen::$STATUS_PENDING; $specimen->reportTo = 1; $specimen->doctor = $doctorNames[rand(0, 9)]; $specimen->referredTo = 0; $specimen->comments = ""; $specimen->auxId = ""; # Schedule tests for this specimen $compatible_test_list = get_compatible_tests($specimen_type_id); if (count($compatible_test_list) == 0) { # No compatible tests found in the lab configuration # Undo specimen entry addition //rollback_transaction(); # TODO: Add error handling here (or do checking on front-end) # Update counters $TESTS_ADDED++; $specimen_id_count++; $count++; continue; } $candidate_test_list = array_values(array_intersect($compatible_test_list, $test_type_list)); if (count($candidate_test_list) == 0) { # No compatible tests found in the lab configuration # Undo specimen entry addition //rollback_transaction(); # Update counters $TESTS_ADDED++; $specimen_id_count++; $count++; continue; } $saved_db = DbUtil::switchToLabConfig($lab_config_id); add_specimen($specimen); list($y_end, $m_end, $d_end) = explode("-", $randomDate); $rstartTime = mktime(0, 0, 0, $m_end, $d_end, $y_end); $rendTime = mktime(23, 59, 59, $m_end, $d_end, $y_end); do { $testTs = getRandomDateWithTime($rstartTime, $rendTime); $test_entry = get_new_test($specimen_id_count, $candidate_test_list, $testTs); add_test_random($test_entry); } while (with_probability($P_NEW_TEST) && count($candidate_test_list) > 0); DbUtil::switchRestore($saved_db); //commit_transaction(); # Update counters $TESTS_ADDED++; $specimen_id_count++; $count++; } # Update global count fo book-keeping $NUM_SPECIMENS = $num_specimens; }