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

fix database file #1110

Merged
merged 11 commits into from
Dec 11, 2023
Merged
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
2 changes: 1 addition & 1 deletion app/models/search_result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def study_values
]
end

def hcq_query
def hcq_query(study)
terms = %w[hydroxychloroquine plaquenil hidroxicloroquina quineprox]

columns = [
Expand Down
7 changes: 4 additions & 3 deletions app/models/util/db_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ def initialize(params={})
##### connection management #####

def public_connection
connection = PublicBase.establish_connection(db).connection
connection = PublicBase.connection
connection.schema_search_path = 'ctgov'
connection
end

def staging_connection
connection = PublicBase.establish_connection(db).connection
connection = PublicBase.connection
connection.schema_search_path = 'ctgov'
connection
end
Expand Down Expand Up @@ -167,7 +167,7 @@ def run_command_line(cmd)
return unless status.exitstatus != 0

log stderr
event.add_problem("#{Time.zone.now}: #{stderr}")
event&.add_problem("#{Time.zone.now}: #{stderr}")
false
end

Expand Down Expand Up @@ -245,6 +245,7 @@ def should_keep_index?(index)
end

def migration
ActiveRecord::Migration.verbose = false
@migration ||= ActiveRecord::Migration.new
end

Expand Down
1 change: 1 addition & 0 deletions config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ test:
username: <%= ENV.fetch("AACT_USERNAME", 'aact') %>
password: <%= ENV.fetch("AACT_PASSWORD", '') %>
database: acct_test
schema_search_path: ctgov,support,public
admin:
<<: *default
host: localhost
Expand Down
102 changes: 3 additions & 99 deletions spec/models/baseline_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
it "doesn't create baseline rows for studies that don't have <baseline> tag" do
nct_id='NCT00513591'
xml=Nokogiri::XML(File.read("spec/support/xml_data/#{nct_id}.xml"))
db = Util::DbManager.new
db.remove_indexes_and_constraints

study=Study.new({xml: xml, nct_id: nct_id}).create
expect(study.baseline_population).to eq('')
expect(study.baseline_measurements).to eq([])
Expand Down Expand Up @@ -37,103 +40,4 @@
expect(bm.dispersion_lower_limit).to eq(14)
expect(bm.dispersion_upper_limit).to eq(86)
end

it "study should have expected baseline relationships" do
ResultGroup.destroy_all
BaselineMeasurement.destroy_all
BaselineCount.destroy_all
nct_id='NCT02028676'
xml=Nokogiri::XML(File.read("spec/support/xml_data/#{nct_id}.xml"))
study=Study.new({xml: xml, nct_id: nct_id}).create

expect(ResultGroup.where('result_type=?','Baseline').size).to eq(10)
expect(BaselineMeasurement.count).to eq(380)
expect(BaselineMeasurement.first.nct_id).to eq(nct_id)
expect(BaselineMeasurement.first.result_group.result_type).to eq('Baseline')
expect(BaselineMeasurement.first.result_group.nct_id).to eq(nct_id)
expect(BaselineCount.count).to eq(10)
b10=BaselineCount.where('ctgov_group_code=?','B10').first
expect(b10.nct_id).to eq(nct_id)
expect(b10.count).to eq(3839)
expect(b10.result_group.title).to eq('Total')
expect(b10.result_group.description).to eq('Total of all reporting groups')
expect(b10.scope).to eq('Overall')
expect(b10.units).to eq('Participants')
b3=BaselineCount.where('ctgov_group_code=?','B3').first
expect(b3.nct_id).to eq(nct_id)
expect(b3.count).to eq(397)
expect(b3.scope).to eq('Overall')
expect(b3.units).to eq('Participants')
expect(b3.result_group.title).to eq('Arm A: Abacavir (ABC)+Lamivudine (3TC)+NNRTI')

expect(study.baseline_population).to eq('All participants who were randomized were included except those who were randomised in error (main enrollment: 1 child HIV-uninfected, 2 on main phase of tuberculosis treatment; cotrimoxazole secondary randomization: 2 children receiving dapsone prophylaxis not cotrimoxazole).')
expect(study.baseline_measurements.size).to eq(380);
bm=study.baseline_measurements.select{|x|x.title=='Gender' && x.classification=='Female' && x.ctgov_group_code=='B1'}.first
expect(bm.param_type).to eq('Number');
expect(bm.category).to eq('');
expect(bm.units).to eq('participants');
expect(bm.param_value).to eq('308');
expect(bm.param_value_num).to eq(308);
bm3=study.baseline_measurements.select{|x|x.title=='Gender' && x.classification=='Female' && x.ctgov_group_code=='B3'}.first
expect(bm3.param_type).to eq('Number');
expect(bm3.param_value).to eq('NA');
expect(bm3.param_value_num).to eq(nil);
expect(bm3.explanation_of_na).to eq('Different randomized comparison');
expect(bm3.dispersion_upper_limit).to eq(nil);

counts=BaselineCount.where('nct_id=?',nct_id)
expect(counts.size).to eq(10);
expect(study.baseline_counts.size).to eq(10);
expect(study.baseline_counts.size).to eq(10);
ba1=study.baseline_counts.select{|x|x.units=='Participants' && x.scope=='Overall' && x.ctgov_group_code=='B1'}.first
ba3=study.baseline_counts.select{|x|x.units=='Participants' && x.scope=='Overall' && x.ctgov_group_code=='B3'}.first
expect(ba1.count).to eq(606);
expect(ba3.count).to eq(397);

expect(study.result_groups.select{|x|x.result_type=='Baseline'}.size).to eq(10);
bg1=study.result_groups.select{|x| x.result_type=='Baseline' && x.ctgov_group_code=='B1'}.first
bg10=study.result_groups.select{|x| x.result_type=='Baseline' && x.ctgov_group_code=='B10'}.first

expect(bg1.title).to eq('Clinically Driven Monitoring (CDM)');
expect(bg10.title).to eq('Total')

expect(bg1.description).to eq('Clinically Driven Monitoring (CDM): Participants were examined by a doctor and had routine full blood count with white cell differential, lymphocyte subsets (CD4, CD8), biochemistry tests (bilirubin, urea, creatinine, aspartate aminotransferase, alanine aminotransferase) at screening, randomisation (lymphocytes only), weeks 4, 8, and 12, then every 12 weeks. Screening results were used to assess eligibility. All subsequent results were only returned if requested for clinical management (authorised by centre project leaders); haemoglobin results at week 8 were automatically returned on the basis of early anaemia in a previous adult trial as were grade 4 laboratory toxicities (protocol safety criteria). Total lymphocytes and CD4 tests were never returned for CDM participants, but for all children other investigations (including tests from the routine panels) could be requested and concomitant drugs prescribed, as clinically indicated at extra patient-initiated or scheduled visits.')
expect(bg10.description).to eq('Total of all reporting groups')
end

it "study should have baselines with expected dispersion value" do
xml=Nokogiri::XML(File.read('spec/support/xml_data/NCT02389088.xml'))
nct_id='NCT02389088'
study=Study.new({xml: xml, nct_id: nct_id}).create
baseline_array=study.baseline_measurements.select{|x| x.title=='Age' and x.ctgov_group_code=='B1'}
expect(baseline_array.size).to eq(1)
expect(baseline_array.first.units).to eq('years')
expect(baseline_array.first.param_type).to eq('Mean')
expect(baseline_array.first.param_value).to eq('26')
expect(baseline_array.first.param_value_num).to eq(26)
expect(baseline_array.first.dispersion_value).to eq('1.2')
expect(baseline_array.first.dispersion_value_num).to eq(1.2)
expect(baseline_array.first.dispersion_type).to eq('Standard Deviation')
baseline_array=study.baseline_measurements.select{|x| x.title=='Gender' and x.ctgov_group_code=='B1'}
expect(baseline_array.size).to eq(2)
female_baseline=baseline_array.select{|x|x.classification=='Female'}.first
male_baseline=baseline_array.select{|x|x.classification=='Male'}.first
expect(female_baseline.units).to eq('participants')
expect(female_baseline.param_type).to eq('Number')
expect(female_baseline.param_value).to eq('9')
expect(female_baseline.param_value_num).to eq(9)
expect(female_baseline.result_group.description).to eq('9 PCOS women')

# This is an example of why we might want to dispense with the attempt
# to link all result-type rows to result_group
# There's only 1 gtoup defined for baseline (B1: 9 PCOS women), but both
# Male and Female measurements are associated with group code B1.

expect(male_baseline.units).to eq('participants')
expect(male_baseline.param_type).to eq('Number')
expect(male_baseline.param_value).to eq('0')
expect(male_baseline.param_value_num).to eq(0)
expect(male_baseline.result_group.description).to eq('9 PCOS women')
end

end
115 changes: 0 additions & 115 deletions spec/models/calculated_value_spec.rb
Original file line number Diff line number Diff line change
@@ -1,119 +1,4 @@
require 'rails_helper'

describe CalculatedValue do
it "should not have actual_duration if completion date is 'anticipated'" do
nct_id='NCT00482794'
# this study's primary completion date is 'anticipated'
xml=Nokogiri::XML(File.read("spec/support/xml_data/#{nct_id}.xml"))
study=Study.new({xml: xml, nct_id: nct_id}).create
CalculatedValue.populate
expect(study.completion_date_type).to eq('Anticipated')
cv=study.calculated_value
expect(cv.has_us_facility).to eq(true)
expect(cv.has_single_facility).to eq(true)
expect(cv.actual_duration).to eq(nil)
expect(cv.months_to_report_results).to eq(nil)
expect(cv.were_results_reported).to eq(false)
expect(cv.registered_in_calendar_year).to eq(2007)
expect(study.calculated_value.number_of_primary_outcomes_to_measure.to_i).to eq(1)
expect(study.calculated_value.number_of_secondary_outcomes_to_measure).to be(nil)
expect(study.calculated_value.number_of_other_outcomes_to_measure).to be(nil)
expect(study.calculated_value.minimum_age_num).to be(nil)
expect(study.calculated_value.minimum_age_unit).to be(nil)
expect(study.calculated_value.maximum_age_num).to be(nil)
expect(study.calculated_value.maximum_age_unit).to be(nil)
end

it "should flag study with just a Puerto Rican site as has_us_facility" do
nct_id='NCT03101111'
xml=Nokogiri::XML(File.read("spec/support/xml_data/#{nct_id}.xml"))
study=Study.new({xml: xml, nct_id: nct_id}).create
CalculatedValue.populate
cv=study.calculated_value
expect(study.countries.size).to eq(1) # Make sure it only has one country: Puerto Rico
expect(study.countries.first.name).to eq('Puerto Rico') # Make sure it only has one country: Puerto Rico
expect(cv.has_us_facility).to eq(true)
expect(study.calculated_value.number_of_primary_outcomes_to_measure.to_i).to be(1)
expect(study.calculated_value.number_of_secondary_outcomes_to_measure.to_i).to be(1)
expect(study.calculated_value.number_of_other_outcomes_to_measure.to_i).to be(1)
expect(study.calculated_value.minimum_age_num.to_i).to be(21)
expect(study.calculated_value.minimum_age_unit).to eq('Years')
expect(study.calculated_value.maximum_age_num.to_i).to be(50)
expect(study.calculated_value.maximum_age_unit).to eq('Years')
end

it "should not have actual_duration if completion date is 'anticipated'" do
nct_id='NCT00023673'
# this study's primary completion date is 'actual'
# actual duration: 7/01-1/09 = 7 years & 6 months (91 months)
# months to report: 1/09-2/14 = 5 years & 2 months (62 months)

xml=Nokogiri::XML(File.read("spec/support/xml_data/#{nct_id}.xml"))
study=Study.new({xml: xml, nct_id: nct_id}).create
expect(study.eligibility.gender).to eq('All')

CalculatedValue.populate
expect(study.start_month_year).to eq('July 2001')
expect(study.primary_completion_month_year).to eq('January 2009')
expect(study.primary_completion_date_type).to eq('Actual')
expect(study.results_first_submitted_date.strftime('%m/%d/%Y')).to eq('02/12/2014')
cv=study.calculated_value
expect(cv.were_results_reported).to eq(true)
expect(cv.has_us_facility).to eq(true)
expect(cv.has_single_facility).to eq(false)
expect(cv.actual_duration).to eq(91)
expect(cv.months_to_report_results).to eq(61)
end

it "should set has_us_facility to nil if no facilities provided" do
nct_id='NCT02591810'
xml=Nokogiri::XML(File.read("spec/support/xml_data/#{nct_id}.xml"))
study=Study.new({xml: xml, nct_id: nct_id}).create
CalculatedValue.populate
expect(study.calculated_value.has_us_facility).to eq(nil)
end

it "should set correct calculated values for a set of studies" do
nct_id1='NCT00023673'
nct_id2='NCT02028676'
Study.destroy_all
CalculatedValue.destroy_all
expect(CalculatedValue.count).to eq(0)

xml=Nokogiri::XML(File.read("spec/support/xml_data/#{nct_id1}.xml"))
study1=Study.new({xml: xml, nct_id: nct_id1}).create

xml=Nokogiri::XML(File.read("spec/support/xml_data/#{nct_id2}.xml"))
study2=Study.new({xml: xml, nct_id: nct_id2}).create

CalculatedValue.populate
expect(CalculatedValue.count).to eq(2)

expect(study1.start_month_year).to eq('July 2001')
expect(study1.primary_completion_month_year).to eq('January 2009')
expect(study1.primary_completion_date_type).to eq('Actual')
expect(study1.results_first_submitted_date.strftime('%m/%d/%Y')).to eq('02/12/2014')

cv=study1.calculated_value
expect(cv.were_results_reported).to eq(true)
expect(cv.has_us_facility).to eq(true)
expect(cv.has_single_facility).to eq(false)
expect(cv.actual_duration).to eq(91)
expect(cv.months_to_report_results).to eq(61)

cv=study2.calculated_value
expect(study2.start_month_year).to eq('March 2007')
expect(study2.primary_completion_month_year).to eq('March 2012')
expect(study2.results_first_submitted_date.strftime('%m/%d/%Y')).to eq('01/15/2014')
expect(cv.were_results_reported).to eq(true)
expect(cv.has_us_facility).to eq(false)

expect(cv.has_single_facility).to eq(false)
expect(cv.actual_duration).to eq(60)
expect(cv.months_to_report_results).to eq(21)
expect(cv.number_of_sae_subjects).to eq(773)
expect(cv.number_of_nsae_subjects).to eq(991)

end

end
28 changes: 0 additions & 28 deletions spec/models/central_contact_spec.rb
Original file line number Diff line number Diff line change
@@ -1,32 +1,4 @@
require 'rails_helper'

RSpec.describe CentralContact, type: :model do
context 'when central contact exists' do

it 'should have expected primary contact values' do
CentralContact.destroy_all
nct_id='NCT02830269'
xml=Nokogiri::XML(File.read("spec/support/xml_data/#{nct_id}.xml"))
opts={xml: xml, nct_id: nct_id}
CentralContact.create_all_from(opts)

primary_contacts = CentralContact.where(contact_type: 'primary')
expect(primary_contacts.size).to eq(1)
sample=primary_contacts.first
expect(sample.name).to eq('GERALD CHANQUES, MD, Ph D')
expect(sample.contact_type).to eq('primary')
expect(sample.phone).to eq('+33467337271')
expect(sample.email).to eq('[email protected]')
expect(sample.nct_id).to eq('NCT02830269')

backups = CentralContact.where(contact_type: 'backup')
expect(backups.size).to eq(1)
sample=backups.select{|c| c.name=='Pierre-François PERRIGAULT, MD'}.first
expect(sample.contact_type).to eq('backup')
expect(sample.phone).to eq('+33467337271')
expect(sample.email).to eq('[email protected]')
expect(sample.nct_id).to eq('NCT02830269')
end
end

end
53 changes: 0 additions & 53 deletions spec/models/country_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,8 @@

RSpec.describe Country, type: :model do
context 'when only location_countries exist' do

it 'should return the expected country name' do
Country.destroy_all
nct_id='NCT00513591'
xml=Nokogiri::XML(File.read("spec/support/xml_data/#{nct_id}.xml"))
opts={xml: xml, nct_id: nct_id}
Country.create_all_from(opts)
countries = Country.where('nct_id=?', nct_id)
expect(countries.size).to eq(1)
test_country=countries.first
expect(test_country.name).to eq('United States')
expect(test_country.removed).to eq(nil)
end

it "saves multiple current and removed countries" do
nct_id='NCT01642004'
xml=Nokogiri::XML(File.read("spec/support/xml_data/#{nct_id}.xml"))
study=Study.new({xml: xml, nct_id: nct_id}).create
expect(study.countries.size).to eq(26)
expect(study.countries.select{|x|x.removed==true}.size).to eq(6)
expect(study.countries.select{|x|x.name=='Peru' and x.removed==nil}.size).to eq(1)
expect(study.countries.select{|x|x.name=='Peru' and x.removed==true}.size).to eq(0)
expect(study.countries.select{|x|x.name=='Norway' and x.removed==true}.size).to eq(1)
end

it "has removed country" do
Country.destroy_all
nct_id='NCT02586688'
xml=Nokogiri::XML(File.read("spec/support/xml_data/#{nct_id}.xml"))
opts={xml: xml, nct_id: nct_id}
Country.create_all_from(opts)

all_countries = Country.where('nct_id=?', nct_id)
removed_countries = all_countries.select{|c|c.removed == true}
not_removed_countries = all_countries.select{|c|c.removed != true}

# it should return the expected removed_country name' do
expect(all_countries.size).to eq(2)
expect(removed_countries.size).to eq(1)
expect(not_removed_countries.size).to eq(1)

expect(removed_countries.first.name).to eq('Canada')
expect(not_removed_countries.first.name).to eq('United States')
end

end

context 'when country does not exist' do
it 'should return nothing' do
nct_id='NCT02389088'
xml=Nokogiri::XML(File.read("spec/support/xml_data/#{nct_id}.xml"))
opts={xml: xml, nct_id: nct_id}
Country.create_all_from(opts)
countries = Country.where('nct_id=?', nct_id)
expect(countries.size).to eq(0)
end
end
end
Loading