} $date_ts = $second_day_ts; $i++; } DbUtil::switchRestore($saved_db); return $retval; } public static function getDiscreteInfectionStatsMonthly($lab_config, $test_type_id, $date_from, $date_to, $gender = null) { $i = 1; # Fetch all test types with one measure having discrete P/N range $retval = array(); $saved_db = DbUtil::switchToLabConfig($lab_config->id); $date_from_parts = explode("-", $date_from); $date_to_parts = explode("-", $date_to); $month_ts = mktime(0, 0, 0, $date_from_parts[1], 0, $date_from_parts[0]); $date_to_ts = mktime(0, 0, 0, $date_to_parts[1], 0, $date_to_parts[0]); # For the test type, fetch negative records while ($month_ts < $date_to_ts) { $end_of_month_ts = mktime(0, 0, 0, $date_from_parts[1] + $i, 0, $date_from_parts[0]); $date_fromp = date("Y-m-d", $month_ts); $date_top = date("Y-m-d", $end_of_month_ts); if ($gender == 'M' || $gender == 'F') { $query_string = "SELECT COUNT(*) AS count_val FROM test t, patient p, specimen s " . "WHERE t.test_type_id={$test_type_id} " . "AND p.patient_id=s.patient_id " . "AND p.sex LIKE '{$gender}' " . "AND t.specimen_id=s.specimen_id " . "AND (s.date_collected BETWEEN '{$date_fromp}' AND '{$date_top}') " . "AND (t.result LIKE 'N,%' OR t.result LIKE 'n�gatif,%' OR t.result LIKE 'negatif,%' OR t.result LIKE 'n,%' OR t.result LIKE 'negative,%')"; } else { $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_fromp}' AND '{$date_top}' )" . "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_fromp}' AND '{$date_top}' )"; $record = query_associative_one($query_string); $count_all = $record['count_val']; # If total tests is 0, ignore if ($count_all != 0) { $retval[$month_ts] = array($count_all, $count_negative); } $month_ts = $end_of_month_ts;