cancer_predict/app/controllers/cancerpredicts_controller.rb

182 lines
8.7 KiB
Ruby
Raw Normal View History

2019-11-15 09:02:17 +00:00
# encoding: utf-8
require 'rubyXL'
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 || []
locale = OrbitHelper.get_site_locale.to_s
result = {:result=>"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)
result['size1'] = -Math.log(params['data']['size'].to_f/10,10)
result['nposit'] = -((params['data']['ratio'].to_f+0.1)/0.1)**0.5
if params['data']['grade'].to_i == 2
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 params['data']['subtype'].to_i == 2
result['subtype_HER2'] = 1
else
result['subtype_HER2'] = 0
end
if params['data']['subtype'].to_i == 3
result['subtype_triple'] = 1
else
result['subtype_triple'] = 0
end
if params['data']['pstage'].to_i == 2
result['pstage_2'] = 1
else
result['pstage_2'] = 0
end
if params['data']['pstage'].to_i == 3
result['pstage_3'] = 1
else
result['pstage_3'] = 0
end
if params['data']['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 0)
result['table'] = '<a id="cancer_table_texts">此分析微針對已接受手術後病人下表為此病人分別在第1年、3及5年下根據選定的術後治療所估計的存活率</a>'
result = result.merge(params)
render :json=> result
end
2019-11-15 09:02:17 +00:00
def index
uid = OrbitHelper.params[:uid] rescue ""
tags = OrbitHelper.widget_tags
categories = OrbitHelper.widget_categories || []
locale = OrbitHelper.get_site_locale.to_s
if (OrbitHelper.params[:result] == nil rescue true)
@table_str = '<div id="cancer_table"><div id="show_help_modal" class="modal fade"></div>'
@table_str_left = '<div id="cancer_table_left">'
@table_str_right = '<div id="cancer_table_right">'
create_first_field
@form_to_show.form_show.each do |num,property|
@field_property = {}
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
@field_property[key] = @disp_value
end
if @field_property['right'] == 0
@table_str_left += '<div data-key='+num.to_s+'>'
break if @field_property["name"] == ""
@table_str_left += '<label for="'+@field_property["variable"]+'" style="float:left;'+(@field_property["comment_text"] == "" ? "margin-right: 2.125em;" : "")+'" class="cencer_table_name">'
@table_str_left += @field_property["name"]
@table_str_left += '</label>'
if @field_property["comment_text"] != ""
@table_str_left += '<button tabindex="0" class="cancer_help_btn" data-target="#show_help_modal" style="float:left;cursor: pointer;padding: 0em 0.475em;font-size: 1.25em;border-radius: 15px;background-color: rgb(210, 106, 2);border-color: rgb(210, 106, 2);color: white;"></button>'
@table_str_left += '<input class="help_texts" type="hidden" value="'+@field_property["comment_text"]+'" name='+@field_property["variable"]+'></input>'
else
@table_str_left += '<div style="margin-right: 2.125em;"></div>'
end
if @field_property["is_num"] == 1
@table_str_left += '<input class="num_only cancer_form_field" id="'+@field_property["variable"]+'" style="float:left;clear:right;" data-range="'+@field_property["range"].to_s+'"></input><button class="btn-sub"></button><button class="btn-add"></button>'
else
@table_str_left += '<div class= "cancer-btn-group cancer_form_field" id="'+@field_property["variable"]+'" style="float:left;clear:right;">'
@field_property["choice_fields"].each do |create_choice|
@table_str_left += '<button class="cancer_table_btn btn btn-default btn-sm">'+create_choice+'</button>'
@table_str_left += '<input type="hidden" value="0" name="'+create_choice+'"></input>'
end
@table_str_left += '</div>'
end
if @field_property["hint"].to_s != ""
@table_str_left +='<div style="color: rgb(104, 104, 104);font-size:0.75em;clear:both;">'+@field_property["hint"]+'</div>'
end
@table_str_left += '</div><div style="clear:both;"></div>'
else
@table_str_right += '<div data-key='+num.to_s+'>'
break if @field_property["name"] == ""
@table_str_right += '<label for="'+@field_property["variable"]+'" style="float:left;'+(@field_property["comment_text"] == "" ? "margin-right: 2.125em;" : "")+'" class="cencer_table_name">'
@table_str_right += @field_property["name"]
@table_str_right += '</label>'
if @field_property["comment_text"] != ""
@table_str_right += '<button tabindex="0" class="cancer_help_btn" data-target="#show_help_modal" style="float:left;cursor: pointer;padding: 0em 0.475em;font-size: 1.25em;border-radius: 15px;background-color: rgb(210, 106, 2);border-color: rgb(210, 106, 2);color: white;"></button>'
@table_str_right += '<input class="help_texts" type="hidden" value="'+@field_property["comment_text"]+'" name='+@field_property["variable"]+'></input>'
else
@table_str_right += '<div style="margin-right: 2.125em;"></div>'
end
if @field_property["is_num"] == 1
@table_str_right += '<input class="num_only cancer_form_field" id="'+@field_property["variable"]+'" style="float:left;clear:right;" data-range="'+@field_property["range"].to_s+'"></input><button class="btn-sub"></button><button class="btn-add"></button>'
else
@table_str_right += '<div class= "cancer-btn-group cancer_form_field" id="'+@field_property["variable"]+'" style="float:left;clear:right;">'
@field_property["choice_fields"].each do |create_choice|
@table_str_right += '<button class="cancer_table_btn btn btn-default btn-sm">'+create_choice+'</button>'
@table_str_right += '<input type="hidden" value="0" name="'+create_choice+'"></input>'
end
@table_str_right += '</div>'
end
if @field_property["hint"].to_s != ""
@table_str_right +='<div style="color: rgb(104, 104, 104);font-size:0.75em;clear:both;">'+@field_property["hint"]+'</div>'
end
@table_str_right += '</div><div style="clear:both;"></div>'
end
2019-11-23 08:14:56 +00:00
end
@table_str_left += '</div>'
@table_str_right += '</div>'
@table_str += (@table_str_left+@table_str_right)
@table_str +='<div style="clear:both;"></div>'
@table_result_str = '<div id="cancer_predict_result" style="display:block;"><span id="result_title">'+t("cancerpredict.table.result").to_s+'</span><div style="clear:both;"></div>'
@table_result_str += '<div class="result_tab_group">'
@table_result_str += '<div id="result_table" class="result_tab"><a>'+t("cancerpredict.table.table").to_s+'</a></div><div style="clear:both;"></div>'
@table_result_str += '<div id="result_curve" class="result_tab"><a>'+t("cancerpredict.table.curve").to_s+'</a></div><div style="clear:both;"></div>'
@table_result_str += '<div id="result_text" class="result_tab"><a>'+t("cancerpredict.table.text").to_s+'<a></div><div style="clear:both;"></div></div></div>'
@submit_btn_str='<button id="cancer_table_submit">'+t('cancerpredict.table.Submit').to_s+'</button>'
@reset_btn_str='<button id="cancer_table_reset">'+t('cancerpredict.table.Reset').to_s+'</button>'
@table_str += (@submit_btn_str+@reset_btn_str+@table_result_str+'</div>')
else
@table_str = OrbitHelper.params.to_s
2019-11-23 08:14:56 +00:00
end
{
"cancerpredict" => [],
"extras"=>{"table"=> @table_str}
}
2019-11-15 09:02:17 +00:00
end
def widget
uid = OrbitHelper.params[:uid] rescue ""
tags = OrbitHelper.widget_tags
categories = OrbitHelper.widget_categories || []
locale = OrbitHelper.get_site_locale.to_s
end
2019-11-23 08:14:56 +00:00
def create_first_field
if Cancerpredictfields.where("title"=>(@app_title + "_back")).take_while{true}.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
@form_to_show = Cancerpredictfields.new()
@form_to_show.title=@app_title
@form_to_show.save
@form_to_show = Cancerpredictfields.where("title"=>@app_title).first
else
@form_to_show = Cancerpredictfields.where("title"=>@app_title).first
end
2019-11-15 09:02:17 +00:00
end
end