-
Notifications
You must be signed in to change notification settings - Fork 0
/
clinical_trials.py
47 lines (40 loc) · 1.94 KB
/
clinical_trials.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
import pandas as pd
import json
import os
path = 'C:/Users/CRS-P-135/Desktop/AllAPIJSON'
NCTID, Sponsor, Study_Country, Phase, Study_date_first, Study_date_last = [], [], [], [], [], []
dir_list = os.listdir(path)
dir_list.remove('Contents.txt')
for dir in dir_list:
json_list = os.listdir(f'{path}/{dir}')
for json_path in json_list:
try :
with open(f'{path}/{dir}/{json_path}') as f:
json_data = json.load(f)
except :
with open(f'{path}/{dir}/{json_path}', encoding = 'utf-8') as f:
json_data = json.load(f)
#NCTID
print(NCTID)
NCTID.append(json_data['FullStudy']['Study']['ProtocolSection']['IdentificationModule']['NCTId'])
#Sponsor
try :
Sponsor.append(json_data['FullStudy']['Study']['ProtocolSection']['SponsorCollaboratorsModule']['LeadSponsor']['LeadSponsorName'])
except KeyError:
Sponsor.append('')
#Study Location_Country
try :
Study_Country.append(json_data['FullStudy']['Study']['ProtocolSection']['ContactsLocationsModule']['LocationList']['Location'][0]['LocationCountry'])
except KeyError:
Study_Country.append('')
#Phase
try :
Phase.append(json_data['FullStudy']['Study']['ProtocolSection']['DesignModule']['PhaseList']['Phase'])
except KeyError:
Phase.append('')
# First_Study_day
Study_date_first.append(json_data['FullStudy']['Study']['ProtocolSection']['StatusModule']['StudyFirstSubmitDate'])
# Last_Study_day
Study_date_last.append(json_data['FullStudy']['Study']['ProtocolSection']['StatusModule']['LastUpdateSubmitDate'])
df = pd.DataFrame(zip(NCTID, Sponsor, Study_Country, Phase, Study_date_first, Study_date_last), columns = ['NCTID', 'Sponsor', 'Study_Country', 'Phase', 'Study_date_first', 'Study_date_last'])
print(df)