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