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