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