
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.interceptor.model; 021 022import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; 023import ca.uhn.fhir.rest.api.RestOperationTypeEnum; 024import ca.uhn.fhir.rest.api.server.RequestDetails; 025import jakarta.annotation.Nonnull; 026import jakarta.annotation.Nullable; 027import org.hl7.fhir.instance.model.api.IBaseResource; 028import org.hl7.fhir.instance.model.api.IIdType; 029 030import static org.apache.commons.lang3.StringUtils.isNotBlank; 031 032/** 033 * This is a model class used as a parameter for the interceptor pointcut 034 * {@link ca.uhn.fhir.interceptor.api.Pointcut#STORAGE_PARTITION_IDENTIFY_READ}. 035 */ 036public class ReadPartitionIdRequestDetails extends PartitionIdRequestDetails { 037 038 private final String myResourceType; 039 private final RestOperationTypeEnum myRestOperationType; 040 private final IIdType myReadResourceId; 041 042 @Nullable 043 private final SearchParameterMap mySearchParams; 044 045 @Nullable 046 private final IBaseResource myConditionalTargetOrNull; 047 048 @Nullable 049 private final String mySearchUuid; 050 051 @Nullable 052 private final String myExtendedOperationName; 053 054 private ReadPartitionIdRequestDetails( 055 String theResourceType, 056 RestOperationTypeEnum theRestOperationType, 057 IIdType theReadResourceId, 058 @Nullable SearchParameterMap theSearchParams, 059 @Nullable IBaseResource theConditionalTargetOrNull, 060 @Nullable String theSearchUuid, 061 String theExtendedOperationName) { 062 myResourceType = theResourceType; 063 myRestOperationType = theRestOperationType; 064 myReadResourceId = theReadResourceId; 065 mySearchParams = theSearchParams; 066 myConditionalTargetOrNull = theConditionalTargetOrNull; 067 mySearchUuid = theSearchUuid; 068 myExtendedOperationName = theExtendedOperationName; 069 } 070 071 public static ReadPartitionIdRequestDetails forGeneric(RequestDetails theRequestDetails) { 072 return new ReadPartitionIdRequestDetails( 073 theRequestDetails.getResourceName(), 074 theRequestDetails.getRestOperationType(), 075 theRequestDetails.getId(), 076 null, 077 null, 078 null, 079 null); 080 } 081 082 @Nullable 083 public String getExtendedOperationName() { 084 return myExtendedOperationName; 085 } 086 087 @Nullable 088 public String getSearchUuid() { 089 return mySearchUuid; 090 } 091 092 public String getResourceType() { 093 return myResourceType; 094 } 095 096 public RestOperationTypeEnum getRestOperationType() { 097 return myRestOperationType; 098 } 099 100 public IIdType getReadResourceId() { 101 return myReadResourceId; 102 } 103 104 @Nullable 105 public SearchParameterMap getSearchParams() { 106 return mySearchParams; 107 } 108 109 @Nullable 110 public IBaseResource getConditionalTargetOrNull() { 111 return myConditionalTargetOrNull; 112 } 113 114 /** 115 * @param theId The resource ID (must include a resource type and ID) 116 */ 117 public static ReadPartitionIdRequestDetails forRead(IIdType theId) { 118 assert isNotBlank(theId.getResourceType()); 119 assert isNotBlank(theId.getIdPart()); 120 return forRead(theId.getResourceType(), theId, false); 121 } 122 123 public static ReadPartitionIdRequestDetails forServerOperation(@Nonnull String theOperationName) { 124 return new ReadPartitionIdRequestDetails( 125 null, RestOperationTypeEnum.EXTENDED_OPERATION_SERVER, null, null, null, null, theOperationName); 126 } 127 128 /** 129 * @since 7.4.0 130 */ 131 public static ReadPartitionIdRequestDetails forDelete(@Nonnull String theResourceType, @Nonnull IIdType theId) { 132 RestOperationTypeEnum op = RestOperationTypeEnum.DELETE; 133 return new ReadPartitionIdRequestDetails( 134 theResourceType, op, theId.withResourceType(theResourceType), null, null, null, null); 135 } 136 137 /** 138 * @since 8.6.0 139 */ 140 public static ReadPartitionIdRequestDetails forDelete(String theResourceType, SearchParameterMap theParams) { 141 RestOperationTypeEnum op = RestOperationTypeEnum.DELETE; 142 return new ReadPartitionIdRequestDetails( 143 theResourceType, 144 op, 145 null, 146 theParams != null ? theParams : SearchParameterMap.newSynchronous(), 147 null, 148 null, 149 null); 150 } 151 152 /** 153 * @since 7.4.0 154 */ 155 public static ReadPartitionIdRequestDetails forPatch(String theResourceType, IIdType theId) { 156 RestOperationTypeEnum op = RestOperationTypeEnum.PATCH; 157 return new ReadPartitionIdRequestDetails( 158 theResourceType, op, theId.withResourceType(theResourceType), null, null, null, null); 159 } 160 161 /** 162 * @since 8.6.0 163 */ 164 public static ReadPartitionIdRequestDetails forPatch(String theResourceType, SearchParameterMap theParams) { 165 RestOperationTypeEnum op = RestOperationTypeEnum.PATCH; 166 return new ReadPartitionIdRequestDetails( 167 theResourceType, 168 op, 169 null, 170 theParams != null ? theParams : SearchParameterMap.newSynchronous(), 171 null, 172 null, 173 null); 174 } 175 176 public static ReadPartitionIdRequestDetails forRead( 177 String theResourceType, @Nonnull IIdType theId, boolean theIsVread) { 178 RestOperationTypeEnum op = theIsVread ? RestOperationTypeEnum.VREAD : RestOperationTypeEnum.READ; 179 return new ReadPartitionIdRequestDetails( 180 theResourceType, op, theId.withResourceType(theResourceType), null, null, null, null); 181 } 182 183 public static ReadPartitionIdRequestDetails forSearchType( 184 String theResourceType, SearchParameterMap theParams, IBaseResource theConditionalOperationTargetOrNull) { 185 return new ReadPartitionIdRequestDetails( 186 theResourceType, 187 RestOperationTypeEnum.SEARCH_TYPE, 188 null, 189 theParams != null ? theParams : SearchParameterMap.newSynchronous(), 190 theConditionalOperationTargetOrNull, 191 null, 192 null); 193 } 194 195 public static ReadPartitionIdRequestDetails forHistory(String theResourceType, IIdType theIdType) { 196 RestOperationTypeEnum restOperationTypeEnum; 197 if (theIdType != null) { 198 restOperationTypeEnum = RestOperationTypeEnum.HISTORY_INSTANCE; 199 } else if (theResourceType != null) { 200 restOperationTypeEnum = RestOperationTypeEnum.HISTORY_TYPE; 201 } else { 202 restOperationTypeEnum = RestOperationTypeEnum.HISTORY_SYSTEM; 203 } 204 return new ReadPartitionIdRequestDetails( 205 theResourceType, restOperationTypeEnum, theIdType, null, null, null, null); 206 } 207 208 public static ReadPartitionIdRequestDetails forSearchUuid(String theUuid) { 209 return new ReadPartitionIdRequestDetails(null, RestOperationTypeEnum.GET_PAGE, null, null, null, theUuid, null); 210 } 211}