From 511696bd84876dba6a9143aa0b78cc2919b9a84a Mon Sep 17 00:00:00 2001 From: Tadgh Date: Mon, 16 Nov 2020 19:11:19 -0500 Subject: [PATCH] Fix validator error messages --- .../empi/rules/config/EmpiRuleValidator.java | 3 +++ .../rules/config/EmpiRuleValidatorTest.java | 22 +++++++++++++++++++ .../svc/EmpiResourceFieldMatcherR4Test.java | 2 +- .../bad-rules-missing-mdm-types.json | 2 +- 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/hapi-fhir-server-empi/src/main/java/ca/uhn/fhir/empi/rules/config/EmpiRuleValidator.java b/hapi-fhir-server-empi/src/main/java/ca/uhn/fhir/empi/rules/config/EmpiRuleValidator.java index 00665307a16..658d420be77 100644 --- a/hapi-fhir-server-empi/src/main/java/ca/uhn/fhir/empi/rules/config/EmpiRuleValidator.java +++ b/hapi-fhir-server-empi/src/main/java/ca/uhn/fhir/empi/rules/config/EmpiRuleValidator.java @@ -72,6 +72,9 @@ public class EmpiRuleValidator implements IEmpiRuleValidator { } public void validateMdmTypes(EmpiRulesJson theEmpiRulesJson) { + if (theEmpiRulesJson.getMdmTypes() == null) { + throw new ConfigurationException("mdmTypes must be set to a list of resource types."); + } for (String resourceType: theEmpiRulesJson.getMdmTypes()) { validateTypeHasIdentifier(resourceType); } diff --git a/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/rules/config/EmpiRuleValidatorTest.java b/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/rules/config/EmpiRuleValidatorTest.java index 9c5ab997cdd..3a45718972b 100644 --- a/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/rules/config/EmpiRuleValidatorTest.java +++ b/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/rules/config/EmpiRuleValidatorTest.java @@ -1,9 +1,11 @@ package ca.uhn.fhir.empi.rules.config; import ca.uhn.fhir.context.ConfigurationException; +import ca.uhn.fhir.context.RuntimeSearchParam; import ca.uhn.fhir.empi.BaseR4Test; import com.google.common.base.Charsets; import org.apache.commons.io.IOUtils; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.Resource; @@ -14,8 +16,18 @@ import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.startsWith; import static org.junit.jupiter.api.Assertions.fail; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; public class EmpiRuleValidatorTest extends BaseR4Test { + + @BeforeEach + public void before() { + when(mySearchParamRetriever.getActiveSearchParam("Patient", "identifier")).thenReturn(mock(RuntimeSearchParam.class)); + when(mySearchParamRetriever.getActiveSearchParam("Practitioner", "identifier")).thenReturn(mock(RuntimeSearchParam.class)); + when(mySearchParamRetriever.getActiveSearchParam("Medication", "identifier")).thenReturn(mock(RuntimeSearchParam.class)); + when(mySearchParamRetriever.getActiveSearchParam("AllergyIntolerance", "identifier")).thenReturn(null); + } @Test public void testValidate() throws IOException { try { @@ -76,6 +88,16 @@ public class EmpiRuleValidatorTest extends BaseR4Test { } } + @Test + public void testInvalidMdmType() throws IOException { + try { + setEmpiRuleJson("bad-rules-missing-mdm-types.json"); + fail(); + } catch (ConfigurationException e) { + assertThat(e.getMessage(), startsWith("mdmTypes must be set to a list of resource types.")); + } + } + @Test public void testMatcherduplicateName() throws IOException { try { diff --git a/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/rules/svc/EmpiResourceFieldMatcherR4Test.java b/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/rules/svc/EmpiResourceFieldMatcherR4Test.java index 8de175a3e91..fc1eb0e084a 100644 --- a/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/rules/svc/EmpiResourceFieldMatcherR4Test.java +++ b/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/rules/svc/EmpiResourceFieldMatcherR4Test.java @@ -31,7 +31,7 @@ public class EmpiResourceFieldMatcherR4Test extends BaseEmpiRulesR4Test { super.before(); ArrayList myLegalMdmTypes = new ArrayList<>(); - myLegalMdmTypes.add("Patient"); + //myLegalMdmTypes.add("Patient"); myEmpiRulesJson.setMdmTypes(myLegalMdmTypes); myComparator = new EmpiResourceFieldMatcher(ourFhirContext, myGivenNameMatchField, myEmpiRulesJson); myJohn = buildJohn(); diff --git a/hapi-fhir-server-empi/src/test/resources/bad-rules-missing-mdm-types.json b/hapi-fhir-server-empi/src/test/resources/bad-rules-missing-mdm-types.json index 822b4303b40..0096784b26f 100644 --- a/hapi-fhir-server-empi/src/test/resources/bad-rules-missing-mdm-types.json +++ b/hapi-fhir-server-empi/src/test/resources/bad-rules-missing-mdm-types.json @@ -8,7 +8,7 @@ "resourcePath" : "name.given", "similarity" : { "algorithm": "COSINE", - "threshold": 0.8 + "matchThreshold": 0.8 } }], "matchResultMap" : {