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