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