001/*- 002 * #%L 003 * HAPI FHIR JPA Server - Master Data Management 004 * %% 005 * Copyright (C) 2014 - 2023 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.mdm.svc; 021 022import ca.uhn.fhir.jpa.api.svc.IIdHelperService; 023import ca.uhn.fhir.mdm.api.IMdmLink; 024import ca.uhn.fhir.mdm.api.MdmLinkJson; 025import ca.uhn.fhir.mdm.api.MdmLinkWithRevision; 026import ca.uhn.fhir.mdm.api.MdmLinkWithRevisionJson; 027import org.springframework.beans.factory.annotation.Autowired; 028 029public class MdmModelConverterSvcImpl implements IMdmModelConverterSvc { 030 031 @Autowired 032 IIdHelperService myIdHelperService; 033 034 @Override 035 public MdmLinkJson toJson(IMdmLink theLink) { 036 MdmLinkJson retVal = new MdmLinkJson(); 037 String sourceId = myIdHelperService 038 .resourceIdFromPidOrThrowException(theLink.getSourcePersistenceId(), theLink.getMdmSourceType()) 039 .toVersionless() 040 .getValue(); 041 retVal.setSourceId(sourceId); 042 String goldenResourceId = myIdHelperService 043 .resourceIdFromPidOrThrowException(theLink.getGoldenResourcePersistenceId(), theLink.getMdmSourceType()) 044 .toVersionless() 045 .getValue(); 046 retVal.setGoldenResourceId(goldenResourceId); 047 retVal.setCreated(theLink.getCreated()); 048 retVal.setEidMatch(theLink.getEidMatch()); 049 retVal.setLinkSource(theLink.getLinkSource()); 050 retVal.setMatchResult(theLink.getMatchResult()); 051 retVal.setLinkCreatedNewResource(theLink.getHadToCreateNewGoldenResource()); 052 retVal.setScore(theLink.getScore()); 053 retVal.setUpdated(theLink.getUpdated()); 054 retVal.setVector(theLink.getVector()); 055 retVal.setVersion(theLink.getVersion()); 056 retVal.setRuleCount(theLink.getRuleCount()); 057 return retVal; 058 } 059 060 @Override 061 public MdmLinkWithRevisionJson toJson(MdmLinkWithRevision<? extends IMdmLink<?>> theMdmLinkRevision) { 062 final MdmLinkJson mdmLinkJson = toJson(theMdmLinkRevision.getMdmLink()); 063 064 return new MdmLinkWithRevisionJson( 065 mdmLinkJson, 066 theMdmLinkRevision.getEnversRevision().getRevisionNumber(), 067 theMdmLinkRevision.getEnversRevision().getRevisionTimestamp()); 068 } 069}