From bc0d587c7f75511706a25439cc3b2b062ed104d3 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Fri, 19 Apr 2024 16:22:57 -0400 Subject: [PATCH] Update for cumulus_library 2.0 --- cumulus_library_hypertension/htn/counts.py | 4 +-- .../htn/study_period.sql | 36 +++++++++---------- cumulus_library_hypertension/htn/table_bp.sql | 26 ++++++++------ .../htn/table_comorbidity.sql | 6 ++-- cumulus_library_hypertension/htn/table_dx.sql | 12 +++---- pyproject.toml | 8 ++--- 6 files changed, 48 insertions(+), 44 deletions(-) diff --git a/cumulus_library_hypertension/htn/counts.py b/cumulus_library_hypertension/htn/counts.py index c2c053b..580391b 100644 --- a/cumulus_library_hypertension/htn/counts.py +++ b/cumulus_library_hypertension/htn/counts.py @@ -1,5 +1,5 @@ from pathlib import Path -from cumulus_library.schema.counts import CountsBuilder +from cumulus_library.statistics.counts import CountsBuilder class HtnCountsBuilder(CountsBuilder): display_text = "Creating htn counts..." @@ -137,7 +137,7 @@ def count_procedure(self, duration=None): return self.count_encounter(view_name, from_table, cols) - def prepare_queries(self, cursor=None, schema=None): + def prepare_queries(self, *args, **kwargs): self.queries =[ self.count_study_period(), self.count_study_period('month'), diff --git a/cumulus_library_hypertension/htn/study_period.sql b/cumulus_library_hypertension/htn/study_period.sql index 8db0f7f..1113ef9 100644 --- a/cumulus_library_hypertension/htn/study_period.sql +++ b/cumulus_library_hypertension/htn/study_period.sql @@ -1,32 +1,32 @@ CREATE table htn__study_period AS SELECT DISTINCT - e.start_date, - e.start_week, - e.start_month, - e.end_date, + e.period_start_day as start_date, + e.period_start_week as start_week, + e.period_start_month as start_month, + e.period_end_day as end_date, e.age_at_visit, e.status, p.gender, p.race_display, p.ethnicity_display, - e.enc_class_code, - e.enc_class_display, - COALESCE(e.enc_type_system, 'None') as enc_type_system, - COALESCE(e.enc_type_code, 'None') as enc_type_code, - COALESCE(e.enc_type_display, 'None') as enc_type_display, - COALESCE(e.enc_service_system, 'None') as enc_service_system, - COALESCE(e.enc_service_code, 'None') as enc_service_code, - COALESCE(e.enc_service_display, 'None') as enc_service_display, - COALESCE(e.enc_priority_system, 'None') as enc_priority_system, - COALESCE(e.enc_priority_code, 'None') as enc_priority_code, - COALESCE(e.enc_priority_display, 'None') as enc_priority_display, + e.class_code AS enc_class_code, + e.class_display AS enc_class_display, + COALESCE(e.type_code_system, 'None') as enc_type_system, + COALESCE(e.type_code, 'None') as enc_type_code, + COALESCE(e.type_display, 'None') as enc_type_display, + COALESCE(e.serviceType_code_system, 'None') as enc_service_system, + COALESCE(e.serviceType_code, 'None') as enc_service_code, + COALESCE(e.serviceType_display, 'None') as enc_service_display, + COALESCE(e.priority_code_system, 'None') as enc_priority_system, + COALESCE(e.priority_code, 'None') as enc_priority_code, + COALESCE(e.priority_display, 'None') as enc_priority_display, p.subject_ref, e.encounter_ref FROM core__patient AS p, - core__encounter_type AS e + core__encounter AS e WHERE (p.subject_ref = e.subject_ref) - AND (e.start_date BETWEEN date('2016-01-01') AND current_date) - AND (e.end_date BETWEEN date('2016-01-01') AND current_date) + AND (e.period_start_day BETWEEN date('2016-01-01') AND current_date) + AND (e.period_end_day BETWEEN date('2016-01-01') AND current_date) ; \ No newline at end of file diff --git a/cumulus_library_hypertension/htn/table_bp.sql b/cumulus_library_hypertension/htn/table_bp.sql index 0ba1b9a..1d2440a 100644 --- a/cumulus_library_hypertension/htn/table_bp.sql +++ b/cumulus_library_hypertension/htn/table_bp.sql @@ -24,13 +24,12 @@ define_component as (select * from htn__define_bp where component!='panel') select distinct define_component.*, - component_code, - component_part.valueQuantity, - component_part.valueQuantity.value as mmHg, - O.obs_date, - O.obs_week, - O.obs_month, - O.obs_year, + OCC.code as component_code, + OCVQ.value as mmHg, + O.effectiveDateTime_day as obs_date, + O.effectiveDateTime_week as obs_week, + O.effectiveDateTime_month as obs_month, + O.effectiveDateTime_year as obs_year, status, O.observation_ref, O.encounter_ref, @@ -38,10 +37,15 @@ select distinct from define_panel, define_component, core__observation_vital_signs as O, - UNNEST(O.component) t (component_part), - UNNEST(component_part.code.coding) u (component_code) -where define_panel.code = O.obs_code.code -and define_component.code = component_code.code + core__observation_component_code as OCC, + core__observation_component_valuequantity as OCVQ, +where define_panel.code = O.observation_code +and define_panel.system = O.observation_code_system +and define_component.code = OCC.code +and define_component.system = OCC.code_system +and O.id = OCC.id +and O.id = OCVQ.id +and OCC.row = OCVQ.row ; -- ######################################################################### diff --git a/cumulus_library_hypertension/htn/table_comorbidity.sql b/cumulus_library_hypertension/htn/table_comorbidity.sql index 385499a..c5c05f1 100644 --- a/cumulus_library_hypertension/htn/table_comorbidity.sql +++ b/cumulus_library_hypertension/htn/table_comorbidity.sql @@ -13,9 +13,9 @@ WITH condition_row AS c.code AS comorbidity_code, c.code_display as comorbidity_display, fhirspec.code_system as comorbidity_system_display, - c.recorded_month AS comorbidity_month, - c.recorded_week AS comorbidity_week, - c.recordeddate as comorbidity_date + c.recordedDate_month AS comorbidity_month, + c.recordedDate_week AS comorbidity_week, + c.recordedDate as comorbidity_date FROM core__condition AS c, core__fhir_mapping_code_system_uri as fhirspec diff --git a/cumulus_library_hypertension/htn/table_dx.sql b/cumulus_library_hypertension/htn/table_dx.sql index 52bbbeb..8029910 100644 --- a/cumulus_library_hypertension/htn/table_dx.sql +++ b/cumulus_library_hypertension/htn/table_dx.sql @@ -15,9 +15,9 @@ SELECT DISTINCT dx.display as cond_display, fhirspec.uri as cond_system, fhirspec.code_system as cond_system_display, - c.recorded_month AS cond_month, - c.recorded_week AS cond_week, - c.recordeddate as cond_date + c.recordedDate_month AS cond_month, + c.recordedDate_week AS cond_week, + c.recordedDate as cond_date FROM htn__define_dx AS dx, core__fhir_mapping_code_system_uri as fhirspec, @@ -37,9 +37,9 @@ SELECT DISTINCT dx.display as cond_display, fhirspec.uri as cond_system, fhirspec.code_system as cond_system_display, - c.recordeddate as cond_date, - c.recorded_month AS cond_month, - c.recorded_week AS cond_week, + c.recordedDate as cond_date, + c.recordedDate_month AS cond_month, + c.recordedDate_week AS cond_week, s.enc_class_code, s.enc_class_display, s.enc_type_display, diff --git a/pyproject.toml b/pyproject.toml index b8c347b..75d49d9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,10 +1,10 @@ [project] name = "cumulus-library-hypertension" -version = "0.1.3" -requires-python = ">= 3.9" +version = "1.0.0" +requires-python = ">= 3.10" dependencies = [ - "cumulus-library >= 1.4, < 2", - "sqlfluff == 2.0.2" + "cumulus-library >= 2.1, < 3", + "sqlfluff >= 3", ] description = "SQL generation for Cumulus hypertension analysis" readme = "README.md"