Skip to content

$populate: a number-typed FHIRPath result never matches a valueInteger answerOption #2122

Description

@leoniedickson

Describe the bug

findInAnswerOptions (packages/sdc-populate/src/SDCPopulateQuestionnaireOperation/utils/answerOption.ts) matches valueInteger options by string comparison only:

if (typeof option.valueInteger === 'number') {
  if (value === option.valueInteger.toString()) {
    return { valueInteger: option.valueInteger };
  }
}

value is compared against option.valueInteger.toString(), but value itself is never converted to a string first. This works when value is already a string (e.g. from user-entered text), but an initialExpression FHIRPath result that evaluates to a genuine JS number (e.g. Observation.valueInteger) fails the comparison outright — 5 === "5" is false under strict equality. The answer then falls through to the numeric branches in parseValueToAnswer instead of returning the matching, normalised option.

To Reproduce

import { findInAnswerOptions } from './utils/answerOption';

const options = [{ valueInteger: 5 }];

findInAnswerOptions(options, 5);   // number
findInAnswerOptions(options, '5'); // string

Expected behavior

Both calls should return { valueInteger: 5 } — the answerOption match shouldn't depend on whether the FHIRPath result happened to be a number or a string.

Actual behavior

findInAnswerOptions(options, 5)   // undefined
findInAnswerOptions(options, '5') // { valueInteger: 5 }

Additional context

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions