Merge branch 'gg_20201105-remove-person-references' of github.com:jamesagnew/hapi-fhir into gg_20201105-remove-person-references
This commit is contained in:
commit
3d34502fae
|
@ -156,7 +156,8 @@ public class EmpiLink {
|
||||||
}
|
}
|
||||||
|
|
||||||
public EmpiLink setSourceResourcePid(Long theSourceResourcePid) {
|
public EmpiLink setSourceResourcePid(Long theSourceResourcePid) {
|
||||||
myPersonPid = theSourceResourcePid;
|
setPersonPid(theSourceResourcePid);
|
||||||
|
|
||||||
mySourceResourcePid = theSourceResourcePid;
|
mySourceResourcePid = theSourceResourcePid;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,6 +47,7 @@ import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class EmpiLinkDaoSvc {
|
public class EmpiLinkDaoSvc {
|
||||||
|
|
||||||
private static final Logger ourLog = Logs.getEmpiTroubleshootingLog();
|
private static final Logger ourLog = Logs.getEmpiTroubleshootingLog();
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
@ -330,33 +331,4 @@ public class EmpiLinkDaoSvc {
|
||||||
return myEmpiLinkFactory.newEmpiLink();
|
return myEmpiLinkFactory.newEmpiLink();
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Transactional
|
|
||||||
// public List<EmpiLink> deleteEmpiLinks(IAnyResource theSourceResource, IAnyResource theTargetResource) {
|
|
||||||
// Long sourceResourcePid = myIdHelperService.getPidOrNull(theSourceResource);
|
|
||||||
// if (sourceResourcePid == null) {
|
|
||||||
// if (ourLog.isDebugEnabled()) {
|
|
||||||
// ourLog.debug(String.format("Unable to find source resource for ID %s, no links deleted", sourceResourcePid));
|
|
||||||
// }
|
|
||||||
// return new ArrayList<>();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// Long targetResourcePid = myIdHelperService.getPidOrNull(theSourceResource);
|
|
||||||
// if (targetResourcePid == null) {
|
|
||||||
// if (ourLog.isDebugEnabled()) {
|
|
||||||
// ourLog.debug(String.format("Unable to find target resource for ID %s, no links deleted", targetResourcePid));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return new ArrayList<>();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// EmpiLink exampleLink = myEmpiLinkFactory
|
|
||||||
// .newEmpiLink()
|
|
||||||
// .setSourceResourcePid(sourceResourcePid)
|
|
||||||
// .setTargetPid(targetResourcePid);
|
|
||||||
//
|
|
||||||
// Example<EmpiLink> example = Example.of(exampleLink);
|
|
||||||
// List<EmpiLink> linksToDelete = myEmpiLinkDao.findAll(example);
|
|
||||||
// myEmpiLinkDao.deleteAll(linksToDelete);
|
|
||||||
// return linksToDelete;
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,26 +102,26 @@ public class EmpiLinkSvcImpl implements IEmpiLinkSvc {
|
||||||
myEmpiLinkDaoSvc.getEmpiLinksByPersonPidTargetPidAndMatchResult(targetId, personId, EmpiMatchResultEnum.NO_MATCH).isPresent();
|
myEmpiLinkDaoSvc.getEmpiLinksByPersonPidTargetPidAndMatchResult(targetId, personId, EmpiMatchResultEnum.NO_MATCH).isPresent();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
// @Override
|
||||||
@Transactional
|
// @Transactional
|
||||||
public void syncEmpiLinksToPersonLinks(IAnyResource thePersonResource, EmpiTransactionContext theEmpiTransactionContext) {
|
// public void syncEmpiLinksToPersonLinks(IAnyResource thePersonResource, EmpiTransactionContext theEmpiTransactionContext) {
|
||||||
// int origLinkCount = myPersonHelper.getLinkCount(thePersonResource);
|
// // int origLinkCount = myPersonHelper.getLinkCount(thePersonResource);
|
||||||
int origLinkCount = myEmpiLinkDaoSvc.findEmpiMatchLinksBySource(thePersonResource).size();
|
// int origLinkCount = myEmpiLinkDaoSvc.findEmpiMatchLinksBySource(thePersonResource).size();
|
||||||
|
//
|
||||||
List<EmpiLink> empiLinks = myEmpiLinkDaoSvc.findEmpiLinksBySourceResource(thePersonResource);
|
// List<EmpiLink> empiLinks = myEmpiLinkDaoSvc.findEmpiLinksBySourceResource(thePersonResource);
|
||||||
|
//
|
||||||
List<IBaseBackboneElement> newLinks = empiLinks.stream()
|
// List<IBaseBackboneElement> newLinks = empiLinks.stream()
|
||||||
.filter(link -> link.isMatch() || link.isPossibleMatch() || link.isRedirect())
|
// .filter(link -> link.isMatch() || link.isPossibleMatch() || link.isRedirect())
|
||||||
.map(this::personLinkFromEmpiLink)
|
// .map(this::personLinkFromEmpiLink)
|
||||||
.collect(Collectors.toList());
|
// .collect(Collectors.toList());
|
||||||
myPersonHelper.setLinks(thePersonResource, newLinks);
|
// myPersonHelper.setLinks(thePersonResource, newLinks);
|
||||||
if (newLinks.size() > origLinkCount) {
|
// if (newLinks.size() > origLinkCount) {
|
||||||
log(theEmpiTransactionContext, thePersonResource.getIdElement().toVersionless() + " links increased from " + origLinkCount + " to " + newLinks.size());
|
// log(theEmpiTransactionContext, thePersonResource.getIdElement().toVersionless() + " links increased from " + origLinkCount + " to " + newLinks.size());
|
||||||
} else if (newLinks.size() < origLinkCount) {
|
// } else if (newLinks.size() < origLinkCount) {
|
||||||
log(theEmpiTransactionContext, thePersonResource.getIdElement().toVersionless() + " links decreased from " + origLinkCount + " to " + newLinks.size());
|
// log(theEmpiTransactionContext, thePersonResource.getIdElement().toVersionless() + " links decreased from " + origLinkCount + " to " + newLinks.size());
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteLink(IAnyResource theSourceResource, IAnyResource theTargetResource, EmpiTransactionContext theEmpiTransactionContext) {
|
public void deleteLink(IAnyResource theSourceResource, IAnyResource theTargetResource, EmpiTransactionContext theEmpiTransactionContext) {
|
||||||
|
|
|
@ -81,7 +81,7 @@ public class EmpiLinkUpdaterSvcImpl implements IEmpiLinkUpdaterSvc {
|
||||||
empiLink.setMatchResult(theMatchResult);
|
empiLink.setMatchResult(theMatchResult);
|
||||||
empiLink.setLinkSource(EmpiLinkSourceEnum.MANUAL);
|
empiLink.setLinkSource(EmpiLinkSourceEnum.MANUAL);
|
||||||
myEmpiLinkDaoSvc.save(empiLink);
|
myEmpiLinkDaoSvc.save(empiLink);
|
||||||
myEmpiLinkSvc.syncEmpiLinksToPersonLinks(thePerson, theEmpiContext);
|
// myEmpiLinkSvc.syncEmpiLinksToPersonLinks(thePerson, theEmpiContext);
|
||||||
myEmpiResourceDaoSvc.upsertSourceResource(thePerson, theEmpiContext.getResourceType());
|
myEmpiResourceDaoSvc.upsertSourceResource(thePerson, theEmpiContext.getResourceType());
|
||||||
if (theMatchResult == EmpiMatchResultEnum.NO_MATCH) {
|
if (theMatchResult == EmpiMatchResultEnum.NO_MATCH) {
|
||||||
// Need to find a new Person to link this target to
|
// Need to find a new Person to link this target to
|
||||||
|
|
|
@ -57,21 +57,21 @@ public class EmpiPersonMergerSvcImpl implements IEmpiPersonMergerSvc {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public IAnyResource mergePersons(IAnyResource theFromPerson, IAnyResource theToPerson, EmpiTransactionContext theEmpiTransactionContext) {
|
public IAnyResource mergePersons(IAnyResource theFrom, IAnyResource theTo, EmpiTransactionContext theEmpiTransactionContext) {
|
||||||
Long toPersonPid = myIdHelperService.getPidOrThrowException(theToPerson);
|
Long toPid = myIdHelperService.getPidOrThrowException(theTo);
|
||||||
|
// TODO NG - Revisit when merge rules are defined
|
||||||
|
// myPersonHelper.mergeFields(theFrom, theTo);
|
||||||
|
mergeLinks(theFrom, theTo, toPid, theEmpiTransactionContext);
|
||||||
|
refreshLinksAndUpdatePerson(theTo, theEmpiTransactionContext);
|
||||||
|
|
||||||
myPersonHelper.mergePersonFields(theFromPerson, theToPerson);
|
Long fromPersonPid = myIdHelperService.getPidOrThrowException(theFrom);
|
||||||
mergeLinks(theFromPerson, theToPerson, toPersonPid, theEmpiTransactionContext);
|
addMergeLink(fromPersonPid, toPid);
|
||||||
refreshLinksAndUpdatePerson(theToPerson, theEmpiTransactionContext);
|
myPersonHelper.deactivateResource(theFrom);
|
||||||
|
|
||||||
Long fromPersonPid = myIdHelperService.getPidOrThrowException(theFromPerson);
|
refreshLinksAndUpdatePerson(theFrom, theEmpiTransactionContext);
|
||||||
addMergeLink(fromPersonPid, toPersonPid);
|
|
||||||
myPersonHelper.deactivatePerson(theFromPerson);
|
|
||||||
|
|
||||||
refreshLinksAndUpdatePerson(theFromPerson, theEmpiTransactionContext);
|
log(theEmpiTransactionContext, "Merged " + theFrom.getIdElement().toVersionless() + " into " + theTo.getIdElement().toVersionless());
|
||||||
|
return theTo;
|
||||||
log(theEmpiTransactionContext, "Merged " + theFromPerson.getIdElement().toVersionless() + " into " + theToPerson.getIdElement().toVersionless());
|
|
||||||
return theToPerson;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addMergeLink(Long theDeactivatedPersonPid, Long theActivePersonPid) {
|
private void addMergeLink(Long theDeactivatedPersonPid, Long theActivePersonPid) {
|
||||||
|
@ -84,7 +84,7 @@ public class EmpiPersonMergerSvcImpl implements IEmpiPersonMergerSvc {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void refreshLinksAndUpdatePerson(IAnyResource theToPerson, EmpiTransactionContext theEmpiTransactionContext) {
|
private void refreshLinksAndUpdatePerson(IAnyResource theToPerson, EmpiTransactionContext theEmpiTransactionContext) {
|
||||||
myEmpiLinkSvc.syncEmpiLinksToPersonLinks(theToPerson, theEmpiTransactionContext);
|
// myEmpiLinkSvc.syncEmpiLinksToPersonLinks(theToPerson, theEmpiTransactionContext);
|
||||||
myEmpiResourceDaoSvc.upsertSourceResource(theToPerson, theEmpiTransactionContext.getResourceType());
|
myEmpiResourceDaoSvc.upsertSourceResource(theToPerson, theEmpiTransactionContext.getResourceType());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -143,7 +143,7 @@ public class EmpiLinkSvcTest extends BaseEmpiR4Test {
|
||||||
|
|
||||||
// Test: it should be impossible to have a AUTO NO_MATCH record. The only NO_MATCH records in the system must be MANUAL.
|
// Test: it should be impossible to have a AUTO NO_MATCH record. The only NO_MATCH records in the system must be MANUAL.
|
||||||
try {
|
try {
|
||||||
myEmpiLinkSvc.updateLink(sourcePatient, patient, EmpiMatchOutcome.NO_MATCH, EmpiLinkSourceEnum.AUTO, null);
|
myEmpiLinkSvc.updateLink(sourcePatient, patient, EmpiMatchOutcome.NO_MATCH, EmpiLinkSourceEnum.AUTO, createContextForUpdate("Patient"));
|
||||||
fail();
|
fail();
|
||||||
} catch (InternalErrorException e) {
|
} catch (InternalErrorException e) {
|
||||||
assertThat(e.getMessage(), is(equalTo("EMPI system is not allowed to automatically NO_MATCH a resource")));
|
assertThat(e.getMessage(), is(equalTo("EMPI system is not allowed to automatically NO_MATCH a resource")));
|
||||||
|
@ -159,7 +159,7 @@ public class EmpiLinkSvcTest extends BaseEmpiR4Test {
|
||||||
|
|
||||||
myEmpiLinkDaoSvc.createOrUpdateLinkEntity(sourcePatient, patient1, EmpiMatchOutcome.NEW_PERSON_MATCH, EmpiLinkSourceEnum.MANUAL, createContextForCreate("Patient"));
|
myEmpiLinkDaoSvc.createOrUpdateLinkEntity(sourcePatient, patient1, EmpiMatchOutcome.NEW_PERSON_MATCH, EmpiLinkSourceEnum.MANUAL, createContextForCreate("Patient"));
|
||||||
myEmpiLinkDaoSvc.createOrUpdateLinkEntity(sourcePatient, patient2, EmpiMatchOutcome.NO_MATCH, EmpiLinkSourceEnum.MANUAL, createContextForCreate("Patient"));
|
myEmpiLinkDaoSvc.createOrUpdateLinkEntity(sourcePatient, patient2, EmpiMatchOutcome.NO_MATCH, EmpiLinkSourceEnum.MANUAL, createContextForCreate("Patient"));
|
||||||
myEmpiLinkSvc.syncEmpiLinksToPersonLinks(sourcePatient, createContextForCreate("Patient"));
|
// myEmpiLinkSvc.syncEmpiLinksToPersonLinks(sourcePatient, createContextForCreate("Patient"));
|
||||||
assertTrue(sourcePatient.hasLink());
|
assertTrue(sourcePatient.hasLink());
|
||||||
//TODO GGG update this test once we decide what has to happen here. There is no more "syncing links"
|
//TODO GGG update this test once we decide what has to happen here. There is no more "syncing links"
|
||||||
//assertEquals(patient1.getIdElement().toVersionless().getValue(), sourcePatient.getLinkFirstRep().getTarget().getReference());
|
//assertEquals(patient1.getIdElement().toVersionless().getValue(), sourcePatient.getLinkFirstRep().getTarget().getReference());
|
||||||
|
|
|
@ -114,12 +114,19 @@ public class EmpiPersonMergerSvcTest extends BaseEmpiR4Test {
|
||||||
}
|
}
|
||||||
|
|
||||||
private EmpiTransactionContext createEmpiContext() {
|
private EmpiTransactionContext createEmpiContext() {
|
||||||
return new EmpiTransactionContext(TransactionLogMessages.createFromTransactionGuid(UUID.randomUUID().toString()), EmpiTransactionContext.OperationType.MERGE_PERSONS);
|
EmpiTransactionContext empiTransactionContext = new EmpiTransactionContext(TransactionLogMessages.createFromTransactionGuid(UUID.randomUUID().toString()), EmpiTransactionContext.OperationType.MERGE_PERSONS);
|
||||||
|
empiTransactionContext.setResourceType("Patient");
|
||||||
|
return empiTransactionContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void mergeRemovesPossibleDuplicatesLink() {
|
public void mergeRemovesPossibleDuplicatesLink() {
|
||||||
EmpiLink empiLink = myEmpiLinkDaoSvc.newEmpiLink().setSourceResourcePid(myToSourcePatientPid).setTargetPid(myFromSourcePatientPid).setMatchResult(EmpiMatchResultEnum.POSSIBLE_DUPLICATE).setLinkSource(EmpiLinkSourceEnum.AUTO);
|
EmpiLink empiLink = myEmpiLinkDaoSvc.newEmpiLink()
|
||||||
|
.setSourceResourcePid(myToSourcePatientPid)
|
||||||
|
.setTargetPid(myFromSourcePatientPid)
|
||||||
|
.setMatchResult(EmpiMatchResultEnum.POSSIBLE_DUPLICATE)
|
||||||
|
.setLinkSource(EmpiLinkSourceEnum.AUTO);
|
||||||
|
|
||||||
saveLink(empiLink);
|
saveLink(empiLink);
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -142,10 +149,11 @@ public class EmpiPersonMergerSvcTest extends BaseEmpiR4Test {
|
||||||
populatePerson(myFromSourcePatient);
|
populatePerson(myFromSourcePatient);
|
||||||
|
|
||||||
Patient mergedSourcePatient = mergeSourcePatients();
|
Patient mergedSourcePatient = mergeSourcePatients();
|
||||||
HumanName returnedName = mergedSourcePatient.getNameFirstRep();
|
// TODO NG - Revisit when rules are ready
|
||||||
assertEquals(GIVEN_NAME, returnedName.getGivenAsSingleString());
|
// HumanName returnedName = mergedSourcePatient.getNameFirstRep();
|
||||||
assertEquals(FAMILY_NAME, returnedName.getFamily());
|
// assertEquals(GIVEN_NAME, returnedName.getGivenAsSingleString());
|
||||||
assertEquals(POSTAL_CODE, mergedSourcePatient.getAddressFirstRep().getPostalCode());
|
// assertEquals(FAMILY_NAME, returnedName.getFamily());
|
||||||
|
// assertEquals(POSTAL_CODE, mergedSourcePatient.getAddressFirstRep().getPostalCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -351,37 +359,39 @@ public class EmpiPersonMergerSvcTest extends BaseEmpiR4Test {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMergeNames() {
|
public void testMergeNames() {
|
||||||
myFromSourcePatient.addName().addGiven("Jim");
|
// TODO NG - Revisit when rules are available
|
||||||
myFromSourcePatient.getNameFirstRep().addGiven("George");
|
// myFromSourcePatient.addName().addGiven("Jim");
|
||||||
assertThat(myFromSourcePatient.getName(), hasSize(1));
|
// myFromSourcePatient.getNameFirstRep().addGiven("George");
|
||||||
assertThat(myFromSourcePatient.getName().get(0).getGiven(), hasSize(2));
|
// assertThat(myFromSourcePatient.getName(), hasSize(1));
|
||||||
|
// assertThat(myFromSourcePatient.getName().get(0).getGiven(), hasSize(2));
|
||||||
myToSourcePatient.addName().addGiven("Jeff");
|
//
|
||||||
myToSourcePatient.getNameFirstRep().addGiven("George");
|
// myToSourcePatient.addName().addGiven("Jeff");
|
||||||
assertThat(myToSourcePatient.getName(), hasSize(1));
|
// myToSourcePatient.getNameFirstRep().addGiven("George");
|
||||||
assertThat(myToSourcePatient.getName().get(0).getGiven(), hasSize(2));
|
// assertThat(myToSourcePatient.getName(), hasSize(1));
|
||||||
|
// assertThat(myToSourcePatient.getName().get(0).getGiven(), hasSize(2));
|
||||||
Patient mergedSourcePatient = mergeSourcePatients();
|
//
|
||||||
assertThat(mergedSourcePatient.getName(), hasSize(2));
|
// Patient mergedSourcePatient = mergeSourcePatients();
|
||||||
assertThat(mergedSourcePatient.getName().get(0).getGiven(), hasSize(2));
|
// assertThat(mergedSourcePatient.getName(), hasSize(2));
|
||||||
assertThat(mergedSourcePatient.getName().get(1).getGiven(), hasSize(2));
|
// assertThat(mergedSourcePatient.getName().get(0).getGiven(), hasSize(2));
|
||||||
|
// assertThat(mergedSourcePatient.getName().get(1).getGiven(), hasSize(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMergeNamesAllSame() {
|
public void testMergeNamesAllSame() {
|
||||||
myFromSourcePatient.addName().addGiven("Jim");
|
// TODO NG - Revisit when rules are available
|
||||||
myFromSourcePatient.getNameFirstRep().addGiven("George");
|
// myFromSourcePatient.addName().addGiven("Jim");
|
||||||
assertThat(myFromSourcePatient.getName(), hasSize(1));
|
// myFromSourcePatient.getNameFirstRep().addGiven("George");
|
||||||
assertThat(myFromSourcePatient.getName().get(0).getGiven(), hasSize(2));
|
// assertThat(myFromSourcePatient.getName(), hasSize(1));
|
||||||
|
// assertThat(myFromSourcePatient.getName().get(0).getGiven(), hasSize(2));
|
||||||
myToSourcePatient.addName().addGiven("Jim");
|
//
|
||||||
myToSourcePatient.getNameFirstRep().addGiven("George");
|
// myToSourcePatient.addName().addGiven("Jim");
|
||||||
assertThat(myToSourcePatient.getName(), hasSize(1));
|
// myToSourcePatient.getNameFirstRep().addGiven("George");
|
||||||
assertThat(myToSourcePatient.getName().get(0).getGiven(), hasSize(2));
|
// assertThat(myToSourcePatient.getName(), hasSize(1));
|
||||||
|
// assertThat(myToSourcePatient.getName().get(0).getGiven(), hasSize(2));
|
||||||
mergeSourcePatients();
|
//
|
||||||
assertThat(myToSourcePatient.getName(), hasSize(1));
|
// mergeSourcePatients();
|
||||||
assertThat(myToSourcePatient.getName().get(0).getGiven(), hasSize(2));
|
// assertThat(myToSourcePatient.getName(), hasSize(1));
|
||||||
|
// assertThat(myToSourcePatient.getName().get(0).getGiven(), hasSize(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -32,7 +32,7 @@ public class EmpiResourceDaoSvcTest extends BaseEmpiR4Test {
|
||||||
badSourcePatient.setActive(false);
|
badSourcePatient.setActive(false);
|
||||||
myPatientDao.update(badSourcePatient);
|
myPatientDao.update(badSourcePatient);
|
||||||
|
|
||||||
Optional<IAnyResource> foundPerson = myResourceDaoSvc.searchSourceResourceByEID(TEST_EID, "Person");
|
Optional<IAnyResource> foundPerson = myResourceDaoSvc.searchSourceResourceByEID(TEST_EID, "Patient");
|
||||||
assertTrue(foundPerson.isPresent());
|
assertTrue(foundPerson.isPresent());
|
||||||
assertThat(foundPerson.get().getIdElement().toUnqualifiedVersionless().getValue(), is(goodSourcePatient.getIdElement().toUnqualifiedVersionless().getValue()));
|
assertThat(foundPerson.get().getIdElement().toUnqualifiedVersionless().getValue(), is(goodSourcePatient.getIdElement().toUnqualifiedVersionless().getValue()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,11 +36,11 @@ public interface IEmpiLinkSvc {
|
||||||
*/
|
*/
|
||||||
void updateLink(IAnyResource thePerson, IAnyResource theTargetResource, EmpiMatchOutcome theMatchResult, EmpiLinkSourceEnum theLinkSource, EmpiTransactionContext theEmpiTransactionContext);
|
void updateLink(IAnyResource thePerson, IAnyResource theTargetResource, EmpiMatchOutcome theMatchResult, EmpiLinkSourceEnum theLinkSource, EmpiTransactionContext theEmpiTransactionContext);
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* Replace Person.link values from what they should be based on EmpiLink values
|
// * Replace Person.link values from what they should be based on EmpiLink values
|
||||||
* @param thePersonResource the person to correct the links on.
|
// * @param thePersonResource the person to correct the links on.
|
||||||
*/
|
// */
|
||||||
void syncEmpiLinksToPersonLinks(IAnyResource thePersonResource, EmpiTransactionContext theEmpiTransactionContext);
|
// void syncEmpiLinksToPersonLinks(IAnyResource thePersonResource, EmpiTransactionContext theEmpiTransactionContext);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a link between given Person and target patient/practitioner
|
* Delete a link between given Person and target patient/practitioner
|
||||||
|
|
|
@ -102,20 +102,24 @@ public class PersonHelper {
|
||||||
|
|
||||||
addHapiEidIfNoExternalEidIsPresent(newSourceResource, sourceResourceIdentifier, theIncomingResource);
|
addHapiEidIfNoExternalEidIsPresent(newSourceResource, sourceResourceIdentifier, theIncomingResource);
|
||||||
|
|
||||||
setActive(newSourceResource, resourceDefinition);
|
setActive(newSourceResource, resourceDefinition, true);
|
||||||
|
|
||||||
EmpiUtil.setEmpiManaged(newSourceResource);
|
EmpiUtil.setEmpiManaged(newSourceResource);
|
||||||
|
|
||||||
return (T) newSourceResource;
|
return (T) newSourceResource;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setActive(IBaseResource theNewSourceResource, RuntimeResourceDefinition theResourceDefinition) {
|
private void setActive(IBaseResource theResource, boolean theActiveFlag) {
|
||||||
|
setActive(theResource, myFhirContext.getResourceDefinition(theResource), theActiveFlag);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setActive(IBaseResource theNewSourceResource, RuntimeResourceDefinition theResourceDefinition, boolean theActiveFlag) {
|
||||||
BaseRuntimeChildDefinition activeChildDefinition = theResourceDefinition.getChildByName("active");
|
BaseRuntimeChildDefinition activeChildDefinition = theResourceDefinition.getChildByName("active");
|
||||||
if (activeChildDefinition == null) {
|
if (activeChildDefinition == null) {
|
||||||
ourLog.warn(String.format("Unable to set active flag on the provided source resource %s.", theNewSourceResource));
|
ourLog.warn(String.format("Unable to set active flag on the provided source resource %s.", theNewSourceResource));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
activeChildDefinition.getMutator().setValue(theNewSourceResource, toBooleanType(true));
|
activeChildDefinition.getMutator().setValue(theNewSourceResource, toBooleanType(theActiveFlag));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -299,6 +303,16 @@ public class PersonHelper {
|
||||||
throw new IllegalStateException("Unsupported FHIR version " + myFhirContext.getVersion().getVersion());
|
throw new IllegalStateException("Unsupported FHIR version " + myFhirContext.getVersion().getVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private <T extends IBase> boolean fromBooleanType(T theFlag) {
|
||||||
|
switch (myFhirContext.getVersion().getVersion()) {
|
||||||
|
case R4:
|
||||||
|
return ((BooleanType)theFlag).booleanValue();
|
||||||
|
case DSTU3:
|
||||||
|
return ((org.hl7.fhir.dstu3.model.BooleanType)theFlag).booleanValue();
|
||||||
|
}
|
||||||
|
throw new IllegalStateException("Unsupported FHIR version " + myFhirContext.getVersion().getVersion());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To avoid adding duplicate
|
* To avoid adding duplicate
|
||||||
*
|
*
|
||||||
|
@ -315,7 +329,7 @@ public class PersonHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void mergePersonFields(IBaseResource theFromPerson, IBaseResource theToPerson) {
|
public void mergeFields(IBaseResource theFromPerson, IBaseResource theToPerson) {
|
||||||
switch (myFhirContext.getVersion().getVersion()) {
|
switch (myFhirContext.getVersion().getVersion()) {
|
||||||
case R4:
|
case R4:
|
||||||
mergeR4PersonFields(theFromPerson, theToPerson);
|
mergeR4PersonFields(theFromPerson, theToPerson);
|
||||||
|
@ -460,31 +474,33 @@ public class PersonHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deactivatePerson(IAnyResource thePerson) {
|
public void deactivateResource(IAnyResource theResource) {
|
||||||
switch (myFhirContext.getVersion().getVersion()) {
|
// get a ref to the actual ID Field
|
||||||
case R4:
|
setActive(theResource, myFhirContext.getResourceDefinition(theResource), false);
|
||||||
Person personR4 = (Person) thePerson;
|
|
||||||
personR4.setActive(false);
|
|
||||||
break;
|
|
||||||
case DSTU3:
|
|
||||||
org.hl7.fhir.dstu3.model.Person personStu3 = (org.hl7.fhir.dstu3.model.Person) thePerson;
|
|
||||||
personStu3.setActive(false);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new UnsupportedOperationException("Version not supported: " + myFhirContext.getVersion().getVersion());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isDeactivated(IBaseResource thePerson) {
|
public boolean isDeactivated(IBaseResource thePerson) {
|
||||||
switch (myFhirContext.getVersion().getVersion()) {
|
RuntimeResourceDefinition resourceDefinition = myFhirContext.getResourceDefinition(thePerson);
|
||||||
case R4:
|
BaseRuntimeChildDefinition activeChildDefinition = resourceDefinition.getChildByName("active");
|
||||||
Person personR4 = (Person) thePerson;
|
|
||||||
return !personR4.getActive();
|
Optional<IBase> value = activeChildDefinition.getAccessor().getFirstValueOrNull(thePerson);
|
||||||
case DSTU3:
|
return value.map(v -> {
|
||||||
org.hl7.fhir.dstu3.model.Person personStu3 = (org.hl7.fhir.dstu3.model.Person) thePerson;
|
return !fromBooleanType(v);
|
||||||
return !personStu3.getActive();
|
}).orElseThrow(
|
||||||
default:
|
() -> new UnsupportedOperationException(String.format("Resource %s does not support deactivation", resourceDefinition.getName()))
|
||||||
throw new UnsupportedOperationException("Version not supported: " + myFhirContext.getVersion().getVersion());
|
);
|
||||||
}
|
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
// switch (myFhirContext.getVersion().getVersion()) {
|
||||||
|
// case R4:
|
||||||
|
// Person personR4 = (Person) thePerson;
|
||||||
|
// return !personR4.getActive();
|
||||||
|
// case DSTU3:
|
||||||
|
// org.hl7.fhir.dstu3.model.Person personStu3 = (org.hl7.fhir.dstu3.model.Person) thePerson;
|
||||||
|
// return !personStu3.getActive();
|
||||||
|
// default:
|
||||||
|
// throw
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue