Search in sources :

Example 1 with DiedSoonAfterEncounterCohortDefinition

use of org.openmrs.module.pihcore.reporting.cohort.definition.DiedSoonAfterEncounterCohortDefinition 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 2 with DiedSoonAfterEncounterCohortDefinition

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

the class DiedSoonAfterEncounterCohortDefinitionEvaluator method evaluate.

@Override
public EvaluatedCohort evaluate(CohortDefinition def, EvaluationContext context) throws EvaluationException {
    DiedSoonAfterEncounterCohortDefinition cohortDefinition = (DiedSoonAfterEncounterCohortDefinition) def;
    String sql = " select distinct p.patient_id \n" + " from patient p \n" + " inner join person per \n" + "   on p.patient_id = per.person_id \n" + "   and per.voided = false \n" + " inner join encounter admit \n" + "   on admit.patient_id = p.patient_id \n" + "   and admit.encounter_type = :encounterType \n" + // was mysql-specific "   and admit.encounter_datetime > DATE_SUB(per.death_date, INTERVAL :windowInHours HOUR) \n" +
    "   and admit.encounter_datetime > TIMESTAMPADD(HOUR, -:windowInHours, per.death_date) \n" + " where per.death_date between :diedOnOrAfter and :diedOnOrBefore \n" + "   and p.voided = false ";
    SQLQuery query = sessionFactory.getCurrentSession().createSQLQuery(sql);
    query.setTimestamp("diedOnOrAfter", cohortDefinition.getDiedOnOrAfter());
    query.setTimestamp("diedOnOrBefore", cohortDefinition.getDiedOnOrBefore());
    query.setInteger("encounterType", cohortDefinition.getEncounterType().getId());
    query.setInteger("windowInHours", cohortDefinition.getWindowInHours());
    Cohort c = new Cohort();
    for (Integer i : (List<Integer>) query.list()) {
        c.addMember(i);
    }
    return new EvaluatedCohort(c, cohortDefinition, context);
}
Also used : EvaluatedCohort(org.openmrs.module.reporting.cohort.EvaluatedCohort) Cohort(org.openmrs.Cohort) DiedSoonAfterEncounterCohortDefinition(org.openmrs.module.pihcore.reporting.cohort.definition.DiedSoonAfterEncounterCohortDefinition) EvaluatedCohort(org.openmrs.module.reporting.cohort.EvaluatedCohort) List(java.util.List) SQLQuery(org.hibernate.SQLQuery)

Example 3 with DiedSoonAfterEncounterCohortDefinition

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

the class PihCohortDefinitionLibrary method getDiedSoonAfterAdmissionDuringPeriod.

@DocumentedDefinition(value = "diedSoonAfterAdmissionDuringPeriod")
public CohortDefinition getDiedSoonAfterAdmissionDuringPeriod() {
    DiedSoonAfterEncounterCohortDefinition cd = new DiedSoonAfterEncounterCohortDefinition();
    cd.setEncounterType(emrApiProperties.getAdmissionEncounterType());
    cd.addParameter(new Parameter("diedOnOrAfter", "mirebalaisreports.parameter.diedOnOrAfter", Date.class));
    cd.addParameter(new Parameter("diedOnOrBefore", "mirebalaisreports.parameter.diedOnOrBefore", Date.class));
    return new MappedParametersCohortDefinition(cd, "diedOnOrAfter", "startDate", "diedOnOrBefore", "endDate");
}
Also used : DiedSoonAfterEncounterCohortDefinition(org.openmrs.module.pihcore.reporting.cohort.definition.DiedSoonAfterEncounterCohortDefinition) Parameter(org.openmrs.module.reporting.evaluation.parameter.Parameter) Date(java.util.Date) MappedParametersCohortDefinition(org.openmrs.module.reporting.cohort.definition.MappedParametersCohortDefinition) DocumentedDefinition(org.openmrs.module.reporting.definition.library.DocumentedDefinition)

Aggregations

DiedSoonAfterEncounterCohortDefinition (org.openmrs.module.pihcore.reporting.cohort.definition.DiedSoonAfterEncounterCohortDefinition)3 Date (java.util.Date)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 Concept (org.openmrs.Concept)1 EncounterType (org.openmrs.EncounterType)1 Location (org.openmrs.Location)1 AdmissionSoonAfterExitCohortDefinition (org.openmrs.module.pihcore.reporting.cohort.definition.AdmissionSoonAfterExitCohortDefinition)1 LastDispositionBeforeExitCohortDefinition (org.openmrs.module.pihcore.reporting.cohort.definition.LastDispositionBeforeExitCohortDefinition)1 EvaluatedCohort (org.openmrs.module.reporting.cohort.EvaluatedCohort)1 EncounterCohortDefinition (org.openmrs.module.reporting.cohort.definition.EncounterCohortDefinition)1 MappedParametersCohortDefinition (org.openmrs.module.reporting.cohort.definition.MappedParametersCohortDefinition)1 CohortIndicatorDataSetDefinition (org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition)1 DocumentedDefinition (org.openmrs.module.reporting.definition.library.DocumentedDefinition)1