Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Push NPM upstream #1190

Merged
merged 2 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}