From 137e13ad1ba2d70c6619efed49f57b24d78b44ae Mon Sep 17 00:00:00 2001 From: Bohung Date: Wed, 26 Jan 2022 14:05:57 +0800 Subject: [PATCH] Finish version 2.(lpv calculation is editable) --- app/assets/javascripts/cancer_predict.js | 372 +++++++------ app/assets/stylesheets/cancer_predict.scss | 6 +- .../stylesheets/cancer_predict_print.scss | 99 ++-- .../admin/cancerpredicts_controller.rb | 240 +++++++-- app/controllers/cancerpredicts_controller.rb | 245 ++++----- app/models/cancer_predict_mapping_file.rb | 12 + app/models/cancerpredictfields.rb | 495 +++++++++++++++-- app/models/cancerpredictrecord.rb | 6 +- .../_export_cancer_tool_record.xlsx.axlsx | 5 +- app/views/admin/cancerpredicts/_form.html.erb | 509 ++---------------- .../admin/cancerpredicts/_form_file.html.erb | 56 +- app/views/admin/cancerpredicts/index.html.erb | 314 +++++++++-- .../admin/cancerpredicts/showSubmit.html.erb | 2 +- cancerpredict.gemspec | 63 +-- config/locales/en.yml | 17 +- config/locales/zh_tw.yml | 31 +- config/routes.rb | 9 +- .../cancer_predict_index.html.erb | 4 +- 18 files changed, 1410 insertions(+), 1075 deletions(-) create mode 100644 app/models/cancer_predict_mapping_file.rb diff --git a/app/assets/javascripts/cancer_predict.js b/app/assets/javascripts/cancer_predict.js index 52355d5..96ae867 100644 --- a/app/assets/javascripts/cancer_predict.js +++ b/app/assets/javascripts/cancer_predict.js @@ -1,3 +1,39 @@ +Array.prototype.get_nearest_value = function(goal){ + var nearest_value = this.reduce(function(prev, curr) { + return (Math.abs(curr - goal) < Math.abs(prev - goal) ? curr : prev); + }); + return nearest_value; +} +function change_object_variables(obj1,obj2,operator="-",target="new"){ + var obj_new = {}; + var obj_keys = Object.keys(obj1); + obj_keys.forEach(function(k){ + if(obj2[k] == undefined){ + if( target == "new"){ + obj_new[k] = obj1[k]; + } + }else{ + if(operator == "-"){ + if( target == "new"){ + obj_new[k] = obj1[k] - obj2[k]; + }else{ + obj1[k] = obj1[k] - obj2[k]; + } + }else if(operator == "+"){ + if( target == "new"){ + obj_new[k] = obj1[k] + obj2[k]; + }else{ + obj1[k] = obj1[k] + obj2[k]; + } + } + } + }) + if( target == "new"){ + return obj_new; + }else{ + return obj1; + } +} $(document).ready(function(){ var head_data = $.post("/cancerpredictResult",{"header":1,locale:I18n.locale}); var data = {}; @@ -15,15 +51,21 @@ $(document).ready(function(){ $('#cancer_table .cencer_table_name').css('max-width','39%'); }; }; - function round(num,Digit){ + function round(num,Digit=0){ return Math.round(Number(num)*(10**Digit))/(10**Digit); }; head_data.done(function(){ - $('.header-nav').html(head_data.responseJSON['head_images']); - $('.navbar-brand').html(head_data.responseJSON['title']); + // $('.header-nav').html(head_images.responseJSON['head_images']); + // $('.navbar-brand').html(head_images.responseJSON['title']) data['danger_texts'] = head_data.responseJSON['danger_texts']; $('head title').text(head_data.responseJSON['page_title']) }); + var mapping_data = $.post("/cancerpredictResult",{"get_mapping_data_from_csv":1,locale:I18n.locale}); + mapping_data.done(function(){ + // $('.header-nav').html(head_images.responseJSON['head_images']); + // $('.navbar-brand').html(head_images.responseJSON['title']) + window.mapping_data_from_csv = mapping_data.responseJSON['mapping_data_from_csv']; + }); Array.prototype.remove_item_from_array = function(){ var result_array = this; for(var i=0;iinput').eq(0).attr('value',"1"); }; - var treatmeny_method = result.responseJSON.treatmeny_method; - $('tr.'+treatmeny_method[0]).addClass('tr_show') - var lpv = [0,-0.8397,-0.4147,-0.3203,-0.4687]; + var treatment_method = result.responseJSON.treatment_method; + var treatment_method_active_indices = result.responseJSON.treatment_method_active_indices; + $('tr.'+treatment_method[0]).addClass('tr_show'); var servive_ratio_arr = [result.responseJSON.servive_ratio] var yes = (I18n.locale=="zh_tw") ? "是" : "yes"; var year = $('#current_year').attr('value'); var active_treatment = ['Surgery_only']; $('tr.'+active_treatment[0]+' .Overall_Survival').html(servive_ratio_arr[0]+'%'); + $('span.'+active_treatment[0]+'.Overall_Survival').html(Math.round(servive_ratio_arr[0])); $('#cancer_predict_result_block').css('display','block'); - var lpv_real = [result.responseJSON['lpv']]; - var lpv_dict={} - var lpv_calc={1:-0.001476145,3:-0.01261639,5:-0.02519608} + var lpv_real = [result.responseJSON['lpv_variable']]; + var lpv = /*therapy_lpv start*/[0, -0.8397, -0.4147, -0.3203, -0.4687];/*therapy_lpv end*/; + var lpv_dict={}; + var lpv_calc=/*lpv_calc_formula_start*/{"1":"Math.exp(-0.001476145)**( Math.exp(lpv_current) )","3":"Math.exp(-0.01261639)**( Math.exp(lpv_current) )","5":"Math.exp(-0.02519608)**( Math.exp(lpv_current) )"};/*lpv_calc_formula_end*/ active_treatment.push = function() { if(arguments.length == 1){ var year = $('#current_year').attr('value'); - var lpv_current = lpv_real[lpv_real.length-1]+lpv_dict[arguments[0]]; + console.log(lpv_real); + console.log(lpv_dict[arguments[0]]) + var lpv_current = change_object_variables(lpv_real[lpv_real.length-1],{"lpv": lpv_dict[arguments[0]]},'+'); lpv_real.push(lpv_current); - var servive_ratio = round((Math.exp(lpv_calc[year])**Math.exp(lpv_current))*100,2); + lpv_current = lpv_current['lpv']; + var servive_ratio = round(eval(lpv_calc[year])*100,2); var benefit = servive_ratio - servive_ratio_arr[servive_ratio_arr.length - 1]; servive_ratio_arr.push(servive_ratio); $('tr.'+arguments[0]+' td.Overall_Survival').html(servive_ratio+'%'); @@ -398,8 +454,10 @@ $(document).ready(function(){ var year = $('#current_year').attr('value'); if(index < this.length - 1){ for(var i = index + 1;i < this.length; i++){ - lpv_real[i] -= lpv_dict[arguments[0]]; - var servive_ratio = round((Math.exp(lpv_calc[year])**Math.exp(lpv_real[i]))*100,2); + change_object_variables(lpv_real[i] , {"lpv": lpv_dict[arguments[0]]} , '-' , 'self'); + var lpv_current = lpv_real[i]; + lpv_current = lpv_current['lpv']; + var servive_ratio = round(eval(lpv_calc[year])*100,2); servive_ratio_arr[i] = servive_ratio; var benefit = servive_ratio - ((i == index+1) ? servive_ratio_arr[index - 1] : servive_ratio_arr[i - 1]); $('tr.'+active_treatment[i]+' td.Overall_Survival').html(servive_ratio+'%'); @@ -435,39 +493,15 @@ $(document).ready(function(){ $('.addition').css('display','none'); $('#result_text_content .extra-text').css('display','none'); }; - console.log(this) return Array.prototype.remove_item_from_array.apply(this, arguments); }else{ - console.log(this) return Array.prototype.remove_item_from_array.apply(this, arguments); }; }; - for(var i = 0;iinput').attr('value',0); - $(this).parent().find('>input').eq(index).attr('value',1); - $(this).parent().find('>button').removeClass('active'); - $(this).parent().removeClass('cancertable_empty'); - if($('.cancertable_empty').length == 0){ - $('#danger_texts').remove(); - }; - }catch(e){}; - $(this).addClass('active'); - if(!click_flag){ - if(!active_treatment.includes($(this).parent().attr('id'))){ - click_flag = true; - active_treatment.push($(this).parent().attr('id')); - click_flag = false; - }; - } - }); - $('#'+treatmeny_method[i]+' .cancer_table_btn').eq(0).off('click'); - $('#'+treatmeny_method[i]+' .cancer_table_btn').eq(0).click(function(){ + $('#'+treatment_method[i]+' .cancer_table_btn').off('click').click(function(){ var index = $(this).index()/2; try{ $(this).parent().find('>input').attr('value',0); @@ -487,6 +521,26 @@ $(document).ready(function(){ }; }; }); + $('#'+treatment_method[i]+' .cancer_table_btn').eq(treatment_method_active_indices[i]).off('click').click(function(){ + var index = $(this).index()/2; + try{ + $(this).parent().find('>input').attr('value',0); + $(this).parent().find('>input').eq(index).attr('value',1); + $(this).parent().find('>button').removeClass('active'); + $(this).parent().removeClass('cancertable_empty'); + if($('.cancertable_empty').length == 0){ + $('#danger_texts').remove(); + }; + }catch(e){}; + $(this).addClass('active'); + if(!click_flag){ + if(!active_treatment.includes($(this).parent().attr('id'))){ + click_flag = true; + active_treatment.push($(this).parent().attr('id')); + click_flag = false; + }; + } + }); }; $('#current_year').change(function(){ year = $(this).attr('value'); @@ -546,123 +600,119 @@ $(document).ready(function(){ }); }; }; - function calculate_and_change_result_value(obj){ - obj.servive_ratio_arr = []; - for(var i = 0;i(original_value+new_lpv-old_lpv)); + obj.lpv_real = obj.lpv_real.map(original_value=>(change_object_variables(original_value,change_object_variables(new_lpv,old_lpv,'-'),'+'))); calculate_and_change_result_value(obj); }; }; - function calculate_first_lpv(result_json){ - result = {} - result['age1'] = Math.pow((Number(result_json['age'])/100),0.5); - result['age2'] = Math.pow((Number(result_json['age'])/100),0.5)*Math.log(result_json['age']/100); - result['size1'] = Math.log(Number(result_json['size'])/10); - if(Number(result_json['lymph_nodes_examined']) != 0) - try{result['ratio'] = Number(result_json['lymph_nodes_positive'])/Number(result_json['lymph_nodes_examined'])}catch(e){result['ratio'] = 0} - else - result['ratio'] = 0 - if(result['ratio'] > 1) - result['ratio'] = 1 - result['nposit'] = Math.pow(((Number(result['ratio'])+0.1)/0.1),0.5); - var T = ''; - if(Number(result_json['tumor_direct_extension']) != 1){ - if(Number(result_json['size']) <= 20) - T = 'T1'; - else if(Number(result_json['size']) > 20 && Number(result_json['size']) <= 50) - T = 'T2'; - else if(Number(result_json['size']) > 50) - T = 'T3'; - }else{ - T = 'T4'; - }; - var N = ''; - if(Number(result_json['lymph_nodes_positive']) == 0) - N = 'N0'; - else if(Number(result_json['lymph_nodes_positive']) >= 1 && Number(result_json['lymph_nodes_positive']) <= 3 && Number(result_json['micrometastasis']) != 1) - N = 'N1'; - else if(Number(result_json['lymph_nodes_positive']) >= 1 && Number(result_json['lymph_nodes_positive']) <= 3 && Number(result_json['micrometastasis']) == 1) - N = 'N1mi'; - else if(Number(result_json['lymph_nodes_positive']) >= 4 && Number(result_json['lymph_nodes_positive']) <= 9) - N = 'N2'; - else if(Number(result_json['lymph_nodes_positive']) >= 10) - N = 'N3'; - M = ''; - if(Number(result_json['Distant_Metastasis']) != 1) - M = 'M0'; - else - M = 'M1'; - if(Number(M == 'M0')) - if(T == 'T1' && (N == 'N0' || N == 'N1mi')) - result['pstage'] = 1; - else if(((T == 'T2' || T == 'T3') && (N == 'N0')) || ((T == 'T1' || T == 'T2') && (N == 'N1'))) - result['pstage'] = 2; - else if((T == 'T4' && N == 'N0') || ((T == 'T3' || T == 'T4') && N == 'N1') || (N == 'N2' || N == 'N3')) - result['pstage'] = 3; - else - result['pstage'] = 4 - if((Number(result_json['ER_status']) != 2 || Number(result_json['PR_status']) != 2) && (Number(result_json['HER2_status']) != 1)) - result['subtype'] = 1; - else if(Number(result_json['HER2_status']) == 1) - result['subtype'] = 2; - else if(Number(result_json['ER_status']) == 2 && Number(result_json['PR_status']) == 2 && (Number(result_json['HER2_status']) != 1)) - result['subtype'] = 3; - if( Number(result_json['grade']) == 2 || Number(result_json['grade']) == 4) - result['grade_2'] = 1; - else - result['grade_2'] = 0; - if( Number(result_json['grade']) == 3) - result['grade_3'] = 1; - else - result['grade_3'] = 0; - if( Number(result['subtype']) == 2) - result['subtype_HER2'] = 1; - else - result['subtype_HER2'] = 0; - if( Number(result['subtype']) == 3) - result['subtype_triple'] = 1; - else - result['subtype_triple'] = 0; - if( Number(result['pstage']) == 2) - result['pstage_2'] = 1; - else - result['pstage_2'] = 0; - if( Number(result['pstage']) == 3) - result['pstage_3'] = 1; - else - result['pstage_3'] = 0; - if( Number(result['pstage']) == 4) - result['pstage_4'] = 1; - else - result['pstage_4'] = 0; - if( Number(result_json['lvi']) == 1) - result['lvi_yes'] = 1; - else - result['lvi_yes'] = 0; - try{ - result['lpv'] = ((result['age1']-0.7276655)*(-10.87)+(result['age2']+0.4540707)*8.968+(result['size1']-0.643632)*0.7678+(result['nposit']-1.346932)*0.5339+ - result['grade_2']*0.4795+result['grade_3']*0.818+result['subtype_HER2']*0.1806+result['subtype_triple']*0.6457+result['pstage_2']*0.5311+ - result['pstage_3']*1.134+result['pstage_4']*2.172+result['lvi_yes']*0.3321-0.04); - }catch(e){result['lpv'] = "error"}; - return result; - }; + /* auto add start */ + function calculate_first_lpv(result_json){ + result = {}; + var map_values , mapping_hash , temp_index ,temp_value , index , closest_value; + result['age'] = Number(result_json['age']); + result['size'] = Number(result_json['size']); + result['lymph_nodes_examined'] = Number(result_json['lymph_nodes_examined']); + result['lymph_nodes_positive'] = Number(result_json['lymph_nodes_positive']); + result['grade'] = Number(result_json['grade']); + result['ER_status'] = Number(result_json['ER_status']); + result['PR_status'] = Number(result_json['PR_status']); + result['HER2_status'] = Number(result_json['HER2_status']); + result['Distant_Metastasis'] = Number(result_json['Distant_Metastasis']); + result['micrometastasis'] = Number(result_json['micrometastasis']); + result['tumor_direct_extension'] = Number(result_json['tumor_direct_extension']); + result['lvi'] = Number(result_json['lvi']); + result['hormone_therapy'] = Number(result_json['hormone_therapy']); + result['Chemotherapy'] = Number(result_json['Chemotherapy']); + result['Radiotherapy'] = Number(result_json['Radiotherapy']); + result['Targeted_therapy'] = Number(result_json['Targeted_therapy']); + + Object.keys(result).forEach(function(k){ + if(Number.isNaN(result[k])){ + result[k] = 0; + } + }) + age1 = (result["age"] / 100.0) ** (0.5); + age2 = age1 * Math.log(result["age"] / 100.0); + size1 = Math.log(result["size"] / 10.0); + ratio = (result["lymph_nodes_examined"] == 0 ? 0 : (1.0 * result["lymph_nodes_positive"] / result["lymph_nodes_examined"])); + ratio = (ratio > 1 ? 1 : ratio); + T4 = (result["tumor_direct_extension"] == 1); + T1 = !T4 && (result["size"] <= 20); + T2 = !T4 && !T1 && (result["size"] > 20 && result["size"] <= 50); + T = (T4 ? 'T4' : (T1 ? 'T1' : (T2 ? 'T2' : 'T3'))); + N0 = (result["lymph_nodes_positive"] == 0); + N1_or_N1mi = !N0 && (result["lymph_nodes_positive"] >= 1 && result["lymph_nodes_positive"] <= 3); + N1 = N1_or_N1mi && result["micrometastasis"] != 1; + N1mi = N1_or_N1mi && result["micrometastasis"] == 1; + N2 = !N0 && !N1_or_N1mi && (result["lymph_nodes_positive"] <= 9); + N = (N0 ? 'N0' : (N1 ? 'N1' : (N1mi ? 'N1mi' : (N2 ? 'N2' : 'N3')))); + M = (result["Distant_Metastasis"] != 1) ? 'M0' : 'M1'; + pstage = (M == 'M1' ? 4 : ((T == 'T1' && (N == 'N0' || N == 'N1mi')) ? 1 : (((T == 'T2' || T == 'T3') && (N == 'N0')) || ((T == 'T1' || T == 'T2') && (N == 'N1')) ? 2 : 3)) ); + nposit = ((ratio + 0.1) / 0.1) ** 0.5; + grade_2 = (result["grade"] == 2 || result["grade"] == 4) ? 1 : 0; + grade_3 = (result["grade"] == 3) ? 1 : 0; + subtype_1 = (result["ER_status"] != 2 || result["PR_status"] != 2) && (result["HER2_status"] != 1); + subtype_2 = !subtype_1 && (result["HER2_status"] == 1); + subtype_3 = !subtype_1 && !subtype_2 && (result["ER_status"] == 2 && result["PR_status"] == 2 && result["HER2_status"] != 1); + subtype_HER2 = subtype_2 ? 1 : 0; + subtype_triple = subtype_3 ? 1 : 0; + pstage_2 = (pstage == 2) ? 1 : 0; + pstage_3 = (pstage == 3) ? 1 : 0; + pstage_4 = (pstage == 4) ? 1 : 0; + lvi_yes = (result["lvi"] == 1) ? 1 : 0; + chemo = (result["Chemotherapy"] == 2) ? 1 : 0; + radio = (result["Radiotherapy"] == 2) ? 1 : 0; + hormone = (result["hormone_therapy"] == 2) ? 1 : 0; + target = (result["Targeted_therapy"] == 2) ? 1 : 0; + try{ + lpv = ((age1-0.7276655)*(-10.87)+(age2+0.4540707)*8.968+(size1-0.643632)*0.7678+(nposit-1.346932)*0.5339+ grade_2*0.4795+grade_3*0.818+subtype_HER2*0.1806+subtype_triple*0.6457+pstage_2*0.5311+ pstage_3*1.134+pstage_4*2.172+lvi_yes*0.3321-0.04+chemo*(-0.4147)+radio*(-0.3203)+hormone*(-0.8397)+target*(-0.4687) + ) + }catch(e){console.log(e)}; + result['lpv_variable'] = {}; + result['lpv_variable']['lpv'] = lpv; + result['lpv'] = lpv; + result['lpv_variable']['lpv'] = result['lpv']; + return result; + }; + function calculate_and_change_result_value(obj){ + obj.servive_ratio_arr = []; + for(var i = 0;i a{ - writing-mode: vertical-lr; - -webkit-writing-mode: vertical-lr; - color: white; + writing-mode: vertical-lr !important; + -webkit-writing-mode: vertical-lr !important; + color: white !important; } .result_tab_group{ - width: 15%; - margin: 0; - float: left; + display: none; } .result_content_group{ - width: 85%; + width: 100%; margin: 0; - float: right; + float: none; } .result_content{ - display: none; + display: block; min-height: 25em; - border: 0.125em solid #c0cbdd; + border: 0.125em solid #c0cbdd !important; padding: 0.5em; } .result_content:first-of-type{ @@ -315,13 +322,13 @@ input.float_num{ color:white; } .cancer_th{ - color: white; - background-color: #003d79; + color: white !important; + background-color: #003d79 !important; border-right: 0.375em solid white; border-top: 0.375em solid white; } .cancer_td { - background-color: #e9eaf5; + background-color: #e9eaf5 !important; border-right: 0.375em solid white; border-top: 0.375em solid white; } @@ -362,30 +369,32 @@ div.texts_show{ width: 80%; } #cancer_table_right{ -float:right; -width:50%; + float:right; + width:50%; } #cancer_table_left{ -float:left; -width:50%; + float:left; + width:50%; } #cancer_table_right_result{ -width: 50%; -float: right; + width: 50%; + float: right; } #cancer_table_left_result{ -width: 50%; -float: left; + width: 50%; + float: left; } #cancer_predict_result{ -width: 50%; -float: left; + width: 50%; + float: left; } .result_title{ -margin-top: 1em; + margin-top: 1em; +} +* { + -webkit-print-color-adjust: exact !important; +} +.layout-content{ + background: #fff !important; } -@media print { - * { - -webkit-print-color-adjust: exact !important; - } } \ No newline at end of file diff --git a/app/controllers/admin/cancerpredicts_controller.rb b/app/controllers/admin/cancerpredicts_controller.rb index cc6daf2..46bc929 100644 --- a/app/controllers/admin/cancerpredicts_controller.rb +++ b/app/controllers/admin/cancerpredicts_controller.rb @@ -4,6 +4,7 @@ class Admin::CancerpredictsController < OrbitAdminController require 'rubyXL' require 'fileutils' require "axlsx" + require "csv" #include Admin::CancerpredictsHelper before_action ->(module_app = @app_title) { set_variables module_app } before_action :create_first_field @@ -26,14 +27,53 @@ class Admin::CancerpredictsController < OrbitAdminController @title_images_id.each{|image_id| @title_images.push Headimages.find_by(:id=>image_id.to_s)} rescue nil @head_new_image = Headimages.new(:cancerpredictfields_id => @form_to_show.id) end - def edit - if !(params["cancerpredictfields"].nil?) + def edit + other_in_use_locales = Site.first.in_use_locales.map{|l| l.to_s} + other_in_use_locales.delete(params[:locale]) + if !(params["cancerpredictfields"].nil?) + org_nums = @form_to_show.form_show_was.keys + remain_org_nums = params["cancerpredictfields"]["form_show"].values.map{|property| property["old_num"]}.select{|n| n.present?} + delete_nums = org_nums - remain_org_nums + if !delete_nums.blank? + delete_nums.each do |delete_num| + @form_to_show.form_show.delete(delete_num) + end + end params["cancerpredictfields"]["form_show"].each do |num,property| property.each do |key,value| - if value != "0" && value != "1" + if key.include?("_file") && (!value[:temp_file].blank? rescue false) + if value[:id].nil? + mapping_file = CancerPredictMappingFile.create(value) + else + mapping_file = CancerPredictMappingFile.find(value[:id]) + mapping_file.temp_file = value[:temp_file] + mapping_file.save + end + @form_to_show.form_show[num.to_s][key.to_s] = mapping_file.id + elsif key.include?("_file") + if value[:_destroy] == "1" + mapping_file = CancerPredictMappingFile.find(value[:id]) + mapping_file.destroy + @form_to_show.form_show[num.to_s][key.to_s] = "" + end + end + next if key.include?("_file") + if (key != "old_num") if key != params[:locale] - if @form_to_show.form_show[num.to_s][key.to_s].class != Array - @form_to_show.form_show[num.to_s][key.to_s] = value + @form_to_show.form_show[num.to_s] = {} if @form_to_show.form_show[num.to_s].nil? + type = Cancerpredictfields::FIELDINFO[key.to_s] + if type && Cancerpredictfields::Field_relations[type] + type = Cancerpredictfields::Field_relations[type] + end + type = type.constantize rescue String + if @form_to_show.form_show[num.to_s][key.to_s].class != Array && type != Array + if type == Fixnum + @form_to_show.form_show[num.to_s][key.to_s] = value.to_i rescue 0 + elsif type == Float + @form_to_show.form_show[num.to_s][key.to_s] = value.to_f rescue 0.0 + else + @form_to_show.form_show[num.to_s][key.to_s] = value + end else if value.length > 2 @form_to_show.form_show[num.to_s][key.to_s] = YAML.load(value) @@ -43,8 +83,20 @@ class Admin::CancerpredictsController < OrbitAdminController end else value.each do |sub_property,sub_value| - if @form_to_show.form_show[ num.to_s ][ sub_property ][params[:locale].to_s].class != Array - @form_to_show.form_show[ num.to_s ][ sub_property ][params[:locale].to_s] = sub_value + type = Cancerpredictfields::FIELDINFO[sub_property.to_s] + if type && Cancerpredictfields::Field_relations[type] + type = Cancerpredictfields::Field_relations[type] + end + type = type.constantize rescue String + @form_to_show.form_show[ num.to_s ][ sub_property ] = {} if @form_to_show.form_show[num.to_s][ sub_property ].nil? + if @form_to_show.form_show[ num.to_s ][ sub_property ][params[:locale].to_s].class != Array && type != Array + if type == Fixnum + @form_to_show.form_show[ num.to_s ][ sub_property ][params[:locale].to_s] = sub_value.to_i rescue 0 + elsif type == Float + @form_to_show.form_show[ num.to_s ][ sub_property ][params[:locale].to_s] = sub_value.to_f rescue 0.0 + else + @form_to_show.form_show[ num.to_s ][ sub_property ][params[:locale].to_s] = sub_value + end else if sub_value.length > 2 @form_to_show.form_show[ num.to_s ][ sub_property ][params[:locale].to_s] = YAML.load(sub_value) @@ -52,49 +104,117 @@ class Admin::CancerpredictsController < OrbitAdminController @form_to_show.form_show[ num.to_s ][ sub_property ][params[:locale].to_s] = [] end end - end - end - else - @form_to_show.form_show[num.to_s][key.to_s] = value.to_i - end - end - end - params["cancerpredictfields"]["form_show_in_result"].each do |num,property| - property.each do |key,value| - if value != "0" && value != "1" - if key != params[:locale] - if @form_to_show.form_show_in_result[num.to_s][key.to_s].class != Array - @form_to_show.form_show_in_result[num.to_s][key.to_s] = value - else - if value.length > 2 - @form_to_show.form_show_in_result[num.to_s][key.to_s] = YAML.load(value) - else - @form_to_show.form_show_in_result[num.to_s][key.to_s] = [] - end - end - else - value.each do |sub_property,sub_value| - if @form_to_show.form_show_in_result[ num.to_s ][ sub_property ][params[:locale].to_s].class != Array - @form_to_show.form_show_in_result[ num.to_s ][ sub_property ][params[:locale].to_s] = sub_value - else - if sub_value.length > 2 - @form_to_show.form_show_in_result[ num.to_s ][ sub_property ][params[:locale].to_s] = YAML.load(sub_value) - else - @form_to_show.form_show_in_result[ num.to_s ][ sub_property ][params[:locale].to_s] = [] + if(property["old_num"] != nil && property["old_num"] != num.to_s) + other_in_use_locales.each do |locale| + @form_to_show.form_show[ num.to_s ][ sub_property ][locale] = @form_to_show.form_show_was[ property["old_num"] ][ sub_property ][locale] end end end end - else - @form_to_show.form_show_in_result[num.to_s][key.to_s] = value.to_i end end end - @create_items = ['title_texts','form_result_is_right','text_descibe','years','table_above_texts','text_above_texts','surgery_only_texts','extra_texts','extra_therapy_texts','danger_texts','texts_between_Result_and_result_block'] + largest_num = org_nums.map{|n| n.to_i}.sort.last + if (params["cancerpredictfields"]["form_show"].keys.last.to_i + 1 ) <= largest_num + ( (params["cancerpredictfields"]["form_show"].keys.last.to_i + 1 ) .. (largest_num)).each do |i| + @form_to_show.form_show.delete i.to_s + end + end + if !params["cancerpredictfields"]["form_show_in_result"].nil? + org_nums = @form_to_show.form_show_in_result_was.keys + remain_org_nums = params["cancerpredictfields"]["form_show_in_result"].values.map{|property| property["old_num"]}.select{|n| n.present?} + delete_nums = org_nums - remain_org_nums + if !delete_nums.blank? + delete_nums.each do |delete_num| + @form_to_show.form_show_in_result.delete(delete_num) + end + end + params["cancerpredictfields"]["form_show_in_result"].each do |num,property| + property.each do |key,value| + if key.include?("_file") && (!value[:temp_file].blank? rescue false) + if value[:id].nil? + mapping_file = CancerPredictMappingFile.create(value) + else + mapping_file = CancerPredictMappingFile.find(value[:id]) + mapping_file.temp_file = value[:temp_file] + mapping_file.save + end + @form_to_show.form_show[num.to_s][key.to_s] = mapping_file.id + elsif key.include?("_file") + if value[:_destroy] == "1" + mapping_file = CancerPredictMappingFile.find(value[:id]) + mapping_file.destroy + @form_to_show.form_show_in_result[num.to_s][key.to_s] = "" + end + end + next if key.include?("_file") + if (key != "old_num") + if key != params[:locale] + @form_to_show.form_show_in_result[num.to_s] = {} if @form_to_show.form_show_in_result[num.to_s].nil? + type = Cancerpredictfields::FIELDINFO[key.to_s] + if type && Cancerpredictfields::Field_relations[type] + type = Cancerpredictfields::Field_relations[type] + end + type = type.constantize rescue String + if @form_to_show.form_show_in_result[num.to_s][key.to_s].class != Array && type != Array + if type == Fixnum + @form_to_show.form_show_in_result[num.to_s][key.to_s] = value.to_i rescue 0 + elsif type == Float + @form_to_show.form_show_in_result[num.to_s][key.to_s] = value.to_f rescue 0.0 + else + @form_to_show.form_show_in_result[num.to_s][key.to_s] = value + end + else + if value.length > 2 + @form_to_show.form_show_in_result[num.to_s][key.to_s] = YAML.load(value) + else + @form_to_show.form_show_in_result[num.to_s][key.to_s] = [] + end + end + else + value.each do |sub_property,sub_value| + type = Cancerpredictfields::FIELDINFO[sub_property.to_s] + if type && Cancerpredictfields::Field_relations[type] + type = Cancerpredictfields::Field_relations[type] + end + type = type.constantize rescue String + @form_to_show.form_show_in_result[ num.to_s ][ sub_property ] = {} if @form_to_show.form_show[num.to_s][ sub_property ].nil? + if @form_to_show.form_show_in_result[ num.to_s ][ sub_property ][params[:locale].to_s].class != Array && type != Array + if type == Fixnum + @form_to_show.form_show_in_result[ num.to_s ][ sub_property ][params[:locale].to_s] = sub_value.to_i rescue 0 + elsif type == Float + @form_to_show.form_show_in_result[ num.to_s ][ sub_property ][params[:locale].to_s] = sub_value.to_f rescue 0.0 + else + @form_to_show.form_show_in_result[ num.to_s ][ sub_property ][params[:locale].to_s] = sub_value + end + else + if sub_value.length > 2 + @form_to_show.form_show_in_result[ num.to_s ][ sub_property ][params[:locale].to_s] = YAML.load(sub_value) + else + @form_to_show.form_show_in_result[ num.to_s ][ sub_property ][params[:locale].to_s] = [] + end + end + if(property["old_num"] != nil && property["old_num"] != num.to_s) + other_in_use_locales.each do |locale| + @form_to_show.form_show_in_result[ num.to_s ][ sub_property ][locale] = @form_to_show.form_show_was[ property["old_num"] ][ sub_property ][locale] + end + end + end + end + end + end + end + largest_num = org_nums.map{|n| n.to_i}.sort.last + if (params["cancerpredictfields"]["form_show_in_result"].keys.last.to_i + 1 ) <= largest_num + ( (params["cancerpredictfields"]["form_show_in_result"].keys.last.to_i + 1 ) .. (largest_num)).each do |i| + @form_to_show.form_show_in_result.delete i.to_s + end + end + end + @create_items = ['title_texts','form_result_is_right','text_descibe','years','table_above_texts','text_above_texts','surgery_only_texts','extra_texts','extra_therapy_texts','danger_texts','texts_between_Result_and_result_block','prediction_formula','hidden_variables','advance_mode'] params_cancer = params.require("cancerpredictfields").permit! @create_items.each do |item| if (@form_to_show[item].class == BSON::Document) || (@form_to_show.send(item).class == Hash) - puts params_cancer[item] item_hash = @form_to_show[item] item_hash = item_hash.merge(params_cancer[item]) @form_to_show[item] = item_hash @@ -185,7 +305,18 @@ class Admin::CancerpredictsController < OrbitAdminController Headimages.find_by(:id => @image_id ).destroy rescue next @form_to_show.title_images_id.delete(@image_id) end + file_ids = (@form_to_show.form_show.values + @form_to_show.form_show_in_result.values).map{|property| [property[:variable],property[:cancer_predict_mapping_file]]}.select{|k,f| f.present?}.to_h + mapping_data_from_csv = {} + if !file_ids.blank? + file_ids.each do |k,v| + mapping_data_from_csv[k] = read_mapping_file(v) + end + end + @form_to_show.mapping_data_from_csv = mapping_data_from_csv.to_json @form_to_show.save + fork do + @form_to_show.auto_write_predict_js + end end @index = 0 Dir.chdir("public") do @@ -232,16 +363,18 @@ class Admin::CancerpredictsController < OrbitAdminController @field_property = {} property.each do |key,value| @value= value + @disp_value if @value.class == BSON::Document || @value.class == Hash @disp_value = @value[current_locale] rescue "" else @disp_value = @value end + @disp_value = "" if @disp_value.nil? @field_property[key] = @disp_value end if @field_property['right'] == 0 + next if @field_property["name"].blank? @table_str_left += '
' - break if @field_property["name"] == "" @table_str_left += '' @@ -256,7 +389,7 @@ class Admin::CancerpredictsController < OrbitAdminController @field_property["comment_text"] = property["comment_text"][locale.to_s] break end - if @field_property["comment_text"] != "" + if @field_property["comment_text"].present? @table_str_left += '' @table_str_left += '' else @@ -304,7 +437,7 @@ class Admin::CancerpredictsController < OrbitAdminController @table_str_right += '' - if @field_property["comment_text"] != "" + if @field_property["comment_text"].present? @table_str_right += '' @table_str_right += '' else @@ -455,7 +588,7 @@ class Admin::CancerpredictsController < OrbitAdminController end def showSubmit @page_num = params[:page] || 1 - @results = Cancerpredictrecord.where("title"=>@app_title).asc(:id).page(@page_num).per(10) + @results = Cancerpredictrecord.where("title"=>@app_title).desc(:id).page(@page_num).per(10) @variables = [] @names = [] @form_to_show.form_show.each do |num,property| @@ -489,7 +622,7 @@ class Admin::CancerpredictsController < OrbitAdminController @pagination = create_pagination(@page_num.to_i) end def export_cancer_tool_record - @cancer_records = Cancerpredictrecord.where("title"=>@app_title).asc(:id) + @cancer_records = Cancerpredictrecord.where("title"=>@app_title).desc(:id) dir_path = 'tmp/cancer_tool/' #FileUtils.rm_r(dir_path, :force => true) if Dir.exist?(dir_path) FileUtils.mkdir dir_path if !Dir.exist?(dir_path) #create dir for storing tmp_file if dir doesn't exist @@ -564,4 +697,21 @@ class Admin::CancerpredictsController < OrbitAdminController end pagination += (((page==all_page_num) ? '
  • ['+I18n.t('cancerpredict.next_page')+']
  • ' : '
  • ['+I18n.t('cancerpredict.next_page')+']
  • ')+'
    ') end + def read_mapping_file(mapping_file_id) + mapping_file = CancerPredictMappingFile.find(mapping_file_id) rescue nil + if !mapping_file.nil? + csv_rows = CSV.read(mapping_file.temp_file.file.path) + titles = csv_rows[0] + infos = {} + titles.each_with_index do |title,i| + infos[title] = [] + csv_rows[1..-1].each do |row| + infos[title] << row[i].to_f + end + end + return infos + else + return {} + end + end end \ No newline at end of file diff --git a/app/controllers/cancerpredicts_controller.rb b/app/controllers/cancerpredicts_controller.rb index 262f028..efc3036 100644 --- a/app/controllers/cancerpredicts_controller.rb +++ b/app/controllers/cancerpredicts_controller.rb @@ -1,16 +1,13 @@ # encoding: utf-8 require 'rubyXL' +require "json" class CancerpredictsController < ApplicationController def initialize super @app_title = "cancerpredict" end def calculate - uid = OrbitHelper.params[:uid] rescue "" - tags = OrbitHelper.widget_tags - categories = OrbitHelper.widget_categories || [] create_first_field - #begin if params['header'].to_i == 1 locale = params['locale'].to_s rescue 'zh_tw' locale = 'zh_tw' if locale == 'zh_cn' @@ -33,6 +30,9 @@ class CancerpredictsController < ApplicationController result['danger_texts'] = (@form_to_show.danger_texts[locale] rescue '') result['title'] = Hash[@head_images.sort].values.join('') result['page_title'] = @form_to_show.title_texts[params[:locale]] + elsif params['get_mapping_data_from_csv'].to_i == 1 + result = {} + result['mapping_data_from_csv'] = JSON.parse(@form_to_show.mapping_data_from_csv) rescue {} else @record = Cancerpredictrecord.new @record.title = @app_title @@ -40,7 +40,7 @@ class CancerpredictsController < ApplicationController @choice_values = [] @choice_names = [] @form_to_show.form_show.values.each{|choice| @choice_keys.push choice[:variable]} - @form_to_show.form_show.values.each{|choice| @choice_values.push choice[:choice_fields]} + @form_to_show.form_show.values.each{|choice| @choice_values.push ((choice[:is_num] == 1) ? [] : choice[:choice_fields])} @form_to_show.form_show.values.each{|choice| @choice_names.push choice[:name]} @choice_keys.each_with_index{|key,i| @record.names[key] = @choice_names[i]} @choice_keys.each_with_index{|key,i| @record.values[key] = @choice_values[i]} @@ -52,160 +52,96 @@ class CancerpredictsController < ApplicationController locale = params['data']['locale'].to_s rescue 'zh_tw' locale = 'zh_tw' if locale == 'zh_cn' result = {} - result['age1'] = (params['data']['age'].to_f/100)**(0.5) - result['age2'] = ((params['data']['age'].to_f/100)**(0.5))*Math.log(params['data']['age'].to_f/100,Math.exp(1)) - result['size1'] = Math.log(params['data']['size'].to_f/10,Math.exp(1)) - if params['data']['lymph_nodes_examined'].to_i != 0 - result['ratio'] = params['data']['lymph_nodes_positive'].to_f/params['data']['lymph_nodes_examined'].to_f rescue 0 - else - result['ratio'] = 0 + mapping_data_from_csv = JSON.parse(@form_to_show.mapping_data_from_csv) rescue {} + @form_to_show.all_variables.each do |v| + result[v] = 0 end - result['ratio'] = 1 if result['ratio'] > 1 - result['nposit'] = ((result['ratio'].to_f+0.1)/0.1)**0.5 - @T = '' - if params['data']['tumor_direct_extension'].to_i != 1 - if params['data']['size'].to_i <= 20 - @T = 'T1' - elsif params['data']['size'].to_i > 20 && params['data']['size'].to_i <= 50 - @T = 'T2' - elsif params['data']['size'].to_i > 50 - @T = 'T3' + @form_to_show.form_show.each do |num,property| + @variable = property[:variable] + if @variable.present? + if property[:is_num] == 1 + if property[:is_float] == 1 + result[@variable] = params['data'][@variable].to_f rescue 0.0 + else + result[@variable] = params['data'][@variable].to_i rescue 0 + end + elsif property[:choice_fields].present? + if !(@form_to_show.advance_mode) + result[@variable] = params['data'][@variable].to_i rescue 0 + else + if property[:need_map_values] == 1 + result[@variable] = property[:map_values][params['data'][@variable].to_i - 1] + else + if property[:revert_value] != 1 + result[@variable] = params['data'][@variable].to_i - 1 + else + result[@variable] = ((property[:choice_fields].length - params['data'][@variable].to_i) rescue params['data'][@variable].to_i) + end + end + end + end + if @form_to_show.advance_mode && property[:cancer_predict_mapping_file].present? + if (mapping_data_from_csv != {}) + mapping_hash = mapping_data_from_csv[@variable] + temp_index = 0 + temp_value = result[@variable] + mapping_hash.each_with_index do |(k,v),i| + if i == 0 + index_val = v.index(temp_value) rescue nil + if !index_val.nil? + temp_index = index_val + else + closest_value = v.min_by{|x| (temp_value-x).abs} + temp_index = v.index(closest_value) + end + end + result[k] = v[temp_index] + end + end + end end - else - @T = 'T4' end - result['T'] = @T - @N = '' - if params['data']['lymph_nodes_positive'].to_i == 0 - @N = 'N0' - elsif params['data']['lymph_nodes_positive'].to_i >= 1 && params['data']['lymph_nodes_positive'].to_i <= 3 && params['data']['micrometastasis'].to_i != 1 - @N = 'N1' - elsif params['data']['lymph_nodes_positive'].to_i >= 1 && params['data']['lymph_nodes_positive'].to_i <= 3 && params['data']['micrometastasis'].to_i == 1 - @N = 'N1mi' - elsif params['data']['lymph_nodes_positive'].to_i >= 4 && params['data']['lymph_nodes_positive'].to_i <= 9 - @N = 'N2' - elsif params['data']['lymph_nodes_positive'].to_i >= 10 - @N = 'N3' + formula_variables = @form_to_show.tmp_lpv_variables + begin + eval_hidden_variables(result) + rescue => e + @form_to_show.generate_eval_formula + eval_hidden_variables(result) end - result['N'] = @N - @M = '' - if params['data']['Distant_Metastasis'].to_i != 1 - @M = 'M0' - else - @M = 'M1' + begin + eval_formula(result) + rescue => e + @form_to_show.generate_eval_formula + eval_formula(result) end - result['M'] = @M - if @M == 'M0' - if @T == 'T1' && (@N == 'N0' || @N == 'N1mi') - result['pstage'] = 1 - elsif ((@T == 'T2' || @T == 'T3') && (@N == 'N0')) || ((@T == 'T1' || @T == 'T2') && (@N == 'N1')) - result['pstage'] = 2 - elsif (@T == 'T4' && @N == 'N0') || ((@T == 'T3' || @T == 'T4') && @N == 'N1') || (@N == 'N2' || @N == 'N3') - result['pstage'] = 3 - end - else - result['pstage'] = 4 + result['lpv'] = result[formula_variables.last] + result['lpv_variable'] = {} + formula_variables.each do |variable_name| + result['lpv_variable']["#{variable_name}"] = result[variable_name] end - if (params['data']['ER_status'].to_i != 2 || params['data']['PR_status'].to_i != 2) && (params['data']['HER2_status'].to_i != 1) - result['subtype'] = 1 - elsif params['data']['HER2_status'].to_i == 1 - result['subtype'] = 2 - elsif params['data']['ER_status'].to_i == 2 && params['data']['PR_status'].to_i == 2 && (params['data']['HER2_status'].to_i != 1) - result['subtype'] = 3 - end - if params['data']['grade'].to_i == 2 || params['data']['grade'].to_i == 4 - result['grade_2'] = 1 - else - result['grade_2'] = 0 - end - if params['data']['grade'].to_i == 3 - result['grade_3'] = 1 - else - result['grade_3'] = 0 - end - if result['subtype'].to_i == 2 - result['subtype_HER2'] = 1 - else - result['subtype_HER2'] = 0 - end - if result['subtype'].to_i == 3 - result['subtype_triple'] = 1 - else - result['subtype_triple'] = 0 - end - if result['pstage'].to_i == 2 - result['pstage_2'] = 1 - else - result['pstage_2'] = 0 - end - if result['pstage'].to_i == 3 - result['pstage_3'] = 1 - else - result['pstage_3'] = 0 - end - if result['pstage'].to_i == 4 - result['pstage_4'] = 1 - else - result['pstage_4'] = 0 - end - if params['data']['lvi'].to_i == 1 - result['lvi_yes'] = 1 - else - result['lvi_yes'] = 0 - end - result['lpv'] = ((result['age1']-0.7276655)*(-10.87)+(result['age2']+0.4540707)*8.968+(result['size1']-0.643632)*0.7678+(result['nposit']-1.346932)*0.5339+ - result['grade_2']*0.4795+result['grade_3']*0.818+result['subtype_HER2']*0.1806+result['subtype_triple']*0.6457+result['pstage_2']*0.5311+ - result['pstage_3']*1.134+result['pstage_4']*2.172+result['lvi_yes']*0.3321-0.04 rescue 'error') @years = @form_to_show.years - result['table'] = '

    '+@form_to_show.table_above_texts[locale]+'

    ' - result['table'] += (''+(locale == 'zh_tw' ? '第' : '')+'') result['years'] = @years - @years.each{|year| result['table'] += ('')} - result['table'] += (''+(locale == 'zh_tw' ? '年' : '')+'') - @table_head = (locale == "zh_tw") ? ['治療','額外治療效益','總生存率(%)'] :['Treatment','Additional Benefit','Overall Survival(%)'] - @head_name = ['Treatment','Additional_Benefit','Overall_Survival'] - @therapy_choices = (locale == "zh_tw") ? ['純手術'] :['Surgery only'] + @therapy_choices = [I18n.t('cancerpredict.table.Surgeryonly')] @form_to_show.form_show_in_result.values.each{|choice| @therapy_choices.push choice["name"][locale]} - @therapy_names = ['Surgery_only'] - @form_to_show.form_show_in_result.values.each{|choice| @therapy_names.push choice["variable"]} - result['treatmeny_method'] = @therapy_names - result['table'] += '' - @table_head.each_with_index{|head,index| result['table'] += ('')} - result['table'] += '' - @therapy_choices.each_with_index do |choice,i| - result['table'] += '' - @table_head.each_with_index do |head,index| - result['table'] += ('') - end - result['table'] += '' - end - @texts = @form_to_show.text_above_texts[locale].gsub('
    ','
    ') - @texts = @texts.split('{{years}}') - @texts.delete('') - result['texts'] = ''+@texts[0] - @years.each{|year| result['texts'] += ('')} - if @texts.count > 1 - result['texts'] += (@texts[1]+'') if @texts.count > 1 + @therapy_names = @form_to_show.treatment_method + result['treatment_method'] = @therapy_names + result['treatment_method_active_indices'] = @form_to_show.treatment_method_active_indices + result['table'] = @form_to_show.result_table_translations[locale] + year = params['data']['year'] rescue nil + if year.nil? + year = @years.first.to_f else - result['texts'] += '' + year = year.to_f end - @lpv_calc = [-0.001476145,-0.01261639,-0.02519608] - @servive_ratio = ((Math.exp(@lpv_calc[-1])**(Math.exp(result['lpv'])))*100).round(2) - @surgery_only_texts = @form_to_show.surgery_only_texts[locale] - @surgery_only_texts.insert(0,'

    ') - @surgery_only_texts = @surgery_only_texts.gsub('{{Surgery_only}}',''+@servive_ratio.round.to_s+'') - @surgery_only_texts = @surgery_only_texts.gsub('{{surgery_year}}',''+@years[-1].to_s+'') - @surgery_only_texts += '' - result['texts'] += @surgery_only_texts - result['texts'] += ''+@form_to_show.extra_texts[locale]+'

    ' + year_index = @years.index(year) + @servive_ratio = eval(@form_to_show.tmp_years_settings_for_ruby[year_index]) + @servive_ratio = (@servive_ratio * 100).round(2) + result['texts'] = @form_to_show.result_text_translations[locale] result['extra_therapy_texts'] = @form_to_show.extra_therapy_texts[locale] rescue @form_to_show.extra_therapy_texts['zh_tw'] result['servive_ratio'] = @servive_ratio end result = result.merge(params) render :json=> result -# rescue - # render :json=> params - #end end def index uid = OrbitHelper.params[:uid] rescue "" @@ -223,13 +159,13 @@ class CancerpredictsController < ApplicationController categories = OrbitHelper.widget_categories || [] end def create_first_field - if Cancerpredictfields.where("title"=>(@app_title + "_back")).take_while{true}.count == 0 + if Cancerpredictfields.where("title"=>(@app_title + "_back")).count == 0 @form_to_show = Cancerpredictfields.new() @form_to_show.title = @app_title +"_back" @form_to_show.save end @form_to_show - if Cancerpredictfields.where("title"=>@app_title).take_while{true}.count == 0 + if Cancerpredictfields.where("title"=>@app_title).count == 0 @form_to_show = Cancerpredictfields.new() @form_to_show.title=@app_title @form_to_show.save @@ -238,4 +174,23 @@ class CancerpredictsController < ApplicationController @form_to_show = Cancerpredictfields.where("title"=>@app_title).first end end + def read_mapping_file(mapping_file) + if mapping_file.class != CancerPredictMappingFile + mapping_file = CancerPredictMappingFile.find(mapping_file_id) rescue nil + end + if !mapping_file.nil? + csv_rows = CSV.read(mapping_file.temp_file.file.path) + titles = csv_rows[0] + infos = {} + titles.each_with_index do |title,i| + infos[title] = [] + csv_rows[1..-1].each do |row| + infos[title] << row[i].to_f + end + end + return infos + else + return {} + end + end end \ No newline at end of file diff --git a/app/models/cancer_predict_mapping_file.rb b/app/models/cancer_predict_mapping_file.rb new file mode 100644 index 0000000..563870c --- /dev/null +++ b/app/models/cancer_predict_mapping_file.rb @@ -0,0 +1,12 @@ +# encoding: utf-8 +class CancerPredictMappingFile + require 'carrierwave/processing/mime_types' + include Mongoid::Document + include Mongoid::Timestamps + include CarrierWave::MimeTypes + mount_uploader :temp_file, HeadImagesUploader + + def file_identifier + filename = self.temp_file.file.original_filename rescue "" + end +end \ No newline at end of file diff --git a/app/models/cancerpredictfields.rb b/app/models/cancerpredictfields.rb index df3cc31..008e846 100644 --- a/app/models/cancerpredictfields.rb +++ b/app/models/cancerpredictfields.rb @@ -1,79 +1,456 @@ class Cancerpredictfields + require "pathname" + require 'json' include Mongoid::Document include Mongoid::Timestamps - include OrbitModel::Status - include OrbitModel::Impression - # encoding: utf-8 - include OrbitTag::Taggable - include OrbitCategory::Categorizable + Field_relations = {"number_field"=>"Fixnum","text_area"=>"String"} + FIELDINFO = {"variable"=>"String","name"=>"String","is_num"=>"Fixnum","hint"=>"String","comment_text"=>"String","choice_fields"=>"Array","range"=>"Array","right"=>"Fixnum","is_float"=>"Fixnum","revert_value"=>"Fixnum","map_values"=>"Array","cancer_predict_mapping_file"=>"String","lpv_impact"=>"Float","active_choice"=>"number_field","disable_condition"=>"text_area"} + NonLoclaized = ["variable","is_num","range","right","is_float","revert_value","map_values","cancer_predict_mapping_file","lpv_impact","active_choice","disable_condition"] + AdvanceFields = ["revert_value","map_values","cancer_predict_mapping_file"] + TherapyFields = ["variable","name","hint","comment_text","choice_fields","lpv_impact","active_choice","disable_condition"] + TherapyOnly = ["lpv_impact","active_choice","disable_condition"] field :title ,type:String ,default:"" - field :form_show , :type=> Hash ,default:{0=>{:variable=>"age",:name=>{"zh_tw"=>"年齡
    (Age)","en"=>"Age"},:is_num=>1, :hint=>{'zh_tw'=>'從 18 歲(含)開始至 93 歲','en'=>'Age must be between 18 and 93'} , :comment_text=>{'zh_tw'=>'年齡為該婦女於確診罹患乳癌時之年齡','en'=>'Age at diagnosis'}, :choice_fields=> {"zh_tw"=>[],"en"=>[]},:range=>[18,93],:right=>0,:is_float=>0}, - 1=>{:variable=>"size",:name=>{"zh_tw"=>"腫瘤大小
    (Tumor size)","en"=>"Tumor size"},:is_num=>1,:hint=>{'zh_tw'=>'','en'=>'The unit of tumor size is millimeter (mm)'}, :comment_text=>{'zh_tw'=>'若有多個原發腫瘤,請輸入最大尺寸之原發腫瘤','en'=>'If there was more than one primary tumor, please enter the size of the largest one.'}, :choice_fields=> {"zh_tw"=>[],"en"=>[]},:range=>[1,230],:right=>0,:is_float=>0}, - 2=>{:variable=>"lymph_nodes_examined",:name=>{"zh_tw"=>"區域淋巴結檢查數目
    (Regional lymph nodes examined)","en"=>"Regional lymph nodes examined"},:is_num=>1,:hint=>{'zh_tw'=>'','en'=>''}, :comment_text=>{'zh_tw'=>'','en'=>''}, :choice_fields=> {"zh_tw"=>['未知'],"en"=>['unknown']},:range=>[0,90],:right=>0,:is_float=>0}, - 3=>{:variable=>"lymph_nodes_positive",:name=>{"zh_tw"=>"區域淋巴結侵犯數目
    (Regional lymph nodes positive)","en"=>"Regional lymph nodes positive"},:is_num=>1,:hint=>{'zh_tw'=>'','en'=>''}, :comment_text=>{'zh_tw'=>'此變項為預測重要變數,若無此資訊預測容易失真。','en'=>'Regional lymph nodes positive is a key predictive variable. If this information is omitted, the prediction result would be biased.'}, :choice_fields=> {"zh_tw"=>['未知'],"en"=>['unknown']},:range=>[0,90],:right=>0,:is_float=>0}, - 4=>{:variable=>"grade",:name=>{"zh_tw"=>"腫瘤分化程度
    (Tumor grade)","en"=>"Tumor grade"},:is_num=>0,:hint=>{'zh_tw'=>'','en'=>''}, :comment_text=>{'zh_tw'=>'腫瘤級數代表腫瘤組織與正常組織間的分化程度,若無分化級數資訊,請選擇“未知”選項,將以級數 2 進行預測。','en'=>'The grade refers to how different the cancer cells are from normal cells. Please select “unknown” if there is no information about grade. The prediction model would use “grade 2” as the alternative variable.'}, :choice_fields=> {"zh_tw"=>['1','2','3','未知'],"en"=>['1','2','3','unknown']},:range=>[],:right=>0,:is_float=>0}, - 5=>{:variable=>"ER_status",:name=>{"zh_tw"=>"ER 狀態
    (ER status)","en"=>"ER status"},:is_num=>0,:hint=>{'zh_tw'=>'','en'=>''}, :comment_text=>{'zh_tw'=>'ER:雌激素受體,若無 ER 資訊請選擇未知,將以佔多數比例陽性作為後續預測。','en'=>'ER status describes the status of estrogen receptor. Please select “unknown” if there is no information about ER status. The prediction model would use “Positive” (the majority class) as the alternative variable.'}, :choice_fields=> {"zh_tw"=>['陽性','陰性','未知'],"en"=>['positive','negative','unknown']},:range=>[],:right=>0,:is_float=>0}, - 6=>{:variable=>"PR_status",:name=>{"zh_tw"=>"PR 狀態
    (PR status)","en"=>"PR status"},:is_num=>0,:hint=>{'zh_tw'=>'','en'=>''}, :comment_text=>{'zh_tw'=>'PR:黃體素受體,若無 PR 資訊請選擇未知,將以佔多數比例陽性作為後續預測。','en'=>'PR status describes the status of progesterone receptor. Please select “unknown” if there is no information about PR status. The prediction model would use “Positive” (the majority class) as the alternative variable.'}, :choice_fields=> {"zh_tw"=>['陽性','陰性','未知'],"en"=>['positive','negative','unknown']},:range=>[],:right=>1,:is_float=>0}, - 7=>{:variable=>"HER2_status",:name=>{"zh_tw"=>"HER2 狀態
    (HER2 status)","en"=>"HER2 status"},:is_num=>0,:hint=>{'zh_tw'=>'','en'=>''}, :comment_text=>{'zh_tw'=>'HER2:第二型人類上皮成長因子接受器蛋白,若無 HER2 資訊請選擇未知,將以佔多數比例陰性作為後續預測。','en'=>'HER2 status describes the status of human epidermal growth factor receptor 2. Please select “unknown” if there is no information about HER2 status. The prediction model would use “Negative” (the majority class) as the alternative variable.'}, :choice_fields=> {"zh_tw"=>['陽性','陰性','未知'],"en"=>['positive','negative','unknown']},:range=>[],:right=>1,:is_float=>0}, - 8=>{:variable=>"Distant_Metastasis",:name=>{"zh_tw"=>"遠端轉移
    (Distant Metastasis)","en"=>"Distant Metastasis"},:is_num=>0,:hint=>{'zh_tw'=>'','en'=>''}, :comment_text=>{'zh_tw'=>'若無遠轉移資訊請選擇未知,將以佔多數比例未遠端轉移作為後續預測。','en'=>'Please select “unknown” if there is no information about distant Metastasis. The prediction model would use “No” (the majority class) as the alternative variable.'}, :choice_fields=> {"zh_tw"=>['是','否','未知'],"en"=>['yes','no','unknown']},:range=>[],:right=>1,:is_float=>0}, - 9=>{:variable=>"micrometastasis",:name=>{"zh_tw"=>"淋巴結顯微轉移
    (Lymph nodes micrometastasis)","en"=>"Micrometastasis"},:is_num=>0,:hint=>{'zh_tw'=>'','en'=>''}, :comment_text=>{'zh_tw'=>'若無顯微移資訊請選擇未知,將以無顯微轉移作為後續預測。','en'=>'Please select “unknown” if there is no information about lymph nodes micrometastasis. The prediction model would use “No” as the alternative variable.'}, :choice_fields=> {"zh_tw"=>['是','否','未知'],"en"=>['yes','no','unknown']},:range=>[],:right=>1,:is_float=>0}, - 10=>{:variable=>"tumor_direct_extension",:name=>{"zh_tw"=>"腫瘤浸潤至胸壁和/或皮膚
    (Tumor direct extension to the chest wall and/or to the skin)","en"=>"Tumor direct extension to the chest wall and/or to the skin"},:is_num=>0,:hint=>{'zh_tw'=>'','en'=>''}, :comment_text=>{'zh_tw'=>'若無腫瘤浸潤至胸壁或皮膚資訊請選擇未知,將以佔多數比例無腫瘤浸潤至胸壁作為後續預測。','en'=>'Please select “unknown” if there is no information about tumor direct extension to the chest wall and/or to the skin. The prediction model would use “No” (the majority class) as the alternative variable'}, :choice_fields=> {"zh_tw"=>['是','否','未知'],"en"=>['yes','no','unknown']},:range=>[],:right=>1,:is_float=>0}, - 11=>{:variable=>"lvi",:name=>{"zh_tw"=>"淋巴管或血管侵犯
    (Lymph vessel or vascular invasion, LVI)","en"=>"Lymph vessel or vascular invasion, LVI"},:is_num=>0,:hint=>{'zh_tw'=>'','en'=>'Lymph vessel or vascular invasion'}, :comment_text=>{'zh_tw'=>'若無淋巴管或血管侵犯資訊,請選擇“未知”選項,將以佔多數比例的淋巴管或血管未侵犯進行預測','en'=>'Please select “unknown” if there is no information about Lymph vessel or vascular invasion. The prediction model would use “No” (the majority class) as the alternative variable.'}, :choice_fields=> {"zh_tw"=>['是','否','未知'],"en"=>['yes','no','unknown']},:range=>[],:right=>1,:is_float=>0} - } - field :form_show_in_result , :type=> Hash ,default:{0=>{:variable=>"hormone_therapy",:name=>{"zh_tw"=>"賀爾蒙治療","en"=>"Hormone/Steroid therapy"},:is_num=>0, :hint=>{'zh_tw'=>'適用賀爾蒙受體陽性病人','en'=>'Hormone/ steroid therapy is available when ER status is positive'} , :comment_text=>{'zh_tw'=>'','en'=>''}, :choice_fields=> {"zh_tw"=>['否','是'],"en"=>['No','Yes']},:range=>[]}, - 1=>{:variable=>"Chemotherapy",:name=>{"zh_tw"=>"化學治療","en"=>"Chemotherapy"},:is_num=>0,:hint=>{'zh_tw'=>'','en'=>''}, :comment_text=>{'zh_tw'=>'','en'=>''}, :choice_fields=> {"zh_tw"=>['否','是'],"en"=>['No','Yes']},:range=>[]}, - 2=>{:variable=>"Radiotherapy",:name=>{"zh_tw"=>"放射治療","en"=>"Radiotherapy"},:is_num=>0,:hint=>{'zh_tw'=>'','en'=>''}, :comment_text=>{'zh_tw'=>'','en'=>''}, :choice_fields=> {"zh_tw"=>['否','是'],"en"=>['No','Yes']},:range=>[]}, - 3=>{:variable=>"Targeted_therapy",:name=>{"zh_tw"=>"標靶治療","en"=>"Targeted therapy"},:is_num=>0,:hint=>{'zh_tw'=>'抗HER2治療','en'=>''}, :comment_text=>{'zh_tw'=>'','en'=>''}, :choice_fields=> {"zh_tw"=>['否','是'],"en"=>['No','Yes']},:range=>[]} - } + field :advance_mode, type: Boolean, default: false + field :form_show , :type=> Hash ,default:{ + "0"=>{"variable"=>"age", "name"=>{"zh_tw"=>"年齡
    (Age)", "en"=>"Age"}, "is_num"=>1, "hint"=>{"zh_tw"=>"從 18 歲(含)開始至 93 歲", "en"=>"Age must be between 18 and 93"}, "comment_text"=>{"zh_tw"=>"年齡為該婦女於確診罹患乳癌時之年齡", "en"=>"Age at diagnosis"}, "choice_fields"=>{"zh_tw"=>[], "en"=>[]}, "range"=>[18, 93], "right"=>0, "is_float"=>0, "need_map_values"=>0, "revert_value"=>0, "map_values"=>[]}, + "1"=>{"variable"=>"size", "name"=>{"zh_tw"=>"腫瘤大小(單位:mm)
    (Tumor size)", "en"=>"Tumor size"}, "is_num"=>1, "hint"=>{"zh_tw"=>"", "en"=>"The unit of tumor size is millimeter (mm)"}, "comment_text"=>{"zh_tw"=>"若有多個原發腫瘤,請輸入最大尺寸之原發腫瘤", "en"=>"If there was more than one primary tumor, please enter the size of the largest one."}, "choice_fields"=>{"zh_tw"=>[], "en"=>[]}, "range"=>[1, 300], "right"=>0, "is_float"=>0, "need_map_values"=>0, "revert_value"=>0, "map_values"=>[]}, + "2"=>{"variable"=>"lymph_nodes_examined", "name"=>{"zh_tw"=>"區域淋巴結檢查數目
    (Regional lymph nodes examined)", "en"=>"Regional lymph nodes examined"}, "is_num"=>1, "hint"=>{"zh_tw"=>"", "en"=>""}, "comment_text"=>{"zh_tw"=>"", "en"=>""}, "choice_fields"=>{"zh_tw"=>["未知"], "en"=>["unknown"]}, "range"=>[0, 90], "right"=>0, "is_float"=>0, "need_map_values"=>0, "revert_value"=>0, "map_values"=>[]}, + "3"=>{"variable"=>"lymph_nodes_positive", "name"=>{"zh_tw"=>"區域淋巴結侵犯數目
    (Regional lymph nodes positive)", "en"=>"Regional lymph nodes positive"}, "is_num"=>1, "hint"=>{"zh_tw"=>"", "en"=>""}, "comment_text"=>{"zh_tw"=>"此變項為預測重要變數,若無此資訊預測容易失真。", "en"=>"Regional lymph nodes positive is a key predictive variable. If this information is omitted, the prediction result would be biased."}, "choice_fields"=>{"zh_tw"=>["未知"], "en"=>["unknown"]}, "range"=>[0, 90], "right"=>0, "is_float"=>0, "need_map_values"=>0, "revert_value"=>0, "map_values"=>[]}, + "4"=>{"variable"=>"grade", "name"=>{"zh_tw"=>"腫瘤分化程度
    (Tumor grade)", "en"=>"Tumor grade"}, "is_num"=>0, "hint"=>{"zh_tw"=>"", "en"=>""}, "comment_text"=>{"zh_tw"=>"腫瘤級數代表腫瘤組織與正常組織間的分化程度,若無分化級數資訊,請選擇“未知”選項,將以級數 2 進行預測。", "en"=>"The grade refers to how different the cancer cells are from normal cells. Please select “unknown” if there is no information about grade. The prediction model would use “grade 2” as the alternative variable."}, "choice_fields"=>{"zh_tw"=>["1", "2", "3", "未知"], "en"=>["1", "2", "3", "unknown"]}, "range"=>[], "right"=>0, "is_float"=>0, "need_map_values"=>0, "revert_value"=>0, "map_values"=>[]}, + "5"=>{"variable"=>"ER_status", "name"=>{"zh_tw"=>"ER 狀態
    (ER status)", "en"=>"ER status"}, "is_num"=>0, "hint"=>{"zh_tw"=>"", "en"=>""}, "comment_text"=>{"zh_tw"=>"ER:雌激素受體,若無 ER 資訊請選擇未知,將以佔多數比例陽 性作為後續預測。", "en"=>"ER status describes the status of estrogen receptor. Please select “unknown” if there is no information about ER status. The prediction model would use “Positive” (the majority class) as the alternative variable."}, "choice_fields"=>{"zh_tw"=>["陽性", "陰性", "未知"], "en"=>["positive", "negative", "unknown"]}, "range"=>[], "right"=>0, "is_float"=>0, "need_map_values"=>0, "revert_value"=>0, "map_values"=>[]}, + "6"=>{"variable"=>"PR_status", "name"=>{"zh_tw"=>"PR 狀態
    (PR status)", "en"=>"PR status"}, "is_num"=>0, "hint"=>{"zh_tw"=>"", "en"=>""}, "comment_text"=>{"zh_tw"=>"PR:黃體素受體, 若無 PR 資訊請選擇未知,將以佔多數比例陽性作為後續預測。", "en"=>"PR status describes the status of progesterone receptor. Please select “unknown” if there is no information about PR status. The prediction model would use “Positive” (the majority class) as the alternative variable."}, "choice_fields"=>{"zh_tw"=>["陽性", "陰性", "未知"], "en"=>["positive", "negative", "unknown"]}, "range"=>[], "right"=>1, "is_float"=>0, "need_map_values"=>0, "revert_value"=>0, "map_values"=>[]}, + "7"=>{"variable"=>"HER2_status", "name"=>{"zh_tw"=>"HER2 狀態
    (HER2 status)", "en"=>"HER2 status"}, "is_num"=>0, "hint"=>{"zh_tw"=>"", "en"=>""}, "comment_text"=>{"zh_tw"=>"HER2:第二型人類上皮成長因子接受器蛋白,若無 HER2 資訊請選擇未知,將以佔多數比例陰性作為後續預測。", "en"=>"HER2 status describes the status of human epidermal growth factor receptor 2. Please select “unknown” if there is no information about HER2 status. The prediction model would use “Negative” (the majority class) as the alternative variable."}, "choice_fields"=>{"zh_tw"=>["陽性", "陰性", "未知"], "en"=>["positive", "negative", "unknown"]}, "range"=>[], "right"=>1, "is_float"=>0, "need_map_values"=>0, "revert_value"=>0, "map_values"=>[]}, + "8"=>{"variable"=>"Distant_Metastasis", "name"=>{"zh_tw"=>"遠端轉移
    (Distant Metastasis)", "en"=>"Distant Metastasis"}, "is_num"=>0, "hint"=>{"zh_tw"=>"", "en"=>""}, "comment_text"=>{"zh_tw"=>"若無遠端轉移資訊請選擇未知,將以佔多數比例未遠端轉移作為後續預測。", "en"=>"Please select “unknown” if there is no information about distant Metastasis. The prediction model would use “No” (the majority class) as the alternative variable."}, "choice_fields"=>{"zh_tw"=>["是", "否", "未知"], "en"=>["yes", "no", "unknown"]}, "range"=>[], "right"=>1, "is_float"=>0, "need_map_values"=>0, "revert_value"=>0, "map_values"=>[]}, + "9"=>{"variable"=>"micrometastasis", "name"=>{"zh_tw"=>"淋巴結顯微轉移
    (Lymph nodes micrometastasis)", "en"=>"Micrometastasis"}, "is_num"=>0, "hint"=>{"zh_tw"=>"", "en"=>""}, "comment_text"=>{"zh_tw"=>"若無顯微移資訊請選擇未知,將以無顯微轉移作為後續預測。", "en"=>"Please select “unknown” if there is no information about lymph nodes micrometastasis. The prediction model would use “No” as the alternative variable."}, "choice_fields"=>{"zh_tw"=>["是", "否", "未知"], "en"=>["yes", "no", "unknown"]}, "range"=>[], "right"=>1, "is_float"=>0, "need_map_values"=>0, "revert_value"=>0, "map_values"=>[]}, + "10"=>{"variable"=>"tumor_direct_extension", "name"=>{"zh_tw"=>"腫瘤浸潤至胸壁和/或皮膚
    (Tumor direct extension to the chest wall and/or to the skin)", "en"=>"Tumor direct extension to the chest wall and/or to the skin"}, "is_num"=>0, "hint"=>{"zh_tw"=>"", "en"=>""}, "comment_text"=>{"zh_tw"=>"若無腫瘤浸潤至胸壁或皮膚資訊請選擇未知,將以佔多數比例無腫瘤浸潤至胸壁作為後續預測。", "en"=>"Please select “unknown” if there is no information about tumor direct extension to the chest wall and/or to the skin. The prediction model would use “No” (the majority class) as the alternative variable"}, "choice_fields"=>{"zh_tw"=>["是", "否", "未知"], "en"=>["yes", "no", "unknown"]}, "range"=>[], "right"=>1, "is_float"=>0, "need_map_values"=>0, "revert_value"=>0, "map_values"=>[]}, + "11"=>{"variable"=>"lvi", "name"=>{"zh_tw"=>"淋巴管或血管侵犯
    (Lymph vessel or vascular invasion, LVI)", "en"=>"Lymph vessel or vascular invasion, LVI"}, "is_num"=>0, "hint"=>{"zh_tw"=>"", "en"=>"Lymph vessel or vascular invasion"}, "comment_text"=>{"zh_tw"=>"若無淋巴管或血管侵犯資訊,請選擇“未知”選項,將以佔多數比例的淋巴管或血管未侵犯進行預測", "en"=>"Please select “unknown” if there is no information about Lymph vessel or vascular invasion. The prediction model would use “No” (the majority class) as the alternative variable."}, "choice_fields"=>{"zh_tw"=>["是", "否", "未知"], "en"=>["yes", "no", "unknown"]}, "range"=>[], "right"=>1, "is_float"=>0, "need_map_values"=>0, "revert_value"=>0, "map_values"=>[]} + } + field :form_show_in_result , :type=> Hash ,default: { + "0"=>{"variable"=>"hormone_therapy", "name"=>{"zh_tw"=>"賀爾蒙治療", "en"=>"Hormone/Steroid therapy"}, "is_num"=>0, "hint"=>{"zh_tw"=>"適用賀爾蒙受體陽性病人", "en"=>"Hormone/ steroid therapy is available when ER status is positive"}, "comment_text"=>{"zh_tw"=>"", "en"=>""}, "choice_fields"=>{"zh_tw"=>["否", "是"], "en"=>["No", "Yes"]}, "range"=>[], "right"=>0, "is_float"=>0, "revert_value"=>0, "map_values"=>"", "active_choice"=>2, "disable_condition"=>"ER_status == 2 && PR_status == 2", "lpv_impact"=>-0.8397}, + "1"=>{"variable"=>"Chemotherapy", "name"=>{"zh_tw"=>"化學治療", "en"=>"Chemotherapy"}, "is_num"=>0, "hint"=>{"zh_tw"=>"", "en"=>""}, "comment_text"=>{"zh_tw"=>"", "en"=>""}, "choice_fields"=>{"zh_tw"=>["否", "是"], "en"=>["No", "Yes"]}, "range"=>[], "right"=>0, "is_float"=>0, "revert_value"=>0, "map_values"=>"", "active_choice"=>2, "disable_condition"=>"", "lpv_impact"=>-0.4147}, + "2"=>{"variable"=>"Radiotherapy", "name"=>{"zh_tw"=>"放射治療", "en"=>"Radiotherapy"}, "is_num"=>0, "hint"=>{"zh_tw"=>"", "en"=>""}, "comment_text"=>{"zh_tw"=>"", "en"=>""}, "choice_fields"=>{"zh_tw"=>["否", "是"], "en"=>["No", "Yes"]}, "range"=>[], "right"=>0, "is_float"=>0, "revert_value"=>0, "map_values"=>"", "active_choice"=>2, "disable_condition"=>"", "lpv_impact"=>-0.3203}, + "3"=>{"variable"=>"Targeted_therapy", "name"=>{"zh_tw"=>"標靶治療", "en"=>"Targeted therapy"}, "is_num"=>0, "hint"=>{"zh_tw"=>"抗HER2治療", "en"=>""}, "comment_text"=>{"zh_tw"=>"", "en"=>""}, "choice_fields"=>{"zh_tw"=>["否", "是"], "en"=>["No", "Yes"]}, "range"=>[], "right"=>0, "is_float"=>0, "revert_value"=>0, "map_values"=>"", "active_choice"=>2, "disable_condition"=>"HER2_status != 1", "lpv_impact"=>-0.4687} + } field :form_result_is_right , :type=> Integer ,default: 0 - field :text_descibe ,type:Hash ,default:{"zh_tw"=>"歡迎使用台灣準備乳癌預後系統!
    本預測系統由台灣癌症登記資料庫2011至2015年間共90,841位乳癌病人所建立
    若要開始 請在下方輸入相關資訊","en"=>"Welcome to the Taiwan Breast Cancer Prediction System!
    The prediction system is constructed using clinical data from 90,841 breast cancer patients in the Taiwan Cancer Registry database between 2011 to 2015, and validated using clinical data from 49,374 breast cancer patients in the U.S.-based Surveillance, Epidemiology and End Results (SEER) database.
    To start, please select the information below."} + field :text_descibe ,type:Hash ,default: { + "zh_tw"=>"歡迎使用台灣準備乳癌預後系統!
    \r\n本預測系統由台灣癌症登記資料庫2011至2015年間共20,997位乳癌病人所建立
    \r\n並驗證美國流行病學癌症資料庫59,271位病人所建立 。
    \r\n若要開始 請在下方選擇相關資訊", + "en"=>"Welcome to the Taiwan Breast Cancer Prediction System!
    \r\nThe prediction system is constructed using clinical data from 90,841 breast cancer patients in the Taiwan Cancer Registry database between 2011 to 2015, and validated using clinical data from 49,374 breast cancer patients in the U.S.-based Surveillance, Epidemiology and End Results (SEER) database.
    \r\nTo start, please select the information below." + } field :small ,type:Hash ,default:{'font_size'=>"0.825em",'active'=>0} field :medium ,type:Hash ,default:{'font_size'=>"1em",'active'=>1} field :large ,type:Hash ,default:{'font_size'=>"1.25em",'active'=>0} - field :head_images_id ,type:Array , default: [BSON::ObjectId('5df62cfc8cd8924e79000009'), BSON::ObjectId('5df745a58cd8924491000006'), BSON::ObjectId('5df745a58cd8924491000007'), BSON::ObjectId('5df745a58cd8924491000008'), BSON::ObjectId('5df745a58cd8924491000009')] + field :head_images_id ,type:Array , default: [BSON::ObjectId('5df62cfc8cd8924e79000009'), BSON::ObjectId('5df745a58cd8924491000006'), BSON::ObjectId('5e7848c98cd8924f8d00004a'), BSON::ObjectId('5ea8f3e48cd892760b000011')] field :title_images_id ,type:Array , default: [BSON::ObjectId('5df87cd88cd8924491000036')] - field :title_texts ,type:Hash ,default:{'zh_tw'=>'華人癌症存活預測','en'=>'Asian breast cancer prediction'} - field :table_above_texts ,type:Hash ,default:{'zh_tw'=>"下表之分析為針對手術後病人,根據選定的術後治療,分別估計在第1年、3及5年的存活率。",'en'=>'The analysis is for women who had undergone surgery.The table shows the 1-, 3- and 5-year survival rates,based on the treatment you have selected.'} - field :text_above_texts ,type:Hash ,default:{'zh_tw'=>"此研究分析來自已接受根除性手術後之婦女所得之結果,根據您所輸入的資訊以及治療方式,在術後
    第{{years}}年,",'en'=>'The analysis is for women who had undergone surgery. Base on the information and the treatment you have selected, the predictions of survival status
    {{years}}'} - field :surgery_only_texts ,type:Hash ,default:{'zh_tw'=>'100 位只接受根除性手術的婦女中,有{{Surgery_only}}位婦女,術後{{surgery_year}}年仍為存活','en'=>'after surgery are as follows:
    {{Surgery_only}} out of 100 women treated with surgery only are alive at {{surgery_year}} years.'} - field :extra_texts ,type:Hash ,default:{'zh_tw'=>',此外','en'=>''} - field :extra_therapy_texts ,type:Hash ,default:{'zh_tw'=>'100 位在術後有接受{{extra_therapy}}的婦女中,有{{survival_num}}位婦女,術後{{surgery_year}}年仍為存活(多了{{Additional_Benefit}}位)','en'=>'{{survival_num}} out of 100 women treated with {{extra_therapy}} are alive (an extra {{Additional_Benefit}})'} - field :danger_texts ,type:Hash ,default:{'zh_tw'=>'請注意紅框的輸入資料是否符合要求!','en'=>'Please check whether input data in red blocks are correct!'} + field :title_texts ,type:Hash ,default: {"zh_tw"=>"華人癌症存活預測", "en"=>"Asian breast cancer prediction"} + field :table_above_texts ,type:Hash ,default: {"zh_tw"=>"下表之分析為針對手術後病人,根據選定的術後治療,分別估計在第1年、3 及5年的存活率。", "en"=>"The analysis is for women who had undergone surgery.The table shows the 1-, 3- and 5-year survival rates,based on the treatment you have selected."} + field :text_above_texts ,type:Hash ,default: {"zh_tw"=>"此研究分析來自已接受根除性手術後之婦女所得之結果,根據您所輸入的資訊以及治療方式,在術後
    第{{years}}年,", "en"=>"The analysis is for women who had undergone surgery. Base on the information and the treatment you have selected, the predictions of survival status
    {{years}}"} + field :surgery_only_texts ,type:Hash ,default: {"zh_tw"=>"100 位只接受根除性手術的婦女中,有{{Surgery_only}}位婦女,術後{{surgery_year}}年仍為存活", "en"=>"after surgery are as follows:
    {{Surgery_only}} out of 100 women treated with surgery only are alive at {{surgery_year}} years."} + field :extra_texts ,type:Hash ,default: {"zh_tw"=>",此外", "en"=>""} + field :extra_therapy_texts ,type:Hash ,default: {"zh_tw"=>"100 位在術後有接受{{extra_therapy}}的婦女中,有{{survival_num}}位婦女,術後{{surgery_year}}年仍為存活(多了{{Additional_Benefit}}位)", "en"=>"{{survival_num}} out of 100 women treated with {{extra_therapy}} are alive (an extra {{Additional_Benefit}})"} + field :danger_texts ,type:Hash ,default: {"zh_tw"=>"請注意紅框的輸入資料是否符合要求!", "en"=>"Please check whether input data in red blocks are correct!"} field :years ,type:Array ,default:[1,3,5] - field :texts_between_Result_and_result_block ,type:Hash ,default:{'zh_tw'=>'如果欲將預測結果應用於臨床上,請務必與您的主治醫師討論後再做最後決定。','en'=>'Please note that the patients need to consult with their medical doctors before making any decision.'} + field :texts_between_Result_and_result_block ,type:Hash ,default: {"zh_tw"=>"如果欲將預測結果應用於臨床上,請務必與您的主治醫師討論後再做最後決定。", "en"=>"Please note that the patients need to consult with their medical doctors before making any decision."} #field :image_uploader ,type:Object - scope :can_display, ->{where(:is_hidden=>false,:is_preview => false).any_of({:postdate.lt=>Time.now, :deadline.gt=>Time.now},{:postdate.lt=>Time.now, :deadline=>nil}).order_by([:is_top, :desc],[:postdate, :desc])} - scope :is_approved, ->{where(:approved => true)} + field :prediction_formula , type: String ,default: "lpv = ((age1-0.7276655)*(-10.87)+(age2+0.4540707)*8.968+(size1-0.643632)*0.7678+(nposit-1.346932)*0.5339+ + grade_2*0.4795+grade_3*0.818+subtype_HER2*0.1806+subtype_triple*0.6457+pstage_2*0.5311+ + pstage_3*1.134+pstage_4*2.172+lvi_yes*0.3321-0.04+chemo*(-0.4147)+radio*(-0.3203)+hormone*(-0.8397)+target*(0.3321) +)" + field :years_settings , type: Array , default: ["exp(-0.001476145)^( exp(lpv) )","exp(-0.01261639)^( exp(lpv) )","exp(-0.02519608)^( exp(lpv) )"] + field :tmp_years_settings , type: Array , default: [] + field :tmp_years_settings_for_ruby , type: Array , default: [] + field :hidden_variables, type: String, default: "age1 = (age / 100.0) ^ (0.5) + age2 = age1 * log(age / 100.0) + size1 = log(size / 10.0) + ratio = (lymph_nodes_examined == 0 ? 0 : (1.0 * lymph_nodes_positive / lymph_nodes_examined)) + ratio = (ratio > 1 ? 1 : ratio) + T4 = (tumor_direct_extension == 1) + T1 = !T4 && (size <= 20) + T2 = !T4 && !T1 && (size > 20 && size <= 50) + T = (T4 ? 'T4' : (T1 ? 'T1' : (T2 ? 'T2' : 'T3'))) + N0 = (lymph_nodes_positive == 0) + N1_or_N1mi = !N0 && (lymph_nodes_positive >= 1 && lymph_nodes_positive <= 3) + N1 = N1_or_N1mi && micrometastasis != 1 + N1mi = N1_or_N1mi && micrometastasis == 1 + N2 = !N0 && !N1_or_N1mi && (lymph_nodes_positive <= 9) + N = (N0 ? 'N0' : (N1 ? 'N1' : (N1mi ? 'N1mi' : (N2 ? 'N2' : 'N3')))) + M = (Distant_Metastasis != 1) ? 'M0' : 'M1' + pstage = (M == 'M1' ? 4 : ((T == 'T1' && (N == 'N0' || N == 'N1mi')) ? 1 : (((T == 'T2' || T == 'T3') && (N == 'N0')) || ((T == 'T1' || T == 'T2') && (N == 'N1')) ? 2 : 3)) ) + nposit = ((ratio + 0.1) / 0.1) ^ 0.5 + grade_2 = (grade == 2 || grade == 4) ? 1 : 0 + grade_3 = (grade == 3) ? 1 : 0 + subtype_1 = (ER_status != 2 || PR_status != 2) && (HER2_status != 1) + subtype_2 = !subtype_1 && (HER2_status == 1) + subtype_3 = !subtype_1 && !subtype_2 && (ER_status == 2 && PR_status == 2 && HER2_status != 1) + subtype_HER2 = subtype_2 ? 1 : 0 + subtype_triple = subtype_3 ? 1 : 0 + pstage_2 = (pstage == 2) ? 1 : 0 + pstage_3 = (pstage == 3) ? 1 : 0 + pstage_4 = (pstage == 4) ? 1 : 0 + lvi_yes = (lvi == 1) ? 1 : 0 + chemo = (Chemotherapy == 2) ? 1 : 0 + radio = (Radiotherapy == 2) ? 1 : 0 + hormone = (hormone_therapy == 2) ? 1 : 0 + target = (Targeted_therapy == 2) ? 1 : 0 + " + field :fix_hidden_variables, type: Array, default: [] + field :tmp_hidden_variables_for_ruby, type: String, default: "" + field :tmp_hidden_variables_for_js, type: String, default: "" + field :lpv_calc, type: Hash, default: {} #for js code + field :tmp_lpv_ruby_code, type: String, default: "" + field :tmp_lpv_variables, type: Array, default: [] + field :mapping_data_from_csv , type: String ,default: "" + field :all_variables, type: Array, default: [] + field :treatment_method, type: Array, default: ['Surgery_only'] + field :treatment_method_active_indices, type: Array, default: [1] + field :result_table, type: String, default: "", localize: true + field :result_text, type: String, default: "", localize: true + field :therapy_lpv, type: Array, default: [0] #before_create :set_expire - def update_user - User.find(update_user_id) rescue nil + before_save do + self.form_show.each do |num,property| + property[:need_map_values] = (property[:map_values].class == Array && property[:choice_fields].class == Array && property[:map_values].length == property[:choice_fields].length) ? 1 : 0 + end + result_keys = [] + self.form_show.each do |num,property| + variable_name = property[:variable] + if variable_name.present? + result_keys << variable_name + end + end + self.form_show_in_result.each do |num,property| + variable_name = property[:variable] + if variable_name.present? + result_keys << variable_name + end + end + mapping_data = JSON.parse(self.mapping_data_from_csv) rescue {} + if self.advance_mode && mapping_data.present? + mapping_data.each do |k,v| + result_keys += (v.keys rescue []) + end + end + result_keys = result_keys.uniq + self.all_variables = result_keys + formula = text_to_math(self.prediction_formula) + tmp_hidden_variables = text_to_math(self.hidden_variables) + result_keys.each do |k| + formula = formula.gsub(/(\A|[^\w])#{k}($|[^\w])/){|f| "#{$1}result[\"#{k.strip}\"]#{$2}" } + tmp_hidden_variables = tmp_hidden_variables.gsub(/(\A|[^\w])#{k}($|[^\w])/){|f| "#{$1}result[\"#{k.strip}\"]#{$2}" } + end + self.tmp_hidden_variables_for_js = tmp_hidden_variables.rstrip.gsub(/\n\s+/,"\n ").gsub("\n",";\n") + ";" + self.fix_hidden_variables = [] + self.tmp_hidden_variables_for_ruby = tmp_hidden_variables.split(/^([^=]+)=([^=])/).select{|s| s.present?}.each_slice(2).map do |a,b| + a = a.strip + self.fix_hidden_variables << a + if b + puts ("result[\"#{a}\"]=" + b) + ("result[\"#{a}\"]=" + b) + else + a + end + end.join("\n") + self.fix_hidden_variables = self.fix_hidden_variables.uniq + formula = formula.split(/^([^=]+)=([^=])/).select{|s| s.present?}.each_slice(2).map do |a,b| + a = a.strip + if b + ("result[\"#{a}\"]=" + b) + else + a + end + end.join("\n") + self.fix_hidden_variables.each do |v| + formula = formula.gsub(/(\A|[^\w\"])#{v}($|[^\w])/){|f| "#{$1}result[\"#{v.strip}\"]#{$2}"} + self.tmp_hidden_variables_for_ruby = self.tmp_hidden_variables_for_ruby.gsub(/(\A|[^\w\"])#{v}($|[^\w])/){|f| "#{$1}result[\"#{v.strip}\"]#{$2}"} + end + self.tmp_lpv_ruby_code = formula + formula_variables = formula.enum_for(:scan,/([^\=\(\)]+)?=[^=]/).map {|x| x[-1] }.compact.map{|s| s.strip[8..-3]} + self.tmp_lpv_variables = formula_variables + self.tmp_years_settings = self.years_settings.map do |s| + text_to_math(s) + end + self.tmp_years_settings_for_ruby = self.tmp_years_settings.clone + formula_variables.each do |variable_name| + self.tmp_years_settings_for_ruby = self.tmp_years_settings_for_ruby.map do |y| + y.gsub(variable_name,"result[\"#{variable_name}\"]") + end + end + self.treatment_method = ['Surgery_only'] + self.form_show_in_result.values.each do |choice| + variable = choice["variable"] + if variable.present? + self.treatment_method << variable + end + end + tmp_table_translations = {} + tmp_text_translations = {} + @years = self.years + @head_name = ['Treatment','Additional_Benefit','Overall_Survival'] + # @head_name = ['Treatment','Overall_Survival'] + @table_head = @head_name.map{|name| I18n.t('cancerpredict.table.'+name)} + @therapy_names = self.treatment_method + I18n.available_locales.each do |locale| + I18n.with_locale(locale) do + @therapy_choices = [I18n.t('cancerpredict.table.Surgeryonly')] + self.form_show_in_result.values.each{|choice| @therapy_choices.push choice["name"][locale]} + tmp_table = "#{I18n.t("cancerpredict.table.table")}
    " + tmp_table += '

    '+self.table_above_texts[locale].to_s+'

    ' + tmp_table += (''+(locale.to_s == 'zh_tw' ? '第' : '')+'') + @years.each{|year| tmp_table += ('')} + tmp_table += (''+(locale == 'zh_tw' ? '年' : '')+'') + tmp_table += '
    ' + head + '
    ' + ((index == 0) ? (((i==0)? '' : '+') + choice) : '-') + '
    ' + @table_head.each_with_index{|head,index| tmp_table += ('')} + tmp_table += '' + @therapy_choices.each_with_index do |choice,i| + tmp_table += '' + @table_head.each_with_index do |head,index| + tmp_table += ('') + end + tmp_table += '' + end + tmp_table_translations[locale] = tmp_table + @texts = self.text_above_texts[locale].to_s.gsub('
    ','
    ').gsub('{{Surgery_only}}','') + @texts = @texts.split('{{years}}') + @texts.delete('') + tmp_text = "#{I18n.t("cancerpredict.table.text")}
    " + tmp_text += (''+@texts[0]) + @years.each{|year| tmp_text += ('')} + if @texts.count > 1 + tmp_text += (@texts[1]+'') if @texts.count > 1 + else + tmp_text += '
    ' + end + if !self.surgery_only_texts[locale].blank? + @surgery_only_texts = self.surgery_only_texts[locale] + @surgery_only_texts.insert(0,'

    ') + @surgery_only_texts = @surgery_only_texts.gsub('{{Surgery_only}}','') + @surgery_only_texts = @surgery_only_texts.gsub('{{surgery_year}}',''+@years[-1].to_s+'') + @surgery_only_texts += '' + else + @surgery_only_texts = '' + end + tmp_text += @surgery_only_texts + tmp_text += ''+self.extra_texts[locale]+'

    ' + tmp_text_translations[locale] = tmp_text + end + end + self.result_table_translations = tmp_table_translations + self.result_text_translations = tmp_text_translations + self.treatment_method_active_indices = [1] + self.form_show_in_result.each do |num, property| + v = property[:active_choice] + if v.present? + self.treatment_method_active_indices << (v - 1) + else + self.treatment_method_active_indices << 1 + end + end + self.lpv_calc = get_years_settings_dict + self.generate_eval_formula end - def update_user=(user) - self.update_user_id = user.id + def generate_eval_formula + eval_hidden_variables = "def eval_hidden_variables(result); #{self.tmp_hidden_variables_for_ruby}; end" + CancerpredictsController.module_eval(eval_hidden_variables) + eval_formula = "def eval_formula(result); #{self.tmp_lpv_ruby_code}; end" + CancerpredictsController.module_eval(eval_formula) end - def email_members - MemberProfile.find(self.email_member_ids) rescue [] + def generate_jscode + js_code = "var map_values , mapping_hash , temp_index ,temp_value , index , closest_value;\r\n" + mapping_data_from_csv = JSON.parse(self.mapping_data_from_csv) rescue {} + tmp_hash = self.form_show.values + self.form_show_in_result.values + tmp_hash.each do |property| + @variable = property[:variable] + if @variable.present? + if property[:is_num] == 1 + js_code += " result['#{@variable}'] = Number(result_json['#{@variable}']);\r\n" + elsif property[:choice_fields].present? + if !(self.advance_mode) + js_code += " result['#{@variable}'] = Number(result_json['#{@variable}']);\r\n" + else + if property[:need_map_values] == 1 + js_code += " map_values = #{property[:map_values]};\r\n" + js_code += " result['#{@variable}'] = map_values[Number(result_json['#{@variable}'']) - 1];\r\n" + else + if property[:revert_value] != 1 + js_code += " result['#{@variable}'] = Number(result_json['#{@variable}']) - 1;\r\n" + else + js_code += " result['#{@variable}'] = (#{property[:choice_fields].length} - Number(result_json['#{@variable}']));\r\n" + end + end + end + end + if self.advance_mode && property[:cancer_predict_mapping_file].present? + if (mapping_data_from_csv != {} && !mapping_data_from_csv[@variable].blank?) + js_code += " mapping_hash = mapping_data_from_csv['#{@variable}'];\r\n" + js_code += " temp_index = 0;\r\n" + js_code += " temp_value = result[#{@variable}];\r\n" + js_code += " index = 0; + $.each(mapping_hash,function(k,v){ + if( i == 0 ){ + var index_val = v.indexOf(temp_value); + if( index_val != -1 ){ + temp_index = index_val; + }else{ + closest_value = v.get_nearest_value(temp_value); + temp_index = v.indexOf(closest_value) + } + } + result[k] = v[temp_index]; + index++; + });\r\n" + end + end + end + end + js_code += "\n Object.keys(result).forEach(function(k){ + if(Number.isNaN(result[k])){ + result[k] = 0; + } + })" + js_code += "\n #{self.tmp_hidden_variables_for_js}" + formula = text_to_math(self.prediction_formula) + self.all_variables.each do |k| + formula = formula.gsub(/#{k}?(-|\+|\*|\s|\=)/){ "result[\"#{k.strip}\"]#{$1}" } + end + formula_variables = self.tmp_lpv_variables.map{|v| v} + js_code = "\n function calculate_first_lpv(result_json){ + result = {}; + #{js_code} + try{ + #{formula.gsub(/\s{2,10}/," ").gsub("\n","\n ")} + }catch(e){console.log(e)}; + result['lpv_variable'] = {}; + #{formula_variables.map{|v| "result['lpv_variable']['#{v}'] = #{v};"}.join("\n ") } + result['lpv'] = #{formula_variables.count == 0 ? 0 : formula_variables.last}; + result['lpv_variable']['lpv'] = result['lpv']; + return result; + }; + function calculate_and_change_result_value(obj){ + obj.servive_ratio_arr = []; + for(var i = 0;i true, :top_end_date.ne => nil, :top_end_date.lt => Time.now).each do |b| - b.is_top = false - b.top_end_date = nil - b.save + def auto_write_predict_js + js_codes = generate_jscode + module_app_path = Pathname.new(File.expand_path(__dir__)).dirname.dirname.to_s + save_path = module_app_path + '/app/assets/javascripts/cancer_predict.js' + file_texts = File.read(save_path) + need_write = false + str1 = "/* auto add start */" + index1 = file_texts.index(str1) + str2 = "/* auto add end */" + index2 = file_texts.index(str2) + if (!index1.nil? && !index2.nil?) + file_texts = replace_str_with_idx(file_texts, index1 + str1.length, index2 - 1, js_codes) + need_write = true + end + str3 = "/*lpv_calc_formula_start*/" + index3 = file_texts.index(str3) + str4 = "/*lpv_calc_formula_end*/" + index4 = file_texts.index(str4) + if (!index3.nil? && !index4.nil?) + file_texts = replace_str_with_idx(file_texts, index3 + str3.length, index4 - 1, self.lpv_calc.to_json.gsub("@",".") + ';') + need_write = true + end + tmp_disable_jscodes = "" + str5 = "/*disable_condition start*/" + index5 = file_texts.index(str5) + str6 = "/*disable_condition end*/" + index6 = file_texts.index(str6) + self.form_show_in_result.each do |num,property| + if property[:disable_condition].present? + tmp = property[:disable_condition].clone + self.all_variables.each do |k| + tmp = tmp.gsub(/(\A|[^\w])#{k}($|[^\w])/){|f| "#{$1}post_json[\"#{k}\"]#{$2}" } + end + variable = property[:variable] + tmp_disable_jscodes += "\n if(#{tmp}){ + $('##{variable} .cancer_table_btn').attr('disabled','disabled'); + $('[for=\"#{variable}\"]').css('color','rgb(204, 204, 204)'); + }else{ + $('##{variable} .cancer_table_btn').removeAttr('disabled'); + $('[for=\"#{variable}\"]').css('color',''); + }" + end + end + if (!index5.nil? && !index6.nil?) + tmp_disable_jscodes += "\n\t\t\t" + file_texts = replace_str_with_idx(file_texts, index5 + str5.length, index6 - 1, tmp_disable_jscodes) + need_write = true + end + str7 = "/*therapy_lpv start*/" + index7 = file_texts.index(str7) + str8 = "/*therapy_lpv end*/" + index8 = file_texts.index(str8) + self.therapy_lpv = [0] + self.form_show_in_result.each do |num,property| + if property[:lpv_impact].present? + self.therapy_lpv << property[:lpv_impact] + else + self.therapy_lpv << 0 + end + end + if (!index7.nil? && !index8.nil?) + file_texts = replace_str_with_idx(file_texts, index7 + str7.length, index8 - 1, self.therapy_lpv.to_s + ';') + need_write = true + end + if need_write + File.write(save_path,file_texts) end end + def get_years_settings_dict + lpv_variable_name = (prediction_formula.include?("=") ? prediction_formula.split("=")[0].strip : "" rescue "") + res = self.years.map.with_index do |y, i| + tmp_formula = self.tmp_years_settings[i] + if lpv_variable_name.present? + tmp_formula = tmp_formula.gsub(lpv_variable_name, "lpv_current") + else + tmp_formula = tmp_formula.gsub("lpv", "lpv_current") + end + [y.to_s.sub(".","@"), tmp_formula] + end + res.to_h + end end \ No newline at end of file diff --git a/app/models/cancerpredictrecord.rb b/app/models/cancerpredictrecord.rb index a073234..85ecc2f 100644 --- a/app/models/cancerpredictrecord.rb +++ b/app/models/cancerpredictrecord.rb @@ -16,6 +16,10 @@ class Cancerpredictrecord scope :is_approved, ->{where(:approved => true)} before_save :set_submit_times def set_submit_times - self.submit_time = Cancerpredictrecord.where(:title=> "cancerpredict").length + 1 + self.submit_time = Cancerpredictrecord.all.count + 1 + end + def check_missing_data + missing_keys = self.names.keys - self.result.keys rescue [] + missing_keys.each{|k| self.result[k] = "" } end end \ No newline at end of file diff --git a/app/views/admin/cancerpredicts/_export_cancer_tool_record.xlsx.axlsx b/app/views/admin/cancerpredicts/_export_cancer_tool_record.xlsx.axlsx index 8fe89b1..cc17054 100644 --- a/app/views/admin/cancerpredicts/_export_cancer_tool_record.xlsx.axlsx +++ b/app/views/admin/cancerpredicts/_export_cancer_tool_record.xlsx.axlsx @@ -17,10 +17,11 @@ wb.add_worksheet(name: "school_class") do |sheet| temp_row << result.created_at.to_s result.result.each do |key,value| if key != "locale" - if result.values[key][I18n.locale.to_s].length == 0 + if (result.values[key][I18n.locale.to_s].length == 0 rescue true) temp_row << value else - temp_row << (result.values[key][I18n.locale.to_s][value.to_i-1] rescue value) + v = result.values[key][I18n.locale.to_s][value.to_i-1] rescue nil + temp_row << (v.nil? ? value : v) end end end diff --git a/app/views/admin/cancerpredicts/_form.html.erb b/app/views/admin/cancerpredicts/_form.html.erb index c789e22..9a45a21 100644 --- a/app/views/admin/cancerpredicts/_form.html.erb +++ b/app/views/admin/cancerpredicts/_form.html.erb @@ -1,472 +1,37 @@ -<% content_for :page_specific_css do %> - <%= stylesheet_link_tag "lib/main-forms" %> - <%= stylesheet_link_tag "lib/fileupload" %> - <%= stylesheet_link_tag "lib/main-list" %> -<% end %> -<% content_for :page_specific_javascript do %> - <%= javascript_include_tag "lib/bootstrap-fileupload" %> - <%= javascript_include_tag "lib/bootstrap-datetimepicker" %> - <%= javascript_include_tag "lib/datetimepicker/datetimepicker.js" %> - <%= javascript_include_tag "lib/file-type" %> - <%= javascript_include_tag "lib/module-area" %> -<% end %> - - -
    - - - - - -
    - - -
    - - -
    - -
    - <%= select_category(f, @module_app) %> -
    -
    - - -
    - -
    - <%= f.datetime_picker :postdate, :no_label => true, :new_record => @bulletin.new_record?, :data=>{"picker-type" => "range", "range" => "start"} %> -
    -
    - -
    - -
    - <%= f.datetime_picker :deadline, :no_label => true, :new_record => @bulletin.new_record?, :data=>{"picker-type" => "range", "range" => "end"} %> -
    -
    - -
    - <%= f.label :is_external_link, t("announcement.is_external_link"), :class => "control-label muted" %> -
    - <%= f.check_box :is_external_link %> -
    -
    - - - -
    - - -
    - - -
    - -
    - - - -
    -
    - <% if !@bulletin.is_top? && !AnnouncementSetting.check_limit_for_user((@bulletin.new_record? ? current_user.id : @bulletin.create_user_id)) %> - Top limit has been reached. The bulletin wont be marked as top even if you click on it. - <% end %> -
    -
    -
    " data-for="is_top"> - -
    - <%= f.datetime_picker :top_end_date, :no_label => true, :new_record => @bulletin.new_record? %> -
    -
    - -
    - <%# end %> - - -
    -
    - - <%= select_tags(f, @module_app) %> -
    -
    - - -
    - - -
    - -
    -
    -
    - <% if @bulletin.image.file %> - <%= image_tag @bulletin.image %> - <% else %> - - <% end %> -
    -
    - - <%= t(:select_image) %> - <%= t(:change) %> - <%= f.file_field :image %> - - <%= t(:cancel) %> -
    - -
    -
    -
    -
    - <% @site_in_use_locales.each do |locale| %> - <%= f.fields_for :image_description_translations do |f| %> -
    - -
    - <%= f.text_field locale, value: (@bulletin.image_description_translations[locale.to_s] rescue nil) %> -
    -
    - <% end %> - <% end %> - -
    - - - -
    - - -
    - -
    - - - -
    - <%= render partial: 'admin/member_selects/email_selection_box', locals: {field: 'bulletin[email_member_ids][]', email_members: @bulletin.email_members} %> -
    -
    -
    -
    - -
    -
    - <%= "#{t("announcement.other_mailaddress")}(#{t("announcement.other_mailaddress_note")})"%> - <%= f.text_area :other_mailaddress, :class=>"span12", :cols=>"25", :rows=>"10" %> -
    -
    -
    - -
    -
    - -
    - <%= f.datetime_picker :email_sentdate, :no_label => true %> -
    -
    -
    - - <% if (@bulletin.email.is_sent rescue false) %> -
    -
    - -
    - -
    -
    -
    - <% end %> - -
    - -
    - - - - - - -
    - - <% @site_in_use_locales.each_with_index do |locale, i| %> - -
    "> - - -
    - -
    - <%= f.fields_for :title_translations do |f| %> - <%= f.text_field locale, class: "input-block-level", placeholder: t(:title), value: (@bulletin.title_translations[locale] rescue nil) %> - <% end %> -
    -
    - - -
    - -
    -
    - <%= f.fields_for :subtitle_translations do |f| %> - <%= f.text_area locale, rows: 2, class: "input-block-level", value: (@bulletin.subtitle_translations[locale] rescue nil) %> - <% end %> -
    -
    -
    - - -
    - -
    -
    - <%= f.fields_for :text_translations do |f| %> - <%= f.cktext_area locale, rows: 5, class: "input-block-level", :value => (@bulletin.text_translations[locale] rescue nil) %> - <% end %> -
    -
    -
    - -
    - - <% end %> - - -
    - -
    - - - <% if @bulletin && !@bulletin.bulletin_links.blank? %> -
    - <% @bulletin.bulletin_links.each_with_index do |bulletin_link, i| %> - <%= f.fields_for :bulletin_links, bulletin_link do |f| %> - <%= render :partial => 'form_link', :object => bulletin_link, :locals => {:f => f, :i => i} %> - <% end %> - <% end %> -
    -
    - <% end %> - - -
    -
    -

    - <%= hidden_field_tag 'bulletin_link_field_count', @bulletin.bulletin_links.count %> - <%= t(:add) %> -

    - -
    -
    - - -
    - -
    - - - <% if @bulletin && !@bulletin.bulletin_files.blank? %> -
    - <% @bulletin.bulletin_files.each_with_index do |bulletin_file, i| %> - <%= f.fields_for :bulletin_files, bulletin_file do |f| %> - <%= render :partial => 'form_file', :object => bulletin_file, :locals => {:f => f, :i => i} %> - <% end %> - <% end %> -
    -
    - <% end %> - - -
    -
    -

    - <%= hidden_field_tag 'bulletin_file_field_count', @bulletin.bulletin_files.count %> - <%= t(:add) %> -

    - -
    -
    - -
    - -
    - - -
    - <%= get_referer_url[:action] rescue "" %> - <%= f.submit t('submit'), class: 'btn btn-primary' %> - - <%= button_tag t("preview"), id: "button_for_preview", name: "commit", class: 'btn', type: :button %> - <%= link_to t('cancel'), admin_announcements_path, :class=>"btn" %> -
    - - - - -<% if !@module_app.tags.empty? %> - -<% end %> -<% content_for :page_specific_javascript do %> - -<% end %> \ No newline at end of file +
    + + + <% keys.each do |key| %> + + <%end%> + + \ No newline at end of file diff --git a/app/views/admin/cancerpredicts/_form_file.html.erb b/app/views/admin/cancerpredicts/_form_file.html.erb index 981ddf4..4b76f25 100644 --- a/app/views/admin/cancerpredicts/_form_file.html.erb +++ b/app/views/admin/cancerpredicts/_form_file.html.erb @@ -1,69 +1,33 @@ -<% if form_file.new_record? %> +<% if form_file.nil? %>
    <% else %>
    - <% if form_file.file.blank? %> + <% if form_file.temp_file.blank? %> <%= t(:no_file) %> <% else %> - <%= link_to content_tag(:i) + form_file.file_identifier, form_file.file.url, {:class => 'file-link file-type', :target => '_blank', :title => form_file.file_identifier} %> + <%= link_to content_tag(:i) + form_file.file_identifier, form_file.temp_file.url, {:class => 'file-link file-type', :target => '_blank', :title => form_file.file_identifier} %> <% end %> <% end %> +<%= f.fields_for key do |f|%>
    - - - <% @site_in_use_locales.each_with_index do |locale, i| %> - <%= locale %>"> - <%= f.fields_for :title_translations do |f| %> - <%= f.text_field locale, :class => "input-medium", placeholder: t(:alternative), :value => (form_file.title_translations[locale] rescue nil) %> - <% end %> - - <% end %> - - - <% @site_in_use_locales.each_with_index do |locale, i| %> - <%= locale %>"> - <%= f.fields_for :description_translations do |f| %> - <%= f.text_field locale, :class => "input-medium", placeholder: t(:description), :value => (form_file.description_translations[locale] rescue nil) %> - <% end %> - - <% end %> - - - - - - <%= hidden_field_tag 'bulletin[bulletin_files_attributes][0][choose_lang][]', '' %> - - <% if form_file.new_record? %> - - - - <% else %> + <% if !form_file.nil? %> - <%= f.hidden_field :id %> + <%= f.hidden_field :id,:value=>(form_file.id) %> <%= f.hidden_field :_destroy, :value => nil, :class => 'should_destroy' %> <% end %>
    -
    \ No newline at end of file +
    +<% end %> \ No newline at end of file diff --git a/app/views/admin/cancerpredicts/index.html.erb b/app/views/admin/cancerpredicts/index.html.erb index 8b5548b..5935c71 100644 --- a/app/views/admin/cancerpredicts/index.html.erb +++ b/app/views/admin/cancerpredicts/index.html.erb @@ -1,5 +1,79 @@ <%= stylesheet_link_tag "lib/fileupload"%> -<%= javascript_include_tag 'lib/bootstrap-fileupload' %> +<%= stylesheet_link_tag "lib/togglebox"%> +<% content_for :page_specific_javascript do %> + <%= javascript_include_tag "lib/bootstrap-fileupload" %> + <%#= javascript_include_tag "lib/bootstrap-datetimepicker" %> + <%#= javascript_include_tag "lib/datetimepicker/datetimepicker.js" %> + <%= javascript_include_tag "lib/file-type" %> + <%= javascript_include_tag "lib/module-area" %> + <%= javascript_include_tag "form" %> +<% end %> + + +
    <%=form_for @form_to_show ,:url=>{:controller=>"cancerpredicts" ,:action=>"edit"} do |form|%> <%= t('cancerpredict.title') %> @@ -154,13 +228,28 @@ <%end%> <%end%> <%end%> + <%= t('cancerpredict.module_mode') %> +
    +
    + +
    + +
    +
    +
    <%= t('cancerpredict.Input_fields') %>
    -
    ' + head + '
    ' + ((index == 0) ? (((i==0)? '' : '+') + choice) : '-') + '
    + <% if key.include? "_file" %> + <%= render :partial => 'form_file', :object => (CancerPredictMappingFile.where(:id=> property[key]).first rescue nil), :locals => {:f => make_fields, :key=>key} %> + <% else %> + <% value = property[key] %> + <% value_type = Cancerpredictfields::FIELDINFO[key] %> + <% value = "[]" if property == {} && value_type == 'Array' %> + <% is_localized = Cancerpredictfields::NonLoclaized.exclude?(key) %> + <% @value= value %> + <% if is_localized %> + <% @disp_value = @value[I18n.locale.to_s] rescue "" %> + <%else%> + <% @disp_value = @value %> + <%end%> + <% field_type = ((value_type == 'String' || value_type == 'Array' || value_type == 'Float') ? "text_field" : value_type) %> + <% if value_type == 'Fixnum' %> + <% if @value == 1%> + <%= make_fields.check_box key,{:checked=>true,:class=>"checkbox",:style=>"float:left;"}%> + <% else%> + <%= make_fields.check_box key,{:checked=>false,:class=>"checkbox",:style=>"float:left;"}%> + <%end%> + <% elsif is_localized %> + <%=make_fields.fields_for I18n.locale.to_s do |locale_fields|%> + <%= locale_fields.send(field_type, key,{:value=>@disp_value}) %> + <%end%> + <% else %> + <%= make_fields.send(field_type, key,{:value=>@disp_value})%> + <%end%> + <%end%> + <%= make_fields.hidden_field :old_num,:value=>num.to_s %>
    +
    + <% keys = Cancerpredictfields::FIELDINFO.keys - Cancerpredictfields::TherapyOnly %> - <% @form_to_show.form_show.values[1].each do |key,vlaue|%> - + + + <% keys.each do |key|%> + <%end%> @@ -168,34 +257,14 @@ <%= form.fields_for :form_show do |formfield|%> <% @form_to_show.form_show.each do |num,property| %> <%=formfield.fields_for num.to_s do |make_fields|%> - - <% property.each do |key,value|%> - <% @value= value %> - <% if @value.class == BSON::Document || @value.class == Hash %> - <% @disp_value = @value[I18n.locale.to_s] rescue "" %> - <%else%> - <% @disp_value = @value %> - <%end%> - <% if @value.class == Fixnum %> - <% if @value == 1%> - - <% else%> - - <%end%> - <% elsif @value.class == BSON::Document || @value.class == Hash %> - <%=make_fields.fields_for I18n.locale.to_s do |locale_fields|%> - - <%end%> - <% else %> - - <%end%> - <%end%> - + <%= render :partial => 'form', :locals=>{:make_fields=>make_fields,:property=>property,:num=>num,:keys => keys} %> <%end%> <%end%> <%end%>
    <%=key%><%=t("cancerpredict.table.#{key}")%>
    <%= make_fields.check_box key,{:checked=>true,:class=>"checkbox",:style=>"float:left;"}%><%= make_fields.check_box key,{:checked=>false,:class=>"checkbox",:style=>"float:left;"}%><%= locale_fields.text_field key,{:value=>@disp_value}%><%= make_fields.text_field key,{:value=>@disp_value}%>
    + +
    <%=t('cancerpredict.table.Results')%>
    @@ -217,52 +286,189 @@ <% end %>
    <% end %> - +
    - <% @form_to_show.form_show_in_result.values[1].each do |key,vlaue|%> - - <%end%> + + + <% keys = Cancerpredictfields::TherapyFields %> + <% keys.each do |key,vlaue|%> + + <%end%> <%= form.fields_for :form_show_in_result do |formfield|%> <% @form_to_show.form_show_in_result.each do |num,property| %> <%=formfield.fields_for num.to_s do |make_fields|%> - - <% property.each do |key,value|%> - <% @value= value %> - <% if @value.class == BSON::Document || @value.class == Hash %> - <% @disp_value = @value[I18n.locale.to_s] rescue "" %> - <%else%> - <% @disp_value = @value %> - <%end%> - <% if @value.class == Fixnum %> - <% if @value == 1%> - - <% else%> - - <%end%> - <% elsif @value.class == BSON::Document || @value.class == Hash %> - <%=make_fields.fields_for I18n.locale.to_s do |locale_fields|%> - - <%end%> - <% else %> - - <%end%> - <%end%> - + <%= render :partial => 'form', :locals=>{:make_fields=>make_fields,:property=>property,:num=>num,:keys => Cancerpredictfields::TherapyFields} %> <%end%> <%end%> <%end%>
    <%=key%><%=t("cancerpredict.table.#{key}")%>
    <%= make_fields.check_box key,{:checked=>true,:class=>"checkbox",:style=>"float:left;"}%><%= make_fields.check_box key,{:checked=>false,:class=>"checkbox",:style=>"float:left;"}%><%= locale_fields.text_field key,{:value=>@disp_value}%><%= make_fields.text_field key,{:value=>@disp_value}%>
    + +
    + <%=t('cancerpredict.table.calculate_settings')%> +
    +
    +
    + +
    +
    + <%= form.text_area :hidden_variables, :rows=>"5", :style=> 'width: 100%;font-family: sans-serif;' %> +
    +
    +
    +
    +
    + +
    +
    + <%= form.text_area :prediction_formula, :rows=>"5", :style=> 'width: 100%;font-family: sans-serif;' %> +
    +
    +
    + <% years = @form_to_show.years %> + <% years.each_with_index do |year,i| %> +
    +
    + +
    +
    + +
    +
    + <% end %> +
    <%=form.submit "#{t(:updatefont)}",{:id=>"updatebtn"}%> <%end%> \ No newline at end of file diff --git a/app/views/admin/cancerpredicts/showSubmit.html.erb b/app/views/admin/cancerpredicts/showSubmit.html.erb index d15ede6..ecde224 100644 --- a/app/views/admin/cancerpredicts/showSubmit.html.erb +++ b/app/views/admin/cancerpredicts/showSubmit.html.erb @@ -36,7 +36,7 @@ <% if result.values[key][I18n.locale.to_s].length == 0 %> <%= value.to_s %> <% else %> - <%= result.values[key][I18n.locale.to_s][value.to_i-1] rescue value %> + <% v = result.values[key][I18n.locale.to_s][value.to_i-1] rescue nil %><%= v.nil? ? value : v %> <% end %> <% end %> <%end%> diff --git a/cancerpredict.gemspec b/cancerpredict.gemspec index 6e59fc2..f228eb5 100644 --- a/cancerpredict.gemspec +++ b/cancerpredict.gemspec @@ -1,37 +1,40 @@ # -*- encoding: utf-8 -*- # stub: cancerpredict 0.0.1 ruby lib -insert_flag = 0 -app_path = File.expand_path(__dir__) -template_path = ENV['PWD'] + '/app/templates' -all_template = Dir.glob(template_path+'/*/') -puts 'copying module' -check_texts = '<%= javascript_include_tag "//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.2/js/bootstrap.min.js"%>' -edit_texts = '<%= javascript_include_tag "//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"%>' -all_template.each do |folder| - if !folder.include?('mobile') - begin - if folder.split('/')[-1] != 'mobile' - begin - system ('cp -r '+ app_path + '/modules/. ' + folder+'/modules/.') - puts "finish copy module cancerpredict to #{folder}" - rescue - puts 'error copy' +bundle_update_flag = ARGV[0]=='update' || ARGV[0]=='install' +if bundle_update_flag + insert_flag = 0 + app_path = File.expand_path(__dir__) + template_path = ENV['PWD'] + '/app/templates' + all_template = Dir.glob(template_path+'/*/') + puts 'copying module' + check_texts = '<%= javascript_include_tag "//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.2/js/bootstrap.min.js"%>' + edit_texts = '<%= javascript_include_tag "//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"%>' + all_template.each do |folder| + if !folder.include?('mobile') + begin + if folder.split('/')[-1] != 'mobile' + begin + system ('cp -r '+ app_path + '/modules/. ' + folder+'/modules/.') + puts "finish copy module cancerpredict to #{folder}" + rescue + puts 'error copy' + end end + texts = File.read(folder+'partial/_head.html.erb') + insert_flag = 0 + if texts.include?(check_texts) + texts = texts.gsub(check_texts,edit_texts) + insert_flag = 1 + end + if insert_flag == 1 + puts 'editing _head.html.erb' + f = File.open(folder+'partial/_head.html.erb','w') + f.write(texts) + f.close + end + rescue + puts "not found _head.html.erb in #{folder}" end - texts = File.read(folder+'partial/_head.html.erb') - insert_flag = 0 - if texts.include?(check_texts) - texts = texts.gsub(check_texts,edit_texts) - insert_flag = 1 - end - if insert_flag == 1 - puts 'editing _head.html.erb' - f = File.open(folder+'partial/_head.html.erb','w') - f.write(texts) - f.close - end - rescue - puts "not found _head.html.erb in #{folder}" end end end diff --git a/config/locales/en.yml b/config/locales/en.yml index 9eec112..4624fa6 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2,7 +2,13 @@ en: module_name: cancerpredict: Predict Breast Cancer Tool cancerpredict: - cancerpredict: adjust the predict breast cancer tool + hidden_variables: "Hidden Variables" + advance_mode_hint1: "After opening advance mode,calculation will change!\nAre you sure switch to advance mode?" + advance_mode_hint2: "一般模式: 選項設定在計算時對應到的值由1開始。(例如: 選項設定為[\"是\",\"否\"],則\"是\"在計算時對應到1,而\"否\"在計算時對應到2)。

    進階模式: 選項設定在計算時對應到的值由0開始。
    而若開啟選項值從大到小,則0對應到選項設定中的最後一項。
    選項對應到的值的意思為當前述的計算值為0時,則對應到定義的Array的第1個元素的值,以此類推。
    欄位對應檔案可上傳一個csv檔案,在計算時,會先依照csv中的第1直行,找到對應的變數1(生成的變數名稱為csv中的第1列)的值,其餘生成的變數值則為對應之後的同一橫列的值。" + module_mode: Module Mode + advance_mode: Advance Mode + Overall_Survival: Overall Survival + cancerpredict: Adjust the predict breast cancer tool submitResult: see submit results of the users result_is_right: Is therapy choices in the right hand side of result block? text_descibe: text descibe @@ -46,8 +52,9 @@ en: no: no unknown: unknown Results: Results - AdditionalBenefit: Additional Benefit - OverallSurvival: Overall Survival(%) + Treatment: Treatment + Additional_Benefit: Additional Benefit + Overall_Survival: Overall Survival(%) Surgeryonly: Surgery only Hormonetherapy: Hormone therapy Chemotherapy: Chemotherapy @@ -57,4 +64,6 @@ en: curve: Curves text: Texts Therapy_choice: Treatment options - \ No newline at end of file + lpv_impact: "lpv Impact(Input: Float)" + active_choice: "Active choice(input 1 present choice 1 is regarded as therapy enable)" + disable_condition: "Disable Condition" \ No newline at end of file diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 898d5bb..2b50f1c 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -2,6 +2,12 @@ zh_tw: module_name: cancerpredict: 乳癌預測工具 cancerpredict: + hidden_variables: "隱藏的變數" + advance_mode_hint1: "開啟進階模式後,計算方式有差異。\n您確定要開啟進階模式?" + advance_mode_hint2: "一般模式: 選項設定在計算時對應到的值由1開始。(例如: 選項設定為[\"是\",\"否\"],則\"是\"在計算時對應到1,而\"否\"在計算時對應到2)。

    進階模式: 選項設定在計算時對應到的值由0開始。
    而若開啟選項值從大到小,則0對應到選項設定中的最後一項。
    選項對應到的值的意思為當前述的計算值為0時,則對應到定義的Array的第1個元素的值,以此類推。
    欄位對應檔案可上傳一個csv檔案,在計算時,會先依照csv中的第1直行,找到對應的變數1(生成的變數名稱為csv中的第1列)的值,其餘生成的變數值則為對應之後的同一橫列的值。" + module_mode: 模組模式 + advance_mode: 進階模式 + Overall_Survival: 總生存率 cancerpredict: 乳癌預測工具調整 submitResult: 查看用戶繳交表單結果 result_is_right: 治療選項在結果的右邊? @@ -47,8 +53,8 @@ zh_tw: unknown: 未知 Results: 結果 Treatment: 治療 - AdditionalBenefit: 額外治療效益 - OverallSurvival: 總生存率(%) + Additional_Benefit: 額外治療效益 + Overall_Survival: 總生存率(%) Surgeryonly: 純手術 Hormonetherapy: 賀爾蒙治療 Chemotherapy: 化學治療 @@ -57,4 +63,23 @@ zh_tw: table: 列表 curve: 曲線 text: 文字 - Therapy_choice: 治療選項 \ No newline at end of file + Therapy_choice: 治療選項 + variable: 變數名稱 + name: 名稱 + is_num: 數字欄位 + hint: 提示文字 + comment_text: 說明文字 + choice_fields: '選項設定([]代表無選項)' + range: '數字範圍設定([]代表無範圍限制)' + right: 顯示在右側 + is_float: 可輸入小數 + revert_value: 選項值從大到小(ex:有兩個選項,則選項值依序為1和0) + map_values: 選項對應到的值(若無,則會使用初始值) + cancer_predict_mapping_file: 欄位對應檔案 + calculate_settings: 計算設定 + prediction_formula: 預測公式 + add_field: 新增填寫欄位 + add_therapy: 新增治療選項 + lpv_impact: "lpv 影響(輸入浮點數)" + active_choice: "啟用治療選項(輸入1代表第1個選項視為啟用治療)" + disable_condition: "禁用條件" \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index cd15307..aec9adf 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,12 @@ Rails.application.routes.draw do - + Thread.new do + c = Cancerpredictfields.last + if c + sleep(5) + c.save + c.auto_write_predict_js + end + end locales = Site.first.in_use_locales rescue I18n.available_locales scope "(:locale)", locale: Regexp.new(locales.join("|")) do diff --git a/modules/cancerpredict/cancer_predict_index.html.erb b/modules/cancerpredict/cancer_predict_index.html.erb index 4203a62..3ae22e8 100644 --- a/modules/cancerpredict/cancer_predict_index.html.erb +++ b/modules/cancerpredict/cancer_predict_index.html.erb @@ -3,5 +3,5 @@ {{table}} - - \ No newline at end of file +<%= stylesheet_link_tag "bootstrap.min.print", media: "print" %> +<%= stylesheet_link_tag "cancer_predict_print", media: "print" %> \ No newline at end of file