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