001package org.hl7.fhir.convertors.conv40_50.resources40_50;
002
003import org.hl7.fhir.convertors.context.ConversionContext40_50;
004import org.hl7.fhir.convertors.conv40_50.datatypes40_50.general40_50.Annotation40_50;
005import org.hl7.fhir.convertors.conv40_50.datatypes40_50.general40_50.CodeableConcept40_50;
006import org.hl7.fhir.convertors.conv40_50.datatypes40_50.general40_50.Identifier40_50;
007import org.hl7.fhir.convertors.conv40_50.datatypes40_50.general40_50.SimpleQuantity40_50;
008import org.hl7.fhir.convertors.conv40_50.datatypes40_50.primitive40_50.Boolean40_50;
009import org.hl7.fhir.convertors.conv40_50.datatypes40_50.primitive40_50.DateTime40_50;
010import org.hl7.fhir.convertors.conv40_50.datatypes40_50.special40_50.Dosage40_50;
011import org.hl7.fhir.convertors.conv40_50.datatypes40_50.special40_50.Reference40_50;
012import org.hl7.fhir.exceptions.FHIRException;
013import org.hl7.fhir.r4.model.Enumeration;
014import org.hl7.fhir.r4.model.MedicationDispense;
015import org.hl7.fhir.r5.model.MedicationDispense.MedicationDispenseStatusCodesEnumFactory;
016
017/*
018  Copyright (c) 2011+, HL7, Inc.
019  All rights reserved.
020  
021  Redistribution and use in source and binary forms, with or without modification, 
022  are permitted provided that the following conditions are met:
023  
024   * Redistributions of source code must retain the above copyright notice, this 
025     list of conditions and the following disclaimer.
026   * Redistributions in binary form must reproduce the above copyright notice, 
027     this list of conditions and the following disclaimer in the documentation 
028     and/or other materials provided with the distribution.
029   * Neither the name of HL7 nor the names of its contributors may be used to 
030     endorse or promote products derived from this software without specific 
031     prior written permission.
032  
033  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
034  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
035  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
036  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
037  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
038  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
039  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
040  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
041  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
042  POSSIBILITY OF SUCH DAMAGE.
043  
044*/
045// Generated on Sun, Feb 24, 2019 11:37+1100 for FHIR v4.0.0
046public class MedicationDispense40_50 {
047
048  public static org.hl7.fhir.r5.model.MedicationDispense convertMedicationDispense(org.hl7.fhir.r4.model.MedicationDispense src) throws FHIRException {
049    if (src == null)
050      return null;
051    org.hl7.fhir.r5.model.MedicationDispense tgt = new org.hl7.fhir.r5.model.MedicationDispense();
052    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyDomainResource(src, tgt);
053    for (org.hl7.fhir.r4.model.Identifier t : src.getIdentifier())
054      tgt.addIdentifier(Identifier40_50.convertIdentifier(t));
055    for (org.hl7.fhir.r4.model.Reference t : src.getPartOf()) tgt.addPartOf(Reference40_50.convertReference(t));
056    if (src.hasStatus())
057      tgt.setStatusElement(convertMedicationStatus(src.getStatusElement()));
058//    if (src.hasStatusReasonCodeableConcept())
059//      tgt.getStatusReason().setConcept(CodeableConcept40_50.convertCodeableConcept(src.getStatusReasonCodeableConcept()));
060//    if (src.hasStatusReasonReference())
061//      tgt.getStatusReason().setReference(Reference40_50.convertReference(src.getStatusReasonReference()));
062    if (src.hasCategory())
063      tgt.addCategory(CodeableConcept40_50.convertCodeableConcept(src.getCategory()));
064    if (src.hasMedicationCodeableConcept())
065      tgt.getMedication().setConcept(CodeableConcept40_50.convertCodeableConcept(src.getMedicationCodeableConcept()));
066    if (src.hasMedicationReference())
067      tgt.getMedication().setReference(Reference40_50.convertReference(src.getMedicationReference()));
068    if (src.hasSubject())
069      tgt.setSubject(Reference40_50.convertReference(src.getSubject()));
070    if (src.hasContext())
071      tgt.setEncounter(Reference40_50.convertReference(src.getContext()));
072    for (org.hl7.fhir.r4.model.Reference t : src.getSupportingInformation())
073      tgt.addSupportingInformation(Reference40_50.convertReference(t));
074    for (org.hl7.fhir.r4.model.MedicationDispense.MedicationDispensePerformerComponent t : src.getPerformer())
075      tgt.addPerformer(convertMedicationDispensePerformerComponent(t));
076    if (src.hasLocation())
077      tgt.setLocation(Reference40_50.convertReference(src.getLocation()));
078    for (org.hl7.fhir.r4.model.Reference t : src.getAuthorizingPrescription())
079      tgt.addAuthorizingPrescription(Reference40_50.convertReference(t));
080    if (src.hasType())
081      tgt.setType(CodeableConcept40_50.convertCodeableConcept(src.getType()));
082    if (src.hasQuantity())
083      tgt.setQuantity(SimpleQuantity40_50.convertSimpleQuantity(src.getQuantity()));
084    if (src.hasDaysSupply())
085      tgt.setDaysSupply(SimpleQuantity40_50.convertSimpleQuantity(src.getDaysSupply()));
086    if (src.hasWhenPrepared())
087      tgt.setWhenPreparedElement(DateTime40_50.convertDateTime(src.getWhenPreparedElement()));
088    if (src.hasWhenHandedOver())
089      tgt.setWhenHandedOverElement(DateTime40_50.convertDateTime(src.getWhenHandedOverElement()));
090    if (src.hasDestination())
091      tgt.setDestination(Reference40_50.convertReference(src.getDestination()));
092    for (org.hl7.fhir.r4.model.Reference t : src.getReceiver()) tgt.addReceiver(Reference40_50.convertReference(t));
093    for (org.hl7.fhir.r4.model.Annotation t : src.getNote()) tgt.addNote(Annotation40_50.convertAnnotation(t));
094    for (org.hl7.fhir.r4.model.Dosage t : src.getDosageInstruction())
095      tgt.addDosageInstruction(Dosage40_50.convertDosage(t));
096    if (src.hasSubstitution())
097      tgt.setSubstitution(convertMedicationDispenseSubstitutionComponent(src.getSubstitution()));
098//    for (org.hl7.fhir.r4.model.Reference t : src.getDetectedIssue())
099//      tgt.addDetectedIssue(Reference40_50.convertReference(t));
100    for (org.hl7.fhir.r4.model.Reference t : src.getEventHistory())
101      tgt.addEventHistory(Reference40_50.convertReference(t));
102    return tgt;
103  }
104
105  public static org.hl7.fhir.r4.model.MedicationDispense convertMedicationDispense(org.hl7.fhir.r5.model.MedicationDispense src) throws FHIRException {
106    if (src == null)
107      return null;
108    org.hl7.fhir.r4.model.MedicationDispense tgt = new org.hl7.fhir.r4.model.MedicationDispense();
109    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyDomainResource(src, tgt);
110    for (org.hl7.fhir.r5.model.Identifier t : src.getIdentifier())
111      tgt.addIdentifier(Identifier40_50.convertIdentifier(t));
112    for (org.hl7.fhir.r5.model.Reference t : src.getPartOf()) tgt.addPartOf(Reference40_50.convertReference(t));
113    if (src.hasStatus())
114      tgt.setStatusElement(convertStatus(src.getStatusElement()));
115//    if (src.getStatusReason().hasConcept())
116//      tgt.setStatusReason(ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().convertType(src.getStatusReason().getConcept()));
117//    if (src.getStatusReason().hasReference())
118//      tgt.setStatusReason(ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().convertType(src.getStatusReason().getReference()));
119    if (src.hasCategory())
120      tgt.setCategory(CodeableConcept40_50.convertCodeableConcept(src.getCategoryFirstRep()));
121    if (src.getMedication().hasConcept())
122      tgt.setMedication(ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().convertType(src.getMedication().getConcept()));
123    if (src.getMedication().hasReference())
124      tgt.setMedication(ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().convertType(src.getMedication().getReference()));
125    if (src.hasSubject())
126      tgt.setSubject(Reference40_50.convertReference(src.getSubject()));
127    if (src.hasEncounter())
128      tgt.setContext(Reference40_50.convertReference(src.getEncounter()));
129    for (org.hl7.fhir.r5.model.Reference t : src.getSupportingInformation())
130      tgt.addSupportingInformation(Reference40_50.convertReference(t));
131    for (org.hl7.fhir.r5.model.MedicationDispense.MedicationDispensePerformerComponent t : src.getPerformer())
132      tgt.addPerformer(convertMedicationDispensePerformerComponent(t));
133    if (src.hasLocation())
134      tgt.setLocation(Reference40_50.convertReference(src.getLocation()));
135    for (org.hl7.fhir.r5.model.Reference t : src.getAuthorizingPrescription())
136      tgt.addAuthorizingPrescription(Reference40_50.convertReference(t));
137    if (src.hasType())
138      tgt.setType(CodeableConcept40_50.convertCodeableConcept(src.getType()));
139    if (src.hasQuantity())
140      tgt.setQuantity(SimpleQuantity40_50.convertSimpleQuantity(src.getQuantity()));
141    if (src.hasDaysSupply())
142      tgt.setDaysSupply(SimpleQuantity40_50.convertSimpleQuantity(src.getDaysSupply()));
143    if (src.hasWhenPrepared())
144      tgt.setWhenPreparedElement(DateTime40_50.convertDateTime(src.getWhenPreparedElement()));
145    if (src.hasWhenHandedOver())
146      tgt.setWhenHandedOverElement(DateTime40_50.convertDateTime(src.getWhenHandedOverElement()));
147    if (src.hasDestination())
148      tgt.setDestination(Reference40_50.convertReference(src.getDestination()));
149    for (org.hl7.fhir.r5.model.Reference t : src.getReceiver()) tgt.addReceiver(Reference40_50.convertReference(t));
150    for (org.hl7.fhir.r5.model.Annotation t : src.getNote()) tgt.addNote(Annotation40_50.convertAnnotation(t));
151    for (org.hl7.fhir.r5.model.Dosage t : src.getDosageInstruction())
152      tgt.addDosageInstruction(Dosage40_50.convertDosage(t));
153    if (src.hasSubstitution())
154      tgt.setSubstitution(convertMedicationDispenseSubstitutionComponent(src.getSubstitution()));
155//    for (org.hl7.fhir.r5.model.Reference t : src.getDetectedIssue())
156//      tgt.addDetectedIssue(Reference40_50.convertReference(t));
157    for (org.hl7.fhir.r5.model.Reference t : src.getEventHistory())
158      tgt.addEventHistory(Reference40_50.convertReference(t));
159    return tgt;
160  }
161
162  private static org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.MedicationDispense.MedicationDispenseStatus> convertStatus(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.MedicationDispense.MedicationDispenseStatusCodes> src) {
163      if (src == null)
164          return null;
165      Enumeration<MedicationDispense.MedicationDispenseStatus> tgt = new Enumeration<>(new MedicationDispense.MedicationDispenseStatusEnumFactory());
166      ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt);
167      if (src.getValue() == null) {
168          tgt.setValue(null);
169      } else {
170          switch (src.getValue()) {
171              case CANCELLED:
172                  tgt.setValue(MedicationDispense.MedicationDispenseStatus.CANCELLED);
173                  break;
174              case COMPLETED:
175                  tgt.setValue(MedicationDispense.MedicationDispenseStatus.COMPLETED);
176                  break;
177              case DECLINED:
178                  tgt.setValue(MedicationDispense.MedicationDispenseStatus.DECLINED);
179                  break;
180              case ENTEREDINERROR:
181                  tgt.setValue(MedicationDispense.MedicationDispenseStatus.ENTEREDINERROR);
182                  break;
183              case INPROGRESS:
184                  tgt.setValue(MedicationDispense.MedicationDispenseStatus.INPROGRESS);
185                  break;
186              case NULL:
187                  tgt.setValue(MedicationDispense.MedicationDispenseStatus.NULL);
188                  break;
189              case ONHOLD:
190                  tgt.setValue(MedicationDispense.MedicationDispenseStatus.ONHOLD);
191                  break;
192              case PREPARATION:
193                  tgt.setValue(MedicationDispense.MedicationDispenseStatus.PREPARATION);
194                  break;
195              case STOPPED:
196                  tgt.setValue(MedicationDispense.MedicationDispenseStatus.STOPPED);
197                  break;
198              case UNKNOWN:
199                  tgt.setValue(MedicationDispense.MedicationDispenseStatus.UNKNOWN);
200                  break;
201          }
202      }
203      return tgt;
204  }
205
206  private static org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.MedicationDispense.MedicationDispenseStatusCodes> convertMedicationStatus(org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.MedicationDispense.MedicationDispenseStatus> src) {
207      if (src == null)
208          return null;
209      org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.MedicationDispense.MedicationDispenseStatusCodes> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new MedicationDispenseStatusCodesEnumFactory());
210      ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt);
211      if (src.getValue() == null) {
212          tgt.setValue(null);
213      } else {
214          switch (src.getValue()) {
215              case CANCELLED:
216                  tgt.setValue(org.hl7.fhir.r5.model.MedicationDispense.MedicationDispenseStatusCodes.CANCELLED);
217                  break;
218              case COMPLETED:
219                  tgt.setValue(org.hl7.fhir.r5.model.MedicationDispense.MedicationDispenseStatusCodes.COMPLETED);
220                  break;
221              case DECLINED:
222                  tgt.setValue(org.hl7.fhir.r5.model.MedicationDispense.MedicationDispenseStatusCodes.DECLINED);
223                  break;
224              case ENTEREDINERROR:
225                  tgt.setValue(org.hl7.fhir.r5.model.MedicationDispense.MedicationDispenseStatusCodes.ENTEREDINERROR);
226                  break;
227              case INPROGRESS:
228                  tgt.setValue(org.hl7.fhir.r5.model.MedicationDispense.MedicationDispenseStatusCodes.INPROGRESS);
229                  break;
230              case NULL:
231                  tgt.setValue(org.hl7.fhir.r5.model.MedicationDispense.MedicationDispenseStatusCodes.NULL);
232                  break;
233              case ONHOLD:
234                  tgt.setValue(org.hl7.fhir.r5.model.MedicationDispense.MedicationDispenseStatusCodes.ONHOLD);
235                  break;
236              case PREPARATION:
237                  tgt.setValue(org.hl7.fhir.r5.model.MedicationDispense.MedicationDispenseStatusCodes.PREPARATION);
238                  break;
239              case STOPPED:
240                  tgt.setValue(org.hl7.fhir.r5.model.MedicationDispense.MedicationDispenseStatusCodes.STOPPED);
241                  break;
242              case UNKNOWN:
243                  tgt.setValue(org.hl7.fhir.r5.model.MedicationDispense.MedicationDispenseStatusCodes.UNKNOWN);
244                  break;
245          }
246      }
247      return tgt;
248  }
249
250  public static org.hl7.fhir.r5.model.MedicationDispense.MedicationDispensePerformerComponent convertMedicationDispensePerformerComponent(org.hl7.fhir.r4.model.MedicationDispense.MedicationDispensePerformerComponent src) throws FHIRException {
251    if (src == null)
252      return null;
253    org.hl7.fhir.r5.model.MedicationDispense.MedicationDispensePerformerComponent tgt = new org.hl7.fhir.r5.model.MedicationDispense.MedicationDispensePerformerComponent();
254    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyBackboneElement(src, tgt);
255    if (src.hasFunction())
256      tgt.setFunction(CodeableConcept40_50.convertCodeableConcept(src.getFunction()));
257    if (src.hasActor())
258      tgt.setActor(Reference40_50.convertReference(src.getActor()));
259    return tgt;
260  }
261
262  public static org.hl7.fhir.r4.model.MedicationDispense.MedicationDispensePerformerComponent convertMedicationDispensePerformerComponent(org.hl7.fhir.r5.model.MedicationDispense.MedicationDispensePerformerComponent src) throws FHIRException {
263    if (src == null)
264      return null;
265    org.hl7.fhir.r4.model.MedicationDispense.MedicationDispensePerformerComponent tgt = new org.hl7.fhir.r4.model.MedicationDispense.MedicationDispensePerformerComponent();
266    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyBackboneElement(src, tgt);
267    if (src.hasFunction())
268      tgt.setFunction(CodeableConcept40_50.convertCodeableConcept(src.getFunction()));
269    if (src.hasActor())
270      tgt.setActor(Reference40_50.convertReference(src.getActor()));
271    return tgt;
272  }
273
274  public static org.hl7.fhir.r5.model.MedicationDispense.MedicationDispenseSubstitutionComponent convertMedicationDispenseSubstitutionComponent(org.hl7.fhir.r4.model.MedicationDispense.MedicationDispenseSubstitutionComponent src) throws FHIRException {
275    if (src == null)
276      return null;
277    org.hl7.fhir.r5.model.MedicationDispense.MedicationDispenseSubstitutionComponent tgt = new org.hl7.fhir.r5.model.MedicationDispense.MedicationDispenseSubstitutionComponent();
278    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyBackboneElement(src, tgt);
279    if (src.hasWasSubstituted())
280      tgt.setWasSubstitutedElement(Boolean40_50.convertBoolean(src.getWasSubstitutedElement()));
281    if (src.hasType())
282      tgt.setType(CodeableConcept40_50.convertCodeableConcept(src.getType()));
283    for (org.hl7.fhir.r4.model.CodeableConcept t : src.getReason())
284      tgt.addReason(CodeableConcept40_50.convertCodeableConcept(t));
285    for (org.hl7.fhir.r4.model.Reference t : src.getResponsibleParty())
286      tgt.setResponsibleParty(Reference40_50.convertReference(t));
287    return tgt;
288  }
289
290  public static org.hl7.fhir.r4.model.MedicationDispense.MedicationDispenseSubstitutionComponent convertMedicationDispenseSubstitutionComponent(org.hl7.fhir.r5.model.MedicationDispense.MedicationDispenseSubstitutionComponent src) throws FHIRException {
291    if (src == null)
292      return null;
293    org.hl7.fhir.r4.model.MedicationDispense.MedicationDispenseSubstitutionComponent tgt = new org.hl7.fhir.r4.model.MedicationDispense.MedicationDispenseSubstitutionComponent();
294    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyBackboneElement(src, tgt);
295    if (src.hasWasSubstituted())
296      tgt.setWasSubstitutedElement(Boolean40_50.convertBoolean(src.getWasSubstitutedElement()));
297    if (src.hasType())
298      tgt.setType(CodeableConcept40_50.convertCodeableConcept(src.getType()));
299    for (org.hl7.fhir.r5.model.CodeableConcept t : src.getReason())
300      tgt.addReason(CodeableConcept40_50.convertCodeableConcept(t));
301    if (src.hasResponsibleParty())
302      tgt.addResponsibleParty(Reference40_50.convertReference(src.getResponsibleParty()));
303    return tgt;
304  }
305}