Search in sources :

Example 1 with EncounterService

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

use of org.openmrs.api.EncounterService in project openmrs-core by openmrs.

the class ObsServiceImpl method getObservations.

/**
 * This implementation queries the obs table comparing the given <code>searchString</code> with
 * the patient's identifier, encounterId, and obsId
 *
 * @see org.openmrs.api.ObsService#getObservations(java.lang.String)
 */
@Override
@Transactional(readOnly = true)
public List<Obs> getObservations(String searchString) {
    // search on patient identifier
    PatientService ps = Context.getPatientService();
    List<Patient> patients = ps.getPatients(searchString);
    List<Person> persons = new ArrayList<>(patients);
    // try to search on encounterId
    EncounterService es = Context.getEncounterService();
    List<Encounter> encounters = new ArrayList<>();
    try {
        Encounter e = es.getEncounter(Integer.valueOf(searchString));
        if (e != null) {
            encounters.add(e);
        }
    } catch (NumberFormatException e) {
    // pass
    }
    List<Obs> returnList = new ArrayList<>();
    if (!encounters.isEmpty() || !persons.isEmpty()) {
        returnList = Context.getObsService().getObservations(persons, encounters, null, null, null, null, null, null, null, null, null, false);
    }
    // try to search on obsId
    try {
        Obs o = getObs(Integer.valueOf(searchString));
        if (o != null) {
            returnList.add(o);
        }
    } catch (NumberFormatException e) {
    // pass
    }
    return returnList;
}
Also used : Obs(org.openmrs.Obs) PatientService(org.openmrs.api.PatientService) ArrayList(java.util.ArrayList) Patient(org.openmrs.Patient) Encounter(org.openmrs.Encounter) Person(org.openmrs.Person) EncounterService(org.openmrs.api.EncounterService) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with EncounterService

use of org.openmrs.api.EncounterService in project openmrs-core by openmrs.

the class PatientDataUnvoidHandler method handle.

@Override
public void handle(Patient patient, User originalVoidingUser, Date origParentVoidedDate, String unused) {
    // can't be unvoiding a patient that doesn't exist in the database
    if (patient.getId() != null) {
        // unvoid all the encounter that got voided as a result of the patient getting voided
        EncounterService es = Context.getEncounterService();
        EncounterSearchCriteria encounterSearchCriteria = new EncounterSearchCriteriaBuilder().setPatient(patient).setIncludeVoided(true).createEncounterSearchCriteria();
        List<Encounter> encounters = es.getEncounters(encounterSearchCriteria);
        if (CollectionUtils.isNotEmpty(encounters)) {
            for (Encounter encounter : encounters) {
                if (encounter.getVoided() && encounter.getDateVoided().equals(origParentVoidedDate) && encounter.getVoidedBy().equals(originalVoidingUser)) {
                    es.unvoidEncounter(encounter);
                }
            }
        }
        // unvoid all the orders that got voided as a result of the patient getting voided
        OrderService os = Context.getOrderService();
        List<Order> orders = os.getAllOrdersByPatient(patient);
        if (CollectionUtils.isNotEmpty(orders)) {
            for (Order order : orders) {
                if (order.getVoided() && order.getDateVoided().equals(origParentVoidedDate) && order.getVoidedBy().equals(originalVoidingUser)) {
                    os.unvoidOrder(order);
                }
            }
        }
        CohortService cs = Context.getCohortService();
        cs.notifyPatientUnvoided(patient, originalVoidingUser, origParentVoidedDate);
    }
}
Also used : Order(org.openmrs.Order) CohortService(org.openmrs.api.CohortService) EncounterSearchCriteria(org.openmrs.parameter.EncounterSearchCriteria) EncounterSearchCriteriaBuilder(org.openmrs.parameter.EncounterSearchCriteriaBuilder) Encounter(org.openmrs.Encounter) OrderService(org.openmrs.api.OrderService) EncounterService(org.openmrs.api.EncounterService)

Example 4 with EncounterService

use of org.openmrs.api.EncounterService in project openmrs-core by openmrs.

the class PatientDataVoidHandler method handle.

/**
 * @see org.openmrs.api.handler.VoidHandler#handle(org.openmrs.Voidable, org.openmrs.User,
 *      java.util.Date, java.lang.String)
 * @should void the orders encounters and observations associated with the patient
 */
