001package org.hl7.fhir.convertors.conv10_30.datatypes10_30;
002
003import java.util.List;
004import java.util.stream.Collectors;
005
006import org.hl7.fhir.convertors.context.ConversionContext10_30;
007import org.hl7.fhir.convertors.conv10_30.datatypes10_30.complextypes10_30.Coding10_30;
008import org.hl7.fhir.convertors.conv10_30.datatypes10_30.primitivetypes10_30.Boolean10_30;
009import org.hl7.fhir.convertors.conv10_30.datatypes10_30.primitivetypes10_30.Code10_30;
010import org.hl7.fhir.convertors.conv10_30.datatypes10_30.primitivetypes10_30.Id10_30;
011import org.hl7.fhir.convertors.conv10_30.datatypes10_30.primitivetypes10_30.Integer10_30;
012import org.hl7.fhir.convertors.conv10_30.datatypes10_30.primitivetypes10_30.MarkDown10_30;
013import org.hl7.fhir.convertors.conv10_30.datatypes10_30.primitivetypes10_30.String10_30;
014import org.hl7.fhir.dstu2.utils.ToolingExtensions;
015import org.hl7.fhir.dstu3.conformance.ProfileUtilities;
016import org.hl7.fhir.dstu3.model.ElementDefinition;
017import org.hl7.fhir.exceptions.FHIRException;
018
019public class ElementDefinition10_30 {
020  public static org.hl7.fhir.dstu3.model.ElementDefinition convertElementDefinition(org.hl7.fhir.dstu2.model.ElementDefinition src, List<String> slicePaths) throws FHIRException {
021    if (src == null || src.isEmpty()) return null;
022    org.hl7.fhir.dstu3.model.ElementDefinition tgt = new org.hl7.fhir.dstu3.model.ElementDefinition();
023    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt);
024    if (src.hasPathElement()) tgt.setPathElement(String10_30.convertString(src.getPathElement()));
025    tgt.setRepresentation(src.getRepresentation().stream().map(ElementDefinition10_30::convertPropertyRepresentation).collect(Collectors.toList()));
026    if (src.hasName()) {
027      if (slicePaths.contains(src.getPath())) tgt.setSliceNameElement(String10_30.convertString(src.getNameElement()));
028      if (src.hasNameElement()) tgt.setIdElement(String10_30.convertString(src.getNameElement()));
029    }
030    if (src.hasLabel()) tgt.setLabelElement(String10_30.convertString(src.getLabelElement()));
031    for (org.hl7.fhir.dstu2.model.Coding t : src.getCode()) tgt.addCode(Coding10_30.convertCoding(t));
032    if (src.hasSlicing()) tgt.setSlicing(convertElementDefinitionSlicingComponent(src.getSlicing()));
033    if (src.hasShort()) tgt.setShortElement(String10_30.convertString(src.getShortElement()));
034    if (src.hasDefinition()) tgt.setDefinitionElement(MarkDown10_30.convertMarkdown(src.getDefinitionElement()));
035    if (src.hasComments()) tgt.setCommentElement(MarkDown10_30.convertMarkdown(src.getCommentsElement()));
036    if (src.hasRequirements()) tgt.setRequirementsElement(MarkDown10_30.convertMarkdown(src.getRequirementsElement()));
037    for (org.hl7.fhir.dstu2.model.StringType t : src.getAlias()) tgt.addAlias(t.getValue());
038    if (src.hasMin()) tgt.setMin(src.getMin());
039    if (src.hasMax()) tgt.setMaxElement(String10_30.convertString(src.getMaxElement()));
040    if (src.hasBase()) tgt.setBase(convertElementDefinitionBaseComponent(src.getBase()));
041    if (src.hasNameReference()) tgt.setContentReference("#" + src.getNameReference());
042    for (org.hl7.fhir.dstu2.model.ElementDefinition.TypeRefComponent t : src.getType())
043      tgt.addType(convertElementDefinitionTypeComponent(t));
044    if (src.hasDefaultValue())
045      tgt.setDefaultValue(ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().convertType(src.getDefaultValue()));
046    if (src.hasMeaningWhenMissing())
047      tgt.setMeaningWhenMissingElement(MarkDown10_30.convertMarkdown(src.getMeaningWhenMissingElement()));
048    if (src.hasFixed())
049      tgt.setFixed(ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().convertType(src.getFixed()));
050    if (src.hasPattern())
051      tgt.setPattern(ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().convertType(src.getPattern()));
052    if (src.hasExample())
053      tgt.addExample().setLabel("General").setValue(ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().convertType(src.getExample()));
054    if (src.hasMinValue())
055      tgt.setMinValue(ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().convertType(src.getMinValue()));
056    if (src.hasMaxValue())
057      tgt.setMaxValue(ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().convertType(src.getMaxValue()));
058    if (src.hasMaxLength()) tgt.setMaxLengthElement(Integer10_30.convertInteger(src.getMaxLengthElement()));
059    for (org.hl7.fhir.dstu2.model.IdType t : src.getCondition()) tgt.addCondition(t.getValue());
060    for (org.hl7.fhir.dstu2.model.ElementDefinition.ElementDefinitionConstraintComponent t : src.getConstraint())
061      tgt.addConstraint(convertElementDefinitionConstraintComponent(t));
062    if (src.hasMustSupport()) tgt.setMustSupportElement(Boolean10_30.convertBoolean(src.getMustSupportElement()));
063    if (src.hasIsModifier()) tgt.setIsModifierElement(Boolean10_30.convertBoolean(src.getIsModifierElement()));
064    if (src.hasIsSummary()) tgt.setIsSummaryElement(Boolean10_30.convertBoolean(src.getIsSummaryElement()));
065    if (src.hasBinding()) tgt.setBinding(convertElementDefinitionBindingComponent(src.getBinding()));
066    for (org.hl7.fhir.dstu2.model.ElementDefinition.ElementDefinitionMappingComponent t : src.getMapping())
067      tgt.addMapping(convertElementDefinitionMappingComponent(t));
068    return tgt;
069  }
070
071  public static org.hl7.fhir.dstu2.model.ElementDefinition convertElementDefinition(org.hl7.fhir.dstu3.model.ElementDefinition src) throws FHIRException {
072    if (src == null || src.isEmpty()) return null;
073    org.hl7.fhir.dstu2.model.ElementDefinition tgt = new org.hl7.fhir.dstu2.model.ElementDefinition();
074    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt);
075    if (src.hasPathElement()) tgt.setPathElement(String10_30.convertString(src.getPathElement()));
076    tgt.setRepresentation(src.getRepresentation().stream().map(ElementDefinition10_30::convertPropertyRepresentation).collect(Collectors.toList()));
077    if (src.hasSliceName()) tgt.setNameElement(String10_30.convertString(src.getSliceNameElement()));
078    else tgt.setNameElement(String10_30.convertString(src.getIdElement()));
079    if (src.hasLabelElement()) tgt.setLabelElement(String10_30.convertString(src.getLabelElement()));
080    for (org.hl7.fhir.dstu3.model.Coding t : src.getCode()) tgt.addCode(Coding10_30.convertCoding(t));
081    if (src.hasSlicing()) tgt.setSlicing(convertElementDefinitionSlicingComponent(src.getSlicing()));
082    if (src.hasShortElement()) tgt.setShortElement(String10_30.convertString(src.getShortElement()));
083    if (src.hasDefinitionElement()) tgt.setDefinitionElement(MarkDown10_30.convertMarkdown(src.getDefinitionElement()));
084    if (src.hasCommentElement()) tgt.setCommentsElement(MarkDown10_30.convertMarkdown(src.getCommentElement()));
085    if (src.hasRequirementsElement())
086      tgt.setRequirementsElement(MarkDown10_30.convertMarkdown(src.getRequirementsElement()));
087    for (org.hl7.fhir.dstu3.model.StringType t : src.getAlias()) tgt.addAlias(t.getValue());
088    tgt.setMin(src.getMin());
089    if (src.hasMaxElement()) tgt.setMaxElement(String10_30.convertString(src.getMaxElement()));
090    if (src.hasBase()) tgt.setBase(convertElementDefinitionBaseComponent(src.getBase()));
091    if (src.hasContentReference()) tgt.setNameReference(src.getContentReference().substring(1));
092    for (org.hl7.fhir.dstu3.model.ElementDefinition.TypeRefComponent t : src.getType())
093      tgt.addType(convertElementDefinitionTypeComponent(t));
094    if (src.hasDefaultValue())
095      tgt.setDefaultValue(ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().convertType(src.getDefaultValue()));
096    if (src.hasMeaningWhenMissingElement())
097      tgt.setMeaningWhenMissingElement(MarkDown10_30.convertMarkdown(src.getMeaningWhenMissingElement()));
098    if (src.hasFixed())
099      tgt.setFixed(ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().convertType(src.getFixed()));
100    if (src.hasPattern())
101      tgt.setPattern(ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().convertType(src.getPattern()));
102    if (src.hasExample())
103      tgt.setExample(ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().convertType(src.getExampleFirstRep().getValue()));
104    if (src.hasMinValue())
105      tgt.setMinValue(ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().convertType(src.getMinValue()));
106    if (src.hasMaxValue())
107      tgt.setMaxValue(ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().convertType(src.getMaxValue()));
108    if (src.hasMaxLengthElement()) tgt.setMaxLengthElement(Integer10_30.convertInteger(src.getMaxLengthElement()));
109    for (org.hl7.fhir.dstu3.model.IdType t : src.getCondition()) tgt.addCondition(t.getValue());
110    for (org.hl7.fhir.dstu3.model.ElementDefinition.ElementDefinitionConstraintComponent t : src.getConstraint())
111      tgt.addConstraint(convertElementDefinitionConstraintComponent(t));
112    if (src.hasMustSupportElement())
113      tgt.setMustSupportElement(Boolean10_30.convertBoolean(src.getMustSupportElement()));
114    if (src.hasIsModifierElement()) tgt.setIsModifierElement(Boolean10_30.convertBoolean(src.getIsModifierElement()));
115    if (src.hasIsSummaryElement()) tgt.setIsSummaryElement(Boolean10_30.convertBoolean(src.getIsSummaryElement()));
116    if (src.hasBinding()) tgt.setBinding(convertElementDefinitionBindingComponent(src.getBinding()));
117    for (org.hl7.fhir.dstu3.model.ElementDefinition.ElementDefinitionMappingComponent t : src.getMapping())
118      tgt.addMapping(convertElementDefinitionMappingComponent(t));
119    return tgt;
120  }
121
122  static public org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.ElementDefinition.PropertyRepresentation> convertPropertyRepresentation(org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.ElementDefinition.PropertyRepresentation> src) throws FHIRException {
123    if (src == null || src.isEmpty()) return null;
124    org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.ElementDefinition.PropertyRepresentation> tgt = new org.hl7.fhir.dstu3.model.Enumeration<>(new org.hl7.fhir.dstu3.model.ElementDefinition.PropertyRepresentationEnumFactory());
125    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt);
126    if (src.getValue() == null) {
127      tgt.setValue(org.hl7.fhir.dstu3.model.ElementDefinition.PropertyRepresentation.NULL);
128    } else {
129      switch (src.getValue()) {
130        case XMLATTR:
131          tgt.setValue(org.hl7.fhir.dstu3.model.ElementDefinition.PropertyRepresentation.XMLATTR);
132          break;
133        default:
134          tgt.setValue(org.hl7.fhir.dstu3.model.ElementDefinition.PropertyRepresentation.NULL);
135          break;
136      }
137    }
138    return tgt;
139  }
140
141  static public org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.ElementDefinition.PropertyRepresentation> convertPropertyRepresentation(org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.ElementDefinition.PropertyRepresentation> src) throws FHIRException {
142    if (src == null || src.isEmpty()) return null;
143    org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.ElementDefinition.PropertyRepresentation> tgt = new org.hl7.fhir.dstu2.model.Enumeration<>(new org.hl7.fhir.dstu2.model.ElementDefinition.PropertyRepresentationEnumFactory());
144    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt);
145    if (src.getValue() == null) {
146      tgt.setValue(org.hl7.fhir.dstu2.model.ElementDefinition.PropertyRepresentation.NULL);
147    } else {
148      switch (src.getValue()) {
149        case XMLATTR:
150          tgt.setValue(org.hl7.fhir.dstu2.model.ElementDefinition.PropertyRepresentation.XMLATTR);
151          break;
152        default:
153          tgt.setValue(org.hl7.fhir.dstu2.model.ElementDefinition.PropertyRepresentation.NULL);
154          break;
155      }
156    }
157    return tgt;
158  }
159
160  public static org.hl7.fhir.dstu3.model.ElementDefinition.ElementDefinitionSlicingComponent convertElementDefinitionSlicingComponent(org.hl7.fhir.dstu2.model.ElementDefinition.ElementDefinitionSlicingComponent src) throws FHIRException {
161    if (src == null || src.isEmpty()) return null;
162    org.hl7.fhir.dstu3.model.ElementDefinition.ElementDefinitionSlicingComponent tgt = new org.hl7.fhir.dstu3.model.ElementDefinition.ElementDefinitionSlicingComponent();
163    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt);
164    for (org.hl7.fhir.dstu2.model.StringType t : src.getDiscriminator())
165      tgt.addDiscriminator(ProfileUtilities.interpretR2Discriminator(t.getValue()));
166    if (src.hasDescriptionElement()) tgt.setDescriptionElement(String10_30.convertString(src.getDescriptionElement()));
167    if (src.hasOrderedElement()) tgt.setOrderedElement(Boolean10_30.convertBoolean(src.getOrderedElement()));
168    if (src.hasRules()) tgt.setRulesElement(convertSlicingRules(src.getRulesElement()));
169    return tgt;
170  }
171
172  public static org.hl7.fhir.dstu2.model.ElementDefinition.ElementDefinitionSlicingComponent convertElementDefinitionSlicingComponent(org.hl7.fhir.dstu3.model.ElementDefinition.ElementDefinitionSlicingComponent src) throws FHIRException {
173    if (src == null || src.isEmpty()) return null;
174    org.hl7.fhir.dstu2.model.ElementDefinition.ElementDefinitionSlicingComponent tgt = new org.hl7.fhir.dstu2.model.ElementDefinition.ElementDefinitionSlicingComponent();
175    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt);
176    for (ElementDefinition.ElementDefinitionSlicingDiscriminatorComponent t : src.getDiscriminator())
177      tgt.addDiscriminator(ProfileUtilities.buildR2Discriminator(t));
178    if (src.hasDescriptionElement()) tgt.setDescriptionElement(String10_30.convertString(src.getDescriptionElement()));
179    if (src.hasOrderedElement()) tgt.setOrderedElement(Boolean10_30.convertBoolean(src.getOrderedElement()));
180    if (src.hasRules()) tgt.setRulesElement(convertSlicingRules(src.getRulesElement()));
181    return tgt;
182  }
183
184  static public org.hl7.fhir.dstu3.model.Enumeration<ElementDefinition.SlicingRules> convertSlicingRules(org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.ElementDefinition.SlicingRules> src) throws FHIRException {
185    if (src == null || src.isEmpty()) return null;
186    org.hl7.fhir.dstu3.model.Enumeration<ElementDefinition.SlicingRules> tgt = new org.hl7.fhir.dstu3.model.Enumeration<>(new ElementDefinition.SlicingRulesEnumFactory());
187    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt);
188    if (src.getValue() == null) {
189      tgt.setValue(ElementDefinition.SlicingRules.NULL);
190    } else {
191      switch (src.getValue()) {
192        case CLOSED:
193          tgt.setValue(ElementDefinition.SlicingRules.CLOSED);
194          break;
195        case OPEN:
196          tgt.setValue(ElementDefinition.SlicingRules.OPEN);
197          break;
198        case OPENATEND:
199          tgt.setValue(ElementDefinition.SlicingRules.OPENATEND);
200          break;
201        default:
202          tgt.setValue(ElementDefinition.SlicingRules.NULL);
203          break;
204      }
205    }
206    return tgt;
207  }
208
209  static public org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.ElementDefinition.SlicingRules> convertSlicingRules(org.hl7.fhir.dstu3.model.Enumeration<ElementDefinition.SlicingRules> src) throws FHIRException {
210    if (src == null || src.isEmpty()) return null;
211    org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.ElementDefinition.SlicingRules> tgt = new org.hl7.fhir.dstu2.model.Enumeration<>(new org.hl7.fhir.dstu2.model.ElementDefinition.SlicingRulesEnumFactory());
212    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt);
213    if (src.getValue() == null) {
214      tgt.setValue(org.hl7.fhir.dstu2.model.ElementDefinition.SlicingRules.NULL);
215    } else {
216      switch (src.getValue()) {
217        case CLOSED:
218          tgt.setValue(org.hl7.fhir.dstu2.model.ElementDefinition.SlicingRules.CLOSED);
219          break;
220        case OPEN:
221          tgt.setValue(org.hl7.fhir.dstu2.model.ElementDefinition.SlicingRules.OPEN);
222          break;
223        case OPENATEND:
224          tgt.setValue(org.hl7.fhir.dstu2.model.ElementDefinition.SlicingRules.OPENATEND);
225          break;
226        default:
227          tgt.setValue(org.hl7.fhir.dstu2.model.ElementDefinition.SlicingRules.NULL);
228          break;
229      }
230    }
231    return tgt;
232  }
233
234  public static ElementDefinition.ElementDefinitionBaseComponent convertElementDefinitionBaseComponent(org.hl7.fhir.dstu2.model.ElementDefinition.ElementDefinitionBaseComponent src) throws FHIRException {
235    if (src == null || src.isEmpty()) return null;
236    ElementDefinition.ElementDefinitionBaseComponent tgt = new ElementDefinition.ElementDefinitionBaseComponent();
237    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt);
238    if (src.hasPathElement()) tgt.setPathElement(String10_30.convertString(src.getPathElement()));
239    if (src.hasMin()) tgt.setMin(src.getMin());
240    if (src.hasMaxElement()) tgt.setMaxElement(String10_30.convertString(src.getMaxElement()));
241    return tgt;
242  }
243
244  public static org.hl7.fhir.dstu2.model.ElementDefinition.ElementDefinitionBaseComponent convertElementDefinitionBaseComponent(ElementDefinition.ElementDefinitionBaseComponent src) throws FHIRException {
245    if (src == null || src.isEmpty()) return null;
246    org.hl7.fhir.dstu2.model.ElementDefinition.ElementDefinitionBaseComponent tgt = new org.hl7.fhir.dstu2.model.ElementDefinition.ElementDefinitionBaseComponent();
247    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt);
248    if (src.hasPathElement()) tgt.setPathElement(String10_30.convertString(src.getPathElement()));
249    if (src.hasMin()) tgt.setMin(src.getMin());
250    if (src.hasMaxElement()) tgt.setMaxElement(String10_30.convertString(src.getMaxElement()));
251    return tgt;
252  }
253
254  public static ElementDefinition.TypeRefComponent convertElementDefinitionTypeComponent(org.hl7.fhir.dstu2.model.ElementDefinition.TypeRefComponent src) throws FHIRException {
255    if (src == null || src.isEmpty()) return null;
256    ElementDefinition.TypeRefComponent tgt = new ElementDefinition.TypeRefComponent();
257    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt);
258    if (src.hasCodeElement()) tgt.setCodeElement(Code10_30.convertCodeToUri(src.getCodeElement()));
259    for (org.hl7.fhir.dstu2.model.UriType t : src.getProfile())
260      if (src.hasTarget()) tgt.setTargetProfile(t.getValueAsString());
261      else tgt.setProfile(t.getValue());
262    tgt.setAggregation(src.getAggregation().stream().map(ElementDefinition10_30::convertAggregationMode).collect(Collectors.toList()));
263    return tgt;
264  }
265
266  public static org.hl7.fhir.dstu2.model.ElementDefinition.TypeRefComponent convertElementDefinitionTypeComponent(ElementDefinition.TypeRefComponent src) throws FHIRException {
267    if (src == null || src.isEmpty()) return null;
268    org.hl7.fhir.dstu2.model.ElementDefinition.TypeRefComponent tgt = new org.hl7.fhir.dstu2.model.ElementDefinition.TypeRefComponent();
269    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt);
270    if (src.hasCodeElement()) tgt.setCodeElement(Code10_30.convertUriToCode(src.getCodeElement()));
271    if (src.hasTarget()) {
272      if (src.hasTargetProfile()) tgt.addProfile(src.getTargetProfile());
273    } else if (src.hasProfile()) tgt.addProfile(src.getProfile());
274    tgt.setAggregation(src.getAggregation().stream().map(ElementDefinition10_30::convertAggregationMode).collect(Collectors.toList()));
275    return tgt;
276  }
277
278  static public org.hl7.fhir.dstu3.model.Enumeration<ElementDefinition.AggregationMode> convertAggregationMode(org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.ElementDefinition.AggregationMode> src) throws FHIRException {
279    if (src == null || src.isEmpty()) return null;
280    org.hl7.fhir.dstu3.model.Enumeration<ElementDefinition.AggregationMode> tgt = new org.hl7.fhir.dstu3.model.Enumeration<>(new ElementDefinition.AggregationModeEnumFactory());
281    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt);
282    if (src.getValue() == null) {
283      tgt.setValue(ElementDefinition.AggregationMode.NULL);
284    } else {
285      switch (src.getValue()) {
286        case CONTAINED:
287          tgt.setValue(ElementDefinition.AggregationMode.CONTAINED);
288          break;
289        case REFERENCED:
290          tgt.setValue(ElementDefinition.AggregationMode.REFERENCED);
291          break;
292        case BUNDLED:
293          tgt.setValue(ElementDefinition.AggregationMode.BUNDLED);
294          break;
295        default:
296          tgt.setValue(ElementDefinition.AggregationMode.NULL);
297          break;
298      }
299    }
300    return tgt;
301  }
302
303  static public org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.ElementDefinition.AggregationMode> convertAggregationMode(org.hl7.fhir.dstu3.model.Enumeration<ElementDefinition.AggregationMode> src) throws FHIRException {
304    if (src == null || src.isEmpty()) return null;
305    org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.ElementDefinition.AggregationMode> tgt = new org.hl7.fhir.dstu2.model.Enumeration<>(new org.hl7.fhir.dstu2.model.ElementDefinition.AggregationModeEnumFactory());
306    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt);
307    if (src.getValue() == null) {
308      tgt.setValue(org.hl7.fhir.dstu2.model.ElementDefinition.AggregationMode.NULL);
309    } else {
310      switch (src.getValue()) {
311        case CONTAINED:
312          tgt.setValue(org.hl7.fhir.dstu2.model.ElementDefinition.AggregationMode.CONTAINED);
313          break;
314        case REFERENCED:
315          tgt.setValue(org.hl7.fhir.dstu2.model.ElementDefinition.AggregationMode.REFERENCED);
316          break;
317        case BUNDLED:
318          tgt.setValue(org.hl7.fhir.dstu2.model.ElementDefinition.AggregationMode.BUNDLED);
319          break;
320        default:
321          tgt.setValue(org.hl7.fhir.dstu2.model.ElementDefinition.AggregationMode.NULL);
322          break;
323      }
324    }
325    return tgt;
326  }
327
328  public static ElementDefinition.ElementDefinitionConstraintComponent convertElementDefinitionConstraintComponent(org.hl7.fhir.dstu2.model.ElementDefinition.ElementDefinitionConstraintComponent src) throws FHIRException {
329    if (src == null || src.isEmpty()) return null;
330    ElementDefinition.ElementDefinitionConstraintComponent tgt = new ElementDefinition.ElementDefinitionConstraintComponent();
331    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt);
332    if (src.hasKeyElement()) tgt.setKeyElement(Id10_30.convertId(src.getKeyElement()));
333    if (src.hasRequirementsElement())
334      tgt.setRequirementsElement(String10_30.convertString(src.getRequirementsElement()));
335    if (src.hasSeverity()) tgt.setSeverityElement(convertConstraintSeverity(src.getSeverityElement()));
336    if (src.hasHumanElement()) tgt.setHumanElement(String10_30.convertString(src.getHumanElement()));
337    tgt.setExpression(ToolingExtensions.readStringExtension(src, ToolingExtensions.EXT_EXPRESSION));
338    if (src.hasXpathElement()) tgt.setXpathElement(String10_30.convertString(src.getXpathElement()));
339    return tgt;
340  }
341
342  public static org.hl7.fhir.dstu2.model.ElementDefinition.ElementDefinitionConstraintComponent convertElementDefinitionConstraintComponent(ElementDefinition.ElementDefinitionConstraintComponent src) throws FHIRException {
343    if (src == null || src.isEmpty()) return null;
344    org.hl7.fhir.dstu2.model.ElementDefinition.ElementDefinitionConstraintComponent tgt = new org.hl7.fhir.dstu2.model.ElementDefinition.ElementDefinitionConstraintComponent();
345    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt);
346    if (src.hasKeyElement()) tgt.setKeyElement(Id10_30.convertId(src.getKeyElement()));
347    if (src.hasRequirementsElement())
348      tgt.setRequirementsElement(String10_30.convertString(src.getRequirementsElement()));
349    if (src.hasSeverity()) tgt.setSeverityElement(convertConstraintSeverity(src.getSeverityElement()));
350    if (src.hasHumanElement()) tgt.setHumanElement(String10_30.convertString(src.getHumanElement()));
351    if (src.hasExpression())
352      ToolingExtensions.addStringExtension(tgt, ToolingExtensions.EXT_EXPRESSION, src.getExpression());
353    if (src.hasXpathElement()) tgt.setXpathElement(String10_30.convertString(src.getXpathElement()));
354    return tgt;
355  }
356
357  static public org.hl7.fhir.dstu3.model.Enumeration<ElementDefinition.ConstraintSeverity> convertConstraintSeverity(org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.ElementDefinition.ConstraintSeverity> src) throws FHIRException {
358    if (src == null || src.isEmpty()) return null;
359    org.hl7.fhir.dstu3.model.Enumeration<ElementDefinition.ConstraintSeverity> tgt = new org.hl7.fhir.dstu3.model.Enumeration<>(new ElementDefinition.ConstraintSeverityEnumFactory());
360    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt);
361    if (src.getValue() == null) {
362      tgt.setValue(ElementDefinition.ConstraintSeverity.NULL);
363    } else {
364      switch (src.getValue()) {
365        case ERROR:
366          tgt.setValue(ElementDefinition.ConstraintSeverity.ERROR);
367          break;
368        case WARNING:
369          tgt.setValue(ElementDefinition.ConstraintSeverity.WARNING);
370          break;
371        default:
372          tgt.setValue(ElementDefinition.ConstraintSeverity.NULL);
373          break;
374      }
375    }
376    return tgt;
377  }
378
379  static public org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.ElementDefinition.ConstraintSeverity> convertConstraintSeverity(org.hl7.fhir.dstu3.model.Enumeration<ElementDefinition.ConstraintSeverity> src) throws FHIRException {
380    if (src == null || src.isEmpty()) return null;
381    org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.ElementDefinition.ConstraintSeverity> tgt = new org.hl7.fhir.dstu2.model.Enumeration<>(new org.hl7.fhir.dstu2.model.ElementDefinition.ConstraintSeverityEnumFactory());
382    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt);
383    if (src.getValue() == null) {
384      tgt.setValue(org.hl7.fhir.dstu2.model.ElementDefinition.ConstraintSeverity.NULL);
385    } else {
386      switch (src.getValue()) {
387        case ERROR:
388          tgt.setValue(org.hl7.fhir.dstu2.model.ElementDefinition.ConstraintSeverity.ERROR);
389          break;
390        case WARNING:
391          tgt.setValue(org.hl7.fhir.dstu2.model.ElementDefinition.ConstraintSeverity.WARNING);
392          break;
393        default:
394          tgt.setValue(org.hl7.fhir.dstu2.model.ElementDefinition.ConstraintSeverity.NULL);
395          break;
396      }
397    }
398    return tgt;
399  }
400
401  public static ElementDefinition.ElementDefinitionBindingComponent convertElementDefinitionBindingComponent(org.hl7.fhir.dstu2.model.ElementDefinition.ElementDefinitionBindingComponent src) throws FHIRException {
402    if (src == null || src.isEmpty()) return null;
403    ElementDefinition.ElementDefinitionBindingComponent tgt = new ElementDefinition.ElementDefinitionBindingComponent();
404    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt);
405    if (src.hasStrength()) tgt.setStrengthElement(convertBindingStrength(src.getStrengthElement()));
406    if (src.hasDescriptionElement()) tgt.setDescriptionElement(String10_30.convertString(src.getDescriptionElement()));
407    if (src.hasValueSet())
408      tgt.setValueSet(ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().convertType(src.getValueSet()));
409    return tgt;
410  }
411
412  public static org.hl7.fhir.dstu2.model.ElementDefinition.ElementDefinitionBindingComponent convertElementDefinitionBindingComponent(ElementDefinition.ElementDefinitionBindingComponent src) throws FHIRException {
413    if (src == null || src.isEmpty()) return null;
414    org.hl7.fhir.dstu2.model.ElementDefinition.ElementDefinitionBindingComponent tgt = new org.hl7.fhir.dstu2.model.ElementDefinition.ElementDefinitionBindingComponent();
415    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt);
416    if (src.hasStrength()) tgt.setStrengthElement(convertBindingStrength(src.getStrengthElement()));
417    if (src.hasDescriptionElement()) tgt.setDescriptionElement(String10_30.convertString(src.getDescriptionElement()));
418    if (src.hasValueSet())
419      tgt.setValueSet(ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().convertType(src.getValueSet()));
420    return tgt;
421  }
422
423  static public org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Enumerations.BindingStrength> convertBindingStrength(org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Enumerations.BindingStrength> src) throws FHIRException {
424    if (src == null || src.isEmpty()) return null;
425    org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Enumerations.BindingStrength> tgt = new org.hl7.fhir.dstu3.model.Enumeration<>(new org.hl7.fhir.dstu3.model.Enumerations.BindingStrengthEnumFactory());
426    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt);
427    if (src.getValue() == null) {
428      tgt.setValue(org.hl7.fhir.dstu3.model.Enumerations.BindingStrength.NULL);
429    } else {
430      switch (src.getValue()) {
431        case REQUIRED:
432          tgt.setValue(org.hl7.fhir.dstu3.model.Enumerations.BindingStrength.REQUIRED);
433          break;
434        case EXTENSIBLE:
435          tgt.setValue(org.hl7.fhir.dstu3.model.Enumerations.BindingStrength.EXTENSIBLE);
436          break;
437        case PREFERRED:
438          tgt.setValue(org.hl7.fhir.dstu3.model.Enumerations.BindingStrength.PREFERRED);
439          break;
440        case EXAMPLE:
441          tgt.setValue(org.hl7.fhir.dstu3.model.Enumerations.BindingStrength.EXAMPLE);
442          break;
443        default:
444          tgt.setValue(org.hl7.fhir.dstu3.model.Enumerations.BindingStrength.NULL);
445          break;
446      }
447    }
448    return tgt;
449  }
450
451  static public org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Enumerations.BindingStrength> convertBindingStrength(org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Enumerations.BindingStrength> src) throws FHIRException {
452    if (src == null || src.isEmpty()) return null;
453    org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Enumerations.BindingStrength> tgt = new org.hl7.fhir.dstu2.model.Enumeration<>(new org.hl7.fhir.dstu2.model.Enumerations.BindingStrengthEnumFactory());
454    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt);
455    if (src.getValue() == null) {
456      tgt.setValue(org.hl7.fhir.dstu2.model.Enumerations.BindingStrength.NULL);
457    } else {
458      switch (src.getValue()) {
459        case REQUIRED:
460          tgt.setValue(org.hl7.fhir.dstu2.model.Enumerations.BindingStrength.REQUIRED);
461          break;
462        case EXTENSIBLE:
463          tgt.setValue(org.hl7.fhir.dstu2.model.Enumerations.BindingStrength.EXTENSIBLE);
464          break;
465        case PREFERRED:
466          tgt.setValue(org.hl7.fhir.dstu2.model.Enumerations.BindingStrength.PREFERRED);
467          break;
468        case EXAMPLE:
469          tgt.setValue(org.hl7.fhir.dstu2.model.Enumerations.BindingStrength.EXAMPLE);
470          break;
471        default:
472          tgt.setValue(org.hl7.fhir.dstu2.model.Enumerations.BindingStrength.NULL);
473          break;
474      }
475    }
476    return tgt;
477  }
478
479  public static ElementDefinition.ElementDefinitionMappingComponent convertElementDefinitionMappingComponent(org.hl7.fhir.dstu2.model.ElementDefinition.ElementDefinitionMappingComponent src) throws FHIRException {
480    if (src == null || src.isEmpty()) return null;
481    ElementDefinition.ElementDefinitionMappingComponent tgt = new ElementDefinition.ElementDefinitionMappingComponent();
482    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt);
483    if (src.hasIdentityElement()) tgt.setIdentityElement(Id10_30.convertId(src.getIdentityElement()));
484    if (src.hasLanguageElement()) tgt.setLanguageElement(Code10_30.convertCode(src.getLanguageElement()));
485    if (src.hasMapElement()) tgt.setMapElement(String10_30.convertString(src.getMapElement()));
486    return tgt;
487  }
488
489  public static org.hl7.fhir.dstu2.model.ElementDefinition.ElementDefinitionMappingComponent convertElementDefinitionMappingComponent(ElementDefinition.ElementDefinitionMappingComponent src) throws FHIRException {
490    if (src == null || src.isEmpty()) return null;
491    org.hl7.fhir.dstu2.model.ElementDefinition.ElementDefinitionMappingComponent tgt = new org.hl7.fhir.dstu2.model.ElementDefinition.ElementDefinitionMappingComponent();
492    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt);
493    if (src.hasIdentityElement()) tgt.setIdentityElement(Id10_30.convertId(src.getIdentityElement()));
494    if (src.hasLanguageElement()) tgt.setLanguageElement(Code10_30.convertCode(src.getLanguageElement()));
495    if (src.hasMapElement()) tgt.setMapElement(String10_30.convertString(src.getMapElement()));
496    return tgt;
497  }
498}