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