You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
129 lines
3.5 KiB
SQL
129 lines
3.5 KiB
SQL
|
|
/*get all the ndc codes associated with an rxcui
|
|
* Same as query
|
|
* http://will-office:4000/REST/rxcui/1668240/allhistoricalndcs.json
|
|
* note the different formats of the dates.
|
|
*
|
|
* Based on http://will-office:4000/RxNav/search?searchBy=RXCUI&searchTerm=1668240
|
|
* it appears that this rxcui is a sbd or bpck (branded drug or pack)
|
|
*
|
|
|
|
* If I grab every brand, then every branded drug or pack associated with that drug and then attach that to the nsde data I would get the marketing dates required.
|
|
* --get brand names
|
|
* trial -> mesh_term -> IN/MIN (rxcui) -> BN (rxcui)
|
|
* -- associate brand names to marketing dates
|
|
* BN (rxcui) --> SBD/BPCK (RXCUI) --> ndc11 --> nsde
|
|
* */
|
|
|
|
/*
|
|
* I do need to figure out a way to change the date types when importing into postgres. In mariadb they ar mmYYYY wheras in the jsonapi they are YYYYmm but I want is YYYY-mm-01
|
|
*/
|
|
|
|
---assoicate ingredients, brands, and approved packaging RXCUIs.
|
|
create temp table tmp_trial_to_ingred as
|
|
with trialncts as (
|
|
SELECT DISTINCT nct_id FROM history.trial_snapshots TS
|
|
)
|
|
SELECT
|
|
bi.nct_id ,
|
|
bi.downcase_mesh_term,
|
|
rp.rxcui AS drug_rxcui
|
|
FROM ctgov.browse_interventions bi
|
|
INNER JOIN rxnorm_migrated.rxnorm_props AS rp
|
|
on bi.downcase_mesh_term = rp.propvalue1 --Link drug ingredient
|
|
WHERE
|
|
bi.nct_id in (
|
|
SELECT nct_id FROM trialncts
|
|
)
|
|
and
|
|
bi.mesh_type='mesh-list'
|
|
;
|
|
--running out of space.
|
|
|
|
-- get list of interventions assoicated with trials of interest
|
|
create temp table tmp_interventions as
|
|
select * from ctgov.browse_interventions bi
|
|
where
|
|
bi.mesh_type ='mesh-list'
|
|
and
|
|
bi.nct_id in (select distinct nct_id from history.trial_snapshots)
|
|
;
|
|
select * from tmp_interventions;
|
|
|
|
--drop table tmp_join_interv_rxcui;
|
|
create temp table tmp_join_interv_rxcui as
|
|
select *
|
|
from
|
|
tmp_interventions tint
|
|
inner join
|
|
rxnorm_migrated.rxnorm_props rp
|
|
on tint.downcase_mesh_term = rp.propvalue1
|
|
where propname='RxNorm Name'
|
|
;-- get the rxcui for ingredients
|
|
|
|
select * from tmp_join_interv_rxcui;
|
|
|
|
--filter rxcui -> is human prescribable
|
|
create temp view tmp_view_prescribable as
|
|
select count(*) from rxnorm_migrated.rxnorm_props rp
|
|
where
|
|
rp.propname = 'PRESCRIBABLE'
|
|
and
|
|
rp.propvalue1 = 'Y'
|
|
;
|
|
|
|
--link prescribable to brand ingredients or brand names.
|
|
|
|
|
|
--get relationships of IN -> BN
|
|
select *
|
|
from
|
|
rxnorm_migrated.rxnorm_relations rr
|
|
where
|
|
rr.tty1 in ('IN','MIN')
|
|
and rr.rxcui1 in (select distinct rxcui from tmp_join_interv_rxcui tjir)
|
|
and rr.tty2 = 'BN'
|
|
;
|
|
|
|
|
|
|
|
--link brand names to drug applications (NDA/ANDA etc)
|
|
select rr.rxcui1 as BN, rr.rxcui2 as pack, ah.ndc as pack_ndc11
|
|
from
|
|
rxnorm_migrated.rxnorm_relations rr
|
|
left outer join rxnorm_migrated."ALLNDC_HISTORY" as ah
|
|
on rr.rxcui2 = ah.rxcui
|
|
where
|
|
tty1 = 'BN'
|
|
and
|
|
tty2 in ('SBD', 'BPCK')
|
|
and
|
|
ah.sab='RXNORM'
|
|
|
|
;
|
|
|
|
|
|
---associate NDAs/ANDAs to marketing start dates
|
|
---Get start of coverage periods for NSDE dates grouped by arbitrary grouping.
|
|
SELECT n.application_number_or_citation, count(*), min( marketing_start_date )
|
|
FROM spl.nsde as n
|
|
where product_type = 'HUMAN PRESCRIPTION DRUG'
|
|
group by n.application_number_or_citation ;
|
|
|
|
|
|
---For a given date, find which NDAs/ANDAs were active were active.
|
|
SELECT n.application_number_or_citation, count(*)
|
|
FROM spl.nsde as n
|
|
where
|
|
product_type = 'HUMAN PRESCRIPTION DRUG'
|
|
and
|
|
marketing_start_date < '2010-05-01'
|
|
and
|
|
marketing_end_date > '2010-05-01'
|
|
group by n.application_number_or_citation ;
|
|
|
|
|
|
|
|
|
|
|