001package org.hl7.fhir.convertors.conv14_40.datatypes14_40.complextypes14_40;
002
003import org.hl7.fhir.convertors.context.ConversionContext14_40;
004import org.hl7.fhir.convertors.conv14_40.datatypes14_40.primitivetypes14_40.Code14_40;
005import org.hl7.fhir.convertors.conv14_40.datatypes14_40.primitivetypes14_40.Decimal14_40;
006import org.hl7.fhir.convertors.conv14_40.datatypes14_40.primitivetypes14_40.String14_40;
007import org.hl7.fhir.convertors.conv14_40.datatypes14_40.primitivetypes14_40.Uri14_40;
008import org.hl7.fhir.exceptions.FHIRException;
009import org.hl7.fhir.r4.model.Quantity;
010
011public class Quantity14_40 {
012  public static org.hl7.fhir.r4.model.Quantity convertQuantity(org.hl7.fhir.dstu2016may.model.Quantity src) throws FHIRException {
013    if (src == null || src.isEmpty()) return null;
014    org.hl7.fhir.r4.model.Quantity tgt = new org.hl7.fhir.r4.model.Quantity();
015    ConversionContext14_40.INSTANCE.getVersionConvertor_14_40().copyElement(src, tgt);
016    if (src.hasValue()) tgt.setValueElement(Decimal14_40.convertDecimal(src.getValueElement()));
017    if (src.hasComparator()) tgt.setComparatorElement(convertQuantityComparator(src.getComparatorElement()));
018    if (src.hasUnit()) tgt.setUnitElement(String14_40.convertString(src.getUnitElement()));
019    if (src.hasSystem()) tgt.setSystemElement(Uri14_40.convertUri(src.getSystemElement()));
020    if (src.hasCode()) tgt.setCodeElement(Code14_40.convertCode(src.getCodeElement()));
021    return tgt;
022  }
023
024  public static org.hl7.fhir.dstu2016may.model.Quantity convertQuantity(org.hl7.fhir.r4.model.Quantity src) throws FHIRException {
025    if (src == null || src.isEmpty()) return null;
026    org.hl7.fhir.dstu2016may.model.Quantity tgt = new org.hl7.fhir.dstu2016may.model.Quantity();
027    ConversionContext14_40.INSTANCE.getVersionConvertor_14_40().copyElement(src, tgt);
028    if (src.hasValue()) tgt.setValueElement(Decimal14_40.convertDecimal(src.getValueElement()));
029    if (src.hasComparator()) tgt.setComparatorElement(convertQuantityComparator(src.getComparatorElement()));
030    if (src.hasUnit()) tgt.setUnitElement(String14_40.convertString(src.getUnitElement()));
031    if (src.hasSystem()) tgt.setSystemElement(Uri14_40.convertUri(src.getSystemElement()));
032    if (src.hasCode()) tgt.setCodeElement(Code14_40.convertCode(src.getCodeElement()));
033    return tgt;
034  }
035
036  static public org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Quantity.QuantityComparator> convertQuantityComparator(org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.Quantity.QuantityComparator> src) throws FHIRException {
037    if (src == null || src.isEmpty()) return null;
038    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());
039    ConversionContext14_40.INSTANCE.getVersionConvertor_14_40().copyElement(src, tgt);
040    if (src.getValue() == null) {
041    tgt.setValue(null);
042} else {
043      switch(src.getValue()) {
044        case LESS_THAN:
045            tgt.setValue(Quantity.QuantityComparator.LESS_THAN);
046            break;
047          case LESS_OR_EQUAL:
048            tgt.setValue(Quantity.QuantityComparator.LESS_OR_EQUAL);
049            break;
050          case GREATER_OR_EQUAL:
051            tgt.setValue(Quantity.QuantityComparator.GREATER_OR_EQUAL);
052            break;
053          case GREATER_THAN:
054            tgt.setValue(Quantity.QuantityComparator.GREATER_THAN);
055            break;
056          default:
057            tgt.setValue(Quantity.QuantityComparator.NULL);
058            break;
059       }
060}
061    return tgt;
062  }
063
064  static public org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.Quantity.QuantityComparator> convertQuantityComparator(org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Quantity.QuantityComparator> src) throws FHIRException {
065    if (src == null || src.isEmpty()) return null;
066    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());
067    ConversionContext14_40.INSTANCE.getVersionConvertor_14_40().copyElement(src, tgt);
068    if (src.getValue() == null) {
069    tgt.setValue(null);
070} else {
071      switch(src.getValue()) {
072        case LESS_THAN:
073            tgt.setValue(org.hl7.fhir.dstu2016may.model.Quantity.QuantityComparator.LESS_THAN);
074            break;
075          case LESS_OR_EQUAL:
076            tgt.setValue(org.hl7.fhir.dstu2016may.model.Quantity.QuantityComparator.LESS_OR_EQUAL);
077            break;
078          case GREATER_OR_EQUAL:
079            tgt.setValue(org.hl7.fhir.dstu2016may.model.Quantity.QuantityComparator.GREATER_OR_EQUAL);
080            break;
081          case GREATER_THAN:
082            tgt.setValue(org.hl7.fhir.dstu2016may.model.Quantity.QuantityComparator.GREATER_THAN);
083            break;
084          default:
085            tgt.setValue(org.hl7.fhir.dstu2016may.model.Quantity.QuantityComparator.NULL);
086            break;
087       }
088}
089    return tgt;
090  }
091}