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