Search in sources :

Example 1 with MultipleObsForEncounterDataDefinition

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

the class BaseEncounterDataSetManager method addSymptomPresentOrAbsentColumn.

protected void addSymptomPresentOrAbsentColumn(EncounterDataSetDefinition dsd, String columnName, String symptomPresentQuestion, String symptomAbsentQuestion, String symptomAnswer, Object valueIfPresent, Object valueIfAbsent) {
    Concept presentConcept = Metadata.getConcept(symptomPresentQuestion);
    Concept absentConcept = Metadata.getConcept(symptomAbsentQuestion);
    Concept answerConcept = Metadata.getConcept(symptomAnswer);
    MultipleObsForEncounterDataDefinition d = new MultipleObsForEncounterDataDefinition();
    d.addQuestion(presentConcept);
    d.addQuestion(absentConcept);
    CodedObsConverter converter = new CodedObsConverter();
    converter.addOption(presentConcept.getUuid(), answerConcept.getUuid(), valueIfPresent);
    converter.addOption(absentConcept.getUuid(), answerConcept.getUuid(), valueIfAbsent);
    addColumn(dsd, columnName, d, converter);
}
Also used : Concept(org.openmrs.Concept) CodedObsConverter(org.openmrs.module.pihcore.reporting.converter.CodedObsConverter) MultipleObsForEncounterDataDefinition(org.openmrs.module.pihcore.reporting.encounter.definition.MultipleObsForEncounterDataDefinition)

Example 2 with MultipleObsForEncounterDataDefinition

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

the class MultipleObsForEncounterDataEvaluatorTest method addSymptomPresentOrAbsentColumn.

protected void addSymptomPresentOrAbsentColumn(EncounterDataSetDefinition dsd, String columnName, String symptomPresentQuestion, String symptomAbsentQuestion, String symptomAnswer, Object valueIfPresent, Object valueIfAbsent) {
    Concept presentConcept = Metadata.getConcept(symptomPresentQuestion);
    Concept absentConcept = Metadata.getConcept(symptomAbsentQuestion);
    Concept answerConcept = Metadata.getConcept(symptomAnswer);
    MultipleObsForEncounterDataDefinition d = new MultipleObsForEncounterDataDefinition();
    d.addQuestion(presentConcept);
    d.addQuestion(absentConcept);
    CodedObsConverter converter = new CodedObsConverter();
    converter.addOption(presentConcept.getUuid(), answerConcept.getUuid(), valueIfPresent);
    converter.addOption(absentConcept.getUuid(), answerConcept.getUuid(), valueIfAbsent);
    dsd.addColumn(columnName.toUpperCase(), d, "", converter);
}
Also used : Concept(org.openmrs.Concept) CodedObsConverter(org.openmrs.module.pihcore.reporting.converter.CodedObsConverter) MultipleObsForEncounterDataDefinition(org.openmrs.module.pihcore.reporting.encounter.definition.MultipleObsForEncounterDataDefinition)

Example 3 with MultipleObsForEncounterDataDefinition

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

the class MultipleObsForEncounterDataEvaluator method evaluate.

@Override
public EvaluatedEncounterData evaluate(EncounterDataDefinition definition, EvaluationContext context) throws EvaluationException {
    MultipleObsForEncounterDataDefinition def = (MultipleObsForEncounterDataDefinition) definition;
    EvaluatedEncounterData data = new EvaluatedEncounterData();
    HqlQueryBuilder q = new HqlQueryBuilder();
    q.select("obs.encounter.encounterId, obs");
    q.from(Obs.class, "obs");
    q.whereIn("obs.concept", def.getQuestions());
    q.whereIn("obs.valueCoded", def.getAnswers());
    q.whereEncounterIn("obs.encounter.encounterId", context);
    List<Object[]> result = Context.getService(EvaluationService.class).evaluateToList(q, context);
    for (Object[] row : result) {
        Integer encounterId = (Integer) row[0];
        Obs obs = (Obs) row[1];
        List l = (List) data.getData().get(encounterId);
        if (l == null) {
            l = new ArrayList();
            data.getData().put(encounterId, l);
        }
        l.add(obs);
    }
    return data;
}
Also used : Obs(org.openmrs.Obs) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) EvaluationService(org.openmrs.module.reporting.evaluation.service.EvaluationService) EvaluatedEncounterData(org.openmrs.module.reporting.data.encounter.EvaluatedEncounterData) HqlQueryBuilder(org.openmrs.module.reporting.evaluation.querybuilder.HqlQueryBuilder) MultipleObsForEncounterDataDefinition(org.openmrs.module.pihcore.reporting.encounter.definition.MultipleObsForEncounterDataDefinition)

Aggregations

MultipleObsForEncounterDataDefinition (org.openmrs.module.pihcore.reporting.encounter.definition.MultipleObsForEncounterDataDefinition)3 Concept (org.openmrs.Concept)2 CodedObsConverter (org.openmrs.module.pihcore.reporting.converter.CodedObsConverter)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Obs (org.openmrs.Obs)1 EvaluatedEncounterData (org.openmrs.module.reporting.data.encounter.EvaluatedEncounterData)1 HqlQueryBuilder (org.openmrs.module.reporting.evaluation.querybuilder.HqlQueryBuilder)1 EvaluationService (org.openmrs.module.reporting.evaluation.service.EvaluationService)1