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()));
}
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");
}
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);
}
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");
}
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()));
}
Aggregations