FHIR / FHIR/sql-on-fhir.js

Reference implementation: where clause does not validate boolean return type

Open Beginner friendly
#7 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
0
Forks
3
PR merge metrics
No merged PRs in 30d

Description

Moved from HL7/sql-on-fhir#310.

The `validate.json > where with path resolving to not boolean` test is failing in the sof-js reference implementation.

## Test case

The test expects an error when a `where` clause path resolves to a non-boolean value:

```json
{
"title": "where with path resolving to not boolean",
"tags": ["shareable"],
"view": {
"resource": "Patient",
"status": "active",
"select": [
{
"column": [
{
"name": "id",
"path": "id",
"type": "id"
}
]
}
],
"where": [
{
"path": "name.family"
}
]
},
"expectError": true
}
```

## Problem

The test expects the view runner to throw an error because `name.family` evaluates to a string (e.g., "F1.1"), not a boolean. However, the sof-js reference implementation does not throw an error.

In `sof-js/src/index.js`, the `select` function has this check:

```javascript
assert(val === undefined || typeof val === 'boolean', "'where' expression path should return 'boolean'")
return val
```

When `name.family` returns a string like "F1.1", JavaScript's truthiness evaluation causes the assertion to fail silently or the value is coerced to truthy, rather than throwing an error.

## Expected behaviour

The view runner should throw an error when a `where` clause path evaluates to a non-boolean value (string, number, etc.).

## Actual behaviour

The view runner does not throw an error and the test fails.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the select function and its where-expression check in sof-js/src/index.js, then inspect the `validate.json > where with path resolving to not boolean` conformance case. Run the reference implementation's validation tests and confirm that a non-boolean path result produces an error while boolean and undefined results retain their expected behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
testing
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
82/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.