Skip to content

Commit

Permalink
Mepts 263 (#125)
Browse files Browse the repository at this point in the history
* E1: Number of active patients in ART at the end of current month who performed Viral Load Test (Annual Notification)

* Added the functionality to exclude the patients who had a VL with the year of reporting for E1

* Adding a generic way to easly pull the common indicators of E1 E2 and E3

* Initial work for the E2 indicators

* Add the E2 indicator and it required definitions

* Adding E3 indicators and its definitions

* Added the F1 indicator

* Added F2 indicator definitions

* Initial work on the F3 indicators

* Finish work on the section F of the report

* Proper mapping of end date so that it can be picked in a claculation

* Fix the exclusion criteria so that those outside should be included in our indicators

* Replacing the for each loop to iterators

* Proper calulation of the date required as start date

* Change from using reporting ORM to native sql

* Proper parameter mappings and proper nagations

* Preparing to start converting ExcludeCriteriaForEandFCalculation into sql equivalent

* Initial work on the exclusion for E1

* Complete change of the calculation for exclusion criteria for E and F done

* Replacing java code for the start date exclution criteria with sql

* General code clean up

* MEPTS-263: updated comment blocks for E-F sections in master card resumo report to match indicator names in the specs

* Combine union of the E2 exclusion into one query

* Using the visit date as encounter date as oppossed to end date for F2 exclusion

* Fix the F2 and F3 exclusion criteria to base on visit date as end date as oppossed to when we were applying the end of reporting period

* Proper E1 exclusion end date set based on the lab results date as oppossed to the end of reporting period

* E2 exclusion done including the date from the encounter date as oppossed to the end of reporting period

* Include the lab visit date for the criteria 3 exclusion instead of using reporting end period

* Fix for Total 0-14 bringing in some case +15

* Fix B.4 where not calculating correctly for total +15

* Fix B.7, B.8,B.10 and B.12 where the references to excel file where wrong, where all pointing to female desagregation
  • Loading branch information
ningosi authored and steliomo committed Nov 15, 2019
1 parent 53580bf commit 22e19ad
Show file tree
Hide file tree
Showing 8 changed files with 1,620 additions and 931 deletions.
1,824 changes: 899 additions & 925 deletions api/src/main/java/org/openmrs/module/eptsreports/metadata/HivMetadata.java

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public ResumoMensalDataSetDefinition(

public DataSetDefinition constructResumoMensalDataset() {
CohortIndicatorDataSetDefinition dsd = new CohortIndicatorDataSetDefinition();
String mappings = "startDate=${startDate},endDate=${endDate},location=${location}";
dsd.setName("Resumo Mensal Data set B");
dsd.addParameters(getParameters());

Expand Down Expand Up @@ -410,6 +411,91 @@ public DataSetDefinition constructResumoMensalDataset() {
getPatientsWhoInitiatedPreTarvDuringCurrentMonthAndDiagnosedForActiveTB(),
"");

// E1 indicators

addRow(
dsd,
"E1",
"Annual Notification",
map(
eptsGeneralIndicator.getIndicator(
"E1",
map(
resumoMensalCohortQueries
.getNumberOfActivePatientsInArtAtEndOfCurrentMonthWithVlPerformed(),
mappings)),
mappings),
resumoMensalAandBdisaggregations.disAggForE());
// E2
addRow(
dsd,
"E2",
"Annual Notification",
map(
eptsGeneralIndicator.getIndicator(
"E2",
map(
resumoMensalCohortQueries
.getNumberOfActivePatientsInArtAtTheEndOfTheCurrentMonthHavingVlTestResults(),
mappings)),
mappings),
resumoMensalAandBdisaggregations.disAggForE());

// E3
addRow(
dsd,
"E3",
"Annual Notification",
map(
eptsGeneralIndicator.getIndicator(
"E3",
map(
resumoMensalCohortQueries
.getActivePatientsOnArtWhoRecievedVldSuppressionResults(),
mappings)),
mappings),
resumoMensalAandBdisaggregations.disAggForE());

// F1
dsd.addColumn(
"F1",
"Number of patients who had clinical appointment during the reporting month",
map(
eptsGeneralIndicator.getIndicator(
"F1",
map(
resumoMensalCohortQueries
.getNumberOfPatientsWhoHadClinicalAppointmentDuringTheReportingMonth(),
mappings)),
mappings),
"");
// F2
dsd.addColumn(
"F2",
"Number of patients who had clinical appointment during the reporting month and were screened for TB",
map(
eptsGeneralIndicator.getIndicator(
"F2",
map(
resumoMensalCohortQueries
.getNumberOfPatientsWhoHadClinicalAppointmentDuringTheReportingMonthAndScreenedFoTb(),
mappings)),
mappings),
"");
// F3
dsd.addColumn(
"F3",
"Number of patients who had at least one clinical appointment during the year",
map(
eptsGeneralIndicator.getIndicator(
"F3",
map(
resumoMensalCohortQueries
.getNumberOfPatientsWithAtLeastOneClinicalAppointmentDuringTheYear(),
mappings)),
mappings),
"");

return dsd;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ public CohortDefinitionDimension age(final AgeDimensionCohortInterface ageDimens
dim.addCohortDefinition(
"0-4",
ageDimensionCohort.createXtoYAgeCohort("patients with age between 0 and 4 years", 0, 4));
dim.addCohortDefinition(
"0-14",
ageDimensionCohort.createXtoYAgeCohort("patients with age between 0 and 14 years", 0, 14));
dim.addCohortDefinition(
"0-15",
ageDimensionCohort.createXtoYAgeCohort("patients with age between 0 and 15 years", 0, 15));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ public List<ColumnParameters> getUnder14YearsColumns() {
new ColumnParameters("fiveTo9years", "5 to 9 years patients", "age=5-9", "02");
ColumnParameters tenTo14yearsMale =
new ColumnParameters(
"tenTo14yearsMale", "10 to 14 years male patients", "gender=M|age=10-15", "03");
"tenTo14yearsMale", "10 to 14 years male patients", "gender=M|age=10-14", "03");
ColumnParameters tenTo14yearsFemale =
new ColumnParameters(
"tenTo14yearsFemale", "10 to 14 years female patients", "gender=F|age=10-15", "04");
"tenTo14yearsFemale", "10 to 14 years female patients", "gender=F|age=10-14", "04");
ColumnParameters under14yearsTotal =
new ColumnParameters(
"under14yearsTotal", "Under 15 years patients - Totals", "age=0-15", "05");
"under14yearsTotal", "Under 15 years patients - Totals", "age=0-14", "05");

return Arrays.asList(
under4years, fiveTo9years, tenTo14yearsMale, tenTo14yearsFemale, under14yearsTotal);
Expand Down Expand Up @@ -62,9 +62,9 @@ public List<ColumnParameters> getAdultPatients() {

public List<ColumnParameters> getAdolescentesColumns() {
ColumnParameters tenTo14Male =
new ColumnParameters("tenTo14Male", "10 to 14 years male", "gender=M|age=10-15", "01");
new ColumnParameters("tenTo14Male", "10 to 14 years male", "gender=M|age=10-14", "01");
ColumnParameters tenTo14Female =
new ColumnParameters("tenTo14Female", "10 to 14 years female", "gender=F|age=10-15", "02");
new ColumnParameters("tenTo14Female", "10 to 14 years female", "gender=F|age=10-14", "02");
ColumnParameters fifteenTo19Female =
new ColumnParameters(
"fifteenTo19Female", "15 to 19 years female", "gender=F|age=15-19", "03");
Expand All @@ -76,4 +76,16 @@ public List<ColumnParameters> getAdolescentesColumns() {
return Arrays.asList(
tenTo14Male, tenTo14Female, fifteenTo19Female, fifteenTo19Male, adolescentTotals);
}

/**
* Get teh disaggregations for the patients under 14 years and those above 14 yeara
*
* @return List of ColumnParameters
*/
public List<ColumnParameters> disAggForE() {
ColumnParameters under14Years =
new ColumnParameters("under14", "Under 14 years", "age=0-14", "01");
ColumnParameters over14Years = new ColumnParameters("over14", "15+ years", "age=15+", "02");
return Arrays.asList(under14Years, over14Years);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,243 @@ public static String getPatientsTransferredFromAnotherHealthFacilityByEndOfPrevi
typeOfPantientConcept,
tarvConcept);
}

public static String getPatientsForF2ForExclusionFromMainQuery(
int encounterType, int tbSymptomsConcept, int yesConcept, int tbTreatmentPlanConcept) {
String query =
"SELECT p.patient_id "
+ "FROM patient p "
+ " JOIN encounter e "
+ " ON p.patient_id = e.patient_id "
+ " JOIN obs o "
+ " ON o.encounter_id = e.encounter_id "
+ " JOIN (SELECT pat.patient_id AS patient_id, enc.encounter_datetime AS endDate FROM encounter enc JOIN patient pat ON pat.patient_id=enc.patient_id "
+ " JOIN obs ob ON enc.encounter_id=ob.encounter_id WHERE pat.voided = 0 AND enc.voided = 0 AND ob.voided = 0 "
+ " AND enc.location_id = :location AND enc.encounter_datetime BETWEEN :startDate AND :endDate "
+ " AND enc.encounter_type= %d AND ob.concept_id=%d AND ob.value_coded=%d) ed "
+ " ON p.patient_id=ed.patient_id"
+ " WHERE p.voided = 0 "
+ " AND e.voided = 0 "
+ " AND e.encounter_type = %d "
+ " AND e.location_id = :location "
+ " AND e.encounter_datetime = ed.endDate "
+ " AND o.voided = 0 "
+ " AND o.concept_id = %d ";
return String.format(
query, encounterType, tbSymptomsConcept, yesConcept, encounterType, tbTreatmentPlanConcept);
}

/**
* Get patients with encounters within start and end date F1: Number of patients who had clinical
* appointment during the reporting month
*
* @return String
*/
public static String getPatientsWithGivenEncounterType(int encounterType) {
String query =
"SELECT p.patient_id FROM patient p JOIN encounter e ON p.patient_id=e.patient_id "
+ " WHERE e.encounter_type=%d AND e.location_id=:location "
+ " AND e.encounter_datetime BETWEEN :startDate AND :endDate AND p.voided=0 AND e.voided=0 ";
return String.format(query, encounterType);
}

/**
* Get patients with viral load suppression
*
* @return String
*/
public static String getPatientsHavingViralLoadSuppression(
int viralLoadConcept, int encounterType) {
String query =
"SELECT p.patient_id FROM patient p JOIN encounter e ON p.patient_id=e.patient_id JOIN obs o ON e.encounter_id=o.encounter_id "
+ " WHERE p.voided=0 AND e.voided=0 AND o.voided=0 AND e.location_id=:location "
+ " AND e.encounter_datetime BETWEEN :startDate AND :endDate "
+ " AND o.value_numeric IS NOT NULL "
+ " AND o.concept_id=%d "
+ " AND e.encounter_type=%d "
+ " AND o.value_numeric < 1000";
return String.format(query, viralLoadConcept, encounterType);
}

/**
* getPatientsWithCodedObsAndAnswers
*
* @return String
*/
public static String getPatientsWithCodedObsAndAnswers(
int encounterType, int questionConceptId, int answerConceptId) {
String query =
"SELECT p.patient_id FROM patient p JOIN encounter e ON p.patient_id=e.patient_id JOIN obs o ON e.encounter_id=o.encounter_id "
+ " WHERE p.voided = 0 AND e.voided = 0 AND o.voided = 0 "
+ " AND e.location_id = :location AND e.encounter_datetime BETWEEN :startDate AND :endDate AND e.encounter_type=%d "
+ " AND o.concept_id=%d AND o.value_coded=%d";
return String.format(query, encounterType, questionConceptId, answerConceptId);
}

/**
* Get patients with viral load suppression
*
* @return String
*/
public static String getPatientsHavingViralLoadResults(int viralLoadConcept, int encounterType) {
String query =
"SELECT p.patient_id FROM patient p JOIN encounter e ON p.patient_id=e.patient_id JOIN obs o ON e.encounter_id=o.encounter_id "
+ " WHERE p.voided=0 AND e.voided=0 AND o.voided=0 AND e.location_id=:location "
+ " AND e.encounter_datetime BETWEEN :startDate AND :endDate "
+ " AND o.value_numeric IS NOT NULL "
+ " AND o.concept_id=%d "
+ " AND e.encounter_type=%d ";
return String.format(query, viralLoadConcept, encounterType);
}

/**
* Get patients with any coded obs value
*
* @return String
*/
public static String gePatientsWithCodedObs(int encounterType, int conceptId) {
String query =
"SELECT p.patient_id FROM patient p JOIN encounter e ON p.patient_id=e.patient_id JOIN obs o ON e.encounter_id=o.encounter_id "
+ " WHERE p.voided = 0 AND e.voided = 0 AND o.voided = 0 "
+ " AND e.location_id = :location AND e.encounter_datetime BETWEEN :startDate AND :endDate AND e.encounter_type=%d "
+ " AND o.concept_id=%d ";
return String.format(query, encounterType, conceptId);
}

/**
* E1 exclusions
*
* @return String
*/
public static String getE1ExclusionCriteria(
int encounterType, int questionConceptId, int answerConceptId) {
String query =
"SELECT p.patient_id FROM patient p JOIN encounter e ON p.patient_id=e.patient_id JOIN obs o ON e.encounter_id=o.encounter_id "
+ " JOIN (SELECT pat.patient_id AS patient_id, enc.encounter_datetime AS endDate FROM patient pat "
+ " JOIN encounter enc ON pat.patient_id=enc.patient_id JOIN obs ob ON enc.encounter_id=ob.encounter_id "
+ " WHERE pat.voided = 0 AND enc.voided = 0 AND ob.voided = 0 AND enc.location_id = :location "
+ " AND enc.encounter_datetime BETWEEN :startDate AND :endDate AND enc.encounter_type=%d AND "
+ " ob.concept_id=%d AND ob.value_coded=%d) ed "
+ " ON p.patient_id=ed.patient_id "
+ " WHERE p.voided = 0 AND e.voided = 0 AND o.voided = 0 "
+ " AND e.location_id = :location AND e.encounter_datetime BETWEEN "
+ " IF(MONTH(:startDate) = 12 && DAY(:startDate) = 21, :startDate, CONCAT(YEAR(:startDate)-1, '-12','-21')) "
+ " AND ed.endDate AND e.encounter_type=%d "
+ " AND o.concept_id=%d AND o.value_coded=%d";
return String.format(
query,
encounterType,
questionConceptId,
answerConceptId,
encounterType,
questionConceptId,
answerConceptId);
}

/**
* E2 exclusions
*
* @param viralLoadConcept
* @param encounterType
* @param qualitativeConcept
* @return String
*/
public static String getE2ExclusionCriteria(
int viralLoadConcept, int encounterType, int qualitativeConcept) {

String query =
"SELECT p.patient_id FROM patient p JOIN encounter e ON p.patient_id=e.patient_id JOIN obs o ON e.encounter_id=o.encounter_id "
+ "JOIN (SELECT pat.patient_id AS patient_id, enc.encounter_datetime AS endDate FROM patient pat JOIN encounter enc ON pat.patient_id=enc.patient_id JOIN obs ob "
+ " ON enc.encounter_id=ob.encounter_id "
+ " WHERE pat.voided=0 AND enc.voided=0 AND ob.voided=0 AND enc.location_id=:location AND enc.encounter_datetime "
+ " BETWEEN :startDate AND :endDate AND ob.concept_id IN(%d, %d) AND enc.encounter_type=%d) ed "
+ " ON p.patient_id=ed.patient_id "
+ " WHERE p.voided=0 AND e.voided=0 AND o.voided=0 AND e.location_id=:location "
+ " AND e.encounter_datetime BETWEEN "
+ " IF(MONTH(:startDate) = 12 && DAY(:startDate) = 21, :startDate, CONCAT(YEAR(:startDate)-1, '-12','-21')) "
+ " AND ed.endDate "
+ " AND o.concept_id IN (%d, %d)"
+ " AND e.encounter_type=%d ";
return String.format(
query,
viralLoadConcept,
qualitativeConcept,
encounterType,
viralLoadConcept,
qualitativeConcept,
encounterType);
}

/**
* E3 exclusion
*
* @param viralLoadConcept
* @param encounterType
* @param qualitativeConcept
* @return
*/
public static String getE3ExclusionCriteria(
int viralLoadConcept, int encounterType, int qualitativeConcept) {
String query =
"SELECT p.patient_id FROM patient p JOIN encounter e ON p.patient_id=e.patient_id JOIN obs o ON e.encounter_id=o.encounter_id "
+ " JOIN (SELECT pat.patient_id AS patient_id, enc.encounter_datetime AS endDate FROM patient pat "
+ " JOIN encounter enc ON pat.patient_id=enc.patient_id JOIN obs ob ON enc.encounter_id=ob.encounter_id "
+ " WHERE pat.voided=0 AND enc.voided=0 AND ob.voided=0 AND enc.location_id=:location "
+ " AND enc.encounter_datetime BETWEEN :startDate AND :endDate AND ob.value_numeric IS NOT NULL "
+ " AND ob.concept_id=%d AND enc.encounter_type=%d AND ob.value_numeric < 1000) ed "
+ " ON p.patient_id=ed.patient_id"
+ " WHERE p.voided=0 AND e.voided=0 AND o.voided=0 AND e.location_id=:location "
+ " AND e.encounter_datetime BETWEEN "
+ " IF(MONTH(:startDate) = 12 && DAY(:startDate) = 21, :startDate, CONCAT(YEAR(:startDate)-1, '-12','-21')) "
+ " AND ed.endDate "
+ " AND o.value_numeric IS NOT NULL "
+ " AND o.concept_id=%d "
+ " AND e.encounter_type=%d "
+ " AND o.value_numeric < 1000"
+ " UNION "
+ " SELECT p.patient_id FROM patient p JOIN encounter e ON p.patient_id=e.patient_id JOIN obs o ON e.encounter_id=o.encounter_id "
+ " JOIN (SELECT pat.patient_id AS patient_id, enc.encounter_datetime AS endDate FROM patient pat "
+ " JOIN encounter enc ON pat.patient_id=enc.patient_id JOIN obs ob ON enc.encounter_id=ob.encounter_id "
+ " WHERE pat.voided = 0 AND enc.voided = 0 AND ob.voided = 0 AND enc.location_id = :location AND "
+ " enc.encounter_datetime BETWEEN :startDate AND :endDate AND enc.encounter_type=%d AND ob.concept_id=%d) ed "
+ " ON p.patient_id=ed.patient_id "
+ " WHERE p.voided = 0 AND e.voided = 0 AND o.voided = 0 "
+ " AND e.location_id = :location AND e.encounter_datetime BETWEEN "
+ " IF(MONTH(:startDate) = 12 && DAY(:startDate) = 21, :startDate, CONCAT(YEAR(:startDate)-1, '-12','-21')) "
+ " AND ed.endDate "
+ " AND e.encounter_type=%d "
+ " AND o.concept_id=%d ";

return String.format(
query,
viralLoadConcept,
encounterType,
viralLoadConcept,
encounterType,
encounterType,
qualitativeConcept,
encounterType,
qualitativeConcept);
}

/**
* F3 exclusions
*
* @param encounterType
* @return
*/
public static String getF3Exclusion(int encounterType) {
String query =
" SELECT p.patient_id FROM patient p JOIN encounter e ON p.patient_id=e.patient_id JOIN ( "
+ " SELECT pat.patient_id AS patient_id, enc.encounter_datetime AS endDate FROM encounter enc JOIN patient pat "
+ " ON enc.patient_id=pat.patient_id WHERE enc.encounter_type=%d AND enc.location_id=:location "
+ " AND enc.encounter_datetime BETWEEN :startDate AND :endDate AND pat.voided=0 AND enc.voided=0) ed "
+ " ON p.patient_id=ed.patient_id"
+ " WHERE e.encounter_type=%d AND e.location_id=:location "
+ " AND e.encounter_datetime BETWEEN "
+ " IF(MONTH(:startDate) = 12 && DAY(:startDate) = 21, :startDate, CONCAT(YEAR(:startDate)-1, '-12','-21')) "
+ " AND ed.endDate "
+ "AND p.voided=0 AND e.voided=0 ";
return String.format(query, encounterType, encounterType);
}
}
Binary file modified api/src/main/resources/Relatorio_Mensal.xls
Binary file not shown.
Loading

0 comments on commit 22e19ad

Please sign in to comment.