@ -1,42 +1,38 @@
/* 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 .
/* OVERVIEW
*
* 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 )
* This links trials to the first date each drug ( indexed by NDA / ANDA etc ) is
* put on the market .
*
* 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
* It takes 3 views to build up to it .
* * /
/*
* 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
- - Match trials to brands and ingredients
create or replace view public . match_trials_to_bn_in 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
rr . tty2 ,
rr . rxcui2 as bn_or_in_cui - - brand or ingredient
, count ( * )
FROM ctgov . browse_interventions bi
INNER JOIN rxnorm_migrated . rxnorm_props AS rp
on bi . downcase_mesh_term = rp . propvalue1 - - Link drug ingredient
left outer JOIN rxnorm_migrated . rxnorm_props AS rp
on bi . downcase_mesh_term = rp . propvalue1 - - link names to drug cuis ( )
left outer join rxnorm_migrated . rxnorm_relations rr
on rr . rxcui1 = rp . rxcui
WHERE
bi . nct_id in (
SELECT nct_id FROM trialncts
)
and
bi . mesh_type = ' mesh-list '
and rp . propname = ' Active_ingredient_name '
and rr . tty2 in ( ' BN ' , ' IN ' , ' MIN ' )
group by bi . nct_id , bi . downcase_mesh_term , rr . tty2 , rr . rxcui2
order by bi . nct_id
;
- - running out of space .
@ -87,42 +83,44 @@ where
- - 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
- - match trials to through brands NDC11
create or replace view public . match_trial_to_ndc11 as
select
mttbi . nct_id ,
ah . ndc ,
count ( * )
from public . match_trials_to_bn_in as mttbi
left outer join rxnorm_migrated . rxnorm_relations as rr
on mttbi . bn_or_in_cui = rr . rxcui1
left outer join rxnorm_migrated . " ALLNDC_HISTORY " as ah
on rr . rxcui2 = ah . rxcui
where
tty1 = ' BN '
rr. tty1 = ' BN '
and
tty2 in ( ' SBD ' , ' BPCK ' )
rr. tty2 in ( ' SBD ' , ' BPCK ' )
and
ah . sab = ' RXNORM '
group by mttbi . nct_id , ah . ndc
order by mttbi . nct_id , ah . ndc
;
- - - 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
- - - associate trials to marketing start dates
create or replace view public . match_trial_to_marketing_start_date as
select
mttn . nct_id ,
n . application_number_or_citation ,
min ( n . marketing_start_date )
from match_trial_to_ndc11 mttn
inner join spl . nsde n
on mttn . ndc = n . package_ndc11
where
product_type = ' HUMAN PRESCRIPTION DRUG '
n . 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 ;
n . marketing_category in ( ' NDA ' , ' ANDA ' , ' BLA ' , ' NDA authorized generic ' , ' NDA AUTHORIZED GENERIC ' )
group by mttn . nct_id , n . application_number_or_citation
order by mttn . nct_id
;