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