Skip to content
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

Suggestions #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
66 changes: 29 additions & 37 deletions Pull NPI information from site.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,65 +11,57 @@
"""

#Initial packages I will need to create the api request and dump into json
import config
import datetime
import requests
import pandas as pd



ts = datetime.datetime.now().isoformat()

print(ts)

npi_file = "*****************************************m.xls"
npi = pd.read_excel(npi_file, header = None)
#Want to give my column a legible name
npi_file = config.npi_file
npi = pd.read_excel(npi_file, header=None)
#Want to give my column a legible name
npi.columns = ['npi']


#make my empy json to dump information into
#This actually ended up being a nasy list of dicts of discts
npi_json = []



#Making my column names
cols = ['NPI', 'Organization Name', 'zipcode', 'state']
organization_name = pd.DataFrame( columns = cols)
cols = ['NPI', 'Organization Name', 'zipcode', 'state']
organization_name = pd.DataFrame(columns=cols)


#I will iterate thru the entire list and dump them into a csv file
#I will iterate thru the entire list and dump them into a csv file
print("With dataframe :\n npi")
print("\nIterating over rows using index attribute :\n")
for num in npi['npi']:
api = "https://npiregistry.cms.hhs.gov/api/?number="+str(num)+"&enumeration_type=&organization_name=&state=&country_code=&limit=&skip=&version=2.0"
api = "https://npiregistry.cms.hhs.gov/api/?number="+str(num)+"&version=2.0"
pulled_data = requests.get(api)
if pulled_data.status_code == 200:
print("Sucessful Query of API "+ str( num))
print("Sucessful Query of API " + str(num))
source = pulled_data.json()


for key in source.keys():
if key == 'result_count':
continue
elif key == 'Errors':
pass
elif source['result_count'] == 0:
pass


else:
number = source['results'][0]['number']
org_name = source['results'][0]['basic']['name']
zipcode = source['results'][0]['addresses'][1]['postal_code']
state = source['results'][0]['addresses'][1]['state']
organization_name = organization_name.append({'NPI': number, 'Organization Name': org_name, 'zipcode': zipcode, 'state':state}, ignore_index = True)


# Error response
if "Errors" in source:
print("- Recieved error")
continue

# No matches found
if len(source["results"]) == 0:
print("- No matches found")
continue

first_result = source["results"][0]
first_address = first_result["addresses"][0]
org = {
"NPI": first_result["number"],
"Organization Name": first_result["basic"]["name"],
"zipcode": first_address["postal_code"],
"state": first_address["state"]
}
organization_name = organization_name.append(org, ignore_index=True)
else:
print("ERROR CONTACTING API")

organization_name.to_csv(r'**************************)



organization_name.to_csv(config.output_file)
2 changes: 2 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
npi_file = "_____.xls"
output_file = "_____.csv"