Updated resource type handling
This commit is contained in:
parent
0ad1b129d3
commit
514dab7784
|
@ -33,6 +33,7 @@ public class EmpiProviderUpdateLinkR4Test extends BaseLinkR4Test {
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateLinkNoMatch() {
|
public void testUpdateLinkNoMatch() {
|
||||||
assertLinkCount(1);
|
assertLinkCount(1);
|
||||||
|
System.out.println(mySourcePatientId);
|
||||||
myEmpiProviderR4.updateLink(mySourcePatientId, myPatientId, NO_MATCH_RESULT, myRequestDetails);
|
myEmpiProviderR4.updateLink(mySourcePatientId, myPatientId, NO_MATCH_RESULT, myRequestDetails);
|
||||||
assertLinkCount(2);
|
assertLinkCount(2);
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ package ca.uhn.fhir.empi.provider;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import ca.uhn.fhir.context.FhirContext;
|
import ca.uhn.fhir.context.FhirContext;
|
||||||
|
import ca.uhn.fhir.context.RuntimeResourceDefinition;
|
||||||
import ca.uhn.fhir.empi.api.EmpiLinkJson;
|
import ca.uhn.fhir.empi.api.EmpiLinkJson;
|
||||||
import ca.uhn.fhir.empi.api.EmpiMatchResultEnum;
|
import ca.uhn.fhir.empi.api.EmpiMatchResultEnum;
|
||||||
import ca.uhn.fhir.empi.model.MdmTransactionContext;
|
import ca.uhn.fhir.empi.model.MdmTransactionContext;
|
||||||
|
@ -29,8 +30,10 @@ import ca.uhn.fhir.rest.server.TransactionLogMessages;
|
||||||
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
|
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
|
||||||
import ca.uhn.fhir.rest.server.provider.ProviderConstants;
|
import ca.uhn.fhir.rest.server.provider.ProviderConstants;
|
||||||
import ca.uhn.fhir.util.ParametersUtil;
|
import ca.uhn.fhir.util.ParametersUtil;
|
||||||
|
import org.hl7.fhir.dstu3.model.StringType;
|
||||||
import org.hl7.fhir.instance.model.api.IBase;
|
import org.hl7.fhir.instance.model.api.IBase;
|
||||||
import org.hl7.fhir.instance.model.api.IBaseParameters;
|
import org.hl7.fhir.instance.model.api.IBaseParameters;
|
||||||
|
import org.hl7.fhir.instance.model.api.IIdType;
|
||||||
import org.hl7.fhir.instance.model.api.IPrimitiveType;
|
import org.hl7.fhir.instance.model.api.IPrimitiveType;
|
||||||
|
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
@ -44,12 +47,13 @@ public abstract class BaseEmpiProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void validateMergeParameters(IPrimitiveType<String> theFromGoldenResourceId, IPrimitiveType<String> theToGoldenResourceId) {
|
protected void validateMergeParameters(IPrimitiveType<String> theFromGoldenResourceId, IPrimitiveType<String> theToGoldenResourceId) {
|
||||||
|
// TODO NG - Add validation to check that types are the same?
|
||||||
validateNotNull(ProviderConstants.MDM_MERGE_GR_FROM_GOLDEN_RESOURCE_ID, theFromGoldenResourceId);
|
validateNotNull(ProviderConstants.MDM_MERGE_GR_FROM_GOLDEN_RESOURCE_ID, theFromGoldenResourceId);
|
||||||
validateNotNull(ProviderConstants.MDM_MERGE_GR_TO_GOLDEN_RESOURCE_ID, theToGoldenResourceId);
|
validateNotNull(ProviderConstants.MDM_MERGE_GR_TO_GOLDEN_RESOURCE_ID, theToGoldenResourceId);
|
||||||
if (theFromGoldenResourceId.getValue().equals(theToGoldenResourceId.getValue())) {
|
if (theFromGoldenResourceId.getValue().equals(theToGoldenResourceId.getValue())) {
|
||||||
throw new InvalidRequestException("fromPersonId must be different from toPersonId");
|
throw new InvalidRequestException("fromPersonId must be different from toPersonId");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void validateNotNull(String theName, IPrimitiveType<String> theString) {
|
private void validateNotNull(String theName, IPrimitiveType<String> theString) {
|
||||||
if (theString == null || theString.getValue() == null) {
|
if (theString == null || theString.getValue() == null) {
|
||||||
|
@ -58,6 +62,7 @@ public abstract class BaseEmpiProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void validateUpdateLinkParameters(IPrimitiveType<String> theGoldenResourceId, IPrimitiveType<String> theResourceId, IPrimitiveType<String> theMatchResult) {
|
protected void validateUpdateLinkParameters(IPrimitiveType<String> theGoldenResourceId, IPrimitiveType<String> theResourceId, IPrimitiveType<String> theMatchResult) {
|
||||||
|
// TODO NG - Add validation to check that types are the same?
|
||||||
validateNotNull(ProviderConstants.MDM_UPDATE_LINK_GOLDEN_RESOURCE_ID, theGoldenResourceId);
|
validateNotNull(ProviderConstants.MDM_UPDATE_LINK_GOLDEN_RESOURCE_ID, theGoldenResourceId);
|
||||||
validateNotNull(ProviderConstants.MDM_UPDATE_LINK_RESOURCE_ID, theResourceId);
|
validateNotNull(ProviderConstants.MDM_UPDATE_LINK_RESOURCE_ID, theResourceId);
|
||||||
validateNotNull(ProviderConstants.MDM_UPDATE_LINK_MATCH_RESULT, theMatchResult);
|
validateNotNull(ProviderConstants.MDM_UPDATE_LINK_MATCH_RESULT, theMatchResult);
|
||||||
|
@ -77,11 +82,16 @@ public abstract class BaseEmpiProvider {
|
||||||
validateNotNull(ProviderConstants.MDM_UPDATE_LINK_RESOURCE_ID, theResourceId);
|
validateNotNull(ProviderConstants.MDM_UPDATE_LINK_RESOURCE_ID, theResourceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected MdmTransactionContext createMdmContext(RequestDetails theRequestDetails, MdmTransactionContext.OperationType theOperationType) {
|
protected String getResourceType(String theParamName, String theResourceId) {
|
||||||
|
IIdType idType = EmpiControllerUtil.getGoldenIdDtOrThrowException(theParamName, theResourceId);
|
||||||
|
return idType.getResourceType();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected MdmTransactionContext createMdmContext(RequestDetails theRequestDetails, MdmTransactionContext.OperationType theOperationType, String theResourceType) {
|
||||||
TransactionLogMessages transactionLogMessages = TransactionLogMessages.createFromTransactionGuid(theRequestDetails.getTransactionGuid());
|
TransactionLogMessages transactionLogMessages = TransactionLogMessages.createFromTransactionGuid(theRequestDetails.getTransactionGuid());
|
||||||
if (true)
|
MdmTransactionContext mdmTransactionContext = new MdmTransactionContext(transactionLogMessages, theOperationType);
|
||||||
throw new RuntimeException("FIXME - NG - We need a way to set resource type here");
|
mdmTransactionContext.setResourceType(theResourceType);
|
||||||
return new MdmTransactionContext(transactionLogMessages, theOperationType);
|
return mdmTransactionContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String extractStringOrNull(IPrimitiveType<String> theString) {
|
protected String extractStringOrNull(IPrimitiveType<String> theString) {
|
||||||
|
|
|
@ -115,7 +115,10 @@ public class EmpiProviderDstu3 extends BaseEmpiProvider {
|
||||||
RequestDetails theRequestDetails) {
|
RequestDetails theRequestDetails) {
|
||||||
validateMergeParameters(theFromPersonId, theToPersonId);
|
validateMergeParameters(theFromPersonId, theToPersonId);
|
||||||
|
|
||||||
return (Person) myEmpiControllerSvc.mergeGoldenResources(theFromPersonId.getValue(), theToPersonId.getValue(), createMdmContext(theRequestDetails, MdmTransactionContext.OperationType.MERGE_PERSONS));
|
String resourceType = getResourceType(ProviderConstants.MDM_MERGE_GR_FROM_GOLDEN_RESOURCE_ID, theFromPersonId.getValue());
|
||||||
|
|
||||||
|
return (Person) myEmpiControllerSvc.mergeGoldenResources(theFromPersonId.getValue(), theToPersonId.getValue(),
|
||||||
|
createMdmContext(theRequestDetails, MdmTransactionContext.OperationType.MERGE_PERSONS, resourceType));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(name = ProviderConstants.MDM_UPDATE_LINK, type = Person.class)
|
@Operation(name = ProviderConstants.MDM_UPDATE_LINK, type = Person.class)
|
||||||
|
@ -126,7 +129,9 @@ public class EmpiProviderDstu3 extends BaseEmpiProvider {
|
||||||
|
|
||||||
validateUpdateLinkParameters(thePersonId, theTargetId, theMatchResult);
|
validateUpdateLinkParameters(thePersonId, theTargetId, theMatchResult);
|
||||||
|
|
||||||
return (Person) myEmpiControllerSvc.updateLink(thePersonId.getValue(), theTargetId.getValue(), theMatchResult.getValue(), createMdmContext(theRequestDetails, MdmTransactionContext.OperationType.UPDATE_LINK));
|
return (Person) myEmpiControllerSvc.updateLink(thePersonId.getValue(), theTargetId.getValue(), theMatchResult.getValue(),
|
||||||
|
createMdmContext(theRequestDetails, MdmTransactionContext.OperationType.UPDATE_LINK,
|
||||||
|
getResourceType(ProviderConstants.MDM_UPDATE_LINK_GOLDEN_RESOURCE_ID, thePersonId.getValue())));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(name = ProviderConstants.MDM_QUERY_LINKS)
|
@Operation(name = ProviderConstants.MDM_QUERY_LINKS)
|
||||||
|
@ -136,13 +141,15 @@ public class EmpiProviderDstu3 extends BaseEmpiProvider {
|
||||||
@OperationParam(name=ProviderConstants.EMPI_QUERY_LINKS_MATCH_RESULT, min = 0, max = 1) StringType theLinkSource,
|
@OperationParam(name=ProviderConstants.EMPI_QUERY_LINKS_MATCH_RESULT, min = 0, max = 1) StringType theLinkSource,
|
||||||
ServletRequestDetails theRequestDetails) {
|
ServletRequestDetails theRequestDetails) {
|
||||||
|
|
||||||
Stream<EmpiLinkJson> empiLinkJson = myEmpiControllerSvc.queryLinks(extractStringOrNull(thePersonId), extractStringOrNull(theTargetId), extractStringOrNull(theMatchResult), extractStringOrNull(theLinkSource), createMdmContext(theRequestDetails, MdmTransactionContext.OperationType.QUERY_LINKS));
|
Stream<EmpiLinkJson> empiLinkJson = myEmpiControllerSvc.queryLinks(extractStringOrNull(thePersonId), extractStringOrNull(theTargetId),
|
||||||
|
extractStringOrNull(theMatchResult), extractStringOrNull(theLinkSource), createMdmContext(theRequestDetails,
|
||||||
|
MdmTransactionContext.OperationType.QUERY_LINKS, getResourceType(ProviderConstants.MDM_QUERY_LINKS_GOLDEN_RESOURCE_ID, thePersonId.getValue())));
|
||||||
return (Parameters) parametersFromEmpiLinks(empiLinkJson, true);
|
return (Parameters) parametersFromEmpiLinks(empiLinkJson, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(name = ProviderConstants.MDM_DUPLICATE_GOLDEN_RESOURCES)
|
@Operation(name = ProviderConstants.MDM_DUPLICATE_GOLDEN_RESOURCES)
|
||||||
public Parameters getDuplicatePersons(ServletRequestDetails theRequestDetails) {
|
public Parameters getDuplicatePersons(ServletRequestDetails theRequestDetails) {
|
||||||
Stream<EmpiLinkJson> possibleDuplicates = myEmpiControllerSvc.getDuplicateGoldenResources(createMdmContext(theRequestDetails, MdmTransactionContext.OperationType.QUERY_LINKS));
|
Stream<EmpiLinkJson> possibleDuplicates = myEmpiControllerSvc.getDuplicateGoldenResources(createMdmContext(theRequestDetails, MdmTransactionContext.OperationType.QUERY_LINKS, (String) null));
|
||||||
return (Parameters) parametersFromEmpiLinks(possibleDuplicates, false);
|
return (Parameters) parametersFromEmpiLinks(possibleDuplicates, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,7 +160,8 @@ public class EmpiProviderDstu3 extends BaseEmpiProvider {
|
||||||
ServletRequestDetails theRequestDetails) {
|
ServletRequestDetails theRequestDetails) {
|
||||||
|
|
||||||
validateNotDuplicateParameters(thePersonId, theTargetId);
|
validateNotDuplicateParameters(thePersonId, theTargetId);
|
||||||
myEmpiControllerSvc.notDuplicateGoldenResource(thePersonId.getValue(), theTargetId.getValue(), createMdmContext(theRequestDetails, MdmTransactionContext.OperationType.NOT_DUPLICATE));
|
myEmpiControllerSvc.notDuplicateGoldenResource(thePersonId.getValue(), theTargetId.getValue(),
|
||||||
|
createMdmContext(theRequestDetails, MdmTransactionContext.OperationType.NOT_DUPLICATE, thePersonId.fhirType()));
|
||||||
|
|
||||||
Parameters retval = (Parameters) ParametersUtil.newInstance(myFhirContext);
|
Parameters retval = (Parameters) ParametersUtil.newInstance(myFhirContext);
|
||||||
ParametersUtil.addParameterToParametersBoolean(myFhirContext, retval, "success", true);
|
ParametersUtil.addParameterToParametersBoolean(myFhirContext, retval, "success", true);
|
||||||
|
|
|
@ -150,7 +150,8 @@ public class EmpiProviderR4 extends BaseEmpiProvider {
|
||||||
RequestDetails theRequestDetails) {
|
RequestDetails theRequestDetails) {
|
||||||
validateMergeParameters(theFromGoldenResourceId, theToGoldenResourceId);
|
validateMergeParameters(theFromGoldenResourceId, theToGoldenResourceId);
|
||||||
|
|
||||||
return myEmpiControllerSvc.mergeGoldenResources(theFromGoldenResourceId.getValue(), theToGoldenResourceId.getValue(), createMdmContext(theRequestDetails, MdmTransactionContext.OperationType.MERGE_PERSONS));
|
return myEmpiControllerSvc.mergeGoldenResources(theFromGoldenResourceId.getValue(), theToGoldenResourceId.getValue(),
|
||||||
|
createMdmContext(theRequestDetails, MdmTransactionContext.OperationType.MERGE_PERSONS, theFromGoldenResourceId.getValue()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(name = ProviderConstants.MDM_UPDATE_LINK)
|
@Operation(name = ProviderConstants.MDM_UPDATE_LINK)
|
||||||
|
@ -158,9 +159,11 @@ public class EmpiProviderR4 extends BaseEmpiProvider {
|
||||||
@OperationParam(name=ProviderConstants.MDM_UPDATE_LINK_RESOURCE_ID, min = 1, max = 1) StringType theResourceId,
|
@OperationParam(name=ProviderConstants.MDM_UPDATE_LINK_RESOURCE_ID, min = 1, max = 1) StringType theResourceId,
|
||||||
@OperationParam(name=ProviderConstants.MDM_UPDATE_LINK_MATCH_RESULT, min = 1, max = 1) StringType theMatchResult,
|
@OperationParam(name=ProviderConstants.MDM_UPDATE_LINK_MATCH_RESULT, min = 1, max = 1) StringType theMatchResult,
|
||||||
ServletRequestDetails theRequestDetails) {
|
ServletRequestDetails theRequestDetails) {
|
||||||
|
|
||||||
validateUpdateLinkParameters(theGoldenResourceId, theResourceId, theMatchResult);
|
validateUpdateLinkParameters(theGoldenResourceId, theResourceId, theMatchResult);
|
||||||
return myEmpiControllerSvc.updateLink(theGoldenResourceId.getValueNotNull(), theResourceId.getValue(), theMatchResult.getValue(), createMdmContext(theRequestDetails, MdmTransactionContext.OperationType.UPDATE_LINK));
|
return myEmpiControllerSvc.updateLink(theGoldenResourceId.getValueNotNull(), theResourceId.getValue(),
|
||||||
|
theMatchResult.getValue(),
|
||||||
|
createMdmContext(theRequestDetails, MdmTransactionContext.OperationType.UPDATE_LINK,
|
||||||
|
getResourceType(ProviderConstants.MDM_UPDATE_LINK_GOLDEN_RESOURCE_ID, theGoldenResourceId.getValue())));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(name = ProviderConstants.MDM_CLEAR, returnParameters = {
|
@Operation(name = ProviderConstants.MDM_CLEAR, returnParameters = {
|
||||||
|
@ -188,13 +191,17 @@ public class EmpiProviderR4 extends BaseEmpiProvider {
|
||||||
@OperationParam(name=ProviderConstants.EMPI_QUERY_LINKS_LINK_SOURCE, min = 0, max = 1) StringType theLinkSource,
|
@OperationParam(name=ProviderConstants.EMPI_QUERY_LINKS_LINK_SOURCE, min = 0, max = 1) StringType theLinkSource,
|
||||||
ServletRequestDetails theRequestDetails) {
|
ServletRequestDetails theRequestDetails) {
|
||||||
|
|
||||||
Stream<EmpiLinkJson> empiLinkJson = myEmpiControllerSvc.queryLinks(extractStringOrNull(theGoldenResourceId), extractStringOrNull(theResourceId), extractStringOrNull(theMatchResult), extractStringOrNull(theLinkSource), createMdmContext(theRequestDetails, MdmTransactionContext.OperationType.QUERY_LINKS));
|
Stream<EmpiLinkJson> empiLinkJson = myEmpiControllerSvc.queryLinks(extractStringOrNull(theGoldenResourceId),
|
||||||
|
extractStringOrNull(theResourceId), extractStringOrNull(theMatchResult), extractStringOrNull(theLinkSource),
|
||||||
|
createMdmContext(theRequestDetails, MdmTransactionContext.OperationType.QUERY_LINKS, theGoldenResourceId.getValue()));
|
||||||
return (Parameters) parametersFromEmpiLinks(empiLinkJson, true);
|
return (Parameters) parametersFromEmpiLinks(empiLinkJson, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(name = ProviderConstants.MDM_DUPLICATE_GOLDEN_RESOURCES, idempotent = true)
|
@Operation(name = ProviderConstants.MDM_DUPLICATE_GOLDEN_RESOURCES, idempotent = true)
|
||||||
public Parameters getDuplicateGoldenResources(ServletRequestDetails theRequestDetails) {
|
public Parameters getDuplicateGoldenResources(ServletRequestDetails theRequestDetails) {
|
||||||
Stream<EmpiLinkJson> possibleDuplicates = myEmpiControllerSvc.getDuplicateGoldenResources(createMdmContext(theRequestDetails, MdmTransactionContext.OperationType.DUPLICATE_GOLDEN_RESOURCES));
|
Stream<EmpiLinkJson> possibleDuplicates = myEmpiControllerSvc.getDuplicateGoldenResources(
|
||||||
|
createMdmContext(theRequestDetails, MdmTransactionContext.OperationType.DUPLICATE_GOLDEN_RESOURCES, (String) null)
|
||||||
|
);
|
||||||
return (Parameters) parametersFromEmpiLinks(possibleDuplicates, false);
|
return (Parameters) parametersFromEmpiLinks(possibleDuplicates, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,7 +211,8 @@ public class EmpiProviderR4 extends BaseEmpiProvider {
|
||||||
ServletRequestDetails theRequestDetails) {
|
ServletRequestDetails theRequestDetails) {
|
||||||
|
|
||||||
validateNotDuplicateParameters(theGoldenResourceId, theResourceId);
|
validateNotDuplicateParameters(theGoldenResourceId, theResourceId);
|
||||||
myEmpiControllerSvc.notDuplicateGoldenResource(theGoldenResourceId.getValue(), theResourceId.getValue(), createMdmContext(theRequestDetails, MdmTransactionContext.OperationType.NOT_DUPLICATE));
|
myEmpiControllerSvc.notDuplicateGoldenResource(theGoldenResourceId.getValue(), theResourceId.getValue(),
|
||||||
|
createMdmContext(theRequestDetails, MdmTransactionContext.OperationType.NOT_DUPLICATE, theGoldenResourceId.getValue()));
|
||||||
|
|
||||||
Parameters retval = (Parameters) ParametersUtil.newInstance(myFhirContext);
|
Parameters retval = (Parameters) ParametersUtil.newInstance(myFhirContext);
|
||||||
ParametersUtil.addParameterToParametersBoolean(myFhirContext, retval, "success", true);
|
ParametersUtil.addParameterToParametersBoolean(myFhirContext, retval, "success", true);
|
||||||
|
|
|
@ -20,10 +20,12 @@ package ca.uhn.fhir.empi.util;
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import ca.uhn.fhir.rest.param.StringParam;
|
||||||
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
|
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
|
||||||
import org.hl7.fhir.instance.model.api.IBase;
|
import org.hl7.fhir.instance.model.api.IBase;
|
||||||
|
|
||||||
public class IdentifierUtil {
|
public class IdentifierUtil {
|
||||||
|
|
||||||
public static CanonicalIdentifier identifierDtFromIdentifier(IBase theIdentifier) {
|
public static CanonicalIdentifier identifierDtFromIdentifier(IBase theIdentifier) {
|
||||||
CanonicalIdentifier retval = new CanonicalIdentifier();
|
CanonicalIdentifier retval = new CanonicalIdentifier();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue