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