ca.uhn.fhir.model.base.composite.BaseQuantityDt Maven / Gradle / Ivy
/*
* #%L
* HAPI FHIR - Core Library
* %%
* Copyright (C) 2014 - 2024 Smile CDR, Inc.
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package ca.uhn.fhir.model.base.composite;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.i18n.Msg;
import ca.uhn.fhir.model.api.BaseIdentifiableElement;
import ca.uhn.fhir.model.api.ICompositeDatatype;
import ca.uhn.fhir.model.api.IQueryParameterType;
import ca.uhn.fhir.model.primitive.BoundCodeDt;
import ca.uhn.fhir.model.primitive.CodeDt;
import ca.uhn.fhir.model.primitive.DecimalDt;
import ca.uhn.fhir.model.primitive.StringDt;
import ca.uhn.fhir.model.primitive.UriDt;
import ca.uhn.fhir.rest.param.ParamPrefixEnum;
import ca.uhn.fhir.rest.param.QuantityParam;
import org.apache.commons.lang3.StringUtils;
import java.math.BigDecimal;
public abstract class BaseQuantityDt extends BaseIdentifiableElement
implements ICompositeDatatype, IQueryParameterType {
private static final long serialVersionUID = 1L;
/**
* Sets the value(s) for value (Numerical value (with implicit precision))
*
*
* Definition:
* The value of the measured amount. The value includes an implicit precision in the presentation of the value
*
*/
public abstract BaseQuantityDt setValue(BigDecimal theValue);
@Override
public void setValueAsQueryToken(
FhirContext theContext, String theParamName, String theQualifier, String theValue) {
getComparatorElement().setValue(null);
setCode(null);
setSystem(null);
setUnits(null);
setValue(null);
if (theValue == null) {
return;
}
String[] parts = theValue.split("\\|");
if (parts.length > 0 && StringUtils.isNotBlank(parts[0])) {
if (parts[0].startsWith("le")) {
// TODO: Use of a deprecated method should be resolved.
getComparatorElement().setValue(ParamPrefixEnum.LESSTHAN_OR_EQUALS.getValue());
setValue(new BigDecimal(parts[0].substring(2)));
} else if (parts[0].startsWith("lt")) {
// TODO: Use of a deprecated method should be resolved.
getComparatorElement().setValue(ParamPrefixEnum.LESSTHAN.getValue());
setValue(new BigDecimal(parts[0].substring(1)));
} else if (parts[0].startsWith("ge")) {
// TODO: Use of a deprecated method should be resolved.
getComparatorElement().setValue(ParamPrefixEnum.GREATERTHAN_OR_EQUALS.getValue());
setValue(new BigDecimal(parts[0].substring(2)));
} else if (parts[0].startsWith("gt")) {
// TODO: Use of a deprecated method should be resolved.
getComparatorElement().setValue(ParamPrefixEnum.GREATERTHAN.getValue());
setValue(new BigDecimal(parts[0].substring(1)));
} else {
setValue(new BigDecimal(parts[0]));
}
}
if (parts.length > 1 && StringUtils.isNotBlank(parts[1])) {
setSystem(parts[1]);
}
if (parts.length > 2 && StringUtils.isNotBlank(parts[2])) {
setUnits(parts[2]);
}
}
/**
* Gets the value(s) for comparator (< | <= | >= | > - how to understand the value).
* creating it if it does
* not exist. Will not return null
.
*
*
* Definition:
* How the value should be understood and represented - whether the actual value is greater or less than
* the stated value due to measurement issues. E.g. if the comparator is \"<\" , then the real value is < stated value
*
*/
public abstract BoundCodeDt> getComparatorElement();
@Override
public String getValueAsQueryToken(FhirContext theContext) {
StringBuilder b = new StringBuilder();
if (getComparatorElement() != null) {
b.append(getComparatorElement().getValue());
}
if (!getValueElement().isEmpty()) {
b.append(getValueElement().getValueAsString());
}
b.append('|');
if (!getSystemElement().isEmpty()) {
b.append(getSystemElement().getValueAsString());
}
b.append('|');
if (!getUnitsElement().isEmpty()) {
b.append(getUnitsElement().getValueAsString());
}
return b.toString();
}
@Override
public String getQueryParameterQualifier() {
return null;
}
/**
* Sets the value for units (Unit representation)
*
*
* Definition:
* A human-readable form of the units
*
*/
public abstract BaseQuantityDt setUnits(String theString);
/**
* Gets the value(s) for system (System that defines coded unit form).
* creating it if it does
* not exist. Will not return null
.
*
*
* Definition:
* The identification of the system that provides the coded form of the unit
*
*/
public abstract UriDt getSystemElement();
/**
* Sets the value for system (System that defines coded unit form)
*
*
* Definition:
* The identification of the system that provides the coded form of the unit
*
*/
public abstract BaseQuantityDt setSystem(String theUri);
/**
* Gets the value(s) for code (Coded form of the unit).
* creating it if it does
* not exist. Will not return null
.
*
*
* Definition:
* A computer processable form of the units in some unit representation system
*
*/
public abstract CodeDt getCodeElement();
/**
* Sets the value for code (Coded form of the unit)
*
*
* Definition:
* A computer processable form of the units in some unit representation system
*
*/
public abstract BaseQuantityDt setCode(String theCode);
/**
* Gets the value(s) for units (Unit representation).
* creating it if it does
* not exist. Will not return null
.
*
*
* Definition:
* A human-readable form of the units
*
*/
public abstract StringDt getUnitsElement();
/**
* Gets the value(s) for value (Numerical value (with implicit precision)).
* creating it if it does
* not exist. Will not return null
.
*
*
* Definition:
* The value of the measured amount. The value includes an implicit precision in the presentation of the value
*
*/
public abstract DecimalDt getValueElement();
/**
* Not supported!
*
* @deprecated get/setMissing is not supported in StringDt. Use {@link QuantityParam} instead if you
* need this functionality
*/
@Deprecated
@Override
public Boolean getMissing() {
return null;
}
/**
* Not supported!
*
* @deprecated get/setMissing is not supported in StringDt. Use {@link QuantityParam} instead if you
* need this functionality
*/
@Deprecated
@Override
public IQueryParameterType setMissing(Boolean theMissing) {
throw new UnsupportedOperationException(
Msg.code(1904)
+ "get/setMissing is not supported in StringDt. Use {@link StringParam} instead if you need this functionality");
}
}