Search in sources :

Example 51 with EncounterType

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

the class EncounterServiceTest method retireEncounterType_shouldThrowErrorWhenTryingToRetireEncounterTypeWhenEncounterTypesAreLocked.

/**
 * @see EncounterService#retireEncounterType(EncounterType, String)
 */
@Test(expected = EncounterTypeLockedException.class)
public void retireEncounterType_shouldThrowErrorWhenTryingToRetireEncounterTypeWhenEncounterTypesAreLocked() {
    GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_ENCOUNTER_TYPES_LOCKED);
    gp.setPropertyValue("true");
    Context.getAdministrationService().saveGlobalProperty(gp);
    EncounterService encounterService = Context.getEncounterService();
    EncounterType encounterType = Context.getEncounterService().getEncounterType(1);
    Assert.assertNotNull(encounterType);
    encounterService.retireEncounterType(encounterType, "reason");
}
Also used : EncounterType(org.openmrs.EncounterType) GlobalProperty(org.openmrs.GlobalProperty) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 52 with EncounterType

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

the class EncounterServiceTest method saveEncounter_shouldUpdateEncounterSuccessfully.

/**
 * @see EncounterService#saveEncounter(Encounter)
 */
@Test
public void saveEncounter_shouldUpdateEncounterSuccessfully() {
    EncounterService es = Context.getEncounterService();
    // get the encounter from the database
    Encounter encounter = es.getEncounter(1);
    // save the current values for comparison later
    Patient origPatient = encounter.getPatient();
    Location origLocation = encounter.getLocation();
    Date origDate = encounter.getEncounterDatetime();
    EncounterType origEncType = encounter.getEncounterType();
    // add values that are different than the ones in the initialData.xml
    // file
    Location loc2 = new Location(2);
    EncounterType encType2 = new EncounterType(2);
    Date d2 = new Date();
    Patient pat2 = new Patient(2);
    encounter.setLocation(loc2);
    encounter.setEncounterType(encType2);
    encounter.setEncounterDatetime(d2);
    encounter.setPatient(pat2);
    // save to the db
    es.saveEncounter(encounter);
    // fetch that encounter from the db
    Encounter newestEnc = es.getEncounter(encounter.getEncounterId());
    assertFalse("The location should be different", origLocation.equals(loc2));
    assertTrue("The location should be different", newestEnc.getLocation().equals(loc2));
    assertFalse("The enc should have changed", origEncType.equals(encType2));
    assertTrue("The enc type needs to have been set", newestEnc.getEncounterType().equals(encType2));
    assertFalse("Make sure the dates changed slightly", origDate.equals(d2));
    assertTrue("The date needs to have been set", DateUtil.truncateToSeconds(newestEnc.getEncounterDatetime()).equals(DateUtil.truncateToSeconds(d2)));
    assertFalse("The patient should be different", origPatient.equals(pat2));
    assertTrue("The patient should have been set", newestEnc.getPatient().equals(pat2));
}
Also used : Encounter(org.openmrs.Encounter) Patient(org.openmrs.Patient) EncounterType(org.openmrs.EncounterType) Date(java.util.Date) Location(org.openmrs.Location) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 53 with EncounterType

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

the class EncounterServiceTest method saveEncounterType_shouldThrowErrorWhenTryingToSaveEncounterTypeWhenEncounterTypesAreLocked.

/**
 * @see EncounterService#saveEncounterType(EncounterType)
 * @see EncounterService#checkIfEncounterTypesAreLocked()
 */
@Test(expected = EncounterTypeLockedException.class)
public void saveEncounterType_shouldThrowErrorWhenTryingToSaveEncounterTypeWhenEncounterTypesAreLocked() {
    GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_ENCOUNTER_TYPES_LOCKED);
    gp.setPropertyValue("true");
    Context.getAdministrationService().saveGlobalProperty(gp);
    EncounterService encounterService = Context.getEncounterService();
    EncounterType encounterType = Context.getEncounterService().getEncounterType(1);
    Assert.assertNotNull(encounterType);
    encounterService.saveEncounterType(encounterType);
}
Also used : EncounterType(org.openmrs.EncounterType) GlobalProperty(org.openmrs.GlobalProperty) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 54 with EncounterType

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

the class EncounterValidatorTest method validate_shouldPassValidationIfFieldLengthsAreCorrect.

/**
 * @see EncounterValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldPassValidationIfFieldLengthsAreCorrect() {
    encounter.setEncounterType(new EncounterType());
    encounter.setPatient(new Patient());
    encounter.setEncounterDatetime(new Date());
    encounter.setVoidReason("voidReason");
    encounterValidator.validate(encounter, errors);
    Assert.assertFalse(errors.hasErrors());
}
Also used : Patient(org.openmrs.Patient) EncounterType(org.openmrs.EncounterType) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 55 with EncounterType

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

the class EncounterTypeValidator 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 description is null or empty or whitespace
 * @should pass validation for an existing EncounterType
 * @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) {
    EncounterType encounterType = (EncounterType) obj;
    if (encounterType == null) {
        errors.rejectValue("encounterType", "error.general");
    } else {
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "error.name");
        if (!errors.hasErrors()) {
            EncounterType duplicate = Context.getEncounterService().getEncounterType(encounterType.getName().trim());
            if (duplicate != null && !OpenmrsUtil.nullSafeEquals(encounterType.getUuid(), duplicate.getUuid()) && !duplicate.getRetired()) {
                errors.rejectValue("name", "EncounterType.error.duplicateEncounterTypeNameSpecified", "Specified Encounter Type name already exists, please specify another ");
            }
        }
        ValidateUtil.validateFieldLengths(errors, obj.getClass(), "name", "description", "retireReason");
    }
}
Also used : EncounterType(org.openmrs.EncounterType)

Aggregations

EncounterType (org.openmrs.EncounterType)60 Test (org.junit.Test)44 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)42 Encounter (org.openmrs.Encounter)19 Date (java.util.Date)17 Location (org.openmrs.Location)12 Patient (org.openmrs.Patient)10 User (org.openmrs.User)10 EncounterRole (org.openmrs.EncounterRole)9 Provider (org.openmrs.Provider)8 BindException (org.springframework.validation.BindException)7 Errors (org.springframework.validation.Errors)7 ArrayList (java.util.ArrayList)5 GlobalProperty (org.openmrs.GlobalProperty)5 List (java.util.List)4 Privilege (org.openmrs.Privilege)4 Concept (org.openmrs.Concept)3 Visit (org.openmrs.Visit)3 HashMap (java.util.HashMap)2 SQLQuery (org.hibernate.SQLQuery)2