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