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.rules.config; 021 022import ca.uhn.fhir.mdm.api.IMdmRuleValidator; 023import ca.uhn.fhir.mdm.api.IMdmSettings; 024import ca.uhn.fhir.mdm.rules.json.MdmRulesJson; 025import ca.uhn.fhir.util.JsonUtil; 026import org.springframework.beans.factory.annotation.Autowired; 027import org.springframework.stereotype.Component; 028 029import java.io.IOException; 030 031@Component 032public class MdmSettings implements IMdmSettings { 033 public static final int DEFAULT_CANDIDATE_SEARCH_LIMIT = 10000; 034 private final IMdmRuleValidator myMdmRuleValidator; 035 036 private boolean myEnabled; 037 private final int myConcurrentConsumers = MDM_DEFAULT_CONCURRENT_CONSUMERS; 038 private String myScriptText; 039 private String mySurvivorshipRules; 040 private MdmRulesJson myMdmRules; 041 private boolean myPreventEidUpdates; 042 private String myGoldenResourcePartitionName; 043 private boolean mySearchAllPartitionForMatch = false; 044 private boolean myShouldAutoDeleteGoldenResources = true; 045 046 /** 047 * If disabled, the underlying MDM system will operate under the following assumptions: 048 * <p> 049 * 1. Source resource may have more than 1 EID of the same system simultaneously. 050 * 2. During linking, incoming patient EIDs will be merged with existing Golden Resource EIDs. 051 */ 052 private boolean myPreventMultipleEids; 053 054 /** 055 * When searching for matching candidates, this is the maximum number of candidates that will be retrieved. If the 056 * number matched is equal to or higher than this, then an exception will be thrown and candidate matching will be aborted 057 */ 058 private int myCandidateSearchLimit = DEFAULT_CANDIDATE_SEARCH_LIMIT; 059 060 @Autowired 061 public MdmSettings(IMdmRuleValidator theMdmRuleValidator) { 062 myMdmRuleValidator = theMdmRuleValidator; 063 } 064 065 @Override 066 public boolean isEnabled() { 067 return myEnabled; 068 } 069 070 public MdmSettings setEnabled(boolean theEnabled) { 071 myEnabled = theEnabled; 072 return this; 073 } 074 075 @Override 076 public int getConcurrentConsumers() { 077 return myConcurrentConsumers; 078 } 079 080 public String getScriptText() { 081 return myScriptText; 082 } 083 084 public MdmSettings setScriptText(String theScriptText) throws IOException { 085 myScriptText = theScriptText; 086 setMdmRules(JsonUtil.deserialize(theScriptText, MdmRulesJson.class)); 087 return this; 088 } 089 090 @Override 091 public MdmRulesJson getMdmRules() { 092 return myMdmRules; 093 } 094 095 @Override 096 public boolean isPreventEidUpdates() { 097 return myPreventEidUpdates; 098 } 099 100 public MdmSettings setPreventEidUpdates(boolean thePreventEidUpdates) { 101 myPreventEidUpdates = thePreventEidUpdates; 102 return this; 103 } 104 105 public MdmSettings setMdmRules(MdmRulesJson theMdmRules) { 106 myMdmRuleValidator.validate(theMdmRules); 107 myMdmRules = theMdmRules; 108 return this; 109 } 110 111 public boolean isPreventMultipleEids() { 112 return myPreventMultipleEids; 113 } 114 115 @Override 116 public String getRuleVersion() { 117 return myMdmRules.getVersion(); 118 } 119 120 public MdmSettings setPreventMultipleEids(boolean thePreventMultipleEids) { 121 myPreventMultipleEids = thePreventMultipleEids; 122 return this; 123 } 124 125 @Override 126 public String getSurvivorshipRules() { 127 return mySurvivorshipRules; 128 } 129 130 public void setSurvivorshipRules(String theSurvivorshipRules) { 131 mySurvivorshipRules = theSurvivorshipRules; 132 } 133 134 @Override 135 public int getCandidateSearchLimit() { 136 return myCandidateSearchLimit; 137 } 138 139 public void setCandidateSearchLimit(int theCandidateSearchLimit) { 140 myCandidateSearchLimit = theCandidateSearchLimit; 141 } 142 143 @Override 144 public String getGoldenResourcePartitionName() { 145 return myGoldenResourcePartitionName; 146 } 147 148 @Override 149 public void setGoldenResourcePartitionName(String theGoldenResourcePartitionName) { 150 myGoldenResourcePartitionName = theGoldenResourcePartitionName; 151 } 152 153 @Override 154 public boolean getSearchAllPartitionForMatch() { 155 return mySearchAllPartitionForMatch; 156 } 157 158 @Override 159 public void setSearchAllPartitionForMatch(boolean theSearchAllPartitionForMatch) { 160 mySearchAllPartitionForMatch = theSearchAllPartitionForMatch; 161 } 162 163 @Override 164 public boolean isAutoExpungeGoldenResources() { 165 return myShouldAutoDeleteGoldenResources; 166 } 167 168 @Override 169 public void setAutoExpungeGoldenResources(boolean theShouldAutoExpunge) { 170 myShouldAutoDeleteGoldenResources = theShouldAutoExpunge; 171 } 172}