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;
021
022import ca.uhn.fhir.jpa.model.entity.TagDefinition;
023import ca.uhn.fhir.model.dstu2.composite.MetaDt;
024import ca.uhn.fhir.model.dstu2.resource.Bundle;
025import ca.uhn.fhir.rest.api.server.RequestDetails;
026import jakarta.persistence.TypedQuery;
027import org.hl7.fhir.instance.model.api.IBaseBundle;
028
029import java.util.Collection;
030import java.util.List;
031
032public class FhirSystemDaoDstu2 extends BaseHapiFhirSystemDao<Bundle, MetaDt> {
033
034        @Override
035        public MetaDt metaGetOperation(RequestDetails theRequestDetails) {
036                String sql = "SELECT d FROM TagDefinition d WHERE d.myId IN (SELECT DISTINCT t.myTagId FROM ResourceTag t)";
037                TypedQuery<TagDefinition> q = myEntityManager.createQuery(sql, TagDefinition.class);
038                List<TagDefinition> tagDefinitions = q.getResultList();
039
040                MetaDt retVal = toMetaDt(tagDefinitions);
041
042                return retVal;
043        }
044
045        protected MetaDt toMetaDt(Collection<TagDefinition> tagDefinitions) {
046                MetaDt retVal = new MetaDt();
047                for (TagDefinition next : tagDefinitions) {
048                        switch (next.getTagType()) {
049                                case PROFILE:
050                                        retVal.addProfile(next.getCode());
051                                        break;
052                                case SECURITY_LABEL:
053                                        retVal.addSecurity()
054                                                        .setSystem(next.getSystem())
055                                                        .setCode(next.getCode())
056                                                        .setDisplay(next.getDisplay());
057                                        break;
058                                case TAG:
059                                        retVal.addTag()
060                                                        .setSystem(next.getSystem())
061                                                        .setCode(next.getCode())
062                                                        .setDisplay(next.getDisplay());
063                                        break;
064                        }
065                }
066                return retVal;
067        }
068
069        @Override
070        public IBaseBundle processMessage(RequestDetails theRequestDetails, IBaseBundle theMessage) {
071                return JpaResourceDao.throwProcessMessageNotImplemented();
072        }
073}