From fcfe991aa3119fa0f897c7448e301d4f0713fc2e Mon Sep 17 00:00:00 2001 From: shilpa-iplit <38578773+shilpa-iplit@users.noreply.github.com> Date: Tue, 22 Oct 2019 18:55:03 +0530 Subject: [PATCH] report feedback (#71) --- .../sql/artMonthlyStartedOnArtReport.sql | 106 +++++++++++++---- .../reports/sql/artMonthlyViralLoadReport.sql | 108 +++++++++++++++--- 2 files changed, 176 insertions(+), 38 deletions(-) diff --git a/openmrs/apps/reports/sql/artMonthlyStartedOnArtReport.sql b/openmrs/apps/reports/sql/artMonthlyStartedOnArtReport.sql index 82d5e6327..28bf3300b 100644 --- a/openmrs/apps/reports/sql/artMonthlyStartedOnArtReport.sql +++ b/openmrs/apps/reports/sql/artMonthlyStartedOnArtReport.sql @@ -298,7 +298,7 @@ FROM ( UNION ALL SELECT - '40-49 YRS' as 'Age Group', + '40-44 YRS' as 'Age Group', count(maleGenderPreviousReportingPeriod) as 'Cumulative number of persons ever started on ART at this facility\nat the end of the previous reporting period\n Male', count(femaleGenderPreviousReportingPeriod) as 'Cumulative number of persons ever started on ART at this facility\nat the end of the previous reporting period\n Female', count(totalGenderPreviousReportingPeriod) as 'Cumulative number of persons ever started on ART at this facility\nat the end of the previous reporting period\n Total', @@ -310,15 +310,15 @@ SELECT count(totalGenderSoFar) as 'Cumulative number of persons ever started on ART at this facility\nat end of the current reporting period (Month)\n Total' FROM ( SELECT - CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 40 and 49 and gender = 'M' and MONTH(artStartDate) < MONTH(CURDATE())) THEN 1 END maleGenderPreviousReportingPeriod, - CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 40 and 49 and gender = 'F' and MONTH(artStartDate) < MONTH(CURDATE())) THEN 1 END femaleGenderPreviousReportingPeriod, - CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 40 and 49 and MONTH(artStartDate) < MONTH(CURDATE())) THEN 1 END totalGenderPreviousReportingPeriod, - CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 40 and 49 and gender = 'M' and MONTH(artStartDate) = MONTH(CURDATE()) AND YEAR(artStartDate) = YEAR(CURDATE())) THEN 1 END maleGenderCurrentReportingPeriod, - CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 40 and 49 and gender = 'F' and MONTH(artStartDate) = MONTH(CURDATE()) AND YEAR(artStartDate) = YEAR(CURDATE())) THEN 1 END femaleGenderCurrentReportingPeriod, - CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 40 and 49 and MONTH(artStartDate) = MONTH(CURDATE()) AND YEAR(artStartDate) = YEAR(CURDATE())) THEN 1 END totalGenderCurrentReportingPeriod, - CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 40 and 49 and gender = 'M' and artStartDate is not NULL) THEN 1 END maleGenderSoFar, - CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 40 and 49 and gender = 'F' and artStartDate is not NULL) THEN 1 END femaleGenderSoFar, - CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 40 and 49 and artStartDate is not NULL) THEN 1 END totalGenderSoFar + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 40 and 44 and gender = 'M' and MONTH(artStartDate) < MONTH(CURDATE())) THEN 1 END maleGenderPreviousReportingPeriod, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 40 and 44 and gender = 'F' and MONTH(artStartDate) < MONTH(CURDATE())) THEN 1 END femaleGenderPreviousReportingPeriod, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 40 and 44 and MONTH(artStartDate) < MONTH(CURDATE())) THEN 1 END totalGenderPreviousReportingPeriod, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 40 and 44 and gender = 'M' and MONTH(artStartDate) = MONTH(CURDATE()) AND YEAR(artStartDate) = YEAR(CURDATE())) THEN 1 END maleGenderCurrentReportingPeriod, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 40 and 44 and gender = 'F' and MONTH(artStartDate) = MONTH(CURDATE()) AND YEAR(artStartDate) = YEAR(CURDATE())) THEN 1 END femaleGenderCurrentReportingPeriod, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 40 and 44 and MONTH(artStartDate) = MONTH(CURDATE()) AND YEAR(artStartDate) = YEAR(CURDATE())) THEN 1 END totalGenderCurrentReportingPeriod, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 40 and 44 and gender = 'M' and artStartDate is not NULL) THEN 1 END maleGenderSoFar, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 40 and 44 and gender = 'F' and artStartDate is not NULL) THEN 1 END femaleGenderSoFar, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 40 and 44 and artStartDate is not NULL) THEN 1 END totalGenderSoFar FROM person LEFT JOIN (SELECT distinct v.patient_id AS 'visitPatientId', o.value_datetime AS 'artStartDate' FROM obs o JOIN concept_name cn ON (cn.concept_name_type = "FULLY_SPECIFIED" AND cn.voided is false AND cn.name="ANC, ART Start Date" and o.concept_id = cn.concept_id) @@ -331,7 +331,7 @@ FROM ( UNION ALL SELECT - '50+ YRS' as 'Age Group', + '45-49 YRS' as 'Age Group', count(maleGenderPreviousReportingPeriod) as 'Cumulative number of persons ever started on ART at this facility\nat the end of the previous reporting period\n Male', count(femaleGenderPreviousReportingPeriod) as 'Cumulative number of persons ever started on ART at this facility\nat the end of the previous reporting period\n Female', count(totalGenderPreviousReportingPeriod) as 'Cumulative number of persons ever started on ART at this facility\nat the end of the previous reporting period\n Total', @@ -343,15 +343,81 @@ SELECT count(totalGenderSoFar) as 'Cumulative number of persons ever started on ART at this facility\nat end of the current reporting period (Month)\n Total' FROM ( SELECT - CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) >= 50 and gender = 'M' and MONTH(artStartDate) < MONTH(CURDATE())) THEN 1 END maleGenderPreviousReportingPeriod, - CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) >= 50 and gender = 'F' and MONTH(artStartDate) < MONTH(CURDATE())) THEN 1 END femaleGenderPreviousReportingPeriod, - CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) >= 50 and MONTH(artStartDate) < MONTH(CURDATE())) THEN 1 END totalGenderPreviousReportingPeriod, - CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) >= 50 and gender = 'M' and MONTH(artStartDate) = MONTH(CURDATE()) AND YEAR(artStartDate) = YEAR(CURDATE())) THEN 1 END maleGenderCurrentReportingPeriod, - CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) >= 50 and gender = 'F' and MONTH(artStartDate) = MONTH(CURDATE()) AND YEAR(artStartDate) = YEAR(CURDATE())) THEN 1 END femaleGenderCurrentReportingPeriod, - CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) >= 50 and MONTH(artStartDate) = MONTH(CURDATE()) AND YEAR(artStartDate) = YEAR(CURDATE())) THEN 1 END totalGenderCurrentReportingPeriod, - CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) >= 50 and gender = 'M' and artStartDate is not NULL) THEN 1 END maleGenderSoFar, - CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) >= 50 and gender = 'F' and artStartDate is not NULL) THEN 1 END femaleGenderSoFar, - CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) >= 50 and artStartDate is not NULL) THEN 1 END totalGenderSoFar + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 45 and 49 and gender = 'M' and MONTH(artStartDate) < MONTH(CURDATE())) THEN 1 END maleGenderPreviousReportingPeriod, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 45 and 49 and gender = 'F' and MONTH(artStartDate) < MONTH(CURDATE())) THEN 1 END femaleGenderPreviousReportingPeriod, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 45 and 49 and MONTH(artStartDate) < MONTH(CURDATE())) THEN 1 END totalGenderPreviousReportingPeriod, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 45 and 49 and gender = 'M' and MONTH(artStartDate) = MONTH(CURDATE()) AND YEAR(artStartDate) = YEAR(CURDATE())) THEN 1 END maleGenderCurrentReportingPeriod, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 45 and 49 and gender = 'F' and MONTH(artStartDate) = MONTH(CURDATE()) AND YEAR(artStartDate) = YEAR(CURDATE())) THEN 1 END femaleGenderCurrentReportingPeriod, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 45 and 49 and MONTH(artStartDate) = MONTH(CURDATE()) AND YEAR(artStartDate) = YEAR(CURDATE())) THEN 1 END totalGenderCurrentReportingPeriod, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 45 and 49 and gender = 'M' and artStartDate is not NULL) THEN 1 END maleGenderSoFar, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 45 and 49 and gender = 'F' and artStartDate is not NULL) THEN 1 END femaleGenderSoFar, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 45 and 49 and artStartDate is not NULL) THEN 1 END totalGenderSoFar + FROM person + LEFT JOIN (SELECT distinct v.patient_id AS 'visitPatientId', o.value_datetime AS 'artStartDate' FROM obs o + JOIN concept_name cn ON (cn.concept_name_type = "FULLY_SPECIFIED" AND cn.voided is false AND cn.name="ANC, ART Start Date" and o.concept_id = cn.concept_id) + JOIN encounter enc ON enc.encounter_id = o.encounter_id + JOIN visit v ON v.visit_id = enc.visit_id + GROUP BY v.patient_id + ORDER BY v.visit_id DESC) AS asd ON (asd.visitPatientId = person_id) +) p + +UNION ALL + +SELECT + '50-54 YRS' as 'Age Group', + count(maleGenderPreviousReportingPeriod) as 'Cumulative number of persons ever started on ART at this facility\nat the end of the previous reporting period\n Male', + count(femaleGenderPreviousReportingPeriod) as 'Cumulative number of persons ever started on ART at this facility\nat the end of the previous reporting period\n Female', + count(totalGenderPreviousReportingPeriod) as 'Cumulative number of persons ever started on ART at this facility\nat the end of the previous reporting period\n Total', + count(maleGenderCurrentReportingPeriod) as 'New persons started on ART at this facility\nduring the reporting period (Month)\n Male', + count(femaleGenderCurrentReportingPeriod) as 'New persons started on ART at this facility\nduring the reporting period (Month)\n Female', + count(totalGenderCurrentReportingPeriod) as 'New persons started on ART at this facility\nduring the reporting period (Month)\n Total', + count(maleGenderSoFar) as 'Cumulative number of persons ever started on ART at this facility\nat end of the current reporting period (Month)\n Male', + count(femaleGenderSoFar) as 'Cumulative number of persons ever started on ART at this facility\nat end of the current reporting period (Month)\n Female', + count(totalGenderSoFar) as 'Cumulative number of persons ever started on ART at this facility\nat end of the current reporting period (Month)\n Total' +FROM ( + SELECT + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 50 and 54 and gender = 'M' and MONTH(artStartDate) < MONTH(CURDATE())) THEN 1 END maleGenderPreviousReportingPeriod, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 50 and 54 and gender = 'F' and MONTH(artStartDate) < MONTH(CURDATE())) THEN 1 END femaleGenderPreviousReportingPeriod, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 50 and 54 and MONTH(artStartDate) < MONTH(CURDATE())) THEN 1 END totalGenderPreviousReportingPeriod, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 50 and 54 and gender = 'M' and MONTH(artStartDate) = MONTH(CURDATE()) AND YEAR(artStartDate) = YEAR(CURDATE())) THEN 1 END maleGenderCurrentReportingPeriod, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 50 and 54 and gender = 'F' and MONTH(artStartDate) = MONTH(CURDATE()) AND YEAR(artStartDate) = YEAR(CURDATE())) THEN 1 END femaleGenderCurrentReportingPeriod, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 50 and 54 and MONTH(artStartDate) = MONTH(CURDATE()) AND YEAR(artStartDate) = YEAR(CURDATE())) THEN 1 END totalGenderCurrentReportingPeriod, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 50 and 54 and gender = 'M' and artStartDate is not NULL) THEN 1 END maleGenderSoFar, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 50 and 54 and gender = 'F' and artStartDate is not NULL) THEN 1 END femaleGenderSoFar, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 50 and 54 and artStartDate is not NULL) THEN 1 END totalGenderSoFar + FROM person + LEFT JOIN (SELECT distinct v.patient_id AS 'visitPatientId', o.value_datetime AS 'artStartDate' FROM obs o + JOIN concept_name cn ON (cn.concept_name_type = "FULLY_SPECIFIED" AND cn.voided is false AND cn.name="ANC, ART Start Date" and o.concept_id = cn.concept_id) + JOIN encounter enc ON enc.encounter_id = o.encounter_id + JOIN visit v ON v.visit_id = enc.visit_id + GROUP BY v.patient_id + ORDER BY v.visit_id DESC) AS asd ON (asd.visitPatientId = person_id) +) p + +UNION ALL + +SELECT + '55+ YRS' as 'Age Group', + count(maleGenderPreviousReportingPeriod) as 'Cumulative number of persons ever started on ART at this facility\nat the end of the previous reporting period\n Male', + count(femaleGenderPreviousReportingPeriod) as 'Cumulative number of persons ever started on ART at this facility\nat the end of the previous reporting period\n Female', + count(totalGenderPreviousReportingPeriod) as 'Cumulative number of persons ever started on ART at this facility\nat the end of the previous reporting period\n Total', + count(maleGenderCurrentReportingPeriod) as 'New persons started on ART at this facility\nduring the reporting period (Month)\n Male', + count(femaleGenderCurrentReportingPeriod) as 'New persons started on ART at this facility\nduring the reporting period (Month)\n Female', + count(totalGenderCurrentReportingPeriod) as 'New persons started on ART at this facility\nduring the reporting period (Month)\n Total', + count(maleGenderSoFar) as 'Cumulative number of persons ever started on ART at this facility\nat end of the current reporting period (Month)\n Male', + count(femaleGenderSoFar) as 'Cumulative number of persons ever started on ART at this facility\nat end of the current reporting period (Month)\n Female', + count(totalGenderSoFar) as 'Cumulative number of persons ever started on ART at this facility\nat end of the current reporting period (Month)\n Total' +FROM ( + SELECT + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) >= 55 and gender = 'M' and MONTH(artStartDate) < MONTH(CURDATE())) THEN 1 END maleGenderPreviousReportingPeriod, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) >= 55 and gender = 'F' and MONTH(artStartDate) < MONTH(CURDATE())) THEN 1 END femaleGenderPreviousReportingPeriod, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) >= 55 and MONTH(artStartDate) < MONTH(CURDATE())) THEN 1 END totalGenderPreviousReportingPeriod, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) >= 55 and gender = 'M' and MONTH(artStartDate) = MONTH(CURDATE()) AND YEAR(artStartDate) = YEAR(CURDATE())) THEN 1 END maleGenderCurrentReportingPeriod, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) >= 55 and gender = 'F' and MONTH(artStartDate) = MONTH(CURDATE()) AND YEAR(artStartDate) = YEAR(CURDATE())) THEN 1 END femaleGenderCurrentReportingPeriod, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) >= 55 and MONTH(artStartDate) = MONTH(CURDATE()) AND YEAR(artStartDate) = YEAR(CURDATE())) THEN 1 END totalGenderCurrentReportingPeriod, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) >= 55 and gender = 'M' and artStartDate is not NULL) THEN 1 END maleGenderSoFar, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) >= 55 and gender = 'F' and artStartDate is not NULL) THEN 1 END femaleGenderSoFar, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) >= 55 and artStartDate is not NULL) THEN 1 END totalGenderSoFar FROM person LEFT JOIN (SELECT distinct v.patient_id AS 'visitPatientId', o.value_datetime AS 'artStartDate' FROM obs o JOIN concept_name cn ON (cn.concept_name_type = "FULLY_SPECIFIED" AND cn.voided is false AND cn.name="ANC, ART Start Date" and o.concept_id = cn.concept_id) diff --git a/openmrs/apps/reports/sql/artMonthlyViralLoadReport.sql b/openmrs/apps/reports/sql/artMonthlyViralLoadReport.sql index 02381a13b..8d8b1dd84 100644 --- a/openmrs/apps/reports/sql/artMonthlyViralLoadReport.sql +++ b/openmrs/apps/reports/sql/artMonthlyViralLoadReport.sql @@ -325,7 +325,7 @@ FROM ( UNION ALL SELECT - '40-49 YRS' as 'Age Group', + '40-44 YRS' as 'Age Group', count(maleGenderSampleCollected) as 'Sample Collected\n Male', count(femaleGenderSampleCollected) as 'Sample Collected\n Female', count(maleGenderResultCollected999) as 'Results Received\n <1000 copies/ml \n Male', @@ -336,14 +336,14 @@ SELECT count(femaleGenderResultCollected11000) as 'Clients with high VL\n (≥11000copies/ml) Traced \n Female' FROM ( SELECT - CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 40 and 49 and gender = 'M' and MONTH(viralSampleDate) < MONTH(CURDATE()) AND YEAR(viralSampleDate) = YEAR(CURDATE())) THEN 1 END maleGenderSampleCollected, - CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 40 and 49 and gender = 'F' and MONTH(viralSampleDate) < MONTH(CURDATE()) AND YEAR(viralSampleDate) = YEAR(CURDATE())) THEN 1 END femaleGenderSampleCollected, - CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 40 and 49 and gender = 'M' and MONTH(vlResultDate) < MONTH(CURDATE()) AND YEAR(vlResultDate) = YEAR(CURDATE()) and vlResult < 1000) THEN 1 END maleGenderResultCollected999, - CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 40 and 49 and gender = 'F' and MONTH(vlResultDate) < MONTH(CURDATE()) AND YEAR(vlResultDate) = YEAR(CURDATE()) and vlResult < 1000) THEN 1 END femaleGenderResultCollected999, - CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 40 and 49 and gender = 'M' and MONTH(vlResultDate) < MONTH(CURDATE()) AND YEAR(vlResultDate) = YEAR(CURDATE()) and vlResult >= 1000) THEN 1 END maleGenderResultCollected1000, - CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 40 and 49 and gender = 'F' and MONTH(vlResultDate) < MONTH(CURDATE()) AND YEAR(vlResultDate) = YEAR(CURDATE()) and vlResult >= 1000) THEN 1 END femaleGenderResultCollected1000, - CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 40 and 49 and gender = 'M' and MONTH(vlResultDate) < MONTH(CURDATE()) AND YEAR(vlResultDate) = YEAR(CURDATE()) and vlResult >= 11000) THEN 1 END maleGenderResultCollected11000, - CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 40 and 49 and gender = 'F' and MONTH(vlResultDate) < MONTH(CURDATE()) AND YEAR(vlResultDate) = YEAR(CURDATE()) and vlResult >= 11000) THEN 1 END femaleGenderResultCollected11000 + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 40 and 44 and gender = 'M' and MONTH(viralSampleDate) < MONTH(CURDATE()) AND YEAR(viralSampleDate) = YEAR(CURDATE())) THEN 1 END maleGenderSampleCollected, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 40 and 44 and gender = 'F' and MONTH(viralSampleDate) < MONTH(CURDATE()) AND YEAR(viralSampleDate) = YEAR(CURDATE())) THEN 1 END femaleGenderSampleCollected, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 40 and 44 and gender = 'M' and MONTH(vlResultDate) < MONTH(CURDATE()) AND YEAR(vlResultDate) = YEAR(CURDATE()) and vlResult < 1000) THEN 1 END maleGenderResultCollected999, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 40 and 44 and gender = 'F' and MONTH(vlResultDate) < MONTH(CURDATE()) AND YEAR(vlResultDate) = YEAR(CURDATE()) and vlResult < 1000) THEN 1 END femaleGenderResultCollected999, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 40 and 44 and gender = 'M' and MONTH(vlResultDate) < MONTH(CURDATE()) AND YEAR(vlResultDate) = YEAR(CURDATE()) and vlResult >= 1000) THEN 1 END maleGenderResultCollected1000, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 40 and 44 and gender = 'F' and MONTH(vlResultDate) < MONTH(CURDATE()) AND YEAR(vlResultDate) = YEAR(CURDATE()) and vlResult >= 1000) THEN 1 END femaleGenderResultCollected1000, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 40 and 44 and gender = 'M' and MONTH(vlResultDate) < MONTH(CURDATE()) AND YEAR(vlResultDate) = YEAR(CURDATE()) and vlResult >= 11000) THEN 1 END maleGenderResultCollected11000, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 40 and 44 and gender = 'F' and MONTH(vlResultDate) < MONTH(CURDATE()) AND YEAR(vlResultDate) = YEAR(CURDATE()) and vlResult >= 11000) THEN 1 END femaleGenderResultCollected11000 FROM person LEFT JOIN (SELECT distinct v.patient_id AS 'visitPatientId', o.value_datetime AS 'viralSampleDate' FROM obs o JOIN concept_name cn ON (cn.concept_name_type = "FULLY_SPECIFIED" AND cn.voided is false AND cn.name="Date VL Sample Collected?" and o.concept_id = cn.concept_id) @@ -361,7 +361,7 @@ FROM ( UNION ALL SELECT - '50+ YRS' as 'Age Group', + '45-49 YRS' as 'Age Group', count(maleGenderSampleCollected) as 'Sample Collected\n Male', count(femaleGenderSampleCollected) as 'Sample Collected\n Female', count(maleGenderResultCollected999) as 'Results Received\n <1000 copies/ml \n Male', @@ -372,14 +372,86 @@ SELECT count(femaleGenderResultCollected11000) as 'Clients with high VL\n (≥11000copies/ml) Traced \n Female' FROM ( SELECT - CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) >= 50 and gender = 'M' and MONTH(viralSampleDate) < MONTH(CURDATE()) AND YEAR(viralSampleDate) = YEAR(CURDATE())) THEN 1 END maleGenderSampleCollected, - CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) >= 50 and gender = 'F' and MONTH(viralSampleDate) < MONTH(CURDATE()) AND YEAR(viralSampleDate) = YEAR(CURDATE())) THEN 1 END femaleGenderSampleCollected, - CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) >= 50 and gender = 'M' and MONTH(vlResultDate) < MONTH(CURDATE()) AND YEAR(vlResultDate) = YEAR(CURDATE()) and vlResult < 1000) THEN 1 END maleGenderResultCollected999, - CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) >= 50 and gender = 'F' and MONTH(vlResultDate) < MONTH(CURDATE()) AND YEAR(vlResultDate) = YEAR(CURDATE()) and vlResult < 1000) THEN 1 END femaleGenderResultCollected999, - CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) >= 50 and gender = 'M' and MONTH(vlResultDate) < MONTH(CURDATE()) AND YEAR(vlResultDate) = YEAR(CURDATE()) and vlResult >= 1000) THEN 1 END maleGenderResultCollected1000, - CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) >= 50 and gender = 'F' and MONTH(vlResultDate) < MONTH(CURDATE()) AND YEAR(vlResultDate) = YEAR(CURDATE()) and vlResult >= 1000) THEN 1 END femaleGenderResultCollected1000, - CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) >= 50 and gender = 'M' and MONTH(vlResultDate) < MONTH(CURDATE()) AND YEAR(vlResultDate) = YEAR(CURDATE()) and vlResult >= 11000) THEN 1 END maleGenderResultCollected11000, - CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) >= 50 and gender = 'F' and MONTH(vlResultDate) < MONTH(CURDATE()) AND YEAR(vlResultDate) = YEAR(CURDATE()) and vlResult >= 11000) THEN 1 END femaleGenderResultCollected11000 + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 45 and 49 and gender = 'M' and MONTH(viralSampleDate) < MONTH(CURDATE()) AND YEAR(viralSampleDate) = YEAR(CURDATE())) THEN 1 END maleGenderSampleCollected, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 45 and 49 and gender = 'F' and MONTH(viralSampleDate) < MONTH(CURDATE()) AND YEAR(viralSampleDate) = YEAR(CURDATE())) THEN 1 END femaleGenderSampleCollected, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 45 and 49 and gender = 'M' and MONTH(vlResultDate) < MONTH(CURDATE()) AND YEAR(vlResultDate) = YEAR(CURDATE()) and vlResult < 1000) THEN 1 END maleGenderResultCollected999, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 45 and 49 and gender = 'F' and MONTH(vlResultDate) < MONTH(CURDATE()) AND YEAR(vlResultDate) = YEAR(CURDATE()) and vlResult < 1000) THEN 1 END femaleGenderResultCollected999, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 45 and 49 and gender = 'M' and MONTH(vlResultDate) < MONTH(CURDATE()) AND YEAR(vlResultDate) = YEAR(CURDATE()) and vlResult >= 1000) THEN 1 END maleGenderResultCollected1000, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 45 and 49 and gender = 'F' and MONTH(vlResultDate) < MONTH(CURDATE()) AND YEAR(vlResultDate) = YEAR(CURDATE()) and vlResult >= 1000) THEN 1 END femaleGenderResultCollected1000, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 45 and 49 and gender = 'M' and MONTH(vlResultDate) < MONTH(CURDATE()) AND YEAR(vlResultDate) = YEAR(CURDATE()) and vlResult >= 11000) THEN 1 END maleGenderResultCollected11000, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 45 and 49 and gender = 'F' and MONTH(vlResultDate) < MONTH(CURDATE()) AND YEAR(vlResultDate) = YEAR(CURDATE()) and vlResult >= 11000) THEN 1 END femaleGenderResultCollected11000 + FROM person + LEFT JOIN (SELECT distinct v.patient_id AS 'visitPatientId', o.value_datetime AS 'viralSampleDate' FROM obs o + JOIN concept_name cn ON (cn.concept_name_type = "FULLY_SPECIFIED" AND cn.voided is false AND cn.name="Date VL Sample Collected?" and o.concept_id = cn.concept_id) + JOIN encounter enc ON enc.encounter_id = o.encounter_id + JOIN visit v ON v.visit_id = enc.visit_id + GROUP BY v.patient_id + ORDER BY v.visit_id DESC) AS vl ON (vl.visitPatientId = person_id) + LEFT JOIN (SELECT distinct v.patient_id AS 'visitPatientId', o.obs_datetime AS 'vlResultDate', o.value_numeric AS 'vlResult' FROM obs o JOIN concept_name cn ON (cn.concept_name_type = "FULLY_SPECIFIED" AND cn.voided is false AND cn.name="VL Results" and o.concept_id = cn.concept_id) + JOIN encounter enc ON enc.encounter_id = o.encounter_id + JOIN visit v ON v.visit_id = enc.visit_id + GROUP BY v.patient_id + ORDER BY v.visit_id DESC) AS vr ON (vr.visitPatientId = person_id) +) p + +UNION ALL + +SELECT + '50-54 YRS' as 'Age Group', + count(maleGenderSampleCollected) as 'Sample Collected\n Male', + count(femaleGenderSampleCollected) as 'Sample Collected\n Female', + count(maleGenderResultCollected999) as 'Results Received\n <1000 copies/ml \n Male', + count(femaleGenderResultCollected999) as 'Results Received\n <1000 copies/ml \n Female', + count(maleGenderResultCollected1000) as 'Results Received\n >=1000 copies/ml \n Male', + count(femaleGenderResultCollected1000) as 'Results Received\n >=1000 copies/ml \n Female', + count(maleGenderResultCollected11000) as 'Clients with high VL\n (≥11000copies/ml) Traced \n Male', + count(femaleGenderResultCollected11000) as 'Clients with high VL\n (≥11000copies/ml) Traced \n Female' +FROM ( + SELECT + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 50 and 54 and gender = 'M' and MONTH(viralSampleDate) < MONTH(CURDATE()) AND YEAR(viralSampleDate) = YEAR(CURDATE())) THEN 1 END maleGenderSampleCollected, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 50 and 54 and gender = 'F' and MONTH(viralSampleDate) < MONTH(CURDATE()) AND YEAR(viralSampleDate) = YEAR(CURDATE())) THEN 1 END femaleGenderSampleCollected, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 50 and 54 and gender = 'M' and MONTH(vlResultDate) < MONTH(CURDATE()) AND YEAR(vlResultDate) = YEAR(CURDATE()) and vlResult < 1000) THEN 1 END maleGenderResultCollected999, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 50 and 54 and gender = 'F' and MONTH(vlResultDate) < MONTH(CURDATE()) AND YEAR(vlResultDate) = YEAR(CURDATE()) and vlResult < 1000) THEN 1 END femaleGenderResultCollected999, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 50 and 54 and gender = 'M' and MONTH(vlResultDate) < MONTH(CURDATE()) AND YEAR(vlResultDate) = YEAR(CURDATE()) and vlResult >= 1000) THEN 1 END maleGenderResultCollected1000, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 50 and 54 and gender = 'F' and MONTH(vlResultDate) < MONTH(CURDATE()) AND YEAR(vlResultDate) = YEAR(CURDATE()) and vlResult >= 1000) THEN 1 END femaleGenderResultCollected1000, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 50 and 54 and gender = 'M' and MONTH(vlResultDate) < MONTH(CURDATE()) AND YEAR(vlResultDate) = YEAR(CURDATE()) and vlResult >= 11000) THEN 1 END maleGenderResultCollected11000, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) between 50 and 54 and gender = 'F' and MONTH(vlResultDate) < MONTH(CURDATE()) AND YEAR(vlResultDate) = YEAR(CURDATE()) and vlResult >= 11000) THEN 1 END femaleGenderResultCollected11000 + FROM person + LEFT JOIN (SELECT distinct v.patient_id AS 'visitPatientId', o.value_datetime AS 'viralSampleDate' FROM obs o + JOIN concept_name cn ON (cn.concept_name_type = "FULLY_SPECIFIED" AND cn.voided is false AND cn.name="Date VL Sample Collected?" and o.concept_id = cn.concept_id) + JOIN encounter enc ON enc.encounter_id = o.encounter_id + JOIN visit v ON v.visit_id = enc.visit_id + GROUP BY v.patient_id + ORDER BY v.visit_id DESC) AS vl ON (vl.visitPatientId = person_id) + LEFT JOIN (SELECT distinct v.patient_id AS 'visitPatientId', o.obs_datetime AS 'vlResultDate', o.value_numeric AS 'vlResult' FROM obs o JOIN concept_name cn ON (cn.concept_name_type = "FULLY_SPECIFIED" AND cn.voided is false AND cn.name="VL Results" and o.concept_id = cn.concept_id) + JOIN encounter enc ON enc.encounter_id = o.encounter_id + JOIN visit v ON v.visit_id = enc.visit_id + GROUP BY v.patient_id + ORDER BY v.visit_id DESC) AS vr ON (vr.visitPatientId = person_id) +) p + +UNION ALL + +SELECT + '55+ YRS' as 'Age Group', + count(maleGenderSampleCollected) as 'Sample Collected\n Male', + count(femaleGenderSampleCollected) as 'Sample Collected\n Female', + count(maleGenderResultCollected999) as 'Results Received\n <1000 copies/ml \n Male', + count(femaleGenderResultCollected999) as 'Results Received\n <1000 copies/ml \n Female', + count(maleGenderResultCollected1000) as 'Results Received\n >=1000 copies/ml \n Male', + count(femaleGenderResultCollected1000) as 'Results Received\n >=1000 copies/ml \n Female', + count(maleGenderResultCollected11000) as 'Clients with high VL\n (≥11000copies/ml) Traced \n Male', + count(femaleGenderResultCollected11000) as 'Clients with high VL\n (≥11000copies/ml) Traced \n Female' +FROM ( + SELECT + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) >= 55 and gender = 'M' and MONTH(viralSampleDate) < MONTH(CURDATE()) AND YEAR(viralSampleDate) = YEAR(CURDATE())) THEN 1 END maleGenderSampleCollected, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) >= 55 and gender = 'F' and MONTH(viralSampleDate) < MONTH(CURDATE()) AND YEAR(viralSampleDate) = YEAR(CURDATE())) THEN 1 END femaleGenderSampleCollected, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) >= 55 and gender = 'M' and MONTH(vlResultDate) < MONTH(CURDATE()) AND YEAR(vlResultDate) = YEAR(CURDATE()) and vlResult < 1000) THEN 1 END maleGenderResultCollected999, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) >= 55 and gender = 'F' and MONTH(vlResultDate) < MONTH(CURDATE()) AND YEAR(vlResultDate) = YEAR(CURDATE()) and vlResult < 1000) THEN 1 END femaleGenderResultCollected999, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) >= 55 and gender = 'M' and MONTH(vlResultDate) < MONTH(CURDATE()) AND YEAR(vlResultDate) = YEAR(CURDATE()) and vlResult >= 1000) THEN 1 END maleGenderResultCollected1000, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) >= 55 and gender = 'F' and MONTH(vlResultDate) < MONTH(CURDATE()) AND YEAR(vlResultDate) = YEAR(CURDATE()) and vlResult >= 1000) THEN 1 END femaleGenderResultCollected1000, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) >= 55 and gender = 'M' and MONTH(vlResultDate) < MONTH(CURDATE()) AND YEAR(vlResultDate) = YEAR(CURDATE()) and vlResult >= 11000) THEN 1 END maleGenderResultCollected11000, + CASE WHEN (TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) >= 55 and gender = 'F' and MONTH(vlResultDate) < MONTH(CURDATE()) AND YEAR(vlResultDate) = YEAR(CURDATE()) and vlResult >= 11000) THEN 1 END femaleGenderResultCollected11000 FROM person LEFT JOIN (SELECT distinct v.patient_id AS 'visitPatientId', o.value_datetime AS 'viralSampleDate' FROM obs o JOIN concept_name cn ON (cn.concept_name_type = "FULLY_SPECIFIED" AND cn.voided is false AND cn.name="Date VL Sample Collected?" and o.concept_id = cn.concept_id)