def _download_zip(self): """Downloads a zipfile containing the XML files of the search results from ClinicalTrials. """ self.info('Download zip.') t = Trials() result_string = t.download(self.search_string) self.zip_string = StringIO(result_string)
def test_search_method_with_human_readable_kwargs(self): Trials().search(condition='diabetes', intervention='Fluoxetine', recruiting='open') expected_url = ('http://clinicaltrials.gov/' 'search?recr=open&displayxml=true' '&cond=diabetes&intr=Fluoxetine') api.urlopen.assert_called_with(expected_url)
def test_download_method_with_human_readable_kwargs(self): Trials().download(condition='diabetes', intervention='Fluoxetine', recruiting='open', count=150) expected_url = ('http://clinicaltrials.gov/' 'search?count=150&studyxml=true' '&cond=diabetes&intr=Fluoxetine&recr=open') api.urlopen.assert_called_with(expected_url)
def get_state_trials(): # trialsList = TRIALS_LIST # create a clinical trials object for searching t = Trials() trialsList = [] # list to store all 50 state's active clinical trials for index in range(0, len(states_abbrev)): trials = t.search(recruiting='open', count=COUNT, state=states_abbrev[index])['search_results']['clinical_study'] # create a whole number of lists for passing in urls/etc. trialsList.append(trials) # clinical trial object list clinical_meta_list = [] # loop through list of state's trials for i in range(0, len(trialsList)): # Get the corresponding state's trials stateTrials = trialsList[i] # loop through each state's trials for j in range(0, len(stateTrials)): # create a holder for this trial trial = stateTrials[j] if 'intervention_summary' not in trial: continue # Query the trial ID, and state it is in nct_id = trial['nct_id'] state = states_abbrev[i] # sponsor = line url = trial['url'] last_changed = trial['last_changed'] title = trial['title'] condition = trial['condition_summary'] intervention = trial['intervention_summary'] # Create a ClinicalTrial Object to hold relevant data clinical_meta_data = ClinicalTrial(nct_id, None, None, state, url, True, title, condition, intervention, None, last_changed, None, None, None, None) # Add object to a list clinical_meta_list.append(clinical_meta_data) return clinical_meta_list
def get_closed_trials(): t = Trials() clinical_trials = [] for state in states_abbrev: closed_trials = t.search(recruiting='closed', count=COUNT, state=state)['search_results']['clinical_study'] for trial in closed_trials: if 'intervention_summary' not in trial: continue # Get the trial ID, url nct_id = trial['nct_id'] url = trial['url'] title = trial['title'] condition = trial['condition_summary'] intervention = trial['intervention_summary'] last_changed = trial['last_changed'] # Create a ClinicalTrial Object to hold relevant data clinical_trial = ClinicalTrial(nct_id, None, None, state, url, False, title, condition, intervention, None, last_changed, None, None, None, None) # Add object to a list clinical_trials.append(clinical_trial) return clinical_trials
def test_search_method_with_specified_count(self): Trials().search(condition="alzheimer's disease", count=200) expected_url = ('http://clinicaltrials.gov/search?' 'count=200&displayxml=true&cond=alzheimer%27s+disease') api.urlopen.assert_called_with(expected_url)
def test_search_method_with_closed_recruiting_kwarg(self): Trials().search('test', recr='closed') expected_url = ('http://clinicaltrials.gov/' 'search?recr=closed&term=test&displayxml=true') api.urlopen.assert_called_with(expected_url)
def test_search_method_with_human_readable_search_type(self): Trials().search('diabetes', 'condition') expected_url = ('http://clinicaltrials.gov/' 'search?displayxml=true&cond=diabetes') api.urlopen.assert_called_with(expected_url)
def test_search_method_with_search_type_arg(self): Trials().search('test', 'outc') expected_url = ('http://clinicaltrials.gov/' 'search?displayxml=true&outc=test') api.urlopen.assert_called_with(expected_url)
def test_search_method_with_special_characters(self): Trials().search('"foo bar"') expected_url = ('http://clinicaltrials.gov/' 'search?term=%22foo+bar%22&displayxml=true') api.urlopen.assert_called_with(expected_url)
def test_search_method_with_no_output_formatting(self): Trials().search('test', output_format=None) self.assertFalse(api.xml2dict.called)
def test_default_search_method(self): Trials().search('test') expected_url = ('http://clinicaltrials.gov/' 'search?term=test&displayxml=true') api.urlopen.assert_called_with(expected_url)
def test_Trials_class_init(self): trials = Trials() self.assertEquals(trials.base_url, 'http://clinicaltrials.gov') self.assertEquals(trials.output_format, 'xml') self.assertEquals(trials.required_params, {'displayxml': 'true'})
def test_default_download_method(self): Trials().download('test') expected_url = ('http://clinicaltrials.gov/' 'search?term=test&studyxml=true') api.urlopen.assert_called_with(expected_url)
def test_search_method_with_multiple_country_kwargs(self): Trials().search(country='US', country2='CA') expected_url = ('http://clinicaltrials.gov/' 'search?cntry1=NA%3AUS' '&cntry2=NA%3ACA&displayxml=true') api.urlopen.assert_called_with(expected_url)
def test_search_method_with_state_kwarg(self): Trials().search('cancer', state='TX') expected_url = ('http://clinicaltrials.gov/' 'search?state1=NA%3AUS%3ATX' '&displayxml=true&term=cancer') api.urlopen.assert_called_with(expected_url)
def test_search_method_with_country_kwarg(self): Trials().search(condition='diabetes', country='CA') expected_url = ('http://clinicaltrials.gov/' 'search?cntry1=NA%3ACA' '&displayxml=true&cond=diabetes') api.urlopen.assert_called_with(expected_url)
def test_search_method_with_spaces(self): Trials().search('foo bar') expected_url = ('http://clinicaltrials.gov/' 'search?term=foo+bar&displayxml=true') api.urlopen.assert_called_with(expected_url)