WIP
This commit is contained in:
parent
ae3040415c
commit
a28e9e736a
|
@ -64,7 +64,7 @@ public class EmpiPersonMergerSvcImpl implements IEmpiPersonMergerSvc {
|
||||||
// myPersonHelper.mergeFields(theFrom, theTo);
|
// myPersonHelper.mergeFields(theFrom, theTo);
|
||||||
|
|
||||||
mergeSourceResourceLinks(theFrom, theTo, toPid, theEmpiTransactionContext);
|
mergeSourceResourceLinks(theFrom, theTo, toPid, theEmpiTransactionContext);
|
||||||
//removeTargetLinks(theFrom);
|
removeTargetLinks(theFrom, theTo, theEmpiTransactionContext);
|
||||||
|
|
||||||
refreshLinksAndUpdatePerson(theTo, theEmpiTransactionContext);
|
refreshLinksAndUpdatePerson(theTo, theEmpiTransactionContext);
|
||||||
|
|
||||||
|
@ -86,10 +86,10 @@ public class EmpiPersonMergerSvcImpl implements IEmpiPersonMergerSvc {
|
||||||
* @param theEmpiTransactionContext Context to keep track of the deletions
|
* @param theEmpiTransactionContext Context to keep track of the deletions
|
||||||
*/
|
*/
|
||||||
private void removeTargetLinks(IAnyResource theFrom, IAnyResource theTo, EmpiTransactionContext theEmpiTransactionContext) {
|
private void removeTargetLinks(IAnyResource theFrom, IAnyResource theTo, EmpiTransactionContext theEmpiTransactionContext) {
|
||||||
List<EmpiLink> empiLinksByTargetAndSource = myEmpiLinkDaoSvc.findEmpiLinksByTarget(theFrom);
|
List<EmpiLink> allLinksWithTheFromAsTarget = myEmpiLinkDaoSvc.findEmpiLinksBySourceResource(theFrom);
|
||||||
empiLinksByTargetAndSource
|
allLinksWithTheFromAsTarget
|
||||||
.stream()
|
.stream()
|
||||||
.filter(EmpiLink::isAuto)
|
.filter(EmpiLink::isAuto) // only keep manual links
|
||||||
.forEach(l -> {
|
.forEach(l -> {
|
||||||
theEmpiTransactionContext.addTransactionLogMessage(String.format("Deleting link %s", l));
|
theEmpiTransactionContext.addTransactionLogMessage(String.format("Deleting link %s", l));
|
||||||
myEmpiLinkDaoSvc.deleteLink(l);
|
myEmpiLinkDaoSvc.deleteLink(l);
|
||||||
|
@ -120,7 +120,7 @@ public class EmpiPersonMergerSvcImpl implements IEmpiPersonMergerSvc {
|
||||||
for (EmpiLink fromLink : fromLinks) {
|
for (EmpiLink fromLink : fromLinks) {
|
||||||
Optional<EmpiLink> optionalToLink = findFirstLinkWithMatchingTarget(toLinks, fromLink);
|
Optional<EmpiLink> optionalToLink = findFirstLinkWithMatchingTarget(toLinks, fromLink);
|
||||||
if (optionalToLink.isPresent()) {
|
if (optionalToLink.isPresent()) {
|
||||||
toLinks.remove(optionalToLink);
|
// toLinks.remove(optionalToLink);
|
||||||
|
|
||||||
// The original links already contain this target, so move it over to the toPerson
|
// The original links already contain this target, so move it over to the toPerson
|
||||||
EmpiLink toLink = optionalToLink.get();
|
EmpiLink toLink = optionalToLink.get();
|
||||||
|
|
|
@ -12,6 +12,7 @@ import ca.uhn.fhir.jpa.empi.interceptor.IEmpiStorageInterceptor;
|
||||||
import ca.uhn.fhir.jpa.entity.EmpiLink;
|
import ca.uhn.fhir.jpa.entity.EmpiLink;
|
||||||
import ca.uhn.fhir.rest.server.TransactionLogMessages;
|
import ca.uhn.fhir.rest.server.TransactionLogMessages;
|
||||||
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
|
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
|
||||||
|
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||||
import org.hl7.fhir.r4.model.Address;
|
import org.hl7.fhir.r4.model.Address;
|
||||||
import org.hl7.fhir.r4.model.DateType;
|
import org.hl7.fhir.r4.model.DateType;
|
||||||
import org.hl7.fhir.r4.model.Enumerations;
|
import org.hl7.fhir.r4.model.Enumerations;
|
||||||
|
@ -28,6 +29,7 @@ import java.io.IOException;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.function.Predicate;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
|
@ -296,7 +298,8 @@ public class EmpiPersonMergerSvcTest extends BaseEmpiR4Test {
|
||||||
saveLink(toLink);
|
saveLink(toLink);
|
||||||
|
|
||||||
mergeSourcePatients();
|
mergeSourcePatients();
|
||||||
assertEquals(1, myToSourcePatient.getLink().size());
|
assertResourceHasLinkCount(myToSourcePatient, 1, (e) -> false);
|
||||||
|
// assertEquals(1, myToSourcePatient.getLink().size());
|
||||||
assertEquals(3, myEmpiLinkDao.count());
|
assertEquals(3, myEmpiLinkDao.count());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -311,7 +314,17 @@ public class EmpiPersonMergerSvcTest extends BaseEmpiR4Test {
|
||||||
myEmpiLinkHelper.logEmpiLinks();
|
myEmpiLinkHelper.logEmpiLinks();
|
||||||
|
|
||||||
assertThat(myToSourcePatient, is(possibleLinkedTo(myTargetPatient1, myTargetPatient2, myTargetPatient3)));
|
assertThat(myToSourcePatient, is(possibleLinkedTo(myTargetPatient1, myTargetPatient2, myTargetPatient3)));
|
||||||
assertEquals(3, myToSourcePatient.getLink().size());
|
// assertEquals(3, myToSourcePatient.getLink().size());
|
||||||
|
assertResourceHasAutoLinkCount(myToSourcePatient, 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertResourceHasAutoLinkCount(IBaseResource theResource, int theCount) {
|
||||||
|
assertResourceHasLinkCount(theResource, theCount, EmpiLink::isAuto);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertResourceHasLinkCount(IBaseResource theResource, int theCount, Predicate<EmpiLink> thePredicate) {
|
||||||
|
List<EmpiLink> links = myEmpiLinkDaoSvc.findEmpiLinksBySourceResource(theResource);
|
||||||
|
assertEquals(theCount, links.stream().filter(thePredicate).count());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -325,7 +338,7 @@ public class EmpiPersonMergerSvcTest extends BaseEmpiR4Test {
|
||||||
myEmpiLinkHelper.logEmpiLinks();
|
myEmpiLinkHelper.logEmpiLinks();
|
||||||
|
|
||||||
assertThat(myToSourcePatient, is(possibleLinkedTo(myTargetPatient1, myTargetPatient2, myTargetPatient3)));
|
assertThat(myToSourcePatient, is(possibleLinkedTo(myTargetPatient1, myTargetPatient2, myTargetPatient3)));
|
||||||
assertEquals(3, myToSourcePatient.getLink().size());
|
assertResourceHasAutoLinkCount(myToSourcePatient, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -341,9 +354,8 @@ public class EmpiPersonMergerSvcTest extends BaseEmpiR4Test {
|
||||||
|
|
||||||
assertThat(myToSourcePatient, is(possibleLinkedTo(myTargetPatient1, myTargetPatient2, myTargetPatient3)));
|
assertThat(myToSourcePatient, is(possibleLinkedTo(myTargetPatient1, myTargetPatient2, myTargetPatient3)));
|
||||||
|
|
||||||
List<EmpiLink> sourcePatientLinks = myEmpiLinkDaoSvc.findEmpiLinksBySourceResource(myToSourcePatient);
|
|
||||||
// assertEquals(3, myToSourcePatient.getLink().size());
|
// assertEquals(3, myToSourcePatient.getLink().size());
|
||||||
assertEquals(3, sourcePatientLinks.stream().filter(EmpiLink::isAuto).count());
|
assertResourceHasAutoLinkCount(myToSourcePatient, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -357,7 +369,9 @@ public class EmpiPersonMergerSvcTest extends BaseEmpiR4Test {
|
||||||
myEmpiLinkHelper.logEmpiLinks();
|
myEmpiLinkHelper.logEmpiLinks();
|
||||||
|
|
||||||
assertThat(myToSourcePatient, is(possibleLinkedTo(myTargetPatient1, myTargetPatient2, myTargetPatient3)));
|
assertThat(myToSourcePatient, is(possibleLinkedTo(myTargetPatient1, myTargetPatient2, myTargetPatient3)));
|
||||||
assertEquals(3, myToSourcePatient.getLink().size());
|
|
||||||
|
// assertEquals(3, myToSourcePatient.getLink().size());
|
||||||
|
assertResourceHasAutoLinkCount(myToSourcePatient, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue