Skip to content

Jrlegrand/30/fda data load #56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 14, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions fda_data_reader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import requests, zipfile, io
import pandas as pd
import sqlite3 as sql

#imports functions for downloading data making database
from mdt_functions import zip_downloader, sql_create_table, db_query, read_sql_string


#downloads urrent FDA NDCs.
z = zip_downloader('https://www.accessdata.fda.gov/cder/ndctext.zip')

#moves FDA files to sqlite database by reading as dataframes
product = pd.read_csv(z.open('product.txt'),sep='\t',dtype=object,header=0,encoding='cp1252')
package = pd.read_csv(z.open('package.txt'),sep='\t',dtype=object,header=0,encoding='cp1252')
sql_create_table('product',product)
sql_create_table('package',package)
del product
del package

#deletes FDA ZIP
del z



#NOTE: Rob's python code to join one of these tables with the rxcui_ndc table goes here
"""
rxcui_ndc_string = read_sql_string('rxcui_ndc.sql')
rxcui_ndc = db_query(rxcui_ndc_string)
sql_create_table('rxcui_ndc', rxcui_ndc)
del rxcui_ndc
"""


#TEST!!!!!!!!!!!!!!!! reads record count from created database
product = db_query("Select count(*) AS records from product limit 1")
print('DB table product has {0} records'.format(product['records'].iloc[0]))

package = db_query("Select count(*) AS records from package limit 1")
print('DB table package has {0} records'.format(package['records'].iloc[0]))