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