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