Search in sources :

Example 86 with Location

use of org.openmrs.Location 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 87 with Location

use of org.openmrs.Location in project openmrs-module-pihcore by PIH.

the class PihCohortDefinitionLibrary method getDiedExitFromLocationDuringPeriodSoonAfterAdmission.

@DocumentedDefinition(value = "diedExitFromLocationDuringPeriodSoonAfterAdmission")
public CohortDefinition getDiedExitFromLocationDuringPeriodSoonAfterAdmission() {
    CohortDefinition diedSoonAfterAdmission = getDiedSoonAfterAdmissionDuringPeriod();
    CohortDefinition diedExit = getDiedExitFromLocationDuringPeriod();
    CompositionCohortDefinition deathsEarly = new CompositionCohortDefinition();
    deathsEarly.addParameter(parameter(Date.class, "startDate"));
    deathsEarly.addParameter(parameter(Date.class, "endDate"));
    deathsEarly.addParameter(parameter(Location.class, "location"));
    deathsEarly.addSearch("died", Mapped.mapStraightThrough(diedExit));
    deathsEarly.addSearch("diedSoon", Mapped.mapStraightThrough(diedSoonAfterAdmission));
    deathsEarly.setCompositionString("died AND diedSoon");
    return diedExit;
}
Also used : CompositionCohortDefinition(org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition) PersonAttributeCohortDefinition(org.openmrs.module.reporting.cohort.definition.PersonAttributeCohortDefinition) EncounterCohortDefinition(org.openmrs.module.reporting.cohort.definition.EncounterCohortDefinition) DiedSoonAfterEncounterCohortDefinition(org.openmrs.module.pihcore.reporting.cohort.definition.DiedSoonAfterEncounterCohortDefinition) LastDispositionBeforeExitCohortDefinition(org.openmrs.module.pihcore.reporting.cohort.definition.LastDispositionBeforeExitCohortDefinition) InpatientLocationCohortDefinition(org.openmrs.module.pihcore.reporting.cohort.definition.InpatientLocationCohortDefinition) DiagnosisCohortDefinition(org.openmrs.module.pihcore.reporting.cohort.definition.DiagnosisCohortDefinition) MappedParametersCohortDefinition(org.openmrs.module.reporting.cohort.definition.MappedParametersCohortDefinition) CohortDefinition(org.openmrs.module.reporting.cohort.definition.CohortDefinition) EncounterWithCodedObsCohortDefinition(org.openmrs.module.reporting.cohort.definition.EncounterWithCodedObsCohortDefinition) InpatientTransferCohortDefinition(org.openmrs.module.pihcore.reporting.cohort.definition.InpatientTransferCohortDefinition) CompositionCohortDefinition(org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition) Date(java.util.Date) Location(org.openmrs.Location) DocumentedDefinition(org.openmrs.module.reporting.definition.library.DocumentedDefinition)

Example 88 with Location

use of org.openmrs.Location in project openmrs-module-pihcore by PIH.

the class PihCohortDefinitionLibrary method getClinicalCheckInAtLocation.

@DocumentedDefinition(value = "clinicalCheckInAtLocation")
public CohortDefinition getClinicalCheckInAtLocation() {
    EncounterWithCodedObsCohortDefinition cd = new EncounterWithCodedObsCohortDefinition();
    cd.addParameter(new Parameter("onOrAfter", "reporting.parameter.onOrAfter", Date.class));
    cd.addParameter(new Parameter("onOrBefore", "reporting.parameter.onOrBefore", Date.class));
    cd.addParameter(new Parameter("locationList", "reporting.parameter.locationList", Location.class));
    cd.addEncounterType(encounterService.getEncounterTypeByUuid(PihEmrConfigConstants.ENCOUNTERTYPE_CHECK_IN_UUID));
    cd.setConcept(conceptService.getConceptByMapping("Type of HUM visit", "PIH"));
    cd.addIncludeCodedValue(conceptService.getConceptByMapping("CLINICAL", "PIH"));
    return new MappedParametersCohortDefinition(cd, "onOrAfter", "startDate", "onOrBefore", "endDate", "locationList", "location");
}
Also used : Parameter(org.openmrs.module.reporting.evaluation.parameter.Parameter) EncounterWithCodedObsCohortDefinition(org.openmrs.module.reporting.cohort.definition.EncounterWithCodedObsCohortDefinition) 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 89 with Location

use of org.openmrs.Location in project openmrs-module-pihcore by PIH.

the class InpatientStatsDailyDataSetManager method constructDataSetDefinition.

