View Javadoc
1   package ca.uhn.fhir.model.base.composite;
2   
3   /*
4    * #%L
5    * HAPI FHIR - Core Library
6    * %%
7    * Copyright (C) 2014 - 2018 University Health Network
8    * %%
9    * Licensed under the Apache License, Version 2.0 (the "License");
10   * you may not use this file except in compliance with the License.
11   * You may obtain a copy of the License at
12   * 
13   *      http://www.apache.org/licenses/LICENSE-2.0
14   * 
15   * Unless required by applicable law or agreed to in writing, software
16   * distributed under the License is distributed on an "AS IS" BASIS,
17   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18   * See the License for the specific language governing permissions and
19   * limitations under the License.
20   * #L%
21   */
22  
23  import java.math.BigDecimal;
24  
25  import org.apache.commons.lang3.StringUtils;
26  
27  import ca.uhn.fhir.context.FhirContext;
28  import ca.uhn.fhir.model.api.*;
29  import ca.uhn.fhir.model.primitive.*;
30  import ca.uhn.fhir.rest.param.ParamPrefixEnum;
31  import ca.uhn.fhir.rest.param.QuantityParam;
32  
33  public abstract class BaseQuantityDt extends BaseIdentifiableElement implements ICompositeDatatype, IQueryParameterType {
34  
35  	private static final long serialVersionUID = 1L;
36  
37  	/**
38  	 * Sets the value(s) for <b>value</b> (Numerical value (with implicit precision))
39  	 *
40       * <p>
41       * <b>Definition:</b>
42       * The value of the measured amount. The value includes an implicit precision in the presentation of the value
43       * </p> 
44  	 */
45  	public abstract BaseQuantityDt setValue(BigDecimal theValue);
46  
47  	
48  	@Override
49  	public void setValueAsQueryToken(FhirContext theContext, String theParamName, String theQualifier, String theValue) {
50  		getComparatorElement().setValue(null);
51  		setCode( null);
52  		setSystem(null);
53  		setUnits( null);
54  		setValue( null);
55  
56  		if (theValue == null) {
57  			return;
58  		}
59  		String[] parts = theValue.split("\\|");
60  		if (parts.length > 0 && StringUtils.isNotBlank(parts[0])) {
61  			if (parts[0].startsWith("le")) {
62  				//TODO: Use of a deprecated method should be resolved.
63  				getComparatorElement().setValue(ParamPrefixEnum.LESSTHAN_OR_EQUALS.getValue());
64  				setValue(new BigDecimal(parts[0].substring(2)));
65  			} else if (parts[0].startsWith("lt")) {
66  				//TODO: Use of a deprecated method should be resolved.
67  				getComparatorElement().setValue(ParamPrefixEnum.LESSTHAN.getValue());
68  				setValue(new BigDecimal(parts[0].substring(1)));
69  			} else if (parts[0].startsWith("ge")) {
70  				//TODO: Use of a deprecated method should be resolved.
71  				getComparatorElement().setValue(ParamPrefixEnum.GREATERTHAN_OR_EQUALS.getValue());
72  				setValue(new BigDecimal(parts[0].substring(2)));
73  			} else if (parts[0].startsWith("gt")) {
74  				//TODO: Use of a deprecated method should be resolved.
75  				getComparatorElement().setValue(ParamPrefixEnum.GREATERTHAN.getValue());
76  				setValue(new BigDecimal(parts[0].substring(1)));
77  			} else {
78  				setValue(new BigDecimal(parts[0]));
79  			}
80  		}
81  		if (parts.length > 1 && StringUtils.isNotBlank(parts[1])) {
82  			setSystem(parts[1]);
83  		}
84  		if (parts.length > 2 && StringUtils.isNotBlank(parts[2])) {
85  			setUnits(parts[2]);
86  		}
87  
88  	}
89  	
90  	/**
91  	 * Gets the value(s) for <b>comparator</b> (&lt; | &lt;= | &gt;= | &gt; - how to understand the value).
92  	 * creating it if it does
93  	 * not exist. Will not return <code>null</code>.
94  	 *
95       * <p>
96       * <b>Definition:</b>
97       * How the value should be understood and represented - whether the actual value is greater or less than 
98       * the stated value due to measurement issues. E.g. if the comparator is \"&lt;\" , then the real value is &lt; stated value
99       * </p> 
100 	 */
101 	public abstract BoundCodeDt<?> getComparatorElement();
102 
103 	@Override
104 	public String getValueAsQueryToken(FhirContext theContext) {
105 		StringBuilder b= new StringBuilder();
106 		if (getComparatorElement() != null) {
107 			b.append(getComparatorElement().getValue());
108 		}
109 		if (!getValueElement().isEmpty()) {
110 			b.append(getValueElement().getValueAsString());
111 		}
112 		b.append('|');
113 		if (!getSystemElement().isEmpty()) {
114 		b.append(getSystemElement().getValueAsString());
115 		}
116 		b.append('|');
117 		if (!getUnitsElement().isEmpty()) {
118 		b.append(getUnitsElement().getValueAsString());
119 		}
120 		
121 		return b.toString();
122 	}
123 	
124 
125 	@Override
126 	public String getQueryParameterQualifier() {
127 		return null;
128 	}	
129 	
130 	
131 	
132 	
133 
134  	/**
135 	 * Sets the value for <b>units</b> (Unit representation)
136 	 *
137      * <p>
138      * <b>Definition:</b>
139      * A human-readable form of the units
140      * </p> 
141 	 */
142 	public abstract BaseQuantityDt setUnits( String theString);
143 
144  
145 	/**
146 	 * Gets the value(s) for <b>system</b> (System that defines coded unit form).
147 	 * creating it if it does
148 	 * not exist. Will not return <code>null</code>.
149 	 *
150      * <p>
151      * <b>Definition:</b>
152      * The identification of the system that provides the coded form of the unit
153      * </p> 
154 	 */
155 	public abstract UriDt getSystemElement();
156 
157 	
158 
159  	/**
160 	 * Sets the value for <b>system</b> (System that defines coded unit form)
161 	 *
162      * <p>
163      * <b>Definition:</b>
164      * The identification of the system that provides the coded form of the unit
165      * </p> 
166 	 */
167 	public abstract BaseQuantityDt setSystem( String theUri);
168  
169 	/**
170 	 * Gets the value(s) for <b>code</b> (Coded form of the unit).
171 	 * creating it if it does
172 	 * not exist. Will not return <code>null</code>.
173 	 *
174      * <p>
175      * <b>Definition:</b>
176      * A computer processable form of the units in some unit representation system
177      * </p> 
178 	 */
179 	public abstract CodeDt getCodeElement();
180 
181  	/**
182 	 * Sets the value for <b>code</b> (Coded form of the unit)
183 	 *
184      * <p>
185      * <b>Definition:</b>
186      * A computer processable form of the units in some unit representation system
187      * </p> 
188 	 */
189 	public abstract BaseQuantityDt setCode( String theCode);
190 	/**
191 	 * Gets the value(s) for <b>units</b> (Unit representation).
192 	 * creating it if it does
193 	 * not exist. Will not return <code>null</code>.
194 	 *
195      * <p>
196      * <b>Definition:</b>
197      * A human-readable form of the units
198      * </p> 
199 	 */
200 	public abstract StringDt getUnitsElement() ;
201 	/**
202 	 * Gets the value(s) for <b>value</b> (Numerical value (with implicit precision)).
203 	 * creating it if it does
204 	 * not exist. Will not return <code>null</code>.
205 	 *
206      * <p>
207      * <b>Definition:</b>
208      * The value of the measured amount. The value includes an implicit precision in the presentation of the value
209      * </p> 
210 	 */
211 	public abstract DecimalDt getValueElement();
212 	
213 	/**
214 	 * <b>Not supported!</b>
215 	 * 
216 	 * @deprecated get/setMissing is not supported in StringDt. Use {@link QuantityParam} instead if you
217 	 * need this functionality
218 	 */
219 	@Deprecated
220 	@Override
221 	public Boolean getMissing() {
222 		return null;
223 	}
224 
225 	/**
226 	 * <b>Not supported!</b>
227 	 * 
228 	 * @deprecated get/setMissing is not supported in StringDt. Use {@link QuantityParam} instead if you
229 	 * need this functionality
230 	 */
231 	@Deprecated
232 	@Override
233 	public IQueryParameterType setMissing(Boolean theMissing) {
234 		throw new UnsupportedOperationException("get/setMissing is not supported in StringDt. Use {@link StringParam} instead if you need this functionality");
235 	}
236 
237 	
238 }