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