001/*-
002 * #%L
003 * HAPI FHIR - Master Data Management
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.mdm.dao;
021
022import ca.uhn.fhir.i18n.Msg;
023import ca.uhn.fhir.mdm.api.IMdmLink;
024import ca.uhn.fhir.mdm.api.MdmLinkSourceEnum;
025import ca.uhn.fhir.mdm.api.MdmLinkWithRevision;
026import ca.uhn.fhir.mdm.api.MdmMatchResultEnum;
027import ca.uhn.fhir.mdm.api.paging.MdmPageRequest;
028import ca.uhn.fhir.mdm.api.params.MdmHistorySearchParameters;
029import ca.uhn.fhir.mdm.api.params.MdmQuerySearchParameters;
030import ca.uhn.fhir.mdm.model.MdmPidTuple;
031import ca.uhn.fhir.rest.api.server.storage.IResourcePersistentId;
032import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
033import org.hl7.fhir.instance.model.api.IIdType;
034import org.springframework.data.domain.Example;
035import org.springframework.data.domain.Page;
036import org.springframework.data.domain.Pageable;
037import org.springframework.data.history.Revisions;
038
039import java.util.Date;
040import java.util.List;
041import java.util.Optional;
042
043public interface IMdmLinkDao<P extends IResourcePersistentId, M extends IMdmLink<P>> {
044        int deleteWithAnyReferenceToPid(P thePid);
045
046        int deleteWithAnyReferenceToPidAndMatchResultNot(P thePid, MdmMatchResultEnum theMatchResult);
047
048        List<MdmPidTuple<P>> expandPidsFromGroupPidGivenMatchResult(
049                        P theGroupPid, MdmMatchResultEnum theMdmMatchResultEnum);
050
051        List<MdmPidTuple<P>> expandPidsBySourcePidAndMatchResult(P theSourcePid, MdmMatchResultEnum theMdmMatchResultEnum);
052
053        List<MdmPidTuple<P>> expandPidsByGoldenResourcePidAndMatchResult(
054                        P theSourcePid, MdmMatchResultEnum theMdmMatchResultEnum);
055
056        // TODO: on next bump, make this method non-default
057        default List<M> findLinksAssociatedWithGoldenResourceOfSourceResourceExcludingNoMatch(P theSourcePid) {
058                throw new UnsupportedOperationException(Msg.code(2428));
059        }
060
061        List<P> findPidByResourceNameAndThreshold(String theResourceName, Date theHighThreshold, Pageable thePageable);
062
063        List<P> findPidByResourceNameAndThresholdAndPartitionId(
064                        String theResourceName, Date theHighThreshold, List<Integer> thePartitionIds, Pageable thePageable);
065
066        List<M> findAllById(List<P> thePids);
067
068        Optional<M> findById(P thePid);
069
070        void deleteAll(List<M> theLinks);
071
072        List<M> findAll(Example<M> theExample);
073
074        List<M> findAll();
075
076        Long count();
077
078        void deleteAll();
079
080        M save(M theMdmLink);
081
082        Optional<M> findOne(Example<M> theExample);
083
084        void delete(M theMdmLink);
085
086        // TODO KHS is this method still required?  Probably not?  But leaving it in for now...
087        M validateMdmLink(IMdmLink theMdmLink) throws UnprocessableEntityException;
088
089        @Deprecated
090        Page<M> search(
091                        IIdType theGoldenResourceId,
092                        IIdType theSourceId,
093                        MdmMatchResultEnum theMatchResult,
094                        MdmLinkSourceEnum theLinkSource,
095                        MdmPageRequest thePageRequest,
096                        List<Integer> thePartitionId);
097
098        Page<M> search(MdmQuerySearchParameters theMdmQuerySearchParameters);
099
100        Optional<M> findBySourcePidAndMatchResult(P theSourcePid, MdmMatchResultEnum theMatch);
101
102        void deleteLinksWithAnyReferenceToPids(List<P> theResourcePersistentIds);
103
104        // TODO: LD:  delete for good on the next bump
105        @Deprecated(since = "6.5.6", forRemoval = true)
106        default Revisions<Long, M> findHistory(P thePid) {
107                throw new UnsupportedOperationException(Msg.code(2296) + "Deprecated and not supported in non-JPA");
108        }
109
110        default List<MdmLinkWithRevision<M>> getHistoryForIds(MdmHistorySearchParameters theMdmHistorySearchParameters) {
111                throw new UnsupportedOperationException(Msg.code(2299) + "not yet implemented");
112        }
113}