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