fhir-persistence 0.7.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2970,7 +2970,7 @@ declare interface SearchStats {
2970
2970
  * Physical storage strategy for a search parameter.
2971
2971
  *
2972
2972
  * - `column` — single column in the main table
2973
- * - `token-column` — three columns (UUID[], TEXT[], TEXT) for token search
2973
+ * - `token-column` — two columns: TEXT (JSON array of "system|code"), TEXT (sort/display)
2974
2974
  * - `lookup-table` — separate lookup table; only a sort column in main table
2975
2975
  */
2976
2976
  export declare type SearchStrategy = 'column' | 'token-column' | 'lookup-table';
@@ -2970,7 +2970,7 @@ declare interface SearchStats {
2970
2970
  * Physical storage strategy for a search parameter.
2971
2971
  *
2972
2972
  * - `column` — single column in the main table
2973
- * - `token-column` — three columns (UUID[], TEXT[], TEXT) for token search
2973
+ * - `token-column` — two columns: TEXT (JSON array of "system|code"), TEXT (sort/display)
2974
2974
  * - `lookup-table` — separate lookup table; only a sort column in main table
2975
2975
  */
2976
2976
  export declare type SearchStrategy = 'column' | 'token-column' | 'lookup-table';
@@ -5207,36 +5207,43 @@ function buildUriFragmentV2(impl, param, dialect) {
5207
5207
  return buildOrFragmentV2(col, "=", param.values);
5208
5208
  }
5209
5209
  function buildTokenColumnFragmentV2(impl, param, dialect) {
5210
- const textCol = quoteColumn(`__${impl.columnName}Text`);
5210
+ const textCol = quoteColumn(`__${impl.columnName}`);
5211
5211
  const sortCol = quoteColumn(`__${impl.columnName}Sort`);
5212
5212
  if (param.modifier === "text") {
5213
5213
  return buildLikeFragmentV2(sortCol, param.values, "", "%");
5214
5214
  }
5215
- const needsLike = param.values.some((v) => v.endsWith("|"));
5216
- if (needsLike) {
5217
- const conds = [];
5218
- const vals = [];
5219
- for (const value of param.values) {
5215
+ const exactValues = [];
5216
+ const likePatterns = [];
5217
+ for (const value of param.values) {
5218
+ if (value.includes("|")) {
5220
5219
  if (value.endsWith("|")) {
5221
- const frag = arrayContainsLikeV2(textCol, value + "%", dialect);
5222
- conds.push(frag.sql);
5223
- vals.push(...frag.values);
5220
+ likePatterns.push(value + "%");
5224
5221
  } else {
5225
- const resolved = value.startsWith("|") ? value.slice(1) : value;
5226
- const frag = arrayContainsV2(textCol, [resolved], dialect);
5227
- conds.push(frag.sql);
5228
- vals.push(...frag.values);
5222
+ exactValues.push(value);
5229
5223
  }
5224
+ } else {
5225
+ likePatterns.push(`%|${value}`);
5230
5226
  }
5231
- const inner = conds.length === 1 ? conds[0] : `(${conds.join(" OR ")})`;
5232
- const sql = param.modifier === "not" ? `NOT (${inner})` : inner;
5233
- return { sql, values: vals };
5234
5227
  }
5235
- const resolvedValues = param.values.map((v) => v.startsWith("|") ? v.slice(1) : v);
5236
- if (param.modifier === "not") {
5237
- return arrayNotContainsV2(textCol, resolvedValues, dialect);
5238
- }
5239
- return arrayContainsV2(textCol, resolvedValues, dialect);
5228
+ const conds = [];
5229
+ const vals = [];
5230
+ if (exactValues.length > 0) {
5231
+ const frag = param.modifier === "not" ? arrayNotContainsV2(textCol, exactValues, dialect) : arrayContainsV2(textCol, exactValues, dialect);
5232
+ conds.push(frag.sql);
5233
+ vals.push(...frag.values);
5234
+ }
5235
+ for (const pattern of likePatterns) {
5236
+ const frag = arrayContainsLikeV2(textCol, pattern, dialect);
5237
+ const sql = param.modifier === "not" ? `NOT (${frag.sql})` : frag.sql;
5238
+ conds.push(sql);
5239
+ vals.push(...frag.values);
5240
+ }
5241
+ if (conds.length === 0) {
5242
+ return { sql: "1=1", values: [] };
5243
+ }
5244
+ const joiner = param.modifier === "not" ? " AND " : " OR ";
5245
+ const inner = conds.length === 1 ? conds[0] : `(${conds.join(joiner)})`;
5246
+ return { sql: inner, values: vals };
5240
5247
  }
5241
5248
  function buildDefaultFragmentV2(impl, param) {
5242
5249
  const col = quoteColumn(impl.columnName);