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