001package org.hl7.fhir.convertors.conv14_50.datatypes14_50.complextypes14_50;
002
003import org.hl7.fhir.convertors.context.ConversionContext14_50;
004import org.hl7.fhir.convertors.conv14_50.datatypes14_50.primitivetypes14_50.Code14_50;
005import org.hl7.fhir.convertors.conv14_50.datatypes14_50.primitivetypes14_50.Decimal14_50;
006import org.hl7.fhir.convertors.conv14_50.datatypes14_50.primitivetypes14_50.String14_50;
007import org.hl7.fhir.convertors.conv14_50.datatypes14_50.primitivetypes14_50.Uri14_50;
008import org.hl7.fhir.exceptions.FHIRException;
009
010public class Quantity14_50 {
011  public static org.hl7.fhir.r5.model.Quantity convertQuantity(org.hl7.fhir.dstu2016may.model.Quantity src) throws FHIRException {
012    if (src == null || src.isEmpty()) return null;
013    org.hl7.fhir.r5.model.Quantity tgt = new org.hl7.fhir.r5.model.Quantity();
014    ConversionContext14_50.INSTANCE.getVersionConvertor_14_50().copyElement(src, tgt);
015    if (src.hasValue()) tgt.setValueElement(Decimal14_50.convertDecimal(src.getValueElement()));
016    if (src.hasComparator()) tgt.setComparatorElement(convertQuantityComparator(src.getComparatorElement()));
017    if (src.hasUnit()) tgt.setUnitElement(String14_50.convertString(src.getUnitElement()));
018    if (src.hasSystem()) tgt.setSystemElement(Uri14_50.convertUri(src.getSystemElement()));
019    if (src.hasCode()) tgt.setCodeElement(Code14_50.convertCode(src.getCodeElement()));
020    return tgt;
021  }
022
023  public static org.hl7.fhir.dstu2016may.model.Quantity convertQuantity(org.hl7.fhir.r5.model.Quantity src) throws FHIRException {
024    if (src == null || src.isEmpty()) return null;
025    org.hl7.fhir.dstu2016may.model.Quantity tgt = new org.hl7.fhir.dstu2016may.model.Quantity();
026    ConversionContext14_50.INSTANCE.getVersionConvertor_14_50().copyElement(src, tgt);
027    if (src.hasValue()) tgt.setValueElement(Decimal14_50.convertDecimal(src.getValueElement()));
028    if (src.hasComparator()) tgt.setComparatorElement(convertQuantityComparator(src.getComparatorElement()));
029    if (src.hasUnit()) tgt.setUnitElement(String14_50.convertString(src.getUnitElement()));
030    if (src.hasSystem()) tgt.setSystemElement(Uri14_50.convertUri(src.getSystemElement()));
031    if (src.hasCode()) tgt.setCodeElement(Code14_50.convertCode(src.getCodeElement()));
032    return tgt;
033  }
034
035  static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Enumerations.QuantityComparator> convertQuantityComparator(org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.Quantity.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    ConversionContext14_50.INSTANCE.getVersionConvertor_14_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  static public org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.Quantity.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.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.Quantity.QuantityComparator> tgt = new org.hl7.fhir.dstu2016may.model.Enumeration<>(new org.hl7.fhir.dstu2016may.model.Quantity.QuantityComparatorEnumFactory());
066    ConversionContext14_50.INSTANCE.getVersionConvertor_14_50().copyElement(src, tgt);
067    if (src.getValue() == null) {
068      tgt.setValue(org.hl7.fhir.dstu2016may.model.Quantity.QuantityComparator.NULL);
069    } else {
070      switch (src.getValue()) {
071        case LESS_THAN:
072          tgt.setValue(org.hl7.fhir.dstu2016may.model.Quantity.QuantityComparator.LESS_THAN);
073          break;
074        case LESS_OR_EQUAL:
075          tgt.setValue(org.hl7.fhir.dstu2016may.model.Quantity.QuantityComparator.LESS_OR_EQUAL);
076          break;
077        case GREATER_OR_EQUAL:
078          tgt.setValue(org.hl7.fhir.dstu2016may.model.Quantity.QuantityComparator.GREATER_OR_EQUAL);
079          break;
080        case GREATER_THAN:
081          tgt.setValue(org.hl7.fhir.dstu2016may.model.Quantity.QuantityComparator.GREATER_THAN);
082          break;
083        default:
084          tgt.setValue(org.hl7.fhir.dstu2016may.model.Quantity.QuantityComparator.NULL);
085          break;
086      }
087    }
088    return tgt;
089  }
090}