From 1ad0246c2a60e69c016c3a41731bc07738e3db44 Mon Sep 17 00:00:00 2001 From: Nick Goupinets Date: Fri, 13 Nov 2020 17:16:10 -0500 Subject: [PATCH] Added config fix --- .../jpa/empi/config/EmpiConsumerConfig.java | 15 +++++++++---- .../jpa/empi/svc/EmpiLinkUpdaterSvcImpl.java | 13 ++++++++---- .../EmpiProviderUpdateLinkR4Test.java | 1 - .../ca/uhn/fhir/empi/util/MessageHelper.java | 21 +++++++++++++++++++ 4 files changed, 41 insertions(+), 9 deletions(-) diff --git a/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/config/EmpiConsumerConfig.java b/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/config/EmpiConsumerConfig.java index a1f00647288..f4d814b7781 100644 --- a/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/config/EmpiConsumerConfig.java +++ b/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/config/EmpiConsumerConfig.java @@ -112,6 +112,11 @@ public class EmpiConsumerConfig { return new PersonHelper(theFhirContext); } + @Bean + MessageHelper messageHelper(IEmpiSettings theEmpiSettings, FhirContext theFhirContext) { + return new MessageHelper(theEmpiSettings, theFhirContext); + } + @Bean EmpiSubscriptionLoader empiSubscriptionLoader() { return new EmpiSubscriptionLoader(); @@ -123,7 +128,7 @@ public class EmpiConsumerConfig { } @Bean - EmpiSourceResourceFindingSvc empiPersonFindingSvc() { + EmpiSourceResourceFindingSvc empiPersonFindingSvc() { return new EmpiSourceResourceFindingSvc(); } @@ -169,7 +174,7 @@ public class EmpiConsumerConfig { } @Bean - IEmpiExpungeSvc empiResetSvc(EmpiLinkDaoSvc theEmpiLinkDaoSvc, EmpiPersonDeletingSvc theEmpiPersonDeletingSvcImpl ) { + IEmpiExpungeSvc empiResetSvc(EmpiLinkDaoSvc theEmpiLinkDaoSvc, EmpiPersonDeletingSvc theEmpiPersonDeletingSvcImpl) { return new EmpiClearSvcImpl(theEmpiLinkDaoSvc, theEmpiPersonDeletingSvcImpl); } @@ -184,7 +189,7 @@ public class EmpiConsumerConfig { } @Bean - EmpiResourceMatcherSvc empiResourceComparatorSvc(FhirContext theFhirContext, IEmpiSettings theEmpiConfig) { + EmpiResourceMatcherSvc empiResourceComparatorSvc(FhirContext theFhirContext, IEmpiSettings theEmpiConfig) { return new EmpiResourceMatcherSvc(theFhirContext, theEmpiConfig); } @@ -229,5 +234,7 @@ public class EmpiConsumerConfig { } @Bean - IEmpiControllerSvc empiControllerSvc() {return new EmpiControllerSvcImpl(); } + IEmpiControllerSvc empiControllerSvc() { + return new EmpiControllerSvcImpl(); + } } diff --git a/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/svc/EmpiLinkUpdaterSvcImpl.java b/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/svc/EmpiLinkUpdaterSvcImpl.java index 1b3e4662a49..ed6995864c8 100644 --- a/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/svc/EmpiLinkUpdaterSvcImpl.java +++ b/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/svc/EmpiLinkUpdaterSvcImpl.java @@ -42,6 +42,7 @@ import org.slf4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; +import java.util.Objects; import java.util.Optional; public class EmpiLinkUpdaterSvcImpl implements IEmpiLinkUpdaterSvc { @@ -107,19 +108,23 @@ public class EmpiLinkUpdaterSvcImpl implements IEmpiLinkUpdaterSvc { } if (!myEmpiSettings.isSupportedMdmType(goldenRecordType)) { - throw new InvalidRequestException("First argument to " + ProviderConstants.MDM_UPDATE_LINK + " must be a Person. Was " + goldenRecordType); + throw new InvalidRequestException(myMessageHelper.getMessageForUnsupportedFirstArgumentTypeInUpdate(goldenRecordType)); } if (!myEmpiSettings.isSupportedMdmType(theTargetType)) { - throw new InvalidRequestException("Second argument to " + ProviderConstants.MDM_UPDATE_LINK + " must be a Patient or Practitioner. Was " + theTargetType); + throw new InvalidRequestException(myMessageHelper.getMessageForUnsupportedSecondArgumentTypeInUpdate(theTargetType)); + } + + if (!Objects.equals(goldenRecordType, theTargetType)) { + throw new InvalidRequestException(myMessageHelper.getMessageForArgumentTypeMismatchInUpdate(goldenRecordType, theTargetType)); } if (!EmpiUtil.isEmpiManaged(theGoldenRecord)) { - throw new InvalidRequestException("Only MDM managed rerson resources may be updated via this operation. The Person resource provided is not tagged as managed by hapi-empi"); + throw new InvalidRequestException(myMessageHelper.getMessageForUnmanagedResource()); } if (!EmpiUtil.isEmpiAccessible(theTarget)) { - throw new InvalidRequestException("The target is marked with the " + EmpiConstants.CODE_NO_EMPI_MANAGED + " tag which means it may not be EMPI linked."); + throw new InvalidRequestException(myMessageHelper.getMessageForUnsupportedTarget()); } } diff --git a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/provider/EmpiProviderUpdateLinkR4Test.java b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/provider/EmpiProviderUpdateLinkR4Test.java index 4ccbd0fad7a..b95b13d29ae 100644 --- a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/provider/EmpiProviderUpdateLinkR4Test.java +++ b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/provider/EmpiProviderUpdateLinkR4Test.java @@ -132,7 +132,6 @@ public class EmpiProviderUpdateLinkR4Test extends BaseLinkR4Test { @Test public void testUpdateStrangePerson() { - // TODO NG - OK? Patient person = createUnmanagedSourceResource(); Patient person = createPatient(); try { myEmpiProviderR4.updateLink(new StringType(person.getIdElement().getValue()), myPatientId, NO_MATCH_RESULT, myRequestDetails); diff --git a/hapi-fhir-server-empi/src/main/java/ca/uhn/fhir/empi/util/MessageHelper.java b/hapi-fhir-server-empi/src/main/java/ca/uhn/fhir/empi/util/MessageHelper.java index eb7b5f284cc..b5b51b26ade 100644 --- a/hapi-fhir-server-empi/src/main/java/ca/uhn/fhir/empi/util/MessageHelper.java +++ b/hapi-fhir-server-empi/src/main/java/ca/uhn/fhir/empi/util/MessageHelper.java @@ -5,6 +5,7 @@ import ca.uhn.fhir.empi.api.EmpiConstants; import ca.uhn.fhir.empi.api.EmpiMatchResultEnum; import ca.uhn.fhir.empi.api.IEmpiLinkQuerySvc; import ca.uhn.fhir.empi.api.IEmpiSettings; +import ca.uhn.fhir.rest.server.provider.ProviderConstants; import org.hl7.fhir.instance.model.api.IAnyResource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -41,4 +42,24 @@ public class MessageHelper { public String getMessageForUnsupportedMatchResult() { return "Match Result may only be set to " + EmpiMatchResultEnum.NO_MATCH + " or " + EmpiMatchResultEnum.MATCH; } + + public String getMessageForUnsupportedFirstArgumentTypeInUpdate(String goldenRecordType) { + return "First argument to " + ProviderConstants.MDM_UPDATE_LINK + " must be a " + + myEmpiSettings.getSupportedMdmTypeNames() + ". Was " + goldenRecordType; + } + + public String getMessageForUnsupportedSecondArgumentTypeInUpdate(String theGoldenRecordType) { + return "First argument to " + ProviderConstants.MDM_UPDATE_LINK + " must be a " + + myEmpiSettings.getSupportedMdmTypeNames() + ". Was " + theGoldenRecordType; + } + + public String getMessageForArgumentTypeMismatchInUpdate(String theGoldenRecordType, String theTargetType) { + return "Arguments to " + ProviderConstants.MDM_UPDATE_LINK + " must be of the same type. Were " + + theGoldenRecordType + " and " + theTargetType; + } + + public String getMessageForUnsupportedTarget() { + return "The target is marked with the " + EmpiConstants.CODE_NO_EMPI_MANAGED + + " tag which means it may not be EMPI linked."; + } }