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 ca.uhn.fhir.model.primitive.CodeDt;
33  import org.apache.commons.lang3.time.DateUtils;
34  import org.springframework.beans.factory.annotation.Autowired;
35  import org.springframework.scheduling.annotation.Scheduled;
36  import org.springframework.transaction.annotation.Propagation;
37  import org.springframework.transaction.annotation.Transactional;
38  
39  import java.util.ArrayList;
40  import java.util.Arrays;
41  import java.util.Collections;
42  import java.util.List;
43  
44  public class FhirResourceDaoSearchParameterDstu2 extends FhirResourceDaoDstu2<SearchParameter> implements IFhirResourceDaoSearchParameter<SearchParameter> {
45  
46  	@Autowired
47  	private IFhirSystemDao<Bundle, MetaDt> mySystemDao;
48  
49  	protected void markAffectedResources(SearchParameter theResource) {
50  		Boolean reindex = theResource != null ? CURRENTLY_REINDEXING.get(theResource) : null;
51  		String expression = theResource != null ? theResource.getXpath() : null;
52  		markResourcesMatchingExpressionAsNeedingReindexing(reindex, expression);
53  	}
54  
55  	@Override
56  	protected void postPersist(ResourceTable theEntity, SearchParameter theResource) {
57  		super.postPersist(theEntity, theResource);
58  		markAffectedResources(theResource);
59  	}
60  
61  	@Override
62  	protected void postUpdate(ResourceTable theEntity, SearchParameter theResource) {
63  		super.postUpdate(theEntity, theResource);
64  		markAffectedResources(theResource);
65  	}
66  
67  	@Override
68  	protected void preDelete(SearchParameter theResourceToDelete, ResourceTable theEntityToDelete) {
69  		super.preDelete(theResourceToDelete, theEntityToDelete);
70  		markAffectedResources(theResourceToDelete);
71  	}
72  
73  	@Override
74  	protected void validateResourceForStorage(SearchParameter theResource, ResourceTable theEntityToSave) {
75  		super.validateResourceForStorage(theResource, theEntityToSave);
76  
77  		Enum<?> status = theResource.getStatusElement().getValueAsEnum();
78  		List<BoundCodeDt<ResourceTypeEnum>> base = Collections.emptyList();
79  		if (theResource.getBase() != null) {
80  			base = Arrays.asList(theResource.getBaseElement());
81  		}
82  		String expression = theResource.getXpath();
83  		FhirContext context = getContext();
84  		SearchParamTypeEnum type = theResource.getTypeElement().getValueAsEnum();
85  
86  		FhirResourceDaoSearchParameterR4.validateSearchParam(type, status, base, expression, context);
87  	}
88  
89  
90  }