001/*
002 * #%L
003 * HAPI FHIR JPA Server
004 * %%
005 * Copyright (C) 2014 - 2025 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.context.FhirVersionEnum;
023import ca.uhn.fhir.jpa.model.entity.NpmPackageVersionResourceEntity;
024import org.springframework.data.domain.Pageable;
025import org.springframework.data.domain.Slice;
026import org.springframework.data.jpa.repository.JpaRepository;
027import org.springframework.data.jpa.repository.Query;
028import org.springframework.data.repository.query.Param;
029
030public interface INpmPackageVersionResourceDao
031                extends JpaRepository<NpmPackageVersionResourceEntity, Long>, IHapiFhirJpaRepository {
032
033        @Query(
034                        "SELECT e FROM NpmPackageVersionResourceEntity e WHERE e.myResourceType = :resourceType AND e.myFhirVersion = :fhirVersion AND ((:isCurrentVersion IS null ) OR (e.myPackageVersion.myCurrentVersion = :isCurrentVersion))")
035        Slice<NpmPackageVersionResourceEntity> findByResourceType(
036                        Pageable thePage,
037                        @Param("fhirVersion") FhirVersionEnum theFhirVersion,
038                        @Param("resourceType") String theResourceType,
039                        @Param("isCurrentVersion") Boolean theIsCurrentVersion);
040
041        @Query(
042                        "SELECT e FROM NpmPackageVersionResourceEntity e WHERE e.myCanonicalUrl = :url AND e.myFhirVersion = :fhirVersion AND ((:isCurrentVersion IS null ) OR (e.myPackageVersion.myCurrentVersion = :isCurrentVersion))")
043        Slice<NpmPackageVersionResourceEntity> findByCanonicalUrl(
044                        Pageable thePage,
045                        @Param("fhirVersion") FhirVersionEnum theFhirVersion,
046                        @Param("url") String theCanonicalUrl,
047                        @Param("isCurrentVersion") Boolean theIsCurrentVersion);
048
049        @Query(
050                        "SELECT e FROM NpmPackageVersionResourceEntity e WHERE e.myCanonicalUrl = :url AND e.myCanonicalVersion = :version AND e.myFhirVersion = :fhirVersion AND ((:isCurrentVersion IS null ) OR (e.myPackageVersion.myCurrentVersion = :isCurrentVersion))")
051        Slice<NpmPackageVersionResourceEntity> findByCanonicalUrlAndVersion(
052                        Pageable theOf,
053                        @Param("fhirVersion") FhirVersionEnum theFhirVersion,
054                        @Param("url") String theCanonicalUrl,
055                        @Param("version") String theCanonicalVersion,
056                        @Param("isCurrentVersion") Boolean theIsCurrentVersion);
057
058        @Query(
059                        "SELECT e FROM NpmPackageVersionResourceEntity e WHERE e.myCanonicalUrl = :url AND e.myFhirVersion = :fhirVersion AND e.myPackageVersion.myPackageId = :packageId AND ((:isCurrentVersion IS null ) OR (e.myPackageVersion.myCurrentVersion = :isCurrentVersion))")
060        Slice<NpmPackageVersionResourceEntity> findByCanonicalUrlAndPackageId(
061                        Pageable theOf,
062                        @Param("fhirVersion") FhirVersionEnum theFhirVersion,
063                        @Param("url") String theCanonicalUrl,
064                        @Param("packageId") String thePackageId,
065                        @Param("isCurrentVersion") Boolean theIsCurrentVersion);
066
067        @Query(
068                        "SELECT e FROM NpmPackageVersionResourceEntity e WHERE e.myCanonicalUrl = :url AND e.myFhirVersion = :fhirVersion AND e.myPackageVersion.myPackageId = :packageId AND e.myPackageVersion.myVersionId = :versionId AND ((:isCurrentVersion IS null ) OR (e.myPackageVersion.myCurrentVersion = :isCurrentVersion))")
069        Slice<NpmPackageVersionResourceEntity> findByCanonicalUrlAndPackageIdAndVersion(
070                        Pageable theOf,
071                        @Param("fhirVersion") FhirVersionEnum theFhirVersion,
072                        @Param("url") String theCanonicalUrl,
073                        @Param("packageId") String thePackageId,
074                        @Param("versionId") String theVersionId,
075                        @Param("isCurrentVersion") Boolean theIsCurrentVersion);
076
077        @Query(
078                        "SELECT e FROM NpmPackageVersionResourceEntity e WHERE e.myCanonicalUrl = :url AND e.myCanonicalVersion = :version AND e.myFhirVersion = :fhirVersion AND e.myPackageVersion.myPackageId = :packageId AND ((:isCurrentVersion IS null ) OR (e.myPackageVersion.myCurrentVersion = :isCurrentVersion))")
079        Slice<NpmPackageVersionResourceEntity> findByCanonicalUrlAndVersionAndPackageId(
080                        Pageable theOf,
081                        @Param("fhirVersion") FhirVersionEnum theFhirVersion,
082                        @Param("url") String theCanonicalUrl,
083                        @Param("version") String theCanonicalVersion,
084                        @Param("packageId") String thePackageId,
085                        @Param("isCurrentVersion") Boolean theIsCurrentVersion);
086
087        @Query(
088                        "SELECT e FROM NpmPackageVersionResourceEntity e WHERE e.myCanonicalUrl = :url AND e.myCanonicalVersion = :version AND e.myFhirVersion = :fhirVersion AND e.myPackageVersion.myPackageId = :packageId AND e.myPackageVersion.myVersionId = :versionId AND ((:isCurrentVersion IS null ) OR (e.myPackageVersion.myCurrentVersion = :isCurrentVersion))")
089        Slice<NpmPackageVersionResourceEntity> findByCanonicalUrlAndVersionAndPackageIdAndVersion(
090                        Pageable theOf,
091                        @Param("fhirVersion") FhirVersionEnum theFhirVersion,
092                        @Param("url") String theCanonicalUrl,
093                        @Param("version") String theCanonicalVersion,
094                        @Param("packageId") String thePackageId,
095                        @Param("versionId") String theVersionId,
096                        @Param("isCurrentVersion") Boolean theIsCurrentVersion);
097}