Search in sources :

Example 1 with EncounterSearchCriteria

use of org.openmrs.parameter.EncounterSearchCriteria 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 2 with EncounterSearchCriteria

use of org.openmrs.parameter.EncounterSearchCriteria in project openmrs-core by openmrs.

the class EncounterServiceTest method getEncounters_shouldIncludeVoidedEncounters.

/**
 * @see EncounterService#getEncounters(Patient, Location, Date, Date, java.util.Collection,
 *      java.util.Collection, java.util.Collection, boolean)
 */
@Test
public void getEncounters_shouldIncludeVoidedEncounters() {
    EncounterSearchCriteria encounterSearchCriteria = new EncounterSearchCriteriaBuilder().setIncludeVoided(true).createEncounterSearchCriteria();
    assertEquals(8, Context.getEncounterService().getEncounters(encounterSearchCriteria).size());
}
Also used : EncounterSearchCriteria(org.openmrs.parameter.EncounterSearchCriteria) EncounterSearchCriteriaBuilder(org.openmrs.parameter.EncounterSearchCriteriaBuilder) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 3 with EncounterSearchCriteria

use of org.openmrs.parameter.EncounterSearchCriteria in project openmrs-core by openmrs.

the class EncounterServiceTest method getEncounters_shouldGetEncountersByType.

/**
 * @see EncounterService#getEncounters(Patient, Location, Date, Date, java.util.Collection,
 *      java.util.Collection, java.util.Collection, boolean)
 */
@Test
public void getEncounters_shouldGetEncountersByType() {
    List<EncounterType> types = new ArrayList<>();
    types.add(new EncounterType(1));
    EncounterSearchCriteria encounterSearchCriteria = new EncounterSearchCriteriaBuilder().setEncounterTypes(types).setIncludeVoided(true).createEncounterSearchCriteria();
    List<Encounter> encounters = Context.getEncounterService().getEncounters(encounterSearchCriteria);
    assertEquals(7, encounters.size());
}
Also used : EncounterSearchCriteria(org.openmrs.parameter.EncounterSearchCriteria) EncounterSearchCriteriaBuilder(org.openmrs.parameter.EncounterSearchCriteriaBuilder) ArrayList(java.util.ArrayList) Encounter(org.openmrs.Encounter) EncounterType(org.openmrs.EncounterType) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 4 with EncounterSearchCriteria

use of org.openmrs.parameter.EncounterSearchCriteria in project openmrs-core by openmrs.

the class EncounterServiceTest method getEncounters_shouldGetEncountersByVisitType.

/**
 * @see EncounterService#getEncounters(Patient, Location, Date, Date, java.util.Collection,
 *      java.util.Collection, java.util.Collection, java.util.Collection, java.util.Collection,
 *      boolean)
 */
@Test
public void getEncounters_shouldGetEncountersByVisitType() {
    List<VisitType> visitTypes = new ArrayList<>();
    visitTypes.add(new VisitType(2));
    EncounterSearchCriteria encounterSearchCriteria = new EncounterSearchCriteriaBuilder().setVisitTypes(visitTypes).setIncludeVoided(true).createEncounterSearchCriteria();
    List<Encounter> encounters = Context.getEncounterService().getEncounters(encounterSearchCriteria);
    assertEquals(2, encounters.size());
}
Also used : EncounterSearchCriteria(org.openmrs.parameter.EncounterSearchCriteria) EncounterSearchCriteriaBuilder(org.openmrs.parameter.EncounterSearchCriteriaBuilder) ArrayList(java.util.ArrayList) VisitType(org.openmrs.VisitType) Encounter(org.openmrs.Encounter) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 5 with EncounterSearchCriteria

use of org.openmrs.parameter.EncounterSearchCriteria in project openmrs-core by openmrs.

the class EncounterServiceTest method getEncounters_shouldExcludeVoidedEncounters.

/**
 * @see EncounterService#getEncounters(Patient, Location, Date, Date, java.util.Collection,
 *      java.util.Collection, java.util.Collection, boolean)
 */
@Test
public void getEncounters_shouldExcludeVoidedEncounters() {
    EncounterSearchCriteria encounterSearchCriteria = new EncounterSearchCriteriaBuilder().setIncludeVoided(false).createEncounterSearchCriteria();
    assertEquals(6, Context.getEncounterService().getEncounters(encounterSearchCriteria).size());
}
Also used : EncounterSearchCriteria(org.openmrs.parameter.EncounterSearchCriteria) EncounterSearchCriteriaBuilder(org.openmrs.parameter.EncounterSearchCriteriaBuilder) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Aggregations

EncounterSearchCriteria (org.openmrs.parameter.EncounterSearchCriteria)13 EncounterSearchCriteriaBuilder (org.openmrs.parameter.EncounterSearchCriteriaBuilder)12 Test (org.junit.Test)10 Encounter (org.openmrs.Encounter)10 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)10 ArrayList (java.util.ArrayList)4 EncounterService (org.openmrs.api.EncounterService)3 SimpleDateFormat (java.text.SimpleDateFormat)2 Order (org.openmrs.Order)2 OrderService (org.openmrs.api.OrderService)2 DateFormat (java.text.DateFormat)1 Date (java.util.Date)1 Criteria (org.hibernate.Criteria)1 EncounterType (org.openmrs.EncounterType)1 Form (org.openmrs.Form)1 Location (org.openmrs.Location)1 Patient (org.openmrs.Patient)1 User (org.openmrs.User)1 Visit (org.openmrs.Visit)1 VisitType (org.openmrs.VisitType)1