private void mergeNames(Patient preferred, Patient notPreferred, PersonMergeLogData mergedData) { // move all names // (must be done after all calls to services above so hbm doesn't try to save things prematurely (hacky) for (PersonName newName : notPreferred.getNames()) { boolean containsName = false; for (PersonName currentName : preferred.getNames()) { containsName = currentName.equalsContent(newName); if (containsName) { break; } } if (!containsName) { PersonName tmpName = constructTemporaryName(newName); preferred.addName(tmpName); mergedData.addCreatedName(tmpName.getUuid()); log.debug("Merging name " + newName.getGivenName() + " to " + preferred.getPatientId()); } } }
for (PersonName n : preferred.getNames()) { if (n.getFullName().equals(name.getFullName())) { addedNameUuid = n.getUuid();
@SuppressWarnings("unchecked") @Test public void shouldNotShowVoidedNamesInFullRepresentation() throws Exception { executeDataSet("PersonControllerTest-otherPersonData.xml"); Person person = service.getPersonByUuid(getUuid()); assertEquals(4, person.getNames().size()); PersonName nameToVoid = person.getNames().iterator().next(); String nameToVoidUuid = nameToVoid.getUuid(); if (!nameToVoid.isVoided()) { //void the Name handle(newDeleteRequest("person/" + getUuid() + "/name/" + nameToVoidUuid, new Parameter("!purge", ""), new Parameter("reason", "none"))); } assertTrue(nameToVoid.isVoided()); MockHttpServletRequest req = newGetRequest(getURI() + "/" + getUuid(), new Parameter( RestConstants.REQUEST_PROPERTY_FOR_REPRESENTATION, RestConstants.REPRESENTATION_FULL)); req.addParameter(RestConstants.REQUEST_PROPERTY_FOR_REPRESENTATION, RestConstants.REPRESENTATION_FULL); SimpleObject result = deserialize(handle(req)); List<SimpleObject> names = (List<SimpleObject>) PropertyUtils.getProperty(result, "names"); assertEquals(3, names.size()); assertFalse(nameToVoidUuid.equals(PropertyUtils.getProperty(names.get(0), "uuid"))); }
name.setDateCreated(new Date()); if (name.getUuid() == null) { name.setUuid(UUID.randomUUID().toString());
@Test public void shouldSetThePreferredNameAndUnmarkTheOldOne() throws Exception { executeDataSet("PersonControllerTest-otherPersonData.xml"); Person person = service.getPersonByUuid(getUuid()); PersonName preferredName = service.getPersonNameByUuid("399e3a7b-6482-487d-94ce-c07bb3ca3cc7"); PersonName notPreferredName = service.getPersonNameByUuid("499e3a7b-6482-487d-94ce-c07bb3ca3cc8"); assertTrue(preferredName.isPreferred()); assertFalse(notPreferredName.isPreferred()); assertFalse(notPreferredName.isVoided()); //sanity check that the names belong to the person assertEquals(person, preferredName.getPerson()); assertEquals(person, notPreferredName.getPerson()); handle(newPostRequest(getURI() + "/" + getUuid(), "{ \"preferredName\":\"" + notPreferredName.getUuid() + "\" }")); assertEquals(notPreferredName, person.getPersonName()); assertTrue(notPreferredName.isPreferred()); assertFalse(preferredName.isPreferred()); }