001package org.hl7.fhir.convertors.conv10_30.resources10_30;
002
003import org.hl7.fhir.convertors.context.ConversionContext10_30;
004import org.hl7.fhir.convertors.conv10_30.datatypes10_30.Reference10_30;
005import org.hl7.fhir.convertors.conv10_30.datatypes10_30.complextypes10_30.Coding10_30;
006import org.hl7.fhir.convertors.conv10_30.datatypes10_30.complextypes10_30.ContactPoint10_30;
007import org.hl7.fhir.convertors.conv10_30.datatypes10_30.complextypes10_30.Identifier10_30;
008import org.hl7.fhir.convertors.conv10_30.datatypes10_30.primitivetypes10_30.Boolean10_30;
009import org.hl7.fhir.convertors.conv10_30.datatypes10_30.primitivetypes10_30.DateTime10_30;
010import org.hl7.fhir.convertors.conv10_30.datatypes10_30.primitivetypes10_30.String10_30;
011import org.hl7.fhir.dstu3.model.ContactDetail;
012import org.hl7.fhir.exceptions.FHIRException;
013
014public class Questionnaire10_30 {
015
016  public static org.hl7.fhir.dstu2.model.Questionnaire convertQuestionnaire(org.hl7.fhir.dstu3.model.Questionnaire src) throws FHIRException {
017    if (src == null || src.isEmpty())
018      return null;
019    org.hl7.fhir.dstu2.model.Questionnaire tgt = new org.hl7.fhir.dstu2.model.Questionnaire();
020    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyDomainResource(src, tgt);
021    for (org.hl7.fhir.dstu3.model.Identifier t : src.getIdentifier())
022      tgt.addIdentifier(Identifier10_30.convertIdentifier(t));
023    if (src.hasVersionElement())
024      tgt.setVersionElement(String10_30.convertString(src.getVersionElement()));
025    if (src.hasStatus())
026      tgt.setStatusElement(convertQuestionnaireStatus(src.getStatusElement()));
027    if (src.hasDate())
028      tgt.setDateElement(DateTime10_30.convertDateTime(src.getDateElement()));
029    if (src.hasPublisherElement())
030      tgt.setPublisherElement(String10_30.convertString(src.getPublisherElement()));
031    for (ContactDetail t : src.getContact())
032      for (org.hl7.fhir.dstu3.model.ContactPoint t1 : t.getTelecom())
033        tgt.addTelecom(ContactPoint10_30.convertContactPoint(t1));
034    org.hl7.fhir.dstu2.model.Questionnaire.GroupComponent root = tgt.getGroup();
035    root.setTitle(src.getTitle());
036    for (org.hl7.fhir.dstu3.model.Coding t : src.getCode()) {
037      root.addConcept(Coding10_30.convertCoding(t));
038    }
039    for (org.hl7.fhir.dstu3.model.CodeType t : src.getSubjectType()) tgt.addSubjectType(t.getValue());
040    for (org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemComponent t : src.getItem())
041      if (t.getType() == org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemType.GROUP)
042        root.addGroup(convertQuestionnaireGroupComponent(t));
043      else
044        root.addQuestion(convertQuestionnaireQuestionComponent(t));
045    return tgt;
046  }
047
048  public static org.hl7.fhir.dstu3.model.Questionnaire convertQuestionnaire(org.hl7.fhir.dstu2.model.Questionnaire src) throws FHIRException {
049    if (src == null || src.isEmpty())
050      return null;
051    org.hl7.fhir.dstu3.model.Questionnaire tgt = new org.hl7.fhir.dstu3.model.Questionnaire();
052    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyDomainResource(src, tgt);
053    for (org.hl7.fhir.dstu2.model.Identifier t : src.getIdentifier())
054      tgt.addIdentifier(Identifier10_30.convertIdentifier(t));
055    if (src.hasVersionElement())
056      tgt.setVersionElement(String10_30.convertString(src.getVersionElement()));
057    if (src.hasStatus())
058      tgt.setStatusElement(convertQuestionnaireStatus(src.getStatusElement()));
059    if (src.hasDate())
060      tgt.setDateElement(DateTime10_30.convertDateTime(src.getDateElement()));
061    if (src.hasPublisherElement())
062      tgt.setPublisherElement(String10_30.convertString(src.getPublisherElement()));
063    for (org.hl7.fhir.dstu2.model.ContactPoint t : src.getTelecom())
064      tgt.addContact(convertQuestionnaireContactComponent(t));
065    org.hl7.fhir.dstu2.model.Questionnaire.GroupComponent root = src.getGroup();
066    tgt.setTitle(root.getTitle());
067    for (org.hl7.fhir.dstu2.model.Coding t : root.getConcept()) tgt.addCode(Coding10_30.convertCoding(t));
068    for (org.hl7.fhir.dstu2.model.CodeType t : src.getSubjectType()) tgt.addSubjectType(t.getValue());
069    tgt.addItem(convertQuestionnaireGroupComponent(root));
070    return tgt;
071  }
072
073  public static org.hl7.fhir.dstu3.model.ContactDetail convertQuestionnaireContactComponent(org.hl7.fhir.dstu2.model.ContactPoint src) throws FHIRException {
074    if (src == null || src.isEmpty())
075      return null;
076    org.hl7.fhir.dstu3.model.ContactDetail tgt = new org.hl7.fhir.dstu3.model.ContactDetail();
077    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt);
078    tgt.addTelecom(ContactPoint10_30.convertContactPoint(src));
079    return tgt;
080  }
081
082  public static org.hl7.fhir.dstu2.model.Questionnaire.GroupComponent convertQuestionnaireGroupComponent(org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemComponent src) throws FHIRException {
083    if (src == null || src.isEmpty())
084      return null;
085    org.hl7.fhir.dstu2.model.Questionnaire.GroupComponent tgt = new org.hl7.fhir.dstu2.model.Questionnaire.GroupComponent();
086    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyBackboneElement(src,tgt);
087    if (src.hasLinkIdElement())
088      tgt.setLinkIdElement(String10_30.convertString(src.getLinkIdElement()));
089    for (org.hl7.fhir.dstu3.model.Coding t : src.getCode()) tgt.addConcept(Coding10_30.convertCoding(t));
090    if (src.hasTextElement())
091      tgt.setTextElement(String10_30.convertString(src.getTextElement()));
092    if (src.hasRequiredElement())
093      tgt.setRequiredElement(Boolean10_30.convertBoolean(src.getRequiredElement()));
094    if (src.hasRepeatsElement())
095      tgt.setRepeatsElement(Boolean10_30.convertBoolean(src.getRepeatsElement()));
096    for (org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemComponent t : src.getItem())
097      if (t.getType() == org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemType.GROUP)
098        tgt.addGroup(convertQuestionnaireGroupComponent(t));
099      else
100        tgt.addQuestion(convertQuestionnaireQuestionComponent(t));
101    return tgt;
102  }
103
104  public static org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemComponent convertQuestionnaireGroupComponent(org.hl7.fhir.dstu2.model.Questionnaire.GroupComponent src) throws FHIRException {
105    if (src == null || src.isEmpty())
106      return null;
107    org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemComponent tgt = new org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemComponent();
108    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyBackboneElement(src,tgt);
109    if (src.hasLinkIdElement())
110      tgt.setLinkIdElement(String10_30.convertString(src.getLinkIdElement()));
111    for (org.hl7.fhir.dstu2.model.Coding t : src.getConcept()) tgt.addCode(Coding10_30.convertCoding(t));
112    if (src.hasTextElement())
113      tgt.setTextElement(String10_30.convertString(src.getTextElement()));
114    tgt.setType(org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemType.GROUP);
115    if (src.hasRequiredElement())
116      tgt.setRequiredElement(Boolean10_30.convertBoolean(src.getRequiredElement()));
117    if (src.hasRepeatsElement())
118      tgt.setRepeatsElement(Boolean10_30.convertBoolean(src.getRepeatsElement()));
119    for (org.hl7.fhir.dstu2.model.Questionnaire.GroupComponent t : src.getGroup())
120      tgt.addItem(convertQuestionnaireGroupComponent(t));
121    for (org.hl7.fhir.dstu2.model.Questionnaire.QuestionComponent t : src.getQuestion())
122      tgt.addItem(convertQuestionnaireQuestionComponent(t));
123    return tgt;
124  }
125
126  static public org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Questionnaire.AnswerFormat> convertQuestionnaireItemType(org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemType> src) throws FHIRException {
127    if (src == null || src.isEmpty())
128      return null;
129    org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Questionnaire.AnswerFormat> tgt = new org.hl7.fhir.dstu2.model.Enumeration<>(new org.hl7.fhir.dstu2.model.Questionnaire.AnswerFormatEnumFactory());
130    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt);
131    switch (src.getValue()) {
132      case BOOLEAN:
133        tgt.setValue(org.hl7.fhir.dstu2.model.Questionnaire.AnswerFormat.BOOLEAN);
134        break;
135      case DECIMAL:
136        tgt.setValue(org.hl7.fhir.dstu2.model.Questionnaire.AnswerFormat.DECIMAL);
137        break;
138      case INTEGER:
139        tgt.setValue(org.hl7.fhir.dstu2.model.Questionnaire.AnswerFormat.INTEGER);
140        break;
141      case DATE:
142        tgt.setValue(org.hl7.fhir.dstu2.model.Questionnaire.AnswerFormat.DATE);
143        break;
144      case DATETIME:
145        tgt.setValue(org.hl7.fhir.dstu2.model.Questionnaire.AnswerFormat.DATETIME);
146        break;
147      case TIME:
148        tgt.setValue(org.hl7.fhir.dstu2.model.Questionnaire.AnswerFormat.TIME);
149        break;
150      case STRING:
151        tgt.setValue(org.hl7.fhir.dstu2.model.Questionnaire.AnswerFormat.STRING);
152        break;
153      case TEXT:
154        tgt.setValue(org.hl7.fhir.dstu2.model.Questionnaire.AnswerFormat.TEXT);
155        break;
156      case URL:
157        tgt.setValue(org.hl7.fhir.dstu2.model.Questionnaire.AnswerFormat.URL);
158        break;
159      case CHOICE:
160        tgt.setValue(org.hl7.fhir.dstu2.model.Questionnaire.AnswerFormat.CHOICE);
161        break;
162      case OPENCHOICE:
163        tgt.setValue(org.hl7.fhir.dstu2.model.Questionnaire.AnswerFormat.OPENCHOICE);
164        break;
165      case ATTACHMENT:
166        tgt.setValue(org.hl7.fhir.dstu2.model.Questionnaire.AnswerFormat.ATTACHMENT);
167        break;
168      case REFERENCE:
169        tgt.setValue(org.hl7.fhir.dstu2.model.Questionnaire.AnswerFormat.REFERENCE);
170        break;
171      case QUANTITY:
172        tgt.setValue(org.hl7.fhir.dstu2.model.Questionnaire.AnswerFormat.QUANTITY);
173        break;
174      default:
175        tgt.setValue(org.hl7.fhir.dstu2.model.Questionnaire.AnswerFormat.NULL);
176        break;
177    }
178    return tgt;
179  }
180
181  public static org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemComponent convertQuestionnaireQuestionComponent(org.hl7.fhir.dstu2.model.Questionnaire.QuestionComponent src) throws FHIRException {
182    if (src == null || src.isEmpty())
183      return null;
184    org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemComponent tgt = new org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemComponent();
185    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyBackboneElement(src,tgt);
186    if (src.hasLinkIdElement())
187      tgt.setLinkIdElement(String10_30.convertString(src.getLinkIdElement()));
188    for (org.hl7.fhir.dstu2.model.Coding t : src.getConcept()) tgt.addCode(Coding10_30.convertCoding(t));
189    if (src.hasTextElement())
190      tgt.setTextElement(String10_30.convertString(src.getTextElement()));
191    if (src.hasType())
192      tgt.setTypeElement(convertQuestionnaireQuestionType(src.getTypeElement()));
193    if (src.hasRequiredElement())
194      tgt.setRequiredElement(Boolean10_30.convertBoolean(src.getRequiredElement()));
195    if (src.hasRepeatsElement())
196      tgt.setRepeatsElement(Boolean10_30.convertBoolean(src.getRepeatsElement()));
197    if (src.hasOptions())
198      tgt.setOptions(Reference10_30.convertReference(src.getOptions()));
199    for (org.hl7.fhir.dstu2.model.Coding t : src.getOption()) tgt.addOption().setValue(Coding10_30.convertCoding(t));
200    for (org.hl7.fhir.dstu2.model.Questionnaire.GroupComponent t : src.getGroup())
201      tgt.addItem(convertQuestionnaireGroupComponent(t));
202    return tgt;
203  }
204
205  public static org.hl7.fhir.dstu2.model.Questionnaire.QuestionComponent convertQuestionnaireQuestionComponent(org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemComponent src) throws FHIRException {
206    if (src == null || src.isEmpty())
207      return null;
208    org.hl7.fhir.dstu2.model.Questionnaire.QuestionComponent tgt = new org.hl7.fhir.dstu2.model.Questionnaire.QuestionComponent();
209    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyBackboneElement(src,tgt);
210    if (src.hasLinkIdElement())
211      tgt.setLinkIdElement(String10_30.convertString(src.getLinkIdElement()));
212    for (org.hl7.fhir.dstu3.model.Coding t : src.getCode()) tgt.addConcept(Coding10_30.convertCoding(t));
213    if (src.hasTextElement())
214      tgt.setTextElement(String10_30.convertString(src.getTextElement()));
215    if (src.hasType())
216      tgt.setTypeElement(convertQuestionnaireItemType(src.getTypeElement()));
217    if (src.hasRequiredElement())
218      tgt.setRequiredElement(Boolean10_30.convertBoolean(src.getRequiredElement()));
219    if (src.hasRepeatsElement())
220      tgt.setRepeatsElement(Boolean10_30.convertBoolean(src.getRepeatsElement()));
221    if (src.hasOptions())
222      tgt.setOptions(Reference10_30.convertReference(src.getOptions()));
223    for (org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemOptionComponent t : src.getOption())
224      if (t.hasValueCoding())
225        try {
226          tgt.addOption(Coding10_30.convertCoding(t.getValueCoding()));
227        } catch (org.hl7.fhir.exceptions.FHIRException e) {
228          throw new FHIRException(e);
229        }
230    for (org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemComponent t : src.getItem())
231      tgt.addGroup(convertQuestionnaireGroupComponent(t));
232    return tgt;
233  }
234
235  static public org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemType> convertQuestionnaireQuestionType(org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Questionnaire.AnswerFormat> src) throws FHIRException {
236    if (src == null || src.isEmpty())
237      return null;
238    org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemType> tgt = new org.hl7.fhir.dstu3.model.Enumeration<>(new org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemTypeEnumFactory());
239    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt);
240    switch (src.getValue()) {
241      case BOOLEAN:
242        tgt.setValue(org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemType.BOOLEAN);
243        break;
244      case DECIMAL:
245        tgt.setValue(org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemType.DECIMAL);
246        break;
247      case INTEGER:
248        tgt.setValue(org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemType.INTEGER);
249        break;
250      case DATE:
251        tgt.setValue(org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemType.DATE);
252        break;
253      case DATETIME:
254        tgt.setValue(org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemType.DATETIME);
255        break;
256      case INSTANT:
257        tgt.setValue(org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemType.DATETIME);
258        break;
259      case TIME:
260        tgt.setValue(org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemType.TIME);
261        break;
262      case STRING:
263        tgt.setValue(org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemType.STRING);
264        break;
265      case TEXT:
266        tgt.setValue(org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemType.TEXT);
267        break;
268      case URL:
269        tgt.setValue(org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemType.URL);
270        break;
271      case CHOICE:
272        tgt.setValue(org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemType.CHOICE);
273        break;
274      case OPENCHOICE:
275        tgt.setValue(org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemType.OPENCHOICE);
276        break;
277      case ATTACHMENT:
278        tgt.setValue(org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemType.ATTACHMENT);
279        break;
280      case REFERENCE:
281        tgt.setValue(org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemType.REFERENCE);
282        break;
283      case QUANTITY:
284        tgt.setValue(org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemType.QUANTITY);
285        break;
286      default:
287        tgt.setValue(org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemType.NULL);
288        break;
289    }
290    return tgt;
291  }
292
293  static public org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Questionnaire.QuestionnaireStatus> convertQuestionnaireStatus(org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Enumerations.PublicationStatus> src) throws FHIRException {
294    if (src == null || src.isEmpty())
295      return null;
296    org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Questionnaire.QuestionnaireStatus> tgt = new org.hl7.fhir.dstu2.model.Enumeration<>(new org.hl7.fhir.dstu2.model.Questionnaire.QuestionnaireStatusEnumFactory());
297    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt);
298    switch (src.getValue()) {
299      case DRAFT:
300        tgt.setValue(org.hl7.fhir.dstu2.model.Questionnaire.QuestionnaireStatus.DRAFT);
301        break;
302      case ACTIVE:
303        tgt.setValue(org.hl7.fhir.dstu2.model.Questionnaire.QuestionnaireStatus.PUBLISHED);
304        break;
305      case RETIRED:
306        tgt.setValue(org.hl7.fhir.dstu2.model.Questionnaire.QuestionnaireStatus.RETIRED);
307        break;
308      default:
309        tgt.setValue(org.hl7.fhir.dstu2.model.Questionnaire.QuestionnaireStatus.NULL);
310        break;
311    }
312    return tgt;
313  }
314
315  static public org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Enumerations.PublicationStatus> convertQuestionnaireStatus(org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Questionnaire.QuestionnaireStatus> src) throws FHIRException {
316    if (src == null || src.isEmpty())
317      return null;
318    org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Enumerations.PublicationStatus> tgt = new org.hl7.fhir.dstu3.model.Enumeration<>(new org.hl7.fhir.dstu3.model.Enumerations.PublicationStatusEnumFactory());
319    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt);
320    switch (src.getValue()) {
321      case DRAFT:
322        tgt.setValue(org.hl7.fhir.dstu3.model.Enumerations.PublicationStatus.DRAFT);
323        break;
324      case PUBLISHED:
325        tgt.setValue(org.hl7.fhir.dstu3.model.Enumerations.PublicationStatus.ACTIVE);
326        break;
327      case RETIRED:
328        tgt.setValue(org.hl7.fhir.dstu3.model.Enumerations.PublicationStatus.RETIRED);
329        break;
330      default:
331        tgt.setValue(org.hl7.fhir.dstu3.model.Enumerations.PublicationStatus.NULL);
332        break;
333    }
334    return tgt;
335  }
336}