diff --git a/Src/java/cqf-fhir-npm/build.gradle b/Src/java/cqf-fhir-npm/build.gradle index 52e084226..15308a7d1 100644 --- a/Src/java/cqf-fhir-npm/build.gradle +++ b/Src/java/cqf-fhir-npm/build.gradle @@ -4,6 +4,7 @@ plugins { dependencies { implementation project(':cql-to-elm') + implementation project(':cqf-fhir') implementation 'com.google.code.gson:gson:2.9.1' implementation 'org.apache.commons:commons-compress:1.20' implementation 'org.eclipse.persistence:org.eclipse.persistence.moxy:2.7.7' diff --git a/Src/java/cqf-fhir-npm/src/main/java/org/cqframework/fhir/npm/NpmPackageManager.java b/Src/java/cqf-fhir-npm/src/main/java/org/cqframework/fhir/npm/NpmPackageManager.java index ac7934392..96fcadb29 100644 --- a/Src/java/cqf-fhir-npm/src/main/java/org/cqframework/fhir/npm/NpmPackageManager.java +++ b/Src/java/cqf-fhir-npm/src/main/java/org/cqframework/fhir/npm/NpmPackageManager.java @@ -6,7 +6,6 @@ import org.hl7.fhir.utilities.VersionUtilities; import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager; import org.hl7.fhir.utilities.npm.NpmPackage; -import org.hl7.fhir.utilities.npm.ToolsVersion; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/Src/java/cqf-fhir-npm/src/main/java/org/cqframework/fhir/npm/NpmProcessor.java b/Src/java/cqf-fhir-npm/src/main/java/org/cqframework/fhir/npm/NpmProcessor.java new file mode 100644 index 000000000..edbe61e6b --- /dev/null +++ b/Src/java/cqf-fhir-npm/src/main/java/org/cqframework/fhir/npm/NpmProcessor.java @@ -0,0 +1,64 @@ +package org.cqframework.fhir.npm; + +import java.util.ArrayList; +import java.util.List; + +import org.cqframework.fhir.utilities.IGContext; +import org.hl7.cql.model.NamespaceInfo; +import org.hl7.fhir.utilities.npm.NpmPackage; + +public class NpmProcessor { + /** + * Provides access to the Npm package manager. Note that this will be throw an exception in the + * case that there is no ig context. + */ + private NpmPackageManager packageManager; + + public NpmPackageManager getPackageManager() { + if (this.packageManager == null) { + throw new IllegalStateException("Package manager is not available outside of an ig context"); + } + return this.packageManager; + } + + /** + * The igContext for the npmProcessor (i.e. the root IG that defines dependencies accessible in + * the context) Note that this may be null in the case that there is no IG context + */ + private IGContext igContext; + + public IGContext getIgContext() { + return this.igContext; + } + + // @Inject + public NpmProcessor(IGContext igContext) { + this.igContext = igContext; + if (igContext != null) { + packageManager = new NpmPackageManager(igContext.getSourceIg()); + } + } + + public NamespaceInfo getIgNamespace() { + if (igContext != null) { + return new NamespaceInfo(igContext.getPackageId(), igContext.getCanonicalBase()); + } + + return null; + } + + public List getNamespaces() { + List namespaceInfos = new ArrayList<>(); + if (packageManager != null) { + List packages = packageManager.getNpmList(); + for (NpmPackage p : packages) { + if (p.name() != null && !p.name().isEmpty() && p.canonical() != null + && !p.canonical().isEmpty()) { + NamespaceInfo ni = new NamespaceInfo(p.name(), p.canonical()); + namespaceInfos.add(ni); + } + } + } + return namespaceInfos; + } +} diff --git a/Src/java/cqf-fhir/src/main/java/org/cqframework/fhir/utilities/LoggerAdapter.java b/Src/java/cqf-fhir/src/main/java/org/cqframework/fhir/utilities/LoggerAdapter.java new file mode 100644 index 000000000..f14e74a3e --- /dev/null +++ b/Src/java/cqf-fhir/src/main/java/org/cqframework/fhir/utilities/LoggerAdapter.java @@ -0,0 +1,27 @@ +package org.cqframework.fhir.utilities; + +import org.hl7.fhir.r5.context.IWorkerContext; +import org.slf4j.Logger; + +public class LoggerAdapter implements IWorkerContext.ILoggingService { + private Logger innerLogger; + + public LoggerAdapter(Logger innerLogger) { + this.innerLogger = innerLogger; + } + + @Override + public void logMessage(String s) { + innerLogger.info(s); + } + + @Override + public void logDebugMessage(LogCategory logCategory, String s) { + innerLogger.debug("{}: {}", logCategory, s); + } + + @Override + public boolean isDebugLogging() { + return this.innerLogger.isDebugEnabled(); + } +}