001/*-
002 * #%L
003 * HAPI FHIR - Master Data Management
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.mdm.util;
021
022import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
023import ca.uhn.fhir.mdm.api.MdmConstants;
024import ca.uhn.fhir.mdm.rules.json.MdmRulesJson;
025import ca.uhn.fhir.rest.param.TokenAndListParam;
026import ca.uhn.fhir.rest.param.TokenParam;
027
028import static ca.uhn.fhir.rest.api.Constants.PARAM_TAG;
029import static org.hl7.fhir.dstu2016may.model.Basic.SP_IDENTIFIER;
030
031public class MdmSearchParamBuildingUtils {
032
033        /**
034         * Builds a search parameter map that can be used to find the
035         * golden resources associated with MDM blocked resources (ie, those
036         * resources that were omitted from MDM matching).
037         */
038        public static SearchParameterMap buildSearchParameterForBlockedResourceCount(String theResourceType) {
039                SearchParameterMap map = new SearchParameterMap();
040                map.setLoadSynchronous(true);
041                TokenAndListParam tagsToSearch = new TokenAndListParam();
042                tagsToSearch.addAnd(new TokenParam(MdmConstants.SYSTEM_GOLDEN_RECORD_STATUS, MdmConstants.CODE_GOLDEN_RECORD));
043                tagsToSearch.addAnd(new TokenParam(MdmConstants.SYSTEM_GOLDEN_RECORD_STATUS, MdmConstants.CODE_BLOCKED));
044
045                map.add(PARAM_TAG, tagsToSearch);
046                return map;
047        }
048
049        /**
050         * Creates a SearchParameterMap used for searching for golden resources
051         * by EID specifically.
052         */
053        public static SearchParameterMap buildEidSearchParameterMap(
054                        String theEid, String theResourceType, MdmRulesJson theMdmRules) {
055                SearchParameterMap map = buildBasicGoldenResourceSearchParameterMap(theEid);
056                map.add(
057                                SP_IDENTIFIER,
058                                new TokenParam(theMdmRules.getEnterpriseEIDSystemForResourceType(theResourceType), theEid));
059                return map;
060        }
061
062        /**
063         * Creates a SearchParameterMap that can be used to find golden resources.
064         */
065        public static SearchParameterMap buildBasicGoldenResourceSearchParameterMap(String theResourceType) {
066                SearchParameterMap map = new SearchParameterMap();
067                map.setLoadSynchronous(true);
068                map.add(PARAM_TAG, new TokenParam(MdmConstants.SYSTEM_GOLDEN_RECORD_STATUS, MdmConstants.CODE_GOLDEN_RECORD));
069                return map;
070        }
071}