diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_4_0/5925-resole-unsupportedoperationexception-validating-mhd.yaml b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_4_0/5925-resole-unsupportedoperationexception-validating-mhd.yaml new file mode 100644 index 00000000000..f19fba74278 --- /dev/null +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_4_0/5925-resole-unsupportedoperationexception-validating-mhd.yaml @@ -0,0 +1,5 @@ +--- +type: fix +issue: 5925 +title: "An UnsupportedOperationException occurred when validating R5 MHD bundles using + the HAPI FHIR validator. Thanks to Renaud Subiger for contributing a fix!" 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 340dcfc775c..0dc166c0c8e 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 @@ -322,7 +322,8 @@ public class VersionSpecificWorkerContextWrapper extends I18nBase implements IWo org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionBindingComponent binding, boolean cacheOk, boolean Hierarchical) { - throw new UnsupportedOperationException(Msg.code(663)); + ValueSet valueSet = fetchResource(ValueSet.class, binding.getValueSet(), src); + return expandVS(valueSet, cacheOk, Hierarchical); } @Override diff --git a/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/NpmPackageValidationSupportTest.java b/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/NpmPackageValidationSupportTest.java index 9549e2ad2ad..0afad0fee73 100644 --- a/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/NpmPackageValidationSupportTest.java +++ b/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/NpmPackageValidationSupportTest.java @@ -24,6 +24,7 @@ import java.util.Map; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class NpmPackageValidationSupportTest extends BaseValidationTestWithInlineMocks { @@ -89,4 +90,32 @@ public class NpmPackageValidationSupportTest extends BaseValidationTestWithInlin assertArrayEquals(expectedBytes, actualBytes); } } + + @Test + public void testValidateIheMhdPackage() throws IOException { + ValidationSupportChain validationSupportChain = new ValidationSupportChain(); + validationSupportChain.addValidationSupport(getNpmPackageValidationSupport("classpath:package/ihe.iti.mhd.tgz")); + validationSupportChain.addValidationSupport(new DefaultProfileValidationSupport(myFhirContext)); + validationSupportChain.addValidationSupport(new CommonCodeSystemsTerminologyService(myFhirContext)); + validationSupportChain.addValidationSupport(new InMemoryTerminologyServerValidationSupport(myFhirContext)); + validationSupportChain.addValidationSupport(new SnapshotGeneratingValidationSupport(myFhirContext)); + + CachingValidationSupport validationSupport = new CachingValidationSupport(validationSupportChain); + + FhirValidator validator = myFhirContext.newValidator(); + FhirInstanceValidator instanceValidator = new FhirInstanceValidator(validationSupport); + validator.registerValidatorModule(instanceValidator); + + String bundle = loadResource("/r4/mhd_minimal_provide_document_bundle.json"); + ValidationResult validationResult = validator.validateWithResult(bundle); + + assertEquals(1, validationResult.getMessages().size()); + + String outcomeSerialized = myFhirContext.newJsonParser() + .setPrettyPrint(true) + .encodeResourceToString(validationResult.toOperationOutcome()); + ourLog.info(outcomeSerialized); + + assertThat(outcomeSerialized, containsString("Terminology_TX_ValueSet_NotFound")); + } } diff --git a/hapi-fhir-validation/src/test/resources/package/ihe.iti.mhd.tgz b/hapi-fhir-validation/src/test/resources/package/ihe.iti.mhd.tgz new file mode 100644 index 00000000000..5e3d6cc6b61 Binary files /dev/null and b/hapi-fhir-validation/src/test/resources/package/ihe.iti.mhd.tgz differ diff --git a/hapi-fhir-validation/src/test/resources/r4/mhd_minimal_provide_document_bundle.json b/hapi-fhir-validation/src/test/resources/r4/mhd_minimal_provide_document_bundle.json new file mode 100644 index 00000000000..0663757c515 --- /dev/null +++ b/hapi-fhir-validation/src/test/resources/r4/mhd_minimal_provide_document_bundle.json @@ -0,0 +1,190 @@ +{ + "resourceType": "Bundle", + "meta": { + "profile": [ + "https://profiles.ihe.net/ITI/MHD/StructureDefinition/IHE.MHD.Minimal.ProvideBundle" + ], + "security": [ + { + "system": "http://terminology.hl7.org/CodeSystem/v3-ActReason", + "code": "HTEST" + } + ] + }, + "type": "transaction", + "timestamp": "2024-05-11T14:16:19.224Z", + "entry": [ + { + "fullUrl": "urn:uuid:9649cc3d-eb0b-407b-b1ba-61c4eef4dba3", + "resource": { + "resourceType": "List", + "id": "9649cc3d-eb0b-407b-b1ba-61c4eef4dba3", + "meta": { + "profile": [ + "https://profiles.ihe.net/ITI/MHD/StructureDefinition/IHE.MHD.Minimal.SubmissionSet" + ], + "security": [ + { + "system": "http://terminology.hl7.org/CodeSystem/v3-ActReason", + "code": "HTEST" + } + ] + }, + "text": { + "status": "extensions", + "div": "