Skip to content

Commit

Permalink
Merge branch 'dev' into fix/AACT-551-fix_table_exporter_tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Javier-Jimenez-18 committed Oct 12, 2023
2 parents a2f4229 + 35f6b19 commit 1bd2f21
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 4 deletions.
43 changes: 43 additions & 0 deletions app/models/clinical_trials_api_v2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,47 @@ def list_fields(field)
JSON.parse(body)
end

# get all the studies from ctgov
def self.all(days_back: nil)
found = Float::INFINITY
offset = 1
items = []

page_token = nil

loop do
url = "#{BASE_URL_V2}studies?fields=NCTId%2CStudyFirstSubmitDate%2CLastUpdatePostDate&pageSize=1000"
url += "&pageToken=#{page_token}" if page_token

attempts = 0
begin
json_response = JSON.parse(Faraday.get(url).body)
rescue Faraday::ConnectionFailed
attempts += 1
retry if attempts <= 3
rescue JSON::ParserError
attempts += 1
retry if attempts <= 3
end

studies = json_response["studies"]
break if studies.empty?

items.concat(studies.map do |rec|
{
"id" => rec["protocolSection"]["identificationModule"]["nctId"],
"posted" => rec["protocolSection"]["statusModule"]["studyFirstSubmitDate"],
"updated" => rec["protocolSection"]["statusModule"]["lastUpdatePostDateStruct"]["date"]
}
puts rec
end
)


page_token = json_response["nextPageToken"]
break if page_token.nil?
end
puts "Total records received: #{items.size}"
end

end
1 change: 0 additions & 1 deletion app/models/study.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def self.current_interventional
has_one :eligibility, :foreign_key => 'nct_id', :dependent => :delete
has_one :participant_flow, :foreign_key => 'nct_id', :dependent => :delete
has_one :calculated_value, :foreign_key => 'nct_id', :dependent => :delete
has_one :study_xml_record, class_name: "Support::StudyXmlRecord", :foreign_key => 'nct_id'

has_many :search_results, :foreign_key => 'nct_id', :dependent => :delete_all
has_many :baseline_measurements, :foreign_key => 'nct_id', :dependent => :delete_all
Expand Down
3 changes: 1 addition & 2 deletions config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ test:
port: 5432
username: <%= ENV.fetch("AACT_USERNAME", 'aact') %>
password: <%= ENV.fetch("AACT_PASSWORD", '') %>
database: aact_test
schema_search_path: ctgov,support,public
database: acct_test
admin:
<<: *default
host: localhost
Expand Down
1 change: 0 additions & 1 deletion spec/models/study_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
it { should have_one(:eligibility).dependent(:delete) }
it { should have_one(:participant_flow).dependent(:delete) }
it { should have_one(:calculated_value).dependent(:delete) }
it { should have_one(:study_xml_record) }
it { should have_many(:baseline_measurements).dependent(:delete_all) }
it { should have_many(:baseline_counts).dependent(:delete_all) }
it { should have_many(:design_groups).dependent(:delete_all) }
Expand Down

0 comments on commit 1bd2f21

Please sign in to comment.