Search in sources :

Example 1 with EvaluatedEncounterData

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()));
}
Also used : EncounterBuilder(org.openmrs.contrib.testdata.builder.EncounterBuilder) EncounterEvaluationContext(org.openmrs.module.reporting.evaluation.context.EncounterEvaluationContext) EncounterIdSet(org.openmrs.module.reporting.query.encounter.EncounterIdSet) Encounter(org.openmrs.Encounter) EvaluatedEncounterData(org.openmrs.module.reporting.data.encounter.EvaluatedEncounterData) BmiEncounterDataDefinition(org.openmrs.module.pihcore.reporting.encounter.definition.BmiEncounterDataDefinition) Test(org.junit.Test) BaseReportTest(org.openmrs.module.pihcore.reporting.BaseReportTest)

Example 2 with EvaluatedEncounterData

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()));
}
Also used : EncounterBuilder(org.openmrs.contrib.testdata.builder.EncounterBuilder) EncounterEvaluationContext(org.openmrs.module.reporting.evaluation.context.EncounterEvaluationContext) EncounterIdSet(org.openmrs.module.reporting.query.encounter.EncounterIdSet) Encounter(org.openmrs.Encounter) EvaluatedEncounterData(org.openmrs.module.reporting.data.encounter.EvaluatedEncounterData) BmiEncounterDataDefinition(org.openmrs.module.pihcore.reporting.encounter.definition.BmiEncounterDataDefinition) Test(org.junit.Test) BaseReportTest(org.openmrs.module.pihcore.reporting.BaseReportTest)

Example 3 with EvaluatedEncounterData

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()));
}
Also used : EncounterBuilder(org.openmrs.contrib.testdata.builder.EncounterBuilder) EncounterEvaluationContext(org.openmrs.module.reporting.evaluation.context.EncounterEvaluationContext) EncounterIdSet(org.openmrs.module.reporting.query.encounter.EncounterIdSet) Encounter(org.openmrs.Encounter) EvaluatedEncounterData(org.openmrs.module.reporting.data.encounter.EvaluatedEncounterData) RetrospectiveEncounterDataDefinition(org.openmrs.module.pihcore.reporting.encounter.definition.RetrospectiveEncounterDataDefinition) Test(org.junit.Test) BaseReportTest(org.openmrs.module.pihcore.reporting.BaseReportTest)

Example 4 with EvaluatedEncounterData

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;
}
Also used : ObsForEncounterDataDefinition(org.openmrs.module.reporting.data.encounter.definition.ObsForEncounterDataDefinition) Obs(org.openmrs.Obs) EvaluatedEncounterData(org.openmrs.module.reporting.data.encounter.EvaluatedEncounterData) Map(java.util.Map)

Example 5 with EvaluatedEncounterData

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;
}
Also used : EvaluatedEncounterData(org.openmrs.module.reporting.data.encounter.EvaluatedEncounterData) Map(java.util.Map) DateTime(org.joda.time.DateTime)

Aggregations

EvaluatedEncounterData (org.openmrs.module.reporting.data.encounter.EvaluatedEncounterData)7 Test (org.junit.Test)5 Encounter (org.openmrs.Encounter)5 EncounterBuilder (org.openmrs.contrib.testdata.builder.EncounterBuilder)5 BaseReportTest (org.openmrs.module.pihcore.reporting.BaseReportTest)5 EncounterEvaluationContext (org.openmrs.module.reporting.evaluation.context.EncounterEvaluationContext)5 EncounterIdSet (org.openmrs.module.reporting.query.encounter.EncounterIdSet)5 BmiEncounterDataDefinition (org.openmrs.module.pihcore.reporting.encounter.definition.BmiEncounterDataDefinition)3 Map (java.util.Map)2 RetrospectiveEncounterDataDefinition (org.openmrs.module.pihcore.reporting.encounter.definition.RetrospectiveEncounterDataDefinition)2 Date (java.util.Date)1 DateTime (org.joda.time.DateTime)1 Obs (org.openmrs.Obs)1 ObsForEncounterDataDefinition (org.openmrs.module.reporting.data.encounter.definition.ObsForEncounterDataDefinition)1