Search in sources :

Example 46 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 47 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)

Example 48 with Provider

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);
}
Also used : Provider(org.openmrs.Provider) Test(org.junit.Test)

Example 49 with Provider

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;
}
Also used : Disjunction(org.hibernate.criterion.Disjunction) Conjunction(org.hibernate.criterion.Conjunction) Criteria(org.hibernate.Criteria) Provider(org.openmrs.Provider)

Example 50 with Provider

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();
}
Also used : Criteria(org.hibernate.Criteria) Provider(org.openmrs.Provider)

Aggregations

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