Search in sources :

Example 1 with EncounterRole

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

the class EncounterRoleValidator method validate.

/**
 * Checks the form object for any inconsistencies/errors
 *
 * @see org.springframework.validation.Validator#validate(java.lang.Object,
 *      org.springframework.validation.Errors)
 * @should fail validation if name is null or empty or whitespace
 * @should fail validation if name is duplicate
 * @should pass validation if all required fields have proper values
 * @should pass validation if field lengths are correct
 * @should fail validation if field lengths are not correct
 */
@Override
public void validate(Object obj, Errors errors) {
    super.validate(obj, errors);
    EncounterRole encounterRole = (EncounterRole) obj;
    if (!errors.hasErrors()) {
        EncounterRole duplicate = Context.getEncounterService().getEncounterRoleByName(encounterRole.getName().trim());
        if (duplicate != null && duplicate.getUuid() != null && !OpenmrsUtil.nullSafeEquals(encounterRole.getUuid(), duplicate.getUuid())) {
            errors.rejectValue("name", "encounterRole.duplicate.name", "Specified Encounter Role name already exists, please specify another ");
        }
        ValidateUtil.validateFieldLengths(errors, obj.getClass(), "name", "description", "retireReason");
    }
}
Also used : EncounterRole(org.openmrs.EncounterRole)

Example 2 with EncounterRole

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

the class EncounterRoleValidatorTest method validate_shouldFailIfTheNameOfTheEncounterRoleIsNullEmptyOrWhitespace.

/**
 * @see org.openmrs.validator.EncounterRoleValidator#validate(Object, org.springframework.validation.Errors)
 */
@Test
public void validate_shouldFailIfTheNameOfTheEncounterRoleIsNullEmptyOrWhitespace() {
    EncounterRole encounterRoleNo1 = new EncounterRole();
    encounterRoleNo1.setName(null);
    Errors errorsNo1 = new BindException(encounterRoleNo1, "encounterRole");
    new EncounterRoleValidator().validate(encounterRoleNo1, errorsNo1);
    Assert.assertTrue(errorsNo1.hasFieldErrors("name"));
    EncounterRole encounterRoleNo2 = new EncounterRole();
    encounterRoleNo2.setName("");
    Errors errorsNo2 = new BindException(encounterRoleNo2, "encounterRole");
    new EncounterRoleValidator().validate(encounterRoleNo2, errorsNo2);
    Assert.assertTrue(errorsNo2.hasFieldErrors("name"));
    EncounterRole encounterRoleNo3 = new EncounterRole();
    encounterRoleNo3.setName("  ");
    Errors errorsNo3 = new BindException(encounterRoleNo3, "encounterRole");
    new EncounterRoleValidator().validate(encounterRoleNo3, errorsNo3);
    Assert.assertTrue(errorsNo3.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 3 with EncounterRole

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

the class EncounterRoleValidatorTest method validate_shouldPassValidationIfFieldLengthsAreCorrect.

/**
 * {@link org.openmrs.validator.EncounterRoleValidator#validate(Object, org.springframework.validation.Errors)}
 */
@Test
public void validate_shouldPassValidationIfFieldLengthsAreCorrect() {
    EncounterRole encounterRole = Context.getEncounterService().getEncounterRoleByName("Unknown");
    Assert.assertNotNull(encounterRole);
    encounterRole.setName("name");
    encounterRole.setDescription("desc");
    encounterRole.setRetireReason("retireReason");
    Errors errors = new BindException(encounterRole, "encounterRole");
    new EncounterRoleValidator().validate(encounterRole, errors);
    Assert.assertFalse(errors.hasErrors());
}
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 4 with EncounterRole

use of org.openmrs.EncounterRole 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 5 with EncounterRole

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

the class EncounterServiceTest method purgeEncounterRole_shouldPurgeEncounterRole.

/**
 * Make sure that purging an encounter removes the row from the database
 *
 * @see EncounterService#purgeEncounterRole(org.openmrs.EncounterRole)
 */
@Test
public void purgeEncounterRole_shouldPurgeEncounterRole() {
    EncounterService encounterService = Context.getEncounterService();
    EncounterRole encounterRole = encounterService.getEncounterRole(1);
    encounterService.purgeEncounterRole(encounterRole);
    EncounterRole fetchedEncounterRole = encounterService.getEncounterRole(encounterRole.getEncounterRoleId());
    assertNull("We shouldn't find the encounter after deletion", fetchedEncounterRole);
}
Also used : EncounterRole(org.openmrs.EncounterRole) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

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