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