Skip to content

Commit

Permalink
Fixes the error 'duplicate namespace' attempting to translate in an I… (
Browse files Browse the repository at this point in the history
#80)

Fixes the error 'duplicate namespace' attempting to translate in an IG context

Co-authored-by: Jonathan Percival <[email protected]>
  • Loading branch information
brynrhodes and JPercival authored Sep 30, 2024
1 parent ced7612 commit f4ad843
Showing 1 changed file with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import java.io.InputStream;
import java.net.URI;
import java.util.HashSet;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.cqframework.cql.cql2elm.LibraryManager;
import org.cqframework.fhir.npm.ILibraryReader;
Expand All @@ -15,7 +17,6 @@
import org.eclipse.lsp4j.FileEvent;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.hl7.cql.model.NamespaceInfo;
import org.opencds.cqf.cql.ls.core.ContentService;
import org.opencds.cqf.cql.ls.core.utility.Uris;
import org.opencds.cqf.cql.ls.server.event.DidChangeWatchedFilesEvent;
Expand Down Expand Up @@ -69,8 +70,20 @@ public synchronized void setupLibraryManager(URI uri, LibraryManager libraryMana
.getModelInfoLoader()
.registerModelInfoProvider(new NpmModelInfoProvider(
npmProcessor.getPackageManager().getNpmList(), reader, adapter));
for (NamespaceInfo ni : npmProcessor.getNamespaces()) {
namespaceManager.ensureNamespaceRegistered(ni);

// 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
// NOTE: This logic is also used in org.opencds.cqf.fhir.cql.Engines.buildEnvironment()
Set<String> keys = new HashSet<String>();
Set<String> uris = new HashSet<String>();
for (var n : npmProcessor.getNamespaces()) {
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 f4ad843

Please sign in to comment.