From 22c701077b9a6621d636a4a001fd1c9c48bad637 Mon Sep 17 00:00:00 2001 From: Bryn Rhodes Date: Tue, 30 Jun 2020 21:02:52 -0600 Subject: [PATCH] #539: Fixed an issue with the FHIR library source provider incorrectly setting namespace of non-FHIR libraries --- .../cql2elm/FhirLibrarySourceProvider.java | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/FhirLibrarySourceProvider.java b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/FhirLibrarySourceProvider.java index 4f8367b92..6d5b861e0 100644 --- a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/FhirLibrarySourceProvider.java +++ b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/FhirLibrarySourceProvider.java @@ -15,20 +15,24 @@ public class FhirLibrarySourceProvider implements LibrarySourceProvider, Namespa @Override public InputStream getLibrarySource(VersionedIdentifier libraryIdentifier) { - // If the FHIRHelpers library is referenced in a namespace-enabled context, - // set the namespace to the FHIR namespace URI - if (namespaceManager != null && namespaceManager.hasNamespaces()) { - // If the context already has a namespace registered for FHIR, use that. - NamespaceInfo namespaceInfo = namespaceManager.getNamespaceInfoFromUri(namespaceUri); - if (namespaceInfo == null) { - namespaceInfo = new NamespaceInfo(namespaceName, namespaceUri); - namespaceManager.ensureNamespaceRegistered(namespaceInfo); + InputStream result = FhirLibrarySourceProvider.class.getResourceAsStream(String.format("/org/hl7/fhir/%s-%s.cql", libraryIdentifier.getId(), + libraryIdentifier.getVersion())); + + if (result != null) { + // If the FHIRHelpers library is referenced in a namespace-enabled context, + // set the namespace to the FHIR namespace URI + if (namespaceManager != null && namespaceManager.hasNamespaces()) { + // If the context already has a namespace registered for FHIR, use that. + NamespaceInfo namespaceInfo = namespaceManager.getNamespaceInfoFromUri(namespaceUri); + if (namespaceInfo == null) { + namespaceInfo = new NamespaceInfo(namespaceName, namespaceUri); + namespaceManager.ensureNamespaceRegistered(namespaceInfo); + } + libraryIdentifier.setSystem(namespaceUri); } - libraryIdentifier.setSystem(namespaceUri); } - return FhirLibrarySourceProvider.class.getResourceAsStream(String.format("/org/hl7/fhir/%s-%s.cql", libraryIdentifier.getId(), - libraryIdentifier.getVersion())); + return result; } private NamespaceManager namespaceManager;