Search in sources :

Example 41 with Provider

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

the class ProviderValidator method validate.

/**
 * Validates the given Provider. checks to see if a provider is valid (Either of Person or
 * Provider name should be set and not both) Checks to see if there is a retired Reason in case
 * a provider is retired
 *
 * @param obj The encounter to validate.
 * @param errors Errors
 * @see org.springframework.validation.Validator#validate(java.lang.Object,
 *      org.springframework.validation.Errors)
 * @should be valid if identifier is not set
 * @should be valid if identifier is set
 * @should be invalid if provider is retired and the retired reason is not mentioned
 * @should be invalid if person is not set
 * @should be valid if only person is set
 * @should reject a provider if it has fewer than min occurs of an attribute
 * @should reject a provider if it has more than max occurs of an attribute
 * @should accept duplicate identifier if the existing provider is not retired
 * @should accept duplicate identifier if the existing provider is retired
 * @should accept a duplicate identifier for a new provider which is not retired
 * @should accept a duplicate identifier for a new provider which is retired
 * @should pass validation if field lengths are correct
 * @should fail validation if field lengths are not correct
 */
@Override
public void validate(Object obj, Errors errors) throws APIException {
    if (log.isDebugEnabled()) {
        log.debug(this.getClass().getName() + ".validate...");
    }
    if (obj == null || !(obj instanceof Provider)) {
        throw new IllegalArgumentException("The parameter obj should not be null and must be of type " + Provider.class);
    }
    Provider provider = (Provider) obj;
    if (provider.getPerson() == null && StringUtils.isBlank(provider.getName())) {
        errors.rejectValue("name", "Provider.error.personOrName.required");
        errors.rejectValue("person", "Provider.error.personOrName.required");
    }
    if (provider.getRetired() && StringUtils.isEmpty(provider.getRetireReason())) {
        errors.rejectValue("retireReason", "Provider.error.retireReason.required");
    }
    ValidateUtil.validateFieldLengths(errors, obj.getClass(), "name", "identifier", "retireReason");
    super.validateAttributes(provider, errors, Context.getProviderService().getAllProviderAttributeTypes());
}
Also used : Provider(org.openmrs.Provider)

Example 42 with Provider

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

the class ProviderByPersonNameComparatorTest method compareProvidersByPersonName_shouldReturnPositiveIfPersonNameForProvider1ComesAfterThatOfProvider2.

/**
 * @see PersonByNameComparator#comparePersonsByName(Person,Person)
 */
@Test
public void compareProvidersByPersonName_shouldReturnPositiveIfPersonNameForProvider1ComesAfterThatOfProvider2() {
    Person person1 = new Person();
    person1.addName(new PersonName("givenNamf", "middleName", "familyName"));
    Provider provider1 = new Provider();
    provider1.setPerson(person1);
    Person person2 = new Person();
    person2.addName(new PersonName("givenName", "middleName", "familyName"));
    Provider provider2 = new Provider();
    provider2.setPerson(person2);
    int actualValue = new ProviderByPersonNameComparator().compare(provider1, provider2);
    Assert.assertTrue("Expected a positive value but it was: " + actualValue, actualValue > 0);
}
Also used : PersonName(org.openmrs.PersonName) Person(org.openmrs.Person) Provider(org.openmrs.Provider) Test(org.junit.Test)

Example 43 with Provider

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

the class ProviderByPersonNameComparatorTest method compareProvidersByPersonName_shouldNotFailIfProvider2HasNoAssociatedPerson.

@Test
public void compareProvidersByPersonName_shouldNotFailIfProvider2HasNoAssociatedPerson() {
    Person person1 = new Person();
    person1.addName(new PersonName("givenName", "middleName", "familyName"));
    Provider provider1 = new Provider();
    provider1.setPerson(person1);
    Provider provider2 = new Provider();
    int actualValue = new ProviderByPersonNameComparator().compare(provider1, provider2);
    Assert.assertTrue("Expected a negative value but it was: " + actualValue, actualValue < 0);
}
Also used : PersonName(org.openmrs.PersonName) Person(org.openmrs.Person) Provider(org.openmrs.Provider) Test(org.junit.Test)

Example 44 with Provider

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

the class ProviderByPersonNameComparatorTest method compareProvidersByPersonsName_shouldReturnNegativeIfPersonNameForProvider1ComesBeforeThatOfProvider2.

/**
 * @see PersonByNameComparator#comparePersonsByName(org.openmrs.Person, org.openmrs.Person)
 */
@Test
public void compareProvidersByPersonsName_shouldReturnNegativeIfPersonNameForProvider1ComesBeforeThatOfProvider2() {
    Person person1 = new Person();
    person1.addName(new PersonName("givenName", "middleName", "familyName"));
    Provider provider1 = new Provider();
    provider1.setPerson(person1);
    Person person2 = new Person();
    person2.addName(new PersonName("givenName", "middleNamf", "familyName"));
    Provider provider2 = new Provider();
    provider2.setPerson(person2);
    int actualValue = new ProviderByPersonNameComparator().compare(provider1, provider2);
    Assert.assertTrue("Expected a negative value but it was: " + actualValue, actualValue < 0);
}
Also used : PersonName(org.openmrs.PersonName) Person(org.openmrs.Person) Provider(org.openmrs.Provider) Test(org.junit.Test)

Example 45 with Provider

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

the class ProviderByPersonNameComparatorTest method compareProvidersByPersonName_shouldReturnZeroIfTheGivenNameMiddleNameAndFamilyNameMatch.

/**
 * @see PersonByNameComparator#comparePersonsByName(Person,Person)
 */
@Test
public void compareProvidersByPersonName_shouldReturnZeroIfTheGivenNameMiddleNameAndFamilyNameMatch() {
    Person person1 = new Person();
    person1.addName(new PersonName("givenName", "middleName", "familyName"));
    Provider provider1 = new Provider();
    provider1.setPerson(person1);
    Person person2 = new Person();
    person2.addName(new PersonName("givenName", "middleName", "familyName"));
    Provider provider2 = new Provider();
    provider2.setPerson(person2);
    int actualValue = new ProviderByPersonNameComparator().compare(provider1, provider2);
    Assert.assertTrue("Expected zero but it was: " + actualValue, actualValue == 0);
}
Also used : PersonName(org.openmrs.PersonName) Person(org.openmrs.Person) Provider(org.openmrs.Provider) Test(org.junit.Test)

Aggregations

Provider (org.openmrs.Provider)49 Test (org.junit.Test)40 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)33 Encounter (org.openmrs.Encounter)16 Date (java.util.Date)12 Person (org.openmrs.Person)10 Patient (org.openmrs.Patient)9 EncounterType (org.openmrs.EncounterType)8 EncounterRole (org.openmrs.EncounterRole)7 Location (org.openmrs.Location)7 PersonName (org.openmrs.PersonName)6 TestOrder (org.openmrs.TestOrder)5 Message (ca.uhn.hl7v2.model.Message)4 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)4 DrugOrder (org.openmrs.DrugOrder)4 Order (org.openmrs.Order)4 OrderUtilTest (org.openmrs.order.OrderUtilTest)4 Criteria (org.hibernate.Criteria)3 Concept (org.openmrs.Concept)3 User (org.openmrs.User)3