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