Renamed sourceResource to goldenResource
This commit is contained in:
parent
8a7dc4e80b
commit
36ce84335a
hapi-fhir-jpaserver-mdm/src
main/java/ca/uhn/fhir/jpa/mdm/svc/candidate
test/java/ca/uhn/fhir/jpa/mdm/matcher
hapi-fhir-server-mdm/src/main/java/ca/uhn/fhir/mdm/util
|
@ -92,35 +92,35 @@ public class GoldenResourceHelper {
|
||||||
|
|
||||||
// get a ref to the actual ID Field
|
// get a ref to the actual ID Field
|
||||||
RuntimeResourceDefinition resourceDefinition = myFhirContext.getResourceDefinition(theIncomingResource);
|
RuntimeResourceDefinition resourceDefinition = myFhirContext.getResourceDefinition(theIncomingResource);
|
||||||
IBaseResource newSourceResource = resourceDefinition.newInstance();
|
IBaseResource newGoldenResource = resourceDefinition.newInstance();
|
||||||
|
|
||||||
// hapi has 2 metamodels: for children and types
|
// hapi has 2 metamodels: for children and types
|
||||||
BaseRuntimeChildDefinition sourceResourceIdentifier = resourceDefinition.getChildByName(FIELD_NAME_IDENTIFIER);
|
BaseRuntimeChildDefinition goldenResourceIdentifier = resourceDefinition.getChildByName(FIELD_NAME_IDENTIFIER);
|
||||||
|
|
||||||
cloneAllExternalEidsIntoNewSourceResource(sourceResourceIdentifier, theIncomingResource, newSourceResource);
|
cloneAllExternalEidsIntoNewGoldenResource(goldenResourceIdentifier, theIncomingResource, newGoldenResource);
|
||||||
|
|
||||||
addHapiEidIfNoExternalEidIsPresent(newSourceResource, sourceResourceIdentifier, theIncomingResource);
|
addHapiEidIfNoExternalEidIsPresent(newGoldenResource, goldenResourceIdentifier, theIncomingResource);
|
||||||
|
|
||||||
MdmUtil.setMdmManaged(newSourceResource);
|
MdmUtil.setMdmManaged(newGoldenResource);
|
||||||
MdmUtil.setGoldenResource(newSourceResource);
|
MdmUtil.setGoldenResource(newGoldenResource);
|
||||||
|
|
||||||
return (T) newSourceResource;
|
return (T) newGoldenResource;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If there are no external EIDs on the incoming resource, create a new HAPI EID on the new SourceResource.
|
* If there are no external EIDs on the incoming resource, create a new HAPI EID on the new Golden Resource.
|
||||||
*/
|
*/
|
||||||
//TODO GGG ask james if there is any way we can convert this canonical EID into a generic STU-agnostic IBase.
|
//TODO GGG ask james if there is any way we can convert this canonical EID into a generic STU-agnostic IBase.
|
||||||
private <T extends IAnyResource> void addHapiEidIfNoExternalEidIsPresent(
|
private <T extends IAnyResource> void addHapiEidIfNoExternalEidIsPresent(
|
||||||
IBaseResource theNewSourceResource, BaseRuntimeChildDefinition theSourceResourceIdentifier, IAnyResource theTargetResource) {
|
IBaseResource theNewGoldenResource, BaseRuntimeChildDefinition theGoldenResourceIdentifier, IAnyResource theTargetResource) {
|
||||||
|
|
||||||
List<CanonicalEID> eidsToApply = myEIDHelper.getExternalEid(theNewSourceResource);
|
List<CanonicalEID> eidsToApply = myEIDHelper.getExternalEid(theNewGoldenResource);
|
||||||
if (!eidsToApply.isEmpty()) {
|
if (!eidsToApply.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CanonicalEID hapiEid = myEIDHelper.createHapiEid();
|
CanonicalEID hapiEid = myEIDHelper.createHapiEid();
|
||||||
theSourceResourceIdentifier.getMutator().addValue(theNewSourceResource, toId(hapiEid));
|
theGoldenResourceIdentifier.getMutator().addValue(theNewGoldenResource, toId(hapiEid));
|
||||||
|
|
||||||
// set identifier on the target resource
|
// set identifier on the target resource
|
||||||
cloneEidIntoResource(theTargetResource, hapiEid);
|
cloneEidIntoResource(theTargetResource, hapiEid);
|
||||||
|
@ -185,18 +185,19 @@ public class GoldenResourceHelper {
|
||||||
}).findFirst().isPresent();
|
}).findFirst().isPresent();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void cloneAllExternalEidsIntoNewSourceResource(BaseRuntimeChildDefinition theSourceResourceIdentifier, IBase theSourceResource, IBase theNewSourceResource) {
|
private void cloneAllExternalEidsIntoNewGoldenResource(BaseRuntimeChildDefinition theGoldenResourceIdentifier,
|
||||||
|
IBase theGoldenResource, IBase theNewGoldenResource) {
|
||||||
// FHIR choice types - fields within fhir where we have a choice of ids
|
// FHIR choice types - fields within fhir where we have a choice of ids
|
||||||
IFhirPath fhirPath = myFhirContext.newFhirPath();
|
IFhirPath fhirPath = myFhirContext.newFhirPath();
|
||||||
List<IBase> sourceResourceIdentifiers = theSourceResourceIdentifier.getAccessor().getValues(theSourceResource);
|
List<IBase> goldenResourceIdentifiers = theGoldenResourceIdentifier.getAccessor().getValues(theGoldenResource);
|
||||||
|
|
||||||
for (IBase base : sourceResourceIdentifiers) {
|
for (IBase base : goldenResourceIdentifiers) {
|
||||||
Optional<IPrimitiveType> system = fhirPath.evaluateFirst(base, "system", IPrimitiveType.class);
|
Optional<IPrimitiveType> system = fhirPath.evaluateFirst(base, "system", IPrimitiveType.class);
|
||||||
if (system.isPresent()) {
|
if (system.isPresent()) {
|
||||||
String mdmSystem = myMdmSettings.getMdmRules().getEnterpriseEIDSystem();
|
String mdmSystem = myMdmSettings.getMdmRules().getEnterpriseEIDSystem();
|
||||||
String baseSystem = system.get().getValueAsString();
|
String baseSystem = system.get().getValueAsString();
|
||||||
if (Objects.equals(baseSystem, mdmSystem)) {
|
if (Objects.equals(baseSystem, mdmSystem)) {
|
||||||
cloneEidIntoResource(theSourceResourceIdentifier, base, theNewSourceResource);
|
cloneEidIntoResource(theGoldenResourceIdentifier, base, theNewGoldenResource);
|
||||||
ourLog.debug("System {} differs from system in the MDM rules {}", baseSystem, mdmSystem);
|
ourLog.debug("System {} differs from system in the MDM rules {}", baseSystem, mdmSystem);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -214,47 +215,47 @@ public class GoldenResourceHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update a Person's EID based on the incoming target resource. If the incoming resource has an external EID, it is applied
|
* Updates EID on Golden Resource, 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}
|
* to the Golden Resource, unless that person already has an external EID which does not match, in which case throw {@link IllegalArgumentException}
|
||||||
* <p>
|
* <p>
|
||||||
* If running in multiple EID mode, then incoming EIDs are simply added to the Person without checking for matches.
|
* If running in multiple EID mode, then incoming EIDs are simply added to the Golden Resource without checking for matches.
|
||||||
*
|
*
|
||||||
* @param theSourceResource The person to update the external EID on.
|
* @param theGoldenResource The golden resource to update the external EID on.
|
||||||
* @param theTargetResource The target we will retrieve the external EID from.
|
* @param theTargetResource The target we will retrieve the external EID from.
|
||||||
* @return the modified {@link IBaseResource} representing the person.
|
* @return the modified {@link IBaseResource} representing the Golden Resource.
|
||||||
*/
|
*/
|
||||||
public IAnyResource updateSourceResourceExternalEidFromTargetResource(IAnyResource theSourceResource, IAnyResource
|
public IAnyResource updateGoldenResourceExternalEidFromTargetResource(IAnyResource theGoldenResource, IAnyResource
|
||||||
theTargetResource, MdmTransactionContext theMdmTransactionContext) {
|
theTargetResource, MdmTransactionContext theMdmTransactionContext) {
|
||||||
//This handles overwriting an automatically assigned EID if a patient that links is coming in with an official EID.
|
//This handles overwriting an automatically assigned EID if a patient that links is coming in with an official EID.
|
||||||
List<CanonicalEID> incomingTargetEid = myEIDHelper.getExternalEid(theTargetResource);
|
List<CanonicalEID> incomingTargetEid = myEIDHelper.getExternalEid(theTargetResource);
|
||||||
List<CanonicalEID> personOfficialEid = myEIDHelper.getExternalEid(theSourceResource);
|
List<CanonicalEID> personOfficialEid = myEIDHelper.getExternalEid(theGoldenResource);
|
||||||
|
|
||||||
if (!incomingTargetEid.isEmpty()) {
|
if (!incomingTargetEid.isEmpty()) {
|
||||||
if (personOfficialEid.isEmpty() || !myMdmSettings.isPreventMultipleEids()) {
|
if (personOfficialEid.isEmpty() || !myMdmSettings.isPreventMultipleEids()) {
|
||||||
log(theMdmTransactionContext, "Incoming resource:" + theTargetResource.getIdElement().toUnqualifiedVersionless() + " + with EID " + incomingTargetEid.stream().map(CanonicalEID::toString).collect(Collectors.joining(",")) + " is applying this EIDs to its related Source Resource, as this Source Resource does not yet have an external EID");
|
log(theMdmTransactionContext, "Incoming resource:" + theTargetResource.getIdElement().toUnqualifiedVersionless() + " + with EID " + incomingTargetEid.stream().map(CanonicalEID::toString).collect(Collectors.joining(",")) + " is applying this EIDs to its related Source Resource, as this Source Resource does not yet have an external EID");
|
||||||
addCanonicalEidsToSourceResourceIfAbsent(theSourceResource, incomingTargetEid);
|
addCanonicalEidsToGoldenResourceIfAbsent(theGoldenResource, incomingTargetEid);
|
||||||
} else if (!personOfficialEid.isEmpty() && myEIDHelper.eidMatchExists(personOfficialEid, incomingTargetEid)) {
|
} else if (!personOfficialEid.isEmpty() && myEIDHelper.eidMatchExists(personOfficialEid, incomingTargetEid)) {
|
||||||
log(theMdmTransactionContext, "incoming resource:" + theTargetResource.getIdElement().toVersionless() + " with EIDs " + incomingTargetEid.stream().map(CanonicalEID::toString).collect(Collectors.joining(",")) + " does not need to overwrite person, as this EID is already present");
|
log(theMdmTransactionContext, "incoming resource:" + theTargetResource.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 {
|
} else {
|
||||||
throw new IllegalArgumentException("This would create a duplicate person!");
|
throw new IllegalArgumentException("This would create a duplicate person!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return theSourceResource;
|
return theGoldenResource;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IBaseResource overwriteExternalEids(IBaseResource theSourceResource, List<CanonicalEID> theNewEid) {
|
public IBaseResource overwriteExternalEids(IBaseResource theGoldenResource, List<CanonicalEID> theNewEid) {
|
||||||
clearExternalEids(theSourceResource);
|
clearExternalEids(theGoldenResource);
|
||||||
addCanonicalEidsToSourceResourceIfAbsent(theSourceResource, theNewEid);
|
addCanonicalEidsToGoldenResourceIfAbsent(theGoldenResource, theNewEid);
|
||||||
return theSourceResource;
|
return theGoldenResource;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void clearExternalEidsFromTheSourceResource(BaseRuntimeChildDefinition theSourceResourceIdentifier, IBase theSourceResource) {
|
private void clearExternalEidsFromTheGoldenResource(BaseRuntimeChildDefinition theGoldenResourceIdentifier, IBase theGoldenResource) {
|
||||||
IFhirPath fhirPath = myFhirContext.newFhirPath();
|
IFhirPath fhirPath = myFhirContext.newFhirPath();
|
||||||
List<IBase> sourceResourceIdentifiers = theSourceResourceIdentifier.getAccessor().getValues(theSourceResource);
|
List<IBase> goldenResourceIdentifiers = theGoldenResourceIdentifier.getAccessor().getValues(theGoldenResource);
|
||||||
List<IBase> clonedIdentifiers = new ArrayList<>();
|
List<IBase> clonedIdentifiers = new ArrayList<>();
|
||||||
FhirTerser terser = myFhirContext.newTerser();
|
FhirTerser terser = myFhirContext.newTerser();
|
||||||
|
|
||||||
for (IBase base : sourceResourceIdentifiers) {
|
for (IBase base : goldenResourceIdentifiers) {
|
||||||
Optional<IPrimitiveType> system = fhirPath.evaluateFirst(base, "system", IPrimitiveType.class);
|
Optional<IPrimitiveType> system = fhirPath.evaluateFirst(base, "system", IPrimitiveType.class);
|
||||||
if (system.isPresent()) {
|
if (system.isPresent()) {
|
||||||
String mdmSystem = myMdmSettings.getMdmRules().getEnterpriseEIDSystem();
|
String mdmSystem = myMdmSettings.getMdmRules().getEnterpriseEIDSystem();
|
||||||
|
@ -266,38 +267,38 @@ public class GoldenResourceHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseRuntimeElementCompositeDefinition<?> childIdentifier = (BaseRuntimeElementCompositeDefinition<?>)
|
BaseRuntimeElementCompositeDefinition<?> childIdentifier = (BaseRuntimeElementCompositeDefinition<?>)
|
||||||
theSourceResourceIdentifier.getChildByName(FIELD_NAME_IDENTIFIER);
|
theGoldenResourceIdentifier.getChildByName(FIELD_NAME_IDENTIFIER);
|
||||||
IBase sourceResourceNewIdentifier = childIdentifier.newInstance();
|
IBase goldenResourceNewIdentifier = childIdentifier.newInstance();
|
||||||
terser.cloneInto(base, sourceResourceNewIdentifier, true);
|
terser.cloneInto(base, goldenResourceNewIdentifier, true);
|
||||||
|
|
||||||
clonedIdentifiers.add(sourceResourceNewIdentifier);
|
clonedIdentifiers.add(goldenResourceNewIdentifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceResourceIdentifiers.clear();
|
goldenResourceIdentifiers.clear();
|
||||||
sourceResourceIdentifiers.addAll(clonedIdentifiers);
|
goldenResourceIdentifiers.addAll(clonedIdentifiers);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void clearExternalEids(IBaseResource theSourceResource) {
|
private void clearExternalEids(IBaseResource theGoldenResource) {
|
||||||
// validate the system - if it's set to EID system - then clear it - type and STU version
|
// validate the system - if it's set to EID system - then clear it - type and STU version
|
||||||
validateContextSupported();
|
validateContextSupported();
|
||||||
|
|
||||||
// get a ref to the actual ID Field
|
// get a ref to the actual ID Field
|
||||||
RuntimeResourceDefinition resourceDefinition = myFhirContext.getResourceDefinition(theSourceResource);
|
RuntimeResourceDefinition resourceDefinition = myFhirContext.getResourceDefinition(theGoldenResource);
|
||||||
BaseRuntimeChildDefinition sourceResourceIdentifier = resourceDefinition.getChildByName(FIELD_NAME_IDENTIFIER);
|
BaseRuntimeChildDefinition goldenResourceIdentifier = resourceDefinition.getChildByName(FIELD_NAME_IDENTIFIER);
|
||||||
clearExternalEidsFromTheSourceResource(sourceResourceIdentifier, theSourceResource);
|
clearExternalEidsFromTheGoldenResource(goldenResourceIdentifier, theGoldenResource);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given a list of incoming External EIDs, and a Source Resource, apply all the EIDs to this resource, which did not already exist on it.
|
* Given a list of incoming External EIDs, and a Golden Resource, apply all the EIDs to this resource, which did not already exist on it.
|
||||||
*/
|
*/
|
||||||
private void addCanonicalEidsToSourceResourceIfAbsent(IBaseResource theSourceResource, List<CanonicalEID> theIncomingTargetExternalEids) {
|
private void addCanonicalEidsToGoldenResourceIfAbsent(IBaseResource theGoldenResource, List<CanonicalEID> theIncomingTargetExternalEids) {
|
||||||
List<CanonicalEID> sourceResourceExternalEids = myEIDHelper.getExternalEid(theSourceResource);
|
List<CanonicalEID> goldenResourceExternalEids = myEIDHelper.getExternalEid(theGoldenResource);
|
||||||
|
|
||||||
for (CanonicalEID incomingExternalEid : theIncomingTargetExternalEids) {
|
for (CanonicalEID incomingExternalEid : theIncomingTargetExternalEids) {
|
||||||
if (sourceResourceExternalEids.contains(incomingExternalEid)) {
|
if (goldenResourceExternalEids.contains(incomingExternalEid)) {
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
cloneEidIntoResource(theSourceResource, incomingExternalEid);
|
cloneEidIntoResource(theGoldenResource, incomingExternalEid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -489,11 +490,11 @@ public class GoldenResourceHelper {
|
||||||
ourLog.debug(theMessage);
|
ourLog.debug(theMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleExternalEidAddition(IAnyResource theSourceResource, IAnyResource theTargetResource, MdmTransactionContext
|
public void handleExternalEidAddition(IAnyResource theGoldenResource, IAnyResource theTargetResource, MdmTransactionContext
|
||||||
theMdmTransactionContext) {
|
theMdmTransactionContext) {
|
||||||
List<CanonicalEID> eidFromResource = myEIDHelper.getExternalEid(theTargetResource);
|
List<CanonicalEID> eidFromResource = myEIDHelper.getExternalEid(theTargetResource);
|
||||||
if (!eidFromResource.isEmpty()) {
|
if (!eidFromResource.isEmpty()) {
|
||||||
updateSourceResourceExternalEidFromTargetResource(theSourceResource, theTargetResource, theMdmTransactionContext);
|
updateGoldenResourceExternalEidFromTargetResource(theGoldenResource, theTargetResource, theMdmTransactionContext);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue