/*Get relationships between brands and branded drugs and packs*/
select * from rxnorm_migrated.rxnorm_relations rr 
where tty1 = 'BN' and tty2 in ('SBD', 'BPCK')
limit 100;

/*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 every 
 * */
select * from ALLNDC_HISTORY ah 
where RXCUI ='1668240'
and SAB='RXNORM'
;
/** 
 * 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.
 * trial -> mesh_term -> IN/MIN (rxcui) -> BN (rxcui) -> SBD/BPCK (rxcui) -> ndc11 -> nsde (marketing dates)
 * */

/*
 * 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
 */*/