@Test public void evaluate_shouldCalculateEligibility() throws Exception { Program hivProgram = MetadataUtils.existing(Program.class, HivMetadata._Program.HIV); TestUtils.enrollInProgram(TestUtils.getPatient(6), hivProgram, TestUtils.date(2011, 1, 1)); TestUtils.enrollInProgram(TestUtils.getPatient(7), hivProgram, TestUtils.date(2011, 1, 1)); TestUtils.enrollInProgram(TestUtils.getPatient(8), hivProgram, TestUtils.date(2011, 1, 1)); Concept cd4 = Dictionary.getConcept(Dictionary.CD4_COUNT); TestUtils.saveObs(TestUtils.getPatient(6), cd4, 1001, TestUtils.date(2015, 1, 1)); TestUtils.saveObs(TestUtils.getPatient(7), cd4, 101, TestUtils.date(2011, 1, 1)); TestUtils.saveObs(TestUtils.getPatient(8), cd4, 101, TestUtils.date(2011, 1, 1)); Concept stavudine = Dictionary.getConcept(Dictionary.STAVUDINE); TestUtils.saveDrugOrder(TestUtils.getPatient(8), stavudine, TestUtils.date(2011, 1, 1), null); List<Integer> cohort = Arrays.asList(6, 7, 8, 999); CalculationResultMap resultMap = new EligibleForArtCalculation().evaluate(cohort, null, Context.getService(PatientCalculationService.class).createCalculationContext()); Assert.assertTrue((Boolean) resultMap.get(6).getValue()); Assert.assertTrue((Boolean) resultMap.get(7).getValue()); Assert.assertFalse((Boolean) resultMap.get(8).getValue()); Assert.assertFalse((Boolean) resultMap.get(999).getValue()); }
@Override public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context) { Program hivProgram = MetadataUtils.existing(Program.class, HivMetadata._Program.HIV); Program tbProgram = MetadataUtils.existing(Program.class, TbMetadata._Program.TB); Set<Integer> alive = Filters.alive(cohort, context); Set<Integer> inHivProgram = Filters.inProgram(hivProgram, alive, context); Concept tca = Dictionary.getConcept(Dictionary.RETURN_VISIT_DATE); Set<Integer> onArt = CalculationUtils.patientsThatPass(calculate(new OnArtCalculation(), cohort, context)); Set<Integer> ltfu = CalculationUtils.patientsThatPass(calculate(new LostToFollowUpIncludingTransferOutCalculation(), cohort, context)); CalculationResultMap nextAppointmentDate = Calculations.lastObsOnOrBefore(tca, context.getNow(), ltfu, context); Set<Integer> ltfuWithinPeriod = nextAppointmentDate.keySet(); CalculationResultMap ages = Calculations.ages(cohort, context); CalculationResultMap lastWhoStage = calculate(new LastWhoStageCalculation(), cohort, context); CalculationResultMap lastCd4 = calculate(new LastCd4CountCalculation(), cohort, context); CalculationResultMap hepatitisMap = Calculations.lastObs(Dictionary.getConcept(Dictionary.PROBLEM_ADDED), cohort, context); Set<Integer> inTbProgram = Filters.inProgram(tbProgram, alive, context); CalculationResultMap tbStatus = Calculations.lastObs(Dictionary.getConcept(Dictionary.TUBERCULOSIS_DISEASE_STATUS), cohort, context); Set<Integer> pregnantWomen = CalculationUtils.patientsThatPass(calculate(new IsPregnantCalculation(), cohort, context)); CalculationResultMap hivRiskFactor = Calculations.lastObs(Dictionary.getConcept(Dictionary.HIV_RISK_FACTOR), cohort, context); CalculationResultMap breastFeedingMap = Calculations.lastObs(Dictionary.getConcept(Dictionary.INFANT_FEEDING_METHOD), cohort, context); Concept hepatitisB = Dictionary.getConcept(Dictionary.HEPATITIS_B); Concept acuteTypeBViralHepatitis = Dictionary.getConcept(Dictionary.ACUTE_TYPE_B_VIRAL_HEPATITIS); Concept acuteFulminatingTypeBViralHepatitis = Dictionary.getConcept(Dictionary.ACUTE_FULMINATING_TYPE_B_VIRAL_HEPATITIS); Concept chronicActiveTypeBViralHepatitis = Dictionary.getConcept(Dictionary.CHRONIC_ACTIVE_TYPE_B_VIRAL_HEPATITIS); CalculationResultMap ret = new CalculationResultMap(); for (Integer ptId : cohort) { boolean eligible = false; boolean hasHepatitis = false; boolean hasTb = false; boolean isPregnant = false; boolean isDiscordant = false; boolean isBreastFeeding = false; Concept hepatitisConcept = EmrCalculationUtils.codedObsResultForPatient(hepatitisMap, ptId); if(hepatitisConcept != null && (hepatitisConcept.equals(hepatitisB) || hepatitisConcept.equals(acuteTypeBViralHepatitis) || hepatitisConcept.equals(acuteFulminatingTypeBViralHepatitis) || hepatitisConcept.equals(chronicActiveTypeBViralHepatitis))) { hasHepatitis = true; } Concept hasTbConcpt = EmrCalculationUtils.codedObsResultForPatient(tbStatus, ptId); if(inTbProgram.contains(ptId) || (hasTbConcpt != null && hasTbConcpt.equals(Dictionary.getConcept(Dictionary.DISEASE_DIAGNOSED))) || (hasTbConcpt != null && hasTbConcpt.equals(Dictionary.getConcept(Dictionary.ON_TREATMENT_FOR_DISEASE)))) { hasTb = true; } if(pregnantWomen.contains(ptId)) { isPregnant = true; } Concept isDiscodantCouple = EmrCalculationUtils.codedObsResultForPatient(hivRiskFactor, ptId); if(isDiscodantCouple != null && isDiscodantCouple.equals(Dictionary.getConcept(Dictionary.DISCORDANT_COUPLE))) { isDiscordant = true; } Concept infantFeedingConcept = EmrCalculationUtils.codedObsResultForPatient(breastFeedingMap, ptId); if (inHivProgram.contains(ptId) && !onArt.contains(ptId)) { if(infantFeedingConcept != null && (infantFeedingConcept.equals(Dictionary.getConcept(Dictionary.BREASTFED_EXCLUSIVELY)) || infantFeedingConcept.equals(Dictionary.getConcept(Dictionary.MIXED_FEEDING)))) { isBreastFeeding = true; } int ageInMonths = ((Age) ages.get(ptId).getValue()).getFullMonths(); Double cd4 = EmrCalculationUtils.numericObsResultForPatient(lastCd4, ptId); Integer whoStage = EmrUtils.whoStage(EmrCalculationUtils.codedObsResultForPatient(lastWhoStage, ptId)); eligible = isEligible(ageInMonths, cd4, whoStage, hasHepatitis, hasTb, isPregnant, isDiscordant, isBreastFeeding); } if(ltfuWithinPeriod.contains(ptId)) { eligible = false; } ret.put(ptId, new BooleanResult(eligible, this)); } return ret; }
EligibleForArtCalculation extends AbstractPatientCalculation implements PatientFlagCalculation { @Override public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context) { Program hivProgram = MetadataUtils.existing(Program.class, HivMetadata._Program.HIV); Program tbProgram = MetadataUtils.existing(Program.class, TbMetadata._Program.TB); Set<Integer> alive = Filters.alive(cohort, context); Set<Integer> inHivProgram = Filters.inProgram(hivProgram, alive, context); Concept tca = Dictionary.getConcept(Dictionary.RETURN_VISIT_DATE); Set<Integer> onArt = CalculationUtils.patientsThatPass(calculate(new OnArtCalculation(), cohort, context)); Set<Integer> ltfu = CalculationUtils.patientsThatPass(calculate(new LostToFollowUpIncludingTransferOutCalculation(), cohort, context)); CalculationResultMap nextAppointmentDate = Calculations.lastObsOnOrBefore(tca, context.getNow(), ltfu, context); Set<Integer> ltfuWithinPeriod = nextAppointmentDate.keySet(); CalculationResultMap ages = Calculations.ages(cohort, context); CalculationResultMap lastWhoStage = calculate(new LastWhoStageCalculation(), cohort, context); CalculationResultMap lastCd4 = calculate(new LastCd4CountCalculation(), cohort, context); CalculationResultMap hepatitisMap = Calculations.lastObs(Dictionary.getConcept(Dictionary.PROBLEM_ADDED), cohort, context); Set<Integer> inTbProgram = Filters.inProgram(tbProgram, alive, context); CalculationResultMap tbStatus = Calculations.lastObs(Dictionary.getConcept(Dictionary.TUBERCULOSIS_DISEASE_STATUS), cohort, context); Set<Integer> pregnantWomen = CalculationUtils.patientsThatPass(calculate(new IsPregnantCalculation(), cohort, context)); CalculationResultMap hivRiskFactor = Calculations.lastObs(Dictionary.getConcept(Dictionary.HIV_RISK_FACTOR), cohort, context); CalculationResultMap breastFeedingMap = Calculations.lastObs(Dictionary.getConcept(Dictionary.INFANT_FEEDING_METHOD), cohort, context); Concept hepatitisB = Dictionary.getConcept(Dictionary.HEPATITIS_B); Concept acuteTypeBViralHepatitis = Dictionary.getConcept(Dictionary.ACUTE_TYPE_B_VIRAL_HEPATITIS); Concept acuteFulminatingTypeBViralHepatitis = Dictionary.getConcept(Dictionary.ACUTE_FULMINATING_TYPE_B_VIRAL_HEPATITIS); Concept chronicActiveTypeBViralHepatitis = Dictionary.getConcept(Dictionary.CHRONIC_ACTIVE_TYPE_B_VIRAL_HEPATITIS); CalculationResultMap ret = new CalculationResultMap(); for (Integer ptId : cohort) { boolean eligible = false; boolean hasHepatitis = false; boolean hasTb = false; boolean isPregnant = false; boolean isDiscordant = false; boolean isBreastFeeding = false; Concept hepatitisConcept = EmrCalculationUtils.codedObsResultForPatient(hepatitisMap, ptId); if(hepatitisConcept != null && (hepatitisConcept.equals(hepatitisB) || hepatitisConcept.equals(acuteTypeBViralHepatitis) || hepatitisConcept.equals(acuteFulminatingTypeBViralHepatitis) || hepatitisConcept.equals(chronicActiveTypeBViralHepatitis))) { hasHepatitis = true; } Concept hasTbConcpt = EmrCalculationUtils.codedObsResultForPatient(tbStatus, ptId); if(inTbProgram.contains(ptId) || (hasTbConcpt != null && hasTbConcpt.equals(Dictionary.getConcept(Dictionary.DISEASE_DIAGNOSED))) || (hasTbConcpt != null && hasTbConcpt.equals(Dictionary.getConcept(Dictionary.ON_TREATMENT_FOR_DISEASE)))) { hasTb = true; } if(pregnantWomen.contains(ptId)) { isPregnant = true; } Concept isDiscodantCouple = EmrCalculationUtils.codedObsResultForPatient(hivRiskFactor, ptId); if(isDiscodantCouple != null && isDiscodantCouple.equals(Dictionary.getConcept(Dictionary.DISCORDANT_COUPLE))) { isDiscordant = true; } Concept infantFeedingConcept = EmrCalculationUtils.codedObsResultForPatient(breastFeedingMap, ptId); if (inHivProgram.contains(ptId) && !onArt.contains(ptId)) { if(infantFeedingConcept != null && (infantFeedingConcept.equals(Dictionary.getConcept(Dictionary.BREASTFED_EXCLUSIVELY)) || infantFeedingConcept.equals(Dictionary.getConcept(Dictionary.MIXED_FEEDING)))) { isBreastFeeding = true; } int ageInMonths = ((Age) ages.get(ptId).getValue()).getFullMonths(); Double cd4 = EmrCalculationUtils.numericObsResultForPatient(lastCd4, ptId); Integer whoStage = EmrUtils.whoStage(EmrCalculationUtils.codedObsResultForPatient(lastWhoStage, ptId)); eligible = isEligible(ageInMonths, cd4, whoStage, hasHepatitis, hasTb, isPregnant, isDiscordant, isBreastFeeding); } if(ltfuWithinPeriod.contains(ptId)) { eligible = false; } ret.put(ptId, new BooleanResult(eligible, this)); } return ret; } }
EligibleForArtCalculation extends AbstractPatientCalculation implements PatientFlagCalculation { @Override public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context) { Program hivProgram = MetadataUtils.existing(Program.class, HivMetadata._Program.HIV); Program tbProgram = MetadataUtils.existing(Program.class, TbMetadata._Program.TB); Set<Integer> alive = Filters.alive(cohort, context); Set<Integer> inHivProgram = Filters.inProgram(hivProgram, alive, context); Concept tca = Dictionary.getConcept(Dictionary.RETURN_VISIT_DATE); Set<Integer> onArt = CalculationUtils.patientsThatPass(calculate(new OnArtCalculation(), cohort, context)); Set<Integer> ltfu = CalculationUtils.patientsThatPass(calculate(new LostToFollowUpIncludingTransferOutCalculation(), cohort, context)); CalculationResultMap nextAppointmentDate = Calculations.lastObsOnOrBefore(tca, context.getNow(), ltfu, context); Set<Integer> ltfuWithinPeriod = nextAppointmentDate.keySet(); CalculationResultMap ages = Calculations.ages(cohort, context); CalculationResultMap lastWhoStage = calculate(new LastWhoStageCalculation(), cohort, context); CalculationResultMap lastCd4 = calculate(new LastCd4CountCalculation(), cohort, context); CalculationResultMap hepatitisMap = Calculations.lastObs(Dictionary.getConcept(Dictionary.PROBLEM_ADDED), cohort, context); Set<Integer> inTbProgram = Filters.inProgram(tbProgram, alive, context); CalculationResultMap tbStatus = Calculations.lastObs(Dictionary.getConcept(Dictionary.TUBERCULOSIS_DISEASE_STATUS), cohort, context); Set<Integer> pregnantWomen = CalculationUtils.patientsThatPass(calculate(new IsPregnantCalculation(), cohort, context)); CalculationResultMap hivRiskFactor = Calculations.lastObs(Dictionary.getConcept(Dictionary.HIV_RISK_FACTOR), cohort, context); CalculationResultMap breastFeedingMap = Calculations.lastObs(Dictionary.getConcept(Dictionary.INFANT_FEEDING_METHOD), cohort, context); Concept hepatitisB = Dictionary.getConcept(Dictionary.HEPATITIS_B); Concept acuteTypeBViralHepatitis = Dictionary.getConcept(Dictionary.ACUTE_TYPE_B_VIRAL_HEPATITIS); Concept acuteFulminatingTypeBViralHepatitis = Dictionary.getConcept(Dictionary.ACUTE_FULMINATING_TYPE_B_VIRAL_HEPATITIS); Concept chronicActiveTypeBViralHepatitis = Dictionary.getConcept(Dictionary.CHRONIC_ACTIVE_TYPE_B_VIRAL_HEPATITIS); CalculationResultMap ret = new CalculationResultMap(); for (Integer ptId : cohort) { boolean eligible = false; boolean hasHepatitis = false; boolean hasTb = false; boolean isPregnant = false; boolean isDiscordant = false; boolean isBreastFeeding = false; Concept hepatitisConcept = EmrCalculationUtils.codedObsResultForPatient(hepatitisMap, ptId); if(hepatitisConcept != null && (hepatitisConcept.equals(hepatitisB) || hepatitisConcept.equals(acuteTypeBViralHepatitis) || hepatitisConcept.equals(acuteFulminatingTypeBViralHepatitis) || hepatitisConcept.equals(chronicActiveTypeBViralHepatitis))) { hasHepatitis = true; } Concept hasTbConcpt = EmrCalculationUtils.codedObsResultForPatient(tbStatus, ptId); if(inTbProgram.contains(ptId) || (hasTbConcpt != null && hasTbConcpt.equals(Dictionary.getConcept(Dictionary.DISEASE_DIAGNOSED))) || (hasTbConcpt != null && hasTbConcpt.equals(Dictionary.getConcept(Dictionary.ON_TREATMENT_FOR_DISEASE)))) { hasTb = true; } if(pregnantWomen.contains(ptId)) { isPregnant = true; } Concept isDiscodantCouple = EmrCalculationUtils.codedObsResultForPatient(hivRiskFactor, ptId); if(isDiscodantCouple != null && isDiscodantCouple.equals(Dictionary.getConcept(Dictionary.DISCORDANT_COUPLE))) { isDiscordant = true; } Concept infantFeedingConcept = EmrCalculationUtils.codedObsResultForPatient(breastFeedingMap, ptId); if (inHivProgram.contains(ptId) && !onArt.contains(ptId)) { if(infantFeedingConcept != null && (infantFeedingConcept.equals(Dictionary.getConcept(Dictionary.BREASTFED_EXCLUSIVELY)) || infantFeedingConcept.equals(Dictionary.getConcept(Dictionary.MIXED_FEEDING)))) { isBreastFeeding = true; } int ageInMonths = ((Age) ages.get(ptId).getValue()).getFullMonths(); Double cd4 = EmrCalculationUtils.numericObsResultForPatient(lastCd4, ptId); Integer whoStage = EmrUtils.whoStage(EmrCalculationUtils.codedObsResultForPatient(lastWhoStage, ptId)); eligible = isEligible(ageInMonths, cd4, whoStage, hasHepatitis, hasTb, isPregnant, isDiscordant, isBreastFeeding); } if(ltfuWithinPeriod.contains(ptId)) { eligible = false; } ret.put(ptId, new BooleanResult(eligible, this)); } return ret; }  }
EligibleForArtCalculation extends AbstractPatientCalculation implements PatientFlagCalculation { @Override public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context) { Program hivProgram = MetadataUtils.existing(Program.class, HivMetadata._Program.HIV); Program tbProgram = MetadataUtils.existing(Program.class, TbMetadata._Program.TB); Set<Integer> alive = Filters.alive(cohort, context); Set<Integer> inHivProgram = Filters.inProgram(hivProgram, alive, context); Concept tca = Dictionary.getConcept(Dictionary.RETURN_VISIT_DATE); Set<Integer> onArt = CalculationUtils.patientsThatPass(calculate(new OnArtCalculation(), cohort, context)); Set<Integer> ltfu = CalculationUtils.patientsThatPass(calculate(new LostToFollowUpIncludingTransferOutCalculation(), cohort, context)); CalculationResultMap nextAppointmentDate = Calculations.lastObsOnOrBefore(tca, context.getNow(), ltfu, context); Set<Integer> ltfuWithinPeriod = nextAppointmentDate.keySet(); CalculationResultMap ages = Calculations.ages(cohort, context); CalculationResultMap lastWhoStage = calculate(new LastWhoStageCalculation(), cohort, context); CalculationResultMap lastCd4 = calculate(new LastCd4CountCalculation(), cohort, context); CalculationResultMap hepatitisMap = Calculations.lastObs(Dictionary.getConcept(Dictionary.PROBLEM_ADDED), cohort, context); Set<Integer> inTbProgram = Filters.inProgram(tbProgram, alive, context); CalculationResultMap tbStatus = Calculations.lastObs(Dictionary.getConcept(Dictionary.TUBERCULOSIS_DISEASE_STATUS), cohort, context); Set<Integer> pregnantWomen = CalculationUtils.patientsThatPass(calculate(new IsPregnantCalculation(), cohort, context)); CalculationResultMap hivRiskFactor = Calculations.lastObs(Dictionary.getConcept(Dictionary.HIV_RISK_FACTOR), cohort, context); CalculationResultMap breastFeedingMap = Calculations.lastObs(Dictionary.getConcept(Dictionary.INFANT_FEEDING_METHOD), cohort, context); Concept hepatitisB = Dictionary.getConcept(Dictionary.HEPATITIS_B); Concept acuteTypeBViralHepatitis = Dictionary.getConcept(Dictionary.ACUTE_TYPE_B_VIRAL_HEPATITIS); Concept acuteFulminatingTypeBViralHepatitis = Dictionary.getConcept(Dictionary.ACUTE_FULMINATING_TYPE_B_VIRAL_HEPATITIS); Concept chronicActiveTypeBViralHepatitis = Dictionary.getConcept(Dictionary.CHRONIC_ACTIVE_TYPE_B_VIRAL_HEPATITIS); CalculationResultMap ret = new CalculationResultMap(); for (Integer ptId : cohort) { boolean eligible = false; boolean hasHepatitis = false; boolean hasTb = false; boolean isPregnant = false; boolean isDiscordant = false; boolean isBreastFeeding = false; Concept hepatitisConcept = EmrCalculationUtils.codedObsResultForPatient(hepatitisMap, ptId); if(hepatitisConcept != null && (hepatitisConcept.equals(hepatitisB) || hepatitisConcept.equals(acuteTypeBViralHepatitis) || hepatitisConcept.equals(acuteFulminatingTypeBViralHepatitis) || hepatitisConcept.equals(chronicActiveTypeBViralHepatitis))) { hasHepatitis = true; } Concept hasTbConcpt = EmrCalculationUtils.codedObsResultForPatient(tbStatus, ptId); if(inTbProgram.contains(ptId) || (hasTbConcpt != null && hasTbConcpt.equals(Dictionary.getConcept(Dictionary.DISEASE_DIAGNOSED))) || (hasTbConcpt != null && hasTbConcpt.equals(Dictionary.getConcept(Dictionary.ON_TREATMENT_FOR_DISEASE)))) { hasTb = true; } if(pregnantWomen.contains(ptId)) { isPregnant = true; } Concept isDiscodantCouple = EmrCalculationUtils.codedObsResultForPatient(hivRiskFactor, ptId); if(isDiscodantCouple != null && isDiscodantCouple.equals(Dictionary.getConcept(Dictionary.DISCORDANT_COUPLE))) { isDiscordant = true; } Concept infantFeedingConcept = EmrCalculationUtils.codedObsResultForPatient(breastFeedingMap, ptId); if (inHivProgram.contains(ptId) && !onArt.contains(ptId)) { if(infantFeedingConcept != null && (infantFeedingConcept.equals(Dictionary.getConcept(Dictionary.BREASTFED_EXCLUSIVELY)) || infantFeedingConcept.equals(Dictionary.getConcept(Dictionary.MIXED_FEEDING)))) { isBreastFeeding = true; } int ageInMonths = ((Age) ages.get(ptId).getValue()).getFullMonths(); Double cd4 = EmrCalculationUtils.numericObsResultForPatient(lastCd4, ptId); Integer whoStage = EmrUtils.whoStage(EmrCalculationUtils.codedObsResultForPatient(lastWhoStage, ptId)); eligible = isEligible(ageInMonths, cd4, whoStage, hasHepatitis, hasTb, isPregnant, isDiscordant, isBreastFeeding); } if(ltfuWithinPeriod.contains(ptId)) { eligible = false; } ret.put(ptId, new BooleanResult(eligible, this)); } return ret; }  @Override String getFlagMessage(); @Override CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues,
	                                     PatientCalculationContext context); }
