001/*-
002 * #%L
003 * HAPI FHIR Search Parameters
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.searchparam.extractor;
021
022import ca.uhn.fhir.interceptor.model.RequestPartitionId;
023import ca.uhn.fhir.jpa.model.cross.IResourceLookup;
024import ca.uhn.fhir.rest.api.server.RequestDetails;
025import ca.uhn.fhir.rest.api.server.storage.TransactionDetails;
026import org.hl7.fhir.instance.model.api.IBaseResource;
027
028import javax.annotation.Nonnull;
029import javax.annotation.Nullable;
030
031public interface IResourceLinkResolver {
032
033        /**
034         * This method resolves the target of a reference found within a resource that is being created/updated. We do this
035         * so that we can create indexed links between resources, and so that we can validate that the target actually
036         * exists in cases where we need to check that.
037         * <p>
038         * This method returns an {@link IResourceLookup} to avoid needing to resolve the entire resource.
039         *
040         * @param theRequestPartitionId The partition ID of the target resource
041         * @param theSourceResourceName The resource type for the resource containing the reference
042         * @param thePathAndRef         The path and reference
043         * @param theRequest            The incoming request, if any
044         * @param theTransactionDetails The current TransactionDetails object
045         */
046        IResourceLookup findTargetResource(@Nonnull RequestPartitionId theRequestPartitionId, String theSourceResourceName, PathAndRef thePathAndRef, RequestDetails theRequest, TransactionDetails theTransactionDetails);
047
048        /**
049         * This method resolves the target of a reference found within a resource that is being created/updated. We do this
050         * so that we can create indexed links between resources, and so that we can validate that the target actually
051         * exists in cases where we need to check that.
052         * <p>
053         * This method returns an {@link IResourceLookup} to avoid needing to resolve the entire resource.
054         *
055         * @param theRequestPartitionId The partition ID of the target resource
056         * @param theSourceResourceName The resource type for the resource containing the reference
057         * @param thePathAndRef         The path and reference
058         * @param theRequest            The incoming request, if any
059         * @param theTransactionDetails The current TransactionDetails object
060         */
061        @Nullable
062        IBaseResource loadTargetResource(@Nonnull RequestPartitionId theRequestPartitionId, String theSourceResourceName, PathAndRef thePathAndRef, RequestDetails theRequest, TransactionDetails theTransactionDetails);
063
064
065
066        void validateTypeOrThrowException(Class<? extends IBaseResource> theType);
067
068}