View Javadoc
1   package ca.uhn.fhir.jpa.dao.r4;
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.BaseHapiFhirSystemDao;
24  import ca.uhn.fhir.jpa.dao.TransactionProcessor;
25  import ca.uhn.fhir.jpa.entity.TagDefinition;
26  import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
27  import ca.uhn.fhir.rest.api.server.RequestDetails;
28  import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails;
29  import org.hl7.fhir.r4.model.Bundle;
30  import org.hl7.fhir.r4.model.Bundle.BundleEntryComponent;
31  import org.hl7.fhir.r4.model.Meta;
32  import org.springframework.beans.factory.annotation.Autowired;
33  import org.springframework.transaction.annotation.Propagation;
34  import org.springframework.transaction.annotation.Transactional;
35  
36  import javax.annotation.PostConstruct;
37  import javax.persistence.TypedQuery;
38  import java.util.Collection;
39  import java.util.List;
40  
41  public class FhirSystemDaoR4 extends BaseHapiFhirSystemDao<Bundle, Meta> {
42  
43  	private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirSystemDaoR4.class);
44  
45  	@Autowired
46  	private TransactionProcessor<Bundle, BundleEntryComponent> myTransactionProcessor;
47  
48  	@PostConstruct
49  	public void start() {
50  		myTransactionProcessor.setDao(this);
51  	}
52  
53  
54  	@Override
55  	public Meta metaGetOperation(RequestDetails theRequestDetails) {
56  		// Notify interceptors
57  		ActionRequestDetails requestDetails = new ActionRequestDetails(theRequestDetails);
58  		notifyInterceptors(RestOperationTypeEnum.META, requestDetails);
59  
60  		String sql = "SELECT d FROM TagDefinition d WHERE d.myId IN (SELECT DISTINCT t.myTagId FROM ResourceTag t)";
61  		TypedQuery<TagDefinition> q = myEntityManager.createQuery(sql, TagDefinition.class);
62  		List<TagDefinition> tagDefinitions = q.getResultList();
63  
64  		return toMeta(tagDefinitions);
65  	}
66  
67  
68  	protected Meta toMeta(Collection<TagDefinition> tagDefinitions) {
69  		Meta retVal = new Meta();
70  		for (TagDefinition next : tagDefinitions) {
71  			switch (next.getTagType()) {
72  				case PROFILE:
73  					retVal.addProfile(next.getCode());
74  					break;
75  				case SECURITY_LABEL:
76  					retVal.addSecurity().setSystem(next.getSystem()).setCode(next.getCode()).setDisplay(next.getDisplay());
77  					break;
78  				case TAG:
79  					retVal.addTag().setSystem(next.getSystem()).setCode(next.getCode()).setDisplay(next.getDisplay());
80  					break;
81  			}
82  		}
83  		return retVal;
84  	}
85  
86  	@Transactional(propagation = Propagation.NEVER)
87  	@Override
88  	public Bundle transaction(RequestDetails theRequestDetails, Bundle theRequest) {
89  		return myTransactionProcessor.transaction(theRequestDetails, theRequest);
90  	}
91  
92  }