001package ca.uhn.fhir.jpa.dao.r5;
002
003/*
004 * #%L
005 * HAPI FHIR JPA Server
006 * %%
007 * Copyright (C) 2014 - 2021 Smile CDR, Inc.
008 * %%
009 * Licensed under the Apache License, Version 2.0 (the "License");
010 * you may not use this file except in compliance with the License.
011 * You may obtain a copy of the License at
012 *
013 *      http://www.apache.org/licenses/LICENSE-2.0
014 *
015 * Unless required by applicable law or agreed to in writing, software
016 * distributed under the License is distributed on an "AS IS" BASIS,
017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018 * See the License for the specific language governing permissions and
019 * limitations under the License.
020 * #L%
021 */
022
023import ca.uhn.fhir.interceptor.model.RequestPartitionId;
024import ca.uhn.fhir.jpa.dao.BaseHapiFhirResourceDaoObservation;
025import ca.uhn.fhir.jpa.model.cross.IBasePersistedResource;
026import ca.uhn.fhir.jpa.model.entity.ResourceTable;
027import ca.uhn.fhir.jpa.partition.IRequestPartitionHelperSvc;
028import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
029import ca.uhn.fhir.rest.api.CacheControlDirective;
030import ca.uhn.fhir.rest.api.Constants;
031import ca.uhn.fhir.rest.api.server.IBundleProvider;
032import ca.uhn.fhir.rest.api.server.RequestDetails;
033import ca.uhn.fhir.rest.api.server.storage.TransactionDetails;
034import org.hl7.fhir.instance.model.api.IBaseResource;
035import org.hl7.fhir.r5.model.Observation;
036import org.springframework.beans.factory.annotation.Autowired;
037
038import javax.servlet.http.HttpServletResponse;
039import java.util.Date;
040
041public class FhirResourceDaoObservationR5 extends BaseHapiFhirResourceDaoObservation<Observation> {
042
043        @Autowired
044        private IRequestPartitionHelperSvc myPartitionHelperSvc;
045
046        @Override
047        public IBundleProvider observationsLastN(SearchParameterMap theSearchParameterMap,  RequestDetails theRequestDetails, HttpServletResponse theServletResponse) {
048
049                updateSearchParamsForLastn(theSearchParameterMap, theRequestDetails);
050
051                RequestPartitionId requestPartitionId = myPartitionHelperSvc.determineReadPartitionForRequestForSearchType(theRequestDetails, getResourceName(), theSearchParameterMap, null);
052                return mySearchCoordinatorSvc.registerSearch(this, theSearchParameterMap, getResourceName(), new CacheControlDirective().parse(theRequestDetails.getHeaders(Constants.HEADER_CACHE_CONTROL)), theRequestDetails, requestPartitionId);
053        }
054
055        @Override
056        protected String getEffectiveParamName() {
057                return Observation.SP_DATE;
058        }
059
060        @Override
061        protected String getCodeParamName() {
062                return Observation.SP_CODE;
063        }
064
065        @Override
066        protected String getSubjectParamName() {
067                return Observation.SP_SUBJECT;
068        }
069
070        @Override
071        protected String getPatientParamName() {
072                return Observation.SP_PATIENT;
073        }
074
075        @Override
076        public ResourceTable updateEntity(RequestDetails theRequest, IBaseResource theResource, IBasePersistedResource theEntity, Date theDeletedTimestampOrNull, boolean thePerformIndexing,
077                                                                                                 boolean theUpdateVersion, TransactionDetails theTransactionDetails, boolean theForceUpdate, boolean theCreateNewHistoryEntry) {
078                return updateObservationEntity(theRequest, theResource, theEntity, theDeletedTimestampOrNull,
079                        thePerformIndexing, theUpdateVersion, theTransactionDetails, theForceUpdate,
080                        theCreateNewHistoryEntry);
081        }
082
083}