001package org.hl7.fhir.convertors.conv30_50.resources30_50; 002 003import org.hl7.fhir.convertors.context.ConversionContext30_50; 004import org.hl7.fhir.convertors.conv30_50.datatypes30_50.Dosage30_50; 005import org.hl7.fhir.convertors.conv30_50.datatypes30_50.Reference30_50; 006import org.hl7.fhir.convertors.conv30_50.datatypes30_50.complextypes30_50.*; 007import org.hl7.fhir.convertors.conv30_50.datatypes30_50.primitivetypes30_50.Boolean30_50; 008import org.hl7.fhir.convertors.conv30_50.datatypes30_50.primitivetypes30_50.DateTime30_50; 009import org.hl7.fhir.exceptions.FHIRException; 010import org.hl7.fhir.r5.model.CodeableReference; 011 012public class MedicationRequest30_50 { 013 014 public static org.hl7.fhir.dstu3.model.MedicationRequest convertMedicationRequest(org.hl7.fhir.r5.model.MedicationRequest src) throws FHIRException { 015 if (src == null) 016 return null; 017 org.hl7.fhir.dstu3.model.MedicationRequest tgt = new org.hl7.fhir.dstu3.model.MedicationRequest(); 018 ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyDomainResource(src, tgt); 019 for (org.hl7.fhir.r5.model.Identifier t : src.getIdentifier()) 020 tgt.addIdentifier(Identifier30_50.convertIdentifier(t)); 021 for (org.hl7.fhir.r5.model.Reference t : src.getBasedOn()) tgt.addBasedOn(Reference30_50.convertReference(t)); 022 if (src.hasGroupIdentifier()) 023 tgt.setGroupIdentifier(Identifier30_50.convertIdentifier(src.getGroupIdentifier())); 024 if (src.hasStatus()) 025 tgt.setStatusElement(convertMedicationRequestStatus(src.getStatusElement())); 026 if (src.hasIntent()) 027 tgt.setIntentElement(convertMedicationRequestIntent(src.getIntentElement())); 028 if (src.hasPriority()) 029 tgt.setPriorityElement(convertMedicationRequestPriority(src.getPriorityElement())); 030 if (src.getMedication().hasConcept()) 031 tgt.setMedication(ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().convertType(src.getMedication().getConcept())); 032 if (src.getMedication().hasReference()) 033 tgt.setMedication(ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().convertType(src.getMedication().getReference())); 034 if (src.hasSubject()) 035 tgt.setSubject(Reference30_50.convertReference(src.getSubject())); 036 if (src.hasEncounter()) 037 tgt.setContext(Reference30_50.convertReference(src.getEncounter())); 038 for (org.hl7.fhir.r5.model.Reference t : src.getSupportingInformation()) 039 tgt.addSupportingInformation(Reference30_50.convertReference(t)); 040 if (src.hasAuthoredOn()) 041 tgt.setAuthoredOnElement(DateTime30_50.convertDateTime(src.getAuthoredOnElement())); 042 if (src.hasRecorder()) 043 tgt.setRecorder(Reference30_50.convertReference(src.getRecorder())); 044 for (CodeableReference t : src.getReason()) { 045 if (t.hasConcept()) { 046 tgt.addReasonCode(CodeableConcept30_50.convertCodeableConcept(t.getConcept())); 047 } 048 if (t.hasReference()) { 049 tgt.addReasonReference(Reference30_50.convertReference(t.getReference())); 050 } 051 } 052 for (org.hl7.fhir.r5.model.Annotation t : src.getNote()) tgt.addNote(Annotation30_50.convertAnnotation(t)); 053 for (org.hl7.fhir.r5.model.Dosage t : src.getDose().getDosageInstruction()) 054 tgt.addDosageInstruction(Dosage30_50.convertDosage(t)); 055 if (src.hasDispenseRequest()) 056 tgt.setDispenseRequest(convertMedicationRequestDispenseRequestComponent(src.getDispenseRequest())); 057 if (src.hasSubstitution()) 058 tgt.setSubstitution(convertMedicationRequestSubstitutionComponent(src.getSubstitution())); 059 if (src.hasPriorPrescription()) 060 tgt.setPriorPrescription(Reference30_50.convertReference(src.getPriorPrescription())); 061 for (org.hl7.fhir.r5.model.Reference t : src.getDetectedIssue()) 062 tgt.addDetectedIssue(Reference30_50.convertReference(t)); 063 for (org.hl7.fhir.r5.model.Reference t : src.getEventHistory()) 064 tgt.addEventHistory(Reference30_50.convertReference(t)); 065 return tgt; 066 } 067 068 public static org.hl7.fhir.r5.model.MedicationRequest convertMedicationRequest(org.hl7.fhir.dstu3.model.MedicationRequest src) throws FHIRException { 069 if (src == null) 070 return null; 071 org.hl7.fhir.r5.model.MedicationRequest tgt = new org.hl7.fhir.r5.model.MedicationRequest(); 072 ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyDomainResource(src, tgt); 073 for (org.hl7.fhir.dstu3.model.Identifier t : src.getIdentifier()) 074 tgt.addIdentifier(Identifier30_50.convertIdentifier(t)); 075 for (org.hl7.fhir.dstu3.model.Reference t : src.getBasedOn()) tgt.addBasedOn(Reference30_50.convertReference(t)); 076 if (src.hasGroupIdentifier()) 077 tgt.setGroupIdentifier(Identifier30_50.convertIdentifier(src.getGroupIdentifier())); 078 if (src.hasStatus()) 079 tgt.setStatusElement(convertMedicationRequestStatus(src.getStatusElement())); 080 if (src.hasIntent()) 081 tgt.setIntentElement(convertMedicationRequestIntent(src.getIntentElement())); 082 if (src.hasPriority()) 083 tgt.setPriorityElement(convertMedicationRequestPriority(src.getPriorityElement())); 084 if (src.hasMedicationCodeableConcept()) 085 tgt.getMedication().setConcept(CodeableConcept30_50.convertCodeableConcept(src.getMedicationCodeableConcept())); 086 if (src.hasMedicationReference()) 087 tgt.getMedication().setReference(Reference30_50.convertReference(src.getMedicationReference())); 088 if (src.hasSubject()) 089 tgt.setSubject(Reference30_50.convertReference(src.getSubject())); 090 if (src.hasContext()) 091 tgt.setEncounter(Reference30_50.convertReference(src.getContext())); 092 for (org.hl7.fhir.dstu3.model.Reference t : src.getSupportingInformation()) 093 tgt.addSupportingInformation(Reference30_50.convertReference(t)); 094 if (src.hasAuthoredOn()) 095 tgt.setAuthoredOnElement(DateTime30_50.convertDateTime(src.getAuthoredOnElement())); 096 if (src.hasRecorder()) 097 tgt.setRecorder(Reference30_50.convertReference(src.getRecorder())); 098 for (org.hl7.fhir.dstu3.model.CodeableConcept t : src.getReasonCode()) 099 tgt.addReason(new CodeableReference().setConcept(CodeableConcept30_50.convertCodeableConcept(t))); 100 for (org.hl7.fhir.dstu3.model.Reference t : src.getReasonReference()) 101 tgt.addReason(new CodeableReference().setReference(Reference30_50.convertReference(t))); 102 for (org.hl7.fhir.dstu3.model.Annotation t : src.getNote()) tgt.addNote(Annotation30_50.convertAnnotation(t)); 103 for (org.hl7.fhir.dstu3.model.Dosage t : src.getDosageInstruction()) 104 tgt.getDose().addDosageInstruction(Dosage30_50.convertDosage(t)); 105 if (src.hasDispenseRequest()) 106 tgt.setDispenseRequest(convertMedicationRequestDispenseRequestComponent(src.getDispenseRequest())); 107 if (src.hasSubstitution()) 108 tgt.setSubstitution(convertMedicationRequestSubstitutionComponent(src.getSubstitution())); 109 if (src.hasPriorPrescription()) 110 tgt.setPriorPrescription(Reference30_50.convertReference(src.getPriorPrescription())); 111 for (org.hl7.fhir.dstu3.model.Reference t : src.getDetectedIssue()) 112 tgt.addDetectedIssue(Reference30_50.convertReference(t)); 113 for (org.hl7.fhir.dstu3.model.Reference t : src.getEventHistory()) 114 tgt.addEventHistory(Reference30_50.convertReference(t)); 115 return tgt; 116 } 117 118 public static org.hl7.fhir.r5.model.MedicationRequest.MedicationRequestDispenseRequestComponent convertMedicationRequestDispenseRequestComponent(org.hl7.fhir.dstu3.model.MedicationRequest.MedicationRequestDispenseRequestComponent src) throws FHIRException { 119 if (src == null) 120 return null; 121 org.hl7.fhir.r5.model.MedicationRequest.MedicationRequestDispenseRequestComponent tgt = new org.hl7.fhir.r5.model.MedicationRequest.MedicationRequestDispenseRequestComponent(); 122 ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt); 123 if (src.hasValidityPeriod()) 124 tgt.setValidityPeriod(Period30_50.convertPeriod(src.getValidityPeriod())); 125 if (src.hasNumberOfRepeatsAllowed()) 126 tgt.setNumberOfRepeatsAllowed(src.getNumberOfRepeatsAllowed()); 127 if (src.hasQuantity()) 128 tgt.setQuantity(SimpleQuantity30_50.convertSimpleQuantity(src.getQuantity())); 129 if (src.hasExpectedSupplyDuration()) 130 tgt.setExpectedSupplyDuration(Duration30_50.convertDuration(src.getExpectedSupplyDuration())); 131 if (src.hasPerformer()) 132 tgt.setDispenser(Reference30_50.convertReference(src.getPerformer())); 133 return tgt; 134 } 135 136 public static org.hl7.fhir.dstu3.model.MedicationRequest.MedicationRequestDispenseRequestComponent convertMedicationRequestDispenseRequestComponent(org.hl7.fhir.r5.model.MedicationRequest.MedicationRequestDispenseRequestComponent src) throws FHIRException { 137 if (src == null) 138 return null; 139 org.hl7.fhir.dstu3.model.MedicationRequest.MedicationRequestDispenseRequestComponent tgt = new org.hl7.fhir.dstu3.model.MedicationRequest.MedicationRequestDispenseRequestComponent(); 140 ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt); 141 if (src.hasValidityPeriod()) 142 tgt.setValidityPeriod(Period30_50.convertPeriod(src.getValidityPeriod())); 143 if (src.hasNumberOfRepeatsAllowed()) 144 tgt.setNumberOfRepeatsAllowed(src.getNumberOfRepeatsAllowed()); 145 if (src.hasQuantity()) 146 tgt.setQuantity(SimpleQuantity30_50.convertSimpleQuantity(src.getQuantity())); 147 if (src.hasExpectedSupplyDuration()) 148 tgt.setExpectedSupplyDuration(Duration30_50.convertDuration(src.getExpectedSupplyDuration())); 149 if (src.hasDispenser()) 150 tgt.setPerformer(Reference30_50.convertReference(src.getDispenser())); 151 return tgt; 152 } 153 154 static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.MedicationRequest.MedicationRequestIntent> convertMedicationRequestIntent(org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.MedicationRequest.MedicationRequestIntent> src) throws FHIRException { 155 if (src == null || src.isEmpty()) 156 return null; 157 org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.MedicationRequest.MedicationRequestIntent> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.MedicationRequest.MedicationRequestIntentEnumFactory()); 158 ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt); 159 switch (src.getValue()) { 160 case PROPOSAL: 161 tgt.setValue(org.hl7.fhir.r5.model.MedicationRequest.MedicationRequestIntent.PROPOSAL); 162 break; 163 case PLAN: 164 tgt.setValue(org.hl7.fhir.r5.model.MedicationRequest.MedicationRequestIntent.PLAN); 165 break; 166 case ORDER: 167 tgt.setValue(org.hl7.fhir.r5.model.MedicationRequest.MedicationRequestIntent.ORDER); 168 break; 169 case INSTANCEORDER: 170 tgt.setValue(org.hl7.fhir.r5.model.MedicationRequest.MedicationRequestIntent.INSTANCEORDER); 171 break; 172 default: 173 tgt.setValue(org.hl7.fhir.r5.model.MedicationRequest.MedicationRequestIntent.NULL); 174 break; 175 } 176 return tgt; 177 } 178 179 static public org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.MedicationRequest.MedicationRequestIntent> convertMedicationRequestIntent(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.MedicationRequest.MedicationRequestIntent> src) throws FHIRException { 180 if (src == null || src.isEmpty()) 181 return null; 182 org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.MedicationRequest.MedicationRequestIntent> tgt = new org.hl7.fhir.dstu3.model.Enumeration<>(new org.hl7.fhir.dstu3.model.MedicationRequest.MedicationRequestIntentEnumFactory()); 183 ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt); 184 switch (src.getValue()) { 185 case PROPOSAL: 186 tgt.setValue(org.hl7.fhir.dstu3.model.MedicationRequest.MedicationRequestIntent.PROPOSAL); 187 break; 188 case PLAN: 189 tgt.setValue(org.hl7.fhir.dstu3.model.MedicationRequest.MedicationRequestIntent.PLAN); 190 break; 191 case ORDER: 192 tgt.setValue(org.hl7.fhir.dstu3.model.MedicationRequest.MedicationRequestIntent.ORDER); 193 break; 194 case INSTANCEORDER: 195 tgt.setValue(org.hl7.fhir.dstu3.model.MedicationRequest.MedicationRequestIntent.INSTANCEORDER); 196 break; 197 default: 198 tgt.setValue(org.hl7.fhir.dstu3.model.MedicationRequest.MedicationRequestIntent.NULL); 199 break; 200 } 201 return tgt; 202 } 203 204 static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Enumerations.RequestPriority> convertMedicationRequestPriority(org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.MedicationRequest.MedicationRequestPriority> src) throws FHIRException { 205 if (src == null || src.isEmpty()) 206 return null; 207 org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Enumerations.RequestPriority> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.Enumerations.RequestPriorityEnumFactory()); 208 ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt); 209 switch (src.getValue()) { 210 case ROUTINE: 211 tgt.setValue(org.hl7.fhir.r5.model.Enumerations.RequestPriority.ROUTINE); 212 break; 213 case URGENT: 214 tgt.setValue(org.hl7.fhir.r5.model.Enumerations.RequestPriority.URGENT); 215 break; 216 case STAT: 217 tgt.setValue(org.hl7.fhir.r5.model.Enumerations.RequestPriority.STAT); 218 break; 219 case ASAP: 220 tgt.setValue(org.hl7.fhir.r5.model.Enumerations.RequestPriority.ASAP); 221 break; 222 default: 223 tgt.setValue(org.hl7.fhir.r5.model.Enumerations.RequestPriority.NULL); 224 break; 225 } 226 return tgt; 227 } 228 229 static public org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.MedicationRequest.MedicationRequestPriority> convertMedicationRequestPriority(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Enumerations.RequestPriority> src) throws FHIRException { 230 if (src == null || src.isEmpty()) 231 return null; 232 org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.MedicationRequest.MedicationRequestPriority> tgt = new org.hl7.fhir.dstu3.model.Enumeration<>(new org.hl7.fhir.dstu3.model.MedicationRequest.MedicationRequestPriorityEnumFactory()); 233 ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt); 234 switch (src.getValue()) { 235 case ROUTINE: 236 tgt.setValue(org.hl7.fhir.dstu3.model.MedicationRequest.MedicationRequestPriority.ROUTINE); 237 break; 238 case URGENT: 239 tgt.setValue(org.hl7.fhir.dstu3.model.MedicationRequest.MedicationRequestPriority.URGENT); 240 break; 241 case STAT: 242 tgt.setValue(org.hl7.fhir.dstu3.model.MedicationRequest.MedicationRequestPriority.STAT); 243 break; 244 case ASAP: 245 tgt.setValue(org.hl7.fhir.dstu3.model.MedicationRequest.MedicationRequestPriority.ASAP); 246 break; 247 default: 248 tgt.setValue(org.hl7.fhir.dstu3.model.MedicationRequest.MedicationRequestPriority.NULL); 249 break; 250 } 251 return tgt; 252 } 253 254 static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.MedicationRequest.MedicationrequestStatus> convertMedicationRequestStatus(org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.MedicationRequest.MedicationRequestStatus> src) throws FHIRException { 255 if (src == null || src.isEmpty()) 256 return null; 257 org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.MedicationRequest.MedicationrequestStatus> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.MedicationRequest.MedicationrequestStatusEnumFactory()); 258 ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt); 259 switch (src.getValue()) { 260 case ACTIVE: 261 tgt.setValue(org.hl7.fhir.r5.model.MedicationRequest.MedicationrequestStatus.ACTIVE); 262 break; 263 case ONHOLD: 264 tgt.setValue(org.hl7.fhir.r5.model.MedicationRequest.MedicationrequestStatus.ONHOLD); 265 break; 266 case CANCELLED: 267 tgt.setValue(org.hl7.fhir.r5.model.MedicationRequest.MedicationrequestStatus.CANCELLED); 268 break; 269 case COMPLETED: 270 tgt.setValue(org.hl7.fhir.r5.model.MedicationRequest.MedicationrequestStatus.COMPLETED); 271 break; 272 case ENTEREDINERROR: 273 tgt.setValue(org.hl7.fhir.r5.model.MedicationRequest.MedicationrequestStatus.ENTEREDINERROR); 274 break; 275 case STOPPED: 276 tgt.setValue(org.hl7.fhir.r5.model.MedicationRequest.MedicationrequestStatus.STOPPED); 277 break; 278 case DRAFT: 279 tgt.setValue(org.hl7.fhir.r5.model.MedicationRequest.MedicationrequestStatus.DRAFT); 280 break; 281 case UNKNOWN: 282 tgt.setValue(org.hl7.fhir.r5.model.MedicationRequest.MedicationrequestStatus.UNKNOWN); 283 break; 284 default: 285 tgt.setValue(org.hl7.fhir.r5.model.MedicationRequest.MedicationrequestStatus.NULL); 286 break; 287 } 288 return tgt; 289 } 290 291 static public org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.MedicationRequest.MedicationRequestStatus> convertMedicationRequestStatus(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.MedicationRequest.MedicationrequestStatus> src) throws FHIRException { 292 if (src == null || src.isEmpty()) 293 return null; 294 org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.MedicationRequest.MedicationRequestStatus> tgt = new org.hl7.fhir.dstu3.model.Enumeration<>(new org.hl7.fhir.dstu3.model.MedicationRequest.MedicationRequestStatusEnumFactory()); 295 ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt); 296 switch (src.getValue()) { 297 case ACTIVE: 298 tgt.setValue(org.hl7.fhir.dstu3.model.MedicationRequest.MedicationRequestStatus.ACTIVE); 299 break; 300 case ONHOLD: 301 tgt.setValue(org.hl7.fhir.dstu3.model.MedicationRequest.MedicationRequestStatus.ONHOLD); 302 break; 303 case CANCELLED: 304 tgt.setValue(org.hl7.fhir.dstu3.model.MedicationRequest.MedicationRequestStatus.CANCELLED); 305 break; 306 case COMPLETED: 307 tgt.setValue(org.hl7.fhir.dstu3.model.MedicationRequest.MedicationRequestStatus.COMPLETED); 308 break; 309 case ENTEREDINERROR: 310 tgt.setValue(org.hl7.fhir.dstu3.model.MedicationRequest.MedicationRequestStatus.ENTEREDINERROR); 311 break; 312 case STOPPED: 313 tgt.setValue(org.hl7.fhir.dstu3.model.MedicationRequest.MedicationRequestStatus.STOPPED); 314 break; 315 case DRAFT: 316 tgt.setValue(org.hl7.fhir.dstu3.model.MedicationRequest.MedicationRequestStatus.DRAFT); 317 break; 318 case UNKNOWN: 319 tgt.setValue(org.hl7.fhir.dstu3.model.MedicationRequest.MedicationRequestStatus.UNKNOWN); 320 break; 321 default: 322 tgt.setValue(org.hl7.fhir.dstu3.model.MedicationRequest.MedicationRequestStatus.NULL); 323 break; 324 } 325 return tgt; 326 } 327 328 public static org.hl7.fhir.r5.model.MedicationRequest.MedicationRequestSubstitutionComponent convertMedicationRequestSubstitutionComponent(org.hl7.fhir.dstu3.model.MedicationRequest.MedicationRequestSubstitutionComponent src) throws FHIRException { 329 if (src == null) 330 return null; 331 org.hl7.fhir.r5.model.MedicationRequest.MedicationRequestSubstitutionComponent tgt = new org.hl7.fhir.r5.model.MedicationRequest.MedicationRequestSubstitutionComponent(); 332 ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt); 333 if (src.hasAllowed()) 334 tgt.setAllowed(Boolean30_50.convertBoolean(src.getAllowedElement())); 335 if (src.hasReason()) 336 tgt.setReason(CodeableConcept30_50.convertCodeableConcept(src.getReason())); 337 return tgt; 338 } 339 340 public static org.hl7.fhir.dstu3.model.MedicationRequest.MedicationRequestSubstitutionComponent convertMedicationRequestSubstitutionComponent(org.hl7.fhir.r5.model.MedicationRequest.MedicationRequestSubstitutionComponent src) throws FHIRException { 341 if (src == null) 342 return null; 343 org.hl7.fhir.dstu3.model.MedicationRequest.MedicationRequestSubstitutionComponent tgt = new org.hl7.fhir.dstu3.model.MedicationRequest.MedicationRequestSubstitutionComponent(); 344 ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt); 345 if (src.hasAllowedBooleanType()) 346 tgt.setAllowedElement(Boolean30_50.convertBoolean(src.getAllowedBooleanType())); 347 if (src.hasReason()) 348 tgt.setReason(CodeableConcept30_50.convertCodeableConcept(src.getReason())); 349 return tgt; 350 } 351}