Skip to content
This repository has been archived by the owner on Oct 8, 2024. It is now read-only.

Cannot directly use FHIR path in SQL #14

Open
QuanWanxx opened this issue Jul 15, 2021 · 0 comments
Open

Cannot directly use FHIR path in SQL #14

QuanWanxx opened this issue Jul 15, 2021 · 0 comments

Comments

@QuanWanxx
Copy link

QuanWanxx commented Jul 15, 2021

All examples and guidance in spec using FHIR path as the column name,

SELECT subject.reference,
       AVG(value.quantity.value) avg_hdl
FROM observation o,
     UNNEST(o.code.coding) c
WHERE c.system = 'http://loinc.org' AND
      c.code = '2085-9' AND
      o.effective.datetime > '2017'
GROUP BY subject.reference

which is actually cannot be used in SQL database because the common pattern for a column name is "{TableName}.{ColumnName}". If we use FHIR path as the column name, we need to use brackets [] to warp it when creating table or querying data.

SELECT [subject.reference],
      AVG([value.quantity.value]) avg_hdl
FROM observation o,
    UNNEST(o.[code.coding]) c
WHERE c.system = 'http://loinc.org' AND
     c.code = '2085-9' AND
     o.[effective.datetime] > '2017'
GROUP BY [subject.reference]

Maybe recommend to use '_' as the separator rather than '.' ? E.g. From "subject.reference" to "subject_reference".

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant