001package org.hl7.fhir.convertors.conv10_30.datatypes10_30.complextypes10_30;
002
003import org.hl7.fhir.convertors.context.ConversionContext10_30;
004import org.hl7.fhir.convertors.conv10_30.datatypes10_30.primitivetypes10_30.Code10_30;
005import org.hl7.fhir.convertors.conv10_30.datatypes10_30.primitivetypes10_30.Decimal10_30;
006import org.hl7.fhir.convertors.conv10_30.datatypes10_30.primitivetypes10_30.String10_30;
007import org.hl7.fhir.convertors.conv10_30.datatypes10_30.primitivetypes10_30.Uri10_30;
008import org.hl7.fhir.exceptions.FHIRException;
009
010public class Quantity10_30 {
011  public static org.hl7.fhir.dstu3.model.Quantity convertQuantity(org.hl7.fhir.dstu2.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    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt);
015    if (src.hasValueElement()) tgt.setValueElement(Decimal10_30.convertDecimal(src.getValueElement()));
016    if (src.hasComparator()) tgt.setComparatorElement(convertQuantityComparator(src.getComparatorElement()));
017    if (src.hasUnitElement()) tgt.setUnitElement(String10_30.convertString(src.getUnitElement()));
018    if (src.hasSystemElement()) tgt.setSystemElement(Uri10_30.convertUri(src.getSystemElement()));
019    if (src.hasCodeElement()) tgt.setCodeElement(Code10_30.convertCode(src.getCodeElement()));
020    return tgt;
021  }
022
023  public static org.hl7.fhir.dstu2.model.Quantity convertQuantity(org.hl7.fhir.dstu3.model.Quantity src) throws FHIRException {
024    if (src == null || src.isEmpty()) return null;
025    org.hl7.fhir.dstu2.model.Quantity tgt = new org.hl7.fhir.dstu2.model.Quantity();
026    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt);
027    if (src.hasValueElement()) tgt.setValueElement(Decimal10_30.convertDecimal(src.getValueElement()));
028    if (src.hasComparator()) tgt.setComparatorElement(convertQuantityComparator(src.getComparatorElement()));
029    if (src.hasUnitElement()) tgt.setUnitElement(String10_30.convertString(src.getUnitElement()));
030    if (src.hasSystemElement()) tgt.setSystemElement(Uri10_30.convertUri(src.getSystemElement()));
031    if (src.hasCodeElement()) tgt.setCodeElement(Code10_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.dstu2.model.Enumeration<org.hl7.fhir.dstu2.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    ConversionContext10_30.INSTANCE.getVersionConvertor_10_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.dstu2.model.Enumeration<org.hl7.fhir.dstu2.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.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Quantity.QuantityComparator> tgt = new org.hl7.fhir.dstu2.model.Enumeration<>(new org.hl7.fhir.dstu2.model.Quantity.QuantityComparatorEnumFactory());
066    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt);
067    if (src.getValue() == null) {
068      tgt.setValue(org.hl7.fhir.dstu2.model.Quantity.QuantityComparator.NULL);
069    } else {
070      switch (src.getValue()) {
071        case LESS_THAN:
072          tgt.setValue(org.hl7.fhir.dstu2.model.Quantity.QuantityComparator.LESS_THAN);
073          break;
074        case LESS_OR_EQUAL:
075          tgt.setValue(org.hl7.fhir.dstu2.model.Quantity.QuantityComparator.LESS_OR_EQUAL);
076          break;
077        case GREATER_OR_EQUAL:
078          tgt.setValue(org.hl7.fhir.dstu2.model.Quantity.QuantityComparator.GREATER_OR_EQUAL);
079          break;
080        case GREATER_THAN:
081          tgt.setValue(org.hl7.fhir.dstu2.model.Quantity.QuantityComparator.GREATER_THAN);
082          break;
083        default:
084          tgt.setValue(org.hl7.fhir.dstu2.model.Quantity.QuantityComparator.NULL);
085          break;
086      }
087    }
088    return tgt;
089  }
090}