Search in sources :

Example 1 with InpatientTransferCohortDefinition

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

the class InpatientTransferCohortDefinitionEvaluatorTest method testEvaluateTransferIn.

@Test
public void testEvaluateTransferIn() throws Exception {
    Location surgicalWard = locationService.getLocation("Sal Aprè Operasyon");
    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");
    InpatientTransferCohortDefinition definition = new InpatientTransferCohortDefinition();
    definition.setOnOrAfter(startDate);
    definition.setOnOrBefore(endDate);
    definition.setInToWard(surgicalWard);
    EvaluatedCohort result = cohortDefinitionService.evaluate(definition, new EvaluationContext());
    assertThat(result, isCohortWithExactlyIds(patient5.getId()));
}
Also used : EvaluatedCohort(org.openmrs.module.reporting.cohort.EvaluatedCohort) EvaluationContext(org.openmrs.module.reporting.evaluation.EvaluationContext) Date(java.util.Date) InpatientTransferCohortDefinition(org.openmrs.module.pihcore.reporting.cohort.definition.InpatientTransferCohortDefinition) Location(org.openmrs.Location) BaseInpatientReportTest(org.openmrs.module.pihcore.reporting.BaseInpatientReportTest) Test(org.junit.Test)

Example 2 with InpatientTransferCohortDefinition

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

the class PihCohortDefinitionLibrary method getTransferInToLocationDuringPeriod.

@DocumentedDefinition(value = "transferInToLocationDuringPeriod")
public CohortDefinition getTransferInToLocationDuringPeriod() {
    InpatientTransferCohortDefinition cd = new InpatientTransferCohortDefinition();
    cd.addParameter(new Parameter("onOrAfter", "reporting.parameter.onOrAfter", Date.class));
    cd.addParameter(new Parameter("onOrBefore", "reporting.parameter.onOrBefore", Date.class));
    cd.addParameter(new Parameter("inToWard", "mirebalaisreports.parameter.inToWard", Location.class));
    return new MappedParametersCohortDefinition(cd, "onOrAfter", "startDate", "onOrBefore", "endDate", "inToWard", "location");
}
Also used : Parameter(org.openmrs.module.reporting.evaluation.parameter.Parameter) InpatientTransferCohortDefinition(org.openmrs.module.pihcore.reporting.cohort.definition.InpatientTransferCohortDefinition) Date(java.util.Date) Location(org.openmrs.Location) MappedParametersCohortDefinition(org.openmrs.module.reporting.cohort.definition.MappedParametersCohortDefinition) DocumentedDefinition(org.openmrs.module.reporting.definition.library.DocumentedDefinition)

Example 3 with InpatientTransferCohortDefinition

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

the class InpatientTransferCohortDefinitionEvaluator method evaluate.

@Override
public EvaluatedCohort evaluate(CohortDefinition cohortDefinition, EvaluationContext context) throws EvaluationException {
    InpatientTransferCohortDefinition cd = (InpatientTransferCohortDefinition) cohortDefinition;
    Location outOfWard = cd.getOutOfWard();
    Location inToWard = cd.getInToWard();
    if (inToWard == null && outOfWard == null) {
        throw new IllegalArgumentException("Must specify outOfWard and/or inToWard");
    }
    Location visitLocation = adtService.getLocationThatSupportsVisits(outOfWard != null ? outOfWard : inToWard);
    if (visitLocation == null) {
        throw new IllegalArgumentException(outOfWard + " and its ancestor locations don't support visits");
    }
    EncounterType admissionEncounterType = emrApiProperties.getAdmissionEncounterType();
    EncounterType dischargeEncounterType = emrApiProperties.getExitFromInpatientEncounterType();
    EncounterType transferEncounterType = emrApiProperties.getTransferWithinHospitalEncounterType();
    String sql = "select distinct v.patient_id " + "from visit v " + "inner join encounter admission " + "  on v.visit_id = admission.visit_id " + "  and admission.voided = false " + "  and admission.encounter_type = :admissionEncounterType " + "  and admission.encounter_datetime <= :onOrBefore " + "inner join encounter transfer " + "  on v.visit_id = transfer.visit_id " + "  and transfer.voided = false " + "  and transfer.encounter_type = :transferEncounterType " + "  and transfer.encounter_datetime between :onOrAfter and :onOrBefore " + "  and transfer.encounter_datetime > admission.encounter_datetime ";
    if (inToWard != null) {
        sql += " and transfer.location_id = :inToWard ";
    }
    sql += "inner join encounter adtBeforeTransfer " + "  on v.visit_id = adtBeforeTransfer.visit_id " + "  and adtBeforeTransfer.voided = false " + "  and adtBeforeTransfer.encounter_type in (:adtEncounterTypes) " + "  and adtBeforeTransfer.encounter_id = ( " + "    select encounter_id " + "    from encounter " + "    where visit_id = v.visit_id " + "    and voided = false " + "    and encounter_type in (:adtEncounterTypes) " + "    and encounter_datetime < transfer.encounter_datetime " + "    order by encounter_datetime desc, date_created desc limit 1" + "  ) " + "where v.voided = false" + "  and v.location_id = :visitLocation " + "  and adtBeforeTransfer.encounter_type in (:admitOrTransferEncounterTypes)";
    if (outOfWard != null) {
        sql += "  and adtBeforeTransfer.location_id = :outOfWard ";
    }
    SQLQuery query = sessionFactory.getCurrentSession().createSQLQuery(sql);
    query.setInteger("admissionEncounterType", admissionEncounterType.getId());
    query.setInteger("transferEncounterType", transferEncounterType.getId());
    query.setTimestamp("onOrBefore", cd.getOnOrBefore());
    query.setTimestamp("onOrAfter", cd.getOnOrAfter());
    query.setInteger("visitLocation", visitLocation.getId());
    if (outOfWard != null) {
        query.setInteger("outOfWard", outOfWard.getId());
    }
    if (inToWard != null) {
        query.setInteger("inToWard", inToWard.getId());
    }
    query.setParameterList("adtEncounterTypes", new Integer[] { admissionEncounterType.getId(), dischargeEncounterType.getId(), transferEncounterType.getId() });
    query.setParameterList("admitOrTransferEncounterTypes", new Integer[] { admissionEncounterType.getId(), transferEncounterType.getId() });
    Cohort c = new Cohort();
    for (Integer i : (List<Integer>) query.list()) {
        c.addMember(i);
    }
    return new EvaluatedCohort(c, cohortDefinition, context);
}
Also used : Cohort(org.openmrs.Cohort) EvaluatedCohort(org.openmrs.module.reporting.cohort.EvaluatedCohort) EvaluatedCohort(org.openmrs.module.reporting.cohort.EvaluatedCohort) List(java.util.List) EncounterType(org.openmrs.EncounterType) SQLQuery(org.hibernate.SQLQuery) InpatientTransferCohortDefinition(org.openmrs.module.pihcore.reporting.cohort.definition.InpatientTransferCohortDefinition) Location(org.openmrs.Location)

