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