public function getAggregateReportSummary($lab_config) { # Returns HTML form elements for configuring infection report # Called from lab_config_home.php # Fetch site-wide settings for all tests from dummy record $site_settings = DiseaseReport::getByKeys($lab_config->id, 0, 0); if($site_settings == null) { # TODO: //$this->getNewAggregateReportConfigForm($lab_config); } ?> <div class='pretty_box' style='width:700px;'> <table class='hor-minimalist-b'> <tbody> <tr valign='top'> <td><?php echo LangUtil::$pageTerms['GROUP_BYGENDER']; ?></td> <td> <?php if($site_settings->groupByGender == 1) echo LangUtil::$generalTerms['YES']; else echo LangUtil::$generalTerms['NO']; ?> </td> </tr> <tr valign='top'> <td><?php echo LangUtil::$pageTerms['GROUP_BYAGE']; ?></td> <td> <?php if($site_settings->groupByAge == 1) echo LangUtil::$generalTerms['YES']; else echo LangUtil::$generalTerms['NO']; ?> </td> </tr> <tr valign='top' <?php if($site_settings->groupByAge == 0) echo " style='display:none' "; ?>> <td><?php echo LangUtil::$pageTerms['RANGE_AGE']; ?> (<?php echo LangUtil::$generalTerms['YEARS']; ?>)</td> <td> <?php # Group by age enabled $age_parts = explode(",", $site_settings->ageGroups); foreach($age_parts as $age_part) { if(trim($age_part) == "") continue; $age_bounds = explode(":", $age_part); echo $age_bounds[0]."-".$age_bounds[1]; echo " "; } ?> </td> </tr> <?php # For each test with numeric range, show ranges $test_list = $lab_config->getTestTypes(); foreach($test_list as $test_type) { ?> <tr valign='top'> <td> <?php echo $test_type->getName(); ?> </td> <td> <?php $measure_to_set = false; $measure_list = $test_type->getMeasures(); ?> <?php $measure_count = 0; foreach($measure_list as $measure) { $disease_report = DiseaseReport::getByKeys($lab_config->id, $test_type->testTypeId, $measure->measureId); $measure_count++; if(strpos($measure->range, "/") !== false) { # Alphanumeric options # Do nothing //$range_options = explode("/", $measure->range); } else { # Numeric ranges # Show fields to select range slots $measure_to_set = true; if(count($measure_list) != 1) { # Show measure names if more than one. if($measure->checkIfSubmeasure() == 1) { $decName = $measure->truncateSubmeasureTag(); } else { $decName = $measure->getName(); } echo $decName." "; } $range_bounds = explode(":", $measure->range); if($disease_report == null) { # No entry exists. Show default values. echo $range_bounds[0]."-".$range_bounds[1]; } else { # Entries exist. Prefill form with these values. $slot_list = explode(",", $disease_report->measureGroups); foreach($slot_list as $slot_part) { if(trim($slot_part) == "") continue; $slot_bounds = explode(":", $slot_part); if($slot_bounds[0] == "\$freetext$$") continue; echo $slot_bounds[0]."-".$slot_bounds[1]; echo " "; } } echo "<br><br>"; } } if($measure_to_set === false) { echo "<small>".LangUtil::$pageTerms['RANGE_NOTREQD']."</small><br><br>"; } ?> </td> </tr> <?php } ?> </tbody> </table> </div> <?php }
# Check if disease report has already been configured. ## If not, add new entries $site_settings = new DiseaseReport(); $site_settings->labConfigId = $lab_config_id; $site_settings->testTypeId = 0; $site_settings->measureId = 0; $site_settings->groupByGender = 1; $site_settings->groupByAge = 0; $site_settings->ageGroups = ""; $site_settings->measureGroups = ""; $existing_settings = DiseaseReport::getByKeys($site_settings->labConfigId, $site_settings->testTypeId, $site_settings->measureId); if ($existing_settings == null) { $site_settings->addToDb(); } $selected_test_list = $lab_config->getTestTypes(); foreach ($selected_test_list as $test_type) { $site_settings->testTypeId = $test_type->testTypeId; $measure_list = $test_type->getMeasures(); foreach ($measure_list as $measure) { $site_settings->measureId = $measure->measureId; $site_settings->measureGroups = $measure->range; if (strpos($site_settings->measureGroups, "/") === true) { # Alphanumeric options: Do not add new entry continue; } $existing_settings = DiseaseReport::getByKeys($site_settings->labConfigId, $site_settings->testTypeId, $site_settings->measureId); if ($existing_settings == null) { $site_settings->addToDb(); } } }
?> <tr> </thead> <tbody> <?php foreach ($selected_test_types as $test) { StatsLib::setDiseaseSetList($lab_config, $test, $date_from, $date_to); $measures = $test->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->testTypeId, $measure->measureId); if ($disease_report == null) { # TODO: Check for error control # Alphanumeric values. Hence entry not found. //continue; break; } $is_range_options = true; if (strpos($measure->range, "/") === false) { $is_range_options = false; } $range_values = array(); if ($is_range_options) { # Alphanumeric options $range_values1 = explode("/", $measure->range); $range_values = str_replace("#", "/", $range_values1);
$cat_test_types = TestType::getByCategory($cat_code); $cat_test_ids = array(); foreach ($cat_test_types as $test_type) { $cat_test_ids[] = $test_type->testTypeId; } $matched_test_ids = array_intersect($cat_test_ids, $selected_test_ids); $selected_test_ids = array_values($matched_test_ids); } # Fetch TestType objects using selected test_type_ids. $selected_test_types = array(); foreach ($selected_test_ids as $test_type_id) { $test = TestType::getById($test_type_id); $selected_test_types[] = $test; } # Fetch site-wide settings $site_settings = DiseaseReport::getByKeys($lab_config->id, 0, 0); $age_group_list = $site_settings->getAgeGroupAsList(); ?> <table> <tbody> <tr> <td><?php echo LangUtil::$generalTerms['FACILITY']; ?> :</td> <td><?php echo $lab_config->getSiteName(); ?> </td> </tr> <tr>
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 }