Search in sources :

Example 16 with EncounterRole

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

the class EncounterServiceTest method getEncounterRoleByUuid_shouldFindEncounterRoleBasedOnUuid.

/**
 * @see EncounterService#getEncounterRoleByUuid(String)
 */
@Test
public void getEncounterRoleByUuid_shouldFindEncounterRoleBasedOnUuid() {
    EncounterService encounterService = Context.getEncounterService();
    EncounterRole encounterRole = encounterService.getEncounterRoleByUuid("430bbb70-6a9c-4e1e-badb-9d1054b1b5e9");
    assertNotNull("valid uuid should be returned", encounterRole);
    encounterRole = encounterService.getEncounterRoleByUuid("invaid uuid");
    assertNull("returns null for invalid uuid", encounterRole);
}
Also used : EncounterRole(org.openmrs.EncounterRole) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 17 with EncounterRole

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

the class EncounterServiceTest method saveEncounter_shouldCascadeSaveEncounterProviders.

/**
 * @see EncounterService#saveEncounter(Encounter)
 */
@Test
public void saveEncounter_shouldCascadeSaveEncounterProviders() {
    // 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);
    EncounterRole role2 = new EncounterRole();
    role2.setName("role2");
    role2 = Context.getEncounterService().saveEncounterRole(role2);
    Provider provider = new Provider();
    provider.setIdentifier("id1");
    provider.setPerson(newPerson("name1"));
    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);
    encounter.addProvider(role2, provider2);
    // when
    EncounterService es = Context.getEncounterService();
    es.saveEncounter(encounter);
    Context.flushSession();
    Context.clearSession();
    // then
    encounter = Context.getEncounterService().getEncounter(encounter.getEncounterId());
    Assert.assertEquals(2, encounter.getProvidersByRole(role).size());
    Assert.assertTrue("Role", encounter.getProvidersByRole(role).containsAll(Arrays.asList(provider, provider2)));
    Assert.assertEquals(1, encounter.getProvidersByRole(role2).size());
    Assert.assertTrue("Role2", encounter.getProvidersByRole(role2).contains(provider2));
}
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 18 with EncounterRole

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

the class EncounterServiceTest method unretireEncounterRole_shouldUnretireTypeAndUnmarkAttributes.

/**
 * @see EncounterService#unretireEncounterRole(org.openmrs.EncounterRole)
 */
@Test
public void unretireEncounterRole_shouldUnretireTypeAndUnmarkAttributes() {
    EncounterService encounterService = Context.getEncounterService();
    EncounterRole encounterRole = encounterService.getEncounterRole(2);
    assertTrue(encounterRole.getRetired());
    assertNotNull(encounterRole.getRetiredBy());
    assertNotNull(encounterRole.getRetireReason());
    assertNotNull(encounterRole.getDateRetired());
    EncounterRole unretiredEncounterRole = encounterService.unretireEncounterRole(encounterRole);
    assertEquals(unretiredEncounterRole, encounterRole);
    assertFalse(unretiredEncounterRole.getRetired());
    assertNull(unretiredEncounterRole.getDateRetired());
    assertNull(unretiredEncounterRole.getRetiredBy());
    assertNull(unretiredEncounterRole.getRetireReason());
}
Also used : EncounterRole(org.openmrs.EncounterRole) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 19 with EncounterRole

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

the class EncounterRoleValidatorTest method validate_shouldFailIfEncounterRoleNameIsDuplicate.

/**
 * @see org.openmrs.validator.EncounterRoleValidator#validate(Object, org.springframework.validation.Errors)
 */
@Test
public void validate_shouldFailIfEncounterRoleNameIsDuplicate() {
    Assert.assertNotNull(Context.getEncounterService().getEncounterRoleByName("Unknown"));
    EncounterRole newEncounterRole = new EncounterRole();
    newEncounterRole.setName("Unknown");
    Errors errors = new BindException(newEncounterRole, "encounterRole");
    new EncounterRoleValidator().validate(newEncounterRole, errors);
    Assert.assertTrue(errors.hasFieldErrors("name"));
}
Also used : Errors(org.springframework.validation.Errors) EncounterRole(org.openmrs.EncounterRole) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 20 with EncounterRole

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

the class EncounterRoleValidatorTest method validate_shouldFailValidationIfFieldLengthsAreNotCorrect.

/**
 * {@link org.openmrs.validator.EncounterRoleValidator#validate(Object, org.springframework.validation.Errors)}
 */
@Test
public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() {
    EncounterRole encounterRole = new EncounterRole();
    encounterRole.setName("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
    encounterRole.setDescription("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
    encounterRole.setRetireReason("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
    Errors errors = new BindException(encounterRole, "encounterRole");
    new EncounterRoleValidator().validate(encounterRole, errors);
    Assert.assertTrue(errors.hasFieldErrors("name"));
    Assert.assertTrue(errors.hasFieldErrors("description"));
    Assert.assertTrue(errors.hasFieldErrors("retireReason"));
}
Also used : Errors(org.springframework.validation.Errors) EncounterRole(org.openmrs.EncounterRole) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

EncounterRole (org.openmrs.EncounterRole)22 Test (org.junit.Test)20 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)17 EncounterType (org.openmrs.EncounterType)7 Provider (org.openmrs.Provider)7 BindException (org.springframework.validation.BindException)7 Errors (org.springframework.validation.Errors)7 Date (java.util.Date)6 Encounter (org.openmrs.Encounter)6 Location (org.openmrs.Location)6 Patient (org.openmrs.Patient)4 EncounterProvider (org.openmrs.EncounterProvider)2 SimpleObject (org.openmrs.ui.framework.SimpleObject)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 User (org.openmrs.User)1 Visit (org.openmrs.Visit)1 AdministrationService (org.openmrs.api.AdministrationService)1 EncounterService (org.openmrs.api.EncounterService)1 AppContextModel (org.openmrs.module.appframework.context.AppContextModel)1