Skip to content

Commit

Permalink
MEPTS-179 Routine fixes, base cohort and gender filter removal (#108)
Browse files Browse the repository at this point in the history
* Fetch the entire list of the lactation map as oppossed to the last obs

* Include the equal boundaries to the second criteria for the routine

* Include equality bounds to the criteria 1 routine

* Including the Observations between the dates in the criteria 3 of routine

* Merged with the work done here Mepts 213 pregnant breast feeding queries

* Exclude 1 day from te six months boundary for criteria 1

* Attach bounadries to the viral load comapred to repoerting period and lower limit

* Adding 1 day to the lower boundaries of the viral load results and suppression

* Remove the boundaries on the 15 months date in criteria 2 routine

* Revert the removal of boundaries in the fifteen months criteria for routine

* We don't exclude restart treatment anymore
  • Loading branch information
ningosi authored and Nathan Floor committed Jun 27, 2019
1 parent 683bea8 commit cde0a53
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public CalculationResultMap evaluate(
cohort,
Arrays.asList(location),
Arrays.asList(yes),
TimeQualifier.LAST,
TimeQualifier.ANY,
null,
context);

Expand Down Expand Up @@ -129,7 +129,8 @@ private Date getResultantDate(

ListResult patientResult = (ListResult) patientStateMap.get(pId);

Obs lactattingObs = EptsCalculationUtils.resultForPatient(lactatingMap, pId);
ListResult lactatingResults = (ListResult) lactatingMap.get(pId);
List<Obs> lactatingObs = EptsCalculationUtils.extractResultValues(lactatingResults);
Obs criteriaHivObs = EptsCalculationUtils.resultForPatient(criteriaHivStartMap, pId);
ListResult deliveryDateResult = (ListResult) deliveryDateMap.get(pId);
List<Obs> deliveryDateObsList = EptsCalculationUtils.extractResultValues(deliveryDateResult);
Expand All @@ -138,7 +139,7 @@ private Date getResultantDate(
// get a list of all eligible dates
List<Date> allEligibleDates =
Arrays.asList(
this.isLactating(lastVlDate, lactattingObs),
this.isLactating(lastVlDate, lactatingObs),
this.hasHIVStartDate(lastVlDate, criteriaHivObs),
this.hasDeliveryDate(lastVlDate, deliveryDateObsList),
this.isInBreastFeedingInProgram(lastVlDate, patientStateList));
Expand Down Expand Up @@ -172,12 +173,14 @@ private Date hasDeliveryDate(Date lastVlDate, List<Obs> deliveryDateObsList) {
return deliveryDate;
}

private Date isLactating(Date lastVlDate, Obs lactantObs) {
private Date isLactating(Date lastVlDate, List<Obs> lactantObsList) {
Date lactatingDate = null;
if (lactantObs != null
&& this.isInBreastFeedingViralLoadRange(
lastVlDate, lactantObs.getEncounter().getEncounterDatetime())) {
lactatingDate = lactantObs.getEncounter().getEncounterDatetime();
for (Obs lactantObs : lactantObsList) {
if (lactantObs.getObsDatetime() != null
&& this.isInBreastFeedingViralLoadRange(
lastVlDate, lactantObs.getEncounter().getEncounterDatetime())) {
lactatingDate = lactantObs.getEncounter().getEncounterDatetime();
}
}
return lactatingDate;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import org.openmrs.module.eptsreports.reporting.calculation.generic.InitialArtStartDateCalculation;
import org.openmrs.module.eptsreports.reporting.utils.EptsCalculationUtils;
import org.openmrs.module.eptsreports.reporting.utils.EptsReportConstants.PatientsOnRoutineEnum;
import org.openmrs.module.reporting.common.DateUtil;
import org.openmrs.module.reporting.common.DurationUnit;
import org.openmrs.module.reporting.common.TimeQualifier;
import org.springframework.stereotype.Component;

Expand Down Expand Up @@ -164,8 +166,8 @@ private boolean isOnRoutine(
&& lastVlObs.getObsDatetime() != null
&& criteria != null
&& onArtForMoreThan3Months.contains(pId)
&& lastVlObs.getObsDatetime().after(latestVlLowerDateLimit)
&& lastVlObs.getObsDatetime().before(onOrBefore)) {
&& lastVlObs.getObsDatetime().compareTo(latestVlLowerDateLimit) >= 0
&& lastVlObs.getObsDatetime().compareTo(onOrBefore) <= 0) {

// get all the VL results for each patient from enrollment
ListResult vlObsResultFromEndOfReportingPeriod =
Expand Down Expand Up @@ -268,8 +270,8 @@ private boolean isOnRoutineCriteria2(
&& allVls.getValueNumeric() != null
&& allVls.getValueNumeric() < 1000) {
if (criteria.equals(PatientsOnRoutineEnum.ADULTCHILDREN)
&& allVls.getObsDatetime().compareTo(twelveMonths) < 0
&& allVls.getObsDatetime().compareTo(fifteenMonths) > 0) {
&& allVls.getObsDatetime().compareTo(twelveMonths) <= 0
&& allVls.getObsDatetime().compareTo(fifteenMonths) >= 0) {
return true;
} else if (criteria.equals(PatientsOnRoutineEnum.BREASTFEEDINGPREGNANT)
&& allVls.getObsDatetime().before(lastViralLoadDate)) {
Expand All @@ -292,15 +294,15 @@ private boolean isOnRoutineCriteria1(
Date nineMonths = EptsCalculationUtils.addMonths(artInitiationDate, 9);

boolean withinAdultLimits =
lastViralLoadDate.compareTo(sixMonths) > 0
lastViralLoadDate.compareTo(sixMonths) >= 0
&& lastViralLoadDate.compareTo(nineMonths) <= 0;
boolean withinBreastfeedingLimits =
lastViralLoadDate.compareTo(threeMonths) > 0
lastViralLoadDate.compareTo(threeMonths) >= 0
&& lastViralLoadDate.compareTo(sixMonths) <= 0;

Date sixMonthsLess1Day = DateUtil.adjustDate(sixMonths, -1, DurationUnit.DAYS);
if (criteria.equals(PatientsOnRoutineEnum.ADULTCHILDREN) && withinAdultLimits) {
return !EptsCalculationUtils.anyObsBetween(
allViralLoadForPatient, artInitiationDate, sixMonths);
allViralLoadForPatient, artInitiationDate, sixMonthsLess1Day);
} else if (criteria.equals(PatientsOnRoutineEnum.BREASTFEEDINGPREGNANT)
&& withinBreastfeedingLimits) {
return !EptsCalculationUtils.anyObsBetween(
Expand All @@ -316,8 +318,8 @@ private List<Obs> getViralLoadForPatientTakenWithin12Months(
// populate viralLoadForPatientTakenWithin12Months with obs which fall within the 12month window
for (Obs obs : vLoadList) {
if (obs != null
&& obs.getObsDatetime().after(latestVlLowerDateLimit)
&& obs.getObsDatetime().before(onOrBefore)) {
&& obs.getObsDatetime().compareTo(latestVlLowerDateLimit) >= 0
&& obs.getObsDatetime().compareTo(onOrBefore) <= 0) {
viralLoadForPatientTakenWithin12Months.add(obs);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ public CohortDefinition getTxNewBreastfeedingComposition() {
EptsReportUtils.map(
getPatientsWhoGaveBirthWithinReportingPeriod(),
"startDate=${onOrAfter},endDate=${onOrBefore},location=${location}"));
cd.addSearch("FEMININO", EptsReportUtils.map(genderCohorts.femaleCohort(), ""));
cd.addSearch(
"LACTANTE",
EptsReportUtils.map(
Expand All @@ -169,8 +168,7 @@ public CohortDefinition getTxNewBreastfeedingComposition() {
Arrays.asList(commonMetadata.getYesConcept())),
"onOrAfter=${onOrAfter},onOrBefore=${onOrBefore},locationList=${location}"));

String compositionString =
"(DATAPARTO OR INICIOLACTANTE OR LACTANTEPROGRAMA OR LACTANTE) AND FEMININO";
String compositionString = "(DATAPARTO OR INICIOLACTANTE OR LACTANTEPROGRAMA OR LACTANTE)";

cd.setCompositionString(compositionString);
return cd;
Expand All @@ -197,16 +195,11 @@ public CohortDefinition getTxNewCompositionCohort(String cohortName) {
Mapped.map(
hivCohortQueries.getPatientsTransferredFromOtherHealthFacility(),
"onOrAfter=${onOrAfter},onOrBefore=${onOrBefore},location=${location}");
Mapped<CohortDefinition> restartedTreatment =
Mapped.map(
hivCohortQueries.getPatientsWhoRestartedTreatment(),
"onOrAfter=${onOrAfter},onOrBefore=${onOrBefore},locationList=${location}");

txNewComposition.getSearches().put("startedART", startedART);
txNewComposition.getSearches().put("transferredIn", transferredIn);
txNewComposition.getSearches().put("restartedTreatment", restartedTreatment);

txNewComposition.setCompositionString("startedART NOT (transferredIn OR restartedTreatment)");
txNewComposition.setCompositionString("startedART NOT transferredIn");
return txNewComposition;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static String getPregnantWhileOnArt(
+ adultInitailEncounter
+ ","
+ adultSegEncounter
+ ") and e.encounter_datetime between :startDate and :endDate and e.location_id=:location and pe.gender='F'"
+ ") and e.encounter_datetime between :startDate and :endDate and e.location_id=:location "
+ " union"
+ " Select p.patient_id"
+ " from patient p"
Expand All @@ -51,7 +51,7 @@ public static String getPregnantWhileOnArt(
+ adultInitailEncounter
+ ","
+ adultSegEncounter
+ ") and e.encounter_datetime between :startDate and :endDate and e.location_id=:location and pe.gender='F' "
+ ") and e.encounter_datetime between :startDate and :endDate and e.location_id=:location "
+ " union"
+ " Select p.patient_id"
+ " from patient p"
Expand All @@ -65,12 +65,12 @@ public static String getPregnantWhileOnArt(
+ adultInitailEncounter
+ ","
+ adultSegEncounter
+ ") and e.encounter_datetime between :startDate and :endDate and e.location_id=:location and pe.gender='F'"
+ ") and e.encounter_datetime between :startDate and :endDate and e.location_id=:location "
+ " union"
+ " select pp.patient_id from patient_program pp"
+ " inner join person pe on pp.patient_id=pe.person_id"
+ " where pp.program_id="
+ etvProgram
+ " and pp.voided=0 and pp.date_enrolled between :startDate and :endDate and pp.location_id=:location and pe.gender='F'";
+ " and pp.voided=0 and pp.date_enrolled between :startDate and :endDate and pp.location_id=:location ";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static String getPatientsWithViralLoadSuppression(
+ " AND o.concept_id="
+ vlConceptQuestion
+ " AND o.value_numeric IS NOT NULL AND"
+ " e.encounter_datetime BETWEEN date_add(:endDate, interval -12 MONTH) and :endDate AND"
+ " e.encounter_datetime BETWEEN date_add(date_add(:endDate, interval -12 MONTH), interval 1 day) AND :endDate AND"
+ " e.location_id=:location GROUP BY p.patient_id"
+ ") ultima_carga"
+ " INNER JOIN obs ON obs.person_id=ultima_carga.patient_id AND obs.obs_datetime="
Expand Down Expand Up @@ -69,7 +69,7 @@ public static String getPatientsHavingViralLoadInLast12Months(
+ ") AND o.concept_id="
+ vlConceptQuestion
+ " AND o.value_numeric IS NOT NULL AND"
+ " e.encounter_datetime BETWEEN date_add(:endDate, interval -12 MONTH) AND :endDate AND"
+ " e.encounter_datetime BETWEEN date_add(date_add(:endDate, interval -12 MONTH), interval 1 day) AND :endDate AND"
+ " e.location_id=:location";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,8 @@ public static boolean dateBetween(Date startDate, Date endDate, Date dateInQuest
public static boolean anyObsBetween(List<Obs> vlObsList, Date startDate, Date endDate) {
for (Obs obs : vlObsList) {
if (obs.getObsDatetime() != null
&& obs.getObsDatetime().after(startDate)
&& obs.getObsDatetime().before(endDate)) {
&& obs.getObsDatetime().compareTo(startDate) >= 0
&& obs.getObsDatetime().compareTo(endDate) <= 0) {
return true;
}
}
Expand Down

0 comments on commit cde0a53

Please sign in to comment.