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

MEPTS - 1577 | PMTCT EID & HEI Differences #1294

Open
wants to merge 5 commits into
base: 2.x_develop
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
Original file line number Diff line number Diff line change
Expand Up @@ -259,29 +259,52 @@
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}) ";

Check warning on line 304 in api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/PmtctEidCohortQueries.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/PmtctEidCohortQueries.java#L304

Added line #L304 was not covered by tests
} else {
query = query + " AND o2.value_coded IN (${165506}, ${165510}) ) ) ";
query = query + " AND oo2.value_coded IN (${165506}, ${165510}) ";

Check warning on line 306 in api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/PmtctEidCohortQueries.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/PmtctEidCohortQueries.java#L306

Added line #L306 was not covered by tests
}
query = query + "GROUP BY p.patient_id ) hiv_sample";

StringSubstitutor stringSubstitutor = new StringSubstitutor(map);

Expand Down Expand Up @@ -316,7 +339,7 @@
* @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));
Expand All @@ -334,50 +357,43 @@
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 ( ";

Check warning on line 360 in api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/PmtctEidCohortQueries.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/PmtctEidCohortQueries.java#L360

Added line #L360 was not covered by tests
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 +=

Check warning on line 365 in api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/PmtctEidCohortQueries.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/PmtctEidCohortQueries.java#L365

Added line #L365 was not covered by tests
" 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 +=

Check warning on line 390 in api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/PmtctEidCohortQueries.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/PmtctEidCohortQueries.java#L390

Added line #L390 was not covered by tests
" 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);

Expand Down Expand Up @@ -422,7 +438,7 @@
EptsReportUtils.map(
getPatientsWhoUnderwentASampleCollectionForVirologicHivTest(), mappings));

cd.addSearch("infantAge", EptsReportUtils.map(getInfantAge(0, 365), mappings));
cd.addSearch("infantAge", EptsReportUtils.map(getInfantAge(0, 365, true), mappings));

Check warning on line 441 in api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/PmtctEidCohortQueries.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/PmtctEidCohortQueries.java#L441

Added line #L441 was not covered by tests

cd.setCompositionString("infantsInCcr AND sampleCollectionHiv AND infantAge");
return cd;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
+ " ) "
+ " GROUP BY "
+ " p.patient_id "
+ " ) virologic_hiv;";
+ " ) virologic_hiv";

StringSubstitutor stringSubstitutor = new StringSubstitutor(map);

Expand Down Expand Up @@ -264,7 +264,8 @@
EptsReportUtils.map(getPatientsWhoHaveVirologivHivTestResult(), mappings));

cd.addSearch(
"infantAge", EptsReportUtils.map(pmtctEidCohortQueries.getInfantAge(0, 365), mappings));
"infantAge",
EptsReportUtils.map(pmtctEidCohortQueries.getInfantAge(0, 365, false), mappings));

Check warning on line 268 in api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/PmtctHeiCohortQueries.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/PmtctHeiCohortQueries.java#L268

Added line #L268 was not covered by tests

cd.setCompositionString("infantsInCcr AND sampleCollectionHiv AND infantAge");
return cd;
Expand Down Expand Up @@ -299,72 +300,59 @@

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} ";

Check warning on line 353 in api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/PmtctHeiCohortQueries.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/PmtctHeiCohortQueries.java#L353

Added line #L353 was not covered by tests
} else {
query = query + " AND virologic_hiv.pcr_result = ${664}";
query = query + " AND oo.value_coded = ${664} ";

Check warning on line 355 in api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/PmtctHeiCohortQueries.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/PmtctHeiCohortQueries.java#L355

Added line #L355 was not covered by tests
}

StringSubstitutor stringSubstitutor = new StringSubstitutor(map);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@
@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");

Check warning on line 42 in api/src/main/java/org/openmrs/module/eptsreports/reporting/library/datasets/PmtctHeiDataset.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/openmrs/module/eptsreports/reporting/library/datasets/PmtctHeiDataset.java#L42

Added line #L42 was not covered by tests
dsd.addParameters(getParameters());

