001/*-
002 * #%L
003 * HAPI FHIR JPA - Search Parameters
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.jpa.searchparam;
021
022import ca.uhn.fhir.model.api.IQueryParameterAnd;
023import ca.uhn.fhir.model.api.IQueryParameterType;
024import ca.uhn.fhir.rest.api.Constants;
025import ca.uhn.fhir.rest.param.HasAndListParam;
026import ca.uhn.fhir.rest.param.HasParam;
027import ca.uhn.fhir.rest.param.StringAndListParam;
028import ca.uhn.fhir.rest.param.StringParam;
029import ca.uhn.fhir.rest.param.TokenAndListParam;
030import ca.uhn.fhir.rest.param.TokenParam;
031import ca.uhn.fhir.rest.param.UriAndListParam;
032import ca.uhn.fhir.rest.param.UriParam;
033import org.hl7.fhir.instance.model.api.IAnyResource;
034
035import java.util.Collections;
036import java.util.HashMap;
037import java.util.Map;
038import java.util.Set;
039
040import static ca.uhn.fhir.rest.api.Constants.PARAM_LASTUPDATED;
041import static ca.uhn.fhir.rest.api.Constants.PARAM_PROFILE;
042import static ca.uhn.fhir.rest.api.Constants.PARAM_SECURITY;
043import static ca.uhn.fhir.rest.api.Constants.PARAM_TAG;
044
045public class ResourceMetaParams {
046        /**
047         * These are parameters which are supported by searches
048         */
049        public static final Map<String, Class<? extends IQueryParameterAnd<?>>> RESOURCE_META_AND_PARAMS;
050        /**
051         * These are parameters which are supported by searches
052         */
053        public static final Map<String, Class<? extends IQueryParameterType>> RESOURCE_META_PARAMS;
054
055        public static final Set<String> STRICT_RESOURCE_META_PARAMS;
056
057        static {
058                Map<String, Class<? extends IQueryParameterType>> resourceMetaParams = new HashMap<>();
059                Map<String, Class<? extends IQueryParameterAnd<?>>> resourceMetaAndParams = new HashMap<>();
060                resourceMetaParams.put(IAnyResource.SP_RES_ID, StringParam.class);
061                resourceMetaAndParams.put(IAnyResource.SP_RES_ID, StringAndListParam.class);
062                resourceMetaParams.put(Constants.PARAM_PID, TokenParam.class);
063                resourceMetaAndParams.put(Constants.PARAM_PID, TokenAndListParam.class);
064                resourceMetaParams.put(PARAM_TAG, TokenParam.class);
065                resourceMetaAndParams.put(PARAM_TAG, TokenAndListParam.class);
066                resourceMetaParams.put(PARAM_PROFILE, UriParam.class);
067                resourceMetaAndParams.put(PARAM_PROFILE, UriAndListParam.class);
068                resourceMetaParams.put(Constants.PARAM_SECURITY, TokenParam.class);
069                resourceMetaAndParams.put(Constants.PARAM_SECURITY, TokenAndListParam.class);
070                resourceMetaParams.put(Constants.PARAM_HAS, HasParam.class);
071                resourceMetaAndParams.put(Constants.PARAM_HAS, HasAndListParam.class);
072                RESOURCE_META_PARAMS = Collections.unmodifiableMap(resourceMetaParams);
073                RESOURCE_META_AND_PARAMS = Collections.unmodifiableMap(resourceMetaAndParams);
074
075                // As described on the FHIR spec: https://hl7.org/fhir/R4/search.html#table
076                STRICT_RESOURCE_META_PARAMS = Set.of(PARAM_TAG, PARAM_PROFILE, PARAM_SECURITY, PARAM_LASTUPDATED);
077        }
078}