001package org.hl7.fhir.convertors.loaders;
002
003import org.hl7.fhir.r4.context.SimpleWorkerContext.IContextResourceLoader;
004import org.hl7.fhir.r4.model.Bundle;
005import org.hl7.fhir.r4.model.CanonicalType;
006import org.hl7.fhir.r4.model.ElementDefinition;
007import org.hl7.fhir.r4.model.Resource;
008import org.hl7.fhir.r4.model.StructureDefinition;
009import org.hl7.fhir.utilities.npm.NpmPackage;
010
011import java.util.ArrayList;
012import java.util.List;
013
014public abstract class BaseLoaderR4 implements IContextResourceLoader {
015
016  public interface ILoaderKnowledgeProvider {
017    /** 
018     * get the path for references to this resource.
019     * @param resource
020     * @return null if not tracking paths
021     */
022    String getResourcePath(Resource resource);
023  }
024  
025  public static class NullLoaderKnowledgeProvider implements ILoaderKnowledgeProvider {
026    @Override
027    public String getResourcePath(Resource resource) {
028      return null;
029    }
030  }
031  protected final String URL_BASE = "http://hl7.org/fhir/";
032  protected final String URL_DSTU2 = "http://hl7.org/fhir/1.0/";
033  protected final String URL_DSTU2016MAY = "http://hl7.org/fhir/1.4/";
034  protected final String URL_DSTU3 = "http://hl7.org/fhir/3.0/";
035  protected final String URL_R4 = "http://hl7.org/fhir/4.0/";
036
037  protected final String URL_ELEMENT_DEF_NAMESPACE = "http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace";
038
039  protected boolean patchUrls;
040  protected boolean killPrimitives;;
041
042  private String[] types;
043  private ILoaderKnowledgeProvider lkp;
044
045  public BaseLoaderR4(String[] types, ILoaderKnowledgeProvider lkp) {
046    super();
047    this.types = types;
048    this.lkp = lkp;
049  }
050  
051  public String[] getTypes() {
052    return types;
053  }
054
055  public boolean isPatchUrls() {
056    return patchUrls;
057  }
058
059  public BaseLoaderR4 setPatchUrls(boolean patchUrls) {
060    this.patchUrls = patchUrls;
061    return this;
062  }
063
064  public boolean isKillPrimitives() {
065    return killPrimitives;
066  }
067
068  public BaseLoaderR4 setKillPrimitives(boolean killPrimitives) {
069    this.killPrimitives = killPrimitives;
070    return this;
071  }
072
073  public String getResourcePath(Resource resource) {
074    return lkp.getResourcePath(resource);
075  }
076
077  public void setPath(Resource r) {
078    String path = lkp.getResourcePath(r);
079    if (path != null) {
080      r.setUserData("path", path);
081    }
082  }
083
084
085}