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