001package org.hl7.fhir.convertors.conv30_40.datatypes30_40.complextypes30_40;
002
003import org.hl7.fhir.convertors.context.ConversionContext30_40;
004import org.hl7.fhir.convertors.conv30_40.datatypes30_40.primitivetypes30_40.Code30_40;
005import org.hl7.fhir.convertors.conv30_40.datatypes30_40.primitivetypes30_40.Decimal30_40;
006import org.hl7.fhir.convertors.conv30_40.datatypes30_40.primitivetypes30_40.String30_40;
007import org.hl7.fhir.convertors.conv30_40.datatypes30_40.primitivetypes30_40.Uri30_40;
008import org.hl7.fhir.exceptions.FHIRException;
009
010public class Quantity30_40 {
011  public static void copyQuantity(org.hl7.fhir.dstu3.model.Quantity src, org.hl7.fhir.r4.model.Quantity tgt) throws FHIRException {
012    if (src == null || tgt == null) return;
013    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyElement(src, tgt);
014    if (src.hasValue()) tgt.setValue(src.getValue());
015    if (src.hasComparator()) tgt.setComparatorElement(convertQuantityComparator(src.getComparatorElement()));
016    if (src.hasUnit()) tgt.setUnit(src.getUnit());
017    if (src.hasSystem()) tgt.setSystem(src.getSystem());
018    if (src.hasCode()) tgt.setCode(src.getCode());
019  }
020
021  public static void copyQuantity(org.hl7.fhir.r4.model.Quantity src, org.hl7.fhir.dstu3.model.Quantity tgt) throws FHIRException {
022    if (src == null || tgt == null) return;
023    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyElement(src, tgt);
024    if (src.hasValue()) tgt.setValue(src.getValue());
025    if (src.hasComparator()) tgt.setComparatorElement(convertQuantityComparator(src.getComparatorElement()));
026    if (src.hasUnit()) tgt.setUnit(src.getUnit());
027    if (src.hasSystem()) tgt.setSystem(src.getSystem());
028    if (src.hasCode()) tgt.setCode(src.getCode());
029  }
030
031  public static org.hl7.fhir.r4.model.Quantity convertQuantity(org.hl7.fhir.dstu3.model.Quantity src) throws FHIRException {
032    if (src == null) return null;
033    org.hl7.fhir.r4.model.Quantity tgt = new org.hl7.fhir.r4.model.Quantity();
034    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyElement(src, tgt);
035    if (src.hasValue()) tgt.setValueElement(Decimal30_40.convertDecimal(src.getValueElement()));
036    if (src.hasComparator()) tgt.setComparatorElement(convertQuantityComparator(src.getComparatorElement()));
037    if (src.hasUnit()) tgt.setUnitElement(String30_40.convertString(src.getUnitElement()));
038    if (src.hasSystem()) tgt.setSystemElement(Uri30_40.convertUri(src.getSystemElement()));
039    if (src.hasCode()) tgt.setCodeElement(Code30_40.convertCode(src.getCodeElement()));
040    return tgt;
041  }
042
043  public static org.hl7.fhir.dstu3.model.Quantity convertQuantity(org.hl7.fhir.r4.model.Quantity src) throws FHIRException {
044    if (src == null) return null;
045    org.hl7.fhir.dstu3.model.Quantity tgt = new org.hl7.fhir.dstu3.model.Quantity();
046    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyElement(src, tgt);
047    if (src.hasValue()) tgt.setValueElement(Decimal30_40.convertDecimal(src.getValueElement()));
048    if (src.hasComparator()) tgt.setComparatorElement(convertQuantityComparator(src.getComparatorElement()));
049    if (src.hasUnit()) tgt.setUnitElement(String30_40.convertString(src.getUnitElement()));
050    if (src.hasSystem()) tgt.setSystemElement(Uri30_40.convertUri(src.getSystemElement()));
051    if (src.hasCode()) tgt.setCodeElement(Code30_40.convertCode(src.getCodeElement()));
052    return tgt;
053  }
054
055  static public org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Quantity.QuantityComparator> convertQuantityComparator(org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Quantity.QuantityComparator> src) throws FHIRException {
056    if (src == null || src.isEmpty()) return null;
057    org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Quantity.QuantityComparator> tgt = new org.hl7.fhir.r4.model.Enumeration<>(new org.hl7.fhir.r4.model.Quantity.QuantityComparatorEnumFactory());
058    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyElement(src, tgt);
059    if (src.getValue() == null) {
060      tgt.setValue(org.hl7.fhir.r4.model.Quantity.QuantityComparator.NULL);
061    } else {
062      switch (src.getValue()) {
063        case LESS_THAN:
064          tgt.setValue(org.hl7.fhir.r4.model.Quantity.QuantityComparator.LESS_THAN);
065          break;
066        case LESS_OR_EQUAL:
067          tgt.setValue(org.hl7.fhir.r4.model.Quantity.QuantityComparator.LESS_OR_EQUAL);
068          break;
069        case GREATER_OR_EQUAL:
070          tgt.setValue(org.hl7.fhir.r4.model.Quantity.QuantityComparator.GREATER_OR_EQUAL);
071          break;
072        case GREATER_THAN:
073          tgt.setValue(org.hl7.fhir.r4.model.Quantity.QuantityComparator.GREATER_THAN);
074          break;
075        default:
076          tgt.setValue(org.hl7.fhir.r4.model.Quantity.QuantityComparator.NULL);
077          break;
078      }
079    }
080    return tgt;
081  }
082
083  static public org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Quantity.QuantityComparator> convertQuantityComparator(org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Quantity.QuantityComparator> src) throws FHIRException {
084    if (src == null || src.isEmpty()) return null;
085    org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Quantity.QuantityComparator> tgt = new org.hl7.fhir.dstu3.model.Enumeration<>(new org.hl7.fhir.dstu3.model.Quantity.QuantityComparatorEnumFactory());
086    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyElement(src, tgt);
087    if (src.getValue() == null) {
088      tgt.setValue(org.hl7.fhir.dstu3.model.Quantity.QuantityComparator.NULL);
089    } else {
090      switch (src.getValue()) {
091        case LESS_THAN:
092          tgt.setValue(org.hl7.fhir.dstu3.model.Quantity.QuantityComparator.LESS_THAN);
093          break;
094        case LESS_OR_EQUAL:
095          tgt.setValue(org.hl7.fhir.dstu3.model.Quantity.QuantityComparator.LESS_OR_EQUAL);
096          break;
097        case GREATER_OR_EQUAL:
098          tgt.setValue(org.hl7.fhir.dstu3.model.Quantity.QuantityComparator.GREATER_OR_EQUAL);
099          break;
100        case GREATER_THAN:
101          tgt.setValue(org.hl7.fhir.dstu3.model.Quantity.QuantityComparator.GREATER_THAN);
102          break;
103        default:
104          tgt.setValue(org.hl7.fhir.dstu3.model.Quantity.QuantityComparator.NULL);
105          break;
106      }
107    }
108    return tgt;
109  }
110}