@Override
public void handle(Patient patient, User voidingUser, Date voidedDate, String voidReason) {
    // void all the encounters associated with this patient
    EncounterService es = Context.getEncounterService();
    List<Encounter> encounters = es.getEncountersByPatient(patient);
    if (CollectionUtils.isNotEmpty(encounters)) {
        for (Encounter encounter : encounters) {
            if (!encounter.getVoided()) {
                // EncounterServiceImpl.voidEncounter and the requiredDataAdvice will set dateVoided to current date
                // if it is null, we need to set it now to match the patient's date voided so that the unvoid
                // handler's logic doesn't fail when comparing dates while unvoiding encounters that were voided
                // with the patient
                encounter.setDateVoided(patient.getDateVoided());
                es.voidEncounter(encounter, voidReason);
            }
        }
    }
    Context.addProxyPrivilege(PrivilegeConstants.EDIT_COHORTS);
    try {
        Context.getCohortService().notifyPatientVoided(patient);
    } finally {
        Context.removeProxyPrivilege(PrivilegeConstants.EDIT_COHORTS);
    }
}
Also used : Encounter(org.openmrs.Encounter) EncounterService(org.openmrs.api.EncounterService)

Example 5 with EncounterService

use of org.openmrs.api.EncounterService in project openmrs-core by openmrs.

the class PatientDataUnvoidHandlerTest method handle_shouldNotUnvoidTheOrdersAndEncountersThatNeverGotVoidedWithThePatient.

/**
 * @see PatientDataUnvoidHandler#handle(Patient,User,Date,String)
 */
@Test
public void handle_shouldNotUnvoidTheOrdersAndEncountersThatNeverGotVoidedWithThePatient() {
    executeDataSet("org/openmrs/api/include/OrderServiceTest-otherEncounters.xml");
    Patient patient = Context.getPatientService().getPatient(7);
    EncounterService es = Context.getEncounterService();
    OrderService os = Context.getOrderService();
    Encounter testEncounter = es.getEncountersByPatient(patient).get(0);
    // santy checks
    assertFalse(testEncounter.getVoided());
    assertNull(testEncounter.getDateVoided());
    assertNull(testEncounter.getVoidedBy());
    assertNull(testEncounter.getVoidReason());
    // void one of the encounter orders be voided at a different time for testing purposes
    assertFalse(testEncounter.getOrders().isEmpty());
    Order testOrder = testEncounter.getOrders().iterator().next();
    assertFalse(testOrder.getVoided());
    Context.getOrderService().voidOrder(testOrder, "testing");
    assertTrue(testOrder.getVoided());
    TestUtil.waitForClockTick();
    // void one of the unvoided encounters for testing purposes
    es.voidEncounter(testEncounter, "random reason");
    assertTrue(testEncounter.getVoided());
    assertTrue(testOrder.getVoided());
    List<Patient> patients = new ArrayList<>();
    patients.add(patient);
    // wait a bit so that the patient isn't voided on the same millisecond
    TestUtil.waitForClockTick();
    // now void the patient for testing purposes
    patient = Context.getPatientService().voidPatient(patient, "Void Reason");
    assertTrue(patient.getVoided());
    new PatientDataUnvoidHandler().handle(patient, patient.getVoidedBy(), patient.getDateVoided(), null);
    // the encounter that was initially voided separately should still be voided
    testEncounter = es.getEncounter(testEncounter.getId());
    assertTrue(testEncounter.getVoided());
    assertNotNull(testEncounter.getDateVoided());
    assertNotNull(testEncounter.getVoidedBy());
    assertNotNull(testEncounter.getVoidReason());
    // the order that was initially voided separately should still be voided
    assertTrue(testOrder.getVoided());
    assertNotNull(testOrder.getDateVoided());
    assertNotNull(testOrder.getVoidedBy());
    assertNotNull(testOrder.getVoidReason());
}
Also used : Order(org.openmrs.Order) ArrayList(java.util.ArrayList) Patient(org.openmrs.Patient) Encounter(org.openmrs.Encounter) OrderService(org.openmrs.api.OrderService) EncounterService(org.openmrs.api.EncounterService) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

EncounterService (org.openmrs.api.EncounterService)11 Encounter (org.openmrs.Encounter)9 Patient (org.openmrs.Patient)6 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 Order (org.openmrs.Order)3 OrderService (org.openmrs.api.OrderService)3 EncounterSearchCriteria (org.openmrs.parameter.EncounterSearchCriteria)3 EncounterSearchCriteriaBuilder (org.openmrs.parameter.EncounterSearchCriteriaBuilder)3 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)3 EncounterType (org.openmrs.EncounterType)2 Person (org.openmrs.Person)2 User (org.openmrs.User)2 ConceptService (org.openmrs.api.ConceptService)2 PatientService (org.openmrs.api.PatientService)2 VisitService (org.openmrs.api.VisitService)2 Message (ca.uhn.hl7v2.model.Message)1 Date (java.util.Date)1 List (java.util.List)1 ConceptProposal (org.openmrs.ConceptProposal)1