public static function getSpecimenCountStats($lab_config, $date_from, $date_to) { # Returns a list of {specimen_type, number of specimens handled} for the given time period $retval = array(); # Fetch all specimen types in this lab configuration $specimen_type_list = get_lab_config_specimen_types($lab_config->id); # Count number of specimens handled for each type $saved_db = DbUtil::switchToLabConfig($lab_config->id); $specimen_count_list = array(); foreach ($specimen_type_list as $specimen_type_id) { $specimen_count_list[] = get_specimen_count($lab_config, $specimen_type_id, $date_from, $date_to); } for ($i = 0; $i < count($specimen_type_list); $i++) { # Add to return value if specimen count not zero if ($specimen_count_list[$i] != 0) { $retval[$specimen_type_list[$i]] = $specimen_count_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); }
} else { echo "<th ></th>"; } if ($byAge == 1 && $byGender == 1) { echo "<th ></th>"; } if ($byAge == 1 || $byGender == 1) { echo "<th ></th>"; } ?> <tr> </thead> <tbody> <?php # Fetching specimen IDs but keeping the variables similar to reports_testcount_grouped.php $test_type_list = get_lab_config_specimen_types($lab_config->id); //$test_type_list = get_lab_config_test_types($lab_config->id); // to get test type ids $saved_db = DbUtil::switchToLabConfig($lab_config->id); $tests_done_list = array(); $tests_list = array(); $summ = 0; foreach ($test_type_list as $test_type_id) { $test_name = get_specimen_name_by_id($test_type_id); echo "<tr valign='top'>"; echo "<td>"; echo $test_name; echo "</td>"; if ($byGender == 1) { echo "<td>"; echo "M"; echo "<br>";
public function getSpecimenTypeCheckboxes($lab_config_id=null, $allCompatibleCheckingOn=true) { # Returns a set of checkboxes with existing specimen types checked if allCompatibleCheckingOn is set to true, # else only returns checkboxes with available specimen 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 specimen types //if($lab_config_id == "") //$specimen_list = get_specimen_types_catalog(); //else $specimen_list = get_specimen_types_catalog($lab_config_id); $current_specimen_list = array(); if($lab_config_id != "") $current_specimen_list = get_lab_config_specimen_types($lab_config_id); # For each specimen type, create a check box. Check it if specimen already in lab configuration ?> <table class='hor-minimalist-b' style='width:700px;'> <tbody> <tr> <?php $count = 0; foreach($specimen_list as $key=>$value) { $specimen_type_id = $key; $specimen_name = $value; $count++; ?> <td><input type='checkbox' class='stype_entry' name='s_type_<?php echo $key; ?>' id='s_type_<?php echo $key; ?>' value='<?php echo $key; ?>' <?php if($allCompatibleCheckingOn==true) { if(in_array($specimen_type_id, $current_specimen_list)) { echo " checked ><span class='clean-ok'>$specimen_name</span>"; } else echo ">$specimen_name"; } else echo ">$specimen_name"; ?> </input></td> <?php if($count % 3 == 0) echo "</tr><tr>"; } ?> </tbody> </table> <?php }
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; }