Skip to content

fix communicationRelatesTo expression to stop double-indexing careTeam/episodeOfCare extensions - #336

Open
OliverDueNielsen wants to merge 1 commit into
release_2026.4-SNAPSHOTfrom
refactor-searchparam
Open

fix communicationRelatesTo expression to stop double-indexing careTeam/episodeOfCare extensions#336
OliverDueNielsen wants to merge 1 commit into
release_2026.4-SNAPSHOTfrom
refactor-searchparam

Conversation

@OliverDueNielsen

@OliverDueNielsen OliverDueNielsen commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

###The problem:
HAPI FHIR logged "inefficient query" warnings during Communication search pagination (category & _tag & status & communicationRelatesTo & subject). Root cause traced via table stats (no pg_stat_statements, no EXPLAIN needed):

The communicationRelatesTo search parameter is a union FHIRPath expression covering 5 reference paths (recipient, sender, senderCareTeam ext, recipientCareTeam ext, episodeOfCare ext) — built as an "all-purpose" narrowing filter. Three of those five paths duplicate facts already indexed by separate, partner-facing search parameters (careTeamSender, careTeamRecipient, episodeOfCare), but written with different FHIRPath syntax (.extension.where(url=...).value vs .extension('url')).

HAPI dedupes indexed reference links via a Set, keyed partly on the literal FHIRPath string that produced them (ResourceLink.equals()).
Different syntax → no dedup, even though both resolve to the identical value. Result: ~899K duplicate rows in hfj_res_link (~39% of the whole table), almost all of it Communication reference indexing. Every Communication search touching communicationRelatesTo scans that inflated index before intersecting with the other filters — sparse joint matches then trigger HAPI's pagination retry warning.

##Fix: rewrite communicationRelatesTo's expression to use the same syntax as the standalone params — same values, same search results, dedup collapses the duplicate rows on reindex.

NOTE: We will need to run a reindex after the IG is used by the patient.

Aims at fixing this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant