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