Search in sources :

Example 71 with Order

use of org.openmrs.Order 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 72 with Order

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

the class EncounterServiceTest method transferEncounter_shouldTransferAnEncounterWithObservationsButNotOrdersToGivenPatient.

/**
 * @see EncounterService#transferEncounter(Encounter,Patient)
 */
@Test
public void transferEncounter_shouldTransferAnEncounterWithObservationsButNotOrdersToGivenPatient() {
    executeDataSet(TRANSFER_ENC_DATA_XML);
    Patient targetPatient = Context.getPatientService().getPatient(201);
    // encounter has 2 obs which are connected with the same order
    Encounter sourceEncounter = Context.getEncounterService().getEncounter(201);
    Assert.assertEquals(2, sourceEncounter.getOrders().size());
    Assert.assertEquals(2, sourceEncounter.getObs().size());
    // transfer
    Encounter transferredEncounter = Context.getEncounterService().transferEncounter(sourceEncounter, targetPatient);
    List<Order> transferredOrders = new ArrayList<>(transferredEncounter.getOrders());
    List<Obs> transferredObservations = new ArrayList<>(transferredEncounter.getObs());
    // check if transferredEncounter is newly created encounter
    Assert.assertNotEquals(sourceEncounter.getId(), transferredEncounter.getId());
    Assert.assertEquals(targetPatient, transferredEncounter.getPatient());
    // check order
    Assert.assertEquals(0, transferredOrders.size());
    // check obs
    Assert.assertEquals(2, transferredObservations.size());
    Assert.assertEquals(targetPatient, transferredObservations.get(0).getPerson());
    Assert.assertEquals(targetPatient, transferredObservations.get(1).getPerson());
    Assert.assertNull(transferredObservations.get(0).getOrder());
    Assert.assertNull(transferredObservations.get(1).getOrder());
    // check if form is transferred
    Assert.assertNotNull(transferredEncounter.getForm());
}
Also used : TestOrder(org.openmrs.TestOrder) Order(org.openmrs.Order) Obs(org.openmrs.Obs) ArrayList(java.util.ArrayList) Patient(org.openmrs.Patient) Encounter(org.openmrs.Encounter) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 73 with Order

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

the class EncounterServiceTest method saveEncounter_shouldCascadePatientToOrdersInTheEncounter.

/**
 * @see EncounterService#saveEncounter(Encounter)
 */
@Test
public void saveEncounter_shouldCascadePatientToOrdersInTheEncounter() {
    Encounter enc = Context.getEncounterService().getEncounter(15);
    Order existing = enc.getOrders().iterator().next();
    // for some reason the xml for the existing encounter has already given
    // this order a different patient than the encounter that it's contained
    // in, but let's verify that:
    Assert.assertNotSame(enc.getPatient().getId(), existing.getPatient().getId());
    Context.getEncounterService().saveEncounter(enc);
    Assert.assertEquals(enc.getPatient().getId(), existing.getPatient().getId());
}
Also used : TestOrder(org.openmrs.TestOrder) Order(org.openmrs.Order) Encounter(org.openmrs.Encounter) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 74 with Order

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

the class EncounterServiceTest method voidEncounter_shouldCascadeToOrders.

/**
 * @see EncounterService#voidEncounter(Encounter,String)
 */
@Test
public void voidEncounter_shouldCascadeToOrders() {
    EncounterService encounterService = Context.getEncounterService();
    // get a nonvoided encounter that has some obs
    Encounter encounter = encounterService.getEncounter(1);
    encounterService.voidEncounter(encounter, "Just Testing");
    Order order = Context.getOrderService().getOrder(1);
    assertTrue(order.getVoided());
    assertEquals("Just Testing", order.getVoidReason());
}
Also used : TestOrder(org.openmrs.TestOrder) Order(org.openmrs.Order) Encounter(org.openmrs.Encounter) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 75 with Order

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

the class EncounterServiceTest method shouldSaveMultipleOrderGroupsIfDifferentOrdersHaveDifferentOrderGroups.

