SQL on FHIR
3.0.0-ballot - STU 3 Ballot International flag

SQL on FHIR, published by HL7 International / FHIR Infrastructure. This guide is not an authorized publication; it is the continuous build for version 3.0.0-ballot built by the FHIR (HL7® FHIR® Standard) CI Build. This version is based on the current content of https://github.com/HL7/sql-on-fhir/ and changes regularly. See the Directory of published versions

Example ViewDefinition: Encounter Flat

This view acts on the Encounter resource to produce a table named "encounter_flat".

The table contains the following columns:

NameFhir TypeSQL TypeCollection
idstringString
statusstringString
patient_idstringString
service_org_idstringString
period_startdateTimeDateTime
period_enddateTimeDateTime
type_sysstringString
type_codestringString
practitioner_idstringString
location_idstringString
episode_of_care_idstringString

Selection Rules:

ItemCollTypeDescription
encounter_flatEncounter
encounter_flat / Select
encounter_flat / Select / idgetResourceKey()
encounter_flat / Select / statusstatus
encounter_flat / Select / patient_idsubject.getReferenceKey(Patient)
encounter_flat / Select / service_org_idserviceProvider.getReferenceKey(Organization)
encounter_flat / Select / period_startactualPeriod.start
encounter_flat / Select / period_endactualPeriod.end
encounter_flat / Selectfor each type.coding, or null
encounter_flat / Select / type_syssystem
encounter_flat / Select / type_codecode
encounter_flat / Selectfor each participant, or null
encounter_flat / Select / practitioner_idactor.getReferenceKey(Practitioner)
encounter_flat / Selectfor each location, or null
encounter_flat / Select / location_idlocation.getReferenceKey(Location)
encounter_flat / Selectfor each episodeOfCare, or null
encounter_flat / Select / episode_of_care_idgetReferenceKey(EpisodeOfCare)

Notes:

This will result in an "encounter_flat" table that looks like this:

idstatuspatient_idservice_org_idperiod_startperiod_endepisode_of_care_idtype_systype_codepractitioner_idlocation_id
9completed28272020-01-01T09:00:00Z2020-01-01T10:00:00ZActCodeAMB3118
10completed29272020-01-02T14:00:00Z2020-01-03T08:00:00ZActCodeEMER3119