View Javadoc
1   package ca.uhn.fhir.jpa.dao;
2   
3   /*
4    * #%L
5    * HAPI FHIR JPA Server
6    * %%
7    * Copyright (C) 2014 - 2019 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 java.util.Collections;
24  
25  import javax.servlet.http.HttpServletRequest;
26  
27  import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
28  import org.hl7.fhir.instance.model.api.IIdType;
29  import org.hl7.fhir.instance.model.api.IPrimitiveType;
30  
31  import ca.uhn.fhir.jpa.searchparam.SearchParameterMap.EverythingModeEnum;
32  import ca.uhn.fhir.model.api.IResource;
33  import ca.uhn.fhir.model.dstu2.resource.Patient;
34  import ca.uhn.fhir.rest.api.*;
35  import ca.uhn.fhir.rest.api.server.IBundleProvider;
36  import ca.uhn.fhir.rest.api.server.RequestDetails;
37  import ca.uhn.fhir.rest.param.*;
38  import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails;
39  
40  public class FhirResourceDaoPatientDstu2 extends FhirResourceDaoDstu2<Patient>implements IFhirResourceDaoPatient<Patient> {
41  
42  	public FhirResourceDaoPatientDstu2() {
43  		super();
44  	}
45  	
46  	private IBundleProvider doEverythingOperation(IIdType theId, IPrimitiveType<Integer> theCount, DateRangeParam theLastUpdated, SortSpec theSort, StringAndListParam theContent, StringAndListParam theNarrative, RequestDetails theRequestDetails) {
47  		SearchParameterMap paramMap = new SearchParameterMap();
48  		if (theCount != null) {
49  			paramMap.setCount(theCount.getValue());
50  		}
51  		if (theContent != null) {
52  			paramMap.add(Constants.PARAM_CONTENT, theContent);
53  		}
54  		if (theNarrative != null) {
55  			paramMap.add(Constants.PARAM_TEXT, theNarrative);
56  		}
57  		paramMap.setIncludes(Collections.singleton(IResource.INCLUDE_ALL.asRecursive()));
58  		paramMap.setEverythingMode(theId != null ? EverythingModeEnum.PATIENT_INSTANCE : EverythingModeEnum.PATIENT_TYPE);
59  		paramMap.setSort(theSort);
60  		paramMap.setLastUpdated(theLastUpdated);
61  		if (theId != null) {
62  			paramMap.add("_id", new StringParam(theId.getIdPart()));
63  		}
64  		
65  		if (!isPagingProviderDatabaseBacked(theRequestDetails)) {
66  			paramMap.setLoadSynchronous(true);
67  		}
68  		
69  		return mySearchCoordinatorSvc.registerSearch(this, paramMap, getResourceName(), new CacheControlDirective().parse(theRequestDetails.getHeaders(Constants.HEADER_CACHE_CONTROL)));
70  	}
71  
72  	@Override
73  	public IBundleProvider patientInstanceEverything(HttpServletRequest theServletRequest, IIdType theId, IPrimitiveType<Integer> theCount, DateRangeParam theLastUpdated, SortSpec theSort, StringAndListParam theContent, StringAndListParam theNarrative, RequestDetails theRequestDetails) {
74  		// Notify interceptors
75  		ActionRequestDetails requestDetails = new ActionRequestDetails(theRequestDetails, getResourceName(), null);
76  		notifyInterceptors(RestOperationTypeEnum.EXTENDED_OPERATION_INSTANCE, requestDetails);
77  
78  		return doEverythingOperation(theId, theCount, theLastUpdated, theSort, theContent, theNarrative, theRequestDetails);
79  	}
80  
81  	@Override
82  	public IBundleProvider patientTypeEverything(HttpServletRequest theServletRequest, IPrimitiveType<Integer> theCount, DateRangeParam theLastUpdated, SortSpec theSort, StringAndListParam theContent, StringAndListParam theNarrative, RequestDetails theRequestDetails) {
83  		// Notify interceptors
84  		ActionRequestDetails requestDetails = new ActionRequestDetails(theRequestDetails, getResourceName(), null);
85  		notifyInterceptors(RestOperationTypeEnum.EXTENDED_OPERATION_TYPE, requestDetails);
86  
87  		return doEverythingOperation(null, theCount, theLastUpdated, theSort, theContent, theNarrative, theRequestDetails);
88  	}
89  
90  }