
001package ca.uhn.fhir.jpa.dao; 002 003/* 004 * #%L 005 * HAPI FHIR JPA Server 006 * %% 007 * Copyright (C) 2014 - 2022 Smile CDR, Inc. 008 * %% 009 * Licensed under the Apache License, Version 2.0 (the "License"); 010 * you may not use this file except in compliance with the License. 011 * You may obtain a copy of the License at 012 * 013 * http://www.apache.org/licenses/LICENSE-2.0 014 * 015 * Unless required by applicable law or agreed to in writing, software 016 * distributed under the License is distributed on an "AS IS" BASIS, 017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 018 * See the License for the specific language governing permissions and 019 * limitations under the License. 020 * #L% 021 */ 022 023import ca.uhn.fhir.jpa.model.entity.TagDefinition; 024import ca.uhn.fhir.model.dstu2.composite.MetaDt; 025import ca.uhn.fhir.model.dstu2.resource.Bundle; 026import ca.uhn.fhir.rest.api.RestOperationTypeEnum; 027import ca.uhn.fhir.rest.api.server.RequestDetails; 028import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails; 029import org.hl7.fhir.instance.model.api.IBaseBundle; 030 031import javax.persistence.TypedQuery; 032import java.util.Collection; 033import java.util.List; 034 035public class FhirSystemDaoDstu2 extends BaseHapiFhirSystemDao<Bundle, MetaDt> { 036 037 @Override 038 public MetaDt metaGetOperation(RequestDetails theRequestDetails) { 039 // Notify interceptors 040 ActionRequestDetails requestDetails = new ActionRequestDetails(theRequestDetails); 041 notifyInterceptors(RestOperationTypeEnum.META, requestDetails); 042 043 String sql = "SELECT d FROM TagDefinition d WHERE d.myId IN (SELECT DISTINCT t.myTagId FROM ResourceTag t)"; 044 TypedQuery<TagDefinition> q = myEntityManager.createQuery(sql, TagDefinition.class); 045 List<TagDefinition> tagDefinitions = q.getResultList(); 046 047 MetaDt retVal = toMetaDt(tagDefinitions); 048 049 return retVal; 050 } 051 052 protected MetaDt toMetaDt(Collection<TagDefinition> tagDefinitions) { 053 MetaDt retVal = new MetaDt(); 054 for (TagDefinition next : tagDefinitions) { 055 switch (next.getTagType()) { 056 case PROFILE: 057 retVal.addProfile(next.getCode()); 058 break; 059 case SECURITY_LABEL: 060 retVal.addSecurity().setSystem(next.getSystem()).setCode(next.getCode()).setDisplay(next.getDisplay()); 061 break; 062 case TAG: 063 retVal.addTag().setSystem(next.getSystem()).setCode(next.getCode()).setDisplay(next.getDisplay()); 064 break; 065 } 066 } 067 return retVal; 068 } 069 070 @Override 071 public IBaseBundle processMessage(RequestDetails theRequestDetails, IBaseBundle theMessage) { 072 return FhirResourceDaoMessageHeaderDstu2.throwProcessMessageNotImplemented(); 073 } 074 075}