001package ca.uhn.fhir.jpa.dao.dstu3;
002
003import ca.uhn.fhir.jpa.api.dao.IFhirResourceDaoSearchParameter;
004import ca.uhn.fhir.jpa.dao.BaseHapiFhirResourceDao;
005import ca.uhn.fhir.jpa.dao.r4.FhirResourceDaoSearchParameterR4;
006import ca.uhn.fhir.jpa.model.entity.ResourceTable;
007import ca.uhn.fhir.jpa.searchparam.extractor.ISearchParamExtractor;
008import org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_30_40;
009import org.hl7.fhir.convertors.factory.VersionConvertorFactory_30_40;
010import org.hl7.fhir.dstu3.model.SearchParameter;
011import org.springframework.beans.factory.annotation.Autowired;
012
013/*
014 * #%L
015 * HAPI FHIR JPA Server
016 * %%
017 * Copyright (C) 2014 - 2022 Smile CDR, Inc.
018 * %%
019 * Licensed under the Apache License, Version 2.0 (the "License");
020 * you may not use this file except in compliance with the License.
021 * You may obtain a copy of the License at
022 *
023 * http://www.apache.org/licenses/LICENSE-2.0
024 *
025 * Unless required by applicable law or agreed to in writing, software
026 * distributed under the License is distributed on an "AS IS" BASIS,
027 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
028 * See the License for the specific language governing permissions and
029 * limitations under the License.
030 * #L%
031 */
032
033public class FhirResourceDaoSearchParameterDstu3 extends BaseHapiFhirResourceDao<SearchParameter> implements IFhirResourceDaoSearchParameter<SearchParameter> {
034
035        @Autowired
036        private ISearchParamExtractor mySearchParamExtractor;
037
038        protected void markAffectedResources(SearchParameter theResource) {
039                Boolean reindex = theResource != null ? CURRENTLY_REINDEXING.get(theResource) : null;
040                String expression = theResource != null ? theResource.getExpression() : null;
041                markResourcesMatchingExpressionAsNeedingReindexing(reindex, expression);
042        }
043
044
045        @Override
046        protected void postPersist(ResourceTable theEntity, SearchParameter theResource) {
047                super.postPersist(theEntity, theResource);
048                markAffectedResources(theResource);
049        }
050
051        @Override
052        protected void postUpdate(ResourceTable theEntity, SearchParameter theResource) {
053                super.postUpdate(theEntity, theResource);
054                markAffectedResources(theResource);
055        }
056
057        @Override
058        protected void preDelete(SearchParameter theResourceToDelete, ResourceTable theEntityToDelete) {
059                super.preDelete(theResourceToDelete, theEntityToDelete);
060                markAffectedResources(theResourceToDelete);
061        }
062
063        @Override
064        protected void validateResourceForStorage(SearchParameter theResource, ResourceTable theEntityToSave) {
065                super.validateResourceForStorage(theResource, theEntityToSave);
066
067                org.hl7.fhir.r4.model.SearchParameter resource = (org.hl7.fhir.r4.model.SearchParameter) VersionConvertorFactory_30_40.convertResource(theResource, new BaseAdvisor_30_40(false));
068
069                FhirResourceDaoSearchParameterR4.validateSearchParam(
070                        resource,
071                        getContext(), getConfig(), mySearchParamRegistry, mySearchParamExtractor);
072        }
073
074}