001package org.hl7.fhir.convertors.conv30_40.resources30_40;
002
003import org.hl7.fhir.convertors.context.ConversionContext30_40;
004import org.hl7.fhir.convertors.conv30_40.datatypes30_40.Dosage30_40;
005import org.hl7.fhir.convertors.conv30_40.datatypes30_40.Reference30_40;
006import org.hl7.fhir.convertors.conv30_40.datatypes30_40.complextypes30_40.Annotation30_40;
007import org.hl7.fhir.convertors.conv30_40.datatypes30_40.complextypes30_40.CodeableConcept30_40;
008import org.hl7.fhir.convertors.conv30_40.datatypes30_40.complextypes30_40.Identifier30_40;
009import org.hl7.fhir.convertors.conv30_40.datatypes30_40.complextypes30_40.SimpleQuantity30_40;
010import org.hl7.fhir.convertors.conv30_40.datatypes30_40.primitivetypes30_40.Boolean30_40;
011import org.hl7.fhir.convertors.conv30_40.datatypes30_40.primitivetypes30_40.DateTime30_40;
012import org.hl7.fhir.exceptions.FHIRException;
013
014public class MedicationDispense30_40 {
015
016  public static org.hl7.fhir.dstu3.model.MedicationDispense convertMedicationDispense(org.hl7.fhir.r4.model.MedicationDispense src) throws FHIRException {
017    if (src == null)
018      return null;
019    org.hl7.fhir.dstu3.model.MedicationDispense tgt = new org.hl7.fhir.dstu3.model.MedicationDispense();
020    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyDomainResource(src, tgt);
021    for (org.hl7.fhir.r4.model.Identifier t : src.getIdentifier())
022      tgt.addIdentifier(Identifier30_40.convertIdentifier(t));
023    for (org.hl7.fhir.r4.model.Reference t : src.getPartOf()) tgt.addPartOf(Reference30_40.convertReference(t));
024    if (src.hasStatus())
025      tgt.setStatusElement(convertMedicationDispenseStatus(src.getStatusElement()));
026    if (src.hasCategory())
027      tgt.setCategory(CodeableConcept30_40.convertCodeableConcept(src.getCategory()));
028    if (src.hasMedication())
029      tgt.setMedication(ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().convertType(src.getMedication()));
030    if (src.hasSubject())
031      tgt.setSubject(Reference30_40.convertReference(src.getSubject()));
032    if (src.hasContext())
033      tgt.setContext(Reference30_40.convertReference(src.getContext()));
034    for (org.hl7.fhir.r4.model.Reference t : src.getSupportingInformation())
035      tgt.addSupportingInformation(Reference30_40.convertReference(t));
036    for (org.hl7.fhir.r4.model.MedicationDispense.MedicationDispensePerformerComponent t : src.getPerformer())
037      tgt.addPerformer(convertMedicationDispensePerformerComponent(t));
038    for (org.hl7.fhir.r4.model.Reference t : src.getAuthorizingPrescription())
039      tgt.addAuthorizingPrescription(Reference30_40.convertReference(t));
040    if (src.hasType())
041      tgt.setType(CodeableConcept30_40.convertCodeableConcept(src.getType()));
042    if (src.hasQuantity())
043      tgt.setQuantity(SimpleQuantity30_40.convertSimpleQuantity(src.getQuantity()));
044    if (src.hasDaysSupply())
045      tgt.setDaysSupply(SimpleQuantity30_40.convertSimpleQuantity(src.getDaysSupply()));
046    if (src.hasWhenPrepared())
047      tgt.setWhenPreparedElement(DateTime30_40.convertDateTime(src.getWhenPreparedElement()));
048    if (src.hasWhenHandedOver())
049      tgt.setWhenHandedOverElement(DateTime30_40.convertDateTime(src.getWhenHandedOverElement()));
050    if (src.hasDestination())
051      tgt.setDestination(Reference30_40.convertReference(src.getDestination()));
052    for (org.hl7.fhir.r4.model.Reference t : src.getReceiver()) tgt.addReceiver(Reference30_40.convertReference(t));
053    for (org.hl7.fhir.r4.model.Annotation t : src.getNote()) tgt.addNote(Annotation30_40.convertAnnotation(t));
054    for (org.hl7.fhir.r4.model.Dosage t : src.getDosageInstruction())
055      tgt.addDosageInstruction(Dosage30_40.convertDosage(t));
056    if (src.hasSubstitution())
057      tgt.setSubstitution(convertMedicationDispenseSubstitutionComponent(src.getSubstitution()));
058    for (org.hl7.fhir.r4.model.Reference t : src.getDetectedIssue())
059      tgt.addDetectedIssue(Reference30_40.convertReference(t));
060    for (org.hl7.fhir.r4.model.Reference t : src.getEventHistory())
061      tgt.addEventHistory(Reference30_40.convertReference(t));
062    return tgt;
063  }
064
065  public static org.hl7.fhir.r4.model.MedicationDispense convertMedicationDispense(org.hl7.fhir.dstu3.model.MedicationDispense src) throws FHIRException {
066    if (src == null)
067      return null;
068    org.hl7.fhir.r4.model.MedicationDispense tgt = new org.hl7.fhir.r4.model.MedicationDispense();
069    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyDomainResource(src, tgt);
070    for (org.hl7.fhir.dstu3.model.Identifier t : src.getIdentifier())
071      tgt.addIdentifier(Identifier30_40.convertIdentifier(t));
072    for (org.hl7.fhir.dstu3.model.Reference t : src.getPartOf()) tgt.addPartOf(Reference30_40.convertReference(t));
073    if (src.hasStatus())
074      tgt.setStatusElement(convertMedicationDispenseStatus(src.getStatusElement()));
075    if (src.hasCategory())
076      tgt.setCategory(CodeableConcept30_40.convertCodeableConcept(src.getCategory()));
077    if (src.hasMedication())
078      tgt.setMedication(ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().convertType(src.getMedication()));
079    if (src.hasSubject())
080      tgt.setSubject(Reference30_40.convertReference(src.getSubject()));
081    if (src.hasContext())
082      tgt.setContext(Reference30_40.convertReference(src.getContext()));
083    for (org.hl7.fhir.dstu3.model.Reference t : src.getSupportingInformation())
084      tgt.addSupportingInformation(Reference30_40.convertReference(t));
085    for (org.hl7.fhir.dstu3.model.MedicationDispense.MedicationDispensePerformerComponent t : src.getPerformer())
086      tgt.addPerformer(convertMedicationDispensePerformerComponent(t));
087    for (org.hl7.fhir.dstu3.model.Reference t : src.getAuthorizingPrescription())
088      tgt.addAuthorizingPrescription(Reference30_40.convertReference(t));
089    if (src.hasType())
090      tgt.setType(CodeableConcept30_40.convertCodeableConcept(src.getType()));
091    if (src.hasQuantity())
092      tgt.setQuantity(SimpleQuantity30_40.convertSimpleQuantity(src.getQuantity()));
093    if (src.hasDaysSupply())
094      tgt.setDaysSupply(SimpleQuantity30_40.convertSimpleQuantity(src.getDaysSupply()));
095    if (src.hasWhenPrepared())
096      tgt.setWhenPreparedElement(DateTime30_40.convertDateTime(src.getWhenPreparedElement()));
097    if (src.hasWhenHandedOver())
098      tgt.setWhenHandedOverElement(DateTime30_40.convertDateTime(src.getWhenHandedOverElement()));
099    if (src.hasDestination())
100      tgt.setDestination(Reference30_40.convertReference(src.getDestination()));
101    for (org.hl7.fhir.dstu3.model.Reference t : src.getReceiver()) tgt.addReceiver(Reference30_40.convertReference(t));
102    for (org.hl7.fhir.dstu3.model.Annotation t : src.getNote()) tgt.addNote(Annotation30_40.convertAnnotation(t));
103    for (org.hl7.fhir.dstu3.model.Dosage t : src.getDosageInstruction())
104      tgt.addDosageInstruction(Dosage30_40.convertDosage(t));
105    if (src.hasSubstitution())
106      tgt.setSubstitution(convertMedicationDispenseSubstitutionComponent(src.getSubstitution()));
107    for (org.hl7.fhir.dstu3.model.Reference t : src.getDetectedIssue())
108      tgt.addDetectedIssue(Reference30_40.convertReference(t));
109    for (org.hl7.fhir.dstu3.model.Reference t : src.getEventHistory())
110      tgt.addEventHistory(Reference30_40.convertReference(t));
111    return tgt;
112  }
113
114  public static org.hl7.fhir.dstu3.model.MedicationDispense.MedicationDispensePerformerComponent convertMedicationDispensePerformerComponent(org.hl7.fhir.r4.model.MedicationDispense.MedicationDispensePerformerComponent src) throws FHIRException {
115    if (src == null)
116      return null;
117    org.hl7.fhir.dstu3.model.MedicationDispense.MedicationDispensePerformerComponent tgt = new org.hl7.fhir.dstu3.model.MedicationDispense.MedicationDispensePerformerComponent();
118    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyBackboneElement(src,tgt);
119    if (src.hasActor())
120      tgt.setActor(Reference30_40.convertReference(src.getActor()));
121    return tgt;
122  }
123
124  public static org.hl7.fhir.r4.model.MedicationDispense.MedicationDispensePerformerComponent convertMedicationDispensePerformerComponent(org.hl7.fhir.dstu3.model.MedicationDispense.MedicationDispensePerformerComponent src) throws FHIRException {
125    if (src == null)
126      return null;
127    org.hl7.fhir.r4.model.MedicationDispense.MedicationDispensePerformerComponent tgt = new org.hl7.fhir.r4.model.MedicationDispense.MedicationDispensePerformerComponent();
128    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyBackboneElement(src,tgt);
129    if (src.hasActor())
130      tgt.setActor(Reference30_40.convertReference(src.getActor()));
131    return tgt;
132  }
133
134  private static org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.MedicationDispense.MedicationDispenseStatus> convertMedicationDispenseStatus(org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.MedicationDispense.MedicationDispenseStatus> src) {
135    if (src == null)
136      return null;
137    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());
138    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyElement(src, tgt);
139    switch (src.getValue()) {
140      case COMPLETED:
141        tgt.setValue(org.hl7.fhir.r4.model.MedicationDispense.MedicationDispenseStatus.COMPLETED);
142        break;
143      case ENTEREDINERROR:
144        tgt.setValue(org.hl7.fhir.r4.model.MedicationDispense.MedicationDispenseStatus.ENTEREDINERROR);
145        break;
146      case INPROGRESS:
147        tgt.setValue(org.hl7.fhir.r4.model.MedicationDispense.MedicationDispenseStatus.INPROGRESS);
148        break;
149      case NULL:
150        tgt.setValue(org.hl7.fhir.r4.model.MedicationDispense.MedicationDispenseStatus.NULL);
151        break;
152      case ONHOLD:
153        tgt.setValue(org.hl7.fhir.r4.model.MedicationDispense.MedicationDispenseStatus.ONHOLD);
154        break;
155      case PREPARATION:
156        tgt.setValue(org.hl7.fhir.r4.model.MedicationDispense.MedicationDispenseStatus.PREPARATION);
157        break;
158      case STOPPED:
159        tgt.setValue(org.hl7.fhir.r4.model.MedicationDispense.MedicationDispenseStatus.STOPPED);
160        break;
161    }
162    return tgt;
163  }
164
165  private static org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.MedicationDispense.MedicationDispenseStatus> convertMedicationDispenseStatus(org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.MedicationDispense.MedicationDispenseStatus> src) {
166    if (src == null)
167      return null;
168    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());
169    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyElement(src, tgt);
170    switch (src.getValue()) {
171      case CANCELLED:
172        tgt.setValue(org.hl7.fhir.dstu3.model.MedicationDispense.MedicationDispenseStatus.STOPPED);
173        break;
174      case COMPLETED:
175        tgt.setValue(org.hl7.fhir.dstu3.model.MedicationDispense.MedicationDispenseStatus.COMPLETED);
176        break;
177      case DECLINED:
178        tgt.setValue(org.hl7.fhir.dstu3.model.MedicationDispense.MedicationDispenseStatus.STOPPED);
179        break;
180      case ENTEREDINERROR:
181        tgt.setValue(org.hl7.fhir.dstu3.model.MedicationDispense.MedicationDispenseStatus.ENTEREDINERROR);
182        break;
183      case INPROGRESS:
184        tgt.setValue(org.hl7.fhir.dstu3.model.MedicationDispense.MedicationDispenseStatus.INPROGRESS);
185        break;
186      case NULL:
187        tgt.setValue(org.hl7.fhir.dstu3.model.MedicationDispense.MedicationDispenseStatus.NULL);
188        break;
189      case ONHOLD:
190        tgt.setValue(org.hl7.fhir.dstu3.model.MedicationDispense.MedicationDispenseStatus.ONHOLD);
191        break;
192      case PREPARATION:
193        tgt.setValue(org.hl7.fhir.dstu3.model.MedicationDispense.MedicationDispenseStatus.PREPARATION);
194        break;
195      case STOPPED:
196        tgt.setValue(org.hl7.fhir.dstu3.model.MedicationDispense.MedicationDispenseStatus.STOPPED);
197        break;
198      case UNKNOWN:
199        tgt.setValue(org.hl7.fhir.dstu3.model.MedicationDispense.MedicationDispenseStatus.NULL);
200        break;
201    }
202    return tgt;
203  }
204
205  public static org.hl7.fhir.r4.model.MedicationDispense.MedicationDispenseSubstitutionComponent convertMedicationDispenseSubstitutionComponent(org.hl7.fhir.dstu3.model.MedicationDispense.MedicationDispenseSubstitutionComponent src) throws FHIRException {
206    if (src == null)
207      return null;
208    org.hl7.fhir.r4.model.MedicationDispense.MedicationDispenseSubstitutionComponent tgt = new org.hl7.fhir.r4.model.MedicationDispense.MedicationDispenseSubstitutionComponent();
209    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyBackboneElement(src,tgt);
210    if (src.hasWasSubstituted())
211      tgt.setWasSubstitutedElement(Boolean30_40.convertBoolean(src.getWasSubstitutedElement()));
212    if (src.hasType())
213      tgt.setType(CodeableConcept30_40.convertCodeableConcept(src.getType()));
214    for (org.hl7.fhir.dstu3.model.CodeableConcept t : src.getReason())
215      tgt.addReason(CodeableConcept30_40.convertCodeableConcept(t));
216    for (org.hl7.fhir.dstu3.model.Reference t : src.getResponsibleParty())
217      tgt.addResponsibleParty(Reference30_40.convertReference(t));
218    return tgt;
219  }
220
221  public static org.hl7.fhir.dstu3.model.MedicationDispense.MedicationDispenseSubstitutionComponent convertMedicationDispenseSubstitutionComponent(org.hl7.fhir.r4.model.MedicationDispense.MedicationDispenseSubstitutionComponent src) throws FHIRException {
222    if (src == null)
223      return null;
224    org.hl7.fhir.dstu3.model.MedicationDispense.MedicationDispenseSubstitutionComponent tgt = new org.hl7.fhir.dstu3.model.MedicationDispense.MedicationDispenseSubstitutionComponent();
225    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyBackboneElement(src,tgt);
226    if (src.hasWasSubstituted())
227      tgt.setWasSubstitutedElement(Boolean30_40.convertBoolean(src.getWasSubstitutedElement()));
228    if (src.hasType())
229      tgt.setType(CodeableConcept30_40.convertCodeableConcept(src.getType()));
230    for (org.hl7.fhir.r4.model.CodeableConcept t : src.getReason())
231      tgt.addReason(CodeableConcept30_40.convertCodeableConcept(t));
232    for (org.hl7.fhir.r4.model.Reference t : src.getResponsibleParty())
233      tgt.addResponsibleParty(Reference30_40.convertReference(t));
234    return tgt;
235  }
236}