@Test
public void shouldSaveMultipleOrderGroupsIfDifferentOrdersHaveDifferentOrderGroups() {
    executeDataSet(ORDER_SET);
    Encounter encounter = new Encounter();
    encounter.setPatient(Context.getPatientService().getPatient(3));
    encounter.setEncounterType(Context.getEncounterService().getEncounterType(1));
    encounter.setEncounterDatetime(new Date());
    Context.getEncounterService().saveEncounter(encounter);
    Integer encounterId = Context.getEncounterService().getEncounterByUuid(encounter.getUuid()).getId();
    // Created a new OrderGroup
    OrderSet orderSet = Context.getOrderSetService().getOrderSet(2000);
    OrderGroup orderGroup = new OrderGroup();
    orderGroup.setOrderSet(orderSet);
    orderGroup.setPatient(encounter.getPatient());
    orderGroup.setEncounter(Context.getEncounterService().getEncounter(encounterId));
    // Created a new OrderGroup
    OrderGroup orderGroup2 = new OrderGroup();
    orderGroup2.setEncounter(Context.getEncounterService().getEncounter(encounterId));
    orderGroup2.setPatient(encounter.getPatient());
    // Added this OrderGroup to two new orders
    Order newOrder1 = new OrderBuilder().withAction(Order.Action.NEW).withPatient(3).withConcept(1000).withCareSetting(1).withOrderer(1).withEncounter(encounterId).withDateActivated(new Date()).withOrderType(17).withUrgency(Order.Urgency.ON_SCHEDULED_DATE).withScheduledDate(new Date()).withOrderGroup(orderGroup).build();
    Order newOrder2 = new OrderBuilder().withAction(Order.Action.NEW).withPatient(3).withConcept(1001).withCareSetting(1).withOrderer(1).withEncounter(encounterId).withDateActivated(new Date()).withOrderType(17).withUrgency(Order.Urgency.ON_SCHEDULED_DATE).withScheduledDate(new Date()).withOrderGroup(orderGroup).build();
    Order newOrder3 = new OrderBuilder().withAction(Order.Action.NEW).withPatient(3).withConcept(1002).withCareSetting(1).withOrderer(1).withEncounter(encounterId).withDateActivated(new Date()).withOrderType(17).withUrgency(Order.Urgency.ON_SCHEDULED_DATE).withScheduledDate(new Date()).withOrderGroup(orderGroup2).build();
    Order newOrder4 = new OrderBuilder().withAction(Order.Action.NEW).withPatient(3).withConcept(1000).withCareSetting(1).withOrderer(1).withEncounter(encounterId).withDateActivated(new Date()).withOrderType(17).withUrgency(Order.Urgency.ON_SCHEDULED_DATE).withScheduledDate(new Date()).build();
    Order newOrder5 = new OrderBuilder().withAction(Order.Action.NEW).withPatient(3).withConcept(1001).withCareSetting(1).withOrderer(1).withEncounter(encounterId).withDateActivated(new Date()).withOrderType(17).withUrgency(Order.Urgency.ON_SCHEDULED_DATE).withScheduledDate(new Date()).withOrderGroup(orderGroup2).build();
    // Add these orders to the Encounter
    encounter.addOrder(newOrder1);
    encounter.addOrder(newOrder2);
    encounter.addOrder(newOrder3);
    encounter.addOrder(newOrder4);
    encounter.addOrder(newOrder5);
    Context.getEncounterService().saveEncounter(encounter);
    Context.flushSession();
    List<Order> orders = new ArrayList<>(Context.getEncounterService().getEncounterByUuid(encounter.getUuid()).getOrders());
    HashMap<Integer, OrderGroup> orderGroups = new HashMap<>();
    for (Order order : orders) {
        if (order.getOrderGroup() != null) {
            orderGroups.put(order.getOrderGroup().getId(), order.getOrderGroup());
        }
    }
    assertEquals("Two New Order Groups Get Saved", 2, orderGroups.size());
}
Also used : TestOrder(org.openmrs.TestOrder) Order(org.openmrs.Order) OrderBuilder(org.openmrs.api.builder.OrderBuilder) OrderGroup(org.openmrs.OrderGroup) HashMap(java.util.HashMap) OrderSet(org.openmrs.OrderSet) ArrayList(java.util.ArrayList) Encounter(org.openmrs.Encounter) Date(java.util.Date) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Aggregations

Order (org.openmrs.Order)155 Test (org.junit.Test)133 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)115 TestOrder (org.openmrs.TestOrder)114 DrugOrder (org.openmrs.DrugOrder)106 OrderUtilTest (org.openmrs.order.OrderUtilTest)97 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)77 Date (java.util.Date)67 Encounter (org.openmrs.Encounter)41 Patient (org.openmrs.Patient)36 BindException (org.springframework.validation.BindException)20 Errors (org.springframework.validation.Errors)20 Concept (org.openmrs.Concept)15 CareSetting (org.openmrs.CareSetting)11 Obs (org.openmrs.Obs)11 SimpleDateFormat (java.text.SimpleDateFormat)10 OrderGroup (org.openmrs.OrderGroup)10 ArrayList (java.util.ArrayList)9 Calendar (java.util.Calendar)9 OrderBuilder (org.openmrs.api.builder.OrderBuilder)9