001package ca.uhn.fhir.jpa.mdm.svc; 002 003/*- 004 * #%L 005 * HAPI FHIR JPA Server - Master Data Management 006 * %% 007 * Copyright (C) 2014 - 2023 Smile CDR, Inc. 008 * %% 009 * Licensed under the Apache License, Version 2.0 (the "License"); 010 * you may not use this file except in compliance with the License. 011 * You may obtain a copy of the License at 012 * 013 * http://www.apache.org/licenses/LICENSE-2.0 014 * 015 * Unless required by applicable law or agreed to in writing, software 016 * distributed under the License is distributed on an "AS IS" BASIS, 017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 018 * See the License for the specific language governing permissions and 019 * limitations under the License. 020 * #L% 021 */ 022 023import ca.uhn.fhir.jpa.mdm.dao.MdmLinkDaoSvc; 024import ca.uhn.fhir.mdm.api.IMdmLink; 025import ca.uhn.fhir.mdm.api.IMdmLinkQuerySvc; 026import ca.uhn.fhir.mdm.api.MdmLinkJson; 027import ca.uhn.fhir.mdm.api.MdmLinkSourceEnum; 028import ca.uhn.fhir.mdm.api.MdmMatchResultEnum; 029import ca.uhn.fhir.mdm.api.MdmQuerySearchParameters; 030import ca.uhn.fhir.mdm.api.paging.MdmPageRequest; 031import ca.uhn.fhir.mdm.model.MdmTransactionContext; 032import org.hl7.fhir.instance.model.api.IIdType; 033import org.slf4j.Logger; 034import org.slf4j.LoggerFactory; 035import org.springframework.beans.factory.annotation.Autowired; 036import org.springframework.data.domain.Page; 037import org.springframework.transaction.annotation.Transactional; 038 039import java.util.List; 040 041public class MdmLinkQuerySvcImplSvc implements IMdmLinkQuerySvc { 042 043 private static final Logger ourLog = LoggerFactory.getLogger(MdmLinkQuerySvcImplSvc.class); 044 045 @Autowired 046 MdmLinkDaoSvc myMdmLinkDaoSvc; 047 048 @Autowired 049 IMdmModelConverterSvc myMdmModelConverterSvc; 050 051 @Override 052 @Deprecated 053 @Transactional 054 public Page<MdmLinkJson> queryLinks(IIdType theGoldenResourceId, IIdType theSourceResourceId, MdmMatchResultEnum theMatchResult, MdmLinkSourceEnum theLinkSource, MdmTransactionContext theMdmContext, MdmPageRequest thePageRequest) { 055 MdmQuerySearchParameters mdmQuerySearchParameters = new MdmQuerySearchParameters(thePageRequest) 056 .setGoldenResourceId(theGoldenResourceId) 057 .setSourceId(theSourceResourceId) 058 .setMatchResult(theMatchResult) 059 .setLinkSource(theLinkSource); 060 061 return queryLinks(mdmQuerySearchParameters, theMdmContext); 062 } 063 064 @Override 065 @Deprecated 066 @Transactional 067 public Page<MdmLinkJson> queryLinks(IIdType theGoldenResourceId, IIdType theSourceResourceId, MdmMatchResultEnum theMatchResult, MdmLinkSourceEnum theLinkSource, MdmTransactionContext theMdmContext, MdmPageRequest thePageRequest, List<Integer> thePartitionIds) { 068 MdmQuerySearchParameters mdmQuerySearchParameters = new MdmQuerySearchParameters(thePageRequest) 069 .setGoldenResourceId(theGoldenResourceId) 070 .setSourceId(theSourceResourceId) 071 .setMatchResult(theMatchResult) 072 .setLinkSource(theLinkSource) 073 .setPartitionIds(thePartitionIds); 074 075 return queryLinks(mdmQuerySearchParameters, theMdmContext); 076 } 077 078 @Override 079 @Transactional 080 public Page<MdmLinkJson> queryLinks(MdmQuerySearchParameters theMdmQuerySearchParameters, MdmTransactionContext theMdmContext) { 081 @SuppressWarnings("unchecked") 082 Page<? extends IMdmLink> mdmLinks = myMdmLinkDaoSvc.executeTypedQuery(theMdmQuerySearchParameters); 083 return mdmLinks.map(myMdmModelConverterSvc::toJson); 084 } 085 086 087 @Override 088 @Transactional 089 public Page<MdmLinkJson> getDuplicateGoldenResources(MdmTransactionContext theMdmContext, MdmPageRequest thePageRequest) { 090 return getDuplicateGoldenResources(theMdmContext, thePageRequest, null, null); 091 } 092 093 @Override 094 @Transactional 095 public Page<MdmLinkJson> getDuplicateGoldenResources(MdmTransactionContext theMdmContext, MdmPageRequest thePageRequest, 096 List<Integer> thePartitionIds, String theRequestResourceType) { 097 MdmQuerySearchParameters mdmQuerySearchParameters = new MdmQuerySearchParameters(thePageRequest) 098 .setMatchResult(MdmMatchResultEnum.POSSIBLE_DUPLICATE) 099 .setPartitionIds(thePartitionIds) 100 .setResourceType(theRequestResourceType); 101 102 @SuppressWarnings("unchecked") 103 Page<? extends IMdmLink> mdmLinkPage = myMdmLinkDaoSvc.executeTypedQuery(mdmQuerySearchParameters); 104 return mdmLinkPage.map(myMdmModelConverterSvc::toJson); 105 } 106}