001package org.hl7.fhir.convertors.conv40_50.resources40_50; 002 003import org.hl7.fhir.convertors.context.ConversionContext40_50; 004import org.hl7.fhir.convertors.conv40_50.datatypes40_50.general40_50.Annotation40_50; 005import org.hl7.fhir.convertors.conv40_50.datatypes40_50.general40_50.CodeableConcept40_50; 006import org.hl7.fhir.convertors.conv40_50.datatypes40_50.general40_50.Identifier40_50; 007import org.hl7.fhir.convertors.conv40_50.datatypes40_50.general40_50.SimpleQuantity40_50; 008import org.hl7.fhir.convertors.conv40_50.datatypes40_50.primitive40_50.Boolean40_50; 009import org.hl7.fhir.convertors.conv40_50.datatypes40_50.primitive40_50.DateTime40_50; 010import org.hl7.fhir.convertors.conv40_50.datatypes40_50.special40_50.Dosage40_50; 011import org.hl7.fhir.convertors.conv40_50.datatypes40_50.special40_50.Reference40_50; 012import org.hl7.fhir.exceptions.FHIRException; 013import org.hl7.fhir.r5.model.MedicationDispense.MedicationDispenseStatusCodesEnumFactory; 014 015/* 016 Copyright (c) 2011+, HL7, Inc. 017 All rights reserved. 018 019 Redistribution and use in source and binary forms, with or without modification, 020 are permitted provided that the following conditions are met: 021 022 * Redistributions of source code must retain the above copyright notice, this 023 list of conditions and the following disclaimer. 024 * Redistributions in binary form must reproduce the above copyright notice, 025 this list of conditions and the following disclaimer in the documentation 026 and/or other materials provided with the distribution. 027 * Neither the name of HL7 nor the names of its contributors may be used to 028 endorse or promote products derived from this software without specific 029 prior written permission. 030 031 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 032 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 033 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 034 IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 035 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 036 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 037 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 038 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 039 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 040 POSSIBILITY OF SUCH DAMAGE. 041 042*/ 043// Generated on Sun, Feb 24, 2019 11:37+1100 for FHIR v4.0.0 044public class MedicationDispense40_50 { 045 046 public static org.hl7.fhir.r5.model.MedicationDispense convertMedicationDispense(org.hl7.fhir.r4.model.MedicationDispense src) throws FHIRException { 047 if (src == null) 048 return null; 049 org.hl7.fhir.r5.model.MedicationDispense tgt = new org.hl7.fhir.r5.model.MedicationDispense(); 050 ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyDomainResource(src, tgt); 051 for (org.hl7.fhir.r4.model.Identifier t : src.getIdentifier()) 052 tgt.addIdentifier(Identifier40_50.convertIdentifier(t)); 053 for (org.hl7.fhir.r4.model.Reference t : src.getPartOf()) tgt.addPartOf(Reference40_50.convertReference(t)); 054 if (src.hasStatus()) 055 tgt.setStatusElement(convertMedicationStatus(src.getStatusElement())); 056// if (src.hasStatusReasonCodeableConcept()) 057// tgt.getStatusReason().setConcept(CodeableConcept40_50.convertCodeableConcept(src.getStatusReasonCodeableConcept())); 058// if (src.hasStatusReasonReference()) 059// tgt.getStatusReason().setReference(Reference40_50.convertReference(src.getStatusReasonReference())); 060 if (src.hasCategory()) 061 tgt.addCategory(CodeableConcept40_50.convertCodeableConcept(src.getCategory())); 062 if (src.hasMedicationCodeableConcept()) 063 tgt.getMedication().setConcept(CodeableConcept40_50.convertCodeableConcept(src.getMedicationCodeableConcept())); 064 if (src.hasMedicationReference()) 065 tgt.getMedication().setReference(Reference40_50.convertReference(src.getMedicationReference())); 066 if (src.hasSubject()) 067 tgt.setSubject(Reference40_50.convertReference(src.getSubject())); 068 if (src.hasContext()) 069 tgt.setEncounter(Reference40_50.convertReference(src.getContext())); 070 for (org.hl7.fhir.r4.model.Reference t : src.getSupportingInformation()) 071 tgt.addSupportingInformation(Reference40_50.convertReference(t)); 072 for (org.hl7.fhir.r4.model.MedicationDispense.MedicationDispensePerformerComponent t : src.getPerformer()) 073 tgt.addPerformer(convertMedicationDispensePerformerComponent(t)); 074 if (src.hasLocation()) 075 tgt.setLocation(Reference40_50.convertReference(src.getLocation())); 076 for (org.hl7.fhir.r4.model.Reference t : src.getAuthorizingPrescription()) 077 tgt.addAuthorizingPrescription(Reference40_50.convertReference(t)); 078 if (src.hasType()) 079 tgt.setType(CodeableConcept40_50.convertCodeableConcept(src.getType())); 080 if (src.hasQuantity()) 081 tgt.setQuantity(SimpleQuantity40_50.convertSimpleQuantity(src.getQuantity())); 082 if (src.hasDaysSupply()) 083 tgt.setDaysSupply(SimpleQuantity40_50.convertSimpleQuantity(src.getDaysSupply())); 084 if (src.hasWhenPrepared()) 085 tgt.setWhenPreparedElement(DateTime40_50.convertDateTime(src.getWhenPreparedElement())); 086 if (src.hasWhenHandedOver()) 087 tgt.setWhenHandedOverElement(DateTime40_50.convertDateTime(src.getWhenHandedOverElement())); 088 if (src.hasDestination()) 089 tgt.setDestination(Reference40_50.convertReference(src.getDestination())); 090 for (org.hl7.fhir.r4.model.Reference t : src.getReceiver()) tgt.addReceiver(Reference40_50.convertReference(t)); 091 for (org.hl7.fhir.r4.model.Annotation t : src.getNote()) tgt.addNote(Annotation40_50.convertAnnotation(t)); 092 for (org.hl7.fhir.r4.model.Dosage t : src.getDosageInstruction()) 093 tgt.addDosageInstruction(Dosage40_50.convertDosage(t)); 094 if (src.hasSubstitution()) 095 tgt.setSubstitution(convertMedicationDispenseSubstitutionComponent(src.getSubstitution())); 096// for (org.hl7.fhir.r4.model.Reference t : src.getDetectedIssue()) 097// tgt.addDetectedIssue(Reference40_50.convertReference(t)); 098 for (org.hl7.fhir.r4.model.Reference t : src.getEventHistory()) 099 tgt.addEventHistory(Reference40_50.convertReference(t)); 100 return tgt; 101 } 102 103 public static org.hl7.fhir.r4.model.MedicationDispense convertMedicationDispense(org.hl7.fhir.r5.model.MedicationDispense src) throws FHIRException { 104 if (src == null) 105 return null; 106 org.hl7.fhir.r4.model.MedicationDispense tgt = new org.hl7.fhir.r4.model.MedicationDispense(); 107 ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyDomainResource(src, tgt); 108 for (org.hl7.fhir.r5.model.Identifier t : src.getIdentifier()) 109 tgt.addIdentifier(Identifier40_50.convertIdentifier(t)); 110 for (org.hl7.fhir.r5.model.Reference t : src.getPartOf()) tgt.addPartOf(Reference40_50.convertReference(t)); 111 if (src.hasStatus()) 112 tgt.setStatusElement(convertStatus(src.getStatusElement())); 113// if (src.getStatusReason().hasConcept()) 114// tgt.setStatusReason(ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().convertType(src.getStatusReason().getConcept())); 115// if (src.getStatusReason().hasReference()) 116// tgt.setStatusReason(ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().convertType(src.getStatusReason().getReference())); 117 if (src.hasCategory()) 118 tgt.setCategory(CodeableConcept40_50.convertCodeableConcept(src.getCategoryFirstRep())); 119 if (src.getMedication().hasConcept()) 120 tgt.setMedication(ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().convertType(src.getMedication().getConcept())); 121 if (src.getMedication().hasReference()) 122 tgt.setMedication(ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().convertType(src.getMedication().getReference())); 123 if (src.hasSubject()) 124 tgt.setSubject(Reference40_50.convertReference(src.getSubject())); 125 if (src.hasEncounter()) 126 tgt.setContext(Reference40_50.convertReference(src.getEncounter())); 127 for (org.hl7.fhir.r5.model.Reference t : src.getSupportingInformation()) 128 tgt.addSupportingInformation(Reference40_50.convertReference(t)); 129 for (org.hl7.fhir.r5.model.MedicationDispense.MedicationDispensePerformerComponent t : src.getPerformer()) 130 tgt.addPerformer(convertMedicationDispensePerformerComponent(t)); 131 if (src.hasLocation()) 132 tgt.setLocation(Reference40_50.convertReference(src.getLocation())); 133 for (org.hl7.fhir.r5.model.Reference t : src.getAuthorizingPrescription()) 134 tgt.addAuthorizingPrescription(Reference40_50.convertReference(t)); 135 if (src.hasType()) 136 tgt.setType(CodeableConcept40_50.convertCodeableConcept(src.getType())); 137 if (src.hasQuantity()) 138 tgt.setQuantity(SimpleQuantity40_50.convertSimpleQuantity(src.getQuantity())); 139 if (src.hasDaysSupply()) 140 tgt.setDaysSupply(SimpleQuantity40_50.convertSimpleQuantity(src.getDaysSupply())); 141 if (src.hasWhenPrepared()) 142 tgt.setWhenPreparedElement(DateTime40_50.convertDateTime(src.getWhenPreparedElement())); 143 if (src.hasWhenHandedOver()) 144 tgt.setWhenHandedOverElement(DateTime40_50.convertDateTime(src.getWhenHandedOverElement())); 145 if (src.hasDestination()) 146 tgt.setDestination(Reference40_50.convertReference(src.getDestination())); 147 for (org.hl7.fhir.r5.model.Reference t : src.getReceiver()) tgt.addReceiver(Reference40_50.convertReference(t)); 148 for (org.hl7.fhir.r5.model.Annotation t : src.getNote()) tgt.addNote(Annotation40_50.convertAnnotation(t)); 149 for (org.hl7.fhir.r5.model.Dosage t : src.getDosageInstruction()) 150 tgt.addDosageInstruction(Dosage40_50.convertDosage(t)); 151 if (src.hasSubstitution()) 152 tgt.setSubstitution(convertMedicationDispenseSubstitutionComponent(src.getSubstitution())); 153// for (org.hl7.fhir.r5.model.Reference t : src.getDetectedIssue()) 154// tgt.addDetectedIssue(Reference40_50.convertReference(t)); 155 for (org.hl7.fhir.r5.model.Reference t : src.getEventHistory()) 156 tgt.addEventHistory(Reference40_50.convertReference(t)); 157 return tgt; 158 } 159 160 private static org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.MedicationDispense.MedicationDispenseStatus> convertStatus(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.MedicationDispense.MedicationDispenseStatusCodes> src) { 161 if (src == null) 162 return null; 163 org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.MedicationDispense.MedicationDispenseStatus> tgt = new org.hl7.fhir.r4.model.Enumeration<>(new org.hl7.fhir.r4.model.MedicationDispense.MedicationDispenseStatusEnumFactory()); 164 ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt); 165 switch (src.getValue()) { 166 case CANCELLED: 167 tgt.setValue(org.hl7.fhir.r4.model.MedicationDispense.MedicationDispenseStatus.CANCELLED); 168 break; 169 case COMPLETED: 170 tgt.setValue(org.hl7.fhir.r4.model.MedicationDispense.MedicationDispenseStatus.COMPLETED); 171 break; 172 case DECLINED: 173 tgt.setValue(org.hl7.fhir.r4.model.MedicationDispense.MedicationDispenseStatus.DECLINED); 174 break; 175 case ENTEREDINERROR: 176 tgt.setValue(org.hl7.fhir.r4.model.MedicationDispense.MedicationDispenseStatus.ENTEREDINERROR); 177 break; 178 case INPROGRESS: 179 tgt.setValue(org.hl7.fhir.r4.model.MedicationDispense.MedicationDispenseStatus.INPROGRESS); 180 break; 181 case NULL: 182 tgt.setValue(org.hl7.fhir.r4.model.MedicationDispense.MedicationDispenseStatus.NULL); 183 break; 184 case ONHOLD: 185 tgt.setValue(org.hl7.fhir.r4.model.MedicationDispense.MedicationDispenseStatus.ONHOLD); 186 break; 187 case PREPARATION: 188 tgt.setValue(org.hl7.fhir.r4.model.MedicationDispense.MedicationDispenseStatus.PREPARATION); 189 break; 190 case STOPPED: 191 tgt.setValue(org.hl7.fhir.r4.model.MedicationDispense.MedicationDispenseStatus.STOPPED); 192 break; 193 case UNKNOWN: 194 tgt.setValue(org.hl7.fhir.r4.model.MedicationDispense.MedicationDispenseStatus.UNKNOWN); 195 break; 196 } 197 return tgt; 198 } 199 200 private static org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.MedicationDispense.MedicationDispenseStatusCodes> convertMedicationStatus(org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.MedicationDispense.MedicationDispenseStatus> src) { 201 if (src == null) 202 return null; 203 org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.MedicationDispense.MedicationDispenseStatusCodes> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new MedicationDispenseStatusCodesEnumFactory()); 204 ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt); 205 switch (src.getValue()) { 206 case CANCELLED: 207 tgt.setValue(org.hl7.fhir.r5.model.MedicationDispense.MedicationDispenseStatusCodes.CANCELLED); 208 break; 209 case COMPLETED: 210 tgt.setValue(org.hl7.fhir.r5.model.MedicationDispense.MedicationDispenseStatusCodes.COMPLETED); 211 break; 212 case DECLINED: 213 tgt.setValue(org.hl7.fhir.r5.model.MedicationDispense.MedicationDispenseStatusCodes.DECLINED); 214 break; 215 case ENTEREDINERROR: 216 tgt.setValue(org.hl7.fhir.r5.model.MedicationDispense.MedicationDispenseStatusCodes.ENTEREDINERROR); 217 break; 218 case INPROGRESS: 219 tgt.setValue(org.hl7.fhir.r5.model.MedicationDispense.MedicationDispenseStatusCodes.INPROGRESS); 220 break; 221 case NULL: 222 tgt.setValue(org.hl7.fhir.r5.model.MedicationDispense.MedicationDispenseStatusCodes.NULL); 223 break; 224 case ONHOLD: 225 tgt.setValue(org.hl7.fhir.r5.model.MedicationDispense.MedicationDispenseStatusCodes.ONHOLD); 226 break; 227 case PREPARATION: 228 tgt.setValue(org.hl7.fhir.r5.model.MedicationDispense.MedicationDispenseStatusCodes.PREPARATION); 229 break; 230 case STOPPED: 231 tgt.setValue(org.hl7.fhir.r5.model.MedicationDispense.MedicationDispenseStatusCodes.STOPPED); 232 break; 233 case UNKNOWN: 234 tgt.setValue(org.hl7.fhir.r5.model.MedicationDispense.MedicationDispenseStatusCodes.UNKNOWN); 235 break; 236 } 237 return tgt; 238 } 239 240 public static org.hl7.fhir.r5.model.MedicationDispense.MedicationDispensePerformerComponent convertMedicationDispensePerformerComponent(org.hl7.fhir.r4.model.MedicationDispense.MedicationDispensePerformerComponent src) throws FHIRException { 241 if (src == null) 242 return null; 243 org.hl7.fhir.r5.model.MedicationDispense.MedicationDispensePerformerComponent tgt = new org.hl7.fhir.r5.model.MedicationDispense.MedicationDispensePerformerComponent(); 244 ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyBackboneElement(src, tgt); 245 if (src.hasFunction()) 246 tgt.setFunction(CodeableConcept40_50.convertCodeableConcept(src.getFunction())); 247 if (src.hasActor()) 248 tgt.setActor(Reference40_50.convertReference(src.getActor())); 249 return tgt; 250 } 251 252 public static org.hl7.fhir.r4.model.MedicationDispense.MedicationDispensePerformerComponent convertMedicationDispensePerformerComponent(org.hl7.fhir.r5.model.MedicationDispense.MedicationDispensePerformerComponent src) throws FHIRException { 253 if (src == null) 254 return null; 255 org.hl7.fhir.r4.model.MedicationDispense.MedicationDispensePerformerComponent tgt = new org.hl7.fhir.r4.model.MedicationDispense.MedicationDispensePerformerComponent(); 256 ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyBackboneElement(src, tgt); 257 if (src.hasFunction()) 258 tgt.setFunction(CodeableConcept40_50.convertCodeableConcept(src.getFunction())); 259 if (src.hasActor()) 260 tgt.setActor(Reference40_50.convertReference(src.getActor())); 261 return tgt; 262 } 263 264 public static org.hl7.fhir.r5.model.MedicationDispense.MedicationDispenseSubstitutionComponent convertMedicationDispenseSubstitutionComponent(org.hl7.fhir.r4.model.MedicationDispense.MedicationDispenseSubstitutionComponent src) throws FHIRException { 265 if (src == null) 266 return null; 267 org.hl7.fhir.r5.model.MedicationDispense.MedicationDispenseSubstitutionComponent tgt = new org.hl7.fhir.r5.model.MedicationDispense.MedicationDispenseSubstitutionComponent(); 268 ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyBackboneElement(src, tgt); 269 if (src.hasWasSubstituted()) 270 tgt.setWasSubstitutedElement(Boolean40_50.convertBoolean(src.getWasSubstitutedElement())); 271 if (src.hasType()) 272 tgt.setType(CodeableConcept40_50.convertCodeableConcept(src.getType())); 273 for (org.hl7.fhir.r4.model.CodeableConcept t : src.getReason()) 274 tgt.addReason(CodeableConcept40_50.convertCodeableConcept(t)); 275 for (org.hl7.fhir.r4.model.Reference t : src.getResponsibleParty()) 276 tgt.setResponsibleParty(Reference40_50.convertReference(t)); 277 return tgt; 278 } 279 280 public static org.hl7.fhir.r4.model.MedicationDispense.MedicationDispenseSubstitutionComponent convertMedicationDispenseSubstitutionComponent(org.hl7.fhir.r5.model.MedicationDispense.MedicationDispenseSubstitutionComponent src) throws FHIRException { 281 if (src == null) 282 return null; 283 org.hl7.fhir.r4.model.MedicationDispense.MedicationDispenseSubstitutionComponent tgt = new org.hl7.fhir.r4.model.MedicationDispense.MedicationDispenseSubstitutionComponent(); 284 ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyBackboneElement(src, tgt); 285 if (src.hasWasSubstituted()) 286 tgt.setWasSubstitutedElement(Boolean40_50.convertBoolean(src.getWasSubstitutedElement())); 287 if (src.hasType()) 288 tgt.setType(CodeableConcept40_50.convertCodeableConcept(src.getType())); 289 for (org.hl7.fhir.r5.model.CodeableConcept t : src.getReason()) 290 tgt.addReason(CodeableConcept40_50.convertCodeableConcept(t)); 291 if (src.hasResponsibleParty()) 292 tgt.addResponsibleParty(Reference40_50.convertReference(src.getResponsibleParty())); 293 return tgt; 294 } 295}