Skip to content

Commit

Permalink
Resolved conflicts:
Browse files Browse the repository at this point in the history
  • Loading branch information
njorocs committed Feb 19, 2019
2 parents b3f9763 + d10e1bc commit 3538fe0
Show file tree
Hide file tree
Showing 10 changed files with 1,271 additions and 107 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
*
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
* graphic logo is a trademark of OpenMRS Inc.
*/
package org.openmrs.module.kenyaemr.calculation.library;

import org.openmrs.Concept;
import org.openmrs.Encounter;
import org.openmrs.EncounterType;
import org.openmrs.Obs;
import org.openmrs.calculation.patient.PatientCalculationContext;
import org.openmrs.calculation.result.CalculationResultMap;
import org.openmrs.module.kenyacore.calculation.*;
import org.openmrs.module.kenyaemr.Dictionary;
import org.openmrs.module.kenyaemr.calculation.EmrCalculationUtils;
import org.openmrs.module.kenyaemr.metadata.MchMetadata;
import org.openmrs.module.metadatadeploy.MetadataUtils;

import java.util.Collection;
import java.util.Map;
import java.util.Set;

/**
* Calculates the recorded pregnancy status of patients
*/
public class IsBreastFeedingCalculation extends AbstractPatientCalculation {
/**
* Evaluates the calculation
* @should calculate null for deceased patients
* @should calculate null for patients with no recorded status
* @should calculate last recorded breastfeeding status for all patients
*/
@Override
public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context) {

Set<Integer> aliveAndFemale = Filters.female(Filters.alive(cohort, context), context);

Concept ExclusiveBreastFeeding = Dictionary.getConcept(Dictionary.BREASTFED_EXCLUSIVELY);
Concept MixedBreastFeeding = Dictionary.getConcept(Dictionary.MIXED_FEEDING);
CalculationResultMap infantFeedingStatusObs = Calculations.lastObs(Dictionary.getConcept(Dictionary.INFANT_FEEDING_METHOD), aliveAndFemale, context);
CalculationResultMap ret = new CalculationResultMap();
for (Integer ptId : cohort) {
boolean breastFeeding = false;

Obs feedingStatusObs = EmrCalculationUtils.obsResultForPatient(infantFeedingStatusObs, ptId);

if (feedingStatusObs != null && feedingStatusObs.getValueCoded().equals(ExclusiveBreastFeeding) || feedingStatusObs.getValueCoded().equals(MixedBreastFeeding) ) {
breastFeeding = true;
}

ret.put(ptId, new BooleanResult(breastFeeding, this));
}

return ret;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.joda.time.DateTime;
import org.joda.time.Days;
import org.joda.time.Minutes;
import org.joda.time.Months;
import org.openmrs.Concept;
import org.openmrs.Encounter;
import org.openmrs.Obs;
Expand All @@ -23,11 +24,14 @@
import org.openmrs.calculation.result.CalculationResultMap;
import org.openmrs.calculation.result.ListResult;
import org.openmrs.calculation.result.SimpleResult;
import org.openmrs.module.kenyacore.calculation.CalculationUtils;
import org.openmrs.module.kenyacore.calculation.Calculations;
import org.openmrs.module.kenyacore.calculation.Filters;
import org.openmrs.module.kenyaemr.Dictionary;
import org.openmrs.module.kenyaemr.calculation.BaseEmrCalculation;
import org.openmrs.module.kenyaemr.calculation.EmrCalculationUtils;
import org.openmrs.module.kenyaemr.calculation.library.IsBreastFeedingCalculation;
import org.openmrs.module.kenyaemr.calculation.library.IsPregnantCalculation;
import org.openmrs.module.kenyaemr.metadata.HivMetadata;
import org.openmrs.module.kenyaemr.metadata.TbMetadata;
import org.openmrs.module.kenyaemr.util.EncounterBasedRegimenUtils;
Expand All @@ -45,7 +49,7 @@
* Not started on tb drugs - due for tb enrollment
* In IPT program
* On ART
*
*Is not pregnant
*/
public class GreenCardVelocityCalculation extends BaseEmrCalculation {

Expand Down Expand Up @@ -76,20 +80,24 @@ public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Obj
Concept latestVL = Dictionary.getConcept(Dictionary.HIV_VIRAL_LOAD);
Concept LDLQuestion = Context.getConceptService().getConcept(1305);
Concept LDLAnswer = Context.getConceptService().getConcept(1302);
//Checking adherence
Concept AdherenceQuestion = Context.getConceptService().getConcept(1658);

CalculationResultMap iptCurrent = Calculations.lastObs(IptCurrentQuestion, cohort, context);
CalculationResultMap iptStarted = Calculations.lastObs(IptStartQuestion, cohort, context);
CalculationResultMap iptStopped = Calculations.lastObs(IptStopQuestion, cohort, context);
CalculationResultMap lastVLObs = Calculations.lastObs(latestVL, inHivProgram, context);
CalculationResultMap lastLDLObs = Calculations.lastObs(LDLQuestion, inHivProgram, context);
CalculationResultMap lastAdherenceObs = Calculations.lastObs(AdherenceQuestion, inHivProgram, context);

// Get active ART regimen of each patient
Concept arvs = Dictionary.getConcept(Dictionary.ANTIRETROVIRAL_DRUGS);
CalculationResultMap currentARVDrugOrders = activeDrugOrders(arvs, cohort, context);

// Get ART start date
CalculationResultMap allDrugOrders = allDrugOrders(arvs, cohort, context);
CalculationResultMap earliestOrderDates = earliestStartDates(allDrugOrders, context);
//find pregnant women
Set<Integer> pregnantWomen = CalculationUtils.patientsThatPass(calculate(new IsPregnantCalculation(), cohort, context));
//find breastfeeding women
Set<Integer> breastFeeding = CalculationUtils.patientsThatPass(calculate(new IsBreastFeedingCalculation(), cohort, context));

CalculationResultMap ret = new CalculationResultMap();
StringBuilder sb = new StringBuilder();
Expand All @@ -105,12 +113,18 @@ public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Obj
Date iptStartDate = null;
Date tbStartObsDate = null;
Date tbStopObsDate = null;
Date adherenceObsDate = null;
Date currentDate =new Date();
boolean inIptProgram = false;
boolean currentInIPT = false;
boolean patientInIPT6Months = false;
boolean goodAdherence6Months = false;
boolean isPregnant = false;
boolean isBreastFeeding = false;
Integer iptStartStopDiff = 0;
Integer iptCompletionDays = 0;
Integer adherenceDiffDays = 0;
Integer goodAdherenceAnswer = 159405;
//ART calculations
String artStartObsDate = null;
Date artStartDate = null;
Expand All @@ -121,7 +135,7 @@ public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Obj
Obs lastVLObsResult = null;
String ldlResult = null;
Double vlResult = 0.0;
//Patient with current on anti tb drugs and/or anti tb start dates
//Patient with current on anti tb drugs and/or anti tb start dates
Obs tbCurrentObs = EmrCalculationUtils.obsResultForPatient(tbCurrent, ptId);
Obs tbStartObs = EmrCalculationUtils.obsResultForPatient(tbStarted, ptId);

Expand All @@ -134,6 +148,8 @@ public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Obj
Double vl = EmrCalculationUtils.numericObsResultForPatient(lastVLObs, ptId);
Concept ldl = EmrCalculationUtils.codedObsResultForPatient(lastLDLObs, ptId);

//Adherence
Concept adherenceResults = EmrCalculationUtils.codedObsResultForPatient(lastAdherenceObs, ptId);
// get latest of ldl or vl
if (ldl != null && vl != null) {
Obs vlObs = EmrCalculationUtils.obsResultForPatient(lastVLObs, ptId);
Expand Down Expand Up @@ -163,7 +179,17 @@ else if (lastVLObsResult != null && (lastVLObsResult.getConcept() == LDLQuestion
vlResult = 0.0;
ldlResult = null;
}

// Good adherence in the last 6 months
if (adherenceResults != null) {
if (adherenceResults != null && adherenceResults.getConceptId().equals(goodAdherenceAnswer) ) {
Obs adherenceObsResults = EmrCalculationUtils.obsResultForPatient(lastAdherenceObs, ptId);
adherenceObsDate = adherenceObsResults.getObsDatetime();
adherenceDiffDays = daysBetween(currentDate, adherenceObsDate);
if (adherenceDiffDays >= 0 && adherenceDiffDays <= 182) {
goodAdherence6Months = true;
}
}
}
//Enrolled in tb program
if (inTbProgram.contains(ptId)) {
patientInTBProgram = true;
Expand Down Expand Up @@ -221,7 +247,7 @@ else if (lastVLObsResult != null && (lastVLObsResult.getConcept() == LDLQuestion
if (artStartObsDate != null) {
try {
artStartDate = DATE_FORMAT.parse(artStartObsDate);
artStartCurrDiff = daysBetween(currentDate,artStartDate);
artStartCurrDiff = monthsBetween(currentDate,artStartDate);
if (artStartCurrDiff > 3) {
hasBeenOnART = true;
}
Expand All @@ -232,16 +258,27 @@ else if (lastVLObsResult != null && (lastVLObsResult.getConcept() == LDLQuestion
}
}

if(pregnantWomen.contains(ptId)) {
isPregnant = true;
}

if(breastFeeding.contains(ptId)) {
isBreastFeeding = true;
}

sb.append("inIPT:").append(inIptProgram).append(",");
sb.append("inTB:").append(patientInTBProgram).append(",");
sb.append("dueTB:").append(patientDueForTBEnrollment).append(",");
sb.append("onART:").append(patientOnART).append(",");
sb.append("hasBeenOnART:").append(hasBeenOnART).append(",");
sb.append("regimenName:").append(regimenName).append(",");
sb.append("duration:").append(artStartCurrDiff).append(",");
sb.append("vlResult:").append(vlResult).append(",");
sb.append("ldlResult:").append(ldlResult).append(",");
sb.append("iptCompleted:").append(patientInIPT6Months);
sb.append("iptCompleted:").append(patientInIPT6Months).append(",");
sb.append("goodAdherence:").append(goodAdherence6Months).append(",");
sb.append("isPregnant:").append(isPregnant).append(",");
sb.append("isBreastFeeding:").append(isBreastFeeding);
// sb.append("dueTB:").append(patientDueForTBEnrollment).append(",");
// sb.append("artStartDate:").append(artStartDate).append(",");

ret.put(ptId, new SimpleResult(sb.toString(), this, context));
Expand All @@ -259,4 +296,9 @@ private int daysBetween(Date date1, Date date2) {
DateTime d2 = new DateTime(date2.getTime());
return Math.abs(Days.daysBetween(d1, d2).getDays());
}
private int monthsBetween(Date d1, Date d2) {
DateTime dateTime1 = new DateTime(d1.getTime());
DateTime dateTime2 = new DateTime(d2.getTime());
return Math.abs(Months.monthsBetween(dateTime1, dateTime2).getMonths());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,11 @@
import org.openmrs.Program;
import org.openmrs.calculation.patient.PatientCalculationContext;
import org.openmrs.calculation.result.CalculationResultMap;
import org.openmrs.calculation.result.SimpleResult;
import org.openmrs.module.kenyacore.calculation.AbstractPatientCalculation;
import org.openmrs.module.kenyacore.calculation.BooleanResult;
import org.openmrs.module.kenyacore.calculation.CalculationUtils;
import org.openmrs.module.kenyacore.calculation.Calculations;
import org.openmrs.module.kenyacore.calculation.Filters;
import org.openmrs.module.kenyacore.calculation.PatientFlagCalculation;
import org.openmrs.module.kenyaemr.Dictionary;
import org.openmrs.module.kenyaemr.calculation.EmrCalculationUtils;
import org.openmrs.module.kenyaemr.calculation.library.IsPregnantCalculation;
import org.openmrs.module.kenyaemr.calculation.library.hiv.LastCd4CountCalculation;
import org.openmrs.module.kenyaemr.calculation.library.hiv.LastWhoStageCalculation;
import org.openmrs.module.kenyaemr.calculation.library.hiv.LostToFollowUpIncludingTransferOutCalculation;
import org.openmrs.module.kenyaemr.metadata.HivMetadata;
import org.openmrs.module.kenyaemr.metadata.TbMetadata;
import org.openmrs.module.kenyaemr.util.EmrUtils;
import org.openmrs.module.metadatadeploy.MetadataUtils;
import org.openmrs.module.reporting.common.Age;

Expand Down
Loading

0 comments on commit 3538fe0

Please sign in to comment.