Skip to content

Item.definition is not returned on QR items from getResponse() #1801

@taylorkle

Description

@taylorkle

Describe the bug
A clear and concise description of what the bug is.

The getResponse() function does not preserve the item.definition property on Q/QR.

To Reproduce
Steps to reproduce the behavior.

  1. build form with questionnaire and corresponding questionnaire response. All items include item.definition.
  2. Call getResponse()

Implementation: https://github.com/reason-healthcare/reason-framework/blob/d5a072b4a8360e74975777e4271cfa64e8ef1cfe/packages/cpg-review/src/app/components/apply-form/QuestionnaireRenderer.tsx#L50-L101

Inputs to useBuildForm
Questionnaire:

{
  "resourceType": "Questionnaire",
  "id": "BreastCancerPathway",
  "extension": [
    {
      "url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-launchContext",
      "extension": [
        {
          "url": "name",
          "valueCoding": {
            "system": "http://hl7.org/fhir/uv/sdc/CodeSystem/launchContext",
            "code": "patient",
            "display": "Patient"
          }
        },
        {
          "url": "type",
          "valueCode": "Patient"
        }
      ]
    }
  ],
  "url": "http://example.org/cancer-guideline/fhir/Questionnaire/BreastCancerPathway",
  "version": "0.1.0-Patient1-2026-01-15-09.47.43",
  "status": "active",
  "item": [
    {
      "linkId": "1",
      "definition": "http://example.org/cancer-guideline/fhir/StructureDefinition/IsTNBCFeature",
      "text": "IsTNBCFeature",
      "type": "group",
      "required": false,
      "repeats": false,
      "item": [
        {
          "linkId": "1.1",
          "definition": "http://example.org/cancer-guideline/fhir/StructureDefinition/IsTNBCFeature#Observation.value[x]",
          "text": "Has triple negative breast cancer",
          "type": "boolean",
          "required": false,
          "repeats": false
        }
      ]
    },
    {
      "linkId": "2",
      "definition": "http://example.org/cancer-guideline/fhir/StructureDefinition/IsT1cFeature",
      "text": "IsT1cFeature",
      "type": "group",
      "required": false,
      "repeats": false,
      "item": [
        {
          "linkId": "2.1",
          "definition": "http://example.org/cancer-guideline/fhir/StructureDefinition/IsT1cFeature#Observation.value[x]",
          "text": "Tumor size is at least T1c",
          "type": "boolean",
          "required": false,
          "repeats": false
        }
      ]
    }
  ]
}

QuestionnaireResponse:

{
  "resourceType": "QuestionnaireResponse",
  "id": "BreastCancerPathway-Patient1",
  "questionnaire": "http://example.org/cancer-guideline/fhir/Questionnaire/BreastCancerPathway|0.1.0-Patient1-2026-01-15-09.47.43",
  "status": "in-progress",
  "subject": {
    "reference": "Patient/Patient1"
  },
  "authored": "2026-01-15T21:47:44+00:00",
  "item": [
    {
      "linkId": "1",
      "definition": "http://example.org/cancer-guideline/fhir/StructureDefinition/IsTNBCFeature",
      "text": "IsTNBCFeature",
      "item": [
        {
          "linkId": "1.1",
          "definition": "http://example.org/cancer-guideline/fhir/StructureDefinition/IsTNBCFeature#Observation.value[x]",
          "text": "Has triple negative breast cancer"
        }
      ]
    },
    {
      "linkId": "2",
      "definition": "http://example.org/cancer-guideline/fhir/StructureDefinition/IsT1cFeature",
      "text": "IsT1cFeature",
      "item": [
        {
          "extension": [
            {
              "url": "http://hl7.org/fhir/StructureDefinition/questionnaireresponse-author",
              "valueReference": {
                "reference": "http://cqframework.org/fhir/Device/clinical-quality-language"
              }
            }
          ],
          "linkId": "2.1",
          "definition": "http://example.org/cancer-guideline/fhir/StructureDefinition/IsT1cFeature#Observation.value[x]",
          "text": "Tumor size is at least T1c",
          "answer": [
            {
              "valueBoolean": true
            }
          ]
        }
      ]
    }
  ]
}

Output from getResponse()

{
  "resourceType": "QuestionnaireResponse",
  "id": "BreastCancerPathway-Patient1",
  "questionnaire": "http://example.org/cancer-guideline/fhir/Questionnaire/BreastCancerPathway|0.1.0-Patient1-2026-01-15-09.59.31",
  "status": "in-progress",
  "subject": {
    "reference": "Patient/Patient1"
  },
  "authored": "2026-01-15T21:59:31+00:00",
  "item": [
    {
      "linkId": "1",
      "text": "IsTNBCFeature",
      "item": [
        {
          "linkId": "1.1",
          "text": "Has triple negative breast cancer",
          "answer": [
            {
              "valueBoolean": true
            }
          ]
        }
      ]
    },
    {
      "linkId": "2",
      "text": "IsT1cFeature",
      "item": [
        {
          "linkId": "2.1",
          "text": "Tumor size is at least T1c",
          "answer": [
            {
              "valueBoolean": true
            }
          ]
        }
      ]
    }
  ]
}

Expected behavior
A clear and concise description of what you expected to happen.

I expect item.definition to carry across questionnaire/questionnaire response when getting the response from the form.

I believe the issue stems from the return in removeRepeatId where only properties linkId, text, answer, and child items are returned.

  return {
    linkId: qItem.linkId,
    ...(qItem.text && { text: qItem.text }),
    ...(childQrItems.length > 0 && { item: childQrItems }),
    ...(updatedAnswers.length > 0 && { answer: updatedAnswers })
  };

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