001package org.hl7.fhir.convertors.conv10_30;
002
003import java.util.ArrayList;
004import java.util.List;
005import org.hl7.fhir.convertors.VersionConvertor_10_30;
006import org.hl7.fhir.dstu3.model.ConceptMap;
007import org.hl7.fhir.dstu3.model.ConceptMap.ConceptMapGroupComponent;
008import org.hl7.fhir.exceptions.FHIRException;
009
010public class ConceptMap10_30 {
011
012    public static org.hl7.fhir.dstu2.model.ConceptMap convertConceptMap(org.hl7.fhir.dstu3.model.ConceptMap src) throws FHIRException {
013        if (src == null || src.isEmpty())
014            return null;
015        org.hl7.fhir.dstu2.model.ConceptMap tgt = new org.hl7.fhir.dstu2.model.ConceptMap();
016        VersionConvertor_10_30.copyDomainResource(src, tgt);
017        if (src.hasUrlElement())
018            tgt.setUrlElement(VersionConvertor_10_30.convertUri(src.getUrlElement()));
019        if (src.hasIdentifier())
020            tgt.setIdentifier(VersionConvertor_10_30.convertIdentifier(src.getIdentifier()));
021        if (src.hasVersionElement())
022            tgt.setVersionElement(VersionConvertor_10_30.convertString(src.getVersionElement()));
023        if (src.hasNameElement())
024            tgt.setNameElement(VersionConvertor_10_30.convertString(src.getNameElement()));
025        if (src.hasStatus())
026            tgt.setStatusElement(VersionConvertor_10_30.convertConformanceResourceStatus(src.getStatusElement()));
027        if (src.hasExperimental())
028            tgt.setExperimentalElement(VersionConvertor_10_30.convertBoolean(src.getExperimentalElement()));
029        if (src.hasPublisherElement())
030            tgt.setPublisherElement(VersionConvertor_10_30.convertString(src.getPublisherElement()));
031        for (org.hl7.fhir.dstu3.model.ContactDetail t : src.getContact()) tgt.addContact(convertConceptMapContactComponent(t));
032        if (src.hasDate())
033            tgt.setDateElement(VersionConvertor_10_30.convertDateTime(src.getDateElement()));
034        if (src.hasDescription())
035            tgt.setDescription(src.getDescription());
036        for (org.hl7.fhir.dstu3.model.UsageContext t : src.getUseContext()) if (t.hasValueCodeableConcept())
037            tgt.addUseContext(VersionConvertor_10_30.convertCodeableConcept(t.getValueCodeableConcept()));
038        for (org.hl7.fhir.dstu3.model.CodeableConcept t : src.getJurisdiction()) tgt.addUseContext(VersionConvertor_10_30.convertCodeableConcept(t));
039        if (src.hasPurpose())
040            tgt.setRequirements(src.getPurpose());
041        if (src.hasCopyright())
042            tgt.setCopyright(src.getCopyright());
043        if (src.hasSource())
044            tgt.setSource(VersionConvertor_10_30.convertType(src.getSource()));
045        if (src.hasTarget())
046            tgt.setTarget(VersionConvertor_10_30.convertType(src.getTarget()));
047        for (org.hl7.fhir.dstu3.model.ConceptMap.ConceptMapGroupComponent g : src.getGroup()) for (org.hl7.fhir.dstu3.model.ConceptMap.SourceElementComponent t : g.getElement()) tgt.addElement(convertSourceElementComponent(t, g));
048        return tgt;
049    }
050
051    public static org.hl7.fhir.dstu3.model.ConceptMap convertConceptMap(org.hl7.fhir.dstu2.model.ConceptMap src) throws FHIRException {
052        if (src == null || src.isEmpty())
053            return null;
054        org.hl7.fhir.dstu3.model.ConceptMap tgt = new org.hl7.fhir.dstu3.model.ConceptMap();
055        VersionConvertor_10_30.copyDomainResource(src, tgt);
056        if (src.hasUrlElement())
057            tgt.setUrlElement(VersionConvertor_10_30.convertUri(src.getUrlElement()));
058        if (src.hasIdentifier())
059            tgt.setIdentifier(VersionConvertor_10_30.convertIdentifier(src.getIdentifier()));
060        if (src.hasVersionElement())
061            tgt.setVersionElement(VersionConvertor_10_30.convertString(src.getVersionElement()));
062        if (src.hasNameElement())
063            tgt.setNameElement(VersionConvertor_10_30.convertString(src.getNameElement()));
064        if (src.hasStatus())
065            tgt.setStatusElement(VersionConvertor_10_30.convertConformanceResourceStatus(src.getStatusElement()));
066        if (src.hasExperimental())
067            tgt.setExperimentalElement(VersionConvertor_10_30.convertBoolean(src.getExperimentalElement()));
068        if (src.hasPublisherElement())
069            tgt.setPublisherElement(VersionConvertor_10_30.convertString(src.getPublisherElement()));
070        for (org.hl7.fhir.dstu2.model.ConceptMap.ConceptMapContactComponent t : src.getContact()) tgt.addContact(convertConceptMapContactComponent(t));
071        if (src.hasDate())
072            tgt.setDateElement(VersionConvertor_10_30.convertDateTime(src.getDateElement()));
073        if (src.hasDescription())
074            tgt.setDescription(src.getDescription());
075        for (org.hl7.fhir.dstu2.model.CodeableConcept t : src.getUseContext()) if (VersionConvertor_10_30.isJurisdiction(t))
076            tgt.addJurisdiction(VersionConvertor_10_30.convertCodeableConcept(t));
077        else
078            tgt.addUseContext(VersionConvertor_10_30.convertCodeableConceptToUsageContext(t));
079        if (src.hasRequirements())
080            tgt.setPurpose(src.getRequirements());
081        if (src.hasCopyright())
082            tgt.setCopyright(src.getCopyright());
083        if (src.hasSource())
084            tgt.setSource(VersionConvertor_10_30.convertType(src.getSource()));
085        if (src.hasTarget())
086            tgt.setTarget(VersionConvertor_10_30.convertType(src.getTarget()));
087        for (org.hl7.fhir.dstu2.model.ConceptMap.SourceElementComponent t : src.getElement()) {
088            List<VersionConvertor_10_30.SourceElementComponentWrapper> ws = convertSourceElementComponent(t);
089            for (VersionConvertor_10_30.SourceElementComponentWrapper w : ws) getGroup(tgt, w.source, w.target).addElement(w.comp);
090        }
091        return tgt;
092    }
093
094    public static org.hl7.fhir.dstu3.model.ContactDetail convertConceptMapContactComponent(org.hl7.fhir.dstu2.model.ConceptMap.ConceptMapContactComponent src) throws FHIRException {
095        if (src == null || src.isEmpty())
096            return null;
097        org.hl7.fhir.dstu3.model.ContactDetail tgt = new org.hl7.fhir.dstu3.model.ContactDetail();
098        VersionConvertor_10_30.copyElement(src, tgt);
099        if (src.hasNameElement())
100            tgt.setNameElement(VersionConvertor_10_30.convertString(src.getNameElement()));
101        for (org.hl7.fhir.dstu2.model.ContactPoint t : src.getTelecom()) tgt.addTelecom(VersionConvertor_10_30.convertContactPoint(t));
102        return tgt;
103    }
104
105    public static org.hl7.fhir.dstu2.model.ConceptMap.ConceptMapContactComponent convertConceptMapContactComponent(org.hl7.fhir.dstu3.model.ContactDetail src) throws FHIRException {
106        if (src == null || src.isEmpty())
107            return null;
108        org.hl7.fhir.dstu2.model.ConceptMap.ConceptMapContactComponent tgt = new org.hl7.fhir.dstu2.model.ConceptMap.ConceptMapContactComponent();
109        VersionConvertor_10_30.copyElement(src, tgt);
110        if (src.hasNameElement())
111            tgt.setNameElement(VersionConvertor_10_30.convertString(src.getNameElement()));
112        for (org.hl7.fhir.dstu3.model.ContactPoint t : src.getTelecom()) tgt.addTelecom(VersionConvertor_10_30.convertContactPoint(t));
113        return tgt;
114    }
115
116    static public org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Enumerations.ConceptMapEquivalence> convertConceptMapEquivalence(org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Enumerations.ConceptMapEquivalence> src) throws FHIRException {
117        if (src == null || src.isEmpty())
118            return null;
119        org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Enumerations.ConceptMapEquivalence> tgt = new org.hl7.fhir.dstu3.model.Enumeration<>(new org.hl7.fhir.dstu3.model.Enumerations.ConceptMapEquivalenceEnumFactory());
120        VersionConvertor_10_30.copyElement(src, tgt);
121        switch(src.getValue()) {
122            case EQUIVALENT:
123                tgt.setValue(org.hl7.fhir.dstu3.model.Enumerations.ConceptMapEquivalence.EQUIVALENT);
124                break;
125            case EQUAL:
126                tgt.setValue(org.hl7.fhir.dstu3.model.Enumerations.ConceptMapEquivalence.EQUAL);
127                break;
128            case WIDER:
129                tgt.setValue(org.hl7.fhir.dstu3.model.Enumerations.ConceptMapEquivalence.WIDER);
130                break;
131            case SUBSUMES:
132                tgt.setValue(org.hl7.fhir.dstu3.model.Enumerations.ConceptMapEquivalence.SUBSUMES);
133                break;
134            case NARROWER:
135                tgt.setValue(org.hl7.fhir.dstu3.model.Enumerations.ConceptMapEquivalence.NARROWER);
136                break;
137            case SPECIALIZES:
138                tgt.setValue(org.hl7.fhir.dstu3.model.Enumerations.ConceptMapEquivalence.SPECIALIZES);
139                break;
140            case INEXACT:
141                tgt.setValue(org.hl7.fhir.dstu3.model.Enumerations.ConceptMapEquivalence.INEXACT);
142                break;
143            case UNMATCHED:
144                tgt.setValue(org.hl7.fhir.dstu3.model.Enumerations.ConceptMapEquivalence.UNMATCHED);
145                break;
146            case DISJOINT:
147                tgt.setValue(org.hl7.fhir.dstu3.model.Enumerations.ConceptMapEquivalence.DISJOINT);
148                break;
149            default:
150                tgt.setValue(org.hl7.fhir.dstu3.model.Enumerations.ConceptMapEquivalence.NULL);
151                break;
152        }
153        return tgt;
154    }
155
156    static public org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Enumerations.ConceptMapEquivalence> convertConceptMapEquivalence(org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Enumerations.ConceptMapEquivalence> src) throws FHIRException {
157        if (src == null || src.isEmpty())
158            return null;
159        org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Enumerations.ConceptMapEquivalence> tgt = new org.hl7.fhir.dstu2.model.Enumeration<>(new org.hl7.fhir.dstu2.model.Enumerations.ConceptMapEquivalenceEnumFactory());
160        VersionConvertor_10_30.copyElement(src, tgt);
161        switch(src.getValue()) {
162            case EQUIVALENT:
163                tgt.setValue(org.hl7.fhir.dstu2.model.Enumerations.ConceptMapEquivalence.EQUIVALENT);
164                break;
165            case EQUAL:
166                tgt.setValue(org.hl7.fhir.dstu2.model.Enumerations.ConceptMapEquivalence.EQUAL);
167                break;
168            case WIDER:
169                tgt.setValue(org.hl7.fhir.dstu2.model.Enumerations.ConceptMapEquivalence.WIDER);
170                break;
171            case SUBSUMES:
172                tgt.setValue(org.hl7.fhir.dstu2.model.Enumerations.ConceptMapEquivalence.SUBSUMES);
173                break;
174            case NARROWER:
175                tgt.setValue(org.hl7.fhir.dstu2.model.Enumerations.ConceptMapEquivalence.NARROWER);
176                break;
177            case SPECIALIZES:
178                tgt.setValue(org.hl7.fhir.dstu2.model.Enumerations.ConceptMapEquivalence.SPECIALIZES);
179                break;
180            case INEXACT:
181                tgt.setValue(org.hl7.fhir.dstu2.model.Enumerations.ConceptMapEquivalence.INEXACT);
182                break;
183            case UNMATCHED:
184                tgt.setValue(org.hl7.fhir.dstu2.model.Enumerations.ConceptMapEquivalence.UNMATCHED);
185                break;
186            case DISJOINT:
187                tgt.setValue(org.hl7.fhir.dstu2.model.Enumerations.ConceptMapEquivalence.DISJOINT);
188                break;
189            default:
190                tgt.setValue(org.hl7.fhir.dstu2.model.Enumerations.ConceptMapEquivalence.NULL);
191                break;
192        }
193        return tgt;
194    }
195
196    public static org.hl7.fhir.dstu3.model.ConceptMap.OtherElementComponent convertOtherElementComponent(org.hl7.fhir.dstu2.model.ConceptMap.OtherElementComponent src) throws FHIRException {
197        if (src == null || src.isEmpty())
198            return null;
199        org.hl7.fhir.dstu3.model.ConceptMap.OtherElementComponent tgt = new org.hl7.fhir.dstu3.model.ConceptMap.OtherElementComponent();
200        VersionConvertor_10_30.copyElement(src, tgt);
201        if (src.hasElementElement())
202            tgt.setPropertyElement(VersionConvertor_10_30.convertUri(src.getElementElement()));
203        if (src.hasCodeSystemElement())
204            tgt.setSystemElement(VersionConvertor_10_30.convertUri(src.getCodeSystemElement()));
205        if (src.hasCodeElement())
206            tgt.setCodeElement(VersionConvertor_10_30.convertString(src.getCodeElement()));
207        return tgt;
208    }
209
210    public static org.hl7.fhir.dstu2.model.ConceptMap.OtherElementComponent convertOtherElementComponent(org.hl7.fhir.dstu3.model.ConceptMap.OtherElementComponent src) throws FHIRException {
211        if (src == null || src.isEmpty())
212            return null;
213        org.hl7.fhir.dstu2.model.ConceptMap.OtherElementComponent tgt = new org.hl7.fhir.dstu2.model.ConceptMap.OtherElementComponent();
214        VersionConvertor_10_30.copyElement(src, tgt);
215        if (src.hasPropertyElement())
216            tgt.setElementElement(VersionConvertor_10_30.convertUri(src.getPropertyElement()));
217        if (src.hasSystemElement())
218            tgt.setCodeSystemElement(VersionConvertor_10_30.convertUri(src.getSystemElement()));
219        if (src.hasCodeElement())
220            tgt.setCodeElement(VersionConvertor_10_30.convertString(src.getCodeElement()));
221        return tgt;
222    }
223
224    public static List<VersionConvertor_10_30.SourceElementComponentWrapper> convertSourceElementComponent(org.hl7.fhir.dstu2.model.ConceptMap.SourceElementComponent src) throws FHIRException {
225        List<VersionConvertor_10_30.SourceElementComponentWrapper> res = new ArrayList<VersionConvertor_10_30.SourceElementComponentWrapper>();
226        if (src == null || src.isEmpty())
227            return res;
228        for (org.hl7.fhir.dstu2.model.ConceptMap.TargetElementComponent t : src.getTarget()) {
229            org.hl7.fhir.dstu3.model.ConceptMap.SourceElementComponent tgt = new org.hl7.fhir.dstu3.model.ConceptMap.SourceElementComponent();
230            VersionConvertor_10_30.copyElement(src, tgt);
231            tgt.setCode(src.getCode());
232            tgt.addTarget(convertTargetElementComponent(t));
233            res.add(new VersionConvertor_10_30.SourceElementComponentWrapper(tgt, src.getCodeSystem(), t.getCodeSystem()));
234        }
235        return res;
236    }
237
238    public static org.hl7.fhir.dstu2.model.ConceptMap.SourceElementComponent convertSourceElementComponent(org.hl7.fhir.dstu3.model.ConceptMap.SourceElementComponent src, org.hl7.fhir.dstu3.model.ConceptMap.ConceptMapGroupComponent g) throws FHIRException {
239        if (src == null || src.isEmpty())
240            return null;
241        org.hl7.fhir.dstu2.model.ConceptMap.SourceElementComponent tgt = new org.hl7.fhir.dstu2.model.ConceptMap.SourceElementComponent();
242        VersionConvertor_10_30.copyElement(src, tgt);
243        tgt.setCodeSystem(g.getSource());
244        if (src.hasCodeElement())
245            tgt.setCodeElement(VersionConvertor_10_30.convertCode(src.getCodeElement()));
246        for (org.hl7.fhir.dstu3.model.ConceptMap.TargetElementComponent t : src.getTarget()) tgt.addTarget(convertTargetElementComponent(t, g));
247        return tgt;
248    }
249
250    public static org.hl7.fhir.dstu2.model.ConceptMap.TargetElementComponent convertTargetElementComponent(org.hl7.fhir.dstu3.model.ConceptMap.TargetElementComponent src, org.hl7.fhir.dstu3.model.ConceptMap.ConceptMapGroupComponent g) throws FHIRException {
251        if (src == null || src.isEmpty())
252            return null;
253        org.hl7.fhir.dstu2.model.ConceptMap.TargetElementComponent tgt = new org.hl7.fhir.dstu2.model.ConceptMap.TargetElementComponent();
254        VersionConvertor_10_30.copyElement(src, tgt);
255        tgt.setCodeSystem(g.getTarget());
256        if (src.hasCodeElement())
257            tgt.setCodeElement(VersionConvertor_10_30.convertCode(src.getCodeElement()));
258        if (src.hasEquivalence())
259            tgt.setEquivalenceElement(convertConceptMapEquivalence(src.getEquivalenceElement()));
260        if (src.hasCommentElement())
261            tgt.setCommentsElement(VersionConvertor_10_30.convertString(src.getCommentElement()));
262        for (org.hl7.fhir.dstu3.model.ConceptMap.OtherElementComponent t : src.getDependsOn()) tgt.addDependsOn(convertOtherElementComponent(t));
263        for (org.hl7.fhir.dstu3.model.ConceptMap.OtherElementComponent t : src.getProduct()) tgt.addProduct(convertOtherElementComponent(t));
264        return tgt;
265    }
266
267    public static org.hl7.fhir.dstu3.model.ConceptMap.TargetElementComponent convertTargetElementComponent(org.hl7.fhir.dstu2.model.ConceptMap.TargetElementComponent src) throws FHIRException {
268        if (src == null || src.isEmpty())
269            return null;
270        org.hl7.fhir.dstu3.model.ConceptMap.TargetElementComponent tgt = new org.hl7.fhir.dstu3.model.ConceptMap.TargetElementComponent();
271        VersionConvertor_10_30.copyElement(src, tgt);
272        if (src.hasCodeElement())
273            tgt.setCodeElement(VersionConvertor_10_30.convertCode(src.getCodeElement()));
274        if (src.hasEquivalence())
275            tgt.setEquivalenceElement(convertConceptMapEquivalence(src.getEquivalenceElement()));
276        if (src.hasCommentsElement())
277            tgt.setCommentElement(VersionConvertor_10_30.convertString(src.getCommentsElement()));
278        for (org.hl7.fhir.dstu2.model.ConceptMap.OtherElementComponent t : src.getDependsOn()) tgt.addDependsOn(convertOtherElementComponent(t));
279        for (org.hl7.fhir.dstu2.model.ConceptMap.OtherElementComponent t : src.getProduct()) tgt.addProduct(convertOtherElementComponent(t));
280        return tgt;
281    }
282
283    static public ConceptMapGroupComponent getGroup(ConceptMap map, String srcs, String tgts) {
284        for (ConceptMapGroupComponent grp : map.getGroup()) {
285            if (grp.getSource().equals(srcs) && grp.getTarget().equals(tgts))
286                return grp;
287        }
288        ConceptMapGroupComponent grp = map.addGroup();
289        grp.setSource(srcs);
290        grp.setTarget(tgts);
291        return grp;
292    }
293}