?> | <?php if ($date_from == $date_to) { echo LangUtil::$generalTerms['DATE'] . ": " . DateLib::mysqlToString($date_from); } else { echo LangUtil::$generalTerms['FROM_DATE'] . ": " . DateLib::mysqlToString($date_from); echo " | "; echo LangUtil::$generalTerms['TO_DATE'] . ": " . DateLib::mysqlToString($date_to); } ?> <br><br> <?php DbUtil::switchToLabConfig($lab_config_id); # Cumulative summary $stat_list = StatsLib::getDiscreteInfectionStats($lab_config, $date_from, $date_to); if (count($stat_list) == 0) { ?> <div class='sidetip_nopos'> <?php echo LangUtil::$pageTerms['TIPS_NODISCRETE']; ?> </div> <?php include "includes/footer.php"; return; } /* ?> <div id='stat_graph' style='display:none;'> <?php
public static function getDiscreteInfectionStatsAggregate($lab_config_id, $date_from, $date_to, $test_type_id) { $retval = array(); #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; # For each test type, fetch negative records 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 ( s.date_collected BETWEEN '{$date_from}' AND '{$date_to}' ) " . "AND (result LIKE 'N,%' OR result LIKE 'n�gatif,%' OR result LIKE 'negatif,%' OR result LIKE 'n,%' OR result LIKE 'negative,%')"; $record = query_associative_one($query_string); $count_negative = intval($record['count_val']); $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 total tests is 0, ignore if ($count_all == 0) { continue; } $testName = $testNames[$testCount]; if (!array_key_exists($testName, $retval)) { $retval[$testName] = array($count_all, $count_negative); } else { $count_all += intval($retval[$testName][0]); $count_negative += intval($retval[$testName][1]); $retval[$testName] = array($count_all, $count_negative); } } } DbUtil::switchRestore($saved_db); return $retval; } else { if ($test_type_id == 0 && count($lab_config_id) == 1) { $lab_config = LabConfig::getById($lab_config_id[0]); $retvalues = StatsLib::getDiscreteInfectionStats($lab_config, $date_from, $date_to); $saved_db = DbUtil::switchToLabConfig($lab_config->id); foreach ($retvalues as $key => $value) { $testName = get_test_name_by_id($key); $retval[$testName] = $value; } DbUtil::switchRestore($saved_db); return $retval; } 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; # For each test type, fetch negative records 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 ( s.date_collected BETWEEN '{$date_from}' AND '{$date_to}' ) " . "AND (result LIKE 'N,%' OR result LIKE 'n�gatif,%' OR result LIKE 'negatif,%' OR result LIKE 'n,%' OR result LIKE 'negative,%')"; $record = query_associative_one($query_string); $count_negative = intval($record['count_val']); $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}' )"; //echo($query_string); $record = query_associative_one($query_string); $count_all = intval($record['count_val']); $testCount++; # If total tests is 0, ignore if ($count_all == 0) { continue; } $testName = $testNames[$testCount]; if (!array_key_exists($testName, $retval)) { $retval[$testName] = array($count_all, $count_negative); } else { $count_all += intval($retval[$testName][0]); $count_negative += intval($retval[$testName][1]); $retval[$testName] = array($count_all, $count_negative); } } } DbUtil::switchRestore($saved_db); return $retval; } 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); $saved_db = DbUtil::switchToLabConfig($lab_config->id); $test_type_id = $testIds[$lab_config->id]; # For particular test type, fetch negative records $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 ( s.date_collected BETWEEN '{$date_from}' AND '{$date_to}' ) " . "AND (result LIKE 'N,%' OR result LIKE 'n�gatif,%' OR result LIKE 'negatif,%' OR result LIKE 'n,%' OR result LIKE 'negative,%')"; $record = query_associative_one($query_string); $count_negative = intval($record['count_val']); $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']); # If total tests is 0, ignore if ($count_all == 0) { continue; } $testName = get_test_name_by_id($test_type_id); $labName = $lab_config->name; $retval[$labName] = array($count_all, $count_negative); } DbUtil::switchRestore($saved_db); return $retval; } 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]; $retvalues = StatsLib::getDiscreteInfectionStats($lab_config, $date_from, $date_to, $test_type_id); $saved_db = DbUtil::switchToLabConfig($lab_config->id); foreach ($retvalues as $key => $value) { $testName = get_test_name_by_id($key); $retval[$testName] = $value; } DbUtil::switchRestore($saved_db); return $retval; } 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]; $saved_db = DbUtil::switchToLabConfig($lab_config->id); # For particular test type, fetch negative records $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 ( s.date_collected BETWEEN '{$date_from}' AND '{$date_to}' ) " . "AND (result LIKE 'N,%' OR result LIKE 'n�gatif,%' OR result LIKE 'negatif,%' OR result LIKE 'n,%' OR result LIKE 'negative,%')"; $record = query_associative_one($query_string); $count_negative = intval($record['count_val']); $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}' )"; //echo($query_string); $record = query_associative_one($query_string); $count_all = intval($record['count_val']); # If total tests is 0, ignore if ($count_all == 0) { continue; } $testName = get_test_name_by_id($test_type_id); $labName = $lab_config->name; $query_string = "SELECT prevalence_threshold FROM test_type " . "WHERE test_type_id={$test_type_id} "; $record = query_associative_one($query_string); $threshold = intval($record['prevalence_threshold']); $retval[$labName] = array($count_all, $count_negative, $threshold); } DbUtil::switchRestore($saved_db); return $retval; } } } } } } }