Source:
<code>public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context) { Program mchmsProgram = MetadataUtils.getProgram(Metadata.Program.MCHMS); Set<Integer> alive = alivePatients(cohort, context); Set<Integer> inMchmsProgram = CalculationUtils.patientsThatPass(Calculations.activeEnrollment(mchmsProgram, alive, context)); CalculationResultMap hivStatusObs = Calculations.lastObs(getConcept(Dictionary.HIV_STATUS), inMchmsProgram, context); CalculationResultMap hivTestDateObs = Calculations.lastObs(getConcept(Dictionary.DATE_OF_HIV_DIAGNOSIS), inMchmsProgram, context); CalculationResultMap ret = new CalculationResultMap(); CalculationResultMap crm = Calculations.lastEncounter(MetadataUtils.getEncounterType(Metadata.EncounterType.MCHMS_ENROLLMENT), cohort, context); boolean hivTestedAtEnrollment; for (Integer ptId : cohort) { hivTestedAtEnrollment = false; if (inMchmsProgram.contains(ptId)) { Concept hivStatus = EmrCalculationUtils.codedObsResultForPatient(hivStatusObs, ptId); Date hivTestDate = EmrCalculationUtils.datetimeObsResultForPatient(hivTestDateObs, ptId); <START> if (hivStatus != null && !hivStatus.equals(Dictionary.getConcept(Dictionary.NOT_HIV_TESTED))) { <END> if (hivTestDate != null) { Date enrollmentDate = ((Encounter) crm.get(ptId).getValue()).getDateCreated(); hivTestedAtEnrollment = (hivTestDate.before(enrollmentDate) || hivTestDate.equals(enrollmentDate)); } } } ret.put(ptId, new BooleanResult(hivTestedAtEnrollment, this, context)); } return ret; }</code><technical_language>Put concept in var of loop</technical_language>

Target:
public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context) { Program mchmsProgram = MetadataUtils.getProgram(Metadata.Program.MCHMS); Set<Integer> alive = alivePatients(cohort, context); Set<Integer> inMchmsProgram = CalculationUtils.patientsThatPass(Calculations.activeEnrollment(mchmsProgram, alive, context)); CalculationResultMap hivStatusObs = Calculations.lastObs(getConcept(Dictionary.HIV_STATUS), inMchmsProgram, context); CalculationResultMap hivTestDateObs = Calculations.lastObs(getConcept(Dictionary.DATE_OF_HIV_DIAGNOSIS), inMchmsProgram, context); Concept notHivTestedConcept = Dictionary.getConcept(Dictionary.NOT_HIV_TESTED); CalculationResultMap ret = new CalculationResultMap(); CalculationResultMap crm = Calculations.lastEncounter(MetadataUtils.getEncounterType(Metadata.EncounterType.MCHMS_ENROLLMENT), cohort, context); for (Integer ptId : cohort) { boolean hivTestedAtEnrollment = false; if (inMchmsProgram.contains(ptId)) { Concept hivStatus = EmrCalculationUtils.codedObsResultForPatient(hivStatusObs, ptId); Date hivTestDate = EmrCalculationUtils.datetimeObsResultForPatient(hivTestDateObs, ptId); if (hivStatus != null && !hivStatus.equals(notHivTestedConcept)) { if (hivTestDate != null) { Date enrollmentDate = ((Encounter) crm.get(ptId).getValue()).getDateCreated(); hivTestedAtEnrollment = (hivTestDate.before(enrollmentDate) || hivTestDate.equals(enrollmentDate)); } } } ret.put(ptId, new BooleanResult(hivTestedAtEnrollment, this, context)); } return ret; }