001package org.hl7.fhir.convertors.conv10_30.resources10_30;
002
003import java.util.ArrayList;
004import java.util.List;
005
006import org.hl7.fhir.convertors.SourceElementComponentWrapper;
007import org.hl7.fhir.convertors.context.ConversionContext10_30;
008import org.hl7.fhir.convertors.conv10_30.VersionConvertor_10_30;
009import org.hl7.fhir.convertors.conv10_30.datatypes10_30.complextypes10_30.CodeableConcept10_30;
010import org.hl7.fhir.convertors.conv10_30.datatypes10_30.complextypes10_30.ContactPoint10_30;
011import org.hl7.fhir.convertors.conv10_30.datatypes10_30.complextypes10_30.Identifier10_30;
012import org.hl7.fhir.convertors.conv10_30.datatypes10_30.primitivetypes10_30.Boolean10_30;
013import org.hl7.fhir.convertors.conv10_30.datatypes10_30.primitivetypes10_30.Code10_30;
014import org.hl7.fhir.convertors.conv10_30.datatypes10_30.primitivetypes10_30.DateTime10_30;
015import org.hl7.fhir.convertors.conv10_30.datatypes10_30.primitivetypes10_30.String10_30;
016import org.hl7.fhir.convertors.conv10_30.datatypes10_30.primitivetypes10_30.Uri10_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 ConceptMap10_30 {
022
023  public static org.hl7.fhir.dstu2.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.dstu2.model.ConceptMap tgt = new org.hl7.fhir.dstu2.model.ConceptMap();
027    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyDomainResource(src, tgt);
028    if (src.hasUrlElement())
029      tgt.setUrlElement(Uri10_30.convertUri(src.getUrlElement()));
030    if (src.hasIdentifier())
031      tgt.setIdentifier(Identifier10_30.convertIdentifier(src.getIdentifier()));
032    if (src.hasVersionElement())
033      tgt.setVersionElement(String10_30.convertString(src.getVersionElement()));
034    if (src.hasNameElement())
035      tgt.setNameElement(String10_30.convertString(src.getNameElement()));
036    if (src.hasStatus())
037      tgt.setStatusElement(Enumerations10_30.convertConformanceResourceStatus(src.getStatusElement()));
038    if (src.hasExperimental())
039      tgt.setExperimentalElement(Boolean10_30.convertBoolean(src.getExperimentalElement()));
040    if (src.hasPublisherElement())
041      tgt.setPublisherElement(String10_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(DateTime10_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(CodeableConcept10_30.convertCodeableConcept(t.getValueCodeableConcept()));
051    for (org.hl7.fhir.dstu3.model.CodeableConcept t : src.getJurisdiction())
052      tgt.addUseContext(CodeableConcept10_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(ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().convertType(src.getSource()));
059    if (src.hasTarget())
060      tgt.setTarget(ConversionContext10_30.INSTANCE.getVersionConvertor_10_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.dstu2.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    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyDomainResource(src, tgt);
072    if (src.hasUrlElement())
073      tgt.setUrlElement(Uri10_30.convertUri(src.getUrlElement()));
074    if (src.hasIdentifier())
075      tgt.setIdentifier(Identifier10_30.convertIdentifier(src.getIdentifier()));
076    if (src.hasVersionElement())
077      tgt.setVersionElement(String10_30.convertString(src.getVersionElement()));
078    if (src.hasNameElement())
079      tgt.setNameElement(String10_30.convertString(src.getNameElement()));
080    if (src.hasStatus())
081      tgt.setStatusElement(Enumerations10_30.convertConformanceResourceStatus(src.getStatusElement()));
082    if (src.hasExperimental())
083      tgt.setExperimentalElement(Boolean10_30.convertBoolean(src.getExperimentalElement()));
084    if (src.hasPublisherElement())
085      tgt.setPublisherElement(String10_30.convertString(src.getPublisherElement()));
086    for (org.hl7.fhir.dstu2.model.ConceptMap.ConceptMapContactComponent t : src.getContact())
087      tgt.addContact(convertConceptMapContactComponent(t));
088    if (src.hasDate())
089      tgt.setDateElement(DateTime10_30.convertDateTime(src.getDateElement()));
090    if (src.hasDescription())
091      tgt.setDescription(src.getDescription());
092    for (org.hl7.fhir.dstu2.model.CodeableConcept t : src.getUseContext())
093      if (VersionConvertor_10_30.isJurisdiction(t))
094        tgt.addJurisdiction(CodeableConcept10_30.convertCodeableConcept(t));
095      else
096        tgt.addUseContext(CodeableConcept10_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(ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().convertType(src.getSource()));
103    if (src.hasTarget())
104      tgt.setTarget(ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().convertType(src.getTarget()));
105    for (org.hl7.fhir.dstu2.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.dstu3.model.ContactDetail convertConceptMapContactComponent(org.hl7.fhir.dstu2.model.ConceptMap.ConceptMapContactComponent src) throws FHIRException {
114    if (src == null || src.isEmpty())
115      return null;
116    org.hl7.fhir.dstu3.model.ContactDetail tgt = new org.hl7.fhir.dstu3.model.ContactDetail();
117    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt);
118    if (src.hasNameElement())
119      tgt.setNameElement(String10_30.convertString(src.getNameElement()));
120    for (org.hl7.fhir.dstu2.model.ContactPoint t : src.getTelecom())
121      tgt.addTelecom(ContactPoint10_30.convertContactPoint(t));
122    return tgt;
123  }
124
125  public static org.hl7.fhir.dstu2.model.ConceptMap.ConceptMapContactComponent convertConceptMapContactComponent(org.hl7.fhir.dstu3.model.ContactDetail src) throws FHIRException {
126    if (src == null || src.isEmpty())
127      return null;
128    org.hl7.fhir.dstu2.model.ConceptMap.ConceptMapContactComponent tgt = new org.hl7.fhir.dstu2.model.ConceptMap.ConceptMapContactComponent();
129    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt);
130    if (src.hasNameElement())
131      tgt.setNameElement(String10_30.convertString(src.getNameElement()));
132    for (org.hl7.fhir.dstu3.model.ContactPoint t : src.getTelecom())
133      tgt.addTelecom(ContactPoint10_30.convertContactPoint(t));
134    return tgt;
135  }
136
137  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 {
138    if (src == null || src.isEmpty())
139      return null;
140    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());
141    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt);
142    switch (src.getValue()) {
143      case EQUIVALENT:
144        tgt.setValue(org.hl7.fhir.dstu3.model.Enumerations.ConceptMapEquivalence.EQUIVALENT);
145        break;
146      case EQUAL:
147        tgt.setValue(org.hl7.fhir.dstu3.model.Enumerations.ConceptMapEquivalence.EQUAL);
148        break;
149      case WIDER:
150        tgt.setValue(org.hl7.fhir.dstu3.model.Enumerations.ConceptMapEquivalence.WIDER);
151        break;
152      case SUBSUMES:
153        tgt.setValue(org.hl7.fhir.dstu3.model.Enumerations.ConceptMapEquivalence.SUBSUMES);
154        break;
155      case NARROWER:
156        tgt.setValue(org.hl7.fhir.dstu3.model.Enumerations.ConceptMapEquivalence.NARROWER);
157        break;
158      case SPECIALIZES:
159        tgt.setValue(org.hl7.fhir.dstu3.model.Enumerations.ConceptMapEquivalence.SPECIALIZES);
160        break;
161      case INEXACT:
162        tgt.setValue(org.hl7.fhir.dstu3.model.Enumerations.ConceptMapEquivalence.INEXACT);
163        break;
164      case UNMATCHED:
165        tgt.setValue(org.hl7.fhir.dstu3.model.Enumerations.ConceptMapEquivalence.UNMATCHED);
166        break;
167      case DISJOINT:
168        tgt.setValue(org.hl7.fhir.dstu3.model.Enumerations.ConceptMapEquivalence.DISJOINT);
169        break;
170      default:
171        tgt.setValue(org.hl7.fhir.dstu3.model.Enumerations.ConceptMapEquivalence.NULL);
172        break;
173    }
174    return tgt;
175  }
176
177  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 {
178    if (src == null || src.isEmpty())
179      return null;
180    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());
181    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt);
182    switch (src.getValue()) {
183      case EQUIVALENT:
184        tgt.setValue(org.hl7.fhir.dstu2.model.Enumerations.ConceptMapEquivalence.EQUIVALENT);
185        break;
186      case EQUAL:
187        tgt.setValue(org.hl7.fhir.dstu2.model.Enumerations.ConceptMapEquivalence.EQUAL);
188        break;
189      case WIDER:
190        tgt.setValue(org.hl7.fhir.dstu2.model.Enumerations.ConceptMapEquivalence.WIDER);
191        break;
192      case SUBSUMES:
193        tgt.setValue(org.hl7.fhir.dstu2.model.Enumerations.ConceptMapEquivalence.SUBSUMES);
194        break;
195      case NARROWER:
196        tgt.setValue(org.hl7.fhir.dstu2.model.Enumerations.ConceptMapEquivalence.NARROWER);
197        break;
198      case SPECIALIZES:
199        tgt.setValue(org.hl7.fhir.dstu2.model.Enumerations.ConceptMapEquivalence.SPECIALIZES);
200        break;
201      case INEXACT:
202        tgt.setValue(org.hl7.fhir.dstu2.model.Enumerations.ConceptMapEquivalence.INEXACT);
203        break;
204      case UNMATCHED:
205        tgt.setValue(org.hl7.fhir.dstu2.model.Enumerations.ConceptMapEquivalence.UNMATCHED);
206        break;
207      case DISJOINT:
208        tgt.setValue(org.hl7.fhir.dstu2.model.Enumerations.ConceptMapEquivalence.DISJOINT);
209        break;
210      default:
211        tgt.setValue(org.hl7.fhir.dstu2.model.Enumerations.ConceptMapEquivalence.NULL);
212        break;
213    }
214    return tgt;
215  }
216
217  public static org.hl7.fhir.dstu3.model.ConceptMap.OtherElementComponent convertOtherElementComponent(org.hl7.fhir.dstu2.model.ConceptMap.OtherElementComponent src) throws FHIRException {
218    if (src == null || src.isEmpty())
219      return null;
220    org.hl7.fhir.dstu3.model.ConceptMap.OtherElementComponent tgt = new org.hl7.fhir.dstu3.model.ConceptMap.OtherElementComponent();
221    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyBackboneElement(src,tgt);
222    if (src.hasElementElement())
223      tgt.setPropertyElement(Uri10_30.convertUri(src.getElementElement()));
224    if (src.hasCodeSystemElement())
225      tgt.setSystemElement(Uri10_30.convertUri(src.getCodeSystemElement()));
226    if (src.hasCodeElement())
227      tgt.setCodeElement(String10_30.convertString(src.getCodeElement()));
228    return tgt;
229  }
230
231  public static org.hl7.fhir.dstu2.model.ConceptMap.OtherElementComponent convertOtherElementComponent(org.hl7.fhir.dstu3.model.ConceptMap.OtherElementComponent src) throws FHIRException {
232    if (src == null || src.isEmpty())
233      return null;
234    org.hl7.fhir.dstu2.model.ConceptMap.OtherElementComponent tgt = new org.hl7.fhir.dstu2.model.ConceptMap.OtherElementComponent();
235    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyBackboneElement(src,tgt);
236    if (src.hasPropertyElement())
237      tgt.setElementElement(Uri10_30.convertUri(src.getPropertyElement()));
238    if (src.hasSystemElement())
239      tgt.setCodeSystemElement(Uri10_30.convertUri(src.getSystemElement()));
240    if (src.hasCodeElement())
241      tgt.setCodeElement(String10_30.convertString(src.getCodeElement()));
242    return tgt;
243  }
244
245  public static List<SourceElementComponentWrapper<ConceptMap.SourceElementComponent>> convertSourceElementComponent(org.hl7.fhir.dstu2.model.ConceptMap.SourceElementComponent src) throws FHIRException {
246    List<SourceElementComponentWrapper<ConceptMap.SourceElementComponent>> res = new ArrayList<>();
247    if (src == null || src.isEmpty())
248      return res;
249    for (org.hl7.fhir.dstu2.model.ConceptMap.TargetElementComponent t : src.getTarget()) {
250      org.hl7.fhir.dstu3.model.ConceptMap.SourceElementComponent tgt = new org.hl7.fhir.dstu3.model.ConceptMap.SourceElementComponent();
251      ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyBackboneElement(src,tgt);
252      tgt.setCode(src.getCode());
253      tgt.addTarget(convertTargetElementComponent(t));
254      res.add(new SourceElementComponentWrapper<>(tgt, src.getCodeSystem(), t.getCodeSystem()));
255    }
256    return res;
257  }
258
259  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 {
260    if (src == null || src.isEmpty())
261      return null;
262    org.hl7.fhir.dstu2.model.ConceptMap.SourceElementComponent tgt = new org.hl7.fhir.dstu2.model.ConceptMap.SourceElementComponent();
263    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyBackboneElement(src,tgt);
264    tgt.setCodeSystem(g.getSource());
265    if (src.hasCodeElement())
266      tgt.setCodeElement(Code10_30.convertCode(src.getCodeElement()));
267    for (org.hl7.fhir.dstu3.model.ConceptMap.TargetElementComponent t : src.getTarget())
268      tgt.addTarget(convertTargetElementComponent(t, g));
269    return tgt;
270  }
271
272  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 {
273    if (src == null || src.isEmpty())
274      return null;
275    org.hl7.fhir.dstu2.model.ConceptMap.TargetElementComponent tgt = new org.hl7.fhir.dstu2.model.ConceptMap.TargetElementComponent();
276    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyBackboneElement(src,tgt);
277    tgt.setCodeSystem(g.getTarget());
278    if (src.hasCodeElement())
279      tgt.setCodeElement(Code10_30.convertCode(src.getCodeElement()));
280    if (src.hasEquivalence())
281      tgt.setEquivalenceElement(convertConceptMapEquivalence(src.getEquivalenceElement()));
282    if (src.hasCommentElement())
283      tgt.setCommentsElement(String10_30.convertString(src.getCommentElement()));
284    for (org.hl7.fhir.dstu3.model.ConceptMap.OtherElementComponent t : src.getDependsOn())
285      tgt.addDependsOn(convertOtherElementComponent(t));
286    for (org.hl7.fhir.dstu3.model.ConceptMap.OtherElementComponent t : src.getProduct())
287      tgt.addProduct(convertOtherElementComponent(t));
288    return tgt;
289  }
290
291  public static org.hl7.fhir.dstu3.model.ConceptMap.TargetElementComponent convertTargetElementComponent(org.hl7.fhir.dstu2.model.ConceptMap.TargetElementComponent src) throws FHIRException {
292    if (src == null || src.isEmpty())
293      return null;
294    org.hl7.fhir.dstu3.model.ConceptMap.TargetElementComponent tgt = new org.hl7.fhir.dstu3.model.ConceptMap.TargetElementComponent();
295    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyBackboneElement(src,tgt);
296    if (src.hasCodeElement())
297      tgt.setCodeElement(Code10_30.convertCode(src.getCodeElement()));
298    if (src.hasEquivalence())
299      tgt.setEquivalenceElement(convertConceptMapEquivalence(src.getEquivalenceElement()));
300    if (src.hasCommentsElement())
301      tgt.setCommentElement(String10_30.convertString(src.getCommentsElement()));
302    for (org.hl7.fhir.dstu2.model.ConceptMap.OtherElementComponent t : src.getDependsOn())
303      tgt.addDependsOn(convertOtherElementComponent(t));
304    for (org.hl7.fhir.dstu2.model.ConceptMap.OtherElementComponent t : src.getProduct())
305      tgt.addProduct(convertOtherElementComponent(t));
306    return tgt;
307  }
308
309  static public ConceptMapGroupComponent getGroup(ConceptMap map, String srcs, String tgts) {
310    for (ConceptMapGroupComponent grp : map.getGroup()) {
311      if (grp.getSource().equals(srcs) && grp.getTarget().equals(tgts))
312        return grp;
313    }
314    ConceptMapGroupComponent grp = map.addGroup();
315    grp.setSource(srcs);
316    grp.setTarget(tgts);
317    return grp;
318  }
319}