Location location = Context.getLocationService().getLocationByUuid(post.get("location").toString());
if (location == null) {
throw new ResponseException(
"Location uuid not found") {};
}
PersonAttribute locationAttribute = new PersonAttribute();
locationAttribute.setAttributeType(Context.getPersonService().getPersonAttributeTypeByName("Health Center"));
locationAttribute.setValue(location.getId().toString());
person.addAttribute(locationAttribute);
if (post.get("email") != null) {
PersonAttribute emailAttribute = new PersonAttribute();
emailAttribute.setAttributeType(Context.getPersonService().getPersonAttributeTypeByName("Email"));
emailAttribute.setValue(post.get("email").toString());
person.addAttribute(emailAttribute);
}
if (post.get("phone") != null) {
PersonAttribute phoneAttribute = new PersonAttribute();
phoneAttribute.setAttributeType(Context.getPersonService().getPersonAttributeTypeByName("Primary Contact"));
phoneAttribute.setValue(post.get("phone").toString());
person.addAttribute(phoneAttribute);
}
if (post.get("donateOrgans") != null) {
PersonAttribute donateOrgansAttribute = new PersonAttribute();
donateOrgansAttribute.setAttributeType(Context.getPersonService().getPersonAttributeTypeByName("Donate Organs"));
donateOrgansAttribute.setValue(post.get("donateOrgans").toString());
person.addAttribute(donateOrgansAttribute);
}
String type = post.get("type").toString();
if (type.equals(TYPE[0])) {
person = savePatient(person, post, location);