View Javadoc
1   package ca.uhn.fhir.context;
2   
3   import static org.apache.commons.lang3.StringUtils.isNotBlank;
4   import static org.apache.commons.lang3.StringUtils.trim;
5   
6   import java.util.*;
7   
8   import org.hl7.fhir.instance.model.api.IIdType;
9   
10  import ca.uhn.fhir.rest.api.RestSearchParameterTypeEnum;
11  
12  /*
13   * #%L
14   * HAPI FHIR - Core Library
15   * %%
16   * Copyright (C) 2014 - 2018 University Health Network
17   * %%
18   * Licensed under the Apache License, Version 2.0 (the "License");
19   * you may not use this file except in compliance with the License.
20   * You may obtain a copy of the License at
21   * 
22   *      http://www.apache.org/licenses/LICENSE-2.0
23   * 
24   * Unless required by applicable law or agreed to in writing, software
25   * distributed under the License is distributed on an "AS IS" BASIS,
26   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27   * See the License for the specific language governing permissions and
28   * limitations under the License.
29   * #L%
30   */
31  
32  public class RuntimeSearchParam {
33  	private final IIdType myId;
34  	private final Set<String> myBase;
35  	private final List<RuntimeSearchParam> myCompositeOf;
36  	private final String myDescription;
37  	private final String myName;
38  	private final RestSearchParameterTypeEnum myParamType;
39  	private final String myPath;
40  	private final Set<String> myTargets;
41  	private final Set<String> myProvidesMembershipInCompartments;
42  	private final RuntimeSearchParamStatusEnum myStatus;
43  	private final String myUri;
44  
45  	public IIdType getId() {
46  		return myId;
47  	}
48  
49  	public String getUri() {
50  		return myUri;
51  	}
52  
53  	public RuntimeSearchParam(IIdType theId, String theUri, String theName, String theDescription, String thePath, RestSearchParameterTypeEnum theParamType, List<RuntimeSearchParam> theCompositeOf,
54  									  Set<String> theProvidesMembershipInCompartments, Set<String> theTargets, RuntimeSearchParamStatusEnum theStatus) {
55  		this(theId, theUri, theName, theDescription, thePath, theParamType, theCompositeOf, theProvidesMembershipInCompartments, theTargets, theStatus, null);
56  	}
57  
58  	public RuntimeSearchParam(IIdType theId, String theUri, String theName, String theDescription, String thePath, RestSearchParameterTypeEnum theParamType, List<RuntimeSearchParam> theCompositeOf,
59  			Set<String> theProvidesMembershipInCompartments, Set<String> theTargets, RuntimeSearchParamStatusEnum theStatus, Collection<String> theBase) {
60  		super();
61  		myId = theId;
62  		myUri = theUri;
63  		myName = theName;
64  		myDescription = theDescription;
65  		myPath = thePath;
66  		myParamType = theParamType;
67  		myCompositeOf = theCompositeOf;
68  		myStatus = theStatus;
69  		if (theProvidesMembershipInCompartments != null && !theProvidesMembershipInCompartments.isEmpty()) {
70  			myProvidesMembershipInCompartments = Collections.unmodifiableSet(theProvidesMembershipInCompartments);
71  		} else {
72  			myProvidesMembershipInCompartments = null;
73  		}
74  		if (theTargets != null && theTargets.isEmpty() == false) {
75  			myTargets = Collections.unmodifiableSet(theTargets);
76  		} else {
77  			myTargets = null;
78  		}
79  
80  		if (theBase == null || theBase.isEmpty()) {
81  			HashSet<String> base = new HashSet<>();
82  			if (isNotBlank(thePath)) {
83  				int indexOf = thePath.indexOf('.');
84  				if (indexOf != -1) {
85  					base.add(trim(thePath.substring(0, indexOf)));
86  				}
87  			}
88  			myBase = Collections.unmodifiableSet(base);
89  		} else {
90  			myBase = Collections.unmodifiableSet(new HashSet<>(theBase));
91  		}
92  	}
93  
94  	public Set<String> getBase() {
95  		return myBase;
96  	}
97  
98  	public Set<String> getTargets() {
99  		return myTargets;
100 	}
101 
102 	public RuntimeSearchParamStatusEnum getStatus() {
103 		return myStatus;
104 	}
105 
106 	public RuntimeSearchParam(String theName, String theDescription, String thePath, RestSearchParameterTypeEnum theParamType, Set<String> theProvidesMembershipInCompartments, Set<String> theTargets, RuntimeSearchParamStatusEnum theStatus) {
107 		this(null, null, theName, theDescription, thePath, theParamType, null, theProvidesMembershipInCompartments, theTargets, theStatus);
108 	}
109 
110 	public List<RuntimeSearchParam> getCompositeOf() {
111 		return myCompositeOf;
112 	}
113 
114 	public String getDescription() {
115 		return myDescription;
116 	}
117 
118 	public String getName() {
119 		return myName;
120 	}
121 
122 	public RestSearchParameterTypeEnum getParamType() {
123 		return myParamType;
124 	}
125 
126 	public String getPath() {
127 		return myPath;
128 	}
129 
130 	public List<String> getPathsSplit() {
131 		String path = getPath();
132 		if (path.indexOf('|') == -1) {
133 			return Collections.singletonList(path);
134 		}
135 
136 		List<String> retVal = new ArrayList<String>();
137 		StringTokenizer tok = new StringTokenizer(path, "|");
138 		while (tok.hasMoreElements()) {
139 			String nextPath = tok.nextToken().trim();
140 			retVal.add(nextPath.trim());
141 		}
142 		return retVal;
143 	}
144 
145 	/**
146 	 * Can return null
147 	 */
148 	public Set<String> getProvidesMembershipInCompartments() {
149 		return myProvidesMembershipInCompartments;
150 	}
151 
152 	public enum RuntimeSearchParamStatusEnum {
153 		ACTIVE,
154 		DRAFT,
155 		RETIRED,
156 		UNKNOWN
157 	}
158 	
159 }