Search in sources :

Example 76 with Order

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

the class EncounterServiceTest method unvoidEncounter_shouldCascadeUnvoidToOrders.

/**
 * @see EncounterService#unvoidEncounter(Encounter)
 */
@Test
public void unvoidEncounter_shouldCascadeUnvoidToOrders() {
    EncounterService encounterService = Context.getEncounterService();
    // get a voided encounter that has some voided obs
    Encounter encounter = encounterService.getEncounter(2);
    encounterService.unvoidEncounter(encounter);
    Order order = Context.getOrderService().getOrder(2);
    assertFalse(order.getVoided());
    assertNull(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 77 with Order

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

the class PatientDataVoidHandlerTest method handle_shouldVoidTheOrdersEncountersAndObservationsAssociatedWithThePatient.

/**
 * @see PatientDataVoidHandler#handle(Patient,User,Date,String)
 */
@Test
public void handle_shouldVoidTheOrdersEncountersAndObservationsAssociatedWithThePatient() {
    Patient patient = Context.getPatientService().getPatient(7);
    Assert.assertFalse(patient.getVoided());
    List<Encounter> encounters = Context.getEncounterService().getEncountersByPatient(patient);
    List<Obs> observations = Context.getObsService().getObservationsByPerson(patient);
    List<Order> orders = Context.getOrderService().getAllOrdersByPatient(patient);
    // we should have some unvoided encounters, obs and orders for the test to be concrete
    assertTrue(CollectionUtils.isNotEmpty(encounters));
    assertTrue(CollectionUtils.isNotEmpty(observations));
    assertTrue(CollectionUtils.isNotEmpty(orders));
    // check that fields to be set by the handler are initially null
    for (Encounter encounter : encounters) {
        assertNull(encounter.getDateVoided());
        assertNull(encounter.getVoidedBy());
        assertNull(encounter.getVoidReason());
    }
    for (Obs obs : observations) {
        assertNull(obs.getDateVoided());
        assertNull(obs.getVoidedBy());
        assertNull(obs.getVoidReason());
    }
    for (Order order : orders) {
        assertNull(order.getDateVoided());
        assertNull(order.getVoidedBy());
        assertNull(order.getVoidReason());
    }
    new PatientDataVoidHandler().handle(patient, new User(1), new Date(), "voidReason");
    // all encounters void related fields should have been set
    for (Encounter encounter : encounters) {
        assertTrue(encounter.getVoided());
        assertNotNull(encounter.getDateVoided());
        assertNotNull(encounter.getVoidedBy());
        assertNotNull(encounter.getVoidReason());
    }
    // all obs void related fields should have been set
    for (Obs obs : observations) {
        assertTrue(obs.getVoided());
        assertNotNull(obs.getDateVoided());
        assertNotNull(obs.getVoidedBy());
        assertNotNull(obs.getVoidReason());
    }
    // all order void related fields should have been set
    for (Order order : orders) {
        assertTrue(order.getVoided());
        assertNotNull(order.getDateVoided());
        assertNotNull(order.getVoidedBy());
        assertNotNull(order.getVoidReason());
    }
    // refresh the lists and check that all encounters, obs and orders were voided
    encounters = Context.getEncounterService().getEncountersByPatient(patient);
    observations = Context.getObsService().getObservationsByPerson(patient);
    assertTrue(CollectionUtils.isEmpty(encounters));
    assertTrue(CollectionUtils.isEmpty(observations));
}
Also used : Order(org.openmrs.Order) Obs(org.openmrs.Obs) User(org.openmrs.User) Patient(org.openmrs.Patient) Encounter(org.openmrs.Encounter) Date(java.util.Date) DateUtils.parseDate(org.apache.commons.lang3.time.DateUtils.parseDate) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 78 with Order

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

the class PatientServiceTest method hasActiveOrderOfType.

private boolean hasActiveOrderOfType(Patient patient, String orderTypeName) {
    OrderType drugOrder = Context.getOrderService().getOrderTypeByName(orderTypeName);
    List<Order> preferredPatientOrders = Context.getOrderService().getAllOrdersByPatient(patient).stream().filter(Order::isActive).filter(order -> Objects.equals(drugOrder, order.getOrderType())).collect(Collectors.toList());
    return !preferredPatientOrders.isEmpty();
}
Also used : IsIterableContainingInAnyOrder.containsInAnyOrder(org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder) Order(org.openmrs.Order) RelationshipType(org.openmrs.RelationshipType) Arrays(java.util.Arrays) TestUtil(org.openmrs.test.TestUtil) Date(java.util.Date) IsIterableContainingInAnyOrder.containsInAnyOrder(org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder) Assert.assertThat(org.junit.Assert.assertThat) PatientIdentifierTypeDefaultComparator(org.openmrs.comparator.PatientIdentifierTypeDefaultComparator) PersonMergeLog(org.openmrs.person.PersonMergeLog) ArgumentMatcher(org.mockito.ArgumentMatcher) Relationship(org.openmrs.Relationship) LuhnIdentifierValidator(org.openmrs.patient.impl.LuhnIdentifierValidator) PatientProgram(org.openmrs.PatientProgram) OrderType(org.openmrs.OrderType) Assert.fail(org.junit.Assert.fail) UniquenessBehavior(org.openmrs.PatientIdentifierType.UniquenessBehavior) PersonName(org.openmrs.PersonName) GregorianCalendar(java.util.GregorianCalendar) PatientIdentifierType(org.openmrs.PatientIdentifierType) Collection(java.util.Collection) PersonAttribute(org.openmrs.PersonAttribute) Set(java.util.Set) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PersonMergeLogData(org.openmrs.person.PersonMergeLogData) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Matchers.is(org.hamcrest.Matchers.is) Patient(org.openmrs.Patient) OpenmrsConstants(org.openmrs.util.OpenmrsConstants) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) OpenmrsUtil(org.openmrs.util.OpenmrsUtil) Visit(org.openmrs.Visit) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Calendar(java.util.Calendar) Location(org.openmrs.Location) AddressMatcher.containsAddress(org.openmrs.util.AddressMatcher.containsAddress) CollectionUtils(org.apache.commons.collections.CollectionUtils) NameMatcher.containsFullName(org.openmrs.util.NameMatcher.containsFullName) Obs(org.openmrs.Obs) SkipBaseSetup(org.openmrs.test.SkipBaseSetup) ExpectedException(org.junit.rules.ExpectedException) PersonAddress(org.openmrs.PersonAddress) LinkedHashSet(java.util.LinkedHashSet) Before(org.junit.Before) Person(org.openmrs.Person) Encounter(org.openmrs.Encounter) PatientIdentifier(org.openmrs.PatientIdentifier) SerializationException(org.openmrs.serialization.SerializationException) Assert.assertNotNull(org.junit.Assert.assertNotNull) GlobalProperty(org.openmrs.GlobalProperty) Order(org.openmrs.Order) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) TestUtil.assertCollectionContentsEquals(org.openmrs.test.TestUtil.assertCollectionContentsEquals) Assert.assertNull(org.junit.Assert.assertNull) Rule(org.junit.Rule) Concept(org.openmrs.Concept) Ignore(org.junit.Ignore) IdentifierValidator(org.openmrs.patient.IdentifierValidator) User(org.openmrs.User) Assert(org.junit.Assert) Context(org.openmrs.api.context.Context) PatientServiceImpl(org.openmrs.api.impl.PatientServiceImpl) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) OrderType(org.openmrs.OrderType)

Example 79 with Order

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

the class ImmutableEntityInterceptorTest method onFlushDirty_shouldPassIfAnEntityHasChangesForAnAllowedMutableProperty.

/**
 * @see ImmutableEntityInterceptor#onFlushDirty(Object, java.io.Serializable, Object[],
 *      Object[], String[], org.hibernate.type.Type[])
 */
@Test
public void onFlushDirty_shouldPassIfAnEntityHasChangesForAnAllowedMutableProperty() {
    String[] propertyNames = new String[] { SomeImmutableEntityInterceptor.MUTABLE_FIELD_NAME };
    String[] previousState = new String[] { "old" };
    String[] currentState = new String[] { "new" };
    new SomeImmutableEntityInterceptor().onFlushDirty(new Order(), null, currentState, previousState, propertyNames, null);
}
Also used : Order(org.openmrs.Order) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 80 with Order

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

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