dsd.addDimension(
"infantAgeInMonths",
EptsReportUtils.map(
eptsCommonDimension.getInfantAgeInMonths(),
eptsCommonDimension.getHeiInfantAgeInMonths(),

Check warning on line 48 in api/src/main/java/org/openmrs/module/eptsreports/reporting/library/datasets/PmtctHeiDataset.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/openmrs/module/eptsreports/reporting/library/datasets/PmtctHeiDataset.java#L48

Added line #L48 was not covered by tests
"startDate=${startDate},endDate=${endDate},location=${location}"));

dsd.addDimension(
Expand All @@ -68,7 +68,7 @@
"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}"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1158,13 +1158,34 @@
dim.addCohortDefinition(
"lessThan2Months",
EptsReportUtils.map(
pmtctEidCohortQueries.getInfantAge(0, 59),
pmtctEidCohortQueries.getInfantAge(0, 59, true),

Check warning on line 1161 in api/src/main/java/org/openmrs/module/eptsreports/reporting/library/dimensions/EptsCommonDimension.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/openmrs/module/eptsreports/reporting/library/dimensions/EptsCommonDimension.java#L1161

Added line #L1161 was not covered by tests
"startDate=${startDate},endDate=${endDate},location=${location}"));

dim.addCohortDefinition(
"from2To12Months",
EptsReportUtils.map(
pmtctEidCohortQueries.getInfantAge(60, 365),
pmtctEidCohortQueries.getInfantAge(60, 365, true),

Check warning on line 1167 in api/src/main/java/org/openmrs/module/eptsreports/reporting/library/dimensions/EptsCommonDimension.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/openmrs/module/eptsreports/reporting/library/dimensions/EptsCommonDimension.java#L1167

Added line #L1167 was not covered by tests
"startDate=${startDate},endDate=${endDate},location=${location}"));
return dim;

Check warning on line 1169 in api/src/main/java/org/openmrs/module/eptsreports/reporting/library/dimensions/EptsCommonDimension.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/openmrs/module/eptsreports/reporting/library/dimensions/EptsCommonDimension.java#L1169

Added line #L1169 was not covered by tests
}

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));

Check warning on line 1177 in api/src/main/java/org/openmrs/module/eptsreports/reporting/library/dimensions/EptsCommonDimension.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/openmrs/module/eptsreports/reporting/library/dimensions/EptsCommonDimension.java#L1173-L1177

Added lines #L1173 - L1177 were not covered by tests

dim.addCohortDefinition(

Check warning on line 1179 in api/src/main/java/org/openmrs/module/eptsreports/reporting/library/dimensions/EptsCommonDimension.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/openmrs/module/eptsreports/reporting/library/dimensions/EptsCommonDimension.java#L1179

Added line #L1179 was not covered by tests
"lessThan2Months",
EptsReportUtils.map(
pmtctEidCohortQueries.getInfantAge(0, 59, false),

Check warning on line 1182 in api/src/main/java/org/openmrs/module/eptsreports/reporting/library/dimensions/EptsCommonDimension.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/openmrs/module/eptsreports/reporting/library/dimensions/EptsCommonDimension.java#L1181-L1182

Added lines #L1181 - L1182 were not covered by tests
"startDate=${startDate},endDate=${endDate},location=${location}"));

dim.addCohortDefinition(

Check warning on line 1185 in api/src/main/java/org/openmrs/module/eptsreports/reporting/library/dimensions/EptsCommonDimension.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/openmrs/module/eptsreports/reporting/library/dimensions/EptsCommonDimension.java#L1185

Added line #L1185 was not covered by tests
"from2To12Months",
EptsReportUtils.map(
pmtctEidCohortQueries.getInfantAge(60, 365, false),

Check warning on line 1188 in api/src/main/java/org/openmrs/module/eptsreports/reporting/library/dimensions/EptsCommonDimension.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/openmrs/module/eptsreports/reporting/library/dimensions/EptsCommonDimension.java#L1187-L1188

Added lines #L1187 - L1188 were not covered by tests
"startDate=${startDate},endDate=${endDate},location=${location}"));
return dim;
}
Expand Down
Binary file modified api/src/main/resources/SESP_MER2.7_TEMP_Quarterly_v1.3.xls
Binary file not shown.