diff --git a/cumulus_library/studies/core/core_templates/condition.sql.jinja b/cumulus_library/studies/core/core_templates/condition.sql.jinja index 16a94b6a..210e6369 100644 --- a/cumulus_library/studies/core/core_templates/condition.sql.jinja +++ b/cumulus_library/studies/core/core_templates/condition.sql.jinja @@ -61,7 +61,7 @@ WITH temp_condition AS ( SELECT tc.id, cdc.code AS category_code, - cdc.code_system AS category_code_system, + cdc.code_system AS category_system, cdc.display AS category_display, tc.code, tc.code_system, diff --git a/cumulus_library/studies/core/core_templates/documentreference.sql.jinja b/cumulus_library/studies/core/core_templates/documentreference.sql.jinja index 360dff03..18ece5f5 100644 --- a/cumulus_library/studies/core/core_templates/documentreference.sql.jinja +++ b/cumulus_library/studies/core/core_templates/documentreference.sql.jinja @@ -44,7 +44,7 @@ WITH temp_documentreference AS ( ) }}, cdrt.code as type_code, - cdrt.code_system as type_code_system, + cdrt.code_system as type_system, cdrt.display as type_display, cdrc.code as category_code, cdrf.code as format_code @@ -75,7 +75,7 @@ SELECT DISTINCT tdr.id, tdr.status, tdr.type_code, - tdr.type_code_system, + tdr.type_system, tdr.type_display, tdr.category_code, tdr.docStatus, diff --git a/cumulus_library/studies/core/core_templates/encounter.sql.jinja b/cumulus_library/studies/core/core_templates/encounter.sql.jinja index fa45c089..e37b485d 100644 --- a/cumulus_library/studies/core/core_templates/encounter.sql.jinja +++ b/cumulus_library/studies/core/core_templates/encounter.sql.jinja @@ -27,7 +27,7 @@ temp_encounter_nullable AS ( [ 'status', ('class', 'code', 'class_code'), - ('class', 'system', 'class_code_system'), + ('class', 'system', 'class_system'), ('subject', 'reference', 'subject_ref'), ], schema @@ -69,7 +69,7 @@ temp_encounter AS ( e.id, e.status, e.class_code, - e.class_code_system, + e.class_system, e.subject_ref, e.period_start, e.period_start_day, @@ -78,19 +78,19 @@ temp_encounter AS ( e.period_start_month, e.period_start_year, edt.code AS type_code, - edt.code_system AS type_code_system, + edt.code_system AS type_system, edt.display AS type_display, eds.code AS serviceType_code, - eds.code_system AS serviceType_code_system, + eds.code_system AS serviceType_system, eds.display AS serviceType_display, edp.code AS priority_code, - edp.code_system AS priority_code_system, + edp.code_system AS priority_system, edp.display AS priority_display, edr.code AS reasonCode_code, - edr.code_system AS reasonCode_code_system, + edr.code_system AS reasonCode_system, edr.display AS reasonCode_display, edd.code AS dischargeDisposition_code, - edd.code_system AS dischargeDisposition_code_system, + edd.code_system AS dischargeDisposition_system, edd.display AS dischargeDisposition_display FROM temp_encounter_nullable AS e @@ -107,19 +107,19 @@ SELECT DISTINCT ac.code AS class_code, ac.display AS class_display, e.type_code, - e.type_code_system, + e.type_system, e.type_display, e.serviceType_code, - e.serviceType_code_system, + e.serviceType_system, e.serviceType_display, e.priority_code, - e.priority_code_system, + e.priority_system, e.priority_display, e.reasonCode_code, - e.reasonCode_code_system, + e.reasonCode_system, e.reasonCode_display, e.dischargeDisposition_code, - e.dischargeDisposition_code_system, + e.dischargeDisposition_system, e.dischargeDisposition_display, date_diff('year', date(p.birthdate), e.period_start_day) AS age_at_visit, p.gender, diff --git a/cumulus_library/studies/core/core_templates/medicationrequest.sql.jinja b/cumulus_library/studies/core/core_templates/medicationrequest.sql.jinja index 6f20a85f..666fffb0 100644 --- a/cumulus_library/studies/core/core_templates/medicationrequest.sql.jinja +++ b/cumulus_library/studies/core/core_templates/medicationrequest.sql.jinja @@ -59,9 +59,9 @@ temp_mr AS ( schema ) -}}, mrc.code AS category_code, - mrc.code_system AS category_code_system, + mrc.code_system AS category_system, mrm.code AS medication_code, - mrm.code_system AS medication_code_system, + mrm.code_system AS medication_system, mrm.display AS medication_display, mrdt.dosageInstruction_text FROM medicationrequest AS mr @@ -76,9 +76,9 @@ SELECT mr.status, mr.intent, mr.category_code, - mr.category_code_system, + mr.category_system, mr.reportedBoolean, - mr.medication_code_system, + mr.medication_system, mr.medication_code, mr.medication_display, mr.authoredOn, diff --git a/cumulus_library/studies/core/core_templates/observation.sql.jinja b/cumulus_library/studies/core/core_templates/observation.sql.jinja index f7df60a7..d4bc8745 100644 --- a/cumulus_library/studies/core/core_templates/observation.sql.jinja +++ b/cumulus_library/studies/core/core_templates/observation.sql.jinja @@ -22,7 +22,7 @@ WITH temp_observation AS ( ('valueQuantity', 'value', 'valueQuantity_value'), ('valueQuantity', 'comparator', 'valueQuantity_comparator'), ('valueQuantity', 'unit', 'valueQuantity_unit'), - ('valueQuantity', 'system', 'valueQuantity_code_system'), + ('valueQuantity', 'system', 'valueQuantity_system'), ('valueQuantity', 'code', 'valueQuantity_code'), ], schema @@ -41,17 +41,17 @@ WITH temp_observation AS ( ) }}, odc.code AS observation_code, - odc.code_system AS observation_code_system, + odc.code_system AS observation_system, odcat.code AS category_code, - odcat.code_system AS category_code_system, + odcat.code_system AS category_system, odi.code AS interpretation_code, - odi.code_system AS interpretation_code_system, + odi.code_system AS interpretation_system, odi.display AS interpretation_display, odvcc.code AS valueCodeableConcept_code, - odvcc.code_system AS valueCodeableConcept_code_system, + odvcc.code_system AS valueCodeableConcept_system, odvcc.display AS valueCodeableConcept_display, odda.code AS dataAbsentReason_code, - odda.code_system AS dataAbsentReason_code_system, + odda.code_system AS dataAbsentReason_system, odda.display AS dataAbsentReason_display FROM observation AS o LEFT JOIN core__observation_dn_category AS odcat ON o.id = odcat.id @@ -64,28 +64,28 @@ WITH temp_observation AS ( SELECT id, category_code, - category_code_system, + category_system, status, observation_code, - observation_code_system, + observation_system, interpretation_code, - interpretation_code_system, + interpretation_system, interpretation_display, effectiveDateTime_day, effectiveDateTime_week, effectiveDateTime_month, effectiveDateTime_year, valueCodeableConcept_code, - valueCodeableConcept_code_system, + valueCodeableConcept_system, valueCodeableConcept_display, valueQuantity_value, valueQuantity_comparator, valueQuantity_unit, - valueQuantity_code_system, + valueQuantity_system, valueQuantity_code, valueString, dataAbsentReason_code, - dataAbsentReason_code_system, + dataAbsentReason_system, dataAbsentReason_display, subject_ref, encounter_ref, diff --git a/cumulus_library/studies/core/observation_type.sql b/cumulus_library/studies/core/observation_type.sql index bee4199a..20aefcfe 100644 --- a/cumulus_library/studies/core/observation_type.sql +++ b/cumulus_library/studies/core/observation_type.sql @@ -6,11 +6,11 @@ CREATE TABLE core__observation_lab AS SELECT co.id, co.observation_code, - co.observation_code_system, + co.observation_system, co.category_code, - co.category_code_system, + co.category_system, co.valueCodeableConcept_code, - co.valueCodeableConcept_code_system, + co.valueCodeableConcept_system, co.valueCodeableConcept_display, co.effectiveDateTime_day, co.effectiveDateTime_week, @@ -24,27 +24,27 @@ FROM core__observation AS co WHERE co.category_code = 'laboratory' - AND co.category_code_system + AND co.category_system = 'http://terminology.hl7.org/CodeSystem/observation-category'; CREATE TABLE core__observation_vital_signs AS SELECT co.id, co.observation_code, - co.observation_code_system, + co.observation_system, co.category_code, - co.category_code_system, + co.category_system, co.valueCodeableConcept_code, - co.valueCodeableConcept_code_system, + co.valueCodeableConcept_system, co.valueCodeableConcept_display, co.valueQuantity_value, co.valueQuantity_comparator, co.valueQuantity_unit, - co.valueQuantity_code_system, + co.valueQuantity_system, co.valueQuantity_code, co.status, co.interpretation_code, - co.interpretation_code_system, + co.interpretation_system, co.interpretation_display, co.effectiveDateTime_day, co.effectiveDateTime_week, @@ -57,5 +57,5 @@ FROM core__observation AS co WHERE co.category_code = 'vital-signs' - AND co.category_code_system + AND co.category_system = 'http://terminology.hl7.org/CodeSystem/observation-category'; diff --git a/cumulus_library/studies/core/reference_sql/builder_condition.sql b/cumulus_library/studies/core/reference_sql/builder_condition.sql index 3dbd4f51..25d1eb81 100644 --- a/cumulus_library/studies/core/reference_sql/builder_condition.sql +++ b/cumulus_library/studies/core/reference_sql/builder_condition.sql @@ -471,7 +471,7 @@ WITH temp_condition AS ( SELECT tc.id, cdc.code AS category_code, - cdc.code_system AS category_code_system, + cdc.code_system AS category_system, cdc.display AS category_display, tc.code, tc.code_system, diff --git a/cumulus_library/studies/core/reference_sql/builder_documentreference.sql b/cumulus_library/studies/core/reference_sql/builder_documentreference.sql index d80153a7..9e4dce6f 100644 --- a/cumulus_library/studies/core/reference_sql/builder_documentreference.sql +++ b/cumulus_library/studies/core/reference_sql/builder_documentreference.sql @@ -175,7 +175,7 @@ WITH temp_documentreference AS ( date_trunc('year', date(from_iso8601_timestamp(dr."context"."period"."start"))) AS author_year, cdrt.code as type_code, - cdrt.code_system as type_code_system, + cdrt.code_system as type_system, cdrt.display as type_display, cdrc.code as category_code, cdrf.code as format_code @@ -201,7 +201,7 @@ SELECT DISTINCT tdr.id, tdr.status, tdr.type_code, - tdr.type_code_system, + tdr.type_system, tdr.type_display, tdr.category_code, tdr.docStatus, diff --git a/cumulus_library/studies/core/reference_sql/builder_encounter.sql b/cumulus_library/studies/core/reference_sql/builder_encounter.sql index 93b279b6..87232077 100644 --- a/cumulus_library/studies/core/reference_sql/builder_encounter.sql +++ b/cumulus_library/studies/core/reference_sql/builder_encounter.sql @@ -611,7 +611,7 @@ temp_encounter_nullable AS ( e.id, e.status, e.class.code AS class_code, - e.class.system AS class_code_system, + e.class.system AS class_system, e.subject.reference AS subject_ref, date(from_iso8601_timestamp(e.period.start)) AS period_start, date_trunc('day', date(from_iso8601_timestamp(e."period"."end"))) @@ -638,7 +638,7 @@ temp_encounter AS ( e.id, e.status, e.class_code, - e.class_code_system, + e.class_system, e.subject_ref, e.period_start, e.period_start_day, @@ -647,19 +647,19 @@ temp_encounter AS ( e.period_start_month, e.period_start_year, edt.code AS type_code, - edt.code_system AS type_code_system, + edt.code_system AS type_system, edt.display AS type_display, eds.code AS serviceType_code, - eds.code_system AS serviceType_code_system, + eds.code_system AS serviceType_system, eds.display AS serviceType_display, edp.code AS priority_code, - edp.code_system AS priority_code_system, + edp.code_system AS priority_system, edp.display AS priority_display, edr.code AS reasonCode_code, - edr.code_system AS reasonCode_code_system, + edr.code_system AS reasonCode_system, edr.display AS reasonCode_display, edd.code AS dischargeDisposition_code, - edd.code_system AS dischargeDisposition_code_system, + edd.code_system AS dischargeDisposition_system, edd.display AS dischargeDisposition_display FROM temp_encounter_nullable AS e @@ -676,19 +676,19 @@ SELECT DISTINCT ac.code AS class_code, ac.display AS class_display, e.type_code, - e.type_code_system, + e.type_system, e.type_display, e.serviceType_code, - e.serviceType_code_system, + e.serviceType_system, e.serviceType_display, e.priority_code, - e.priority_code_system, + e.priority_system, e.priority_display, e.reasonCode_code, - e.reasonCode_code_system, + e.reasonCode_system, e.reasonCode_display, e.dischargeDisposition_code, - e.dischargeDisposition_code_system, + e.dischargeDisposition_system, e.dischargeDisposition_display, date_diff('year', date(p.birthdate), e.period_start_day) AS age_at_visit, p.gender, diff --git a/cumulus_library/studies/core/reference_sql/builder_medicationrequest.sql b/cumulus_library/studies/core/reference_sql/builder_medicationrequest.sql index e74478ce..890e86d3 100644 --- a/cumulus_library/studies/core/reference_sql/builder_medicationrequest.sql +++ b/cumulus_library/studies/core/reference_sql/builder_medicationrequest.sql @@ -82,9 +82,9 @@ temp_mr AS ( mr.subject.reference AS subject_ref, mr.encounter.reference AS encounter_ref, mrc.code AS category_code, - mrc.code_system AS category_code_system, + mrc.code_system AS category_system, mrm.code AS medication_code, - mrm.code_system AS medication_code_system, + mrm.code_system AS medication_system, mrm.display AS medication_display, mrdt.dosageInstruction_text FROM medicationrequest AS mr @@ -99,9 +99,9 @@ SELECT mr.status, mr.intent, mr.category_code, - mr.category_code_system, + mr.category_system, mr.reportedBoolean, - mr.medication_code_system, + mr.medication_system, mr.medication_code, mr.medication_display, mr.authoredOn, diff --git a/cumulus_library/studies/core/reference_sql/builder_observation.sql b/cumulus_library/studies/core/reference_sql/builder_observation.sql index 77feb2fc..e946e5ec 100644 --- a/cumulus_library/studies/core/reference_sql/builder_observation.sql +++ b/cumulus_library/studies/core/reference_sql/builder_observation.sql @@ -343,7 +343,7 @@ WITH temp_observation AS ( o.valueQuantity.value AS valueQuantity_value, o.valueQuantity.comparator AS valueQuantity_comparator, o.valueQuantity.unit AS valueQuantity_unit, - o.valueQuantity.system AS valueQuantity_code_system, + o.valueQuantity.system AS valueQuantity_system, o.valueQuantity.code AS valueQuantity_code, date_trunc('day', date(from_iso8601_timestamp(o."effectiveDateTime"))) AS effectiveDateTime_day, @@ -354,17 +354,17 @@ WITH temp_observation AS ( date_trunc('year', date(from_iso8601_timestamp(o."effectiveDateTime"))) AS effectiveDateTime_year, odc.code AS observation_code, - odc.code_system AS observation_code_system, + odc.code_system AS observation_system, odcat.code AS category_code, - odcat.code_system AS category_code_system, + odcat.code_system AS category_system, odi.code AS interpretation_code, - odi.code_system AS interpretation_code_system, + odi.code_system AS interpretation_system, odi.display AS interpretation_display, odvcc.code AS valueCodeableConcept_code, - odvcc.code_system AS valueCodeableConcept_code_system, + odvcc.code_system AS valueCodeableConcept_system, odvcc.display AS valueCodeableConcept_display, odda.code AS dataAbsentReason_code, - odda.code_system AS dataAbsentReason_code_system, + odda.code_system AS dataAbsentReason_system, odda.display AS dataAbsentReason_display FROM observation AS o LEFT JOIN core__observation_dn_category AS odcat ON o.id = odcat.id @@ -377,28 +377,28 @@ WITH temp_observation AS ( SELECT id, category_code, - category_code_system, + category_system, status, observation_code, - observation_code_system, + observation_system, interpretation_code, - interpretation_code_system, + interpretation_system, interpretation_display, effectiveDateTime_day, effectiveDateTime_week, effectiveDateTime_month, effectiveDateTime_year, valueCodeableConcept_code, - valueCodeableConcept_code_system, + valueCodeableConcept_system, valueCodeableConcept_display, valueQuantity_value, valueQuantity_comparator, valueQuantity_unit, - valueQuantity_code_system, + valueQuantity_system, valueQuantity_code, valueString, dataAbsentReason_code, - dataAbsentReason_code_system, + dataAbsentReason_system, dataAbsentReason_display, subject_ref, encounter_ref, diff --git a/cumulus_library/studies/core/reference_sql/builder_prereq_tables.sql b/cumulus_library/studies/core/reference_sql/builder_prereq_tables.sql index 05489899..74f78be7 100644 --- a/cumulus_library/studies/core/reference_sql/builder_prereq_tables.sql +++ b/cumulus_library/studies/core/reference_sql/builder_prereq_tables.sql @@ -139,7 +139,7 @@ FROM -- This includes both the expected URI, as well as several found URIs from -- various source systems -CREATE TABLE core__fhir_mapping_code_system_uri AS SELECT * FROM +CREATE TABLE core__fhir_mapping_system_uri AS SELECT * FROM ( VALUES ('ICD10', 'http://hl7.org/fhir/sid/icd-10-cm'), diff --git a/cumulus_library/studies/discovery/code_detection.py b/cumulus_library/studies/discovery/code_detection.py index 111164cc..36bd22fc 100644 --- a/cumulus_library/studies/discovery/code_detection.py +++ b/cumulus_library/studies/discovery/code_detection.py @@ -60,7 +60,7 @@ def prepare_queries( code_source[key] = code_definition[key] code_sources.append(code_source) code_sources = self._check_codes_in_fields(code_sources, config.db) - query = discovery_templates.get_code_system_pairs( + query = discovery_templates.get_system_pairs( "discovery__code_sources", code_sources ) self.queries.append(query) diff --git a/cumulus_library/studies/discovery/discovery_templates/discovery_templates.py b/cumulus_library/studies/discovery/discovery_templates/discovery_templates.py index 05445db6..323a62a7 100644 --- a/cumulus_library/studies/discovery/discovery_templates/discovery_templates.py +++ b/cumulus_library/studies/discovery/discovery_templates/discovery_templates.py @@ -3,7 +3,7 @@ from cumulus_library.template_sql import base_templates -def get_code_system_pairs(output_table_name: str, code_system_tables: list) -> str: +def get_system_pairs(output_table_name: str, code_system_tables: list) -> str: """Extracts code system details as a standalone table""" # Since it's easier to wrangle data before SQL, this code block does diff --git a/docs/core-study-details.md b/docs/core-study-details.md index 78492d6d..f2f9d72c 100644 --- a/docs/core-study-details.md +++ b/docs/core-study-details.md @@ -220,7 +220,7 @@ making sure to include all associated resources. |id |varchar | | |status |varchar | | |type_code |varchar | | -|type_code_system |varchar | | +|type_system |varchar | | |type_display |varchar | | |category_code |varchar | | |docstatus |varchar | | @@ -286,19 +286,19 @@ making sure to include all associated resources. |class_code |varchar(6) | | |class_display |varchar(21)| | |type_code |varchar | | -|type_code_system |varchar | | +|type_system |varchar | | |type_display |varchar | | |servicetype_code |varchar | | -|servicetype_code_system |varchar | | +|servicetype_system |varchar | | |servicetype_display |varchar | | |priority_code |varchar | | -|priority_code_system |varchar | | +|priority_system |varchar | | |priority_display |varchar | | |reasoncode_code |varchar | | -|reasoncode_code_system |varchar | | +|reasoncode_system |varchar | | |reasoncode_display |varchar | | |dischargedisposition_code |varchar | | -|dischargedisposition_code_system|varchar | | +|dischargedisposition_system|varchar | | |dischargedisposition_display |varchar | | |age_at_visit |bigint | | |gender |varchar | | @@ -382,7 +382,7 @@ making sure to include all associated resources. |display|varchar(21)| | -### core__fhir_mapping_code_system_uri +### core__fhir_mapping_system_uri | Column | Type |Description| |-----------|-----------|-----------| @@ -437,9 +437,9 @@ making sure to include all associated resources. |status |varchar| | |intent |varchar| | |category_code |varchar| | -|category_code_system |varchar| | +|category_system |varchar| | |reportedboolean |boolean| | -|medication_code_system|varchar| | +|medication_system|varchar| | |medication_code |varchar| | |medication_display |varchar| | |authoredon |date | | @@ -490,19 +490,19 @@ making sure to include all associated resources. |--------------------------------|-------|-----------| |id |varchar| | |category_code |varchar| | -|category_code_system |varchar| | +|category_system |varchar| | |status |varchar| | |observation_code |varchar| | -|observation_code_system |varchar| | +|observation_system |varchar| | |interpretation_code |varchar| | -|interpretation_code_system |varchar| | +|interpretation_system |varchar| | |interpretation_display |varchar| | |effectivedatetime_day |date | | |effectivedatetime_week |date | | |effectivedatetime_month |date | | |effectivedatetime_year |date | | |valuecodeableconcept_code |varchar| | -|valuecodeableconcept_code_system|varchar| | +|valuecodeableconcept_system|varchar| | |valuecodeableconcept_display |varchar| | |valuequantity_value |double | | |valuequantity_comparator |varchar| | @@ -511,7 +511,7 @@ making sure to include all associated resources. |valuequantity_code |varchar| | |valuestring |varchar| | |dataabsentreason_code |varchar| | -|dataabsentreason_code_system |varchar| | +|dataabsentreason_system |varchar| | |dataabsentreason_display |varchar| | |subject_ref |varchar| | |encounter_ref |varchar| | @@ -574,11 +574,11 @@ making sure to include all associated resources. |--------------------------------|-------|-----------| |id |varchar| | |observation_code |varchar| | -|observation_code_system |varchar| | +|observation_system |varchar| | |category_code |varchar| | -|category_code_system |varchar| | +|category_system |varchar| | |valuecodeableconcept_code |varchar| | -|valuecodeableconcept_code_system|varchar| | +|valuecodeableconcept_system|varchar| | |valuecodeableconcept_display |varchar| | |effectivedatetime_day |date | | |effectivedatetime_week |date | | @@ -596,15 +596,15 @@ making sure to include all associated resources. |--------------------------------|-------|-----------| |id |varchar| | |observation_code |varchar| | -|observation_code_system |varchar| | +|observation_system |varchar| | |category_code |varchar| | -|category_code_system |varchar| | +|category_system |varchar| | |valuecodeableconcept_code |varchar| | -|valuecodeableconcept_code_system|varchar| | +|valuecodeableconcept_system|varchar| | |valuecodeableconcept_display |varchar| | |status |varchar| | |interpretation_code |varchar| | -|interpretation_code_system |varchar| | +|interpretation_system |varchar| | |interpretation_display |varchar| | |effectivedatetime_day |date | | |effectivedatetime_week |date | | diff --git a/tests/test_discovery.py b/tests/test_discovery.py index 252f9760..4bf9540d 100644 --- a/tests/test_discovery.py +++ b/tests/test_discovery.py @@ -69,7 +69,7 @@ def test_discovery(tmp_path): raise e -def test_get_code_system_pairs(): +def test_get_system_pairs(): expected = """CREATE TABLE output_table AS SELECT DISTINCT 'arrays' AS table_name, @@ -118,7 +118,7 @@ def test_get_code_system_pairs(): """ - query = discovery_templates.get_code_system_pairs( + query = discovery_templates.get_system_pairs( "output_table", [ {