Search in sources :

Example 21 with OrderType

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

the class OrderTypeValidatorTest method validate_shouldPassIfAllFieldsAreCorrectForAnExistingOrderType.

/**
 * @see OrderTypeValidator#validate(Object, org.springframework.validation.Errors)
 */
@Test
public void validate_shouldPassIfAllFieldsAreCorrectForAnExistingOrderType() {
    OrderType orderType = orderService.getOrderType(1);
    assertNotNull(orderType);
    Errors errors = new BindException(orderType, "orderType");
    new OrderTypeValidator().validate(orderType, errors);
    Assert.assertFalse(errors.hasErrors());
}
Also used : Errors(org.springframework.validation.Errors) OrderType(org.openmrs.OrderType) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 22 with OrderType

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

the class OrderTypeValidatorTest method validate_shouldFailIfNameIsWhitespace.

/**
 * @see OrderTypeValidator#validate(Object, org.springframework.validation.Errors)
 */
@Test
public void validate_shouldFailIfNameIsWhitespace() {
    OrderType orderType = new OrderType();
    orderType.setName("");
    Errors errors = new BindException(orderType, "orderType");
    new OrderTypeValidator().validate(orderType, errors);
    Assert.assertEquals(true, errors.hasFieldErrors("name"));
}
Also used : Errors(org.springframework.validation.Errors) OrderType(org.openmrs.OrderType) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 23 with OrderType

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

the class OrderTypeValidatorTest method validate_shouldFailIfParentIsAmongItsDescendants.

/**
 * @see OrderTypeValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailIfParentIsAmongItsDescendants() {
    OrderType orderType = orderService.getOrderType(2);
    OrderType descendant = orderService.getOrderType(9);
    Assert.assertTrue(descendant.getParent().getParent().equals(orderType));
    orderType.setParent(descendant);
    Errors errors = new BindException(orderType, "orderType");
    new OrderTypeValidator().validate(orderType, errors);
    Assert.assertEquals(true, errors.hasFieldErrors("parent"));
}
Also used : Errors(org.springframework.validation.Errors) OrderType(org.openmrs.OrderType) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 24 with OrderType

use of org.openmrs.OrderType 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 25 with OrderType

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

the class PatientServiceTest method mergePatients_shouldNotFailIfMultiplePatientsHaveActiveOrderOfDifferentTypes.

/**
 * @see PatientService#mergePatients(org.openmrs.Patient, org.openmrs.Patient)
 */
@Test
public void mergePatients_shouldNotFailIfMultiplePatientsHaveActiveOrderOfDifferentTypes() throws Exception {
    Patient preferredPatient = patientService.getPatient(2);
    Patient notPreferredPatient = patientService.getPatient(7);
    OrderType DrugOrder = Context.getOrderService().getOrderTypeByName("Drug order");
    voidOrdersForType(Collections.singleton(preferredPatient), DrugOrder);
    assertFalse("Test pre-request: No Active Drug order in " + preferredPatient, hasActiveOrderOfType(preferredPatient, "Drug order"));
    assertTrue("Test pre-request: At least one Active Test order in " + preferredPatient, hasActiveOrderOfType(preferredPatient, "Test order"));
    assertTrue("Test pre-request: At least one Active Drug order in " + notPreferredPatient, hasActiveOrderOfType(notPreferredPatient, "Drug order"));
    assertFalse("Test pre-request: No Active Test order in " + notPreferredPatient, hasActiveOrderOfType(notPreferredPatient, "Test order"));
    patientService.mergePatients(preferredPatient, notPreferredPatient);
}
Also used : OrderType(org.openmrs.OrderType) Patient(org.openmrs.Patient) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Aggregations

OrderType (org.openmrs.OrderType)54 Test (org.junit.Test)46 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)45 OrderUtilTest (org.openmrs.order.OrderUtilTest)29 BindException (org.springframework.validation.BindException)22 Errors (org.springframework.validation.Errors)22 Patient (org.openmrs.Patient)17 DrugOrder (org.openmrs.DrugOrder)16 CareSetting (org.openmrs.CareSetting)15 Encounter (org.openmrs.Encounter)11 GlobalProperty (org.openmrs.GlobalProperty)8 Order (org.openmrs.Order)8 TestOrder (org.openmrs.TestOrder)6 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)5 ConceptClass (org.openmrs.ConceptClass)5 HashSet (java.util.HashSet)4 Date (java.util.Date)3 ArrayList (java.util.ArrayList)2 Criteria (org.hibernate.Criteria)2 PatientServiceImplTest (org.openmrs.api.impl.PatientServiceImplTest)2