View Javadoc
1   package ca.uhn.fhir.jpa.dao.dstu3;
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 ca.uhn.fhir.rest.api.CacheControlDirective;
28  import org.hl7.fhir.dstu3.model.Patient;
29  import org.hl7.fhir.instance.model.api.IIdType;
30  import org.hl7.fhir.instance.model.api.IPrimitiveType;
31  import org.springframework.beans.factory.annotation.Autowired;
32  
33  import ca.uhn.fhir.jpa.dao.*;
34  import ca.uhn.fhir.jpa.dao.SearchParameterMap.EverythingModeEnum;
35  import ca.uhn.fhir.model.api.IResource;
36  import ca.uhn.fhir.rest.api.Constants;
37  import ca.uhn.fhir.rest.api.SortSpec;
38  import ca.uhn.fhir.rest.api.server.IBundleProvider;
39  import ca.uhn.fhir.rest.api.server.RequestDetails;
40  import ca.uhn.fhir.rest.param.*;
41  
42  public class FhirResourceDaoPatientDstu3 extends FhirResourceDaoDstu3<Patient>implements IFhirResourceDaoPatient<Patient> {
43  
44  	@Autowired
45  	private ISearchParamRegistry mySerarchParamRegistry;
46  
47  	private IBundleProvider doEverythingOperation(IIdType theId, IPrimitiveType<Integer> theCount, DateRangeParam theLastUpdated, SortSpec theSort, StringAndListParam theContent, StringAndListParam theNarrative, RequestDetails theRequestDetails) {
48  		SearchParameterMap paramMap = new SearchParameterMap();
49  		if (theCount != null) {
50  			paramMap.setCount(theCount.getValue());
51  		}
52  		if (theContent != null) {
53  			paramMap.add(Constants.PARAM_CONTENT, theContent);
54  		}
55  		if (theNarrative != null) {
56  			paramMap.add(Constants.PARAM_TEXT, theNarrative);
57  		}
58  		paramMap.setIncludes(Collections.singleton(IResource.INCLUDE_ALL.asRecursive()));
59  		paramMap.setEverythingMode(theId != null ? EverythingModeEnum.PATIENT_INSTANCE : EverythingModeEnum.PATIENT_TYPE);
60  		paramMap.setSort(theSort);
61  		paramMap.setLastUpdated(theLastUpdated);
62  		if (theId != null) {
63  			paramMap.add("_id", new StringParam(theId.getIdPart()));
64  		}
65  		
66  		if (!isPagingProviderDatabaseBacked(theRequestDetails)) {
67  			paramMap.setLoadSynchronous(true);
68  		}
69  		
70  		return mySearchCoordinatorSvc.registerSearch(this, paramMap, getResourceName(), new CacheControlDirective().parse(theRequestDetails.getHeaders(Constants.HEADER_CACHE_CONTROL)));
71  	}
72  
73  	@Override
74  	public IBundleProvider patientInstanceEverything(HttpServletRequest theServletRequest, IIdType theId, IPrimitiveType<Integer> theCount, DateRangeParam theLastUpdated, SortSpec theSort, StringAndListParam theContent, StringAndListParam theNarrative, RequestDetails theRequestDetails) {
75  		return doEverythingOperation(theId, theCount, theLastUpdated, theSort, theContent, theNarrative, theRequestDetails);
76  	}
77  
78  	@Override
79  	public IBundleProvider patientTypeEverything(HttpServletRequest theServletRequest, IPrimitiveType<Integer> theCount, DateRangeParam theLastUpdated, SortSpec theSort, StringAndListParam theContent, StringAndListParam theNarrative, RequestDetails theRequestDetails) {
80  		return doEverythingOperation(null, theCount, theLastUpdated, theSort, theContent, theNarrative, theRequestDetails);
81  	}
82  
83  }