001package org.hl7.fhir.convertors.conv43_50.datatypes43_50.general43_50;
002
003import org.hl7.fhir.convertors.context.ConversionContext43_50;
004import org.hl7.fhir.convertors.conv43_50.datatypes43_50.primitive43_50.Code43_50;
005import org.hl7.fhir.convertors.conv43_50.datatypes43_50.primitive43_50.Decimal43_50;
006import org.hl7.fhir.convertors.conv43_50.datatypes43_50.primitive43_50.String43_50;
007import org.hl7.fhir.convertors.conv43_50.datatypes43_50.primitive43_50.Uri43_50;
008import org.hl7.fhir.exceptions.FHIRException;
009import org.hl7.fhir.r5.model.Enumerations;
010
011public class Quantity43_50 {
012  public static org.hl7.fhir.r5.model.Quantity convertQuantity(org.hl7.fhir.r4b.model.Quantity src) throws FHIRException {
013    if (src == null) return null;
014    org.hl7.fhir.r5.model.Quantity tgt = new org.hl7.fhir.r5.model.Quantity();
015    ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().copyElement(src, tgt);
016    if (src.hasValue()) tgt.setValueElement(Decimal43_50.convertDecimal(src.getValueElement()));
017    if (src.hasComparator()) tgt.setComparatorElement(convertQuantityComparator(src.getComparatorElement()));
018    if (src.hasUnit()) tgt.setUnitElement(String43_50.convertString(src.getUnitElement()));
019    if (src.hasSystem()) tgt.setSystemElement(Uri43_50.convertUri(src.getSystemElement()));
020    if (src.hasCode()) tgt.setCodeElement(Code43_50.convertCode(src.getCodeElement()));
021    return tgt;
022  }
023
024  public static org.hl7.fhir.r4b.model.Quantity convertQuantity(org.hl7.fhir.r5.model.Quantity src) throws FHIRException {
025    if (src == null) return null;
026    org.hl7.fhir.r4b.model.Quantity tgt = new org.hl7.fhir.r4b.model.Quantity();
027    ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().copyElement(src, tgt);
028    if (src.hasValue()) tgt.setValueElement(Decimal43_50.convertDecimal(src.getValueElement()));
029    if (src.hasComparator()) tgt.setComparatorElement(convertQuantityComparator(src.getComparatorElement()));
030    if (src.hasUnit()) tgt.setUnitElement(String43_50.convertString(src.getUnitElement()));
031    if (src.hasSystem()) tgt.setSystemElement(Uri43_50.convertUri(src.getSystemElement()));
032    if (src.hasCode()) tgt.setCodeElement(Code43_50.convertCode(src.getCodeElement()));
033    return tgt;
034  }
035
036  public static org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Enumerations.QuantityComparator> convertQuantityComparator(org.hl7.fhir.r4b.model.Enumeration<org.hl7.fhir.r4b.model.Enumerations.QuantityComparator> src) throws FHIRException {
037    if (src == null || src.isEmpty()) return null;
038    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());
039    ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().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(Enumerations.QuantityComparator.LESS_THAN);
046                    break;
047                case LESS_OR_EQUAL:
048                    tgt.setValue(Enumerations.QuantityComparator.LESS_OR_EQUAL);
049                    break;
050                case GREATER_OR_EQUAL:
051                    tgt.setValue(Enumerations.QuantityComparator.GREATER_OR_EQUAL);
052                    break;
053                case GREATER_THAN:
054                    tgt.setValue(Enumerations.QuantityComparator.GREATER_THAN);
055                    break;
056                default:
057                    tgt.setValue(Enumerations.QuantityComparator.NULL);
058                    break;
059       }
060}
061    return tgt;
062  }
063
064  public static org.hl7.fhir.r4b.model.Enumeration<org.hl7.fhir.r4b.model.Enumerations.QuantityComparator> convertQuantityComparator(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Enumerations.QuantityComparator> src) throws FHIRException {
065    if (src == null || src.isEmpty()) return null;
066    org.hl7.fhir.r4b.model.Enumeration<org.hl7.fhir.r4b.model.Enumerations.QuantityComparator> tgt = new org.hl7.fhir.r4b.model.Enumeration<>(new org.hl7.fhir.r4b.model.Enumerations.QuantityComparatorEnumFactory());
067    ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().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.r4b.model.Enumerations.QuantityComparator.LESS_THAN);
074                    break;
075                case LESS_OR_EQUAL:
076                    tgt.setValue(org.hl7.fhir.r4b.model.Enumerations.QuantityComparator.LESS_OR_EQUAL);
077                    break;
078                case GREATER_OR_EQUAL:
079                    tgt.setValue(org.hl7.fhir.r4b.model.Enumerations.QuantityComparator.GREATER_OR_EQUAL);
080                    break;
081                case GREATER_THAN:
082                    tgt.setValue(org.hl7.fhir.r4b.model.Enumerations.QuantityComparator.GREATER_THAN);
083                    break;
084                default:
085                    tgt.setValue(org.hl7.fhir.r4b.model.Enumerations.QuantityComparator.NULL);
086                    break;
087       }
088}
089    return tgt;
090  }
091
092  public static void copyQuantity(org.hl7.fhir.r4b.model.Quantity src, org.hl7.fhir.r5.model.Quantity tgt) throws FHIRException {
093    if (src == null || tgt == null) return;
094    ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().copyElement(src, tgt);
095    if (src.hasValue()) tgt.setValue(src.getValue());
096    if (src.hasComparator()) tgt.setComparatorElement(convertQuantityComparator(src.getComparatorElement()));
097    if (src.hasUnit()) tgt.setUnit(src.getUnit());
098    if (src.hasSystem()) tgt.setSystem(src.getSystem());
099    if (src.hasCode()) tgt.setCode(src.getCode());
100  }
101
102  public static void copyQuantity(org.hl7.fhir.r5.model.Quantity src, org.hl7.fhir.r4b.model.Quantity tgt) throws FHIRException {
103    if (src == null || tgt == null) return;
104    ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().copyElement(src, tgt);
105    if (src.hasValue()) tgt.setValue(src.getValue());
106    if (src.hasComparator()) tgt.setComparatorElement(convertQuantityComparator(src.getComparatorElement()));
107    if (src.hasUnit()) tgt.setUnit(src.getUnit());
108    if (src.hasSystem()) tgt.setSystem(src.getSystem());
109    if (src.hasCode()) tgt.setCode(src.getCode());
110  }
111}