Skip to content

Equal-To Operator on ValueQuantity in Observations #79

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
vmontagh opened this issue Dec 14, 2024 · 0 comments
Open

Equal-To Operator on ValueQuantity in Observations #79

vmontagh opened this issue Dec 14, 2024 · 0 comments

Comments

@vmontagh
Copy link

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<Named<FHIR.decimal>, 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<Named<FHIR.decimal>, System.String, System.Boolean, System.Integer, System.Time, System.DateTime>
define "TypeCheckerIssue":
  [Observation] obs
    where obs.value.value.value = 1

Bundle

{
    "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

{
  "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"
                  }
                }
              }
            }
          }
        ]
      }
    }
  ]
}
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

No branches or pull requests

1 participant