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.complextypes10_50.CodeableConcept10_50;
005import org.hl7.fhir.convertors.conv10_50.datatypes10_50.complextypes10_50.Ratio10_50;
006import org.hl7.fhir.convertors.conv10_50.datatypes10_50.complextypes10_50.Timing10_50;
007import org.hl7.fhir.convertors.conv10_50.datatypes10_50.primitivetypes10_50.Boolean10_50;
008import org.hl7.fhir.convertors.conv10_50.datatypes10_50.primitivetypes10_50.String10_50;
009import org.hl7.fhir.exceptions.FHIRException;
010import org.hl7.fhir.r5.model.Dosage;
011
012public class MedicationOrder10_50 {
013  public static org.hl7.fhir.r5.model.Dosage convertMedicationOrderDosageInstructionComponent(org.hl7.fhir.dstu2.model.MedicationOrder.MedicationOrderDosageInstructionComponent src) throws FHIRException {
014    if (src == null || src.isEmpty()) return null;
015    org.hl7.fhir.r5.model.Dosage tgt = new org.hl7.fhir.r5.model.Dosage();
016    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyElement(src, tgt);
017    if (src.hasTextElement()) tgt.setTextElement(String10_50.convertString(src.getTextElement()));
018    if (src.hasTiming()) tgt.setTiming(Timing10_50.convertTiming(src.getTiming()));
019    if (src.hasAsNeededBooleanType())
020      tgt.setAsNeededElement(Boolean10_50.convertBoolean(src.getAsNeededBooleanType()));
021    if (src.hasSiteCodeableConcept())
022      tgt.setSite(CodeableConcept10_50.convertCodeableConcept(src.getSiteCodeableConcept()));
023    if (src.hasRoute()) tgt.setRoute(CodeableConcept10_50.convertCodeableConcept(src.getRoute()));
024    if (src.hasMethod()) tgt.setMethod(CodeableConcept10_50.convertCodeableConcept(src.getMethod()));
025    if (src.hasDose() || src.hasRate()) {
026      Dosage.DosageDoseAndRateComponent dr = tgt.addDoseAndRate();
027      if (src.hasDose())
028        dr.setDose(ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().convertType(src.getDose()));
029      if (src.hasRate())
030        dr.setRate(ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().convertType(src.getRate()));
031    }
032    if (src.hasMaxDosePerPeriod()) tgt.addMaxDosePerPeriod(Ratio10_50.convertRatio(src.getMaxDosePerPeriod()));
033    return tgt;
034  }
035
036  public static org.hl7.fhir.dstu2.model.MedicationOrder.MedicationOrderDosageInstructionComponent convertMedicationOrderDosageInstructionComponent(Dosage src) throws FHIRException {
037    if (src == null || src.isEmpty()) return null;
038    org.hl7.fhir.dstu2.model.MedicationOrder.MedicationOrderDosageInstructionComponent tgt = new org.hl7.fhir.dstu2.model.MedicationOrder.MedicationOrderDosageInstructionComponent();
039    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyElement(src, tgt);
040    if (src.hasTextElement()) tgt.setTextElement(String10_50.convertString(src.getTextElement()));
041    if (src.hasTiming()) tgt.setTiming(Timing10_50.convertTiming(src.getTiming()));
042    if (src.hasAsNeeded())
043      tgt.setAsNeeded(Boolean10_50.convertBoolean(src.getAsNeededElement()));
044    if (src.hasSite())
045      tgt.setSite(ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().convertType(src.getSite()));
046    if (src.hasRoute()) tgt.setRoute(CodeableConcept10_50.convertCodeableConcept(src.getRoute()));
047    if (src.hasMethod()) tgt.setMethod(CodeableConcept10_50.convertCodeableConcept(src.getMethod()));
048    if (src.hasDoseAndRate() && src.getDoseAndRate().get(0).hasDose())
049      tgt.setDose(ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().convertType(src.getDoseAndRate().get(0).getDose()));
050    if (src.hasDoseAndRate() && src.getDoseAndRate().get(0).hasRate())
051      tgt.setRate(ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().convertType(src.getDoseAndRate().get(0).getRate()));
052    if (src.hasMaxDosePerPeriod()) tgt.setMaxDosePerPeriod(Ratio10_50.convertRatio(src.getMaxDosePerPeriodFirstRep()));
053    return tgt;
054  }
055}