EID copy magic

This commit is contained in:
Nick Goupinets 2020-11-05 17:39:25 -05:00
parent e9509f9963
commit 0b4f647520
5 changed files with 477 additions and 447 deletions

View File

@ -108,7 +108,8 @@ public class EmpiEidUpdateService {
private void createNewPersonAndFlagAsDuplicate(IAnyResource theResource, EmpiTransactionContext theEmpiTransactionContext, IAnyResource theOldPerson) {
log(theEmpiTransactionContext, "Duplicate detected based on the fact that both resources have different external EIDs.");
IAnyResource newPerson = myPersonHelper.createPersonFromEmpiTarget(theResource);
IAnyResource newPerson = myPersonHelper.createSourceResourceFromEmpiTarget(theResource);
myEmpiLinkSvc.updateLink(newPerson, theResource, EmpiMatchOutcome.NEW_PERSON_MATCH, EmpiLinkSourceEnum.AUTO, theEmpiTransactionContext);
myEmpiLinkSvc.updateLink(newPerson, theOldPerson, EmpiMatchOutcome.POSSIBLE_DUPLICATE, EmpiLinkSourceEnum.AUTO, theEmpiTransactionContext);
}

View File

@ -121,7 +121,7 @@ public class EmpiMatchLinkSvc {
private void handleEmpiWithNoCandidates(IAnyResource theResource, EmpiTransactionContext theEmpiTransactionContext) {
log(theEmpiTransactionContext, String.format("There were no matched candidates for EMPI, creating a new %s.", theResource.getIdElement().getResourceType()));
IAnyResource newPerson = myPersonHelper.createPersonFromEmpiTarget(theResource);
IAnyResource newPerson = myPersonHelper.createSourceResourceFromEmpiTarget(theResource);
// TODO GGG :)
// 1. Get the right helper
// 2. Create source resoruce for the EMPI target
@ -135,7 +135,7 @@ public class EmpiMatchLinkSvc {
IAnyResource person = myEmpiPersonFindingSvc.getPersonFromMatchedPersonCandidate(thePersonCandidate);
if (myPersonHelper.isPotentialDuplicate(person, theResource)) {
log(theEmpiTransactionContext, "Duplicate detected based on the fact that both resources have different external EIDs.");
IAnyResource newPerson = myPersonHelper.createPersonFromEmpiTarget(theResource);
IAnyResource newPerson = myPersonHelper.createSourceResourceFromEmpiTarget(theResource);
myEmpiLinkSvc.updateLink(newPerson, theResource, EmpiMatchOutcome.NEW_PERSON_MATCH, EmpiLinkSourceEnum.AUTO, theEmpiTransactionContext);
myEmpiLinkSvc.updateLink(newPerson, person, EmpiMatchOutcome.POSSIBLE_DUPLICATE, EmpiLinkSourceEnum.AUTO, theEmpiTransactionContext);
} else {

View File

@ -34,16 +34,9 @@ import static ca.uhn.fhir.empi.api.EmpiMatchResultEnum.NO_MATCH;
import static ca.uhn.fhir.empi.api.EmpiMatchResultEnum.POSSIBLE_DUPLICATE;
import static ca.uhn.fhir.empi.api.EmpiMatchResultEnum.POSSIBLE_MATCH;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.blankOrNullString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.equalToIgnoringCase;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.in;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.Matchers.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.slf4j.LoggerFactory.getLogger;
public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test {
@ -341,7 +334,7 @@ public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test {
//In a normal situation, janePatient2 would just match to jane patient, but here we need to hack it so they are their
//own individual Persons for the purpose of this test.
IAnyResource person = myPersonHelper.createPersonFromEmpiTarget(janePatient2);
IAnyResource person = myPersonHelper.createSourceResourceFromEmpiTarget(janePatient2);
myEmpiLinkSvc.updateLink(person, janePatient2, EmpiMatchOutcome.NEW_PERSON_MATCH, EmpiLinkSourceEnum.AUTO, createContextForCreate());
assertThat(janePatient, is(not(sameSourceResourceAs(janePatient2))));
@ -420,6 +413,24 @@ public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test {
assertThat(patient3, is(sameSourceResourceAs(patient)));
}
@Test
public void testCreateSourceResourceFromEmpiTarget() {
Patient janePatient = buildJanePatient();
Patient janeSourceResourcePatient = myPersonHelper.createSourceResourceFromEmpiTarget(janePatient);
assertThat("Resource must not be identical", janePatient != janeSourceResourcePatient);
assertFalse(janePatient.getIdentifier().isEmpty());
assertFalse(janeSourceResourcePatient.getIdentifier().isEmpty());
Identifier janeId = janePatient.getIdentifier().get(0);
Identifier janeSourceResourceId = janeSourceResourcePatient.getIdentifier().get(0);
assertEquals(janeId.getValue(), janeSourceResourceId.getValue());
assertEquals(janeId.getSystem(), janeSourceResourceId.getSystem());
}
//Case #1
@Test
public void testPatientUpdateOverwritesPersonDataOnChanges() {

View File

@ -22,8 +22,8 @@ package ca.uhn.fhir.empi.util;
import ca.uhn.fhir.context.BaseRuntimeChildDefinition;
import ca.uhn.fhir.context.BaseRuntimeElementCompositeDefinition;
import ca.uhn.fhir.context.BaseRuntimeElementDefinition;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.FhirVersionEnum;
import ca.uhn.fhir.context.RuntimeResourceDefinition;
import ca.uhn.fhir.empi.api.EmpiConstants;
import ca.uhn.fhir.empi.api.IEmpiSettings;
@ -31,7 +31,6 @@ import ca.uhn.fhir.empi.log.Logs;
import ca.uhn.fhir.empi.model.CanonicalEID;
import ca.uhn.fhir.empi.model.CanonicalIdentityAssuranceLevel;
import ca.uhn.fhir.empi.model.EmpiTransactionContext;
import ca.uhn.fhir.model.api.annotation.ResourceDef;
import ca.uhn.fhir.util.FhirTerser;
import org.apache.commons.lang3.StringUtils;
import org.hl7.fhir.instance.model.api.IAnyResource;
@ -63,6 +62,9 @@ import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static ca.uhn.fhir.context.FhirVersionEnum.DSTU3;
import static ca.uhn.fhir.context.FhirVersionEnum.R4;
@Service
public class PersonHelper {
private static final Logger ourLog = Logs.getEmpiTroubleshootingLog();
@ -118,9 +120,10 @@ public class PersonHelper {
/**
* Create or update a link from source {@link IBaseResource} to the target {@link IIdType}, with the given {@link CanonicalIdentityAssuranceLevel}.
* @param thePerson The person who's link needs to be updated.
* @param theResourceId The target of the link
* @param canonicalAssuranceLevel The level of certainty of this link.
*
* @param thePerson The person who's link needs to be updated.
* @param theResourceId The target of the link
* @param canonicalAssuranceLevel The level of certainty of this link.
* @param theEmpiTransactionContext
*/
public void addOrUpdateLink(IBaseResource thePerson, IIdType theResourceId, @Nonnull CanonicalIdentityAssuranceLevel canonicalAssuranceLevel, EmpiTransactionContext theEmpiTransactionContext) {
@ -189,8 +192,9 @@ public class PersonHelper {
/**
* Removes a link from the given {@link IBaseResource} to the target {@link IIdType}.
* @param thePerson The person to remove the link from.
* @param theResourceId The target ID to remove.
*
* @param thePerson The person to remove the link from.
* @param theResourceId The target ID to remove.
* @param theEmpiTransactionContext
*/
public void removeLink(IBaseResource thePerson, IIdType theResourceId, EmpiTransactionContext theEmpiTransactionContext) {
@ -214,30 +218,32 @@ public class PersonHelper {
}
/**
* Create a Person from a given patient. This will carry over the Patient's EID if it exists. If it does not exist,
* Creates a copy of the specified resource. This method will carry over resource EID if it exists. If it does not exist,
* a randomly generated UUID EID will be created.
*
* @param theSourceResource The Patient that will be used as the starting point for the person.
* @return the Person that is created.
* @param <T> Supported MDM resource type (e.g. Patient, Practitioner)
* @param theSourceResource The resource that will be used as the starting point for the MDM linking.
*/
public IAnyResource createPersonFromEmpiTarget(IAnyResource theSourceResource) {
public <T extends IAnyResource> T createSourceResourceFromEmpiTarget(T theSourceResource) {
ensureContextSupported();
List<CanonicalEID> eidsToApply = myEIDHelper.getExternalEid(theSourceResource);
if (eidsToApply.isEmpty()) {
eidsToApply.add(myEIDHelper.createHapiEid());
}
FhirTerser terser = myFhirContext.newTerser();
// get a ref to the actual ID Field
RuntimeResourceDefinition resourceDefinition = myFhirContext.getResourceDefinition(theSourceResource);
IBaseResource newSourceResource = resourceDefinition.newInstance();
// FHIR terser - clone into
// hapi has 2 metamodels: for children and types
BaseRuntimeChildDefinition sourceResourceIdentifier = resourceDefinition.getChildByName("identifier");
// FHIR choice types - fields within fhir where we have a choice of ids
BaseRuntimeElementCompositeDefinition<?> childIdentifier =
(BaseRuntimeElementCompositeDefinition<?>) sourceResourceIdentifier.getChildByName("identifier");
FhirTerser terser = myFhirContext.newTerser();
List<IBase> sourceResourceEids = sourceResourceIdentifier.getAccessor().getValues(theSourceResource);
for (IBase base : sourceResourceEids) {
IBase sourceResourceNewIdentifier = childIdentifier.newInstance();
@ -245,12 +251,13 @@ public class PersonHelper {
sourceResourceIdentifier.getMutator().addValue(newSourceResource, sourceResourceNewIdentifier);
}
// now we have all IDs pulled into it
// terser.getValues() - we will need to add values into the target manually, use mutator for that
terser.cloneInto(theSourceResource, newSourceResource, true);
return (T) newSourceResource;
switch (myFhirContext.getVersion().getVersion()) {
case R4:
// switch (myFhirContext.getVersion().getVersion()) {
// case R4:
// Person personR4 = new Person();
//
// personR4.setActive(true);
@ -259,434 +266,454 @@ public class PersonHelper {
// copyEmpiTargetDataIntoPerson(theSourceResource, personR4, true);
// return personR4;
// IAnyResource sourceResource = theSourceResource;
return null;
case DSTU3:
org.hl7.fhir.dstu3.model.Person personDstu3 = new org.hl7.fhir.dstu3.model.Person();
personDstu3.setActive(true);
eidsToApply.forEach(eid -> personDstu3.addIdentifier(eid.toDSTU3()));
personDstu3.getMeta().addTag((org.hl7.fhir.dstu3.model.Coding) buildEmpiManagedTag());
copyEmpiTargetDataIntoPerson(theSourceResource, personDstu3, true);
return personDstu3;
default:
throw new UnsupportedOperationException("Version not supported: " + myFhirContext.getVersion().getVersion());
// return null;
// case DSTU3:
// org.hl7.fhir.dstu3.model.Person personDstu3 = new org.hl7.fhir.dstu3.model.Person();
// personDstu3.setActive(true);
// eidsToApply.forEach(eid -> personDstu3.addIdentifier(eid.toDSTU3()));
// personDstu3.getMeta().addTag((org.hl7.fhir.dstu3.model.Coding) buildEmpiManagedTag());
// copyEmpiTargetDataIntoPerson(theSourceResource, personDstu3, true);
// return personDstu3;
// default:
// throw new UnsupportedOperationException("Version not supported: " + myFhirContext.getVersion().getVersion());
// }
}
}
/**
* This will copy over all attributes that are copiable from Patient/Practitioner to Person.
*
* @param theBaseResource The incoming {@link Patient} or {@link Practitioner} who's data we want to copy into Person.
* @param thePerson The incoming {@link Person} who needs to have their data updated.
* @param theAllowOverwriting If enabled, will overwrite existing values on the person. Otherwise, will set them only if they are currently empty/null.
*
*/
private void copyEmpiTargetDataIntoPerson(IBaseResource theBaseResource, IBaseResource thePerson, Boolean theAllowOverwriting) {
switch (myFhirContext.getVersion().getVersion()) {
case R4:
copyR4TargetInformation(theBaseResource, thePerson, theAllowOverwriting);
break;
case DSTU3:
copyDSTU3TargetInformation(theBaseResource, thePerson, theAllowOverwriting);
break;
default:
throw new UnsupportedOperationException("Version not supported: " + myFhirContext.getVersion().getVersion());
private void ensureContextSupported() {
FhirVersionEnum fhirVersion = myFhirContext.getVersion().getVersion();
if (fhirVersion == R4 || fhirVersion == DSTU3) {
return;
}
throw new UnsupportedOperationException("Version not supported: " + myFhirContext.getVersion().getVersion());
}
}
private void copyR4TargetInformation(IBaseResource theBaseResource, IBaseResource thePerson, boolean theAllowOverwriting) {
Person person = (Person) thePerson;
switch (myFhirContext.getResourceType(theBaseResource)) {
case "Patient":
Patient patient = (Patient) theBaseResource;
if (theAllowOverwriting || person.getName().isEmpty()) {
person.setName(patient.getName());
}
if (theAllowOverwriting || person.getAddress().isEmpty()) {
person.setAddress(patient.getAddress());
}
if (theAllowOverwriting || person.getTelecom().isEmpty()) {
person.setTelecom(patient.getTelecom());
}
if (theAllowOverwriting || person.getBirthDate() == null) {
person.setBirthDate(patient.getBirthDate());
}
if (theAllowOverwriting || person.getGender() == null) {
person.setGender(patient.getGender());
}
if (theAllowOverwriting || person.getPhoto().isEmpty()) {
person.setPhoto(patient.getPhotoFirstRep());
}
break;
case "Practitioner":
Practitioner practitioner = (Practitioner) theBaseResource;
if (theAllowOverwriting || person.getName().isEmpty()) {
person.setName(practitioner.getName());
}
if (theAllowOverwriting || person.getAddress().isEmpty()) {
person.setAddress(practitioner.getAddress());
}
if (theAllowOverwriting || person.getTelecom().isEmpty()) {
person.setTelecom(practitioner.getTelecom());
}
if (theAllowOverwriting || person.getBirthDate() == null) {
person.setBirthDate(practitioner.getBirthDate());
}
if (theAllowOverwriting || person.getGender() == null) {
person.setGender(practitioner.getGender());
}
if (theAllowOverwriting || person.getPhoto().isEmpty()) {
person.setPhoto(practitioner.getPhotoFirstRep());
}
break;
default:
throw new UnsupportedOperationException("EMPI targets are limited to Practitioner/Patient. This is a : " + myFhirContext.getResourceType(theBaseResource));
/**
* This will copy over all attributes that are copiable from Patient/Practitioner to Person.
*
* @param theBaseResource The incoming {@link Patient} or {@link Practitioner} who's data we want to copy into Person.
* @param thePerson The incoming {@link Person} who needs to have their data updated.
* @param theAllowOverwriting If enabled, will overwrite existing values on the person. Otherwise, will set them only if they are currently empty/null.
*/
private void copyEmpiTargetDataIntoPerson (IBaseResource theBaseResource, IBaseResource thePerson, Boolean
theAllowOverwriting){
switch (myFhirContext.getVersion().getVersion()) {
case R4:
copyR4TargetInformation(theBaseResource, thePerson, theAllowOverwriting);
break;
case DSTU3:
copyDSTU3TargetInformation(theBaseResource, thePerson, theAllowOverwriting);
break;
default:
throw new UnsupportedOperationException("Version not supported: " + myFhirContext.getVersion().getVersion());
}
}
}
private void copyDSTU3TargetInformation(IBaseResource theBaseResource, IBaseResource thePerson, boolean theAllowOverwriting) {
org.hl7.fhir.dstu3.model.Person person = (org.hl7.fhir.dstu3.model.Person) thePerson;
switch (myFhirContext.getResourceType(theBaseResource)) {
case "Patient":
org.hl7.fhir.dstu3.model.Patient patient = (org.hl7.fhir.dstu3.model.Patient) theBaseResource;
if (theAllowOverwriting || person.getName().isEmpty()) {
person.setName(patient.getName());
}
if (theAllowOverwriting || person.getAddress().isEmpty()) {
person.setAddress(patient.getAddress());
}
if (theAllowOverwriting || person.getTelecom().isEmpty()) {
person.setTelecom(patient.getTelecom());
}
if (theAllowOverwriting || person.getBirthDate() == null ) {
person.setBirthDate(patient.getBirthDate());
}
if (theAllowOverwriting || person.getGender() == null ) {
person.setGender(patient.getGender());
}
if (theAllowOverwriting || person.getPhoto().isEmpty()) {
person.setPhoto(patient.getPhotoFirstRep());
}
break;
case "Practitioner":
org.hl7.fhir.dstu3.model.Practitioner practitioner = (org.hl7.fhir.dstu3.model.Practitioner) theBaseResource;
if (theAllowOverwriting || person.getName().isEmpty()) {
person.setName(practitioner.getName());
}
if (theAllowOverwriting || person.getAddress().isEmpty()) {
person.setAddress(practitioner.getAddress());
}
if (theAllowOverwriting || person.getTelecom().isEmpty()) {
person.setTelecom(practitioner.getTelecom());
}
if (theAllowOverwriting || person.getBirthDate() == null) {
person.setBirthDate(practitioner.getBirthDate());
}
if (theAllowOverwriting || person.getGender() == null) {
person.setGender(practitioner.getGender());
}
if (theAllowOverwriting || person.getPhoto().isEmpty()) {
person.setPhoto(practitioner.getPhotoFirstRep());
}
break;
default:
throw new UnsupportedOperationException("EMPI targets are limited to Practitioner/Patient. This is a : " + myFhirContext.getResourceType(theBaseResource));
private void copyR4TargetInformation (IBaseResource theBaseResource, IBaseResource thePerson,
boolean theAllowOverwriting){
Person person = (Person) thePerson;
switch (myFhirContext.getResourceType(theBaseResource)) {
case "Patient":
Patient patient = (Patient) theBaseResource;
if (theAllowOverwriting || person.getName().isEmpty()) {
person.setName(patient.getName());
}
if (theAllowOverwriting || person.getAddress().isEmpty()) {
person.setAddress(patient.getAddress());
}
if (theAllowOverwriting || person.getTelecom().isEmpty()) {
person.setTelecom(patient.getTelecom());
}
if (theAllowOverwriting || person.getBirthDate() == null) {
person.setBirthDate(patient.getBirthDate());
}
if (theAllowOverwriting || person.getGender() == null) {
person.setGender(patient.getGender());
}
if (theAllowOverwriting || person.getPhoto().isEmpty()) {
person.setPhoto(patient.getPhotoFirstRep());
}
break;
case "Practitioner":
Practitioner practitioner = (Practitioner) theBaseResource;
if (theAllowOverwriting || person.getName().isEmpty()) {
person.setName(practitioner.getName());
}
if (theAllowOverwriting || person.getAddress().isEmpty()) {
person.setAddress(practitioner.getAddress());
}
if (theAllowOverwriting || person.getTelecom().isEmpty()) {
person.setTelecom(practitioner.getTelecom());
}
if (theAllowOverwriting || person.getBirthDate() == null) {
person.setBirthDate(practitioner.getBirthDate());
}
if (theAllowOverwriting || person.getGender() == null) {
person.setGender(practitioner.getGender());
}
if (theAllowOverwriting || person.getPhoto().isEmpty()) {
person.setPhoto(practitioner.getPhotoFirstRep());
}
break;
default:
throw new UnsupportedOperationException("EMPI targets are limited to Practitioner/Patient. This is a : " + myFhirContext.getResourceType(theBaseResource));
}
}
}
private IBaseCoding buildEmpiManagedTag() {
switch (myFhirContext.getVersion().getVersion()) {
case R4:
Coding empiManagedCoding = new Coding();
empiManagedCoding.setSystem(EmpiConstants.SYSTEM_EMPI_MANAGED);
empiManagedCoding.setCode(EmpiConstants.CODE_HAPI_EMPI_MANAGED);
empiManagedCoding.setDisplay(EmpiConstants.DISPLAY_HAPI_EMPI_MANAGED);
return empiManagedCoding;
case DSTU3:
org.hl7.fhir.dstu3.model.Coding empiManagedCodingDstu3 = new org.hl7.fhir.dstu3.model.Coding();
empiManagedCodingDstu3.setSystem(EmpiConstants.SYSTEM_EMPI_MANAGED);
empiManagedCodingDstu3.setCode(EmpiConstants.CODE_HAPI_EMPI_MANAGED);
empiManagedCodingDstu3.setDisplay(EmpiConstants.DISPLAY_HAPI_EMPI_MANAGED);
return empiManagedCodingDstu3;
default:
throw new UnsupportedOperationException("Version not supported: " + myFhirContext.getVersion().getVersion());
private void copyDSTU3TargetInformation (IBaseResource theBaseResource, IBaseResource thePerson,
boolean theAllowOverwriting){
org.hl7.fhir.dstu3.model.Person person = (org.hl7.fhir.dstu3.model.Person) thePerson;
switch (myFhirContext.getResourceType(theBaseResource)) {
case "Patient":
org.hl7.fhir.dstu3.model.Patient patient = (org.hl7.fhir.dstu3.model.Patient) theBaseResource;
if (theAllowOverwriting || person.getName().isEmpty()) {
person.setName(patient.getName());
}
if (theAllowOverwriting || person.getAddress().isEmpty()) {
person.setAddress(patient.getAddress());
}
if (theAllowOverwriting || person.getTelecom().isEmpty()) {
person.setTelecom(patient.getTelecom());
}
if (theAllowOverwriting || person.getBirthDate() == null) {
person.setBirthDate(patient.getBirthDate());
}
if (theAllowOverwriting || person.getGender() == null) {
person.setGender(patient.getGender());
}
if (theAllowOverwriting || person.getPhoto().isEmpty()) {
person.setPhoto(patient.getPhotoFirstRep());
}
break;
case "Practitioner":
org.hl7.fhir.dstu3.model.Practitioner practitioner = (org.hl7.fhir.dstu3.model.Practitioner) theBaseResource;
if (theAllowOverwriting || person.getName().isEmpty()) {
person.setName(practitioner.getName());
}
if (theAllowOverwriting || person.getAddress().isEmpty()) {
person.setAddress(practitioner.getAddress());
}
if (theAllowOverwriting || person.getTelecom().isEmpty()) {
person.setTelecom(practitioner.getTelecom());
}
if (theAllowOverwriting || person.getBirthDate() == null) {
person.setBirthDate(practitioner.getBirthDate());
}
if (theAllowOverwriting || person.getGender() == null) {
person.setGender(practitioner.getGender());
}
if (theAllowOverwriting || person.getPhoto().isEmpty()) {
person.setPhoto(practitioner.getPhotoFirstRep());
}
break;
default:
throw new UnsupportedOperationException("EMPI targets are limited to Practitioner/Patient. This is a : " + myFhirContext.getResourceType(theBaseResource));
}
}
}
/**
* Update a Person's EID based on the incoming target resource. If the incoming resource has an external EID, it is applied
* to the Person, unless that person already has an external EID which does not match, in which case throw {@link IllegalArgumentException}
*
* If running in multiple EID mode, then incoming EIDs are simply added to the Person without checking for matches.
*
* @param thePerson The person to update the external EID on.
* @param theEmpiTarget The target we will retrieve the external EID from.
* @return the modified {@link IBaseResource} representing the person.
*/
public IAnyResource updatePersonExternalEidFromEmpiTarget(IAnyResource thePerson, IAnyResource theEmpiTarget, EmpiTransactionContext theEmpiTransactionContext) {
//This handles overwriting an automatically assigned EID if a patient that links is coming in with an official EID.
List<CanonicalEID> incomingTargetEid = myEIDHelper.getExternalEid(theEmpiTarget);
List<CanonicalEID> personOfficialEid = myEIDHelper.getExternalEid(thePerson);
private IBaseCoding buildEmpiManagedTag () {
switch (myFhirContext.getVersion().getVersion()) {
case R4:
Coding empiManagedCoding = new Coding();
empiManagedCoding.setSystem(EmpiConstants.SYSTEM_EMPI_MANAGED);
empiManagedCoding.setCode(EmpiConstants.CODE_HAPI_EMPI_MANAGED);
empiManagedCoding.setDisplay(EmpiConstants.DISPLAY_HAPI_EMPI_MANAGED);
return empiManagedCoding;
case DSTU3:
org.hl7.fhir.dstu3.model.Coding empiManagedCodingDstu3 = new org.hl7.fhir.dstu3.model.Coding();
empiManagedCodingDstu3.setSystem(EmpiConstants.SYSTEM_EMPI_MANAGED);
empiManagedCodingDstu3.setCode(EmpiConstants.CODE_HAPI_EMPI_MANAGED);
empiManagedCodingDstu3.setDisplay(EmpiConstants.DISPLAY_HAPI_EMPI_MANAGED);
return empiManagedCodingDstu3;
default:
throw new UnsupportedOperationException("Version not supported: " + myFhirContext.getVersion().getVersion());
if (!incomingTargetEid.isEmpty()) {
if (personOfficialEid.isEmpty() || !myEmpiConfig.isPreventMultipleEids()) {
log(theEmpiTransactionContext, "Incoming resource:" + theEmpiTarget.getIdElement().toUnqualifiedVersionless() + " + with EID " + incomingTargetEid.stream().map(CanonicalEID::toString).collect(Collectors.joining(",")) + " is applying this EIDs to its related Person, as this person does not yet have an external EID");
addCanonicalEidsToPersonIfAbsent(thePerson, incomingTargetEid);
} else if (!personOfficialEid.isEmpty() && myEIDHelper.eidMatchExists(personOfficialEid, incomingTargetEid)) {
log(theEmpiTransactionContext, "incoming resource:" + theEmpiTarget.getIdElement().toVersionless() + " with EIDs "+incomingTargetEid.stream().map(CanonicalEID::toString).collect(Collectors.joining(",")) +" does not need to overwrite person, as this EID is already present");
}
}
/**
* Update a Person's EID based on the incoming target resource. If the incoming resource has an external EID, it is applied
* to the Person, unless that person already has an external EID which does not match, in which case throw {@link IllegalArgumentException}
* <p>
* If running in multiple EID mode, then incoming EIDs are simply added to the Person without checking for matches.
*
* @param thePerson The person to update the external EID on.
* @param theEmpiTarget The target we will retrieve the external EID from.
* @return the modified {@link IBaseResource} representing the person.
*/
public IAnyResource updatePersonExternalEidFromEmpiTarget (IAnyResource thePerson, IAnyResource
theEmpiTarget, EmpiTransactionContext theEmpiTransactionContext){
//This handles overwriting an automatically assigned EID if a patient that links is coming in with an official EID.
List<CanonicalEID> incomingTargetEid = myEIDHelper.getExternalEid(theEmpiTarget);
List<CanonicalEID> personOfficialEid = myEIDHelper.getExternalEid(thePerson);
if (!incomingTargetEid.isEmpty()) {
if (personOfficialEid.isEmpty() || !myEmpiConfig.isPreventMultipleEids()) {
log(theEmpiTransactionContext, "Incoming resource:" + theEmpiTarget.getIdElement().toUnqualifiedVersionless() + " + with EID " + incomingTargetEid.stream().map(CanonicalEID::toString).collect(Collectors.joining(",")) + " is applying this EIDs to its related Person, as this person does not yet have an external EID");
addCanonicalEidsToPersonIfAbsent(thePerson, incomingTargetEid);
} else if (!personOfficialEid.isEmpty() && myEIDHelper.eidMatchExists(personOfficialEid, incomingTargetEid)) {
log(theEmpiTransactionContext, "incoming resource:" + theEmpiTarget.getIdElement().toVersionless() + " with EIDs " + incomingTargetEid.stream().map(CanonicalEID::toString).collect(Collectors.joining(",")) + " does not need to overwrite person, as this EID is already present");
} else {
throw new IllegalArgumentException("This would create a duplicate person!");
}
}
return thePerson;
}
public IBaseResource overwriteExternalEids (IBaseResource thePerson, List < CanonicalEID > theNewEid){
clearExternalEids(thePerson);
addCanonicalEidsToPersonIfAbsent(thePerson, theNewEid);
return thePerson;
}
private void clearExternalEids (IBaseResource thePerson){
switch (myFhirContext.getVersion().getVersion()) {
case R4:
Person personR4 = (Person) thePerson;
personR4.getIdentifier().removeIf(theIdentifier -> theIdentifier.getSystem().equalsIgnoreCase(myEmpiConfig.getEmpiRules().getEnterpriseEIDSystem()));
break;
case DSTU3:
org.hl7.fhir.dstu3.model.Person personDstu3 = (org.hl7.fhir.dstu3.model.Person) thePerson;
personDstu3.getIdentifier().removeIf(theIdentifier -> theIdentifier.getSystem().equalsIgnoreCase(myEmpiConfig.getEmpiRules().getEnterpriseEIDSystem()));
break;
default:
throw new UnsupportedOperationException("Version not supported: " + myFhirContext.getVersion().getVersion());
}
}
private void addCanonicalEidsToPersonIfAbsent (IBaseResource thePerson, List < CanonicalEID > theIncomingTargetEid)
{
switch (myFhirContext.getVersion().getVersion()) {
case R4:
theIncomingTargetEid.forEach(eid -> addIdentifierIfAbsent((Person) thePerson, eid.toR4()));
break;
case DSTU3:
theIncomingTargetEid.forEach(eid -> addIdentifierIfAbsent((org.hl7.fhir.dstu3.model.Person) thePerson, eid.toDSTU3()));
break;
default:
throw new UnsupportedOperationException("Version not supported: " + myFhirContext.getVersion().getVersion());
}
}
/**
* To avoid adding duplicate
*
* @param thePerson
* @param theIdentifier
*/
private void addIdentifierIfAbsent (org.hl7.fhir.dstu3.model.Person thePerson, org.hl7.fhir.dstu3.model.Identifier
theIdentifier){
Optional<org.hl7.fhir.dstu3.model.Identifier> first = thePerson.getIdentifier().stream().filter(identifier -> identifier.getSystem().equals(theIdentifier.getSystem())).filter(identifier -> identifier.getValue().equals(theIdentifier.getValue())).findFirst();
if (first.isPresent()) {
return;
} else {
throw new IllegalArgumentException("This would create a duplicate person!");
thePerson.addIdentifier(theIdentifier);
}
}
return thePerson;
}
public IBaseResource overwriteExternalEids(IBaseResource thePerson, List<CanonicalEID> theNewEid) {
clearExternalEids(thePerson);
addCanonicalEidsToPersonIfAbsent(thePerson, theNewEid);
return thePerson;
}
private void clearExternalEids(IBaseResource thePerson) {
switch (myFhirContext.getVersion().getVersion()) {
case R4:
Person personR4 = (Person) thePerson;
personR4.getIdentifier().removeIf(theIdentifier -> theIdentifier.getSystem().equalsIgnoreCase(myEmpiConfig.getEmpiRules().getEnterpriseEIDSystem()));
break;
case DSTU3:
org.hl7.fhir.dstu3.model.Person personDstu3 = (org.hl7.fhir.dstu3.model.Person) thePerson;
personDstu3.getIdentifier().removeIf(theIdentifier -> theIdentifier.getSystem().equalsIgnoreCase(myEmpiConfig.getEmpiRules().getEnterpriseEIDSystem()));
break;
default:
throw new UnsupportedOperationException("Version not supported: " + myFhirContext.getVersion().getVersion());
}
}
private void addCanonicalEidsToPersonIfAbsent(IBaseResource thePerson, List<CanonicalEID> theIncomingTargetEid) {
switch (myFhirContext.getVersion().getVersion()) {
case R4:
theIncomingTargetEid.forEach(eid -> addIdentifierIfAbsent((Person) thePerson, eid.toR4()));
break;
case DSTU3:
theIncomingTargetEid.forEach(eid -> addIdentifierIfAbsent((org.hl7.fhir.dstu3.model.Person) thePerson, eid.toDSTU3()));
break;
default:
throw new UnsupportedOperationException("Version not supported: " + myFhirContext.getVersion().getVersion());
}
}
/**
* To avoid adding duplicate
*
* @param thePerson
* @param theIdentifier
*/
private void addIdentifierIfAbsent(org.hl7.fhir.dstu3.model.Person thePerson, org.hl7.fhir.dstu3.model.Identifier theIdentifier) {
Optional<org.hl7.fhir.dstu3.model.Identifier> first = thePerson.getIdentifier().stream().filter(identifier -> identifier.getSystem().equals(theIdentifier.getSystem())).filter(identifier -> identifier.getValue().equals(theIdentifier.getValue())).findFirst();
if (first.isPresent()) {
return;
} else {
thePerson.addIdentifier(theIdentifier);
}
}
private void addIdentifierIfAbsent(Person thePerson, Identifier theIdentifier) {
Optional<Identifier> first = thePerson.getIdentifier().stream().filter(identifier -> identifier.getSystem().equals(theIdentifier.getSystem())).filter(identifier -> identifier.getValue().equals(theIdentifier.getValue())).findFirst();
if (first.isPresent()) {
return;
} else {
thePerson.addIdentifier(theIdentifier);
}
}
public void mergePersonFields(IBaseResource theFromPerson, IBaseResource theToPerson) {
switch (myFhirContext.getVersion().getVersion()) {
case R4:
mergeR4PersonFields(theFromPerson, theToPerson);
break;
case DSTU3:
mergeDstu3PersonFields(theFromPerson, theToPerson);
break;
default:
throw new UnsupportedOperationException("Version not supported: " + myFhirContext.getVersion().getVersion());
}
}
private void mergeR4PersonFields(IBaseResource theFromPerson, IBaseResource theToPerson) {
Person fromPerson = (Person) theFromPerson;
Person toPerson = (Person) theToPerson;
mergeElementList(fromPerson, toPerson, HumanName.class, Person::getName, HumanName::equalsDeep);
mergeElementList(fromPerson, toPerson, Identifier.class, Person::getIdentifier, Identifier::equalsDeep);
mergeElementList(fromPerson, toPerson, Address.class, Person::getAddress, Address::equalsDeep);
mergeElementList(fromPerson, toPerson, ContactPoint.class, Person::getTelecom, ContactPoint::equalsDeep);
if (!toPerson.hasBirthDate()) {
toPerson.setBirthDate(fromPerson.getBirthDate());
}
if (!toPerson.hasGender()) {
toPerson.setGender(fromPerson.getGender());
}
if (!toPerson.hasPhoto()) {
toPerson.setPhoto(fromPerson.getPhoto());
}
}
private <P,T> void mergeElementList(P fromPerson, P toPerson, Class<T> theBase, Function<P, List<T>> theGetList, BiPredicate<T, T> theEquals) {
List<T> fromList = theGetList.apply(fromPerson);
List<T> toList = theGetList.apply(toPerson);
List<T> itemsToAdd = new ArrayList<>();
for (T fromItem : fromList) {
if (toList.stream().noneMatch(t -> theEquals.test(fromItem, t))) {
itemsToAdd.add(fromItem);
private void addIdentifierIfAbsent (Person thePerson, Identifier theIdentifier){
Optional<Identifier> first = thePerson.getIdentifier().stream().filter(identifier -> identifier.getSystem().equals(theIdentifier.getSystem())).filter(identifier -> identifier.getValue().equals(theIdentifier.getValue())).findFirst();
if (first.isPresent()) {
return;
} else {
thePerson.addIdentifier(theIdentifier);
}
}
toList.addAll(itemsToAdd);
}
private void mergeDstu3PersonFields(IBaseResource theFromPerson, IBaseResource theToPerson) {
org.hl7.fhir.dstu3.model.Person fromPerson = (org.hl7.fhir.dstu3.model.Person) theFromPerson;
org.hl7.fhir.dstu3.model.Person toPerson = (org.hl7.fhir.dstu3.model.Person) theToPerson;
mergeElementList(fromPerson, toPerson, org.hl7.fhir.dstu3.model.HumanName.class, org.hl7.fhir.dstu3.model.Person::getName, org.hl7.fhir.dstu3.model.HumanName::equalsDeep);
mergeElementList(fromPerson, toPerson, org.hl7.fhir.dstu3.model.Identifier.class, org.hl7.fhir.dstu3.model.Person::getIdentifier, org.hl7.fhir.dstu3.model.Identifier::equalsDeep);
mergeElementList(fromPerson, toPerson, org.hl7.fhir.dstu3.model.Address.class, org.hl7.fhir.dstu3.model.Person::getAddress, org.hl7.fhir.dstu3.model.Address::equalsDeep);
mergeElementList(fromPerson, toPerson, org.hl7.fhir.dstu3.model.ContactPoint.class, org.hl7.fhir.dstu3.model.Person::getTelecom, org.hl7.fhir.dstu3.model.ContactPoint::equalsDeep);
if (!toPerson.hasBirthDate()) {
toPerson.setBirthDate(fromPerson.getBirthDate());
public void mergePersonFields (IBaseResource theFromPerson, IBaseResource theToPerson){
switch (myFhirContext.getVersion().getVersion()) {
case R4:
mergeR4PersonFields(theFromPerson, theToPerson);
break;
case DSTU3:
mergeDstu3PersonFields(theFromPerson, theToPerson);
break;
default:
throw new UnsupportedOperationException("Version not supported: " + myFhirContext.getVersion().getVersion());
}
}
if (!toPerson.hasGender()) {
toPerson.setGender(fromPerson.getGender());
private void mergeR4PersonFields (IBaseResource theFromPerson, IBaseResource theToPerson){
Person fromPerson = (Person) theFromPerson;
Person toPerson = (Person) theToPerson;
mergeElementList(fromPerson, toPerson, HumanName.class, Person::getName, HumanName::equalsDeep);
mergeElementList(fromPerson, toPerson, Identifier.class, Person::getIdentifier, Identifier::equalsDeep);
mergeElementList(fromPerson, toPerson, Address.class, Person::getAddress, Address::equalsDeep);
mergeElementList(fromPerson, toPerson, ContactPoint.class, Person::getTelecom, ContactPoint::equalsDeep);
if (!toPerson.hasBirthDate()) {
toPerson.setBirthDate(fromPerson.getBirthDate());
}
if (!toPerson.hasGender()) {
toPerson.setGender(fromPerson.getGender());
}
if (!toPerson.hasPhoto()) {
toPerson.setPhoto(fromPerson.getPhoto());
}
}
if (!toPerson.hasPhoto()) {
toPerson.setPhoto(fromPerson.getPhoto());
private <P, T > void mergeElementList (P fromPerson, P
toPerson, Class < T > theBase, Function< P, List < T >> theGetList, BiPredicate< T, T > theEquals){
List<T> fromList = theGetList.apply(fromPerson);
List<T> toList = theGetList.apply(toPerson);
List<T> itemsToAdd = new ArrayList<>();
for (T fromItem : fromList) {
if (toList.stream().noneMatch(t -> theEquals.test(fromItem, t))) {
itemsToAdd.add(fromItem);
}
}
toList.addAll(itemsToAdd);
}
private void mergeDstu3PersonFields (IBaseResource theFromPerson, IBaseResource theToPerson){
org.hl7.fhir.dstu3.model.Person fromPerson = (org.hl7.fhir.dstu3.model.Person) theFromPerson;
org.hl7.fhir.dstu3.model.Person toPerson = (org.hl7.fhir.dstu3.model.Person) theToPerson;
mergeElementList(fromPerson, toPerson, org.hl7.fhir.dstu3.model.HumanName.class, org.hl7.fhir.dstu3.model.Person::getName, org.hl7.fhir.dstu3.model.HumanName::equalsDeep);
mergeElementList(fromPerson, toPerson, org.hl7.fhir.dstu3.model.Identifier.class, org.hl7.fhir.dstu3.model.Person::getIdentifier, org.hl7.fhir.dstu3.model.Identifier::equalsDeep);
mergeElementList(fromPerson, toPerson, org.hl7.fhir.dstu3.model.Address.class, org.hl7.fhir.dstu3.model.Person::getAddress, org.hl7.fhir.dstu3.model.Address::equalsDeep);
mergeElementList(fromPerson, toPerson, org.hl7.fhir.dstu3.model.ContactPoint.class, org.hl7.fhir.dstu3.model.Person::getTelecom, org.hl7.fhir.dstu3.model.ContactPoint::equalsDeep);
if (!toPerson.hasBirthDate()) {
toPerson.setBirthDate(fromPerson.getBirthDate());
}
if (!toPerson.hasGender()) {
toPerson.setGender(fromPerson.getGender());
}
if (!toPerson.hasPhoto()) {
toPerson.setPhoto(fromPerson.getPhoto());
}
}
/**
* An incoming resource is a potential duplicate if it matches a Patient that has a Person with an official EID, but
* the incoming resource also has an EID that does not match.
*
* @param theExistingPerson
* @param theComparingPerson
* @return
*/
public boolean isPotentialDuplicate (IAnyResource theExistingPerson, IAnyResource theComparingPerson){
List<CanonicalEID> externalEidsPerson = myEIDHelper.getExternalEid(theExistingPerson);
List<CanonicalEID> externalEidsResource = myEIDHelper.getExternalEid(theComparingPerson);
return !externalEidsPerson.isEmpty() && !externalEidsResource.isEmpty() && !myEIDHelper.eidMatchExists(externalEidsResource, externalEidsPerson);
}
public IBaseBackboneElement newPersonLink (IIdType theTargetId, CanonicalIdentityAssuranceLevel theAssuranceLevel)
{
switch (myFhirContext.getVersion().getVersion()) {
case R4:
return newR4PersonLink(theTargetId, theAssuranceLevel);
case DSTU3:
return newDstu3PersonLink(theTargetId, theAssuranceLevel);
default:
throw new UnsupportedOperationException("Version not supported: " + myFhirContext.getVersion().getVersion());
}
}
private IBaseBackboneElement newR4PersonLink (IIdType theTargetId, CanonicalIdentityAssuranceLevel
theAssuranceLevel){
Person.PersonLinkComponent retval = new Person.PersonLinkComponent();
retval.setTarget(new Reference(theTargetId));
retval.setAssurance(theAssuranceLevel.toR4());
return retval;
}
private IBaseBackboneElement newDstu3PersonLink (IIdType theTargetId, CanonicalIdentityAssuranceLevel
theAssuranceLevel){
org.hl7.fhir.dstu3.model.Person.PersonLinkComponent retval = new org.hl7.fhir.dstu3.model.Person.PersonLinkComponent();
retval.setTarget(new org.hl7.fhir.dstu3.model.Reference(theTargetId));
retval.setAssurance(theAssuranceLevel.toDstu3());
return retval;
}
public void setLinks (IAnyResource thePersonResource, List < IBaseBackboneElement > theNewLinks){
switch (myFhirContext.getVersion().getVersion()) {
case R4:
setLinksR4(thePersonResource, theNewLinks);
break;
case DSTU3:
setLinksDstu3(thePersonResource, theNewLinks);
break;
default:
throw new UnsupportedOperationException("Version not supported: " + myFhirContext.getVersion().getVersion());
}
}
private void setLinksDstu3 (IAnyResource thePersonResource, List < IBaseBackboneElement > theLinks){
org.hl7.fhir.dstu3.model.Person person = (org.hl7.fhir.dstu3.model.Person) thePersonResource;
List<org.hl7.fhir.dstu3.model.Person.PersonLinkComponent> links = (List<org.hl7.fhir.dstu3.model.Person.PersonLinkComponent>) (List<?>) theLinks;
person.setLink(links);
}
private void setLinksR4 (IAnyResource thePersonResource, List < IBaseBackboneElement > theLinks){
Person person = (Person) thePersonResource;
List<Person.PersonLinkComponent> links = (List<Person.PersonLinkComponent>) (List<?>) theLinks;
person.setLink(links);
}
public void updatePersonFromNewlyCreatedEmpiTarget (IBaseResource thePerson, IBaseResource
theResource, EmpiTransactionContext theEmpiTransactionContext){
copyEmpiTargetDataIntoPerson(theResource, thePerson, false);
}
public void updatePersonFromUpdatedEmpiTarget (IBaseResource thePerson, IBaseResource
theResource, EmpiTransactionContext theEmpiTransactionContext){
copyEmpiTargetDataIntoPerson(theResource, thePerson, true);
}
public int getLinkCount (IAnyResource thePerson){
switch (myFhirContext.getVersion().getVersion()) {
case R4:
Person personR4 = (Person) thePerson;
return personR4.getLink().size();
case DSTU3:
org.hl7.fhir.dstu3.model.Person personStu3 = (org.hl7.fhir.dstu3.model.Person) thePerson;
return personStu3.getLink().size();
default:
throw new UnsupportedOperationException("Version not supported: " + myFhirContext.getVersion().getVersion());
}
}
private void log (EmpiTransactionContext theEmpiTransactionContext, String theMessage){
theEmpiTransactionContext.addTransactionLogMessage(theMessage);
ourLog.debug(theMessage);
}
public void handleExternalEidAddition (IAnyResource thePerson, IAnyResource theResource, EmpiTransactionContext
theEmpiTransactionContext){
List<CanonicalEID> eidFromResource = myEIDHelper.getExternalEid(theResource);
if (!eidFromResource.isEmpty()) {
updatePersonExternalEidFromEmpiTarget(thePerson, theResource, theEmpiTransactionContext);
}
}
public void deactivatePerson (IAnyResource thePerson){
switch (myFhirContext.getVersion().getVersion()) {
case R4:
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){
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 new UnsupportedOperationException("Version not supported: " + myFhirContext.getVersion().getVersion());
}
}
}
/**
* An incoming resource is a potential duplicate if it matches a Patient that has a Person with an official EID, but
* the incoming resource also has an EID that does not match.
*
* @param theExistingPerson
* @param theComparingPerson
* @return
*/
public boolean isPotentialDuplicate(IAnyResource theExistingPerson, IAnyResource theComparingPerson) {
List<CanonicalEID> externalEidsPerson = myEIDHelper.getExternalEid(theExistingPerson);
List<CanonicalEID> externalEidsResource = myEIDHelper.getExternalEid(theComparingPerson);
return !externalEidsPerson.isEmpty() && !externalEidsResource.isEmpty() && !myEIDHelper.eidMatchExists(externalEidsResource, externalEidsPerson);
}
public IBaseBackboneElement newPersonLink(IIdType theTargetId, CanonicalIdentityAssuranceLevel theAssuranceLevel) {
switch (myFhirContext.getVersion().getVersion()) {
case R4:
return newR4PersonLink(theTargetId, theAssuranceLevel);
case DSTU3:
return newDstu3PersonLink(theTargetId, theAssuranceLevel);
default:
throw new UnsupportedOperationException("Version not supported: " + myFhirContext.getVersion().getVersion());
}
}
private IBaseBackboneElement newR4PersonLink(IIdType theTargetId, CanonicalIdentityAssuranceLevel theAssuranceLevel) {
Person.PersonLinkComponent retval = new Person.PersonLinkComponent();
retval.setTarget(new Reference(theTargetId));
retval.setAssurance(theAssuranceLevel.toR4());
return retval;
}
private IBaseBackboneElement newDstu3PersonLink(IIdType theTargetId, CanonicalIdentityAssuranceLevel theAssuranceLevel) {
org.hl7.fhir.dstu3.model.Person.PersonLinkComponent retval = new org.hl7.fhir.dstu3.model.Person.PersonLinkComponent();
retval.setTarget(new org.hl7.fhir.dstu3.model.Reference(theTargetId));
retval.setAssurance(theAssuranceLevel.toDstu3());
return retval;
}
public void setLinks(IAnyResource thePersonResource, List<IBaseBackboneElement> theNewLinks) {
switch (myFhirContext.getVersion().getVersion()) {
case R4:
setLinksR4(thePersonResource, theNewLinks);
break;
case DSTU3:
setLinksDstu3(thePersonResource, theNewLinks);
break;
default:
throw new UnsupportedOperationException("Version not supported: " + myFhirContext.getVersion().getVersion());
}
}
private void setLinksDstu3(IAnyResource thePersonResource, List<IBaseBackboneElement> theLinks) {
org.hl7.fhir.dstu3.model.Person person = (org.hl7.fhir.dstu3.model.Person)thePersonResource;
List<org.hl7.fhir.dstu3.model.Person.PersonLinkComponent> links = (List<org.hl7.fhir.dstu3.model.Person.PersonLinkComponent>)(List<?>)theLinks;
person.setLink(links);
}
private void setLinksR4(IAnyResource thePersonResource, List<IBaseBackboneElement> theLinks) {
Person person = (Person)thePersonResource;
List<Person.PersonLinkComponent> links = (List<Person.PersonLinkComponent>)(List<?>)theLinks;
person.setLink(links);
}
public void updatePersonFromNewlyCreatedEmpiTarget(IBaseResource thePerson, IBaseResource theResource, EmpiTransactionContext theEmpiTransactionContext) {
copyEmpiTargetDataIntoPerson(theResource, thePerson, false);
}
public void updatePersonFromUpdatedEmpiTarget(IBaseResource thePerson, IBaseResource theResource, EmpiTransactionContext theEmpiTransactionContext) {
copyEmpiTargetDataIntoPerson(theResource, thePerson, true);
}
public int getLinkCount(IAnyResource thePerson) {
switch (myFhirContext.getVersion().getVersion()) {
case R4:
Person personR4 = (Person) thePerson;
return personR4.getLink().size();
case DSTU3:
org.hl7.fhir.dstu3.model.Person personStu3 = (org.hl7.fhir.dstu3.model.Person) thePerson;
return personStu3.getLink().size();
default:
throw new UnsupportedOperationException("Version not supported: " + myFhirContext.getVersion().getVersion());
}
}
private void log(EmpiTransactionContext theEmpiTransactionContext, String theMessage) {
theEmpiTransactionContext.addTransactionLogMessage(theMessage);
ourLog.debug(theMessage);
}
public void handleExternalEidAddition(IAnyResource thePerson, IAnyResource theResource, EmpiTransactionContext theEmpiTransactionContext) {
List<CanonicalEID> eidFromResource = myEIDHelper.getExternalEid(theResource);
if (!eidFromResource.isEmpty()) {
updatePersonExternalEidFromEmpiTarget(thePerson, theResource, theEmpiTransactionContext);
}
}
public void deactivatePerson(IAnyResource thePerson) {
switch (myFhirContext.getVersion().getVersion()) {
case R4:
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) {
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 new UnsupportedOperationException("Version not supported: " + myFhirContext.getVersion().getVersion());
}
}
}

View File

@ -1,9 +0,0 @@
package ca.uhn.fhir.empi.util;
import org.hl7.fhir.instance.model.api.IAnyResource;
public class SourceResourceBuilder {
IAnyResource copy(IAnyResource)
}