001package ca.uhn.fhir.rest.server.interceptor.auth;
002
003/*-
004 * #%L
005 * HAPI FHIR - Server Framework
006 * %%
007 * Copyright (C) 2014 - 2022 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.rest.api.Constants;
024import ca.uhn.fhir.rest.api.server.RequestDetails;
025import org.hl7.fhir.instance.model.api.IBaseResource;
026import org.hl7.fhir.instance.model.api.IIdType;
027
028import java.util.Collection;
029import java.util.HashMap;
030import java.util.Map;
031
032public class RuleTarget {
033        IBaseResource resource;
034        Collection<IIdType> resourceIds = null;
035        String resourceType = null;
036        private Map<String, String[]> mySearchParams = null;
037
038        public Map<String, String[]> getSearchParams() {
039                return mySearchParams;
040        }
041
042        public void setSearchParams(RequestDetails theRequestDetails) {
043                mySearchParams = stripMdmSuffix(theRequestDetails.getParameters());
044        }
045
046        private Map<String, String[]> stripMdmSuffix(Map<String, String[]> theParameters) {
047                Map<String, String[]> retval = new HashMap<>();
048                for (Map.Entry<String, String[]> entry : theParameters.entrySet()) {
049                        String key = entry.getKey();
050                        String[] value = entry.getValue();
051                        key = stripMdmQualifier(key);
052                        key = stripNicknameQualifier(key);
053                        retval.put(key, value);
054                }
055                return retval;
056        }
057
058        private String stripMdmQualifier(String theKey) {
059                if (theKey.endsWith(Constants.PARAMQUALIFIER_MDM)) {
060                        theKey = theKey.split(Constants.PARAMQUALIFIER_MDM)[0];
061                }
062                return theKey;
063        }
064
065        private String stripNicknameQualifier(String theKey) {
066                if (theKey.endsWith(Constants.PARAMQUALIFIER_NICKNAME)) {
067                        theKey = theKey.split(Constants.PARAMQUALIFIER_NICKNAME)[0];
068                }
069                return theKey;
070        }
071}