Compare commits

..

49 Commits

Author SHA1 Message Date
邱博亞 5eeb34e336 Fix bug. 2024-03-18 21:32:30 +08:00
邱博亞 2f0225db2a remove carrierwave/processing/mime_type for new version 2024-03-18 21:22:15 +08:00
BoHung Chiu 40d63b69b3 Fix js not reload bug. 2022-06-17 21:31:24 +08:00
BoHung Chiu b58d757848 Fix bug. 2022-05-23 18:38:11 +08:00
BoHung Chiu 4116037d83 Fix bug. 2022-05-23 18:21:35 +08:00
BoHung Chiu 8c0d8a955d Fix js bug. 2022-02-25 10:56:10 +08:00
BoHung Chiu e31e1e85e0 Fix js bug. 2022-02-25 10:49:59 +08:00
BoHung Chiu c9d670f796 Fix bug. 2022-02-09 16:04:34 +08:00
BoHung Chiu cdb18dafd8 Fix css. 2022-02-09 15:38:25 +08:00
BoHung Chiu 8b10901dae Fix bug. 2022-02-08 15:43:27 +08:00
BoHung Chiu 3c97c85649 Fix bug. 2022-02-07 19:24:39 +08:00
BoHung Chiu f9f96c5045 Fix bug. 2022-02-07 19:00:39 +08:00
BoHung Chiu 4115a98ecb Fix bug. 2022-02-07 18:30:42 +08:00
BoHung Chiu f157dffc28 Fix bug. 2022-02-07 17:29:17 +08:00
BoHung Chiu d969d02990 Fix bug. 2022-01-28 15:51:58 +08:00
BoHung Chiu 4fd40830be Fix bug. 2022-01-28 15:50:24 +08:00
BoHung Chiu 14deddb4aa Fix bug. 2022-01-28 15:41:17 +08:00
BoHung Chiu a2ffbf9230 Fix backend page bug. 2022-01-28 12:51:21 +08:00
BoHung Chiu cac17bef8c Fix bug. 2022-01-27 17:02:29 +08:00
BoHung Chiu 92345e9ac3 Fix bug. 2022-01-26 19:57:13 +08:00
BoHung Chiu e5205fab5f Fix bug. 2022-01-26 19:40:14 +08:00
BoHung Chiu 05f913f513 Update cancer_predict.js. 2022-01-26 19:28:53 +08:00
BoHung Chiu b8e6e80d81 Update to version2.(Fix all known bugs.) 2022-01-26 19:19:28 +08:00
BoHung Chiu 73c46c2b51 change translations. 2022-01-23 17:17:49 +08:00
BoHung Chiu 9d2872b884 Fix js contents. 2022-01-23 16:58:03 +08:00
BoHung Chiu a56f6ba5e3 Fix bug.(Accelerate most time) 2022-01-23 14:00:57 +08:00
BoHung Chiu 360a86fecd Fix bug. 2022-01-22 18:47:32 +08:00
BoHung Chiu 96465e34f3 Fix bug. 2022-01-22 17:27:15 +08:00
BoHung Chiu 8041af8fd6 Update default settings. 2022-01-22 12:56:22 +08:00
BoHung Chiu 0ff0b42b70 Fix bug. 2022-01-22 12:52:03 +08:00
BoHung Chiu a6bb253f20 Change translation. 2020-10-23 15:05:18 +08:00
chiu 285c543f71 Remove unused file. 2020-10-23 10:53:56 +08:00
chiu 43711808e9 Change a lot,including mapping files and add feature that users can edit calculation formula at backend page by themself. 2020-10-23 10:52:23 +08:00
BOHUNG 4d41c5bce0 change tool name translation 2020-03-18 19:05:36 +08:00
BOHUNG 1561620c83 change tool name translation 2020-03-18 19:03:51 +08:00
BOHUNG 17f3fe623d change translation 2020-03-18 18:24:43 +08:00
BOHUNG 70b66409dd change table in tool. 2020-03-18 18:22:13 +08:00
BOHUNG a1aeeb008a fix bugs and change text for ntu_coph. 2020-03-04 15:37:59 +08:00
bohung 97337b7716 fix 2020-02-27 16:31:32 +08:00
bohung 802c4de893 fix 2020-02-27 16:11:01 +08:00
bohung be40283db0 fix 2020-02-27 16:06:51 +08:00
bohung b813662f4f first edit 2020-02-27 16:04:44 +08:00
BOHUNG 05a2a18763 add module_name to fix translations missing. 2020-02-24 15:29:23 +08:00
BOHUNG 7441a96bc5 fix bug 2020-02-06 15:48:50 +08:00
BOHUNG d1f87a2370 add export record feature 2020-02-03 16:49:00 +08:00
BOHUNG d8255b6ad0 fix 2020-02-03 15:26:04 +08:00
BOHUNG 62045584fc push from final_version to master 2020-01-28 18:29:04 +08:00
BOHUNG 294d98f83f copy from final_version branch to master 2020-01-13 19:35:30 +08:00
BOHUNG 34b4187716 finish reset_btn and set a submit_btn 2019-11-22 17:43:39 +08:00
11 changed files with 1147 additions and 1109 deletions

View File

