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