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.data;
021
022import ca.uhn.fhir.jpa.entity.TermValueSetConcept;
023import org.springframework.data.domain.Pageable;
024import org.springframework.data.jpa.repository.JpaRepository;
025import org.springframework.data.jpa.repository.Modifying;
026import org.springframework.data.jpa.repository.Query;
027import org.springframework.data.repository.query.Param;
028
029import java.util.List;
030import java.util.Optional;
031
032public interface ITermValueSetConceptDao extends JpaRepository<TermValueSetConcept, Long>, IHapiFhirJpaRepository {
033
034        @Query("SELECT COUNT(*) FROM TermValueSetConcept vsc WHERE vsc.myValueSetPid = :pid")
035        Integer countByTermValueSetId(@Param("pid") Long theValueSetId);
036
037        @Query("DELETE FROM TermValueSetConcept vsc WHERE vsc.myValueSetPid = :pid")
038        @Modifying
039        void deleteByTermValueSetId(@Param("pid") Long theValueSetId);
040
041        @Query("SELECT vsc FROM TermValueSetConcept vsc WHERE vsc.myValueSetPid = :pid AND vsc.mySystem = :system_url")
042        List<TermValueSetConcept> findByTermValueSetIdSystemOnly(
043                        Pageable thePage, @Param("pid") Long theValueSetId, @Param("system_url") String theSystem);
044
045        @Query(
046                        "SELECT vsc FROM TermValueSetConcept vsc WHERE vsc.myValueSetPid = :pid AND vsc.mySystem = :system_url AND vsc.myCode = :codeval")
047        Optional<TermValueSetConcept> findByTermValueSetIdSystemAndCode(
048                        @Param("pid") Long theValueSetId, @Param("system_url") String theSystem, @Param("codeval") String theCode);
049
050        @Query(
051                        "SELECT vsc FROM TermValueSetConcept vsc WHERE vsc.myValueSetPid = :pid AND vsc.mySystem = :system_url AND vsc.mySystemVer = :system_version AND vsc.myCode = :codeval")
052        Optional<TermValueSetConcept> findByTermValueSetIdSystemAndCodeWithVersion(
053                        @Param("pid") Long theValueSetId,
054                        @Param("system_url") String theSystem,
055                        @Param("system_version") String theSystemVersion,
056                        @Param("codeval") String theCode);
057
058        @Query(
059                        "SELECT vsc FROM TermValueSetConcept vsc WHERE vsc.myValueSet.myResourcePid = :resource_pid AND vsc.myCode = :codeval")
060        List<TermValueSetConcept> findByValueSetResourcePidAndCode(
061                        @Param("resource_pid") Long theValueSetId, @Param("codeval") String theCode);
062
063        @Query(
064                        "SELECT vsc FROM TermValueSetConcept vsc WHERE vsc.myValueSet.myResourcePid = :resource_pid AND vsc.mySystem = :system_url AND vsc.myCode = :codeval")
065        Optional<TermValueSetConcept> findByValueSetResourcePidSystemAndCode(
066                        @Param("resource_pid") Long theValueSetId,
067                        @Param("system_url") String theSystem,
068                        @Param("codeval") String theCode);
069
070        @Query(
071                        "SELECT vsc FROM TermValueSetConcept vsc WHERE vsc.myValueSet.myResourcePid = :resource_pid AND vsc.mySystem = :system_url AND vsc.mySystemVer = :system_version AND vsc.myCode = :codeval")
072        Optional<TermValueSetConcept> findByValueSetResourcePidSystemAndCodeWithVersion(
073                        @Param("resource_pid") Long theValueSetId,
074                        @Param("system_url") String theSystem,
075                        @Param("system_version") String theSystemVersion,
076                        @Param("codeval") String theCode);
077
078        @Query("SELECT vsc.myId FROM TermValueSetConcept vsc WHERE vsc.myValueSetPid = :pid ORDER BY vsc.myId")
079        List<Long> findIdsByTermValueSetId(@Param("pid") Long theValueSetId);
080
081        @Query("UPDATE TermValueSetConcept vsc SET vsc.myOrder = :order WHERE vsc.myId = :pid")
082        @Modifying
083        void updateOrderById(@Param("pid") Long theId, @Param("order") int theOrder);
084}