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  	private IBundleProvider doEverythingOperation(IIdType theId, IPrimitiveType<Integer> theCount, DateRangeParam theLastUpdated, SortSpec theSort, StringAndListParam theContent, StringAndListParam theNarrative, RequestDetails theRequestDetails) {
45  		SearchParameterMap paramMap = new SearchParameterMap();
46  		if (theCount != null) {
47  			paramMap.setCount(theCount.getValue());
48  		}
49  		if (theContent != null) {
50  			paramMap.add(Constants.PARAM_CONTENT, theContent);
51  		}
52  		if (theNarrative != null) {
53  			paramMap.add(Constants.PARAM_TEXT, theNarrative);
54  		}
55  		paramMap.setIncludes(Collections.singleton(IResource.INCLUDE_ALL.asRecursive()));
56  		paramMap.setEverythingMode(theId != null ? EverythingModeEnum.PATIENT_INSTANCE : EverythingModeEnum.PATIENT_TYPE);
57  		paramMap.setSort(theSort);
58  		paramMap.setLastUpdated(theLastUpdated);
59  		if (theId != null) {
60  			paramMap.add("_id", new StringParam(theId.getIdPart()));
61  		}
62  		
63  		if (!isPagingProviderDatabaseBacked(theRequestDetails)) {
64  			paramMap.setLoadSynchronous(true);
65  		}
66  		
67  		return mySearchCoordinatorSvc.registerSearch(this, paramMap, getResourceName(), new CacheControlDirective().parse(theRequestDetails.getHeaders(Constants.HEADER_CACHE_CONTROL)));
68  	}
69  
70  	@Override
71  	public IBundleProvider patientInstanceEverything(HttpServletRequest theServletRequest, IIdType theId, IPrimitiveType<Integer> theCount, DateRangeParam theLastUpdated, SortSpec theSort, StringAndListParam theContent, StringAndListParam theNarrative, RequestDetails theRequestDetails) {
72  		return doEverythingOperation(theId, theCount, theLastUpdated, theSort, theContent, theNarrative, theRequestDetails);
73  	}
74  
75  	@Override
76  	public IBundleProvider patientTypeEverything(HttpServletRequest theServletRequest, IPrimitiveType<Integer> theCount, DateRangeParam theLastUpdated, SortSpec theSort, StringAndListParam theContent, StringAndListParam theNarrative, RequestDetails theRequestDetails) {
77  		return doEverythingOperation(null, theCount, theLastUpdated, theSort, theContent, theNarrative, theRequestDetails);
78  	}
79  
80  }