View Javadoc
1   package ca.uhn.fhir.rest.gclient;
2   
3   import static org.apache.commons.lang3.StringUtils.*;
4   
5   import java.util.Arrays;
6   import java.util.List;
7   
8   import ca.uhn.fhir.model.dstu.composite.IdentifierDt;
9   
10  /*
11   * #%L
12   * HAPI FHIR - Core Library
13   * %%
14   * Copyright (C) 2014 University Health Network
15   * %%
16   * Licensed under the Apache License, Version 2.0 (the "License");
17   * you may not use this file except in compliance with the License.
18   * You may obtain a copy of the License at
19   * 
20   *      http://www.apache.org/licenses/LICENSE-2.0
21   * 
22   * Unless required by applicable law or agreed to in writing, software
23   * distributed under the License is distributed on an "AS IS" BASIS,
24   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25   * See the License for the specific language governing permissions and
26   * limitations under the License.
27   * #L%
28   */
29  
30  
31  /**
32   * Token parameter type for use in fluent client interfaces
33   */
34  public class TokenClientParam implements IParam {
35  
36  	private String myParamName;
37  
38  	@Override
39  	public String getParamName() {
40  		return myParamName;
41  	}
42  
43  	public TokenClientParam(String theParamName) {
44  		myParamName = theParamName;
45  	}
46  
47  	public IMatches exactly() {
48  		return new IMatches() {
49  			@Override
50  			public ICriterion<TokenClientParam> systemAndCode(String theSystem, String theCode) {
51  				return new TokenCriterion(getParamName(), defaultString(theSystem), theCode);
52  			}
53  
54  			@Override
55  			public ICriterion<TokenClientParam> systemAndIdentifier(String theSystem, String theCode) {
56  				return new TokenCriterion(getParamName(), defaultString(theSystem), theCode);
57  			}
58  
59  			@Override
60  			public ICriterion<TokenClientParam> code(String theCode) {
61  				return new TokenCriterion(getParamName(), null, theCode);
62  			}
63  
64  			@Override
65  			public ICriterion<TokenClientParam> identifier(String theIdentifier) {
66  				return new TokenCriterion(getParamName(), null, theIdentifier);
67  			}
68  
69  			@Override
70  			public ICriterion<TokenClientParam> identifier(IdentifierDt theIdentifier) {
71  				return new TokenCriterion(getParamName(), theIdentifier.getSystem().getValueAsString(), theIdentifier.getValue().getValue());
72  			}
73  
74  			@Override
75  			public ICriterion<TokenClientParam> identifiers(List<IdentifierDt> theIdentifiers) {
76  				return new TokenCriterion(getParamName(), theIdentifiers);
77  			}
78  
79  			@Override
80  			public ICriterion<TokenClientParam> identifiers(IdentifierDt... theIdentifiers) {
81  				return new TokenCriterion(getParamName(), Arrays.asList(theIdentifiers));
82  			}
83  };
84  	}
85  
86  	public interface IMatches {
87  		/**
88  		 * Creates a search criterion that matches against the given code system and code
89  		 * 
90  		 * @param theSystem
91  		 *            The code system (should be a URI)
92  		 * @param theCode
93  		 *            The code
94  		 * @return A criterion
95  		 */
96  		ICriterion<TokenClientParam> systemAndCode(String theSystem, String theCode);
97  
98  		/**
99  		 * Creates a search criterion that matches against the given system and identifier
100 		 * 
101 		 * @param theSystem
102 		 *            The code system (should be a URI)
103 		 * @param theIdentifier
104 		 *            The identifier
105 		 * @return A criterion
106 		 */
107 		ICriterion<TokenClientParam> systemAndIdentifier(String theSystem, String theIdentifier);
108 
109 		/**
110 		 * Creates a search criterion that matches against the given identifier, with no system specified
111 		 * 
112 		 * @param theIdentifier
113 		 *            The identifier
114 		 * @return A criterion
115 		 */
116 		ICriterion<TokenClientParam> identifier(String theIdentifier);
117 
118 		/**
119 		 * Creates a search criterion that matches against the given code, with no code system specified
120 		 * 
121 		 * @param theIdentifier
122 		 *            The identifier
123 		 * @return A criterion
124 		 */
125 		ICriterion<TokenClientParam> code(String theIdentifier);
126 
127 		/**
128 		 * Creates a search criterion that matches against the given identifier (system and code if both are present, or whatever is present)
129 		 * 
130 		 * @param theIdentifier
131 		 *            The identifier
132 		 * @return A criterion
133 		 */
134 		ICriterion<TokenClientParam> identifier(IdentifierDt theIdentifier);
135 		
136 		/**
137 		 * Creates a search criterion that matches against the given collection of identifiers (system and code if both are present, or whatever is present).
138 		 * In the query URL that is generated, identifiers will be joined with a ',' to create an OR query.
139 		 * 
140 		 * @param theIdentifier
141 		 *            The identifier
142 		 * @return A criterion
143 		 */
144 		ICriterion<TokenClientParam> identifiers(List<IdentifierDt> theIdentifiers);
145 
146 		/**
147 		 * Creates a search criterion that matches against the given collection of identifiers (system and code if both are present, or whatever is present).
148 		 * In the query URL that is generated, identifiers will be joined with a ',' to create an OR query.
149 		 * 
150 		 * @param theIdentifier
151 		 *            The identifier
152 		 * @return A criterion
153 		 */
154 		ICriterion<TokenClientParam> identifiers(IdentifierDt... theIdentifiers);
155 
156 	}
157 
158 }