Support the logical OR (comma separated values) for FHIR search parameters#555
Open
schwzr wants to merge 1 commit into
Open
Support the logical OR (comma separated values) for FHIR search parameters#555schwzr wants to merge 1 commit into
schwzr wants to merge 1 commit into
Conversation
Implements the FHIR search OR join: comma separated values within a single search parameter are combined with a logical OR, while separately repeated parameters keep the existing logical AND semantics, per https://www.hl7.org/fhir/search.html#combining - SearchQuery groups the parameter instances created from one comma separated value; the SQL filter combines the members of a group with OR and the groups with AND, the in-memory (subscription) matcher does the same, and the search self link keeps OR values comma joined within one parameter - a comma escaped as \, is treated as a literal character (and unescaped); other escape sequences are left for the parameter type specific parsing - no change to the individual search parameter type implementations Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #554
Summary
Implements the FHIR search OR join: comma separated values within a single search parameter are combined with a logical OR, while separately repeated parameters keep the existing logical AND semantics, per https://www.hl7.org/fhir/search.html#combining
GET [base]/[type]?param=a,b→ resources matchingaORbGET [base]/[type]?param=a¶m=b→ resources matchingaANDb(unchanged)Implementation
The combination is applied centrally in
SearchQuery, so the ~40 individual search parameter type implementations are left untouched. A single comma separated value is split into an OR-group of parameter instances; the group's filter fragments are combined withOR, the groups (and the read-access filter) withAND. The same grouping is applied to:( <frag1> OR <frag2> ... ), one query with N bound parameters (PostgreSQL combines the GIN index scans viaBitmapOr, no extra round-trips),selflink (OR values kept comma separated within one parameter, AND values as repeated parameters).A comma escaped as
\,is treated as a literal character (and unescaped); the other FHIR escape sequences (\|,\$,\\) are left for the parameter type specific parsing (unchanged behavior).For a value without a comma the OR-group has a single member and the emitted SQL fragment is byte-identical to before — so existing searches are unaffected.
Scope
In scope: OR (comma) combination for all search parameter types (token, string, reference, date, number, quantity, uri,
_id,_lastUpdated,_profile,_tag, ...),\,escaping, correctselflink reconstruction, subscription matcher, tests.Out of scope (for now):
\|/\$/\\inside a value (only\,is handled).IN/= ANY(...)expression per parameter type (the planner already doesBitmapOr; a per-type collapse would be a later micro-optimization).Testing
SearchQueryOrValueTest: 11/11 (comma split incl. escaped comma, other escapes preserved, edge cases).SearchOrIntegrationTest: 5/5 against a real server + PostgreSQL (Testcontainers): OR union, three-value OR, OR-vs-AND distinction, OR with a non-matching value,selflink comma-joining.ParallelCreateIntegrationTest#testCreateDuplicateStructureDefinitionsParallelDirect(a parallel race test, ~50% on any branch, passes ondevelop); it is unrelated to this change, which produces byte-identical SQL for the single-value (no comma) searches that test relies on.🤖 Generated with Claude Code