Skip to content

Commit

Permalink
Update for cumulus_library 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mikix committed Apr 19, 2024
1 parent c7d83f8 commit bc0d587
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 44 deletions.
4 changes: 2 additions & 2 deletions cumulus_library_hypertension/htn/counts.py
Original file line number Diff line number Diff line change
@@ -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..."
Expand Down Expand Up @@ -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'),
Expand Down
36 changes: 18 additions & 18 deletions cumulus_library_hypertension/htn/study_period.sql
Original file line number Diff line number Diff line change
@@ -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)
;
26 changes: 15 additions & 11 deletions cumulus_library_hypertension/htn/table_bp.sql
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,28 @@ 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,
O.subject_ref
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
;

-- #########################################################################
Expand Down
6 changes: 3 additions & 3 deletions cumulus_library_hypertension/htn/table_comorbidity.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions cumulus_library_hypertension/htn/table_dx.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down

0 comments on commit bc0d587

Please sign in to comment.