001package ca.uhn.fhir.fhirpath; 002 003/* 004 * #%L 005 * HAPI FHIR - Core Library 006 * %% 007 * Copyright (C) 2014 - 2023 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 org.hl7.fhir.instance.model.api.IBase; 024 025import javax.annotation.Nonnull; 026import java.util.List; 027import java.util.Optional; 028 029public interface IFhirPath { 030 031 /** 032 * Apply the given FhirPath expression against the given input and return 033 * all results in a list 034 * 035 * @param theInput The input object (generally a resource or datatype) 036 * @param thePath The fluent path expression 037 * @param theReturnType The type to return (in order to avoid casting) 038 */ 039 <T extends IBase> List<T> evaluate(IBase theInput, String thePath, Class<T> theReturnType); 040 041 /** 042 * Apply the given FhirPath expression against the given input and return 043 * the first match (if any) 044 * 045 * @param theInput The input object (generally a resource or datatype) 046 * @param thePath The fluent path expression 047 * @param theReturnType The type to return (in order to avoid casting) 048 */ 049 <T extends IBase> Optional<T> evaluateFirst(IBase theInput, String thePath, Class<T> theReturnType); 050 051 052 /** 053 * Parses the expression and throws an exception if it can not parse correctly 054 */ 055 void parse(String theExpression) throws Exception; 056 057 058 /** 059 * This method can be used optionally to supply an evaluation context for the 060 * FHIRPath evaluator instance. The context can be used to supply data needed by 061 * specific functions, e.g. allowing the <code>resolve()</code> function to 062 * fetch referenced resources. 063 * 064 * @since 6.4.0 065 */ 066 void setEvaluationContext(@Nonnull IFhirPathEvaluationContext theEvaluationContext); 067}