001package org.hl7.fhir.convertors.conv10_40.resources10_40;
002
003import org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_10_40;
004import org.hl7.fhir.convertors.context.ConversionContext10_40;
005import org.hl7.fhir.convertors.conv10_40.VersionConvertor_10_40;
006import org.hl7.fhir.convertors.conv10_40.datatypes10_40.complextypes10_40.CodeableConcept10_40;
007import org.hl7.fhir.convertors.conv10_40.datatypes10_40.complextypes10_40.Coding10_40;
008import org.hl7.fhir.convertors.conv10_40.datatypes10_40.complextypes10_40.ContactPoint10_40;
009import org.hl7.fhir.convertors.conv10_40.datatypes10_40.complextypes10_40.Identifier10_40;
010import org.hl7.fhir.convertors.conv10_40.datatypes10_40.primitivetypes10_40.*;
011import org.hl7.fhir.dstu2.model.ValueSet;
012import org.hl7.fhir.exceptions.FHIRException;
013import org.hl7.fhir.r4.model.BooleanType;
014import org.hl7.fhir.r4.model.CodeSystem;
015import org.hl7.fhir.r4.model.CodeSystem.CodeSystemContentMode;
016import org.hl7.fhir.r4.model.CodeSystem.ConceptDefinitionComponent;
017import org.hl7.fhir.r4.terminologies.CodeSystemUtilities;
018
019import java.util.List;
020
021public class ValueSet10_40 {
022
023  public static org.hl7.fhir.r4.model.ValueSet.ConceptReferenceComponent convertConceptReferenceComponent(org.hl7.fhir.dstu2.model.ValueSet.ConceptReferenceComponent src) throws FHIRException {
024    if (src == null || src.isEmpty())
025      return null;
026    org.hl7.fhir.r4.model.ValueSet.ConceptReferenceComponent tgt = new org.hl7.fhir.r4.model.ValueSet.ConceptReferenceComponent();
027    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt);
028    if (src.hasCodeElement())
029      tgt.setCodeElement(Code10_40.convertCode(src.getCodeElement()));
030    if (src.hasDisplayElement())
031      tgt.setDisplayElement(String10_40.convertString(src.getDisplayElement()));
032    for (org.hl7.fhir.dstu2.model.ValueSet.ConceptDefinitionDesignationComponent t : src.getDesignation())
033      tgt.addDesignation(convertConceptReferenceDesignationComponent(t));
034    return tgt;
035  }
036
037  public static org.hl7.fhir.dstu2.model.ValueSet.ConceptReferenceComponent convertConceptReferenceComponent(org.hl7.fhir.r4.model.ValueSet.ConceptReferenceComponent src) throws FHIRException {
038    if (src == null || src.isEmpty())
039      return null;
040    org.hl7.fhir.dstu2.model.ValueSet.ConceptReferenceComponent tgt = new org.hl7.fhir.dstu2.model.ValueSet.ConceptReferenceComponent();
041    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt);
042    if (src.hasCodeElement())
043      tgt.setCodeElement(Code10_40.convertCode(src.getCodeElement()));
044    if (src.hasDisplayElement())
045      tgt.setDisplayElement(String10_40.convertString(src.getDisplayElement()));
046    for (org.hl7.fhir.r4.model.ValueSet.ConceptReferenceDesignationComponent t : src.getDesignation())
047      tgt.addDesignation(convertConceptReferenceDesignationComponent(t));
048    return tgt;
049  }
050
051  public static org.hl7.fhir.r4.model.ValueSet.ConceptReferenceDesignationComponent convertConceptReferenceDesignationComponent(org.hl7.fhir.dstu2.model.ValueSet.ConceptDefinitionDesignationComponent src) throws FHIRException {
052    if (src == null || src.isEmpty())
053      return null;
054    org.hl7.fhir.r4.model.ValueSet.ConceptReferenceDesignationComponent tgt = new org.hl7.fhir.r4.model.ValueSet.ConceptReferenceDesignationComponent();
055    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt);
056    if (src.hasLanguageElement())
057      tgt.setLanguageElement(Code10_40.convertCode(src.getLanguageElement()));
058    if (src.hasUse())
059      tgt.setUse(Coding10_40.convertCoding(src.getUse()));
060    if (src.hasValueElement())
061      tgt.setValueElement(String10_40.convertString(src.getValueElement()));
062    return tgt;
063  }
064
065  public static org.hl7.fhir.dstu2.model.ValueSet.ConceptDefinitionDesignationComponent convertConceptReferenceDesignationComponent(org.hl7.fhir.r4.model.ValueSet.ConceptReferenceDesignationComponent src) throws FHIRException {
066    if (src == null || src.isEmpty())
067      return null;
068    org.hl7.fhir.dstu2.model.ValueSet.ConceptDefinitionDesignationComponent tgt = new org.hl7.fhir.dstu2.model.ValueSet.ConceptDefinitionDesignationComponent();
069    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt);
070    if (src.hasLanguageElement())
071      tgt.setLanguageElement(Code10_40.convertCode(src.getLanguageElement()));
072    if (src.hasUse())
073      tgt.setUse(Coding10_40.convertCoding(src.getUse()));
074    if (src.hasValueElement())
075      tgt.setValueElement(String10_40.convertString(src.getValueElement()));
076    return tgt;
077  }
078
079  public static org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent convertConceptSetComponent(org.hl7.fhir.dstu2.model.ValueSet.ConceptSetComponent src) throws FHIRException {
080    if (src == null || src.isEmpty())
081      return null;
082    org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent tgt = new org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent();
083    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt);
084    if (src.hasSystemElement())
085      tgt.setSystemElement(Uri10_40.convertUri(src.getSystemElement()));
086    if (src.hasVersionElement())
087      tgt.setVersionElement(String10_40.convertString(src.getVersionElement()));
088    for (org.hl7.fhir.dstu2.model.ValueSet.ConceptReferenceComponent t : src.getConcept())
089      tgt.addConcept(convertConceptReferenceComponent(t));
090    for (org.hl7.fhir.dstu2.model.ValueSet.ConceptSetFilterComponent t : src.getFilter())
091      tgt.addFilter(convertConceptSetFilterComponent(t));
092    return tgt;
093  }
094
095  public static org.hl7.fhir.dstu2.model.ValueSet.ConceptSetComponent convertConceptSetComponent(org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent src) throws FHIRException {
096    if (src == null || src.isEmpty())
097      return null;
098    org.hl7.fhir.dstu2.model.ValueSet.ConceptSetComponent tgt = new org.hl7.fhir.dstu2.model.ValueSet.ConceptSetComponent();
099    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt);
100    if (src.hasSystemElement())
101      tgt.setSystemElement(Uri10_40.convertUri(src.getSystemElement()));
102    if (src.hasVersionElement())
103      tgt.setVersionElement(String10_40.convertString(src.getVersionElement()));
104    for (org.hl7.fhir.r4.model.ValueSet.ConceptReferenceComponent t : src.getConcept())
105      tgt.addConcept(convertConceptReferenceComponent(t));
106    for (org.hl7.fhir.r4.model.ValueSet.ConceptSetFilterComponent t : src.getFilter())
107      tgt.addFilter(convertConceptSetFilterComponent(t));
108    return tgt;
109  }
110
111  public static org.hl7.fhir.dstu2.model.ValueSet.ConceptSetFilterComponent convertConceptSetFilterComponent(org.hl7.fhir.r4.model.ValueSet.ConceptSetFilterComponent src) throws FHIRException {
112    if (src == null || src.isEmpty())
113      return null;
114    org.hl7.fhir.dstu2.model.ValueSet.ConceptSetFilterComponent tgt = new org.hl7.fhir.dstu2.model.ValueSet.ConceptSetFilterComponent();
115    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt);
116    if (src.hasPropertyElement())
117      tgt.setPropertyElement(Code10_40.convertCode(src.getPropertyElement()));
118    if (src.hasOp())
119      tgt.setOpElement(convertFilterOperator(src.getOpElement()));
120    if (src.hasValue())
121      tgt.setValue(src.getValue());
122    return tgt;
123  }
124
125  public static org.hl7.fhir.r4.model.ValueSet.ConceptSetFilterComponent convertConceptSetFilterComponent(org.hl7.fhir.dstu2.model.ValueSet.ConceptSetFilterComponent src) throws FHIRException {
126    if (src == null || src.isEmpty())
127      return null;
128    org.hl7.fhir.r4.model.ValueSet.ConceptSetFilterComponent tgt = new org.hl7.fhir.r4.model.ValueSet.ConceptSetFilterComponent();
129    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt);
130    if (src.hasPropertyElement())
131      tgt.setPropertyElement(Code10_40.convertCode(src.getPropertyElement()));
132    if (src.hasOp())
133      tgt.setOpElement(convertFilterOperator(src.getOpElement()));
134    if (src.hasValue())
135      tgt.setValue(src.getValue());
136    return tgt;
137  }
138
139  static public org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.ValueSet.FilterOperator> convertFilterOperator(org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.ValueSet.FilterOperator> src) throws FHIRException {
140    if (src == null || src.isEmpty())
141      return null;
142    org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.ValueSet.FilterOperator> tgt = new org.hl7.fhir.r4.model.Enumeration<>(new org.hl7.fhir.r4.model.ValueSet.FilterOperatorEnumFactory());
143    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt);
144    switch (src.getValue()) {
145      case EQUAL:
146        tgt.setValue(org.hl7.fhir.r4.model.ValueSet.FilterOperator.EQUAL);
147        break;
148      case ISA:
149        tgt.setValue(org.hl7.fhir.r4.model.ValueSet.FilterOperator.ISA);
150        break;
151      case ISNOTA:
152        tgt.setValue(org.hl7.fhir.r4.model.ValueSet.FilterOperator.ISNOTA);
153        break;
154      case REGEX:
155        tgt.setValue(org.hl7.fhir.r4.model.ValueSet.FilterOperator.REGEX);
156        break;
157      case IN:
158        tgt.setValue(org.hl7.fhir.r4.model.ValueSet.FilterOperator.IN);
159        break;
160      case NOTIN:
161        tgt.setValue(org.hl7.fhir.r4.model.ValueSet.FilterOperator.NOTIN);
162        break;
163      default:
164        tgt.setValue(org.hl7.fhir.r4.model.ValueSet.FilterOperator.NULL);
165        break;
166    }
167    return tgt;
168  }
169
170  static public org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.ValueSet.FilterOperator> convertFilterOperator(org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.ValueSet.FilterOperator> src) throws FHIRException {
171    if (src == null || src.isEmpty())
172      return null;
173    org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.ValueSet.FilterOperator> tgt = new org.hl7.fhir.dstu2.model.Enumeration<>(new org.hl7.fhir.dstu2.model.ValueSet.FilterOperatorEnumFactory());
174    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt);
175    switch (src.getValue()) {
176      case EQUAL:
177        tgt.setValue(org.hl7.fhir.dstu2.model.ValueSet.FilterOperator.EQUAL);
178        break;
179      case ISA:
180        tgt.setValue(org.hl7.fhir.dstu2.model.ValueSet.FilterOperator.ISA);
181        break;
182      case ISNOTA:
183        tgt.setValue(org.hl7.fhir.dstu2.model.ValueSet.FilterOperator.ISNOTA);
184        break;
185      case REGEX:
186        tgt.setValue(org.hl7.fhir.dstu2.model.ValueSet.FilterOperator.REGEX);
187        break;
188      case IN:
189        tgt.setValue(org.hl7.fhir.dstu2.model.ValueSet.FilterOperator.IN);
190        break;
191      case NOTIN:
192        tgt.setValue(org.hl7.fhir.dstu2.model.ValueSet.FilterOperator.NOTIN);
193        break;
194      default:
195        tgt.setValue(org.hl7.fhir.dstu2.model.ValueSet.FilterOperator.NULL);
196        break;
197    }
198    return tgt;
199  }
200
201  public static org.hl7.fhir.r4.model.ValueSet convertValueSet(org.hl7.fhir.dstu2.model.ValueSet src) throws FHIRException {
202    return convertValueSet(src, null);
203  }
204
205  public static org.hl7.fhir.r4.model.ValueSet convertValueSet(org.hl7.fhir.dstu2.model.ValueSet src, BaseAdvisor_10_40 advisor) throws FHIRException {
206    if (src == null || src.isEmpty())
207      return null;
208    org.hl7.fhir.r4.model.ValueSet tgt = new org.hl7.fhir.r4.model.ValueSet();
209    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyDomainResource(src, tgt);
210    if (src.hasUrlElement())
211      tgt.setUrlElement(Uri10_40.convertUri(src.getUrlElement()));
212    if (src.hasIdentifier())
213      tgt.addIdentifier(Identifier10_40.convertIdentifier(src.getIdentifier()));
214    if (src.hasVersionElement())
215      tgt.setVersionElement(String10_40.convertString(src.getVersionElement()));
216    if (src.hasNameElement())
217      tgt.setNameElement(String10_40.convertString(src.getNameElement()));
218    if (src.hasStatus())
219      tgt.setStatusElement(Enumerations10_40.convertConformanceResourceStatus(src.getStatusElement()));
220    if (src.hasExperimental())
221      tgt.setExperimentalElement(Boolean10_40.convertBoolean(src.getExperimentalElement()));
222    if (src.hasPublisherElement())
223      tgt.setPublisherElement(String10_40.convertString(src.getPublisherElement()));
224    for (org.hl7.fhir.dstu2.model.ValueSet.ValueSetContactComponent t : src.getContact())
225      tgt.addContact(convertValueSetContactComponent(t));
226    if (src.hasDate())
227      tgt.setDateElement(DateTime10_40.convertDateTime(src.getDateElement()));
228    if (src.hasDescription())
229      tgt.setDescription(src.getDescription());
230    for (org.hl7.fhir.dstu2.model.CodeableConcept t : src.getUseContext())
231      if (VersionConvertor_10_40.isJurisdiction(t))
232        tgt.addJurisdiction(CodeableConcept10_40.convertCodeableConcept(t));
233      else
234        tgt.addUseContext(CodeableConcept10_40.convertCodeableConceptToUsageContext(t));
235    if (src.hasImmutableElement())
236      tgt.setImmutableElement(Boolean10_40.convertBoolean(src.getImmutableElement()));
237    if (src.hasRequirements())
238      tgt.setPurpose(src.getRequirements());
239    if (src.hasCopyright())
240      tgt.setCopyright(src.getCopyright());
241    if (src.hasExtensible())
242      tgt.addExtension("http://hl7.org/fhir/StructureDefinition/valueset-extensible", new BooleanType(src.getExtensible()));
243    if (src.hasCompose()) {
244      if (src.hasCompose())
245        tgt.setCompose(convertValueSetComposeComponent(src.getCompose()));
246      tgt.getCompose().setLockedDate(src.getLockedDate());
247    }
248    if (src.hasCodeSystem() && advisor != null) {
249      org.hl7.fhir.r4.model.CodeSystem tgtcs = new org.hl7.fhir.r4.model.CodeSystem();
250      ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyDomainResource(src, tgtcs);
251      tgtcs.setUrl(src.getCodeSystem().getSystem());
252      tgtcs.addIdentifier(Identifier10_40.convertIdentifier(src.getIdentifier()));
253      tgtcs.setVersion(src.getCodeSystem().getVersion());
254      tgtcs.setName(src.getName() + " Code System");
255      tgtcs.setStatusElement(Enumerations10_40.convertConformanceResourceStatus(src.getStatusElement()));
256      if (src.hasExperimental())
257        tgtcs.setExperimental(src.getExperimental());
258      tgtcs.setPublisher(src.getPublisher());
259      for (org.hl7.fhir.dstu2.model.ValueSet.ValueSetContactComponent t : src.getContact())
260        tgtcs.addContact(convertValueSetContactComponent(t));
261      if (src.hasDate())
262        tgtcs.setDate(src.getDate());
263      tgtcs.setDescription(src.getDescription());
264      for (org.hl7.fhir.dstu2.model.CodeableConcept t : src.getUseContext())
265        if (VersionConvertor_10_40.isJurisdiction(t))
266          tgtcs.addJurisdiction(CodeableConcept10_40.convertCodeableConcept(t));
267        else
268          tgtcs.addUseContext(CodeableConcept10_40.convertCodeableConceptToUsageContext(t));
269      tgtcs.setPurpose(src.getRequirements());
270      tgtcs.setCopyright(src.getCopyright());
271      tgtcs.setContent(CodeSystemContentMode.COMPLETE);
272      tgtcs.setCaseSensitive(src.getCodeSystem().getCaseSensitive());
273      for (org.hl7.fhir.dstu2.model.ValueSet.ConceptDefinitionComponent cs : src.getCodeSystem().getConcept())
274        processConcept(tgtcs.getConcept(), cs, tgtcs);
275      advisor.handleCodeSystem(tgtcs, tgt);
276      tgt.setUserData("r2-cs", tgtcs);
277      tgt.getCompose().addInclude().setSystem(tgtcs.getUrl());
278    }
279    if (src.hasExpansion())
280      tgt.setExpansion(convertValueSetExpansionComponent(src.getExpansion()));
281    return tgt;
282  }
283
284  public static org.hl7.fhir.dstu2.model.ValueSet convertValueSet(org.hl7.fhir.r4.model.ValueSet src, BaseAdvisor_10_40 advisor) throws FHIRException {
285    if (src == null || src.isEmpty())
286      return null;
287    org.hl7.fhir.dstu2.model.ValueSet tgt = new org.hl7.fhir.dstu2.model.ValueSet();
288    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyDomainResource(src, tgt);
289    if (src.hasUrlElement())
290      tgt.setUrlElement(Uri10_40.convertUri(src.getUrlElement()));
291    for (org.hl7.fhir.r4.model.Identifier i : src.getIdentifier())
292      tgt.setIdentifier(Identifier10_40.convertIdentifier(i));
293    if (src.hasVersionElement())
294      tgt.setVersionElement(String10_40.convertString(src.getVersionElement()));
295    if (src.hasNameElement())
296      tgt.setNameElement(String10_40.convertString(src.getNameElement()));
297    if (src.hasStatus())
298      tgt.setStatusElement(Enumerations10_40.convertConformanceResourceStatus(src.getStatusElement()));
299    if (src.hasExperimental())
300      tgt.setExperimentalElement(Boolean10_40.convertBoolean(src.getExperimentalElement()));
301    if (src.hasPublisherElement())
302      tgt.setPublisherElement(String10_40.convertString(src.getPublisherElement()));
303    for (org.hl7.fhir.r4.model.ContactDetail t : src.getContact()) tgt.addContact(convertValueSetContactComponent(t));
304    if (src.hasDate())
305      tgt.setDateElement(DateTime10_40.convertDateTime(src.getDateElement()));
306    tgt.setLockedDate(src.getCompose().getLockedDate());
307    if (src.hasDescription())
308      tgt.setDescription(src.getDescription());
309    for (org.hl7.fhir.r4.model.UsageContext t : src.getUseContext())
310      if (t.hasValueCodeableConcept())
311        tgt.addUseContext(CodeableConcept10_40.convertCodeableConcept(t.getValueCodeableConcept()));
312    for (org.hl7.fhir.r4.model.CodeableConcept t : src.getJurisdiction())
313      tgt.addUseContext(CodeableConcept10_40.convertCodeableConcept(t));
314    if (src.hasImmutableElement())
315      tgt.setImmutableElement(Boolean10_40.convertBoolean(src.getImmutableElement()));
316    if (src.hasPurpose())
317      tgt.setRequirements(src.getPurpose());
318    if (src.hasCopyright())
319      tgt.setCopyright(src.getCopyright());
320    if (src.hasExtension("http://hl7.org/fhir/StructureDefinition/valueset-extensible"))
321      tgt.setExtensible(((BooleanType) src.getExtensionByUrl("http://hl7.org/fhir/StructureDefinition/valueset-extensible").getValue()).booleanValue());
322    org.hl7.fhir.r4.model.CodeSystem srcCS = (CodeSystem) src.getUserData("r2-cs");
323    if (srcCS == null)
324      srcCS = advisor.getCodeSystem(src);
325    if (srcCS != null) {
326      tgt.getCodeSystem().setSystem(srcCS.getUrl());
327      tgt.getCodeSystem().setVersion(srcCS.getVersion());
328      tgt.getCodeSystem().setCaseSensitive(srcCS.getCaseSensitive());
329      for (org.hl7.fhir.r4.model.CodeSystem.ConceptDefinitionComponent cs : srcCS.getConcept())
330        processConcept(tgt.getCodeSystem().getConcept(), cs, srcCS);
331    }
332    if (src.hasCompose())
333      tgt.setCompose(convertValueSetComposeComponent(src.getCompose(), srcCS == null ? null : srcCS.getUrl()));
334    if (src.hasExpansion())
335      tgt.setExpansion(convertValueSetExpansionComponent(src.getExpansion()));
336    return tgt;
337  }
338
339  public static org.hl7.fhir.dstu2.model.ValueSet convertValueSet(org.hl7.fhir.r4.model.ValueSet src) throws FHIRException {
340    return convertValueSet(src, null);
341  }
342
343  public static org.hl7.fhir.dstu2.model.ValueSet.ValueSetComposeComponent convertValueSetComposeComponent(org.hl7.fhir.r4.model.ValueSet.ValueSetComposeComponent src, String noSystem) throws FHIRException {
344    if (src == null || src.isEmpty())
345      return null;
346    org.hl7.fhir.dstu2.model.ValueSet.ValueSetComposeComponent tgt = new org.hl7.fhir.dstu2.model.ValueSet.ValueSetComposeComponent();
347    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt);
348    for (org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent t : src.getInclude()) {
349      for (org.hl7.fhir.r4.model.UriType ti : t.getValueSet()) tgt.addImport(ti.getValue());
350      if (noSystem == null || !t.getSystem().equals(noSystem))
351        tgt.addInclude(convertConceptSetComponent(t));
352    }
353    for (org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent t : src.getExclude())
354      tgt.addExclude(convertConceptSetComponent(t));
355    return tgt;
356  }
357
358  public static org.hl7.fhir.r4.model.ValueSet.ValueSetComposeComponent convertValueSetComposeComponent(org.hl7.fhir.dstu2.model.ValueSet.ValueSetComposeComponent src) throws FHIRException {
359    if (src == null || src.isEmpty())
360      return null;
361    org.hl7.fhir.r4.model.ValueSet.ValueSetComposeComponent tgt = new org.hl7.fhir.r4.model.ValueSet.ValueSetComposeComponent();
362    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt);
363    for (org.hl7.fhir.dstu2.model.UriType t : src.getImport()) tgt.addInclude().addValueSet(t.getValue());
364    for (org.hl7.fhir.dstu2.model.ValueSet.ConceptSetComponent t : src.getInclude())
365      tgt.addInclude(convertConceptSetComponent(t));
366    for (org.hl7.fhir.dstu2.model.ValueSet.ConceptSetComponent t : src.getExclude())
367      tgt.addExclude(convertConceptSetComponent(t));
368    return tgt;
369  }
370
371  public static org.hl7.fhir.r4.model.ContactDetail convertValueSetContactComponent(org.hl7.fhir.dstu2.model.ValueSet.ValueSetContactComponent src) throws FHIRException {
372    if (src == null || src.isEmpty())
373      return null;
374    org.hl7.fhir.r4.model.ContactDetail tgt = new org.hl7.fhir.r4.model.ContactDetail();
375    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt);
376    if (src.hasNameElement())
377      tgt.setNameElement(String10_40.convertString(src.getNameElement()));
378    for (org.hl7.fhir.dstu2.model.ContactPoint t : src.getTelecom())
379      tgt.addTelecom(ContactPoint10_40.convertContactPoint(t));
380    return tgt;
381  }
382
383  public static org.hl7.fhir.dstu2.model.ValueSet.ValueSetContactComponent convertValueSetContactComponent(org.hl7.fhir.r4.model.ContactDetail src) throws FHIRException {
384    if (src == null || src.isEmpty())
385      return null;
386    org.hl7.fhir.dstu2.model.ValueSet.ValueSetContactComponent tgt = new org.hl7.fhir.dstu2.model.ValueSet.ValueSetContactComponent();
387    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt);
388    if (src.hasNameElement())
389      tgt.setNameElement(String10_40.convertString(src.getNameElement()));
390    for (org.hl7.fhir.r4.model.ContactPoint t : src.getTelecom())
391      tgt.addTelecom(ContactPoint10_40.convertContactPoint(t));
392    return tgt;
393  }
394
395  public static org.hl7.fhir.dstu2.model.ValueSet.ValueSetExpansionComponent convertValueSetExpansionComponent(org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionComponent src) throws FHIRException {
396    if (src == null || src.isEmpty())
397      return null;
398    org.hl7.fhir.dstu2.model.ValueSet.ValueSetExpansionComponent tgt = new org.hl7.fhir.dstu2.model.ValueSet.ValueSetExpansionComponent();
399    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt);
400    if (src.hasIdentifierElement())
401      tgt.setIdentifierElement(Uri10_40.convertUri(src.getIdentifierElement()));
402    if (src.hasTimestampElement())
403      tgt.setTimestampElement(DateTime10_40.convertDateTime(src.getTimestampElement()));
404    if (src.hasTotalElement())
405      tgt.setTotalElement(Integer10_40.convertInteger(src.getTotalElement()));
406    if (src.hasOffsetElement())
407      tgt.setOffsetElement(Integer10_40.convertInteger(src.getOffsetElement()));
408    for (org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionParameterComponent t : src.getParameter())
409      tgt.addParameter(convertValueSetExpansionParameterComponent(t));
410    for (org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionContainsComponent t : src.getContains())
411      tgt.addContains(convertValueSetExpansionContainsComponent(t));
412    return tgt;
413  }
414
415  public static org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionComponent convertValueSetExpansionComponent(org.hl7.fhir.dstu2.model.ValueSet.ValueSetExpansionComponent src) throws FHIRException {
416    if (src == null || src.isEmpty())
417      return null;
418    org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionComponent tgt = new org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionComponent();
419    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt);
420    if (src.hasIdentifierElement())
421      tgt.setIdentifierElement(Uri10_40.convertUri(src.getIdentifierElement()));
422    if (src.hasTimestampElement())
423      tgt.setTimestampElement(DateTime10_40.convertDateTime(src.getTimestampElement()));
424    if (src.hasTotalElement())
425      tgt.setTotalElement(Integer10_40.convertInteger(src.getTotalElement()));
426    if (src.hasOffsetElement())
427      tgt.setOffsetElement(Integer10_40.convertInteger(src.getOffsetElement()));
428    for (org.hl7.fhir.dstu2.model.ValueSet.ValueSetExpansionParameterComponent t : src.getParameter())
429      tgt.addParameter(convertValueSetExpansionParameterComponent(t));
430    for (org.hl7.fhir.dstu2.model.ValueSet.ValueSetExpansionContainsComponent t : src.getContains())
431      tgt.addContains(convertValueSetExpansionContainsComponent(t));
432    return tgt;
433  }
434
435  public static org.hl7.fhir.dstu2.model.ValueSet.ValueSetExpansionContainsComponent convertValueSetExpansionContainsComponent(org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionContainsComponent src) throws FHIRException {
436    if (src == null || src.isEmpty())
437      return null;
438    org.hl7.fhir.dstu2.model.ValueSet.ValueSetExpansionContainsComponent tgt = new org.hl7.fhir.dstu2.model.ValueSet.ValueSetExpansionContainsComponent();
439    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt);
440    if (src.hasSystemElement())
441      tgt.setSystemElement(Uri10_40.convertUri(src.getSystemElement()));
442    if (src.hasAbstractElement())
443      tgt.setAbstractElement(Boolean10_40.convertBoolean(src.getAbstractElement()));
444    if (src.hasVersionElement())
445      tgt.setVersionElement(String10_40.convertString(src.getVersionElement()));
446    if (src.hasCodeElement())
447      tgt.setCodeElement(Code10_40.convertCode(src.getCodeElement()));
448    if (src.hasDisplayElement())
449      tgt.setDisplayElement(String10_40.convertString(src.getDisplayElement()));
450    for (org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionContainsComponent t : src.getContains())
451      tgt.addContains(convertValueSetExpansionContainsComponent(t));
452    return tgt;
453  }
454
455  public static org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionContainsComponent convertValueSetExpansionContainsComponent(org.hl7.fhir.dstu2.model.ValueSet.ValueSetExpansionContainsComponent src) throws FHIRException {
456    if (src == null || src.isEmpty())
457      return null;
458    org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionContainsComponent tgt = new org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionContainsComponent();
459    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt);
460    if (src.hasSystemElement())
461      tgt.setSystemElement(Uri10_40.convertUri(src.getSystemElement()));
462    if (src.hasAbstractElement())
463      tgt.setAbstractElement(Boolean10_40.convertBoolean(src.getAbstractElement()));
464    if (src.hasVersionElement())
465      tgt.setVersionElement(String10_40.convertString(src.getVersionElement()));
466    if (src.hasCodeElement())
467      tgt.setCodeElement(Code10_40.convertCode(src.getCodeElement()));
468    if (src.hasDisplayElement())
469      tgt.setDisplayElement(String10_40.convertString(src.getDisplayElement()));
470    for (org.hl7.fhir.dstu2.model.ValueSet.ValueSetExpansionContainsComponent t : src.getContains())
471      tgt.addContains(convertValueSetExpansionContainsComponent(t));
472    return tgt;
473  }
474
475  public static org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionParameterComponent convertValueSetExpansionParameterComponent(org.hl7.fhir.dstu2.model.ValueSet.ValueSetExpansionParameterComponent src) throws FHIRException {
476    if (src == null || src.isEmpty())
477      return null;
478    org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionParameterComponent tgt = new org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionParameterComponent();
479    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt);
480    if (src.hasNameElement())
481      tgt.setNameElement(String10_40.convertString(src.getNameElement()));
482    if (src.hasValue())
483      tgt.setValue(ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().convertType(src.getValue()));
484    return tgt;
485  }
486
487  public static org.hl7.fhir.dstu2.model.ValueSet.ValueSetExpansionParameterComponent convertValueSetExpansionParameterComponent(org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionParameterComponent src) throws FHIRException {
488    if (src == null || src.isEmpty())
489      return null;
490    org.hl7.fhir.dstu2.model.ValueSet.ValueSetExpansionParameterComponent tgt = new org.hl7.fhir.dstu2.model.ValueSet.ValueSetExpansionParameterComponent();
491    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt);
492    if (src.hasNameElement())
493      tgt.setNameElement(String10_40.convertString(src.getNameElement()));
494    if (src.hasValue())
495      tgt.setValue(ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().convertType(src.getValue()));
496    return tgt;
497  }
498
499  static public void processConcept(List<ConceptDefinitionComponent> concepts, org.hl7.fhir.dstu2.model.ValueSet.ConceptDefinitionComponent cs, CodeSystem tgtcs) throws FHIRException {
500    org.hl7.fhir.r4.model.CodeSystem.ConceptDefinitionComponent ct = new org.hl7.fhir.r4.model.CodeSystem.ConceptDefinitionComponent();
501    concepts.add(ct);
502    ct.setCode(cs.getCode());
503    ct.setDisplay(cs.getDisplay());
504    ct.setDefinition(cs.getDefinition());
505    if (cs.getAbstract())
506      CodeSystemUtilities.setNotSelectable(tgtcs, ct);
507    for (org.hl7.fhir.dstu2.model.ValueSet.ConceptDefinitionDesignationComponent csd : cs.getDesignation()) {
508      org.hl7.fhir.r4.model.CodeSystem.ConceptDefinitionDesignationComponent cst = new org.hl7.fhir.r4.model.CodeSystem.ConceptDefinitionDesignationComponent();
509      cst.setLanguage(csd.getLanguage());
510      cst.setUse(Coding10_40.convertCoding(csd.getUse()));
511      cst.setValue(csd.getValue());
512    }
513    for (org.hl7.fhir.dstu2.model.ValueSet.ConceptDefinitionComponent csc : cs.getConcept())
514      processConcept(ct.getConcept(), csc, tgtcs);
515  }
516
517  static public void processConcept(List<ValueSet.ConceptDefinitionComponent> concepts, ConceptDefinitionComponent cs, CodeSystem srcCS) throws FHIRException {
518    org.hl7.fhir.dstu2.model.ValueSet.ConceptDefinitionComponent ct = new org.hl7.fhir.dstu2.model.ValueSet.ConceptDefinitionComponent();
519    concepts.add(ct);
520    ct.setCode(cs.getCode());
521    ct.setDisplay(cs.getDisplay());
522    ct.setDefinition(cs.getDefinition());
523    if (CodeSystemUtilities.isNotSelectable(srcCS, cs))
524      ct.setAbstract(true);
525    for (org.hl7.fhir.r4.model.CodeSystem.ConceptDefinitionDesignationComponent csd : cs.getDesignation()) {
526      org.hl7.fhir.dstu2.model.ValueSet.ConceptDefinitionDesignationComponent cst = new org.hl7.fhir.dstu2.model.ValueSet.ConceptDefinitionDesignationComponent();
527      cst.setLanguage(csd.getLanguage());
528      cst.setUse(Coding10_40.convertCoding(csd.getUse()));
529      cst.setValue(csd.getValue());
530    }
531    for (ConceptDefinitionComponent csc : cs.getConcept()) processConcept(ct.getConcept(), csc, srcCS);
532  }
533
534  public static ValueSet.ValueSetCodeSystemComponent convertCodeSystem(CodeSystem src) throws FHIRException {
535    if (src == null || src.isEmpty()) return null;
536    ValueSet.ValueSetCodeSystemComponent tgt = new ValueSet.ValueSetCodeSystemComponent();
537    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt);
538    if (src.hasUrlElement()) tgt.setSystemElement(Uri10_40.convertUri(src.getUrlElement()));
539    if (src.hasVersionElement()) tgt.setVersionElement(String10_40.convertString(src.getVersionElement()));
540    if (src.hasCaseSensitiveElement())
541      tgt.setCaseSensitiveElement(Boolean10_40.convertBoolean(src.getCaseSensitiveElement()));
542    for (ConceptDefinitionComponent cc : src.getConcept()) tgt.addConcept(convertCodeSystemConcept(src, cc));
543    return tgt;
544  }
545
546  public static ValueSet.ConceptDefinitionComponent convertCodeSystemConcept(CodeSystem cs, ConceptDefinitionComponent src) throws FHIRException {
547    if (src == null || src.isEmpty()) return null;
548    ValueSet.ConceptDefinitionComponent tgt = new ValueSet.ConceptDefinitionComponent();
549    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt);
550    tgt.setAbstract(CodeSystemUtilities.isNotSelectable(cs, src));
551    tgt.setCode(src.getCode());
552    tgt.setDefinition(src.getDefinition());
553    tgt.setDisplay(src.getDisplay());
554    for (ConceptDefinitionComponent cc : src.getConcept()) tgt.addConcept(convertCodeSystemConcept(cs, cc));
555    for (CodeSystem.ConceptDefinitionDesignationComponent cc : src.getDesignation())
556      tgt.addDesignation(convertCodeSystemDesignation(cc));
557    return tgt;
558  }
559
560  public static ValueSet.ConceptDefinitionDesignationComponent convertCodeSystemDesignation(CodeSystem.ConceptDefinitionDesignationComponent src) throws FHIRException {
561    if (src == null || src.isEmpty()) return null;
562    ValueSet.ConceptDefinitionDesignationComponent tgt = new ValueSet.ConceptDefinitionDesignationComponent();
563    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt);
564    tgt.setUse(Coding10_40.convertCoding(src.getUse()));
565    tgt.setLanguage(src.getLanguage());
566    tgt.setValue(src.getValue());
567    return tgt;
568  }
569}