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