public static function dobToAge($dob) { # Converts date of birth to age in years/months /* $today = date("m-d-Y"); $dob_array = explode("-", $dob); # gives Y-m-d $dob_formatted = $dob_array[1]."-".$dob_array[2]."-".$dob_array[0]; $diff = round(floor(DateLib::dateDiff("-", $today, $dob_formatted)/365), 0); if($diff >= 2) { return $diff." ".LangUtil::$generalTerms['YEARS']; } else { $diff = round(floor(DateLib::dateDiff("-", $today, $dob_formatted)/30), 0); if($diff >= 2) { return "$diff ".LangUtil::$generalTerms['MONTHS']; } else { $diff = round(floor(DateLib::dateDiff("-", $today, $dob_formatted)%31), 0); return "$diff ".LangUtil::$generalTerms['DAYS']; } } */ $labConfig = LabConfig::getById($_SESSION['lab_config_id']); $today = date('Y-m-d'); $diff = abs(strtotime($today) - strtotime($dob)); # explode below gives Y-m-d (Required, because the difference function to get years, months & days is approximate. # Therefore if current day is same as dob day, do display days. $dob_array = explode("-", $dob); $today_array = explode("-", $today); $value = ""; $years = floor($diff / (365 * 60 * 60 * 24)); if ($years >= $labConfig->ageLimit) { $value .= $years . " " . LangUtil::$generalTerms['YEARS']; } else { $months = floor(($diff - $years * 365 * 60 * 60 * 24) / (30 * 60 * 60 * 24)); $days = floor(($diff - $years * 365 * 60 * 60 * 24 - $months * 30 * 60 * 60 * 24) / (60 * 60 * 24)); if ($years > 0) { $value .= $years . " " . LangUtil::$generalTerms['YEARS']; } if ($months > 0) { if ($years > 0) { $value .= ", "; } $value .= $months . " " . LangUtil::$generalTerms['MONTHS']; } if ($dob_array[2] != $today_array[2]) { if ($days > 0) { if ($months > 0 || $years > 0) { $value .= ", "; } $value .= $days . " " . LangUtil::$generalTerms['DAYS'] . " "; } } } return $value; }
function generate_worksheet_config($lab_config_id) { $lab_config = LabConfig::getById($lab_config_id); $test_ids = $lab_config->getTestTypeIds(); $saved_db = DbUtil::switchToLabConfig($lab_config_id); foreach ($test_ids as $test_id) { $test_entry = TestType::getById($test_id); $query_string = "SELECT * FROM report_config WHERE test_type_id={$test_id} LIMIT 1"; $record = query_associative_one($query_string); if ($record == null) { # Add new entry $query_string_add = "INSERT INTO report_config (" . "test_type_id, header, footer, margins, " . "p_fields, s_fields, t_fields, p_custom_fields, s_custom_fields " . ") VALUES (" . "'{$test_id}', 'Worksheet - " . $test_entry->name . "', '', '5,0,5,0', " . "'0,1,0,1,1,0,0', '0,0,1,1,0,0', '1,0,1,0,0,0,0,1', '', '' " . ")"; query_insert_one($query_string_add); } } DbUtil::switchRestore($saved_db); }
function updateDatabase() { global $labConfigId, $DB_HOST, $DB_USER, $DB_PASS; $country = strtolower(LabConfig::getUserCountry($labConfigId)); $saved_db = DbUtil::switchToCountry($country); $currentDir = getcwd(); $mainBlisDir = substr($currentDir, $length, strpos($currentDir, "htdocs")); //$blisLabBackupFilePath = "\"".$mainBlisDir.$backup_folder."\blis_".$lab_config_id."\blis_".$lab_config_id."_backup.sql\""; $sqlFilePath = "\"" . $mainBlisDir . "htdocs\\export\\temp.sql\""; $mysqlExePath = "\"" . $mainBlisDir . "server\\mysql\\bin\\mysql.exe\""; $dbname = "blis_" . $country; $command = $mysqlExePath . " -h {$DB_HOST} -P 7188 -u {$DB_USER} -p{$DB_PASS} {$dbname} < {$sqlFilePath}"; $command = "C: &" . $command; //the C: is a useless command to prevent the original command from failing because of having more than 2 double quotes echo $command; system($command, $return_var); if ($return_var == 0) { echo "true"; } else { echo "false"; } DbUtil::switchRestore($saved_db); }
if (is_numeric($file_name_parts[1])) { $count++; } if (is_numeric($file_name_parts[1])) { $last = get_last_import_date(intval($file_name_parts[1])); if (isset($last)) { $last = date('F j, Y g:i a', strtotime($last)); } else { $last = 'Never'; } } else { $last = "Unknown"; } $lname = "Unknown"; if (is_numeric($file_name_parts[1])) { $lab_obj = LabConfig::getById(intval($file_name_parts[1])); if (isset($lab_obj)) { $lname = $lab_obj->name; } } ?> <table> <tr> <td>File name: </td> <td><?php echo $file_name_and_extension[0]; ?> </td> </tr> <tr>
} } } } } # # Disease Report related functions # Called from report_disease.php # public static function getDiseaseTotal($lab_config, $test_type, $date_from, $date_to) { # Returns the total number of tests performed during the given date range $query_string = "SELECT COUNT(*) AS val FROM test t, specimen sp " . "WHERE t.test_type_id={$test_type->testTypeId} " . "AND t.specimen_id=sp.specimen_id " . "AND t.result <> '' " . "AND (sp.date_collected BETWEEN '{$date_from}' AND '{$date_to}')"; $saved_db = DbUtil::switchToLabConfig($lab_config->id); $resultset = query_associative_all($query_string, $row_count); DbUtil::switchRestore($saved_db); return $resultset[0]['val']; } public static function setDiseaseSetList($lab_config, $test_type, $date_from, $date_to, $multipleCount = 0) { # Initializes diseaseSetList for capturing params if ($multipleCount == 0) { StatsLib::$diseaseSetList = array(); } $query_string = "SELECT t.result AS result_value, " . "p.sex AS patient_gender, " . "p.patient_id AS patient_id " . "FROM test t, specimen sp, patient p " . "WHERE t.specimen_id=sp.specimen_id " . "AND t.result <> '' " . "AND t.test_type_id={$test_type->testTypeId} " . "AND (sp.date_collected BETWEEN '{$date_from}' AND '{$date_to}') " . "AND sp.patient_id=p.patient_id"; $saved_db = DbUtil::switchToLabConfig($lab_config->id); $resultset = query_associative_all($query_string, $row_count); $measure_list = $test_type->getMeasureIds(); if (count($resultset) == 0 || $resultset == null) { DbUtil::switchRestore($saved_db); return; } foreach ($resultset as $record) { $patient_id = $record['patient_id']; $patient = Patient::getById($patient_id); $current_set = new DiseaseSet(); $current_set->resultValues = array(); $result_csv_parts = explode(",", $record['result_value']); # Build assoc list for result values ## Format: resultValues[measure_id] = result_value for ($i = 0; $i < count($measure_list); $i++) { $result_part = $result_csv_parts[$i]; if (trim($result_part) == "") { continue; } $curr_measure_id = $measure_list[$i]; $current_set->resultValues[$curr_measure_id] = $result_part; }
<?php # # Updates options to use or hide non-mandatory fields for specimens and patients # Called via Ajax from lab_config_home.php # include "../users/accesslist.php"; if (!(isAdmin(get_user_by_id($_SESSION['user_id'])) && in_array(basename($_SERVER['PHP_SELF']), $adminPageList)) && !(isSuperAdmin(get_user_by_id($_SESSION['user_id'])) && in_array(basename($_SERVER['PHP_SELF']), $superAdminPageList)) && !(isCountryDir(get_user_by_id($_SESSION['user_id'])) && in_array(basename($_SERVER['PHP_SELF']), $countryDirPageList))) { displayForbiddenMessage(); } $saved_session = SessionUtil::save(); $lab_config = LabConfig::getById($_REQUEST['lab_config_id']); if ($lab_config == null) { SessionUtil::restore($saved_session); return; } # Patient related fields $use_pid = 0; $use_addl_id_patient = 0; $mand_addl_id_patient = 0; $use_daily_num = 0; $mand_daily_num = 0; $use_pname = 0; $mand_pname = 0; $use_sex = 0; $use_age = 0; $mand_age = 0; $use_dob = 0; $mand_age = 0; $ageLimit = 5; //$show_pname = 1;
public static function getById($lab_config_id) { $saved_db = DbUtil::switchToGlobal(); global $con; //$lab_config_id = mysql_real_escape_string($lab_config_id, $con); $query_config = "SELECT * FROM lab_config WHERE lab_config_id = {$lab_config_id} LIMIT 1"; $record = query_associative_one($query_config); DbUtil::switchRestore($saved_db); return LabConfig::getObject($record); }
$stat_lists[] = $stat_list; unset($stat_list); } } else { if ($test_type_id != 0 && count($lab_config_ids) == 1) { $lab_config = get_lab_config_by_id($lab_config_id); $test_type_id = $testIds[$lab_config->id]; $labName = $lab_config->name; $namesArray[] = $labName; $stat_list = StatsLib::getTatMonthlyProgressionStats($lab_config, $test_type_id, $date_from, $date_to, $include_pending); ksort($stat_list); $stat_lists[] = $stat_list; } else { if ($test_type_id != 0 && count($lab_config_ids) > 1) { foreach ($lab_config_ids as $key) { $lab_config = LabConfig::getById($key); $test_type_id = $testIds[$lab_config->id]; $namesArray[] = $lab_config->name; $stat_list = StatsLib::getTatMonthlyProgressionStats($lab_config, $test_type_id, $date_from, $date_to, $include_pending); ksort($stat_list); $stat_lists[] = $stat_list; unset($stat_list); } } } } } } } $progressData = array(); foreach ($stat_lists as $stat_list) {
public static function performBackup($lab_config_id, $currentDir, $include_langdata = true) { # Performs backup of current data for a lab global $SERVER, $ON_ARC; if ($SERVER == $ON_ARC) { # System on arc2 server: Do not allow backup option return false; } $file_list1 = array(); $file_list2 = array(); $file_list3 = array(); $DB_HOST = localhost; $DB_USER = root; $DB_PASS = blis123; $mainBlisDir = substr($currentDir, $length, strpos($currentDir, "htdocs")); $mysqldumpPath = "\"" . $mainBlisDir . "server\\mysql\\bin\\mysqldump.exe\""; $dbname = "blis_" . $lab_config_id; $backupLabDbFileName = "blis_" . $lab_config_id . "_backup.sql"; $count = 0; $command = $mysqldumpPath . " -B -h {$DB_HOST} -P 7188 -u {$DB_USER} -p{$DB_PASS} {$dbname} > {$backupLabDbFileName}"; system($command, $return); $file_list1[] = $backupLabDbFileName; $dbname = "blis_revamp"; $backupDbFileName = "blis_revamp_backup.sql"; $command = $mysqldumpPath . " -B -h {$DB_HOST} -P 7188 -u {$DB_USER} -p{$DB_PASS} {$dbname} > {$backupDbFileName}"; system($command, $return); $file_list2[] = $backupDbFileName; $dir_name3 = "../../local/langdata_" . $lab_config_id; if ($handle = opendir($dir_name3)) { while (false !== ($file = readdir($handle))) { if ($file === "." || $file == "..") { continue; } $file_list3[] = $dir_name3 . "/{$file}"; } } $lab_config = LabConfig::getById($lab_config_id); db_close(); $site_name = str_replace(" ", "-", $lab_config->getSiteName()); $destination = "../../blis_backup_" . $site_name . "_" . date("Ymd-Hi") . "/"; @mkdir($destination); @mkdir($destination . "blis_revamp/"); @mkdir($destination . "blis_" . $lab_config_id . "/"); @mkdir($destination . "langdata_" . $lab_config_id . "/"); chmod($destination, 777); foreach ($file_list1 as $file) { $file_name_parts = explode("/", $file); $target_file_name = $destination . "blis_" . $lab_config_id . "/" . $file_name_parts[count($file_name_parts) - 1]; $ourFileHandle = fopen($target_file_name, 'w') or die("can't open file"); fclose($ourFileHandle); if (!copy($file, $target_file_name)) { //echo "Error: $file $destination.$file <br>"; return false; } } foreach ($file_list2 as $file) { $file_name_parts = explode("/", $file); if (!copy($file, $destination . "blis_revamp/" . $file_name_parts[count($file_name_parts) - 1])) { //echo "Error: $file $destination.$file <br>"; return false; } } foreach ($file_list3 as $file) { $file_name_parts = explode("/", $file); if (!copy($file, $destination . "langdata_" . $lab_config_id . "/" . $file_name_parts[count($file_name_parts) - 1])) { //echo "Error: $file $destination.$file <br>"; return false; } } # All okay return true; }
public function getPatientSearchAttribSelect($hide_patient_name=false) { $userrr = get_user_by_id($_SESSION['user_id']); global $LIS_TECH_RO, $LIS_TECH_RW, $LIS_CLERK; if ( $_SESSION['user_level'] == $LIS_TECH_RO || $_SESSION['user_level'] == $LIS_TECH_RW || $_SESSION['user_level'] == $LIS_CLERK || $_SESSION['user_level'] == $LIS_PHYSICIAN ) { $lab_config = LabConfig::getById($_SESSION['lab_config_id']); $patientBarcodeSearch = patientSearchBarcodeCheck(); if($hide_patient_name === false && $lab_config->pname != 0) { ?> <option value='1'><?php echo LangUtil::$generalTerms['PATIENT_NAME']; ?></option> <?php } if($lab_config->dailyNum == 1 || $lab_config->dailyNum == 11 || $lab_config->dailyNum == 2 || $lab_config->dailyNum == 12) { ?> <option value='3'><?php echo LangUtil::$generalTerms['PATIENT_DAILYNUM']; ?></option> <?php } if($lab_config->pid != 0) { ?> <option value='0'><?php echo LangUtil::$generalTerms['PATIENT_ID']; ?></option> <?php } if($lab_config->patientAddl != 0) { ?> <option value='2'><?php echo LangUtil::$generalTerms['ADDL_ID']; ?></option> <?php } if($patientBarcodeSearch != 0 && is_country_dir($userrr) != 1 && is_super_admin($userrr) != 1 ) { ?> <option value='9'><?php echo 'Barcode Search'; ?></option> <?php } } else if(User::onlyOneLabConfig($_SESSION['user_id'], $_SESSION['user_level'])) { # Lab admin $lab_config_list = get_lab_configs($_SESSION['user_id']); $lab_config = $lab_config_list[0]; $patientBarcodeSearch = patientSearchBarcodeCheck(); if($lab_config->pname != 0) { ?> <option value='1'><?php echo LangUtil::$generalTerms['PATIENT_NAME']; ?></option> <?php } if($lab_config->dailyNum == 1 || $lab_config->dailyNum == 11 || $lab_config->dailyNum == 2 || $lab_config->dailyNum == 12) { ?> <option value='3'><?php echo LangUtil::$generalTerms['PATIENT_DAILYNUM']; ?></option> <?php } if($lab_config->pid != 0) { ?> <option value='0'><?php echo LangUtil::$generalTerms['PATIENT_ID']; ?></option> <?php } if($lab_config->patientAddl != 0) { ?> <option value='2'><?php echo LangUtil::$generalTerms['ADDL_ID']; ?></option> <?php } if($patientBarcodeSearch != 0 && is_country_dir($userrr) != 1 && is_super_admin($userrr) != 1 ) { ?> <option value='9'><?php echo 'Barcode Search'; ?></option> <?php } } else { $patientBarcodeSearch = patientSearchBarcodeCheck(); # Show all options ?> <option value='1'><?php echo LangUtil::$generalTerms['PATIENT_NAME']; ?></option> <option value='3'><?php echo LangUtil::$generalTerms['PATIENT_DAILYNUM']; ?></option> <option value='0'><?php echo LangUtil::$generalTerms['PATIENT_ID']; ?></option> <option value='2'><?php echo LangUtil::$generalTerms['ADDL_ID']; ?></option> <?php if($patientBarcodeSearch != 0 && is_country_dir($userrr) != 1 && is_super_admin($userrr) != 1 ){ ?> <option value='9'><?php echo 'Barcode Search'; ?></option> <?php } ?> <?php } }
<?php # # Returns <option> tags for list of test types by category (section) and site # Called via Ajax from reports.php # include "../includes/db_lib.php"; include "../includes/page_elems.php"; LangUtil::setPageId("general"); $page_elems = new PageElems(); $selvalue = $_REQUEST['type']; ?> <option value='0'><?php echo LangUtil::$generalTerms['ALL']; // ?> </option> <?php $lab_config = LabConfig::getById($_SESSION['lab_config_id']); if ($selvalue == "p") { $custom_field_list = $lab_config->getPatientCustomFields(); foreach ($custom_field_list as $custom_field) { echo "<option value='p_" . $custom_field->id . "'>" . $custom_field->fieldName . "</option>"; } } elseif ($selvalue == "s") { $custom_field_list = $lab_config->getSpecimenCustomFields(); foreach ($custom_field_list as $custom_field) { echo "<option value='s_" . $custom_field->id . "'>" . $custom_field->fieldName . "</option>"; } }
<?php # # Returns <option> tags for list of locations available for selection for a particular test # Called via Ajax from reports.php # include "../includes/db_lib.php"; $selectValues = $_REQUEST['l']; $labIdTestIdArr = explode(';', $selectValues); $checkBoxName = $_REQUEST['checkBoxName']; echo "<input type='checkbox' name='{$checkBoxName}' value='0'>" . LangUtil::$generalTerms['ALL'] . "</input>"; for ($i = 0; $i < count($labIdTestIdArr); $i++) { $labIdTestId = explode(':', $labIdTestIdArr[$i]); $labId = $labIdTestId[0]; $testId = $labIdTestId[1]; $lab_config = new LabConfig(); $record = $lab_config->getById($labId); echo "<br><input type='checkbox' name='{$checkBoxName}' value={$labId}>{$record->name}</input>"; }
public function getPatientFieldsOrderForm() { global $SYSTEM_PATIENT_FIELDS; ?> <table cellspacing='5px' class='smaller_font'> <tr valign='top'> <td><b><?php echo LangUtil::$generalTerms['PATIENT_FIELDS']?></b></td> <td></td> <td><b><?php echo LangUtil::$generalTerms['PATIENT_ORDERED_FIELDS']?></b></td> <td></td> </tr> <?php # Patient main fields ?> <tr valign='top'> <td> <input type="hidden" id="p_fields_left" name="p_fields_left" /> <input type="hidden" id="o_fields_left" name="o_fields_left" /> <select id="p_fields" name="p_fields" size="15" onchange="javascript:setSel(this);"> <?php $combined_fields =$SYSTEM_PATIENT_FIELDS; $lab_config = LabConfig::getById($_SESSION['lab_config_id']); if( $lab_config ) { $custom_field_list = $lab_config->getPatientCustomFields(); foreach($custom_field_list as $custom_field) { $custom_array = array ("p_custom_$custom_field->id" => $custom_field->fieldName); $combined_fields = array_merge($combined_fields,$custom_array); } } $record=Patient::getReportfieldsOrder(); if(!is_array($record)) { foreach ($combined_fields as $field=>$text) {?> <option value="<?php echo $field ?>"><?php if(!stristr($field,"custom")) echo LangUtil::$generalTerms[$text]; else echo $text;?></option> <?php } } else { $unordered=explode(",",$record['p_fields']); foreach( $unordered as $field) { ?> <option value="<?php echo $field ?>"><?php if(!stristr($field,"custom")) echo LangUtil::$generalTerms[$combined_fields[$field]]; else echo $combined_fields[$field];?></option> <?php } } ?> </select> </td> <td valign="middle"> <input type="button" name="AddOrder" id="AddOrder" value=">" disabled="disabled" onclick="javascript:setOrder();"/> <input type="button" name="RemOrder" id="RemOrder" value="<" disabled="disabled" onclick="javascript:remOrder();" /> </td> <td><select id="o_fields" name="o_fields" size="15" onchange="javascript:setSel(this);"> <?php if(is_array($record)) { $ordered=explode(",",$record['o_fields']); foreach( $ordered as $field) { ?> <option value="<?php echo $field ?>"><?php if(!stristr($field,"custom")) echo LangUtil::$generalTerms[$combined_fields[$field]]; else echo $combined_fields[$field];?></option> <?php } } ?> </select> </td> <td valign="middle"> <input type="button" id="o_up" name="o_up" value="ʌ" onclick="javascript:reorder('up');"/><br /> <input type="button" id="o_down" name="o_down" value="v" onclick="javascript:reorder('down');" /> </td> </tr> <tr> <td> <br /> <input type='button' value='<?php echo LangUtil::$generalTerms['CMD_SUBMIT']; ?>' id='ordered_fields_submit' onclick='javascript:submit_ordered_fields_form();'> </input><small> <a href='lab_config_home.php?id=<?php echo $lab_config->id; ?>'> <?php echo LangUtil::$generalTerms['CMD_CANCEL']; ?> </a> </small> </td> <td> <span id='ordered_fields_submit_progress' style='display:none;'> <?php $this->getProgressSpinner(LangUtil::$generalTerms['CMD_SUBMITTING']); ?> </span></td> <td></td> </tr> </table> <script type='text/javascript'> var selvalue; var seltext; var selIndex; function setSel(sel) { selvalue=sel.options[sel.selectedIndex].value; seltext=sel.options[sel.selectedIndex].text; selIndex=sel.selectedIndex; if($(sel).attr("name")=="p_fields") { document.getElementById("AddOrder").disabled=false; document.getElementById("RemOrder").disabled=true; } else { document.getElementById("RemOrder").disabled=false; document.getElementById("AddOrder").disabled=true; } } function setOrder() { var opt = document.createElement("option"); document.getElementById("o_fields").options.add(opt); opt.text = seltext; opt.value = selvalue; document.getElementById("p_fields").options.remove(selIndex); document.getElementById("AddOrder").disabled=true; } function remOrder() { var opt = document.createElement("option"); document.getElementById("p_fields").options.add(opt); opt.text = seltext; opt.value = selvalue; document.getElementById("o_fields").options.remove(selIndex); document.getElementById("RemOrder").disabled=true; } function reorder(direction) { var o_fields=document.getElementById("o_fields"); var newIndex=0; if(direction=="up") newIndex=selIndex-1; else newIndex=selIndex+1; if(newIndex >=o_fields.options.length || newIndex < 0) return; var keys = new Array(); var texts = new Array(); var tempkey=""; var temptext=""; for(var i=0;i<o_fields.options.length;i++) { keys[i] = o_fields.options[i].value; texts[i] = o_fields.options[i].text; } while(o_fields.options.length>0) { o_fields.options.remove(0); } tempkey=keys[newIndex]; temptext=texts[newIndex]; keys[newIndex]=keys[selIndex]; texts[newIndex]=texts[selIndex]; keys[selIndex]=tempkey; texts[selIndex]=temptext; for(var i=0;i<keys.length;i++) { var opt = document.createElement("option"); o_fields.options.add(opt); opt.text = texts[i]; opt.value = keys[i]; } o_fields.selectedIndex=newIndex; selIndex=newIndex; } </script> <?php }
public function getPatientSearchAttribSelect($hide_patient_name = false) { global $LIS_TECH_RO, $LIS_TECH_RW, $LIS_CLERK; if ($_SESSION['user_level'] == $LIS_TECH_RO || $_SESSION['user_level'] == $LIS_TECH_RW || $_SESSION['user_level'] == $LIS_CLERK || $_SESSION['user_level'] == $LIS_PHYSICIAN) { $lab_config = LabConfig::getById($_SESSION['lab_config_id']); if ($hide_patient_name === false && $lab_config->pname != 0) { ?> <option value='1'><?php echo LangUtil::$generalTerms['PATIENT_NAME']; ?> </option> <?php } if ($lab_config->dailyNum != 0) { ?> <option value='3'><?php echo LangUtil::$generalTerms['PATIENT_DAILYNUM']; ?> </option> <?php } if ($lab_config->pid != 0) { ?> <option value='0'><?php echo LangUtil::$generalTerms['PATIENT_ID']; ?> </option> <?php } if ($lab_config->patientAddl != 0) { ?> <option value='2'><?php echo LangUtil::$generalTerms['ADDL_ID']; ?> </option> <?php } } else { if (User::onlyOneLabConfig($_SESSION['user_id'], $_SESSION['user_level'])) { # Lab admin $lab_config_list = get_lab_configs($_SESSION['user_id']); $lab_config = $lab_config_list[0]; if ($lab_config->pname != 0) { ?> <option value='1'><?php echo LangUtil::$generalTerms['PATIENT_NAME']; ?> </option> <?php } if ($lab_config->dailyNum != 0) { ?> <option value='3'><?php echo LangUtil::$generalTerms['PATIENT_DAILYNUM']; ?> </option> <?php } if ($lab_config->pid != 0) { ?> <option value='0'><?php echo LangUtil::$generalTerms['PATIENT_ID']; ?> </option> <?php } if ($lab_config->patientAddl != 0) { ?> <option value='2'><?php echo LangUtil::$generalTerms['ADDL_ID']; ?> </option> <?php } } else { # Show all options ?> <option value='1'><?php echo LangUtil::$generalTerms['PATIENT_NAME']; ?> </option> <option value='3'><?php echo LangUtil::$generalTerms['PATIENT_DAILYNUM']; ?> </option> <option value='0'><?php echo LangUtil::$generalTerms['PATIENT_ID']; ?> </option> <option value='2'><?php echo LangUtil::$generalTerms['ADDL_ID']; ?> </option> <?php } } }
function get_cumul_stats($lab_config_id, $test_type_id, $date_from, $date_to) { $lab_config = LabConfig::getById($lab_config_id); $test_type = TestType::getById($test_type_id); $measure_list = $test_type->getMeasures(); $site_settings = DiseaseReport::getByKeys($lab_config->id, 0, 0); $age_group_list = $site_settings->getAgeGroupAsList(); ?> <table class='pretty_print' style='border-collapse: collapse;'> <thead> <tr valign='top'> <th><?php echo LangUtil::$generalTerms['TEST']; ?> </th> <th ><?php echo LangUtil::$generalTerms['RESULTS']; ?> </th> <?php if ($site_settings->groupByGender == 1) { echo "<th >" . LangUtil::$generalTerms['GENDER'] . "</th>"; } if ($site_settings->groupByAge == 1) { echo "<th >" . LangUtil::$pageTerms['RANGE_AGE'] . "</th>"; for ($i = 1; $i < count($age_group_list); $i++) { echo "<th >" . LangUtil::$pageTerms['RANGE_AGE'] . "</th>"; } } if ($site_settings->groupByGender == 1) { echo "<th ></th>"; } ?> <th ><?php echo LangUtil::$pageTerms['TOTAL']; ?> </th> <th ><?php echo LangUtil::$pageTerms['TOTAL_TESTS']; ?> </th> </tr> <tr> <th ></th> <th ></th> <?php if ($site_settings->groupByGender == 1) { echo "<th ></th>"; } if ($site_settings->groupByAge == 1) { foreach ($age_group_list as $age_slot) { echo "<th>{$age_slot['0']}"; if (trim($age_slot[1]) == "+") { echo "+"; } else { echo " - {$age_slot['1']}"; } echo "</th>"; } } if ($site_settings->groupByGender == 1) { echo "<th >" . LangUtil::$pageTerms['TOTAL_MF'] . "</th>"; } echo "<th ></th>"; echo "<th ></th>"; ?> <tr> </thead> <tbody> <?php StatsLib::setDiseaseSetList($lab_config, $test_type, $date_from, $date_to); $measures = $test_type->getMeasures(); foreach ($measures as $measure) { $male_total = array(); $female_total = array(); $cross_gender_total = array(); $curr_male_total = 0; $curr_female_total = 0; $curr_cross_gender_total = 0; $disease_report = DiseaseReport::getByKeys($lab_config->id, $test_type->testTypeId, $measure->measureId); if ($disease_report == null) { # TODO: Check for error control # Alphanumeric values. Hence entry not found. //continue; } $is_range_options = true; if (strpos($measure->range, "/") === false) { $is_range_options = false; } $range_values = array(); if ($is_range_options) { # Alphanumeric options $range_values = explode("/", $measure->range); } else { # Numeric ranges: Fetch ranges configured for this test-type/measure from DB $range_values = $disease_report->getMeasureGroupAsList(); } ?> <tr valign='top'> <td><?php echo $measure->getName(); ?> </td> <td> <?php foreach ($range_values as $range_value) { if ($is_range_options) { echo "{$range_value}<br>"; } else { echo "{$range_value['0']}-{$range_value['1']}<br>"; } if ($site_settings->groupByGender == 1) { echo "<br>"; } } ?> </td> <?php if ($site_settings->groupByGender == 1) { # Group by gender set to true echo "<td>"; for ($i = 1; $i <= count($range_values); $i++) { echo "M<br>F<br>"; } } if ($site_settings->groupByAge == 1) { # Group by age set to true: Fetch age slots from DB $age_slot_list = $site_settings->getAgeGroupAsList(); foreach ($age_slot_list as $age_slot) { echo "<td>"; $range_value_count = 0; foreach ($range_values as $range_value) { $range_value_count++; if (!isset($male_total[$range_value_count])) { $male_total[$range_value_count] = 0; $female_total[$range_value_count] = 0; $cross_gender_total[$range_value_count] = 0; } $curr_male_total = 0; $curr_female_total = 0; $curr_cross_gender_total = 0; $range_type = DiseaseSetFilter::$CONTINUOUS; if ($is_range_options == true) { $range_type = DiseaseSetFilter::$DISCRETE; } if ($site_settings->groupByGender == 0) { # No genderwise count required. # Create filter $disease_filter = new DiseaseSetFilter(); $disease_filter->patientAgeRange = $age_slot; $disease_filter->patientGender = null; $disease_filter->measureId = $measure->measureId; $disease_filter->rangeType = $range_type; $disease_filter->rangeValues = $range_value; $curr_total = StatsLib::getDiseaseFilterCount($disease_filter); $curr_cross_gender_total += $curr_total; echo "{$curr_total}<br>"; } else { # Genderwise count required. # Create filter $disease_filter = new DiseaseSetFilter(); $disease_filter->patientAgeRange = $age_slot; $disease_filter->measureId = $measure->measureId; $disease_filter->rangeType = $range_type; $disease_filter->rangeValues = $range_value; ## Count for males. $disease_filter->patientGender = 'M'; $curr_total1 = StatsLib::getDiseaseFilterCount($disease_filter); $curr_male_total += $curr_total1; ## Count for females. $disease_filter->patientGender = 'F'; $curr_total2 = StatsLib::getDiseaseFilterCount($disease_filter); $curr_female_total += $curr_total2; echo "{$curr_total1}<br>{$curr_total2}<br>"; } # Build assoc list to track genderwise totals $male_total[$range_value_count] += $curr_male_total; $female_total[$range_value_count] += $curr_female_total; $cross_gender_total[$range_value_count] += $curr_cross_gender_total; } echo "</td>"; } } else { # Age slots not configured: Show cumulative count for all age values $range_value_count = 0; foreach ($range_values as $range_value) { $range_value_count++; if (!isset($male_total[$range_value_count])) { $male_total[$range_value_count] = 0; $female_total[$range_value_count] = 0; $cross_gender_total[$range_value_count] = 0; } $curr_male_total = 0; $curr_female_total = 0; $curr_cross_gender_total = 0; $range_type = DiseaseSetFilter::$CONTINUOUS; if ($is_range_options == true) { $range_type = DiseaseSetFilter::$DISCRETE; } if ($site_settings->groupByGender == 0) { # No genderwise count required. # Create filter $disease_filter = new DiseaseSetFilter(); $disease_filter->patientAgeRange = array(0, 200); $disease_filter->patientGender = null; $disease_filter->measureId = $measure->measureId; $disease_filter->rangeType = $range_type; $disease_filter->rangeValues = $range_value; $curr_total = StatsLib::getDiseaseFilterCount($disease_filter); $curr_cross_gender_total += $curr_total; } else { # Genderwise count required. # Create filter $disease_filter = new DiseaseSetFilter(); $disease_filter->patientAgeRange = array(0, 200); $disease_filter->measureId = $measure->measureId; $disease_filter->rangeType = $range_type; $disease_filter->rangeValues = $range_value; ## Count for males. $disease_filter->patientGender = 'M'; $curr_total1 = StatsLib::getDiseaseFilterCount($disease_filter); $curr_male_total += $curr_total1; ## Count for females. $disease_filter->patientGender = 'F'; $curr_total2 = StatsLib::getDiseaseFilterCount($disease_filter); $curr_female_total += $curr_total2; } # Build assoc list to track genderwise totals $male_total[$range_value_count] += $curr_male_total; $female_total[$range_value_count] += $curr_female_total; $cross_gender_total[$range_value_count] += $curr_cross_gender_total; } } if ($site_settings->groupByGender == 1) { echo "<td>"; for ($i = 1; $i <= count($range_values); $i++) { $this_male_total = $male_total[$i]; $this_female_total = $female_total[$i]; echo "{$this_male_total}<br>{$this_female_total}<br>"; $this_cross_gender_total = $this_male_total + $this_female_total; } echo "</td>"; } echo "<td>"; for ($i = 1; $i <= count($range_values); $i++) { if ($site_settings->groupByGender == 1) { echo $male_total[$i] + $female_total[$i]; echo "<br><br>"; } else { echo $cross_gender_total[$i]; echo "<br>"; } } echo "</td>"; # Grand total: # TODO: Check the following function for off-by-one error //$disease_total = StatsLib::getDiseaseTotal($lab_config, $test, $date_from, $date_to); //echo "<td >$disease_total</td>"; echo "<td>"; if ($site_settings->groupByGender == 1) { echo array_sum($male_total) + array_sum($female_total); } else { echo array_sum($cross_gender_total); } echo "</td>"; ?> </tr> <?php } ?> </tbody> </table> <?php }
function processWeeklyTrends($lab_config_id, $test_type_id, $date_from, $date_to, $test_name = null) { global $namesArray; global $stat_list; # All Tests & All Labs */ if ($test_type_id == 0 && $lab_config_id == 0) { $site_list = get_site_list($_SESSION['user_id']); $userId = $_SESSION['user_id']; $saved_db = DbUtil::switchToGlobal(); $query = "SELECT * FROM test_mapping WHERE user_id = {$userId}"; $resultset = query_associative_all($query, $row_count); foreach ($resultset as $record) { $labIdTestIds = explode(';', $record['lab_id_test_id']); foreach ($labIdTestIds as $labIdTestId) { $labIdTestId = explode(':', $labIdTestId); $labId = $labIdTestId[0]; $testId = $labIdTestId[1]; $test_type_list_all[$labId][] = $testId; $test_type_names[$labId][] = $record['test_name']; } } DbUtil::switchRestore($saved_db); foreach ($site_list as $key => $value) { $lab_config = LabConfig::getById($key); $test_type_list = array(); $test_type_list = $test_type_list_all[$key]; $testNames = $test_type_names[$key]; $saved_db = DbUtil::switchToLabConfig($lab_config->id); $testCount = -1; foreach ($test_type_list as $test_type_id) { $query_string = "SELECT COUNT(*) AS count_val FROM test t, specimen s " . "WHERE t.test_type_id={$test_type_id} " . "AND t.specimen_id=s.specimen_id " . "AND result!=''" . "AND ( s.date_collected BETWEEN '{$date_from}' AND '{$date_to}' )"; $record = query_associative_one($query_string); $count_all = intval($record['count_val']); $testCount++; if ($count_all == 0) { continue; } $namesArray[] = $lab_config->name . " - " . $testNames[$testCount]; getWeeklyStats($lab_config, $test_type_id, $date_from, $date_to); } } } else { if ($test_type_id == 0 && count($lab_config_id) == 1) { $lab_config = LabConfig::getById($lab_config_id[0]); $test_type_list = get_discrete_value_test_types($lab_config); foreach ($test_type_list as $test_type_id) { $namesArray[] = get_test_name_by_id($test_type_id, $lab_config_id[0]); getWeeklyStats($lab_config, $test_type_id, $date_from, $date_to); } } else { if ($test_type_id == 0 && count($lab_config_id) > 1) { $userId = $_SESSION['user_id']; $saved_db = DbUtil::switchToGlobal(); $query = "SELECT * FROM test_mapping WHERE user_id = {$userId}"; $resultset = query_associative_all($query, $row_count); foreach ($resultset as $record) { $labIdTestIds = explode(';', $record['lab_id_test_id']); foreach ($labIdTestIds as $labIdTestId) { $labIdTestId = explode(':', $labIdTestId); $labId = $labIdTestId[0]; $testId = $labIdTestId[1]; $test_type_list_all[$labId][] = $testId; $test_type_names[$labId][] = $record['test_name']; } } DbUtil::switchRestore($saved_db); foreach ($lab_config_id as $key) { $lab_config = LabConfig::getById($key); $test_type_list = array(); $test_type_list = $test_type_list_all[$key]; $testNames = $test_type_names[$key]; $saved_db = DbUtil::switchToLabConfig($lab_config->id); $testCount = -1; foreach ($test_type_list as $test_type_id) { $query_string = "SELECT COUNT(*) AS count_val FROM test t, specimen s " . "WHERE t.test_type_id={$test_type_id} " . "AND t.specimen_id=s.specimen_id " . "AND result!=''" . "AND ( s.date_collected BETWEEN '{$date_from}' AND '{$date_to}' )"; $record = query_associative_one($query_string); $count_all = intval($record['count_val']); $testCount++; if ($count_all == 0) { continue; } $namesArray[] = $lab_config->name . " - " . $testNames[$testCount]; getWeeklyStats($lab_config, $test_type_id, $date_from, $date_to); } } } else { /* Build Array Map with Lab Id as Key and Test Id as corresponding Value */ $labIdTestIds = explode(";", $test_type_id); $testIds = array(); foreach ($labIdTestIds as $labIdTestId) { $labIdTestIdsSeparated = explode(":", $labIdTestId); $labId = $labIdTestIdsSeparated[0]; $testId = $labIdTestIdsSeparated[1]; $testIds[$labId] = $testId; } # Particular Test & All Labs if ($test_type_id != 0 && $lab_config_id == 0) { $site_list = get_site_list($_SESSION['user_id']); foreach ($site_list as $key => $value) { $lab_config = LabConfig::getById($key); $test_type_id = $testIds[$lab_config->id]; $namesArray[] = $lab_config->name; getWeeklyStats($lab_config, $test_type_id, $date_from, $date_to); } } else { if ($test_type_id != 0 && count($lab_config_id) == 1) { $lab_config = LabConfig::getById($lab_config_id[0]); $test_type_id = $testIds[$lab_config->id]; $namesArray[] = $lab_config->name; getWeeklyStats($lab_config, $test_type_id, $date_from, $date_to); } else { if ($lab_config_id != 0 && $test_type_id != 0) { foreach ($lab_config_id as $key) { $lab_config = LabConfig::getById($key); $test_type_id = $testIds[$lab_config->id]; $namesArray[] = $lab_config->name; getWeeklyStats($lab_config, $test_type_id, $date_from, $date_to); } } } } } } } /* $lab_config = LabConfig::getById($lab_config_id[0]); if($lab_config) { //$test_type_list = get_discrete_value_test_types($lab_config); foreach($test_type_list as $test_type_id) { $namesArray[] = get_test_name_by_id($test_type_id, $lab_config_id[0]); getWeeklyStats($lab_config, $test_type_id, $date_from, $date_to); } } */ }
function processWeeklyTrends($lab_config_id, $test_type_id, $date_from, $date_to, $test_name = null) { global $namesArray; global $stat_list; $lab_config = LabConfig::getById($lab_config_id[0]); $test_type_list = get_discrete_value_test_types($lab_config); foreach ($test_type_list as $test_type_id) { $namesArray[] = get_test_name_by_id($test_type_id, $lab_config_id[0]); getWeeklyStats($lab_config, $test_type_id, $date_from, $date_to); } }
} } else { if ($reportType == "Prevalence") { publishDates($date_from, $date_to); $stat_list = array(); $retval = array(); $existing_stat_list = array(); $testName = null; for ($i = 0; $i < count($lab_config_id_array); $i++) { $labIdTestTypeIdSeparated = explode(":", $lab_config_id_array[$i]); $lab_config_id = $labIdTestTypeIdSeparated[0]; $test_type_id = $labIdTestTypeIdSeparated[1]; $retval = StatsLib::getDiscreteInfectionStatsAggregate($lab_config_id, $date_from, $date_to, $test_type_id); $existing_stat_list = $stat_list; $stat_list = array_merge($existing_stat_list, $retval); $lab_config = LabConfig::getById($lab_config_id); $labName = $lab_config->name; $labNamesArray[] = $labName; getWeeklyStats($lab_config, $test_type_id, $date_from, $date_to); if (!$testName) { $saved_db = DbUtil::switchToLabConfig($lab_config_id); $testName = get_test_name_by_id($test_type_id); DbUtil::switchRestore($saved_db); } if (count($stat_list) == 0) { ?> <div class='sidetip_nopos'> <?php echo LangUtil::$pageTerms['TIPS_NODISCRETE']; ?> </div>
//$sites_list = get_site_list($_SESSION['user_id']); $config_list = get_lab_configs_imported(); foreach ($config_list as $lab_config) { //foreach($sites_list as $key => $value) //$site_list[] = $key; $site_list[] = $lab_config->id; } } else { if (count($lab_config_ids) == 1) { $site_list = $lab_config_ids; } else { $site_list = $lab_config_ids; } } foreach ($site_list as $labConfigId) { $labNames .= LabConfig::getById($labConfigId)->name . ", "; } $labNames = substr($labNames, 0, strlen($labNames) - 2); //print_r($labNames); //$selected_test_ids = $lab_config->getTestTypeIds(); if ($cat_code != 0) { # Fetch all tests belonging to this category (aka lab section) $cat_test_types = TestTypeMapping::getByCategory($cat_code); print_r($cat_test_types); $selected_test_ids = array(); foreach ($cat_test_types as $test_type) { $selected_test_ids[] = $test_type->testId; } //$matched_test_ids = array_intersect($cat_test_ids, $selected_test_ids); //$selected_test_ids = array_values($matched_test_ids); } else {
function create_backup($lab_config_id) { $lab_config = LabConfig::getById($lab_config_id); $site_name = $lab_config->name; $site_name = str_replace(" ", "-", $site_name); $timestamp = date("Ymd-hi"); $file_list1 = array(); # dbdir/blis_xxx $file_list2 = array(); # dbdir/blis_revamp $file_list3 = array(); # htdocs/langdata $dir_name = "../../dbdir/blis_" . $lab_config_id; $count = 0; if ($handle = opendir($dir_name)) { while (false !== ($file = readdir($handle))) { if ($file === "." || $file == "..") { continue; } $file_list1[] = $dir_name . "/{$file}"; $count++; print $dir_name . "/{$file}"; } print "\n number of files"; print $count; $dir_name = "../../dbdir/blis_revamp"; if ($handle = opendir($dir_name)) { while (false !== ($file = readdir($handle))) { if ($file === "." || $file == "..") { continue; } $file_list2[] = $dir_name . "/{$file}"; } $dir_name = "../../locale/langdata"; if ($handle = opendir($dir_name)) { while (false !== ($file = readdir($handle))) { if ($file === "." || $file == "..") { continue; } $file_list3[] = $dir_name . "/{$file}"; } $zip_file_name = $site_name . "_" . $timestamp . ".zip"; $result = create_zip($file_list1, $file_list2, $file_list3, $zip_file_name, true, $lab_config_id); } } } # Send file stream to user for download $file = $zip_file_name; header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename=' . basename($file)); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Length: ' . filesize($file)); ob_clean(); flush(); readfile($file); unlink($file); }
$user = get_user_by_id($_SESSION['user_id']); if (!(is_country_dir($user) || is_super_admin($user))) { $saved_db = DbUtil::switchToGlobal(); $query = "SELECT lab_config_id FROM lab_config WHERE admin_user_id = " . $_SESSION['user_id']; $record = query_associative_one($query); $labId = $record['lab_config_id']; if ($labId != $lab_config_id) { echo "You are not authorized to access the configuration"; include "includes/footer.php"; die; } DbUtil::switchRestore($saved_db); } //echo "Lab Config Id ".$lab_config_id; $lab_config = LabConfig::getById($lab_config_id); $doctor_lab_config = LabConfig::getDoctorConfig($lab_config_id); //Patient Custom Fields for the lab with $lab_config $custom_field_list_patients = get_lab_config_patient_custom_fields($lab_config->id); $custom_field_list_specimen = get_lab_config_specimen_custom_fields($lab_config->id); $custom_field_list_labTitle = get_lab_config_labtitle_custom_fields($lab_config->id); //echo "custom fields = ".$custom_field_list[0]->id; if ($lab_config == null) { ?> <br><br> <div class='sidetip_nopos'> <?php echo LangUtil::$generalTerms['MSG_NOTFOUND']; ?> </div> <?php include "includes/footer.php";