### Eclipse Workspace Patch 1.0 #P openmrs-trunk Index: src/api/org/openmrs/api/impl/PatientServiceImpl.java =================================================================== --- src/api/org/openmrs/api/impl/PatientServiceImpl.java (revision 6866) +++ src/api/org/openmrs/api/impl/PatientServiceImpl.java (working copy) @@ -59,6 +59,8 @@ import org.openmrs.util.OpenmrsConstants; import org.openmrs.validator.PatientIdentifierValidator; +import com.sun.jndi.cosnaming.IiopUrl.Address; + /** * Default implementation of the patient service. This class should not be used on its own. The * current OpenMRS implementation should be fetched from the Context via @@ -685,9 +687,22 @@ // TODO: this should be a copy, not a move EncounterService es = Context.getEncounterService(); for (Encounter e : es.getEncountersByPatient(notPreferred)) { - e.setPatient(preferred); + Encounter newE = new Encounter(); + newE.setEncounterDatetime(e.getEncounterDatetime()); + newE.setEncounterType(e.getEncounterType()); + newE.setForm(e.getForm()); + newE.setObs(e.getAllObs()); + newE.setLocation(e.getLocation()); + newE.setPatient(preferred); + newE.setCreator(Context.getAuthenticatedUser()); + newE.setVoided(false); + newE.setVoidedBy(null); + newE.setVoidReason(null); + + e.setVoided(true); + e.setVoidedBy(Context.getAuthenticatedUser()); log.debug("Merging encounter " + e.getEncounterId() + " to " + preferred.getPatientId()); - es.saveEncounter(e); + es.saveEncounter(newE); } // move all identifiers @@ -698,6 +713,8 @@ // types. tmpIdentifier.setLocation(pi.getLocation()); tmpIdentifier.setPatient(preferred); + + pi.setVoided(true); boolean found = false; for (PatientIdentifier preferredIdentifier : preferred.getIdentifiers()) { if (preferredIdentifier.getIdentifier() != null @@ -770,6 +787,8 @@ preferred.addAddress(tmpAddress); log.debug("Merging address " + newAddress.getPersonAddressId() + " to " + preferred.getPatientId()); } + newAddress.setVoided(true); + newAddress.setVoidedBy(Context.getAuthenticatedUser()); } // copy all program enrollments @@ -780,6 +799,8 @@ enroll.setPatient(preferred); log.debug("Copying patientProgram " + pp.getPatientProgramId() + " to " + preferred.getPatientId()); programService.savePatientProgram(enroll); + pp.setVoided(true); + pp.setVoidedBy(Context.getAuthenticatedUser()); } } @@ -794,6 +815,8 @@ tmpRel.setPersonB(preferred); log.debug("Copying relationship " + rel.getRelationshipId() + " to " + preferred.getPatientId()); personService.saveRelationship(tmpRel); + rel.setVoided(true); + rel.setVoidedBy(Context.getAuthenticatedUser()); } } @@ -802,8 +825,28 @@ ObsService obsService = Context.getObsService(); for (Obs obs : obsService.getObservationsByPerson(notPreferred)) { if (obs.getEncounter() == null && !obs.isVoided()) { - obs.setPerson(preferred); - obsService.saveObs(obs, "Merged from patient #" + notPreferred.getPatientId()); + Obs newOb = new Obs() + newOb.setPerson(preferred); + newOb.setAccessionNumber(obs.getAccessionNumber()); + newOb.setComplexData(obs.getComplexData()); + newOb.setConcept(obs.getConcept()) + newOb.setCreator(obs.getCreator()); + newOb.setDateCreated(obs.getDateCreated()); + newOb.setDateStarted(obs.getDateStarted()); + newOb.setDateStopped(obs.getDateStopped()); + newOb.setEncounter(obs.getEncounter()); + newOb.setGroupMembers(obs.getGroupMembers()); + newOb.setLocation(obs.getLocation()); + newOb.setObsDatetime(obs.getObsDatetime()); + newOb.setObsGroup(obs.getObsGroup()); + newOb.setOrder(obs.getOrder()); + newOb.setVoided(false); + newOb.setVoidedBy(null); + newOb.setVoidReason(null); + + obsService.saveObs(newOb, "Merged from patient #" + notPreferred.getPatientId()); + obs.setVoided(true); + obs.setVoidedBy(Context.getAuthenticatedUser()); } } @@ -814,6 +857,8 @@ Order tmpOrder = o.copy(); tmpOrder.setPatient(preferred); os.saveOrder(tmpOrder); + o.setVoided(true); + o.setVoidedBy(Context.getAuthenticatedUser()); } } @@ -823,6 +868,8 @@ PersonAttribute tmpAttr = attr.copy(); tmpAttr.setPerson(null); preferred.addAttribute(tmpAttr); + attr.setVoided(true); + attr.setVoidedBy(Context.getAuthenticatedUser()); } }