001package org.hl7.fhir.convertors.conv43_50.resources43_50;
002
003import org.hl7.fhir.convertors.context.ConversionContext43_50;
004import org.hl7.fhir.convertors.conv43_50.datatypes43_50.general43_50.CodeableConcept43_50;
005import org.hl7.fhir.convertors.conv43_50.datatypes43_50.general43_50.Identifier43_50;
006import org.hl7.fhir.convertors.conv43_50.datatypes43_50.general43_50.Ratio43_50;
007import org.hl7.fhir.convertors.conv43_50.datatypes43_50.primitive43_50.Boolean43_50;
008import org.hl7.fhir.convertors.conv43_50.datatypes43_50.primitive43_50.DateTime43_50;
009import org.hl7.fhir.convertors.conv43_50.datatypes43_50.primitive43_50.String43_50;
010import org.hl7.fhir.convertors.conv43_50.datatypes43_50.special43_50.Reference43_50;
011import org.hl7.fhir.exceptions.FHIRException;
012
013/*
014  Copyright (c) 2011+, HL7, Inc.
015  All rights reserved.
016  
017  Redistribution and use in source and binary forms, with or without modification, 
018  are permitted provided that the following conditions are met:
019  
020   * Redistributions of source code must retain the above copyright notice, this 
021     list of conditions and the following disclaimer.
022   * Redistributions in binary form must reproduce the above copyright notice, 
023     this list of conditions and the following disclaimer in the documentation 
024     and/or other materials provided with the distribution.
025   * Neither the name of HL7 nor the names of its contributors may be used to 
026     endorse or promote products derived from this software without specific 
027     prior written permission.
028  
029  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
030  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
031  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
032  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
033  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
034  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
035  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
036  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
037  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
038  POSSIBILITY OF SUCH DAMAGE.
039  
040*/
041// Generated on Sun, Feb 24, 2019 11:37+1100 for FHIR v4.0.0
042public class Medication43_50 {
043
044  public static org.hl7.fhir.r5.model.Medication convertMedication(org.hl7.fhir.r4b.model.Medication src) throws FHIRException {
045    if (src == null)
046      return null;
047    org.hl7.fhir.r5.model.Medication tgt = new org.hl7.fhir.r5.model.Medication();
048    ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().copyDomainResource(src, tgt);
049    for (org.hl7.fhir.r4b.model.Identifier t : src.getIdentifier())
050      tgt.addIdentifier(Identifier43_50.convertIdentifier(t));
051    if (src.hasCode())
052      tgt.setCode(CodeableConcept43_50.convertCodeableConcept(src.getCode()));
053    if (src.hasStatus())
054      tgt.setStatusElement(convertMedicationStatus(src.getStatusElement()));
055    if (src.hasManufacturer())
056      tgt.setMarketingAuthorizationHolder(Reference43_50.convertReference(src.getManufacturer()));
057    if (src.hasForm())
058      tgt.setDoseForm(CodeableConcept43_50.convertCodeableConcept(src.getForm()));
059//    if (src.hasAmount())
060//      tgt.setTotalVolume(Ratio43_50.convertRatio(src.getAmount()));
061    for (org.hl7.fhir.r4b.model.Medication.MedicationIngredientComponent t : src.getIngredient())
062      tgt.addIngredient(convertMedicationIngredientComponent(t));
063    if (src.hasBatch())
064      tgt.setBatch(convertMedicationBatchComponent(src.getBatch()));
065    return tgt;
066  }
067
068  public static org.hl7.fhir.r4b.model.Medication convertMedication(org.hl7.fhir.r5.model.Medication src) throws FHIRException {
069    if (src == null)
070      return null;
071    org.hl7.fhir.r4b.model.Medication tgt = new org.hl7.fhir.r4b.model.Medication();
072    ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().copyDomainResource(src, tgt);
073    for (org.hl7.fhir.r5.model.Identifier t : src.getIdentifier())
074      tgt.addIdentifier(Identifier43_50.convertIdentifier(t));
075    if (src.hasCode())
076      tgt.setCode(CodeableConcept43_50.convertCodeableConcept(src.getCode()));
077    if (src.hasStatus())
078      tgt.setStatusElement(convertMedicationStatus(src.getStatusElement()));
079    if (src.hasMarketingAuthorizationHolder())
080      tgt.setManufacturer(Reference43_50.convertReference(src.getMarketingAuthorizationHolder()));
081    if (src.hasDoseForm())
082      tgt.setForm(CodeableConcept43_50.convertCodeableConcept(src.getDoseForm()));
083//    if (src.hasTotalVolume())
084//      tgt.setAmount(Ratio43_50.convertRatio(src.getTotalVolume()));
085    for (org.hl7.fhir.r5.model.Medication.MedicationIngredientComponent t : src.getIngredient())
086      tgt.addIngredient(convertMedicationIngredientComponent(t));
087    if (src.hasBatch())
088      tgt.setBatch(convertMedicationBatchComponent(src.getBatch()));
089    return tgt;
090  }
091
092  static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Medication.MedicationStatusCodes> convertMedicationStatus(org.hl7.fhir.r4b.model.Enumeration<org.hl7.fhir.r4b.model.Medication.MedicationStatusCodes> src) throws FHIRException {
093    if (src == null || src.isEmpty())
094      return null;
095    org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Medication.MedicationStatusCodes> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.Medication.MedicationStatusCodesEnumFactory());
096    ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().copyElement(src, tgt);
097    switch (src.getValue()) {
098      case ACTIVE:
099        tgt.setValue(org.hl7.fhir.r5.model.Medication.MedicationStatusCodes.ACTIVE);
100        break;
101      case INACTIVE:
102        tgt.setValue(org.hl7.fhir.r5.model.Medication.MedicationStatusCodes.INACTIVE);
103        break;
104      case ENTEREDINERROR:
105        tgt.setValue(org.hl7.fhir.r5.model.Medication.MedicationStatusCodes.ENTEREDINERROR);
106        break;
107      default:
108        tgt.setValue(org.hl7.fhir.r5.model.Medication.MedicationStatusCodes.NULL);
109        break;
110    }
111    return tgt;
112  }
113
114  static public org.hl7.fhir.r4b.model.Enumeration<org.hl7.fhir.r4b.model.Medication.MedicationStatusCodes> convertMedicationStatus(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Medication.MedicationStatusCodes> src) throws FHIRException {
115    if (src == null || src.isEmpty())
116      return null;
117    org.hl7.fhir.r4b.model.Enumeration<org.hl7.fhir.r4b.model.Medication.MedicationStatusCodes> tgt = new org.hl7.fhir.r4b.model.Enumeration<>(new org.hl7.fhir.r4b.model.Medication.MedicationStatusCodesEnumFactory());
118    ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().copyElement(src, tgt);
119    switch (src.getValue()) {
120      case ACTIVE:
121        tgt.setValue(org.hl7.fhir.r4b.model.Medication.MedicationStatusCodes.ACTIVE);
122        break;
123      case INACTIVE:
124        tgt.setValue(org.hl7.fhir.r4b.model.Medication.MedicationStatusCodes.INACTIVE);
125        break;
126      case ENTEREDINERROR:
127        tgt.setValue(org.hl7.fhir.r4b.model.Medication.MedicationStatusCodes.ENTEREDINERROR);
128        break;
129      default:
130        tgt.setValue(org.hl7.fhir.r4b.model.Medication.MedicationStatusCodes.NULL);
131        break;
132    }
133    return tgt;
134  }
135
136  public static org.hl7.fhir.r5.model.Medication.MedicationIngredientComponent convertMedicationIngredientComponent(org.hl7.fhir.r4b.model.Medication.MedicationIngredientComponent src) throws FHIRException {
137    if (src == null)
138      return null;
139    org.hl7.fhir.r5.model.Medication.MedicationIngredientComponent tgt = new org.hl7.fhir.r5.model.Medication.MedicationIngredientComponent();
140    ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().copyBackboneElement(src, tgt);
141    if (src.hasItemCodeableConcept())
142      tgt.getItem().setConcept(CodeableConcept43_50.convertCodeableConcept(src.getItemCodeableConcept()));
143    if (src.hasItemReference())
144      tgt.getItem().setReference(Reference43_50.convertReference(src.getItemReference()));
145    if (src.hasIsActive())
146      tgt.setIsActiveElement(Boolean43_50.convertBoolean(src.getIsActiveElement()));
147    if (src.hasStrength())
148      tgt.setStrength(Ratio43_50.convertRatio(src.getStrength()));
149    return tgt;
150  }
151
152  public static org.hl7.fhir.r4b.model.Medication.MedicationIngredientComponent convertMedicationIngredientComponent(org.hl7.fhir.r5.model.Medication.MedicationIngredientComponent src) throws FHIRException {
153    if (src == null)
154      return null;
155    org.hl7.fhir.r4b.model.Medication.MedicationIngredientComponent tgt = new org.hl7.fhir.r4b.model.Medication.MedicationIngredientComponent();
156    ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().copyBackboneElement(src, tgt);
157    if (src.getItem().hasConcept())
158      tgt.setItem(ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().convertType(src.getItem().getConcept()));
159    if (src.getItem().hasReference())
160      tgt.setItem(ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().convertType(src.getItem().getReference()));
161    if (src.hasIsActive())
162      tgt.setIsActiveElement(Boolean43_50.convertBoolean(src.getIsActiveElement()));
163    if (src.hasStrengthRatio())
164      tgt.setStrength(Ratio43_50.convertRatio(src.getStrengthRatio()));
165    return tgt;
166  }
167
168  public static org.hl7.fhir.r5.model.Medication.MedicationBatchComponent convertMedicationBatchComponent(org.hl7.fhir.r4b.model.Medication.MedicationBatchComponent src) throws FHIRException {
169    if (src == null)
170      return null;
171    org.hl7.fhir.r5.model.Medication.MedicationBatchComponent tgt = new org.hl7.fhir.r5.model.Medication.MedicationBatchComponent();
172    ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().copyBackboneElement(src, tgt);
173    if (src.hasLotNumber())
174      tgt.setLotNumberElement(String43_50.convertString(src.getLotNumberElement()));
175    if (src.hasExpirationDate())
176      tgt.setExpirationDateElement(DateTime43_50.convertDateTime(src.getExpirationDateElement()));
177    return tgt;
178  }
179
180  public static org.hl7.fhir.r4b.model.Medication.MedicationBatchComponent convertMedicationBatchComponent(org.hl7.fhir.r5.model.Medication.MedicationBatchComponent src) throws FHIRException {
181    if (src == null)
182      return null;
183    org.hl7.fhir.r4b.model.Medication.MedicationBatchComponent tgt = new org.hl7.fhir.r4b.model.Medication.MedicationBatchComponent();
184    ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().copyBackboneElement(src, tgt);
185    if (src.hasLotNumber())
186      tgt.setLotNumberElement(String43_50.convertString(src.getLotNumberElement()));
187    if (src.hasExpirationDate())
188      tgt.setExpirationDateElement(DateTime43_50.convertDateTime(src.getExpirationDateElement()));
189    return tgt;
190  }
191}