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