@@ -239,27 +239,28 @@ def search(
239239 patient_sort = f"C#{ category_id } #T#{ type_id } "
240240 key_conditions .append ("begins_with(patient_sort, :patient_sort)" )
241241 expression_values [":patient_sort" ] = patient_sort
242+ else :
243+ # Handle single/multiple categories and pointer types with filter expressions
244+ if len (categories ) == 1 :
245+ split_category = categories [0 ].split ("|" )
246+ category_id = (
247+ SYSTEM_SHORT_IDS [split_category [0 ]] + "-" + split_category [1 ]
248+ )
249+ patient_sort = f"C#{ category_id } "
250+ key_conditions .append ("begins_with(patient_sort, :patient_sort)" )
251+ expression_values [":patient_sort" ] = patient_sort
252+
253+ if len (categories ) > 1 :
254+ expression_names ["#category" ] = "category"
255+ category_filters = [
256+ f"#category = :category_{ i } " for i in range (len (categories ))
257+ ]
258+ caetgory_filter_values = {
259+ f":category_{ i } " : categories [i ] for i in range (len (categories ))
260+ }
261+ filter_expressions .append (f"({ ' OR ' .join (category_filters )} )" )
262+ expression_values .update (caetgory_filter_values )
242263
243- if len (categories ) == 1 :
244- split_category = categories [0 ].split ("|" )
245- category_id = SYSTEM_SHORT_IDS [split_category [0 ]] + "-" + split_category [1 ]
246- patient_sort = f"C#{ category_id } "
247- key_conditions .append ("begins_with(patient_sort, :patient_sort)" )
248- expression_values [":patient_sort" ] = patient_sort
249-
250- if len (categories ) > 1 :
251- expression_names ["#category" ] = "category"
252- category_filters = [
253- f"#category = :category_{ i } " for i in range (len (categories ))
254- ]
255- caetgory_filter_values = {
256- f":category_{ i } " : categories [i ] for i in range (len (categories ))
257- }
258- filter_expressions .append (f"({ ' OR ' .join (category_filters )} )" )
259- expression_values .update (caetgory_filter_values )
260-
261- # Handle multiple types if no category filter
262- if not categories and len (pointer_types ) > 1 :
263264 expression_names ["#pointer_type" ] = "type"
264265 types_filters = [
265266 f"#pointer_type = :type_{ i } " for i in range (len (pointer_types ))
0 commit comments