View Javadoc
1   package ca.uhn.fhir.rest.gclient;
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 ca.uhn.fhir.rest.api.Constants;
24  import org.hl7.fhir.instance.model.api.IPrimitiveType;
25  
26  import java.util.Arrays;
27  import java.util.List;
28  
29  /**
30   * 
31   * @author james
32   *
33   */
34  public class  StringClientParam extends BaseClientParam implements IParam {
35  
36  	private final String myParamName;
37  
38  	public StringClientParam(String theParamName) {
39  		myParamName = theParamName;
40  	}
41  
42  	@Override
43  	public String getParamName() {
44  		return myParamName;
45  	}
46  
47  	/**
48  	 * The string matches the given value (servers will often, but are not required to) implement this as a left match,
49  	 * meaning that a value of "smi" would match "smi" and "smith".
50  	 */
51  	public IStringMatch matches() {
52  		return new StringMatches();
53  	}
54  
55  	/**
56  	 * The string matches exactly the given value
57  	 */
58  	public IStringMatch matchesExactly() {
59  		return new StringExactly();
60  	}
61  
62  	/**
63  	 * The string contains given value
64  	 */
65  	public IStringMatch contains() {
66  		return new StringContains();
67  	}
68  
69  	public interface IStringMatch {
70  
71  		/**
72  		 * Requests that resources be returned which match the given value
73  		 */
74  		ICriterion<StringClientParam> value(String theValue);
75  
76  		/**
77  		 * Requests that resources be returned which match ANY of the given values (this is an OR search, not an AND search). Note that to
78  		 * specify an AND search, simply add a subsequent {@link IQuery#where(ICriterion) where} criteria with the same
79  		 * parameter.
80  		 */
81  		ICriterion<StringClientParam> values(List<String> theValues);
82  
83  		/**
84  		 * Requests that resources be returned which match the given value
85  		 */
86  		ICriterion<StringClientParam> value(IPrimitiveType<String> theValue);
87  
88  		/**
89  		 * Requests that resources be returned which match ANY of the given values (this is an OR search, not an AND search). Note that to
90  		 * specify an AND search, simply add a subsequent {@link IQuery#where(ICriterion) where} criteria with the same
91  		 * parameter.
92  		 */
93  		ICriterion<?> values(String... theValues);
94  
95  	}
96  
97  	private class StringExactly implements IStringMatch {
98  		@Override
99  		public ICriterion<StringClientParam> value(String theValue) {
100 			return new StringCriterion<>(getParamName() + Constants.PARAMQUALIFIER_STRING_EXACT, theValue);
101 		}
102 
103 		@Override
104 		public ICriterion<StringClientParam> value(IPrimitiveType<String> theValue) {
105 			return new StringCriterion<>(getParamName() + Constants.PARAMQUALIFIER_STRING_EXACT, theValue.getValue());
106 		}
107 
108 		@Override
109 		public ICriterion<StringClientParam> values(List<String> theValue) {
110 			return new StringCriterion<>(getParamName() + Constants.PARAMQUALIFIER_STRING_EXACT, theValue);
111 		}
112 
113 		@Override
114 		public ICriterion<?> values(String... theValues) {
115 			return new StringCriterion<StringClientParam>(getParamName() + Constants.PARAMQUALIFIER_STRING_EXACT, Arrays.asList(theValues));
116 		}
117 	}
118 
119 	private class StringContains implements IStringMatch {
120 		@Override
121 		public ICriterion<StringClientParam> value(String theValue) {
122 			return new StringCriterion<>(getParamName() + Constants.PARAMQUALIFIER_STRING_CONTAINS, theValue);
123 		}
124 
125 		@Override
126 		public ICriterion<StringClientParam> value(IPrimitiveType<String> theValue) {
127 			return new StringCriterion<>(getParamName() + Constants.PARAMQUALIFIER_STRING_CONTAINS, theValue.getValue());
128 		}
129 
130 		@Override
131 		public ICriterion<StringClientParam> values(List<String> theValue) {
132 			return new StringCriterion<>(getParamName() + Constants.PARAMQUALIFIER_STRING_CONTAINS, theValue);
133 		}
134 
135 		@Override
136 		public ICriterion<?> values(String... theValues) {
137 			return new StringCriterion<StringClientParam>(getParamName() + Constants.PARAMQUALIFIER_STRING_CONTAINS, Arrays.asList(theValues));
138 		}
139 	}
140 
141 	private class StringMatches implements IStringMatch {
142 		@Override
143 		public ICriterion<StringClientParam> value(String theValue) {
144 			return new StringCriterion<>(getParamName(), theValue);
145 		}
146 
147 		@Override
148 		public ICriterion<StringClientParam> value(IPrimitiveType<String> theValue) {
149 			return new StringCriterion<>(getParamName(), theValue.getValue());
150 		}
151 
152 		@Override
153 		public ICriterion<StringClientParam> values(List<String> theValue) {
154 			return new StringCriterion<>(getParamName(), theValue);
155 		}
156 
157 		@Override
158 		public ICriterion<?> values(String... theValues) {
159 			return new StringCriterion<StringClientParam>(getParamName(), Arrays.asList(theValues));
160 		}
161 
162 	}
163 
164 }