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