use of org.openmrs.PersonAttribute in project openmrs-core by openmrs.
the class PatientServiceImpl method mergeAddresses.
private void mergeAddresses(Patient preferred, Patient notPreferred, PersonMergeLogData mergedData) throws SerializationException {
// (must be done after all calls to services above so hbm doesn't try to save things prematurely (hacky)
for (PersonAddress newAddress : notPreferred.getAddresses()) {
boolean containsAddress = false;
for (PersonAddress currentAddress : preferred.getAddresses()) {
containsAddress = currentAddress.equalsContent(newAddress);
if (containsAddress) {
break;
}
}
if (!containsAddress) {
PersonAddress tmpAddress = (PersonAddress) newAddress.clone();
tmpAddress.setPersonAddressId(null);
tmpAddress.setVoided(false);
tmpAddress.setVoidedBy(null);
tmpAddress.setVoidReason(null);
// addresses from non-preferred patient shouldn't be marked as preferred
tmpAddress.setPreferred(false);
tmpAddress.setUuid(UUID.randomUUID().toString());
preferred.addAddress(tmpAddress);
mergedData.addCreatedAddress(tmpAddress.getUuid());
log.debug("Merging address " + newAddress.getPersonAddressId() + " to " + preferred.getPatientId());
}
}
// copy person attributes
for (PersonAttribute attr : notPreferred.getAttributes()) {
if (!attr.getVoided()) {
PersonAttribute tmpAttr = attr.copy();
tmpAttr.setPerson(null);
tmpAttr.setUuid(UUID.randomUUID().toString());
preferred.addAttribute(tmpAttr);
mergedData.addCreatedAttribute(tmpAttr.getUuid());
}
}
// move all other patient info
mergedData.setPriorGender(preferred.getGender());
if (!"M".equals(preferred.getGender()) && !"F".equals(preferred.getGender())) {
preferred.setGender(notPreferred.getGender());
}
mergedData.setPriorDateOfBirth(preferred.getBirthdate());
mergedData.setPriorDateOfBirthEstimated(preferred.getBirthdateEstimated());
if (preferred.getBirthdate() == null || (preferred.getBirthdateEstimated() && !notPreferred.getBirthdateEstimated())) {
preferred.setBirthdate(notPreferred.getBirthdate());
preferred.setBirthdateEstimated(notPreferred.getBirthdateEstimated());
}
mergedData.setPriorDateOfDeathEstimated(preferred.getDeathdateEstimated());
if (preferred.getDeathdateEstimated() == null) {
preferred.setDeathdateEstimated(notPreferred.getDeathdateEstimated());
}
mergedData.setPriorDateOfDeath(preferred.getDeathDate());
if (preferred.getDeathDate() == null) {
preferred.setDeathDate(notPreferred.getDeathDate());
}
if (preferred.getCauseOfDeath() != null) {
mergedData.setPriorCauseOfDeath(preferred.getCauseOfDeath().getUuid());
}
if (preferred.getCauseOfDeath() == null) {
preferred.setCauseOfDeath(notPreferred.getCauseOfDeath());
}
// void the non preferred patient
Context.getPatientService().voidPatient(notPreferred, "Merged with patient #" + preferred.getPatientId());
// void the person associated with not preferred patient
Context.getPersonService().voidPerson(notPreferred, "The patient corresponding to this person has been voided and Merged with patient #" + preferred.getPatientId());
// associate the Users associated with the not preferred person, to the preferred person.
changeUserAssociations(preferred, notPreferred, mergedData);
// Save the newly update preferred patient
// This must be called _after_ voiding the nonPreferred patient so that
// a "Duplicate Identifier" error doesn't pop up.
savePatient(preferred);
// save the person merge log
PersonMergeLog personMergeLog = new PersonMergeLog();
personMergeLog.setWinner(preferred);
personMergeLog.setLoser(notPreferred);
personMergeLog.setPersonMergeLogData(mergedData);
Context.getPersonService().savePersonMergeLog(personMergeLog);
}
use of org.openmrs.PersonAttribute in project openmrs-core by openmrs.
the class ORUR01Handler method updateHealthCenter.
private void updateHealthCenter(Patient patient, PV1 pv1) {
// Update patient's location if it has changed
if (log.isDebugEnabled()) {
log.debug("Checking for discharge to location");
}
DLD dld = pv1.getDischargedToLocation();
log.debug("DLD = " + dld);
if (dld == null) {
return;
}
IS hl7DischargeToLocation = dld.getDischargeLocation();
log.debug("is = " + hl7DischargeToLocation);
if (hl7DischargeToLocation == null) {
return;
}
String dischargeToLocation = hl7DischargeToLocation.getValue();
log.debug("dischargeToLocation = " + dischargeToLocation);
if (dischargeToLocation != null && dischargeToLocation.length() > 0) {
if (log.isDebugEnabled()) {
log.debug("Patient discharged to " + dischargeToLocation);
}
// delimiter
for (int i = 0; i < dischargeToLocation.length(); i++) {
char ch = dischargeToLocation.charAt(i);
if (ch == '&' || ch == '^') {
dischargeToLocation = dischargeToLocation.substring(0, i);
break;
}
}
Integer newLocationId = Integer.parseInt(dischargeToLocation);
// Hydrate a full patient object from patient object containing only
// identifier
patient = Context.getPatientService().getPatient(patient.getPatientId());
PersonAttributeType healthCenterAttrType = Context.getPersonService().getPersonAttributeTypeByName("Health Center");
if (healthCenterAttrType == null) {
log.error("A person attribute type with name 'Health Center' is not defined but patient " + patient.getPatientId() + " is trying to change their health center to " + newLocationId);
return;
}
PersonAttribute currentHealthCenter = patient.getAttribute("Health Center");
if (currentHealthCenter == null || !newLocationId.toString().equals(currentHealthCenter.getValue())) {
PersonAttribute newHealthCenter = new PersonAttribute(healthCenterAttrType, newLocationId.toString());
log.debug("Updating patient's location from " + currentHealthCenter + " to " + newLocationId);
// add attribute (and void old if there is one)
patient.addAttribute(newHealthCenter);
// save the patient and their new attribute
Context.getPatientService().savePatient(patient);
}
}
log.debug("finished discharge to location method");
}
use of org.openmrs.PersonAttribute in project openmrs-core by openmrs.
the class PersonServiceTest method getPersonAttributeByUuid_shouldFindObjectGivenValidUuid.
/**
* @see PersonService#getPersonAttributeByUuid(String)
*/
@Test
public void getPersonAttributeByUuid_shouldFindObjectGivenValidUuid() throws Exception {
String uuid = "0768f3da-b692-44b7-a33f-abf2c450474e";
PersonAttribute person = Context.getPersonService().getPersonAttributeByUuid(uuid);
Assert.assertEquals(1, (int) person.getPersonAttributeId());
}
use of org.openmrs.PersonAttribute in project openmrs-core by openmrs.
the class PersonServiceTest method getPersonAttribute_shouldReturnPersonAttributeWhenGivenIdDoesExist.
/**
* @see PersonService#getPersonAttribute(Integer)
*/
@Test
public void getPersonAttribute_shouldReturnPersonAttributeWhenGivenIdDoesExist() throws Exception {
PersonAttribute personAttribute = Context.getPersonService().getPersonAttribute(17);
Assert.assertNotNull(personAttribute);
assertTrue("Expecting the return is of a person attribute", personAttribute.getClass().equals(PersonAttribute.class));
}
use of org.openmrs.PersonAttribute in project openmrs-core by openmrs.
the class PersonServiceTest method getPersonAttribute_shouldReturnNullWhenGivenIdDoesNotExist.
/**
* @see PersonService#getPersonAttribute(Integer)
*/
@Test
public void getPersonAttribute_shouldReturnNullWhenGivenIdDoesNotExist() throws Exception {
PersonAttribute personAttribute = Context.getPersonService().getPersonAttribute(10000);
Assert.assertNull(personAttribute);
}
Aggregations