Skip to content

Commit

Permalink
Push NPM upstream (#1190)
Browse files Browse the repository at this point in the history
  • Loading branch information
JPercival authored Aug 18, 2023
1 parent a3787c0 commit 843f17f
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 1 deletion.
1 change: 1 addition & 0 deletions Src/java/cqf-fhir-npm/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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<NamespaceInfo> getNamespaces() {
List<NamespaceInfo> namespaceInfos = new ArrayList<>();
if (packageManager != null) {
List<NpmPackage> 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;
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}

0 comments on commit 843f17f

Please sign in to comment.