diff --git a/app/controllers/admin/conditions_controller.rb b/app/controllers/admin/conditions_controller.rb index e85a2b0..6b8bb54 100644 --- a/app/controllers/admin/conditions_controller.rb +++ b/app/controllers/admin/conditions_controller.rb @@ -5,9 +5,6 @@ def recent_as @start_date = (params[:start_date].nil?) ? (DateTime.now - 30.days).strftime('%m/%d/%Y') : params[:start_date] @end_date = (params[:end_date].nil?) ? DateTime.now.strftime('%m/%d/%Y') : params[:end_date] - - #d = params.has_key?('days') ? params[:days].to_i : 30 - #@conditions = StudyFinder::Condition.recent_as(d.days).paginate(page: params[:page]) @conditions = StudyFinder::Condition.find_range(@start_date, @end_date) add_breadcrumb 'Reports' diff --git a/app/controllers/admin/trials_controller.rb b/app/controllers/admin/trials_controller.rb index e0914ae..5db5b5e 100644 --- a/app/controllers/admin/trials_controller.rb +++ b/app/controllers/admin/trials_controller.rb @@ -5,12 +5,6 @@ class Admin::TrialsController < ApplicationController require 'parsers/oncore' def new - # trial = Parsers::Ctgov.new('NCT01794143') - # trial.load - # trial.process - - # raise Parsers::Oncore.new('2003NT036').process.to_yaml - @trial = StudyFinder::Trial.new @systems = ['Ctgov', 'Oncore'] @@ -60,10 +54,22 @@ def review end def recent_as - d = params.has_key?('days') ? params[:days].to_i : 30 - @trials = StudyFinder::Trial.recent_as(d.days).paginate(page: params[:page]) + @start_date = (params[:start_date].nil?) ? (DateTime.now - 30.days).strftime('%m/%d/%Y') : params[:start_date] + @end_date = (params[:end_date].nil?) ? DateTime.now.strftime('%m/%d/%Y') : params[:end_date] + @trials = StudyFinder::Trial.includes(:disease_sites).find_range(@start_date, @end_date) + add_breadcrumb 'Trials Administration' add_breadcrumb 'Recently Added' + + respond_to do |format| + format.html + + format.xls do + response.headers['Content-Type'] = 'application/vnd.ms-excel' + response.headers['Content-Disposition'] = "attachment; filename=\"study_finder_trials_#{DateTime.now}.xls\"" + render "recent_as.xls.erb" + end + end end def index @@ -110,7 +116,11 @@ def update private def trial_params - params.require(:study_finder_trial).permit(:simple_description, :visible, :featured, :recruiting, :contact_override, :contact_override_first_name, :contact_override_last_name, :recruitment_url, :reviewed, :irb_number, site_ids: [], disease_site_ids: []) + params.require(:study_finder_trial).permit( + :simple_description, :visible, + :featured, :recruiting, :contact_override, :cancer_yn, + :contact_override_first_name, :contact_override_last_name, :pi_name, :pi_id, :recruitment_url, + :reviewed, :irb_number, site_ids: [], disease_site_ids: []) end end diff --git a/app/models/study_finder/trial.rb b/app/models/study_finder/trial.rb index 613a498..c84612f 100644 --- a/app/models/study_finder/trial.rb +++ b/app/models/study_finder/trial.rb @@ -35,6 +35,10 @@ def self.import_from_file(file) end end + def self.find_range(start_date, end_date) + where('updated_at between ? and ?', start_date, end_date ).order('updated_at DESC') + end + def display_title display = brief_title unless acronym.nil? @@ -136,6 +140,7 @@ def mesh_terms indexes :max_age, type: 'float' indexes :gender indexes :phase, type: 'string' + indexes :cancer_yn, type: 'string' indexes :visible, type: 'boolean' indexes :healthy_volunteers @@ -143,6 +148,9 @@ def mesh_terms indexes :contact_override_first_name indexes :contact_override_last_name + indexes :pi_name, type: 'string', analyzer: 'en' + indexes :pi_id + indexes :category_ids indexes :keyword_suggest, type: 'completion', analyzer: 'typeahead', search_analyzer: 'typeahead', payloads: false @@ -198,9 +206,12 @@ def as_indexed_json(options={}) :contact_email, :contact_backup_last_name, :contact_backup_email, + :pi_name, + :pi_id, :recruitment_url, :irb_number, :phase, + :cancer_yn, :min_age_unit, :max_age_unit, :featured @@ -273,7 +284,7 @@ def self.match_all_search(search) query_string: { query: search[:q], default_operator: "AND", - fields: ["display_title", "interventions", "conditions_map", "simple_description", "eligibility_criteria", "system_id", "keywords"] + fields: ["display_title", "interventions", "conditions_map", "simple_description", "eligibility_criteria", "system_id", "keywords", "pi_name"] } }, filter: create_filters(search) @@ -301,7 +312,7 @@ def self.match_all_admin(search) multi_match: { query: search[:q], operator: "and", - fields: ["display_title", "interventions", "conditions_map", "simple_description", "eligibility_criteria", "system_id", "keywords"] + fields: ["display_title", "interventions", "conditions_map", "simple_description", "eligibility_criteria", "system_id", "keywords", "pi_name"] } } } diff --git a/app/views/admin/trials/_form.html.haml b/app/views/admin/trials/_form.html.haml index b4cb8cf..11450a8 100644 --- a/app/views/admin/trials/_form.html.haml +++ b/app/views/admin/trials/_form.html.haml @@ -19,6 +19,10 @@ = f.input :irb_number, label: 'IRB Number' = f.input :visible, as: :select = f.input :featured, as: :select, collection: [['No', 0],['Yes', 1]], include_blank: false + = f.input :cancer_yn, as: :select, collection: [['Yes', 'Y'],['No', 'N']], include_blank: true, label: 'Cancer Y/N' + + = f.input :pi_name, label: 'PI Name' + = f.input :pi_id, label: 'PI ID' = f.association :sites, label_method: :site_name, value_method: :id, input_html: { class: 'select2' } = f.association :disease_sites, label_method: :disease_site_label, value_method: :id, input_html: { class: 'select2' } diff --git a/app/views/admin/trials/recent_as.html.haml b/app/views/admin/trials/recent_as.html.haml index c72c782..c93b2ff 100644 --- a/app/views/admin/trials/recent_as.html.haml +++ b/app/views/admin/trials/recent_as.html.haml @@ -2,20 +2,29 @@ .admin .clearfix .pull-left - %h3 Recent Trials - .pull-right - = will_paginate @collection, renderer: BootstrapPagination::Rails + %h3 Recent Trials (#{@trials.size}) %p.description This section is where the administrator can review recently imported trials within StudyFinder. %hr .clearfix - .pull-right - = link_to 'Back to Admin', admin_trials_path, class: 'btn btn-default' + = form_tag admin_trial_recent_as_path, method: :get do |f| + .pull-left.row + .col-md-4 + %label Start Date + %input#start_date.form-control.datepicker{ name: 'start_date', type: 'text', value: @start_date } + .col-md-4 + %label End Date + %input#end_date.form-control.datepicker{ name: 'end_date', type: 'text', value: @end_date } + .col-md-4 + %button.btn.btn-primary{ style: 'margin-top: 25px;'} Filter Trials + .pull-right + = link_to 'Back to Reports', admin_reports_path, class: 'btn btn-default' %table.table.table-bordered.table-trials %thead %tr %th System Id %th Brief Title + %th Disease Sites %th{nowrap: true} Last Updated %tbody - if @trials.empty? @@ -26,6 +35,7 @@ %tr %td= t.system_id %td= t.display_title + %td= t.disease_sites.map { |d| "#{d.disease_site_name}" }.join('; ') %td= t.updated_at.localtime.strftime('%m/%d/%Y') - - = will_paginate @collection, renderer: BootstrapPagination::Rails + + = link_to "Export to Excel", admin_trial_recent_as_path(format: :xls, start_date: params[:start_date], end_date: params[:end_date]), class: 'btn btn-success' diff --git a/app/views/admin/trials/recent_as.xls.erb b/app/views/admin/trials/recent_as.xls.erb new file mode 100644 index 0000000..5b87451 --- /dev/null +++ b/app/views/admin/trials/recent_as.xls.erb @@ -0,0 +1,25 @@ + + + + + + System ID + Brief Title + Disease Sites + Last Updated + + <% @trials.each do |t| %> + + <%= t.system_id %> + <%= t.display_title %> + <%= t.disease_sites.map { |d| "#{d.disease_site_name}" }.join('; ') %> + <%= t.try(:updated_at).strftime('%m/%d/%Y') %> + + <% end %> +
+
+
\ No newline at end of file diff --git a/app/views/studies/index.html.haml b/app/views/studies/index.html.haml index e8cc5b7..2dfa846 100644 --- a/app/views/studies/index.html.haml +++ b/app/views/studies/index.html.haml @@ -86,6 +86,16 @@ - c = determine_contacts(t) = contacts_display(c) + - if t.respond_to?(:pi_name) + .field.important.nomargin + %label.single Principal Investigator: + %strong #{t.pi_name} + + - if t.respond_to?(:pi_id) + .field.important.nomargin + %label.single Principal Investigator ID: + %strong #{t.pi_id} + .field.important.nomargin %label.single Gender: %strong diff --git a/db/migrate/20180126133618_add_cancer_yn_to_study_finder_trials.rb b/db/migrate/20180126133618_add_cancer_yn_to_study_finder_trials.rb new file mode 100644 index 0000000..2fbfc58 --- /dev/null +++ b/db/migrate/20180126133618_add_cancer_yn_to_study_finder_trials.rb @@ -0,0 +1,5 @@ +class AddCancerYnToStudyFinderTrials < ActiveRecord::Migration + def change + add_column :study_finder_trials, :cancer_yn, :string + end +end diff --git a/db/migrate/20180126133905_add_pi_to_study_finder_trials.rb b/db/migrate/20180126133905_add_pi_to_study_finder_trials.rb new file mode 100644 index 0000000..054c745 --- /dev/null +++ b/db/migrate/20180126133905_add_pi_to_study_finder_trials.rb @@ -0,0 +1,6 @@ +class AddPiToStudyFinderTrials < ActiveRecord::Migration + def change + add_column :study_finder_trials, :pi_name, :string + add_column :study_finder_trials, :pi_id, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 0cdeb18..ba37d85 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170220010712) do +ActiveRecord::Schema.define(version: 20180126133905) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -29,11 +29,16 @@ t.datetime "updated_at" end - create_table "study_finder_disease_categories", force: :cascade do |t| - t.string "disease_category_name" + create_table "study_finder_disease_sites", force: :cascade do |t| + t.string "disease_site_name" t.integer "group_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "study_finder_ds_trials", force: :cascade do |t| + t.integer "disease_site_id" + t.integer "trial_id" end create_table "study_finder_groups", force: :cascade do |t| @@ -198,6 +203,9 @@ t.boolean "reviewed", default: false t.integer "featured", default: 0 t.string "irb_number" + t.string "cancer_yn" + t.string "pi_name" + t.string "pi_id" end create_table "study_finder_updaters", force: :cascade do |t|