Skip to content

Commit ff2eba1

Browse files
committed
Improvement on all cd4 counts calculation
1 parent a45eeb4 commit ff2eba1

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

api/src/main/java/org/openmrs/module/kenyaemr/calculation/library/hiv/AllCd4CountCalculation.java

+23-19
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,30 @@
3030
*/
3131
public class AllCd4CountCalculation extends AbstractPatientCalculation {
3232

33-
@Override
34-
public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context) {
33+
@Override
34+
public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context) {
35+
ObsService obsService = Context.getObsService();
36+
PersonService patientService = Context.getPersonService();
37+
DateFormat dateFormatter = new SimpleDateFormat("dd/MM/yyyy");
3538

36-
ObsService obsService = Context.getObsService();
37-
PersonService patientService = Context.getPersonService();
38-
List<SimpleObject> cd4ret = new ArrayList<SimpleObject>();
39-
CalculationResultMap ret = new CalculationResultMap();
40-
DateFormat dateFormatter = new SimpleDateFormat("dd/MM/yyyy");
39+
CalculationResultMap resultMap = new CalculationResultMap();
4140

42-
for (Integer ptId : cohort) {
41+
for (Integer patientId : cohort) {
42+
List<Obs> cd4Observations = obsService.getObservationsByPersonAndConcept(
43+
patientService.getPerson(patientId), Dictionary.getConcept(Dictionary.CD4_COUNT)
44+
);
4345

44-
List<Obs> cd4List = obsService.getObservationsByPersonAndConcept(patientService.getPerson(ptId),Dictionary.getConcept(Dictionary.CD4_COUNT));
45-
for (int i = 0; i < cd4List.size(); ++i) {
46-
cd4ret.add(SimpleObject.create(
47-
"cd4Count", cd4List.get(i).getValueNumeric(),
48-
"cd4CountDate", dateFormatter.format(cd4List.get(i).getObsDatetime())
49-
));
50-
}
51-
ret.put(ptId, new SimpleResult(cd4ret, this, context));
52-
}
53-
return ret;
54-
}
46+
if (!cd4Observations.isEmpty()) {
47+
List<SimpleObject> cd4Results = new ArrayList<>();
48+
for (Obs obs : cd4Observations) {
49+
cd4Results.add(SimpleObject.create(
50+
"cd4Count", obs.getValueNumeric(),
51+
"cd4CountDate", dateFormatter.format(obs.getObsDatetime())
52+
));
53+
}
54+
resultMap.put(patientId, new SimpleResult(cd4Results, this, context));
55+
}
56+
}
57+
return resultMap;
58+
}
5559
}

0 commit comments

Comments
 (0)