@Override
public DataSetDefinition constructDataSetDefinition(DataSetDescriptor dataSetDescriptor, File file) {
    List<Location> inpatientLocations = adtService.getInpatientLocations();
    EncounterType admissionEncounterType = encounterService.getEncounterTypeByUuid(PihEmrConfigConstants.ENCOUNTERTYPE_ADMISSION_UUID);
    Concept dischargedDisposition = conceptService.getConceptByMapping("DISCHARGED", "PIH");
    Concept deathDisposition = conceptService.getConceptByMapping("DEATH", "PIH");
    Concept transferOutDisposition = conceptService.getConceptByMapping("Transfer out of hospital", "PIH");
    Concept leftWithoutCompletionOfTreatmentDisposition = conceptService.getConceptByMapping("Departed without medical discharge", "PIH");
    Concept leftWithoutSeeingClinicianDisposition = conceptService.getConceptByMapping("Left without seeing a clinician", "PIH");
    List<Concept> dispositionsToConsider = Arrays.asList(dischargedDisposition, deathDisposition, transferOutDisposition, leftWithoutCompletionOfTreatmentDisposition, leftWithoutSeeingClinicianDisposition);
    // Dispositions we're currently ignoring: "Transfer within hospital", "Admit to hospital", "Discharged", "Emergency Department observation", "Home"
    CohortIndicatorDataSetDefinition cohortDsd = new CohortIndicatorDataSetDefinition();
    cohortDsd.addParameter(getStartDateParameter());
    cohortDsd.addParameter(getEndDateParameter());
    DiedSoonAfterEncounterCohortDefinition diedSoonAfterAdmission = new DiedSoonAfterEncounterCohortDefinition();
    diedSoonAfterAdmission.setEncounterType(admissionEncounterType);
    diedSoonAfterAdmission.addParameter(new Parameter("diedOnOrAfter", "Died on or after", Date.class));
    diedSoonAfterAdmission.addParameter(new Parameter("diedOnOrBefore", "Died on or before", Date.class));
    for (Location location : inpatientLocations) {
        addIndicator(cohortDsd, "censusAtStart", "Census at start", location, Mapped.map(pihCohorts.getInpatientAtLocationOnDate(), "date=${startDate}"));
        addIndicator(cohortDsd, "censusAtEnd", "Census at end", location, Mapped.map(pihCohorts.getInpatientAtLocationOnDate(), "date=${endDate}"));
        addIndicator(cohortDsd, "admissions", "Admission", location, Mapped.mapStraightThrough(pihCohorts.getAdmissionAtLocationDuringPeriod()));
        addIndicator(cohortDsd, "transfersIn", "Transfer In", location, Mapped.mapStraightThrough(pihCohorts.getTransferInToLocationDuringPeriod()));
        addIndicator(cohortDsd, "transfersOut", "Transfer Out", location, Mapped.mapStraightThrough(pihCohorts.getTransferOutOfLocationDuringPeriod()));
        addIndicator(cohortDsd, "discharged", "Discharged", location, Mapped.mapStraightThrough(pihCohorts.getDischargeExitFromLocationDuringPeriod()));
        addIndicator(cohortDsd, "deathsWithin48", "Deaths within 48h", location, Mapped.mapStraightThrough(pihCohorts.getDiedExitFromLocationDuringPeriodSoonAfterAdmission()));
        addIndicator(cohortDsd, "deathsAfter48", "Deaths after 48h", location, Mapped.mapStraightThrough(pihCohorts.getDiedExitFromLocationDuringPeriodNotSoonAfterAdmission()));
        addIndicator(cohortDsd, "transfersOutOfHUM", "Transfer Outs", location, Mapped.mapStraightThrough(pihCohorts.getTransferOutOfHumExitFromLocationDuringPeriod()));
        // number left without completing treatment
        LastDispositionBeforeExitCohortDefinition leftWithoutCompletingTreatment = new LastDispositionBeforeExitCohortDefinition();
        leftWithoutCompletingTreatment.addParameter(new Parameter("exitOnOrAfter", "Exit on or after", Date.class));
        leftWithoutCompletingTreatment.addParameter(new Parameter("exitOnOrBefore", "Exit on or before", Date.class));
        leftWithoutCompletingTreatment.setExitFromWard(location);
        leftWithoutCompletingTreatment.setDispositionsToConsider(dispositionsToConsider);
        leftWithoutCompletingTreatment.addDisposition(leftWithoutCompletionOfTreatmentDisposition);
        addIndicator(cohortDsd, "leftWithoutCompletingTx", "Left Without Completing Treatment", location, Mapped.map(leftWithoutCompletingTreatment, "exitOnOrAfter=${startDate},exitOnOrBefore=${endDate}"));
        LastDispositionBeforeExitCohortDefinition leftWithoutSeeingClinician = new LastDispositionBeforeExitCohortDefinition();
        leftWithoutSeeingClinician.addParameter(new Parameter("exitOnOrAfter", "Exit on or after", Date.class));
        leftWithoutSeeingClinician.addParameter(new Parameter("exitOnOrBefore", "Exit on or before", Date.class));
        leftWithoutSeeingClinician.setExitFromWard(location);
        leftWithoutSeeingClinician.setDispositionsToConsider(dispositionsToConsider);
        leftWithoutSeeingClinician.addDisposition(leftWithoutSeeingClinicianDisposition);
        addIndicator(cohortDsd, "leftWithoutSeeingClinician", "Left Without Seeing Clinician", location, Mapped.map(leftWithoutSeeingClinician, "exitOnOrAfter=${startDate},exitOnOrBefore=${endDate}"));
    }
    // number of ED check-ins
    // TODO change this to count by visits or by encounters, instead of by patients
    EncounterCohortDefinition edCheckIn = new EncounterCohortDefinition();
    edCheckIn.addParameter(new Parameter("onOrAfter", "On or after", Date.class));
    edCheckIn.addParameter(new Parameter("onOrBefore", "On or before", Date.class));
    edCheckIn.addEncounterType(encounterService.getEncounterTypeByUuid(PihEmrConfigConstants.ENCOUNTERTYPE_CHECK_IN_UUID));
    edCheckIn.addLocation(locationService.getLocationByUuid(EMERGENCY_DEPARTMENT_UUID));
    edCheckIn.addLocation(locationService.getLocationByUuid(EMERGENCY_RECEPTION_UUID));
    addIndicator(cohortDsd, "edcheckin", "ED Check In", Mapped.map(edCheckIn, "onOrAfter=${startDate},onOrBefore=${endDate}"));
    // number of surgical op-notes entered
    EncounterCohortDefinition surgicalNotes = new EncounterCohortDefinition();
    surgicalNotes.addParameter(new Parameter("onOrAfter", "On or after", Date.class));
    surgicalNotes.addParameter(new Parameter("onOrBefore", "On or before", Date.class));
    surgicalNotes.addEncounterType(encounterService.getEncounterTypeByUuid(PihEmrConfigConstants.ENCOUNTERTYPE_POST_OPERATIVE_NOTE_UUID));
    addIndicator(cohortDsd, "orvolume", "OR Volume", Mapped.map(surgicalNotes, "onOrAfter=${startDate},onOrBefore=${endDate}"));
    // potential readmissions
    AdmissionSoonAfterExitCohortDefinition readmission = new AdmissionSoonAfterExitCohortDefinition();
    readmission.addParameter(new Parameter("onOrAfter", "On or after", Date.class));
    readmission.addParameter(new Parameter("onOrBefore", "On or before", Date.class));
    addIndicator(cohortDsd, "possiblereadmission", "Possible Readmission", Mapped.map(readmission, "onOrAfter=${startDate},onOrBefore=${endDate}"));
    return cohortDsd;
}
Also used : Concept(org.openmrs.Concept) AdmissionSoonAfterExitCohortDefinition(org.openmrs.module.pihcore.reporting.cohort.definition.AdmissionSoonAfterExitCohortDefinition) CohortIndicatorDataSetDefinition(org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition) DiedSoonAfterEncounterCohortDefinition(org.openmrs.module.pihcore.reporting.cohort.definition.DiedSoonAfterEncounterCohortDefinition) Parameter(org.openmrs.module.reporting.evaluation.parameter.Parameter) LastDispositionBeforeExitCohortDefinition(org.openmrs.module.pihcore.reporting.cohort.definition.LastDispositionBeforeExitCohortDefinition) EncounterType(org.openmrs.EncounterType) Date(java.util.Date) EncounterCohortDefinition(org.openmrs.module.reporting.cohort.definition.EncounterCohortDefinition) DiedSoonAfterEncounterCohortDefinition(org.openmrs.module.pihcore.reporting.cohort.definition.DiedSoonAfterEncounterCohortDefinition) Location(org.openmrs.Location)

Example 90 with Location

use of org.openmrs.Location 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)

Aggregations

Location (org.openmrs.Location)235 Test (org.junit.Test)161 Date (java.util.Date)80 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)74 Patient (org.openmrs.Patient)66 Encounter (org.openmrs.Encounter)38 SimpleObject (org.openmrs.ui.framework.SimpleObject)32 PatientIdentifierType (org.openmrs.PatientIdentifierType)31 VisitDomainWrapper (org.openmrs.module.emrapi.visit.VisitDomainWrapper)31 Visit (org.openmrs.Visit)28 AppContextModel (org.openmrs.module.appframework.context.AppContextModel)28 Obs (org.openmrs.Obs)27 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)27 PatientIdentifier (org.openmrs.PatientIdentifier)26 Concept (org.openmrs.Concept)19 EncounterType (org.openmrs.EncounterType)18 DateTime (org.joda.time.DateTime)17 ArrayList (java.util.ArrayList)15 VisitContextModel (org.openmrs.module.coreapps.contextmodel.VisitContextModel)15 BindException (org.springframework.validation.BindException)15