From 5f152a7e78a4964f5397a8d649f8e7e88ec60689 Mon Sep 17 00:00:00 2001 From: "dotasek.dev" Date: Wed, 28 Feb 2024 14:54:20 -0500 Subject: [PATCH] Fix more tests --- .../VersionSpecificWorkerContextWrapper.java | 3 +- .../FhirInstanceValidatorDstu3Test.java | 34 ++++++++------ ...estionnaireResponseValidatorDstu3Test.java | 2 +- .../QuestionnaireValidatorDstu3Test.java | 2 +- .../FhirInstanceValidatorR4Test.java | 45 +++++++++++-------- pom.xml | 2 +- 6 files changed, 53 insertions(+), 35 deletions(-) diff --git a/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/validator/VersionSpecificWorkerContextWrapper.java b/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/validator/VersionSpecificWorkerContextWrapper.java index 7d1a34ae50d..5c3128fe42a 100644 --- a/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/validator/VersionSpecificWorkerContextWrapper.java +++ b/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/validator/VersionSpecificWorkerContextWrapper.java @@ -775,7 +775,8 @@ public class VersionSpecificWorkerContextWrapper extends I18nBase implements IWo .setDiagnostics(message) .setDetails(new CodeableConcept().setText(message)); - return new ValidationResult(ValidationMessage.IssueSeverity.ERROR, null, Collections.singletonList(issue)); + return new ValidationResult( + ValidationMessage.IssueSeverity.ERROR, null, Collections.singletonList(issue)); } ValidationResult retVal = validateCode(theOptions, next, theVs); if (retVal.isOk()) { diff --git a/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/FhirInstanceValidatorDstu3Test.java b/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/FhirInstanceValidatorDstu3Test.java index e19521e6fcd..283caeda32c 100644 --- a/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/FhirInstanceValidatorDstu3Test.java +++ b/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/FhirInstanceValidatorDstu3Test.java @@ -71,6 +71,7 @@ import org.mockito.stubbing.Answer; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; +import java.util.EnumSet; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -351,9 +352,9 @@ public class FhirInstanceValidatorDstu3Test extends BaseValidationTestWithInline ValidationResult result = val.validateWithResult(p); assertFalse(result.isSuccessful()); List all = logResultsAndReturnAll(result); - assertEquals(1, all.size()); + assertEquals(2, all.size()); assertEquals(ResultSeverityEnum.ERROR, all.get(0).getSeverity()); - assertEquals("Unknown code 'urn:iso:std:iso:3166#QQ' for 'urn:iso:std:iso:3166#QQ'", all.get(0).getMessage()); + assertEquals("Unknown code (for 'urn:iso:std:iso:3166#QQ')", all.get(0).getMessage()); } } @@ -516,6 +517,7 @@ public class FhirInstanceValidatorDstu3Test extends BaseValidationTestWithInline @Test public void testGoal() { + addValidConcept("http://foo", "some other goal"); Goal goal = new Goal(); goal.setSubject(new Reference("Patient/123")); goal.setDescription(new CodeableConcept().addCoding(new Coding("http://foo", "some other goal", ""))); @@ -778,9 +780,7 @@ public class FhirInstanceValidatorDstu3Test extends BaseValidationTestWithInline ValidationResult results = myVal.validateWithResult(is); List outcome = logResultsAndReturnNonInformationalOnes(results); assertEquals(1, outcome.size()); - assertEquals("Unknown code 'http://dicom.nema.org/resources/ontology/DCM#BAR' for 'http://dicom.nema.org/resources/ontology/DCM#BAR'", outcome.get(0).getMessage()); -// assertEquals("The Coding provided is not in the value set http://hl7.org/fhir/ValueSet/dicom-cid29, and a code should come from this value set unless it has no suitable code. (error message = Unknown code[BAR] in system[http://dicom.nema.org/resources/ontology/DCM])", outcome.get(1).getMessage()); - + assertThat(outcome.get(0).getMessage(), containsString("The Coding provided (http://dicom.nema.org/resources/ontology/DCM#BAR) was not found in the value set 'Acquisition Modality Codes' (http://hl7.org/fhir/ValueSet/dicom-cid29|20121129)") ); } /** @@ -1048,7 +1048,7 @@ public class FhirInstanceValidatorDstu3Test extends BaseValidationTestWithInline ValidationResult output = myVal.validateWithResult(input); List res = logResultsAndReturnNonInformationalOnes(output); assertEquals(1, res.size(), output.toString()); - assertEquals("A code with no system has no defined meaning, and it cannot be validated. A system should be provided", output.getMessages().get(0).getMessage()); + assertEquals("Coding has no system. A code with no system has no defined meaning, and it cannot be validated. A system should be provided", output.getMessages().get(0).getMessage()); } /** @@ -1137,7 +1137,7 @@ public class FhirInstanceValidatorDstu3Test extends BaseValidationTestWithInline List errors = logResultsAndReturnAll(output); assertEquals(ResultSeverityEnum.ERROR, errors.get(0).getSeverity()); - assertEquals("Unknown code for 'http://loinc.org#12345'", errors.get(0).getMessage()); + assertEquals("Unknown code (for 'http://loinc.org#12345')", errors.get(0).getMessage()); } @Test @@ -1233,6 +1233,8 @@ public class FhirInstanceValidatorDstu3Test extends BaseValidationTestWithInline @Test public void testValidateResourceWithExampleBindingCodeValidationFailing() { + addValidConcept("http://loinc.org", "12345"); + Observation input = createObservationWithDefaultSubjectPerfomerEffective(); myInstanceVal.setValidationSupport(myValidationSupport); @@ -1259,7 +1261,7 @@ public class FhirInstanceValidatorDstu3Test extends BaseValidationTestWithInline ValidationResult output = myVal.validateWithResult(input); List errors = logResultsAndReturnAll(output); assertThat(errors.toString(), errors.size(), greaterThan(0)); - assertEquals("Unknown code for 'http://acme.org#9988877'", errors.get(0).getMessage()); + assertEquals("Unknown code (for 'http://acme.org#9988877')", errors.get(0).getMessage()); } @@ -1295,7 +1297,7 @@ public class FhirInstanceValidatorDstu3Test extends BaseValidationTestWithInline ValidationResult output = myVal.validateWithResult(input); List errors = logResultsAndReturnNonInformationalOnes(output); assertEquals(1, errors.size()); - assertEquals("Unknown code for 'http://loinc.org#1234'", errors.get(0).getMessage()); + assertEquals("Unknown code (for 'http://loinc.org#1234')", errors.get(0).getMessage()); } @Test @@ -1321,12 +1323,14 @@ public class FhirInstanceValidatorDstu3Test extends BaseValidationTestWithInline ValidationResult output = myVal.validateWithResult(patient); List all = logResultsAndReturnAll(output); - assertEquals(1, all.size()); + assertEquals(2, all.size()); + assertThat(all.get(0).getMessage(), containsString("Unknown code (for 'http://example.com/foo/bar#bar')")); + assertEquals(ResultSeverityEnum.ERROR, all.get(0).getSeverity()); assertEquals("Patient.identifier[0].type", all.get(0).getLocationString()); assertThat( - all.get(0).getMessage(), + all.get(1).getMessage(), containsString("None of the codings provided are in the value set 'Identifier Type Codes'")); - assertEquals(ResultSeverityEnum.WARNING, all.get(0).getSeverity()); + assertEquals(ResultSeverityEnum.WARNING, all.get(1).getSeverity()); } @@ -1359,6 +1363,9 @@ public class FhirInstanceValidatorDstu3Test extends BaseValidationTestWithInline IValidationPolicyAdvisor policyAdvisor = mock(IValidationPolicyAdvisor.class); IValidatorResourceFetcher fetcher = mock(IValidatorResourceFetcher.class); + when(policyAdvisor.policyForElement(any(), any(),any(),any(),any())).thenReturn(EnumSet.allOf(IValidationPolicyAdvisor.ElementValidationAction.class)); + when(policyAdvisor.policyForCodedContent(any(),any(),any(),any(),any(),any(),any(),any(),any())).thenReturn(EnumSet.allOf(IValidationPolicyAdvisor.CodedContentValidationAction.class)); + when(policyAdvisor.policyForReference(any(), any(), any(), any())).thenReturn(ReferenceValidationPolicy.CHECK_TYPE_IF_EXISTS); when(policyAdvisor.policyForReference(any(), any(), any(), any())).thenReturn(ReferenceValidationPolicy.CHECK_TYPE_IF_EXISTS); @@ -1373,8 +1380,9 @@ public class FhirInstanceValidatorDstu3Test extends BaseValidationTestWithInline @Test public void testValueWithWhitespace() throws IOException { - String input = IOUtils.toString(FhirInstanceValidatorDstu3Test.class.getResourceAsStream("/dstu3-rick-test.json"), Charsets.UTF_8); + addValidConcept("http://loinc.org", "34133-1"); + String input = IOUtils.toString(FhirInstanceValidatorDstu3Test.class.getResourceAsStream("/dstu3-rick-test.json"), Charsets.UTF_8); ValidationResult results = myVal.validateWithResult(input); List outcome = logResultsAndReturnNonInformationalOnes(results); assertEquals(2, outcome.size()); diff --git a/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/QuestionnaireResponseValidatorDstu3Test.java b/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/QuestionnaireResponseValidatorDstu3Test.java index 39866ef6bfc..0ca42311adc 100644 --- a/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/QuestionnaireResponseValidatorDstu3Test.java +++ b/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/QuestionnaireResponseValidatorDstu3Test.java @@ -278,7 +278,7 @@ public class QuestionnaireResponseValidatorDstu3Test { errors = myVal.validateWithResult(qa); errors = stripBindingHasNoSourceMessage(errors); ourLog.info(errors.toString()); - assertThat(errors.toString(), containsString("Unknown code: http://codesystems.com/system / code1 for 'http://codesystems.com/system#code1'")); + assertThat(errors.toString(), containsString("Unknown code: http://codesystems.com/system / code1 (for 'http://codesystems.com/system#code1')")); assertThat(errors.toString(), containsString("QuestionnaireResponse.item[0].answer[0]")); // Unhandled system diff --git a/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/QuestionnaireValidatorDstu3Test.java b/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/QuestionnaireValidatorDstu3Test.java index cc947941185..6b9774a3d85 100644 --- a/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/QuestionnaireValidatorDstu3Test.java +++ b/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/QuestionnaireValidatorDstu3Test.java @@ -119,7 +119,7 @@ public class QuestionnaireValidatorDstu3Test extends BaseValidationTestWithInlin ValidationResult errors = myVal.validateWithResult(q); ourLog.info(errors.toString()); assertThat(errors.isSuccessful(), Matchers.is(true)); - assertThat(errors.getMessages().get(0).getMessage(), containsString("and a coding should come from this value set unless it has no suitable code (note that the validator cannot judge what is suitable) (codes = null#text-box)")); + assertThat(errors.getMessages().get(1).getMessage(), containsString("and a coding should come from this value set unless it has no suitable code (note that the validator cannot judge what is suitable) (codes = null#text-box)")); } } diff --git a/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/FhirInstanceValidatorR4Test.java b/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/FhirInstanceValidatorR4Test.java index 22e6dd7c01d..22d4c3e80cd 100644 --- a/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/FhirInstanceValidatorR4Test.java +++ b/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/FhirInstanceValidatorR4Test.java @@ -377,7 +377,7 @@ public class FhirInstanceValidatorR4Test extends BaseValidationTestWithInlineMoc ValidationResult result = val.validateWithResult(input); List all = logResultsAndReturnErrorOnes(result); assertFalse(result.isSuccessful(), all.toString()); - assertThat(result.getMessages().get(0).getMessage(), startsWith("Unknown code 'https://hapifhir.io/fhir/CodeSystem/hapi-fhir-storage-response-code#foo'")); + assertThat(result.getMessages().get(0).getMessage(), startsWith("Unknown code (for 'https://hapifhir.io/fhir/CodeSystem/hapi-fhir-storage-response-code#foo')")); } @@ -396,7 +396,7 @@ public class FhirInstanceValidatorR4Test extends BaseValidationTestWithInlineMoc ValidationResult result = val.validateWithResult(p); List all = logResultsAndReturnErrorOnes(result); assertFalse(result.isSuccessful()); - assertEquals("The code 'AA ' is not valid (whitespace rules)", all.get(0).getMessage()); + assertEquals("The code 'AA ' is not valid (whitespace rules)", all.get(1).getMessage()); } @@ -518,6 +518,8 @@ public class FhirInstanceValidatorR4Test extends BaseValidationTestWithInlineMoc */ @Test public void testValidateDoesntEnforceBestPracticesByDefault() { + addValidConcept("http://loinc.org", "1234"); + Observation input = new Observation(); input.addPerformer(new Reference("Practitioner/124")); input.setEffective(new DateTimeType("2023-01-01T11:22:33Z")); @@ -708,10 +710,11 @@ public class FhirInstanceValidatorR4Test extends BaseValidationTestWithInlineMoc public void testLargeBase64() throws IOException { String input = IOUtils.toString(FhirInstanceValidatorR4Test.class.getResourceAsStream("/r4/diagnosticreport-example-gingival-mass.json"), Constants.CHARSET_UTF8); ValidationResult output = myFhirValidator.validateWithResult(input); - List errors = logResultsAndReturnAll(output); - assertEquals(2, errors.size()); - assertThat(errors.get(0).getMessage(), containsString("None of the codings provided are in the value set 'LOINC Diagnostic Report Codes'")); - assertEquals("Base64 encoded values SHOULD not contain any whitespace (per RFC 4648). Note that non-validating readers are encouraged to accept whitespace anyway", errors.get(1).getMessage()); + List messages = logResultsAndReturnAll(output); + assertEquals(3, messages.size()); + assertThat(messages.get(0).getMessage(), containsString("Unknown code (for 'http://loinc.org#1-8')")); + assertThat(messages.get(1).getMessage(), containsString("None of the codings provided are in the value set 'LOINC Diagnostic Report Codes'")); + assertEquals("Base64 encoded values SHOULD not contain any whitespace (per RFC 4648). Note that non-validating readers are encouraged to accept whitespace anyway", messages.get(2).getMessage()); } @Test @@ -1112,7 +1115,7 @@ public class FhirInstanceValidatorR4Test extends BaseValidationTestWithInlineMoc ValidationResult output = myFhirValidator.validateWithResult(input); List res = logResultsAndReturnNonInformationalOnes(output); assertEquals(1, res.size(), output.toString()); - assertEquals("A code with no system has no defined meaning, and it cannot be validated. A system should be provided", output.getMessages().get(0).getMessage()); + assertEquals("Coding has no system. A code with no system has no defined meaning, and it cannot be validated. A system should be provided", output.getMessages().get(0).getMessage()); } /** @@ -1203,7 +1206,7 @@ public class FhirInstanceValidatorR4Test extends BaseValidationTestWithInlineMoc List errors = logResultsAndReturnAll(output); assertEquals(ResultSeverityEnum.ERROR, errors.get(0).getSeverity()); - assertEquals("Unknown code for 'http://loinc.org#12345'", errors.get(0).getMessage()); + assertEquals("Unknown code (for 'http://loinc.org#12345')", errors.get(0).getMessage()); } @Test @@ -1330,6 +1333,7 @@ public class FhirInstanceValidatorR4Test extends BaseValidationTestWithInlineMoc @Test public void testValidateResourceWithExampleBindingCodeValidationFailing() { + addValidConcept("http://loinc.org", "12345"); Observation input = createObservationWithDefaultSubjectPerfomerEffective(); input.getText().setDiv(new XhtmlNode().setValue("
AA
")).setStatus(Narrative.NarrativeStatus.GENERATED); @@ -1400,7 +1404,7 @@ public class FhirInstanceValidatorR4Test extends BaseValidationTestWithInlineMoc ValidationResult output = myFhirValidator.validateWithResult(input); List errors = logResultsAndReturnAll(output); assertThat(errors.toString(), errors.size(), greaterThan(0)); - assertEquals("Unknown code for 'http://acme.org#9988877'", errors.get(0).getMessage()); + assertEquals("Unknown code (for 'http://acme.org#9988877')", errors.get(0).getMessage()); } @@ -1439,7 +1443,7 @@ public class FhirInstanceValidatorR4Test extends BaseValidationTestWithInlineMoc ValidationResult output = myFhirValidator.validateWithResult(input); List errors = logResultsAndReturnNonInformationalOnes(output); assertEquals(1, errors.size()); - assertEquals("Unknown code for 'http://loinc.org#1234'", errors.get(0).getMessage()); + assertEquals("Unknown code (for 'http://loinc.org#1234')", errors.get(0).getMessage()); } @Test @@ -1467,10 +1471,13 @@ public class FhirInstanceValidatorR4Test extends BaseValidationTestWithInlineMoc ValidationResult output = myFhirValidator.validateWithResult(p); List all = logResultsAndReturnAll(output); - assertEquals(1, all.size()); - assertEquals("Patient.identifier[0].type", all.get(0).getLocationString()); - assertThat(all.get(0).getMessage(), containsString("None of the codings provided are in the value set 'IdentifierType'")); - assertEquals(ResultSeverityEnum.WARNING, all.get(0).getSeverity()); + assertEquals(2, all.size()); + + assertThat(all.get(0).getMessage(), containsString("Unknown code (for 'http://example.com/foo/bar#bar')")); + assertEquals(ResultSeverityEnum.ERROR, all.get(0).getSeverity()); + + assertThat(all.get(1).getMessage(), containsString("None of the codings provided are in the value set 'IdentifierType'")); + assertEquals(ResultSeverityEnum.WARNING, all.get(1).getSeverity()); } @@ -1731,6 +1738,8 @@ public class FhirInstanceValidatorR4Test extends BaseValidationTestWithInlineMoc @Test void testValidateCommonCodes_Currency_ErrorMessageIsPreserved() { + addValidConcept("http://loinc.org", "1234"); + buildValidationSupportWithLogicalAndSupport(false); Observation input = createObservationWithDefaultSubjectPerfomerEffective(); @@ -1752,10 +1761,10 @@ public class FhirInstanceValidatorR4Test extends BaseValidationTestWithInlineMoc OperationOutcome oo = (OperationOutcome) result.toOperationOutcome(); ourLog.info(ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(oo)); - assertEquals("Unknown code 'urn:iso:std:iso:4217#blah' (for 'urn:iso:std:iso:4217#blah')", result.getMessages().get(0).getMessage()); - assertEquals(ResultSeverityEnum.ERROR, result.getMessages().get(0).getSeverity()); - assertEquals(22, result.getMessages().get(0).getLocationLine()); - assertEquals(4, result.getMessages().get(0).getLocationCol()); + assertEquals("Unknown code 'urn:iso:std:iso:4217#blah' (for 'urn:iso:std:iso:4217#blah')", result.getMessages().get(1).getMessage()); + assertEquals(ResultSeverityEnum.ERROR, result.getMessages().get(1).getSeverity()); + assertEquals(22, result.getMessages().get(1).getLocationLine()); + assertEquals(4, result.getMessages().get(1).getLocationCol()); assertEquals("Observation.value.ofType(Quantity)", result.getMessages().get(0).getLocationString()); assertEquals("Terminology_PassThrough_TX_Message", result.getMessages().get(0).getMessageId()); diff --git a/pom.xml b/pom.xml index e945ec6401e..b7988cd4830 100644 --- a/pom.xml +++ b/pom.xml @@ -910,7 +910,7 @@ - 6.2.16-SNAPSHOT + 6.3.1-SNAPSHOT 2.41.1 -Dfile.encoding=UTF-8 -Xmx2048m