001package org.hl7.fhir.convertors.conv10_50.resources10_50;
002
003import org.hl7.fhir.convertors.context.ConversionContext10_50;
004import org.hl7.fhir.convertors.conv10_50.datatypes10_50.Reference10_50;
005import org.hl7.fhir.convertors.conv10_50.datatypes10_50.complextypes10_50.Identifier10_50;
006import org.hl7.fhir.convertors.conv10_50.datatypes10_50.primitivetypes10_50.DateTime10_50;
007import org.hl7.fhir.convertors.conv10_50.datatypes10_50.primitivetypes10_50.String10_50;
008import org.hl7.fhir.exceptions.FHIRException;
009
010public class QuestionnaireResponse10_50 {
011
012  public static org.hl7.fhir.dstu2.model.QuestionnaireResponse.GroupComponent convertQuestionnaireItemToGroup(org.hl7.fhir.r5.model.QuestionnaireResponse.QuestionnaireResponseItemComponent src) throws FHIRException {
013    if (src == null || src.isEmpty())
014      return null;
015    org.hl7.fhir.dstu2.model.QuestionnaireResponse.GroupComponent tgt = new org.hl7.fhir.dstu2.model.QuestionnaireResponse.GroupComponent();
016    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyBackboneElement(src,tgt);
017    if (src.hasLinkIdElement())
018      tgt.setLinkIdElement(String10_50.convertString(src.getLinkIdElement()));
019    if (src.hasTextElement())
020      tgt.setTextElement(String10_50.convertString(src.getTextElement()));
021    for (org.hl7.fhir.r5.model.QuestionnaireResponse.QuestionnaireResponseItemComponent t : src.getItem())
022      if (t.hasAnswer())
023        tgt.addQuestion(convertQuestionnaireItemToQuestion(t));
024      else
025        tgt.addGroup(convertQuestionnaireItemToGroup(t));
026    return tgt;
027  }
028
029  public static org.hl7.fhir.dstu2.model.QuestionnaireResponse.QuestionComponent convertQuestionnaireItemToQuestion(org.hl7.fhir.r5.model.QuestionnaireResponse.QuestionnaireResponseItemComponent src) throws FHIRException {
030    if (src == null || src.isEmpty())
031      return null;
032    org.hl7.fhir.dstu2.model.QuestionnaireResponse.QuestionComponent tgt = new org.hl7.fhir.dstu2.model.QuestionnaireResponse.QuestionComponent();
033    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyBackboneElement(src,tgt);
034    if (src.hasLinkIdElement())
035      tgt.setLinkIdElement(String10_50.convertString(src.getLinkIdElement()));
036    if (src.hasTextElement())
037      tgt.setTextElement(String10_50.convertString(src.getTextElement()));
038    for (org.hl7.fhir.r5.model.QuestionnaireResponse.QuestionnaireResponseItemAnswerComponent t : src.getAnswer())
039      tgt.addAnswer(convertQuestionnaireResponseItemAnswerComponent(t));
040    return tgt;
041  }
042
043  public static org.hl7.fhir.dstu2.model.QuestionnaireResponse convertQuestionnaireResponse(org.hl7.fhir.r5.model.QuestionnaireResponse src) throws FHIRException {
044    if (src == null || src.isEmpty())
045      return null;
046    org.hl7.fhir.dstu2.model.QuestionnaireResponse tgt = new org.hl7.fhir.dstu2.model.QuestionnaireResponse();
047    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyDomainResource(src, tgt);
048    if (src.hasIdentifier())
049      tgt.setIdentifier(Identifier10_50.convertIdentifier(src.getIdentifierFirstRep()));
050    if (src.hasQuestionnaireElement())
051      tgt.setQuestionnaire(Reference10_50.convertCanonicalToReference(src.getQuestionnaireElement()));
052    if (src.hasStatus())
053      tgt.setStatusElement(convertQuestionnaireResponseStatus(src.getStatusElement()));
054    if (src.hasSubject())
055      tgt.setSubject(Reference10_50.convertReference(src.getSubject()));
056    if (src.hasAuthor())
057      tgt.setAuthor(Reference10_50.convertReference(src.getAuthor()));
058    if (src.hasAuthoredElement())
059      tgt.setAuthoredElement(DateTime10_50.convertDateTime(src.getAuthoredElement()));
060    if (src.hasSource())
061      tgt.setSource(Reference10_50.convertReference(src.getSource()));
062    if (src.hasEncounter())
063      tgt.setEncounter(Reference10_50.convertReference(src.getEncounter()));
064    if (src.getItem().size() != 1)
065      throw new FHIRException("multiple root items not supported");
066    tgt.setGroup(convertQuestionnaireItemToGroup(src.getItem().get(0)));
067    return tgt;
068  }
069
070  public static org.hl7.fhir.r5.model.QuestionnaireResponse convertQuestionnaireResponse(org.hl7.fhir.dstu2.model.QuestionnaireResponse src) throws FHIRException {
071    if (src == null || src.isEmpty())
072      return null;
073    org.hl7.fhir.r5.model.QuestionnaireResponse tgt = new org.hl7.fhir.r5.model.QuestionnaireResponse();
074    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyDomainResource(src, tgt);
075    if (src.hasIdentifier())
076      tgt.addIdentifier(Identifier10_50.convertIdentifier(src.getIdentifier()));
077    if (src.hasQuestionnaire())
078      tgt.setQuestionnaireElement(Reference10_50.convertReferenceToCanonical(src.getQuestionnaire()));
079    if (src.hasStatus())
080      tgt.setStatusElement(convertQuestionnaireResponseStatus(src.getStatusElement()));
081    if (src.hasSubject())
082      tgt.setSubject(Reference10_50.convertReference(src.getSubject()));
083    if (src.hasAuthor())
084      tgt.setAuthor(Reference10_50.convertReference(src.getAuthor()));
085    if (src.hasAuthoredElement())
086      tgt.setAuthoredElement(DateTime10_50.convertDateTime(src.getAuthoredElement()));
087    if (src.hasSource())
088      tgt.setSource(Reference10_50.convertReference(src.getSource()));
089    if (src.hasEncounter())
090      tgt.setEncounter(Reference10_50.convertReference(src.getEncounter()));
091    if (src.hasGroup())
092      tgt.addItem(convertQuestionnaireResponseGroupComponent(src.getGroup()));
093    return tgt;
094  }
095
096  public static org.hl7.fhir.r5.model.QuestionnaireResponse.QuestionnaireResponseItemComponent convertQuestionnaireResponseGroupComponent(org.hl7.fhir.dstu2.model.QuestionnaireResponse.GroupComponent src) throws FHIRException {
097    if (src == null || src.isEmpty())
098      return null;
099    org.hl7.fhir.r5.model.QuestionnaireResponse.QuestionnaireResponseItemComponent tgt = new org.hl7.fhir.r5.model.QuestionnaireResponse.QuestionnaireResponseItemComponent();
100    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyBackboneElement(src,tgt);
101    if (src.hasLinkIdElement())
102      tgt.setLinkIdElement(String10_50.convertString(src.getLinkIdElement()));
103    if (src.hasTextElement())
104      tgt.setTextElement(String10_50.convertString(src.getTextElement()));
105    for (org.hl7.fhir.dstu2.model.QuestionnaireResponse.GroupComponent t : src.getGroup())
106      tgt.addItem(convertQuestionnaireResponseGroupComponent(t));
107    for (org.hl7.fhir.dstu2.model.QuestionnaireResponse.QuestionComponent t : src.getQuestion())
108      tgt.addItem(convertQuestionnaireResponseQuestionComponent(t));
109    return tgt;
110  }
111
112  public static org.hl7.fhir.dstu2.model.QuestionnaireResponse.QuestionAnswerComponent convertQuestionnaireResponseItemAnswerComponent(org.hl7.fhir.r5.model.QuestionnaireResponse.QuestionnaireResponseItemAnswerComponent src) throws FHIRException {
113    if (src == null || src.isEmpty())
114      return null;
115    org.hl7.fhir.dstu2.model.QuestionnaireResponse.QuestionAnswerComponent tgt = new org.hl7.fhir.dstu2.model.QuestionnaireResponse.QuestionAnswerComponent();
116    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyBackboneElement(src,tgt);
117    if (src.hasValue())
118      tgt.setValue(ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().convertType(src.getValue()));
119    for (org.hl7.fhir.r5.model.QuestionnaireResponse.QuestionnaireResponseItemComponent t : src.getItem())
120      tgt.addGroup(convertQuestionnaireItemToGroup(t));
121    return tgt;
122  }
123
124  public static org.hl7.fhir.r5.model.QuestionnaireResponse.QuestionnaireResponseItemAnswerComponent convertQuestionnaireResponseItemAnswerComponent(org.hl7.fhir.dstu2.model.QuestionnaireResponse.QuestionAnswerComponent src) throws FHIRException {
125    if (src == null || src.isEmpty())
126      return null;
127    org.hl7.fhir.r5.model.QuestionnaireResponse.QuestionnaireResponseItemAnswerComponent tgt = new org.hl7.fhir.r5.model.QuestionnaireResponse.QuestionnaireResponseItemAnswerComponent();
128    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyBackboneElement(src,tgt);
129    if (src.hasValue())
130      tgt.setValue(ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().convertType(src.getValue()));
131    for (org.hl7.fhir.dstu2.model.QuestionnaireResponse.GroupComponent t : src.getGroup())
132      tgt.addItem(convertQuestionnaireResponseGroupComponent(t));
133    return tgt;
134  }
135
136  public static org.hl7.fhir.r5.model.QuestionnaireResponse.QuestionnaireResponseItemComponent convertQuestionnaireResponseQuestionComponent(org.hl7.fhir.dstu2.model.QuestionnaireResponse.QuestionComponent src) throws FHIRException {
137    if (src == null || src.isEmpty())
138      return null;
139    org.hl7.fhir.r5.model.QuestionnaireResponse.QuestionnaireResponseItemComponent tgt = new org.hl7.fhir.r5.model.QuestionnaireResponse.QuestionnaireResponseItemComponent();
140    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyBackboneElement(src,tgt);
141    if (src.hasLinkIdElement())
142      tgt.setLinkIdElement(String10_50.convertString(src.getLinkIdElement()));
143    if (src.hasTextElement())
144      tgt.setTextElement(String10_50.convertString(src.getTextElement()));
145    for (org.hl7.fhir.dstu2.model.QuestionnaireResponse.QuestionAnswerComponent t : src.getAnswer())
146      tgt.addAnswer(convertQuestionnaireResponseItemAnswerComponent(t));
147    return tgt;
148  }
149
150  static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.QuestionnaireResponse.QuestionnaireResponseStatus> convertQuestionnaireResponseStatus(org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.QuestionnaireResponse.QuestionnaireResponseStatus> src) throws FHIRException {
151    if (src == null || src.isEmpty())
152      return null;
153    org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.QuestionnaireResponse.QuestionnaireResponseStatus> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.QuestionnaireResponse.QuestionnaireResponseStatusEnumFactory());
154    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyElement(src, tgt);
155    switch (src.getValue()) {
156      case INPROGRESS:
157        tgt.setValue(org.hl7.fhir.r5.model.QuestionnaireResponse.QuestionnaireResponseStatus.INPROGRESS);
158        break;
159      case COMPLETED:
160        tgt.setValue(org.hl7.fhir.r5.model.QuestionnaireResponse.QuestionnaireResponseStatus.COMPLETED);
161        break;
162      case AMENDED:
163        tgt.setValue(org.hl7.fhir.r5.model.QuestionnaireResponse.QuestionnaireResponseStatus.AMENDED);
164        break;
165      default:
166        tgt.setValue(org.hl7.fhir.r5.model.QuestionnaireResponse.QuestionnaireResponseStatus.NULL);
167        break;
168    }
169    return tgt;
170  }
171
172  static public org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.QuestionnaireResponse.QuestionnaireResponseStatus> convertQuestionnaireResponseStatus(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.QuestionnaireResponse.QuestionnaireResponseStatus> src) throws FHIRException {
173    if (src == null || src.isEmpty())
174      return null;
175    org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.QuestionnaireResponse.QuestionnaireResponseStatus> tgt = new org.hl7.fhir.dstu2.model.Enumeration<>(new org.hl7.fhir.dstu2.model.QuestionnaireResponse.QuestionnaireResponseStatusEnumFactory());
176    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyElement(src, tgt);
177    switch (src.getValue()) {
178      case INPROGRESS:
179        tgt.setValue(org.hl7.fhir.dstu2.model.QuestionnaireResponse.QuestionnaireResponseStatus.INPROGRESS);
180        break;
181      case COMPLETED:
182        tgt.setValue(org.hl7.fhir.dstu2.model.QuestionnaireResponse.QuestionnaireResponseStatus.COMPLETED);
183        break;
184      case AMENDED:
185        tgt.setValue(org.hl7.fhir.dstu2.model.QuestionnaireResponse.QuestionnaireResponseStatus.AMENDED);
186        break;
187      default:
188        tgt.setValue(org.hl7.fhir.dstu2.model.QuestionnaireResponse.QuestionnaireResponseStatus.NULL);
189        break;
190    }
191    return tgt;
192  }
193}