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