Skip to content

Remove null values from CDS Hook API responses #142

@jenniferjiangkells

Description

@jenniferjiangkells

CDS Hook API responses currently include null values for all optional fields, making responses verbose and harder to read. This is especially noticeable in example scripts and documentation.

Example current output:

{
  "cards": [{
    "summary": "Sepsis Risk: 0.1",
    "indicator": "info",
    "source": {
      "label": "ML prediction",
      "url": null,
      "icon": null,
      "topic": null
    },
    "uuid": null,
    "detail": "No action required.",
    "suggestions": null,
    "selectionBehavior": null,
    "overrideReasons": null,
    "links": null
  }],
  "systemActions": null
}

Desired output:

{
  "cards": [{
    "summary": "Sepsis Risk: 0.1",
    "indicator": "info",
    "source": {
      "label": "ML prediction"
    },
    "detail": "No action required."
  }]
}

Files to check:

  • scripts/predict_example.py (confirmed issue)
  • Any file calling .model_dump() on CDS models
  • healthchain/gateway/cds/ (CDS service implementations)
  • Example scripts in cookbook/

Goal:
Configure Pydantic serialization to exclude None values from API responses.

Acceptance Criteria:

  • Find all locations where CDS models are serialized (search for .model_dump())
  • Add exclude_none=True parameter to serialization calls
  • Verify responses are cleaner in examples (test manually)
  • Ensure all tests still pass
  • Response validation should still work correctly

Implementation:

Card(...).model_dump(exclude_none=True)

Resources:

  • Pydantic serialization docs
  • healthchain/models/responses/cdsresponse.py for model definitions
  • Test with: python scripts/predict_example.py and check http://localhost:8000/docs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Component: GatewayIssue/PR that handles connections, API gatewaysgood first issueGood for newcomershacktoberfestIssues suitable for hacktoberfest

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions