Search in sources :

Example 1 with LastDispositionBeforeExitCohortDefinition

use of org.openmrs.module.pihcore.reporting.cohort.definition.LastDispositionBeforeExitCohortDefinition in project openmrs-module-pihcore by PIH.

the class PihCohortDefinitionLibrary method lastDispositionBeforeExitHelper.

private CohortDefinition lastDispositionBeforeExitHelper(Concept disposition) {
    LastDispositionBeforeExitCohortDefinition cd = new LastDispositionBeforeExitCohortDefinition();
    cd.addParameter(new Parameter("exitOnOrAfter", "mirebalaisreports.parameter.exitOnOrAfter", Date.class));
    cd.addParameter(new Parameter("exitOnOrBefore", "mirebalaisreports.parameter.exitOnOrBefore", Date.class));
    cd.addParameter(new Parameter("exitFromWard", "mirebalaisreports.parameter.exitFromWard", Location.class));
    cd.setDispositionsToConsider(getDispositionsToConsiderAsExit());
    cd.addDisposition(disposition);
    return new MappedParametersCohortDefinition(cd, "exitOnOrAfter", "startDate", "exitOnOrBefore", "endDate", "exitFromWard", "location");
}
Also used : Parameter(org.openmrs.module.reporting.evaluation.parameter.Parameter) LastDispositionBeforeExitCohortDefinition(org.openmrs.module.pihcore.reporting.cohort.definition.LastDispositionBeforeExitCohortDefinition) Date(java.util.Date) Location(org.openmrs.Location) MappedParametersCohortDefinition(org.openmrs.module.reporting.cohort.definition.MappedParametersCohortDefinition)

Example 2 with LastDispositionBeforeExitCohortDefinition

use of org.openmrs.module.pihcore.reporting.cohort.definition.LastDispositionBeforeExitCohortDefinition in project openmrs-module-pihcore by PIH.

the class LastDispositionBeforeExitCohortDefinitionEvaluatorTest method testEvaluate.

@Test
public void testEvaluate() throws Exception {
    Location mensInternalMedicine = Metadata.lookup(MirebalaisLocations.MENS_INTERNAL_MEDICINE);
    Date startDate = DateUtil.parseDate("2013-10-03 00:00:00", "yyyy-MM-dd HH:mm:ss");
    Date endDate = DateUtil.parseDate("2013-10-03 23:59:59", "yyyy-MM-dd HH:mm:ss");
    Concept discharged = conceptService.getConceptByMapping("DISCHARGED", "PIH");
    LastDispositionBeforeExitCohortDefinition definition = new LastDispositionBeforeExitCohortDefinition();
    definition.setExitFromWard(mensInternalMedicine);
    definition.setExitOnOrAfter(startDate);
    definition.setExitOnOrBefore(endDate);
    definition.addDisposition(discharged);
    EvaluatedCohort result = cohortDefinitionService.evaluate(definition, new EvaluationContext());
    assertThat(result, isCohortWithExactlyIds(patient4.getId()));
}
Also used : Concept(org.openmrs.Concept) EvaluatedCohort(org.openmrs.module.reporting.cohort.EvaluatedCohort) LastDispositionBeforeExitCohortDefinition(org.openmrs.module.pihcore.reporting.cohort.definition.LastDispositionBeforeExitCohortDefinition) EvaluationContext(org.openmrs.module.reporting.evaluation.EvaluationContext) Date(java.util.Date) Location(org.openmrs.Location) BaseInpatientReportTest(org.openmrs.module.pihcore.reporting.BaseInpatientReportTest) Test(org.junit.Test)

Example 3 with LastDispositionBeforeExitCohortDefinition

use of org.openmrs.module.pihcore.reporting.cohort.definition.LastDispositionBeforeExitCohortDefinition in project openmrs-module-pihcore by PIH.

the class LastDispositionBeforeExitCohortDefinitionEvaluator method evaluate.

