
001/* 002 * #%L 003 * HAPI FHIR JPA Server 004 * %% 005 * Copyright (C) 2014 - 2023 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.r4; 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 org.hl7.fhir.instance.model.api.IBaseBundle; 027import org.hl7.fhir.r4.model.Bundle; 028import org.hl7.fhir.r4.model.Meta; 029 030import javax.persistence.TypedQuery; 031import java.util.Collection; 032import java.util.List; 033 034public class FhirSystemDaoR4 extends BaseHapiFhirSystemDao<Bundle, Meta> { 035 036 @Override 037 public Meta metaGetOperation(RequestDetails theRequestDetails) { 038 String sql = "SELECT d FROM TagDefinition d WHERE d.myId IN (SELECT DISTINCT t.myTagId FROM ResourceTag t)"; 039 TypedQuery<TagDefinition> q = myEntityManager.createQuery(sql, TagDefinition.class); 040 List<TagDefinition> tagDefinitions = q.getResultList(); 041 042 return toMeta(tagDefinitions); 043 } 044 045 @Override 046 public IBaseBundle processMessage(RequestDetails theRequestDetails, IBaseBundle theMessage) { 047 return JpaResourceDao.throwProcessMessageNotImplemented(); 048 } 049 050 051 protected Meta toMeta(Collection<TagDefinition> tagDefinitions) { 052 Meta retVal = new Meta(); 053 for (TagDefinition next : tagDefinitions) { 054 switch (next.getTagType()) { 055 case PROFILE: 056 retVal.addProfile(next.getCode()); 057 break; 058 case SECURITY_LABEL: 059 retVal.addSecurity().setSystem(next.getSystem()).setCode(next.getCode()).setDisplay(next.getDisplay()); 060 break; 061 case TAG: 062 retVal.addTag().setSystem(next.getSystem()).setCode(next.getCode()).setDisplay(next.getDisplay()); 063 break; 064 } 065 } 066 return retVal; 067 } 068 069}