Search in sources :

Example 1 with EncounterType

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

the class RedirectToDeathNoteIfMissing method hasDeathCertificateEncounter.

private boolean hasDeathCertificateEncounter(Patient patient) {
    EncounterService encounterService = Context.getEncounterService();
    EncounterType deathCertificateEncounterType = Context.getEncounterService().getEncounterTypeByUuid(PihCoreConstants.DEATH_CERTIFICATE_ENCOUNTER_TYPE_UUID);
    List<Encounter> deathCertificateEncounters = encounterService.getEncounters(patient, null, null, null, null, Arrays.asList(deathCertificateEncounterType), null, null, null, false);
    return deathCertificateEncounters.size() > 0;
}
Also used : Encounter(org.openmrs.Encounter) EncounterType(org.openmrs.EncounterType) EncounterService(org.openmrs.api.EncounterService)

Example 2 with EncounterType

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

the class PihPatientMergeActions method voidMostRecentRegistrationIfNonPreferred.

private void voidMostRecentRegistrationIfNonPreferred(Patient preferred, Patient nonPreferred) {
    EncounterType registrationEncounterType = encounterService.getEncounterTypeByUuid(EncounterTypes.PATIENT_REGISTRATION.uuid());
    // the getEncounters method returns encounters sorted by date
    List<Encounter> preferredRegistrations = encounterService.getEncounters(preferred, null, null, null, null, Collections.singleton(registrationEncounterType), null, null, null, false);
    List<Encounter> nonPreferredRegistrations = encounterService.getEncounters(nonPreferred, null, null, null, null, Collections.singleton(registrationEncounterType), null, null, null, false);
    Encounter mostRecentPreferredRegistration = (preferredRegistrations != null && preferredRegistrations.size() > 0) ? preferredRegistrations.get(preferredRegistrations.size() - 1) : null;
    if (nonPreferredRegistrations != null && mostRecentPreferredRegistration != null) {
        for (Encounter nonPreferredRegistration : nonPreferredRegistrations) {
            if (nonPreferredRegistration.getEncounterDatetime().after(mostRecentPreferredRegistration.getEncounterDatetime())) {
                encounterService.voidEncounter(nonPreferredRegistration, "merging into patient " + preferred.getId() + ": voiding most recent registration encounter on non-preferred patient");
            }
        }
    }
}
Also used : Encounter(org.openmrs.Encounter) EncounterType(org.openmrs.EncounterType)

Example 3 with EncounterType

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

use of org.openmrs.EncounterType in project openmrs-core by openmrs.

the class HibernateEncounterDAO method getEncounterType.

/**
 * @see org.openmrs.api.EncounterService#getEncounterType(java.lang.String)
 */
@Override
public EncounterType getEncounterType(String name) throws DAOException {
    Criteria crit = sessionFactory.getCurrentSession().createCriteria(EncounterType.class);
    crit.add(Restrictions.eq("retired", false));
    crit.add(Restrictions.eq("name", name));
    return (EncounterType) crit.uniqueResult();
}
Also used : Criteria(org.hibernate.Criteria) EncounterSearchCriteria(org.openmrs.parameter.EncounterSearchCriteria) EncounterType(org.openmrs.EncounterType)

Example 5 with EncounterType

use of org.openmrs.EncounterType in project openmrs-core by openmrs.

the class EncounterValidatorTest method validate_shouldFailValidationIfFieldLengthsAreNotCorrect.

/**
 * @see EncounterValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() {
    encounter.setEncounterType(new EncounterType());
    encounter.setPatient(new Patient());
    encounter.setEncounterDatetime(new Date());
    encounter.setVoidReason("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
    encounterValidator.validate(encounter, errors);
    Assert.assertTrue(errors.hasFieldErrors("voidReason"));
}
Also used : Patient(org.openmrs.Patient) EncounterType(org.openmrs.EncounterType) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

EncounterType (org.openmrs.EncounterType)60 Test (org.junit.Test)44 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)42 Encounter (org.openmrs.Encounter)19 Date (java.util.Date)17 Location (org.openmrs.Location)12 Patient (org.openmrs.Patient)10 User (org.openmrs.User)10 EncounterRole (org.openmrs.EncounterRole)9 Provider (org.openmrs.Provider)8 BindException (org.springframework.validation.BindException)7 Errors (org.springframework.validation.Errors)7 ArrayList (java.util.ArrayList)5 GlobalProperty (org.openmrs.GlobalProperty)5 List (java.util.List)4 Privilege (org.openmrs.Privilege)4 Concept (org.openmrs.Concept)3 Visit (org.openmrs.Visit)3 HashMap (java.util.HashMap)2 SQLQuery (org.hibernate.SQLQuery)2