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