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