# 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'] = '此分析微針對已接受手術後病人,下表為此病人分別在第1年、3及5年下,根據選定的術後治療所估計的存活率' result = result.merge(params) render :json=> result end 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 = '
' @table_str_left = '
' @table_str_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 += '
' break if @field_property["name"] == "" @table_str_left += '' if @field_property["comment_text"] != "" @table_str_left += '' @table_str_left += '' else @table_str_left += '
' end if @field_property["is_num"] == 1 @table_str_left += '' else @table_str_left += '
' @field_property["choice_fields"].each do |create_choice| @table_str_left += '' @table_str_left += '' end @table_str_left += '
' end if @field_property["hint"].to_s != "" @table_str_left +='
'+@field_property["hint"]+'
' end @table_str_left += '
' else @table_str_right += '
' break if @field_property["name"] == "" @table_str_right += '' if @field_property["comment_text"] != "" @table_str_right += '' @table_str_right += '' else @table_str_right += '
' end if @field_property["is_num"] == 1 @table_str_right += '' else @table_str_right += '
' @field_property["choice_fields"].each do |create_choice| @table_str_right += '' @table_str_right += '' end @table_str_right += '
' end if @field_property["hint"].to_s != "" @table_str_right +='
'+@field_property["hint"]+'
' end @table_str_right += '
' end end @table_str_left += '
' @table_str_right += '
' @table_str += (@table_str_left+@table_str_right) @table_str +='
' @table_result_str = '
'+t("cancerpredict.table.result").to_s+'
' @table_result_str += '
' @submit_btn_str='' @reset_btn_str='' @table_str += (@submit_btn_str+@reset_btn_str+@table_result_str+'
') else @table_str = OrbitHelper.params.to_s end { "cancerpredict" => [], "extras"=>{"table"=> @table_str} } end def widget uid = OrbitHelper.params[:uid] rescue "" tags = OrbitHelper.widget_tags categories = OrbitHelper.widget_categories || [] locale = OrbitHelper.get_site_locale.to_s end 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 end end