001package org.hl7.fhir.convertors.conv30_50.datatypes30_50.complextypes30_50;
002
003import org.hl7.fhir.convertors.context.ConversionContext30_50;
004import org.hl7.fhir.convertors.conv30_50.datatypes30_50.primitivetypes30_50.Code30_50;
005import org.hl7.fhir.convertors.conv30_50.datatypes30_50.primitivetypes30_50.Decimal30_50;
006import org.hl7.fhir.convertors.conv30_50.datatypes30_50.primitivetypes30_50.String30_50;
007import org.hl7.fhir.convertors.conv30_50.datatypes30_50.primitivetypes30_50.Uri30_50;
008import org.hl7.fhir.exceptions.FHIRException;
009
010public class Quantity30_50 {
011  public static void copyQuantity(org.hl7.fhir.dstu3.model.Quantity src, org.hl7.fhir.r5.model.Quantity tgt) throws FHIRException {
012    if (src == null || tgt == null) return;
013    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().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.setUnitElement(String30_50.convertString(src.getUnitElement()));
017    if (src.hasSystem()) tgt.setSystemElement(Uri30_50.convertUri(src.getSystemElement()));
018    if (src.hasCode()) tgt.setCodeElement(Code30_50.convertCode(src.getCodeElement()));
019  }
020
021  public static void copyQuantity(org.hl7.fhir.r5.model.Quantity src, org.hl7.fhir.dstu3.model.Quantity tgt) throws FHIRException {
022    if (src == null || tgt == null) return;
023    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().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.setUnitElement(String30_50.convertString(src.getUnitElement()));
027    if (src.hasSystem()) tgt.setSystemElement(Uri30_50.convertUri(src.getSystemElement()));
028    if (src.hasCode()) tgt.setCodeElement(Code30_50.convertCode(src.getCodeElement()));
029  }
030
031  public static org.hl7.fhir.r5.model.Quantity convertQuantity(org.hl7.fhir.dstu3.model.Quantity src) throws FHIRException {
032    if (src == null) return null;
033    org.hl7.fhir.r5.model.Quantity tgt = new org.hl7.fhir.r5.model.Quantity();
034    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt);
035    if (src.hasValue()) tgt.setValueElement(Decimal30_50.convertDecimal(src.getValueElement()));
036    if (src.hasComparator()) tgt.setComparatorElement(convertQuantityComparator(src.getComparatorElement()));
037    if (src.hasUnit()) tgt.setUnitElement(String30_50.convertString(src.getUnitElement()));
038    if (src.hasSystem()) tgt.setSystemElement(Uri30_50.convertUri(src.getSystemElement()));
039    if (src.hasCode()) tgt.setCodeElement(Code30_50.convertCode(src.getCodeElement()));
040    return tgt;
041  }
042
043  public static org.hl7.fhir.dstu3.model.Quantity convertQuantity(org.hl7.fhir.r5.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_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt);
047    if (src.hasValue()) tgt.setValueElement(Decimal30_50.convertDecimal(src.getValueElement()));
048    if (src.hasComparator()) tgt.setComparatorElement(convertQuantityComparator(src.getComparatorElement()));
049    if (src.hasUnit()) tgt.setUnitElement(String30_50.convertString(src.getUnitElement()));
050    if (src.hasSystem()) tgt.setSystemElement(Uri30_50.convertUri(src.getSystemElement()));
051    if (src.hasCode()) tgt.setCodeElement(Code30_50.convertCode(src.getCodeElement()));
052    return tgt;
053  }
054
055  static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Enumerations.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.r5.model.Enumeration<org.hl7.fhir.r5.model.Enumerations.QuantityComparator> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.Enumerations.QuantityComparatorEnumFactory());
058    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt);
059    if (src.getValue() == null) {
060      tgt.setValue(org.hl7.fhir.r5.model.Enumerations.QuantityComparator.NULL);
061    } else {
062      switch (src.getValue()) {
063        case LESS_THAN:
064          tgt.setValue(org.hl7.fhir.r5.model.Enumerations.QuantityComparator.LESS_THAN);
065          break;
066        case LESS_OR_EQUAL:
067          tgt.setValue(org.hl7.fhir.r5.model.Enumerations.QuantityComparator.LESS_OR_EQUAL);
068          break;
069        case GREATER_OR_EQUAL:
070          tgt.setValue(org.hl7.fhir.r5.model.Enumerations.QuantityComparator.GREATER_OR_EQUAL);
071          break;
072        case GREATER_THAN:
073          tgt.setValue(org.hl7.fhir.r5.model.Enumerations.QuantityComparator.GREATER_THAN);
074          break;
075        default:
076          tgt.setValue(org.hl7.fhir.r5.model.Enumerations.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.r5.model.Enumeration<org.hl7.fhir.r5.model.Enumerations.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_50.INSTANCE.getVersionConvertor_30_50().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}