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