Skip to content

Commit

Permalink
Merge pull request #20 from smart-on-fhir/mg/additional_rules
Browse files Browse the repository at this point in the history
Additional rules search
  • Loading branch information
dogversioning authored Jul 29, 2024
2 parents 4cf8391 + 6e3531f commit e044069
Show file tree
Hide file tree
Showing 34 changed files with 1,141,905 additions and 4,761 deletions.
1 change: 1 addition & 0 deletions cumulus_library_opioid/manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ study_prefix = "opioid"
file_names = [
"vocab/static_builder.py",
"vocab/rxnorm_vsac_builder.py",
"vocab/additional_rules_builder.py",
]

[sql_config]
Expand Down
116 changes: 116 additions & 0 deletions cumulus_library_opioid/reference_sql/additional_rules_builder.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
-- noqa: disable=all
-- This sql was autogenerated as a reference example using the library
-- CLI. Its format is tied to the specific database it was run against,
-- and it may not be correct for all databases. Use the CLI's build
-- option to derive the best SQL for your dataset.

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

CREATE TABLE opioid__search_rules_descriptions AS
SELECT
e.tty1,
e.rela,
e.tty2,
e.rule,
e.include,
u1.tty_str AS tty1_str,
u2.tty_str AS tty2_str
FROM
opioid__umls_tty as u1,
opioid__umls_tty as u2,
opioid__search_rules as e
WHERE
u1.tty = e.tty1
AND u2.tty = e.tty2

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

CREATE OR REPLACE VIEW opioid__acep_potential_rules AS
SELECT
s.rxcui AS rxcui1,
r.rxcui AS rxcui2,
s.tty AS tty1,
r.tty AS tty2,
s.rui,
s.rel,
s.rela,
s.str AS str1,
r.str AS str2,
r.keyword
FROM opioid__all_rxnconso_keywords AS r,
opioid__acep_rela AS s
WHERE
s.rxcui2 = r.rxcui
AND s.rxcui2 NOT IN (SELECT DISTINCT RXCUI FROM opioid__acep_rxnconso_keywords)

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

CREATE OR REPLACE VIEW opioid__acep_included_rels AS
SELECT
r.rxcui1,
r.rxcui2,
r.tty1,
r.tty2,
r.rui,
r.rel,
r.rela,
r.str1,
r.str2,
r.keyword
FROM opioid__acep_potential_rules AS r,
opioid__search_rules AS e
WHERE
r.REL NOT IN ('RB', 'PAR')
AND e.include = TRUE
AND r.TTY1 = e.TTY1
AND r.TTY2 = e.TTY2
AND r.RELA = e.RELA

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

CREATE OR REPLACE VIEW opioid__acep_included_keywords AS
SELECT
r.rxcui1,
r.rxcui2,
r.tty1,
r.tty2,
r.rui,
r.rel,
r.rela,
r.str1,
r.str2,
r.keyword
FROM opioid__acep_potential_rules AS r
WHERE
r.REL NOT IN ('RB', 'PAR')
AND length(r.keyword) >= 4

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

CREATE TABLE opioid__acep_combined_ruleset AS
SELECT
rxcui1,
rxcui2,
tty1,
tty2,
rui,
rel,
rela,
str1,
str2,
keyword
FROM opioid__acep_included_keywords
UNION
SELECT
rxcui1,
rxcui2,
tty1,
tty2,
rui,
rel,
rela,
str1,
str2,
keyword
FROM opioid__acep_included_rels

88 changes: 88 additions & 0 deletions cumulus_library_opioid/reference_sql/rxnorm_vsac_builder.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
-- noqa: disable=all
-- This sql was autogenerated as a reference example using the library
-- CLI. Its format is tied to the specific database it was run against,
-- and it may not be correct for all databases. Use the CLI's build
-- option to derive the best SQL for your dataset.

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

CREATE OR REPLACE VIEW opioid__acep_rxnconso AS
SELECT
a.rxcui,
a.str,
a.tty,
a.sab,
a.code
FROM rxnorm.rxnconso AS a,
opioid__acep_vsac AS b
WHERE
a.rxcui = b.code

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

CREATE OR REPLACE VIEW opioid__acep_rxnconso_keywords AS
SELECT
a.rxcui,
a.str,
a.tty,
a.sab,
a.code,
b.str AS keyword
FROM opioid__acep_rxnconso AS a,
opioid__keywords AS b
WHERE
lower(a.str) LIKE concat('%',b.STR, '%')

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

CREATE OR REPLACE VIEW opioid__acep_rxnsty AS
SELECT
a.rxcui,
a.tui,
a.stn,
a.sty,
a.atui,
a.cvf
FROM rxnorm.rxnsty AS a,
opioid__acep_vsac AS b
WHERE
a.rxcui = b.code

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

CREATE OR REPLACE VIEW opioid__acep_rxnrel AS
SELECT
a.rxcui1,
a.rxaui1,
a.stype1,
a.rel,
a.rxcui2,
a.rxaui2,
a.stype2,
a.rela,
a.rui,
a.srui,
a.sab,
a.sl,
a.rg
FROM rxnorm.rxnrel AS a,
opioid__acep_vsac AS b
WHERE
a.rxcui1 = b.code

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

CREATE OR REPLACE VIEW opioid__acep_rela AS
SELECT
a.rxcui,
a.str,
a.tty,
a.sab,
b.rxcui2,
b.rel,
b.rela,
b.rui
FROM opioid__acep_rxnconso_keywords AS a,
opioid__acep_RXNREL AS b
WHERE
a.rxcui = b.rxcui1
62 changes: 62 additions & 0 deletions cumulus_library_opioid/reference_sql/static_builder.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
-- noqa: disable=all
-- This sql was autogenerated as a reference example using the library
-- CLI. Its format is tied to the specific database it was run against,
-- and it may not be correct for all databases. Use the CLI's build
-- option to derive the best SQL for your dataset.

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

CREATE EXTERNAL TABLE IF NOT EXISTS `cumulus_mhg_dev_db`.`opioid__keywords` (
STR STRING
)
STORED AS PARQUET
LOCATION 's3://bucketname/path_to_db_storage/opioid/keywords.filtered'
tblproperties ("parquet.compression"="SNAPPY");

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

CREATE EXTERNAL TABLE IF NOT EXISTS `cumulus_mhg_dev_db`.`opioid__all_rxnconso_keywords` (
RXCUI STRING,
STR STRING,
TTY STRING,
SAB STRING,
CODE STRING,
keyword STRING,
keyword_len STRING
)
STORED AS PARQUET
LOCATION 's3://bucketname/path_to_db_storage/opioid/all_rxcui_str.RXNCONSO_curated'
tblproperties ("parquet.compression"="SNAPPY");

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

CREATE EXTERNAL TABLE IF NOT EXISTS `cumulus_mhg_dev_db`.`opioid__search_rules` (
TTY1 STRING,
RELA STRING,
TTY2 STRING,
rule STRING,
include BOOLEAN
)
STORED AS PARQUET
LOCATION 's3://bucketname/path_to_db_storage/opioid/expand_rules'
tblproperties ("parquet.compression"="SNAPPY");

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

CREATE EXTERNAL TABLE IF NOT EXISTS `cumulus_mhg_dev_db`.`opioid__umls_tty` (
TTY STRING,
TTY_STR STRING
)
STORED AS PARQUET
LOCATION 's3://bucketname/path_to_db_storage/opioid/umls_tty'
tblproperties ("parquet.compression"="SNAPPY");

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

CREATE EXTERNAL TABLE IF NOT EXISTS `cumulus_mhg_dev_db`.`opioid__acep_vsac` (
code STRING,
display STRING
)
STORED AS PARQUET
LOCATION 's3://bucketname/path_to_db_storage/opioid/acep'
tblproperties ("parquet.compression"="SNAPPY");
Loading

0 comments on commit e044069

Please sign in to comment.