diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/BaseWorkerContext.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/BaseWorkerContext.java index 93f3d350a..c7ea92444 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/BaseWorkerContext.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/BaseWorkerContext.java @@ -53,6 +53,7 @@ import org.hl7.fhir.exceptions.NoTerminologyServiceException; import org.hl7.fhir.exceptions.TerminologyServiceException; import org.hl7.fhir.r5.conformance.ProfileUtilities; import org.hl7.fhir.r5.context.CanonicalResourceManager.CanonicalResourceProxy; +import org.hl7.fhir.r5.context.IWorkerContext.PackageVersion; import org.hl7.fhir.r5.context.IWorkerContext.ILoggingService.LogCategory; import org.hl7.fhir.r5.context.TerminologyCache.CacheToken; import org.hl7.fhir.r5.model.BooleanType; @@ -159,7 +160,7 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte } private Object lock = new Object(); // used as a lock for the data that follows - protected String version; + protected String version; // although the internal resources are all R5, the version of FHIR they describe may not be private String cacheId; private boolean isTxCaching; private Set cached = new HashSet<>(); @@ -266,10 +267,7 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte } } - public void cachePackage(PackageVersion packageDetails, List dependencies) { - // nothing yet - } - + public void cacheResource(Resource r) throws FHIRException { cacheResourceFromPackage(r, null); } @@ -1317,6 +1315,65 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte } } + public PackageVersion getPackageForUrl(String uri) { + if (uri == null) { + return null; + } + uri = ProfileUtilities.sdNs(uri, getOverrideVersionNs()); + + synchronized (lock) { + + String version = null; + if (uri.contains("|")) { + version = uri.substring(uri.lastIndexOf("|")+1); + uri = uri.substring(0, uri.lastIndexOf("|")); + } + if (uri.contains("#")) { + uri = uri.substring(0, uri.indexOf("#")); + } + if (structures.has(uri)) { + return structures.getPackageInfo(uri, version); + } + if (guides.has(uri)) { + return guides.getPackageInfo(uri, version); + } + if (capstmts.has(uri)) { + return capstmts.getPackageInfo(uri, version); + } + if (measures.has(uri)) { + return measures.getPackageInfo(uri, version); + } + if (libraries.has(uri)) { + return libraries.getPackageInfo(uri, version); + } + if (valueSets.has(uri)) { + return valueSets.getPackageInfo(uri, version); + } + if (codeSystems.has(uri)) { + return codeSystems.getPackageInfo(uri, version); + } + if (operations.has(uri)) { + return operations.getPackageInfo(uri, version); + } + if (searchParameters.has(uri)) { + return searchParameters.getPackageInfo(uri, version); + } + if (plans.has(uri)) { + return plans.getPackageInfo(uri, version); + } + if (maps.has(uri)) { + return maps.getPackageInfo(uri, version); + } + if (transforms.has(uri)) { + return transforms.getPackageInfo(uri, version); + } + if (questionnaires.has(uri)) { + return questionnaires.getPackageInfo(uri, version); + } + return null; + } + } + @SuppressWarnings("unchecked") public T fetchResourceWithException(String cls, String uri, CanonicalResource source) throws FHIRException { if (uri == null) { diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/CanonicalResourceManager.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/CanonicalResourceManager.java index efa9d4619..73b60a05e 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/CanonicalResourceManager.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/CanonicalResourceManager.java @@ -292,6 +292,20 @@ public class CanonicalResourceManager { return map.containsKey(url) ? map.get(url).getResource() : null; } + public PackageVersion getPackageInfo(String system, String version) { + if (version == null) { + return map.containsKey(system) ? map.get(system).getPackageInfo() : null; + } else { + if (map.containsKey(system+"|"+version)) + return map.get(system+"|"+version).getPackageInfo(); + String mm = VersionUtilities.getMajMin(version); + if (mm != null && map.containsKey(system+"|"+mm)) + return map.get(system+"|"+mm).getPackageInfo(); + else + return null; + } + } + public boolean has(String url) { return map.containsKey(url); } diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/IWorkerContext.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/IWorkerContext.java index 5155a60a0..fd3b1c84e 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/IWorkerContext.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/IWorkerContext.java @@ -170,6 +170,27 @@ public interface IWorkerContext { } } + public class PackageDetails extends PackageVersion { + private String name; + private String canonical; + private String web; + public PackageDetails(String id, String version, String name, String canonical, String web) { + super(id, version); + this.name = name; + this.canonical = canonical; + this.web = web; + } + public String getName() { + return name; + } + public String getCanonical() { + return canonical; + } + public String getWeb() { + return web; + } + + } public interface ICanonicalResourceLocator { void findResource(Object caller, String url); // if it can be found, put it in the context } @@ -387,7 +408,7 @@ public interface IWorkerContext { * * @param packageInfo */ - public void cachePackage(PackageVersion packageDetails, List dependencies); + public void cachePackage(PackageDetails packageDetails, List dependencies); // -- profile services --------------------------------------------------------- @@ -779,10 +800,14 @@ public interface IWorkerContext { */ int loadFromPackageAndDependencies(NpmPackage pi, IContextResourceLoader loader, BasePackageCacheManager pcm) throws FileNotFoundException, IOException, FHIRException; - public boolean hasPackage(String id, String ver); + public boolean hasPackage(String id, String ver); + public boolean hasPackage(PackageVersion pack); + public PackageDetails getPackage(PackageVersion pack); public int getClientRetryCount(); public IWorkerContext setClientRetryCount(int value); public TimeTracker clock(); + + public PackageVersion getPackageForUrl(String url); } \ No newline at end of file diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/SimpleWorkerContext.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/SimpleWorkerContext.java index 0eaabce29..e3796e404 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/SimpleWorkerContext.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/SimpleWorkerContext.java @@ -54,6 +54,7 @@ import org.hl7.fhir.exceptions.FHIRFormatError; import org.hl7.fhir.r5.conformance.ProfileUtilities; import org.hl7.fhir.r5.conformance.ProfileUtilities.ProfileKnowledgeProvider; import org.hl7.fhir.r5.context.CanonicalResourceManager.CanonicalResourceProxy; +import org.hl7.fhir.r5.context.IWorkerContext.PackageVersion; import org.hl7.fhir.r5.context.IWorkerContext.ILoggingService.LogCategory; import org.hl7.fhir.r5.context.SimpleWorkerContext.PackageResourceLoader; import org.hl7.fhir.r5.formats.IParser; @@ -810,15 +811,6 @@ public class SimpleWorkerContext extends BaseWorkerContext implements IWorkerCon this.progress = progress; } - @Override - public boolean hasPackage(String id, String ver) { - return loadedPackages.contains(id+"#"+ver); - } - - public boolean hasPackage(String idAndver) { - return loadedPackages.contains(idAndver); - } - public void setClock(TimeTracker tt) { clock = tt; } @@ -837,5 +829,34 @@ public class SimpleWorkerContext extends BaseWorkerContext implements IWorkerCon } return xverManager; } + + public void cachePackage(PackageVersion packageDetails, List dependencies) { + // nothing yet + } + + @Override + public boolean hasPackage(String id, String ver) { + return loadedPackages.contains(id+"#"+ver); + } + + public boolean hasPackage(String idAndver) { + return loadedPackages.contains(idAndver); + } + + @Override + public void cachePackage(PackageDetails packageDetails, List dependencies) { + // TODO Auto-generated method stub + } + + @Override + public boolean hasPackage(PackageVersion pack) { + return false; + } + + @Override + public PackageDetails getPackage(PackageVersion pack) { + return null; + } + }