001package org.hl7.fhir.convertors.conv40_50.resources40_50;
002
003import org.hl7.fhir.convertors.context.ConversionContext40_50;
004import org.hl7.fhir.convertors.conv40_50.datatypes40_50.general40_50.CodeableConcept40_50;
005import org.hl7.fhir.convertors.conv40_50.datatypes40_50.general40_50.Identifier40_50;
006import org.hl7.fhir.convertors.conv40_50.datatypes40_50.general40_50.Period40_50;
007import org.hl7.fhir.convertors.conv40_50.datatypes40_50.primitive40_50.DateTime40_50;
008import org.hl7.fhir.convertors.conv40_50.datatypes40_50.primitive40_50.String40_50;
009import org.hl7.fhir.convertors.conv40_50.datatypes40_50.special40_50.Narrative40_50;
010import org.hl7.fhir.convertors.conv40_50.datatypes40_50.special40_50.Reference40_50;
011import org.hl7.fhir.exceptions.FHIRException;
012import org.hl7.fhir.r4.model.Composition;
013import org.hl7.fhir.r5.model.*;
014
015/*
016  Copyright (c) 2011+, HL7, Inc.
017  All rights reserved.
018  
019  Redistribution and use in source and binary forms, with or without modification, 
020  are permitted provided that the following conditions are met:
021  
022   * Redistributions of source code must retain the above copyright notice, this 
023     list of conditions and the following disclaimer.
024   * Redistributions in binary form must reproduce the above copyright notice, 
025     this list of conditions and the following disclaimer in the documentation 
026     and/or other materials provided with the distribution.
027   * Neither the name of HL7 nor the names of its contributors may be used to 
028     endorse or promote products derived from this software without specific 
029     prior written permission.
030  
031  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
032  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
033  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
034  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
035  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
036  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
037  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
038  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
039  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
040  POSSIBILITY OF SUCH DAMAGE.
041  
042*/
043// Generated on Sun, Feb 24, 2019 11:37+1100 for FHIR v4.0.0
044public class Composition40_50 {
045
046  public static org.hl7.fhir.r5.model.Composition convertComposition(org.hl7.fhir.r4.model.Composition src) throws FHIRException {
047    if (src == null)
048      return null;
049    org.hl7.fhir.r5.model.Composition tgt = new org.hl7.fhir.r5.model.Composition();
050    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyDomainResource(src, tgt);
051    if (src.hasIdentifier())
052      tgt.addIdentifier(Identifier40_50.convertIdentifier(src.getIdentifier()));
053    if (src.hasStatus())
054      tgt.setStatusElement(convertCompositionStatus(src.getStatusElement()));
055    if (src.hasType())
056      tgt.setType(CodeableConcept40_50.convertCodeableConcept(src.getType()));
057    for (org.hl7.fhir.r4.model.CodeableConcept t : src.getCategory())
058      tgt.addCategory(CodeableConcept40_50.convertCodeableConcept(t));
059    if (src.hasSubject())
060      tgt.addSubject(Reference40_50.convertReference(src.getSubject()));
061    if (src.hasEncounter())
062      tgt.setEncounter(Reference40_50.convertReference(src.getEncounter()));
063    if (src.hasDate())
064      tgt.setDateElement(DateTime40_50.convertDateTime(src.getDateElement()));
065    for (org.hl7.fhir.r4.model.Reference t : src.getAuthor()) tgt.addAuthor(Reference40_50.convertReference(t));
066    if (src.hasTitle())
067      tgt.setTitleElement(String40_50.convertString(src.getTitleElement()));
068    if (src.hasConfidentiality())
069      tgt.getMeta().addSecurity().setCode(src.getConfidentiality().toCode());
070    for (org.hl7.fhir.r4.model.Composition.CompositionAttesterComponent t : src.getAttester())
071      tgt.addAttester(convertCompositionAttesterComponent(t));
072    if (src.hasCustodian())
073      tgt.setCustodian(Reference40_50.convertReference(src.getCustodian()));
074    for (org.hl7.fhir.r4.model.Composition.CompositionRelatesToComponent t : src.getRelatesTo())
075      tgt.addRelatesTo(convertCompositionRelatesToComponent(t));
076    for (org.hl7.fhir.r4.model.Composition.CompositionEventComponent t : src.getEvent())
077      tgt.addEvent(convertCompositionEventComponent(t));
078    for (org.hl7.fhir.r4.model.Composition.SectionComponent t : src.getSection())
079      tgt.addSection(convertSectionComponent(t));
080    return tgt;
081  }
082
083  public static org.hl7.fhir.r4.model.Composition convertComposition(org.hl7.fhir.r5.model.Composition src) throws FHIRException {
084    if (src == null)
085      return null;
086    org.hl7.fhir.r4.model.Composition tgt = new org.hl7.fhir.r4.model.Composition();
087    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyDomainResource(src, tgt);
088    if (src.hasIdentifier())
089      tgt.setIdentifier(Identifier40_50.convertIdentifier(src.getIdentifierFirstRep()));
090    if (src.hasStatus())
091      tgt.setStatusElement(convertCompositionStatus(src.getStatusElement()));
092    if (src.hasType())
093      tgt.setType(CodeableConcept40_50.convertCodeableConcept(src.getType()));
094    for (org.hl7.fhir.r5.model.CodeableConcept t : src.getCategory())
095      tgt.addCategory(CodeableConcept40_50.convertCodeableConcept(t));
096    if (src.hasSubject())
097      tgt.setSubject(Reference40_50.convertReference(src.getSubjectFirstRep()));
098    if (src.hasEncounter())
099      tgt.setEncounter(Reference40_50.convertReference(src.getEncounter()));
100    if (src.hasDate())
101      tgt.setDateElement(DateTime40_50.convertDateTime(src.getDateElement()));
102    for (org.hl7.fhir.r5.model.Reference t : src.getAuthor()) tgt.addAuthor(Reference40_50.convertReference(t));
103    if (src.hasTitle())
104      tgt.setTitleElement(String40_50.convertString(src.getTitleElement()));
105    if (src.getMeta().hasSecurity())
106      tgt.setConfidentialityElement(convertDocumentConfidentiality(src.getMeta().getSecurityFirstRep()));
107    for (org.hl7.fhir.r5.model.Composition.CompositionAttesterComponent t : src.getAttester())
108      tgt.addAttester(convertCompositionAttesterComponent(t));
109    if (src.hasCustodian())
110      tgt.setCustodian(Reference40_50.convertReference(src.getCustodian()));
111    for (RelatedArtifact t : src.getRelatesTo())
112      tgt.addRelatesTo(convertCompositionRelatesToComponent(t));
113    for (org.hl7.fhir.r5.model.Composition.CompositionEventComponent t : src.getEvent())
114      tgt.addEvent(convertCompositionEventComponent(t));
115    for (org.hl7.fhir.r5.model.Composition.SectionComponent t : src.getSection())
116      tgt.addSection(convertSectionComponent(t));
117    return tgt;
118  }
119
120  static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Enumerations.CompositionStatus> convertCompositionStatus(org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Composition.CompositionStatus> src) throws FHIRException {
121      if (src == null || src.isEmpty())
122          return null;
123      Enumeration<Enumerations.CompositionStatus> tgt = new Enumeration<>(new Enumerations.CompositionStatusEnumFactory());
124      ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt);
125      if (src.getValue() == null) {
126          tgt.setValue(null);
127      } else {
128          switch (src.getValue()) {
129              case PRELIMINARY:
130                  tgt.setValue(Enumerations.CompositionStatus.PRELIMINARY);
131                  break;
132              case FINAL:
133                  tgt.setValue(Enumerations.CompositionStatus.FINAL);
134                  break;
135              case AMENDED:
136                  tgt.setValue(Enumerations.CompositionStatus.AMENDED);
137                  break;
138              case ENTEREDINERROR:
139                  tgt.setValue(Enumerations.CompositionStatus.ENTEREDINERROR);
140                  break;
141              default:
142                  tgt.setValue(Enumerations.CompositionStatus.NULL);
143                  break;
144          }
145      }
146      return tgt;
147  }
148
149  static public org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Composition.CompositionStatus> convertCompositionStatus(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Enumerations.CompositionStatus> src) throws FHIRException {
150      if (src == null || src.isEmpty())
151          return null;
152      org.hl7.fhir.r4.model.Enumeration<Composition.CompositionStatus> tgt = new org.hl7.fhir.r4.model.Enumeration<>(new Composition.CompositionStatusEnumFactory());
153      ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt);
154      if (src.getValue() == null) {
155          tgt.setValue(null);
156      } else {
157          switch (src.getValue()) {
158              case PRELIMINARY:
159                  tgt.setValue(Composition.CompositionStatus.PRELIMINARY);
160                  break;
161              case FINAL:
162                  tgt.setValue(Composition.CompositionStatus.FINAL);
163                  break;
164              case AMENDED:
165                  tgt.setValue(Composition.CompositionStatus.AMENDED);
166                  break;
167              case ENTEREDINERROR:
168                  tgt.setValue(Composition.CompositionStatus.ENTEREDINERROR);
169                  break;
170              default:
171                  tgt.setValue(Composition.CompositionStatus.NULL);
172                  break;
173          }
174      }
175      return tgt;
176  }
177
178  static public org.hl7.fhir.r5.model.Coding convertDocumentConfidentiality(org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Composition.DocumentConfidentiality> src) throws FHIRException {
179    if (src == null || src.isEmpty())
180      return null;
181    org.hl7.fhir.r5.model.Coding tgt = new org.hl7.fhir.r5.model.Coding();
182    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt);
183    tgt.setCode(src.getValue().toCode());
184    return tgt;
185  }
186
187  static public org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Composition.DocumentConfidentiality> convertDocumentConfidentiality(org.hl7.fhir.r5.model.Coding src) throws FHIRException {
188    if (src == null || src.isEmpty())
189      return null;
190    org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Composition.DocumentConfidentiality> tgt = new org.hl7.fhir.r4.model.Enumeration<>(new org.hl7.fhir.r4.model.Composition.DocumentConfidentialityEnumFactory());
191    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt);
192    switch (src.getCode()) {
193      case "U":
194        tgt.setValue(org.hl7.fhir.r4.model.Composition.DocumentConfidentiality.U);
195        break;
196      case "L":
197        tgt.setValue(org.hl7.fhir.r4.model.Composition.DocumentConfidentiality.L);
198        break;
199      case "M":
200        tgt.setValue(org.hl7.fhir.r4.model.Composition.DocumentConfidentiality.M);
201        break;
202      case "N":
203        tgt.setValue(org.hl7.fhir.r4.model.Composition.DocumentConfidentiality.N);
204        break;
205      case "R":
206        tgt.setValue(org.hl7.fhir.r4.model.Composition.DocumentConfidentiality.R);
207        break;
208      case "V":
209        tgt.setValue(org.hl7.fhir.r4.model.Composition.DocumentConfidentiality.V);
210        break;
211      default:
212        tgt.setValue(org.hl7.fhir.r4.model.Composition.DocumentConfidentiality.NULL);
213        break;
214    }
215    return tgt;
216  }
217
218  public static org.hl7.fhir.r5.model.Composition.CompositionAttesterComponent convertCompositionAttesterComponent(org.hl7.fhir.r4.model.Composition.CompositionAttesterComponent src) throws FHIRException {
219    if (src == null)
220      return null;
221    org.hl7.fhir.r5.model.Composition.CompositionAttesterComponent tgt = new org.hl7.fhir.r5.model.Composition.CompositionAttesterComponent();
222    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyBackboneElement(src, tgt);
223    if (src.hasMode())
224      tgt.setMode(convertCompositionAttestationMode(src.getModeElement()));
225    if (src.hasTime())
226      tgt.setTimeElement(DateTime40_50.convertDateTime(src.getTimeElement()));
227    if (src.hasParty())
228      tgt.setParty(Reference40_50.convertReference(src.getParty()));
229    return tgt;
230  }
231
232  public static org.hl7.fhir.r4.model.Composition.CompositionAttesterComponent convertCompositionAttesterComponent(org.hl7.fhir.r5.model.Composition.CompositionAttesterComponent src) throws FHIRException {
233    if (src == null)
234      return null;
235    org.hl7.fhir.r4.model.Composition.CompositionAttesterComponent tgt = new org.hl7.fhir.r4.model.Composition.CompositionAttesterComponent();
236    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyBackboneElement(src, tgt);
237    if (src.hasMode())
238      tgt.setModeElement(convertCompositionAttestationMode(src.getMode()));
239    if (src.hasTime())
240      tgt.setTimeElement(DateTime40_50.convertDateTime(src.getTimeElement()));
241    if (src.hasParty())
242      tgt.setParty(Reference40_50.convertReference(src.getParty()));
243    return tgt;
244  }
245
246  static public org.hl7.fhir.r5.model.CodeableConcept convertCompositionAttestationMode(org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Composition.CompositionAttestationMode> src) throws FHIRException {
247      if (src == null || src.isEmpty())
248          return null;
249      CodeableConcept tgt = new CodeableConcept();
250      ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt);
251      if (src.getValue() == null) {
252        // Add nothing
253      } else {
254          switch (src.getValue()) {
255              case PERSONAL:
256                  tgt.addCoding().setSystem("http://hl7.org/fhir/composition-attestation-mode").setCode("personal");
257                  break;
258              case PROFESSIONAL:
259                  tgt.addCoding().setSystem("http://hl7.org/fhir/composition-attestation-mode").setCode("professional");
260                  break;
261              case LEGAL:
262                  tgt.addCoding().setSystem("http://hl7.org/fhir/composition-attestation-mode").setCode("legal");
263                  break;
264              case OFFICIAL:
265                  tgt.addCoding().setSystem("http://hl7.org/fhir/composition-attestation-mode").setCode("official");
266                  break;
267              default:
268                  break;
269          }
270      }
271      return tgt;
272  }
273
274  static public org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Composition.CompositionAttestationMode> convertCompositionAttestationMode(org.hl7.fhir.r5.model.CodeableConcept src) throws FHIRException {
275    if (src == null || src.isEmpty())
276      return null;
277    org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Composition.CompositionAttestationMode> tgt = new org.hl7.fhir.r4.model.Enumeration<>(new org.hl7.fhir.r4.model.Composition.CompositionAttestationModeEnumFactory());
278    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt);
279    switch (src.getCode("http://hl7.org/fhir/composition-attestation-mode")) {
280      case "personal":
281        tgt.setValue(org.hl7.fhir.r4.model.Composition.CompositionAttestationMode.PERSONAL);
282        break;
283      case "professional":
284        tgt.setValue(org.hl7.fhir.r4.model.Composition.CompositionAttestationMode.PROFESSIONAL);
285        break;
286      case "legal":
287        tgt.setValue(org.hl7.fhir.r4.model.Composition.CompositionAttestationMode.LEGAL);
288        break;
289      case "official":
290        tgt.setValue(org.hl7.fhir.r4.model.Composition.CompositionAttestationMode.OFFICIAL);
291        break;
292      default:
293        tgt.setValue(org.hl7.fhir.r4.model.Composition.CompositionAttestationMode.NULL);
294        break;
295    }
296    return tgt;
297  }
298
299  public static org.hl7.fhir.r5.model.RelatedArtifact convertCompositionRelatesToComponent(org.hl7.fhir.r4.model.Composition.CompositionRelatesToComponent src) throws FHIRException {
300    if (src == null)
301      return null;
302    org.hl7.fhir.r5.model.RelatedArtifact tgt = new org.hl7.fhir.r5.model.RelatedArtifact();
303    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt);
304    if (src.hasCode())
305      tgt.setTypeElement(convertDocumentRelationshipType(src.getCodeElement()));
306    if (src.hasTargetReference())
307      tgt.setResourceReference(Reference40_50.convertReference(src.getTargetReference()));
308    return tgt;
309  }
310
311  public static org.hl7.fhir.r4.model.Composition.CompositionRelatesToComponent convertCompositionRelatesToComponent(org.hl7.fhir.r5.model.RelatedArtifact src) throws FHIRException {
312    if (src == null)
313      return null;
314    org.hl7.fhir.r4.model.Composition.CompositionRelatesToComponent tgt = new org.hl7.fhir.r4.model.Composition.CompositionRelatesToComponent();
315    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt);
316    if (src.hasType())
317      tgt.setCodeElement(convertDocumentRelationshipType(src.getTypeElement()));
318    if (src.hasResourceReference())
319      tgt.setTarget(ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().convertType(src.getResourceReference()));
320    return tgt;
321  }
322
323  static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.RelatedArtifact.RelatedArtifactType> convertDocumentRelationshipType(org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Composition.DocumentRelationshipType> src) throws FHIRException {
324      if (src == null || src.isEmpty())
325          return null;
326      Enumeration<RelatedArtifact.RelatedArtifactType> tgt = new Enumeration<>(new RelatedArtifact.RelatedArtifactTypeEnumFactory());
327      ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt);
328      if (src.getValue() == null) {
329          tgt.setValue(null);
330      } else {
331          switch (src.getValue()) {
332              case REPLACES:
333                  tgt.setValue(RelatedArtifact.RelatedArtifactType.REPLACES);
334                  break;
335              case TRANSFORMS:
336                  tgt.setValue(RelatedArtifact.RelatedArtifactType.TRANSFORMS);
337                  break;
338              case SIGNS:
339                  tgt.setValue(RelatedArtifact.RelatedArtifactType.SIGNS);
340                  break;
341              case APPENDS:
342                  tgt.setValue(RelatedArtifact.RelatedArtifactType.APPENDS);
343                  break;
344              default:
345                  tgt.setValue(RelatedArtifact.RelatedArtifactType.NULL);
346                  break;
347          }
348      }
349      return tgt;
350  }
351
352  static public org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Composition.DocumentRelationshipType> convertDocumentRelationshipType(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.RelatedArtifact.RelatedArtifactType> src) throws FHIRException {
353      if (src == null || src.isEmpty())
354          return null;
355      org.hl7.fhir.r4.model.Enumeration<Composition.DocumentRelationshipType> tgt = new org.hl7.fhir.r4.model.Enumeration<>(new Composition.DocumentRelationshipTypeEnumFactory());
356      ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt);
357      if (src.getValue() == null) {
358          tgt.setValue(null);
359      } else {
360          switch (src.getValue()) {
361              case REPLACES:
362                  tgt.setValue(Composition.DocumentRelationshipType.REPLACES);
363                  break;
364              case TRANSFORMS:
365                  tgt.setValue(Composition.DocumentRelationshipType.TRANSFORMS);
366                  break;
367              case SIGNS:
368                  tgt.setValue(Composition.DocumentRelationshipType.SIGNS);
369                  break;
370              case APPENDS:
371                  tgt.setValue(Composition.DocumentRelationshipType.APPENDS);
372                  break;
373              default:
374                  tgt.setValue(Composition.DocumentRelationshipType.NULL);
375                  break;
376          }
377      }
378      return tgt;
379  }
380
381  public static org.hl7.fhir.r5.model.Composition.CompositionEventComponent convertCompositionEventComponent(org.hl7.fhir.r4.model.Composition.CompositionEventComponent src) throws FHIRException {
382    if (src == null)
383      return null;
384    org.hl7.fhir.r5.model.Composition.CompositionEventComponent tgt = new org.hl7.fhir.r5.model.Composition.CompositionEventComponent();
385    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyBackboneElement(src, tgt);
386    for (org.hl7.fhir.r4.model.CodeableConcept t : src.getCode())
387      tgt.addDetail().setConcept(CodeableConcept40_50.convertCodeableConcept(t));
388    if (src.hasPeriod())
389      tgt.setPeriod(Period40_50.convertPeriod(src.getPeriod()));
390    for (org.hl7.fhir.r4.model.Reference t : src.getDetail()) tgt.addDetail().setReference(Reference40_50.convertReference(t));
391    return tgt;
392  }
393
394  public static org.hl7.fhir.r4.model.Composition.CompositionEventComponent convertCompositionEventComponent(org.hl7.fhir.r5.model.Composition.CompositionEventComponent src) throws FHIRException {
395    if (src == null)
396      return null;
397    org.hl7.fhir.r4.model.Composition.CompositionEventComponent tgt = new org.hl7.fhir.r4.model.Composition.CompositionEventComponent();
398    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyBackboneElement(src, tgt);
399    if (src.hasPeriod())
400      tgt.setPeriod(Period40_50.convertPeriod(src.getPeriod()));
401    for (CodeableReference t : src.getDetail()) {
402      if (t.hasConcept()) {
403        tgt.addCode(CodeableConcept40_50.convertCodeableConcept(t.getConcept()));
404      }
405      if (t.hasReference()) {
406        tgt.addDetail(Reference40_50.convertReference(t.getReference()));
407      }
408    }
409    return tgt;
410  }
411
412  public static org.hl7.fhir.r5.model.Composition.SectionComponent convertSectionComponent(org.hl7.fhir.r4.model.Composition.SectionComponent src) throws FHIRException {
413    if (src == null)
414      return null;
415    org.hl7.fhir.r5.model.Composition.SectionComponent tgt = new org.hl7.fhir.r5.model.Composition.SectionComponent();
416    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyBackboneElement(src, tgt);
417    if (src.hasTitle())
418      tgt.setTitleElement(String40_50.convertString(src.getTitleElement()));
419    if (src.hasCode())
420      tgt.setCode(CodeableConcept40_50.convertCodeableConcept(src.getCode()));
421    for (org.hl7.fhir.r4.model.Reference t : src.getAuthor()) tgt.addAuthor(Reference40_50.convertReference(t));
422    if (src.hasFocus())
423      tgt.setFocus(Reference40_50.convertReference(src.getFocus()));
424    if (src.hasText())
425      tgt.setText(Narrative40_50.convertNarrative(src.getText()));
426//    if (src.hasMode())
427//      tgt.setModeElement(convertSectionMode(src.getModeElement()));
428    if (src.hasOrderedBy())
429      tgt.setOrderedBy(CodeableConcept40_50.convertCodeableConcept(src.getOrderedBy()));
430    for (org.hl7.fhir.r4.model.Reference t : src.getEntry()) tgt.addEntry(Reference40_50.convertReference(t));
431    if (src.hasEmptyReason())
432      tgt.setEmptyReason(CodeableConcept40_50.convertCodeableConcept(src.getEmptyReason()));
433    for (org.hl7.fhir.r4.model.Composition.SectionComponent t : src.getSection())
434      tgt.addSection(convertSectionComponent(t));
435    return tgt;
436  }
437
438  public static org.hl7.fhir.r4.model.Composition.SectionComponent convertSectionComponent(org.hl7.fhir.r5.model.Composition.SectionComponent src) throws FHIRException {
439    if (src == null)
440      return null;
441    org.hl7.fhir.r4.model.Composition.SectionComponent tgt = new org.hl7.fhir.r4.model.Composition.SectionComponent();
442    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyBackboneElement(src, tgt);
443    if (src.hasTitle())
444      tgt.setTitleElement(String40_50.convertString(src.getTitleElement()));
445    if (src.hasCode())
446      tgt.setCode(CodeableConcept40_50.convertCodeableConcept(src.getCode()));
447    for (org.hl7.fhir.r5.model.Reference t : src.getAuthor()) tgt.addAuthor(Reference40_50.convertReference(t));
448    if (src.hasFocus())
449      tgt.setFocus(Reference40_50.convertReference(src.getFocus()));
450    if (src.hasText())
451      tgt.setText(Narrative40_50.convertNarrative(src.getText()));
452//    if (src.hasMode())
453//      tgt.setModeElement(convertSectionMode(src.getModeElement()));
454    if (src.hasOrderedBy())
455      tgt.setOrderedBy(CodeableConcept40_50.convertCodeableConcept(src.getOrderedBy()));
456    for (org.hl7.fhir.r5.model.Reference t : src.getEntry()) tgt.addEntry(Reference40_50.convertReference(t));
457    if (src.hasEmptyReason())
458      tgt.setEmptyReason(CodeableConcept40_50.convertCodeableConcept(src.getEmptyReason()));
459    for (org.hl7.fhir.r5.model.Composition.SectionComponent t : src.getSection())
460      tgt.addSection(convertSectionComponent(t));
461    return tgt;
462  }
463
464  static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Enumerations.ListMode> convertSectionMode(org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Composition.SectionMode> src) throws FHIRException {
465      if (src == null || src.isEmpty())
466          return null;
467      Enumeration<Enumerations.ListMode> tgt = new Enumeration<>(new Enumerations.ListModeEnumFactory());
468      ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt);
469      if (src.getValue() == null) {
470          tgt.setValue(null);
471      } else {
472          switch (src.getValue()) {
473              case WORKING:
474                  tgt.setValue(Enumerations.ListMode.WORKING);
475                  break;
476              case SNAPSHOT:
477                  tgt.setValue(Enumerations.ListMode.SNAPSHOT);
478                  break;
479              case CHANGES:
480                  tgt.setValue(Enumerations.ListMode.CHANGES);
481                  break;
482              default:
483                  tgt.setValue(Enumerations.ListMode.NULL);
484                  break;
485          }
486      }
487      return tgt;
488  }
489
490  static public org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Composition.SectionMode> convertSectionMode(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Enumerations.ListMode> src) throws FHIRException {
491      if (src == null || src.isEmpty())
492          return null;
493      org.hl7.fhir.r4.model.Enumeration<Composition.SectionMode> tgt = new org.hl7.fhir.r4.model.Enumeration<>(new Composition.SectionModeEnumFactory());
494      ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt);
495      if (src.getValue() == null) {
496          tgt.setValue(null);
497      } else {
498          switch (src.getValue()) {
499              case WORKING:
500                  tgt.setValue(Composition.SectionMode.WORKING);
501                  break;
502              case SNAPSHOT:
503                  tgt.setValue(Composition.SectionMode.SNAPSHOT);
504                  break;
505              case CHANGES:
506                  tgt.setValue(Composition.SectionMode.CHANGES);
507                  break;
508              default:
509                  tgt.setValue(Composition.SectionMode.NULL);
510                  break;
511          }
512      }
513      return tgt;
514  }
515}