From 2e00a82db424f2e99d29f1f5a1a140109922f299 Mon Sep 17 00:00:00 2001 From: BOHUNG Date: Sun, 8 Dec 2019 13:32:03 +0800 Subject: [PATCH] finish add overall_servival --- app/assets/javascripts/cancer_predict.js | 83 ++++++++++++++++--- app/controllers/cancerpredicts_controller.rb | 47 ++++++----- .../cancer_predict_index.html.erb | 16 +++- 3 files changed, 110 insertions(+), 36 deletions(-) diff --git a/app/assets/javascripts/cancer_predict.js b/app/assets/javascripts/cancer_predict.js index 882cb45..d34384e 100644 --- a/app/assets/javascripts/cancer_predict.js +++ b/app/assets/javascripts/cancer_predict.js @@ -118,35 +118,94 @@ $(document).ready(function(){ post_json[name] = index; }; }; + post_json['locale'] = I18n.locale; var result = $.post("/cancerpredictResult",{"data":post_json}); result.done(function(){ var load_heml = $('#result_table_content').html(result.responseJSON.table); load_heml.ready(function(){ $('#result_table_content .cancer_years').eq(0).addClass('active'); - $('.cancer_table_btn').off('click').on('click',function(){ - var index = $(this).index()/2; + for(var i = 0;i < $('#result_table_content .cancer_years').length;i++){ + $('#result_table_content .cancer_years').eq(i).attr('index',i) + }; + $('#result_table_content .cancer_years').off('click').on('click',function(){ 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'); + $(this).parent().find('.cancer_years').removeClass('active'); + //$('#result_text_content .cancer_years').eq($(this).attr('index')).click(); }catch{}; $(this).addClass('active'); + $('#current_year').attr('index',$(this).attr('index')); + $('#current_year').attr('value',$(this).html()); + $('#current_year').change(); }); }); load_heml = $('#result_text_content').html(result.responseJSON.texts); load_heml.ready(function(){ $('#result_text_content .cancer_years').eq(0).addClass('active'); - $('.cancer_table_btn').off('click').on('click',function(){ - var index = $(this).index()/2; + for(var i = 0;i < $('#result_text_content .cancer_years').length;i++){ + $('#result_text_content .cancer_years').eq(i).attr('index',i) + }; + $('#result_text_content .cancer_years').off('click').on('click',function(){ 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'); + $(this).parent().find('.cancer_years').removeClass('active'); + //$('#result_table_content .cancer_years').eq($(this).attr('index')).click(); }catch{}; $(this).addClass('active'); + $('#current_year').attr('value',$(this).html()); + $('#current_year').attr('index',$(this).attr('index')); $('.surgery_year').html($(this).html()); + $('#current_year').change(); + }); + var treatmeny_method = result.responseJSON.treatmeny_method; + var lpv = [0,-0.8397,-0.4147,-0.3203,0.3321]; + 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'] + var lpv_real = [result.responseJSON['lpv']]; + var lpv_dict={} + var lpv_calc={1:-0.001476145,3:-0.01261639,5:-0.02519608} + 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]]; + lpv_real.push(lpv_current); + var servive_ratio = (Math.exp(lpv_calc[year])**lpv_current)*100; + var benefit = servive_ratio - servive_ratio_arr[servive_ratio_arr.legnth - 1]; + servive_ratio_arr.push(servive_ratio); + $('tr.'+arguments[0]+' td.Overall_Survival').html(servive_ratio); + $('tr.'+arguments[0]+' td.Additional_Benefit').html(benefit); + console.log(servive_ratio_arr[servive_ratio_arr.legnth - 1]); + return Array.prototype.push.apply(this, arguments); + }else{ + return Array.prototype.push.apply(this, arguments); + } + }; + for(var i = 0;i"123"} 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,10) @@ -58,37 +60,38 @@ class CancerpredictsController < ApplicationController 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') - result['table'] = '

此分析微針對已接受手術後病人,下表為此病人分別在第1年、3及5年下,根據選定的術後治療所估計的存活率

' - result['table'] += '' @years = ['1','3','5'] + result['table'] = '

此分析微針對已接受手術後病人,下表為此病人分別在第1年、3及5年下,根據選定的術後治療所估計的存活率

' + result['table'] += '' result['years'] = @years @years.each{|year| result['table'] += ('')} result['table'] += '' - @table_head = (I18n.locale.to_s == "zh_tw") ? ['治療','額外治療效益','總生存率(%)'] :['Treatment','Additional Benefit','Overall Survival(%)'] - @therapy_choices = (I18n.locale.to_s == "zh_tw") ? ['純手術'] :['Treatment'] - @form_to_show.form_show_in_result.values.each{|choice| @therapy_choices.push choice["name"][I18n.locale.to_s]} - @therapy_names = ['Treatment'] + @table_head = (locale == "zh_tw") ? ['治療','額外治療效益','總生存率(%)'] :['Treatment','Additional Benefit','Overall Survival(%)'] + @head_name = ['Treatment','Additional_Benefit','Overall_Survival'] + @therapy_choices = (locale == "zh_tw") ? ['純手術'] :['Surgery only'] + @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'] += ('')} + @table_head.each_with_index{|head,index| result['table'] += ('')} result['table'] += '' @therapy_choices.each_with_index do |choice,i| - result['table'] += '' + result['table'] += '' @table_head.each_with_index do |head,index| - if index == 0 - result['table'] += ('') - else - result['table'] += ('') - end + result['table'] += ('') end result['table'] += '' end result['texts'] = '此研究分析來自已接受根除性手術後之婦女所得之結果,根據您所輸入的資訊以及治療方式,'+'
'+'在術後第' @years.each{|year| result['texts'] += ('')} result['texts'] += ',' - @servive_ratio = Math.exp(-0.001476145)**(Math.exp((result['lpv']))) - result['texts'] += ('100 位只接受根除性手術的婦女中,有 '+ ''+@servive_ratio.round.to_s+''+' 位婦女,術後 '+''+@years[0].to_s+''+'年仍為存活') - result['texts'] += '' + @servive_ratio = (Math.exp(-0.001476145)**(result['lpv']))*100 + result['texts'] += ('100 位只接受根除性手術的婦女中,有 '+ ''+@servive_ratio.round.to_s+''+' 位婦女,術後 '+''+@years[0].to_s+''+'年仍為存活') + result['texts'] += '' + result['servive_ratio'] = @servive_ratio result = result.merge(params) render :json=> result end @@ -119,17 +122,17 @@ class CancerpredictsController < ApplicationController @table_str_left += '' if @field_property["comment_text"] != "" @table_str_left += '' - @table_str_left += '' + @table_str_left += '' else @table_str_left += '
' end if @field_property["is_num"] == 1 - @table_str_left += '' + @table_str_left += '' else @table_str_left += '
' @field_property["choice_fields"].each do |create_choice| @table_str_left += '' - @table_str_left += '' + @table_str_left += '' end @table_str_left += '
' end @@ -145,17 +148,17 @@ class CancerpredictsController < ApplicationController @table_str_right += '' if @field_property["comment_text"] != "" @table_str_right += '' - @table_str_right += '' + @table_str_right += '' else @table_str_right += '
' end if @field_property["is_num"] == 1 - @table_str_right += '' + @table_str_right += '' else @table_str_right += '
' @field_property["choice_fields"].each do |create_choice| @table_str_right += '' - @table_str_right += '' + @table_str_right += '' end @table_str_right += '
' end diff --git a/modules/cancerpredict/cancer_predict_index.html.erb b/modules/cancerpredict/cancer_predict_index.html.erb index 263b22e..e3d553a 100644 --- a/modules/cancerpredict/cancer_predict_index.html.erb +++ b/modules/cancerpredict/cancer_predict_index.html.erb @@ -82,9 +82,19 @@ top: -0.3em; padding: 0; } + .cancer_table_btn:focus{ + color: #5d7ca2 !important; + background-color: #9dc3e6 !important; + border-color: #8c8c8c !important; + } + .cancer_table_btn:hover{ + color: #5d7ca2 !important; + background-color: #9dc3e6 !important; + border-color: #8c8c8c !important; + } .cancer_table_btn.active{ - color: #333; - background-color: #e6e6e6; + color: #5d7ca2; + background-color: #9dc3e6; border-color: #8c8c8c; } .cancertable_empty{ @@ -204,6 +214,8 @@ #result_table_content table{ clear: both; width:100%; + table-layout: fixed; + overflow-wrap: break-word; } .cancer_th{ color: white;
' + head + '' + head + '
' + choice + '' + '-' + '' + ((index == 0) ? choice : '-') + '