001package org.hl7.fhir.convertors.conv10_50.resources10_50;
002
003import java.util.Collections;
004
005import org.hl7.fhir.convertors.context.ConversionContext10_50;
006import org.hl7.fhir.convertors.conv10_50.datatypes10_50.Narrative10_50;
007import org.hl7.fhir.convertors.conv10_50.datatypes10_50.Reference10_50;
008import org.hl7.fhir.convertors.conv10_50.datatypes10_50.complextypes10_50.CodeableConcept10_50;
009import org.hl7.fhir.convertors.conv10_50.datatypes10_50.complextypes10_50.Identifier10_50;
010import org.hl7.fhir.convertors.conv10_50.datatypes10_50.complextypes10_50.Period10_50;
011import org.hl7.fhir.convertors.conv10_50.datatypes10_50.primitivetypes10_50.Code10_50;
012import org.hl7.fhir.convertors.conv10_50.datatypes10_50.primitivetypes10_50.DateTime10_50;
013import org.hl7.fhir.convertors.conv10_50.datatypes10_50.primitivetypes10_50.String10_50;
014import org.hl7.fhir.exceptions.FHIRException;
015
016public class Composition10_50 {
017
018  public static org.hl7.fhir.r5.model.Composition convertComposition(org.hl7.fhir.dstu2.model.Composition src) throws FHIRException {
019    if (src == null || src.isEmpty())
020      return null;
021    org.hl7.fhir.r5.model.Composition tgt = new org.hl7.fhir.r5.model.Composition();
022    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyDomainResource(src, tgt);
023    if (src.hasIdentifier())
024      tgt.addIdentifier(Identifier10_50.convertIdentifier(src.getIdentifier()));
025    if (src.hasDate())
026      tgt.setDateElement(DateTime10_50.convertDateTime(src.getDateElement()));
027    if (src.hasType())
028      tgt.setType(CodeableConcept10_50.convertCodeableConcept(src.getType()));
029    if (src.hasClass_())
030      tgt.addCategory(CodeableConcept10_50.convertCodeableConcept(src.getClass_()));
031    if (src.hasTitleElement())
032      tgt.setTitleElement(String10_50.convertString(src.getTitleElement()));
033    if (src.hasStatus())
034      tgt.setStatusElement(convertCompositionStatus(src.getStatusElement()));
035    try {
036      if (src.hasConfidentiality())
037        tgt.getMeta().addSecurity().setCodeElement(Code10_50.convertCode(src.getConfidentialityElement()));
038    } catch (org.hl7.fhir.exceptions.FHIRException e) {
039      throw new FHIRException(e);
040    }
041    if (src.hasSubject())
042      tgt.addSubject(Reference10_50.convertReference(src.getSubject()));
043    for (org.hl7.fhir.dstu2.model.Reference t : src.getAuthor()) tgt.addAuthor(Reference10_50.convertReference(t));
044    for (org.hl7.fhir.dstu2.model.Composition.CompositionAttesterComponent t : src.getAttester())
045      tgt.addAttester(convertCompositionAttesterComponent(t));
046    if (src.hasCustodian())
047      tgt.setCustodian(Reference10_50.convertReference(src.getCustodian()));
048    for (org.hl7.fhir.dstu2.model.Composition.CompositionEventComponent t : src.getEvent())
049      tgt.addEvent(convertCompositionEventComponent(t));
050    if (src.hasEncounter())
051      tgt.setEncounter(Reference10_50.convertReference(src.getEncounter()));
052    for (org.hl7.fhir.dstu2.model.Composition.SectionComponent t : src.getSection())
053      tgt.addSection(convertSectionComponent(t));
054    return tgt;
055  }
056
057  public static org.hl7.fhir.dstu2.model.Composition convertComposition(org.hl7.fhir.r5.model.Composition src) throws FHIRException {
058    if (src == null || src.isEmpty())
059      return null;
060    org.hl7.fhir.dstu2.model.Composition tgt = new org.hl7.fhir.dstu2.model.Composition();
061    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyDomainResource(src, tgt);
062    if (src.hasIdentifier())
063      tgt.setIdentifier(Identifier10_50.convertIdentifier(src.getIdentifierFirstRep()));
064    if (src.hasDate())
065      tgt.setDateElement(DateTime10_50.convertDateTime(src.getDateElement()));
066    if (src.hasType())
067      tgt.setType(CodeableConcept10_50.convertCodeableConcept(src.getType()));
068    if (src.hasCategory())
069      tgt.setClass_(CodeableConcept10_50.convertCodeableConcept(src.getCategoryFirstRep()));
070    if (src.hasTitleElement())
071      tgt.setTitleElement(String10_50.convertString(src.getTitleElement()));
072    if (src.hasStatus())
073      tgt.setStatusElement(convertCompositionStatus(src.getStatusElement()));
074    tgt.setConfidentiality(src.getMeta().getSecurityFirstRep().getCode());
075    if (src.hasSubject())
076      tgt.setSubject(Reference10_50.convertReference(src.getSubjectFirstRep()));
077    for (org.hl7.fhir.r5.model.Reference t : src.getAuthor()) tgt.addAuthor(Reference10_50.convertReference(t));
078    for (org.hl7.fhir.r5.model.Composition.CompositionAttesterComponent t : src.getAttester())
079      tgt.addAttester(convertCompositionAttesterComponent(t));
080    if (src.hasCustodian())
081      tgt.setCustodian(Reference10_50.convertReference(src.getCustodian()));
082    for (org.hl7.fhir.r5.model.Composition.CompositionEventComponent t : src.getEvent())
083      tgt.addEvent(convertCompositionEventComponent(t));
084    if (src.hasEncounter())
085      tgt.setEncounter(Reference10_50.convertReference(src.getEncounter()));
086    for (org.hl7.fhir.r5.model.Composition.SectionComponent t : src.getSection())
087      tgt.addSection(convertSectionComponent(t));
088    return tgt;
089  }
090
091  static public org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Composition.CompositionAttestationMode> convertCompositionAttestationMode(org.hl7.fhir.r5.model.CodeableConcept src) throws FHIRException {
092    if (src == null || src.isEmpty())
093      return null;
094    org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Composition.CompositionAttestationMode> tgt = new org.hl7.fhir.dstu2.model.Enumeration<>(new org.hl7.fhir.dstu2.model.Composition.CompositionAttestationModeEnumFactory());
095    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyElement(src, tgt);
096    switch (src.getCode("http://hl7.org/fhir/composition-attestation-mode")) {
097      case "personal":
098        tgt.setValue(org.hl7.fhir.dstu2.model.Composition.CompositionAttestationMode.PERSONAL);
099        break;
100      case "professional":
101        tgt.setValue(org.hl7.fhir.dstu2.model.Composition.CompositionAttestationMode.PROFESSIONAL);
102        break;
103      case "legal":
104        tgt.setValue(org.hl7.fhir.dstu2.model.Composition.CompositionAttestationMode.LEGAL);
105        break;
106      case "official":
107        tgt.setValue(org.hl7.fhir.dstu2.model.Composition.CompositionAttestationMode.OFFICIAL);
108        break;
109      default:
110        tgt.setValue(org.hl7.fhir.dstu2.model.Composition.CompositionAttestationMode.NULL);
111        break;
112    }
113    return tgt;
114  }
115
116  static public org.hl7.fhir.r5.model.CodeableConcept convertCompositionAttestationMode(org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Composition.CompositionAttestationMode> src) throws FHIRException {
117    if (src == null || src.isEmpty())
118      return null;
119    org.hl7.fhir.r5.model.CodeableConcept tgt = new org.hl7.fhir.r5.model.CodeableConcept();
120    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyElement(src, tgt);
121    switch (src.getValue()) {
122      case PERSONAL:
123        tgt.addCoding().setSystem("http://hl7.org/fhir/composition-attestation-mode").setCode("personal");
124        break;
125      case PROFESSIONAL:
126        tgt.addCoding().setSystem("http://hl7.org/fhir/composition-attestation-mode").setCode("professional");
127        break;
128      case LEGAL:
129        tgt.addCoding().setSystem("http://hl7.org/fhir/composition-attestation-mode").setCode("legal");
130        break;
131      case OFFICIAL:
132        tgt.addCoding().setSystem("http://hl7.org/fhir/composition-attestation-mode").setCode("official");
133        break;
134      default:
135        break;
136    }
137    return tgt;
138  }
139  public static org.hl7.fhir.dstu2.model.Composition.CompositionAttesterComponent convertCompositionAttesterComponent(org.hl7.fhir.r5.model.Composition.CompositionAttesterComponent src) throws FHIRException {
140    if (src == null || src.isEmpty())
141      return null;
142    org.hl7.fhir.dstu2.model.Composition.CompositionAttesterComponent tgt = new org.hl7.fhir.dstu2.model.Composition.CompositionAttesterComponent();
143    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyBackboneElement(src,tgt);
144    if (src.hasMode())
145      tgt.setMode(Collections.singletonList(convertCompositionAttestationMode(src.getMode())));
146    if (src.hasTimeElement())
147      tgt.setTimeElement(DateTime10_50.convertDateTime(src.getTimeElement()));
148    if (src.hasParty())
149      tgt.setParty(Reference10_50.convertReference(src.getParty()));
150    return tgt;
151  }
152
153  public static org.hl7.fhir.r5.model.Composition.CompositionAttesterComponent convertCompositionAttesterComponent(org.hl7.fhir.dstu2.model.Composition.CompositionAttesterComponent src) throws FHIRException {
154    if (src == null || src.isEmpty())
155      return null;
156    org.hl7.fhir.r5.model.Composition.CompositionAttesterComponent tgt = new org.hl7.fhir.r5.model.Composition.CompositionAttesterComponent();
157    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyBackboneElement(src,tgt);
158    if (src.hasMode())
159      tgt.setMode(convertCompositionAttestationMode(src.getMode().get(0)));
160    if (src.hasTimeElement())
161      tgt.setTimeElement(DateTime10_50.convertDateTime(src.getTimeElement()));
162    if (src.hasParty())
163      tgt.setParty(Reference10_50.convertReference(src.getParty()));
164    return tgt;
165  }
166
167  public static org.hl7.fhir.dstu2.model.Composition.CompositionEventComponent convertCompositionEventComponent(org.hl7.fhir.r5.model.Composition.CompositionEventComponent src) throws FHIRException {
168    if (src == null || src.isEmpty())
169      return null;
170    org.hl7.fhir.dstu2.model.Composition.CompositionEventComponent tgt = new org.hl7.fhir.dstu2.model.Composition.CompositionEventComponent();
171    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyBackboneElement(src,tgt);
172    for (org.hl7.fhir.r5.model.CodeableConcept t : src.getCode())
173      tgt.addCode(CodeableConcept10_50.convertCodeableConcept(t));
174    if (src.hasPeriod())
175      tgt.setPeriod(Period10_50.convertPeriod(src.getPeriod()));
176    for (org.hl7.fhir.r5.model.Reference t : src.getDetail()) tgt.addDetail(Reference10_50.convertReference(t));
177    return tgt;
178  }
179
180  public static org.hl7.fhir.r5.model.Composition.CompositionEventComponent convertCompositionEventComponent(org.hl7.fhir.dstu2.model.Composition.CompositionEventComponent src) throws FHIRException {
181    if (src == null || src.isEmpty())
182      return null;
183    org.hl7.fhir.r5.model.Composition.CompositionEventComponent tgt = new org.hl7.fhir.r5.model.Composition.CompositionEventComponent();
184    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyBackboneElement(src,tgt);
185    for (org.hl7.fhir.dstu2.model.CodeableConcept t : src.getCode())
186      tgt.addCode(CodeableConcept10_50.convertCodeableConcept(t));
187    if (src.hasPeriod())
188      tgt.setPeriod(Period10_50.convertPeriod(src.getPeriod()));
189    for (org.hl7.fhir.dstu2.model.Reference t : src.getDetail()) tgt.addDetail(Reference10_50.convertReference(t));
190    return tgt;
191  }
192
193  static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Enumerations.CompositionStatus> convertCompositionStatus(org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Composition.CompositionStatus> src) throws FHIRException {
194    if (src == null || src.isEmpty())
195      return null;
196    org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Enumerations.CompositionStatus> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.Enumerations.CompositionStatusEnumFactory());
197    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyElement(src, tgt);
198    switch (src.getValue()) {
199      case PRELIMINARY:
200        tgt.setValue(org.hl7.fhir.r5.model.Enumerations.CompositionStatus.PRELIMINARY);
201        break;
202      case FINAL:
203        tgt.setValue(org.hl7.fhir.r5.model.Enumerations.CompositionStatus.FINAL);
204        break;
205      case AMENDED:
206        tgt.setValue(org.hl7.fhir.r5.model.Enumerations.CompositionStatus.AMENDED);
207        break;
208      case ENTEREDINERROR:
209        tgt.setValue(org.hl7.fhir.r5.model.Enumerations.CompositionStatus.ENTEREDINERROR);
210        break;
211      default:
212        tgt.setValue(org.hl7.fhir.r5.model.Enumerations.CompositionStatus.NULL);
213        break;
214    }
215    return tgt;
216  }
217
218  static public org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Composition.CompositionStatus> convertCompositionStatus(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Enumerations.CompositionStatus> src) throws FHIRException {
219    if (src == null || src.isEmpty())
220      return null;
221    org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Composition.CompositionStatus> tgt = new org.hl7.fhir.dstu2.model.Enumeration<>(new org.hl7.fhir.dstu2.model.Composition.CompositionStatusEnumFactory());
222    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyElement(src, tgt);
223    switch (src.getValue()) {
224      case PRELIMINARY:
225        tgt.setValue(org.hl7.fhir.dstu2.model.Composition.CompositionStatus.PRELIMINARY);
226        break;
227      case FINAL:
228        tgt.setValue(org.hl7.fhir.dstu2.model.Composition.CompositionStatus.FINAL);
229        break;
230      case AMENDED:
231        tgt.setValue(org.hl7.fhir.dstu2.model.Composition.CompositionStatus.AMENDED);
232        break;
233      case ENTEREDINERROR:
234        tgt.setValue(org.hl7.fhir.dstu2.model.Composition.CompositionStatus.ENTEREDINERROR);
235        break;
236      default:
237        tgt.setValue(org.hl7.fhir.dstu2.model.Composition.CompositionStatus.NULL);
238        break;
239    }
240    return tgt;
241  }
242
243  public static org.hl7.fhir.dstu2.model.Composition.SectionComponent convertSectionComponent(org.hl7.fhir.r5.model.Composition.SectionComponent src) throws FHIRException {
244    if (src == null || src.isEmpty())
245      return null;
246    org.hl7.fhir.dstu2.model.Composition.SectionComponent tgt = new org.hl7.fhir.dstu2.model.Composition.SectionComponent();
247    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyBackboneElement(src,tgt);
248    if (src.hasTitleElement())
249      tgt.setTitleElement(String10_50.convertString(src.getTitleElement()));
250    if (src.hasCode())
251      tgt.setCode(CodeableConcept10_50.convertCodeableConcept(src.getCode()));
252    if (src.hasText())
253      tgt.setText(Narrative10_50.convertNarrative(src.getText()));
254    tgt.setMode(src.getMode().toCode());
255    if (src.hasOrderedBy())
256      tgt.setOrderedBy(CodeableConcept10_50.convertCodeableConcept(src.getOrderedBy()));
257    for (org.hl7.fhir.r5.model.Reference t : src.getEntry()) tgt.addEntry(Reference10_50.convertReference(t));
258    if (src.hasEmptyReason())
259      tgt.setEmptyReason(CodeableConcept10_50.convertCodeableConcept(src.getEmptyReason()));
260    for (org.hl7.fhir.r5.model.Composition.SectionComponent t : src.getSection())
261      tgt.addSection(convertSectionComponent(t));
262    return tgt;
263  }
264
265  public static org.hl7.fhir.r5.model.Composition.SectionComponent convertSectionComponent(org.hl7.fhir.dstu2.model.Composition.SectionComponent src) throws FHIRException {
266    if (src == null || src.isEmpty())
267      return null;
268    org.hl7.fhir.r5.model.Composition.SectionComponent tgt = new org.hl7.fhir.r5.model.Composition.SectionComponent();
269    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyBackboneElement(src,tgt);
270    if (src.hasTitleElement())
271      tgt.setTitleElement(String10_50.convertString(src.getTitleElement()));
272    if (src.hasCode())
273      tgt.setCode(CodeableConcept10_50.convertCodeableConcept(src.getCode()));
274    if (src.hasText())
275      tgt.setText(Narrative10_50.convertNarrative(src.getText()));
276    try {
277      if (src.hasMode())
278        tgt.setMode(org.hl7.fhir.r5.model.Enumerations.ListMode.fromCode(src.getMode()));
279    } catch (org.hl7.fhir.exceptions.FHIRException e) {
280      throw new FHIRException(e);
281    }
282    if (src.hasOrderedBy())
283      tgt.setOrderedBy(CodeableConcept10_50.convertCodeableConcept(src.getOrderedBy()));
284    for (org.hl7.fhir.dstu2.model.Reference t : src.getEntry()) tgt.addEntry(Reference10_50.convertReference(t));
285    if (src.hasEmptyReason())
286      tgt.setEmptyReason(CodeableConcept10_50.convertCodeableConcept(src.getEmptyReason()));
287    for (org.hl7.fhir.dstu2.model.Composition.SectionComponent t : src.getSection())
288      tgt.addSection(convertSectionComponent(t));
289    return tgt;
290  }
291}