
001package org.hl7.fhir.r5.context; 002 003import java.io.IOException; 004import java.io.InputStream; 005import java.util.List; 006import java.util.Set; 007 008import org.hl7.fhir.exceptions.FHIRException; 009import org.hl7.fhir.r5.context.SimpleWorkerContext.PackageResourceLoader; 010import org.hl7.fhir.r5.model.Bundle; 011import org.hl7.fhir.r5.model.CodeSystem; 012import org.hl7.fhir.r5.model.Resource; 013import org.hl7.fhir.r5.terminologies.client.TerminologyClientManager.ITerminologyClientFactory; 014import org.hl7.fhir.utilities.MarkedToMoveToAdjunctPackage; 015import org.hl7.fhir.utilities.npm.NpmPackage; 016import org.hl7.fhir.utilities.npm.NpmPackage.PackageResourceInformation; 017 018import com.google.gson.JsonSyntaxException; 019 020@MarkedToMoveToAdjunctPackage 021public interface IContextResourceLoader { 022 /** 023 * @return List of the resource types that should be loaded 024 */ 025 Set<String> getTypes(); 026 027 /** 028 * Request to actually load the resources and do whatever is required 029 * 030 * @param stream 031 * @param isJson 032 * @return A bundle because some single resources become multiple resources after loading 033 * @throws FHIRException 034 * @throws IOException 035 */ 036 Bundle loadBundle(InputStream stream, boolean isJson) throws FHIRException, IOException; 037 038 /** 039 * Load a single resources (lazy load) 040 * 041 * @param stream 042 * @param isJson 043 * @return 044 * @throws FHIRException - throw this if you a single resource can't be returned - can't lazy load in this circumstance 045 * @throws IOException 046 */ 047 Resource loadResource(InputStream stream, boolean isJson) throws FHIRException, IOException; 048 049 /** 050 * get the path for references to this resource. 051 * @param resource 052 * @return null if not tracking paths 053 */ 054 String getResourcePath(Resource resource); 055 056 /** 057 * called when a new package is being loaded 058 * 059 * this is called by loadPackageAndDependencies when a new package is loaded 060 * @param npm 061 * @return 062 * @throws IOException 063 * @throws JsonSyntaxException 064 */ 065 IContextResourceLoader getNewLoader(NpmPackage npm) throws JsonSyntaxException, IOException; 066 067 /** 068 * called when processing R2 for implicit code systems in ValueSets 069 * 070 * @return 071 */ 072 List<CodeSystem> getCodeSystems(); 073 074 /** 075 * if this is true, then the loader will patch canonical URLs and cross-links 076 * to add /X.X/ into the URL so that different versions can be loaded safely 077 * 078 * default is false 079 */ 080 void setPatchUrls(boolean value); 081 082 /** 083 * patch the URL if necessary 084 * 085 * @param url 086 * @return 087 */ 088 String patchUrl(String url, String resourceType); 089 090 /** 091 * set this to false (default is true) if you don't want profiles loaded 092 * @param value 093 * @return 094 */ 095 IContextResourceLoader setLoadProfiles(boolean value); 096 097 /** 098 * @return the terminology client factory 099 */ 100 ITerminologyClientFactory txFactory(); 101 102 /** 103 * Called during the loading process - the loader can decide which resources to load. 104 * At this point, only the .index.json is being read 105 * 106 * @param pi 107 * @param pri 108 * @return 109 */ 110 boolean wantLoad(NpmPackage pi, PackageResourceInformation pri); 111 112 /** 113 * let's the loader review the R5 list of resources being asked for, and add Basic or other names as required 114 * @param types 115 * @return 116 */ 117 Set<String> reviewActualTypes(Set<String> types); 118 119 /** 120 * let's the loader change the identified type (e.g. when loading converted Basic resources) 121 * 122 * @param types 123 * @return 124 */ 125 PackageResourceLoader editInfo(PackageResourceLoader pri); 126}