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