001package org.hl7.fhir.convertors.conv10_50.resources10_50; 002 003import org.hl7.fhir.convertors.context.ConversionContext10_50; 004import org.hl7.fhir.convertors.conv10_50.datatypes10_50.Reference10_50; 005import org.hl7.fhir.convertors.conv10_50.datatypes10_50.complextypes10_50.*; 006import org.hl7.fhir.convertors.conv10_50.datatypes10_50.primitivetypes10_50.DateTime10_50; 007import org.hl7.fhir.convertors.conv10_50.datatypes10_50.primitivetypes10_50.String10_50; 008import org.hl7.fhir.exceptions.FHIRException; 009import org.hl7.fhir.r5.model.Dosage; 010import org.hl7.fhir.r5.model.Dosage.DosageDoseAndRateComponent; 011import org.hl7.fhir.r5.model.MedicationDispense.MedicationDispenseStatusCodesEnumFactory; 012 013public class MedicationDispense10_50 { 014 015 public static org.hl7.fhir.r5.model.MedicationDispense convertMedicationDispense(org.hl7.fhir.dstu2.model.MedicationDispense src) throws FHIRException { 016 if (src == null || src.isEmpty()) 017 return null; 018 org.hl7.fhir.r5.model.MedicationDispense tgt = new org.hl7.fhir.r5.model.MedicationDispense(); 019 ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyDomainResource(src, tgt); 020 if (src.hasIdentifier()) 021 tgt.addIdentifier(Identifier10_50.convertIdentifier(src.getIdentifier())); 022 if (src.hasStatusElement()) 023 tgt.setStatusElement(convertMedicationDispenseStatus(src.getStatusElement())); 024 if (src.hasMedicationCodeableConcept()) 025 tgt.getMedication().setConcept(CodeableConcept10_50.convertCodeableConcept(src.getMedicationCodeableConcept())); 026 if (src.hasMedicationReference()) 027 tgt.getMedication().setReference(Reference10_50.convertReference(src.getMedicationReference())); 028 if (src.hasPatient()) 029 tgt.setSubject(Reference10_50.convertReference(src.getPatient())); 030 for (org.hl7.fhir.dstu2.model.Reference t : src.getAuthorizingPrescription()) 031 tgt.addAuthorizingPrescription(Reference10_50.convertReference(t)); 032 if (src.hasType()) 033 tgt.setType(CodeableConcept10_50.convertCodeableConcept(src.getType())); 034 if (src.hasQuantity()) 035 tgt.setQuantity(SimpleQuantity10_50.convertSimpleQuantity(src.getQuantity())); 036 if (src.hasDaysSupply()) 037 tgt.setDaysSupply(SimpleQuantity10_50.convertSimpleQuantity(src.getDaysSupply())); 038 if (src.hasWhenPreparedElement()) 039 tgt.setWhenPreparedElement(DateTime10_50.convertDateTime(src.getWhenPreparedElement())); 040 if (src.hasWhenHandedOverElement()) 041 tgt.setWhenHandedOverElement(DateTime10_50.convertDateTime(src.getWhenHandedOverElement())); 042 if (src.hasDestination()) 043 tgt.setDestination(Reference10_50.convertReference(src.getDestination())); 044 for (org.hl7.fhir.dstu2.model.Reference t : src.getReceiver()) tgt.addReceiver(Reference10_50.convertReference(t)); 045 if (src.hasNote()) 046 tgt.addNote().setText(src.getNote()); 047 for (org.hl7.fhir.dstu2.model.MedicationDispense.MedicationDispenseDosageInstructionComponent t : src.getDosageInstruction()) 048 tgt.addDosageInstruction(convertMedicationDispenseDosageInstructionComponent(t)); 049 if (src.hasSubstitution()) 050 tgt.setSubstitution(convertMedicationDispenseSubstitutionComponent(src.getSubstitution())); 051 return tgt; 052 } 053 054 public static org.hl7.fhir.dstu2.model.MedicationDispense convertMedicationDispense(org.hl7.fhir.r5.model.MedicationDispense src) throws FHIRException { 055 if (src == null || src.isEmpty()) 056 return null; 057 org.hl7.fhir.dstu2.model.MedicationDispense tgt = new org.hl7.fhir.dstu2.model.MedicationDispense(); 058 ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyDomainResource(src, tgt); 059 if (src.hasIdentifier()) 060 tgt.setIdentifier(Identifier10_50.convertIdentifier(src.getIdentifierFirstRep())); 061 if (src.hasStatusElement()) 062 tgt.setStatusElement(convertMedicationDispenseStatus(src.getStatusElement())); 063 if (src.getMedication().hasConcept()) 064 tgt.setMedication(ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().convertType(src.getMedication().getConcept())); 065 if (src.getMedication().hasReference()) 066 tgt.setMedication(ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().convertType(src.getMedication().getReference())); 067 if (src.hasSubject()) 068 tgt.setPatient(Reference10_50.convertReference(src.getSubject())); 069 for (org.hl7.fhir.r5.model.Reference t : src.getAuthorizingPrescription()) 070 tgt.addAuthorizingPrescription(Reference10_50.convertReference(t)); 071 if (src.hasType()) 072 tgt.setType(CodeableConcept10_50.convertCodeableConcept(src.getType())); 073 if (src.hasQuantity()) 074 tgt.setQuantity(SimpleQuantity10_50.convertSimpleQuantity(src.getQuantity())); 075 if (src.hasDaysSupply()) 076 tgt.setDaysSupply(SimpleQuantity10_50.convertSimpleQuantity(src.getDaysSupply())); 077 if (src.hasWhenPreparedElement()) 078 tgt.setWhenPreparedElement(DateTime10_50.convertDateTime(src.getWhenPreparedElement())); 079 if (src.hasWhenHandedOverElement()) 080 tgt.setWhenHandedOverElement(DateTime10_50.convertDateTime(src.getWhenHandedOverElement())); 081 if (src.hasDestination()) 082 tgt.setDestination(Reference10_50.convertReference(src.getDestination())); 083 for (org.hl7.fhir.r5.model.Reference t : src.getReceiver()) tgt.addReceiver(Reference10_50.convertReference(t)); 084 for (org.hl7.fhir.r5.model.Annotation t : src.getNote()) tgt.setNote(t.getText()); 085 for (org.hl7.fhir.r5.model.Dosage t : src.getDosageInstruction()) 086 tgt.addDosageInstruction(convertMedicationDispenseDosageInstructionComponent(t)); 087 if (src.hasSubstitution()) 088 tgt.setSubstitution(convertMedicationDispenseSubstitutionComponent(src.getSubstitution())); 089 return tgt; 090 } 091 092 public static org.hl7.fhir.r5.model.Dosage convertMedicationDispenseDosageInstructionComponent(org.hl7.fhir.dstu2.model.MedicationDispense.MedicationDispenseDosageInstructionComponent src) throws FHIRException { 093 if (src == null || src.isEmpty()) 094 return null; 095 org.hl7.fhir.r5.model.Dosage tgt = new org.hl7.fhir.r5.model.Dosage(); 096 ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyElement(src, tgt); 097 if (src.hasTextElement()) 098 tgt.setTextElement(String10_50.convertString(src.getTextElement())); 099 if (src.hasTiming()) 100 tgt.setTiming(Timing10_50.convertTiming(src.getTiming())); 101 if (src.hasAsNeeded()) 102 tgt.setAsNeeded(ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().convertType(src.getAsNeeded())); 103 if (src.hasSiteCodeableConcept()) 104 tgt.setSite(CodeableConcept10_50.convertCodeableConcept(src.getSiteCodeableConcept())); 105 if (src.hasRoute()) 106 tgt.setRoute(CodeableConcept10_50.convertCodeableConcept(src.getRoute())); 107 if (src.hasMethod()) 108 tgt.setMethod(CodeableConcept10_50.convertCodeableConcept(src.getMethod())); 109 if (src.hasDose() || src.hasRate()) { 110 DosageDoseAndRateComponent dr = tgt.addDoseAndRate(); 111 if (src.hasDose()) 112 dr.setDose(ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().convertType(src.getDose())); 113 if (src.hasRate()) 114 dr.setRate(ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().convertType(src.getRate())); 115 } 116 if (src.hasMaxDosePerPeriod()) 117 tgt.setMaxDosePerPeriod(Ratio10_50.convertRatio(src.getMaxDosePerPeriod())); 118 return tgt; 119 } 120 121 public static org.hl7.fhir.dstu2.model.MedicationDispense.MedicationDispenseDosageInstructionComponent convertMedicationDispenseDosageInstructionComponent(Dosage src) throws FHIRException { 122 if (src == null || src.isEmpty()) 123 return null; 124 org.hl7.fhir.dstu2.model.MedicationDispense.MedicationDispenseDosageInstructionComponent tgt = new org.hl7.fhir.dstu2.model.MedicationDispense.MedicationDispenseDosageInstructionComponent(); 125 ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyElement(src, tgt); 126 tgt.setText(src.getText()); 127 tgt.setTiming(Timing10_50.convertTiming(src.getTiming())); 128 tgt.setAsNeeded(ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().convertType(src.getAsNeeded())); 129 tgt.setSite(ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().convertType(src.getSite())); 130 tgt.setRoute(CodeableConcept10_50.convertCodeableConcept(src.getRoute())); 131 tgt.setMethod(CodeableConcept10_50.convertCodeableConcept(src.getMethod())); 132 if (src.hasDoseAndRate() && src.getDoseAndRate().get(0).hasDose()) 133 tgt.setDose(ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().convertType(src.getDoseAndRate().get(0).getDose())); 134 tgt.setMaxDosePerPeriod(Ratio10_50.convertRatio(src.getMaxDosePerPeriod())); 135 if (src.hasDoseAndRate() && src.getDoseAndRate().get(0).hasRate()) 136 tgt.setRate(ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().convertType(src.getDoseAndRate().get(0).getRate())); 137 return tgt; 138 } 139 140 public static org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.MedicationDispense.MedicationDispenseStatusCodes> convertMedicationDispenseStatus(org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.MedicationDispense.MedicationDispenseStatus> src) throws FHIRException { 141 if (src == null) 142 return null; 143 org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.MedicationDispense.MedicationDispenseStatusCodes> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new MedicationDispenseStatusCodesEnumFactory()); 144 ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyElement(src, tgt); 145 switch (src.getValue()) { 146 case COMPLETED: 147 tgt.setValue(org.hl7.fhir.r5.model.MedicationDispense.MedicationDispenseStatusCodes.COMPLETED); 148 break; 149 case ENTEREDINERROR: 150 tgt.setValue(org.hl7.fhir.r5.model.MedicationDispense.MedicationDispenseStatusCodes.ENTEREDINERROR); 151 break; 152 case INPROGRESS: 153 tgt.setValue(org.hl7.fhir.r5.model.MedicationDispense.MedicationDispenseStatusCodes.INPROGRESS); 154 break; 155 case NULL: 156 tgt.setValue(org.hl7.fhir.r5.model.MedicationDispense.MedicationDispenseStatusCodes.NULL); 157 break; 158 case ONHOLD: 159 tgt.setValue(org.hl7.fhir.r5.model.MedicationDispense.MedicationDispenseStatusCodes.ONHOLD); 160 break; 161 case STOPPED: 162 tgt.setValue(org.hl7.fhir.r5.model.MedicationDispense.MedicationDispenseStatusCodes.STOPPED); 163 break; 164 } 165 return tgt; 166 } 167 168 public static org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.MedicationDispense.MedicationDispenseStatus> convertMedicationDispenseStatus(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.MedicationDispense.MedicationDispenseStatusCodes> src) throws FHIRException { 169 if (src == null) 170 return null; 171 org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.MedicationDispense.MedicationDispenseStatus> tgt = new org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.MedicationDispense.MedicationDispenseStatus>(new org.hl7.fhir.dstu2.model.MedicationDispense.MedicationDispenseStatusEnumFactory()); 172 ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyElement(src, tgt); 173 switch (src.getValue()) { 174 case COMPLETED: 175 tgt.setValue(org.hl7.fhir.dstu2.model.MedicationDispense.MedicationDispenseStatus.COMPLETED); 176 break; 177 case ENTEREDINERROR: 178 tgt.setValue(org.hl7.fhir.dstu2.model.MedicationDispense.MedicationDispenseStatus.ENTEREDINERROR); 179 break; 180 case INPROGRESS: 181 tgt.setValue(org.hl7.fhir.dstu2.model.MedicationDispense.MedicationDispenseStatus.INPROGRESS); 182 break; 183 case NULL: 184 tgt.setValue(org.hl7.fhir.dstu2.model.MedicationDispense.MedicationDispenseStatus.NULL); 185 break; 186 case ONHOLD: 187 tgt.setValue(org.hl7.fhir.dstu2.model.MedicationDispense.MedicationDispenseStatus.ONHOLD); 188 break; 189 case STOPPED: 190 tgt.setValue(org.hl7.fhir.dstu2.model.MedicationDispense.MedicationDispenseStatus.STOPPED); 191 break; 192 } 193 return tgt; 194 } 195 196 public static org.hl7.fhir.dstu2.model.MedicationDispense.MedicationDispenseSubstitutionComponent convertMedicationDispenseSubstitutionComponent(org.hl7.fhir.r5.model.MedicationDispense.MedicationDispenseSubstitutionComponent src) throws FHIRException { 197 if (src == null || src.isEmpty()) 198 return null; 199 org.hl7.fhir.dstu2.model.MedicationDispense.MedicationDispenseSubstitutionComponent tgt = new org.hl7.fhir.dstu2.model.MedicationDispense.MedicationDispenseSubstitutionComponent(); 200 ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyElement(src, tgt); 201 if (src.hasType()) 202 tgt.setType(CodeableConcept10_50.convertCodeableConcept(src.getType())); 203 for (org.hl7.fhir.r5.model.CodeableConcept t : src.getReason()) 204 tgt.addReason(CodeableConcept10_50.convertCodeableConcept(t)); 205 if (src.hasResponsibleParty()) 206 tgt.addResponsibleParty(Reference10_50.convertReference(src.getResponsibleParty())); 207 return tgt; 208 } 209 210 public static org.hl7.fhir.r5.model.MedicationDispense.MedicationDispenseSubstitutionComponent convertMedicationDispenseSubstitutionComponent(org.hl7.fhir.dstu2.model.MedicationDispense.MedicationDispenseSubstitutionComponent src) throws FHIRException { 211 if (src == null || src.isEmpty()) 212 return null; 213 org.hl7.fhir.r5.model.MedicationDispense.MedicationDispenseSubstitutionComponent tgt = new org.hl7.fhir.r5.model.MedicationDispense.MedicationDispenseSubstitutionComponent(); 214 ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyElement(src, tgt); 215 if (src.hasType()) 216 tgt.setType(CodeableConcept10_50.convertCodeableConcept(src.getType())); 217 for (org.hl7.fhir.dstu2.model.CodeableConcept t : src.getReason()) 218 tgt.addReason(CodeableConcept10_50.convertCodeableConcept(t)); 219 for (org.hl7.fhir.dstu2.model.Reference t : src.getResponsibleParty()) 220 tgt.setResponsibleParty(Reference10_50.convertReference(t)); 221 return tgt; 222 } 223}