-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrillium_provider_import.py
113 lines (87 loc) · 3.98 KB
/
trillium_provider_import.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import json
import mysql.connector
#######################################################################################
# open mysql connection
#######################################################################################
config = {
'user': 'root',
'password': 'root',
'host': '127.0.0.1',
'database': 'npi',
'raise_on_warnings': False,
}
cnx = mysql.connector.connect(**config)
cursor = cnx.cursor()
file = open("providers_4.8.17.txt",'r')
data = file.readlines()
################
# prep
################
sql0 = 'truncate tchp_providers'
cursor.execute(sql0)
cnx.commit()
sql0 = 'truncate tchp_locations'
cursor.execute(sql0)
cnx.commit()
sql0 = 'truncate tchp_specialties'
cursor.execute(sql0)
cnx.commit()
ii = 0
sql = []
for line in data:
text = data[ii]
json_txt_start = text.find('"providers":')
json_txt_end = text.find(',"queryTime":{')
json_txt2 = text[json_txt_start:json_txt_end]
json_final = json.loads(json_txt2[12:])
x = json.dumps(json_final, indent=4, sort_keys=True)
for i in range(len(json_final)):
val0 = json_final[i]['nationalProviderIdentifiers'][0]['nationalProviderIdentifier']
val1 = json_final[i]['gender']
val2 = json_final[i]['providerName']
val3 = json_final[i]['firstName']
val4 = json_final[i]['middleName']
val5 = json_final[i]['lastName']
val6 = json_final[i]['degree']
sql1 = 'INSERT INTO tchp_providers (NPI, gender, providerName, firstName, middleName, lastName, degree) \
VALUES ("{}", "{}", "{}", "{}", "{}", "{}", "{}")'.format(val0, val1, val2, val3, val4, val5, val6)
if sql1 not in sql:
sql.append(sql1)
for iii in range(len(json_final[i]['networkLocation'])):
#try:
val0 = json_final[i]['nationalProviderIdentifiers'][0]['nationalProviderIdentifier']
val1 = iii+1
val2 = json_final[i]['networkLocation'][iii]['locationName']
val3 = json_final[i]['networkLocation'][iii]['providerOrgName']
val4 = json_final[i]['networkLocation'][iii]['primaryLocInd']
val5 = json_final[i]['networkLocation'][iii]['addressLine1']
val6 = json_final[i]['networkLocation'][iii]['addressLine2']
val7 = json_final[i]['networkLocation'][iii]['cityName']
val8 = json_final[i]['networkLocation'][iii]['stateCode']
val9 = json_final[i]['networkLocation'][iii]['zipCode']
val10 = json_final[i]['networkLocation'][iii]['countyName']
val11 = json_final[i]['networkLocation'][iii]['coordinates']['lat']
val12 = json_final[i]['networkLocation'][iii]['coordinates']['lon']
sql1 = 'INSERT INTO tchp_locations (NPI, location_number, locationName, providerOrgName, locationPrimary, addressLine1, addressLine2, city, state, zip, county, lat, lon) \
VALUES ("{}", "{}", "{}", "{}", "{}", "{}", "{}", "{}", "{}", "{}", "{}", "{}", "{}")'.format(
val0, val1, val2, val3, val4, val5, val6, val7, val8, val9, val10, val11, val12)
if sql1 not in sql:
sql.append(sql1)
for iiii in range(len(json_final[i]['networkLocation'][iii]['specialty'])):
#try:
val0 = json_final[i]['nationalProviderIdentifiers'][0]['nationalProviderIdentifier']
val1 = json_final[i]['networkLocation'][iii]['specialty'][iiii]['fapGrouping']
val2 = json_final[i]['networkLocation'][iii]['specialty'][iiii]['specialtyDesc']
sql1 = 'INSERT INTO tchp_specialties (NPI, specialtyGroup, specialtyDesc) \
VALUES ("{}", "{}", "{}")'.format(
val0, val1, val2)
if sql1 not in sql:
sql.append(sql1)
for int in range(len(sql)):
#print(sql[int])
try:
cursor.execute(sql[int])
except:
continue
cnx.commit()
ii += 1