View Javadoc
1   package ca.uhn.fhir.jpa.dao.dstu3;
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.dstu3.model.Bundle;
30  import org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent;
31  import org.hl7.fhir.dstu3.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 FhirSystemDaoDstu3 extends BaseHapiFhirSystemDao<Bundle, Meta> {
42  
43  	@Autowired
44  	private TransactionProcessor<Bundle, BundleEntryComponent> myTransactionProcessor;
45  
46  	@PostConstruct
47  	public void start() {
48  		myTransactionProcessor.setDao(this);
49  	}
50  
51  	@Override
52  	public Meta metaGetOperation(RequestDetails theRequestDetails) {
53  		// Notify interceptors
54  		ActionRequestDetails requestDetails = new ActionRequestDetails(theRequestDetails);
55  		notifyInterceptors(RestOperationTypeEnum.META, requestDetails);
56  
57  		String sql = "SELECT d FROM TagDefinition d WHERE d.myId IN (SELECT DISTINCT t.myTagId FROM ResourceTag t)";
58  		TypedQuery<TagDefinition> q = myEntityManager.createQuery(sql, TagDefinition.class);
59  		List<TagDefinition> tagDefinitions = q.getResultList();
60  
61  		return toMeta(tagDefinitions);
62  	}
63  
64  	private Meta toMeta(Collection<TagDefinition> tagDefinitions) {
65  		Meta retVal = new Meta();
66  		for (TagDefinition next : tagDefinitions) {
67  			switch (next.getTagType()) {
68  				case PROFILE:
69  					retVal.addProfile(next.getCode());
70  					break;
71  				case SECURITY_LABEL:
72  					retVal.addSecurity().setSystem(next.getSystem()).setCode(next.getCode()).setDisplay(next.getDisplay());
73  					break;
74  				case TAG:
75  					retVal.addTag().setSystem(next.getSystem()).setCode(next.getCode()).setDisplay(next.getDisplay());
76  					break;
77  			}
78  		}
79  		return retVal;
80  	}
81  
82  	@Transactional(propagation = Propagation.NEVER)
83  	@Override
84  	public Bundle transaction(RequestDetails theRequestDetails, Bundle theRequest) {
85  		return myTransactionProcessor.transaction(theRequestDetails, theRequest);
86  	}
87  
88  
89  }