diff --git a/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/PmtctEidCohortQueries.java b/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/PmtctEidCohortQueries.java index 0202323733..3d5ace632e 100644 --- a/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/PmtctEidCohortQueries.java +++ b/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/PmtctEidCohortQueries.java @@ -259,29 +259,52 @@ public CohortDefinition getPatientsWhoUnderwentFirstOrSecondSampleCollectionForV map.put("165510", hivMetadata.getFollowingtSampleBetween9To17MonthsConcept().getConceptId()); String query = - "SELECT patient_id FROM ( " - + " SELECT p.patient_id, " - + " Min(o.value_datetime) AS collection_date " - + "FROM patient p " - + " INNER JOIN encounter e ON p.patient_id = e.patient_id " - + " INNER JOIN obs o ON o.encounter_id = e.encounter_id " - + " INNER JOIN obs o2 ON o2.encounter_id = e.encounter_id " - + "WHERE p.voided = 0 " - + " AND e.voided = 0 " - + " AND o.voided = 0 " - + " AND o2.voided = 0 " - + " AND e.location_id = :location " - + " AND e.encounter_type = ${13} " - + " AND ( (o.concept_id = ${23821} " - + " AND o.value_datetime >= :startDate " - + " AND o.value_datetime <= :endDate ) " - + " AND (o2.concept_id = ${165502} "; + "SELECT " + + " hiv_sample.patient_id " + + "FROM " + + " ( " + + " SELECT " + + " p.patient_id, " + + " Min(o.value_datetime) AS collection_date " + + " FROM patient p " + + " INNER JOIN encounter e ON p.patient_id = e.patient_id " + + " INNER JOIN obs o ON o.encounter_id = e.encounter_id " + + " INNER JOIN obs o2 ON o2.encounter_id = e.encounter_id " + + " WHERE p.voided = 0 " + + " AND e.voided = 0 " + + " AND o.voided = 0 " + + " AND o2.voided = 0 " + + " AND e.location_id = :location " + + " AND e.encounter_type = ${13} " + + " AND ( " + + " ( " + + " o.concept_id = ${23821} " + + " AND o.value_datetime >= :startDate " + + " AND o.value_datetime <= :endDate " + + " ) " + + " AND ( " + + " o2.concept_id = ${165502} " + + " AND o2.value_coded IN (${165503}, ${165506}, ${165507}, ${165510}) " + + " ) " + + " ) " + + " GROUP BY p.patient_id " + + " ) hiv_sample " + + " INNER JOIN encounter ee ON hiv_sample.patient_id = ee.patient_id " + + " INNER JOIN obs oo ON oo.encounter_id = ee.encounter_id " + + " INNER JOIN obs oo2 ON oo2.encounter_id = ee.encounter_id " + + "WHERE ee.voided = 0 " + + " AND oo.voided = 0 " + + " AND oo2.voided = 0 " + + " AND ee.location_id = :location " + + " AND ee.encounter_type = ${13} " + + " AND oo.concept_id = ${23821} " + + " AND oo.value_datetime = hiv_sample.collection_date " + + " AND oo2.concept_id = ${165502} "; if (firstSample) { - query = query + " AND o2.value_coded IN (${165503}, ${165507}) ) ) "; + query = query + " AND oo2.value_coded IN (${165503}, ${165507}) "; } else { - query = query + " AND o2.value_coded IN (${165506}, ${165510}) ) ) "; + query = query + " AND oo2.value_coded IN (${165506}, ${165510}) "; } - query = query + "GROUP BY p.patient_id ) hiv_sample"; StringSubstitutor stringSubstitutor = new StringSubstitutor(map); @@ -316,7 +339,7 @@ public CohortDefinition getPatientsWhoUnderwentFirstOrSecondSampleCollectionForV * @param maxAge Maximum age in Days of a patient based on Specimen Collection Date * @return CohortDefinition */ - public CohortDefinition getInfantAge(Integer minAge, Integer maxAge) { + public CohortDefinition getInfantAge(Integer minAge, Integer maxAge, boolean eidOrHei) { SqlCohortDefinition sqlCohortDefinition = new SqlCohortDefinition(); sqlCohortDefinition.setName("Infant Age"); sqlCohortDefinition.addParameter(new Parameter("startDate", "Start Date", Date.class)); @@ -334,50 +357,43 @@ public CohortDefinition getInfantAge(Integer minAge, Integer maxAge) { map.put("minAge", minAge); map.put("maxAge", maxAge); - String query = - "SELECT " - + " pr.person_id " - + "FROM " - + " person pr " - + " INNER JOIN ( " - + " SELECT " - + " p.patient_id, " - + " Min(o.value_datetime) AS collection_date " - + " FROM " - + " patient p " - + " INNER JOIN encounter e ON p.patient_id = e.patient_id " - + " INNER JOIN obs o ON o.encounter_id = e.encounter_id " - + " INNER JOIN obs o2 ON o2.encounter_id = e.encounter_id " - + " WHERE " - + " p.voided = 0 " - + " AND e.voided = 0 " - + " AND o.voided = 0 " - + " AND o2.voided = 0 " - + " AND e.location_id = :location " - + " AND e.encounter_type = ${13} " - + " AND ( " - + " ( " - + " o.concept_id = ${23821} " - + " AND o.value_datetime >= :startDate " - + " AND o.value_datetime <= :endDate " - + " ) " - + " AND ( " - + " o2.concept_id = ${165502} " - + " AND o2.value_coded IN (${165503}, ${165506}, ${165507}, ${165510}) " - + " ) " - + " ) " - + " GROUP BY " - + " p.patient_id " - + " ) specimen_collection ON pr.person_id = specimen_collection.patient_id " - + "WHERE " - + " pr.birthdate IS NOT NULL " - + " AND specimen_collection.collection_date IS NOT NULL " - + " AND TIMESTAMPDIFF( " - + " DAY, pr.birthdate, specimen_collection.collection_date " - + " ) >= ${minAge} " - + " AND TIMESTAMPDIFF( " - + " DAY, pr.birthdate, specimen_collection.collection_date " - + " ) <= ${maxAge}"; + String query = "SELECT pr.person_id " + "FROM person pr " + "INNER JOIN ( "; + query += + eidOrHei + ? " SELECT p.patient_id, MIN(o.value_datetime) AS collection_date " + : " SELECT p.patient_id, MAX(o.value_datetime) AS collection_date "; + query += + " FROM patient p " + + " INNER JOIN encounter e ON p.patient_id = e.patient_id " + + " INNER JOIN obs o ON o.encounter_id = e.encounter_id " + + " INNER JOIN obs o2 ON o2.encounter_id = e.encounter_id " + + " WHERE p.voided = 0 " + + " AND e.voided = 0 " + + " AND o.voided = 0 " + + " AND o2.voided = 0 " + + " AND e.location_id = :location " + + " AND e.encounter_type = ${13} "; + query += + eidOrHei + ? " AND ( " + + " (o.concept_id = ${23821} " + + " AND o.value_datetime >= :startDate " + + " AND o.value_datetime <= :endDate) " + + " AND (o2.concept_id = ${165502} " + + " AND o2.value_coded IN (${165503}, ${165506}, ${165507}, ${165510})) " + + " ) " + : " AND ( " + + " o.concept_id = ${23821} " + + " AND (o2.concept_id = ${165502} " + + " AND o2.value_coded IN (${165503}, ${165506}, ${165507}, ${165510})) " + + " ) "; + query += + " GROUP BY p.patient_id " + + ") specimen_collection ON pr.person_id = specimen_collection.patient_id " + + "WHERE pr.birthdate IS NOT NULL " + + "AND specimen_collection.collection_date IS NOT NULL " + + "AND TIMESTAMPDIFF(DAY, pr.birthdate, specimen_collection.collection_date) >= ${minAge} " + + "AND TIMESTAMPDIFF(DAY, pr.birthdate, specimen_collection.collection_date) <= ${maxAge}"; StringSubstitutor stringSubstitutor = new StringSubstitutor(map); @@ -422,7 +438,7 @@ public CohortDefinition getPmtctEidNumerator() { EptsReportUtils.map( getPatientsWhoUnderwentASampleCollectionForVirologicHivTest(), mappings)); - cd.addSearch("infantAge", EptsReportUtils.map(getInfantAge(0, 365), mappings)); + cd.addSearch("infantAge", EptsReportUtils.map(getInfantAge(0, 365, true), mappings)); cd.setCompositionString("infantsInCcr AND sampleCollectionHiv AND infantAge"); return cd; diff --git a/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/PmtctHeiCohortQueries.java b/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/PmtctHeiCohortQueries.java index 8d3357b994..117ff2b20c 100644 --- a/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/PmtctHeiCohortQueries.java +++ b/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/PmtctHeiCohortQueries.java @@ -166,7 +166,7 @@ public CohortDefinition getPatientsWhoHaveVirologivHivTestResult() { + " ) " + " GROUP BY " + " p.patient_id " - + " ) virologic_hiv;"; + + " ) virologic_hiv"; StringSubstitutor stringSubstitutor = new StringSubstitutor(map); @@ -264,7 +264,8 @@ public CohortDefinition getPmtctHeiNumerator() { EptsReportUtils.map(getPatientsWhoHaveVirologivHivTestResult(), mappings)); cd.addSearch( - "infantAge", EptsReportUtils.map(pmtctEidCohortQueries.getInfantAge(0, 365), mappings)); + "infantAge", + EptsReportUtils.map(pmtctEidCohortQueries.getInfantAge(0, 365, false), mappings)); cd.setCompositionString("infantsInCcr AND sampleCollectionHiv AND infantAge"); return cd; @@ -299,72 +300,59 @@ public CohortDefinition getPositveOrNegativePcrResult(boolean posiveResult) { String query = "SELECT " - + " p.patient_id " + + " hiv_sample.patient_id " + "FROM " - + " patient p " - + " INNER JOIN encounter e ON p.patient_id = e.patient_id " - + " INNER JOIN obs o ON o.encounter_id = e.encounter_id " - + " INNER JOIN ( " - + " SELECT " - + " p.patient_id, " - + " MAX(o.value_datetime) AS pcr_result_date, " - + " o2.value_coded AS pcr_result " - + " FROM " - + " patient p " - + " INNER JOIN encounter e ON p.patient_id = e.patient_id " - + " INNER JOIN obs o ON o.encounter_id = e.encounter_id " - + " INNER JOIN obs o2 ON o2.encounter_id = e.encounter_id " - + " INNER JOIN obs o3 ON o3.encounter_id = e.encounter_id " - + " INNER JOIN ( " + + " ( " + " SELECT " - + " p.patient_id, " - + " ps.birthdate AS birtday " + + " p.patient_id, " + + " MAX(e.encounter_datetime) AS collection_date " + " FROM " - + " patient p " - + " INNER JOIN person ps ON p.patient_id = ps.person_id " + + " patient p " + + " INNER JOIN encounter e ON p.patient_id = e.patient_id " + + " INNER JOIN obs o ON o.encounter_id = e.encounter_id " + + " INNER JOIN obs o2 ON o2.encounter_id = e.encounter_id " + + " INNER JOIN ( " + + " SELECT " + + " p.patient_id, " + + " ps.birthdate AS birthday " + + " FROM " + + " patient p " + + " INNER JOIN person ps ON p.patient_id = ps.person_id " + + " WHERE " + + " p.voided = 0 " + + " AND ps.voided = 0 " + + " ) pat ON pat.patient_id = p.patient_id " + " WHERE " - + " p.voided = 0 " - + " AND ps.voided = 0 " - + " ) pat ON pat.patient_id = p.patient_id " - + " WHERE " - + " p.voided = 0 " - + " AND e.voided = 0 " - + " AND o.voided = 0 " - + " AND o2.voided = 0 " - + " AND o3.voided = 0 " - + " AND e.encounter_type = ${13} " - + " AND e.encounter_datetime >= :startDate " - + " AND e.encounter_datetime <= :endDate " - + " AND e.location_id = :location " - + " AND ( " - + " ( " - + " o.concept_id = ${23821} " - + " AND o.value_datetime <= DATE_ADD(pat.birtday, INTERVAL 365 DAY) " - + " ) " - + " AND ( " - + " o2.concept_id = ${1030} " - + " AND o2.value_coded IN (${703}, ${664}) " - + " ) " - + " AND ( " - + " o3.concept_id = ${165502} " - + " AND o3.value_coded IN (${165503}, ${165506}, ${165507}, ${165510}) " - + " ) " - + " ) " - + " GROUP BY " - + " p.patient_id " - + " ) virologic_hiv ON virologic_hiv.patient_id = p.patient_id " - + " AND p.voided = 0 " - + " AND e.voided = 0 " - + " AND o.voided = 0 " - + " AND e.encounter_type = ${13} " - + " AND e.encounter_datetime >= :startDate " - + " AND e.encounter_datetime <= :endDate " - + " AND e.location_id = :location " - + " AND o.concept_id = ${1030} "; + + " p.voided = 0 " + + " AND e.voided = 0 " + + " AND o.voided = 0 " + + " AND o2.voided = 0 " + + " AND e.location_id = :location " + + " AND e.encounter_type = ${13} " + + " AND ( " + + " o.concept_id = ${23821} " + + " AND o.value_datetime <= DATE_ADD(pat.birthday, INTERVAL 365 DAY) " + + " ) " + + " AND ( " + + " o2.concept_id = ${165502} " + + " AND o2.value_coded IN (${165503}, ${165506}, ${165507}, ${165510}) " + + " ) " + + " GROUP BY " + + " p.patient_id " + + " ) hiv_sample " + + " INNER JOIN encounter ee ON hiv_sample.patient_id = ee.patient_id " + + " INNER JOIN obs oo ON oo.encounter_id = ee.encounter_id " + + "WHERE " + + " ee.voided = 0 " + + " AND oo.voided = 0 " + + " AND ee.encounter_type = ${13} " + + " AND ee.encounter_datetime = hiv_sample.collection_date " + + " AND ee.location_id = :location " + + " AND oo.concept_id = ${1030} "; if (posiveResult) { - query = query + " AND virologic_hiv.pcr_result = ${703}"; + query = query + " AND oo.value_coded = ${703} "; } else { - query = query + " AND virologic_hiv.pcr_result = ${664}"; + query = query + " AND oo.value_coded = ${664} "; } StringSubstitutor stringSubstitutor = new StringSubstitutor(map); diff --git a/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/datasets/PmtctHeiDataset.java b/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/datasets/PmtctHeiDataset.java index 6d87162542..6437994a41 100644 --- a/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/datasets/PmtctHeiDataset.java +++ b/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/datasets/PmtctHeiDataset.java @@ -33,19 +33,19 @@ public class PmtctHeiDataset extends BaseDataSet { @Autowired private PmtctHeiCohortQueries pmtctHeiCohortQueries; /** - * Construction of the PMTCT - EID dataset + * Construction of the PMTCT - HEI dataset * * @return @{@link DataSetDefinition} */ public DataSetDefinition constructPmtctHeiDataSet() { CohortIndicatorDataSetDefinition dsd = new CohortIndicatorDataSetDefinition(); - dsd.setName("PMTCT-EID Dataset"); + dsd.setName("PMTCT-HEI Dataset"); dsd.addParameters(getParameters()); dsd.addDimension( "infantAgeInMonths", EptsReportUtils.map( - eptsCommonDimension.getInfantAgeInMonths(), + eptsCommonDimension.getHeiInfantAgeInMonths(), "startDate=${startDate},endDate=${endDate},location=${location}")); dsd.addDimension( @@ -68,7 +68,7 @@ public DataSetDefinition constructPmtctHeiDataSet() { "startDate=${startDate},endDate=${endDate},location=${location}")); dsd.addColumn( - "TOTAL", + "HEITOTAL", "The PMTCT_HEI numerator reports the number of HIV-exposed infants, with a virologic HIV test result returned in the reporting period, whose diagnostic sample was collected by 12 months of age.", EptsReportUtils.map( TOTAL, "startDate=${startDate},endDate=${endDate},location=${location}"), diff --git a/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/dimensions/EptsCommonDimension.java b/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/dimensions/EptsCommonDimension.java index d2cbdca0e8..0fd6a8d34d 100644 --- a/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/dimensions/EptsCommonDimension.java +++ b/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/dimensions/EptsCommonDimension.java @@ -1158,13 +1158,34 @@ public CohortDefinitionDimension getInfantAgeInMonths() { dim.addCohortDefinition( "lessThan2Months", EptsReportUtils.map( - pmtctEidCohortQueries.getInfantAge(0, 59), + pmtctEidCohortQueries.getInfantAge(0, 59, true), "startDate=${startDate},endDate=${endDate},location=${location}")); dim.addCohortDefinition( "from2To12Months", EptsReportUtils.map( - pmtctEidCohortQueries.getInfantAge(60, 365), + pmtctEidCohortQueries.getInfantAge(60, 365, true), + "startDate=${startDate},endDate=${endDate},location=${location}")); + return dim; + } + + public CohortDefinitionDimension getHeiInfantAgeInMonths() { + CohortDefinitionDimension dim = new CohortDefinitionDimension(); + dim.setName("Infant Age in Number of Days"); + dim.addParameter(new Parameter("startDate", "startDate", Date.class)); + dim.addParameter(new Parameter("endDate", "endDate", Date.class)); + dim.addParameter(new Parameter("location", "location", Location.class)); + + dim.addCohortDefinition( + "lessThan2Months", + EptsReportUtils.map( + pmtctEidCohortQueries.getInfantAge(0, 59, false), + "startDate=${startDate},endDate=${endDate},location=${location}")); + + dim.addCohortDefinition( + "from2To12Months", + EptsReportUtils.map( + pmtctEidCohortQueries.getInfantAge(60, 365, false), "startDate=${startDate},endDate=${endDate},location=${location}")); return dim; } diff --git a/api/src/main/resources/SESP_MER2.7_TEMP_Quarterly_v1.3.xls b/api/src/main/resources/SESP_MER2.7_TEMP_Quarterly_v1.3.xls index 409ed42bd7..9eb54f4936 100644 Binary files a/api/src/main/resources/SESP_MER2.7_TEMP_Quarterly_v1.3.xls and b/api/src/main/resources/SESP_MER2.7_TEMP_Quarterly_v1.3.xls differ