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