Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FHIR field naming conformance #201

Merged
merged 3 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions cumulus_library/.sqlfluff
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@
templater = jinja
dialect = athena
sql_file_exts = .sql,.sql.jinja
# this rule overfires on athena nested arrays
exclude_rules=references.from,structure.column_order,aliasing.unused
exclude_rules=
# these rule overfires on athena nested arrays
references.from,
structure.column_order,
aliasing.unused,
# this rule interferes with FHIR naming conventions
capitalisation.identifiers
max_line_length = 90

[sqlfluff:indentation]
Expand Down Expand Up @@ -100,12 +105,12 @@ schema =
'category': {
'coding': True, 'code': True, 'display': True, 'system': True, 'userSelected': True, 'version': True, 'text': True
},
'clinicalstatus': {
'clinicalStatus': {
'coding': True, 'code': True, 'display': True, 'system': True, 'userSelected': True, 'version': True, 'text': True
},
'id': True,
'recordeddate': True,
'verificationstatus': {
'recordedDate': True,
'verificationStatus': {
'coding': True, 'code': True, 'display': True, 'system': True, 'userSelected': True, 'version': True, 'text': True},
'subject': {
'reference': True, 'display': False, 'type': True
Expand All @@ -118,7 +123,7 @@ schema =
'id': True,
'type': True,
'status': True,
'docstatus': True,
'docStatus': True,
'context': {
'period': True, 'start': True
},
Expand All @@ -143,7 +148,7 @@ schema =
'id': True,
'status': True,
'intent': True,
'authoredon': True,
'authoredOn': True,
'category': {
'code': True, 'system': True, 'display': False
},
Expand All @@ -166,14 +171,14 @@ schema =
'interpretation': {
'coding': True, 'code': True, 'display': True, 'system': True, 'text': True
},
'referencerange': {
'referenceRange': {
'low': False, 'high': False, 'normalvalue': False, 'type': False, 'appliesto': False, 'age': False, 'text': True
},
'effectivedatetime': True,
'valuequantity': {
'valueQuantity': {
'value': True, 'comparator': False, 'unit': False, 'system': False, 'code': False
},
'valuecodeableconcept': {
'valueCodeableConcept': {
'coding': True, 'code': True, 'display': True, 'system': True
},
'subject': {
Expand Down
14 changes: 7 additions & 7 deletions cumulus_library/statistics/statistics_templates/count.sql.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ statistics/counts.py level -#}
{%- if fhir_resource in ('encounter', 'condition') -%}
encounter_ref
{%- elif fhir_resource == 'documentreference' -%}
doc_ref
documentreference_ref
{%- elif fhir_resource == 'observation'-%}
observation_ref
{%- else -%}
Expand All @@ -28,7 +28,7 @@ logic at the statistics/counts.py level -#}
{{- syntax.comma_delineate(loop) }}
{%- endfor %}
{%- if fhir_resource in ('documentreference', 'observation' ) -%},
enc_class_display
class_display
{% endif %}
{%- endmacro -%}

Expand All @@ -40,7 +40,7 @@ which will drop nulls, resulting in potentially non-unique keys -#}
{{- syntax.comma_delineate(loop) }}
{%- endfor %}
{%- if fhir_resource in ('documentreference', 'observation' ) -%},
COALESCE(enc_class_display,'')
COALESCE(class_display,'')
{% endif %}
{%- endmacro -%}

Expand Down Expand Up @@ -73,7 +73,7 @@ CREATE TABLE {{ table_name }} AS (
s.{{ tertiary }},
{%- endif -%}
{%- if fhir_resource in ('documentreference', 'observation') %}
e.enc_class_display,
e.class_display,
{%- endif %}
{#- these exceptions deal with table aliasing related to
single table queries, where this may be a multitable query
Expand Down Expand Up @@ -123,9 +123,9 @@ CREATE TABLE {{ table_name }} AS (
{%- endif -%}
{%- if fhir_resource in ('documentreference', 'observation' )%}
coalesce(
cast(enc_class_display AS varchar),
cast(class_display AS varchar),
'{{ missing_null }}'
) AS enc_class_display,
) AS class_display,
{%- endif -%}
{%- for col in table_cols %}
coalesce(
Expand Down Expand Up @@ -203,7 +203,7 @@ CREATE TABLE {{ table_name }} AS (
{{- syntax.comma_delineate(loop) }}
{%- endfor %}
{%- if fhir_resource in ('documentreference', 'observation' ) -%},
p.enc_class_display
p.class_display
{%- endif %}
FROM powerset AS p
{%- if secondary %}
Expand Down
2 changes: 1 addition & 1 deletion cumulus_library/studies/core/builder_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"text",
],
"id": [],
"recordeddate": [],
"recordedDate": [],
"verificationstatus": [
"coding",
"code",
Expand Down
2 changes: 1 addition & 1 deletion cumulus_library/studies/core/builder_documentreference.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"id": [],
"type": [],
"status": [],
"docstatus": [],
"docStatus": [],
"subject": ["reference"],
"context": ["encounter", "period", "start"],
"category": [],
Expand Down
8 changes: 4 additions & 4 deletions cumulus_library/studies/core/builder_medicationrequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
"id": [],
"status": [],
"intent": [],
"authoredon": [],
"reportedboolean": [],
"authoredOn": [],
"reportedBoolean": [],
"category": ["code", "system", "display"],
"medicationcodeableconcept": ["code", "system", "display"],
"medicationCodeableConcept": ["code", "system", "display"],
"subject": ["reference"],
"encounter": ["reference"],
"dosageinstruction": ["text"],
"dosageInstruction": ["text"],
}
}

Expand Down
14 changes: 7 additions & 7 deletions cumulus_library/studies/core/builder_observation.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@
"status": [],
"code": ["coding", "code", "display", "system", "text"],
"interpretation": ["coding", "code", "display", "system", "text"],
"referencerange": [
"referenceRange": [
"low",
"high",
"normalvalue",
"normalValue",
"type",
"appliesto",
"appliesTo",
"age",
"text",
],
"effectivedatetime": [],
"valuequantity": ["value", "comparator", "unit", "system", "code"],
"valuecodeableconcept": ["coding", "code", "display", "system"],
"valuestring": [],
"effectiveDateTime": [],
"valueQuantity": ["value", "comparator", "unit", "system", "code"],
"valueCodeableConcept": ["coding", "code", "display", "system"],
"valueString": [],
"subject": ["reference"],
"encounter": ["reference"],
}
Expand Down
2 changes: 1 addition & 1 deletion cumulus_library/studies/core/builder_patient.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"id": [],
"gender": [],
"address": [],
"birthdate": [],
"birthDate": [],
}
}

Expand Down
32 changes: 16 additions & 16 deletions cumulus_library/studies/core/core_templates/condition.sql.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ WITH temp_condition AS (
utils.date_cols_from_str(
'condition',
'c',
['recordeddate'],
['recordedDate'],
schema
)
}},
Expand All @@ -48,15 +48,15 @@ WITH temp_condition AS (
'condition',
'c',
[
('recordeddate', 'week'),
('recordeddate', 'month'),
('recordeddate', 'year'),
('recordedDate', 'week'),
('recordedDate', 'month'),
('recordedDate', 'year'),
],
schema
)
}},
c.verificationstatus,
c.clinicalstatus
c.verificationStatus,
c.clinicalStatus
FROM condition AS c
LEFT JOIN core__condition_codable_concepts_all AS cca ON c.id = cca.id
)
Expand All @@ -71,17 +71,17 @@ SELECT
tc.subject_ref,
tc.encounter_ref,
concat('Condition/', tc.id) AS condition_ref,
tc.recordeddate,
tc.recordeddate_week AS recorded_week,
tc.recordeddate_month AS recorded_month,
tc.recordeddate_year AS recorded_year,
t_clinicalstatus_coding.clinicalstatus_row.code AS clinicalstatus_code,
t_verificationstatus_coding.verificationstatus_row.code AS verificationstatus_code
tc.recordedDate,
tc.recordedDate_week,
tc.recordedDate_month,
tc.recordedDate_year,
t_clinicalStatus_coding.clinicalStatus_row.code AS clinicalStatus_code,
t_verificationStatus_coding.verificationStatus_row.code AS verificationStatus_code
FROM temp_condition AS tc,
unnest(category) AS t_category (category_coding),
unnest(category_coding.coding) AS t_category_coding (category_row),
unnest(clinicalstatus.coding) AS t_clinicalstatus_coding (clinicalstatus_row),
unnest(verificationstatus.coding)
AS t_verificationstatus_coding (verificationstatus_row)
unnest(clinicalStatus.coding) AS t_clinicalStatus_coding (clinicalStatus_row),
unnest(verificationStatus.coding)
AS t_verificationStatus_coding (verificationStatus_row)

WHERE tc.recordeddate BETWEEN date('2016-01-01') AND current_date;
WHERE tc.recordedDate BETWEEN date('2016-01-01') AND current_date;
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ targets is an array expecting a data type of the following:
{#- depth two nested column -#}
{%- elif col is not string and col|length ==4%}
{%- if schema[table][col[0]][col[2]] %}
date(from_iso8601_timestamp({{ alias }}.{{ col[0] }}.{{ col[1] }}.{{ col[2].lower() }})) AS {{col[3]}}
date(from_iso8601_timestamp({{ alias }}.{{ col[0] }}.{{ col[1] }}.{{ col[2] }})) AS {{col[3]}}
{%- else %}
cast(NULL AS date) AS {{ col[3].lower() }}
{%- endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ WITH temp_documentreference AS (
'type',
'status',
'date',
'docstatus',
'docStatus',
'context',
('subject', 'reference', 'subject_ref'),
('context', 'period', 'start', 'author_date')
Expand All @@ -39,11 +39,11 @@ WITH temp_documentreference AS (
schema
)
}},
cdrt.code as doc_type_code,
cdrt.code_system as doc_type_code_system,
cdrt.display as doc_type_display,
cdrc.code as doc_category_code,
cdrf.code as doc_format_code
cdrt.code as type_code,
cdrt.code_system as type_code_system,
cdrt.display as type_display,
cdrc.code as category_code,
cdrf.code as format_code
FROM documentreference AS dr
LEFT JOIN core__documentreference_dn_type AS cdrt ON dr.id = cdrt.id
LEFT JOIN core__documentreference_dn_category AS cdrc ON dr.id = cdrc.id
Expand All @@ -70,20 +70,20 @@ temp_encounters AS (
SELECT DISTINCT
tdr.id,
tdr.status,
tdr.doc_type_code,
tdr.doc_type_code_system,
tdr.doc_type_display,
tdr.doc_category_code,
tdr.docstatus,
tdr.type_code,
tdr.type_code_system,
tdr.type_display,
tdr.category_code,
tdr.docStatus,
tdr."date",
tdr.author_day AS author_date,
tdr.author_day,
tdr.author_week,
tdr.author_month,
tdr.author_year,
tdr.doc_format_code,
tdr.format_code,
tdr.subject_ref,
te.encounter_ref,
concat('DocumentReference/', tdr.id) AS doc_ref
concat('DocumentReference/', tdr.id) AS documentreference_ref
FROM temp_documentreference AS tdr
LEFT JOIN temp_encounters AS te ON tdr.id = te.id
WHERE date(tdr.author_day) BETWEEN date('2016-06-01') AND current_date;
Loading
Loading