From 526ccff010e88a20fcdf511b6676f0cec23c9482 Mon Sep 17 00:00:00 2001 From: Adam Stewart Date: Sun, 7 Apr 2024 09:35:12 -0500 Subject: [PATCH 1/2] Add NCD and Child Scorecard encounters to demographics report. --- .../scripts/generate-demographics-report.php | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/server/hedley/modules/custom/hedley_admin/scripts/generate-demographics-report.php b/server/hedley/modules/custom/hedley_admin/scripts/generate-demographics-report.php index b2bf156e39..372371fb17 100644 --- a/server/hedley/modules/custom/hedley_admin/scripts/generate-demographics-report.php +++ b/server/hedley/modules/custom/hedley_admin/scripts/generate-demographics-report.php @@ -200,7 +200,7 @@ function encounter_all_count($type, $filter = NULL, $limit = NULL, $region = NUL LEFT JOIN field_data_field_individual_participant ip ON e.field_{$type}_encounter_target_id=ip.entity_id LEFT JOIN field_data_field_person person ON ip.field_individual_participant_target_id=person.entity_id LEFT JOIN field_data_field_district district ON person.field_person_target_id=district.entity_id - WHERE + WHERE FROM_UNIXTIME(node.created) < '$limit' {$region_clause}")->fetchField(); } @@ -261,7 +261,7 @@ function encounter_unique_count($type, $filter = NULL, $limit = NULL, $region = LEFT JOIN field_data_field_individual_participant ip ON e.field_{$type}_encounter_target_id=ip.entity_id LEFT JOIN field_data_field_person person ON ip.field_individual_participant_target_id=person.entity_id LEFT JOIN field_data_field_district district ON person.field_person_target_id=district.entity_id - WHERE + WHERE FROM_UNIXTIME(node.created) < '$limit' {$region_clause}")->fetchField(); } @@ -280,7 +280,8 @@ function encounter_unique_count($type, $filter = NULL, $limit = NULL, $region = $group_encounter_all = group_encounter_all($measurement_types_sql_list, $limit_date, $region); $group_encounter_unique = group_encounter_unique($measurement_types_sql_list, $limit_date, $region); -drush_print("# Demographics report - " . $limit_date); +$print_region = ($region) ? $region : "All Districts"; +drush_print("# Demographics report - " . $print_region . " - " . $limit_date); drush_print("## REGISTERED PATIENTS"); @@ -501,10 +502,20 @@ function group_encounter_unique($measurement_types_list, $limit = NULL, $region encounter_unique_count('well_child', 'hc', $limit_date, $region), ], [ - ' Home Visit', + 'Home Visit', encounter_all_count('home_visit', 'chw', $limit_date, $region), encounter_unique_count('home_visit', 'chw', $limit_date, $region), ], + [ + 'Child Scorecard', + encounter_all_count('child_scoreboard', 'chw', $limit_date, $region), + encounter_unique_count('child_scoreboard', 'chw', $limit_date, $region), + ], + [ + 'NCD', + encounter_all_count('ncd', 'nc', $limit_date, $region), + encounter_unique_count('ncd', 'hc', $limit_date, $region), + ], [ 'Nutrition (total)', $group_encounter_all['pmtct']->counter + $group_encounter_all['fbf']->counter + $group_encounter_all['sorwathe']->counter + $group_encounter_all['chw']->counter + $group_encounter_all['achi']->counter + encounter_all_count('nutrition', 'chw', $limit_date, $region), @@ -542,8 +553,8 @@ function group_encounter_unique($measurement_types_list, $limit = NULL, $region ], [ 'TOTAL', - $group_encounter_all['pmtct']->counter + $group_encounter_all['fbf']->counter + $group_encounter_all['sorwathe']->counter + $group_encounter_all['chw']->counter + $group_encounter_all['achi']->counter + encounter_all_count('nutrition', 'chw', $limit_date, $region) + encounter_all_count('prenatal', 'all', $limit_date, $region) + encounter_all_count('acute_illness', 'all', $limit_date, $region) + encounter_all_count('well_child', 'hc', $limit_date, $region) + encounter_all_count('home_visit', 'chw', $limit_date, $region), - $group_encounter_unique['pmtct']->counter + $group_encounter_unique['fbf']->counter + $group_encounter_unique['sorwathe']->counter + $group_encounter_unique['chw']->counter + $group_encounter_unique['achi']->counter + encounter_unique_count('nutrition', 'chw', $limit_date, $region) + encounter_unique_count('prenatal', 'all', $limit_date, $region) + encounter_unique_count('acute_illness', 'all', $limit_date, $region) + encounter_unique_count('well_child', 'hc', $limit_date, $region) + encounter_unique_count('home_visit', 'chw', $limit_date, $region), + $group_encounter_all['pmtct']->counter + $group_encounter_all['fbf']->counter + $group_encounter_all['sorwathe']->counter + $group_encounter_all['chw']->counter + $group_encounter_all['achi']->counter + encounter_all_count('nutrition', 'chw', $limit_date, $region) + encounter_all_count('prenatal', 'all', $limit_date, $region) + encounter_all_count('acute_illness', 'all', $limit_date, $region) + encounter_all_count('well_child', 'hc', $limit_date, $region) + encounter_all_count('home_visit', 'chw', $limit_date, $region) + encounter_all_count('child_scoreboard', 'chw', $limit_date, $region) + encounter_all_count('ncd', 'nc', $limit_date, $region), + $group_encounter_unique['pmtct']->counter + $group_encounter_unique['fbf']->counter + $group_encounter_unique['sorwathe']->counter + $group_encounter_unique['chw']->counter + $group_encounter_unique['achi']->counter + encounter_unique_count('nutrition', 'chw', $limit_date, $region) + encounter_unique_count('prenatal', 'all', $limit_date, $region) + encounter_unique_count('acute_illness', 'all', $limit_date, $region) + encounter_unique_count('well_child', 'hc', $limit_date, $region) + encounter_unique_count('home_visit', 'chw', $limit_date, $region) + encounter_unique_count('child_scoreboard', 'chw', $limit_date, $region) + encounter_unique_count('ncd', 'nc', $limit_date, $region), ], ]; From 444b2dcd2d87a706de959cef24f1bac280a5c146 Mon Sep 17 00:00:00 2001 From: Adam Stewart Date: Wed, 19 Jun 2024 07:29:16 -0500 Subject: [PATCH 2/2] Add more fixes. --- server/RoboFile.php | 4 +-- .../anc-first-visit-all-pregnancies.SQL | 3 -- .../anc-report-active-pregnancies-chw.SQL | 1 - .../anc-report-active-pregnancies-nurse.SQL | 1 - .../scripts/anc-report-active-pregnancies.SQL | 1 - .../anc-report-all-pregnancies-chw.SQL | 1 - .../anc-report-all-pregnancies-nurse.SQL | 1 - .../scripts/anc-report-all-pregnancies.SQL | 1 - .../anc-report-completed-pregnancies-chw.SQL | 1 - ...anc-report-completed-pregnancies-nurse.SQL | 1 - .../anc-report-completed-pregnancies.SQL | 1 - .../scripts/generate-acute-illness-report.php | 34 +++++++++++++------ .../scripts/generate-anc-report.php | 4 +++ .../scripts/generate-nutrition-report.php | 4 +-- 14 files changed, 31 insertions(+), 27 deletions(-) diff --git a/server/RoboFile.php b/server/RoboFile.php index 8d511f2324..ce52ab25ba 100644 --- a/server/RoboFile.php +++ b/server/RoboFile.php @@ -426,11 +426,11 @@ public function reportAcuteIllness($start_date = NULL, $end_date = NULL, $region /** * Generates the ANC report. */ - public function reportAnc($limit_date = NULL) { + public function reportAnc($limit_date = NULL, $region = NULL) { if (empty($limit_date)) { $limit_date = date('Y-m-d'); } - $this->_exec("cd /var/www/html/server/www && drush scr profiles/hedley/modules/custom/hedley_admin/scripts/generate-anc-report.php --limit_date=$limit_date"); + $this->_exec("cd /var/www/html/server/www && drush scr profiles/hedley/modules/custom/hedley_admin/scripts/generate-anc-report.php --limit_date=$limit_date --region=$region"); } /** diff --git a/server/hedley/modules/custom/hedley_admin/scripts/anc-first-visit-all-pregnancies.SQL b/server/hedley/modules/custom/hedley_admin/scripts/anc-first-visit-all-pregnancies.SQL index c35b49f323..dc7556a690 100644 --- a/server/hedley/modules/custom/hedley_admin/scripts/anc-first-visit-all-pregnancies.SQL +++ b/server/hedley/modules/custom/hedley_admin/scripts/anc-first-visit-all-pregnancies.SQL @@ -13,7 +13,6 @@ SELECT WHERE encounter.field_encounter_type_value = 'antenatal' AND edd.field_expected_date_concluded_value is NOT NULL AND - field_district_value='Bugesera' AND FROM_UNIXTIME(node.created) < :limit AND DATEDIFF (edd.field_expected_date_concluded_value, FROM_UNIXTIME(node.created)) > 180 AND DATEDIFF (edd.field_expected_date_concluded_value, FROM_UNIXTIME(node.created)) < 320) AS first_trimester, @@ -35,7 +34,6 @@ SELECT WHERE encounter.field_encounter_type_value = 'antenatal' AND edd.field_expected_date_concluded_value is NOT NULL AND - field_district_value='Bugesera' AND FROM_UNIXTIME(node.created) < :limit AND DATEDIFF (edd.field_expected_date_concluded_value, FROM_UNIXTIME(node.created)) > 90 AND DATEDIFF (edd.field_expected_date_concluded_value, FROM_UNIXTIME(node.created)) <= 180) AS second_trimester, @@ -56,7 +54,6 @@ SELECT WHERE encounter.field_encounter_type_value = 'antenatal' AND edd.field_expected_date_concluded_value is NOT NULL AND - field_district_value='Bugesera' AND FROM_UNIXTIME(node.created) < :limit AND DATEDIFF (edd.field_expected_date_concluded_value, FROM_UNIXTIME(node.created)) > 0 AND DATEDIFF (edd.field_expected_date_concluded_value, FROM_UNIXTIME(node.created)) <= 90) AS third_trimester diff --git a/server/hedley/modules/custom/hedley_admin/scripts/anc-report-active-pregnancies-chw.SQL b/server/hedley/modules/custom/hedley_admin/scripts/anc-report-active-pregnancies-chw.SQL index 17bbee6527..69fa2c6b7e 100644 --- a/server/hedley/modules/custom/hedley_admin/scripts/anc-report-active-pregnancies-chw.SQL +++ b/server/hedley/modules/custom/hedley_admin/scripts/anc-report-active-pregnancies-chw.SQL @@ -19,7 +19,6 @@ FROM fdfpet.field_prenatal_encounter_type_value LIKE 'Chw%' AND date(edd.field_expected_date_concluded_value) >= DATE_ADD(:limit, INTERVAL 30 DAY) AND edd.field_expected_date_concluded_value is NOT NULL AND - field_district_value='Bugesera' AND FROM_UNIXTIME(node.created) < :limit GROUP BY field_individual_participant_target_id) a diff --git a/server/hedley/modules/custom/hedley_admin/scripts/anc-report-active-pregnancies-nurse.SQL b/server/hedley/modules/custom/hedley_admin/scripts/anc-report-active-pregnancies-nurse.SQL index 737431390d..90da86c576 100644 --- a/server/hedley/modules/custom/hedley_admin/scripts/anc-report-active-pregnancies-nurse.SQL +++ b/server/hedley/modules/custom/hedley_admin/scripts/anc-report-active-pregnancies-nurse.SQL @@ -19,7 +19,6 @@ FROM (fdfpet.field_prenatal_encounter_type_value='nurse' OR fdfpet.field_prenatal_encounter_type_value is NULL) AND date(edd.field_expected_date_concluded_value) >= DATE_ADD(:limit, INTERVAL 30 DAY) AND edd.field_expected_date_concluded_value is NOT NULL AND - field_district_value='Bugesera' AND FROM_UNIXTIME(node.created) < :limit GROUP BY field_individual_participant_target_id) a diff --git a/server/hedley/modules/custom/hedley_admin/scripts/anc-report-active-pregnancies.SQL b/server/hedley/modules/custom/hedley_admin/scripts/anc-report-active-pregnancies.SQL index b9960aacbd..9aa86ad086 100644 --- a/server/hedley/modules/custom/hedley_admin/scripts/anc-report-active-pregnancies.SQL +++ b/server/hedley/modules/custom/hedley_admin/scripts/anc-report-active-pregnancies.SQL @@ -18,7 +18,6 @@ FROM ip.bundle = 'prenatal_encounter' AND date(edd.field_expected_date_concluded_value) >= DATE_ADD(:limit, INTERVAL 30 DAY) AND edd.field_expected_date_concluded_value is NOT NULL AND - field_district_value='Bugesera' AND FROM_UNIXTIME(node.created) < :limit GROUP BY field_individual_participant_target_id) a diff --git a/server/hedley/modules/custom/hedley_admin/scripts/anc-report-all-pregnancies-chw.SQL b/server/hedley/modules/custom/hedley_admin/scripts/anc-report-all-pregnancies-chw.SQL index 3b8c7fbd5e..5136d1a290 100644 --- a/server/hedley/modules/custom/hedley_admin/scripts/anc-report-all-pregnancies-chw.SQL +++ b/server/hedley/modules/custom/hedley_admin/scripts/anc-report-all-pregnancies-chw.SQL @@ -18,7 +18,6 @@ FROM ip.bundle = 'prenatal_encounter' AND fdfpet.field_prenatal_encounter_type_value LIKE 'Chw%' AND edd.field_expected_date_concluded_value is NOT NULL AND - field_district_value='Bugesera' AND FROM_UNIXTIME(node.created) < :limit GROUP BY field_individual_participant_target_id) a diff --git a/server/hedley/modules/custom/hedley_admin/scripts/anc-report-all-pregnancies-nurse.SQL b/server/hedley/modules/custom/hedley_admin/scripts/anc-report-all-pregnancies-nurse.SQL index cbc8a258e3..1d80826962 100644 --- a/server/hedley/modules/custom/hedley_admin/scripts/anc-report-all-pregnancies-nurse.SQL +++ b/server/hedley/modules/custom/hedley_admin/scripts/anc-report-all-pregnancies-nurse.SQL @@ -18,7 +18,6 @@ FROM ip.bundle = 'prenatal_encounter' AND (fdfpet.field_prenatal_encounter_type_value='nurse' OR fdfpet.field_prenatal_encounter_type_value is NULL) AND edd.field_expected_date_concluded_value is NOT NULL AND - field_district_value='Bugesera' AND FROM_UNIXTIME(node.created) < :limit GROUP BY field_individual_participant_target_id) a diff --git a/server/hedley/modules/custom/hedley_admin/scripts/anc-report-all-pregnancies.SQL b/server/hedley/modules/custom/hedley_admin/scripts/anc-report-all-pregnancies.SQL index 49bbfabbe8..1896bd5b2a 100644 --- a/server/hedley/modules/custom/hedley_admin/scripts/anc-report-all-pregnancies.SQL +++ b/server/hedley/modules/custom/hedley_admin/scripts/anc-report-all-pregnancies.SQL @@ -18,7 +18,6 @@ FROM WHERE ip.bundle = 'prenatal_encounter' AND edd.field_expected_date_concluded_value is NOT NULL AND - field_district_value='Bugesera' AND FROM_UNIXTIME(node.created) < :limit GROUP BY field_individual_participant_target_id) a diff --git a/server/hedley/modules/custom/hedley_admin/scripts/anc-report-completed-pregnancies-chw.SQL b/server/hedley/modules/custom/hedley_admin/scripts/anc-report-completed-pregnancies-chw.SQL index c39c41d936..4f6969d215 100644 --- a/server/hedley/modules/custom/hedley_admin/scripts/anc-report-completed-pregnancies-chw.SQL +++ b/server/hedley/modules/custom/hedley_admin/scripts/anc-report-completed-pregnancies-chw.SQL @@ -19,7 +19,6 @@ FROM fdfpet.field_prenatal_encounter_type_value LIKE 'Chw%' AND date(edd.field_expected_date_concluded_value) < DATE_ADD(:limit, INTERVAL 30 DAY) AND edd.field_expected_date_concluded_value is NOT NULL AND - field_district_value='Bugesera' AND FROM_UNIXTIME(node.created) < :limit GROUP BY field_individual_participant_target_id) a diff --git a/server/hedley/modules/custom/hedley_admin/scripts/anc-report-completed-pregnancies-nurse.SQL b/server/hedley/modules/custom/hedley_admin/scripts/anc-report-completed-pregnancies-nurse.SQL index 160d14fb5f..77ad16271f 100644 --- a/server/hedley/modules/custom/hedley_admin/scripts/anc-report-completed-pregnancies-nurse.SQL +++ b/server/hedley/modules/custom/hedley_admin/scripts/anc-report-completed-pregnancies-nurse.SQL @@ -19,7 +19,6 @@ FROM (fdfpet.field_prenatal_encounter_type_value='nurse' OR fdfpet.field_prenatal_encounter_type_value is NULL) AND date(edd.field_expected_date_concluded_value) < DATE_ADD(:limit, INTERVAL 30 DAY) AND edd.field_expected_date_concluded_value is NOT NULL AND - field_district_value='Bugesera' AND FROM_UNIXTIME(node.created) < :limit GROUP BY field_individual_participant_target_id) a diff --git a/server/hedley/modules/custom/hedley_admin/scripts/anc-report-completed-pregnancies.SQL b/server/hedley/modules/custom/hedley_admin/scripts/anc-report-completed-pregnancies.SQL index a3fa9b0842..2ace76f283 100644 --- a/server/hedley/modules/custom/hedley_admin/scripts/anc-report-completed-pregnancies.SQL +++ b/server/hedley/modules/custom/hedley_admin/scripts/anc-report-completed-pregnancies.SQL @@ -18,7 +18,6 @@ FROM ip.bundle = 'prenatal_encounter' AND date(edd.field_expected_date_concluded_value) < DATE_ADD(:limit, INTERVAL 30 DAY) AND edd.field_expected_date_concluded_value is NOT NULL AND - field_district_value='Bugesera' AND FROM_UNIXTIME(node.created) < :limit GROUP BY field_individual_participant_target_id) a diff --git a/server/hedley/modules/custom/hedley_admin/scripts/generate-acute-illness-report.php b/server/hedley/modules/custom/hedley_admin/scripts/generate-acute-illness-report.php index c330007200..57b90b01c5 100644 --- a/server/hedley/modules/custom/hedley_admin/scripts/generate-acute-illness-report.php +++ b/server/hedley/modules/custom/hedley_admin/scripts/generate-acute-illness-report.php @@ -30,15 +30,15 @@ // Get all of the encounters and the related participations. $result = db_query(" -SELECT +SELECT ip.entity_id as encounter, ip.field_individual_participant_target_id as participant - FROM + FROM field_data_field_individual_participant ip LEFT JOIN field_data_field_scheduled_date sd ON ip.entity_id = sd.entity_id - LEFT JOIN + LEFT JOIN field_data_field_person person ON ip.field_individual_participant_target_id=person.entity_id - LEFT JOIN + LEFT JOIN field_data_field_district district ON person.field_person_target_id=district.entity_id WHERE ip.bundle = 'acute_illness_encounter' @@ -62,6 +62,8 @@ $first_encounters = array_unique($first_encounters); $diagnoses = []; +$malaria_test_count = 0; + // Now get the diagnosis for each first encounter. foreach ($first_encounters as $first_encounter) { @@ -69,6 +71,17 @@ $result = db_query($query)->fetchField(); if ($result) { $diagnoses[] = $result; + if ($result == 'fever-of-unknown-origin') { + $check_malaria = db_query('SELECT field_malaria_rapid_test_value + FROM field_data_field_malaria_rapid_test mrt + LEFT JOIN field_data_field_acute_illness_encounter aie ON aie.entity_id = mrt.entity_id + LEFT JOIN field_data_field_acute_illness_diagnosis di ON aie.field_acute_illness_encounter_target_id = di.entity_id + WHERE di.entity_id = ' . $first_encounter)->fetchField(); + + if ($check_malaria == 'unable-to-run') { + $malaria_test_count++; + } + } } } @@ -95,21 +108,23 @@ $table = new HedleyAdminTextTable(['Initial Diagnosis', 'Count']); drush_print($table->render($data)); +drush_print ('Malaria tests: ' . $malaria_test_count); + // ANC Diagnoses. drush_print("# ANC Diagnoses report - $region_name - $start_date - $end_date"); // Get all of the encounters and the related participations. $result = db_query(" -SELECT +SELECT ip.entity_id as encounter, ip.field_individual_participant_target_id as participant - FROM + FROM field_data_field_individual_participant ip LEFT JOIN field_data_field_scheduled_date sd ON ip.entity_id = sd.entity_id - LEFT JOIN + LEFT JOIN field_data_field_person person ON ip.field_individual_participant_target_id=person.entity_id - LEFT JOIN + LEFT JOIN field_data_field_district district ON person.field_person_target_id=district.entity_id WHERE ip.bundle = 'prenatal_encounter' @@ -147,6 +162,3 @@ 'Total', count($diagnoses), ]; - -$table = new HedleyAdminTextTable(['ANC Diagnosis', 'Count']); -drush_print($table->render($data)); diff --git a/server/hedley/modules/custom/hedley_admin/scripts/generate-anc-report.php b/server/hedley/modules/custom/hedley_admin/scripts/generate-anc-report.php index d15342cc4e..0c41393bd2 100644 --- a/server/hedley/modules/custom/hedley_admin/scripts/generate-anc-report.php +++ b/server/hedley/modules/custom/hedley_admin/scripts/generate-anc-report.php @@ -12,6 +12,8 @@ require_once __DIR__ . '/report_common.inc'; $limit_date = drush_get_option('limit_date', FALSE); +$region = drush_get_option('region', FALSE); + if (!$limit_date) { drush_print('Please specify --limit_date option'); exit; @@ -47,6 +49,8 @@ // 1 visit => 6 // 5+ visits => 15. $group_limit = 5; +$region_clause = ($region) ? "AND field_district_value LIKE '%$region%'" : ""; + foreach ($queries as $label => $query) { $table = new HedleyAdminTextTable([$label, 'Counter']); $data = []; diff --git a/server/hedley/modules/custom/hedley_admin/scripts/generate-nutrition-report.php b/server/hedley/modules/custom/hedley_admin/scripts/generate-nutrition-report.php index 18b23a79d4..f1c39c58cd 100644 --- a/server/hedley/modules/custom/hedley_admin/scripts/generate-nutrition-report.php +++ b/server/hedley/modules/custom/hedley_admin/scripts/generate-nutrition-report.php @@ -272,7 +272,7 @@ function base_query_for_bundle($bundle): EntityFieldQuery { * Examined patients. */ function format_prevalence(array $cases, array $examined) { - return round(((count($cases) / count(array_unique($examined))) * 100), 3) . ' %'; + return round(((count($cases) / count(array_unique($examined))) * 100), 3) . ' % (' . count(array_unique($examined)) . ')'; } /** @@ -391,7 +391,7 @@ function calculate_incidence(array $dataset, string $current_period, array $prev } } - return round((($new_cases / count(array_unique($dataset[$current_period]['any']))) * 100), 3) . ' %'; + return round((($new_cases / count(array_unique($dataset[$current_period]['any']))) * 100), 3) . ' % (' . $new_cases . ')'; } /**