Skip to content

Add embedded SQL queries to ViewDefinition examples#313

Draft
johngrimes wants to merge 10 commits into
masterfrom
embedded-sql-queries
Draft

Add embedded SQL queries to ViewDefinition examples#313
johngrimes wants to merge 10 commits into
masterfrom
embedded-sql-queries

Conversation

@johngrimes
Copy link
Copy Markdown
Collaborator

@johngrimes johngrimes commented Feb 5, 2026

Summary

This PR adds dynamic SQL query generation to ViewDefinition example pages using the IG Publisher's SQL on FHIR integration feature.

Changes:

  • Create example FHIR resources (Patient, Observation, Condition, Encounter) that provide test data for ViewDefinition execution
  • Register ViewDefinitions with the IG Publisher via the viewDefinition parameter in sushi-config.yaml
  • Replace static markdown tables in *-notes.md files with {% sql %} Liquid tags
  • Add new notes files for ConditionFlat and EncounterFlat examples

Blocking issue

IG Publisher validation rejects ViewDefinitions with FHIR resource properties

The IG Publisher's SQL on FHIR validator (org.hl7.fhir.r5.utils.sql.Validator) fails with errors like:

ERROR @ $.id (line 3, col9): Unknown JSON property id
org.hl7.fhir.exceptions.FHIRException: View Definition is not valid

SUSHI generates ViewDefinition instances as Binary resources containing JSON with FHIR resource properties (id, meta, fhirVersion) that the validator doesn't recognise. The validator expects pure ViewDefinition structure without these fields.

Potential solutions:

  1. Upstream fix in IG Publisher to strip/ignore FHIR resource properties when validating ViewDefinitions from Binary resources
  2. Create ViewDefinition JSON files manually in input/resources/ without FHIR metadata

Outstanding tasks

  • 4.1 Run full IG build and verify no errors (blocked by validation issue)
  • 4.2 Verify generated HTML pages contain expected tables
  • 4.3 Compare generated tables with previous static tables to ensure data matches

Additional notes

  • EncounterFlat ViewDefinition targets FHIR R4 only, so its notes file contains a static explanation rather than a dynamic SQL query (the IG is built with R5)
  • PatientDemographics and ShareablePatientDemographics share the same view name by design

- Create example FHIR resources (Patient, Observation, Condition,
  Encounter) in FSH to provide data for ViewDefinition execution
- Register ViewDefinitions with IG Publisher via viewDefinition parameter
- Replace static markdown tables in notes files with {% sql %} Liquid tags
- Add new notes files for ConditionFlat and EncounterFlat examples

Note: The IG Publisher's SQL on FHIR validator currently rejects these
ViewDefinitions due to FHIR resource properties (id, meta) that SUSHI
adds to logical model instances. This requires an upstream fix in the
IG Publisher to strip these properties during validation.
@arjun
Copy link
Copy Markdown
Collaborator

arjun commented Apr 7, 2026

4/7: Currently block with PR on IG Publisher with Lloyd

Replace R4-only paths (period.start, period.end, participant.individual)
with their R5 equivalents (actualPeriod.start, actualPeriod.end,
participant.actor) and drop the R4 fhirVersion constraint. Update the
notes page to embed a dynamic SQL query instead of a static columns table.

Note: the rendered table is currently empty because of a separate IG
Publisher bug that mis-types dateTime columns as integer; the view
itself is now structurally correct against R5 Encounter resources.
Add a small vehicle CodeSystem (matching the hierarchy documented in
the CodeSystemHierarchy notes) and two QuestionnaireResponse instances
covering both flat and nested item structures. These will be picked up
by the CodeSystemHierarchy and QuestionnaireResponseItems views once
the upstream IG Publisher handles the `repeat` directive correctly.
Update the version field in publication-request.json from 2.0.0 to 2.1.0
to match the package version declared in sushi-config.yaml. The previous
value caused IG Publisher to report errors that the publication request
targeted a version mismatching the package, and that 2.0.0 had already
been published.
Address several validation errors reported by the IG Publisher:

- Update the blood pressure observations to comply with the implicit
  Observation BP profile. Change the UCUM code from 'mmHg' to 'mm[Hg]',
  use the official LOINC display 'Blood pressure panel with all children
  optional' for 85354-9, and add the required vital-signs category.
- Add minimal Practitioner, Organization, and Location example
  instances referenced by ExampleEncounter1 and ExampleEncounter2 so
  that the references resolve.
- Rename the vehicles CodeSystem id from '1' to 'vehicles'. The shared
  id was causing the IG Publisher's narrative renderer to mis-link
  integer cell values in ViewDefinition output tables to the
  CodeSystem, producing broken-link errors across many Binary pages.
- Assign an OID identifier to the vehicles CodeSystem to satisfy the
  IG Publisher's OID requirement for CodeSystem resources.
@johngrimes
Copy link
Copy Markdown
Collaborator Author

All work for this has been completed and we will be able to merge this once hapifhir/org.hl7.fhir.core#2453 flows through to the IG Publisher.

Replace static markdown tables in the CodeSystemHierarchy and
QuestionnaireResponseItems notes with embedded SQL query blocks so that
the displayed results are generated from the live view definitions.
Adds a new PatientNamesWithIndex example demonstrating the same
approach, with a supporting additional name entry on the patient
example and the corresponding path-resource entries in the IG config.
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

Successfully merging this pull request may close these issues.

2 participants