use of org.openmrs.module.reporting.data.encounter.EvaluatedEncounterData in project openmrs-module-pihcore by PIH.
the class BmiEncounterDataEvaluatorTest method shouldReturnNullIfNoWeight.
@Test
public void shouldReturnNullIfNoWeight() throws Exception {
EncounterBuilder eb = data.encounter();
eb.patient(createPatient());
eb.encounterDatetime(DateUtil.getDateTime(2015, 4, 15));
eb.location(Metadata.lookup(MirebalaisLocations.CDI_KLINIK_EKSTEN_JENERAL));
eb.encounterType(Metadata.lookup(EncounterTypes.VITALS));
eb.obs(Metadata.getConcept("PIH:WEIGHT (KG)"), 45.4);
Encounter enc = eb.save();
EncounterEvaluationContext context = new EncounterEvaluationContext();
context.setBaseEncounters(new EncounterIdSet(enc.getEncounterId()));
EvaluatedEncounterData res = encounterDataService.evaluate(new BmiEncounterDataDefinition(), context);
assertNull(res.getData().get(enc.getEncounterId()));
}
use of org.openmrs.module.reporting.data.encounter.EvaluatedEncounterData in project openmrs-module-pihcore by PIH.
the class BmiEncounterDataEvaluatorTest method shouldReturnNullIfNoHeight.
@Test
public void shouldReturnNullIfNoHeight() throws Exception {
EncounterBuilder eb = data.encounter();
eb.patient(createPatient());
eb.encounterDatetime(DateUtil.getDateTime(2015, 4, 15));
eb.location(Metadata.lookup(MirebalaisLocations.CDI_KLINIK_EKSTEN_JENERAL));
eb.encounterType(Metadata.lookup(EncounterTypes.VITALS));
eb.obs(Metadata.getConcept("PIH:HEIGHT (CM)"), 152.4);
Encounter enc = eb.save();
EncounterEvaluationContext context = new EncounterEvaluationContext();
context.setBaseEncounters(new EncounterIdSet(enc.getEncounterId()));
EvaluatedEncounterData res = encounterDataService.evaluate(new BmiEncounterDataDefinition(), context);
assertNull(res.getData().get(enc.getEncounterId()));
}
use of org.openmrs.module.reporting.data.encounter.EvaluatedEncounterData in project openmrs-module-pihcore by PIH.
the class RetrospectiveEncounterDataEvaluatorTest method shouldFindEncounterToBeRetrospective.
@Test
public void shouldFindEncounterToBeRetrospective() throws Exception {
EncounterBuilder eb = data.encounter();
eb.patient(createPatient());
eb.encounterDatetime(DateUtil.getDateTime(2015, 4, 15));
eb.location(Metadata.lookup(MirebalaisLocations.CDI_KLINIK_EKSTEN_JENERAL));
eb.encounterType(1);
Encounter enc = eb.save();
EncounterEvaluationContext context = new EncounterEvaluationContext();
context.setBaseEncounters(new EncounterIdSet(enc.getEncounterId()));
EvaluatedEncounterData res = encounterDataService.evaluate(new RetrospectiveEncounterDataDefinition(), context);
assertTrue((Boolean) res.getData().get(enc.getEncounterId()));
}
use of org.openmrs.module.reporting.data.encounter.EvaluatedEncounterData in project openmrs-module-pihcore by PIH.
the class BmiEncounterDataEvaluator method evaluate.
@Override
public EvaluatedEncounterData evaluate(EncounterDataDefinition definition, EvaluationContext context) throws EvaluationException {
ObsForEncounterDataDefinition weightDataDefinition = new ObsForEncounterDataDefinition();
weightDataDefinition.setQuestion(Metadata.getConcept("PIH:WEIGHT (KG)"));
weightDataDefinition.setSingleObs(true);
EvaluatedEncounterData weights = encounterDataService.evaluate(weightDataDefinition, context);
ObsForEncounterDataDefinition heightDataDefinition = new ObsForEncounterDataDefinition();
heightDataDefinition.setQuestion(Metadata.getConcept("PIH:HEIGHT (CM)"));
heightDataDefinition.setSingleObs(true);
EvaluatedEncounterData heights = encounterDataService.evaluate(heightDataDefinition, context);
EvaluatedEncounterData ret = new EvaluatedEncounterData(definition, context);
for (Map.Entry<Integer, Object> entry : weights.getData().entrySet()) {
Integer encId = entry.getKey();
Obs height = (Obs) heights.getData().get(encId);
Obs weight = (Obs) weights.getData().get(encId);
if (height != null && height.getValueNumeric() != null && weight != null && weight.getValueNumeric() != null) {
Double bmi = Math.rint((weight.getValueNumeric() / ((height.getValueNumeric() / 100) * (height.getValueNumeric() / 100))) * 10) / 10;
ret.addData(encId, bmi);
} else {
ret.addData(encId, null);
}
}
return ret;
}
use of org.openmrs.module.reporting.data.encounter.EvaluatedEncounterData in project openmrs-module-pihcore by PIH.
the class RetrospectiveEncounterDataEvaluator method evaluate.
@Override
public EvaluatedEncounterData evaluate(EncounterDataDefinition definition, EvaluationContext context) throws EvaluationException {
EvaluatedEncounterData encounterDatetimes = encounterDataService.evaluate(builtInEncounterData.getEncounterDatetime(), context);
EvaluatedEncounterData encounterDatesCreated = encounterDataService.evaluate(builtInEncounterData.getDateCreated(), context);
EvaluatedEncounterData ret = new EvaluatedEncounterData(definition, context);
for (Map.Entry<Integer, Object> entry : encounterDatetimes.getData().entrySet()) {
Integer encId = entry.getKey();
DateTime encounterDatetime = new DateTime(encounterDatetimes.getData().get(encId));
DateTime dateCreated = new DateTime(encounterDatesCreated.getData().get(encId));
ret.addData(encId, Minutes.minutesBetween(encounterDatetime, dateCreated).getMinutes() > 30);
}
return ret;
}
Aggregations