EligibleForArtCalculation extends AbstractPatientCalculation implements PatientFlagCalculation { @Override public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context) { Program hivProgram = MetadataUtils.existing(Program.class, HivMetadata._Program.HIV); Program tbProgram = MetadataUtils.existing(Program.class, TbMetadata._Program.TB); Set<Integer> alive = Filters.alive(cohort, context); Set<Integer> inHivProgram = Filters.inProgram(hivProgram, alive, context); Concept tca = Dictionary.getConcept(Dictionary.RETURN_VISIT_DATE); Set<Integer> onArt = CalculationUtils.patientsThatPass(calculate(new OnArtCalculation(), cohort, context)); Set<Integer> ltfu = CalculationUtils.patientsThatPass(calculate(new LostToFollowUpIncludingTransferOutCalculation(), cohort, context)); CalculationResultMap nextAppointmentDate = Calculations.lastObsOnOrBefore(tca, context.getNow(), ltfu, context); Set<Integer> ltfuWithinPeriod = nextAppointmentDate.keySet(); CalculationResultMap ages = Calculations.ages(cohort, context); CalculationResultMap lastWhoStage = calculate(new LastWhoStageCalculation(), cohort, context); CalculationResultMap lastCd4 = calculate(new LastCd4CountCalculation(), cohort, context); CalculationResultMap hepatitisMap = Calculations.lastObs(Dictionary.getConcept(Dictionary.PROBLEM_ADDED), cohort, context); Set<Integer> inTbProgram = Filters.inProgram(tbProgram, alive, context); CalculationResultMap tbStatus = Calculations.lastObs(Dictionary.getConcept(Dictionary.TUBERCULOSIS_DISEASE_STATUS), cohort, context); Set<Integer> pregnantWomen = CalculationUtils.patientsThatPass(calculate(new IsPregnantCalculation(), cohort, context)); CalculationResultMap hivRiskFactor = Calculations.lastObs(Dictionary.getConcept(Dictionary.HIV_RISK_FACTOR), cohort, context); CalculationResultMap breastFeedingMap = Calculations.lastObs(Dictionary.getConcept(Dictionary.INFANT_FEEDING_METHOD), cohort, context); Concept hepatitisB = Dictionary.getConcept(Dictionary.HEPATITIS_B); Concept acuteTypeBViralHepatitis = Dictionary.getConcept(Dictionary.ACUTE_TYPE_B_VIRAL_HEPATITIS); Concept acuteFulminatingTypeBViralHepatitis = Dictionary.getConcept(Dictionary.ACUTE_FULMINATING_TYPE_B_VIRAL_HEPATITIS); Concept chronicActiveTypeBViralHepatitis = Dictionary.getConcept(Dictionary.CHRONIC_ACTIVE_TYPE_B_VIRAL_HEPATITIS); CalculationResultMap ret = new CalculationResultMap(); for (Integer ptId : cohort) { boolean eligible = false; boolean hasHepatitis = false; boolean hasTb = false; boolean isPregnant = false; boolean isDiscordant = false; boolean isBreastFeeding = false; Concept hepatitisConcept = EmrCalculationUtils.codedObsResultForPatient(hepatitisMap, ptId); if(hepatitisConcept != null && (hepatitisConcept.equals(hepatitisB) || hepatitisConcept.equals(acuteTypeBViralHepatitis) || hepatitisConcept.equals(acuteFulminatingTypeBViralHepatitis) || hepatitisConcept.equals(chronicActiveTypeBViralHepatitis))) { hasHepatitis = true; } Concept hasTbConcpt = EmrCalculationUtils.codedObsResultForPatient(tbStatus, ptId); if(inTbProgram.contains(ptId) || (hasTbConcpt != null && hasTbConcpt.equals(Dictionary.getConcept(Dictionary.DISEASE_DIAGNOSED))) || (hasTbConcpt != null && hasTbConcpt.equals(Dictionary.getConcept(Dictionary.ON_TREATMENT_FOR_DISEASE)))) { hasTb = true; } if(pregnantWomen.contains(ptId)) { isPregnant = true; } Concept isDiscodantCouple = EmrCalculationUtils.codedObsResultForPatient(hivRiskFactor, ptId); if(isDiscodantCouple != null && isDiscodantCouple.equals(Dictionary.getConcept(Dictionary.DISCORDANT_COUPLE))) { isDiscordant = true; } Concept infantFeedingConcept = EmrCalculationUtils.codedObsResultForPatient(breastFeedingMap, ptId); if (inHivProgram.contains(ptId) && !onArt.contains(ptId)) { if(infantFeedingConcept != null && (infantFeedingConcept.equals(Dictionary.getConcept(Dictionary.BREASTFED_EXCLUSIVELY)) || infantFeedingConcept.equals(Dictionary.getConcept(Dictionary.MIXED_FEEDING)))) { isBreastFeeding = true; } int ageInMonths = ((Age) ages.get(ptId).getValue()).getFullMonths(); Double cd4 = EmrCalculationUtils.numericObsResultForPatient(lastCd4, ptId); Integer whoStage = EmrUtils.whoStage(EmrCalculationUtils.codedObsResultForPatient(lastWhoStage, ptId)); eligible = isEligible(ageInMonths, cd4, whoStage, hasHepatitis, hasTb, isPregnant, isDiscordant, isBreastFeeding); } if(ltfuWithinPeriod.contains(ptId)) { eligible = false; } ret.put(ptId, new BooleanResult(eligible, this)); } return ret; }  @Override String getFlagMessage(); @Override CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues,
	                                     PatientCalculationContext context);  }