001package org.hl7.fhir.convertors.conv14_30.datatypes14_30.complextypes14_30;
002
003import org.hl7.fhir.convertors.context.ConversionContext14_30;
004import org.hl7.fhir.convertors.conv14_30.datatypes14_30.primitivetypes14_30.Code14_30;
005import org.hl7.fhir.convertors.conv14_30.datatypes14_30.primitivetypes14_30.Decimal14_30;
006import org.hl7.fhir.convertors.conv14_30.datatypes14_30.primitivetypes14_30.String14_30;
007import org.hl7.fhir.convertors.conv14_30.datatypes14_30.primitivetypes14_30.Uri14_30;
008import org.hl7.fhir.exceptions.FHIRException;
009
010public class Quantity14_30 {
011  public static org.hl7.fhir.dstu3.model.Quantity convertQuantity(org.hl7.fhir.dstu2016may.model.Quantity src) throws FHIRException {
012    if (src == null || src.isEmpty()) return null;
013    org.hl7.fhir.dstu3.model.Quantity tgt = new org.hl7.fhir.dstu3.model.Quantity();
014    ConversionContext14_30.INSTANCE.getVersionConvertor_14_30().copyElement(src, tgt);
015    if (src.hasValue()) tgt.setValueElement(Decimal14_30.convertDecimal(src.getValueElement()));
016    if (src.hasComparator()) tgt.setComparatorElement(convertQuantityComparator(src.getComparatorElement()));
017    if (src.hasUnit()) tgt.setUnitElement(String14_30.convertString(src.getUnitElement()));
018    if (src.hasSystem()) tgt.setSystemElement(Uri14_30.convertUri(src.getSystemElement()));
019    if (src.hasCode()) tgt.setCodeElement(Code14_30.convertCode(src.getCodeElement()));
020    return tgt;
021  }
022
023  public static org.hl7.fhir.dstu2016may.model.Quantity convertQuantity(org.hl7.fhir.dstu3.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_30.INSTANCE.getVersionConvertor_14_30().copyElement(src, tgt);
027    if (src.hasValue()) tgt.setValueElement(Decimal14_30.convertDecimal(src.getValueElement()));
028    if (src.hasComparator()) tgt.setComparatorElement(convertQuantityComparator(src.getComparatorElement()));
029    if (src.hasUnit()) tgt.setUnitElement(String14_30.convertString(src.getUnitElement()));
030    if (src.hasSystem()) tgt.setSystemElement(Uri14_30.convertUri(src.getSystemElement()));
031    if (src.hasCode()) tgt.setCodeElement(Code14_30.convertCode(src.getCodeElement()));
032    return tgt;
033  }
034
035  static public org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Quantity.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.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());
038    ConversionContext14_30.INSTANCE.getVersionConvertor_14_30().copyElement(src, tgt);
039    if (src.getValue() == null) {
040      tgt.setValue(org.hl7.fhir.dstu3.model.Quantity.QuantityComparator.NULL);
041    } else {
042      switch (src.getValue()) {
043        case LESS_THAN:
044          tgt.setValue(org.hl7.fhir.dstu3.model.Quantity.QuantityComparator.LESS_THAN);
045          break;
046        case LESS_OR_EQUAL:
047          tgt.setValue(org.hl7.fhir.dstu3.model.Quantity.QuantityComparator.LESS_OR_EQUAL);
048          break;
049        case GREATER_OR_EQUAL:
050          tgt.setValue(org.hl7.fhir.dstu3.model.Quantity.QuantityComparator.GREATER_OR_EQUAL);
051          break;
052        case GREATER_THAN:
053          tgt.setValue(org.hl7.fhir.dstu3.model.Quantity.QuantityComparator.GREATER_THAN);
054          break;
055        default:
056          tgt.setValue(org.hl7.fhir.dstu3.model.Quantity.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.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Quantity.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_30.INSTANCE.getVersionConvertor_14_30().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}