View Javadoc
1   package ca.uhn.fhir.jpa.provider;
2   
3   import static org.apache.commons.lang3.StringUtils.isNotBlank;
4   
5   import java.util.List;
6   
7   /*
8    * #%L
9    * HAPI FHIR JPA Server
10   * %%
11   * Copyright (C) 2014 - 2018 University Health Network
12   * %%
13   * Licensed under the Apache License, Version 2.0 (the "License");
14   * you may not use this file except in compliance with the License.
15   * You may obtain a copy of the License at
16   * 
17   *      http://www.apache.org/licenses/LICENSE-2.0
18   * 
19   * Unless required by applicable law or agreed to in writing, software
20   * distributed under the License is distributed on an "AS IS" BASIS,
21   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22   * See the License for the specific language governing permissions and
23   * limitations under the License.
24   * #L%
25   */
26  
27  import ca.uhn.fhir.jpa.dao.IFhirResourceDaoPatient;
28  import ca.uhn.fhir.jpa.util.JpaConstants;
29  import ca.uhn.fhir.model.api.annotation.Description;
30  import ca.uhn.fhir.model.dstu2.resource.Patient;
31  import ca.uhn.fhir.model.primitive.StringDt;
32  import ca.uhn.fhir.model.valueset.BundleTypeEnum;
33  import ca.uhn.fhir.rest.annotation.*;
34  import ca.uhn.fhir.rest.api.Constants;
35  import ca.uhn.fhir.rest.api.SortSpec;
36  import ca.uhn.fhir.rest.api.server.IBundleProvider;
37  import ca.uhn.fhir.rest.api.server.RequestDetails;
38  import ca.uhn.fhir.rest.param.*;
39  
40  public class BaseJpaResourceProviderPatientDstu2 extends JpaResourceProviderDstu2<Patient> {
41  
42  	/**
43  	 * Patient/123/$everything
44  	 */
45  	@Operation(name = JpaConstants.OPERATION_EVERYTHING, idempotent = true, bundleType=BundleTypeEnum.SEARCHSET)
46  	public IBundleProvider patientInstanceEverything(
47  
48  			javax.servlet.http.HttpServletRequest theServletRequest,
49  
50  			@IdParam 
51  			ca.uhn.fhir.model.primitive.IdDt theId,
52  			
53  			@Description(formalDefinition="Results from this method are returned across multiple pages. This parameter controls the size of those pages.") 
54  			@OperationParam(name = Constants.PARAM_COUNT) 
55  			ca.uhn.fhir.model.primitive.UnsignedIntDt theCount,
56  			
57  			@Description(shortDefinition="Only return resources which were last updated as specified by the given range")
58  			@OperationParam(name = Constants.PARAM_LASTUPDATED, min=0, max=1) 
59  			DateRangeParam theLastUpdated,
60  
61  			@Description(shortDefinition="Filter the resources to return only resources matching the given _content filter (note that this filter is applied only to results which link to the given patient, not to the patient itself or to supporting resources linked to by the matched resources)")
62  			@OperationParam(name = Constants.PARAM_CONTENT, min=0, max=OperationParam.MAX_UNLIMITED) 
63  			List<StringDt> theContent,
64  
65  			@Description(shortDefinition="Filter the resources to return only resources matching the given _text filter (note that this filter is applied only to results which link to the given patient, not to the patient itself or to supporting resources linked to by the matched resources)")
66  			@OperationParam(name = Constants.PARAM_TEXT, min=0, max=OperationParam.MAX_UNLIMITED) 
67  			List<StringDt> theNarrative,
68  
69  			@Sort
70  			SortSpec theSortSpec, 
71  			
72  			RequestDetails theRequestDetails
73  			) {
74  
75  		startRequest(theServletRequest);
76  		try {
77  			return ((IFhirResourceDaoPatient<Patient>) getDao()).patientInstanceEverything(theServletRequest, theId, theCount, theLastUpdated, theSortSpec, toStringAndList(theContent), toStringAndList(theNarrative), theRequestDetails);
78  		} finally {
79  			endRequest(theServletRequest);
80  		}
81  	}
82  
83  	/**
84  	 * /Patient/$everything
85  	 */
86  		@Operation(name = JpaConstants.OPERATION_EVERYTHING, idempotent = true, bundleType=BundleTypeEnum.SEARCHSET)
87  		public IBundleProvider patientTypeEverything(
88  
89  				javax.servlet.http.HttpServletRequest theServletRequest,
90  
91  				@Description(formalDefinition="Results from this method are returned across multiple pages. This parameter controls the size of those pages.") 
92  				@OperationParam(name = Constants.PARAM_COUNT) 
93  				ca.uhn.fhir.model.primitive.UnsignedIntDt theCount,
94  				
95  				@Description(shortDefinition="Only return resources which were last updated as specified by the given range")
96  				@OperationParam(name = Constants.PARAM_LASTUPDATED, min=0, max=1) 
97  				DateRangeParam theLastUpdated,
98  
99  				@Description(shortDefinition="Filter the resources to return only resources matching the given _content filter (note that this filter is applied only to results which link to the given patient, not to the patient itself or to supporting resources linked to by the matched resources)")
100 				@OperationParam(name = Constants.PARAM_CONTENT, min=0, max=OperationParam.MAX_UNLIMITED) 
101 				List<StringDt> theContent,
102 
103 				@Description(shortDefinition="Filter the resources to return only resources matching the given _text filter (note that this filter is applied only to results which link to the given patient, not to the patient itself or to supporting resources linked to by the matched resources)")
104 				@OperationParam(name = Constants.PARAM_TEXT, min=0, max=OperationParam.MAX_UNLIMITED) 
105 				List<StringDt> theNarrative,
106 
107 				@Sort
108 				SortSpec theSortSpec, 
109 				
110 				RequestDetails theRequestDetails
111 				) {
112 
113 		startRequest(theServletRequest);
114 		try {
115 			return ((IFhirResourceDaoPatient<Patient>) getDao()).patientTypeEverything(theServletRequest, theCount, theLastUpdated, theSortSpec, toStringAndList(theContent), toStringAndList(theNarrative), theRequestDetails);
116 		} finally {
117 			endRequest(theServletRequest);
118 		}
119 
120 	}
121 
122 	private StringAndListParam toStringAndList(List<StringDt> theNarrative) {
123 		StringAndListParam retVal = new StringAndListParam();
124 		if (theNarrative != null) {
125 			for (StringDt next : theNarrative) {
126 				if (isNotBlank(next.getValue())) {
127 					retVal.addAnd(new StringOrListParam().addOr(new StringParam(next.getValue())));
128 				}
129 			}
130 		}
131 		if (retVal.getValuesAsQueryTokens().isEmpty()) {
132 			return null;
133 		}
134 		return retVal;
135 	}
136 
137 }