|
30 | 30 | */
|
31 | 31 | public class AllCd4CountCalculation extends AbstractPatientCalculation {
|
32 | 32 |
|
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"); |
35 | 38 |
|
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(); |
41 | 40 |
|
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 | + ); |
43 | 45 |
|
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 | + } |
55 | 59 | }
|
0 commit comments