Skip to content

Commit

Permalink
Fixes the error "namespace x is already loaded" (#523)
Browse files Browse the repository at this point in the history
* Fixes the error "namespace x is already loaded"

* Fix formatting

---------

Co-authored-by: Jonathan Percival <[email protected]>
Co-authored-by: JP <[email protected]>
  • Loading branch information
3 people authored Sep 27, 2024
1 parent 6e14c44 commit 47e7140
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion cqf-fhir-cql/src/main/java/org/opencds/cqf/fhir/cql/Engines.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import ca.uhn.fhir.context.FhirContext;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.cqframework.cql.cql2elm.LibraryManager;
import org.cqframework.cql.cql2elm.LibrarySourceProvider;
import org.cqframework.cql.cql2elm.ModelManager;
Expand Down Expand Up @@ -145,8 +147,18 @@ private static Environment buildEnvironment(
libraryManager.getLibrarySourceLoader().clearProviders();

if (npmProcessor != null) {
// TODO: This is a workaround for: a) multiple packages with the same package id will be in the dependency
// list, and b) there are packages with different package ids but the same base canonical (e.g.
// fhir.r4.examples has the same base canonical as fhir.r4)
// NOTE: Using ensureNamespaceRegistered works around a but not b
Set<String> keys = new HashSet<String>();
Set<String> uris = new HashSet<String>();
for (var n : npmProcessor.getNamespaces()) {
libraryManager.getNamespaceManager().addNamespace(n);
if (!keys.contains(n.getName()) && !uris.contains(n.getUri())) {
libraryManager.getNamespaceManager().addNamespace(n);
keys.add(n.getName());
uris.add(n.getUri());
}
}
}

Expand Down

0 comments on commit 47e7140

Please sign in to comment.