Skip to content

Commit

Permalink
core: tighten up core_observation_lab and _vital_signs inclusion
Browse files Browse the repository at this point in the history
Require both these observation sub-type tables to use the proper
category code and system.
  • Loading branch information
mikix committed Apr 16, 2024
1 parent 117ec0f commit 05556c3
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 4 deletions.
16 changes: 12 additions & 4 deletions cumulus_library/studies/core/observation_type.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
CREATE TABLE core__observation_lab AS

SELECT
co.id,
co.observation_code,
Expand All @@ -17,7 +16,12 @@ SELECT
co.subject_ref,
co.encounter_ref,
co.observation_ref
FROM core__observation AS co;
FROM
core__observation AS co
WHERE
co.category_code = 'laboratory'
AND co.category_code_system
= 'http://terminology.hl7.org/CodeSystem/observation-category';

CREATE TABLE core__observation_vital_signs AS
SELECT
Expand All @@ -40,5 +44,9 @@ SELECT
co.subject_ref,
co.encounter_ref,
co.observation_ref
FROM core__observation AS co
WHERE co.category_code = 'vital-signs';
FROM
core__observation AS co
WHERE
co.category_code = 'vital-signs'
AND co.category_code_system
= 'http://terminology.hl7.org/CodeSystem/observation-category';
1 change: 1 addition & 0 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
("core__medicationrequest"),
("core__observation"),
("core__observation_lab"),
("core__observation_vital_signs"),
("core__patient"),
("core__count_condition_month"),
("core__count_documentreference_month"),
Expand Down
2 changes: 2 additions & 0 deletions tests/test_data/core/core__observation.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
('000ee3e3-845d-922b-ddad-1e4f150eb845', 'vital-signs', 'http://terminology.hl7.org/CodeSystem/observation-category', 'final', '39156-5', 'http://loinc.org', None, None, None, datetime.date(2018, 7, 31), datetime.date(2018, 7, 30), datetime.date(2018, 7, 1), datetime.date(2018, 1, 1), None, None, None, 29.33, None, 'kg/m2', 'http://unitsofmeasure.org', 'kg/m2', None, None, None, None, 'Patient/6385ddd7-2639-6505-3789-0521b8f66c8b', 'Encounter/fd0754a4-e96d-cba7-b3c0-77697a09c86e', 'Observation/000ee3e3-845d-922b-ddad-1e4f150eb845')
('00104f5f-cd8f-c1b5-7585-f3421d98ae65', 'vital-signs', 'http://terminology.hl7.org/CodeSystem/observation-category', 'final', '72514-3', 'http://loinc.org', None, None, None, datetime.date(2018, 9, 20), datetime.date(2018, 9, 17), datetime.date(2018, 9, 1), datetime.date(2018, 1, 1), None, None, None, 2.0, None, '{score}', 'http://unitsofmeasure.org', '{score}', None, None, None, None, 'Patient/6385ddd7-2639-6505-3789-0521b8f66c8b', 'Encounter/fd0754a4-e96d-cba7-b3c0-77697a09c86e', 'Observation/00104f5f-cd8f-c1b5-7585-f3421d98ae65')
('05e6184c-f3ef-017b-ce21-599d375020b3', 'laboratory', 'http://terminology.hl7.org/CodeSystem/observation-category', 'final', '34533-0', 'http://loinc.org', None, None, None, datetime.date(2018, 6, 2), datetime.date(2018, 5, 28), datetime.date(2018, 6, 1), datetime.date(2018, 1, 1), '167248002', 'http://snomed.info/sct', 'Urine smell ammoniacal (finding)', None, None, None, None, None, None, None, None, None, 'Patient/8877ef1f-7cd7-3242-d7f0-73cf3f7165f4', 'Encounter/299b6495-3fe7-8db3-c494-6e1ce8b7986d', 'Observation/05e6184c-f3ef-017b-ce21-599d375020b3')
('0935feb5-36bc-6a6c-7969-841bacbabdfe', 'laboratory', 'http://terminology.hl7.org/CodeSystem/observation-category', 'final', '5778-6', 'http://loinc.org', None, None, None, datetime.date(2018, 7, 11), datetime.date(2018, 7, 9), datetime.date(2018, 7, 1), datetime.date(2018, 1, 1), '371254008', 'http://snomed.info/sct', 'Brown color (qualifier value)', None, None, None, None, None, None, None, None, None, 'Patient/5ce2e599-fb6e-9b4d-3c2e-87310619b957', 'Encounter/4b03a408-6694-88e3-0e63-3ee464ecd6cd', 'Observation/0935feb5-36bc-6a6c-7969-841bacbabdfe')
('0d35c92c-8982-9737-2bae-79789514fde8', 'laboratory', 'http://terminology.hl7.org/CodeSystem/observation-category', 'final', '34533-0', 'http://loinc.org', None, None, None, datetime.date(2018, 7, 2), datetime.date(2018, 7, 2), datetime.date(2018, 7, 1), datetime.date(2018, 1, 1), '167248002', 'http://snomed.info/sct', 'Urine smell ammoniacal (finding)', None, None, None, None, None, None, None, None, None, 'Patient/17fde357-dcc9-af8b-a8d3-4bd213afeb22', 'Encounter/32d0ae2d-1be8-9e90-a4da-4c222abd88a9', 'Observation/0d35c92c-8982-9737-2bae-79789514fde8')
Expand Down
2 changes: 2 additions & 0 deletions tests/test_data/core/core__observation_vital_signs.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
('000ee3e3-845d-922b-ddad-1e4f150eb845', '39156-5', 'http://loinc.org', 'vital-signs', 'http://terminology.hl7.org/CodeSystem/observation-category', None, None, None, 'final', None, None, None, datetime.date(2018, 7, 31), datetime.date(2018, 7, 30), datetime.date(2018, 7, 1), datetime.date(2018, 1, 1), 'Patient/6385ddd7-2639-6505-3789-0521b8f66c8b', 'Encounter/fd0754a4-e96d-cba7-b3c0-77697a09c86e', 'Observation/000ee3e3-845d-922b-ddad-1e4f150eb845')
('00104f5f-cd8f-c1b5-7585-f3421d98ae65', '72514-3', 'http://loinc.org', 'vital-signs', 'http://terminology.hl7.org/CodeSystem/observation-category', None, None, None, 'final', None, None, None, datetime.date(2018, 9, 20), datetime.date(2018, 9, 17), datetime.date(2018, 9, 1), datetime.date(2018, 1, 1), 'Patient/6385ddd7-2639-6505-3789-0521b8f66c8b', 'Encounter/fd0754a4-e96d-cba7-b3c0-77697a09c86e', 'Observation/00104f5f-cd8f-c1b5-7585-f3421d98ae65')
2 changes: 2 additions & 0 deletions tests/test_data/duckdb_data/observation/vitals.ndjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{"resourceType":"Observation","id":"000ee3e3-845d-922b-ddad-1e4f150eb845","meta":{"profile":["http://hl7.org/fhir/us/core/StructureDefinition/us-core-bmi"]},"status":"final","category":[{"coding":[{"system":"http://terminology.hl7.org/CodeSystem/observation-category","code":"vital-signs","display":"Vital signs"}]}],"code":{"coding":[{"system":"http://loinc.org","code":"39156-5","display":"Body mass index (BMI) [Ratio]"}],"text":"Body mass index (BMI) [Ratio]"},"subject":{"reference":"Patient/6385ddd7-2639-6505-3789-0521b8f66c8b"},"encounter":{"reference":"Encounter/fd0754a4-e96d-cba7-b3c0-77697a09c86e"},"effectiveDateTime":"2018-07-31T11:46:59-04:00","issued":"2018-07-31T11:46:59.829-04:00","valueQuantity":{"value":29.33,"unit":"kg/m2","system":"http://unitsofmeasure.org","code":"kg/m2"}}
{"resourceType":"Observation","id":"00104f5f-cd8f-c1b5-7585-f3421d98ae65","status":"final","category":[{"coding":[{"system":"http://terminology.hl7.org/CodeSystem/observation-category","code":"vital-signs","display":"Vital signs"}]}],"code":{"coding":[{"system":"http://loinc.org","code":"72514-3","display":"Pain severity - 0-10 verbal numeric rating [Score] - Reported"}],"text":"Pain severity - 0-10 verbal numeric rating [Score] - Reported"},"subject":{"reference":"Patient/6385ddd7-2639-6505-3789-0521b8f66c8b"},"encounter":{"reference":"Encounter/fd0754a4-e96d-cba7-b3c0-77697a09c86e"},"effectiveDateTime":"2018-09-20T09:37:16-04:00","issued":"2018-09-20T09:37:16.824-04:00","valueQuantity":{"value":2,"unit":"{score}","system":"http://unitsofmeasure.org","code":"{score}"}}

0 comments on commit 05556c3

Please sign in to comment.