
001package org.hl7.fhir.r5.test.utils; 002 003import java.io.IOException; 004import java.io.InputStream; 005import java.util.ArrayList; 006import java.util.List; 007 008import org.hl7.fhir.exceptions.FHIRException; 009import org.hl7.fhir.r5.context.IWorkerContext.IContextResourceLoader; 010import org.hl7.fhir.r5.formats.JsonParser; 011import org.hl7.fhir.r5.formats.XmlParser; 012import org.hl7.fhir.r5.model.Bundle; 013import org.hl7.fhir.r5.model.CodeSystem; 014import org.hl7.fhir.r5.model.Resource; 015import org.hl7.fhir.utilities.npm.NpmPackage; 016import org.hl7.fhir.utilities.npm.NpmPackage.PackageResourceInformation; 017 018public class TestPackageLoader implements IContextResourceLoader { 019 020 private List<String> types; 021 022 public TestPackageLoader(List<String> types) { 023 this.types = types; 024 } 025 026 @Override 027 public Bundle loadBundle(InputStream stream, boolean isJson) throws FHIRException, IOException { 028 return null; 029 } 030 031 @Override 032 public Resource loadResource(InputStream stream, boolean isJson) throws FHIRException, IOException { 033 return isJson ? new JsonParser().parse(stream) : new XmlParser().parse(stream); 034 } 035 036 @Override 037 public List<String> getTypes() { 038 return types; 039 } 040 041 @Override 042 public String getResourcePath(Resource resource) { 043 return resource.fhirType().toLowerCase()+"-"+resource.getId()+".html"; 044 } 045 046 @Override 047 public IContextResourceLoader getNewLoader(NpmPackage npm) { 048 return this; 049 } 050 051 @Override 052 public List<CodeSystem> getCodeSystems() { 053 return new ArrayList<>(); 054 } 055 056 @Override 057 public void setPatchUrls(boolean value) { 058 059 } 060 061 @Override 062 public String patchUrl(String url, String resourceType) { 063 return url; 064 } 065 066 @Override 067 public IContextResourceLoader setLoadProfiles(boolean value) { 068 return this; 069 } 070 071 @Override 072 public boolean wantLoad(NpmPackage pi, PackageResourceInformation pri) { 073 return true; 074 } 075 076}