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);
}
use of org.openmrs.Provider in project openmrs-core by openmrs.
the class ProviderByPersonNameComparatorTest method compareProvidersByPersonName_shouldNotFailIfNeitherProviderHasAnAssociatedPerson.
@Test
public void compareProvidersByPersonName_shouldNotFailIfNeitherProviderHasAnAssociatedPerson() {
Provider provider1 = new Provider();
Provider provider2 = new Provider();
int actualValue = new ProviderByPersonNameComparator().compare(provider1, provider2);
Assert.assertTrue("Expected zero but it was: " + actualValue, actualValue == 0);
}
use of org.openmrs.Provider in project openmrs-core by openmrs.
the class HibernateProviderDAO method prepareProviderCriteria.
/**
* Creates a Provider Criteria based on name
*
* @param name represents provider name
* @param includeRetired
* @return Criteria represents the hibernate criteria to search
*/
private Criteria prepareProviderCriteria(String name, boolean includeRetired) {
if (StringUtils.isBlank(name)) {
name = "%";
}
Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Provider.class).createAlias("person", "p", JoinType.LEFT_OUTER_JOIN);
if (!includeRetired) {
criteria.add(Restrictions.eq("retired", false));
}
criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
criteria.createAlias("p.names", "personName", JoinType.LEFT_OUTER_JOIN);
Disjunction or = Restrictions.disjunction();
or.add(Restrictions.ilike("identifier", name, getMatchMode()));
or.add(Restrictions.ilike("name", name, MatchMode.ANYWHERE));
Conjunction and = Restrictions.conjunction();
or.add(and);
String[] splitNames = name.split(" ");
for (String splitName : splitNames) {
and.add(getNameSearchExpression(splitName));
}
criteria.add(or);
return criteria;
}
use of org.openmrs.Provider in project openmrs-core by openmrs.
the class HibernateProviderDAO method getProviderByIdentifier.
/**
* @see org.openmrs.api.db.ProviderDAO#getProviderByIdentifier(java.lang.String)
*/
@Override
public Provider getProviderByIdentifier(String identifier) {
Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Provider.class);
criteria.add(Restrictions.ilike("identifier", identifier, MatchMode.EXACT));
return (Provider) criteria.uniqueResult();
}
Aggregations