-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
92 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
Src/java/cqf-fhir-npm/src/main/java/org/cqframework/fhir/npm/NpmProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
Src/java/cqf-fhir/src/main/java/org/cqframework/fhir/utilities/LoggerAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |