Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Reports #1214

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions server/RoboFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -62,13 +62,26 @@
$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) {

$query = 'SELECT field_acute_illness_diagnosis_value FROM field_data_field_acute_illness_diagnosis di WHERE entity_id = ' . $first_encounter;
$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++;
}
}
}
}

Expand All @@ -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'
Expand Down Expand Up @@ -147,6 +162,3 @@
'Total',
count($diagnoses),
];

$table = new HedleyAdminTextTable(['ANC Diagnosis', 'Count']);
drush_print($table->render($data));
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand All @@ -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");

Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
],
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) . ')';
}

/**
Expand Down Expand Up @@ -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 . ')';
}

/**
Expand Down