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