View Javadoc
1   package ca.uhn.fhir.jpa.provider;
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 ca.uhn.fhir.jpa.dao.IFhirSystemDao;
24  import ca.uhn.fhir.jpa.search.reindex.IResourceReindexingSvc;
25  import ca.uhn.fhir.jpa.util.ExpungeOptions;
26  import ca.uhn.fhir.jpa.util.ExpungeOutcome;
27  import ca.uhn.fhir.rest.annotation.At;
28  import ca.uhn.fhir.rest.annotation.History;
29  import ca.uhn.fhir.rest.annotation.Since;
30  import ca.uhn.fhir.rest.api.server.IBundleProvider;
31  import ca.uhn.fhir.rest.api.server.RequestDetails;
32  import ca.uhn.fhir.rest.param.DateRangeParam;
33  import org.hl7.fhir.instance.model.api.IPrimitiveType;
34  import org.hl7.fhir.r4.model.Parameters;
35  import org.springframework.beans.factory.annotation.Autowired;
36  import org.springframework.beans.factory.annotation.Required;
37  
38  import javax.servlet.http.HttpServletRequest;
39  import java.util.Date;
40  
41  public class BaseJpaSystemProvider<T, MT> extends BaseJpaProvider {
42  
43  	public static final String MARK_ALL_RESOURCES_FOR_REINDEXING = "$mark-all-resources-for-reindexing";
44  	public static final String PERFORM_REINDEXING_PASS = "$perform-reindexing-pass";
45  
46  	private IFhirSystemDao<T, MT> myDao;
47  	@Autowired
48  	private IResourceReindexingSvc myResourceReindexingSvc;
49  
50  	public BaseJpaSystemProvider() {
51  		// nothing
52  	}
53  
54  	protected IResourceReindexingSvc getResourceReindexingSvc() {
55  		return myResourceReindexingSvc;
56  	}
57  
58  	protected Parameters doExpunge(IPrimitiveType<? extends Integer> theLimit, IPrimitiveType<? extends Boolean> theExpungeDeletedResources, IPrimitiveType<? extends Boolean> theExpungeOldVersions, IPrimitiveType<? extends Boolean> theExpungeEverything) {
59  		ExpungeOptions options = createExpungeOptions(theLimit, theExpungeDeletedResources, theExpungeOldVersions, theExpungeEverything);
60  		ExpungeOutcome outcome = getDao().expunge(options);
61  		return createExpungeResponse(outcome);
62  	}
63  
64  	protected IFhirSystemDao<T, MT> getDao() {
65  		return myDao;
66  	}
67  
68  	@Required
69  	public void setDao(IFhirSystemDao<T, MT> theDao) {
70  		myDao = theDao;
71  	}
72  
73  	@History
74  	public IBundleProvider historyServer(HttpServletRequest theRequest, @Since Date theDate, @At DateRangeParam theAt, RequestDetails theRequestDetails) {
75  		startRequest(theRequest);
76  		try {
77  			DateRangeParam range = super.processSinceOrAt(theDate, theAt);
78  			return myDao.history(range.getLowerBoundAsInstant(), range.getUpperBoundAsInstant(), theRequestDetails);
79  		} finally {
80  			endRequest(theRequest);
81  		}
82  	}
83  
84  }