Head off potential MDM bug (#3140)

* wip

* fix up error message

* wip

* Fix all tests

* Update old tests for failure messages

* Add another test case

* Remove dead file

* Fix log message
This commit is contained in:
Tadgh 2021-11-04 18:09:46 -04:00 committed by GitHub
parent 59bf8b836f
commit e29ad5179a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 20 additions and 8 deletions

View File

@ -57,7 +57,7 @@ public class MdmResourceFilteringSvc {
*/ */
public boolean shouldBeProcessed(IAnyResource theResource) { public boolean shouldBeProcessed(IAnyResource theResource) {
if (MdmResourceUtil.isMdmManaged(theResource)) { if (MdmResourceUtil.isMdmManaged(theResource)) {
ourLog.debug("MDM Message handler is dropping [{}] as it is MDM-managed.", theResource); ourLog.debug("MDM Message handler is dropping [{}] as it is MDM-managed.", theResource.getId());
return false; return false;
} }

View File

@ -7,6 +7,7 @@ import ca.uhn.fhir.mdm.api.IMdmMatchFinderSvc;
import ca.uhn.fhir.mdm.api.IMdmSubmitSvc; import ca.uhn.fhir.mdm.api.IMdmSubmitSvc;
import ca.uhn.fhir.mdm.provider.MdmProviderDstu3Plus; import ca.uhn.fhir.mdm.provider.MdmProviderDstu3Plus;
import ca.uhn.fhir.mdm.rules.config.MdmSettings; import ca.uhn.fhir.mdm.rules.config.MdmSettings;
import ca.uhn.fhir.mdm.util.MessageHelper;
import ca.uhn.fhir.test.utilities.BatchJobHelper; import ca.uhn.fhir.test.utilities.BatchJobHelper;
import com.google.common.base.Charsets; import com.google.common.base.Charsets;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
@ -39,6 +40,8 @@ public abstract class BaseProviderR4Test extends BaseMdmR4Test {
private MdmSettings myMdmSettings; private MdmSettings myMdmSettings;
@Autowired @Autowired
BatchJobHelper myBatchJobHelper; BatchJobHelper myBatchJobHelper;
@Autowired
MessageHelper myMessageHelper;
private String defaultScript; private String defaultScript;

View File

@ -141,7 +141,7 @@ public class MdmProviderCreateLinkR4Test extends BaseLinkR4Test {
@Test @Test
public void testCreateIllegalSecondArg() { public void testCreateIllegalSecondArg() {
try { try {
myMdmProvider.createLink(myPatientId, new StringType(""), MATCH_RESULT, myRequestDetails); myMdmProvider.createLink(myVersionlessGodlenResourceId, new StringType(""), MATCH_RESULT, myRequestDetails);
fail(); fail();
} catch (InvalidRequestException e) { } catch (InvalidRequestException e) {
assertThat(e.getMessage(), endsWith(" must have form <resourceType>/<id> where <id> is the id of the resource and <resourceType> is the type of the resource")); assertThat(e.getMessage(), endsWith(" must have form <resourceType>/<id> where <id> is the id of the resource and <resourceType> is the type of the resource"));
@ -155,7 +155,7 @@ public class MdmProviderCreateLinkR4Test extends BaseLinkR4Test {
myMdmProvider.createLink(new StringType(patient.getIdElement().getValue()), myPatientId, MATCH_RESULT, myRequestDetails); myMdmProvider.createLink(new StringType(patient.getIdElement().getValue()), myPatientId, MATCH_RESULT, myRequestDetails);
fail(); fail();
} catch (InvalidRequestException e) { } catch (InvalidRequestException e) {
String expectedMessage = myMessageHelper.getMessageForUnmanagedResource(); String expectedMessage = myMessageHelper.getMessageForFailedGoldenResourceLoad("goldenResourceId", patient.getId());
assertEquals(expectedMessage, e.getMessage()); assertEquals(expectedMessage, e.getMessage());
} }
} }

View File

@ -129,7 +129,8 @@ public class MdmProviderMergeGoldenResourcesR4Test extends BaseProviderR4Test {
myMdmProvider.mergeGoldenResources(fromGoldenResourceId, toGoldenResourceId, null, myRequestDetails); myMdmProvider.mergeGoldenResources(fromGoldenResourceId, toGoldenResourceId, null, myRequestDetails);
fail(); fail();
} catch (InvalidRequestException e) { } catch (InvalidRequestException e) {
assertEquals("Only MDM managed resources can be merged. MDM managed resources must have the HAPI-MDM tag.", e.getMessage()); String message = myMessageHelper.getMessageForFailedGoldenResourceLoad("fromGoldenResourceId", fromGoldenResourceId.getValue());
assertEquals(e.getMessage(), message);
} }
} }

View File

@ -117,7 +117,7 @@ public class MdmProviderUpdateLinkR4Test extends BaseLinkR4Test {
@Test @Test
public void testUpdateIllegalSecondArg() { public void testUpdateIllegalSecondArg() {
try { try {
myMdmProvider.updateLink(myPatientId, new StringType(""), NO_MATCH_RESULT, myRequestDetails); myMdmProvider.updateLink(myVersionlessGodlenResourceId, new StringType(""), NO_MATCH_RESULT, myRequestDetails);
fail(); fail();
} catch (InvalidRequestException e) { } catch (InvalidRequestException e) {
assertThat(e.getMessage(), endsWith(" must have form <resourceType>/<id> where <id> is the id of the resource and <resourceType> is the type of the resource")); assertThat(e.getMessage(), endsWith(" must have form <resourceType>/<id> where <id> is the id of the resource and <resourceType> is the type of the resource"));
@ -151,7 +151,7 @@ public class MdmProviderUpdateLinkR4Test extends BaseLinkR4Test {
myMdmProvider.updateLink(new StringType(patient.getIdElement().getValue()), myPatientId, NO_MATCH_RESULT, myRequestDetails); myMdmProvider.updateLink(new StringType(patient.getIdElement().getValue()), myPatientId, NO_MATCH_RESULT, myRequestDetails);
fail(); fail();
} catch (InvalidRequestException e) { } catch (InvalidRequestException e) {
String expectedMessage = myMessageHelper.getMessageForUnmanagedResource(); String expectedMessage = myMessageHelper.getMessageForFailedGoldenResourceLoad("goldenResourceId", patient.getIdElement().getValue());
assertEquals(expectedMessage, e.getMessage()); assertEquals(expectedMessage, e.getMessage());
} }
} }

View File

@ -64,7 +64,12 @@ public class MdmControllerHelper {
public IAnyResource getLatestGoldenResourceFromIdOrThrowException(String theParamName, String theGoldenResourceId) { public IAnyResource getLatestGoldenResourceFromIdOrThrowException(String theParamName, String theGoldenResourceId) {
IdDt resourceId = MdmControllerUtil.getGoldenIdDtOrThrowException(theParamName, theGoldenResourceId); IdDt resourceId = MdmControllerUtil.getGoldenIdDtOrThrowException(theParamName, theGoldenResourceId);
return loadResource(resourceId.toUnqualifiedVersionless()); IAnyResource iAnyResource = loadResource(resourceId.toUnqualifiedVersionless());
if (MdmResourceUtil.isGoldenRecord(iAnyResource)) {
return iAnyResource;
} else {
throw new InvalidRequestException(myMessageHelper.getMessageForFailedGoldenResourceLoad(theParamName, theGoldenResourceId));
}
} }

View File

@ -57,7 +57,6 @@ public class MdmControllerUtil {
static IdDt getGoldenIdDtOrThrowException(String theParamName, String theId) { static IdDt getGoldenIdDtOrThrowException(String theParamName, String theId) {
IdDt goldenResourceId = new IdDt(theId); IdDt goldenResourceId = new IdDt(theId);
//TODO GGG MDM: maybe add a gate here to only consider resources that can possibly be EMPI'ed?
if (goldenResourceId.getIdPart() == null) { if (goldenResourceId.getIdPart() == null) {
throw new InvalidRequestException(theParamName + " is '" + theId + "'. must have form <resourceType>/<id> where <id> is the id of the resource"); throw new InvalidRequestException(theParamName + " is '" + theId + "'. must have form <resourceType>/<id> where <id> is the id of the resource");
} }

View File

@ -107,4 +107,8 @@ public class MessageHelper {
public String getMessageForMultipleGoldenRecords(String theSourceResource) { public String getMessageForMultipleGoldenRecords(String theSourceResource) {
return theSourceResource + " already has matched golden resource. Use $mdm-query-links to see more details."; return theSourceResource + " already has matched golden resource. Use $mdm-query-links to see more details.";
} }
public String getMessageForFailedGoldenResourceLoad(String theParamName, String theGoldenResourceId) {
return theGoldenResourceId + " used as parameter [" + theParamName + "] could not be loaded as a golden resource, as it appears to be lacking the golden resource meta tags.";
}
} }