
001package org.hl7.fhir.r5.context; 002 003import org.hl7.fhir.exceptions.FHIRException; 004import org.hl7.fhir.r5.model.PackageInformation; 005import org.hl7.fhir.r5.model.Parameters; 006import org.hl7.fhir.r5.model.Resource; 007import org.hl7.fhir.utilities.MarkedToMoveToAdjunctPackage; 008import org.hl7.fhir.utilities.npm.BasePackageCacheManager; 009import org.hl7.fhir.utilities.npm.IPackageCacheManager; 010import org.hl7.fhir.utilities.npm.NpmPackage; 011 012import javax.annotation.Nonnull; 013import java.io.FileNotFoundException; 014import java.io.IOException; 015import java.util.Locale; 016 017@MarkedToMoveToAdjunctPackage 018public interface IWorkerContextManager { 019 020 interface IPackageLoadingTracker { 021 public void packageLoaded(String pid, String version); 022 } 023 024 interface ICanonicalResourceLocator { 025 void findResource(Object caller, String url); // if it can be found, put it in the context 026 } 027 028 public IPackageCacheManager packageManager(); 029 030 public void setPackageManager(IPackageCacheManager manager); 031 032 /** 033 * Get the expansion parameters passed through the terminology server when txServer calls are made 034 * 035 * Note that the Validation Options override these when they are specified on validateCode 036 */ 037 public void setExpansionParameters(Parameters expParameters); 038 039 /** 040 * Sets the locale for this worker context. 041 * 042 * @param locale The locale to use. 043 * @deprecated Usage of this method is discouraged outside very specific scenarios in testing and the IG publisher. 044 * It is preferred to set the locale via the constructor of the implementing class. 045 */ 046 @Deprecated 047 void setLocale(Locale locale); 048 049// @Deprecated 050// void setValidationMessageLanguage(Locale locale); 051 052 /** 053 * cache a resource for later retrieval using fetchResource. 054 * 055 * Note that various context implementations will have their own ways of loading 056 * rseources, and not all need implement cacheResource. 057 * 058 * If the resource is loaded out of a package, call cacheResourceFromPackage instead 059 * @param res 060 * @throws FHIRException 061 */ 062 public void cacheResource(Resource res) throws FHIRException; 063 064 065 /** 066 * cache a resource for later retrieval using fetchResource. 067 * 068 * The package information is used to help manage the cache internally, and to 069 * help with reference resolution. Packages should be define using cachePackage (but don't have to be) 070 * 071 * Note that various context implementations will have their own ways of loading 072 * rseources, and not all need implement cacheResource 073 * 074 * @param res 075 * @throws FHIRException 076 */ 077 public void cacheResourceFromPackage(Resource res, PackageInformation packageInfo) throws FHIRException; 078 079 /** 080 * Inform the cache about package dependencies. This can be used to help resolve references 081 * 082 * Note that the cache doesn't load dependencies 083 * 084 * @param packageInfo 085 */ 086 @Deprecated 087 public void cachePackage(PackageInformation packageInfo); 088 089 /** 090 * Load relevant resources of the appropriate types (as specified by the loader) from the nominated package 091 * 092 * note that the package system may use lazy loading; the loader will be called later when the classes that use the context need the relevant resource 093 * 094 * @param pi - the package to load 095 * @param loader - an implemenation of IContextResourceLoader that knows how to read the resources in the package (e.g. for the appropriate version). 096 * @return the number of resources loaded 097 */ 098 int loadFromPackage(NpmPackage pi, IContextResourceLoader loader) throws FileNotFoundException, IOException, FHIRException; 099 100 /** 101 * Load relevant resources of the appropriate types (as specified by the loader) from the nominated package 102 * 103 * note that the package system may use lazy loading; the loader will be called later when the classes that use the context need the relevant resource 104 * 105 * @param pi - the package to load 106 * @return the number of resources loaded 107 */ 108 int loadPackage(NpmPackage pi) throws FileNotFoundException, IOException, FHIRException; 109 110 /** 111 * Load relevant resources of the appropriate types (as specified by the loader) from the nominated package 112 * 113 * note that the package system may use lazy loading; the loader will be called later when the classes that use the context need the relevant resource 114 * 115 * @param idAndVer - the package to load 116 * @return the number of resources loaded 117 */ 118 int loadPackage(String idAndVer) throws FileNotFoundException, IOException, FHIRException; 119 120 121 /** 122 * Load relevant resources of the appropriate types (as specified by the loader) from the nominated package 123 * 124 * note that the package system uses lazy loading; the loader will be called later when the classes that use the context need the relevant resource 125 * 126 * This method also loads all the packages that the package depends on (recursively) 127 * 128 * @param pi - the package to load 129 * @param loader - an implemenation of IContextResourceLoader that knows how to read the resources in the package (e.g. for the appropriate version). 130 * @param pcm - used to find and load additional dependencies 131 * @return the number of resources loaded 132 */ 133 int loadFromPackageAndDependencies(NpmPackage pi, IContextResourceLoader loader, BasePackageCacheManager pcm) throws FileNotFoundException, IOException, FHIRException; 134 135}