001package org.hl7.fhir.r5.test.utils;
002
003 import 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.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.r5.terminologies.client.TerminologyClientManager.ITerminologyClientFactory;
016import org.hl7.fhir.r5.terminologies.client.TerminologyClientR5.TerminologyClientR5Factory;
017import org.hl7.fhir.utilities.MarkedToMoveToAdjunctPackage;
018import org.hl7.fhir.utilities.npm.NpmPackage;
019import org.hl7.fhir.utilities.npm.NpmPackage.PackageResourceInformation;
020
021@MarkedToMoveToAdjunctPackage
022public class TestPackageLoader implements IContextResourceLoader {
023
024  private List<String> types;
025
026  public TestPackageLoader(List<String> types) {
027    this.types = types;
028  }
029
030  @Override
031  public Bundle loadBundle(InputStream stream, boolean isJson) throws FHIRException, IOException {
032    return null;
033  }
034
035  @Override
036  public Resource loadResource(InputStream stream, boolean isJson) throws FHIRException, IOException {
037    return isJson ? new JsonParser().parse(stream) : new XmlParser().parse(stream);
038  }
039
040  @Override
041  public List<String> getTypes() {
042    return types;
043  }
044
045  @Override
046  public String getResourcePath(Resource resource) {
047    return resource.fhirType().toLowerCase()+"-"+resource.getId()+".html";
048  }
049
050  @Override
051  public IContextResourceLoader getNewLoader(NpmPackage npm) {
052    return this;
053  }
054
055  @Override
056  public List<CodeSystem> getCodeSystems() {
057    return new ArrayList<>();
058  }
059
060  @Override
061  public void setPatchUrls(boolean value) {
062    
063  }
064
065  @Override
066  public String patchUrl(String url, String resourceType) {
067    return url;
068  }
069
070  @Override
071  public IContextResourceLoader setLoadProfiles(boolean value) {
072    return this;
073  }
074
075  @Override
076  public boolean wantLoad(NpmPackage pi, PackageResourceInformation pri) {
077    return true;
078  }
079
080  @Override
081  public ITerminologyClientFactory txFactory() {
082    return new TerminologyClientR5Factory();
083  }
084
085}