2019-11-15 00:44:28 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
require 'rubyXL'
|
|
|
|
class Admin::CancerpredictsController < OrbitAdminController
|
2019-11-15 09:02:17 +00:00
|
|
|
#include Admin::CancerpredictsHelper
|
2019-11-15 00:44:28 +00:00
|
|
|
before_action ->(module_app = @app_title) { set_variables module_app }
|
2019-11-23 03:15:11 +00:00
|
|
|
before_action :create_first_field
|
2019-11-15 00:44:28 +00:00
|
|
|
#before_action :load_access_levels
|
|
|
|
def initialize
|
|
|
|
super
|
|
|
|
@app_title = "cancerpredict"
|
|
|
|
end
|
|
|
|
|
|
|
|
def index
|
|
|
|
@tags = @module_app.tags
|
|
|
|
@categories = @module_app.categories.enabled
|
|
|
|
@filter_fields = filter_fields(@categories, @tags)
|
|
|
|
@table_fields = [:status, :category, :title, :start_date, :end_date, :last_modified]
|
2019-12-15 13:08:41 +00:00
|
|
|
@head_images_id = @form_to_show.head_images_id
|
|
|
|
@title_images_id = @form_to_show.title_images_id
|
|
|
|
@head_images = []
|
|
|
|
@title_images = []
|
|
|
|
@head_images_id.each{|image_id| @head_images.push Headimages.find_by(:id=>image_id.to_s)} rescue nil
|
|
|
|
@title_images_id.each{|image_id| @title_images.push Headimages.find_by(:id=>image_id.to_s)} rescue nil
|
|
|
|
@head_new_image = Headimages.new(:cancerpredictfields_id => @form_to_show.id)
|
2019-11-15 00:44:28 +00:00
|
|
|
end
|
2019-11-23 08:14:56 +00:00
|
|
|
def edit
|
2019-12-15 13:08:41 +00:00
|
|
|
if !(params["cancerpredictfields"].nil?)
|
|
|
|
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
|
2019-12-11 15:59:17 +00:00
|
|
|
else
|
2019-12-15 13:08:41 +00:00
|
|
|
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
|
|
|
|
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
|
|
|
|
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
|
2019-12-11 15:59:17 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
2019-12-15 13:08:41 +00:00
|
|
|
@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
|
2019-12-11 15:59:17 +00:00
|
|
|
else
|
2019-12-15 13:08:41 +00:00
|
|
|
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
|
2019-12-11 15:59:17 +00:00
|
|
|
else
|
2019-12-15 13:08:41 +00:00
|
|
|
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
|
2019-12-11 15:59:17 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-12-15 13:08:41 +00:00
|
|
|
else
|
|
|
|
@form_to_show.form_show_in_result[num.to_s][key.to_s] = value.to_i
|
2019-12-11 15:59:17 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-01-12 05:14:58 +00:00
|
|
|
@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']
|
|
|
|
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
|
|
|
|
elsif @form_to_show[item].class == Array
|
|
|
|
@form_to_show[item] = YAML.load(params_cancer[item])
|
|
|
|
@form_to_show[item] = [] if @form_to_show[item].class != Array
|
|
|
|
else
|
|
|
|
@form_to_show[item] = params_cancer[item]
|
|
|
|
end
|
|
|
|
end
|
2019-12-15 13:08:41 +00:00
|
|
|
@size = ['small','medium','large']
|
|
|
|
@size.each{|size| @form_to_show[size] = params["cancerpredictfields"][size]}
|
|
|
|
@file_path = Rails.root.to_s + '/app/assets/images/predict_tool'
|
|
|
|
if !Dir.exist? @file_path
|
|
|
|
FileUtils.mkdir_p @file_path
|
|
|
|
end
|
|
|
|
@images = params["cancerpredictfields"]['head_images']
|
|
|
|
@head_images_id = @form_to_show.head_images_id
|
|
|
|
@delete_index = []
|
|
|
|
if !@images.nil?
|
|
|
|
@images.each do |num,image|
|
|
|
|
if num.to_i < @head_images_id.length && @head_images_id.length != 0
|
|
|
|
if image['remove_image'] == "1"
|
|
|
|
@delete_index.push num.to_i
|
2019-12-14 04:21:09 +00:00
|
|
|
else
|
2019-12-15 13:08:41 +00:00
|
|
|
@image_id = @head_images_id[num.to_i]
|
|
|
|
@image = Headimages.find_by(:id=>@image_id.to_s)
|
|
|
|
if !image['sort_number'].nil?
|
|
|
|
@image.sort_number = image['sort_number'].to_i
|
|
|
|
@image.save
|
2019-12-14 04:21:09 +00:00
|
|
|
end
|
2019-12-15 13:08:41 +00:00
|
|
|
next if image['temp_file'] == nil
|
|
|
|
@file_name = image['temp_file'].original_filename.gsub('(','_').gsub(')','_').gsub(' ','_') rescue next
|
|
|
|
@image.sort_number = image['sort_number'].to_i
|
|
|
|
@image.temp_file = image['temp_file']
|
|
|
|
@image.save
|
2019-12-14 04:21:09 +00:00
|
|
|
end
|
|
|
|
else
|
2019-12-15 13:08:41 +00:00
|
|
|
@file_name = image['temp_file'].original_filename.gsub('(','_').gsub(')','_').gsub(' ','_') rescue next
|
2019-12-21 15:50:17 +00:00
|
|
|
@headimages = Headimages.new(:cancerpredictfields_id => @form_to_show.id,:title => @app_title+'head_images')
|
2019-12-15 13:08:41 +00:00
|
|
|
@headimages.temp_file = image['temp_file']
|
|
|
|
@headimages.sort_number = image['sort_number'].to_i if !image['sort_number'].nil?
|
|
|
|
@headimages.save
|
|
|
|
@form_to_show.head_images_id.push @headimages.id
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
@delete_index.reverse!
|
|
|
|
@delete_index.each do |i|
|
|
|
|
@image_id = @head_images_id[i.to_i]
|
|
|
|
Headimages.find_by(:id => @image_id ).destroy rescue next
|
|
|
|
@form_to_show.head_images_id.delete(@image_id)
|
|
|
|
end
|
|
|
|
@images = params["cancerpredictfields"]['title_images']
|
|
|
|
@title_images_id = @form_to_show.title_images_id
|
|
|
|
@delete_index = []
|
|
|
|
if !@images.nil?
|
|
|
|
@images.each do |num,image|
|
|
|
|
if num.to_i < @title_images_id.length && @title_images_id.length != 0
|
|
|
|
if image['remove_image'] == "1"
|
|
|
|
@delete_index.push num.to_i
|
|
|
|
else
|
|
|
|
@image_id = @title_images_id[num.to_i]
|
|
|
|
@image = Headimages.find_by(:id=>@image_id.to_s)
|
|
|
|
if !image['sort_number'].nil?
|
|
|
|
@image.sort_number = image['sort_number'].to_i
|
|
|
|
@image.save
|
2019-12-14 04:21:09 +00:00
|
|
|
end
|
2019-12-15 13:08:41 +00:00
|
|
|
next if image['temp_file'] == nil
|
|
|
|
@file_name = image['temp_file'].original_filename.gsub('(','_').gsub(')','_').gsub(' ','_') rescue next
|
|
|
|
@image.sort_number = image['sort_number'].to_i
|
|
|
|
@image.temp_file = image['temp_file']
|
|
|
|
@image.save
|
2019-12-14 04:21:09 +00:00
|
|
|
end
|
2019-12-15 13:08:41 +00:00
|
|
|
else
|
|
|
|
@file_name = image['temp_file'].original_filename.gsub('(','_').gsub(')','_').gsub(' ','_') rescue next
|
2019-12-21 15:50:17 +00:00
|
|
|
@headimages = Headimages.new(:cancerpredictfields_id => @form_to_show.id,:title => @app_title+'title_images' )
|
2019-12-15 13:08:41 +00:00
|
|
|
@headimages.temp_file = image['temp_file']
|
|
|
|
@headimages.sort_number = image['sort_number'].to_i if !image['sort_number'].nil?
|
|
|
|
@headimages.save
|
|
|
|
@form_to_show.title_images_id.push @headimages.id
|
2019-12-14 04:21:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-12-15 13:08:41 +00:00
|
|
|
@delete_index.reverse!
|
|
|
|
@delete_index.each do |i|
|
|
|
|
@image_id = @title_images_id[i.to_i]
|
|
|
|
Headimages.find_by(:id => @image_id ).destroy rescue next
|
|
|
|
@form_to_show.title_images_id.delete(@image_id)
|
|
|
|
end
|
|
|
|
@form_to_show.save
|
2019-12-14 04:21:09 +00:00
|
|
|
end
|
2020-01-12 05:14:58 +00:00
|
|
|
@index = 0
|
|
|
|
Dir.chdir("public") do
|
|
|
|
while File.exist?('cancerfield_back'+@index.to_s+'.txt')
|
|
|
|
@index += 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
Dir.chdir("public") do
|
|
|
|
@file_back = File.open('cancerfield_back'+@index.to_s+'.txt', 'w')
|
|
|
|
@file_back.write(@form_to_show.attributes)
|
|
|
|
@file_back.close
|
|
|
|
@file_org = File.open('cancerfield_org'+@index.to_s+'.txt', 'w')
|
|
|
|
@file_org.write(Cancerpredictfields.where("title"=>@app_title+'_back').first.attributes)
|
|
|
|
@file_org.close
|
|
|
|
end
|
2019-12-15 13:08:41 +00:00
|
|
|
redirect_to admin_cancerpredicts_path
|
2019-12-11 15:59:17 +00:00
|
|
|
end
|
|
|
|
def showSubmit
|
|
|
|
@results = Cancerpredictrecord.where("title"=>@app_title).take_while{true}
|
|
|
|
@variables = []
|
|
|
|
@names = []
|
|
|
|
@form_to_show.form_show.each do |num,property|
|
|
|
|
property.each do |key,value|
|
|
|
|
if key == "variable"
|
|
|
|
@variables.push value
|
|
|
|
elsif key == "name"
|
|
|
|
@names.push value[I18n.locale.to_s]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
@result_variables = []
|
|
|
|
@result_names = []
|
|
|
|
@indexs=[]
|
2019-12-14 04:21:09 +00:00
|
|
|
@results[0].result.each{|key,value| @result_variables.push key} rescue nil
|
2019-12-11 15:59:17 +00:00
|
|
|
@result_variables.each do |variable|
|
|
|
|
@index = @variables.index(variable.to_s)
|
|
|
|
@result_names.push @names[@index] if !@index.nil?
|
|
|
|
@indexs.push @index if !@index.nil?
|
|
|
|
end
|
|
|
|
@choicenames=[]
|
|
|
|
@indexs.each do |index|
|
|
|
|
if @form_to_show.form_show[index.to_s]["is_num"] == 1 || @form_to_show.form_show[index.to_s]["is_float"] == 1
|
|
|
|
@choicenames.push ""
|
|
|
|
else
|
|
|
|
@choicenames.push @form_to_show.form_show[index.to_s]["choice_fields"][I18n.locale.to_s]
|
|
|
|
end
|
|
|
|
end
|
2019-11-23 08:14:56 +00:00
|
|
|
end
|
2019-11-23 03:15:11 +00:00
|
|
|
def create_first_field
|
2019-11-23 08:14:56 +00:00
|
|
|
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
|
2019-11-23 03:15:11 +00:00
|
|
|
end
|
2019-11-23 08:14:56 +00:00
|
|
|
end
|
2019-11-15 00:44:28 +00:00
|
|
|
end
|