View Javadoc
1   package ca.uhn.fhir.rest.gclient;
2   
3   /*
4    * #%L
5    * HAPI FHIR - Core Library
6    * %%
7    * Copyright (C) 2014 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.util.List;
24  
25  import org.apache.commons.lang3.StringUtils;
26  
27  import ca.uhn.fhir.model.dstu.composite.IdentifierDt;
28  import ca.uhn.fhir.rest.param.ParameterUtil;
29  
30  class TokenCriterion implements ICriterion<TokenClientParam>, ICriterionInternal {
31  
32  	private String myValue;
33  	private String myName;
34  
35  	public TokenCriterion(String theName, String theSystem, String theCode) {
36  		myName = theName;
37  		myValue=toValue(theSystem, theCode);
38  	}
39  
40  	private String toValue(String theSystem, String theCode) {
41  		String system = ParameterUtil.escape(theSystem);
42  		String code = ParameterUtil.escape(theCode);
43  		String value;
44  		if (StringUtils.isNotBlank(system)) {
45  			value = system + "|" + StringUtils.defaultString(code);
46  		} else if (system == null) {
47  			value = StringUtils.defaultString(code);
48  		} else {
49  			value = "|" + StringUtils.defaultString(code);
50  		}
51  		return value;
52  	}
53  
54  	public TokenCriterion(String theParamName, List<IdentifierDt> theValue) {
55  		myName=theParamName;
56  		StringBuilder b = new StringBuilder();
57  		for (IdentifierDt next : theValue) {
58  			if (next.getSystem().isEmpty() && next.getValue().isEmpty()) {
59  				continue;
60  			}
61  			if (b.length() > 0) {
62  				b.append(',');
63  			}
64  			b.append(toValue(next.getSystem().getValueAsString(), next.getValue().getValue()));
65  		}
66  		myValue = b.toString();
67  	}
68  
69  	@Override
70  	public String getParameterValue() {
71  		return myValue;
72  	}
73  
74  	@Override
75  	public String getParameterName() {
76  		return myName;
77  	}
78  
79  }