001package org.hl7.fhir.convertors.conv30_40.resources30_40; 002 003import org.hl7.fhir.convertors.context.ConversionContext30_40; 004import org.hl7.fhir.convertors.conv30_40.datatypes30_40.ContactDetail30_40; 005import org.hl7.fhir.convertors.conv30_40.datatypes30_40.Reference30_40; 006import org.hl7.fhir.convertors.conv30_40.datatypes30_40.complextypes30_40.CodeableConcept30_40; 007import org.hl7.fhir.convertors.conv30_40.datatypes30_40.complextypes30_40.Timing30_40; 008import org.hl7.fhir.convertors.conv30_40.datatypes30_40.primitivetypes30_40.*; 009import org.hl7.fhir.dstu3.model.ImplementationGuide; 010import org.hl7.fhir.exceptions.FHIRException; 011import org.hl7.fhir.r4.model.Enumeration; 012 013import java.util.List; 014 015public class ImplementationGuide30_40 { 016 017 public static org.hl7.fhir.dstu3.model.ImplementationGuide convertImplementationGuide(org.hl7.fhir.r4.model.ImplementationGuide src) throws FHIRException { 018 if (src == null) 019 return null; 020 org.hl7.fhir.dstu3.model.ImplementationGuide tgt = new org.hl7.fhir.dstu3.model.ImplementationGuide(); 021 ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyDomainResource(src, tgt); 022 if (src.hasUrl()) 023 tgt.setUrlElement(Uri30_40.convertUri(src.getUrlElement())); 024 if (src.hasVersion()) 025 tgt.setVersionElement(String30_40.convertString(src.getVersionElement())); 026 if (src.hasName()) 027 tgt.setNameElement(String30_40.convertString(src.getNameElement())); 028 if (src.hasStatus()) 029 tgt.setStatusElement(Enumerations30_40.convertPublicationStatus(src.getStatusElement())); 030 if (src.hasExperimental()) 031 tgt.setExperimentalElement(Boolean30_40.convertBoolean(src.getExperimentalElement())); 032 if (src.hasDateElement()) 033 tgt.setDateElement(DateTime30_40.convertDateTime(src.getDateElement())); 034 if (src.hasPublisher()) 035 tgt.setPublisherElement(String30_40.convertString(src.getPublisherElement())); 036 for (org.hl7.fhir.r4.model.ContactDetail t : src.getContact()) 037 tgt.addContact(ContactDetail30_40.convertContactDetail(t)); 038 if (src.hasDescription()) 039 tgt.setDescriptionElement(MarkDown30_40.convertMarkdown(src.getDescriptionElement())); 040 for (org.hl7.fhir.r4.model.UsageContext t : src.getUseContext()) 041 tgt.addUseContext(Timing30_40.convertUsageContext(t)); 042 for (org.hl7.fhir.r4.model.CodeableConcept t : src.getJurisdiction()) 043 tgt.addJurisdiction(CodeableConcept30_40.convertCodeableConcept(t)); 044 if (src.hasCopyright()) 045 tgt.setCopyrightElement(MarkDown30_40.convertMarkdown(src.getCopyrightElement())); 046 if (src.hasFhirVersion()) 047 for (Enumeration<org.hl7.fhir.r4.model.Enumerations.FHIRVersion> v : src.getFhirVersion()) { 048 tgt.setFhirVersion(v.asStringValue()); 049 break; 050 } 051 for (org.hl7.fhir.r4.model.ImplementationGuide.ImplementationGuideDependsOnComponent t : src.getDependsOn()) 052 tgt.addDependency(convertImplementationGuideDependencyComponent(t)); 053 for (org.hl7.fhir.r4.model.ImplementationGuide.ImplementationGuideDefinitionGroupingComponent t : src.getDefinition().getGrouping()) 054 tgt.addPackage(convertImplementationGuidePackageComponent(t)); 055 for (org.hl7.fhir.r4.model.ImplementationGuide.ImplementationGuideDefinitionResourceComponent t : src.getDefinition().getResource()) { 056 findPackage(tgt.getPackage(), t.getGroupingId()).addResource(convertImplementationGuidePackageResourceComponent(t)); 057 } 058 for (org.hl7.fhir.r4.model.ImplementationGuide.ImplementationGuideGlobalComponent t : src.getGlobal()) 059 tgt.addGlobal(convertImplementationGuideGlobalComponent(t)); 060 if (src.getDefinition().hasPage()) 061 tgt.setPage(convertImplementationGuidePageComponent(src.getDefinition().getPage())); 062 return tgt; 063 } 064 065 public static org.hl7.fhir.r4.model.ImplementationGuide convertImplementationGuide(org.hl7.fhir.dstu3.model.ImplementationGuide src) throws FHIRException { 066 if (src == null) 067 return null; 068 org.hl7.fhir.r4.model.ImplementationGuide tgt = new org.hl7.fhir.r4.model.ImplementationGuide(); 069 ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyDomainResource(src, tgt); 070 if (src.hasUrl()) 071 tgt.setUrlElement(Uri30_40.convertUri(src.getUrlElement())); 072 if (src.hasVersion()) 073 tgt.setVersionElement(String30_40.convertString(src.getVersionElement())); 074 if (src.hasName()) 075 tgt.setNameElement(String30_40.convertString(src.getNameElement())); 076 if (src.hasStatus()) 077 tgt.setStatusElement(Enumerations30_40.convertPublicationStatus(src.getStatusElement())); 078 if (src.hasExperimental()) 079 tgt.setExperimentalElement(Boolean30_40.convertBoolean(src.getExperimentalElement())); 080 if (src.hasDateElement()) 081 tgt.setDateElement(DateTime30_40.convertDateTime(src.getDateElement())); 082 if (src.hasPublisher()) 083 tgt.setPublisherElement(String30_40.convertString(src.getPublisherElement())); 084 for (org.hl7.fhir.dstu3.model.ContactDetail t : src.getContact()) 085 tgt.addContact(ContactDetail30_40.convertContactDetail(t)); 086 if (src.hasDescription()) 087 tgt.setDescriptionElement(MarkDown30_40.convertMarkdown(src.getDescriptionElement())); 088 for (org.hl7.fhir.dstu3.model.UsageContext t : src.getUseContext()) 089 tgt.addUseContext(Timing30_40.convertUsageContext(t)); 090 for (org.hl7.fhir.dstu3.model.CodeableConcept t : src.getJurisdiction()) 091 tgt.addJurisdiction(CodeableConcept30_40.convertCodeableConcept(t)); 092 if (src.hasCopyright()) 093 tgt.setCopyrightElement(MarkDown30_40.convertMarkdown(src.getCopyrightElement())); 094 if (src.hasFhirVersion()) 095 tgt.addFhirVersion(org.hl7.fhir.r4.model.Enumerations.FHIRVersion.fromCode(src.getFhirVersion())); 096 for (org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuideDependencyComponent t : src.getDependency()) 097 tgt.addDependsOn(convertImplementationGuideDependencyComponent(t)); 098 for (org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuidePackageComponent t : src.getPackage()) 099 tgt.getDefinition().addGrouping(convertImplementationGuidePackageComponent(tgt.getDefinition(), t)); 100 for (org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuideGlobalComponent t : src.getGlobal()) 101 tgt.addGlobal(convertImplementationGuideGlobalComponent(t)); 102 if (src.hasPage()) 103 tgt.getDefinition().setPage(convertImplementationGuidePageComponent(src.getPage())); 104 return tgt; 105 } 106 107 public static org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuideDependencyComponent convertImplementationGuideDependencyComponent(org.hl7.fhir.r4.model.ImplementationGuide.ImplementationGuideDependsOnComponent src) throws FHIRException { 108 if (src == null) 109 return null; 110 org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuideDependencyComponent tgt = new org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuideDependencyComponent(); 111 ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyElement(src, tgt); 112 tgt.setType(org.hl7.fhir.dstu3.model.ImplementationGuide.GuideDependencyType.REFERENCE); 113 if (src.hasUri()) 114 tgt.setUri(src.getUri()); 115 return tgt; 116 } 117 118 public static org.hl7.fhir.r4.model.ImplementationGuide.ImplementationGuideDependsOnComponent convertImplementationGuideDependencyComponent(org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuideDependencyComponent src) throws FHIRException { 119 if (src == null) 120 return null; 121 org.hl7.fhir.r4.model.ImplementationGuide.ImplementationGuideDependsOnComponent tgt = new org.hl7.fhir.r4.model.ImplementationGuide.ImplementationGuideDependsOnComponent(); 122 ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyElement(src, tgt); 123 if (src.hasUri()) 124 tgt.setUri(src.getUri()); 125 return tgt; 126 } 127 128 public static org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuideGlobalComponent convertImplementationGuideGlobalComponent(org.hl7.fhir.r4.model.ImplementationGuide.ImplementationGuideGlobalComponent src) throws FHIRException { 129 if (src == null) 130 return null; 131 org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuideGlobalComponent tgt = new org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuideGlobalComponent(); 132 ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyElement(src, tgt); 133 if (src.hasType()) 134 tgt.setTypeElement(Code30_40.convertCode(src.getTypeElement())); 135 if (src.hasProfile()) 136 tgt.setProfile(Reference30_40.convertCanonicalToReference(src.getProfileElement())); 137 return tgt; 138 } 139 140 public static org.hl7.fhir.r4.model.ImplementationGuide.ImplementationGuideGlobalComponent convertImplementationGuideGlobalComponent(org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuideGlobalComponent src) throws FHIRException { 141 if (src == null) 142 return null; 143 org.hl7.fhir.r4.model.ImplementationGuide.ImplementationGuideGlobalComponent tgt = new org.hl7.fhir.r4.model.ImplementationGuide.ImplementationGuideGlobalComponent(); 144 ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyElement(src, tgt); 145 if (src.hasType()) 146 tgt.setTypeElement(Code30_40.convertCode(src.getTypeElement())); 147 if (src.hasProfile()) 148 tgt.setProfileElement(Reference30_40.convertReferenceToCanonical(src.getProfile())); 149 return tgt; 150 } 151 152 public static org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuidePackageComponent convertImplementationGuidePackageComponent(org.hl7.fhir.r4.model.ImplementationGuide.ImplementationGuideDefinitionGroupingComponent src) throws FHIRException { 153 if (src == null) 154 return null; 155 org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuidePackageComponent tgt = new org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuidePackageComponent(); 156 ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyElement(src, tgt); 157 tgt.setId(src.getId()); 158 if (src.hasName()) 159 tgt.setNameElement(String30_40.convertString(src.getNameElement())); 160 if (src.hasDescription()) 161 tgt.setDescriptionElement(String30_40.convertString(src.getDescriptionElement())); 162 return tgt; 163 } 164 165 public static org.hl7.fhir.r4.model.ImplementationGuide.ImplementationGuideDefinitionGroupingComponent convertImplementationGuidePackageComponent(org.hl7.fhir.r4.model.ImplementationGuide.ImplementationGuideDefinitionComponent context, org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuidePackageComponent src) throws FHIRException { 166 if (src == null) 167 return null; 168 org.hl7.fhir.r4.model.ImplementationGuide.ImplementationGuideDefinitionGroupingComponent tgt = new org.hl7.fhir.r4.model.ImplementationGuide.ImplementationGuideDefinitionGroupingComponent(); 169 tgt.setId("p" + (context.getGrouping().size() + 1)); 170 ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyElement(src, tgt); 171 if (src.hasName()) 172 tgt.setNameElement(String30_40.convertString(src.getNameElement())); 173 if (src.hasDescription()) 174 tgt.setDescriptionElement(String30_40.convertString(src.getDescriptionElement())); 175 for (org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuidePackageResourceComponent t : src.getResource()) { 176 org.hl7.fhir.r4.model.ImplementationGuide.ImplementationGuideDefinitionResourceComponent tn = convertImplementationGuidePackageResourceComponent(t); 177 tn.setGroupingId(tgt.getId()); 178 context.addResource(tn); 179 } 180 return tgt; 181 } 182 183 public static org.hl7.fhir.r4.model.ImplementationGuide.ImplementationGuideDefinitionResourceComponent convertImplementationGuidePackageResourceComponent(org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuidePackageResourceComponent src) throws FHIRException { 184 if (src == null) 185 return null; 186 org.hl7.fhir.r4.model.ImplementationGuide.ImplementationGuideDefinitionResourceComponent tgt = new org.hl7.fhir.r4.model.ImplementationGuide.ImplementationGuideDefinitionResourceComponent(); 187 ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyElement(src, tgt); 188 if (src.hasExampleFor()) { 189 org.hl7.fhir.r4.model.Type t = ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().convertType(src.getExampleFor()); 190 tgt.setExample(t instanceof org.hl7.fhir.r4.model.Reference ? new org.hl7.fhir.r4.model.CanonicalType(((org.hl7.fhir.r4.model.Reference) t).getReference()) : t); 191 } else if (src.hasExample()) 192 tgt.setExample(new org.hl7.fhir.r4.model.BooleanType(src.getExample())); 193 if (src.hasName()) 194 tgt.setNameElement(String30_40.convertString(src.getNameElement())); 195 if (src.hasDescription()) 196 tgt.setDescriptionElement(String30_40.convertString(src.getDescriptionElement())); 197 if (src.hasSourceReference()) 198 tgt.setReference(Reference30_40.convertReference(src.getSourceReference())); 199 else if (src.hasSourceUriType()) 200 tgt.setReference(new org.hl7.fhir.r4.model.Reference(src.getSourceUriType().getValue())); 201 return tgt; 202 } 203 204 public static org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuidePackageResourceComponent convertImplementationGuidePackageResourceComponent(org.hl7.fhir.r4.model.ImplementationGuide.ImplementationGuideDefinitionResourceComponent src) throws FHIRException { 205 if (src == null) 206 return null; 207 org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuidePackageResourceComponent tgt = new org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuidePackageResourceComponent(); 208 ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyElement(src, tgt); 209 if (src.hasExampleCanonicalType()) { 210 if (src.hasExampleCanonicalType()) 211 tgt.setExampleFor(Reference30_40.convertCanonicalToReference(src.getExampleCanonicalType())); 212 tgt.setExample(true); 213 } else if (src.hasExampleBooleanType()) 214 tgt.setExample(src.getExampleBooleanType().getValue()); 215 else 216 tgt.setExample(false); 217 if (src.hasName()) 218 tgt.setNameElement(String30_40.convertString(src.getNameElement())); 219 if (src.hasDescription()) 220 tgt.setDescriptionElement(String30_40.convertString(src.getDescriptionElement())); 221 if (src.hasReference()) 222 tgt.setSource(Reference30_40.convertReference(src.getReference())); 223 return tgt; 224 } 225 226 public static org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuidePageComponent convertImplementationGuidePageComponent(org.hl7.fhir.r4.model.ImplementationGuide.ImplementationGuideDefinitionPageComponent src) throws FHIRException { 227 if (src == null) 228 return null; 229 org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuidePageComponent tgt = new org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuidePageComponent(); 230 ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyElement(src, tgt); 231 if (src.hasNameUrlType()) 232 tgt.setSource(src.getNameUrlType().getValue()); 233 if (src.hasTitle()) 234 tgt.setTitleElement(String30_40.convertString(src.getTitleElement())); 235 if (src.hasGeneration()) 236 tgt.setKind(convertPageGeneration(src.getGeneration())); 237 for (org.hl7.fhir.r4.model.ImplementationGuide.ImplementationGuideDefinitionPageComponent t : src.getPage()) 238 tgt.addPage(convertImplementationGuidePageComponent(t)); 239 return tgt; 240 } 241 242 public static org.hl7.fhir.r4.model.ImplementationGuide.ImplementationGuideDefinitionPageComponent convertImplementationGuidePageComponent(org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuidePageComponent src) throws FHIRException { 243 if (src == null) 244 return null; 245 org.hl7.fhir.r4.model.ImplementationGuide.ImplementationGuideDefinitionPageComponent tgt = new org.hl7.fhir.r4.model.ImplementationGuide.ImplementationGuideDefinitionPageComponent(); 246 ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyElement(src, tgt); 247 if (src.hasSource()) 248 tgt.setName(convertUriToUrl(src.getSourceElement())); 249 if (src.hasTitle()) 250 tgt.setTitleElement(String30_40.convertString(src.getTitleElement())); 251 if (src.hasKind()) 252 tgt.setGeneration(convertPageGeneration(src.getKind())); 253 for (org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuidePageComponent t : src.getPage()) 254 tgt.addPage(convertImplementationGuidePageComponent(t)); 255 return tgt; 256 } 257 258 static public org.hl7.fhir.r4.model.ImplementationGuide.GuidePageGeneration convertPageGeneration(org.hl7.fhir.dstu3.model.ImplementationGuide.GuidePageKind kind) { 259 switch (kind) { 260 case PAGE: 261 return org.hl7.fhir.r4.model.ImplementationGuide.GuidePageGeneration.HTML; 262 default: 263 return org.hl7.fhir.r4.model.ImplementationGuide.GuidePageGeneration.GENERATED; 264 } 265 } 266 267 static public org.hl7.fhir.dstu3.model.ImplementationGuide.GuidePageKind convertPageGeneration(org.hl7.fhir.r4.model.ImplementationGuide.GuidePageGeneration generation) { 268 switch (generation) { 269 case HTML: 270 return org.hl7.fhir.dstu3.model.ImplementationGuide.GuidePageKind.PAGE; 271 default: 272 return org.hl7.fhir.dstu3.model.ImplementationGuide.GuidePageKind.RESOURCE; 273 } 274 } 275 276 public static org.hl7.fhir.r4.model.UrlType convertUriToUrl(org.hl7.fhir.dstu3.model.UriType src) throws FHIRException { 277 org.hl7.fhir.r4.model.UrlType tgt = new org.hl7.fhir.r4.model.UrlType(src.getValue()); 278 ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyElement(src, tgt); 279 return tgt; 280 } 281 282 static public org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuidePackageComponent findPackage(List<ImplementationGuide.ImplementationGuidePackageComponent> definition, String id) { 283 for (org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuidePackageComponent t : definition) 284 if (t.getId().equals(id)) 285 return t; 286 org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuidePackageComponent t1 = new org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuidePackageComponent(); 287 t1.setName("Default Package"); 288 t1.setId(id); 289 return t1; 290 } 291}