google / google/cql

Equal-To Operator on ValueQuantity in Observations

Open
#79 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
113
Forks
20
PR merge metrics
No merged PRs in 30d

Description

## Description

The **equal-to operator** silently fails when used with `ValueQuantity`. When comparing an `Observation`'s value with an integer, the result is always `false`, regardless of the value on the other side of the comparison (see the `NoResult` statement).

Attempting to access inner values, such as `value.value`, results in a type checker error. However, accessing `unit.value` works as expected. To resolve this issue, we resorted to type casting, as demonstrated in `QuantityValueFromObservation` below.

## Input

```
library HeartRateValidation version '1.0'

include FHIRHelpers version '4.0.1' called FHIRHelpers

define function QuantityValueFromObservation(o FHIR.Observation):
( cast o.value as FHIR.Quantity ).value.value

define "WithHelper":
[Observation] obs
where QuantityValueFromObservation(obs) = 1

define "NoResult":
[Observation] obs
where obs.value = 1

// internal error - handleProtoValue expected runtimeResultType to be a Named type, got: Choice, System.String, System.Boolean, System.Integer, System.Time, System.DateTime>
define "TypeCheckerIssue":
[Observation] obs
where obs.value.value = 1

// internal error - handleProtoValue expected runtimeResultType to be a Named type, got: Choice, System.String, System.Boolean, System.Integer, System.Time, System.DateTime>
define "TypeCheckerIssue":
[Observation] obs
where obs.value.value.value = 1
```

## Bundle

```json
{
"resourceType": "Bundle",
"id": "example-bundle",
"type": "collection",
"entry": [
{
"fullUrl": "urn:uuid:heart-rate",
"resource": {
"resourceType": "Observation",
"id": "heart-rate",
"text": {
"status": "generated"
},
"status": "final",
"category": [
{
"coding": [
{
"system": "http://terminology.hl7.org/CodeSystem/observation-category",
"code": "vital-signs",
"display": "Vital Signs"
}
],
"text": "Vital Signs"
}
],
"code": {
"coding": [
{
"system": "http://loinc.org",
"code": "8867-4",
"display": "Heart Rate"
}
],
"text": "heart_rate"
},
"subject": {
"reference": "Patient/example",
"display": "Amy Shaw"
},
"encounter": {
"display": "GP Visit"
},
"effectiveDateTime": "1999-07-02",
"valueQuantity": {
"value": 1,
"unit": "beats/min",
"system": "http://unitsofmeasure.org",
"code": "/min"
}
}
}
]
}
```

## output

```json
{
"bundleSource": "data/bundles/observations_heart_rate.json",
"evalResults": [
{
"libName": "HeartRateValidation",
"libVersion": "1.0",
"expressionDefinitions": {
"Heart Rate Vital Signs": {
"@type": "System.ValueSet",
"id": "http://fhir.verily.com/ValueSet/heath-rate"
},
"NoResult": [],
"TypeCheckerIssue": [],
"WithHelper": [
{
"@type": "FHIR.Observation",
"value": {
"id": {
"value": "heart-rate"
},
"text": {
"status": {
"value": "GENERATED"
}
},
"status": {
"value": "FINAL"
},
"category": [
{
"coding": [
{
"system": {
"value": "http://terminology.hl7.org/CodeSystem/observation-category"
},
"code": {
"value": "vital-signs"
},
"display": {
"value": "Vital Signs"
}
}
],
"text": {
"value": "Vital Signs"
}
}
],
"code": {
"coding": [
{
"system": {
"value": "http://loinc.org"
},
"code": {
"value": "8867-4"
},
"display": {
"value": "Heart Rate"
}
}
],
"text": {
"value": "heart_rate"
}
},
"subject": {
"patientId": {
"value": "example"
},
"display": {
"value": "Amy Shaw"
}
},
"encounter": {
"display": {
"value": "GP Visit"
}
},
"effective": {
"dateTime": {
"valueUs": "930873600000000",
"timezone": "UTC",
"precision": "DAY"
}
},
"value": {
"quantity": {
"value": {
"value": "1"
},
"unit": {
"value": "beats/min"
},
"system": {
"value": "http://unitsofmeasure.org"
},
"code": {
"value": "/min"
}
}
}
}
}
]
}
}
]
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.