Example #1
0
 public static function getDiscreteInfectionStats($lab_config, $date_from, $date_to, $test_type_id_passed = null)
 {
     # Fetch all test types with one measure having discrete P/N range
     $retval = array();
     if (!$test_type_id_passed) {
         $test_type_list = get_discrete_value_test_types($lab_config);
     } else {
         $test_type_list[] = $test_type_id_passed;
     }
     $saved_db = DbUtil::switchToLabConfig($lab_config->id);
     # 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 = $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 = $record['count_val'];
         # If total tests is 0, ignore
         if ($count_all == 0) {
             continue;
         }
         $query_string = "SELECT prevalence_threshold FROM test_type " . "WHERE test_type_id={$test_type_id} ";
         $record = query_associative_one($query_string);
         $threshold = $record['prevalence_threshold'];
         $retval[$test_type_id] = array($count_all, $count_negative, $threshold);
     }
     DbUtil::switchRestore($saved_db);
     return $retval;
 }
Example #2
0
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);
    	}
    }
    */
}
Example #3
0
	public function getDiscreteTestTypesSelect($lab_config_id)
	{
		# Returns test types used at a site for drop down <select> boxes
		$lab_config = LabConfig::getById($lab_config_id);
		$test_id_list = get_discrete_value_test_types($lab_config);
		$test_type_list = array();
		foreach($test_id_list as $test_type_id)
		{
			$test_type = TestType::getById($test_type_id);
			$test_type_list[] = $test_type;
		}
		foreach($test_type_list as $test_type)
		{
			echo "<option value='$test_type->testTypeId'>".$test_type->getName()."</option>";
		}
	}
Example #4
0
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);
    }
}