Links WIP
This commit is contained in:
parent
9df0c16b95
commit
fa0e87b56c
|
@ -35,6 +35,7 @@ import ca.uhn.fhir.empi.provider.EmpiProviderLoader;
|
|||
import ca.uhn.fhir.empi.rules.config.EmpiRuleValidator;
|
||||
import ca.uhn.fhir.empi.rules.svc.EmpiResourceMatcherSvc;
|
||||
import ca.uhn.fhir.empi.util.EIDHelper;
|
||||
import ca.uhn.fhir.empi.util.MessageHelper;
|
||||
import ca.uhn.fhir.empi.util.PersonHelper;
|
||||
import ca.uhn.fhir.jpa.dao.empi.EmpiLinkDeleteSvc;
|
||||
import ca.uhn.fhir.jpa.empi.broker.EmpiMessageHandler;
|
||||
|
@ -223,7 +224,9 @@ public class EmpiConsumerConfig {
|
|||
}
|
||||
|
||||
@Bean
|
||||
EmpiControllerHelper empiProviderHelper(FhirContext theFhirContext, IResourceLoader theResourceLoader) { return new EmpiControllerHelper(theFhirContext, theResourceLoader); }
|
||||
EmpiControllerHelper empiProviderHelper(FhirContext theFhirContext, IResourceLoader theResourceLoader, IEmpiSettings theEmpiSettings, MessageHelper messageHelper) {
|
||||
return new EmpiControllerHelper(theFhirContext, theResourceLoader, theEmpiSettings, messageHelper);
|
||||
}
|
||||
|
||||
@Bean
|
||||
IEmpiControllerSvc empiControllerSvc() {return new EmpiControllerSvcImpl(); }
|
||||
|
|
|
@ -26,9 +26,12 @@ import ca.uhn.fhir.empi.api.EmpiLinkSourceEnum;
|
|||
import ca.uhn.fhir.empi.api.EmpiMatchResultEnum;
|
||||
import ca.uhn.fhir.empi.api.IEmpiLinkSvc;
|
||||
import ca.uhn.fhir.empi.api.IEmpiLinkUpdaterSvc;
|
||||
import ca.uhn.fhir.empi.api.IEmpiSettings;
|
||||
import ca.uhn.fhir.empi.log.Logs;
|
||||
import ca.uhn.fhir.empi.model.MdmTransactionContext;
|
||||
import ca.uhn.fhir.empi.rules.config.EmpiSettings;
|
||||
import ca.uhn.fhir.empi.util.EmpiUtil;
|
||||
import ca.uhn.fhir.empi.util.MessageHelper;
|
||||
import ca.uhn.fhir.jpa.dao.index.IdHelperService;
|
||||
import ca.uhn.fhir.jpa.empi.dao.EmpiLinkDaoSvc;
|
||||
import ca.uhn.fhir.jpa.entity.EmpiLink;
|
||||
|
@ -42,6 +45,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
import java.util.Optional;
|
||||
|
||||
public class EmpiLinkUpdaterSvcImpl implements IEmpiLinkUpdaterSvc {
|
||||
|
||||
private static final Logger ourLog = Logs.getEmpiTroubleshootingLog();
|
||||
|
||||
@Autowired
|
||||
|
@ -56,6 +60,10 @@ public class EmpiLinkUpdaterSvcImpl implements IEmpiLinkUpdaterSvc {
|
|||
EmpiResourceDaoSvc myEmpiResourceDaoSvc;
|
||||
@Autowired
|
||||
EmpiMatchLinkSvc myEmpiMatchLinkSvc;
|
||||
@Autowired
|
||||
IEmpiSettings myEmpiSettings;
|
||||
@Autowired
|
||||
MessageHelper myMessageHelper;
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
|
@ -90,22 +98,24 @@ public class EmpiLinkUpdaterSvcImpl implements IEmpiLinkUpdaterSvc {
|
|||
return thePerson;
|
||||
}
|
||||
|
||||
private void validateUpdateLinkRequest(IAnyResource thePerson, IAnyResource theTarget, EmpiMatchResultEnum theMatchResult, String theTargetType) {
|
||||
String personType = myFhirContext.getResourceType(thePerson);
|
||||
private void validateUpdateLinkRequest(IAnyResource theGoldenRecord, IAnyResource theTarget, EmpiMatchResultEnum theMatchResult, String theTargetType) {
|
||||
String goldenRecordType = myFhirContext.getResourceType(theGoldenRecord);
|
||||
|
||||
if (theMatchResult != EmpiMatchResultEnum.NO_MATCH &&
|
||||
theMatchResult != EmpiMatchResultEnum.MATCH) {
|
||||
throw new InvalidRequestException("Match Result may only be set to " + EmpiMatchResultEnum.NO_MATCH + " or " + EmpiMatchResultEnum.MATCH);
|
||||
throw new InvalidRequestException(myMessageHelper.getMessageForUnsupportedMatchResult());
|
||||
}
|
||||
|
||||
if (!"Person".equals(personType)) {
|
||||
throw new InvalidRequestException("First argument to " + ProviderConstants.MDM_UPDATE_LINK + " must be a Person. Was " + personType);
|
||||
if (!myEmpiSettings.isSupportedMdmType(goldenRecordType)) {
|
||||
throw new InvalidRequestException("First argument to " + ProviderConstants.MDM_UPDATE_LINK + " must be a Person. Was " + goldenRecordType);
|
||||
}
|
||||
if (!EmpiUtil.supportedTargetType(theTargetType)) {
|
||||
|
||||
if (!myEmpiSettings.isSupportedMdmType(theTargetType)) {
|
||||
throw new InvalidRequestException("Second argument to " + ProviderConstants.MDM_UPDATE_LINK + " must be a Patient or Practitioner. Was " + theTargetType);
|
||||
}
|
||||
|
||||
if (!EmpiUtil.isEmpiManaged(thePerson)) {
|
||||
throw new InvalidRequestException("Only EMPI Managed Person resources may be updated via this operation. The Person resource provided is not tagged as managed by hapi-empi");
|
||||
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");
|
||||
}
|
||||
|
||||
if (!EmpiUtil.isEmpiAccessible(theTarget)) {
|
||||
|
|
|
@ -138,11 +138,12 @@ abstract public class BaseEmpiR4Test extends BaseJpaR4Test {
|
|||
protected void saveLink(EmpiLink theEmpiLink) {
|
||||
myEmpiLinkDaoSvc.save(theEmpiLink);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
protected Patient createUnmanagedSourceResource() {
|
||||
return createGoldenPatient(new Patient(), false);
|
||||
}
|
||||
//
|
||||
// @Nonnull
|
||||
// protected Patient createUnmanagedSourceResource() {
|
||||
// // return createGoldenPatient(new Patient(), false);
|
||||
// return createGoldenPatient(new Patient(), false);
|
||||
// }
|
||||
|
||||
@Nonnull
|
||||
protected Patient createGoldenPatient() {
|
||||
|
@ -163,6 +164,7 @@ abstract public class BaseEmpiR4Test extends BaseJpaR4Test {
|
|||
protected Patient createGoldenPatient(Patient thePatient, boolean theEmpiManaged) {
|
||||
EmpiUtil.setEmpiManaged(thePatient);
|
||||
EmpiUtil.setGoldenResource(thePatient);
|
||||
|
||||
DaoMethodOutcome outcome = myPatientDao.create(thePatient);
|
||||
Patient patient = (Patient) outcome.getResource();
|
||||
patient.setId(outcome.getId());
|
||||
|
|
|
@ -58,8 +58,8 @@ public class EmpiProviderMergePersonsR4Test extends BaseProviderR4Test {
|
|||
|
||||
@Test
|
||||
public void testUnmanagedMerge() {
|
||||
StringType fromPersonId = new StringType(createUnmanagedSourceResource().getIdElement().getValue());
|
||||
StringType toPersonId = new StringType(createUnmanagedSourceResource().getIdElement().getValue());
|
||||
StringType fromPersonId = new StringType(createPatient().getIdElement().getValue());
|
||||
StringType toPersonId = new StringType(createPatient().getIdElement().getValue());
|
||||
try {
|
||||
myEmpiProviderR4.mergeGoldenResources(fromPersonId, toPersonId, myRequestDetails);
|
||||
fail();
|
||||
|
|
|
@ -3,6 +3,9 @@ package ca.uhn.fhir.jpa.empi.provider;
|
|||
import ca.uhn.fhir.empi.api.EmpiConstants;
|
||||
import ca.uhn.fhir.empi.api.EmpiLinkSourceEnum;
|
||||
import ca.uhn.fhir.empi.api.EmpiMatchResultEnum;
|
||||
import ca.uhn.fhir.empi.api.IEmpiSettings;
|
||||
import ca.uhn.fhir.empi.provider.EmpiControllerHelper;
|
||||
import ca.uhn.fhir.empi.util.MessageHelper;
|
||||
import ca.uhn.fhir.jpa.entity.EmpiLink;
|
||||
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
|
||||
import ca.uhn.fhir.rest.server.exceptions.ResourceVersionConflictException;
|
||||
|
@ -10,6 +13,7 @@ import org.hl7.fhir.r4.model.Patient;
|
|||
import org.hl7.fhir.r4.model.Person;
|
||||
import org.hl7.fhir.r4.model.StringType;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -22,6 +26,16 @@ import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
|||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
public class EmpiProviderUpdateLinkR4Test extends BaseLinkR4Test {
|
||||
|
||||
// @Autowired
|
||||
// private IEmpiSettings myEmpiSettings;
|
||||
|
||||
@Autowired
|
||||
private MessageHelper myMessageHelper;
|
||||
|
||||
@Autowired
|
||||
private EmpiControllerHelper myEmpiControllerHelper;
|
||||
|
||||
@Test
|
||||
public void testUpdateLinkNoMatch() {
|
||||
assertLinkCount(1);
|
||||
|
@ -118,12 +132,14 @@ public class EmpiProviderUpdateLinkR4Test extends BaseLinkR4Test {
|
|||
|
||||
@Test
|
||||
public void testUpdateStrangePerson() {
|
||||
Patient person = createUnmanagedSourceResource();
|
||||
// TODO NG - OK? Patient person = createUnmanagedSourceResource();
|
||||
Patient person = createPatient();
|
||||
try {
|
||||
myEmpiProviderR4.updateLink(new StringType(person.getIdElement().getValue()), myPatientId, NO_MATCH_RESULT, myRequestDetails);
|
||||
fail();
|
||||
} catch (InvalidRequestException e) {
|
||||
assertEquals("Only EMPI Managed Person resources may be updated via this operation. The Source Resource provided is not tagged as managed by hapi-empi", e.getMessage());
|
||||
String expectedMessage = myMessageHelper.getMessageForUnmanagedResource();
|
||||
assertEquals(expectedMessage, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -21,6 +21,9 @@ package ca.uhn.fhir.empi.api;
|
|||
*/
|
||||
|
||||
import ca.uhn.fhir.empi.rules.json.EmpiRulesJson;
|
||||
import org.hl7.fhir.instance.model.api.IAnyResource;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public interface IEmpiSettings {
|
||||
String EMPI_CHANNEL_NAME = "empi";
|
||||
|
@ -38,4 +41,12 @@ public interface IEmpiSettings {
|
|||
boolean isPreventMultipleEids();
|
||||
|
||||
String getRuleVersion();
|
||||
|
||||
default boolean isSupportedMdmType(String theResourceName) {
|
||||
return getEmpiRules().getMdmTypes().contains(theResourceName);
|
||||
}
|
||||
|
||||
default String getSupportedMdmTypeNames() {
|
||||
return getEmpiRules().getMdmTypes().stream().collect(Collectors.joining(", "));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,9 @@ package ca.uhn.fhir.empi.provider;
|
|||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.empi.api.EmpiConstants;
|
||||
import ca.uhn.fhir.empi.api.IEmpiSettings;
|
||||
import ca.uhn.fhir.empi.util.EmpiUtil;
|
||||
import ca.uhn.fhir.empi.util.MessageHelper;
|
||||
import ca.uhn.fhir.model.primitive.IdDt;
|
||||
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
|
||||
import ca.uhn.fhir.rest.server.exceptions.ResourceVersionConflictException;
|
||||
|
@ -34,15 +36,24 @@ import org.hl7.fhir.instance.model.api.IIdType;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class EmpiControllerHelper {
|
||||
private final FhirContext myFhirContext;
|
||||
private final IResourceLoader myResourceLoader;
|
||||
private final IEmpiSettings myEmpiSettings;
|
||||
private final MessageHelper myMessageHelper;
|
||||
|
||||
@Autowired
|
||||
public EmpiControllerHelper(FhirContext theFhirContext, IResourceLoader theResourceLoader) {
|
||||
public EmpiControllerHelper(FhirContext theFhirContext, IResourceLoader theResourceLoader, IEmpiSettings theEmpiSettings, MessageHelper theMessageHelper) {
|
||||
myFhirContext = theFhirContext;
|
||||
myResourceLoader = theResourceLoader;
|
||||
myEmpiSettings = theEmpiSettings;
|
||||
myMessageHelper = theMessageHelper;
|
||||
}
|
||||
|
||||
public void validateSameVersion(IAnyResource theResource, String theResourceId) {
|
||||
|
@ -81,12 +92,16 @@ public class EmpiControllerHelper {
|
|||
return myFhirContext.newJsonParser().encodeResourceToString(theAnyResource);
|
||||
}
|
||||
|
||||
private void validateIsEmpiManaged(String theName, IAnyResource thePerson) {
|
||||
if (!"Person".equals(myFhirContext.getResourceType(thePerson))) {
|
||||
throw new InvalidRequestException("Only Person resources can be merged. The " + theName + " points to a " + myFhirContext.getResourceType(thePerson));
|
||||
public void validateIsEmpiManaged(String theName, IAnyResource theResource) {
|
||||
String resourceType = myFhirContext.getResourceType(theResource);
|
||||
if (!myEmpiSettings.isSupportedMdmType(resourceType)) {
|
||||
throw new InvalidRequestException(
|
||||
myMessageHelper.getMessageForUnsupportedResource(theName, resourceType)
|
||||
);
|
||||
}
|
||||
if (!EmpiUtil.isEmpiManaged(thePerson)) {
|
||||
throw new InvalidRequestException("Only EMPI managed resources can be merged. Empi managed resource have the " + EmpiConstants.CODE_HAPI_MDM_MANAGED + " tag.");
|
||||
|
||||
if (!EmpiUtil.isEmpiManaged(theResource)) {
|
||||
throw new InvalidRequestException(myMessageHelper.getMessageForUnmanagedResource());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
package ca.uhn.fhir.empi.util;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
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 org.hl7.fhir.instance.model.api.IAnyResource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class MessageHelper {
|
||||
|
||||
@Autowired
|
||||
private final IEmpiSettings myEmpiSettings;
|
||||
|
||||
@Autowired
|
||||
private final FhirContext myFhirContext;
|
||||
|
||||
public MessageHelper(IEmpiSettings theEmpiSettings, FhirContext theFhirContext) {
|
||||
myEmpiSettings = theEmpiSettings;
|
||||
myFhirContext = theFhirContext;
|
||||
}
|
||||
|
||||
public String getMessageForUnmanagedResource() {
|
||||
return String.format(
|
||||
"Only MDM managed resources can be merged. MDM managed resources must have the %s tag.",
|
||||
EmpiConstants.CODE_HAPI_MDM_MANAGED);
|
||||
}
|
||||
|
||||
public String getMessageForUnsupportedResource(String theName, IAnyResource theResource) {
|
||||
return getMessageForUnsupportedResource(theName, myFhirContext.getResourceType(theResource));
|
||||
}
|
||||
|
||||
public String getMessageForUnsupportedResource(String theName, String theResourceType) {
|
||||
return String.format("Only %s resources can be merged. The %s points to a %s",
|
||||
myEmpiSettings.getSupportedMdmTypeNames(), theName, theResourceType);
|
||||
}
|
||||
|
||||
public String getMessageForUnsupportedMatchResult() {
|
||||
return "Match Result may only be set to " + EmpiMatchResultEnum.NO_MATCH + " or " + EmpiMatchResultEnum.MATCH;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue