View Javadoc
1   package ca.uhn.fhir.jpa.search;
2   
3   /*-
4    * #%L
5    * HAPI FHIR JPA Server
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.context.RuntimeSearchParam;
24  import ca.uhn.fhir.rest.api.RestSearchParameterTypeEnum;
25  import org.hl7.fhir.instance.model.api.IBaseReference;
26  import org.hl7.fhir.instance.model.api.IIdType;
27  import org.hl7.fhir.instance.model.api.IPrimitiveType;
28  
29  import java.util.*;
30  
31  import static org.apache.commons.lang3.StringUtils.isNotBlank;
32  
33  public class JpaRuntimeSearchParam extends RuntimeSearchParam {
34  
35  	private final boolean myUnique;
36  	private final List<Component> myComponents;
37  
38  	/**
39  	 * Constructor
40  	 */
41  	public JpaRuntimeSearchParam(IIdType theId, String theUri, String theName, String theDescription, String thePath, RestSearchParameterTypeEnum theParamType, Set<String> theProvidesMembershipInCompartments, Set<String> theTargets, RuntimeSearchParamStatusEnum theStatus, boolean theUnique, List<Component> theComponents, Collection<? extends IPrimitiveType<String>> theBase) {
42  		super(theId, theUri, theName, theDescription, thePath, theParamType, createCompositeList(theParamType), theProvidesMembershipInCompartments, theTargets, theStatus, toStrings(theBase));
43  		myUnique = theUnique;
44  		myComponents = Collections.unmodifiableList(theComponents);
45  	}
46  
47  	private static Collection<String> toStrings(Collection<? extends IPrimitiveType<String>> theBase) {
48  		HashSet<String> retVal = new HashSet<>();
49  		for (IPrimitiveType<String> next : theBase) {
50  			if (isNotBlank(next.getValueAsString())) {
51  				retVal.add(next.getValueAsString());
52  			}
53  		}
54  		return retVal;
55  	}
56  
57  	public List<Component> getComponents() {
58  		return myComponents;
59  	}
60  
61  	public boolean isUnique() {
62  		return myUnique;
63  	}
64  
65  	private static ArrayList<RuntimeSearchParam> createCompositeList(RestSearchParameterTypeEnum theParamType) {
66  		if (theParamType == RestSearchParameterTypeEnum.COMPOSITE) {
67  			return new ArrayList<>();
68  		} else {
69  			return null;
70  		}
71  	}
72  
73  	public static class Component {
74  		private final String myExpression;
75  		private final IBaseReference myReference;
76  
77  		public Component(String theExpression, IBaseReference theReference) {
78  			myExpression = theExpression;
79  			myReference = theReference;
80  
81  		}
82  
83  		public String getExpression() {
84  			return myExpression;
85  		}
86  
87  		public IBaseReference getReference() {
88  			return myReference;
89  		}
90  	}
91  
92  
93  }