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