RestRepository ANDs multiple codes of a retrieve terminology filter (should be OR): silent empty results with inline codes

Open
#1,152 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
68/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
java, kotlin
Domain
api

Research direction

Start with cqf-fhir-utility/.../repository/RestRepository.kt and trace how its flattened parameter lists reach IQuery.where(Map). Use the provided FHIR R4 reproduction with two inline terminology codes, and confirm that multiple values for one key become comma-separated OR values while separate same-key entries retain AND semantics. Add or update a query-building test that verifies the generated request and confirms an Observation matching either code is retrieved.

Written by the indexing model from the issue text.

Description

Summary

RestRepository.search(..., Multimap<String, List<IQueryParameterType>>, ...) flattens each inner list into repeated query parameters, which FHIR search reads as AND. The retrieve provider builds terminology filters as code -> [c1, c2, ...] meaning OR. With two or more inline codes, a CQL retrieve against a remote server silently returns nothing — no error, the expression just evaluates to an empty list / false.

Where

cqf-fhir-utility/.../repository/RestRepository.kt (present in 4.15.0 and on main as of 4.17.0):

for (key in searchParameters.keySet()) {
    val flattenLists = searchParameters.get(key).flatMap { obj -> obj!! }.toMutableList()
    params[key] = flattenLists
}
...
op = op.where(searchParameters)   // IQuery.where(Map<String, List<IQueryParameterType>>)

IQuery.where(Map) emits one key=value per list element, so code -> [loinc|4548-4, loinc|17856-6] becomes
Observation?code=http://loinc.org|4548-4&code=http://loinc.org|17856-6 (AND) instead of
Observation?code=http://loinc.org|4548-4,http://loinc.org|17856-6 (OR).

Repro
  • RetrieveSettings: TERMINOLOGY_FILTER_MODE.USE_INLINE_CODES, SEARCH_FILTER_MODE.USE_SEARCH_PARAMETERS.
  • Data repository: RestRepository(client) pointing at any FHIR R4 server (reproduced on HAPI FHIR 8.4 and on Google Cloud Healthcare API).
  • Library: define "HbA1c": [Observation: "HbA1c"] where the ValueSet has two codes; the subject has one Observation with either code.
  • Result: empty list. Expected: the Observation.

USE_VALUE_SET_URL (code:in) is not a workaround on servers without :in support (Healthcare API answers 400).

Suggested fix

Keep each inner list as a single comma-joined parameter (OR) and keep separate entries for the same key as separate parameters (AND), e.g. build the query with TokenOrListParam or join the values before calling where. We run this as a wrapper today and can open a PR if that approach is acceptable.

Related, smaller
  • Long inline code lists produce GET request lines over common server limits (8 KB on Tomcat); falling back to POST <type>/_search above a size threshold avoids 400s.
  • IQuery.usingStyle(SearchStyleEnum.POST) combined with byUrl(...) still sends GET in HAPI's generic client, which makes that fallback easy to get wrong.
Dominant language
Java
Stars
52
Forks
46
Avg merge
1d 14h
Merged PRs (30d)
5

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from cqframework/clinical-reasoning

All issues in cqframework/clinical-reasoning

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.