use of org.openmrs.Location in project openmrs-core by openmrs.
the class ObsServiceTest method saveObs_shouldAllowSettingPropertiesOnObs.
/**
* @see ObsService#saveObs(Obs,String)
*/
@Test
public void saveObs_shouldAllowSettingPropertiesOnObs() {
ObsService obsService = Context.getObsService();
Order order = null;
Concept concept = Context.getConceptService().getConcept(3);
Patient patient = new Patient(2);
Encounter encounter = new Encounter(3);
Date datetime = new Date();
Location location = new Location(1);
Integer valueGroupId = 7;
Date valueDatetime = new Date();
Concept valueCoded = new Concept(3);
Double valueNumeric = 2.0;
String valueModifier = "cc";
String valueText = "value text2";
String comment = "commenting2";
Obs obs = new Obs();
obs.setOrder(order);
obs.setConcept(concept);
obs.setPerson(patient);
obs.setEncounter(encounter);
obs.setObsDatetime(datetime);
obs.setLocation(location);
obs.setValueGroupId(valueGroupId);
obs.setValueDatetime(valueDatetime);
obs.setValueCoded(valueCoded);
obs.setValueNumeric(valueNumeric);
obs.setValueModifier(valueModifier);
obs.setValueText(valueText);
obs.setComment(comment);
Obs saved = obsService.saveObs(obs, null);
assertEquals(order, saved.getOrder());
assertEquals(patient, saved.getPerson());
assertEquals(comment, saved.getComment());
assertEquals(concept, saved.getConcept());
assertEquals(encounter, saved.getEncounter());
assertEquals(DateUtil.truncateToSeconds(datetime), saved.getObsDatetime());
assertEquals(location, saved.getLocation());
assertEquals(valueGroupId, saved.getValueGroupId());
assertEquals(DateUtil.truncateToSeconds(valueDatetime), saved.getValueDatetime());
assertEquals(valueCoded, saved.getValueCoded());
assertEquals(valueNumeric, saved.getValueNumeric());
assertEquals(valueModifier, saved.getValueModifier());
assertEquals(valueText, saved.getValueText());
}
use of org.openmrs.Location in project openmrs-core by openmrs.
the class ObsServiceTest method saveObs_shouldCascadeSaveToChildObsGroups.
/**
* @see ObsService#saveObs(Obs,String)
*/
@Test
public void saveObs_shouldCascadeSaveToChildObsGroups() {
ObsService obsService = Context.getObsService();
Obs parentObs = new Obs();
parentObs.setConcept(Context.getConceptService().getConcept(3));
parentObs.setObsDatetime(new Date());
parentObs.setPerson(new Patient(2));
parentObs.setLocation(new Location(1));
Obs groupMember = new Obs();
groupMember.setConcept(Context.getConceptService().getConcept(3));
groupMember.setValueNumeric(1.0);
groupMember.setObsDatetime(new Date());
groupMember.setPerson(new Patient(2));
groupMember.setLocation(new Location(1));
parentObs.addGroupMember(groupMember);
obsService.saveObs(parentObs, null);
// make sure the child obs was saved
Assert.assertNotNull(groupMember.getObsId());
}
use of org.openmrs.Location in project openmrs-core by openmrs.
the class PersonServiceTest method createTestPatient.
/*
* Helper to create patient that does not have any existing relationships. Returns created Patient.
*/
private Patient createTestPatient() {
Patient patient = new Patient();
PersonName pName = new PersonName();
pName.setGivenName("Tom");
pName.setMiddleName("E.");
pName.setFamilyName("Patient");
patient.addName(pName);
PersonAddress pAddress = new PersonAddress();
pAddress.setAddress1("123 My street");
pAddress.setAddress2("Apt 402");
pAddress.setCityVillage("Anywhere city");
pAddress.setCountry("Some Country");
Set<PersonAddress> pAddressList = patient.getAddresses();
pAddressList.add(pAddress);
patient.setAddresses(pAddressList);
patient.addAddress(pAddress);
patient.setBirthdate(new Date());
patient.setBirthdateEstimated(true);
patient.setDeathDate(new Date());
patient.setCauseOfDeath(new Concept(1));
patient.setGender("male");
List<PatientIdentifierType> patientIdTypes = ps.getAllPatientIdentifierTypes();
assertNotNull(patientIdTypes);
PatientIdentifier patientIdentifier = new PatientIdentifier();
patientIdentifier.setIdentifier("123-0");
patientIdentifier.setIdentifierType(patientIdTypes.get(0));
patientIdentifier.setLocation(new Location(1));
patientIdentifier.setPreferred(true);
Set<PatientIdentifier> patientIdentifiers = new TreeSet<>();
patientIdentifiers.add(patientIdentifier);
patient.setIdentifiers(patientIdentifiers);
ps.savePatient(patient);
return patient;
}
use of org.openmrs.Location in project openmrs-core by openmrs.
the class LocationValidator 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
* @should fail validation if retired and retireReason is null or empty
* @should set retired to false if retireReason is null or empty
* @should pass validation if all fields are correct
* @should pass validation if retired location is given retired reason
* @should fail validation if parent location creates a loop
* @should fail validation if name is exist in non retired locations
* @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) {
Location location = (Location) obj;
if (location == null) {
errors.rejectValue("location", "error.general");
} else {
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "error.name");
if (location.getRetired() && !StringUtils.hasLength(location.getRetireReason())) {
// so that the jsp page displays
location.setRetired(false);
// properly again
errors.rejectValue("retireReason", "error.null");
}
Location exist = Context.getLocationService().getLocation(location.getName());
if (exist != null && !exist.getRetired() && !OpenmrsUtil.nullSafeEquals(location.getUuid(), exist.getUuid())) {
errors.rejectValue("name", "location.duplicate.name");
}
// Traverse all the way up (down?) to the root and check if it
// equals the root.
Location root = location;
while (root.getParentLocation() != null) {
root = root.getParentLocation();
if (root.equals(location)) {
// Have gone in a circle
errors.rejectValue("parentLocation", "Location.parentLocation.error");
break;
}
}
ValidateUtil.validateFieldLengths(errors, obj.getClass(), "name", "description", "address1", "address2", "cityVillage", "stateProvince", "country", "postalCode", "latitude", "longitude", "countyDistrict", "address3", "address4", "address5", "address6", "address7", "address8", "address9", "address10", "address11", "address12", "address13", "address14", "address15", "retireReason");
super.validateAttributes(location, errors, Context.getLocationService().getAllLocationAttributeTypes());
}
}
use of org.openmrs.Location in project openmrs-core by openmrs.
the class LocationValidatorTest method validate_shouldPassValidationIfRetiredLocationIsGivenRetiredReason.
/**
* @see LocationValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldPassValidationIfRetiredLocationIsGivenRetiredReason() {
Location location = new Location();
location.setName("County General");
location.setDescription("desc");
location.setRetired(true);
location.setRetireReason("Because I don't like County General");
Errors errors = new BindException(location, "location");
new LocationValidator().validate(location, errors);
Assert.assertFalse(errors.hasErrors());
}
Aggregations