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());
}
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);
}
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);
}
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);
}
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);
}
Aggregations