Search in sources :

Example 1 with ObsForEncounterDataDefinition

use of org.openmrs.module.reporting.data.encounter.definition.ObsForEncounterDataDefinition 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 2 with ObsForEncounterDataDefinition

use of org.openmrs.module.reporting.data.encounter.definition.ObsForEncounterDataDefinition in project openmrs-module-pihcore by PIH.

the class PihEncounterDataLibrary method getSingleObsInEncounter.

@DocumentedDefinition
public EncounterDataDefinition getSingleObsInEncounter(Concept concept) {
    ObsForEncounterDataDefinition d = new ObsForEncounterDataDefinition();
    d.setQuestion(concept);
    d.setSingleObs(true);
    return d;
}
Also used : ObsForEncounterDataDefinition(org.openmrs.module.reporting.data.encounter.definition.ObsForEncounterDataDefinition) DocumentedDefinition(org.openmrs.module.reporting.definition.library.DocumentedDefinition)

Aggregations

ObsForEncounterDataDefinition (org.openmrs.module.reporting.data.encounter.definition.ObsForEncounterDataDefinition)2 Map (java.util.Map)1 Obs (org.openmrs.Obs)1 EvaluatedEncounterData (org.openmrs.module.reporting.data.encounter.EvaluatedEncounterData)1 DocumentedDefinition (org.openmrs.module.reporting.definition.library.DocumentedDefinition)1