View Javadoc
1   package ca.uhn.fhir.rest.gclient;
2   
3   import static org.apache.commons.lang3.StringUtils.isNotBlank;
4   
5   import ca.uhn.fhir.context.FhirContext;
6   import ca.uhn.fhir.rest.param.ParamPrefixEnum;
7   import ca.uhn.fhir.rest.param.ParameterUtil;
8   
9   /*
10   * #%L
11   * HAPI FHIR - Core Library
12   * %%
13   * Copyright (C) 2014 - 2018 University Health Network
14   * %%
15   * Licensed under the Apache License, Version 2.0 (the "License");
16   * you may not use this file except in compliance with the License.
17   * You may obtain a copy of the License at
18   * 
19   *      http://www.apache.org/licenses/LICENSE-2.0
20   * 
21   * Unless required by applicable law or agreed to in writing, software
22   * distributed under the License is distributed on an "AS IS" BASIS,
23   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24   * See the License for the specific language governing permissions and
25   * limitations under the License.
26   * #L%
27   */
28  
29  class QuantityCriterion implements ICriterion<QuantityClientParam>, ICriterionInternal {
30  
31  	private String myValue;
32  	private String myName;
33  	private String mySystem;
34  	private String myUnits;
35  	private ParamPrefixEnum myPrefix;
36  
37  	public QuantityCriterion(String theParamName, ParamPrefixEnum thePrefix, String theValue, String theSystem, String theUnits) {
38  		myValue = theValue;
39  		myPrefix = thePrefix;
40  		myName = theParamName;
41  		mySystem = theSystem;
42  		myUnits = theUnits;
43  	}
44  
45  	@Override
46  	public String getParameterName() {
47  		return myName;
48  	}
49  
50  	@Override
51  	public String getParameterValue(FhirContext theContext) {
52  		StringBuilder b = new StringBuilder();
53  		if (isNotBlank(myValue) || isNotBlank(mySystem) || isNotBlank(myUnits)) {
54  			if (myPrefix != null) {
55  				b.append(ParameterUtil.escapeWithDefault(myPrefix.getValue()));
56  			}
57  			b.append(ParameterUtil.escapeWithDefault(myValue));
58  			b.append('|');
59  			b.append(ParameterUtil.escapeWithDefault(mySystem));
60  			b.append('|');
61  			b.append(ParameterUtil.escapeWithDefault(myUnits));
62  		}
63  		return b.toString();
64  	}
65  
66  }