diff --git a/app/assets/javascripts/cancer_predict.js b/app/assets/javascripts/cancer_predict.js index e8b2549..24c00f7 100644 --- a/app/assets/javascripts/cancer_predict.js +++ b/app/assets/javascripts/cancer_predict.js @@ -1,3 +1,32 @@ +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 = {}; + Object.keys(function(k){ + 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 = {}; @@ -24,6 +53,12 @@ $(document).ready(function(){ 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;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['sex_value'] = result_json['sex'] - 1 - result['Age_value'] = result_json['age'] - if(result_json['calcification_score'] < 1400) - result['cal_value'] = 0; - else - result['cal_value'] = 1; - try{ - result['lpv'] = -0.51427548* (result['sex_value']- 0.508312) + 0.05764604* (result['Age_value'] - 61.894501) + 0.49138819*(result['cal_value'] - 0.334399); - }catch(e){result['lpv'] = "error"}; - console.log(result['lpv']); - 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['sex_value'] = Number(result_json['sex_value']) - 1; + result['age'] = Number(result_json['age']); + mapping_hash = mapping_data_from_csv['age']; + temp_index = 0; + temp_value = result[age]; + 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++; + }); + result['calH'] = Number(result_json['calH']); + mapping_hash = mapping_data_from_csv['calH']; + temp_index = 0; + temp_value = result[calH]; + 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++; + }); + result['calAH'] = Number(result_json['calAH']); + mapping_hash = mapping_data_from_csv['calAH']; + temp_index = 0; + temp_value = result[calAH]; + 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++; + }); + result['calDH'] = Number(result_json['calDH']); + mapping_hash = mapping_data_from_csv['calDH']; + temp_index = 0; + temp_value = result[calDH]; + 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++; + }); + result['fat'] = Number(result_json['fat']); + mapping_hash = mapping_data_from_csv['fat']; + temp_index = 0; + temp_value = result[fat]; + 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++; + }); + result['N4'] = (2 - Number(result_json['N4'])); + result['O20'] = (2 - Number(result_json['O20'])); + result['O18'] = (2 - Number(result_json['O18'])); + result['N12'] = (2 - Number(result_json['N12'])); + result['N20'] = (2 - Number(result_json['N20'])); + result['N31'] = (2 - Number(result_json['N31'])); + result['O6'] = (2 - Number(result_json['O6'])); + result['N34'] = (2 - Number(result_json['N34'])); + result['N46'] = (2 - Number(result_json['N46'])); + result['N14'] = (2 - Number(result_json['N14'])); + result['N29'] = (2 - Number(result_json['N29'])); + result['N2'] = (2 - Number(result_json['N2'])); + result['N26'] = (2 - Number(result_json['N26'])); + result['O11'] = (2 - Number(result_json['O11'])); + result['N6'] = (2 - Number(result_json['N6'])); + result['O14'] = (2 - Number(result_json['O14'])); + result['N43'] = (2 - Number(result_json['N43'])); + result['O3'] = (2 - Number(result_json['O3'])); + result['O17'] = (2 - Number(result_json['O17'])); + result['O9'] = (2 - Number(result_json['O9'])); + + try{ + result['lpv'] = (A = 0.1327868* (result["sex_value"]- 0.4858824) + 0.0371720* (result["age_test1"] - 61.56000) -0.07447278* (result["age_test2"] - 13.10152) + 0.4315686* (result["age_test3"] - 0.9844332) + 0.0009163615*( result["calH_test1"] - 182.9347) -0.0007536899*( result["calH_test2"] - 124.8706) -0.0004697183*( result["calH_test3"] -80.75636) + 0.0001401325*( result["calAH_test1"] - 700.7824) -0.001349783*( result["calAH_test2"] - 634.2167) +0.001753832*( result["calAH_test3"] -419.3361) + 0.0001906046*( result["calDH_test1"] -835.2894) -0.000251567*( result["calDH_test2"] - 213.1630) -0.002173942*( result["fat_test1"] -108.4149)+0.003066541*( result["fat_test2"] - 28.33497) +0.6700708*(result["N4"]-0.3241176) +0.3336162*(result["O3"]-0.4994118) +0.1322476*(result["O20"]-0.1741176) +0.9084972*(result["O18"]-0.008823529) +0.2978388*(result["N12"]-0.1152941) +0.1777935*(result["N20"]-0.3582353) +1.588042*(result["N31"]-0.002352941) +0.2197419*(result["O6"]-0.07823529) +1.791159*(result["N34"]-0.001176471) -14.02639*(result["N46"]-0.003529412) +0.4305973*(result["N14"]-0.02176471) -0.4472885*(result["N29"]-0.02411765) -1.570431*(result["N20"]-0.0005882353) +0.2601319*(result["N26"]-0.04941176) -0.2364269*(result["O11"]-0.1164706) +0.1784179*(result["N6"]-0.1070588) +0.6023170*(result["O14"]-0.01294118) -1.031959*(result["N43"]-0.007058824) +0.4257809*(result["O17"]-0.01823529) +0.2002546*(result["O9"]-0.06176471)); + }catch(e){result['lpv'] = "error"}; + console.log(result['lpv']); + result['lpv_variable']['A'] = A; + return result; + }; + function calculate_and_change_result_value(obj){ + obj.servive_ratio_arr = []; + for(var i = 0;i(module_app = @app_title) { set_variables module_app } before_action :create_first_field @@ -27,74 +28,157 @@ class Admin::CancerpredictsController < OrbitAdminController @head_new_image = Headimages.new(:cancerpredictfields_id => @form_to_show.id) end 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 != 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 - else - if value.length > 2 - @form_to_show.form_show[num.to_s][key.to_s] = YAML.load(value) - else - @form_to_show.form_show[num.to_s][key.to_s] = [] - end - end + if key.include?("_file") && (!value[:temp_file].blank? rescue false) + if value[:id].nil? + mapping_file = CancerPredictMappingFile.create(value) 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 + 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 value != "0" && value != "1" + if key != params[:locale] + @form_to_show.form_show[num.to_s] = {} if @form_to_show.form_show[num.to_s].nil? + type = Cancerpredictfields::FIELDINFO[key.to_s].constantize rescue String + if @form_to_show.form_show[num.to_s][key.to_s].class != Array && type != Array + @form_to_show.form_show[num.to_s][key.to_s] = value else - if sub_value.length > 2 - @form_to_show.form_show[ num.to_s ][ sub_property ][params[:locale].to_s] = YAML.load(sub_value) + if value.length > 2 + @form_to_show.form_show[num.to_s][key.to_s] = YAML.load(value) else - @form_to_show.form_show[ num.to_s ][ sub_property ][params[:locale].to_s] = [] + @form_to_show.form_show[num.to_s][key.to_s] = [] + end + end + else + value.each do |sub_property,sub_value| + type = Cancerpredictfields::FIELDINFO[sub_property.to_s].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 + @form_to_show.form_show[ num.to_s ][ sub_property ][params[:locale].to_s] = sub_value + else + if sub_value.length > 2 + @form_to_show.form_show[ num.to_s ][ sub_property ][params[:locale].to_s] = YAML.load(sub_value) + else + @form_to_show.form_show[ 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[ 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[num.to_s][key.to_s] = value.to_i 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] = [] - end - end - end - end - else - @form_to_show.form_show_in_result[num.to_s][key.to_s] = value.to_i + 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 - end if !params["cancerpredictfields"]["form_show_in_result"].nil? - @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'] + 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[num.to_s][key.to_s] = "" + end + end + next if key.include?("_file") + if (key != "old_num") + 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] = [] + 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_in_result_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 + 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'] 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 +269,29 @@ 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.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 + js_codes = auto_write_predict_js + save_path = `bundle show cancerpredict` + save_path = save_path.sub("\n","") + '/app/assets/javascripts/cancer_predict.js' + file_texts = File.read(save_path) + str1 = "/* auto add start */" + index1 = file_texts.index(str1) + str2 = "/* auto add end */" + index2 = file_texts.index(str2) + file_texts = file_texts.sub(file_texts[(index1+str1.length+2) .. (index2 - 1)] , js_codes) + if !index1.nil? && !index2.nil? + File.write(save_path,file_texts) + end + end end @index = 0 Dir.chdir("public") do @@ -232,16 +338,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 +364,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 @@ -565,4 +673,125 @@ 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 + def auto_write_predict_js + js_code = "var map_values , mapping_hash , temp_index ,temp_value , index , closest_value;\r\n" + mapping_data_from_csv = YAML.load(@form_to_show.mapping_data_from_csv) rescue {} + #js_code += "\t\t\t\tvar mapping_data_from_csv = #{mapping_data_from_csv.to_s.gsub("=>",":")};\r\n" + variable_keys = [] + @form_to_show.form_show.each do |num,property| + @variable = property[:variable] + if @variable.present? + if property[:is_num] == 1 + js_code += "\t\t\t\tresult['#{@variable}'] = Number(result_json['#{@variable}']);\r\n" + elsif property[:choice_fields].present? + if property[:map_values].class == Array && property[:choice_fields].class == Array && property[:map_values].length == property[:choice_fields].length + js_code += "\t\t\t\tmap_values = #{property[:map_values]};\r\n" + js_code += "\t\t\t\tresult['#{@variable}'] = map_values[Number(result_json['#{@variable}'']) - 1];\r\n" + else + if property[:revert_value].to_i != 1 + js_code += "\t\t\t\tresult['#{@variable}'] = Number(result_json['#{@variable}']) - 1;\r\n" + else + js_code += "\t\t\t\tresult['#{@variable}'] = (#{property[:choice_fields].length} - Number(result_json['#{@variable}']));\r\n" + end + end + end + variable_keys.push(@variable) + if property[:cancer_predict_mapping_file].present? + if (mapping_data_from_csv != {} && !mapping_data_from_csv[@variable].blank?) + variable_keys.concat(mapping_data_from_csv[@variable].keys) + js_code += "\t\t\t\tmapping_hash = mapping_data_from_csv['#{@variable}'];\r\n" + js_code += "\t\t\t\ttemp_index = 0;\r\n" + js_code += "\t\t\t\ttemp_value = result[#{@variable}];\r\n" + js_code += "\t\t\t\tindex = 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 + formula = @form_to_show.prediction_formula.gsub("\r\n"," ").gsub("^","**") + variable_keys.each do |k| + formula = formula.gsub(/#{k}?(-|\+|\*|\s|\=)/){ "result[\"#{k}\"]#{$1}" } + end + formula_variables = formula.enum_for(:scan,/([^\=]*)?=/).map { Regexp.last_match[1] }.map{|s| s.strip.split(/(\s*|;\r\n)/).last} + js_code = "function calculate_first_lpv(result_json){ + result = {}; + #{js_code} + try{ + result['lpv'] = (#{formula}); + }catch(e){result['lpv'] = \"error\"}; + console.log(result['lpv']); + #{formula_variables.map{|v| "result['lpv_variable']['#{v}'] = #{v};"}.join("\r\n\t\t\t\t") } + return result; + }; + function calculate_and_change_result_value(obj){ + obj.servive_ratio_arr = []; + for(var i = 0;i

    '+@form_to_show.table_above_texts[locale].to_s+'

    ' result['table'] += (''+(locale == 'zh_tw' ? '第' : '')+'') @@ -82,7 +137,16 @@ class CancerpredictsController < ApplicationController result['table'] += '' end @lpv_calc = [0.9736358,0.9548993,0.9229336] - @servive_ratio = ((1-(@lpv_calc[0]**(Math.exp(result['lpv']))))*100).round(2) + year = params['data']['year'] rescue nil + if year.nil? + year = @years.first.to_f + else + year = year.to_f + end + year_index = @years.index(year) + #@servive_ratio = ((1-(@lpv_calc[0]**(Math.exp(result['lpv']))))*100).round(2) rescue 1 + @servive_ratio = eval(@form_to_show.years_settings[year_index].gsub('^','**').gsub('exp','Math.exp')) + @servive_ratio = ((1 - @servive_ratio) * 100).round(2) @texts = @form_to_show.text_above_texts[locale].to_s.gsub('
    ','
    ').gsub('{{Surgery_only}}',''+@servive_ratio.round(2).to_s+'') @texts = @texts.split('{{years}}') @texts.delete('') @@ -144,4 +208,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 3db1b55..01a4821 100644 --- a/app/models/cancerpredictfields.rb +++ b/app/models/cancerpredictfields.rb @@ -6,10 +6,12 @@ class Cancerpredictfields # encoding: utf-8 include OrbitTag::Taggable include OrbitCategory::Categorizable + 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"} + field :title ,type:String ,default:"" - field :form_show , :type=> Hash ,default:{0=>{:variable=>"sex",:name=>{"zh_tw"=>"性別
    (Sex)","en"=>"Sex"},:is_num=>0, :hint=>{'zh_tw'=>'','en'=>''} , :comment_text=>{'zh_tw'=>'','en'=>''}, :choice_fields=> {"zh_tw"=>['男','女'],"en"=>['Male','Female']},:range=>[],:right=>0,:is_float=>0}, - 1=>{:variable=>"age",:name=>{"zh_tw"=>"年齡
    (Age)","en"=>"Age"},:is_num=>1, :hint=>{'zh_tw'=>'從 20 歲(含)開始至 98 歲','en'=>'Age must be between 20 and 98'} , :comment_text=>{'zh_tw'=>'','en'=>''}, :choice_fields=> {"zh_tw"=>[],"en"=>[]},:range=>[20,98],:right=>0,:is_float=>0}, - 2=>{:variable=>"calcification_score",:name=>{"zh_tw"=>"鈣化指數
    (Calcification score)","en"=>"Calcification score"},:is_num=>1,:hint=>{'zh_tw'=>'請輸入0到5000的數字','en'=>'Please enter a number between 0 and 5000'}, :comment_text=>{'zh_tw'=>'','en'=>''}, :choice_fields=> {"zh_tw"=>[],"en"=>[]},:range=>[0,5000],:right=>0,:is_float=>1} + field :form_show , :type=> Hash ,default:{0=>{:variable=>"sex",:name=>{"zh_tw"=>"性別
    (Sex)","en"=>"Sex"},:is_num=>0, :hint=>{'zh_tw'=>'','en'=>''} , :comment_text=>{'zh_tw'=>'','en'=>''}, :choice_fields=> {"zh_tw"=>['男','女'],"en"=>['Male','Female']},:range=>[],:right=>0,:is_float=>0,:revert_value=>0,:map_values=>[],:cancer_predict_mapping_file=>""}, + 1=>{:variable=>"age",:name=>{"zh_tw"=>"年齡
    (Age)","en"=>"Age"},:is_num=>1, :hint=>{'zh_tw'=>'從 20 歲(含)開始至 98 歲','en'=>'Age must be between 20 and 98'} , :comment_text=>{'zh_tw'=>'','en'=>''}, :choice_fields=> {"zh_tw"=>[],"en"=>[]},:range=>[20,98],:right=>0,:is_float=>0,:revert_value=>0,:map_values=>[],:cancer_predict_mapping_file=>""}, + 2=>{:variable=>"calcification_score",:name=>{"zh_tw"=>"鈣化指數
    (Calcification score)","en"=>"Calcification score"},:is_num=>1,:hint=>{'zh_tw'=>'請輸入0到5000的數字','en'=>'Please enter a number between 0 and 5000'}, :comment_text=>{'zh_tw'=>'','en'=>''}, :choice_fields=> {"zh_tw"=>[],"en"=>[]},:range=>[0,5000],:right=>0,:is_float=>1,:revert_value=>0,:map_values=>[],:cancer_predict_mapping_file=>""} } 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=>[]}, @@ -30,9 +32,12 @@ class Cancerpredictfields 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:[0.5,1,1.5] + field :years ,type:Array ,default:[1,1.5,2,2.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 :image_uploader ,type:Object + field :prediction_formula , type: String ,default: "" + field :years_settings , type: Array , default: ["0.8095037^( exp(A) )","0.729158^( exp(A) )","0.6717211^( exp(A) )","0.6056773^( exp(A) )"] + field :mapping_data_from_csv , type: String ,default: "" 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)} #before_create :set_expire diff --git a/app/views/admin/cancerpredicts/_form.html.erb b/app/views/admin/cancerpredicts/_form.html.erb index c789e22..1c91614 100644 --- a/app/views/admin/cancerpredicts/_form.html.erb +++ b/app/views/admin/cancerpredicts/_form.html.erb @@ -1,472 +1,39 @@ -<% 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) %> -
    -
    - -
    - -
    -
    -
    + + ❌ + + <% keys.each do |key| %> + <% 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] %> + <% if property == {} %> + <% value_type = Cancerpredictfields::FIELDINFO[key].constantize rescue String %> + <% value = "[]" if value_type == Array %> + <% else %> + <% value_type = value.class %> <% 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 + <% @value= value %> + <% if value_type == BSON::Document || value_type == Hash %> + <% @disp_value = @value[I18n.locale.to_s] rescue "" %> + <%else%> + <% @disp_value = @value %> + <%end%> + <% 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 value_type == BSON::Document || value_type == Hash %> + <%=make_fields.fields_for I18n.locale.to_s do |locale_fields|%> + <%= locale_fields.text_field key,{:value=>@disp_value}%> + <%end%> + <% else %> + <%= make_fields.text_field key,{:value=>@disp_value}%> + <%end%> + <%end%> + <%end%> + <%= make_fields.hidden_field :old_num,:value=>num.to_s %> + \ 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 c22c15b..7be0a82 100644 --- a/app/views/admin/cancerpredicts/index.html.erb +++ b/app/views/admin/cancerpredicts/index.html.erb @@ -1,5 +1,32 @@ <%= stylesheet_link_tag "lib/fileupload"%> -<%= javascript_include_tag 'lib/bootstrap-fileupload' %> +<% 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') %> @@ -156,11 +183,15 @@ <%end%> <%= t('cancerpredict.Input_fields') %>
    - +
    + <% keys = @form_to_show.form_show.values[0].keys rescue [] %> + <% keys = Cancerpredictfields::FIELDINFO.keys if keys.blank? %> - <% @form_to_show.form_show.values[1].each do |key,vlaue|%> - + + + <% keys.each do |key|%> + <%end%> @@ -168,34 +199,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,21 +228,31 @@ <% end %>
    <% end %> - <% if (!@form_to_show.form_show_in_result.blank? rescue false) %> - - - - <% @form_to_show.form_show_in_result.values[1].each do |key,vlaue|%> - +
    <%=key%>
    + + + + + <% keys = @form_to_show.form_show_in_result.values[0].keys rescue [] %> + <% keys = Cancerpredictfields::FIELDINFO.keys if keys.blank? %> + <% 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|%> + + + + <%= 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|%> + <% if key.include? "_file" %> + + <% else %> <% @value= value %> <% if @value.class == BSON::Document || @value.class == Hash %> <% @disp_value = @value[I18n.locale.to_s] rescue "" %> @@ -252,13 +273,39 @@ <%end%> <%end%> - <%end%> + + <%end%> <%end%> - -
    <%=t("cancerpredict.table.#{key}")%>
    + <%= render :partial => 'form_file', :object => (CancerPredictMappingFile.where(:id=> property[key]).first rescue nil), :locals => {:f => make_fields, :key=>key} %> + <%= make_fields.text_field key,{:value=>@disp_value}%>
    <%= make_fields.hidden_field :old_num,:value=>num.to_s %>
    - <% end %> + <%end%> + + + +
    + <%=t('cancerpredict.table.calculate_settings')%> +
    +
    +
    + +
    +
    + <%= form.text_area :prediction_formula, :rows=>"5", :style=> 'width: calc(100% - 12em);' %> +
    +
    +
    + <% years = @form_to_show.years %> + <% years.each_with_index do |year,i| %> +
    +
    + +
    +
    + +
    +
    + <% end %> +
    <%=form.submit "#{t(:updatefont)}",{:id=>"updatebtn"}%> <%end%> @@ -267,4 +314,115 @@ $('.text_choice').prop('checked' , false); $(this).prop('checked' , true); }); + $("#add_field").click(function(){ + var index = $("#fields_table tbody tr").length.toString(); + <%= fields_for :cancerpredictfields do |form|%> + <%= form.fields_for :form_show do |formfield|%> + <%=formfield.fields_for :new_index do |make_fields|%> + <% keys = @form_to_show.form_show.values[0].keys rescue [] %> + <% keys = Cancerpredictfields::FIELDINFO.keys if keys.blank? %> + var html = "<%= "#{render :partial => 'form', :locals=>{:make_fields=>make_fields,:property=>{},:num=>'',:keys => keys}}".gsub(/(\r\n|\n)/,"").gsub("\"","\\\"").html_safe %>"; + $("#fields_table tbody").append(html.replaceAll('new_index',index)); + <% end %> + <% end %> + <% end %> + $(".remove_div").off("click").on("click",function(){ + $el = $(this).parent().siblings("tr").not($(this)).eq(0); + $(this).parent().remove(); + update_key($el); + }) + }) + $("#add_therapy").click(function(){ + var index = $("#therapies_table tbody tr").length.toString(); + <%= fields_for :cancerpredictfields do |form|%> + <%= form.fields_for :form_show_in_result do |formfield|%> + <%=formfield.fields_for :new_index do |make_fields|%> + <% keys = @form_to_show.form_show_in_result.values[0].keys rescue [] %> + <% keys = Cancerpredictfields::FIELDINFO.keys if keys.blank? %> + var html = "<%= "#{render :partial => 'form', :locals=>{:make_fields=>make_fields,:property=>{},:num=>'',:keys => keys}}".gsub(/(\r\n|\n)/,"").gsub("\"","\\\"").html_safe %>"; + $("#therapies_table tbody").append(html.replaceAll('new_index',index)); + <% end %> + <% end %> + <% end %> + $(".remove_div").off("click").on("click",function(){ + $el = $(this).parent().siblings("tr").not($(this)).eq(0); + $(this).parent().remove(); + update_key($el); + }) + }) + function update_key(ele){ + console.log($(ele)) + var ui_child=$(ele).parent().find('> tr'); + console.log(ui_child); + for (var i=0;i tbody" ).sortable({ + axis: "y", + revert: true, + placeholder: "sortable-placeholder", + handle: ".sort_div", + update: function(event, ui) { + update_key($(ui.item[0])) + } + }); + $(".remove_div").click(function(){ + $el = $(this).parent().siblings("tr").not($(this)).eq(0); + $(this).parent().remove(); + update_key($el); + }) + $(".remove_existing_record").click(function(){ + if(window.confirm("Are you sure want to remove this file?")){ + $(this).find(".should_destroy").val("1"); + $(this).parent().siblings(".file-link").remove(); + } + }) + $("#years").on('blur',function(){ + var years = []; + try{ + years = $(this).val().split(/\[|,|\]/).filter(function(aa){return aa !="" && aa != undefined}).map(function(aa){return aa.trim()}); + }catch(e){}; + var index = 0; + years.forEach(function(year){ + if($("#years_settings [data-year='"+year+"']").length == 0){ + var year_text = ('
    '+ + '
    '+ + ''+ + '
    '+ + '
    '+ + ''+ + '
    '+ + '
    '); + if(index != 0){ + $("#years_settings [data-year='"+years[index - 1]+"']").after(year_text); + }else{ + $("#years_settings").html(year_text+$("#years_settings").html()); + } + } + index++; + }) + var all_years = $("#years_settings [data-year]").map(function(i,aa){return $(aa).attr("data-year").toString().trim() }).toArray(); + all_years.forEach(function(a_year){ + if(years.indexOf(a_year) == -1){ + $("#years_settings [data-year='"+a_year+"']").remove() + } + }) + + + }) \ No newline at end of file diff --git a/cancer_predict.js b/cancer_predict.js new file mode 100644 index 0000000..24c00f7 --- /dev/null +++ b/cancer_predict.js @@ -0,0 +1,926 @@ +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 = {}; + Object.keys(function(k){ + 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 = {}; + if(I18n.locale == 'en'){ + var window_width = $(window).width(); + if(window_width < 520){ + $('#cancer_table .cencer_table_name').css('max-width',''); + }else if(window_width < 768){ + $('#cancer_table .cencer_table_name').css({'max-width':'','width':'11em'}); + }else if(window_width < 860){ + $('#cancer_table .cencer_table_name').css('max-width','30%'); + }else if(window_width < 1130){ + $('#cancer_table .cencer_table_name').css('max-width','33%'); + }else{ + $('#cancer_table .cencer_table_name').css('max-width','39%'); + }; + }; + function round(num,Digit=0){ + return Math.round(Number(num)*(10**Digit))/(10**Digit); + }; + head_data.done(function(){ + // $('.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;i $(this).data('range')[1] && $(this).data('range')[1] != undefined) ){ + $(this).css('color','#f24a69'); + $(this).addClass('cancertable_empty'); + }else{ + $(this).css('color','#333'); + $(this).removeClass('cancertable_empty'); + if($('.cancertable_empty').length == 0){ + $('#danger_texts').remove(); + }; + }; + }); + $('input#lymph_nodes_positive').off('input').on('input',function(){ + $(this).siblings('.num_only_value').val($(this).val()); + if( Number($(this).val()) < $(this).data('range_new')[0] || $(this).val() == "" || (Number($(this).val()) > $(this).data('range_new')[1] && $(this).data('range_new')[1] != undefined) ){ + $(this).css('color','#f24a69'); + $(this).addClass('cancertable_empty'); + }else{ + $(this).css('color','#333'); + $(this).removeClass('cancertable_empty'); + if($('.cancertable_empty').length == 0){ + $('#danger_texts').remove(); + }; + }; + }); + $('input#lymph_nodes_examined').off('input').on('input',function(){ + $(this).siblings('.num_only_value').val($(this).val()); + if( Number($(this).val()) < $(this).data('range_new')[0] || $(this).val() == "" || (Number($(this).val()) > $(this).data('range_new')[1] && $(this).data('range_new')[1] != undefined) ){ + $(this).css('color','#f24a69'); + $(this).addClass('cancertable_empty'); + }else{ + $(this).css('color','#333'); + $(this).removeClass('cancertable_empty'); + if($('.cancertable_empty').length == 0){ + $('#danger_texts').remove(); + }; + }; + }); + $('.cancer_help_btn').off("click").on('click',function(){ + var modal_head = ""; + try{ modal_head = $(this).parent().find(">label").html()}catch(e){}; + var modal_body = ""; + try{ modal_body = $(this).parent().find(">input.help_texts").attr('value')}catch(e){}; + $('#show_help_modal').html("") + $('#show_help_modal').modal('show'); + $('#show_help_modal .close').off("click").on('click',function(){ + $('#show_help_modal').modal('hide'); + }); + $('#show_help_modal .modal-footer button').off("click").on('click',function(){ + $('#show_help_modal').modal('hide'); + }); + }); + $('.btn-add').click(function(){ + $(this).parent().find('.num_only').removeClass('cancertable_empty'); + if($(this).parent().find('.num_only').val()!=""){ + var input_value = Number($(this).parent().find('.num_only').val()); + if(Array.isArray($(this).parent().find('.num_only').data('range'))){ + var compare_value = $(this).parent().find('.num_only').data('range')[1]; + if(compare_value != undefined){ + if(input_value+1 <= Number(compare_value)) + $(this).parent().find('.num_only').val(input_value+1); + else{ + input_value = $(this).parent().find('.num_only').data('range')[0]; + if(input_value != undefined) + $(this).parent().find('.num_only').val(input_value); + }; + }else{ + $(this).parent().find('.num_only').val(input_value+1); + }; + compare_value = $(this).parent().find('.num_only').data('range')[0]; + if(compare_value != undefined){ + if($(this).parent().find('.num_only').val() >= compare_value){ + $(this).parent().find('.num_only').removeClass('cancertable_empty'); + $(this).parent().find('.num_only').css('color','#333'); + }; + if($('.cancertable_empty').length == 0){ + $('#danger_texts').remove(); + }; + }else{ + $(this).parent().find('.num_only').removeClass('cancertable_empty'); + $(this).parent().find('.num_only').css('color','#333'); + if($('.cancertable_empty').length == 0){ + $('#danger_texts').remove(); + }; + }; + }; + }else{ + try{ + var input_value = $(this).parent().find('.num_only').data('range')[0]; + if(input_value != undefined) + $(this).parent().find('.num_only').val(input_value); + }catch(e){ + $(this).parent().find('.num_only').val(0); + }; + if($(this).parent().find('.num_only').val() != ""){ + $(this).parent().find('.num_only').removeClass('cancertable_empty'); + $(this).parent().find('.num_only').css('color','#333'); + }; + }; + }); + $('.btn-sub').click(function(){ + if($(this).parent().find('.num_only').val()!=""){ + var input_value = Number($(this).parent().find('.num_only').val()); + if(Array.isArray($(this).parent().find('.num_only').data('range'))){ + var compare_value = $(this).parent().find('.num_only').data('range')[0]; + if(compare_value != undefined){ + if(input_value-1 >= Number(compare_value)) + $(this).parent().find('.num_only').val(input_value-1); + else{ + input_value = $(this).parent().find('.num_only').data('range')[1]; + if(input_value != undefined) + $(this).parent().find('.num_only').val(input_value); + }; + }else{ + $(this).parent().find('.num_only').val(input_value-1); + }; + compare_value = $(this).parent().find('.num_only').data('range')[1]; + if(compare_value != undefined){ + if($(this).parent().find('.num_only').val() <= compare_value){ + $(this).parent().find('.num_only').removeClass('cancertable_empty'); + $(this).parent().find('.num_only').css('color','#333'); + }; + if($('.cancertable_empty').length == 0){ + $('#danger_texts').remove(); + }; + }else{ + $(this).parent().find('.num_only').removeClass('cancertable_empty'); + $(this).parent().find('.num_only').css('color','#333'); + if($('.cancertable_empty').length == 0){ + $('#danger_texts').remove(); + }; + }; + }; + }else{ + try{ + var input_value = $(this).parent().find('.num_only').data('range')[1]; + if(input_value != undefined){ + $(this).parent().find('.num_only').val(input_value); + }else{ + input_value = $(this).parent().find('.num_only').data('range')[0]; + if(input_value != undefined) + $(this).parent().find('.num_only').val(input_value); + } + }catch(e){ + $(this).parent().find('.num_only').val(0); + }; + if($(this).parent().find('.num_only').val() != ""){ + $(this).parent().find('.num_only').removeClass('cancertable_empty'); + $(this).parent().find('.num_only').css('color','#333'); + }; + }; + if($('.cancertable_empty').length == 0){ + $('#danger_texts').remove(); + }; + }); + $('.cancer_table_btn').off('click').on('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'); + }); + $('#cancer_table_reset').click(function(){ + $('.cancer_table_btn').removeClass('active'); + $('.cancer-btn-group input').attr('value',0); + $('.num_only').val(''); + $('.num_only_value').val(''); + $('#cancer_table .cancer_form_field').removeClass('cancertable_empty'); + $('#cancer_predict_result_block').css('display','none'); + $('#danger_texts').remove(); + $('select.select_num').val(''); + }); + function get_input_data(){ + var flag; + flag = 1; + for(var i = 0;i < $('#cancer_table .cancer_form_field').length;i++){ + if($('#cancer_table .cancer_form_field').eq(i).hasClass('num_only')){ + if($('#cancer_table .cancer_form_field').eq(i).val()==""){ + flag = 0; + $('#cancer_table .cancer_form_field').eq(i).addClass('cancertable_empty'); + }else if($('#cancer_table .cancer_form_field').eq(i).val() != "" && !$('#cancer_table .cancer_form_field').eq(i).hasClass('cancertable_empty')){ + $('#cancer_table .cancer_form_field').eq(i).removeClass('cancertable_empty'); + }; + }else{ + if($('#cancer_table .cancer_form_field').eq(i).find('[value="1"]').length == 0){ + flag = 0; + $('#cancer_table .cancer_form_field').eq(i).addClass('cancertable_empty'); + }else{ + $('#cancer_table .cancer_form_field').eq(i).removeClass('cancertable_empty'); + } + }; + }; + if( Number($('input#lymph_nodes_examined').siblings('.num_only_value').val()) < Number($('input#lymph_nodes_positive').siblings('.num_only_value').val())){ + $('input#lymph_nodes_positive').addClass('cancertable_empty'); + $('input#lymph_nodes_positive').css('color','rgb(242, 74, 105)'); + }; + if($('.cancertable_empty').length != 0){ + flag = 0; + ($('#danger_texts').length == 0) ? $('#cancer_table_submit').parent().before(''+data['danger_texts']+'') : null; + $('#danger_texts').css('margin-left',$(window).width()/2-$('#danger_texts').width()/2); + }else{ + $('#danger_texts').remove(); + }; + if(flag == 1){ + var post_json= {}; + for(var i = 0;i < $('#cancer_table .cancer_form_field').length;i++){ + var name = $('#cancer_table .cancer_form_field').eq(i).attr('id') + if($('#cancer_table .cancer_form_field').eq(i).hasClass('num_only')) + post_json[name] = Number($('#cancer_table .cancer_form_field').eq(i).siblings('.num_only_value').val()); + else{ + var index = ($('#cancer_table .cancer_form_field').eq(i).find('[value="1"]').index()+1)/2; + post_json[name] = index; + }; + }; + if( post_json["ER_status"] == 2 && post_json["PR_status"] == 2 ){ + $('#hormone_therapy .cancer_table_btn').attr('disabled','disabled'); + $('[for="hormone_therapy"]').css('color','rgb(204, 204, 204)'); + }else{ + $('#hormone_therapy .cancer_table_btn').removeAttr('disabled'); + $('[for="hormone_therapy"]').css('color',''); + }; + if(post_json["HER2_status"] != 1){ + $('#Targeted_therapy .cancer_table_btn').attr('disabled','disabled'); + $('[for="Targeted_therapy"]').css('color','rgb(204, 204, 204)'); + }else{ + $('#Targeted_therapy .cancer_table_btn').removeAttr('disabled'); + $('[for="Targeted_therapy"]').css('color',''); + }; + return post_json; + }else{ + return null; + } + }; + function set_result(result){ + if(result.responseJSON.lpv != "error"){ + $('#choice_fields .cancer_table_btn').removeClass('active'); + var load_heml = $('#result_table_content').html(result.responseJSON.table); + load_heml.ready(function(){ + $('#result_table_content .cancer_years').eq(0).addClass('active'); + 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('.cancer_years').removeClass('active'); + }catch(e){}; + $(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'); + for(var i = 0;i < $('#result_text_content .cancer_years').length;i++){ + $('#result_text_content .cancer_years').eq(i).attr('index',i) + }; + $('#current_year').off('change'); + $('#result_text_content .cancer_years').off('click') + $('#result_text_content .cancer_years').click(function(){ + try{ + $(this).parent().find('.cancer_years').removeClass('active'); + }catch(e){}; + $(this).addClass('active'); + $('#current_year').attr('value',$(this).html()); + $('#current_year').attr('index',$(this).attr('index')); + $('.surgery_year').html($(this).html()); + $('#current_year').change(); + }); + $('#cancer_table_right_result .cancer-btn-group .cancer_table_btn').removeClass('active'); + $('#cancer_table_right_result .cancer-btn-group >input').attr('value',"0"); + for(var i = 0;i < $('#cancer_table_left_result .cancer-btn-group').length;i++){ + $('#cancer_table_left_result .cancer-btn-group').eq(i).find('.cancer_table_btn').eq(0).addClass('active'); + $('#cancer_table_left_result .cancer-btn-group').eq(i).find('>input').eq(0).attr('value',"1"); + }; + for(var i = 0;i < $('#cancer_table_right_result .cancer-btn-group').length;i++){ + $('#cancer_table_right_result .cancer-btn-group').eq(i).find('.cancer_table_btn').eq(0).addClass('active'); + $('#cancer_table_right_result .cancer-btn-group').eq(i).find('>input').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 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]+'%'); + $('#cancer_predict_result_block').css('display','block'); + var lpv_real = [result.responseJSON['lpv_variable']]; + var lpv_dict={} + var lpv_calc={0.5:0.9736358,1:0.9548993,1.5:0.9229336} + active_treatment.push = function() { + if(arguments.length == 1){ + var year = $('#current_year').attr('value'); + var lpv_current = change_object_variables(lpv_real[lpv_real.length-1],lpv_dict[arguments[0]],'+'); + lpv_real.push(lpv_current); + var servive_ratio = round((1 - (lpv_calc[year]**Math.exp(lpv_current)))*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+'%'); + $('tr.'+arguments[0]+' td.Additional_Benefit').html(round(benefit,2)+'%'); + $('tr.'+arguments[0]).css('display','table-row'); + $('tr.tr_show').eq(-1).after($('tr.'+arguments[0])); + $('tr.'+arguments[0]).addClass('tr_show'); + if(this.length == 1){ + $('.addition').css('display','inline-block'); + $('#result_text_content .extra-text').css('display','inline-block'); + } + var add_choices = this.slice(1,this.length); + add_choices.push(arguments[0]); + var add_choices_transform = []; + for(var i = 0;i= 2) + add_choices_str += ((I18n.locale == 'en' ? ', and ': '以及')+add_choices_transform[add_choices_transform.length-1]) + else + add_choices_str = add_choices_transform[0]; + var extra_therapy_texts = result.responseJSON['extra_therapy_texts']; + extra_therapy_texts = extra_therapy_texts.replace('{{extra_therapy}}',''+add_choices_str+''); + extra_therapy_texts = extra_therapy_texts.replace('{{survival_num}}',''+Math.round(servive_ratio)+''); + extra_therapy_texts = extra_therapy_texts.replace('{{surgery_year}}',''+year+''); + extra_therapy_texts = extra_therapy_texts.replace('{{Additional_Benefit}}',''+Math.round(benefit)+''); + var new_text = '

    '; + new_text += (extra_therapy_texts+'

    '); + $('#result_text_content .extra-text .texts_show').eq(-1).after(new_text) + return Array.prototype.push.apply(this, arguments); + }else{ + return Array.prototype.push.apply(this, arguments); + } + }; + active_treatment.remove_item_from_array = function(){ + if(arguments.length == 1 && !Array.isArray(arguments[0])){ + var index = this.indexOf(arguments[0]) + var year = $('#current_year').attr('value'); + if(index < this.length - 1){ + for(var i = index + 1;i < this.length; i++){ + change_object_variables(lpv_real[i] , lpv_dict[arguments[0]] , '-' , 'self'); + var servive_ratio = round((Math.exp(lpv_calc[year])**Math.exp(lpv_real[i]))*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+'%'); + $('.'+active_treatment[i]+'.Overall_Survival').html(Math.round(servive_ratio)); + $('tr.'+active_treatment[i]+' td.Additional_Benefit').html(round(benefit,2)+'%'); + $('.'+active_treatment[i]+'.Additional_Benefit').html(Math.round(benefit)); + }; + var add_choices = []; + for(var i = 1;i < this.length; i++){ + if(i != index){ + add_choices.push(this[i]); + var add_choices_transform = []; + for(var j = 0;j= 2) + add_choices_str += ((I18n.locale == 'en' ? ', and ': '以及')+add_choices_transform[add_choices_transform.length-1]) + else + add_choices_str = add_choices_transform[0]; + $('.'+active_treatment[i]+'.choices').html(add_choices_str); + } + }; + }; + $('tr.'+arguments[0]+' td.Overall_Survival').html('-'); + $('tr.'+arguments[0]+' td.Additional_Benefit').html('-'); + $('tr.'+arguments[0]).css('display','none'); + $('tr.'+arguments[0]).removeClass('tr_show'); + $('span.'+arguments[0]).eq(0).parent().remove(); + lpv_real = lpv_real.remove_item_from_array(lpv_real[index]); + servive_ratio_arr = servive_ratio_arr.remove_item_from_array(servive_ratio_arr[index]); + if(this.length == 2){ + $('.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(){ + 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 = active_treatment.remove_item_from_array($(this).parent().attr('id')); + click_flag = false; + }; + }; + }); + }; + $('#current_year').change(function(){ + year = $(this).attr('value'); + $('.surgery_year').html(year); + $('.cancer_years').removeClass('active'); + $('#result_text_content .cancer_years').eq($(this).attr("index")).addClass('active'); + $('#result_table_content .cancer_years').eq($(this).attr("index")).addClass('active'); + var obj = {"servive_ratio_arr":servive_ratio_arr,"active_treatment":active_treatment,"lpv_real":lpv_real,"lpv_calc":lpv_calc,"year":year} + calculate_and_change_result_value(obj); + servive_ratio_arr = obj.servive_ratio_arr; + active_treatment = obj.active_treatment; + lpv_real = obj.lpv_real; + lpv_calc = obj.lpv_calc; + year = obj.year; + }); + $('#cancer_table .cancer_form_field').off('change').on('change',function(){ + var obj = {"servive_ratio_arr":servive_ratio_arr,"active_treatment":active_treatment,"lpv_real":lpv_real,"lpv_calc":lpv_calc,"year":year} + after_submit_change_func(obj); + servive_ratio_arr = obj.servive_ratio_arr; + active_treatment = obj.active_treatment; + lpv_real = obj.lpv_real; + lpv_calc = obj.lpv_calc; + year = obj.year; + }); + $('#cancer_table .cancer_form_field').click(function(){ + $(this).change(); + }); + $('select.select_num').off('click').on('click',function(){ + $(this).change(); + var obj = {"servive_ratio_arr":servive_ratio_arr,"active_treatment":active_treatment,"lpv_real":lpv_real,"lpv_calc":lpv_calc,"year":year} + after_submit_change_func(obj); + servive_ratio_arr = obj.servive_ratio_arr; + active_treatment = obj.active_treatment; + lpv_real = obj.lpv_real; + lpv_calc = obj.lpv_calc; + year = obj.year; + }); + $('.num_only').on('input', function() { + if( Number($(this).val()) < $(this).data('range')[0] || $(this).val() == "" || (Number($(this).val()) > $(this).data('range')[1] && $(this).data('range')[1] != undefined) ){ + $(this).css('color','#f24a69'); + $(this).addClass('cancertable_empty'); + }else{ + $(this).css('color','#333'); + $(this).removeClass('cancertable_empty'); + if($('.cancertable_empty').length == 0){ + $('#danger_texts').remove(); + }; + var obj = {"servive_ratio_arr":servive_ratio_arr,"active_treatment":active_treatment,"lpv_real":lpv_real,"lpv_calc":lpv_calc,"year":year}; + after_submit_change_func(obj); + servive_ratio_arr = obj.servive_ratio_arr; + active_treatment = obj.active_treatment; + lpv_real = obj.lpv_real; + lpv_calc = obj.lpv_calc; + year = obj.year; + }; + }); + }); + }; + }; + function after_submit_change_func(obj){ + var post_json = get_input_data(); + if(post_json != null){ + var new_lpv = calculate_first_lpv(post_json)['lpv_variable']; + var old_lpv = obj.lpv_real[0]; + 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); + }; + }; + /* auto add start */ +function calculate_first_lpv(result_json){ + result = {}; + var map_values , mapping_hash , temp_index ,temp_value , index , closest_value; + result['sex_value'] = Number(result_json['sex_value']) - 1; + result['age'] = Number(result_json['age']); + mapping_hash = mapping_data_from_csv['age']; + temp_index = 0; + temp_value = result[age]; + 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++; + }); + result['calH'] = Number(result_json['calH']); + mapping_hash = mapping_data_from_csv['calH']; + temp_index = 0; + temp_value = result[calH]; + 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++; + }); + result['calAH'] = Number(result_json['calAH']); + mapping_hash = mapping_data_from_csv['calAH']; + temp_index = 0; + temp_value = result[calAH]; + 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++; + }); + result['calDH'] = Number(result_json['calDH']); + mapping_hash = mapping_data_from_csv['calDH']; + temp_index = 0; + temp_value = result[calDH]; + 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++; + }); + result['fat'] = Number(result_json['fat']); + mapping_hash = mapping_data_from_csv['fat']; + temp_index = 0; + temp_value = result[fat]; + 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++; + }); + result['N4'] = (2 - Number(result_json['N4'])); + result['O20'] = (2 - Number(result_json['O20'])); + result['O18'] = (2 - Number(result_json['O18'])); + result['N12'] = (2 - Number(result_json['N12'])); + result['N20'] = (2 - Number(result_json['N20'])); + result['N31'] = (2 - Number(result_json['N31'])); + result['O6'] = (2 - Number(result_json['O6'])); + result['N34'] = (2 - Number(result_json['N34'])); + result['N46'] = (2 - Number(result_json['N46'])); + result['N14'] = (2 - Number(result_json['N14'])); + result['N29'] = (2 - Number(result_json['N29'])); + result['N2'] = (2 - Number(result_json['N2'])); + result['N26'] = (2 - Number(result_json['N26'])); + result['O11'] = (2 - Number(result_json['O11'])); + result['N6'] = (2 - Number(result_json['N6'])); + result['O14'] = (2 - Number(result_json['O14'])); + result['N43'] = (2 - Number(result_json['N43'])); + result['O3'] = (2 - Number(result_json['O3'])); + result['O17'] = (2 - Number(result_json['O17'])); + result['O9'] = (2 - Number(result_json['O9'])); + + try{ + result['lpv'] = (A = 0.1327868* (result["sex_value"]- 0.4858824) + 0.0371720* (result["age_test1"] - 61.56000) -0.07447278* (result["age_test2"] - 13.10152) + 0.4315686* (result["age_test3"] - 0.9844332) + 0.0009163615*( result["calH_test1"] - 182.9347) -0.0007536899*( result["calH_test2"] - 124.8706) -0.0004697183*( result["calH_test3"] -80.75636) + 0.0001401325*( result["calAH_test1"] - 700.7824) -0.001349783*( result["calAH_test2"] - 634.2167) +0.001753832*( result["calAH_test3"] -419.3361) + 0.0001906046*( result["calDH_test1"] -835.2894) -0.000251567*( result["calDH_test2"] - 213.1630) -0.002173942*( result["fat_test1"] -108.4149)+0.003066541*( result["fat_test2"] - 28.33497) +0.6700708*(result["N4"]-0.3241176) +0.3336162*(result["O3"]-0.4994118) +0.1322476*(result["O20"]-0.1741176) +0.9084972*(result["O18"]-0.008823529) +0.2978388*(result["N12"]-0.1152941) +0.1777935*(result["N20"]-0.3582353) +1.588042*(result["N31"]-0.002352941) +0.2197419*(result["O6"]-0.07823529) +1.791159*(result["N34"]-0.001176471) -14.02639*(result["N46"]-0.003529412) +0.4305973*(result["N14"]-0.02176471) -0.4472885*(result["N29"]-0.02411765) -1.570431*(result["N20"]-0.0005882353) +0.2601319*(result["N26"]-0.04941176) -0.2364269*(result["O11"]-0.1164706) +0.1784179*(result["N6"]-0.1070588) +0.6023170*(result["O14"]-0.01294118) -1.031959*(result["N43"]-0.007058824) +0.4257809*(result["O17"]-0.01823529) +0.2002546*(result["O9"]-0.06176471)); + }catch(e){result['lpv'] = "error"}; + console.log(result['lpv']); + result['lpv_variable']['A'] = A; + return result; + }; + function calculate_and_change_result_value(obj){ + obj.servive_ratio_arr = []; + for(var i = 0;i=48&&event.keyCode<=57||(this.value.indexOf('.')<0?event.keyCode==46:false); + }); + $('.float_num').off('keyup').on('keyup',function(){ + this.value = this.value.replace(/[^\d.]/g,''); + }); + $('.num_only').blur(function() { + if( Number($(this).val()) < $(this).data('range')[0] || $(this).val() == "" || (Number($(this).val()) > $(this).data('range')[1] && $(this).data('range')[1] != undefined) ){ + $(this).css('color','#f24a69'); + $(this).addClass('cancertable_empty'); + }else{ + $(this).css('color','#333'); + $(this).removeClass('cancertable_empty'); + if($('.cancertable_empty').length == 0){ + $('#danger_texts').remove(); + }; + }; + }); + $('select.select_num').off('click').on('click',function(){ + $(this).change(); + }); + $('select.select_num').change(function(){ + if(this.selectedIndex != 0){ + $(this).siblings('input.num_only').val($(this).find('option').eq(this.selectedIndex).text()); + $(this).siblings('input.num_only').removeClass('cancertable_empty'); + $(this).siblings('input.num_only').css('color','#333'); + }else{ + $(this).siblings('input.num_only').addClass('cancertable_empty'); + $(this).siblings('input.num_only').css('color','rgb(242, 74, 105)'); + $(this).siblings('input.num_only').val($(this).val()); + } + $(this).siblings('input.num_only_value').val($(this).val()); + if($('.cancertable_empty').length == 0){ + $('#danger_texts').remove(); + }; + }); + $('input#lymph_nodes_examined').siblings('select.select_num').off('change').on('change',function(){ + var range = $('input#lymph_nodes_positive').data('range'); + range[1] = Number($(this).val()); + $('input#lymph_nodes_positive').data('range_new', range); + if(this.selectedIndex != 0){ + $(this).siblings('input.num_only').val($(this).find('option').eq(this.selectedIndex).text()); + $(this).siblings('input.num_only').removeClass('cancertable_empty'); + $(this).siblings('input.num_only').css('color','#333'); + }else{ + $(this).siblings('input.num_only').addClass('cancertable_empty'); + $(this).siblings('input.num_only').css('color','rgb(242, 74, 105)'); + $(this).siblings('input.num_only').val($(this).val()); + } + $(this).siblings('input.num_only_value').val($(this).val()); + if($('.cancertable_empty').length == 0){ + $('#danger_texts').remove(); + }; + $(this).siblings('.num_only_value').val($(this).val()); + if( Number($('input#lymph_nodes_positive').siblings('.num_only_value').val()) <= Number($(this).val()) ){ + $('input#lymph_nodes_positive').css('color','#333'); + $('input#lymph_nodes_positive').removeClass('cancertable_empty'); + }; + if( Number($(this).val()) < $(this).siblings('.num_only').data('range_new')[0] || $(this).val() == "" || (Number($(this).val()) > $(this).siblings('.num_only').data('range_new')[1] && $(this).siblings('.num_only').data('range_new')[1] != undefined) ){ + $(this).siblings('.num_only').css('color','#f24a69'); + $(this).siblings('.num_only').addClass('cancertable_empty'); + }else{ + $(this).siblings('.num_only').css('color','#333'); + $(this).siblings('.num_only').removeClass('cancertable_empty'); + if($('.cancertable_empty').length == 0){ + $('#danger_texts').remove(); + }; + }; + }); + $('input#lymph_nodes_positive').siblings('select.select_num').off('change').on('change',function(){ + var range = $('input#lymph_nodes_examined').data('range'); + range[0] = Number($(this).val()); + $('input#lymph_nodes_examined').data('range_new', range); + if(this.selectedIndex != 0){ + $(this).siblings('input.num_only').val($(this).find('option').eq(this.selectedIndex).text()); + $(this).siblings('input.num_only').removeClass('cancertable_empty'); + $(this).siblings('input.num_only').css('color','#333'); + }else{ + $(this).siblings('input.num_only').addClass('cancertable_empty'); + $(this).siblings('input.num_only').css('color','rgb(242, 74, 105)'); + $(this).siblings('input.num_only').val($(this).val()); + } + $(this).siblings('input.num_only_value').val($(this).val()); + if($('.cancertable_empty').length == 0){ + $('#danger_texts').remove(); + }; + $(this).siblings('.num_only_value').val($(this).val()); + if( Number($('input#lymph_nodes_examined').siblings('.num_only_value').val()) >= Number($(this).val()) ){ + $('input#lymph_nodes_examined').css('color','#333'); + $('input#lymph_nodes_examined').removeClass('cancertable_empty'); + }; + if( Number($(this).val()) < $(this).siblings('.num_only').data('range_new')[0] || $(this).val() == "" || (Number($(this).val()) > $(this).siblings('.num_only').data('range_new')[1] && $(this).siblings('.num_only').data('range_new')[1] != undefined) ){ + $(this).siblings('.num_only').css('color','#f24a69'); + $(this).siblings('.num_only').addClass('cancertable_empty'); + }else{ + $(this).siblings('.num_only').css('color','#333'); + $(this).siblings('.num_only').removeClass('cancertable_empty'); + if($('.cancertable_empty').length == 0){ + $('#danger_texts').remove(); + }; + }; + }); + $('select.select_num').blur(function() { + if( Number($(this).siblings('.num_only_value').val()) < $(this).siblings('.num_only').data('range')[0] || $(this).siblings('.num_only_value').val() == "" || (Number($(this).siblings('.num_only_value').val()) > $(this).siblings('.num_only').data('range')[1] && $(this).siblings('.num_only').data('range')[1] != undefined) ){ + $(this).siblings('.num_only').css('color','#f24a69'); + $(this).siblings('.num_only').addClass('cancertable_empty'); + }else{ + $(this).siblings('.num_only').css('color','#333'); + $(this).siblings('.num_only').removeClass('cancertable_empty'); + if($('.cancertable_empty').length == 0){ + $('#danger_texts').remove(); + }; + }; + }); + if($(window).width() < 768) + $('#cancer_predict_result').attr('style',''); +}); +$(window).resize(function(){ + if($(window).width() > 768){ + if($('.cancer_table_right_result').length != 0) + $('#cancer_predict_result').css('float','right'); + }else{ + $('#cancer_predict_result').attr('style',''); + }; + if(I18n.locale == 'en'){ + var window_width = $(window).width(); + if(window_width < 520){ + $('#cancer_table .cencer_table_name').css('max-width',''); + }else if(window_width < 768){ + $('#cancer_table .cencer_table_name').css({'max-width':'','width':'11em'}); + }else if(window_width < 860){ + $('#cancer_table .cencer_table_name').css('max-width','30%'); + }else if(window_width < 1130){ + $('#cancer_table .cencer_table_name').css('max-width','33%'); + }else{ + $('#cancer_table .cencer_table_name').css('max-width','39%'); + }; + }; +}); diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 419b7a7..a364356 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -57,4 +57,21 @@ 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: 新增治療選項 +