@ -327,20 +327,6 @@ $(document).ready(function(){
$('[for="hormone_therapy"]').css('color',''); $('[for="hormone_therapy"]').css('color','');
}; };
/*disable_condition start*/ /*disable_condition start*/
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','');
}
/*disable_condition end*/ /*disable_condition end*/
return post_json; return post_json;
}else{ }else{
@ -352,7 +338,7 @@ $(document).ready(function(){
$('#choice_fields .cancer_table_btn').removeClass('active'); $('#choice_fields .cancer_table_btn').removeClass('active');
var load_heml = $('#result_table_content').html(result.responseJSON.table); var load_heml = $('#result_table_content').html(result.responseJSON.table);
load_heml.ready(function(){ load_heml.ready(function(){
$('#result_table_content .cancer_years').eq(-1).addClass('active'); $('#result_table_content .cancer_years').eq(0).addClass('active');
for(var i = 0;i < $('#result_table_content .cancer_years').length;i++){ 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').eq(i).attr('index',i)
}; };
@ -368,7 +354,7 @@ $(document).ready(function(){
}); });
load_heml = $('#result_text_content').html(result.responseJSON.texts); load_heml = $('#result_text_content').html(result.responseJSON.texts);
load_heml.ready(function(){ load_heml.ready(function(){
$('#result_text_content .cancer_years').eq(-1).addClass('active'); $('#result_text_content .cancer_years').eq(0).addClass('active');
for(var i = 0;i < $('#result_text_content .cancer_years').length;i++){ for(var i = 0;i < $('#result_text_content .cancer_years').length;i++){
$('#result_text_content .cancer_years').eq(i).attr('index',i) $('#result_text_content .cancer_years').eq(i).attr('index',i)
}; };
@ -405,9 +391,9 @@ $(document).ready(function(){
$('span.'+active_treatment[0]+'.Overall_Survival').html(Math.round(servive_ratio_arr[0])); $('span.'+active_treatment[0]+'.Overall_Survival').html(Math.round(servive_ratio_arr[0]));
$('#cancer_predict_result_block').css('display','block'); $('#cancer_predict_result_block').css('display','block');
var lpv_real = [result.responseJSON['lpv_variable']]; var lpv_real = [result.responseJSON['lpv_variable']];
var lpv = /*therapy_lpv start*/[0, -0.8397, -0.4147, -0.3203, -0.4687];/*therapy_lpv end*/; var lpv = /*therapy_lpv start*/[0];/*therapy_lpv end*/;
var lpv_dict={}; var lpv_dict={};
var lpv_calc=/*lpv_calc_formula_start*/{"1":"Math.exp(-0.001476145)**( Math.exp(lpv_current) )","3":"Math.exp(-0.01261639)**( Math.exp(lpv_current) )","5":"Math.exp(-0.02519608)**( Math.exp(lpv_current) )"};/*lpv_calc_formula_end*/ var lpv_calc=/*lpv_calc_formula_start*/{"1":"0.8095037**( Math.exp(lpv_current) )","1.5":"0.729158**( Math.exp(lpv_current) )","2":"0.6717211**( Math.exp(lpv_current) )","2.5":"0.6056773**( Math.exp(lpv_current) )"};/*lpv_calc_formula_end*/
active_treatment.push = function() { active_treatment.push = function() {
if(arguments.length == 1){ if(arguments.length == 1){
var year = $('#current_year').attr('value'); var year = $('#current_year').attr('value');
@ -416,7 +402,7 @@ $(document).ready(function(){
var lpv_current = change_object_variables(lpv_real[lpv_real.length-1],{"lpv": lpv_dict[arguments[0]]},'+'); var lpv_current = change_object_variables(lpv_real[lpv_real.length-1],{"lpv": lpv_dict[arguments[0]]},'+');
lpv_real.push(lpv_current); lpv_real.push(lpv_current);
lpv_current = lpv_current['lpv']; lpv_current = lpv_current['lpv'];
var servive_ratio = round(eval(lpv_calc[year])*100,2); var servive_ratio = round((1 - eval(lpv_calc[year]))*100,2);
var benefit = servive_ratio - servive_ratio_arr[servive_ratio_arr.length - 1]; var benefit = servive_ratio - servive_ratio_arr[servive_ratio_arr.length - 1];
servive_ratio_arr.push(servive_ratio); servive_ratio_arr.push(servive_ratio);
$('tr.'+arguments[0]+' td.Overall_Survival').html(servive_ratio+'%'); $('tr.'+arguments[0]+' td.Overall_Survival').html(servive_ratio+'%');
@ -461,7 +447,7 @@ $(document).ready(function(){
change_object_variables(lpv_real[i] , {"lpv": lpv_dict[arguments[0]]} , '-' , 'self'); change_object_variables(lpv_real[i] , {"lpv": lpv_dict[arguments[0]]} , '-' , 'self');
var lpv_current = lpv_real[i]; var lpv_current = lpv_real[i];
lpv_current = lpv_current['lpv']; lpv_current = lpv_current['lpv'];
var servive_ratio = round(eval(lpv_calc[year])*100,2); var servive_ratio = round((1 - eval(lpv_calc[year]))*100,2);
servive_ratio_arr[i] = servive_ratio; servive_ratio_arr[i] = servive_ratio;
var benefit = servive_ratio - ((i == index+1) ? servive_ratio_arr[index - 1] : servive_ratio_arr[i - 1]); 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+'%'); $('tr.'+active_treatment[i]+' td.Overall_Survival').html(servive_ratio+'%');
@ -617,75 +603,135 @@ $(document).ready(function(){
function calculate_first_lpv(result_json){ function calculate_first_lpv(result_json){
result = {}; result = {};
var map_values , mapping_hash , temp_index ,temp_value , index , closest_value; var map_values , mapping_hash , temp_index ,temp_value , index , closest_value;
result['sex_value'] = (2 - Number(result_json['sex_value']));
result['age'] = Number(result_json['age']); result['age'] = Number(result_json['age']);
result['size'] = Number(result_json['size']); mapping_hash = mapping_data_from_csv['age'];
result['lymph_nodes_examined'] = Number(result_json['lymph_nodes_examined']); temp_index = 0;
result['lymph_nodes_positive'] = Number(result_json['lymph_nodes_positive']); temp_value = result['age'];
result['grade'] = Number(result_json['grade']); index = 0;
result['ER_status'] = Number(result_json['ER_status']); $.each(mapping_hash,function(k,v){
result['PR_status'] = Number(result_json['PR_status']); if( index == 0 ){
result['HER2_status'] = Number(result_json['HER2_status']); var index_val = v.indexOf(temp_value);
result['Distant_Metastasis'] = Number(result_json['Distant_Metastasis']); if( index_val != -1 ){
result['micrometastasis'] = Number(result_json['micrometastasis']); temp_index = index_val;
result['tumor_direct_extension'] = Number(result_json['tumor_direct_extension']); }else{
result['lvi'] = Number(result_json['lvi']); closest_value = v.get_nearest_value(temp_value);
result['hormone_therapy'] = Number(result_json['hormone_therapy']); temp_index = v.indexOf(closest_value)
result['Chemotherapy'] = Number(result_json['Chemotherapy']); }
result['Radiotherapy'] = Number(result_json['Radiotherapy']); }
result['Targeted_therapy'] = Number(result_json['Targeted_therapy']); 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( index == 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( index == 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( index == 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( index == 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['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['N14'] = (2 - Number(result_json['N14']));
result['N26'] = (2 - Number(result_json['N26']));
result['O3'] = (2 - Number(result_json['O3']));
result['O20'] = (2 - Number(result_json['O20']));
result['O18'] = (2 - Number(result_json['O18']));
result['O11'] = (2 - Number(result_json['O11']));
result['N29'] = (2 - Number(result_json['N29']));
result['N6'] = (2 - Number(result_json['N6']));
result['O14'] = (2 - Number(result_json['O14']));
result['N43'] = (2 - Number(result_json['N43']));
result['O17'] = (2 - Number(result_json['O17']));
result['O9'] = (2 - Number(result_json['O9']));
Object.keys(result).forEach(function(k){ Object.keys(result).forEach(function(k){
if(Number.isNaN(result[k])){ if(Number.isNaN(result[k])){
result[k] = 0; result[k] = 0;
} }
}) })
age1 = (result["age"] / 100.0) ** (0.5); ;
age2 = age1 * Math.log(result["age"] / 100.0);
size1 = Math.log(result["size"] / 10.0);
ratio = (result["lymph_nodes_examined"] == 0 ? 0 : (1.0 * result["lymph_nodes_positive"] / result["lymph_nodes_examined"]));
ratio = (ratio > 1 ? 1 : ratio);
T4 = (result["tumor_direct_extension"] == 1);
T1 = !T4 && (result["size"] <= 20);
T2 = !T4 && !T1 && (result["size"] > 20 && result["size"] <= 50);
T = (T4 ? 'T4' : (T1 ? 'T1' : (T2 ? 'T2' : 'T3')));
N0 = (result["lymph_nodes_positive"] == 0);
N1_or_N1mi = !N0 && (result["lymph_nodes_positive"] >= 1 && result["lymph_nodes_positive"] <= 3);
N1 = N1_or_N1mi && result["micrometastasis"] != 1;
N1mi = N1_or_N1mi && result["micrometastasis"] == 1;
N2 = !N0 && !N1_or_N1mi && (result["lymph_nodes_positive"] <= 9);
N = (N0 ? 'N0' : (N1 ? 'N1' : (N1mi ? 'N1mi' : (N2 ? 'N2' : 'N3'))));
M = (result["Distant_Metastasis"] != 1) ? 'M0' : 'M1';
pstage = (M == 'M1' ? 4 : ((T == 'T1' && (N == 'N0' || N == 'N1mi')) ? 1 : (((T == 'T2' || T == 'T3') && (N == 'N0')) || ((T == 'T1' || T == 'T2') && (N == 'N1')) ? 2 : 3)) );
nposit = ((ratio + 0.1) / 0.1) ** 0.5;
grade_2 = (result["grade"] == 2 || result["grade"] == 4) ? 1 : 0;
grade_3 = (result["grade"] == 3) ? 1 : 0;
subtype_1 = (result["ER_status"] != 2 || result["PR_status"] != 2) && (result["HER2_status"] != 1);
subtype_2 = !subtype_1 && (result["HER2_status"] == 1);
subtype_3 = !subtype_1 && !subtype_2 && (result["ER_status"] == 2 && result["PR_status"] == 2 && result["HER2_status"] != 1);
subtype_HER2 = subtype_2 ? 1 : 0;
subtype_triple = subtype_3 ? 1 : 0;
pstage_2 = (pstage == 2) ? 1 : 0;
pstage_3 = (pstage == 3) ? 1 : 0;
pstage_4 = (pstage == 4) ? 1 : 0;
lvi_yes = (result["lvi"] == 1) ? 1 : 0;
chemo = (result["Chemotherapy"] == 2) ? 1 : 0;
radio = (result["Radiotherapy"] == 2) ? 1 : 0;
hormone = (result["hormone_therapy"] == 2) ? 1 : 0;
target = (result["Targeted_therapy"] == 2) ? 1 : 0;
try{ try{
lpv = ((age1-0.7276655)*(-10.87)+(age2+0.4540707)*8.968+(size1-0.643632)*0.7678+(nposit-1.346932)*0.5339+ grade_2*0.4795+grade_3*0.818+subtype_HER2*0.1806+subtype_triple*0.6457+pstage_2*0.5311+ pstage_3*1.134+pstage_4*2.172+lvi_yes*0.3321-0.04+chemo*(-0.4147)+radio*(-0.3203)+hormone*(-0.8397)+target*(-0.4687) 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.00004697183*( 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) +0.4305973*(result["N14"]-0.02176471) -0.4472885*(result["N29"]-0.02411765) +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){console.log(e)}; }catch(e){console.log(e)};
result['lpv_variable'] = {}; result['lpv_variable'] = {};
result['lpv_variable']['lpv'] = lpv; result['lpv_variable']['A'] = A;
result['lpv'] = lpv; result['lpv'] = A;
result['lpv_variable']['lpv'] = result['lpv']; result['lpv_variable']['lpv'] = result['lpv'];
return result; return result;
}; };
function calculate_and_change_result_value(obj){ function calculate_and_change_result_value(obj){
obj.servive_ratio_arr = []; obj.servive_ratio_arr = [];
for(var i = 0;i<obj.active_treatment.length;i++){ for(var i = 0;i<obj.active_treatment.length;i++){
var servive_ratio = round(calculate_servive_ratio(obj.year,obj.lpv_real[i])*100,2); var servive_ratio = round((1 - calculate_servive_ratio(obj.year,obj.lpv_real[i]))*100,2);
var benefit = servive_ratio - obj.servive_ratio_arr[obj.servive_ratio_arr.length-1]; var benefit = servive_ratio - obj.servive_ratio_arr[obj.servive_ratio_arr.length-1];
obj.servive_ratio_arr.push(servive_ratio); obj.servive_ratio_arr.push(servive_ratio);
$('tr.'+obj.active_treatment[i]+' td.Overall_Survival').html(servive_ratio+'%'); $('tr.'+obj.active_treatment[i]+' td.Overall_Survival').html(servive_ratio+'%');
@ -700,16 +746,19 @@ $(document).ready(function(){
function calculate_servive_ratio(year,obj){ function calculate_servive_ratio(year,obj){
var servive_ratio; var servive_ratio;
var lpv = obj['lpv']; var A = obj['A'];
switch(year) { switch(year) {
case '1': case '1':
servive_ratio = Math.exp(-0.001476145)**( Math.exp(lpv) ); servive_ratio = 0.8095037**( Math.exp(A) );
break; break;
case '3': case '1.5':
servive_ratio = Math.exp(-0.01261639)**( Math.exp(lpv) ); servive_ratio = 0.729158**( Math.exp(A) );
break; break;
case '5': case '2':
servive_ratio = Math.exp(-0.02519608)**( Math.exp(lpv) ); servive_ratio = 0.6717211**( Math.exp(A) );
break;
case '2.5':
servive_ratio = 0.6056773**( Math.exp(A) );
break; break;
default: default:
console.log('not found year.'); console.log('not found year.');

View File

@ -1,8 +1,8 @@
# encoding: utf-8 # encoding: utf-8
class Admin::CancerpredictsController < OrbitAdminController class Admin::CancerpredictsController < OrbitAdminController
require "spreadsheet" require 'spreadsheet'
require "rubyXL" require 'rubyXL'
require "fileutils" require 'fileutils'
require "axlsx" require "axlsx"
require "csv" require "csv"
#include Admin::CancerpredictsHelper #include Admin::CancerpredictsHelper
@ -14,11 +14,6 @@ class Admin::CancerpredictsController < OrbitAdminController
super super
@app_title = "cancerpredict" @app_title = "cancerpredict"
end end
def yaml_load(v)
YAML.load(v)
end
def index def index
@tags = @module_app.tags @tags = @module_app.tags
@categories = @module_app.categories.enabled @categories = @module_app.categories.enabled
@ -28,18 +23,17 @@ class Admin::CancerpredictsController < OrbitAdminController
@title_images_id = @form_to_show.title_images_id @title_images_id = @form_to_show.title_images_id
@head_images = [] @head_images = []
@title_images = [] @title_images = []
@head_images_id.each { |image_id| @head_images.push Headimages.find_by(:id => image_id.to_s) } rescue nil @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 @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) @head_new_image = Headimages.new(:cancerpredictfields_id => @form_to_show.id)
end end
def edit def edit
other_in_use_locales = Site.first.in_use_locales.map { |l| l.to_s } other_in_use_locales = Site.first.in_use_locales.map{|l| l.to_s}
other_in_use_locales.delete(params[:locale]) other_in_use_locales.delete(params[:locale])
if !(params["cancerpredictfields"].nil?) if !(params["cancerpredictfields"].nil?)
if !(params["cancerpredictfields"]["form_show"].nil?) if !(params["cancerpredictfields"]["form_show"].nil?)
params["cancerpredictfields"]["form_show"].each do |num, property| params["cancerpredictfields"]["form_show"].each do |num,property|
property.each do |key, value| property.each do |key,value|
if key.include?("_file") && (!value[:temp_file].blank? rescue false) if key.include?("_file") && (!value[:temp_file].blank? rescue false)
if value[:id].nil? if value[:id].nil?
mapping_file = CancerPredictMappingFile.create(value) mapping_file = CancerPredictMappingFile.create(value)
@ -75,37 +69,37 @@ class Admin::CancerpredictsController < OrbitAdminController
end end
else else
if value.length > 2 if value.length > 2
@form_to_show.form_show[num.to_s][key.to_s] = yaml_load(value) @form_to_show.form_show[num.to_s][key.to_s] = YAML.load(value)
else else
@form_to_show.form_show[num.to_s][key.to_s] = [] @form_to_show.form_show[num.to_s][key.to_s] = []
end end
end end
else else
value.each do |sub_property, sub_value| value.each do |sub_property,sub_value|
type = Cancerpredictfields::FIELDINFO[sub_property.to_s] type = Cancerpredictfields::FIELDINFO[sub_property.to_s]
if type && Cancerpredictfields::Field_relations[type] if type && Cancerpredictfields::Field_relations[type]
type = Cancerpredictfields::Field_relations[type] type = Cancerpredictfields::Field_relations[type]
end end
type = type.constantize rescue String type = type.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? @form_to_show.form_show[ num.to_s ][ sub_property ] = {} if @form_to_show.form_show[num.to_s][ sub_property ].nil?
if type != Array if type != Array
if type == Fixnum if type == Fixnum
@form_to_show.form_show[num.to_s][sub_property][params[:locale].to_s] = sub_value.to_i rescue 0 @form_to_show.form_show[ num.to_s ][ sub_property ][params[:locale].to_s] = sub_value.to_i rescue 0
elsif type == Float elsif type == Float
@form_to_show.form_show[num.to_s][sub_property][params[:locale].to_s] = sub_value.to_f rescue 0.0 @form_to_show.form_show[ num.to_s ][ sub_property ][params[:locale].to_s] = sub_value.to_f rescue 0.0
else else
@form_to_show.form_show[num.to_s][sub_property][params[:locale].to_s] = sub_value @form_to_show.form_show[ num.to_s ][ sub_property ][params[:locale].to_s] = sub_value
end end
else else
if sub_value.length > 2 if sub_value.length > 2
@form_to_show.form_show[num.to_s][sub_property][params[:locale].to_s] = yaml_load(sub_value) @form_to_show.form_show[ num.to_s ][ sub_property ][params[:locale].to_s] = YAML.load(sub_value)
else else
@form_to_show.form_show[num.to_s][sub_property][params[:locale].to_s] = [] @form_to_show.form_show[ num.to_s ][ sub_property ][params[:locale].to_s] = []
end end
end end
if (property["old_num"].present? && property["old_num"] != num.to_s) if(property["old_num"].present? && property["old_num"] != num.to_s)
other_in_use_locales.each do |locale| 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] @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
end end
@ -114,20 +108,20 @@ class Admin::CancerpredictsController < OrbitAdminController
end end
end end
org_nums = @form_to_show.form_show_was.keys 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? } remain_org_nums = params["cancerpredictfields"]["form_show"].values.map{|property| property["old_num"]}.select{|n| n.present?}
delete_nums = org_nums - remain_org_nums delete_nums = org_nums - remain_org_nums
if !delete_nums.blank? if !delete_nums.blank?
delete_nums.each do |delete_num| delete_nums.each do |delete_num|
@form_to_show.form_show.delete(delete_num) @form_to_show.form_show.delete(delete_num)
end end
end end
@form_to_show.form_show = @form_to_show.form_show.values.map.with_index { |v, i| [i.to_s, v] }.to_h @form_to_show.form_show = @form_to_show.form_show.values.map.with_index{|v,i| [i.to_s, v]}.to_h
else else
@form_to_show.form_show = {} @form_to_show.form_show = {}
end end
if !params["cancerpredictfields"]["form_show_in_result"].nil? if !params["cancerpredictfields"]["form_show_in_result"].nil?
params["cancerpredictfields"]["form_show_in_result"].each do |num, property| params["cancerpredictfields"]["form_show_in_result"].each do |num,property|
property.each do |key, value| property.each do |key,value|
if key.include?("_file") && (!value[:temp_file].blank? rescue false) if key.include?("_file") && (!value[:temp_file].blank? rescue false)
if value[:id].nil? if value[:id].nil?
mapping_file = CancerPredictMappingFile.create(value) mapping_file = CancerPredictMappingFile.create(value)
@ -163,37 +157,37 @@ class Admin::CancerpredictsController < OrbitAdminController
end end
else else
if value.length > 2 if value.length > 2
@form_to_show.form_show_in_result[num.to_s][key.to_s] = yaml_load(value) @form_to_show.form_show_in_result[num.to_s][key.to_s] = YAML.load(value)
else else
@form_to_show.form_show_in_result[num.to_s][key.to_s] = [] @form_to_show.form_show_in_result[num.to_s][key.to_s] = []
end end
end end
else else
value.each do |sub_property, sub_value| value.each do |sub_property,sub_value|
type = Cancerpredictfields::FIELDINFO[sub_property.to_s] type = Cancerpredictfields::FIELDINFO[sub_property.to_s]
if type && Cancerpredictfields::Field_relations[type] if type && Cancerpredictfields::Field_relations[type]
type = Cancerpredictfields::Field_relations[type] type = Cancerpredictfields::Field_relations[type]
end end
type = type.constantize rescue String type = type.constantize rescue String
@form_to_show.form_show_in_result[num.to_s][sub_property] = {} if @form_to_show.form_show_in_result[num.to_s][sub_property].nil? @form_to_show.form_show_in_result[ num.to_s ][ sub_property ] = {} if @form_to_show.form_show_in_result[num.to_s][ sub_property ].nil?
if type != Array if type != Array
if type == Fixnum if type == Fixnum
@form_to_show.form_show_in_result[num.to_s][sub_property][params[:locale].to_s] = sub_value.to_i rescue 0 @form_to_show.form_show_in_result[ num.to_s ][ sub_property ][params[:locale].to_s] = sub_value.to_i rescue 0
elsif type == Float elsif type == Float
@form_to_show.form_show_in_result[num.to_s][sub_property][params[:locale].to_s] = sub_value.to_f rescue 0.0 @form_to_show.form_show_in_result[ num.to_s ][ sub_property ][params[:locale].to_s] = sub_value.to_f rescue 0.0
else else
@form_to_show.form_show_in_result[num.to_s][sub_property][params[:locale].to_s] = sub_value @form_to_show.form_show_in_result[ num.to_s ][ sub_property ][params[:locale].to_s] = sub_value
end end
else else
if sub_value.length > 2 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) @form_to_show.form_show_in_result[ num.to_s ][ sub_property ][params[:locale].to_s] = YAML.load(sub_value)
else else
@form_to_show.form_show_in_result[num.to_s][sub_property][params[:locale].to_s] = [] @form_to_show.form_show_in_result[ num.to_s ][ sub_property ][params[:locale].to_s] = []
end end
end end
if (property["old_num"].present? && property["old_num"] != num.to_s) if(property["old_num"].present? && property["old_num"] != num.to_s)
other_in_use_locales.each do |locale| 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_was[property["old_num"]][sub_property][locale] @form_to_show.form_show_in_result[ num.to_s ][ sub_property ][locale] = @form_to_show.form_show_was[ property["old_num"] ][ sub_property ][locale]
end end
end end
end end
@ -202,18 +196,18 @@ class Admin::CancerpredictsController < OrbitAdminController
end end
end end
org_nums = @form_to_show.form_show_in_result_was.keys 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? } 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 delete_nums = org_nums - remain_org_nums
if !delete_nums.blank? if !delete_nums.blank?
delete_nums.each do |delete_num| delete_nums.each do |delete_num|
@form_to_show.form_show_in_result.delete(delete_num) @form_to_show.form_show_in_result.delete(delete_num)
end end
end end
@form_to_show.form_show_in_result = @form_to_show.form_show_in_result.values.map.with_index { |v, i| [i.to_s, v] }.to_h @form_to_show.form_show_in_result = @form_to_show.form_show_in_result.values.map.with_index{|v,i| [i.to_s, v]}.to_h
else else
@form_to_show.form_show_in_result = {} @form_to_show.form_show_in_result = {}
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", "hidden_variables", "advance_mode", "years_settings"] @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','hidden_variables','advance_mode','years_settings']
params_cancer = params.require("cancerpredictfields").permit! params_cancer = params.require("cancerpredictfields").permit!
@create_items.each do |item| @create_items.each do |item|
if (@form_to_show[item].class == BSON::Document) || (@form_to_show.send(item).class == Hash) if (@form_to_show[item].class == BSON::Document) || (@form_to_show.send(item).class == Hash)
@ -222,7 +216,7 @@ class Admin::CancerpredictsController < OrbitAdminController
@form_to_show[item] = item_hash @form_to_show[item] = item_hash
elsif @form_to_show[item].class == Array elsif @form_to_show[item].class == Array
if params_cancer[item].class != Array if params_cancer[item].class != Array
@form_to_show[item] = yaml_load(params_cancer[item]) rescue [] @form_to_show[item] = YAML.load(params_cancer[item]) rescue []
else else
@form_to_show[item] = params_cancer[item] @form_to_show[item] = params_cancer[item]
end end
@ -231,38 +225,38 @@ class Admin::CancerpredictsController < OrbitAdminController
@form_to_show[item] = params_cancer[item] @form_to_show[item] = params_cancer[item]
end end
end end
@size = ["small", "medium", "large"] @size = ['small','medium','large']
@size.each { |size| @form_to_show[size] = params["cancerpredictfields"][size].to_h } @size.each{|size| @form_to_show[size] = params["cancerpredictfields"][size]}
@file_path = Rails.root.to_s + "/app/assets/images/predict_tool" @file_path = Rails.root.to_s + '/app/assets/images/predict_tool'
if !Dir.exist? @file_path if !Dir.exist? @file_path
FileUtils.mkdir_p @file_path FileUtils.mkdir_p @file_path
end end
@images = params["cancerpredictfields"]["head_images"] @images = params["cancerpredictfields"]['head_images']
@head_images_id = @form_to_show.head_images_id @head_images_id = @form_to_show.head_images_id
@delete_index = [] @delete_index = []
if !@images.nil? if !@images.nil?
@images.each do |num, image| @images.each do |num,image|
if num.to_i < @head_images_id.length && @head_images_id.length != 0 if num.to_i < @head_images_id.length && @head_images_id.length != 0
if image["remove_image"] == "1" if image['remove_image'] == "1"
@delete_index.push num.to_i @delete_index.push num.to_i
else else
@image_id = @head_images_id[num.to_i] @image_id = @head_images_id[num.to_i]
@image = Headimages.find_by(:id => @image_id.to_s) @image = Headimages.find_by(:id=>@image_id.to_s)
if !image["sort_number"].nil? if !image['sort_number'].nil?
@image.sort_number = image["sort_number"].to_i @image.sort_number = image['sort_number'].to_i
@image.save @image.save
end end
next if image["temp_file"] == nil next if image['temp_file'] == nil
@file_name = image["temp_file"].original_filename.gsub("(", "_").gsub(")", "_").gsub(" ", "_") rescue next @file_name = image['temp_file'].original_filename.gsub('(','_').gsub(')','_').gsub(' ','_') rescue next
@image.sort_number = image["sort_number"].to_i @image.sort_number = image['sort_number'].to_i
@image.temp_file = image["temp_file"] @image.temp_file = image['temp_file']
@image.save @image.save
end end
else else
@file_name = image["temp_file"].original_filename.gsub("(", "_").gsub(")", "_").gsub(" ", "_") rescue next @file_name = image['temp_file'].original_filename.gsub('(','_').gsub(')','_').gsub(' ','_') rescue next
@headimages = Headimages.new(:cancerpredictfields_id => @form_to_show.id, :title => @app_title + "head_images") @headimages = Headimages.new(:cancerpredictfields_id => @form_to_show.id,:title => @app_title+'head_images')
@headimages.temp_file = image["temp_file"] @headimages.temp_file = image['temp_file']
@headimages.sort_number = image["sort_number"].to_i if !image["sort_number"].nil? @headimages.sort_number = image['sort_number'].to_i if !image['sort_number'].nil?
@headimages.save @headimages.save
@form_to_show.head_images_id.push @headimages.id @form_to_show.head_images_id.push @headimages.id
end end
@ -271,35 +265,35 @@ class Admin::CancerpredictsController < OrbitAdminController
@delete_index.reverse! @delete_index.reverse!
@delete_index.each do |i| @delete_index.each do |i|
@image_id = @head_images_id[i.to_i] @image_id = @head_images_id[i.to_i]
Headimages.find_by(:id => @image_id).destroy rescue next Headimages.find_by(:id => @image_id ).destroy rescue next
@form_to_show.head_images_id.delete(@image_id) @form_to_show.head_images_id.delete(@image_id)
end end
@images = params["cancerpredictfields"]["title_images"] @images = params["cancerpredictfields"]['title_images']
@title_images_id = @form_to_show.title_images_id @title_images_id = @form_to_show.title_images_id
@delete_index = [] @delete_index = []
if !@images.nil? if !@images.nil?
@images.each do |num, image| @images.each do |num,image|
if num.to_i < @title_images_id.length && @title_images_id.length != 0 if num.to_i < @title_images_id.length && @title_images_id.length != 0
if image["remove_image"] == "1" if image['remove_image'] == "1"
@delete_index.push num.to_i @delete_index.push num.to_i
else else
@image_id = @title_images_id[num.to_i] @image_id = @title_images_id[num.to_i]
@image = Headimages.find_by(:id => @image_id.to_s) @image = Headimages.find_by(:id=>@image_id.to_s)
if !image["sort_number"].nil? if !image['sort_number'].nil?
@image.sort_number = image["sort_number"].to_i @image.sort_number = image['sort_number'].to_i
@image.save @image.save
end end
next if image["temp_file"] == nil next if image['temp_file'] == nil
@file_name = image["temp_file"].original_filename.gsub("(", "_").gsub(")", "_").gsub(" ", "_") rescue next @file_name = image['temp_file'].original_filename.gsub('(','_').gsub(')','_').gsub(' ','_') rescue next
@image.sort_number = image["sort_number"].to_i @image.sort_number = image['sort_number'].to_i
@image.temp_file = image["temp_file"] @image.temp_file = image['temp_file']
@image.save @image.save
end end
else else
@file_name = image["temp_file"].original_filename.gsub("(", "_").gsub(")", "_").gsub(" ", "_") rescue next @file_name = image['temp_file'].original_filename.gsub('(','_').gsub(')','_').gsub(' ','_') rescue next
@headimages = Headimages.new(:cancerpredictfields_id => @form_to_show.id, :title => @app_title + "title_images") @headimages = Headimages.new(:cancerpredictfields_id => @form_to_show.id,:title => @app_title+'title_images' )
@headimages.temp_file = image["temp_file"] @headimages.temp_file = image['temp_file']
@headimages.sort_number = image["sort_number"].to_i if !image["sort_number"].nil? @headimages.sort_number = image['sort_number'].to_i if !image['sort_number'].nil?
@headimages.save @headimages.save
@form_to_show.title_images_id.push @headimages.id @form_to_show.title_images_id.push @headimages.id
end end
@ -308,13 +302,13 @@ class Admin::CancerpredictsController < OrbitAdminController
@delete_index.reverse! @delete_index.reverse!
@delete_index.each do |i| @delete_index.each do |i|
@image_id = @title_images_id[i.to_i] @image_id = @title_images_id[i.to_i]
Headimages.find_by(:id => @image_id).destroy rescue next Headimages.find_by(:id => @image_id ).destroy rescue next
@form_to_show.title_images_id.delete(@image_id) @form_to_show.title_images_id.delete(@image_id)
end end
file_ids = (@form_to_show.form_show.values + @form_to_show.form_show_in_result.values).map { |property| [property[:variable], property[:cancer_predict_mapping_file]] }.select { |k, f| f.present? }.to_h file_ids = (@form_to_show.form_show.values + @form_to_show.form_show_in_result.values).map{|property| [property[:variable],property[:cancer_predict_mapping_file]]}.select{|k,f| f.present?}.to_h
mapping_data_from_csv = {} mapping_data_from_csv = {}
if !file_ids.blank? if !file_ids.blank?
file_ids.each do |k, v| file_ids.each do |k,v|
mapping_data_from_csv[k] = read_mapping_file(v) mapping_data_from_csv[k] = read_mapping_file(v)
end end
end end
@ -324,46 +318,51 @@ class Admin::CancerpredictsController < OrbitAdminController
@form_to_show.auto_write_predict_js @form_to_show.auto_write_predict_js
end end
end end
@index = 0
Dir.chdir("public") do
while File.exist?('cancerfield_back'+@index.to_s+'.txt')
@index += 1
end
end
Dir.chdir("public") do
@site_locales = Site.last.in_use_locales.each do |locale| @site_locales = Site.last.in_use_locales.each do |locale|
I18n.with_locale(locale) do I18n.with_locale(locale) do
File.open(Cancerpredictfields::ToolTableMap[I18n.locale], "w") do |f| @file_tmp = File.new('cancer_tool_table_tmp_'+locale.to_s+'.txt', 'w')
tmp_table_texts = create_table(locale) tmp_table_texts = create_table(locale)
f.write(tmp_table_texts) @file_tmp.write(tmp_table_texts)
@file_tmp.close
end end
end end
end end
idx = 0 Dir.chdir("public") do
while File.exist?("public/cancerfield_back#{idx}.txt") @file_back = File.open('cancerfield_back'+@index.to_s+'.txt', 'w')
idx += 1 @file_back.write(@form_to_show.attributes)
end @file_back.close
File.open("public/cancerfield_back#{idx}.txt", "w") do |f| @file_org = File.open('cancerfield_org'+@index.to_s+'.txt', 'w')
f.write(@form_to_show.attributes) @file_org.write(Cancerpredictfields.where("title"=>@app_title+'_back').first.attributes)
end @file_org.close
File.open("public/cancerfield_org#{idx}.txt", "w") do |f|
f.write(Cancerpredictfields.where("title" => @app_title + "_back").first.attributes)
end end
redirect_to admin_cancerpredicts_path redirect_to admin_cancerpredicts_path
end end
def create_table(current_locale) def create_table(current_locale)
create_first_field create_first_field
current_site = Site.last current_site = Site.last
@size = {} @size = {}
@size_name = ["small", "medium", "large"] @size_name = ['small','medium','large']
@size_name.each { |name| @size[name] = @form_to_show[name]["font_size"] } @size_name.each{|name| @size[name] = @form_to_show[name]['font_size']}
@size_active_size = "" @size_active_size = ''
@size.each { |size_key, size_value| (@form_to_show[size_key]["active"].to_i == 1) ? (@size_active_size = size_value) : nil } @size.each{|size_key,size_value| (@form_to_show[size_key]['active'].to_i == 1) ? ( @size_active_size = size_value ): nil }
@table_str = '<div id="cancer_table" style="font-size:' + @size_active_size + ';"><div id="show_help_modal" class="modal fade"></div>' @table_str = '<div id="cancer_table" style="font-size:' + @size_active_size + ';"><div id="show_help_modal" class="modal fade"></div>'
@table_str += '<div id="cancer_table_top"><div id="text_describe">' + @form_to_show.text_descibe[current_locale] + "</div>" @table_str += '<div id="cancer_table_top"><div id="text_describe">'+@form_to_show.text_descibe[current_locale] +'</div>'
@table_str += '<div id="font_size_choices">' + '<label id="font_texts">' + t("cancerpredict.font_size").titleize + ":</label>" @table_str += '<div id="font_size_choices">'+'<label id="font_texts">'+t('cancerpredict.font_size').titleize+':</label>'
@size.each { |size_key, size_value| @table_str += ('<button class="cancer_table_btn ' + ((@form_to_show[size_key]["active"].to_i == 1) ? "active" : "") + ' btn btn-default btn-sm" onclick="document.getElementById(\'cancer_table\').style[\'font-size\']=\'' + size_value + '\';document.getElementById(\'cancer_predict_result_block\').style[\'font-size\']=\'' + size_value + '\';">' + t("cancerpredict." + size_key).titleize + "</button>") } @size.each{|size_key,size_value| @table_str += ('<button class="cancer_table_btn '+((@form_to_show[size_key]['active'].to_i == 1) ? 'active' :'') + ' btn btn-default btn-sm" onclick="document.getElementById(\'cancer_table\').style[\'font-size\']=\''+size_value+'\';document.getElementById(\'cancer_predict_result_block\').style[\'font-size\']=\''+size_value+'\';">'+t('cancerpredict.'+size_key).titleize+'</button>' )}
@table_str += '</div></div><div style="clear:both;"></div>' @table_str += '</div></div><div style="clear:both;"></div>'
@table_str_left = '<div id="cancer_table_left">' @table_str_left = '<div id="cancer_table_left">'
@table_str_right = '<div id="cancer_table_right">' @table_str_right = '<div id="cancer_table_right">'
@form_to_show.form_show.each do |num, property| @form_to_show.form_show.each do |num,property|
@field_property = {} @field_property = {}
property.each do |key, value| property.each do |key,value|
@value = value @value= value
@disp_value @disp_value
if @value.class == BSON::Document || @value.class == Hash if @value.class == BSON::Document || @value.class == Hash
@disp_value = @value[current_locale] rescue "" @disp_value = @value[current_locale] rescue ""
@ -373,15 +372,15 @@ class Admin::CancerpredictsController < OrbitAdminController
@disp_value = "" if @disp_value.nil? @disp_value = "" if @disp_value.nil?
@field_property[key] = @disp_value @field_property[key] = @disp_value
end end
if @field_property["right"] == 0 if @field_property['right'] == 0
next if @field_property["name"].blank? next if @field_property["name"].blank?
@table_str_left += "<div data-key=" + num.to_s + ">" @table_str_left += '<div data-key='+num.to_s+'>'
@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 += '<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 += @field_property["name"]
@table_str_left += "</label>" @table_str_left += '</label>'
if @field_property["comment_text"].present? if @field_property["comment_text"].present?
@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;"><i aria-hidden="true" class="fa fa-question"></i></button>' @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;"><i aria-hidden="true" class="fa fa-question"></i></button>'
@table_str_left += '<input class="help_texts" type="hidden" value="' + @field_property["comment_text"] + '" name=' + @field_property["variable"] + "/>" @table_str_left += '<input class="help_texts" type="hidden" value="'+@field_property["comment_text"]+'" name='+@field_property["variable"]+'/>'
else else
@site_locales = current_site.in_use_locales @site_locales = current_site.in_use_locales
@site_locales.delete(current_locale) @site_locales.delete(current_locale)
@ -392,55 +391,55 @@ class Admin::CancerpredictsController < OrbitAdminController
end end
if @field_property["comment_text"].present? if @field_property["comment_text"].present?
@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;"><i aria-hidden="true" class="fa fa-question"></i></button>' @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;"><i aria-hidden="true" class="fa fa-question"></i></button>'
@table_str_left += '<input class="help_texts" type="hidden" value="' + @field_property["comment_text"] + '" name=' + @field_property["variable"] + "/>" @table_str_left += '<input class="help_texts" type="hidden" value="'+@field_property["comment_text"]+'" name='+@field_property["variable"]+'/>'
else else
@table_str_left += '<div style="margin-right: 2.125em;float: left;"></div>' @table_str_left += '<div style="margin-right: 2.125em;float: left;"></div>'
end end
end end
if @field_property["is_num"] == 1 if @field_property["is_num"] == 1
if @field_property["is_float"] == 1 if @field_property["is_float"] == 1
@table_str_left += '<div class="num_group"><input class="num_only float_num cancer_form_field" id="' + @field_property["variable"] + '" style="float:left;clear:right;" data-range="' + @field_property["range"].to_s + '"/><input class="num_only_value" type="hidden" /></div>' @table_str_left += '<div class="num_group"><input class="num_only float_num cancer_form_field" id="'+@field_property["variable"]+'" style="float:left;clear:right;" data-range="'+@field_property["range"].to_s+'"/><input class="num_only_value" type="hidden" /></div>'
else else
if @field_property["range"] == [] if @field_property["range"] == []
@table_str_left += '<div class="num_group"><input class="num_only float_num cancer_form_field" id="' + @field_property["variable"] + '" style="float:left;clear:right;" data-range="' + @field_property["range"].to_s + '"/></div>' @table_str_left += '<div class="num_group"><input class="num_only float_num cancer_form_field" id="'+@field_property["variable"]+'" style="float:left;clear:right;" data-range="'+@field_property["range"].to_s+'"/></div>'
else else
@table_str_left += '<div class="num_group"><form class="for_num">' @table_str_left += '<div class="num_group"><form class="for_num">'
@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 + '" onkeyup="value=value.replace(/[^\d]/g,\'\') "onbeforepaste="clipboardData.setData(\'text\',clipboardData.getData(\'text\').replace(/[^\d]/g,\'\'))"/>' @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+'" onkeyup="value=value.replace(/[^\d]/g,\'\') "onbeforepaste="clipboardData.setData(\'text\',clipboardData.getData(\'text\').replace(/[^\d]/g,\'\'))"/>'
@table_str_left += '<input class="num_only_value" type="hidden" value="0"/>' @table_str_left += '<input class="num_only_value" type="hidden" value="0"/>'
@please_choice = (current_locale.to_s == "zh_tw") ? "請選擇" : "Please choice" @please_choice = (current_locale.to_s == "zh_tw") ? "請選擇" : "Please choice"
@table_str_left += '<select class="select_num"><option value="">' + @please_choice + "</option>" @table_str_left += '<select class="select_num"><option value="">'+@please_choice+'</option>'
if @field_property["choice_fields"] != [] if @field_property["choice_fields"] != []
@field_property["choice_fields"].each do |choice| @field_property["choice_fields"].each do |choice|
@table_str_left += ('<option value="0">' + choice.to_s.titleize + "</option>") @table_str_left += ('<option value="0">' + choice.to_s.titleize + '</option>')
end end
end end
for @num in @field_property["range"][0]..@field_property["range"][1] for @num in @field_property["range"][0] .. @field_property["range"][1]
@table_str_left += ('<option value="' + @num.to_s + '">' + @num.to_s + "</option>") @table_str_left += ('<option value="' + @num.to_s + '">' + @num.to_s + '</option>')
end end
@table_str_left += "</select></form></div>" @table_str_left += '</select></form></div>'
end end
end end
else else
@table_str_left += '<div class= "cancer-btn-group cancer_form_field" id="' + @field_property["variable"] + '" style="float:left;clear:right;">' @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| @field_property["choice_fields"].each do |create_choice|
@table_str_left += '<button class="cancer_table_btn btn btn-default btn-sm">' + create_choice.to_s.titleize + "</button>" @table_str_left += '<button class="cancer_table_btn btn btn-default btn-sm">'+create_choice.titleize+'</button>'
@table_str_left += '<input type="hidden" value="0" name="' + create_choice.to_s + '"/>' @table_str_left += '<input type="hidden" value="0" name="'+create_choice+'"/>'
end end
@table_str_left += "</div>" @table_str_left += '</div>'
end end
if @field_property["hint"].to_s != "" 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>" @table_str_left +='<div style="color: rgb(104, 104, 104);font-size:0.75em;clear:both;">'+@field_property["hint"]+'</div>'
end end
@table_str_left += '</div><div style="clear:both;"></div>' @table_str_left += '</div><div style="clear:both;"></div>'
else else
@table_str_right += "<div data-key=" + num.to_s + ">" @table_str_right += '<div data-key='+num.to_s+'>'
break if @field_property["name"] == "" 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 += '<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 += @field_property["name"]
@table_str_right += "</label>" @table_str_right += '</label>'
if @field_property["comment_text"].present? if @field_property["comment_text"].present?
@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;"><i aria-hidden="true" class="fa fa-question"></i></button>' @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;"><i aria-hidden="true" class="fa fa-question"></i></button>'
@table_str_right += '<input class="help_texts" type="hidden" value="' + @field_property["comment_text"] + '" name=' + @field_property["variable"] + "/>" @table_str_right += '<input class="help_texts" type="hidden" value="'+@field_property["comment_text"]+'" name='+@field_property["variable"]+'/>'
else else
@site_locales = current_site.in_use_locales @site_locales = current_site.in_use_locales
@site_locales.delete(current_locale) @site_locales.delete(current_locale)
@ -451,72 +450,72 @@ class Admin::CancerpredictsController < OrbitAdminController
end end
if @field_property["comment_text"].present? if @field_property["comment_text"].present?
@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;"><i aria-hidden="true" class="fa fa-question"></i></button>' @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;"><i aria-hidden="true" class="fa fa-question"></i></button>'
@table_str_right += '<input class="help_texts" type="hidden" value="' + @field_property["comment_text"] + '" name=' + @field_property["variable"] + "/>" @table_str_right += '<input class="help_texts" type="hidden" value="'+@field_property["comment_text"]+'" name='+@field_property["variable"]+'/>'
else else
@table_str_right += '<div style="margin-right: 2.125em;float: left;"></div>' @table_str_right += '<div style="margin-right: 2.125em;float: left;"></div>'
end end
end end
if @field_property["is_num"] == 1 if @field_property["is_num"] == 1
if @field_property["is_float"] == 1 if @field_property["is_float"] == 1
@table_str_right += '<div class="num_group"><input class="num_only float_num cancer_form_field" id="' + @field_property["variable"] + '" style="float:left;clear:right;" data-range="' + @field_property["range"].to_s + '"/><input class="num_only_value" type="hidden" /></div>' @table_str_right += '<div class="num_group"><input class="num_only float_num cancer_form_field" id="'+@field_property["variable"]+'" style="float:left;clear:right;" data-range="'+@field_property["range"].to_s+'"/><input class="num_only_value" type="hidden" /></div>'
else else
if @field_property["range"] == [] if @field_property["range"] == []
@table_str_left += '<div class="num_group"><input class="num_only float_num cancer_form_field" id="' + @field_property["variable"] + '" style="float:left;clear:right;" data-range="' + @field_property["range"].to_s + '"/></div>' @table_str_left += '<div class="num_group"><input class="num_only float_num cancer_form_field" id="'+@field_property["variable"]+'" style="float:left;clear:right;" data-range="'+@field_property["range"].to_s+'"/></div>'
else else
@table_str_right += '<div class="num_group"><form class="for_num">' @table_str_right += '<div class="num_group"><form class="for_num">'
@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 + '" onkeyup="value=value.replace(/[^\d]/g,\'\') "onbeforepaste="clipboardData.setData(\'text\',clipboardData.getData(\'text\').replace(/[^\d]/g,\'\'))"/>' @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+'" onkeyup="value=value.replace(/[^\d]/g,\'\') "onbeforepaste="clipboardData.setData(\'text\',clipboardData.getData(\'text\').replace(/[^\d]/g,\'\'))"/>'
@table_str_right += '<input class="num_only_value" type="hidden" value="0"/>' @table_str_right += '<input class="num_only_value" type="hidden" value="0"/>'
@please_choice = (current_locale.to_s == "zh_tw") ? "請選擇" : "Please choice" @please_choice = (current_locale.to_s == "zh_tw") ? "請選擇" : "Please choice"
@table_str_right += '<select class="select_num"><option value="">' + @please_choice + "</option>" @table_str_right += '<select class="select_num"><option value="">'+@please_choice+'</option>'
if @field_property["choice_fields"] != [] if @field_property["choice_fields"] != []
@field_property["choice_fields"].each do |choice| @field_property["choice_fields"].each do |choice|
@table_str_right += ('<option value="0">' + choice.to_s.titleize + "</option>") @table_str_right += ('<option value="0">' + choice.to_s.titleize + '</option>')
end end
end end
for @num in @field_property["range"][0]..@field_property["range"][1] for @num in @field_property["range"][0] .. @field_property["range"][1]
@table_str_right += ('<option value="' + @num.to_s + '">' + @num.to_s + "</option>") @table_str_right += ('<option value="' + @num.to_s + '">' + @num.to_s + '</option>')
end end
@table_str_right += "</select></form></div>" @table_str_right += '</select></form></div>'
end end
end end
else else
@table_str_right += '<div class= "cancer-btn-group cancer_form_field" id="' + @field_property["variable"] + '" style="float:left;clear:right;">' @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| @field_property["choice_fields"].each do |create_choice|
@table_str_right += '<button class="cancer_table_btn btn btn-default btn-sm">' + create_choice.to_s.titleize + "</button>" @table_str_right += '<button class="cancer_table_btn btn btn-default btn-sm">'+create_choice.titleize+'</button>'
@table_str_right += '<input type="hidden" value="0" name="' + create_choice.to_s + '"/>' @table_str_right += '<input type="hidden" value="0" name="'+create_choice+'"/>'
end end
@table_str_right += "</div>" @table_str_right += '</div>'
end end
if @field_property["hint"].to_s != "" if @field_property["hint"].to_s != ""
@table_str_right += '<div class="hint-texts">' + @field_property["hint"] + "</div>" @table_str_right +='<div class="hint-texts">'+@field_property["hint"]+'</div>'
end end
@table_str_right += '</div><div style="clear:both;"></div>' @table_str_right += '</div><div style="clear:both;"></div>'
end end
end end
@table_str_left += "</div>" @table_str_left += '</div>'
@table_str_right += "</div>" @table_str_right += '</div>'
@table_str += (@table_str_left + @table_str_right) @table_str += (@table_str_left+@table_str_right)
@table_str += '<div style="clear:both;"></div>' @table_str +='<div style="clear:both;"></div>'
@table_result_str = '<div id="cancer_predict_result" style="' + ((@form_to_show.form_result_is_right == 0) ? "float:right;" : "") + '"><span class="result_title">' + t("cancerpredict.table.result").to_s + '</span><div style="clear:both;"></div>' @table_result_str = '<div id="cancer_predict_result" style="'+((@form_to_show.form_result_is_right == 0) ? 'float:right;' : '')+'"><span class="result_title">'+t("cancerpredict.table.result").to_s+'</span><div style="clear:both;"></div>'
@tab_name = ["table", "text"] @tab_name = ['table','text']
@table_result_str += '<div class="texts_under_result">' + @form_to_show.texts_between_Result_and_result_block[current_locale] + "</div>" @table_result_str +='<div class="texts_under_result">' + @form_to_show.texts_between_Result_and_result_block[current_locale]+'</div>'
@table_result_str += '<div id="result_contents"><div class="result_tab_group">' @table_result_str += '<div id="result_contents"><div class="result_tab_group">'
@tab_name.each_with_index { |name, index| @table_result_str += ('<div id="result_' + name + '_tab" class="result_tab' + ((index != 0) ? "" : " active") + '"><a>' + t("cancerpredict.table." + name).to_s + '</a></div><div style="clear:both;"></div>') } @tab_name.each_with_index{|name,index| @table_result_str += ('<div id="result_'+name+'_tab" class="result_tab'+((index != 0) ? "" : " active")+'"><a>'+t("cancerpredict.table."+name).to_s+'</a></div><div style="clear:both;"></div>')}
@table_result_str += '</div><div class="result_content_group">' @table_result_str += '</div><div class="result_content_group">'
@tab_name.each { |name| @table_result_str += '<div id="result_' + name + '_content" class="result_content"><a>' + "no content" + "</a></div>" } @tab_name.each{|name| @table_result_str += '<div id="result_'+name+'_content" class="result_content"><a>'+'no content'+'</a></div>'}
@table_result_str += "</div></div></div>" @table_result_str += '</div></div></div>'
@table_button = '<div id="cancer_table_button_group">' @table_button = '<div id="cancer_table_button_group">'
@submit_btn_str = '<button id="cancer_table_submit">' + t("cancerpredict.table.Submit").to_s + "</button>" @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>" @reset_btn_str='<button id="cancer_table_reset">'+t('cancerpredict.table.Reset').to_s+'</button>'
@table_button += (@submit_btn_str + @reset_btn_str + '<div style="clear:both;"></div></div></div>') @table_button += (@submit_btn_str+@reset_btn_str+'<div style="clear:both;"></div></div></div>')
@table_result_choice_fileds = '<div id="cancer_table_right_result">' if @form_to_show.form_result_is_right == 1 @table_result_choice_fileds = '<div id="cancer_table_right_result">' if @form_to_show.form_result_is_right == 1
@table_result_choice_fileds = '<div id="cancer_table_left_result">' if @form_to_show.form_result_is_right == 0 @table_result_choice_fileds = '<div id="cancer_table_left_result">' if @form_to_show.form_result_is_right == 0
@table_result_choice_fileds += '<span class="result_title">' + t("cancerpredict.table.Therapy_choice").to_s + '</span><div style="clear:both;"></div>' @table_result_choice_fileds += '<span class="result_title">'+t('cancerpredict.table.Therapy_choice').to_s+'</span><div style="clear:both;"></div>'
@table_result_choice_fileds += '<div id="choice_fields">' @table_result_choice_fileds += '<div id="choice_fields">'
@form_to_show.form_show_in_result.each do |num, property| @form_to_show.form_show_in_result.each do |num,property|
@field_property = {} @field_property = {}
property.each do |key, value| property.each do |key,value|
@value = value @value= value
if @value.class == BSON::Document || @value.class == Hash if @value.class == BSON::Document || @value.class == Hash
@disp_value = @value[current_locale.to_s] rescue "" @disp_value = @value[current_locale.to_s] rescue ""
else else
@ -525,14 +524,14 @@ class Admin::CancerpredictsController < OrbitAdminController
@disp_value = "" if @disp_value.nil? @disp_value = "" if @disp_value.nil?
@field_property[key] = @disp_value @field_property[key] = @disp_value
end end
@table_result_choice_fileds += "<div data-key=" + num.to_s + ">" @table_result_choice_fileds += '<div data-key='+num.to_s+'>'
break if @field_property["name"] == "" break if @field_property["name"] == ""
@table_result_choice_fileds += '<label for="' + @field_property["variable"] + '" style="float:left;' + (@field_property["comment_text"] == "" ? "margin-right: 2.125em;" : "") + '" class="cencer_table_name">' @table_result_choice_fileds += '<label for="'+@field_property["variable"]+'" style="float:left;'+(@field_property["comment_text"] == "" ? "margin-right: 2.125em;" : "")+'" class="cencer_table_name">'
@table_result_choice_fileds += @field_property["name"] @table_result_choice_fileds += @field_property["name"]
@table_result_choice_fileds += "</label>" @table_result_choice_fileds += '</label>'
if @field_property["comment_text"].present? if @field_property["comment_text"].present?
@table_result_choice_fileds += '<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;"><i aria-hidden="true" class="fa fa-question"></i></button>' @table_result_choice_fileds += '<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;"><i aria-hidden="true" class="fa fa-question"></i></button>'
@table_result_choice_fileds += '<input class="help_texts" type="hidden" value="' + @field_property["comment_text"] + '" name=' + @field_property["variable"] + "></input>" @table_result_choice_fileds += '<input class="help_texts" type="hidden" value="'+@field_property["comment_text"]+'" name='+@field_property["variable"]+'></input>'
else else
@site_locales = current_site.in_use_locales @site_locales = current_site.in_use_locales
@site_locales.delete(current_locale) @site_locales.delete(current_locale)
@ -543,59 +542,58 @@ class Admin::CancerpredictsController < OrbitAdminController
end end
if @field_property["comment_text"].present? if @field_property["comment_text"].present?
@table_result_choice_fileds += '<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;"><i aria-hidden="true" class="fa fa-question"></i></button>' @table_result_choice_fileds += '<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;"><i aria-hidden="true" class="fa fa-question"></i></button>'
@table_result_choice_fileds += '<input class="help_texts" type="hidden" value="' + @field_property["comment_text"] + '" name=' + @field_property["variable"] + "/>" @table_result_choice_fileds += '<input class="help_texts" type="hidden" value="'+@field_property["comment_text"]+'" name='+@field_property["variable"]+'/>'
else else
@table_result_choice_fileds += '<div style="margin-right: 2.125em;float: left;"></div>' @table_result_choice_fileds += '<div style="margin-right: 2.125em;float: left;"></div>'
end end
end end
if @field_property["is_num"] == 1 if @field_property["is_num"] == 1
if @field_property["is_float"] == 1 if @field_property["is_float"] == 1
@table_result_choice_fileds += '<div class="num_group"><input class="num_only float_num cancer_form_field" id="' + @field_property["variable"] + '" style="float:left;clear:right;" data-range="' + @field_property["range"].to_s + '"/><input class="num_only_value" type="hidden" /></button>' @table_result_choice_fileds += '<div class="num_group"><input class="num_only float_num cancer_form_field" id="'+@field_property["variable"]+'" style="float:left;clear:right;" data-range="'+@field_property["range"].to_s+'"/><input class="num_only_value" type="hidden" /></button>'
else else
if @field_property["range"] == [] if @field_property["range"] == []
@table_str_left += '<div class="num_group"><input class="num_only float_num cancer_form_field" id="' + @field_property["variable"] + '" style="float:left;clear:right;" data-range="' + @field_property["range"].to_s + '"/></div>' @table_str_left += '<div class="num_group"><input class="num_only float_num cancer_form_field" id="'+@field_property["variable"]+'" style="float:left;clear:right;" data-range="'+@field_property["range"].to_s+'"/></div>'
else else
@table_result_choice_fileds += '<div class="num_group"><form class="for_num">' @table_result_choice_fileds += '<div class="num_group"><form class="for_num">'
@table_result_choice_fileds += '<input class="num_only cancer_form_field" id="' + @field_property["variable"] + '" style="float:left;clear:right;" data-range="' + @field_property["range"].to_s + '" onkeyup="value=value.replace(/[^\d]/g,\'\') "onbeforepaste="clipboardData.setData(\'text\',clipboardData.getData(\'text\').replace(/[^\d]/g,\'\'))"/><button class="btn-sub"></button><button class="btn-add"></button></div>' @table_result_choice_fileds += '<input class="num_only cancer_form_field" id="'+@field_property["variable"]+'" style="float:left;clear:right;" data-range="'+@field_property["range"].to_s+'" onkeyup="value=value.replace(/[^\d]/g,\'\') "onbeforepaste="clipboardData.setData(\'text\',clipboardData.getData(\'text\').replace(/[^\d]/g,\'\'))"/><button class="btn-sub"></button><button class="btn-add"></button></div>'
@table_str_left += '<input class="num_only_value" type="hidden" value="0"/>' @table_str_left += '<input class="num_only_value" type="hidden" value="0"/>'
@please_choice = (current_locale.to_s == "zh_tw") ? "請選擇" : "Please choice" @please_choice = (current_locale.to_s == "zh_tw") ? "請選擇" : "Please choice"
@table_result_choice_fileds += '<select class="select_num"><option value="">' + @please_choice + "</option>" @table_result_choice_fileds += '<select class="select_num"><option value="">'+@please_choice+'</option>'
if @field_property["choice_fields"] != [] if @field_property["choice_fields"] != []
@field_property["choice_fields"].each do |choice| @field_property["choice_fields"].each do |choice|
@table_result_choice_fileds += ('<option value="0">' + choice.to_s.titleize + "</option>") @table_result_choice_fileds += ('<option value="0">' + choice.to_s.titleize + '</option>')
end end
end end
for @num in @field_property["range"][0]..@field_property["range"][1] for @num in @field_property["range"][0] .. @field_property["range"][1]
@table_result_choice_fileds += ('<option value="' + @num.to_s + '">' + @num.to_s + "</option>") @table_result_choice_fileds += ('<option value="' + @num.to_s + '">' + @num.to_s + '</option>')
end end
@table_result_choice_fileds += "</select></form></div>" @table_result_choice_fileds += '</select></form></div>'
end end
end end
else else
@table_result_choice_fileds += '<div class= "cancer-btn-group cancer_form_field" id="' + @field_property["variable"] + '" style="float:left;clear:right;">' @table_result_choice_fileds += '<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| @field_property["choice_fields"].each do |create_choice|
@table_result_choice_fileds += '<button class="cancer_table_btn btn btn-default btn-sm">' + create_choice.to_s.titleize + "</button>" @table_result_choice_fileds += '<button class="cancer_table_btn btn btn-default btn-sm">'+create_choice.titleize+'</button>'
@table_result_choice_fileds += '<input type="hidden" value="0" name="' + create_choice.to_s + '"></input>' @table_result_choice_fileds += '<input type="hidden" value="0" name="'+create_choice+'"></input>'
end end
@table_result_choice_fileds += "</div>" @table_result_choice_fileds += '</div>'
end end
if @field_property["hint"].to_s != "" if @field_property["hint"].to_s != ""
@table_result_choice_fileds += '<div class="hint-texts">' + @field_property["hint"] + "</div>" @table_result_choice_fileds +='<div class="hint-texts">'+@field_property["hint"]+'</div>'
end end
@table_result_choice_fileds += '</div><div style="clear:both;"></div>' @table_result_choice_fileds += '</div><div style="clear:both;"></div>'
end end
@table_result_choice_fileds += "</div></div>" @table_result_choice_fileds += '</div></div>'
@table_str += (@table_button + '<div id="cancer_predict_result_block" style="font-size:' + @size_active_size + ';">' + @table_result_str + @table_result_choice_fileds + "</div>" + '<div style="clear:both;"></div>') @table_str += (@table_button+'<div id="cancer_predict_result_block" style="font-size:' + @size_active_size + ';">'+@table_result_str+@table_result_choice_fileds+'</div>'+'<div style="clear:both;"></div>')
return @table_str return @table_str
end end
def showSubmit def showSubmit
@page_num = params[:page] || 1 @page_num = params[:page] || 1
@results = Cancerpredictrecord.where("title" => @app_title).desc(:id).page(@page_num).per(10) @results = Cancerpredictrecord.where("title"=>@app_title).desc(:id).page(@page_num).per(10)
@variables = [] @variables = []
@names = [] @names = []
@form_to_show.form_show.each do |num, property| @form_to_show.form_show.each do |num,property|
property.each do |key, value| property.each do |key,value|
if key == "variable" if key == "variable"
@variables.push value @variables.push value
elsif key == "name" elsif key == "name"
@ -605,10 +603,10 @@ class Admin::CancerpredictsController < OrbitAdminController
end end
@result_variables = [] @result_variables = []
@result_names = [] @result_names = []
@indexs = [] @indexs=[]
@choicenames = [] @choicenames=[]
if @results.length != 0 if @results.length != 0
@results[0].result.each { |key, value| @result_variables.push key } rescue nil @results[0].result.each{|key,value| @result_variables.push key} rescue nil
@result_variables.each do |variable| @result_variables.each do |variable|
@index = @variables.index(variable.to_s) @index = @variables.index(variable.to_s)
@result_names.push @names[@index] if !@index.nil? @result_names.push @names[@index] if !@index.nil?
@ -624,87 +622,89 @@ class Admin::CancerpredictsController < OrbitAdminController
end end
@pagination = create_pagination(@page_num.to_i) @pagination = create_pagination(@page_num.to_i)
end end
def export_cancer_tool_record def export_cancer_tool_record
cancer_records = Cancerpredictrecord.where("title" => @app_title).desc(:id) cancer_records = Cancerpredictrecord.where("title"=>@app_title).desc(:id)
dir_path = "tmp/cancer_tool/" dir_path = 'tmp/cancer_tool/'
#FileUtils.rm_r(dir_path, :force => true) if Dir.exist?(dir_path) #FileUtils.rm_r(dir_path, :force => true) if Dir.exist?(dir_path)
FileUtils.mkdir dir_path if !Dir.exist?(dir_path) #create dir for storing tmp_file if dir doesn't exist FileUtils.mkdir dir_path if !Dir.exist?(dir_path) #create dir for storing tmp_file if dir doesn't exist
@filename = ("#{Time.now.year}_%02s_%02s_export_cancer_tool_record.xlsx" % [Time.now.month, Time.now.day]).gsub(" ", "0") @filename = ("#{Time.now.year}_%02s_%02s_export_cancer_tool_record.xlsx"%[Time.now.month,Time.now.day]).gsub(" ","0")
File.open("#{dir_path}#{@filename}", "w") do |f| Dir.chdir(dir_path) do
f.write render_to_string(:handlers => [:axlsx], :formats => [:xlsx], :partial => "export_cancer_tool_record.xlsx", :locals => { :results => cancer_records }) File.open(@filename, 'w') do |f|
f.write render_to_string( :handlers=> [:axlsx], :formats=> [:xlsx] ,:partial=> 'export_cancer_tool_record.xlsx',:locals=> {:results=> cancer_records} )
end end
tmp_filename_data = File.read("#{dir_path}#{@filename}")
send_data(tmp_filename_data, type: "application/xlsx", disposition: "attachment", filename: @filename)
end end
tmp_filename_data = File.read(dir_path +@filename)
send_data(tmp_filename_data, type: 'application/xlsx', disposition: 'attachment', filename: @filename)
end
def create_first_field def create_first_field
if Cancerpredictfields.where("title" => (@app_title + "_back")).take_while { true }.count == 0 if Cancerpredictfields.where("title"=>(@app_title + "_back")).take_while{true}.count == 0
@form_to_show = Cancerpredictfields.new() @form_to_show = Cancerpredictfields.new()
@form_to_show.title = @app_title + "_back" @form_to_show.title = @app_title +"_back"
@form_to_show.save @form_to_show.save
end end
@form_to_show @form_to_show
if Cancerpredictfields.where("title" => @app_title).take_while { true }.count == 0 if Cancerpredictfields.where("title"=>@app_title).take_while{true}.count == 0
@form_to_show = Cancerpredictfields.new() @form_to_show = Cancerpredictfields.new()
@form_to_show.title = @app_title @form_to_show.title=@app_title
@form_to_show.save @form_to_show.save
@form_to_show = Cancerpredictfields.where("title" => @app_title).first @form_to_show = Cancerpredictfields.where("title"=>@app_title).first
Dir.chdir("public") do
@site_locales = Site.last.in_use_locales.each do |locale| @site_locales = Site.last.in_use_locales.each do |locale|
File.open(Cancerpredictfields::ToolTableMap[I18n.locale], "w") do |f| I18n.with_locale(locale) do
@file_tmp = File.new('cancer_tool_table_tmp_'+locale.to_s+'.txt', 'w')
tmp_table_texts = create_table(locale) tmp_table_texts = create_table(locale)
f.write(tmp_table_texts) @file_tmp.write(tmp_table_texts)
@file_tmp.close
end
end end
end end
else else
@form_to_show = Cancerpredictfields.where("title" => @app_title).first @form_to_show = Cancerpredictfields.where("title"=>@app_title).first
end end
end end
def create_pagination(page=1,fields=Cancerpredictrecord.all,extra_params="")
def create_pagination(page = 1, fields = Cancerpredictrecord.all, extra_params = "")
page = 1 if page == 0 page = 1 if page == 0
per_page_num = 10.0 per_page_num = 10.0
all_page_num = (fields.count / per_page_num).ceil all_page_num = (fields.count / per_page_num).ceil
all_page_num = 1 if all_page_num == 0 all_page_num = 1 if all_page_num == 0
pagination = '<div class="PageDetails">' + ((I18n.locale.to_s == "zh_tw") ? "#{page}" : "page #{page}") + "/" + ((I18n.locale.to_s == "zh_tw") ? "#{all_page_num}" : "Total #{all_page_num} page(s)") + '<ol class="PageList">' + pagination = '<div class="PageDetails">'+((I18n.locale.to_s == 'zh_tw') ? "#{page}" : "page #{page}") +'/'+ ((I18n.locale.to_s == 'zh_tw') ? "#{all_page_num}" : "Total #{all_page_num} page(s)")+'<ol class="PageList">'+
((page == 1) ? "<li>[" + I18n.t("cancerpredict.prev_page") + "]</li>" : '<li><a href="' + (extra_params.blank? ? "?" : "?#{extra_params}&") + "page=" + (page - 1).to_s + '"> [' + I18n.t("cancerpredict.prev_page") + "] </a></li>") ((page == 1) ? '<li>['+I18n.t('cancerpredict.prev_page')+']</li>' : '<li><a href="'+(extra_params.blank? ? '?' : "?#{extra_params}&")+'page='+(page-1).to_s+'"> ['+I18n.t('cancerpredict.prev_page')+'] </a></li>')
if all_page_num > 7 if all_page_num > 7
if page <= (all_page_num / 2) if page <= (all_page_num / 2)
if page <= 7 if page <= 7
(1..page).to_a.each { |page_num| pagination += ((page_num == page) ? "<li>[" + page_num.to_s + "]</li>" : '<li><a href="' + (extra_params.blank? ? "?" : "?#{extra_params}&") + "page=" + page_num.to_s + '"> ' + page_num.to_s + " </a></li>") } (1..page).to_a.each{|page_num| pagination += ((page_num == page) ? '<li>['+page_num.to_s+']</li>' : '<li><a href="'+(extra_params.blank? ? '?' : "?#{extra_params}&")+'page='+page_num.to_s+'"> '+page_num.to_s+' </a></li>')}
else else
(1..3).to_a.each { |page_num| pagination += ((page_num == page) ? "<li>[" + page_num.to_s + "]</li>" : '<li><a href="' + (extra_params.blank? ? "?" : "?#{extra_params}&") + "page=" + page_num.to_s + '"> ' + page_num.to_s + " </a></li>") } (1..3).to_a.each{|page_num| pagination += ((page_num == page) ? '<li>['+page_num.to_s+']</li>' : '<li><a href="'+(extra_params.blank? ? '?' : "?#{extra_params}&")+'page='+page_num.to_s+'"> '+page_num.to_s+' </a></li>')}
pagination += "<li>...</li>" pagination +='<li>...</li>'
(page - 3..page).to_a.each { |page_num| pagination += ((page_num == page) ? "<li>[" + page_num.to_s + "]</li>" : '<li><a href="' + (extra_params.blank? ? "?" : "?#{extra_params}&") + "page=" + page_num.to_s + '"> ' + page_num.to_s + " </a></li>") } (page-3..page).to_a.each{|page_num| pagination += ((page_num == page) ? '<li>['+page_num.to_s+']</li>' : '<li><a href="'+(extra_params.blank? ? '?' : "?#{extra_params}&")+'page='+page_num.to_s+'"> '+page_num.to_s+' </a></li>')}
end end
(page + 1..page + 3).to_a.each { |page_num| pagination += ((page_num == page) ? "<li>[" + page_num.to_s + "]</li>" : '<li><a href="' + (extra_params.blank? ? "?" : "?#{extra_params}&") + "page=" + page_num.to_s + '"> ' + page_num.to_s + " </a></li>") } (page+1..page+3).to_a.each{|page_num| pagination += ((page_num == page) ? '<li>['+page_num.to_s+']</li>' : '<li><a href="'+(extra_params.blank? ? '?' : "?#{extra_params}&")+'page='+page_num.to_s+'"> '+page_num.to_s+' </a></li>')}
pagination += "<li>...</li>" pagination +='<li>...</li>'
(all_page_num - 2..all_page_num).to_a.each { |page_num| pagination += ((page_num == page) ? "<li>[" + page_num.to_s + "]</li>" : '<li><a href="' + (extra_params.blank? ? "?" : "?#{extra_params}&") + "page=" + page_num.to_s + '"> ' + page_num.to_s + " </a></li>") } (all_page_num-2..all_page_num).to_a.each{|page_num| pagination += ((page_num == page) ? '<li>['+page_num.to_s+']</li>' : '<li><a href="'+(extra_params.blank? ? '?' : "?#{extra_params}&")+'page='+page_num.to_s+'"> '+page_num.to_s+' </a></li>')}
else else
(1..3).to_a.each { |page_num| pagination += ((page_num == page) ? "<li>[" + page_num.to_s + "]</li>" : '<li><a href="' + (extra_params.blank? ? "?" : "?#{extra_params}&") + "page=" + page_num.to_s + '"> ' + page_num.to_s + " </a></li>") } (1..3).to_a.each{|page_num| pagination += ((page_num == page) ? '<li>['+page_num.to_s+']</li>' : '<li><a href="'+(extra_params.blank? ? '?' : "?#{extra_params}&")+'page='+page_num.to_s+'"> '+page_num.to_s+' </a></li>')}
pagination += "<li>...</li>" pagination +='<li>...</li>'
(page - 3..page).to_a.each { |page_num| pagination += ((page_num == page) ? "<li>[" + page_num.to_s + "]</li>" : '<li><a href="' + (extra_params.blank? ? "?" : "?#{extra_params}&") + "page=" + page_num.to_s + '"> ' + page_num.to_s + " </a></li>") } (page-3..page).to_a.each{|page_num| pagination += ((page_num == page) ? '<li>['+page_num.to_s+']</li>' : '<li><a href="'+(extra_params.blank? ? '?' : "?#{extra_params}&")+'page='+page_num.to_s+'"> '+page_num.to_s+' </a></li>')}
if all_page_num - page <= 7 if all_page_num - page <= 7
(page + 1..all_page_num).to_a.each { |page_num| pagination += ((page_num == page) ? "<li>[" + page_num.to_s + "]</li>" : '<li><a href="' + (extra_params.blank? ? "?" : "?#{extra_params}&") + "page=" + page_num.to_s + '"> ' + page_num.to_s + " </a></li>") } (page+1..all_page_num).to_a.each{|page_num| pagination += ((page_num == page) ? '<li>['+page_num.to_s+']</li>' : '<li><a href="'+(extra_params.blank? ? '?' : "?#{extra_params}&")+'page='+page_num.to_s+'"> '+page_num.to_s+' </a></li>')}
else else
(page + 1..page + 3).to_a.each { |page_num| pagination += ((page_num == page) ? "<li>[" + page_num.to_s + "]</li>" : '<li><a href="' + (extra_params.blank? ? "?" : "?#{extra_params}&") + "page=" + page_num.to_s + '"> ' + page_num.to_s + " </a></li>") } (page+1..page+3).to_a.each{|page_num| pagination += ((page_num == page) ? '<li>['+page_num.to_s+']</li>' : '<li><a href="'+(extra_params.blank? ? '?' : "?#{extra_params}&")+'page='+page_num.to_s+'"> '+page_num.to_s+' </a></li>')}
pagination += "<li>...</li>" pagination +='<li>...</li>'
(all_page_num - 2..all_page_num).to_a.each { |page_num| pagination += ((page_num == page) ? "<li>[" + page_num.to_s + "]</li>" : '<li><a href="' + (extra_params.blank? ? "?" : "?#{extra_params}&") + "page=" + page_num.to_s + '"> ' + page_num.to_s + " </a></li>") } (all_page_num-2..all_page_num).to_a.each{|page_num| pagination += ((page_num == page) ? '<li>['+page_num.to_s+']</li>' : '<li><a href="'+(extra_params.blank? ? '?' : "?#{extra_params}&")+'page='+page_num.to_s+'"> '+page_num.to_s+' </a></li>')}
end end
end end
else else
(1..all_page_num).to_a.each { |page_num| pagination += ((page_num == page) ? "<li>[" + page_num.to_s + "]</li>" : '<li><a href="' + (extra_params.blank? ? "?" : "?#{extra_params}&") + "page=" + page_num.to_s + '"> ' + page_num.to_s + " </a></li>") } (1..all_page_num).to_a.each{|page_num| pagination += ((page_num == page) ? '<li>['+page_num.to_s+']</li>' : '<li><a href="'+(extra_params.blank? ? '?' : "?#{extra_params}&")+'page='+page_num.to_s+'"> '+page_num.to_s+' </a></li>')}
end end
pagination += (((page == all_page_num) ? "<li>[" + I18n.t("cancerpredict.next_page") + "]</li>" : '<li><a href="' + (extra_params.blank? ? "?" : "?#{extra_params}&") + "page=" + (page + 1).to_s + '"> [' + I18n.t("cancerpredict.next_page") + "] </a></li>") + "</ol></div>") pagination += (((page==all_page_num) ? '<li>['+I18n.t('cancerpredict.next_page')+']</li>' : '<li><a href="'+(extra_params.blank? ? '?' : "?#{extra_params}&")+'page='+(page+1).to_s+'"> ['+I18n.t('cancerpredict.next_page')+'] </a></li>')+'</ol></div>')
end end
def read_mapping_file(mapping_file_id) def read_mapping_file(mapping_file_id)
mapping_file = CancerPredictMappingFile.find(mapping_file_id) rescue nil mapping_file = CancerPredictMappingFile.find(mapping_file_id) rescue nil
if !mapping_file.nil? if !mapping_file.nil?
csv_rows = CSV.read(mapping_file.temp_file.file.path) csv_rows = CSV.read(mapping_file.temp_file.file.path)
titles = csv_rows[0] titles = csv_rows[0]
infos = {} infos = {}
titles.each_with_index do |title, i| titles.each_with_index do |title,i|
infos[title] = [] infos[title] = []
csv_rows[1..-1].each do |row| csv_rows[1..-1].each do |row|
infos[title] << row[i].to_f infos[title] << row[i].to_f

View File

@ -1,83 +1,81 @@
# encoding: utf-8 # encoding: utf-8
require "rubyXL" require 'rubyXL'
require "json" require "json"
class CancerpredictsController < ApplicationController class CancerpredictsController < ApplicationController
def initialize def initialize
super super
@app_title = "cancerpredict" @app_title = "cancerpredict"
end end
def calculate def calculate
create_first_field create_first_field
if params["header"].to_i == 1 if params['header'].to_i == 1
locale = params["locale"].to_s rescue "zh_tw" locale = params['locale'].to_s rescue 'zh_tw'
locale = "zh_tw" if locale == "zh_cn" locale = 'zh_tw' if locale == 'zh_cn'
result = {} result = {}
@head_images = {} @head_images = {}
@form_to_show.head_images_id.each do |image_id| @form_to_show.head_images_id.each do |image_id|
next if image_id.to_s == "" next if image_id.to_s == ""
@image = Headimages.find_by(:id => image_id.to_s) @image = Headimages.find_by(:id=>image_id.to_s)
@url = @image.temp_file.to_s @url = @image.temp_file.to_s
@head_images[@image.sort_number.to_i] = ('<img class="head_logo" alt ="' + Pathname.new(@image.temp_file.file.file).basename.to_s + '" src="' + @url + '"/>') @head_images[@image.sort_number.to_i] = ('<img class="head_logo" alt ="' + Pathname.new(@image.temp_file.file.file).basename.to_s+'" src="'+@url+'"/>')
end end
result["head_images"] = Hash[@head_images.sort].values.join("") result['head_images'] = Hash[@head_images.sort].values.join('')
@head_images = {} @head_images = {}
@form_to_show.title_images_id.each do |image_id| @form_to_show.title_images_id.each do |image_id|
next if image_id.to_s == "" next if image_id.to_s == ""
@image = Headimages.find_by(:id => image_id.to_s) @image = Headimages.find_by(:id=>image_id.to_s)
@url = @image.temp_file.to_s @url = @image.temp_file.to_s
@head_images[@image.sort_number.to_i] = ('<img class="head_logo" alt ="' + Pathname.new(@image.temp_file.file.file).basename.to_s + '" src="' + @url + '"/>') @head_images[@image.sort_number.to_i] = ('<img class="head_logo" alt ="' + Pathname.new(@image.temp_file.file.file).basename.to_s+'" src="'+@url+'"/>')
end end
result["danger_texts"] = (@form_to_show.danger_texts[locale] rescue "") result['danger_texts'] = (@form_to_show.danger_texts[locale] rescue '')
result["title"] = Hash[@head_images.sort].values.join("") result['title'] = Hash[@head_images.sort].values.join('')
result["page_title"] = @form_to_show.title_texts[params[:locale]] result['page_title'] = @form_to_show.title_texts[params[:locale]]
elsif params["get_mapping_data_from_csv"].to_i == 1 elsif params['get_mapping_data_from_csv'].to_i == 1
result = {} result = {}
result["mapping_data_from_csv"] = JSON.parse(@form_to_show.mapping_data_from_csv) rescue {} result['mapping_data_from_csv'] = JSON.parse(@form_to_show.mapping_data_from_csv) rescue {}
else else
@record = Cancerpredictrecord.new @record = Cancerpredictrecord.new
@record.title = @app_title @record.title = @app_title
@choice_keys = [] @choice_keys = []
@choice_values = [] @choice_values = []
@choice_names = [] @choice_names = []
@form_to_show.form_show.values.each { |choice| @choice_keys.push choice[:variable] } @form_to_show.form_show.values.each{|choice| @choice_keys.push choice[:variable]}
@form_to_show.form_show.values.each { |choice| @choice_values.push ((choice[:is_num] == 1) ? [] : choice[:choice_fields]) } @form_to_show.form_show.values.each{|choice| @choice_values.push ((choice[:is_num] == 1) ? [] : choice[:choice_fields])}
@form_to_show.form_show.values.each { |choice| @choice_names.push choice[:name] } @form_to_show.form_show.values.each{|choice| @choice_names.push choice[:name]}
@choice_keys.each_with_index { |key, i| @record.names[key] = @choice_names[i] } @choice_keys.each_with_index{|key,i| @record.names[key] = @choice_names[i]}
@choice_keys.each_with_index { |key, i| @record.values[key] = @choice_values[i] } @choice_keys.each_with_index{|key,i| @record.values[key] = @choice_values[i]}
params["data"].each do |rec_key, rec_value| params['data'].each do |rec_key,rec_value|
@record.result[rec_key] = rec_value @record.result[rec_key] = rec_value
end end
@record.submit_time = Time.now.to_s @record.submit_time = Time.now.to_s
@record.save @record.save
locale = params["data"]["locale"].to_s rescue "zh_tw" locale = params['data']['locale'].to_s rescue 'zh_tw'
locale = "zh_tw" if locale == "zh_cn" locale = 'zh_tw' if locale == 'zh_cn'
result = {} result = {}
mapping_data_from_csv = JSON.parse(@form_to_show.mapping_data_from_csv) rescue {} mapping_data_from_csv = JSON.parse(@form_to_show.mapping_data_from_csv) rescue {}
@form_to_show.all_variables.each do |v| @form_to_show.all_variables.each do |v|
result[v] = 0 result[v] = 0
end end
@form_to_show.form_show.each do |num, property| @form_to_show.form_show.each do |num,property|
@variable = property[:variable] @variable = property[:variable]
if @variable.present? if @variable.present?
if property[:is_num] == 1 if property[:is_num] == 1
if property[:is_float] == 1 if property[:is_float] == 1
result[@variable] = params["data"][@variable].to_f rescue 0.0 result[@variable] = params['data'][@variable].to_f rescue 0.0
else else
result[@variable] = params["data"][@variable].to_i rescue 0 result[@variable] = params['data'][@variable].to_i rescue 0
end end
elsif property[:choice_fields].present? elsif property[:choice_fields].present?
if !(@form_to_show.advance_mode) if !(@form_to_show.advance_mode)
result[@variable] = params["data"][@variable].to_i rescue 0 result[@variable] = params['data'][@variable].to_i rescue 0
else else
if property[:need_map_values] == 1 if property[:need_map_values] == 1
result[@variable] = property[:map_values][params["data"][@variable].to_i - 1] result[@variable] = property[:map_values][params['data'][@variable].to_i - 1]
else else
if property[:revert_value] != 1 if property[:revert_value] != 1
result[@variable] = params["data"][@variable].to_i - 1 result[@variable] = params['data'][@variable].to_i - 1
else else
result[@variable] = ((property[:choice_fields].length - params["data"][@variable].to_i) rescue params["data"][@variable].to_i) result[@variable] = ((property[:choice_fields].length - params['data'][@variable].to_i) rescue params['data'][@variable].to_i)
end end
end end
end end
@ -87,13 +85,13 @@ class CancerpredictsController < ApplicationController
mapping_hash = mapping_data_from_csv[@variable] mapping_hash = mapping_data_from_csv[@variable]
temp_index = 0 temp_index = 0
temp_value = result[@variable] temp_value = result[@variable]
mapping_hash.each_with_index do |(k, v), i| mapping_hash.each_with_index do |(k,v),i|
if i == 0 if i == 0
index_val = v.index(temp_value) rescue nil index_val = v.index(temp_value) rescue nil
if !index_val.nil? if !index_val.nil?
temp_index = index_val temp_index = index_val
else else
closest_value = v.min_by { |x| (temp_value - x).abs } closest_value = v.min_by{|x| (temp_value-x).abs}
temp_index = v.index(closest_value) temp_index = v.index(closest_value)
end end
end end
@ -116,45 +114,44 @@ class CancerpredictsController < ApplicationController
@form_to_show.generate_eval_formula @form_to_show.generate_eval_formula
eval_formula(result) eval_formula(result)
end end
result["lpv"] = result[formula_variables.last] result['lpv'] = result[formula_variables.last]
result["lpv_variable"] = {} result['lpv_variable'] = {}
formula_variables.each do |variable_name| formula_variables.each do |variable_name|
result["lpv_variable"]["#{variable_name}"] = result[variable_name] result['lpv_variable']["#{variable_name}"] = result[variable_name]
end end
@years = @form_to_show.years @years = @form_to_show.years
result["years"] = @years result['years'] = @years
@therapy_choices = [I18n.t("cancerpredict.table.Surgeryonly")] @therapy_choices = [I18n.t('cancerpredict.table.Surgeryonly')]
@form_to_show.form_show_in_result.values.each { |choice| @therapy_choices.push choice["name"][locale] } @form_to_show.form_show_in_result.values.each{|choice| @therapy_choices.push choice["name"][locale]}
@therapy_names = @form_to_show.treatment_method @therapy_names = @form_to_show.treatment_method
result["treatment_method"] = @therapy_names result['treatment_method'] = @therapy_names
result["treatment_method_active_indices"] = @form_to_show.treatment_method_active_indices result['treatment_method_active_indices'] = @form_to_show.treatment_method_active_indices
result["table"] = @form_to_show.result_table_translations[locale] result['table'] = @form_to_show.result_table_translations[locale]
year = params["data"]["year"] rescue nil year = params['data']['year'] rescue nil
if year.nil? if year.nil?
year = @years.last.to_f year = @years.first.to_f
else else
year = year.to_f year = year.to_f
end end
year_index = @years.index(year) year_index = @years.index(year)
@servive_ratio = eval(@form_to_show.tmp_years_settings_for_ruby[year_index]) @servive_ratio = eval(@form_to_show.tmp_years_settings_for_ruby[year_index])
@servive_ratio = (@servive_ratio * 100).round(2) @servive_ratio = ((1 - @servive_ratio) * 100).round(2)
result["texts"] = @form_to_show.result_text_translations[locale] result['texts'] = @form_to_show.result_text_translations[locale]
result["extra_therapy_texts"] = @form_to_show.extra_therapy_texts[locale] rescue @form_to_show.extra_therapy_texts["zh_tw"] result['extra_therapy_texts'] = @form_to_show.extra_therapy_texts[locale] rescue @form_to_show.extra_therapy_texts['zh_tw']
result["servive_ratio"] = @servive_ratio result['servive_ratio'] = @servive_ratio
end end
result = result.merge(params) result = result.merge(params)
render :json => result render :json=> result
end end
def index def index
uid = OrbitHelper.params[:uid] rescue "" uid = OrbitHelper.params[:uid] rescue ""
tags = OrbitHelper.widget_tags tags = OrbitHelper.widget_tags
categories = OrbitHelper.widget_categories || [] categories = OrbitHelper.widget_categories || []
@table_str = File.read(Cancerpredictfields::ToolTableMap[I18n.locale]) @table_str = File.read('public/cancer_tool_table_tmp_'+I18n.locale.to_s+'.txt')
preidct_js_url = "/assets/#{Cancerpredictfields::JS}" preidct_js_url = '/assets/cancer_predict.js'
if File.exist?(Cancerpredictfields::JSFileName) if File.exist?('public/cancer_tool_js_filename.txt')
js_filename = File.read(Cancerpredictfields::JSFileName) js_filename = File.read('public/cancer_tool_js_filename.txt')
if js_filename.include?(Cancerpredictfields::JS) if js_filename.match(/cancer_predict\.js$/)
asset = Rails.application.assets[js_filename] asset = Rails.application.assets[js_filename]
preidct_js_url = "#{Rails.application.config.assets.prefix}/#{asset.digest_path}" preidct_js_url = "#{Rails.application.config.assets.prefix}/#{asset.digest_path}"
else else
@ -163,19 +160,18 @@ class CancerpredictsController < ApplicationController
end end
{ {
"cancerpredict" => [], "cancerpredict" => [],
"extras" => { "table" => @table_str, "preidct_js_url" => preidct_js_url }, "extras"=>{"table"=> @table_str,'preidct_js_url'=>preidct_js_url}
} }
end end
def widget def widget
uid = OrbitHelper.params[:uid] rescue "" uid = OrbitHelper.params[:uid] rescue ""
tags = OrbitHelper.widget_tags tags = OrbitHelper.widget_tags
categories = OrbitHelper.widget_categories || [] categories = OrbitHelper.widget_categories || []
@table_str = File.read(Cancerpredictfields::ToolTableMap[I18n.locale]) @table_str = File.read('public/cancer_tool_table_tmp_'+I18n.locale.to_s+'.txt')
preidct_js_url = "/assets/#{Cancerpredictfields::JS}" preidct_js_url = '/assets/cancer_predict.js'
if File.exist?(Cancerpredictfields::JSFileName) if File.exist?('public/cancer_tool_js_filename.txt')
js_filename = File.read(Cancerpredictfields::JSFileName) js_filename = File.read('public/cancer_tool_js_filename.txt')
if js_filename.include?(Cancerpredictfields::JS) if js_filename.match(/cancer_predict\.js$/)
asset = Rails.application.assets[js_filename] asset = Rails.application.assets[js_filename]
preidct_js_url = "#{Rails.application.config.assets.prefix}/#{asset.digest_path}" preidct_js_url = "#{Rails.application.config.assets.prefix}/#{asset.digest_path}"
else else
@ -184,27 +180,25 @@ class CancerpredictsController < ApplicationController
end end
{ {
"cancerpredict" => [], "cancerpredict" => [],
"extras" => { "table" => @table_str, "preidct_js_url" => preidct_js_url }, "extras"=>{"table"=> @table_str,'preidct_js_url'=>preidct_js_url}
} }
end end
def create_first_field def create_first_field
if Cancerpredictfields.where("title" => (@app_title + "_back")).count == 0 if Cancerpredictfields.where("title"=>(@app_title + "_back")).count == 0
@form_to_show = Cancerpredictfields.new() @form_to_show = Cancerpredictfields.new()
@form_to_show.title = @app_title + "_back" @form_to_show.title = @app_title +"_back"
@form_to_show.save @form_to_show.save
end end
@form_to_show @form_to_show
if Cancerpredictfields.where("title" => @app_title).count == 0 if Cancerpredictfields.where("title"=>@app_title).count == 0
@form_to_show = Cancerpredictfields.new() @form_to_show = Cancerpredictfields.new()
@form_to_show.title = @app_title @form_to_show.title=@app_title
@form_to_show.save @form_to_show.save
@form_to_show = Cancerpredictfields.where("title" => @app_title).first @form_to_show = Cancerpredictfields.where("title"=>@app_title).first
else else
@form_to_show = Cancerpredictfields.where("title" => @app_title).first @form_to_show = Cancerpredictfields.where("title"=>@app_title).first
end end
end end
def read_mapping_file(mapping_file) def read_mapping_file(mapping_file)
if mapping_file.class != CancerPredictMappingFile if mapping_file.class != CancerPredictMappingFile
mapping_file = CancerPredictMappingFile.find(mapping_file_id) rescue nil mapping_file = CancerPredictMappingFile.find(mapping_file_id) rescue nil
@ -213,7 +207,7 @@ class CancerpredictsController < ApplicationController
csv_rows = CSV.read(mapping_file.temp_file.file.path) csv_rows = CSV.read(mapping_file.temp_file.file.path)
titles = csv_rows[0] titles = csv_rows[0]
infos = {} infos = {}
titles.each_with_index do |title, i| titles.each_with_index do |title,i|
infos[title] = [] infos[title] = []
csv_rows[1..-1].each do |row| csv_rows[1..-1].each do |row|
infos[title] << row[i].to_f infos[title] << row[i].to_f

View File

@ -1,13 +1,4 @@
module Admin::CancerpredictsHelper module Admin::CancerpredictsHelper
def bc_yaml_dump(arr)
if arr.blank?
'[]'
elsif arr.class != String
'[' + arr.map{|s| (s.is_a?(String) && !(s.is_i?) && s.include?(' ')) ? "\"#{s}\"" : s}.join(', ') + ']'
else
arr
end
end
def create_pagination(page=1,fields=Cancerpredictrecord.all,extra_params="") def create_pagination(page=1,fields=Cancerpredictrecord.all,extra_params="")
page = 1 if page == 0 page = 1 if page == 0
per_page_num = 10.0 per_page_num = 10.0

View File

@ -9,95 +9,112 @@ class Cancerpredictfields
AdvanceFields = ["revert_value","map_values","cancer_predict_mapping_file"] AdvanceFields = ["revert_value","map_values","cancer_predict_mapping_file"]
TherapyFields = ["variable","name","hint","comment_text","choice_fields","lpv_impact","active_choice","disable_condition"] TherapyFields = ["variable","name","hint","comment_text","choice_fields","lpv_impact","active_choice","disable_condition"]
TherapyOnly = ["lpv_impact","active_choice","disable_condition"] TherapyOnly = ["lpv_impact","active_choice","disable_condition"]
JSFileName = "public/cancer_tool_js_filename.txt".freeze
ModuleAppPath = Pathname.new(File.expand_path(__dir__)).dirname.dirname.to_s.freeze
JS = "cancer_predict.js"
ToolTableMap = I18n.available_locales.map do |locale|
[locale, "public/cancer_tool_table_tmp_#{locale}.txt".freeze]
end.to_h
field :title ,type:String ,default:"" field :title ,type:String ,default:""
field :advance_mode, type: Boolean, default: false field :advance_mode, type: Boolean, default: true
field :form_show , :type=> Hash ,default:{ field :form_show , :type=> Hash ,default:{
"0"=>{"variable"=>"age", "name"=>{"zh_tw"=>"年齡<br/>(Age)", "en"=>"Age"}, "is_num"=>1, "hint"=>{"zh_tw"=>"從 18 歲(含)開始至 93 歲", "en"=>"Age must be between 18 and 93"}, "comment_text"=>{"zh_tw"=>"年齡為該婦女於確診罹患乳癌時之年齡", "en"=>"Age at diagnosis"}, "choice_fields"=>{"zh_tw"=>[], "en"=>[]}, "range"=>[18, 93], "right"=>0, "is_float"=>0, "need_map_values"=>0, "revert_value"=>0, "map_values"=>[]}, "0"=>{"variable"=>"sex_value", "name"=>{"zh_tw"=>"性別<br/>(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"=>1, "map_values"=>[], "cancer_predict_mapping_file"=>"", "need_map_values"=>0},
"1"=>{"variable"=>"size", "name"=>{"zh_tw"=>"腫瘤大小(單位:mm)<br/>(Tumor size)", "en"=>"Tumor size"}, "is_num"=>1, "hint"=>{"zh_tw"=>"", "en"=>"The unit of tumor size is millimeter (mm)"}, "comment_text"=>{"zh_tw"=>"若有多個原發腫瘤,請輸入最大尺寸之原發腫瘤", "en"=>"If there was more than one primary tumor, please enter the size of the largest one."}, "choice_fields"=>{"zh_tw"=>[], "en"=>[]}, "range"=>[1, 300], "right"=>0, "is_float"=>0, "need_map_values"=>0, "revert_value"=>0, "map_values"=>[]}, "1"=>{"variable"=>"age", "name"=>{"zh_tw"=>"年齡<br/>(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"=>BSON::ObjectId('5f8e60441d41c801f600011a'), "need_map_values"=>0},
"2"=>{"variable"=>"lymph_nodes_examined", "name"=>{"zh_tw"=>"區域淋巴結檢查數目<br/>(Regional lymph nodes examined)", "en"=>"Regional lymph nodes examined"}, "is_num"=>1, "hint"=>{"zh_tw"=>"", "en"=>""}, "comment_text"=>{"zh_tw"=>"", "en"=>""}, "choice_fields"=>{"zh_tw"=>["未知"], "en"=>["unknown"]}, "range"=>[0, 90], "right"=>0, "is_float"=>0, "need_map_values"=>0, "revert_value"=>0, "map_values"=>[]}, "2"=>{"variable"=>"calH", "name"=>{"zh_tw"=>"心臟鈣化分數<br/>(Heart Calcification score)", "en"=>"Heart 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"=>BSON::ObjectId('5f8e66c71d41c801f6000139'), "need_map_values"=>0},
"3"=>{"variable"=>"lymph_nodes_positive", "name"=>{"zh_tw"=>"區域淋巴結侵犯數目<br/>(Regional lymph nodes positive)", "en"=>"Regional lymph nodes positive"}, "is_num"=>1, "hint"=>{"zh_tw"=>"", "en"=>""}, "comment_text"=>{"zh_tw"=>"此變項為預測重要變數,若無此資訊預測容易失真。", "en"=>"Regional lymph nodes positive is a key predictive variable. If this information is omitted, the prediction result would be biased."}, "choice_fields"=>{"zh_tw"=>["未知"], "en"=>["unknown"]}, "range"=>[0, 90], "right"=>0, "is_float"=>0, "need_map_values"=>0, "revert_value"=>0, "map_values"=>[]}, "3"=>{"variable"=>"calAH", "name"=>{"zh_tw"=>"升主動脈鈣化分數", "en"=>"Aorta ascendens Calcification score"}, "hint"=>{"zh_tw"=>"請輸入0到10000的數字", "en"=>"Please enter a number between 0 and 10000"}, "comment_text"=>{"zh_tw"=>"", "en"=>""}, "choice_fields"=>{"zh_tw"=>[], "en"=>[]}, "is_num"=>1, "range"=>[0, 10000], "right"=>0, "is_float"=>1, "revert_value"=>0, "map_values"=>[], "cancer_predict_mapping_file"=>BSON::ObjectId('5f8e6ded1d41c801f600013d'), "need_map_values"=>0},
"4"=>{"variable"=>"grade", "name"=>{"zh_tw"=>"腫瘤分化程度<br/>(Tumor grade)", "en"=>"Tumor grade"}, "is_num"=>0, "hint"=>{"zh_tw"=>"", "en"=>""}, "comment_text"=>{"zh_tw"=>"腫瘤級數代表腫瘤組織與正常組織間的分化程度,若無分化級數資訊,請選擇“未知”選項,將以級數 2 進行預測。", "en"=>"The grade refers to how different the cancer cells are from normal cells. Please select “unknown” if there is no information about grade. The prediction model would use “grade 2” as the alternative variable."}, "choice_fields"=>{"zh_tw"=>["1", "2", "3", "未知"], "en"=>["1", "2", "3", "unknown"]}, "range"=>[], "right"=>0, "is_float"=>0, "need_map_values"=>0, "revert_value"=>0, "map_values"=>[]}, "4"=>{"variable"=>"calDH", "name"=>{"zh_tw"=>"降主動脈鈣化分數", "en"=>"Aorta descendens Calcification score"}, "hint"=>{"zh_tw"=>"請輸 入0到10000的數字", "en"=>"Please enter a number between 0 and 10000"}, "comment_text"=>{"zh_tw"=>"", "en"=>""}, "choice_fields"=>{"zh_tw"=>[], "en"=>[]}, "is_num"=>1, "range"=>[0, 10000], "right"=>0, "is_float"=>1, "revert_value"=>0, "map_values"=>[], "cancer_predict_mapping_file"=>BSON::ObjectId('5f8e6ded1d41c801f600013e'), "need_map_values"=>0},
"5"=>{"variable"=>"ER_status", "name"=>{"zh_tw"=>"ER 狀態<br/>(ER status)", "en"=>"ER status"}, "is_num"=>0, "hint"=>{"zh_tw"=>"", "en"=>""}, "comment_text"=>{"zh_tw"=>"ER:雌激素受體,若無 ER 資訊請選擇未知,將以佔多數比例陽 性作為後續預測。", "en"=>"ER status describes the status of estrogen receptor. Please select “unknown” if there is no information about ER status. The prediction model would use “Positive” (the majority class) as the alternative variable."}, "choice_fields"=>{"zh_tw"=>["陽性", "陰性", "未知"], "en"=>["positive", "negative", "unknown"]}, "range"=>[], "right"=>0, "is_float"=>0, "need_map_values"=>0, "revert_value"=>0, "map_values"=>[]}, "5"=>{"variable"=>"fat", "name"=>{"zh_tw"=>"脂肪分數", "en"=>"Fat"}, "hint"=>{"zh_tw"=>"請輸入20到408的數字", "en"=>"Please enter a number between 20 and 408"}, "comment_text"=>{"zh_tw"=>"", "en"=>""}, "choice_fields"=>{"zh_tw"=>[], "en"=>[]}, "is_num"=>1, "range"=>[20, 408], "right"=>0, "is_float"=>1, "revert_value"=>0, "map_values"=>[], "cancer_predict_mapping_file"=>BSON::ObjectId('5f8e6ded1d41c801f600013f'), "need_map_values"=>0},
"6"=>{"variable"=>"PR_status", "name"=>{"zh_tw"=>"PR 狀態<br/>(PR status)", "en"=>"PR status"}, "is_num"=>0, "hint"=>{"zh_tw"=>"", "en"=>""}, "comment_text"=>{"zh_tw"=>"PR:黃體素受體, 若無 PR 資訊請選擇未知,將以佔多數比例陽性作為後續預測。", "en"=>"PR status describes the status of progesterone receptor. Please select “unknown” if there is no information about PR status. The prediction model would use “Positive” (the majority class) as the alternative variable."}, "choice_fields"=>{"zh_tw"=>["陽性", "陰性", "未知"], "en"=>["positive", "negative", "unknown"]}, "range"=>[], "right"=>1, "is_float"=>0, "need_map_values"=>0, "revert_value"=>0, "map_values"=>[]}, "6"=>{"variable"=>"N4", "name"=>{"zh_tw"=>"腫瘤", "en"=>"Neoplasia"}, "hint"=>{"zh_tw"=>"", "en"=>""}, "comment_text"=>{"zh_tw"=>"", "en"=>""}, "choice_fields"=>{"zh_tw"=>["", "沒有"], "en"=>["yes", "no"]}, "is_num"=>0, "range"=>[], "right"=>0, "is_float"=>0, "revert_value"=>1, "map_values"=>[], "cancer_predict_mapping_file"=>"", "need_map_values"=>0},
"7"=>{"variable"=>"HER2_status", "name"=>{"zh_tw"=>"HER2 狀態<br/>(HER2 status)", "en"=>"HER2 status"}, "is_num"=>0, "hint"=>{"zh_tw"=>"", "en"=>""}, "comment_text"=>{"zh_tw"=>"HER2:第二型人類上皮成長因子接受器蛋白,若無 HER2 資訊請選擇未知,將以佔多數比例陰性作為後續預測。", "en"=>"HER2 status describes the status of human epidermal growth factor receptor 2. Please select “unknown” if there is no information about HER2 status. The prediction model would use “Negative” (the majority class) as the alternative variable."}, "choice_fields"=>{"zh_tw"=>["陽性", "陰性", "未知"], "en"=>["positive", "negative", "unknown"]}, "range"=>[], "right"=>1, "is_float"=>0, "need_map_values"=>0, "revert_value"=>0, "map_values"=>[]}, "7"=>{"variable"=>"N12", "name"=>{"zh_tw"=>"癡呆症", "en"=>"Dementias"}, "hint"=>{"zh_tw"=>"", "en"=>""}, "comment_text"=>{"zh_tw"=>"", "en"=>""}, "choice_fields"=>{"zh_tw"=>["", "沒有"], "en"=>["yes", "no"]}, "is_num"=>0, "range"=>[], "right"=>0, "is_float"=>0, "revert_value"=>1, "map_values"=>[], "cancer_predict_mapping_file"=>"", "need_map_values"=>0},
"8"=>{"variable"=>"Distant_Metastasis", "name"=>{"zh_tw"=>"遠端轉移<br/>(Distant Metastasis)", "en"=>"Distant Metastasis"}, "is_num"=>0, "hint"=>{"zh_tw"=>"", "en"=>""}, "comment_text"=>{"zh_tw"=>"若無遠端轉移資訊請選擇未知,將以佔多數比例未遠端轉移作為後續預測。", "en"=>"Please select “unknown” if there is no information about distant Metastasis. The prediction model would use “No” (the majority class) as the alternative variable."}, "choice_fields"=>{"zh_tw"=>["", "", "未知"], "en"=>["yes", "no", "unknown"]}, "range"=>[], "right"=>1, "is_float"=>0, "need_map_values"=>0, "revert_value"=>0, "map_values"=>[]}, "8"=>{"variable"=>"N20", "name"=>{"zh_tw"=>"慢性肝炎", "en"=>" Chronic hepatitis"}, "hint"=>{"zh_tw"=>"", "en"=>""}, "comment_text"=>{"zh_tw"=>"", "en"=>""}, "choice_fields"=>{"zh_tw"=>["", "沒有"], "en"=>["yes", "no"]}, "is_num"=>0, "range"=>[], "right"=>0, "is_float"=>0, "revert_value"=>1, "map_values"=>[], "cancer_predict_mapping_file"=>"", "need_map_values"=>0},
"9"=>{"variable"=>"micrometastasis", "name"=>{"zh_tw"=>"淋巴結顯微轉移<br/>(Lymph nodes micrometastasis)", "en"=>"Micrometastasis"}, "is_num"=>0, "hint"=>{"zh_tw"=>"", "en"=>""}, "comment_text"=>{"zh_tw"=>"若無顯微移資訊請選擇未知,將以無顯微轉移作為後續預測。", "en"=>"Please select “unknown” if there is no information about lymph nodes micrometastasis. The prediction model would use “No” as the alternative variable."}, "choice_fields"=>{"zh_tw"=>["", "", "未知"], "en"=>["yes", "no", "unknown"]}, "range"=>[], "right"=>1, "is_float"=>0, "need_map_values"=>0, "revert_value"=>0, "map_values"=>[]}, "9"=>{"variable"=>"N31", "name"=>{"zh_tw"=>"垂體侏儒症", "en"=>" Pituitary dwarfism"}, "hint"=>{"zh_tw"=>"", "en"=>""}, "comment_text"=>{"zh_tw"=>"", "en"=>""}, "choice_fields"=>{"zh_tw"=>["", "沒有"], "en"=>["yes", "no"]}, "is_num"=>0, "range"=>[], "right"=>0, "is_float"=>0, "revert_value"=>1, "map_values"=>[], "cancer_predict_mapping_file"=>"", "need_map_values"=>0},
"10"=>{"variable"=>"tumor_direct_extension", "name"=>{"zh_tw"=>"腫瘤浸潤至胸壁和/或皮膚<br/>(Tumor direct extension to the chest wall and/or to the skin)", "en"=>"Tumor direct extension to the chest wall and/or to the skin"}, "is_num"=>0, "hint"=>{"zh_tw"=>"", "en"=>""}, "comment_text"=>{"zh_tw"=>"若無腫瘤浸潤至胸壁或皮膚資訊請選擇未知,將以佔多數比例無腫瘤浸潤至胸壁作為後續預測。", "en"=>"Please select “unknown” if there is no information about tumor direct extension to the chest wall and/or to the skin. The prediction model would use “No” (the majority class) as the alternative variable"}, "choice_fields"=>{"zh_tw"=>["", "", "未知"], "en"=>["yes", "no", "unknown"]}, "range"=>[], "right"=>1, "is_float"=>0, "need_map_values"=>0, "revert_value"=>0, "map_values"=>[]}, "10"=>{"variable"=>"O6", "name"=>{"zh_tw"=>"慢性腎病", "en"=>" Chronic Kidney Disease"}, "hint"=>{"zh_tw"=>"", "en"=>""}, "comment_text"=>{"zh_tw"=>"", "en"=>""}, "choice_fields"=>{"zh_tw"=>["", "沒有"], "en"=>["yes", "no"]}, "is_num"=>0, "range"=>[], "right"=>1, "is_float"=>0, "revert_value"=>1, "map_values"=>[], "cancer_predict_mapping_file"=>"", "need_map_values"=>0},
"11"=>{"variable"=>"lvi", "name"=>{"zh_tw"=>"淋巴管或血管侵犯<br/>(Lymph vessel or vascular invasion, LVI)", "en"=>"Lymph vessel or vascular invasion, LVI"}, "is_num"=>0, "hint"=>{"zh_tw"=>"", "en"=>"Lymph vessel or vascular invasion"}, "comment_text"=>{"zh_tw"=>"若無淋巴管或血管侵犯資訊,請選擇“未知”選項,將以佔多數比例的淋巴管或血管未侵犯進行預測", "en"=>"Please select “unknown” if there is no information about Lymph vessel or vascular invasion. The prediction model would use “No” (the majority class) as the alternative variable."}, "choice_fields"=>{"zh_tw"=>["", "", "未知"], "en"=>["yes", "no", "unknown"]}, "range"=>[], "right"=>1, "is_float"=>0, "need_map_values"=>0, "revert_value"=>0, "map_values"=>[]} "11"=>{"variable"=>"N34", "name"=>{"zh_tw"=>"克羅恩病和潰瘍性結腸炎", "en"=>"Crohn's disease and ulcerative colitis"}, "hint"=>{"zh_tw"=>"", "en"=>""}, "comment_text"=>{"zh_tw"=>"", "en"=>""}, "choice_fields"=>{"zh_tw"=>["", "沒有"], "en"=>["yes", "no"]}, "is_num"=>0, "range"=>[], "right"=>1, "is_float"=>0, "revert_value"=>1, "map_values"=>[], "cancer_predict_mapping_file"=>"", "need_map_values"=>0},
} "12"=>{"variable"=>"N14", "name"=>{"zh_tw"=>"帕金森氏", "en"=>"Parkinson's disease"}, "hint"=>{"zh_tw"=>"", "en"=>""}, "comment_text"=>{"zh_tw"=>"", "en"=>""}, "choice_fields"=>{"zh_tw"=>["", "沒有"], "en"=>["yes", "no"]}, "is_num"=>0, "range"=>[], "right"=>1, "is_float"=>0, "revert_value"=>1, "map_values"=>[], "cancer_predict_mapping_file"=>"", "need_map_values"=>0},
field :form_show_in_result , :type=> Hash ,default: { "13"=>{"variable"=>"N26", "name"=>{"zh_tw"=>"多發性硬化症", "en"=>"Multiple sclerosis"}, "hint"=>{"zh_tw"=>"", "en"=>""}, "comment_text"=>{"zh_tw"=>"", "en"=>""}, "choice_fields"=>{"zh_tw"=>["", "沒有"], "en"=>["yes", "no"]}, "is_num"=>0, "range"=>[], "right"=>1, "is_float"=>0, "revert_value"=>1, "map_values"=>[], "cancer_predict_mapping_file"=>"", "need_map_values"=>0},
"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"=>[], "right"=>0, "is_float"=>0, "revert_value"=>0, "map_values"=>"", "active_choice"=>2, "disable_condition"=>"ER_status == 2 && PR_status == 2", "lpv_impact"=>-0.8397}, "14"=>{"variable"=>"O3", "name"=>{"zh_tw"=>"高血壓", "en"=>"Multiple sclerosis"}, "hint"=>{"zh_tw"=>"", "en"=>""}, "comment_text"=>{"zh_tw"=>"", "en"=>""}, "choice_fields"=>{"zh_tw"=>["", "沒有"], "en"=>["yes", "no"]}, "is_num"=>0, "range"=>[], "right"=>1, "is_float"=>0, "revert_value"=>1, "map_values"=>[], "cancer_predict_mapping_file"=>"", "need_map_values"=>0},
"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"=>[], "right"=>0, "is_float"=>0, "revert_value"=>0, "map_values"=>"", "active_choice"=>2, "disable_condition"=>"", "lpv_impact"=>-0.4147}, "15"=>{"variable"=>"O20", "name"=>{"zh_tw"=>"嚴重精神疾病", "en"=>"Severe mental illness"}, "hint"=>{"zh_tw"=>"", "en"=>""}, "comment_text"=>{"zh_tw"=>"", "en"=>""}, "choice_fields"=>{"zh_tw"=>["", "沒有"], "en"=>["yes", "no"]}, "is_num"=>0, "range"=>[], "right"=>1, "is_float"=>0, "revert_value"=>1, "map_values"=>[], "cancer_predict_mapping_file"=>"", "need_map_values"=>0},
"2"=>{"variable"=>"Radiotherapy", "name"=>{"zh_tw"=>"放射治療", "en"=>"Radiotherapy"}, "is_num"=>0, "hint"=>{"zh_tw"=>"", "en"=>""}, "comment_text"=>{"zh_tw"=>"", "en"=>""}, "choice_fields"=>{"zh_tw"=>["", ""], "en"=>["No", "Yes"]}, "range"=>[], "right"=>0, "is_float"=>0, "revert_value"=>0, "map_values"=>"", "active_choice"=>2, "disable_condition"=>"", "lpv_impact"=>-0.3203}, "16"=>{"variable"=>"O18", "name"=>{"zh_tw"=>"類風溼關節炎", "en"=>"Rheumatoid arthritis"}, "hint"=>{"zh_tw"=>"", "en"=>""}, "comment_text"=>{"zh_tw"=>"", "en"=>""}, "choice_fields"=>{"zh_tw"=>["", "沒有"], "en"=>["yes", "no"]}, "is_num"=>0, "range"=>[], "right"=>1, "is_float"=>0, "revert_value"=>1, "map_values"=>[], "cancer_predict_mapping_file"=>"", "need_map_values"=>0},
"3"=>{"variable"=>"Targeted_therapy", "name"=>{"zh_tw"=>"標靶治療", "en"=>"Targeted therapy"}, "is_num"=>0, "hint"=>{"zh_tw"=>"抗HER2治療", "en"=>""}, "comment_text"=>{"zh_tw"=>"", "en"=>""}, "choice_fields"=>{"zh_tw"=>["", ""], "en"=>["No", "Yes"]}, "range"=>[], "right"=>0, "is_float"=>0, "revert_value"=>0, "map_values"=>"", "active_choice"=>2, "disable_condition"=>"HER2_status != 1", "lpv_impact"=>-0.4687} "17"=>{"variable"=>"O11", "name"=>{"zh_tw"=>"非出血性腦血管疾病", "en"=>"Non-Hemorrhagic Cerebrovascular Disease"}, "hint"=>{"zh_tw"=>"", "en"=>""}, "comment_text"=>{"zh_tw"=>"", "en"=>""}, "choice_fields"=>{"zh_tw"=>["", "沒有"], "en"=>["yes", "no"]}, "is_num"=>0, "range"=>[], "right"=>1, "is_float"=>0, "revert_value"=>1, "map_values"=>[], "need_map_values"=>0},
"18"=>{"variable"=>"N29", "name"=>{"zh_tw"=>"強直性脊柱炎", "en"=>"Ankylosing spondylitis"}, "hint"=>{"zh_tw"=>"", "en"=>""}, "comment_text"=>{"zh_tw"=>"", "en"=>""}, "choice_fields"=>{"zh_tw"=>["", "沒有"], "en"=>["yes", "no"]}, "is_num"=>0, "range"=>[], "right"=>1, "is_float"=>0, "revert_value"=>1, "map_values"=>[], "need_map_values"=>0},
"19"=>{"variable"=>"N6", "name"=>{"zh_tw"=>"動脈血管", "en"=>"Arterial vasculopathy"}, "is_num"=>0, "hint"=>{"zh_tw"=>"", "en"=>""}, "comment_text"=>{"zh_tw"=>"", "en"=>""}, "choice_fields"=>{"zh_tw"=>["", "沒有"], "en"=>["yes", "no"]}, "range"=>[], "right"=>1, "is_float"=>0, "revert_value"=>1, "map_values"=>[], "need_map_values"=>0},
"20"=>{"variable"=>"O14", "name"=>{"zh_tw"=>"葡萄糖不耐症", "en"=>nil}, "is_num"=>0, "hint"=>{"zh_tw"=>"", "en"=>nil}, "comment_text"=>{"zh_tw"=>"", "en"=>nil}, "choice_fields"=>{"zh_tw"=>["", "沒有"], "en"=>nil}, "range"=>[], "right"=>1, "is_float"=>0, "revert_value"=>1, "map_values"=>[], "need_map_values"=>0},
"21"=>{"variable"=>"N43", "name"=>{"zh_tw"=>"Basedow's disease", "en"=>nil}, "is_num"=>0, "hint"=>{"zh_tw"=>"", "en"=>nil}, "comment_text"=>{"zh_tw"=>"", "en"=>nil}, "choice_fields"=>{"zh_tw"=>["", "沒有"], "en"=>nil}, "range"=>[], "right"=>1, "is_float"=>0, "revert_value"=>1, "map_values"=>[], "need_map_values"=>0},
"22"=>{"variable"=>"O17", "name"=>{"zh_tw"=>"偏頭痛", "en"=>nil}, "is_num"=>0, "hint"=>{"zh_tw"=>"", "en"=>nil}, "comment_text"=>{"zh_tw"=>"", "en"=>nil}, "choice_fields"=>{"zh_tw"=>["", "沒有"], "en"=>nil}, "range"=>[], "right"=>1, "is_float"=>0, "revert_value"=>1, "map_values"=>[], "need_map_values"=>0},
"23"=>{"variable"=>"O9", "name"=>{"zh_tw"=>"心臟衰竭", "en"=>nil}, "hint"=>{"zh_tw"=>"", "en"=>nil}, "comment_text"=>{"zh_tw"=>"", "en"=>nil}, "choice_fields"=>{"zh_tw"=>["", "沒有"], "en"=>nil}, "is_num"=>0, "range"=>[], "right"=>1, "is_float"=>0, "revert_value"=>1, "map_values"=>[], "need_map_values"=>0}
} }
field :form_show_in_result , :type=> Hash ,default: {}
field :form_result_is_right , :type=> Integer ,default: 0 field :form_result_is_right , :type=> Integer ,default: 0
field :text_descibe ,type:Hash ,default: { field :text_descibe ,type:Hash ,default: {
"zh_tw"=>"歡迎使用台灣準備乳癌預後系統!<br />\r\n本預測系統由台灣癌症登記資料庫2011至2015年間共20,997位乳癌病人所建立<br />\r\n並驗證美國流行病學癌症資料庫59,271位病人所建立 。<br />\r\n若要開始 請在下方選擇相關資訊", "zh_tw"=>"歡迎使用台灣心血管 疾病預後預測系統<br />\r\n本預測系統由全民健保資料庫2017年~2020年間共1700位病人電腦斷層影像所建立之預測模型<br />\r\n請 在下方填入相關資訊",
"en"=>"Welcome to the Taiwan Breast Cancer Prediction System!<br />\r\nThe prediction system is constructed using clinical data from 90,841 breast cancer patients in the Taiwan Cancer Registry database between 2011 to 2015, and validated using clinical data from 49,374 breast cancer patients in the U.S.-based Surveillance, Epidemiology and End Results (SEER) database.<br />\r\nTo start, please select the information below." "en"=>"Welcome to the Taiwan cardiovascular disease prognosis prediction&nbsp;System!<br />\r\nThe prediction system is a prediction model established by CT images of 1,700 patients form the National Health Insurance Database&nbsp;between 2017 to 2020.<br />\r\nTo start, please select the information below."
} }
field :small ,type:Hash ,default:{'font_size'=>"0.825em",'active'=>0} field :small ,type:Hash ,default:{'font_size'=>"0.825em",'active'=>0}
field :medium ,type:Hash ,default:{'font_size'=>"1em",'active'=>1} field :medium ,type:Hash ,default:{'font_size'=>"1em",'active'=>1}
field :large ,type:Hash ,default:{'font_size'=>"1.25em",'active'=>0} field :large ,type:Hash ,default:{'font_size'=>"1.25em",'active'=>0}
field :head_images_id ,type:Array , default: [BSON::ObjectId('5df62cfc8cd8924e79000009'), BSON::ObjectId('5df745a58cd8924491000006'), BSON::ObjectId('5e7848c98cd8924f8d00004a'), BSON::ObjectId('5ea8f3e48cd892760b000011')] field :head_images_id ,type:Array , default: []
field :title_images_id ,type:Array , default: [BSON::ObjectId('5df87cd88cd8924491000036')] field :title_images_id ,type:Array , default: []
field :title_texts ,type:Hash ,default: {"zh_tw"=>"華人癌症存活預測", "en"=>"Asian breast cancer prediction"} field :title_texts ,type:Hash ,default: {"zh_tw"=>"臺灣心血管疾病存活預測", "en"=>"Cardiovascular Disease Survival Forecast in Taiwan"}
field :table_above_texts ,type:Hash ,default: {"zh_tw"=>"下表之分析為針對手術後病人,根據選定的術後治療,分別估計在第1年、3 及5年的存活率。", "en"=>"The analysis is for women who had undergone surgery.The table shows the 1-, 3- and 5-year survival rates,based on the treatment you have selected."} field :table_above_texts ,type:Hash ,default: {"zh_tw"=>"下表之分析為針對手術後病人,根據選定的術後治療,分別估計在一年、一年半、兩年及兩年半的心血管疾病住院或死亡機率。", "en"=>"The analysis is for women who had undergone surgery.The table shows the 1,1.5, 2 and 2.5 year survival rates,based on the treatment you have selected."}
field :text_above_texts ,type:Hash ,default: {"zh_tw"=>"此研究分析來自已接受根除性手術後之婦女所得之結果,根據您所輸入的資訊以及治療方式,在術後<br/>第{{years}}年,", "en"=>"The analysis is for women who had undergone surgery. Base on the information and the treatment you have selected, the predictions of survival status<br/>{{years}}"} field :text_above_texts ,type:Hash ,default: {"zh_tw"=>"此研究分析來自於照射胸部電腦斷層所得之結果,根據您所輸入的資訊,在第{{years}}年內,有{{Surgery_only}}%的 機率可能心血管疾病住院或死亡。", "en"=>"This research comes from the results obtained by irradiating the chest CT. According to the information you entered that you have the {{Surgery_only}}% of hospitalization or death for cardiovascular disease within {{years}} years."}
field :surgery_only_texts ,type:Hash ,default: {"zh_tw"=>"100 位只接受根除性手術的婦女中,有{{Surgery_only}}位婦女,術後{{surgery_year}}年仍為存活", "en"=>"after surgery are as follows:<br/>{{Surgery_only}} out of 100 women treated with surgery only are alive at {{surgery_year}} years."} field :surgery_only_texts ,type:Hash ,default: {"zh_tw"=>"", "en"=>""}
field :extra_texts ,type:Hash ,default: {"zh_tw"=>",此外", "en"=>""} 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 :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 :danger_texts ,type:Hash ,default: {"zh_tw"=>"請注意紅框的輸入資料是否符合要求!", "en"=>"Please check whether input data in red blocks are correct!"}
field :years ,type:Array ,default:[1,3,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 :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 :image_uploader ,type:Object
field :prediction_formula , type: String ,default: "lpv = ((age1-0.7276655)*(-10.87)+(age2+0.4540707)*8.968+(size1-0.643632)*0.7678+(nposit-1.346932)*0.5339+ field :prediction_formula , type: String ,default: "A = 0.1327868* (sex_value- 0.4858824)
grade_2*0.4795+grade_3*0.818+subtype_HER2*0.1806+subtype_triple*0.6457+pstage_2*0.5311+
pstage_3*1.134+pstage_4*2.172+lvi_yes*0.3321-0.04+chemo*(-0.4147)+radio*(-0.3203)+hormone*(-0.8397)+target*(0.3321) + 0.0371720* (age_test1 - 61.56000) -0.07447278* (age_test2 - 13.10152)
)"
field :years_settings , type: Array , default: ["exp(-0.001476145)^( exp(lpv) )","exp(-0.01261639)^( exp(lpv) )","exp(-0.02519608)^( exp(lpv) )"] + 0.4315686* (age_test3 - 0.9844332)
+ 0.0009163615*( calH_test1 - 182.9347)
-0.0007536899*( calH_test2 - 124.8706) -0.00004697183*( calH_test3 -80.75636)
+ 0.0001401325*( calAH_test1 - 700.7824)
-0.001349783*( calAH_test2 - 634.2167) +0.001753832*( calAH_test3 -419.3361)
+ 0.0001906046*( calDH_test1 -835.2894) -0.000251567*( calDH_test2 - 213.1630)
-0.002173942*( fat_test1 -108.4149)+0.003066541*( fat_test2 - 28.33497)
+0.6700708*(N4-0.3241176)
+0.3336162*(O3-0.4994118)
+0.1322476*(O20-0.1741176)
+0.9084972*(O18-0.008823529)
+0.2978388*(N12-0.1152941)
+0.1777935*(N20-0.3582353)
+1.588042*(N31-0.002352941)
+0.2197419*(O6-0.07823529)
+1.791159*(N34-0.001176471)
+0.4305973*(N14-0.02176471)
-0.4472885*(N29-0.02411765)
+0.2601319*(N26-0.04941176)
-0.2364269*(O11-0.1164706)
+0.1784179*(N6-0.1070588)
+0.6023170*(O14-0.01294118)
-1.031959*(N43-0.007058824)
+0.4257809*(O17-0.01823529)
+0.2002546*(O9-0.06176471)"
field :years_settings , type: Array , default: ["0.8095037^( exp(A) )", "0.729158^( exp(A) )", "0.6717211^( exp(A) )", "0.6056773^( exp(A) )"]
field :tmp_years_settings , type: Array , default: [] field :tmp_years_settings , type: Array , default: []
field :tmp_years_settings_for_ruby , type: Array , default: [] field :tmp_years_settings_for_ruby , type: Array , default: []
field :hidden_variables, type: String, default: "age1 = (age / 100.0) ^ (0.5) field :hidden_variables, type: String, default: ""
age2 = age1 * log(age / 100.0)
size1 = log(size / 10.0)
ratio = (lymph_nodes_examined == 0 ? 0 : (1.0 * lymph_nodes_positive / lymph_nodes_examined))
ratio = (ratio > 1 ? 1 : ratio)
T4 = (tumor_direct_extension == 1)
T1 = !T4 && (size <= 20)
T2 = !T4 && !T1 && (size > 20 && size <= 50)
T = (T4 ? 'T4' : (T1 ? 'T1' : (T2 ? 'T2' : 'T3')))
N0 = (lymph_nodes_positive == 0)
N1_or_N1mi = !N0 && (lymph_nodes_positive >= 1 && lymph_nodes_positive <= 3)
N1 = N1_or_N1mi && micrometastasis != 1
N1mi = N1_or_N1mi && micrometastasis == 1
N2 = !N0 && !N1_or_N1mi && (lymph_nodes_positive <= 9)
N = (N0 ? 'N0' : (N1 ? 'N1' : (N1mi ? 'N1mi' : (N2 ? 'N2' : 'N3'))))
M = (Distant_Metastasis != 1) ? 'M0' : 'M1'
pstage = (M == 'M1' ? 4 : ((T == 'T1' && (N == 'N0' || N == 'N1mi')) ? 1 : (((T == 'T2' || T == 'T3') && (N == 'N0')) || ((T == 'T1' || T == 'T2') && (N == 'N1')) ? 2 : 3)) )
nposit = ((ratio + 0.1) / 0.1) ^ 0.5
grade_2 = (grade == 2 || grade == 4) ? 1 : 0
grade_3 = (grade == 3) ? 1 : 0
subtype_1 = (ER_status != 2 || PR_status != 2) && (HER2_status != 1)
subtype_2 = !subtype_1 && (HER2_status == 1)
subtype_3 = !subtype_1 && !subtype_2 && (ER_status == 2 && PR_status == 2 && HER2_status != 1)
subtype_HER2 = subtype_2 ? 1 : 0
subtype_triple = subtype_3 ? 1 : 0
pstage_2 = (pstage == 2) ? 1 : 0
pstage_3 = (pstage == 3) ? 1 : 0
pstage_4 = (pstage == 4) ? 1 : 0
lvi_yes = (lvi == 1) ? 1 : 0
chemo = (Chemotherapy == 2) ? 1 : 0
radio = (Radiotherapy == 2) ? 1 : 0
hormone = (hormone_therapy == 2) ? 1 : 0
target = (Targeted_therapy == 2) ? 1 : 0
"
field :fix_hidden_variables, type: Array, default: [] field :fix_hidden_variables, type: Array, default: []
field :tmp_hidden_variables_for_ruby, type: String, default: "" field :tmp_hidden_variables_for_ruby, type: String, default: ""
field :tmp_hidden_variables_for_js, type: String, default: "" field :tmp_hidden_variables_for_js, type: String, default: ""
@ -189,8 +206,8 @@ class Cancerpredictfields
tmp_table_translations = {} tmp_table_translations = {}
tmp_text_translations = {} tmp_text_translations = {}
@years = self.years @years = self.years
@head_name = ['Treatment','Additional_Benefit','Overall_Survival'] # @head_name = ['Treatment','Additional_Benefit','Overall_Survival']
# @head_name = ['Treatment','Overall_Survival'] @head_name = ['Treatment','Overall_Survival']
@therapy_names = self.treatment_method @therapy_names = self.treatment_method
I18n.available_locales.each do |locale| I18n.available_locales.each do |locale|
I18n.with_locale(locale) do I18n.with_locale(locale) do
@ -198,7 +215,7 @@ class Cancerpredictfields
@therapy_choices = [I18n.t('cancerpredict.table.Surgeryonly')] @therapy_choices = [I18n.t('cancerpredict.table.Surgeryonly')]
self.form_show_in_result.values.each{|choice| @therapy_choices.push choice["name"][locale].to_s} self.form_show_in_result.values.each{|choice| @therapy_choices.push choice["name"][locale].to_s}
tmp_table = "<span class=\"result_title print_only\">#{I18n.t("cancerpredict.table.table")}</span><div style=\"clear: both\"></div>" tmp_table = "<span class=\"result_title print_only\">#{I18n.t("cancerpredict.table.table")}</span><div style=\"clear: both\"></div>"
tmp_table += '<input id="current_year" type="hidden" value="'+@years[-1].to_s+'" index="0"/><p id="cancer_table_texts">'+self.table_above_texts[locale].to_s+'</p>' tmp_table += '<input id="current_year" type="hidden" value="'+@years[0].to_s+'" index="0"/><p id="cancer_table_texts">'+self.table_above_texts[locale].to_s+'</p>'
tmp_table += ('<a style="display: inline-block;">'+(locale.to_s == 'zh_tw' ? '第' : '')+'</a><a style="display: inline-block;">') tmp_table += ('<a style="display: inline-block;">'+(locale.to_s == 'zh_tw' ? '第' : '')+'</a><a style="display: inline-block;">')
@years.each{|year| tmp_table += ('<button class="cancer_years cancer_table_btn btn btn-default btn-sm">'+year.to_s+'</button>')} @years.each{|year| tmp_table += ('<button class="cancer_years cancer_table_btn btn btn-default btn-sm">'+year.to_s+'</button>')}
tmp_table += ('</a><a style="display: inline-block;">'+(locale == 'zh_tw' ? '年' : '')+'</a>') tmp_table += ('</a><a style="display: inline-block;">'+(locale == 'zh_tw' ? '年' : '')+'</a>')
@ -293,7 +310,7 @@ class Cancerpredictfields
end end
def reload_js_asset(path, force_reload=false) def reload_js_asset(path, force_reload=false)
reload_any_asset(path, 'application/javascript', force_reload) do |new_path| reload_any_asset(path, 'application/javascript', force_reload) do |new_path|
File.open(JSFileName, 'w+'){|f| f.write(new_path)} File.open("#{Rails.root}/public/cancer_tool_js_filename.txt",'w+'){|f| f.write(new_path)}
end end
end end
def generate_eval_formula def generate_eval_formula
@ -376,7 +393,7 @@ class Cancerpredictfields
function calculate_and_change_result_value(obj){ function calculate_and_change_result_value(obj){
obj.servive_ratio_arr = []; obj.servive_ratio_arr = [];
for(var i = 0;i<obj.active_treatment.length;i++){ for(var i = 0;i<obj.active_treatment.length;i++){
var servive_ratio = round(calculate_servive_ratio(obj.year,obj.lpv_real[i])*100,2); var servive_ratio = round((1 - calculate_servive_ratio(obj.year,obj.lpv_real[i]))*100,2);
var benefit = servive_ratio - obj.servive_ratio_arr[obj.servive_ratio_arr.length-1]; var benefit = servive_ratio - obj.servive_ratio_arr[obj.servive_ratio_arr.length-1];
obj.servive_ratio_arr.push(servive_ratio); obj.servive_ratio_arr.push(servive_ratio);
$('tr.'+obj.active_treatment[i]+' td.Overall_Survival').html(servive_ratio+'%'); $('tr.'+obj.active_treatment[i]+' td.Overall_Survival').html(servive_ratio+'%');
@ -423,7 +440,8 @@ class Cancerpredictfields
end end
def auto_write_predict_js(force_reload=true) def auto_write_predict_js(force_reload=true)
js_codes = generate_jscode js_codes = generate_jscode
save_path = "#{ModuleAppPath}/app/assets/javascripts/#{JS}" module_app_path = Pathname.new(File.expand_path(__dir__)).dirname.dirname.to_s
save_path = module_app_path + '/app/assets/javascripts/cancer_predict.js'
file_texts = File.read(save_path) file_texts = File.read(save_path)
need_write = false need_write = false
str1 = "/* auto add start */" str1 = "/* auto add start */"
@ -487,8 +505,8 @@ class Cancerpredictfields
if need_write if need_write
File.write(save_path,file_texts) File.write(save_path,file_texts)
reload_js_asset(save_path, force_reload) reload_js_asset(save_path, force_reload)
elsif !(File.exist?(JSFileName)) elsif !(File.exist?("#{Rails.root}/public/cancer_tool_js_filename.txt"))
File.open(JSFileName, 'w+'){|f| f.write(save_path)} File.open("#{Rails.root}/public/cancer_tool_js_filename.txt",'w+'){|f| f.write(save_path)}
end end
end end
def get_years_settings_dict def get_years_settings_dict

View File

@ -16,7 +16,6 @@
<%else%> <%else%>
<% @disp_value = @value %> <% @disp_value = @value %>
<%end%> <%end%>
<% @disp_value = bc_yaml_dump(@disp_value) if value_type == 'Array' %>
<% field_type = ((value_type == 'String' || value_type == 'Array' || value_type == 'Float') ? "text_field" : value_type) %> <% field_type = ((value_type == 'String' || value_type == 'Array' || value_type == 'Float') ? "text_field" : value_type) %>
<% if value_type == 'Fixnum' %> <% if value_type == 'Fixnum' %>
<% if @value == 1%> <% if @value == 1%>

View File

@ -277,27 +277,15 @@
<div><%= form.check_box "form_result_is_right",{:checked=>false,:class=>"checkbox",:style=>"float: left;position: relative;left: 0;transform: none!important;margin-left: 1em;",:id=>"form_result_is_right"}%></div> <div><%= form.check_box "form_result_is_right",{:checked=>false,:class=>"checkbox",:style=>"float: left;position: relative;left: 0;transform: none!important;margin-left: 1em;",:id=>"form_result_is_right"}%></div>
<%end%> <%end%>
<div style="clear:both;"></div> <div style="clear:both;"></div>
<% @create_items = ['years','table_above_texts','text_above_texts','surgery_only_texts','extra_texts','extra_therapy_texts','danger_texts','texts_between_Result_and_result_block'] <% @create_items = ['years','table_above_texts','text_above_texts','surgery_only_texts','extra_texts','extra_therapy_texts','danger_texts','texts_between_Result_and_result_block'] %>
array_indices = [0] <% @create_items.each do |item|%>
%>
<% @create_items.each_with_index do |item, i|%>
<label for="<%=item%>" style="float: left;margin-right:1em;width:11em;"><%= t('cancerpredict.'+item)+':' %></label> <label for="<%=item%>" style="float: left;margin-right:1em;width:11em;"><%= t('cancerpredict.'+item)+':' %></label>
<% if @form_to_show[item].class == BSON::Document || @form_to_show[item].class == Hash %> <% if @form_to_show[item].class == BSON::Document || @form_to_show[item].class == Hash %>
<%= form.fields_for item do |locale_fields|%> <%= form.fields_for item do |locale_fields|%>
<% value = @form_to_show[item][I18n.locale.to_s] <%= locale_fields.text_field I18n.locale.to_s,{:value=>@form_to_show[item][I18n.locale.to_s] ,:id=> item,:style=>'width:calc(100% - 16em)'} %>
if array_indices.include?(i)
value = bc_yaml_dump(value)
end
%>
<%= locale_fields.text_field I18n.locale.to_s,{:value=> value,:id=> item,:style=>'width:calc(100% - 16em)'} %>
<% end %> <% end %>
<% else %> <% else %>
<% value = @form_to_show[item] <%= form.text_field item,{:value=>@form_to_show[item],:id=> item,:style=>'width:calc(100% - 16em)'} %>
if array_indices.include?(i)
value = bc_yaml_dump(value)
end
%>
<%= form.text_field item,{:value=> value,:id=> item,:style=>'width:calc(100% - 16em)'} %>
<% end %> <% end %>
<div style="clear:both;"></div> <div style="clear:both;"></div>
<% end %> <% end %>

View File

@ -1,14 +1,14 @@
en: en:
module_name: module_name:
cancerpredict: Predict Breast Cancer Tool cancerpredict: Cardiovascular Disease Survival Forecast in Taiwan Tool
cancerpredict: cancerpredict:
hidden_variables: "Hidden Variables" hidden_variables: "Hidden Variables"
advance_mode_hint1: "After opening advance modecalculation will change!\nAre you sure switch to advance mode?" advance_mode_hint1: "After opening advance modecalculation will change!\nAre you sure switch to advance mode?"
advance_mode_hint2: "一般模式: 選項設定在計算時對應到的值由1開始。(例如: 選項設定為[\"是\",\"否\"],則\"是\"在計算時對應到1而\"否\"在計算時對應到2)。<br><hr class=\"solid_line_hr\">進階模式: 選項設定在計算時對應到的值由0開始。<br>而若開啟選項值從大到小則0對應到選項設定中的最後一項。<br>選項對應到的值的意思為當前述的計算值為0時則對應到定義的Array的第1個元素的值以此類推。<br>欄位對應檔案可上傳一個csv檔案在計算時會先依照csv中的第1直行找到對應的變數1(生成的變數名稱為csv中的第1列)的值,其餘生成的變數值則為對應之後的同一橫列的值。" advance_mode_hint2: "一般模式: 選項設定在計算時對應到的值由1開始。(例如: 選項設定為[\"是\",\"否\"],則\"是\"在計算時對應到1而\"否\"在計算時對應到2)。<br><hr class=\"solid_line_hr\">進階模式: 選項設定在計算時對應到的值由0開始。<br>而若開啟選項值從大到小則0對應到選項設定中的最後一項。<br>選項對應到的值的意思為當前述的計算值為0時則對應到定義的Array的第1個元素的值以此類推。<br>欄位對應檔案可上傳一個csv檔案在計算時會先依照csv中的第1直行找到對應的變數1(生成的變數名稱為csv中的第1列)的值,其餘生成的變數值則為對應之後的同一橫列的值。"
module_mode: Module Mode module_mode: Module Mode
advance_mode: Advance Mode advance_mode: Advance Mode
Overall_Survival: Overall Survival Overall_Survival: Probability
cancerpredict: Adjust the predict breast cancer tool cancerpredict: Adjust Cardiovascular Disease Survival Forecast in Taiwan Tool
submitResult: see submit results of the users submitResult: see submit results of the users
result_is_right: Is therapy choices in the right hand side of result block? result_is_right: Is therapy choices in the right hand side of result block?
text_descibe: text descibe text_descibe: text descibe
@ -33,7 +33,7 @@ en:
texts_between_Result_and_result_block: Texts between "Result" and "Result block" texts_between_Result_and_result_block: Texts between "Result" and "Result block"
prev_page: Previous page prev_page: Previous page
next_page: Next page next_page: Next page
export_cancer_predict_tool_records: Export cancer predict tool records export_cancer_predict_tool_records: Export Cardiovascular Disease Survival Forecast in Taiwan Tool records
table: table:
welcome: Welcome to The after breast cancer healing system of Taiwanprepare!\nTo start, please enter the relevant information below. welcome: Welcome to The after breast cancer healing system of Taiwanprepare!\nTo start, please enter the relevant information below.
Reset: Reset Reset: Reset
@ -52,10 +52,10 @@ en:
no: no no: no
unknown: unknown unknown: unknown
Results: Results Results: Results
Treatment: Treatment Treatment: Event
Additional_Benefit: Additional Benefit Additional_Benefit: Additional Benefit
Overall_Survival: Overall Survival(%) Overall_Survival: Probability(%)
Surgeryonly: Surgery only Surgeryonly: Readmission or death
Hormonetherapy: Hormone therapy Hormonetherapy: Hormone therapy
Chemotherapy: Chemotherapy Chemotherapy: Chemotherapy
years: years years: years

View File

@ -1,14 +1,14 @@
zh_tw: zh_tw:
module_name: module_name:
cancerpredict: 乳癌預測工具 cancerpredict: 臺灣心血管疾病存活預測工具
cancerpredict: cancerpredict:
hidden_variables: "隱藏的變數" hidden_variables: "隱藏的變數"
advance_mode_hint1: "開啟進階模式後,計算方式有差異。\n您確定要開啟進階模式?" advance_mode_hint1: "開啟進階模式後,計算方式有差異。\n您確定要開啟進階模式?"
advance_mode_hint2: "一般模式: 選項設定在計算時對應到的值由1開始。(例如: 選項設定為[\"是\",\"否\"],則\"是\"在計算時對應到1而\"否\"在計算時對應到2)。<br><hr class=\"solid_line_hr\">進階模式: 選項設定在計算時對應到的值由0開始。<br>而若開啟選項值從大到小則0對應到選項設定中的最後一項。<br>選項對應到的值的意思為當前述的計算值為0時則對應到定義的Array的第1個元素的值以此類推。<br>欄位對應檔案可上傳一個csv檔案在計算時會先依照csv中的第1直行找到對應的變數1(生成的變數名稱為csv中的第1列)的值,其餘生成的變數值則為對應之後的同一橫列的值。" advance_mode_hint2: "一般模式: 選項設定在計算時對應到的值由1開始。(例如: 選項設定為[\"是\",\"否\"],則\"是\"在計算時對應到1而\"否\"在計算時對應到2)。<br><hr class=\"solid_line_hr\">進階模式: 選項設定在計算時對應到的值由0開始。<br>而若開啟選項值從大到小則0對應到選項設定中的最後一項。<br>選項對應到的值的意思為當前述的計算值為0時則對應到定義的Array的第1個元素的值以此類推。<br>欄位對應檔案可上傳一個csv檔案在計算時會先依照csv中的第1直行找到對應的變數1(生成的變數名稱為csv中的第1列)的值,其餘生成的變數值則為對應之後的同一橫列的值。"
module_mode: 模組模式 module_mode: 模組模式
advance_mode: 進階模式 advance_mode: 進階模式
Overall_Survival: 總生存率 Overall_Survival: Probability
cancerpredict: 乳癌預測工具調整 cancerpredict: 臺灣心血管疾病存活預測工具調整
submitResult: 查看用戶繳交表單結果 submitResult: 查看用戶繳交表單結果
result_is_right: 治療選項在結果的右邊? result_is_right: 治療選項在結果的右邊?
text_descibe: 文字說明 text_descibe: 文字說明
@ -33,7 +33,7 @@ zh_tw:
texts_between_Result_and_result_block: 在"結果"和"結果區塊"之間的文字 texts_between_Result_and_result_block: 在"結果"和"結果區塊"之間的文字
prev_page: 上一頁 prev_page: 上一頁
next_page: 下一頁 next_page: 下一頁
export_cancer_predict_tool_records: 匯出乳癌預測系統的使用者紀錄 export_cancer_predict_tool_records: 匯出臺灣心血管疾病存活預測工具的使用者紀錄
table: table:
welcome: 歡迎使用台灣準備乳癌癒後系統!\n若要開始 請在下方輸入相關資訊 welcome: 歡迎使用台灣準備乳癌癒後系統!\n若要開始 請在下方輸入相關資訊
Reset: 重置 Reset: 重置
@ -52,9 +52,9 @@ zh_tw:
no: no:
unknown: 未知 unknown: 未知
Results: 結果 Results: 結果
Treatment: 治療 Treatment: Event(事件)
Additional_Benefit: 額外治療效益 Additional_Benefit: 額外治療效益
Overall_Survival: 總生存率(%) Overall_Survival: Probability(機率)(%)
Surgeryonly: 純手術 Surgeryonly: 純手術
Hormonetherapy: 賀爾蒙治療 Hormonetherapy: 賀爾蒙治療
Chemotherapy: 化學治療 Chemotherapy: 化學治療

View File

@ -12,11 +12,10 @@ module Cancerpredict
set_keyword_contstraints ['cancerpredictResult'] set_keyword_contstraints ['cancerpredictResult']
frontend_enabled frontend_enabled
side_bar do side_bar do
head_label_i18n 'cancerpredict.cancerpredict', icon_class: "icons-tools" head_label_i18n 'cancerpredict.cancerpredict', icon_class: "icons-megaphone"
available_for "users" available_for "users"
active_for_controllers (['admin/cancerpredicts']) active_for_controllers (['admin/cancerpredicts'])
head_link_path "admin_cancerpredicts_path" head_link_path "admin_cancerpredicts_path"
set_sidebar_order -10
context_link 'cancerpredict.cancerpredict', context_link 'cancerpredict.cancerpredict',
:link_path=>"admin_cancerpredicts_path" , :link_path=>"admin_cancerpredicts_path" ,

View File

@ -3,8 +3,8 @@
{ {
"filename" : "cancer_predict_index", "filename" : "cancer_predict_index",
"name" : { "name" : {
"zh_tw" : "1. 乳癌預測工具", "zh_tw" : "1. 臺灣心血管疾病存活預測工具",
"en" : "1. Breast cancer predict tool" "en" : "1. Cardiovascular Disease Survival Forecast Tool"
}, },
"thumbnail" : "thumb.png" "thumbnail" : "thumb.png"
} }
@ -13,8 +13,8 @@
{ {
"filename" : "cancer_predict_widget", "filename" : "cancer_predict_widget",
"name" : { "name" : {
"zh_tw" : "1. 乳癌預測工具", "zh_tw" : "1. 臺灣心血管疾病存活預測工具",
"en" : "1. Breast cancer predict tool" "en" : "1. Cardiovascular Disease Survival Forecast Tool"
}, },
"thumbnail" : "thumb.png" "thumbnail" : "thumb.png"
} }