
001package org.hl7.fhir.convertors.conv30_50.resources30_50; 002 003import java.util.List; 004 005import org.hl7.fhir.convertors.VersionConvertorConstants; 006import org.hl7.fhir.convertors.context.ConversionContext30_50; 007import org.hl7.fhir.convertors.conv30_50.datatypes30_50.ContactDetail30_50; 008import org.hl7.fhir.convertors.conv30_50.datatypes30_50.Reference30_50; 009import org.hl7.fhir.convertors.conv30_50.datatypes30_50.UsageContext30_50; 010import org.hl7.fhir.convertors.conv30_50.datatypes30_50.complextypes30_50.CodeableConcept30_50; 011import org.hl7.fhir.convertors.conv30_50.datatypes30_50.primitivetypes30_50.Boolean30_50; 012import org.hl7.fhir.convertors.conv30_50.datatypes30_50.primitivetypes30_50.Code30_50; 013import org.hl7.fhir.convertors.conv30_50.datatypes30_50.primitivetypes30_50.DateTime30_50; 014import org.hl7.fhir.convertors.conv30_50.datatypes30_50.primitivetypes30_50.MarkDown30_50; 015import org.hl7.fhir.convertors.conv30_50.datatypes30_50.primitivetypes30_50.String30_50; 016import org.hl7.fhir.convertors.conv30_50.datatypes30_50.primitivetypes30_50.Uri30_50; 017import org.hl7.fhir.dstu3.model.ImplementationGuide; 018import org.hl7.fhir.exceptions.FHIRException; 019import org.hl7.fhir.r4.model.Extension; 020import org.hl7.fhir.r5.model.CanonicalType; 021import org.hl7.fhir.r5.model.Enumeration; 022 023public class ImplementationGuide30_50 { 024 025 static final String EXT_IG_DEFINITION_RESOURCE_PROFILE = "http://hl7.org/fhir/5.0/StructureDefinition/extension-ImplementationGuide.definition.resource.profile"; 026 027 public static org.hl7.fhir.dstu3.model.ImplementationGuide convertImplementationGuide(org.hl7.fhir.r5.model.ImplementationGuide src) throws FHIRException { 028 if (src == null) 029 return null; 030 org.hl7.fhir.dstu3.model.ImplementationGuide tgt = new org.hl7.fhir.dstu3.model.ImplementationGuide(); 031 ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyDomainResource(src, tgt); 032 if (src.hasUrl()) 033 tgt.setUrlElement(Uri30_50.convertUri(src.getUrlElement())); 034 if (src.hasVersion()) 035 tgt.setVersionElement(String30_50.convertString(src.getVersionElement())); 036 if (src.hasName()) 037 tgt.setNameElement(String30_50.convertString(src.getNameElement())); 038 if (src.hasStatus()) 039 tgt.setStatusElement(Enumerations30_50.convertPublicationStatus(src.getStatusElement())); 040 if (src.hasExperimental()) 041 tgt.setExperimentalElement(Boolean30_50.convertBoolean(src.getExperimentalElement())); 042 if (src.hasDate()) 043 tgt.setDateElement(DateTime30_50.convertDateTime(src.getDateElement())); 044 if (src.hasPublisher()) 045 tgt.setPublisherElement(String30_50.convertString(src.getPublisherElement())); 046 for (org.hl7.fhir.r5.model.ContactDetail t : src.getContact()) 047 tgt.addContact(ContactDetail30_50.convertContactDetail(t)); 048 if (src.hasDescription()) 049 tgt.setDescriptionElement(MarkDown30_50.convertMarkdown(src.getDescriptionElement())); 050 for (org.hl7.fhir.r5.model.UsageContext t : src.getUseContext()) 051 tgt.addUseContext(UsageContext30_50.convertUsageContext(t)); 052 for (org.hl7.fhir.r5.model.CodeableConcept t : src.getJurisdiction()) 053 tgt.addJurisdiction(CodeableConcept30_50.convertCodeableConcept(t)); 054 if (src.hasCopyright()) 055 tgt.setCopyrightElement(MarkDown30_50.convertMarkdown(src.getCopyrightElement())); 056 if (src.hasFhirVersion()) 057 for (Enumeration<org.hl7.fhir.r5.model.Enumerations.FHIRVersion> v : src.getFhirVersion()) { 058 tgt.setFhirVersion(v.asStringValue()); 059 break; 060 } 061 for (org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideDependsOnComponent t : src.getDependsOn()) 062 tgt.addDependency(convertImplementationGuideDependencyComponent(t)); 063 for (org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideDefinitionGroupingComponent t : src.getDefinition().getGrouping()) 064 tgt.addPackage(convertImplementationGuidePackageComponent(t)); 065 for (org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideDefinitionResourceComponent t : src.getDefinition().getResource()) { 066 findPackage(tgt.getPackage(), t.getGroupingId()).addResource(convertImplementationGuidePackageResourceComponent(t)); 067 } 068 for (org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideGlobalComponent t : src.getGlobal()) 069 tgt.addGlobal(convertImplementationGuideGlobalComponent(t)); 070 if (src.getDefinition().hasPage()) 071 tgt.setPage(convertImplementationGuidePageComponent(src.getDefinition().getPage())); 072 return tgt; 073 } 074 075 public static org.hl7.fhir.r5.model.ImplementationGuide convertImplementationGuide(org.hl7.fhir.dstu3.model.ImplementationGuide src) throws FHIRException { 076 if (src == null) 077 return null; 078 org.hl7.fhir.r5.model.ImplementationGuide tgt = new org.hl7.fhir.r5.model.ImplementationGuide(); 079 ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyDomainResource(src, tgt); 080 if (src.hasUrl()) 081 tgt.setUrlElement(Uri30_50.convertUri(src.getUrlElement())); 082 if (src.hasVersion()) 083 tgt.setVersionElement(String30_50.convertString(src.getVersionElement())); 084 if (src.hasName()) 085 tgt.setNameElement(String30_50.convertString(src.getNameElement())); 086 if (src.hasStatus()) 087 tgt.setStatusElement(Enumerations30_50.convertPublicationStatus(src.getStatusElement())); 088 if (src.hasExperimental()) 089 tgt.setExperimentalElement(Boolean30_50.convertBoolean(src.getExperimentalElement())); 090 if (src.hasDate()) 091 tgt.setDateElement(DateTime30_50.convertDateTime(src.getDateElement())); 092 if (src.hasPublisher()) 093 tgt.setPublisherElement(String30_50.convertString(src.getPublisherElement())); 094 for (org.hl7.fhir.dstu3.model.ContactDetail t : src.getContact()) 095 tgt.addContact(ContactDetail30_50.convertContactDetail(t)); 096 if (src.hasDescription()) 097 tgt.setDescriptionElement(MarkDown30_50.convertMarkdown(src.getDescriptionElement())); 098 for (org.hl7.fhir.dstu3.model.UsageContext t : src.getUseContext()) 099 tgt.addUseContext(UsageContext30_50.convertUsageContext(t)); 100 for (org.hl7.fhir.dstu3.model.CodeableConcept t : src.getJurisdiction()) 101 tgt.addJurisdiction(CodeableConcept30_50.convertCodeableConcept(t)); 102 if (src.hasCopyright()) 103 tgt.setCopyrightElement(MarkDown30_50.convertMarkdown(src.getCopyrightElement())); 104 if (src.hasFhirVersion()) 105 tgt.addFhirVersion(org.hl7.fhir.r5.model.Enumerations.FHIRVersion.fromCode(src.getFhirVersion())); 106 for (org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuideDependencyComponent t : src.getDependency()) 107 tgt.addDependsOn(convertImplementationGuideDependencyComponent(t)); 108 for (org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuidePackageComponent t : src.getPackage()) 109 tgt.getDefinition().addGrouping(convertImplementationGuidePackageComponent(tgt.getDefinition(), t)); 110 for (org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuideGlobalComponent t : src.getGlobal()) 111 tgt.addGlobal(convertImplementationGuideGlobalComponent(t)); 112 if (src.hasPage()) 113 tgt.getDefinition().setPage(convertImplementationGuidePageComponent(src.getPage())); 114 return tgt; 115 } 116 117 public static org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuideDependencyComponent convertImplementationGuideDependencyComponent(org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideDependsOnComponent src) throws FHIRException { 118 if (src == null) 119 return null; 120 org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuideDependencyComponent tgt = new org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuideDependencyComponent(); 121 ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyBackboneElement(src,tgt); 122 tgt.setType(org.hl7.fhir.dstu3.model.ImplementationGuide.GuideDependencyType.REFERENCE); 123 if (src.hasUri()) 124 tgt.setUri(src.getUri()); 125 if (src.hasPackageId()) 126 tgt.addExtension(new org.hl7.fhir.dstu3.model.Extension(VersionConvertorConstants.IG_DEPENDSON_PACKAGE_EXTENSION, new org.hl7.fhir.dstu3.model.IdType(src.getPackageId()))); 127 if (src.hasVersion()) 128 tgt.addExtension(new org.hl7.fhir.dstu3.model.Extension(VersionConvertorConstants.IG_DEPENDSON_VERSION_EXTENSION, new org.hl7.fhir.dstu3.model.StringType(src.getVersion()))); 129 return tgt; 130 } 131 132 public static org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideDependsOnComponent convertImplementationGuideDependencyComponent(org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuideDependencyComponent src) throws FHIRException { 133 if (src == null) 134 return null; 135 org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideDependsOnComponent tgt = new org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideDependsOnComponent(); 136 ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyBackboneElement(src,tgt); 137 if (src.hasUri()) 138 tgt.setUri(src.getUri()); 139 if (org.hl7.fhir.dstu3.utils.ToolingExtensions.hasExtension(src, VersionConvertorConstants.IG_DEPENDSON_PACKAGE_EXTENSION)) { 140 tgt.setPackageId(org.hl7.fhir.dstu3.utils.ToolingExtensions.readStringExtension(src, VersionConvertorConstants.IG_DEPENDSON_PACKAGE_EXTENSION)); 141 } 142 if (org.hl7.fhir.dstu3.utils.ToolingExtensions.hasExtension(src, VersionConvertorConstants.IG_DEPENDSON_VERSION_EXTENSION)) { 143 tgt.setVersion(org.hl7.fhir.dstu3.utils.ToolingExtensions.readStringExtension(src, VersionConvertorConstants.IG_DEPENDSON_VERSION_EXTENSION)); 144 } 145 return tgt; 146 } 147 148 public static org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideGlobalComponent convertImplementationGuideGlobalComponent(org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuideGlobalComponent src) throws FHIRException { 149 if (src == null) 150 return null; 151 org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideGlobalComponent tgt = new org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideGlobalComponent(); 152 ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyBackboneElement(src,tgt); 153 if (src.hasType()) 154 tgt.setTypeElement(Code30_50.convertCode(src.getTypeElement())); 155 if (src.hasProfile()) 156 tgt.setProfileElement(Reference30_50.convertReferenceToCanonical(src.getProfile())); 157 return tgt; 158 } 159 160 public static org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuideGlobalComponent convertImplementationGuideGlobalComponent(org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideGlobalComponent src) throws FHIRException { 161 if (src == null) 162 return null; 163 org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuideGlobalComponent tgt = new org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuideGlobalComponent(); 164 ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyBackboneElement(src,tgt); 165 if (src.hasType()) 166 tgt.setTypeElement(Code30_50.convertCode(src.getTypeElement())); 167 if (src.hasProfile()) 168 tgt.setProfile(Reference30_50.convertCanonicalToReference(src.getProfileElement())); 169 return tgt; 170 } 171 172 public static org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuidePackageComponent convertImplementationGuidePackageComponent(org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideDefinitionGroupingComponent src) throws FHIRException { 173 if (src == null) 174 return null; 175 org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuidePackageComponent tgt = new org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuidePackageComponent(); 176 ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyBackboneElement(src,tgt); 177 tgt.setId(src.getId()); 178 if (src.hasName()) 179 tgt.setNameElement(String30_50.convertString(src.getNameElement())); 180 if (src.hasDescription()) 181 tgt.setDescriptionElement(String30_50.convertString(src.getDescriptionElement())); 182 return tgt; 183 } 184 185 public static org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideDefinitionGroupingComponent convertImplementationGuidePackageComponent(org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideDefinitionComponent context, org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuidePackageComponent src) throws FHIRException { 186 if (src == null) 187 return null; 188 org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideDefinitionGroupingComponent tgt = new org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideDefinitionGroupingComponent(); 189 tgt.setId("p" + (context.getGrouping().size() + 1)); 190 ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyBackboneElement(src,tgt); 191 if (src.hasName()) 192 tgt.setNameElement(String30_50.convertString(src.getNameElement())); 193 if (src.hasDescription()) 194 tgt.setDescriptionElement(String30_50.convertStringToMarkdown(src.getDescriptionElement())); 195 for (org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuidePackageResourceComponent t : src.getResource()) { 196 org.hl7.fhir.r5.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.dstu3.model.ImplementationGuide.ImplementationGuidePackageResourceComponent convertImplementationGuidePackageResourceComponent(org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideDefinitionResourceComponent src) throws FHIRException { 204 if (src == null) 205 return null; 206 org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuidePackageResourceComponent tgt = new org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuidePackageResourceComponent(); 207 ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyBackboneElement(src,tgt); 208 if (src.hasProfile()) { 209 tgt.setExampleFor(Reference30_50.convertCanonicalToReference(src.getProfile().get(0))); 210 tgt.setExample(true); 211 if (src.getProfile().size() > 1) { 212 for (CanonicalType p: src.getProfile().subList(1, src.getProfile().size())) { 213 tgt.addExtension(EXT_IG_DEFINITION_RESOURCE_PROFILE, Uri30_50.convertUri(p)); 214 } 215 } 216 } else if (src.hasIsExample()) 217 tgt.setExample(src.getIsExample()); 218 else 219 tgt.setExample(false); 220 221 if (src.hasName()) 222 tgt.setNameElement(String30_50.convertString(src.getNameElement())); 223 if (src.hasDescription()) 224 tgt.setDescriptionElement(String30_50.convertString(src.getDescriptionElement())); 225 if (src.hasReference()) 226 tgt.setSource(Reference30_50.convertReference(src.getReference())); 227 return tgt; 228 } 229 230 public static org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideDefinitionResourceComponent convertImplementationGuidePackageResourceComponent(org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuidePackageResourceComponent src) throws FHIRException { 231 if (src == null) 232 return null; 233 org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideDefinitionResourceComponent tgt = new org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideDefinitionResourceComponent(); 234 ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyBackboneElement(src,tgt); 235 for (org.hl7.fhir.dstu3.model.Extension ext: src.getExtensionsByUrl(EXT_IG_DEFINITION_RESOURCE_PROFILE)) { 236 tgt.getProfile().add(Uri30_50.convertCanonical((org.hl7.fhir.dstu3.model.UriType)ext.getValue())); 237 } 238 if (src.hasExampleFor()) { 239 tgt.getProfile().add(Reference30_50.convertReferenceToCanonical(src.getExampleFor())); 240 } else if (src.hasExample()) 241 tgt.setIsExampleElement(new org.hl7.fhir.r5.model.BooleanType(src.getExample())); 242 if (src.hasName()) 243 tgt.setNameElement(String30_50.convertString(src.getNameElement())); 244 if (src.hasDescription()) 245 tgt.setDescriptionElement(String30_50.convertStringToMarkdown(src.getDescriptionElement())); 246 if (src.hasSourceReference()) 247 tgt.setReference(Reference30_50.convertReference(src.getSourceReference())); 248 else if (src.hasSourceUriType()) 249 tgt.setReference(new org.hl7.fhir.r5.model.Reference(src.getSourceUriType().getValue())); 250 return tgt; 251 } 252 253 public static org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuidePageComponent convertImplementationGuidePageComponent(org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideDefinitionPageComponent src) throws FHIRException { 254 if (src == null) 255 return null; 256 org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuidePageComponent tgt = new org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuidePageComponent(); 257 ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyBackboneElement(src,tgt); 258 if (src.hasName()) 259 tgt.setSource(src.getName()); 260 if (src.hasTitle()) 261 tgt.setTitleElement(String30_50.convertString(src.getTitleElement())); 262 if (src.hasGeneration()) 263 tgt.setKind(convertPageGeneration(src.getGeneration())); 264 for (org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideDefinitionPageComponent t : src.getPage()) 265 tgt.addPage(convertImplementationGuidePageComponent(t)); 266 return tgt; 267 } 268 269 public static org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideDefinitionPageComponent convertImplementationGuidePageComponent(org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuidePageComponent src) throws FHIRException { 270 if (src == null) 271 return null; 272 org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideDefinitionPageComponent tgt = new org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideDefinitionPageComponent(); 273 ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyBackboneElement(src,tgt); 274 if (src.hasSource()) 275 tgt.setNameElement(convertUriToUrl(src.getSourceElement())); 276 if (src.hasTitle()) 277 tgt.setTitleElement(String30_50.convertString(src.getTitleElement())); 278 if (src.hasKind()) 279 tgt.setGeneration(convertPageGeneration(src.getKind())); 280 for (org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuidePageComponent t : src.getPage()) 281 tgt.addPage(convertImplementationGuidePageComponent(t)); 282 return tgt; 283 } 284 285 static public org.hl7.fhir.r5.model.ImplementationGuide.GuidePageGeneration convertPageGeneration(org.hl7.fhir.dstu3.model.ImplementationGuide.GuidePageKind kind) { 286 switch (kind) { 287 case PAGE: 288 return org.hl7.fhir.r5.model.ImplementationGuide.GuidePageGeneration.HTML; 289 default: 290 return org.hl7.fhir.r5.model.ImplementationGuide.GuidePageGeneration.GENERATED; 291 } 292 } 293 294 static public org.hl7.fhir.dstu3.model.ImplementationGuide.GuidePageKind convertPageGeneration(org.hl7.fhir.r5.model.ImplementationGuide.GuidePageGeneration generation) { 295 switch (generation) { 296 case HTML: 297 return org.hl7.fhir.dstu3.model.ImplementationGuide.GuidePageKind.PAGE; 298 default: 299 return org.hl7.fhir.dstu3.model.ImplementationGuide.GuidePageKind.RESOURCE; 300 } 301 } 302 303 public static org.hl7.fhir.r5.model.UrlType convertUriToUrl(org.hl7.fhir.dstu3.model.UriType src) throws FHIRException { 304 org.hl7.fhir.r5.model.UrlType tgt = new org.hl7.fhir.r5.model.UrlType(src.getValue()); 305 ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt); 306 return tgt; 307 } 308 309 static public org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuidePackageComponent findPackage(List<ImplementationGuide.ImplementationGuidePackageComponent> definition, String id) { 310 for (org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuidePackageComponent t : definition) 311 if (t.hasId() && t.getId().equals(id)) 312 return t; 313 org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuidePackageComponent t1 = new org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuidePackageComponent(); 314 t1.setName("Default Package"); 315 t1.setId(id); 316 return t1; 317 } 318}