001package ca.uhn.fhir.jpa.dao.data;
002
003import ca.uhn.fhir.jpa.entity.TermCodeSystemVersion;
004import ca.uhn.fhir.jpa.entity.TermConcept;
005import org.springframework.data.domain.Page;
006import org.springframework.data.domain.Pageable;
007import org.springframework.data.jpa.repository.JpaRepository;
008import org.springframework.data.jpa.repository.Modifying;
009import org.springframework.data.jpa.repository.Query;
010import org.springframework.data.repository.query.Param;
011
012import java.util.List;
013import java.util.Optional;
014
015/*
016 * #%L
017 * HAPI FHIR JPA Server
018 * %%
019 * Copyright (C) 2014 - 2022 Smile CDR, Inc.
020 * %%
021 * Licensed under the Apache License, Version 2.0 (the "License");
022 * you may not use this file except in compliance with the License.
023 * You may obtain a copy of the License at
024 *
025 *      http://www.apache.org/licenses/LICENSE-2.0
026 *
027 * Unless required by applicable law or agreed to in writing, software
028 * distributed under the License is distributed on an "AS IS" BASIS,
029 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
030 * See the License for the specific language governing permissions and
031 * limitations under the License.
032 * #L%
033 */
034
035public interface ITermConceptDao extends JpaRepository<TermConcept, Long>, IHapiFhirJpaRepository {
036
037        @Query("SELECT t FROM TermConcept t " +
038                "LEFT JOIN FETCH t.myDesignations d " +
039                "WHERE t.myId IN :pids")
040        List<TermConcept> fetchConceptsAndDesignationsByPid(@Param("pids") List<Long> thePids);
041
042        @Query("SELECT t FROM TermConcept t " +
043                "LEFT JOIN FETCH t.myDesignations d " +
044                "WHERE t.myCodeSystemVersionPid = :pid")
045        List<TermConcept> fetchConceptsAndDesignationsByVersionPid(@Param("pid") Long theCodeSystemVersionPid);
046
047        @Query("SELECT COUNT(t) FROM TermConcept t WHERE t.myCodeSystem.myId = :cs_pid")
048        Integer countByCodeSystemVersion(@Param("cs_pid") Long thePid);
049
050        @Query("SELECT c FROM TermConcept c WHERE c.myCodeSystem = :code_system AND c.myCode = :code")
051        Optional<TermConcept> findByCodeSystemAndCode(@Param("code_system") TermCodeSystemVersion theCodeSystem, @Param("code") String theCode);
052
053        @Query("FROM TermConcept WHERE myCodeSystem = :code_system AND myCode in (:codeList)")
054        List<TermConcept> findByCodeSystemAndCodeList(@Param("code_system") TermCodeSystemVersion theCodeSystem, @Param("codeList") List<String> theCodeList);
055
056        @Modifying
057        @Query("DELETE FROM TermConcept WHERE myCodeSystem.myId = :cs_pid")
058        int deleteByCodeSystemVersion(@Param("cs_pid") Long thePid);
059
060        @Query("SELECT c FROM TermConcept c WHERE c.myCodeSystem = :code_system")
061        List<TermConcept> findByCodeSystemVersion(@Param("code_system") TermCodeSystemVersion theCodeSystem);
062
063        @Query("SELECT t FROM TermConcept t WHERE t.myIndexStatus = null")
064        Page<TermConcept> findResourcesRequiringReindexing(Pageable thePageRequest);
065
066}