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