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