
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.fulltext; 021 022import jakarta.annotation.Nonnull; 023import org.hl7.fhir.instance.model.api.IBaseResource; 024import org.hl7.fhir.instance.model.api.IIdType; 025 026import java.util.function.Supplier; 027import javax.annotation.Nullable; 028 029/** 030 * This is a request object containing a request to extract the FullText index data from 031 * a resource during storage. 032 * 033 * @see ca.uhn.fhir.interceptor.api.Pointcut#JPA_INDEX_EXTRACT_FULLTEXT for a description of how this should be used. 034 * @since 8.4.0 035 */ 036public class FullTextExtractionRequest { 037 038 @Nullable 039 private final IIdType myResourceId; 040 041 @Nullable 042 private final IBaseResource myResource; 043 044 @Nonnull 045 private final String myResourceType; 046 047 @Nonnull 048 private final Supplier<String> myDefaultSupplier; 049 050 /** 051 * Constructor 052 */ 053 public FullTextExtractionRequest( 054 @Nullable IIdType theResourceId, 055 @Nullable IBaseResource theResource, 056 @Nonnull String theResourceType, 057 @Nonnull Supplier<String> theDefaultSupplier) { 058 myResourceId = theResourceId; 059 myResource = theResource; 060 myResourceType = theResourceType; 061 myDefaultSupplier = theDefaultSupplier; 062 } 063 064 /** 065 * @return Returns {@literal true} if this request represents a resource deletion 066 */ 067 public boolean isDelete() { 068 return myResource == null; 069 } 070 071 /** 072 * @return Returns the ID of the resource being indexed. This may be <code>null</code> if a new resource is being created, and a type isn't assigned yet 073 */ 074 @Nullable 075 public IIdType getResourceId() { 076 return myResourceId; 077 } 078 079 /** 080 * @return Returns the resource being indexed. May be <code>null</code> if the operation is a resource deletion. 081 */ 082 @Nullable 083 public IBaseResource getResource() { 084 return myResource; 085 } 086 087 /** 088 * @return Returns the resource type being indexed. 089 */ 090 @Nonnull 091 public String getResourceType() { 092 return myResourceType; 093 } 094 095 /** 096 * @return Returns the extracted content/text string that is automatically extracted from the resource 097 */ 098 public String getDefaultString() { 099 return myDefaultSupplier.get(); 100 } 101}