View Javadoc
1   package ca.uhn.fhir.rest.gclient;
2   
3   import java.util.Collection;
4   
5   import ca.uhn.fhir.context.FhirContext;
6   import ca.uhn.fhir.model.primitive.IdDt;
7   
8   /*
9    * #%L
10   * HAPI FHIR - Core Library
11   * %%
12   * Copyright (C) 2014 - 2018 University Health Network
13   * %%
14   * Licensed under the Apache License, Version 2.0 (the "License");
15   * you may not use this file except in compliance with the License.
16   * You may obtain a copy of the License at
17   * 
18   *      http://www.apache.org/licenses/LICENSE-2.0
19   * 
20   * Unless required by applicable law or agreed to in writing, software
21   * distributed under the License is distributed on an "AS IS" BASIS,
22   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23   * See the License for the specific language governing permissions and
24   * limitations under the License.
25   * #L%
26   */
27  
28  
29  public class ReferenceClientParam extends BaseClientParam  implements IParam {
30  
31  	private String myName;
32  
33  	public ReferenceClientParam(String theName) {
34  		myName = theName;
35  	}
36  
37  	@Override
38  	public String getParamName() {
39  		return myName;
40  	}
41  	
42  	public ICriterion<ReferenceClientParam> hasChainedProperty(ICriterion<?> theCriterion) {
43  		return new ReferenceChainCriterion(getParamName(), theCriterion);
44  	}
45  
46  	/**
47  	 * Match the referenced resource if the resource has the given ID (this can be
48  	 * the logical ID or the absolute URL of the resource)
49  	 */
50  	public ICriterion<ReferenceClientParam> hasId(IdDt theId) {
51  		return new StringCriterion<ReferenceClientParam>(getParamName(), theId.getValue());
52  	}
53  
54  	/**
55  	 * Match the referenced resource if the resource has the given ID (this can be
56  	 * the logical ID or the absolute URL of the resource)
57  	 */
58  	public ICriterion<ReferenceClientParam> hasId(String theId) {
59  		return new StringCriterion<ReferenceClientParam>(getParamName(), theId);
60  	}
61  
62  	/**
63  	 * Match the referenced resource if the resource has ANY of the given IDs
64  	 * (this is an OR search, not an AND search), (this can be the logical ID or
65  	 * the absolute URL of the resource). Note that to specify an AND search,
66  	 * simply add a subsequent {@link IQuery#where(ICriterion) where} criteria
67  	 * with the same parameter.
68  	 */
69  	public ICriterion<ReferenceClientParam> hasAnyOfIds(Collection<String> theIds) {
70  		return new StringCriterion<ReferenceClientParam>(getParamName(), theIds);
71  	}
72  	
73  	private static class ReferenceChainCriterion implements ICriterion<ReferenceClientParam>, ICriterionInternal {
74  
75  		private String myParamName;
76  		private ICriterionInternal myWrappedCriterion;
77  
78  		public ReferenceChainCriterion(String theParamName, ICriterion<?> theWrappedCriterion) {
79  			myParamName = theParamName;
80  			myWrappedCriterion = (ICriterionInternal) theWrappedCriterion;
81  		}
82  
83  		@Override
84  		public String getParameterName() {
85  			return myParamName + "." + myWrappedCriterion.getParameterName();
86  		}
87  
88  		@Override
89  		public String getParameterValue(FhirContext theContext) {
90  			return myWrappedCriterion.getParameterValue(theContext);
91  		}
92  
93  	}
94  
95  }