@Override
public EvaluatedCohort evaluate(CohortDefinition cohortDefinition, EvaluationContext context) throws EvaluationException {
    LastDispositionBeforeExitCohortDefinition cd = (LastDispositionBeforeExitCohortDefinition) cohortDefinition;
    Location exitFromWard = cd.getExitFromWard();
    List<Concept> dispositions = cd.getDispositions();
    List<Concept> dispositionsToConsider = cd.getDispositionsToConsider();
    String sql = "select distinct v.patient_id " + "from visit v " + "inner join encounter exit_encounter " + " on exit_encounter.visit_id = v.visit_id " + " and exit_encounter.voided = false " + " and exit_encounter.encounter_type = :exitEncounterType " + " and exit_encounter.encounter_datetime between :exitOnOrAfter and :exitOnOrBefore ";
    if (exitFromWard != null) {
        sql += " and exit_encounter.location_id = :exitFromWard ";
    }
    sql += "inner join encounter obs_encounter " + " on obs_encounter.visit_id = v.visit_id " + " and obs_encounter.encounter_id = (" + "   select find_obs_encounter.encounter_id " + "   from encounter find_obs_encounter " + "   inner join obs has_obs " + "     on has_obs.encounter_id = find_obs_encounter.encounter_id " + "     and has_obs.voided = false " + "     and has_obs.concept_id = :dispositionConcept ";
    if (dispositionsToConsider != null) {
        sql += "     and has_obs.value_coded in (:dispositionsToConsider) ";
    }
    sql += "    where find_obs_encounter.visit_id = v.visit_id " + "     and find_obs_encounter.voided = false " + "    order by find_obs_encounter.encounter_datetime desc, find_obs_encounter.date_created desc limit 1 " + // "     and find_obs_encounter.location_id = :exitFromWard " +
    " )" + "inner join obs o " + " on o.voided = false " + " and o.concept_id = :dispositionConcept " + " and o.encounter_id = obs_encounter.encounter_id " + "where v.voided = false " + " and o.value_coded in (:dispositions) ";
    SQLQuery query = sessionFactory.getCurrentSession().createSQLQuery(sql);
    query.setInteger("dispositionConcept", dispositionService.getDispositionDescriptor().getDispositionConcept().getId());
    query.setParameterList("dispositions", idList(dispositions));
    query.setInteger("exitEncounterType", emrApiProperties.getExitFromInpatientEncounterType().getId());
    query.setTimestamp("exitOnOrAfter", cd.getExitOnOrAfter());
    query.setTimestamp("exitOnOrBefore", cd.getExitOnOrBefore());
    if (exitFromWard != null) {
        query.setInteger("exitFromWard", exitFromWard.getId());
    }
    if (dispositionsToConsider != null) {
        query.setParameterList("dispositionsToConsider", idList(dispositionsToConsider));
    }
    Cohort c = new Cohort();
    for (Integer i : (List<Integer>) query.list()) {
        c.addMember(i);
    }
    return new EvaluatedCohort(c, cohortDefinition, context);
}
Also used : Concept(org.openmrs.Concept) Cohort(org.openmrs.Cohort) EvaluatedCohort(org.openmrs.module.reporting.cohort.EvaluatedCohort) EvaluatedCohort(org.openmrs.module.reporting.cohort.EvaluatedCohort) ArrayList(java.util.ArrayList) List(java.util.List) LastDispositionBeforeExitCohortDefinition(org.openmrs.module.pihcore.reporting.cohort.definition.LastDispositionBeforeExitCohortDefinition) SQLQuery(org.hibernate.SQLQuery) Location(org.openmrs.Location)

Aggregations

Location (org.openmrs.Location)3 LastDispositionBeforeExitCohortDefinition (org.openmrs.module.pihcore.reporting.cohort.definition.LastDispositionBeforeExitCohortDefinition)3 Date (java.util.Date)2 Concept (org.openmrs.Concept)2 EvaluatedCohort (org.openmrs.module.reporting.cohort.EvaluatedCohort)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 SQLQuery (org.hibernate.SQLQuery)1 Test (org.junit.Test)1 Cohort (org.openmrs.Cohort)1 BaseInpatientReportTest (org.openmrs.module.pihcore.reporting.BaseInpatientReportTest)1 MappedParametersCohortDefinition (org.openmrs.module.reporting.cohort.definition.MappedParametersCohortDefinition)1 EvaluationContext (org.openmrs.module.reporting.evaluation.EvaluationContext)1 Parameter (org.openmrs.module.reporting.evaluation.parameter.Parameter)1