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