Skip to content

Commit

Permalink
Add conclusionCode to diagnosticreport table
Browse files Browse the repository at this point in the history
  • Loading branch information
mikix committed Dec 4, 2024
1 parent 47c8e3e commit 0c01575
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 3 deletions.
5 changes: 5 additions & 0 deletions cumulus_library/studies/core/builder_diagnosticreport.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ def prepare_queries(self, *args, config: cumulus_library.StudyConfig, **kwargs):
column_hierarchy=[("code", dict)],
target_table="core__diagnosticreport_dn_code",
),
sql_utils.CodeableConceptConfig(
source_table="diagnosticreport",
column_hierarchy=[("conclusionCode", list)],
target_table="core__diagnosticreport_dn_conclusioncode",
),
]
self.queries += sql_utils.denormalize_complex_objects(config.db, code_sources)
validated_schema = sql_utils.validate_schema(config.db, expected_table_cols)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
-- * the `reporter` field, simply due to it not likely being interesting to consumers
-- and being an array field, which would require a lot of row duplication.
--
-- AND ADDING:
-- * the `conclusionCode` field, because it has clinical relevance
--
-- US Core profiles for reference:
-- * https://hl7.org/fhir/us/core/STU4/StructureDefinition-us-core-diagnosticreport-lab.html
-- * https://hl7.org/fhir/us/core/STU4/StructureDefinition-us-core-diagnosticreport-note.html
Expand Down Expand Up @@ -91,6 +94,10 @@ SELECT
td.issued_month,
td.issued_year,

dn_conclusion.code AS conclusionCode_code,
dn_conclusion.system AS conclusionCode_system,
dn_conclusion.display AS conclusionCode_display,

concat('DiagnosticReport/', td.id) AS diagnosticreport_ref,
td.subject_ref,
td.encounter_ref,
Expand All @@ -99,4 +106,6 @@ SELECT
FROM temp_diagnosticreport AS td
LEFT JOIN core__diagnosticreport_dn_code AS dn_code ON td.id = dn_code.id
LEFT JOIN core__diagnosticreport_dn_category AS dn_category ON td.id = dn_category.id
LEFT JOIN core__diagnosticreport_dn_conclusioncode AS dn_conclusion
ON td.id = dn_conclusion.id
LEFT JOIN temp_result AS tr ON td.id = tr.id;
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,18 @@ CREATE TABLE core__diagnosticreport_dn_code AS (

-- ###########################################################

CREATE TABLE IF NOT EXISTS "main"."core__diagnosticreport_dn_conclusioncode"
AS (
SELECT * FROM (
VALUES
(cast(NULL AS varchar),cast(NULL AS bigint),cast(NULL AS varchar),cast(NULL AS varchar),cast(NULL AS varchar),cast(NULL AS boolean))
)
AS t ("id","row","code","system","display","userSelected")
WHERE 1 = 0 -- ensure empty table
);

-- ###########################################################




Expand All @@ -104,6 +116,9 @@ CREATE TABLE core__diagnosticreport_dn_code AS (
-- * the `reporter` field, simply due to it not likely being interesting to consumers
-- and being an array field, which would require a lot of row duplication.
--
-- AND ADDING:
-- * the `conclusionCode` field, because it has clinical relevance
--
-- US Core profiles for reference:
-- * https://hl7.org/fhir/us/core/STU4/StructureDefinition-us-core-diagnosticreport-lab.html
-- * https://hl7.org/fhir/us/core/STU4/StructureDefinition-us-core-diagnosticreport-note.html
Expand Down Expand Up @@ -192,6 +207,10 @@ SELECT
td.issued_month,
td.issued_year,

dn_conclusion.code AS conclusionCode_code,
dn_conclusion.system AS conclusionCode_system,
dn_conclusion.display AS conclusionCode_display,

concat('DiagnosticReport/', td.id) AS diagnosticreport_ref,
td.subject_ref,
td.encounter_ref,
Expand All @@ -200,4 +219,6 @@ SELECT
FROM temp_diagnosticreport AS td
LEFT JOIN core__diagnosticreport_dn_code AS dn_code ON td.id = dn_code.id
LEFT JOIN core__diagnosticreport_dn_category AS dn_category ON td.id = dn_category.id
LEFT JOIN core__diagnosticreport_dn_conclusioncode AS dn_conclusion
ON td.id = dn_conclusion.id
LEFT JOIN temp_result AS tr ON td.id = tr.id;
14 changes: 14 additions & 0 deletions docs/core-study-details.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ Per resource, the optional fields are as follows:
- Condition
- encounter
- recordedDate
- DiagnosticReport
- conclusionCode
- DocumentReference
- docStatus
- Encounter
Expand Down Expand Up @@ -408,6 +410,18 @@ vital signs) instead.
|userselected|boolean| |


### core__diagnosticreport_dn_conclusioncode

| Column | Type |Description|
|------------|-------|-----------|
|id |varchar| |
|row |bigint | |
|code |varchar| |
|system |varchar| |
|display |varchar| |
|userselected|boolean| |


### core__documentreference

| Column | Type |Description|
Expand Down
24 changes: 21 additions & 3 deletions tests/core/test_core_diagreports.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,16 @@ def test_core_diag_report_many_cases(tmp_path):
{"reference": "Observation/result1"},
{"reference": "Observation/result2"},
],
conclusionCode=[
{"coding": [{"code": "conc1", "system": "sys:conc", "display": "Conclusion One"}]},
{"coding": [{"code": "conc2", "system": "sys:conc", "display": "Conclusion Two"}]},
],
)

con = testbed.build()
df = con.sql("SELECT * FROM core__diagnosticreport").df()
rows = json.loads(df.to_json(orient="records"))

assert 8 == len(rows)
assert len(rows) == 16

combos = combine_dictionaries(
# Start with a list of size one - all the consistent elements across all rows
Expand Down Expand Up @@ -85,12 +88,24 @@ def test_core_diag_report_many_cases(tmp_path):
{"code_code": "code1", "code_system": "sys:code", "code_display": "Code One"},
{"code_code": "code2", "code_system": "sys:code", "code_display": "Code Two"},
],
[
{
"conclusionCode_code": "conc1",
"conclusionCode_system": "sys:conc",
"conclusionCode_display": "Conclusion One",
},
{
"conclusionCode_code": "conc2",
"conclusionCode_system": "sys:conc",
"conclusionCode_display": "Conclusion Two",
},
],
[
{"result_ref": "Observation/result1"},
{"result_ref": "Observation/result2"},
],
)
assert 8 == len(combos) # sanity check our product math
assert len(combos) == 16 # sanity check our product math

assert dict_set_from_list(rows) == dict_set_from_list(combos)

Expand Down Expand Up @@ -134,6 +149,9 @@ def test_core_diag_report_minimal(tmp_path):
"issued_month": None,
"issued_year": None,
"result_ref": None,
"conclusionCode_code": None,
"conclusionCode_system": None,
"conclusionCode_display": None,
}
]

Expand Down

0 comments on commit 0c01575

Please sign in to comment.