View Javadoc
1   package ca.uhn.fhir.jpa.dao;
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.context.FhirContext;
24  import ca.uhn.fhir.jpa.dao.r4.FhirResourceDaoSearchParameterR4;
25  import ca.uhn.fhir.jpa.entity.ResourceTable;
26  import ca.uhn.fhir.model.dstu2.composite.MetaDt;
27  import ca.uhn.fhir.model.dstu2.resource.Bundle;
28  import ca.uhn.fhir.model.dstu2.resource.SearchParameter;
29  import ca.uhn.fhir.model.dstu2.valueset.ResourceTypeEnum;
30  import ca.uhn.fhir.model.dstu2.valueset.SearchParamTypeEnum;
31  import ca.uhn.fhir.model.primitive.BoundCodeDt;
32  import org.springframework.beans.factory.annotation.Autowired;
33  
34  import java.util.Arrays;
35  import java.util.Collections;
36  import java.util.List;
37  
38  public class FhirResourceDaoSearchParameterDstu2 extends FhirResourceDaoDstu2<SearchParameter> implements IFhirResourceDaoSearchParameter<SearchParameter> {
39  
40  	@Autowired
41  	private IFhirSystemDao<Bundle, MetaDt> mySystemDao;
42  
43  	protected void markAffectedResources(SearchParameter theResource) {
44  		Boolean reindex = theResource != null ? CURRENTLY_REINDEXING.get(theResource) : null;
45  		String expression = theResource != null ? theResource.getXpath() : null;
46  		markResourcesMatchingExpressionAsNeedingReindexing(reindex, expression);
47  	}
48  
49  	@Override
50  	protected void postPersist(ResourceTable theEntity, SearchParameter theResource) {
51  		super.postPersist(theEntity, theResource);
52  		markAffectedResources(theResource);
53  	}
54  
55  	@Override
56  	protected void postUpdate(ResourceTable theEntity, SearchParameter theResource) {
57  		super.postUpdate(theEntity, theResource);
58  		markAffectedResources(theResource);
59  	}
60  
61  	@Override
62  	protected void preDelete(SearchParameter theResourceToDelete, ResourceTable theEntityToDelete) {
63  		super.preDelete(theResourceToDelete, theEntityToDelete);
64  		markAffectedResources(theResourceToDelete);
65  	}
66  
67  	@Override
68  	protected void validateResourceForStorage(SearchParameter theResource, ResourceTable theEntityToSave) {
69  		super.validateResourceForStorage(theResource, theEntityToSave);
70  
71  		Enum<?> status = theResource.getStatusElement().getValueAsEnum();
72  		List<BoundCodeDt<ResourceTypeEnum>> base = Collections.emptyList();
73  		if (theResource.getBase() != null) {
74  			base = Arrays.asList(theResource.getBaseElement());
75  		}
76  		String expression = theResource.getXpath();
77  		FhirContext context = getContext();
78  		SearchParamTypeEnum type = theResource.getTypeElement().getValueAsEnum();
79  
80  		FhirResourceDaoSearchParameterR4.validateSearchParam(type, status, base, expression, context, getConfig());
81  	}
82  
83  
84  }