Example 4 with InpatientTransferCohortDefinition

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

the class PihCohortDefinitionLibrary method getTransferOutOfLocationDuringPeriod.

@DocumentedDefinition(value = "transferOutOfLocationDuringPeriod")
public CohortDefinition getTransferOutOfLocationDuringPeriod() {
    InpatientTransferCohortDefinition cd = new InpatientTransferCohortDefinition();
    cd.addParameter(new Parameter("onOrAfter", "reporting.parameter.onOrAfter", Date.class));
    cd.addParameter(new Parameter("onOrBefore", "reporting.parameter.onOrBefore", Date.class));
    cd.addParameter(new Parameter("outOfWard", "mirebalaisreports.parameter.outOfWard", Location.class));
    return new MappedParametersCohortDefinition(cd, "onOrAfter", "startDate", "onOrBefore", "endDate", "outOfWard", "location");
}
Also used : Parameter(org.openmrs.module.reporting.evaluation.parameter.Parameter) InpatientTransferCohortDefinition(org.openmrs.module.pihcore.reporting.cohort.definition.InpatientTransferCohortDefinition) Date(java.util.Date) Location(org.openmrs.Location) MappedParametersCohortDefinition(org.openmrs.module.reporting.cohort.definition.MappedParametersCohortDefinition) DocumentedDefinition(org.openmrs.module.reporting.definition.library.DocumentedDefinition)

Example 5 with InpatientTransferCohortDefinition

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

the class InpatientTransferCohortDefinitionEvaluatorTest method testEvaluateTransferOut.

@Test
public void testEvaluateTransferOut() throws Exception {
    Location womensInternalMedicine = locationService.getLocation("Sal Fanm");
    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");
    InpatientTransferCohortDefinition definition = new InpatientTransferCohortDefinition();
    definition.setOnOrAfter(startDate);
    definition.setOnOrBefore(endDate);
    definition.setOutOfWard(womensInternalMedicine);
    EvaluatedCohort result = cohortDefinitionService.evaluate(definition, new EvaluationContext());
    assertThat(result, isCohortWithExactlyIds(patient5.getId()));
}
Also used : EvaluatedCohort(org.openmrs.module.reporting.cohort.EvaluatedCohort) EvaluationContext(org.openmrs.module.reporting.evaluation.EvaluationContext) Date(java.util.Date) InpatientTransferCohortDefinition(org.openmrs.module.pihcore.reporting.cohort.definition.InpatientTransferCohortDefinition) Location(org.openmrs.Location) BaseInpatientReportTest(org.openmrs.module.pihcore.reporting.BaseInpatientReportTest) Test(org.junit.Test)

Aggregations

Location (org.openmrs.Location)5 InpatientTransferCohortDefinition (org.openmrs.module.pihcore.reporting.cohort.definition.InpatientTransferCohortDefinition)5 Date (java.util.Date)4 EvaluatedCohort (org.openmrs.module.reporting.cohort.EvaluatedCohort)3 Test (org.junit.Test)2 BaseInpatientReportTest (org.openmrs.module.pihcore.reporting.BaseInpatientReportTest)2 MappedParametersCohortDefinition (org.openmrs.module.reporting.cohort.definition.MappedParametersCohortDefinition)2 DocumentedDefinition (org.openmrs.module.reporting.definition.library.DocumentedDefinition)2 EvaluationContext (org.openmrs.module.reporting.evaluation.EvaluationContext)2 Parameter (org.openmrs.module.reporting.evaluation.parameter.Parameter)2 List (java.util.List)1 SQLQuery (org.hibernate.SQLQuery)1 Cohort (org.openmrs.Cohort)1 EncounterType (org.openmrs.EncounterType)1