Search in sources :

Example 6 with Provider

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

the class ProviderValidatorTest method validate_shouldAcceptDuplicateIdentifierIfTheExistingProviderIsRetired.

/**
 * @see ProviderValidator#validate(Object, Errors)
 */
@Test
public void validate_shouldAcceptDuplicateIdentifierIfTheExistingProviderIsRetired() {
    executeDataSet(OTHERS_PROVIDERS_XML);
    Provider duplicateRetiredProvider = providerService.getProvider(201);
    Assert.assertTrue(duplicateRetiredProvider.getRetired());
    Provider provider = providerService.getProvider(1);
    provider.setIdentifier(duplicateRetiredProvider.getIdentifier());
    providerValidator.validate(provider, errors);
    Assert.assertFalse(errors.hasErrors());
}
Also used : Provider(org.openmrs.Provider) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 7 with Provider

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

the class ProviderValidatorTest method setup.

@Before
public void setup() {
    provider = new Provider();
    errors = new BindException(provider, "provider");
    providerValidator = new ProviderValidator();
    providerService = Context.getProviderService();
}
Also used : BindException(org.springframework.validation.BindException) Provider(org.openmrs.Provider) Before(org.junit.Before)

Example 8 with Provider

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

the class ProviderByPersonNameComparatorTest method compareProvidersByPersonName_shouldNotFailIfProvider1HasNoAssociatedPerson.

@Test
public void compareProvidersByPersonName_shouldNotFailIfProvider1HasNoAssociatedPerson() {
    Provider provider1 = new Provider();
    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 9 with Provider

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

the class EncounterServiceTest method saveEncounter_shouldCascadeDeleteEncounterProviders.

/**
 * @see EncounterService#saveEncounter(Encounter)
 */
@Test
public void saveEncounter_shouldCascadeDeleteEncounterProviders() {
    // given
    Encounter encounter = new Encounter();
    encounter.setLocation(new Location(1));
    encounter.setEncounterType(new EncounterType(1));
    encounter.setEncounterDatetime(new Date());
    encounter.setPatient(new Patient(3));
    EncounterRole role = new EncounterRole();
    role.setName("role");
    role = Context.getEncounterService().saveEncounterRole(role);
    Provider provider = new Provider();
    provider.setIdentifier("id1");
    provider.setPerson(newPerson("name"));
    provider = Context.getProviderService().saveProvider(provider);
    Provider provider2 = new Provider();
    provider2.setIdentifier("id2");
    provider2.setPerson(newPerson("name2"));
    provider2 = Context.getProviderService().saveProvider(provider2);
    encounter.addProvider(role, provider);
    encounter.addProvider(role, provider2);
    EncounterService es = Context.getEncounterService();
    es.saveEncounter(encounter);
    Context.flushSession();
    Context.clearSession();
    // when
    encounter = Context.getEncounterService().getEncounter(encounter.getEncounterId());
    encounter.setProvider(role, provider);
    es.saveEncounter(encounter);
    Context.flushSession();
    Context.clearSession();
    // then
    encounter = Context.getEncounterService().getEncounter(encounter.getEncounterId());
    Assert.assertEquals(1, encounter.getProvidersByRole(role).size());
    Assert.assertTrue("Role", encounter.getProvidersByRole(role).contains(provider));
}
Also used : Encounter(org.openmrs.Encounter) Patient(org.openmrs.Patient) EncounterRole(org.openmrs.EncounterRole) EncounterType(org.openmrs.EncounterType) Date(java.util.Date) Location(org.openmrs.Location) Provider(org.openmrs.Provider) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 10 with Provider

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

the class EncounterServiceTest method filterEncountersByViewPermissions_shouldFilterEncountersIfUserIsNotAllowedToSeeSomeEncounters.

/**
 * @see EncounterService#filterEncountersByViewPermissions(List, User)
 */
@Test
public void filterEncountersByViewPermissions_shouldFilterEncountersIfUserIsNotAllowedToSeeSomeEncounters() {
    EncounterService encounterService = Context.getEncounterService();
    int expectedSize = encounterService.getEncountersByPatientId(3).size();
    Encounter encounter = new Encounter();
    encounter.setLocation(new Location(1));
    encounter.setEncounterDatetime(new Date());
    encounter.setPatient(Context.getPatientService().getPatient(3));
    EncounterType encounterType = new EncounterType(1);
    encounterType.setViewPrivilege(Context.getUserService().getPrivilege("Some Privilege For View Encounter Types"));
    encounter.setEncounterType(encounterType);
    EncounterRole role = new EncounterRole();
    role.setName("role");
    role = encounterService.saveEncounterRole(role);
    Provider provider = new Provider();
    provider.setIdentifier("id1");
    provider.setPerson(newPerson("name"));
    provider = Context.getProviderService().saveProvider(provider);
    encounter.addProvider(role, provider);
    encounterService.saveEncounter(encounter);
    List<Encounter> patientEncounters = encounterService.getEncountersByPatientId(3);
    assertEquals(expectedSize + 1, patientEncounters.size());
    if (Context.isAuthenticated()) {
        Context.logout();
    }
    Context.authenticate("test_user", "test");
    Context.addProxyPrivilege(PrivilegeConstants.GET_ENCOUNTERS);
    patientEncounters = encounterService.getEncountersByPatientId(3);
    int actualSize = patientEncounters.size();
    Context.removeProxyPrivilege(PrivilegeConstants.GET_ENCOUNTERS);
    Context.logout();
    assertEquals(actualSize, expectedSize);
    assertTrue(!patientEncounters.contains(encounter));
}
Also used : Encounter(org.openmrs.Encounter) EncounterRole(org.openmrs.EncounterRole) EncounterType(org.openmrs.EncounterType) Date(java.util.Date) Location(org.openmrs.Location) Provider(org.openmrs.Provider) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) 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