001package org.hl7.fhir.convertors;
002
003import org.hl7.fhir.convertors.conv14_50.*;
004import org.hl7.fhir.dstu2016may.model.CodeableConcept;
005import org.hl7.fhir.dstu2016may.model.Reference;
006import org.hl7.fhir.exceptions.FHIRException;
007import org.hl7.fhir.r5.conformance.ProfileUtilities;
008import org.hl7.fhir.r5.model.CanonicalType;
009import org.hl7.fhir.r5.model.ConceptMap.SourceElementComponent;
010import org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionSlicingDiscriminatorComponent;
011import org.hl7.fhir.utilities.Utilities;
012
013import java.util.ArrayList;
014import java.util.Collections;
015import java.util.List;
016import java.util.stream.Collectors;
017
018/*
019  Copyright (c) 2011+, HL7, Inc.
020  All rights reserved.
021
022  Redistribution and use in source and binary forms, with or without modification,
023  are permitted provided that the following conditions are met:
024
025 * Redistributions of source code must retain the above copyright notice, this
026     list of conditions and the following disclaimer.
027 * Redistributions in binary form must reproduce the above copyright notice,
028     this list of conditions and the following disclaimer in the documentation
029     and/or other materials provided with the distribution.
030 * Neither the name of HL7 nor the names of its contributors may be used to
031     endorse or promote products derived from this software without specific
032     prior written permission.
033
034  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
035  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
036  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
037  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
038  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
039  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
040  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
041  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
042  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
043  POSSIBILITY OF SUCH DAMAGE.
044 */
045
046public class VersionConvertor_14_50 {
047  static public List<String> CANONICAL_URLS = new ArrayList<String>();
048
049  static {
050    CANONICAL_URLS.add("http://hl7.org/fhir/StructureDefinition/11179-permitted-value-conceptmap");
051    CANONICAL_URLS.add("http://hl7.org/fhir/StructureDefinition/11179-permitted-value-valueset");
052    CANONICAL_URLS.add("http://hl7.org/fhir/StructureDefinition/codesystem-map");
053    CANONICAL_URLS.add("http://hl7.org/fhir/StructureDefinition/cqif-library");
054    CANONICAL_URLS.add("http://hl7.org/fhir/StructureDefinition/elementdefinition-allowedUnits");
055    CANONICAL_URLS.add("http://hl7.org/fhir/StructureDefinition/elementdefinition-inheritedExtensibleValueSet");
056    CANONICAL_URLS.add("http://hl7.org/fhir/StructureDefinition/elementdefinition-maxValueSet");
057    CANONICAL_URLS.add("http://hl7.org/fhir/StructureDefinition/elementdefinition-minValueSet");
058    CANONICAL_URLS.add("http://hl7.org/fhir/StructureDefinition/event-instantiatesCanonical");
059    CANONICAL_URLS.add("http://hl7.org/fhir/StructureDefinition/questionnaire-allowedProfile");
060    CANONICAL_URLS.add("http://hl7.org/fhir/StructureDefinition/questionnaire-deMap");
061    CANONICAL_URLS.add("http://hl7.org/fhir/StructureDefinition/questionnaire-sourceStructureMap");
062    CANONICAL_URLS.add("http://hl7.org/fhir/StructureDefinition/questionnaire-targetStructureMap");
063    CANONICAL_URLS.add("http://hl7.org/fhir/StructureDefinition/questionnaire-unit-valueSet");
064    CANONICAL_URLS.add("http://hl7.org/fhir/StructureDefinition/valueset-map");
065    CANONICAL_URLS.add("http://hl7.org/fhir/StructureDefinition/valueset-supplement");
066    CANONICAL_URLS.add("http://hl7.org/fhir/StructureDefinition/valueset-system");
067  }
068
069  static public boolean mappedExtension(String url) {
070    if (url.equals(VersionConvertorConstants.PROFILE_EXTENSION) || url.equals(VersionConvertorConstants.IG_DEPENDSON_PACKAGE_EXTENSION) || url.equals(VersionConvertorConstants.IG_DEPENDSON_VERSION_EXTENSION) || url.equals(VersionConvertorConstants.IG_CONFORMANCE_MESSAGE_EVENT))
071      return true;
072    return false;
073  }
074
075  static public void copyElement(org.hl7.fhir.dstu2016may.model.Element src, org.hl7.fhir.r5.model.Element tgt, String... exemptExtensions) throws FHIRException {
076    if (src.hasId()) tgt.setId(src.getId());
077    for (org.hl7.fhir.dstu2016may.model.Extension e : src.getExtension()) {
078      if (!Utilities.existsInList(e.getUrl(), exemptExtensions) && !mappedExtension(e.getUrl().toString()))
079        tgt.addExtension(convertExtension(e));
080    }
081  }
082
083  static public void copyElement(org.hl7.fhir.r5.model.Element src, org.hl7.fhir.dstu2016may.model.Element tgt, String... exemptExtensions) throws FHIRException {
084    if (src.hasId()) tgt.setId(src.getId());
085    for (org.hl7.fhir.r5.model.Extension e : src.getExtension()) {
086      if (!Utilities.existsInList(e.getUrl(), exemptExtensions)) {
087        tgt.addExtension(convertExtension(e));
088      }
089    }
090  }
091
092  static public void copyBackboneElement(org.hl7.fhir.dstu2016may.model.BackboneElement src, org.hl7.fhir.r5.model.BackboneElement tgt) throws FHIRException {
093    copyElement(src, tgt);
094    for (org.hl7.fhir.dstu2016may.model.Extension e : src.getModifierExtension()) {
095      tgt.addModifierExtension(convertExtension(e));
096    }
097  }
098
099  static public void copyBackboneElement(org.hl7.fhir.r5.model.BackboneElement src, org.hl7.fhir.dstu2016may.model.BackboneElement tgt) throws FHIRException {
100    copyElement(src, tgt);
101    for (org.hl7.fhir.r5.model.Extension e : src.getModifierExtension()) {
102      tgt.addModifierExtension(convertExtension(e));
103    }
104  }
105
106  public static org.hl7.fhir.r5.model.Base64BinaryType convertBase64Binary(org.hl7.fhir.dstu2016may.model.Base64BinaryType src) throws FHIRException {
107    org.hl7.fhir.r5.model.Base64BinaryType tgt = new org.hl7.fhir.r5.model.Base64BinaryType();
108    if (src.hasValue()) tgt.setValue(src.getValue());
109    copyElement(src, tgt);
110    return tgt;
111  }
112
113  public static org.hl7.fhir.dstu2016may.model.Base64BinaryType convertBase64Binary(org.hl7.fhir.r5.model.Base64BinaryType src) throws FHIRException {
114    org.hl7.fhir.dstu2016may.model.Base64BinaryType tgt = new org.hl7.fhir.dstu2016may.model.Base64BinaryType();
115    if (src.hasValue()) tgt.setValue(src.getValue());
116    copyElement(src, tgt);
117    return tgt;
118  }
119
120  public static org.hl7.fhir.r5.model.BooleanType convertBoolean(org.hl7.fhir.dstu2016may.model.BooleanType src) throws FHIRException {
121    org.hl7.fhir.r5.model.BooleanType tgt = new org.hl7.fhir.r5.model.BooleanType();
122    if (src.hasValue()) tgt.setValue(src.getValue());
123    copyElement(src, tgt);
124    return tgt;
125  }
126
127  public static org.hl7.fhir.dstu2016may.model.BooleanType convertBoolean(org.hl7.fhir.r5.model.BooleanType src) throws FHIRException {
128    org.hl7.fhir.dstu2016may.model.BooleanType tgt = new org.hl7.fhir.dstu2016may.model.BooleanType();
129    if (src.hasValue()) tgt.setValue(src.getValue());
130    copyElement(src, tgt);
131    return tgt;
132  }
133
134  public static org.hl7.fhir.r5.model.CodeType convertCode(org.hl7.fhir.dstu2016may.model.CodeType src) throws FHIRException {
135    org.hl7.fhir.r5.model.CodeType tgt = new org.hl7.fhir.r5.model.CodeType();
136    if (src.hasValue()) tgt.setValue(src.getValue());
137    copyElement(src, tgt);
138    return tgt;
139  }
140
141  public static org.hl7.fhir.dstu2016may.model.CodeType convertCode(org.hl7.fhir.r5.model.CodeType src) throws FHIRException {
142    org.hl7.fhir.dstu2016may.model.CodeType tgt = new org.hl7.fhir.dstu2016may.model.CodeType();
143    if (src.hasValue()) tgt.setValue(src.getValue());
144    copyElement(src, tgt);
145    return tgt;
146  }
147
148  public static org.hl7.fhir.r5.model.DateType convertDate(org.hl7.fhir.dstu2016may.model.DateType src) throws FHIRException {
149    org.hl7.fhir.r5.model.DateType tgt = new org.hl7.fhir.r5.model.DateType();
150    if (src.hasValue()) tgt.setValue(src.getValue());
151    copyElement(src, tgt);
152    return tgt;
153  }
154
155  public static org.hl7.fhir.dstu2016may.model.DateType convertDate(org.hl7.fhir.r5.model.DateType src) throws FHIRException {
156    org.hl7.fhir.dstu2016may.model.DateType tgt = new org.hl7.fhir.dstu2016may.model.DateType();
157    if (src.hasValue()) tgt.setValue(src.getValue());
158    copyElement(src, tgt);
159    return tgt;
160  }
161
162  public static org.hl7.fhir.r5.model.DateTimeType convertDateTime(org.hl7.fhir.dstu2016may.model.DateTimeType src) throws FHIRException {
163    org.hl7.fhir.r5.model.DateTimeType tgt = new org.hl7.fhir.r5.model.DateTimeType();
164    if (src.hasValue()) tgt.setValue(src.getValue());
165    copyElement(src, tgt);
166    return tgt;
167  }
168
169  public static org.hl7.fhir.dstu2016may.model.DateTimeType convertDateTime(org.hl7.fhir.r5.model.DateTimeType src) throws FHIRException {
170    org.hl7.fhir.dstu2016may.model.DateTimeType tgt = new org.hl7.fhir.dstu2016may.model.DateTimeType();
171    if (src.hasValue()) tgt.setValue(src.getValue());
172    copyElement(src, tgt);
173    return tgt;
174  }
175
176  public static org.hl7.fhir.r5.model.DecimalType convertDecimal(org.hl7.fhir.dstu2016may.model.DecimalType src) throws FHIRException {
177    org.hl7.fhir.r5.model.DecimalType tgt = new org.hl7.fhir.r5.model.DecimalType();
178    if (src.hasValue()) tgt.setValue(src.getValue());
179    copyElement(src, tgt);
180    return tgt;
181  }
182
183  public static org.hl7.fhir.dstu2016may.model.DecimalType convertDecimal(org.hl7.fhir.r5.model.DecimalType src) throws FHIRException {
184    org.hl7.fhir.dstu2016may.model.DecimalType tgt = new org.hl7.fhir.dstu2016may.model.DecimalType();
185    if (src.hasValue()) tgt.setValue(src.getValue());
186    copyElement(src, tgt);
187    return tgt;
188  }
189
190  public static org.hl7.fhir.r5.model.IdType convertId(org.hl7.fhir.dstu2016may.model.IdType src) throws FHIRException {
191    org.hl7.fhir.r5.model.IdType tgt = new org.hl7.fhir.r5.model.IdType();
192    if (src.hasValue()) tgt.setValue(src.getValue());
193    copyElement(src, tgt);
194    return tgt;
195  }
196
197  public static org.hl7.fhir.dstu2016may.model.IdType convertId(org.hl7.fhir.r5.model.IdType src) throws FHIRException {
198    org.hl7.fhir.dstu2016may.model.IdType tgt = new org.hl7.fhir.dstu2016may.model.IdType();
199    if (src.hasValue()) tgt.setValue(src.getValue());
200    copyElement(src, tgt);
201    return tgt;
202  }
203
204  public static org.hl7.fhir.r5.model.InstantType convertInstant(org.hl7.fhir.dstu2016may.model.InstantType src) throws FHIRException {
205    org.hl7.fhir.r5.model.InstantType tgt = new org.hl7.fhir.r5.model.InstantType();
206    if (src.hasValue()) tgt.setValue(src.getValue());
207    copyElement(src, tgt);
208    return tgt;
209  }
210
211  public static org.hl7.fhir.dstu2016may.model.InstantType convertInstant(org.hl7.fhir.r5.model.InstantType src) throws FHIRException {
212    org.hl7.fhir.dstu2016may.model.InstantType tgt = new org.hl7.fhir.dstu2016may.model.InstantType();
213    if (src.hasValue()) tgt.setValue(src.getValue());
214    copyElement(src, tgt);
215    return tgt;
216  }
217
218  public static org.hl7.fhir.r5.model.IntegerType convertInteger(org.hl7.fhir.dstu2016may.model.IntegerType src) throws FHIRException {
219    org.hl7.fhir.r5.model.IntegerType tgt = new org.hl7.fhir.r5.model.IntegerType();
220    if (src.hasValue()) tgt.setValue(src.getValue());
221    copyElement(src, tgt);
222    return tgt;
223  }
224
225  public static org.hl7.fhir.dstu2016may.model.IntegerType convertInteger(org.hl7.fhir.r5.model.IntegerType src) throws FHIRException {
226    org.hl7.fhir.dstu2016may.model.IntegerType tgt = new org.hl7.fhir.dstu2016may.model.IntegerType();
227    if (src.hasValue()) tgt.setValue(src.getValue());
228    copyElement(src, tgt);
229    return tgt;
230  }
231
232  public static org.hl7.fhir.r5.model.MarkdownType convertMarkdown(org.hl7.fhir.dstu2016may.model.MarkdownType src) throws FHIRException {
233    org.hl7.fhir.r5.model.MarkdownType tgt = new org.hl7.fhir.r5.model.MarkdownType();
234    if (src.hasValue()) tgt.setValue(src.getValue());
235    copyElement(src, tgt);
236    return tgt;
237  }
238
239  public static org.hl7.fhir.dstu2016may.model.MarkdownType convertMarkdown(org.hl7.fhir.r5.model.MarkdownType src) throws FHIRException {
240    org.hl7.fhir.dstu2016may.model.MarkdownType tgt = new org.hl7.fhir.dstu2016may.model.MarkdownType();
241    if (src.hasValue()) tgt.setValue(src.getValue());
242    copyElement(src, tgt);
243    return tgt;
244  }
245
246  public static org.hl7.fhir.r5.model.OidType convertOid(org.hl7.fhir.dstu2016may.model.OidType src) throws FHIRException {
247    org.hl7.fhir.r5.model.OidType tgt = new org.hl7.fhir.r5.model.OidType();
248    if (src.hasValue()) tgt.setValue(src.getValue());
249    copyElement(src, tgt);
250    return tgt;
251  }
252
253  public static org.hl7.fhir.dstu2016may.model.OidType convertOid(org.hl7.fhir.r5.model.OidType src) throws FHIRException {
254    org.hl7.fhir.dstu2016may.model.OidType tgt = new org.hl7.fhir.dstu2016may.model.OidType();
255    if (src.hasValue()) tgt.setValue(src.getValue());
256    copyElement(src, tgt);
257    return tgt;
258  }
259
260  public static org.hl7.fhir.r5.model.PositiveIntType convertPositiveInt(org.hl7.fhir.dstu2016may.model.PositiveIntType src) throws FHIRException {
261    org.hl7.fhir.r5.model.PositiveIntType tgt = new org.hl7.fhir.r5.model.PositiveIntType();
262    if (src.hasValue()) tgt.setValue(src.getValue());
263    copyElement(src, tgt);
264    return tgt;
265  }
266
267  public static org.hl7.fhir.dstu2016may.model.PositiveIntType convertPositiveInt(org.hl7.fhir.r5.model.PositiveIntType src) throws FHIRException {
268    org.hl7.fhir.dstu2016may.model.PositiveIntType tgt = new org.hl7.fhir.dstu2016may.model.PositiveIntType();
269    if (src.hasValue()) tgt.setValue(src.getValue());
270    copyElement(src, tgt);
271    return tgt;
272  }
273
274  public static org.hl7.fhir.r5.model.StringType convertString(org.hl7.fhir.dstu2016may.model.StringType src) throws FHIRException {
275    org.hl7.fhir.r5.model.StringType tgt = new org.hl7.fhir.r5.model.StringType();
276    if (src.hasValue()) tgt.setValue(src.getValue());
277    copyElement(src, tgt);
278    return tgt;
279  }
280
281  public static org.hl7.fhir.dstu2016may.model.StringType convertString(org.hl7.fhir.r5.model.StringType src) throws FHIRException {
282    org.hl7.fhir.dstu2016may.model.StringType tgt = new org.hl7.fhir.dstu2016may.model.StringType();
283    if (src.hasValue()) tgt.setValue(src.getValue());
284    copyElement(src, tgt);
285    return tgt;
286  }
287
288  public static org.hl7.fhir.r5.model.TimeType convertTime(org.hl7.fhir.dstu2016may.model.TimeType src) throws FHIRException {
289    org.hl7.fhir.r5.model.TimeType tgt = new org.hl7.fhir.r5.model.TimeType();
290    if (src.hasValue()) tgt.setValue(src.getValue());
291    copyElement(src, tgt);
292    return tgt;
293  }
294
295  public static org.hl7.fhir.dstu2016may.model.TimeType convertTime(org.hl7.fhir.r5.model.TimeType src) throws FHIRException {
296    org.hl7.fhir.dstu2016may.model.TimeType tgt = new org.hl7.fhir.dstu2016may.model.TimeType();
297    if (src.hasValue()) tgt.setValue(src.getValue());
298    copyElement(src, tgt);
299    return tgt;
300  }
301
302  public static org.hl7.fhir.r5.model.UnsignedIntType convertUnsignedInt(org.hl7.fhir.dstu2016may.model.UnsignedIntType src) throws FHIRException {
303    org.hl7.fhir.r5.model.UnsignedIntType tgt = new org.hl7.fhir.r5.model.UnsignedIntType();
304    if (src.hasValue()) tgt.setValue(src.getValue());
305    copyElement(src, tgt);
306    return tgt;
307  }
308
309  public static org.hl7.fhir.dstu2016may.model.UnsignedIntType convertUnsignedInt(org.hl7.fhir.r5.model.UnsignedIntType src) throws FHIRException {
310    org.hl7.fhir.dstu2016may.model.UnsignedIntType tgt = new org.hl7.fhir.dstu2016may.model.UnsignedIntType();
311    if (src.hasValue()) tgt.setValue(src.getValue());
312    copyElement(src, tgt);
313    return tgt;
314  }
315
316  public static org.hl7.fhir.r5.model.UriType convertUri(org.hl7.fhir.dstu2016may.model.UriType src) throws FHIRException {
317    org.hl7.fhir.r5.model.UriType tgt = new org.hl7.fhir.r5.model.UriType();
318    if (src.hasValue()) tgt.setValue(src.getValue());
319    copyElement(src, tgt);
320    return tgt;
321  }
322
323  public static org.hl7.fhir.dstu2016may.model.UriType convertUri(org.hl7.fhir.r5.model.UriType src) throws FHIRException {
324    org.hl7.fhir.dstu2016may.model.UriType tgt = new org.hl7.fhir.dstu2016may.model.UriType();
325    if (src.hasValue()) tgt.setValue(src.getValue());
326    copyElement(src, tgt);
327    return tgt;
328  }
329
330  public static org.hl7.fhir.r5.model.UuidType convertUuid(org.hl7.fhir.dstu2016may.model.UuidType src) throws FHIRException {
331    org.hl7.fhir.r5.model.UuidType tgt = new org.hl7.fhir.r5.model.UuidType();
332    if (src.hasValue()) tgt.setValue(src.getValue());
333    copyElement(src, tgt);
334    return tgt;
335  }
336
337  public static org.hl7.fhir.dstu2016may.model.UuidType convertUuid(org.hl7.fhir.r5.model.UuidType src) throws FHIRException {
338    org.hl7.fhir.dstu2016may.model.UuidType tgt = new org.hl7.fhir.dstu2016may.model.UuidType();
339    if (src.hasValue()) tgt.setValue(src.getValue());
340    copyElement(src, tgt);
341    return tgt;
342  }
343
344  public static org.hl7.fhir.r5.model.Extension convertExtension(org.hl7.fhir.dstu2016may.model.Extension src) throws FHIRException {
345    if (src == null || src.isEmpty()) return null;
346    org.hl7.fhir.r5.model.Extension tgt = new org.hl7.fhir.r5.model.Extension();
347    copyElement(src, tgt);
348    if (src.hasUrlElement()) tgt.setUrlElement(convertUri(src.getUrlElement()));
349    if (src.hasValue())
350      if (CANONICAL_URLS.contains(src.getUrl()) && src.getValue() instanceof org.hl7.fhir.dstu2016may.model.Reference)
351        tgt.setValue(convertReferenceToCanonical((Reference) src.getValue()));
352      else tgt.setValue(convertType(src.getValue()));
353    return tgt;
354  }
355
356  public static org.hl7.fhir.dstu2016may.model.Extension convertExtension(org.hl7.fhir.r5.model.Extension src) throws FHIRException {
357    if (src == null || src.isEmpty()) return null;
358    org.hl7.fhir.dstu2016may.model.Extension tgt = new org.hl7.fhir.dstu2016may.model.Extension();
359    copyElement(src, tgt);
360    if (src.hasUrlElement()) tgt.setUrlElement(convertUri(src.getUrlElement()));
361    if (src.hasValue())
362      if (CANONICAL_URLS.contains(src.getUrl()) && src.getValue() instanceof org.hl7.fhir.r5.model.CanonicalType)
363        tgt.setValue(convertCanonicalToReference((CanonicalType) src.getValue()));
364      else tgt.setValue(convertType(src.getValue()));
365    return tgt;
366  }
367
368  public static org.hl7.fhir.r5.model.Narrative convertNarrative(org.hl7.fhir.dstu2016may.model.Narrative src) throws FHIRException {
369    if (src == null || src.isEmpty()) return null;
370    org.hl7.fhir.r5.model.Narrative tgt = new org.hl7.fhir.r5.model.Narrative();
371    copyElement(src, tgt);
372    if (src.hasStatus()) tgt.setStatusElement(convertNarrativeStatus(src.getStatusElement()));
373    if (src.hasDiv()) tgt.setDiv(src.getDiv());
374    return tgt;
375  }
376
377  public static org.hl7.fhir.dstu2016may.model.Narrative convertNarrative(org.hl7.fhir.r5.model.Narrative src) throws FHIRException {
378    if (src == null || src.isEmpty()) return null;
379    org.hl7.fhir.dstu2016may.model.Narrative tgt = new org.hl7.fhir.dstu2016may.model.Narrative();
380    copyElement(src, tgt);
381    if (src.hasStatus()) tgt.setStatusElement(convertNarrativeStatus(src.getStatusElement()));
382    if (src.hasDiv()) tgt.setDiv(src.getDiv());
383    return tgt;
384  }
385
386  static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Narrative.NarrativeStatus> convertNarrativeStatus(org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.Narrative.NarrativeStatus> src) throws FHIRException {
387    if (src == null || src.isEmpty()) return null;
388    org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Narrative.NarrativeStatus> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.Narrative.NarrativeStatusEnumFactory());
389    VersionConvertor_14_50.copyElement(src, tgt);
390    if (src.getValue() == null) {
391      tgt.setValue(org.hl7.fhir.r5.model.Narrative.NarrativeStatus.NULL);
392    } else {
393      switch (src.getValue()) {
394        case GENERATED:
395          tgt.setValue(org.hl7.fhir.r5.model.Narrative.NarrativeStatus.GENERATED);
396          break;
397        case EXTENSIONS:
398          tgt.setValue(org.hl7.fhir.r5.model.Narrative.NarrativeStatus.EXTENSIONS);
399          break;
400        case ADDITIONAL:
401          tgt.setValue(org.hl7.fhir.r5.model.Narrative.NarrativeStatus.ADDITIONAL);
402          break;
403        case EMPTY:
404          tgt.setValue(org.hl7.fhir.r5.model.Narrative.NarrativeStatus.EMPTY);
405          break;
406        default:
407          tgt.setValue(org.hl7.fhir.r5.model.Narrative.NarrativeStatus.NULL);
408          break;
409      }
410    }
411    return tgt;
412  }
413
414  static public org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.Narrative.NarrativeStatus> convertNarrativeStatus(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Narrative.NarrativeStatus> src) throws FHIRException {
415    if (src == null || src.isEmpty()) return null;
416    org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.Narrative.NarrativeStatus> tgt = new org.hl7.fhir.dstu2016may.model.Enumeration<>(new org.hl7.fhir.dstu2016may.model.Narrative.NarrativeStatusEnumFactory());
417    VersionConvertor_14_50.copyElement(src, tgt);
418    if (src.getValue() == null) {
419      tgt.setValue(org.hl7.fhir.dstu2016may.model.Narrative.NarrativeStatus.NULL);
420    } else {
421      switch (src.getValue()) {
422        case GENERATED:
423          tgt.setValue(org.hl7.fhir.dstu2016may.model.Narrative.NarrativeStatus.GENERATED);
424          break;
425        case EXTENSIONS:
426          tgt.setValue(org.hl7.fhir.dstu2016may.model.Narrative.NarrativeStatus.EXTENSIONS);
427          break;
428        case ADDITIONAL:
429          tgt.setValue(org.hl7.fhir.dstu2016may.model.Narrative.NarrativeStatus.ADDITIONAL);
430          break;
431        case EMPTY:
432          tgt.setValue(org.hl7.fhir.dstu2016may.model.Narrative.NarrativeStatus.EMPTY);
433          break;
434        default:
435          tgt.setValue(org.hl7.fhir.dstu2016may.model.Narrative.NarrativeStatus.NULL);
436          break;
437      }
438    }
439    return tgt;
440  }
441
442  public static org.hl7.fhir.r5.model.Age convertAge(org.hl7.fhir.dstu2016may.model.Age src) throws FHIRException {
443    if (src == null || src.isEmpty()) return null;
444    org.hl7.fhir.r5.model.Age tgt = new org.hl7.fhir.r5.model.Age();
445    copyElement(src, tgt);
446    if (src.hasValue()) tgt.setValueElement(convertDecimal(src.getValueElement()));
447    if (src.hasComparator()) tgt.setComparatorElement(convertQuantityComparator(src.getComparatorElement()));
448    if (src.hasUnit()) tgt.setUnitElement(convertString(src.getUnitElement()));
449    if (src.hasSystem()) tgt.setSystemElement(convertUri(src.getSystemElement()));
450    if (src.hasCode()) tgt.setCodeElement(convertCode(src.getCodeElement()));
451    return tgt;
452  }
453
454  public static org.hl7.fhir.dstu2016may.model.Age convertAge(org.hl7.fhir.r5.model.Age src) throws FHIRException {
455    if (src == null || src.isEmpty()) return null;
456    org.hl7.fhir.dstu2016may.model.Age tgt = new org.hl7.fhir.dstu2016may.model.Age();
457    copyElement(src, tgt);
458    if (src.hasValue()) tgt.setValueElement(convertDecimal(src.getValueElement()));
459    if (src.hasComparator()) tgt.setComparatorElement(convertQuantityComparator(src.getComparatorElement()));
460    if (src.hasUnit()) tgt.setUnitElement(convertString(src.getUnitElement()));
461    if (src.hasSystem()) tgt.setSystemElement(convertUri(src.getSystemElement()));
462    if (src.hasCode()) tgt.setCodeElement(convertCode(src.getCodeElement()));
463    return tgt;
464  }
465
466  public static org.hl7.fhir.r5.model.Annotation convertAnnotation(org.hl7.fhir.dstu2016may.model.Annotation src) throws FHIRException {
467    if (src == null || src.isEmpty()) return null;
468    org.hl7.fhir.r5.model.Annotation tgt = new org.hl7.fhir.r5.model.Annotation();
469    copyElement(src, tgt);
470    if (src.hasAuthor()) tgt.setAuthor(convertType(src.getAuthor()));
471    if (src.hasTime()) tgt.setTimeElement(convertDateTime(src.getTimeElement()));
472    tgt.setText(src.getText());
473    return tgt;
474  }
475
476  public static org.hl7.fhir.dstu2016may.model.Annotation convertAnnotation(org.hl7.fhir.r5.model.Annotation src) throws FHIRException {
477    if (src == null || src.isEmpty()) return null;
478    org.hl7.fhir.dstu2016may.model.Annotation tgt = new org.hl7.fhir.dstu2016may.model.Annotation();
479    copyElement(src, tgt);
480    if (src.hasAuthor()) tgt.setAuthor(convertType(src.getAuthor()));
481    if (src.hasTime()) tgt.setTimeElement(convertDateTime(src.getTimeElement()));
482    tgt.setText(src.getText());
483    return tgt;
484  }
485
486  public static org.hl7.fhir.r5.model.Attachment convertAttachment(org.hl7.fhir.dstu2016may.model.Attachment src) throws FHIRException {
487    if (src == null || src.isEmpty()) return null;
488    org.hl7.fhir.r5.model.Attachment tgt = new org.hl7.fhir.r5.model.Attachment();
489    copyElement(src, tgt);
490    if (src.hasContentType()) tgt.setContentTypeElement(convertCode(src.getContentTypeElement()));
491    if (src.hasLanguage()) tgt.setLanguageElement(convertCode(src.getLanguageElement()));
492    if (src.hasData()) tgt.setDataElement(convertBase64Binary(src.getDataElement()));
493    if (src.hasUrl()) tgt.setUrl(src.getUrl());
494    if (src.hasSize()) tgt.setSize(Long.valueOf(src.getSize()));
495    if (src.hasHash()) tgt.setHashElement(convertBase64Binary(src.getHashElement()));
496    if (src.hasTitle()) tgt.setTitleElement(convertString(src.getTitleElement()));
497    if (src.hasCreation()) tgt.setCreationElement(convertDateTime(src.getCreationElement()));
498    return tgt;
499  }
500
501  public static org.hl7.fhir.dstu2016may.model.Attachment convertAttachment(org.hl7.fhir.r5.model.Attachment src) throws FHIRException {
502    if (src == null || src.isEmpty()) return null;
503    org.hl7.fhir.dstu2016may.model.Attachment tgt = new org.hl7.fhir.dstu2016may.model.Attachment();
504    copyElement(src, tgt);
505    if (src.hasContentType()) tgt.setContentTypeElement(convertCode(src.getContentTypeElement()));
506    if (src.hasLanguage()) tgt.setLanguageElement(convertCode(src.getLanguageElement()));
507    if (src.hasData()) tgt.setDataElement(convertBase64Binary(src.getDataElement()));
508    if (src.hasUrl()) tgt.setUrl(src.getUrl());
509    if (src.hasSize()) tgt.setSize(Math.toIntExact(src.getSize()));
510    if (src.hasHash()) tgt.setHashElement(convertBase64Binary(src.getHashElement()));
511    if (src.hasTitle()) tgt.setTitleElement(convertString(src.getTitleElement()));
512    if (src.hasCreation()) tgt.setCreationElement(convertDateTime(src.getCreationElement()));
513    return tgt;
514  }
515
516  public static org.hl7.fhir.r5.model.CodeableConcept convertCodeableConcept(org.hl7.fhir.dstu2016may.model.CodeableConcept src) throws FHIRException {
517    if (src == null || src.isEmpty()) return null;
518    org.hl7.fhir.r5.model.CodeableConcept tgt = new org.hl7.fhir.r5.model.CodeableConcept();
519    copyElement(src, tgt);
520    for (org.hl7.fhir.dstu2016may.model.Coding t : src.getCoding()) tgt.addCoding(convertCoding(t));
521    if (src.hasText()) tgt.setTextElement(convertString(src.getTextElement()));
522    return tgt;
523  }
524
525  public static org.hl7.fhir.dstu2016may.model.CodeableConcept convertCodeableConcept(org.hl7.fhir.r5.model.CodeableConcept src) throws FHIRException {
526    if (src == null || src.isEmpty()) return null;
527    org.hl7.fhir.dstu2016may.model.CodeableConcept tgt = new org.hl7.fhir.dstu2016may.model.CodeableConcept();
528    copyElement(src, tgt);
529    for (org.hl7.fhir.r5.model.Coding t : src.getCoding()) tgt.addCoding(convertCoding(t));
530    if (src.hasText()) tgt.setTextElement(convertString(src.getTextElement()));
531    return tgt;
532  }
533
534  public static org.hl7.fhir.r5.model.Coding convertCoding(org.hl7.fhir.dstu2016may.model.Coding src) throws FHIRException {
535    if (src == null || src.isEmpty()) return null;
536    org.hl7.fhir.r5.model.Coding tgt = new org.hl7.fhir.r5.model.Coding();
537    copyElement(src, tgt);
538    if (src.hasSystem()) tgt.setSystemElement(convertUri(src.getSystemElement()));
539    if (src.hasVersion()) tgt.setVersionElement(convertString(src.getVersionElement()));
540    if (src.hasCode()) tgt.setCodeElement(convertCode(src.getCodeElement()));
541    if (src.hasDisplay()) tgt.setDisplayElement(convertString(src.getDisplayElement()));
542    if (src.hasUserSelected()) tgt.setUserSelectedElement(convertBoolean(src.getUserSelectedElement()));
543    return tgt;
544  }
545
546  public static org.hl7.fhir.dstu2016may.model.Coding convertCoding(org.hl7.fhir.r5.model.Coding src) throws FHIRException {
547    if (src == null || src.isEmpty()) return null;
548    org.hl7.fhir.dstu2016may.model.Coding tgt = new org.hl7.fhir.dstu2016may.model.Coding();
549    copyElement(src, tgt);
550    if (src.hasSystem()) tgt.setSystemElement(convertUri(src.getSystemElement()));
551    if (src.hasVersion()) tgt.setVersionElement(convertString(src.getVersionElement()));
552    if (src.hasCode()) tgt.setCodeElement(convertCode(src.getCodeElement()));
553    if (src.hasDisplay()) tgt.setDisplayElement(convertString(src.getDisplayElement()));
554    if (src.hasUserSelected()) tgt.setUserSelectedElement(convertBoolean(src.getUserSelectedElement()));
555    return tgt;
556  }
557
558  public static org.hl7.fhir.r5.model.Count convertCount(org.hl7.fhir.dstu2016may.model.Count src) throws FHIRException {
559    if (src == null || src.isEmpty()) return null;
560    org.hl7.fhir.r5.model.Count tgt = new org.hl7.fhir.r5.model.Count();
561    copyElement(src, tgt);
562    if (src.hasValue()) tgt.setValueElement(convertDecimal(src.getValueElement()));
563    if (src.hasComparator()) tgt.setComparatorElement(convertQuantityComparator(src.getComparatorElement()));
564    if (src.hasUnit()) tgt.setUnitElement(convertString(src.getUnitElement()));
565    if (src.hasSystem()) tgt.setSystemElement(convertUri(src.getSystemElement()));
566    if (src.hasCode()) tgt.setCodeElement(convertCode(src.getCodeElement()));
567    return tgt;
568  }
569
570  public static org.hl7.fhir.dstu2016may.model.Count convertCount(org.hl7.fhir.r5.model.Count src) throws FHIRException {
571    if (src == null || src.isEmpty()) return null;
572    org.hl7.fhir.dstu2016may.model.Count tgt = new org.hl7.fhir.dstu2016may.model.Count();
573    copyElement(src, tgt);
574    if (src.hasValue()) tgt.setValueElement(convertDecimal(src.getValueElement()));
575    if (src.hasComparator()) tgt.setComparatorElement(convertQuantityComparator(src.getComparatorElement()));
576    if (src.hasUnit()) tgt.setUnitElement(convertString(src.getUnitElement()));
577    if (src.hasSystem()) tgt.setSystemElement(convertUri(src.getSystemElement()));
578    if (src.hasCode()) tgt.setCodeElement(convertCode(src.getCodeElement()));
579    return tgt;
580  }
581
582  public static org.hl7.fhir.r5.model.Distance convertDistance(org.hl7.fhir.dstu2016may.model.Distance src) throws FHIRException {
583    if (src == null || src.isEmpty()) return null;
584    org.hl7.fhir.r5.model.Distance tgt = new org.hl7.fhir.r5.model.Distance();
585    copyElement(src, tgt);
586    if (src.hasValue()) tgt.setValueElement(convertDecimal(src.getValueElement()));
587    if (src.hasComparator()) tgt.setComparatorElement(convertQuantityComparator(src.getComparatorElement()));
588    if (src.hasUnit()) tgt.setUnitElement(convertString(src.getUnitElement()));
589    if (src.hasSystem()) tgt.setSystemElement(convertUri(src.getSystemElement()));
590    if (src.hasCode()) tgt.setCodeElement(convertCode(src.getCodeElement()));
591    return tgt;
592  }
593
594  public static org.hl7.fhir.dstu2016may.model.Distance convertDistance(org.hl7.fhir.r5.model.Distance src) throws FHIRException {
595    if (src == null || src.isEmpty()) return null;
596    org.hl7.fhir.dstu2016may.model.Distance tgt = new org.hl7.fhir.dstu2016may.model.Distance();
597    copyElement(src, tgt);
598    if (src.hasValue()) tgt.setValueElement(convertDecimal(src.getValueElement()));
599    if (src.hasComparator()) tgt.setComparatorElement(convertQuantityComparator(src.getComparatorElement()));
600    if (src.hasUnit()) tgt.setUnitElement(convertString(src.getUnitElement()));
601    if (src.hasSystem()) tgt.setSystemElement(convertUri(src.getSystemElement()));
602    if (src.hasCode()) tgt.setCodeElement(convertCode(src.getCodeElement()));
603    return tgt;
604  }
605
606  public static org.hl7.fhir.r5.model.Duration convertDuration(org.hl7.fhir.dstu2016may.model.Duration src) throws FHIRException {
607    if (src == null || src.isEmpty()) return null;
608    org.hl7.fhir.r5.model.Duration tgt = new org.hl7.fhir.r5.model.Duration();
609    copyElement(src, tgt);
610    if (src.hasValue()) tgt.setValueElement(convertDecimal(src.getValueElement()));
611    if (src.hasComparator()) tgt.setComparatorElement(convertQuantityComparator(src.getComparatorElement()));
612    if (src.hasUnit()) tgt.setUnitElement(convertString(src.getUnitElement()));
613    if (src.hasSystem()) tgt.setSystemElement(convertUri(src.getSystemElement()));
614    if (src.hasCode()) tgt.setCodeElement(convertCode(src.getCodeElement()));
615    return tgt;
616  }
617
618  public static org.hl7.fhir.dstu2016may.model.Duration convertDuration(org.hl7.fhir.r5.model.Duration src) throws FHIRException {
619    if (src == null || src.isEmpty()) return null;
620    org.hl7.fhir.dstu2016may.model.Duration tgt = new org.hl7.fhir.dstu2016may.model.Duration();
621    copyElement(src, tgt);
622    if (src.hasValue()) tgt.setValueElement(convertDecimal(src.getValueElement()));
623    if (src.hasComparator()) tgt.setComparatorElement(convertQuantityComparator(src.getComparatorElement()));
624    if (src.hasUnit()) tgt.setUnitElement(convertString(src.getUnitElement()));
625    if (src.hasSystem()) tgt.setSystemElement(convertUri(src.getSystemElement()));
626    if (src.hasCode()) tgt.setCodeElement(convertCode(src.getCodeElement()));
627    return tgt;
628  }
629
630  public static org.hl7.fhir.r5.model.Money convertMoney(org.hl7.fhir.dstu2016may.model.Money src) throws FHIRException {
631    if (src == null || src.isEmpty()) return null;
632    org.hl7.fhir.r5.model.Money tgt = new org.hl7.fhir.r5.model.Money();
633    copyElement(src, tgt);
634    if (src.hasValue()) tgt.setValueElement(convertDecimal(src.getValueElement()));
635    if (src.hasCode()) tgt.setCurrencyElement(convertCode(src.getCodeElement()));
636    return tgt;
637  }
638
639  public static org.hl7.fhir.dstu2016may.model.Money convertMoney(org.hl7.fhir.r5.model.Money src) throws FHIRException {
640    if (src == null || src.isEmpty()) return null;
641    org.hl7.fhir.dstu2016may.model.Money tgt = new org.hl7.fhir.dstu2016may.model.Money();
642    copyElement(src, tgt);
643    if (src.hasValue()) tgt.setValueElement(convertDecimal(src.getValueElement()));
644    if (src.hasCurrency()) tgt.setCodeElement(convertCode(src.getCurrencyElement()));
645    return tgt;
646  }
647
648  public static org.hl7.fhir.r5.model.Identifier convertIdentifier(org.hl7.fhir.dstu2016may.model.Identifier src) throws FHIRException {
649    if (src == null || src.isEmpty()) return null;
650    org.hl7.fhir.r5.model.Identifier tgt = new org.hl7.fhir.r5.model.Identifier();
651    copyElement(src, tgt);
652    if (src.hasUse()) tgt.setUseElement(convertIdentifierUse(src.getUseElement()));
653    if (src.hasType()) tgt.setType(convertCodeableConcept(src.getType()));
654    if (src.hasSystem()) tgt.setSystemElement(convertUri(src.getSystemElement()));
655    if (src.hasValue()) tgt.setValueElement(convertString(src.getValueElement()));
656    if (src.hasPeriod()) tgt.setPeriod(convertPeriod(src.getPeriod()));
657    if (src.hasAssigner()) tgt.setAssigner(convertReference(src.getAssigner()));
658    return tgt;
659  }
660
661  public static org.hl7.fhir.dstu2016may.model.Identifier convertIdentifier(org.hl7.fhir.r5.model.Identifier src) throws FHIRException {
662    if (src == null || src.isEmpty()) return null;
663    org.hl7.fhir.dstu2016may.model.Identifier tgt = new org.hl7.fhir.dstu2016may.model.Identifier();
664    copyElement(src, tgt);
665    if (src.hasUse()) tgt.setUseElement(convertIdentifierUse(src.getUseElement()));
666    if (src.hasType()) tgt.setType(convertCodeableConcept(src.getType()));
667    if (src.hasSystem()) tgt.setSystemElement(convertUri(src.getSystemElement()));
668    if (src.hasValue()) tgt.setValueElement(convertString(src.getValueElement()));
669    if (src.hasPeriod()) tgt.setPeriod(convertPeriod(src.getPeriod()));
670    if (src.hasAssigner()) tgt.setAssigner(convertReference(src.getAssigner()));
671    return tgt;
672  }
673
674  static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Identifier.IdentifierUse> convertIdentifierUse(org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.Identifier.IdentifierUse> src) throws FHIRException {
675    if (src == null || src.isEmpty()) return null;
676    org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Identifier.IdentifierUse> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.Identifier.IdentifierUseEnumFactory());
677    VersionConvertor_14_50.copyElement(src, tgt);
678    if (src.getValue() == null) {
679      tgt.setValue(org.hl7.fhir.r5.model.Identifier.IdentifierUse.NULL);
680    } else {
681      switch (src.getValue()) {
682        case USUAL:
683          tgt.setValue(org.hl7.fhir.r5.model.Identifier.IdentifierUse.USUAL);
684          break;
685        case OFFICIAL:
686          tgt.setValue(org.hl7.fhir.r5.model.Identifier.IdentifierUse.OFFICIAL);
687          break;
688        case TEMP:
689          tgt.setValue(org.hl7.fhir.r5.model.Identifier.IdentifierUse.TEMP);
690          break;
691        case SECONDARY:
692          tgt.setValue(org.hl7.fhir.r5.model.Identifier.IdentifierUse.SECONDARY);
693          break;
694        default:
695          tgt.setValue(org.hl7.fhir.r5.model.Identifier.IdentifierUse.NULL);
696          break;
697      }
698    }
699    return tgt;
700  }
701
702  static public org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.Identifier.IdentifierUse> convertIdentifierUse(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Identifier.IdentifierUse> src) throws FHIRException {
703    if (src == null || src.isEmpty()) return null;
704    org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.Identifier.IdentifierUse> tgt = new org.hl7.fhir.dstu2016may.model.Enumeration<>(new org.hl7.fhir.dstu2016may.model.Identifier.IdentifierUseEnumFactory());
705    VersionConvertor_14_50.copyElement(src, tgt);
706    if (src.getValue() == null) {
707      tgt.setValue(org.hl7.fhir.dstu2016may.model.Identifier.IdentifierUse.NULL);
708    } else {
709      switch (src.getValue()) {
710        case USUAL:
711          tgt.setValue(org.hl7.fhir.dstu2016may.model.Identifier.IdentifierUse.USUAL);
712          break;
713        case OFFICIAL:
714          tgt.setValue(org.hl7.fhir.dstu2016may.model.Identifier.IdentifierUse.OFFICIAL);
715          break;
716        case TEMP:
717          tgt.setValue(org.hl7.fhir.dstu2016may.model.Identifier.IdentifierUse.TEMP);
718          break;
719        case SECONDARY:
720          tgt.setValue(org.hl7.fhir.dstu2016may.model.Identifier.IdentifierUse.SECONDARY);
721          break;
722        default:
723          tgt.setValue(org.hl7.fhir.dstu2016may.model.Identifier.IdentifierUse.NULL);
724          break;
725      }
726    }
727    return tgt;
728  }
729
730  public static org.hl7.fhir.r5.model.Period convertPeriod(org.hl7.fhir.dstu2016may.model.Period src) throws FHIRException {
731    if (src == null || src.isEmpty()) return null;
732    org.hl7.fhir.r5.model.Period tgt = new org.hl7.fhir.r5.model.Period();
733    copyElement(src, tgt);
734    if (src.hasStart()) tgt.setStartElement(convertDateTime(src.getStartElement()));
735    if (src.hasEnd()) tgt.setEndElement(convertDateTime(src.getEndElement()));
736    return tgt;
737  }
738
739  public static org.hl7.fhir.dstu2016may.model.Period convertPeriod(org.hl7.fhir.r5.model.Period src) throws FHIRException {
740    if (src == null || src.isEmpty()) return null;
741    org.hl7.fhir.dstu2016may.model.Period tgt = new org.hl7.fhir.dstu2016may.model.Period();
742    copyElement(src, tgt);
743    if (src.hasStart()) tgt.setStartElement(convertDateTime(src.getStartElement()));
744    if (src.hasEnd()) tgt.setEndElement(convertDateTime(src.getEndElement()));
745    return tgt;
746  }
747
748  public static org.hl7.fhir.r5.model.Quantity convertQuantity(org.hl7.fhir.dstu2016may.model.Quantity src) throws FHIRException {
749    if (src == null || src.isEmpty()) return null;
750    org.hl7.fhir.r5.model.Quantity tgt = new org.hl7.fhir.r5.model.Quantity();
751    copyElement(src, tgt);
752    if (src.hasValue()) tgt.setValueElement(convertDecimal(src.getValueElement()));
753    if (src.hasComparator()) tgt.setComparatorElement(convertQuantityComparator(src.getComparatorElement()));
754    if (src.hasUnit()) tgt.setUnitElement(convertString(src.getUnitElement()));
755    if (src.hasSystem()) tgt.setSystemElement(convertUri(src.getSystemElement()));
756    if (src.hasCode()) tgt.setCodeElement(convertCode(src.getCodeElement()));
757    return tgt;
758  }
759
760  public static org.hl7.fhir.dstu2016may.model.Quantity convertQuantity(org.hl7.fhir.r5.model.Quantity src) throws FHIRException {
761    if (src == null || src.isEmpty()) return null;
762    org.hl7.fhir.dstu2016may.model.Quantity tgt = new org.hl7.fhir.dstu2016may.model.Quantity();
763    copyElement(src, tgt);
764    if (src.hasValue()) tgt.setValueElement(convertDecimal(src.getValueElement()));
765    if (src.hasComparator()) tgt.setComparatorElement(convertQuantityComparator(src.getComparatorElement()));
766    if (src.hasUnit()) tgt.setUnitElement(convertString(src.getUnitElement()));
767    if (src.hasSystem()) tgt.setSystemElement(convertUri(src.getSystemElement()));
768    if (src.hasCode()) tgt.setCodeElement(convertCode(src.getCodeElement()));
769    return tgt;
770  }
771
772  static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Enumerations.QuantityComparator> convertQuantityComparator(org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.Quantity.QuantityComparator> src) throws FHIRException {
773    if (src == null || src.isEmpty()) return null;
774    org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Enumerations.QuantityComparator> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.Enumerations.QuantityComparatorEnumFactory());
775    VersionConvertor_14_50.copyElement(src, tgt);
776    if (src.getValue() == null) {
777      tgt.setValue(org.hl7.fhir.r5.model.Enumerations.QuantityComparator.NULL);
778    } else {
779      switch (src.getValue()) {
780        case LESS_THAN:
781          tgt.setValue(org.hl7.fhir.r5.model.Enumerations.QuantityComparator.LESS_THAN);
782          break;
783        case LESS_OR_EQUAL:
784          tgt.setValue(org.hl7.fhir.r5.model.Enumerations.QuantityComparator.LESS_OR_EQUAL);
785          break;
786        case GREATER_OR_EQUAL:
787          tgt.setValue(org.hl7.fhir.r5.model.Enumerations.QuantityComparator.GREATER_OR_EQUAL);
788          break;
789        case GREATER_THAN:
790          tgt.setValue(org.hl7.fhir.r5.model.Enumerations.QuantityComparator.GREATER_THAN);
791          break;
792        default:
793          tgt.setValue(org.hl7.fhir.r5.model.Enumerations.QuantityComparator.NULL);
794          break;
795      }
796    }
797    return tgt;
798  }
799
800  static public org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.Quantity.QuantityComparator> convertQuantityComparator(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Enumerations.QuantityComparator> src) throws FHIRException {
801    if (src == null || src.isEmpty()) return null;
802    org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.Quantity.QuantityComparator> tgt = new org.hl7.fhir.dstu2016may.model.Enumeration<>(new org.hl7.fhir.dstu2016may.model.Quantity.QuantityComparatorEnumFactory());
803    VersionConvertor_14_50.copyElement(src, tgt);
804    if (src.getValue() == null) {
805      tgt.setValue(org.hl7.fhir.dstu2016may.model.Quantity.QuantityComparator.NULL);
806    } else {
807      switch (src.getValue()) {
808        case LESS_THAN:
809          tgt.setValue(org.hl7.fhir.dstu2016may.model.Quantity.QuantityComparator.LESS_THAN);
810          break;
811        case LESS_OR_EQUAL:
812          tgt.setValue(org.hl7.fhir.dstu2016may.model.Quantity.QuantityComparator.LESS_OR_EQUAL);
813          break;
814        case GREATER_OR_EQUAL:
815          tgt.setValue(org.hl7.fhir.dstu2016may.model.Quantity.QuantityComparator.GREATER_OR_EQUAL);
816          break;
817        case GREATER_THAN:
818          tgt.setValue(org.hl7.fhir.dstu2016may.model.Quantity.QuantityComparator.GREATER_THAN);
819          break;
820        default:
821          tgt.setValue(org.hl7.fhir.dstu2016may.model.Quantity.QuantityComparator.NULL);
822          break;
823      }
824    }
825    return tgt;
826  }
827
828  public static org.hl7.fhir.r5.model.Range convertRange(org.hl7.fhir.dstu2016may.model.Range src) throws FHIRException {
829    if (src == null || src.isEmpty()) return null;
830    org.hl7.fhir.r5.model.Range tgt = new org.hl7.fhir.r5.model.Range();
831    copyElement(src, tgt);
832    if (src.hasLow()) tgt.setLow(convertSimpleQuantity(src.getLow()));
833    if (src.hasHigh()) tgt.setHigh(convertSimpleQuantity(src.getHigh()));
834    return tgt;
835  }
836
837  public static org.hl7.fhir.dstu2016may.model.Range convertRange(org.hl7.fhir.r5.model.Range src) throws FHIRException {
838    if (src == null || src.isEmpty()) return null;
839    org.hl7.fhir.dstu2016may.model.Range tgt = new org.hl7.fhir.dstu2016may.model.Range();
840    copyElement(src, tgt);
841    if (src.hasLow()) tgt.setLow(convertSimpleQuantity(src.getLow()));
842    if (src.hasHigh()) tgt.setHigh(convertSimpleQuantity(src.getHigh()));
843    return tgt;
844  }
845
846  public static org.hl7.fhir.r5.model.Ratio convertRatio(org.hl7.fhir.dstu2016may.model.Ratio src) throws FHIRException {
847    if (src == null || src.isEmpty()) return null;
848    org.hl7.fhir.r5.model.Ratio tgt = new org.hl7.fhir.r5.model.Ratio();
849    copyElement(src, tgt);
850    if (src.hasNumerator()) tgt.setNumerator(convertQuantity(src.getNumerator()));
851    if (src.hasDenominator()) tgt.setDenominator(convertQuantity(src.getDenominator()));
852    return tgt;
853  }
854
855  public static org.hl7.fhir.dstu2016may.model.Ratio convertRatio(org.hl7.fhir.r5.model.Ratio src) throws FHIRException {
856    if (src == null || src.isEmpty()) return null;
857    org.hl7.fhir.dstu2016may.model.Ratio tgt = new org.hl7.fhir.dstu2016may.model.Ratio();
858    copyElement(src, tgt);
859    if (src.hasNumerator()) tgt.setNumerator(convertQuantity(src.getNumerator()));
860    if (src.hasDenominator()) tgt.setDenominator(convertQuantity(src.getDenominator()));
861    return tgt;
862  }
863
864  public static org.hl7.fhir.r5.model.Reference convertReference(org.hl7.fhir.dstu2016may.model.Reference src) throws FHIRException {
865    if (src == null || src.isEmpty()) return null;
866    org.hl7.fhir.r5.model.Reference tgt = new org.hl7.fhir.r5.model.Reference();
867    copyElement(src, tgt);
868    if (src.hasReference()) tgt.setReference(src.getReference());
869    if (src.hasDisplay()) tgt.setDisplayElement(convertString(src.getDisplayElement()));
870    return tgt;
871  }
872
873  public static org.hl7.fhir.dstu2016may.model.Reference convertReference(org.hl7.fhir.r5.model.Reference src) throws FHIRException {
874    if (src == null || src.isEmpty()) return null;
875    org.hl7.fhir.dstu2016may.model.Reference tgt = new org.hl7.fhir.dstu2016may.model.Reference();
876    copyElement(src, tgt);
877    if (src.hasReference()) tgt.setReference(src.getReference());
878    if (src.hasDisplay()) tgt.setDisplayElement(convertString(src.getDisplayElement()));
879    return tgt;
880  }
881
882  public static org.hl7.fhir.r5.model.SampledData convertSampledData(org.hl7.fhir.dstu2016may.model.SampledData src) throws FHIRException {
883    if (src == null || src.isEmpty()) return null;
884    org.hl7.fhir.r5.model.SampledData tgt = new org.hl7.fhir.r5.model.SampledData();
885    copyElement(src, tgt);
886    if (src.hasOrigin()) tgt.setOrigin(convertSimpleQuantity(src.getOrigin()));
887    if (src.hasPeriodElement()) tgt.setPeriodElement(convertDecimal(src.getPeriodElement()));
888    if (src.hasFactor()) tgt.setFactorElement(convertDecimal(src.getFactorElement()));
889    if (src.hasLowerLimit()) tgt.setLowerLimitElement(convertDecimal(src.getLowerLimitElement()));
890    if (src.hasUpperLimit()) tgt.setUpperLimitElement(convertDecimal(src.getUpperLimitElement()));
891    if (src.hasDimensionsElement()) tgt.setDimensionsElement(convertPositiveInt(src.getDimensionsElement()));
892    if (src.hasDataElement()) tgt.setDataElement(convertString(src.getDataElement()));
893    return tgt;
894  }
895
896  public static org.hl7.fhir.dstu2016may.model.SampledData convertSampledData(org.hl7.fhir.r5.model.SampledData src) throws FHIRException {
897    if (src == null || src.isEmpty()) return null;
898    org.hl7.fhir.dstu2016may.model.SampledData tgt = new org.hl7.fhir.dstu2016may.model.SampledData();
899    copyElement(src, tgt);
900    if (src.hasOrigin()) tgt.setOrigin(convertSimpleQuantity(src.getOrigin()));
901    if (src.hasPeriodElement()) tgt.setPeriodElement(convertDecimal(src.getPeriodElement()));
902    if (src.hasFactor()) tgt.setFactorElement(convertDecimal(src.getFactorElement()));
903    if (src.hasLowerLimit()) tgt.setLowerLimitElement(convertDecimal(src.getLowerLimitElement()));
904    if (src.hasUpperLimit()) tgt.setUpperLimitElement(convertDecimal(src.getUpperLimitElement()));
905    if (src.hasDimensionsElement()) tgt.setDimensionsElement(convertPositiveInt(src.getDimensionsElement()));
906    if (src.hasDataElement()) tgt.setDataElement(convertString(src.getDataElement()));
907    return tgt;
908  }
909
910  public static org.hl7.fhir.r5.model.Signature convertSignature(org.hl7.fhir.dstu2016may.model.Signature src) throws FHIRException {
911    if (src == null || src.isEmpty()) return null;
912    org.hl7.fhir.r5.model.Signature tgt = new org.hl7.fhir.r5.model.Signature();
913    copyElement(src, tgt);
914    for (org.hl7.fhir.dstu2016may.model.Coding t : src.getType()) tgt.addType(convertCoding(t));
915    if (src.hasWhenElement()) tgt.setWhenElement(convertInstant(src.getWhenElement()));
916    if (src.hasWhoUriType()) tgt.setWho(new org.hl7.fhir.r5.model.Reference(src.getWhoUriType().getValue()));
917    else tgt.setWho(convertReference(src.getWhoReference()));
918    if (src.hasContentType()) tgt.setSigFormatElement(convertCode(src.getContentTypeElement()));
919    if (src.hasBlob()) tgt.setDataElement(convertBase64Binary(src.getBlobElement()));
920    return tgt;
921  }
922
923  public static org.hl7.fhir.dstu2016may.model.Signature convertSignature(org.hl7.fhir.r5.model.Signature src) throws FHIRException {
924    if (src == null || src.isEmpty()) return null;
925    org.hl7.fhir.dstu2016may.model.Signature tgt = new org.hl7.fhir.dstu2016may.model.Signature();
926    copyElement(src, tgt);
927    for (org.hl7.fhir.r5.model.Coding t : src.getType()) tgt.addType(convertCoding(t));
928    if (src.hasWhenElement()) tgt.setWhenElement(convertInstant(src.getWhenElement()));
929    if (src.hasWho()) tgt.setWho(convertType(src.getWho()));
930    if (src.hasSigFormat()) tgt.setContentTypeElement(convertCode(src.getSigFormatElement()));
931    if (src.hasData()) tgt.setBlobElement(convertBase64Binary(src.getDataElement()));
932    return tgt;
933  }
934
935  public static org.hl7.fhir.r5.model.Address convertAddress(org.hl7.fhir.dstu2016may.model.Address src) throws FHIRException {
936    if (src == null || src.isEmpty()) return null;
937    org.hl7.fhir.r5.model.Address tgt = new org.hl7.fhir.r5.model.Address();
938    copyElement(src, tgt);
939    if (src.hasUse()) tgt.setUseElement(convertAddressUse(src.getUseElement()));
940    if (src.hasType()) tgt.setTypeElement(convertAddressType(src.getTypeElement()));
941    if (src.hasText()) tgt.setTextElement(convertString(src.getTextElement()));
942    for (org.hl7.fhir.dstu2016may.model.StringType t : src.getLine()) tgt.addLine(t.getValue());
943    if (src.hasCity()) tgt.setCityElement(convertString(src.getCityElement()));
944    if (src.hasDistrict()) tgt.setDistrictElement(convertString(src.getDistrictElement()));
945    if (src.hasState()) tgt.setStateElement(convertString(src.getStateElement()));
946    if (src.hasPostalCode()) tgt.setPostalCodeElement(convertString(src.getPostalCodeElement()));
947    if (src.hasCountry()) tgt.setCountryElement(convertString(src.getCountryElement()));
948    if (src.hasPeriod()) tgt.setPeriod(convertPeriod(src.getPeriod()));
949    return tgt;
950  }
951
952  public static org.hl7.fhir.dstu2016may.model.Address convertAddress(org.hl7.fhir.r5.model.Address src) throws FHIRException {
953    if (src == null || src.isEmpty()) return null;
954    org.hl7.fhir.dstu2016may.model.Address tgt = new org.hl7.fhir.dstu2016may.model.Address();
955    copyElement(src, tgt);
956    if (src.hasUse()) tgt.setUseElement(convertAddressUse(src.getUseElement()));
957    if (src.hasType()) tgt.setTypeElement(convertAddressType(src.getTypeElement()));
958    if (src.hasText()) tgt.setTextElement(convertString(src.getTextElement()));
959    for (org.hl7.fhir.r5.model.StringType t : src.getLine()) tgt.addLine(t.getValue());
960    if (src.hasCity()) tgt.setCityElement(convertString(src.getCityElement()));
961    if (src.hasDistrict()) tgt.setDistrictElement(convertString(src.getDistrictElement()));
962    if (src.hasState()) tgt.setStateElement(convertString(src.getStateElement()));
963    if (src.hasPostalCode()) tgt.setPostalCodeElement(convertString(src.getPostalCodeElement()));
964    if (src.hasCountry()) tgt.setCountryElement(convertString(src.getCountryElement()));
965    if (src.hasPeriod()) tgt.setPeriod(convertPeriod(src.getPeriod()));
966    return tgt;
967  }
968
969  static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Address.AddressUse> convertAddressUse(org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.Address.AddressUse> src) throws FHIRException {
970    if (src == null || src.isEmpty()) return null;
971    org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Address.AddressUse> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.Address.AddressUseEnumFactory());
972    VersionConvertor_14_50.copyElement(src, tgt);
973    if (src.getValue() == null) {
974      tgt.setValue(org.hl7.fhir.r5.model.Address.AddressUse.NULL);
975    } else {
976      switch (src.getValue()) {
977        case HOME:
978          tgt.setValue(org.hl7.fhir.r5.model.Address.AddressUse.HOME);
979          break;
980        case WORK:
981          tgt.setValue(org.hl7.fhir.r5.model.Address.AddressUse.WORK);
982          break;
983        case TEMP:
984          tgt.setValue(org.hl7.fhir.r5.model.Address.AddressUse.TEMP);
985          break;
986        case OLD:
987          tgt.setValue(org.hl7.fhir.r5.model.Address.AddressUse.OLD);
988          break;
989        default:
990          tgt.setValue(org.hl7.fhir.r5.model.Address.AddressUse.NULL);
991          break;
992      }
993    }
994    return tgt;
995  }
996
997  static public org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.Address.AddressUse> convertAddressUse(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Address.AddressUse> src) throws FHIRException {
998    if (src == null || src.isEmpty()) return null;
999    org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.Address.AddressUse> tgt = new org.hl7.fhir.dstu2016may.model.Enumeration<>(new org.hl7.fhir.dstu2016may.model.Address.AddressUseEnumFactory());
1000    VersionConvertor_14_50.copyElement(src, tgt);
1001    if (src.getValue() == null) {
1002      tgt.setValue(org.hl7.fhir.dstu2016may.model.Address.AddressUse.NULL);
1003    } else {
1004      switch (src.getValue()) {
1005        case HOME:
1006          tgt.setValue(org.hl7.fhir.dstu2016may.model.Address.AddressUse.HOME);
1007          break;
1008        case WORK:
1009          tgt.setValue(org.hl7.fhir.dstu2016may.model.Address.AddressUse.WORK);
1010          break;
1011        case TEMP:
1012          tgt.setValue(org.hl7.fhir.dstu2016may.model.Address.AddressUse.TEMP);
1013          break;
1014        case OLD:
1015          tgt.setValue(org.hl7.fhir.dstu2016may.model.Address.AddressUse.OLD);
1016          break;
1017        default:
1018          tgt.setValue(org.hl7.fhir.dstu2016may.model.Address.AddressUse.NULL);
1019          break;
1020      }
1021    }
1022    return tgt;
1023  }
1024
1025  static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Address.AddressType> convertAddressType(org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.Address.AddressType> src) throws FHIRException {
1026    if (src == null || src.isEmpty()) return null;
1027    org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Address.AddressType> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.Address.AddressTypeEnumFactory());
1028    VersionConvertor_14_50.copyElement(src, tgt);
1029    if (src.getValue() == null) {
1030      tgt.setValue(org.hl7.fhir.r5.model.Address.AddressType.NULL);
1031    } else {
1032      switch (src.getValue()) {
1033        case POSTAL:
1034          tgt.setValue(org.hl7.fhir.r5.model.Address.AddressType.POSTAL);
1035          break;
1036        case PHYSICAL:
1037          tgt.setValue(org.hl7.fhir.r5.model.Address.AddressType.PHYSICAL);
1038          break;
1039        case BOTH:
1040          tgt.setValue(org.hl7.fhir.r5.model.Address.AddressType.BOTH);
1041          break;
1042        default:
1043          tgt.setValue(org.hl7.fhir.r5.model.Address.AddressType.NULL);
1044          break;
1045      }
1046    }
1047    return tgt;
1048  }
1049
1050  static public org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.Address.AddressType> convertAddressType(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Address.AddressType> src) throws FHIRException {
1051    if (src == null || src.isEmpty()) return null;
1052    org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.Address.AddressType> tgt = new org.hl7.fhir.dstu2016may.model.Enumeration<>(new org.hl7.fhir.dstu2016may.model.Address.AddressTypeEnumFactory());
1053    VersionConvertor_14_50.copyElement(src, tgt);
1054    if (src.getValue() == null) {
1055      tgt.setValue(org.hl7.fhir.dstu2016may.model.Address.AddressType.NULL);
1056    } else {
1057      switch (src.getValue()) {
1058        case POSTAL:
1059          tgt.setValue(org.hl7.fhir.dstu2016may.model.Address.AddressType.POSTAL);
1060          break;
1061        case PHYSICAL:
1062          tgt.setValue(org.hl7.fhir.dstu2016may.model.Address.AddressType.PHYSICAL);
1063          break;
1064        case BOTH:
1065          tgt.setValue(org.hl7.fhir.dstu2016may.model.Address.AddressType.BOTH);
1066          break;
1067        default:
1068          tgt.setValue(org.hl7.fhir.dstu2016may.model.Address.AddressType.NULL);
1069          break;
1070      }
1071    }
1072    return tgt;
1073  }
1074
1075  public static org.hl7.fhir.r5.model.ContactPoint convertContactPoint(org.hl7.fhir.dstu2016may.model.ContactPoint src) throws FHIRException {
1076    if (src == null || src.isEmpty()) return null;
1077    org.hl7.fhir.r5.model.ContactPoint tgt = new org.hl7.fhir.r5.model.ContactPoint();
1078    copyElement(src, tgt);
1079    if (src.hasSystem()) tgt.setSystemElement(convertContactPointSystem(src.getSystemElement()));
1080    if (src.hasValue()) tgt.setValueElement(convertString(src.getValueElement()));
1081    if (src.hasUse()) tgt.setUseElement(convertContactPointUse(src.getUseElement()));
1082    if (src.hasRank()) tgt.setRankElement(convertPositiveInt(src.getRankElement()));
1083    if (src.hasPeriod()) tgt.setPeriod(convertPeriod(src.getPeriod()));
1084    return tgt;
1085  }
1086
1087  public static org.hl7.fhir.dstu2016may.model.ContactPoint convertContactPoint(org.hl7.fhir.r5.model.ContactPoint src) throws FHIRException {
1088    if (src == null || src.isEmpty()) return null;
1089    org.hl7.fhir.dstu2016may.model.ContactPoint tgt = new org.hl7.fhir.dstu2016may.model.ContactPoint();
1090    copyElement(src, tgt);
1091    if (src.hasSystem()) tgt.setSystemElement(convertContactPointSystem(src.getSystemElement()));
1092    if (src.hasValue()) tgt.setValueElement(convertString(src.getValueElement()));
1093    if (src.hasUse()) tgt.setUseElement(convertContactPointUse(src.getUseElement()));
1094    if (src.hasRank()) tgt.setRankElement(convertPositiveInt(src.getRankElement()));
1095    if (src.hasPeriod()) tgt.setPeriod(convertPeriod(src.getPeriod()));
1096    return tgt;
1097  }
1098
1099  static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.ContactPoint.ContactPointSystem> convertContactPointSystem(org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.ContactPoint.ContactPointSystem> src) throws FHIRException {
1100    if (src == null || src.isEmpty()) return null;
1101    org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.ContactPoint.ContactPointSystem> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.ContactPoint.ContactPointSystemEnumFactory());
1102    VersionConvertor_14_50.copyElement(src, tgt);
1103    if (src.getValue() == null) {
1104      tgt.setValue(org.hl7.fhir.r5.model.ContactPoint.ContactPointSystem.NULL);
1105    } else {
1106      switch (src.getValue()) {
1107        case PHONE:
1108          tgt.setValue(org.hl7.fhir.r5.model.ContactPoint.ContactPointSystem.PHONE);
1109          break;
1110        case FAX:
1111          tgt.setValue(org.hl7.fhir.r5.model.ContactPoint.ContactPointSystem.FAX);
1112          break;
1113        case EMAIL:
1114          tgt.setValue(org.hl7.fhir.r5.model.ContactPoint.ContactPointSystem.EMAIL);
1115          break;
1116        case PAGER:
1117          tgt.setValue(org.hl7.fhir.r5.model.ContactPoint.ContactPointSystem.PAGER);
1118          break;
1119        case OTHER:
1120          tgt.setValue(org.hl7.fhir.r5.model.ContactPoint.ContactPointSystem.URL);
1121          break;
1122        default:
1123          tgt.setValue(org.hl7.fhir.r5.model.ContactPoint.ContactPointSystem.NULL);
1124          break;
1125      }
1126    }
1127    return tgt;
1128  }
1129
1130  static public org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.ContactPoint.ContactPointSystem> convertContactPointSystem(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.ContactPoint.ContactPointSystem> src) throws FHIRException {
1131    if (src == null || src.isEmpty()) return null;
1132    org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.ContactPoint.ContactPointSystem> tgt = new org.hl7.fhir.dstu2016may.model.Enumeration<>(new org.hl7.fhir.dstu2016may.model.ContactPoint.ContactPointSystemEnumFactory());
1133    VersionConvertor_14_50.copyElement(src, tgt);
1134    if (src.getValue() == null) {
1135      tgt.setValue(org.hl7.fhir.dstu2016may.model.ContactPoint.ContactPointSystem.NULL);
1136    } else {
1137      switch (src.getValue()) {
1138        case PHONE:
1139          tgt.setValue(org.hl7.fhir.dstu2016may.model.ContactPoint.ContactPointSystem.PHONE);
1140          break;
1141        case FAX:
1142          tgt.setValue(org.hl7.fhir.dstu2016may.model.ContactPoint.ContactPointSystem.FAX);
1143          break;
1144        case EMAIL:
1145          tgt.setValue(org.hl7.fhir.dstu2016may.model.ContactPoint.ContactPointSystem.EMAIL);
1146          break;
1147        case PAGER:
1148          tgt.setValue(org.hl7.fhir.dstu2016may.model.ContactPoint.ContactPointSystem.PAGER);
1149          break;
1150        case URL:
1151          tgt.setValue(org.hl7.fhir.dstu2016may.model.ContactPoint.ContactPointSystem.OTHER);
1152          break;
1153        default:
1154          tgt.setValue(org.hl7.fhir.dstu2016may.model.ContactPoint.ContactPointSystem.NULL);
1155          break;
1156      }
1157    }
1158    return tgt;
1159  }
1160
1161  static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.ContactPoint.ContactPointUse> convertContactPointUse(org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.ContactPoint.ContactPointUse> src) throws FHIRException {
1162    if (src == null || src.isEmpty()) return null;
1163    org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.ContactPoint.ContactPointUse> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.ContactPoint.ContactPointUseEnumFactory());
1164    VersionConvertor_14_50.copyElement(src, tgt);
1165    if (src.getValue() == null) {
1166      tgt.setValue(org.hl7.fhir.r5.model.ContactPoint.ContactPointUse.NULL);
1167    } else {
1168      switch (src.getValue()) {
1169        case HOME:
1170          tgt.setValue(org.hl7.fhir.r5.model.ContactPoint.ContactPointUse.HOME);
1171          break;
1172        case WORK:
1173          tgt.setValue(org.hl7.fhir.r5.model.ContactPoint.ContactPointUse.WORK);
1174          break;
1175        case TEMP:
1176          tgt.setValue(org.hl7.fhir.r5.model.ContactPoint.ContactPointUse.TEMP);
1177          break;
1178        case OLD:
1179          tgt.setValue(org.hl7.fhir.r5.model.ContactPoint.ContactPointUse.OLD);
1180          break;
1181        case MOBILE:
1182          tgt.setValue(org.hl7.fhir.r5.model.ContactPoint.ContactPointUse.MOBILE);
1183          break;
1184        default:
1185          tgt.setValue(org.hl7.fhir.r5.model.ContactPoint.ContactPointUse.NULL);
1186          break;
1187      }
1188    }
1189    return tgt;
1190  }
1191
1192  static public org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.ContactPoint.ContactPointUse> convertContactPointUse(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.ContactPoint.ContactPointUse> src) throws FHIRException {
1193    if (src == null || src.isEmpty()) return null;
1194    org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.ContactPoint.ContactPointUse> tgt = new org.hl7.fhir.dstu2016may.model.Enumeration<>(new org.hl7.fhir.dstu2016may.model.ContactPoint.ContactPointUseEnumFactory());
1195    VersionConvertor_14_50.copyElement(src, tgt);
1196    if (src.getValue() == null) {
1197      tgt.setValue(org.hl7.fhir.dstu2016may.model.ContactPoint.ContactPointUse.NULL);
1198    } else {
1199      switch (src.getValue()) {
1200        case HOME:
1201          tgt.setValue(org.hl7.fhir.dstu2016may.model.ContactPoint.ContactPointUse.HOME);
1202          break;
1203        case WORK:
1204          tgt.setValue(org.hl7.fhir.dstu2016may.model.ContactPoint.ContactPointUse.WORK);
1205          break;
1206        case TEMP:
1207          tgt.setValue(org.hl7.fhir.dstu2016may.model.ContactPoint.ContactPointUse.TEMP);
1208          break;
1209        case OLD:
1210          tgt.setValue(org.hl7.fhir.dstu2016may.model.ContactPoint.ContactPointUse.OLD);
1211          break;
1212        case MOBILE:
1213          tgt.setValue(org.hl7.fhir.dstu2016may.model.ContactPoint.ContactPointUse.MOBILE);
1214          break;
1215        default:
1216          tgt.setValue(org.hl7.fhir.dstu2016may.model.ContactPoint.ContactPointUse.NULL);
1217          break;
1218      }
1219    }
1220    return tgt;
1221  }
1222
1223  public static org.hl7.fhir.r5.model.ElementDefinition convertElementDefinition(org.hl7.fhir.dstu2016may.model.ElementDefinition src, List<org.hl7.fhir.dstu2016may.model.ElementDefinition> context, int pos) throws FHIRException {
1224    if (src == null || src.isEmpty()) return null;
1225    org.hl7.fhir.r5.model.ElementDefinition tgt = new org.hl7.fhir.r5.model.ElementDefinition();
1226    copyElement(src, tgt);
1227    if (src.hasPathElement()) tgt.setPathElement(convertString(src.getPathElement()));
1228    tgt.setRepresentation(src.getRepresentation().stream().map(VersionConvertor_14_50::convertPropertyRepresentation).collect(Collectors.toList()));
1229    if (src.hasName()) tgt.setSliceNameElement(convertString(src.getNameElement()));
1230    if (src.hasLabel()) tgt.setLabelElement(convertString(src.getLabelElement()));
1231    for (org.hl7.fhir.dstu2016may.model.Coding t : src.getCode()) tgt.addCode(convertCoding(t));
1232    if (src.hasSlicing()) tgt.setSlicing(convertElementDefinitionSlicingComponent(src.getSlicing(), context, pos));
1233    if (src.hasShort()) tgt.setShortElement(convertString(src.getShortElement()));
1234    if (src.hasDefinition()) tgt.setDefinitionElement(convertMarkdown(src.getDefinitionElement()));
1235    if (src.hasComments()) tgt.setCommentElement(convertMarkdown(src.getCommentsElement()));
1236    if (src.hasRequirements()) tgt.setRequirementsElement(convertMarkdown(src.getRequirementsElement()));
1237    for (org.hl7.fhir.dstu2016may.model.StringType t : src.getAlias()) tgt.addAlias(t.getValue());
1238    if (src.hasMin()) tgt.setMin(src.getMin());
1239    if (src.hasMax()) tgt.setMaxElement(convertString(src.getMaxElement()));
1240    if (src.hasBase()) tgt.setBase(convertElementDefinitionBaseComponent(src.getBase()));
1241    if (src.hasContentReference())
1242      tgt.setContentReferenceElement(convertUri(src.getContentReferenceElement()));
1243    // work around for problem in R2B definitions:
1244    if (!src.hasContentReference()) {
1245      for (org.hl7.fhir.dstu2016may.model.ElementDefinition.TypeRefComponent t : src.getType())
1246        convertTypeRefComponent(t, tgt.getType());
1247      if (src.hasDefaultValue()) tgt.setDefaultValue(convertType(src.getDefaultValue()));
1248      if (src.hasMeaningWhenMissing())
1249        tgt.setMeaningWhenMissingElement(convertMarkdown(src.getMeaningWhenMissingElement()));
1250      if (src.hasFixed()) tgt.setFixed(convertType(src.getFixed()));
1251      if (src.hasPattern()) tgt.setPattern(convertType(src.getPattern()));
1252      if (src.hasExample()) tgt.addExample().setLabel("General").setValue(convertType(src.getExample()));
1253      if (src.hasMinValue()) tgt.setMinValue(convertType(src.getMinValue()));
1254      if (src.hasMaxValue()) tgt.setMaxValue(convertType(src.getMaxValue()));
1255      if (src.hasMaxLength()) tgt.setMaxLengthElement(convertInteger(src.getMaxLengthElement()));
1256      for (org.hl7.fhir.dstu2016may.model.IdType t : src.getCondition()) tgt.addCondition(t.getValue());
1257      for (org.hl7.fhir.dstu2016may.model.ElementDefinition.ElementDefinitionConstraintComponent t : src.getConstraint())
1258        tgt.addConstraint(convertElementDefinitionConstraintComponent(t));
1259      if (src.hasMustSupport()) tgt.setMustSupportElement(convertBoolean(src.getMustSupportElement()));
1260      if (src.hasIsModifier()) tgt.setIsModifierElement(convertBoolean(src.getIsModifierElement()));
1261      if (tgt.getIsModifier()) {
1262        String reason = org.hl7.fhir.dstu2016may.utils.ToolingExtensions.readStringExtension(src, VersionConvertorConstants.MODIFIER_REASON_EXTENSION);
1263        if (Utilities.noString(reason)) reason = VersionConvertorConstants.MODIFIER_REASON_LEGACY;
1264        tgt.setIsModifierReason(reason);
1265      }
1266      if (src.hasIsSummary()) tgt.setIsSummaryElement(convertBoolean(src.getIsSummaryElement()));
1267      if (src.hasBinding()) tgt.setBinding(convertElementDefinitionBindingComponent(src.getBinding()));
1268      for (org.hl7.fhir.dstu2016may.model.ElementDefinition.ElementDefinitionMappingComponent t : src.getMapping())
1269        tgt.addMapping(convertElementDefinitionMappingComponent(t));
1270    }
1271    return tgt;
1272  }
1273
1274  public static org.hl7.fhir.dstu2016may.model.ElementDefinition convertElementDefinition(org.hl7.fhir.r5.model.ElementDefinition src) throws FHIRException {
1275    if (src == null || src.isEmpty()) return null;
1276    org.hl7.fhir.dstu2016may.model.ElementDefinition tgt = new org.hl7.fhir.dstu2016may.model.ElementDefinition();
1277    copyElement(src, tgt);
1278    if (src.hasPathElement()) tgt.setPathElement(convertString(src.getPathElement()));
1279    tgt.setRepresentation(src.getRepresentation().stream().map(VersionConvertor_14_50::convertPropertyRepresentation).collect(Collectors.toList()));
1280    if (src.hasSliceName()) tgt.setNameElement(convertString(src.getSliceNameElement()));
1281    if (src.hasLabel()) tgt.setLabelElement(convertString(src.getLabelElement()));
1282    for (org.hl7.fhir.r5.model.Coding t : src.getCode()) tgt.addCode(convertCoding(t));
1283    if (src.hasSlicing()) tgt.setSlicing(convertElementDefinitionSlicingComponent(src.getSlicing()));
1284    if (src.hasShort()) tgt.setShortElement(convertString(src.getShortElement()));
1285    if (src.hasDefinition()) tgt.setDefinitionElement(convertMarkdown(src.getDefinitionElement()));
1286    if (src.hasComment()) tgt.setCommentsElement(convertMarkdown(src.getCommentElement()));
1287    if (src.hasRequirements()) tgt.setRequirementsElement(convertMarkdown(src.getRequirementsElement()));
1288    for (org.hl7.fhir.r5.model.StringType t : src.getAlias()) tgt.addAlias(t.getValue());
1289    if (src.hasMin()) tgt.setMin(src.getMin());
1290    if (src.hasMax()) tgt.setMaxElement(convertString(src.getMaxElement()));
1291    if (src.hasBase()) tgt.setBase(convertElementDefinitionBaseComponent(src.getBase()));
1292    if (src.hasContentReference()) tgt.setContentReferenceElement(convertUri(src.getContentReferenceElement()));
1293    for (org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent t : src.getType())
1294      convertTypeRefComponent(t, tgt.getType());
1295    if (src.hasDefaultValue()) tgt.setDefaultValue(convertType(src.getDefaultValue()));
1296    if (src.hasMeaningWhenMissing())
1297      tgt.setMeaningWhenMissingElement(convertMarkdown(src.getMeaningWhenMissingElement()));
1298    if (src.hasFixed()) tgt.setFixed(convertType(src.getFixed()));
1299    if (src.hasPattern()) tgt.setPattern(convertType(src.getPattern()));
1300    if (src.hasExample()) tgt.setExample(convertType(src.getExample().get(0).getValue()));
1301    if (src.hasMinValue()) tgt.setMinValue(convertType(src.getMinValue()));
1302    if (src.hasMaxValue()) tgt.setMaxValue(convertType(src.getMaxValue()));
1303    if (src.hasMaxLength()) tgt.setMaxLengthElement(convertInteger(src.getMaxLengthElement()));
1304    for (org.hl7.fhir.r5.model.IdType t : src.getCondition()) tgt.addCondition(t.getValue());
1305    for (org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent t : src.getConstraint())
1306      tgt.addConstraint(convertElementDefinitionConstraintComponent(t));
1307    if (src.hasMustSupport()) tgt.setMustSupportElement(convertBoolean(src.getMustSupportElement()));
1308    if (src.hasIsModifier()) tgt.setIsModifierElement(convertBoolean(src.getIsModifierElement()));
1309    if (src.hasIsModifierReason() && !VersionConvertorConstants.MODIFIER_REASON_LEGACY.equals(src.getIsModifierReason()))
1310      org.hl7.fhir.dstu2016may.utils.ToolingExtensions.setStringExtension(tgt, VersionConvertorConstants.MODIFIER_REASON_EXTENSION, src.getIsModifierReason());
1311    if (src.hasIsSummary()) tgt.setIsSummaryElement(convertBoolean(src.getIsSummaryElement()));
1312    if (src.hasBinding()) tgt.setBinding(convertElementDefinitionBindingComponent(src.getBinding()));
1313    for (org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionMappingComponent t : src.getMapping())
1314      tgt.addMapping(convertElementDefinitionMappingComponent(t));
1315    return tgt;
1316  }
1317
1318  static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.ElementDefinition.PropertyRepresentation> convertPropertyRepresentation(org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.ElementDefinition.PropertyRepresentation> src) throws FHIRException {
1319    if (src == null || src.isEmpty()) return null;
1320    org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.ElementDefinition.PropertyRepresentation> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.ElementDefinition.PropertyRepresentationEnumFactory());
1321    VersionConvertor_14_50.copyElement(src, tgt);
1322    if (src.getValue() == null) {
1323      tgt.setValue(org.hl7.fhir.r5.model.ElementDefinition.PropertyRepresentation.NULL);
1324    } else {
1325      switch (src.getValue()) {
1326        case XMLATTR:
1327          tgt.setValue(org.hl7.fhir.r5.model.ElementDefinition.PropertyRepresentation.XMLATTR);
1328          break;
1329        case XMLTEXT:
1330          tgt.setValue(org.hl7.fhir.r5.model.ElementDefinition.PropertyRepresentation.XMLTEXT);
1331          break;
1332        case TYPEATTR:
1333          tgt.setValue(org.hl7.fhir.r5.model.ElementDefinition.PropertyRepresentation.TYPEATTR);
1334          break;
1335        case CDATEXT:
1336          tgt.setValue(org.hl7.fhir.r5.model.ElementDefinition.PropertyRepresentation.CDATEXT);
1337          break;
1338        default:
1339          tgt.setValue(org.hl7.fhir.r5.model.ElementDefinition.PropertyRepresentation.NULL);
1340          break;
1341      }
1342    }
1343    return tgt;
1344  }
1345
1346  static public org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.ElementDefinition.PropertyRepresentation> convertPropertyRepresentation(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.ElementDefinition.PropertyRepresentation> src) throws FHIRException {
1347    if (src == null || src.isEmpty()) return null;
1348    org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.ElementDefinition.PropertyRepresentation> tgt = new org.hl7.fhir.dstu2016may.model.Enumeration<>(new org.hl7.fhir.dstu2016may.model.ElementDefinition.PropertyRepresentationEnumFactory());
1349    VersionConvertor_14_50.copyElement(src, tgt);
1350    if (src.getValue() == null) {
1351      tgt.setValue(org.hl7.fhir.dstu2016may.model.ElementDefinition.PropertyRepresentation.NULL);
1352    } else {
1353      switch (src.getValue()) {
1354        case XMLATTR:
1355          tgt.setValue(org.hl7.fhir.dstu2016may.model.ElementDefinition.PropertyRepresentation.XMLATTR);
1356          break;
1357        case XMLTEXT:
1358          tgt.setValue(org.hl7.fhir.dstu2016may.model.ElementDefinition.PropertyRepresentation.XMLTEXT);
1359          break;
1360        case TYPEATTR:
1361          tgt.setValue(org.hl7.fhir.dstu2016may.model.ElementDefinition.PropertyRepresentation.TYPEATTR);
1362          break;
1363        case CDATEXT:
1364          tgt.setValue(org.hl7.fhir.dstu2016may.model.ElementDefinition.PropertyRepresentation.CDATEXT);
1365          break;
1366        default:
1367          tgt.setValue(org.hl7.fhir.dstu2016may.model.ElementDefinition.PropertyRepresentation.NULL);
1368          break;
1369      }
1370    }
1371    return tgt;
1372  }
1373
1374  public static org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionSlicingComponent convertElementDefinitionSlicingComponent(org.hl7.fhir.dstu2016may.model.ElementDefinition.ElementDefinitionSlicingComponent src, List<org.hl7.fhir.dstu2016may.model.ElementDefinition> context, int pos) throws FHIRException {
1375    if (src == null || src.isEmpty()) return null;
1376    org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionSlicingComponent tgt = new org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionSlicingComponent();
1377    copyElement(src, tgt);
1378    org.hl7.fhir.dstu2016may.model.ElementDefinition slicingElement = context.get(pos);
1379    for (org.hl7.fhir.dstu2016may.model.StringType t : src.getDiscriminator()) {
1380      boolean isExists = false;
1381      if (!t.asStringValue().contains("@")) {
1382        int slices = 0;
1383        boolean existsSlicePresent = false;
1384        boolean notExistsSlicePresent = false;
1385        String existsPath = slicingElement.getPath() + "." + t.asStringValue();
1386        for (int i = pos + 1; i < context.size(); i++) {
1387          org.hl7.fhir.dstu2016may.model.ElementDefinition e = context.get(i);
1388          if (e.getPath().equals(slicingElement.getPath())) slices++;
1389          else if (!e.getPath().startsWith(slicingElement.getPath() + ".")) break;
1390          else if (e.getPath().equals(existsPath)) {
1391            if (e.hasMin() && e.getMin() > 0 && !e.hasFixed()) existsSlicePresent = true;
1392            else if (e.hasMax() && e.getMax().equals("0")) notExistsSlicePresent = true;
1393          }
1394        }
1395        isExists = (slices == 2 && existsSlicePresent && notExistsSlicePresent) || (slices == 1 && existsSlicePresent != notExistsSlicePresent);
1396      }
1397      tgt.addDiscriminator(ProfileUtilities.interpretR2Discriminator(t.getValue(), isExists));
1398    }
1399    if (src.hasDescription()) tgt.setDescriptionElement(convertString(src.getDescriptionElement()));
1400    if (src.hasOrdered()) tgt.setOrderedElement(convertBoolean(src.getOrderedElement()));
1401    if (src.hasRules()) tgt.setRulesElement(convertSlicingRules(src.getRulesElement()));
1402    return tgt;
1403  }
1404
1405  public static org.hl7.fhir.dstu2016may.model.ElementDefinition.ElementDefinitionSlicingComponent convertElementDefinitionSlicingComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionSlicingComponent src) throws FHIRException {
1406    if (src == null || src.isEmpty()) return null;
1407    org.hl7.fhir.dstu2016may.model.ElementDefinition.ElementDefinitionSlicingComponent tgt = new org.hl7.fhir.dstu2016may.model.ElementDefinition.ElementDefinitionSlicingComponent();
1408    copyElement(src, tgt);
1409    for (ElementDefinitionSlicingDiscriminatorComponent t : src.getDiscriminator())
1410      tgt.addDiscriminator(ProfileUtilities.buildR2Discriminator(t));
1411    if (src.hasDescription()) tgt.setDescriptionElement(convertString(src.getDescriptionElement()));
1412    if (src.hasOrdered()) tgt.setOrderedElement(convertBoolean(src.getOrderedElement()));
1413    if (src.hasRules()) tgt.setRulesElement(convertSlicingRules(src.getRulesElement()));
1414    return tgt;
1415  }
1416
1417  static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.ElementDefinition.SlicingRules> convertSlicingRules(org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.ElementDefinition.SlicingRules> src) throws FHIRException {
1418    if (src == null || src.isEmpty()) return null;
1419    org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.ElementDefinition.SlicingRules> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.ElementDefinition.SlicingRulesEnumFactory());
1420    VersionConvertor_14_50.copyElement(src, tgt);
1421    if (src.getValue() == null) {
1422      tgt.setValue(org.hl7.fhir.r5.model.ElementDefinition.SlicingRules.NULL);
1423    } else {
1424      switch (src.getValue()) {
1425        case CLOSED:
1426          tgt.setValue(org.hl7.fhir.r5.model.ElementDefinition.SlicingRules.CLOSED);
1427          break;
1428        case OPEN:
1429          tgt.setValue(org.hl7.fhir.r5.model.ElementDefinition.SlicingRules.OPEN);
1430          break;
1431        case OPENATEND:
1432          tgt.setValue(org.hl7.fhir.r5.model.ElementDefinition.SlicingRules.OPENATEND);
1433          break;
1434        default:
1435          tgt.setValue(org.hl7.fhir.r5.model.ElementDefinition.SlicingRules.NULL);
1436          break;
1437      }
1438    }
1439    return tgt;
1440  }
1441
1442  static public org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.ElementDefinition.SlicingRules> convertSlicingRules(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.ElementDefinition.SlicingRules> src) throws FHIRException {
1443    if (src == null || src.isEmpty()) return null;
1444    org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.ElementDefinition.SlicingRules> tgt = new org.hl7.fhir.dstu2016may.model.Enumeration<>(new org.hl7.fhir.dstu2016may.model.ElementDefinition.SlicingRulesEnumFactory());
1445    VersionConvertor_14_50.copyElement(src, tgt);
1446    if (src.getValue() == null) {
1447      tgt.setValue(org.hl7.fhir.dstu2016may.model.ElementDefinition.SlicingRules.NULL);
1448    } else {
1449      switch (src.getValue()) {
1450        case CLOSED:
1451          tgt.setValue(org.hl7.fhir.dstu2016may.model.ElementDefinition.SlicingRules.CLOSED);
1452          break;
1453        case OPEN:
1454          tgt.setValue(org.hl7.fhir.dstu2016may.model.ElementDefinition.SlicingRules.OPEN);
1455          break;
1456        case OPENATEND:
1457          tgt.setValue(org.hl7.fhir.dstu2016may.model.ElementDefinition.SlicingRules.OPENATEND);
1458          break;
1459        default:
1460          tgt.setValue(org.hl7.fhir.dstu2016may.model.ElementDefinition.SlicingRules.NULL);
1461          break;
1462      }
1463    }
1464    return tgt;
1465  }
1466
1467  public static org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionBaseComponent convertElementDefinitionBaseComponent(org.hl7.fhir.dstu2016may.model.ElementDefinition.ElementDefinitionBaseComponent src) throws FHIRException {
1468    if (src == null || src.isEmpty()) return null;
1469    org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionBaseComponent tgt = new org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionBaseComponent();
1470    copyElement(src, tgt);
1471    if (src.hasPathElement()) tgt.setPathElement(convertString(src.getPathElement()));
1472    tgt.setMin(src.getMin());
1473    if (src.hasMaxElement()) tgt.setMaxElement(convertString(src.getMaxElement()));
1474    return tgt;
1475  }
1476
1477  public static org.hl7.fhir.dstu2016may.model.ElementDefinition.ElementDefinitionBaseComponent convertElementDefinitionBaseComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionBaseComponent src) throws FHIRException {
1478    if (src == null || src.isEmpty()) return null;
1479    org.hl7.fhir.dstu2016may.model.ElementDefinition.ElementDefinitionBaseComponent tgt = new org.hl7.fhir.dstu2016may.model.ElementDefinition.ElementDefinitionBaseComponent();
1480    copyElement(src, tgt);
1481    if (src.hasPathElement()) tgt.setPathElement(convertString(src.getPathElement()));
1482    tgt.setMin(src.getMin());
1483    if (src.hasMaxElement()) tgt.setMaxElement(convertString(src.getMaxElement()));
1484    return tgt;
1485  }
1486
1487  static public void convertTypeRefComponent(org.hl7.fhir.dstu2016may.model.ElementDefinition.TypeRefComponent src, List<org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent> list) throws FHIRException {
1488    if (src == null) return;
1489    org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent tgt = null;
1490    for (org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent t : list)
1491      if (t.getCode().equals(src.getCode())) tgt = t;
1492    if (tgt == null) {
1493      tgt = new org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent();
1494      list.add(tgt);
1495      copyElement(src, tgt);
1496      tgt.setCode(src.getCode());
1497    }
1498    if (tgt.hasTarget()) {
1499      for (org.hl7.fhir.dstu2016may.model.UriType u : src.getProfile()) {
1500        if (src.getCode().equals("Reference")) tgt.addTargetProfile(u.getValue());
1501        else tgt.addProfile(u.getValue());
1502      }
1503      for (org.hl7.fhir.dstu2016may.model.Extension t : src.getExtensionsByUrl(VersionConvertorConstants.PROFILE_EXTENSION)) {
1504        String s = ((org.hl7.fhir.dstu2016may.model.PrimitiveType<String>) t.getValue()).getValue();
1505        tgt.addProfile(s);
1506      }
1507    } else {
1508      for (org.hl7.fhir.dstu2016may.model.UriType u : src.getProfile()) tgt.addProfile(u.getValue());
1509    }
1510    for (org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.ElementDefinition.AggregationMode> t : src.getAggregation()) {
1511      org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.ElementDefinition.AggregationMode> a = convertAggregationMode(t);
1512      if (!tgt.hasAggregation(a.getValue())) copyElement(t, tgt.addAggregation(a.getValue()));
1513    }
1514    if (src.hasVersioning()) tgt.setVersioningElement(convertReferenceVersionRules(src.getVersioningElement()));
1515  }
1516
1517  public static void convertTypeRefComponent(org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent src, List<org.hl7.fhir.dstu2016may.model.ElementDefinition.TypeRefComponent> list) throws FHIRException {
1518    if (src == null) return;
1519    org.hl7.fhir.dstu2016may.model.ElementDefinition.TypeRefComponent tgt = new org.hl7.fhir.dstu2016may.model.ElementDefinition.TypeRefComponent();
1520    copyElement(src, tgt);
1521    tgt.setCode(src.getCode());
1522    list.add(tgt);
1523    if (src.hasTarget()) {
1524      for (org.hl7.fhir.r5.model.UriType u : src.getProfile()) {
1525        org.hl7.fhir.dstu2016may.model.Extension t = new org.hl7.fhir.dstu2016may.model.Extension(VersionConvertorConstants.PROFILE_EXTENSION);
1526        t.setValue(convertType(u));
1527        tgt.addExtension(t);
1528      }
1529      for (org.hl7.fhir.r5.model.UriType u : src.getTargetProfile()) {
1530        if (!u.equals(src.getTargetProfile().get(0))) {
1531          tgt = tgt.copy();
1532          tgt.getProfile().clear();
1533          list.add(tgt);
1534        }
1535        tgt.addProfile(u.getValue());
1536      }
1537    } else {
1538      for (org.hl7.fhir.r5.model.UriType u : src.getProfile()) {
1539        tgt.addProfile(u.getValue());
1540      }
1541    }
1542    for (org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.ElementDefinition.AggregationMode> t : src.getAggregation()) {
1543      org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.ElementDefinition.AggregationMode> a = convertAggregationMode(t);
1544      if (!tgt.hasAggregation(a.getValue())) copyElement(t, tgt.addAggregationElement().setValue(a.getValue()));
1545    }
1546    if (src.hasVersioning()) tgt.setVersioningElement(convertReferenceVersionRules(src.getVersioningElement()));
1547  }
1548
1549  static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.ElementDefinition.AggregationMode> convertAggregationMode(org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.ElementDefinition.AggregationMode> src) throws FHIRException {
1550    if (src == null || src.isEmpty()) return null;
1551    org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.ElementDefinition.AggregationMode> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.ElementDefinition.AggregationModeEnumFactory());
1552    VersionConvertor_14_50.copyElement(src, tgt);
1553    if (src.getValue() == null) {
1554      tgt.setValue(org.hl7.fhir.r5.model.ElementDefinition.AggregationMode.NULL);
1555    } else {
1556      switch (src.getValue()) {
1557        case CONTAINED:
1558          tgt.setValue(org.hl7.fhir.r5.model.ElementDefinition.AggregationMode.CONTAINED);
1559          break;
1560        case REFERENCED:
1561          tgt.setValue(org.hl7.fhir.r5.model.ElementDefinition.AggregationMode.REFERENCED);
1562          break;
1563        case BUNDLED:
1564          tgt.setValue(org.hl7.fhir.r5.model.ElementDefinition.AggregationMode.BUNDLED);
1565          break;
1566        default:
1567          tgt.setValue(org.hl7.fhir.r5.model.ElementDefinition.AggregationMode.NULL);
1568          break;
1569      }
1570    }
1571    return tgt;
1572  }
1573
1574  static public org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.ElementDefinition.AggregationMode> convertAggregationMode(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.ElementDefinition.AggregationMode> src) throws FHIRException {
1575    if (src == null || src.isEmpty()) return null;
1576    org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.ElementDefinition.AggregationMode> tgt = new org.hl7.fhir.dstu2016may.model.Enumeration<>(new org.hl7.fhir.dstu2016may.model.ElementDefinition.AggregationModeEnumFactory());
1577    VersionConvertor_14_50.copyElement(src, tgt);
1578    if (src.getValue() == null) {
1579      tgt.setValue(org.hl7.fhir.dstu2016may.model.ElementDefinition.AggregationMode.NULL);
1580    } else {
1581      switch (src.getValue()) {
1582        case CONTAINED:
1583          tgt.setValue(org.hl7.fhir.dstu2016may.model.ElementDefinition.AggregationMode.CONTAINED);
1584          break;
1585        case REFERENCED:
1586          tgt.setValue(org.hl7.fhir.dstu2016may.model.ElementDefinition.AggregationMode.REFERENCED);
1587          break;
1588        case BUNDLED:
1589          tgt.setValue(org.hl7.fhir.dstu2016may.model.ElementDefinition.AggregationMode.BUNDLED);
1590          break;
1591        default:
1592          tgt.setValue(org.hl7.fhir.dstu2016may.model.ElementDefinition.AggregationMode.NULL);
1593          break;
1594      }
1595    }
1596    return tgt;
1597  }
1598
1599  static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.ElementDefinition.ReferenceVersionRules> convertReferenceVersionRules(org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.ElementDefinition.ReferenceVersionRules> src) throws FHIRException {
1600    if (src == null || src.isEmpty()) return null;
1601    org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.ElementDefinition.ReferenceVersionRules> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.ElementDefinition.ReferenceVersionRulesEnumFactory());
1602    VersionConvertor_14_50.copyElement(src, tgt);
1603    if (src.getValue() == null) {
1604      tgt.setValue(org.hl7.fhir.r5.model.ElementDefinition.ReferenceVersionRules.NULL);
1605    } else {
1606      switch (src.getValue()) {
1607        case EITHER:
1608          tgt.setValue(org.hl7.fhir.r5.model.ElementDefinition.ReferenceVersionRules.EITHER);
1609          break;
1610        case INDEPENDENT:
1611          tgt.setValue(org.hl7.fhir.r5.model.ElementDefinition.ReferenceVersionRules.INDEPENDENT);
1612          break;
1613        case SPECIFIC:
1614          tgt.setValue(org.hl7.fhir.r5.model.ElementDefinition.ReferenceVersionRules.SPECIFIC);
1615          break;
1616        default:
1617          tgt.setValue(org.hl7.fhir.r5.model.ElementDefinition.ReferenceVersionRules.NULL);
1618          break;
1619      }
1620    }
1621    return tgt;
1622  }
1623
1624  static public org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.ElementDefinition.ReferenceVersionRules> convertReferenceVersionRules(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.ElementDefinition.ReferenceVersionRules> src) throws FHIRException {
1625    if (src == null || src.isEmpty()) return null;
1626    org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.ElementDefinition.ReferenceVersionRules> tgt = new org.hl7.fhir.dstu2016may.model.Enumeration<>(new org.hl7.fhir.dstu2016may.model.ElementDefinition.ReferenceVersionRulesEnumFactory());
1627    VersionConvertor_14_50.copyElement(src, tgt);
1628    if (src.getValue() == null) {
1629      tgt.setValue(org.hl7.fhir.dstu2016may.model.ElementDefinition.ReferenceVersionRules.NULL);
1630    } else {
1631      switch (src.getValue()) {
1632        case EITHER:
1633          tgt.setValue(org.hl7.fhir.dstu2016may.model.ElementDefinition.ReferenceVersionRules.EITHER);
1634          break;
1635        case INDEPENDENT:
1636          tgt.setValue(org.hl7.fhir.dstu2016may.model.ElementDefinition.ReferenceVersionRules.INDEPENDENT);
1637          break;
1638        case SPECIFIC:
1639          tgt.setValue(org.hl7.fhir.dstu2016may.model.ElementDefinition.ReferenceVersionRules.SPECIFIC);
1640          break;
1641        default:
1642          tgt.setValue(org.hl7.fhir.dstu2016may.model.ElementDefinition.ReferenceVersionRules.NULL);
1643          break;
1644      }
1645    }
1646    return tgt;
1647  }
1648
1649  public static org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent convertElementDefinitionConstraintComponent(org.hl7.fhir.dstu2016may.model.ElementDefinition.ElementDefinitionConstraintComponent src) throws FHIRException {
1650    if (src == null || src.isEmpty()) return null;
1651    org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent tgt = new org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent();
1652    copyElement(src, tgt);
1653    if (src.hasKeyElement()) tgt.setKeyElement(convertId(src.getKeyElement()));
1654    if (src.hasRequirements()) tgt.setRequirementsElement(convertString(src.getRequirementsElement()));
1655    if (src.hasSeverity()) tgt.setSeverityElement(convertConstraintSeverity(src.getSeverityElement()));
1656    if (src.hasHumanElement()) tgt.setHumanElement(convertString(src.getHumanElement()));
1657    if (src.hasExpression()) tgt.setExpression(convertToR4Expression(src.getExpression()));
1658    if (src.hasXpathElement()) tgt.setXpathElement(convertString(src.getXpathElement()));
1659    return tgt;
1660  }
1661
1662  public static org.hl7.fhir.dstu2016may.model.ElementDefinition.ElementDefinitionConstraintComponent convertElementDefinitionConstraintComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent src) throws FHIRException {
1663    if (src == null || src.isEmpty()) return null;
1664    org.hl7.fhir.dstu2016may.model.ElementDefinition.ElementDefinitionConstraintComponent tgt = new org.hl7.fhir.dstu2016may.model.ElementDefinition.ElementDefinitionConstraintComponent();
1665    copyElement(src, tgt);
1666    if (src.hasKeyElement()) tgt.setKeyElement(convertId(src.getKeyElement()));
1667    if (src.hasRequirements()) tgt.setRequirementsElement(convertString(src.getRequirementsElement()));
1668    if (src.hasSeverity()) tgt.setSeverityElement(convertConstraintSeverity(src.getSeverityElement()));
1669    if (src.hasHumanElement()) tgt.setHumanElement(convertString(src.getHumanElement()));
1670    if (src.hasExpression()) tgt.setExpression(convertTo2016MayExpression(src.getExpression()));
1671    if (src.hasXpathElement()) tgt.setXpathElement(convertString(src.getXpathElement()));
1672    return tgt;
1673  }
1674
1675  public static String convertToR4Expression(String oldExpression) {
1676    String pass1 = oldExpression.replaceAll("\\$context", "%context").replaceAll("\\$resource", "%resource").replaceAll("code\\+profile", "code&profile").replaceAll("path\\+'\\.'", "path&'.'").replaceAll("fullUrl\\+resource", "fullUrl&resource");
1677    String pass2 = pass1;
1678    if (pass1.endsWith(".distinct()")) pass2 = pass1.substring(0, pass2.length() - 11) + ".isDistinct()";
1679    String pass3 = pass2;
1680    if (pass2.endsWith(".empty() or (type.count() = 1)"))
1681      pass3 = pass2.substring(0, pass2.length() - 30) + ".empty() or (type.count() <= 1)";
1682    String pass4 = pass3;
1683    if (pass3.equals("duration >= 0")) pass4 = "duration.exists() implies duration >= 0";
1684    else if (pass3.equals("period >= 0")) pass4 = "period.exists() implies period >= 0";
1685    else if (pass3.equals("fullUrl.empty() xor resource")) pass4 = "fullUrl.empty() xor resource.exists()";
1686    return pass4;
1687  }
1688
1689  public static String convertTo2016MayExpression(String newExpression) {
1690    String pass1 = newExpression.replaceAll("%context", "\\$context").replaceAll("%resource", "\\$resource").replaceAll("code&profile", "code+profile").replaceAll("path&'\\.'", "path+'.'").replaceAll("fullUrl%resource", "fullUrl+resource");
1691    String pass2 = pass1;
1692    if (pass1.endsWith(".isDistinct()")) pass2 = pass1.substring(0, pass1.length() - 13) + ".distinct()";
1693    String pass3 = pass2;
1694    if (pass2.endsWith(".empty() or (type.count() <= 1)"))
1695      pass3 = pass2.substring(0, pass2.length() - 31) + ".empty() or (type.count() = 1)";
1696    String pass4 = pass3;
1697    if (pass3.equals("duration.exists() implies duration >= 0")) pass4 = "duration >= 0";
1698    else if (pass3.equals("period.exists() implies period >= 0")) pass4 = "period >= 0";
1699    else if (pass3.equals("fullUrl.empty() xor resource.exists()")) pass4 = "fullUrl.empty() xor resource";
1700    return pass4;
1701  }
1702
1703  static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.ElementDefinition.ConstraintSeverity> convertConstraintSeverity(org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.ElementDefinition.ConstraintSeverity> src) throws FHIRException {
1704    if (src == null || src.isEmpty()) return null;
1705    org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.ElementDefinition.ConstraintSeverity> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.ElementDefinition.ConstraintSeverityEnumFactory());
1706    VersionConvertor_14_50.copyElement(src, tgt);
1707    if (src.getValue() == null) {
1708      tgt.setValue(org.hl7.fhir.r5.model.ElementDefinition.ConstraintSeverity.NULL);
1709    } else {
1710      switch (src.getValue()) {
1711        case ERROR:
1712          tgt.setValue(org.hl7.fhir.r5.model.ElementDefinition.ConstraintSeverity.ERROR);
1713          break;
1714        case WARNING:
1715          tgt.setValue(org.hl7.fhir.r5.model.ElementDefinition.ConstraintSeverity.WARNING);
1716          break;
1717        default:
1718          tgt.setValue(org.hl7.fhir.r5.model.ElementDefinition.ConstraintSeverity.NULL);
1719          break;
1720      }
1721    }
1722    return tgt;
1723  }
1724
1725  static public org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.ElementDefinition.ConstraintSeverity> convertConstraintSeverity(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.ElementDefinition.ConstraintSeverity> src) throws FHIRException {
1726    if (src == null || src.isEmpty()) return null;
1727    org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.ElementDefinition.ConstraintSeverity> tgt = new org.hl7.fhir.dstu2016may.model.Enumeration<>(new org.hl7.fhir.dstu2016may.model.ElementDefinition.ConstraintSeverityEnumFactory());
1728    VersionConvertor_14_50.copyElement(src, tgt);
1729    if (src.getValue() == null) {
1730      tgt.setValue(org.hl7.fhir.dstu2016may.model.ElementDefinition.ConstraintSeverity.NULL);
1731    } else {
1732      switch (src.getValue()) {
1733        case ERROR:
1734          tgt.setValue(org.hl7.fhir.dstu2016may.model.ElementDefinition.ConstraintSeverity.ERROR);
1735          break;
1736        case WARNING:
1737          tgt.setValue(org.hl7.fhir.dstu2016may.model.ElementDefinition.ConstraintSeverity.WARNING);
1738          break;
1739        default:
1740          tgt.setValue(org.hl7.fhir.dstu2016may.model.ElementDefinition.ConstraintSeverity.NULL);
1741          break;
1742      }
1743    }
1744    return tgt;
1745  }
1746
1747  public static org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionBindingComponent convertElementDefinitionBindingComponent(org.hl7.fhir.dstu2016may.model.ElementDefinition.ElementDefinitionBindingComponent src) throws FHIRException {
1748    if (src == null || src.isEmpty()) return null;
1749    org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionBindingComponent tgt = new org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionBindingComponent();
1750    copyElement(src, tgt);
1751    if (src.hasStrength()) tgt.setStrengthElement(convertBindingStrength(src.getStrengthElement()));
1752    if (src.hasDescription()) tgt.setDescriptionElement(convertString(src.getDescriptionElement()));
1753    if (src.hasValueSet()) {
1754      org.hl7.fhir.r5.model.DataType t = convertType(src.getValueSet());
1755      if (t instanceof org.hl7.fhir.r5.model.Reference)
1756        tgt.setValueSet(((org.hl7.fhir.r5.model.Reference) t).getReference());
1757      else tgt.setValueSet(t.primitiveValue());
1758      tgt.setValueSet(VersionConvertorConstants.refToVS(tgt.getValueSet()));
1759    }
1760    return tgt;
1761  }
1762
1763  public static org.hl7.fhir.dstu2016may.model.ElementDefinition.ElementDefinitionBindingComponent convertElementDefinitionBindingComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionBindingComponent src) throws FHIRException {
1764    if (src == null || src.isEmpty()) return null;
1765    org.hl7.fhir.dstu2016may.model.ElementDefinition.ElementDefinitionBindingComponent tgt = new org.hl7.fhir.dstu2016may.model.ElementDefinition.ElementDefinitionBindingComponent();
1766    copyElement(src, tgt);
1767    if (src.hasStrength()) tgt.setStrengthElement(convertBindingStrength(src.getStrengthElement()));
1768    if (src.hasDescription()) tgt.setDescriptionElement(convertString(src.getDescriptionElement()));
1769    if (src.hasValueSet()) {
1770      String vsr = VersionConvertorConstants.vsToRef(src.getValueSet());
1771      if (vsr != null) tgt.setValueSet(new org.hl7.fhir.dstu2016may.model.UriType(vsr));
1772      else tgt.setValueSet(new org.hl7.fhir.dstu2016may.model.Reference(src.getValueSet()));
1773    }
1774    return tgt;
1775  }
1776
1777  static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Enumerations.BindingStrength> convertBindingStrength(org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.Enumerations.BindingStrength> src) throws FHIRException {
1778    if (src == null || src.isEmpty()) return null;
1779    org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Enumerations.BindingStrength> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.Enumerations.BindingStrengthEnumFactory());
1780    VersionConvertor_14_50.copyElement(src, tgt);
1781    if (src.getValue() == null) {
1782      tgt.setValue(org.hl7.fhir.r5.model.Enumerations.BindingStrength.NULL);
1783    } else {
1784      switch (src.getValue()) {
1785        case REQUIRED:
1786          tgt.setValue(org.hl7.fhir.r5.model.Enumerations.BindingStrength.REQUIRED);
1787          break;
1788        case EXTENSIBLE:
1789          tgt.setValue(org.hl7.fhir.r5.model.Enumerations.BindingStrength.EXTENSIBLE);
1790          break;
1791        case PREFERRED:
1792          tgt.setValue(org.hl7.fhir.r5.model.Enumerations.BindingStrength.PREFERRED);
1793          break;
1794        case EXAMPLE:
1795          tgt.setValue(org.hl7.fhir.r5.model.Enumerations.BindingStrength.EXAMPLE);
1796          break;
1797        default:
1798          tgt.setValue(org.hl7.fhir.r5.model.Enumerations.BindingStrength.NULL);
1799          break;
1800      }
1801    }
1802    return tgt;
1803  }
1804
1805  static public org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.Enumerations.BindingStrength> convertBindingStrength(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Enumerations.BindingStrength> src) throws FHIRException {
1806    if (src == null || src.isEmpty()) return null;
1807    org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.Enumerations.BindingStrength> tgt = new org.hl7.fhir.dstu2016may.model.Enumeration<>(new org.hl7.fhir.dstu2016may.model.Enumerations.BindingStrengthEnumFactory());
1808    VersionConvertor_14_50.copyElement(src, tgt);
1809    if (src.getValue() == null) {
1810      tgt.setValue(org.hl7.fhir.dstu2016may.model.Enumerations.BindingStrength.NULL);
1811    } else {
1812      switch (src.getValue()) {
1813        case REQUIRED:
1814          tgt.setValue(org.hl7.fhir.dstu2016may.model.Enumerations.BindingStrength.REQUIRED);
1815          break;
1816        case EXTENSIBLE:
1817          tgt.setValue(org.hl7.fhir.dstu2016may.model.Enumerations.BindingStrength.EXTENSIBLE);
1818          break;
1819        case PREFERRED:
1820          tgt.setValue(org.hl7.fhir.dstu2016may.model.Enumerations.BindingStrength.PREFERRED);
1821          break;
1822        case EXAMPLE:
1823          tgt.setValue(org.hl7.fhir.dstu2016may.model.Enumerations.BindingStrength.EXAMPLE);
1824          break;
1825        default:
1826          tgt.setValue(org.hl7.fhir.dstu2016may.model.Enumerations.BindingStrength.NULL);
1827          break;
1828      }
1829    }
1830    return tgt;
1831  }
1832
1833  public static org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionMappingComponent convertElementDefinitionMappingComponent(org.hl7.fhir.dstu2016may.model.ElementDefinition.ElementDefinitionMappingComponent src) throws FHIRException {
1834    if (src == null || src.isEmpty()) return null;
1835    org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionMappingComponent tgt = new org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionMappingComponent();
1836    copyElement(src, tgt);
1837    if (src.hasIdentityElement()) tgt.setIdentityElement(convertId(src.getIdentityElement()));
1838    if (src.hasLanguage()) tgt.setLanguageElement(convertCode(src.getLanguageElement()));
1839    if (src.hasMapElement()) tgt.setMapElement(convertString(src.getMapElement()));
1840    return tgt;
1841  }
1842
1843  public static org.hl7.fhir.dstu2016may.model.ElementDefinition.ElementDefinitionMappingComponent convertElementDefinitionMappingComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionMappingComponent src) throws FHIRException {
1844    if (src == null || src.isEmpty()) return null;
1845    org.hl7.fhir.dstu2016may.model.ElementDefinition.ElementDefinitionMappingComponent tgt = new org.hl7.fhir.dstu2016may.model.ElementDefinition.ElementDefinitionMappingComponent();
1846    copyElement(src, tgt);
1847    if (src.hasIdentityElement()) tgt.setIdentityElement(convertId(src.getIdentityElement()));
1848    if (src.hasLanguage()) tgt.setLanguageElement(convertCode(src.getLanguageElement()));
1849    if (src.hasMapElement()) tgt.setMapElement(convertString(src.getMapElement()));
1850    return tgt;
1851  }
1852
1853  public static org.hl7.fhir.r5.model.HumanName convertHumanName(org.hl7.fhir.dstu2016may.model.HumanName src) throws FHIRException {
1854    if (src == null || src.isEmpty()) return null;
1855    org.hl7.fhir.r5.model.HumanName tgt = new org.hl7.fhir.r5.model.HumanName();
1856    copyElement(src, tgt);
1857    if (src.hasUse()) tgt.setUseElement(convertNameUse(src.getUseElement()));
1858    if (src.hasText()) tgt.setTextElement(convertString(src.getTextElement()));
1859    for (org.hl7.fhir.dstu2016may.model.StringType t : src.getFamily()) tgt.setFamily(t.getValue());
1860    for (org.hl7.fhir.dstu2016may.model.StringType t : src.getGiven()) tgt.addGiven(t.getValue());
1861    for (org.hl7.fhir.dstu2016may.model.StringType t : src.getPrefix()) tgt.addPrefix(t.getValue());
1862    for (org.hl7.fhir.dstu2016may.model.StringType t : src.getSuffix()) tgt.addSuffix(t.getValue());
1863    if (src.hasPeriod()) tgt.setPeriod(convertPeriod(src.getPeriod()));
1864    return tgt;
1865  }
1866
1867  public static org.hl7.fhir.dstu2016may.model.HumanName convertHumanName(org.hl7.fhir.r5.model.HumanName src) throws FHIRException {
1868    if (src == null || src.isEmpty()) return null;
1869    org.hl7.fhir.dstu2016may.model.HumanName tgt = new org.hl7.fhir.dstu2016may.model.HumanName();
1870    copyElement(src, tgt);
1871    if (src.hasUse()) tgt.setUseElement(convertNameUse(src.getUseElement()));
1872    if (src.hasText()) tgt.setTextElement(convertString(src.getTextElement()));
1873    if (src.hasFamily()) tgt.addFamily(src.getFamily());
1874    for (org.hl7.fhir.r5.model.StringType t : src.getGiven()) tgt.addGiven(t.getValue());
1875    for (org.hl7.fhir.r5.model.StringType t : src.getPrefix()) tgt.addPrefix(t.getValue());
1876    for (org.hl7.fhir.r5.model.StringType t : src.getSuffix()) tgt.addSuffix(t.getValue());
1877    if (src.hasPeriod()) tgt.setPeriod(convertPeriod(src.getPeriod()));
1878    return tgt;
1879  }
1880
1881  static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.HumanName.NameUse> convertNameUse(org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.HumanName.NameUse> src) throws FHIRException {
1882    if (src == null || src.isEmpty()) return null;
1883    org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.HumanName.NameUse> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.HumanName.NameUseEnumFactory());
1884    VersionConvertor_14_50.copyElement(src, tgt);
1885    if (src.getValue() == null) {
1886      tgt.setValue(org.hl7.fhir.r5.model.HumanName.NameUse.NULL);
1887    } else {
1888      switch (src.getValue()) {
1889        case USUAL:
1890          tgt.setValue(org.hl7.fhir.r5.model.HumanName.NameUse.USUAL);
1891          break;
1892        case OFFICIAL:
1893          tgt.setValue(org.hl7.fhir.r5.model.HumanName.NameUse.OFFICIAL);
1894          break;
1895        case TEMP:
1896          tgt.setValue(org.hl7.fhir.r5.model.HumanName.NameUse.TEMP);
1897          break;
1898        case NICKNAME:
1899          tgt.setValue(org.hl7.fhir.r5.model.HumanName.NameUse.NICKNAME);
1900          break;
1901        case ANONYMOUS:
1902          tgt.setValue(org.hl7.fhir.r5.model.HumanName.NameUse.ANONYMOUS);
1903          break;
1904        case OLD:
1905          tgt.setValue(org.hl7.fhir.r5.model.HumanName.NameUse.OLD);
1906          break;
1907        case MAIDEN:
1908          tgt.setValue(org.hl7.fhir.r5.model.HumanName.NameUse.MAIDEN);
1909          break;
1910        default:
1911          tgt.setValue(org.hl7.fhir.r5.model.HumanName.NameUse.NULL);
1912          break;
1913      }
1914    }
1915    return tgt;
1916  }
1917
1918  static public org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.HumanName.NameUse> convertNameUse(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.HumanName.NameUse> src) throws FHIRException {
1919    if (src == null || src.isEmpty()) return null;
1920    org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.HumanName.NameUse> tgt = new org.hl7.fhir.dstu2016may.model.Enumeration<>(new org.hl7.fhir.dstu2016may.model.HumanName.NameUseEnumFactory());
1921    VersionConvertor_14_50.copyElement(src, tgt);
1922    if (src.getValue() == null) {
1923      tgt.setValue(org.hl7.fhir.dstu2016may.model.HumanName.NameUse.NULL);
1924    } else {
1925      switch (src.getValue()) {
1926        case USUAL:
1927          tgt.setValue(org.hl7.fhir.dstu2016may.model.HumanName.NameUse.USUAL);
1928          break;
1929        case OFFICIAL:
1930          tgt.setValue(org.hl7.fhir.dstu2016may.model.HumanName.NameUse.OFFICIAL);
1931          break;
1932        case TEMP:
1933          tgt.setValue(org.hl7.fhir.dstu2016may.model.HumanName.NameUse.TEMP);
1934          break;
1935        case NICKNAME:
1936          tgt.setValue(org.hl7.fhir.dstu2016may.model.HumanName.NameUse.NICKNAME);
1937          break;
1938        case ANONYMOUS:
1939          tgt.setValue(org.hl7.fhir.dstu2016may.model.HumanName.NameUse.ANONYMOUS);
1940          break;
1941        case OLD:
1942          tgt.setValue(org.hl7.fhir.dstu2016may.model.HumanName.NameUse.OLD);
1943          break;
1944        case MAIDEN:
1945          tgt.setValue(org.hl7.fhir.dstu2016may.model.HumanName.NameUse.MAIDEN);
1946          break;
1947        default:
1948          tgt.setValue(org.hl7.fhir.dstu2016may.model.HumanName.NameUse.NULL);
1949          break;
1950      }
1951    }
1952    return tgt;
1953  }
1954
1955  public static org.hl7.fhir.r5.model.Meta convertMeta(org.hl7.fhir.dstu2016may.model.Meta src) throws FHIRException {
1956    if (src == null || src.isEmpty()) return null;
1957    org.hl7.fhir.r5.model.Meta tgt = new org.hl7.fhir.r5.model.Meta();
1958    copyElement(src, tgt);
1959    if (src.hasVersionId()) tgt.setVersionIdElement(convertId(src.getVersionIdElement()));
1960    if (src.hasLastUpdated()) tgt.setLastUpdatedElement(convertInstant(src.getLastUpdatedElement()));
1961    for (org.hl7.fhir.dstu2016may.model.UriType t : src.getProfile()) tgt.addProfile(t.getValue());
1962    for (org.hl7.fhir.dstu2016may.model.Coding t : src.getSecurity()) tgt.addSecurity(convertCoding(t));
1963    for (org.hl7.fhir.dstu2016may.model.Coding t : src.getTag()) tgt.addTag(convertCoding(t));
1964    return tgt;
1965  }
1966
1967  public static org.hl7.fhir.dstu2016may.model.Meta convertMeta(org.hl7.fhir.r5.model.Meta src) throws FHIRException {
1968    if (src == null || src.isEmpty()) return null;
1969    org.hl7.fhir.dstu2016may.model.Meta tgt = new org.hl7.fhir.dstu2016may.model.Meta();
1970    copyElement(src, tgt);
1971    if (src.hasVersionId()) tgt.setVersionIdElement(convertId(src.getVersionIdElement()));
1972    if (src.hasLastUpdated()) tgt.setLastUpdatedElement(convertInstant(src.getLastUpdatedElement()));
1973    for (org.hl7.fhir.r5.model.UriType t : src.getProfile()) tgt.addProfile(t.getValue());
1974    for (org.hl7.fhir.r5.model.Coding t : src.getSecurity()) tgt.addSecurity(convertCoding(t));
1975    for (org.hl7.fhir.r5.model.Coding t : src.getTag()) tgt.addTag(convertCoding(t));
1976    return tgt;
1977  }
1978
1979  public static org.hl7.fhir.r5.model.Timing convertTiming(org.hl7.fhir.dstu2016may.model.Timing src) throws FHIRException {
1980    if (src == null || src.isEmpty()) return null;
1981    org.hl7.fhir.r5.model.Timing tgt = new org.hl7.fhir.r5.model.Timing();
1982    copyElement(src, tgt);
1983    for (org.hl7.fhir.dstu2016may.model.DateTimeType t : src.getEvent()) tgt.addEvent(t.getValue());
1984    if (src.hasRepeat()) tgt.setRepeat(convertTimingRepeatComponent(src.getRepeat()));
1985    if (src.hasCode()) tgt.setCode(convertCodeableConcept(src.getCode()));
1986    return tgt;
1987  }
1988
1989  public static org.hl7.fhir.dstu2016may.model.Timing convertTiming(org.hl7.fhir.r5.model.Timing src) throws FHIRException {
1990    if (src == null || src.isEmpty()) return null;
1991    org.hl7.fhir.dstu2016may.model.Timing tgt = new org.hl7.fhir.dstu2016may.model.Timing();
1992    copyElement(src, tgt);
1993    for (org.hl7.fhir.r5.model.DateTimeType t : src.getEvent()) tgt.addEvent(t.getValue());
1994    if (src.hasRepeat()) tgt.setRepeat(convertTimingRepeatComponent(src.getRepeat()));
1995    if (src.hasCode()) tgt.setCode(convertCodeableConcept(src.getCode()));
1996    return tgt;
1997  }
1998
1999  public static org.hl7.fhir.r5.model.Timing.TimingRepeatComponent convertTimingRepeatComponent(org.hl7.fhir.dstu2016may.model.Timing.TimingRepeatComponent src) throws FHIRException {
2000    if (src == null || src.isEmpty()) return null;
2001    org.hl7.fhir.r5.model.Timing.TimingRepeatComponent tgt = new org.hl7.fhir.r5.model.Timing.TimingRepeatComponent();
2002    copyElement(src, tgt);
2003    if (src.hasBounds()) tgt.setBounds(convertType(src.getBounds()));
2004    if (src.hasCount()) tgt.setCount(src.getCount());
2005    if (src.hasCountMax()) tgt.setCountMax(src.getCountMax());
2006    if (src.hasDuration()) tgt.setDurationElement(convertDecimal(src.getDurationElement()));
2007    if (src.hasDurationMax()) tgt.setDurationMaxElement(convertDecimal(src.getDurationMaxElement()));
2008    if (src.hasDurationUnit()) tgt.setDurationUnitElement(convertUnitsOfTime(src.getDurationUnitElement()));
2009    if (src.hasFrequency()) tgt.setFrequency(src.getFrequency());
2010    if (src.hasFrequencyMax()) tgt.setFrequencyMax(src.getFrequencyMax());
2011    if (src.hasPeriod()) tgt.setPeriodElement(convertDecimal(src.getPeriodElement()));
2012    if (src.hasPeriodMax()) tgt.setPeriodMaxElement(convertDecimal(src.getPeriodMaxElement()));
2013    if (src.hasPeriodUnit()) tgt.setPeriodUnitElement(convertUnitsOfTime(src.getPeriodUnitElement()));
2014    if (src.hasWhen()) tgt.setWhen(Collections.singletonList(convertEventTiming(src.getWhenElement())));
2015    if (src.hasOffset()) tgt.setOffsetElement(convertUnsignedInt(src.getOffsetElement()));
2016    return tgt;
2017  }
2018
2019  public static org.hl7.fhir.dstu2016may.model.Timing.TimingRepeatComponent convertTimingRepeatComponent(org.hl7.fhir.r5.model.Timing.TimingRepeatComponent src) throws FHIRException {
2020    if (src == null || src.isEmpty()) return null;
2021    org.hl7.fhir.dstu2016may.model.Timing.TimingRepeatComponent tgt = new org.hl7.fhir.dstu2016may.model.Timing.TimingRepeatComponent();
2022    copyElement(src, tgt);
2023    if (src.hasBounds()) tgt.setBounds(convertType(src.getBounds()));
2024    if (src.hasCount()) tgt.setCount(src.getCount());
2025    if (src.hasCountMax()) tgt.setCountMax(src.getCountMax());
2026    if (src.hasDuration()) tgt.setDurationElement(convertDecimal(src.getDurationElement()));
2027    if (src.hasDurationMax()) tgt.setDurationMaxElement(convertDecimal(src.getDurationMaxElement()));
2028    if (src.hasDurationUnit()) tgt.setDurationUnitElement(convertUnitsOfTime(src.getDurationUnitElement()));
2029    if (src.hasFrequency()) tgt.setFrequency(src.getFrequency());
2030    if (src.hasFrequencyMax()) tgt.setFrequencyMax(src.getFrequencyMax());
2031    if (src.hasPeriod()) tgt.setPeriodElement(convertDecimal(src.getPeriodElement()));
2032    if (src.hasPeriodMax()) tgt.setPeriodMaxElement(convertDecimal(src.getPeriodMaxElement()));
2033    if (src.hasPeriodUnit()) tgt.setPeriodUnitElement(convertUnitsOfTime(src.getPeriodUnitElement()));
2034    if (src.hasWhen()) tgt.setWhenElement(convertEventTiming(src.getWhen().get(0)));
2035    if (src.hasOffset()) tgt.setOffsetElement(convertUnsignedInt(src.getOffsetElement()));
2036    return tgt;
2037  }
2038
2039  static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Timing.UnitsOfTime> convertUnitsOfTime(org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.Timing.UnitsOfTime> src) throws FHIRException {
2040    if (src == null || src.isEmpty()) return null;
2041    org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Timing.UnitsOfTime> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.Timing.UnitsOfTimeEnumFactory());
2042    VersionConvertor_14_50.copyElement(src, tgt);
2043    if (src.getValue() == null) {
2044      tgt.setValue(org.hl7.fhir.r5.model.Timing.UnitsOfTime.NULL);
2045    } else {
2046      switch (src.getValue()) {
2047        case S:
2048          tgt.setValue(org.hl7.fhir.r5.model.Timing.UnitsOfTime.S);
2049          break;
2050        case MIN:
2051          tgt.setValue(org.hl7.fhir.r5.model.Timing.UnitsOfTime.MIN);
2052          break;
2053        case H:
2054          tgt.setValue(org.hl7.fhir.r5.model.Timing.UnitsOfTime.H);
2055          break;
2056        case D:
2057          tgt.setValue(org.hl7.fhir.r5.model.Timing.UnitsOfTime.D);
2058          break;
2059        case WK:
2060          tgt.setValue(org.hl7.fhir.r5.model.Timing.UnitsOfTime.WK);
2061          break;
2062        case MO:
2063          tgt.setValue(org.hl7.fhir.r5.model.Timing.UnitsOfTime.MO);
2064          break;
2065        case A:
2066          tgt.setValue(org.hl7.fhir.r5.model.Timing.UnitsOfTime.A);
2067          break;
2068        default:
2069          tgt.setValue(org.hl7.fhir.r5.model.Timing.UnitsOfTime.NULL);
2070          break;
2071      }
2072    }
2073    return tgt;
2074  }
2075
2076  static public org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.Timing.UnitsOfTime> convertUnitsOfTime(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Timing.UnitsOfTime> src) throws FHIRException {
2077    if (src == null || src.isEmpty()) return null;
2078    org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.Timing.UnitsOfTime> tgt = new org.hl7.fhir.dstu2016may.model.Enumeration<>(new org.hl7.fhir.dstu2016may.model.Timing.UnitsOfTimeEnumFactory());
2079    VersionConvertor_14_50.copyElement(src, tgt);
2080    if (src.getValue() == null) {
2081      tgt.setValue(org.hl7.fhir.dstu2016may.model.Timing.UnitsOfTime.NULL);
2082    } else {
2083      switch (src.getValue()) {
2084        case S:
2085          tgt.setValue(org.hl7.fhir.dstu2016may.model.Timing.UnitsOfTime.S);
2086          break;
2087        case MIN:
2088          tgt.setValue(org.hl7.fhir.dstu2016may.model.Timing.UnitsOfTime.MIN);
2089          break;
2090        case H:
2091          tgt.setValue(org.hl7.fhir.dstu2016may.model.Timing.UnitsOfTime.H);
2092          break;
2093        case D:
2094          tgt.setValue(org.hl7.fhir.dstu2016may.model.Timing.UnitsOfTime.D);
2095          break;
2096        case WK:
2097          tgt.setValue(org.hl7.fhir.dstu2016may.model.Timing.UnitsOfTime.WK);
2098          break;
2099        case MO:
2100          tgt.setValue(org.hl7.fhir.dstu2016may.model.Timing.UnitsOfTime.MO);
2101          break;
2102        case A:
2103          tgt.setValue(org.hl7.fhir.dstu2016may.model.Timing.UnitsOfTime.A);
2104          break;
2105        default:
2106          tgt.setValue(org.hl7.fhir.dstu2016may.model.Timing.UnitsOfTime.NULL);
2107          break;
2108      }
2109    }
2110    return tgt;
2111  }
2112
2113  static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Timing.EventTiming> convertEventTiming(org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.Timing.EventTiming> src) throws FHIRException {
2114    if (src == null || src.isEmpty()) return null;
2115    org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Timing.EventTiming> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.Timing.EventTimingEnumFactory());
2116    VersionConvertor_14_50.copyElement(src, tgt);
2117    if (src.getValue() == null) {
2118      tgt.setValue(org.hl7.fhir.r5.model.Timing.EventTiming.NULL);
2119    } else {
2120      switch (src.getValue()) {
2121        case HS:
2122          tgt.setValue(org.hl7.fhir.r5.model.Timing.EventTiming.HS);
2123          break;
2124        case WAKE:
2125          tgt.setValue(org.hl7.fhir.r5.model.Timing.EventTiming.WAKE);
2126          break;
2127        case C:
2128          tgt.setValue(org.hl7.fhir.r5.model.Timing.EventTiming.C);
2129          break;
2130        case CM:
2131          tgt.setValue(org.hl7.fhir.r5.model.Timing.EventTiming.CM);
2132          break;
2133        case CD:
2134          tgt.setValue(org.hl7.fhir.r5.model.Timing.EventTiming.CD);
2135          break;
2136        case CV:
2137          tgt.setValue(org.hl7.fhir.r5.model.Timing.EventTiming.CV);
2138          break;
2139        case AC:
2140          tgt.setValue(org.hl7.fhir.r5.model.Timing.EventTiming.AC);
2141          break;
2142        case ACM:
2143          tgt.setValue(org.hl7.fhir.r5.model.Timing.EventTiming.ACM);
2144          break;
2145        case ACD:
2146          tgt.setValue(org.hl7.fhir.r5.model.Timing.EventTiming.ACD);
2147          break;
2148        case ACV:
2149          tgt.setValue(org.hl7.fhir.r5.model.Timing.EventTiming.ACV);
2150          break;
2151        case PC:
2152          tgt.setValue(org.hl7.fhir.r5.model.Timing.EventTiming.PC);
2153          break;
2154        case PCM:
2155          tgt.setValue(org.hl7.fhir.r5.model.Timing.EventTiming.PCM);
2156          break;
2157        case PCD:
2158          tgt.setValue(org.hl7.fhir.r5.model.Timing.EventTiming.PCD);
2159          break;
2160        case PCV:
2161          tgt.setValue(org.hl7.fhir.r5.model.Timing.EventTiming.PCV);
2162          break;
2163        default:
2164          tgt.setValue(org.hl7.fhir.r5.model.Timing.EventTiming.NULL);
2165          break;
2166      }
2167    }
2168    return tgt;
2169  }
2170
2171  static public org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.Timing.EventTiming> convertEventTiming(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Timing.EventTiming> src) throws FHIRException {
2172    if (src == null || src.isEmpty()) return null;
2173    org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.Timing.EventTiming> tgt = new org.hl7.fhir.dstu2016may.model.Enumeration<>(new org.hl7.fhir.dstu2016may.model.Timing.EventTimingEnumFactory());
2174    VersionConvertor_14_50.copyElement(src, tgt);
2175    if (src.getValue() == null) {
2176      tgt.setValue(org.hl7.fhir.dstu2016may.model.Timing.EventTiming.NULL);
2177    } else {
2178      switch (src.getValue()) {
2179        case HS:
2180          tgt.setValue(org.hl7.fhir.dstu2016may.model.Timing.EventTiming.HS);
2181          break;
2182        case WAKE:
2183          tgt.setValue(org.hl7.fhir.dstu2016may.model.Timing.EventTiming.WAKE);
2184          break;
2185        case C:
2186          tgt.setValue(org.hl7.fhir.dstu2016may.model.Timing.EventTiming.C);
2187          break;
2188        case CM:
2189          tgt.setValue(org.hl7.fhir.dstu2016may.model.Timing.EventTiming.CM);
2190          break;
2191        case CD:
2192          tgt.setValue(org.hl7.fhir.dstu2016may.model.Timing.EventTiming.CD);
2193          break;
2194        case CV:
2195          tgt.setValue(org.hl7.fhir.dstu2016may.model.Timing.EventTiming.CV);
2196          break;
2197        case AC:
2198          tgt.setValue(org.hl7.fhir.dstu2016may.model.Timing.EventTiming.AC);
2199          break;
2200        case ACM:
2201          tgt.setValue(org.hl7.fhir.dstu2016may.model.Timing.EventTiming.ACM);
2202          break;
2203        case ACD:
2204          tgt.setValue(org.hl7.fhir.dstu2016may.model.Timing.EventTiming.ACD);
2205          break;
2206        case ACV:
2207          tgt.setValue(org.hl7.fhir.dstu2016may.model.Timing.EventTiming.ACV);
2208          break;
2209        case PC:
2210          tgt.setValue(org.hl7.fhir.dstu2016may.model.Timing.EventTiming.PC);
2211          break;
2212        case PCM:
2213          tgt.setValue(org.hl7.fhir.dstu2016may.model.Timing.EventTiming.PCM);
2214          break;
2215        case PCD:
2216          tgt.setValue(org.hl7.fhir.dstu2016may.model.Timing.EventTiming.PCD);
2217          break;
2218        case PCV:
2219          tgt.setValue(org.hl7.fhir.dstu2016may.model.Timing.EventTiming.PCV);
2220          break;
2221        default:
2222          tgt.setValue(org.hl7.fhir.dstu2016may.model.Timing.EventTiming.NULL);
2223          break;
2224      }
2225    }
2226    return tgt;
2227  }
2228
2229  public static org.hl7.fhir.r5.model.Quantity convertSimpleQuantity(org.hl7.fhir.dstu2016may.model.SimpleQuantity src) throws FHIRException {
2230    if (src == null || src.isEmpty()) return null;
2231    org.hl7.fhir.r5.model.SimpleQuantity tgt = new org.hl7.fhir.r5.model.SimpleQuantity();
2232    copyElement(src, tgt);
2233    if (src.hasValue()) tgt.setValueElement(convertDecimal(src.getValueElement()));
2234    if (src.hasComparator()) tgt.setComparatorElement(convertQuantityComparator(src.getComparatorElement()));
2235    if (src.hasUnit()) tgt.setUnitElement(convertString(src.getUnitElement()));
2236    if (src.hasSystem()) tgt.setSystemElement(convertUri(src.getSystemElement()));
2237    if (src.hasCode()) tgt.setCodeElement(convertCode(src.getCodeElement()));
2238    return tgt;
2239  }
2240
2241  public static org.hl7.fhir.dstu2016may.model.SimpleQuantity convertSimpleQuantity(org.hl7.fhir.r5.model.Quantity src) throws FHIRException {
2242    if (src == null || src.isEmpty()) return null;
2243    org.hl7.fhir.dstu2016may.model.SimpleQuantity tgt = new org.hl7.fhir.dstu2016may.model.SimpleQuantity();
2244    copyElement(src, tgt);
2245    if (src.hasValue()) tgt.setValueElement(convertDecimal(src.getValueElement()));
2246    if (src.hasComparator()) tgt.setComparatorElement(convertQuantityComparator(src.getComparatorElement()));
2247    if (src.hasUnit()) tgt.setUnitElement(convertString(src.getUnitElement()));
2248    if (src.hasSystem()) tgt.setSystemElement(convertUri(src.getSystemElement()));
2249    if (src.hasCode()) tgt.setCodeElement(convertCode(src.getCodeElement()));
2250    return tgt;
2251  }
2252
2253  public static org.hl7.fhir.r5.model.DataType convertType(org.hl7.fhir.dstu2016may.model.Type src) throws FHIRException {
2254    if (src == null || src.isEmpty()) return null;
2255    if (src instanceof org.hl7.fhir.dstu2016may.model.Base64BinaryType)
2256      return convertBase64Binary((org.hl7.fhir.dstu2016may.model.Base64BinaryType) src);
2257    if (src instanceof org.hl7.fhir.dstu2016may.model.BooleanType)
2258      return convertBoolean((org.hl7.fhir.dstu2016may.model.BooleanType) src);
2259    if (src instanceof org.hl7.fhir.dstu2016may.model.CodeType)
2260      return convertCode((org.hl7.fhir.dstu2016may.model.CodeType) src);
2261    if (src instanceof org.hl7.fhir.dstu2016may.model.DateType)
2262      return convertDate((org.hl7.fhir.dstu2016may.model.DateType) src);
2263    if (src instanceof org.hl7.fhir.dstu2016may.model.DateTimeType)
2264      return convertDateTime((org.hl7.fhir.dstu2016may.model.DateTimeType) src);
2265    if (src instanceof org.hl7.fhir.dstu2016may.model.DecimalType)
2266      return convertDecimal((org.hl7.fhir.dstu2016may.model.DecimalType) src);
2267    if (src instanceof org.hl7.fhir.dstu2016may.model.IdType)
2268      return convertId((org.hl7.fhir.dstu2016may.model.IdType) src);
2269    if (src instanceof org.hl7.fhir.dstu2016may.model.InstantType)
2270      return convertInstant((org.hl7.fhir.dstu2016may.model.InstantType) src);
2271    if (src instanceof org.hl7.fhir.dstu2016may.model.MarkdownType)
2272      return convertMarkdown((org.hl7.fhir.dstu2016may.model.MarkdownType) src);
2273    if (src instanceof org.hl7.fhir.dstu2016may.model.OidType)
2274      return convertOid((org.hl7.fhir.dstu2016may.model.OidType) src);
2275    if (src instanceof org.hl7.fhir.dstu2016may.model.PositiveIntType)
2276      return convertPositiveInt((org.hl7.fhir.dstu2016may.model.PositiveIntType) src);
2277    if (src instanceof org.hl7.fhir.dstu2016may.model.StringType)
2278      return convertString((org.hl7.fhir.dstu2016may.model.StringType) src);
2279    if (src instanceof org.hl7.fhir.dstu2016may.model.TimeType)
2280      return convertTime((org.hl7.fhir.dstu2016may.model.TimeType) src);
2281    if (src instanceof org.hl7.fhir.dstu2016may.model.UnsignedIntType)
2282      return convertUnsignedInt((org.hl7.fhir.dstu2016may.model.UnsignedIntType) src);
2283    if (src instanceof org.hl7.fhir.dstu2016may.model.IntegerType)
2284      return convertInteger((org.hl7.fhir.dstu2016may.model.IntegerType) src);
2285    if (src instanceof org.hl7.fhir.dstu2016may.model.UriType)
2286      return convertUri((org.hl7.fhir.dstu2016may.model.UriType) src);
2287    if (src instanceof org.hl7.fhir.dstu2016may.model.UuidType)
2288      return convertUuid((org.hl7.fhir.dstu2016may.model.UuidType) src);
2289    if (src instanceof org.hl7.fhir.dstu2016may.model.Extension)
2290      return convertExtension((org.hl7.fhir.dstu2016may.model.Extension) src);
2291    if (src instanceof org.hl7.fhir.dstu2016may.model.Narrative)
2292      return convertNarrative((org.hl7.fhir.dstu2016may.model.Narrative) src);
2293    if (src instanceof org.hl7.fhir.dstu2016may.model.Age) return convertAge((org.hl7.fhir.dstu2016may.model.Age) src);
2294    if (src instanceof org.hl7.fhir.dstu2016may.model.Annotation)
2295      return convertAnnotation((org.hl7.fhir.dstu2016may.model.Annotation) src);
2296    if (src instanceof org.hl7.fhir.dstu2016may.model.Attachment)
2297      return convertAttachment((org.hl7.fhir.dstu2016may.model.Attachment) src);
2298    if (src instanceof org.hl7.fhir.dstu2016may.model.CodeableConcept)
2299      return convertCodeableConcept((org.hl7.fhir.dstu2016may.model.CodeableConcept) src);
2300    if (src instanceof org.hl7.fhir.dstu2016may.model.Coding)
2301      return convertCoding((org.hl7.fhir.dstu2016may.model.Coding) src);
2302    if (src instanceof org.hl7.fhir.dstu2016may.model.Count)
2303      return convertCount((org.hl7.fhir.dstu2016may.model.Count) src);
2304    if (src instanceof org.hl7.fhir.dstu2016may.model.Distance)
2305      return convertDistance((org.hl7.fhir.dstu2016may.model.Distance) src);
2306    if (src instanceof org.hl7.fhir.dstu2016may.model.Duration)
2307      return convertDuration((org.hl7.fhir.dstu2016may.model.Duration) src);
2308    if (src instanceof org.hl7.fhir.dstu2016may.model.Identifier)
2309      return convertIdentifier((org.hl7.fhir.dstu2016may.model.Identifier) src);
2310    if (src instanceof org.hl7.fhir.dstu2016may.model.Money)
2311      return convertMoney((org.hl7.fhir.dstu2016may.model.Money) src);
2312    if (src instanceof org.hl7.fhir.dstu2016may.model.Period)
2313      return convertPeriod((org.hl7.fhir.dstu2016may.model.Period) src);
2314    if (src instanceof org.hl7.fhir.dstu2016may.model.Quantity)
2315      return convertQuantity((org.hl7.fhir.dstu2016may.model.Quantity) src);
2316    if (src instanceof org.hl7.fhir.dstu2016may.model.Range)
2317      return convertRange((org.hl7.fhir.dstu2016may.model.Range) src);
2318    if (src instanceof org.hl7.fhir.dstu2016may.model.Ratio)
2319      return convertRatio((org.hl7.fhir.dstu2016may.model.Ratio) src);
2320    if (src instanceof org.hl7.fhir.dstu2016may.model.Reference)
2321      return convertReference((org.hl7.fhir.dstu2016may.model.Reference) src);
2322    if (src instanceof org.hl7.fhir.dstu2016may.model.SampledData)
2323      return convertSampledData((org.hl7.fhir.dstu2016may.model.SampledData) src);
2324    if (src instanceof org.hl7.fhir.dstu2016may.model.Signature)
2325      return convertSignature((org.hl7.fhir.dstu2016may.model.Signature) src);
2326    if (src instanceof org.hl7.fhir.dstu2016may.model.Address)
2327      return convertAddress((org.hl7.fhir.dstu2016may.model.Address) src);
2328    if (src instanceof org.hl7.fhir.dstu2016may.model.ContactPoint)
2329      return convertContactPoint((org.hl7.fhir.dstu2016may.model.ContactPoint) src);
2330    if (src instanceof org.hl7.fhir.dstu2016may.model.HumanName)
2331      return convertHumanName((org.hl7.fhir.dstu2016may.model.HumanName) src);
2332    if (src instanceof org.hl7.fhir.dstu2016may.model.Meta)
2333      return convertMeta((org.hl7.fhir.dstu2016may.model.Meta) src);
2334    if (src instanceof org.hl7.fhir.dstu2016may.model.Timing)
2335      return convertTiming((org.hl7.fhir.dstu2016may.model.Timing) src);
2336    throw new FHIRException("Unknown type " + src.fhirType());
2337  }
2338
2339  public static org.hl7.fhir.dstu2016may.model.Type convertType(org.hl7.fhir.r5.model.DataType src) throws FHIRException {
2340    if (src == null || src.isEmpty()) return null;
2341    if (src instanceof org.hl7.fhir.r5.model.Base64BinaryType)
2342      return convertBase64Binary((org.hl7.fhir.r5.model.Base64BinaryType) src);
2343    if (src instanceof org.hl7.fhir.r5.model.BooleanType)
2344      return convertBoolean((org.hl7.fhir.r5.model.BooleanType) src);
2345    if (src instanceof org.hl7.fhir.r5.model.CodeType) return convertCode((org.hl7.fhir.r5.model.CodeType) src);
2346    if (src instanceof org.hl7.fhir.r5.model.DateType) return convertDate((org.hl7.fhir.r5.model.DateType) src);
2347    if (src instanceof org.hl7.fhir.r5.model.DateTimeType)
2348      return convertDateTime((org.hl7.fhir.r5.model.DateTimeType) src);
2349    if (src instanceof org.hl7.fhir.r5.model.DecimalType)
2350      return convertDecimal((org.hl7.fhir.r5.model.DecimalType) src);
2351    if (src instanceof org.hl7.fhir.r5.model.IdType) return convertId((org.hl7.fhir.r5.model.IdType) src);
2352    if (src instanceof org.hl7.fhir.r5.model.InstantType)
2353      return convertInstant((org.hl7.fhir.r5.model.InstantType) src);
2354    if (src instanceof org.hl7.fhir.r5.model.MarkdownType)
2355      return convertMarkdown((org.hl7.fhir.r5.model.MarkdownType) src);
2356    if (src instanceof org.hl7.fhir.r5.model.OidType) return convertOid((org.hl7.fhir.r5.model.OidType) src);
2357    if (src instanceof org.hl7.fhir.r5.model.PositiveIntType)
2358      return convertPositiveInt((org.hl7.fhir.r5.model.PositiveIntType) src);
2359    if (src instanceof org.hl7.fhir.r5.model.StringType) return convertString((org.hl7.fhir.r5.model.StringType) src);
2360    if (src instanceof org.hl7.fhir.r5.model.TimeType) return convertTime((org.hl7.fhir.r5.model.TimeType) src);
2361    if (src instanceof org.hl7.fhir.r5.model.UnsignedIntType)
2362      return convertUnsignedInt((org.hl7.fhir.r5.model.UnsignedIntType) src);
2363    if (src instanceof org.hl7.fhir.r5.model.IntegerType)
2364      return convertInteger((org.hl7.fhir.r5.model.IntegerType) src);
2365    if (src instanceof org.hl7.fhir.r5.model.UriType) return convertUri((org.hl7.fhir.r5.model.UriType) src);
2366    if (src instanceof org.hl7.fhir.r5.model.UuidType) return convertUuid((org.hl7.fhir.r5.model.UuidType) src);
2367    if (src instanceof org.hl7.fhir.r5.model.Extension) return convertExtension((org.hl7.fhir.r5.model.Extension) src);
2368    if (src instanceof org.hl7.fhir.r5.model.Narrative) return convertNarrative((org.hl7.fhir.r5.model.Narrative) src);
2369    if (src instanceof org.hl7.fhir.r5.model.Age) return convertAge((org.hl7.fhir.r5.model.Age) src);
2370    if (src instanceof org.hl7.fhir.r5.model.Annotation)
2371      return convertAnnotation((org.hl7.fhir.r5.model.Annotation) src);
2372    if (src instanceof org.hl7.fhir.r5.model.Attachment)
2373      return convertAttachment((org.hl7.fhir.r5.model.Attachment) src);
2374    if (src instanceof org.hl7.fhir.r5.model.CodeableConcept)
2375      return convertCodeableConcept((org.hl7.fhir.r5.model.CodeableConcept) src);
2376    if (src instanceof org.hl7.fhir.r5.model.Coding) return convertCoding((org.hl7.fhir.r5.model.Coding) src);
2377    if (src instanceof org.hl7.fhir.r5.model.Count) return convertCount((org.hl7.fhir.r5.model.Count) src);
2378    if (src instanceof org.hl7.fhir.r5.model.Distance) return convertDistance((org.hl7.fhir.r5.model.Distance) src);
2379    if (src instanceof org.hl7.fhir.r5.model.Duration) return convertDuration((org.hl7.fhir.r5.model.Duration) src);
2380    if (src instanceof org.hl7.fhir.r5.model.Identifier)
2381      return convertIdentifier((org.hl7.fhir.r5.model.Identifier) src);
2382    if (src instanceof org.hl7.fhir.r5.model.Money) return convertMoney((org.hl7.fhir.r5.model.Money) src);
2383    if (src instanceof org.hl7.fhir.r5.model.Period) return convertPeriod((org.hl7.fhir.r5.model.Period) src);
2384    if (src instanceof org.hl7.fhir.r5.model.Quantity) return convertQuantity((org.hl7.fhir.r5.model.Quantity) src);
2385    if (src instanceof org.hl7.fhir.r5.model.Range) return convertRange((org.hl7.fhir.r5.model.Range) src);
2386    if (src instanceof org.hl7.fhir.r5.model.Ratio) return convertRatio((org.hl7.fhir.r5.model.Ratio) src);
2387    if (src instanceof org.hl7.fhir.r5.model.Reference) return convertReference((org.hl7.fhir.r5.model.Reference) src);
2388    if (src instanceof org.hl7.fhir.r5.model.SampledData)
2389      return convertSampledData((org.hl7.fhir.r5.model.SampledData) src);
2390    if (src instanceof org.hl7.fhir.r5.model.Signature) return convertSignature((org.hl7.fhir.r5.model.Signature) src);
2391    if (src instanceof org.hl7.fhir.r5.model.Address) return convertAddress((org.hl7.fhir.r5.model.Address) src);
2392    if (src instanceof org.hl7.fhir.r5.model.ContactPoint)
2393      return convertContactPoint((org.hl7.fhir.r5.model.ContactPoint) src);
2394    if (src instanceof org.hl7.fhir.r5.model.HumanName) return convertHumanName((org.hl7.fhir.r5.model.HumanName) src);
2395    if (src instanceof org.hl7.fhir.r5.model.Meta) return convertMeta((org.hl7.fhir.r5.model.Meta) src);
2396    if (src instanceof org.hl7.fhir.r5.model.Timing) return convertTiming((org.hl7.fhir.r5.model.Timing) src);
2397    throw new FHIRException("Unknown type " + src.fhirType());
2398  }
2399
2400  static public boolean isExemptExtension(String url, String[] extensionsToIgnore) {
2401    boolean ok = false;
2402    for (String s : extensionsToIgnore) if (s.equals(url)) ok = true;
2403    return ok;
2404  }
2405
2406  static public void copyDomainResource(org.hl7.fhir.dstu2016may.model.DomainResource src, org.hl7.fhir.r5.model.DomainResource tgt, String... extensionsToIgnore) throws FHIRException {
2407    copyResource(src, tgt);
2408    tgt.setText(convertNarrative(src.getText()));
2409    for (org.hl7.fhir.dstu2016may.model.Resource t : src.getContained()) tgt.addContained(convertResource(t));
2410    for (org.hl7.fhir.dstu2016may.model.Extension t : src.getExtension())
2411      if (!isExemptExtension(t.getUrl(), extensionsToIgnore)) tgt.addExtension(convertExtension(t));
2412    for (org.hl7.fhir.dstu2016may.model.Extension t : src.getModifierExtension())
2413      if (!isExemptExtension(t.getUrl(), extensionsToIgnore)) tgt.addModifierExtension(convertExtension(t));
2414  }
2415
2416  static public void copyDomainResource(org.hl7.fhir.r5.model.DomainResource src, org.hl7.fhir.dstu2016may.model.DomainResource tgt, String... extensionsToIgnore) throws FHIRException {
2417    copyResource(src, tgt);
2418    if (src.hasText()) tgt.setText(convertNarrative(src.getText()));
2419    for (org.hl7.fhir.r5.model.Resource t : src.getContained()) tgt.addContained(convertResource(t));
2420    for (org.hl7.fhir.r5.model.Extension t : src.getExtension())
2421      if (!isExemptExtension(t.getUrl(), extensionsToIgnore)) tgt.addExtension(convertExtension(t));
2422    for (org.hl7.fhir.r5.model.Extension t : src.getModifierExtension())
2423      if (!isExemptExtension(t.getUrl(), extensionsToIgnore)) tgt.addModifierExtension(convertExtension(t));
2424  }
2425
2426  static public void copyResource(org.hl7.fhir.dstu2016may.model.Resource src, org.hl7.fhir.r5.model.Resource tgt) throws FHIRException {
2427    if (src.hasId()) tgt.setId(src.getId());
2428    if (src.hasMeta()) tgt.setMeta(convertMeta(src.getMeta()));
2429    if (src.hasImplicitRules()) tgt.setImplicitRules(src.getImplicitRules());
2430    if (src.hasLanguage()) tgt.setLanguage(src.getLanguage());
2431  }
2432
2433  static public void copyResource(org.hl7.fhir.r5.model.Resource src, org.hl7.fhir.dstu2016may.model.Resource tgt) throws FHIRException {
2434    if (src.hasId()) tgt.setId(src.getId());
2435    if (src.hasMeta()) tgt.setMeta(convertMeta(src.getMeta()));
2436    if (src.hasImplicitRules()) tgt.setImplicitRules(src.getImplicitRules());
2437    if (src.hasLanguage()) tgt.setLanguage(src.getLanguage());
2438  }
2439
2440  public static org.hl7.fhir.r5.model.Binary convertBinary(org.hl7.fhir.dstu2016may.model.Binary src) throws FHIRException {
2441    if (src == null || src.isEmpty()) return null;
2442    org.hl7.fhir.r5.model.Binary tgt = new org.hl7.fhir.r5.model.Binary();
2443    copyResource(src, tgt);
2444    if (src.hasContentTypeElement()) tgt.setContentTypeElement(convertCode(src.getContentTypeElement()));
2445    if (src.hasContent()) tgt.setContent(src.getContent());
2446    return tgt;
2447  }
2448
2449  public static org.hl7.fhir.dstu2016may.model.Binary convertBinary(org.hl7.fhir.r5.model.Binary src) throws FHIRException {
2450    if (src == null || src.isEmpty()) return null;
2451    org.hl7.fhir.dstu2016may.model.Binary tgt = new org.hl7.fhir.dstu2016may.model.Binary();
2452    copyResource(src, tgt);
2453    if (src.hasContentTypeElement()) tgt.setContentTypeElement(convertCode(src.getContentTypeElement()));
2454    tgt.setContentElement(convertBase64Binary(src.getContentElement()));
2455    return tgt;
2456  }
2457
2458  static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Enumerations.PublicationStatus> convertConformanceResourceStatus(org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.Enumerations.ConformanceResourceStatus> src) throws FHIRException {
2459    if (src == null || src.isEmpty()) return null;
2460    org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Enumerations.PublicationStatus> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.Enumerations.PublicationStatusEnumFactory());
2461    VersionConvertor_14_50.copyElement(src, tgt);
2462    if (src.getValue() == null) {
2463      tgt.setValue(org.hl7.fhir.r5.model.Enumerations.PublicationStatus.NULL);
2464    } else {
2465      switch (src.getValue()) {
2466        case DRAFT:
2467          tgt.setValue(org.hl7.fhir.r5.model.Enumerations.PublicationStatus.DRAFT);
2468          break;
2469        case ACTIVE:
2470          tgt.setValue(org.hl7.fhir.r5.model.Enumerations.PublicationStatus.ACTIVE);
2471          break;
2472        case RETIRED:
2473          tgt.setValue(org.hl7.fhir.r5.model.Enumerations.PublicationStatus.RETIRED);
2474          break;
2475        default:
2476          tgt.setValue(org.hl7.fhir.r5.model.Enumerations.PublicationStatus.NULL);
2477          break;
2478      }
2479    }
2480    return tgt;
2481  }
2482
2483  static public org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.Enumerations.ConformanceResourceStatus> convertConformanceResourceStatus(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Enumerations.PublicationStatus> src) throws FHIRException {
2484    if (src == null || src.isEmpty()) return null;
2485    org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.Enumerations.ConformanceResourceStatus> tgt = new org.hl7.fhir.dstu2016may.model.Enumeration<>(new org.hl7.fhir.dstu2016may.model.Enumerations.ConformanceResourceStatusEnumFactory());
2486    VersionConvertor_14_50.copyElement(src, tgt);
2487    if (src.getValue() == null) {
2488      tgt.setValue(org.hl7.fhir.dstu2016may.model.Enumerations.ConformanceResourceStatus.NULL);
2489    } else {
2490      switch (src.getValue()) {
2491        case DRAFT:
2492          tgt.setValue(org.hl7.fhir.dstu2016may.model.Enumerations.ConformanceResourceStatus.DRAFT);
2493          break;
2494        case ACTIVE:
2495          tgt.setValue(org.hl7.fhir.dstu2016may.model.Enumerations.ConformanceResourceStatus.ACTIVE);
2496          break;
2497        case RETIRED:
2498          tgt.setValue(org.hl7.fhir.dstu2016may.model.Enumerations.ConformanceResourceStatus.RETIRED);
2499          break;
2500        default:
2501          tgt.setValue(org.hl7.fhir.dstu2016may.model.Enumerations.ConformanceResourceStatus.NULL);
2502          break;
2503      }
2504    }
2505    return tgt;
2506  }
2507
2508  static public boolean isJurisdiction(CodeableConcept t) {
2509    return t.hasCoding() && ("http://unstats.un.org/unsd/methods/m49/m49.htm".equals(t.getCoding().get(0).getSystem()) || "urn:iso:std:iso:3166".equals(t.getCoding().get(0).getSystem()) || "https://www.usps.com/".equals(t.getCoding().get(0).getSystem()));
2510  }
2511
2512  public static org.hl7.fhir.r5.model.UsageContext convertCodeableConceptToUsageContext(org.hl7.fhir.dstu2016may.model.CodeableConcept t) throws FHIRException {
2513    org.hl7.fhir.r5.model.UsageContext result = new org.hl7.fhir.r5.model.UsageContext();
2514    result.setValue(convertCodeableConcept(t));
2515    return result;
2516  }
2517
2518  static public class SourceElementComponentWrapper {
2519    public SourceElementComponentWrapper(SourceElementComponent comp, String source, String target) {
2520      super();
2521      this.source = source;
2522      this.target = target;
2523      this.comp = comp;
2524    }
2525
2526    public String source;
2527    public String target;
2528    public org.hl7.fhir.r5.model.ConceptMap.SourceElementComponent comp;
2529  }
2530
2531  static public CanonicalType convertReferenceToCanonical(Reference src) throws FHIRException {
2532    CanonicalType dst = new CanonicalType(src.getReference());
2533    copyElement(src, dst);
2534    return dst;
2535  }
2536
2537  static public Reference convertCanonicalToReference(CanonicalType src) throws FHIRException {
2538    Reference dst = new Reference(src.getValue());
2539    copyElement(src, dst);
2540    return dst;
2541  }
2542
2543  static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Enumerations.SearchParamType> convertSearchParamType(org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.Enumerations.SearchParamType> src) throws FHIRException {
2544    if (src == null || src.isEmpty()) return null;
2545    org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Enumerations.SearchParamType> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.Enumerations.SearchParamTypeEnumFactory());
2546    VersionConvertor_14_50.copyElement(src, tgt);
2547    if (src.getValue() == null) {
2548      tgt.setValue(org.hl7.fhir.r5.model.Enumerations.SearchParamType.NULL);
2549    } else {
2550      switch (src.getValue()) {
2551        case NUMBER:
2552          tgt.setValue(org.hl7.fhir.r5.model.Enumerations.SearchParamType.NUMBER);
2553          break;
2554        case DATE:
2555          tgt.setValue(org.hl7.fhir.r5.model.Enumerations.SearchParamType.DATE);
2556          break;
2557        case STRING:
2558          tgt.setValue(org.hl7.fhir.r5.model.Enumerations.SearchParamType.STRING);
2559          break;
2560        case TOKEN:
2561          tgt.setValue(org.hl7.fhir.r5.model.Enumerations.SearchParamType.TOKEN);
2562          break;
2563        case REFERENCE:
2564          tgt.setValue(org.hl7.fhir.r5.model.Enumerations.SearchParamType.REFERENCE);
2565          break;
2566        case COMPOSITE:
2567          tgt.setValue(org.hl7.fhir.r5.model.Enumerations.SearchParamType.COMPOSITE);
2568          break;
2569        case QUANTITY:
2570          tgt.setValue(org.hl7.fhir.r5.model.Enumerations.SearchParamType.QUANTITY);
2571          break;
2572        case URI:
2573          tgt.setValue(org.hl7.fhir.r5.model.Enumerations.SearchParamType.URI);
2574          break;
2575        default:
2576          tgt.setValue(org.hl7.fhir.r5.model.Enumerations.SearchParamType.NULL);
2577          break;
2578      }
2579    }
2580    return tgt;
2581  }
2582
2583  static public org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.Enumerations.SearchParamType> convertSearchParamType(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Enumerations.SearchParamType> src) throws FHIRException {
2584    if (src == null || src.isEmpty()) return null;
2585    org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.Enumerations.SearchParamType> tgt = new org.hl7.fhir.dstu2016may.model.Enumeration<>(new org.hl7.fhir.dstu2016may.model.Enumerations.SearchParamTypeEnumFactory());
2586    VersionConvertor_14_50.copyElement(src, tgt);
2587    if (src.getValue() == null) {
2588      tgt.setValue(org.hl7.fhir.dstu2016may.model.Enumerations.SearchParamType.NULL);
2589    } else {
2590      switch (src.getValue()) {
2591        case NUMBER:
2592          tgt.setValue(org.hl7.fhir.dstu2016may.model.Enumerations.SearchParamType.NUMBER);
2593          break;
2594        case DATE:
2595          tgt.setValue(org.hl7.fhir.dstu2016may.model.Enumerations.SearchParamType.DATE);
2596          break;
2597        case STRING:
2598          tgt.setValue(org.hl7.fhir.dstu2016may.model.Enumerations.SearchParamType.STRING);
2599          break;
2600        case TOKEN:
2601          tgt.setValue(org.hl7.fhir.dstu2016may.model.Enumerations.SearchParamType.TOKEN);
2602          break;
2603        case REFERENCE:
2604          tgt.setValue(org.hl7.fhir.dstu2016may.model.Enumerations.SearchParamType.REFERENCE);
2605          break;
2606        case COMPOSITE:
2607          tgt.setValue(org.hl7.fhir.dstu2016may.model.Enumerations.SearchParamType.COMPOSITE);
2608          break;
2609        case QUANTITY:
2610          tgt.setValue(org.hl7.fhir.dstu2016may.model.Enumerations.SearchParamType.QUANTITY);
2611          break;
2612        case URI:
2613          tgt.setValue(org.hl7.fhir.dstu2016may.model.Enumerations.SearchParamType.URI);
2614          break;
2615        default:
2616          tgt.setValue(org.hl7.fhir.dstu2016may.model.Enumerations.SearchParamType.NULL);
2617          break;
2618      }
2619    }
2620    return tgt;
2621  }
2622
2623  static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.CapabilityStatement.EventCapabilityMode> convertConformanceEventMode(org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.Conformance.ConformanceEventMode> src) throws FHIRException {
2624    if (src == null || src.isEmpty()) return null;
2625    org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.CapabilityStatement.EventCapabilityMode> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.CapabilityStatement.EventCapabilityModeEnumFactory());
2626    VersionConvertor_14_50.copyElement(src, tgt);
2627    if (src.getValue() == null) {
2628      tgt.setValue(org.hl7.fhir.r5.model.CapabilityStatement.EventCapabilityMode.NULL);
2629    } else {
2630      switch (src.getValue()) {
2631        case SENDER:
2632          tgt.setValue(org.hl7.fhir.r5.model.CapabilityStatement.EventCapabilityMode.SENDER);
2633          break;
2634        case RECEIVER:
2635          tgt.setValue(org.hl7.fhir.r5.model.CapabilityStatement.EventCapabilityMode.RECEIVER);
2636          break;
2637        default:
2638          tgt.setValue(org.hl7.fhir.r5.model.CapabilityStatement.EventCapabilityMode.NULL);
2639          break;
2640      }
2641    }
2642    return tgt;
2643  }
2644
2645  static public org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.Conformance.ConformanceEventMode> convertConformanceEventMode(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.CapabilityStatement.EventCapabilityMode> src) throws FHIRException {
2646    if (src == null || src.isEmpty()) return null;
2647    org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.Conformance.ConformanceEventMode> tgt = new org.hl7.fhir.dstu2016may.model.Enumeration<>(new org.hl7.fhir.dstu2016may.model.Conformance.ConformanceEventModeEnumFactory());
2648    VersionConvertor_14_50.copyElement(src, tgt);
2649    if (src.getValue() == null) {
2650      tgt.setValue(org.hl7.fhir.dstu2016may.model.Conformance.ConformanceEventMode.NULL);
2651    } else {
2652      switch (src.getValue()) {
2653        case SENDER:
2654          tgt.setValue(org.hl7.fhir.dstu2016may.model.Conformance.ConformanceEventMode.SENDER);
2655          break;
2656        case RECEIVER:
2657          tgt.setValue(org.hl7.fhir.dstu2016may.model.Conformance.ConformanceEventMode.RECEIVER);
2658          break;
2659        default:
2660          tgt.setValue(org.hl7.fhir.dstu2016may.model.Conformance.ConformanceEventMode.NULL);
2661          break;
2662      }
2663    }
2664    return tgt;
2665  }
2666
2667  public static org.hl7.fhir.r5.model.Resource convertResource(org.hl7.fhir.dstu2016may.model.Resource src) throws FHIRException {
2668    if (src == null || src.isEmpty()) return null;
2669    if (src instanceof org.hl7.fhir.dstu2016may.model.Parameters)
2670      return Parameters14_50.convertParameters((org.hl7.fhir.dstu2016may.model.Parameters) src);
2671    if (src instanceof org.hl7.fhir.dstu2016may.model.Bundle)
2672      return Bundle14_50.convertBundle((org.hl7.fhir.dstu2016may.model.Bundle) src);
2673    if (src instanceof org.hl7.fhir.dstu2016may.model.CodeSystem)
2674      return CodeSystem14_50.convertCodeSystem((org.hl7.fhir.dstu2016may.model.CodeSystem) src);
2675    if (src instanceof org.hl7.fhir.dstu2016may.model.CompartmentDefinition)
2676      return CompartmentDefinition14_50.convertCompartmentDefinition((org.hl7.fhir.dstu2016may.model.CompartmentDefinition) src);
2677    if (src instanceof org.hl7.fhir.dstu2016may.model.ConceptMap)
2678      return ConceptMap14_50.convertConceptMap((org.hl7.fhir.dstu2016may.model.ConceptMap) src);
2679    if (src instanceof org.hl7.fhir.dstu2016may.model.Conformance)
2680      return Conformance14_50.convertConformance((org.hl7.fhir.dstu2016may.model.Conformance) src);
2681    if (src instanceof org.hl7.fhir.dstu2016may.model.DataElement)
2682      return DataElement14_50.convertDataElement((org.hl7.fhir.dstu2016may.model.DataElement) src);
2683    if (src instanceof org.hl7.fhir.dstu2016may.model.ImplementationGuide)
2684      return ImplementationGuide14_50.convertImplementationGuide((org.hl7.fhir.dstu2016may.model.ImplementationGuide) src);
2685    if (src instanceof org.hl7.fhir.dstu2016may.model.NamingSystem)
2686      return NamingSystem14_50.convertNamingSystem((org.hl7.fhir.dstu2016may.model.NamingSystem) src);
2687    if (src instanceof org.hl7.fhir.dstu2016may.model.OperationDefinition)
2688      return OperationDefinition14_50.convertOperationDefinition((org.hl7.fhir.dstu2016may.model.OperationDefinition) src);
2689    if (src instanceof org.hl7.fhir.dstu2016may.model.OperationOutcome)
2690      return OperationOutcome14_50.convertOperationOutcome((org.hl7.fhir.dstu2016may.model.OperationOutcome) src);
2691    if (src instanceof org.hl7.fhir.dstu2016may.model.Questionnaire)
2692      return Questionnaire14_50.convertQuestionnaire((org.hl7.fhir.dstu2016may.model.Questionnaire) src);
2693    if (src instanceof org.hl7.fhir.dstu2016may.model.QuestionnaireResponse)
2694      return QuestionnaireResponse14_50.convertQuestionnaireResponse((org.hl7.fhir.dstu2016may.model.QuestionnaireResponse) src);
2695    if (src instanceof org.hl7.fhir.dstu2016may.model.SearchParameter)
2696      return SearchParameter14_50.convertSearchParameter((org.hl7.fhir.dstu2016may.model.SearchParameter) src);
2697    if (src instanceof org.hl7.fhir.dstu2016may.model.StructureDefinition)
2698      return StructureDefinition14_50.convertStructureDefinition((org.hl7.fhir.dstu2016may.model.StructureDefinition) src);
2699    if (src instanceof org.hl7.fhir.dstu2016may.model.StructureMap)
2700      return StructureMap14_50.convertStructureMap((org.hl7.fhir.dstu2016may.model.StructureMap) src);
2701    if (src instanceof org.hl7.fhir.dstu2016may.model.ValueSet)
2702      return ValueSet14_50.convertValueSet((org.hl7.fhir.dstu2016may.model.ValueSet) src);
2703    throw new FHIRException("Unknown resource " + src.fhirType());
2704  }
2705
2706  public static org.hl7.fhir.dstu2016may.model.Resource convertResource(org.hl7.fhir.r5.model.Resource src) throws FHIRException {
2707    if (src == null || src.isEmpty()) return null;
2708    if (src instanceof org.hl7.fhir.r5.model.Parameters)
2709      return Parameters14_50.convertParameters((org.hl7.fhir.r5.model.Parameters) src);
2710    if (src instanceof org.hl7.fhir.r5.model.Bundle)
2711      return Bundle14_50.convertBundle((org.hl7.fhir.r5.model.Bundle) src);
2712    if (src instanceof org.hl7.fhir.r5.model.CodeSystem)
2713      return CodeSystem14_50.convertCodeSystem((org.hl7.fhir.r5.model.CodeSystem) src);
2714    if (src instanceof org.hl7.fhir.r5.model.CompartmentDefinition)
2715      return CompartmentDefinition14_50.convertCompartmentDefinition((org.hl7.fhir.r5.model.CompartmentDefinition) src);
2716    if (src instanceof org.hl7.fhir.r5.model.ConceptMap)
2717      return ConceptMap14_50.convertConceptMap((org.hl7.fhir.r5.model.ConceptMap) src);
2718    if (src instanceof org.hl7.fhir.r5.model.CapabilityStatement)
2719      return Conformance14_50.convertConformance((org.hl7.fhir.r5.model.CapabilityStatement) src);
2720    if (src instanceof org.hl7.fhir.r5.model.ImplementationGuide)
2721      return ImplementationGuide14_50.convertImplementationGuide((org.hl7.fhir.r5.model.ImplementationGuide) src);
2722    if (src instanceof org.hl7.fhir.r5.model.NamingSystem)
2723      return NamingSystem14_50.convertNamingSystem((org.hl7.fhir.r5.model.NamingSystem) src);
2724    if (src instanceof org.hl7.fhir.r5.model.OperationDefinition)
2725      return OperationDefinition14_50.convertOperationDefinition((org.hl7.fhir.r5.model.OperationDefinition) src);
2726    if (src instanceof org.hl7.fhir.r5.model.OperationOutcome)
2727      return OperationOutcome14_50.convertOperationOutcome((org.hl7.fhir.r5.model.OperationOutcome) src);
2728    if (src instanceof org.hl7.fhir.r5.model.Questionnaire)
2729      return Questionnaire14_50.convertQuestionnaire((org.hl7.fhir.r5.model.Questionnaire) src);
2730    if (src instanceof org.hl7.fhir.r5.model.QuestionnaireResponse)
2731      return QuestionnaireResponse14_50.convertQuestionnaireResponse((org.hl7.fhir.r5.model.QuestionnaireResponse) src);
2732    if (src instanceof org.hl7.fhir.r5.model.SearchParameter)
2733      return SearchParameter14_50.convertSearchParameter((org.hl7.fhir.r5.model.SearchParameter) src);
2734    if (src instanceof org.hl7.fhir.r5.model.StructureDefinition)
2735      return StructureDefinition14_50.convertStructureDefinition((org.hl7.fhir.r5.model.StructureDefinition) src);
2736    if (src instanceof org.hl7.fhir.r5.model.StructureMap)
2737      return StructureMap14_50.convertStructureMap((org.hl7.fhir.r5.model.StructureMap) src);
2738    if (src instanceof org.hl7.fhir.r5.model.ValueSet)
2739      return ValueSet14_50.convertValueSet((org.hl7.fhir.r5.model.ValueSet) src);
2740    throw new FHIRException("Unknown resource " + src.fhirType());
2741  }
2742
2743  public static boolean convertsResource(String rt) {
2744    return Utilities.existsInList(rt, "Parameters", "Bundle", "CodeSystem", "CompartmentDefinition", "ConceptMap", "CapabilityStatement", "ImplementationGuide", "NamingSystem", "OperationDefinition", "OperationOutcome", "Questionnaire", "QuestionnaireResponse", "SearchParameter", "StructureDefinition", "StructureMap", "ValueSet");
2745  }
2746}