Update to version2.(Fix all known bugs.)

This commit is contained in:
BoHung Chiu 2022-01-26 19:19:28 +08:00
parent 73c46c2b51
commit b8e6e80d81
16 changed files with 815 additions and 619 deletions

View File

@ -6,18 +6,25 @@ Array.prototype.get_nearest_value = function(goal){
} }
function change_object_variables(obj1,obj2,operator="-",target="new"){ function change_object_variables(obj1,obj2,operator="-",target="new"){
var obj_new = {}; var obj_new = {};
Object.keys(function(k){ var obj_keys = Object.keys(obj1);
if(operator == "-"){ obj_keys.forEach(function(k){
if(obj2[k] == undefined){
if( target == "new"){ if( target == "new"){
obj_new[k] = obj1[k] - obj2[k]; obj_new[k] = obj1[k];
}else{
obj1[k] = obj1[k] - obj2[k];
} }
}else if(operator == "+"){ }else{
if( target == "new"){ if(operator == "-"){
obj_new[k] = obj1[k] + obj2[k]; if( target == "new"){
}else{ obj_new[k] = obj1[k] - obj2[k];
obj1[k] = obj1[k] + obj2[k]; }else{
obj1[k] = obj1[k] - obj2[k];
}
}else if(operator == "+"){
if( target == "new"){
obj_new[k] = obj1[k] + obj2[k];
}else{
obj1[k] = obj1[k] + obj2[k];
}
} }
} }
}) })
@ -315,13 +322,22 @@ $(document).ready(function(){
$('#hormone_therapy .cancer_table_btn').removeAttr('disabled'); $('#hormone_therapy .cancer_table_btn').removeAttr('disabled');
$('[for="hormone_therapy"]').css('color',''); $('[for="hormone_therapy"]').css('color','');
}; };
if(post_json["HER2_status"] != 1){ /*disable_condition start*/
$('#Targeted_therapy .cancer_table_btn').attr('disabled','disabled'); if(post_json["ER_status"] == 2 && post_json["PR_status"] == 2){
$('[for="Targeted_therapy"]').css('color','rgb(204, 204, 204)'); $('#hormone_therapy .cancer_table_btn').attr('disabled','disabled');
}else{ $('[for="hormone_therapy"]').css('color','rgb(204, 204, 204)');
$('#Targeted_therapy .cancer_table_btn').removeAttr('disabled'); }else{
$('[for="Targeted_therapy"]').css('color',''); $('#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*/
return post_json; return post_json;
}else{ }else{
return null; return null;
@ -374,23 +390,28 @@ $(document).ready(function(){
$('#cancer_table_right_result .cancer-btn-group').eq(i).find('.cancer_table_btn').eq(0).addClass('active'); $('#cancer_table_right_result .cancer-btn-group').eq(i).find('.cancer_table_btn').eq(0).addClass('active');
$('#cancer_table_right_result .cancer-btn-group').eq(i).find('>input').eq(0).attr('value',"1"); $('#cancer_table_right_result .cancer-btn-group').eq(i).find('>input').eq(0).attr('value',"1");
}; };
var treatmeny_method = result.responseJSON.treatmeny_method; var treatment_method = result.responseJSON.treatment_method;
$('tr.'+treatmeny_method[0]).addClass('tr_show') var treatment_method_active_indices = result.responseJSON.treatment_method_active_indices;
var lpv = [0,-0.8397,-0.4147,-0.3203,-0.4687]; $('tr.'+treatment_method[0]).addClass('tr_show');
var servive_ratio_arr = [result.responseJSON.servive_ratio] var servive_ratio_arr = [result.responseJSON.servive_ratio]
var yes = (I18n.locale=="zh_tw") ? "是" : "yes"; var yes = (I18n.locale=="zh_tw") ? "是" : "yes";
var year = $('#current_year').attr('value'); var year = $('#current_year').attr('value');
var active_treatment = ['Surgery_only']; var active_treatment = ['Surgery_only'];
$('tr.'+active_treatment[0]+' .Overall_Survival').html(servive_ratio_arr[0]+'%'); $('tr.'+active_treatment[0]+' .Overall_Survival').html(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_dict={} var lpv = /*therapy_lpv start*/[0, -0.8397, -0.4147, -0.3203, -0.4687];/*therapy_lpv 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*/ 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*/
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');
var lpv_current = change_object_variables(lpv_real[lpv_real.length-1],lpv_dict[arguments[0]],'+'); console.log(lpv_real);
console.log(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'];
var servive_ratio = round((1 - 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);
@ -433,9 +454,10 @@ $(document).ready(function(){
var year = $('#current_year').attr('value'); var year = $('#current_year').attr('value');
if(index < this.length - 1){ if(index < this.length - 1){
for(var i = index + 1;i < this.length; i++){ for(var i = index + 1;i < this.length; i++){
change_object_variables(lpv_real[i] , 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];
var servive_ratio = round(eval(lpv_calc[year])*100,2); lpv_current = lpv_current['lpv'];
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+'%');
@ -471,39 +493,15 @@ $(document).ready(function(){
$('.addition').css('display','none'); $('.addition').css('display','none');
$('#result_text_content .extra-text').css('display','none'); $('#result_text_content .extra-text').css('display','none');
}; };
console.log(this)
return Array.prototype.remove_item_from_array.apply(this, arguments); return Array.prototype.remove_item_from_array.apply(this, arguments);
}else{ }else{
console.log(this)
return Array.prototype.remove_item_from_array.apply(this, arguments); return Array.prototype.remove_item_from_array.apply(this, arguments);
}; };
}; };
for(var i = 0;i<treatmeny_method.length;i++){ for(var i = 0;i<treatment_method.length;i++){
lpv_dict[treatmeny_method[i]] = lpv[i]; lpv_dict[treatment_method[i]] = lpv[i];
var click_flag=false; var click_flag=false;
$('#'+treatmeny_method[i]+' .cancer_table_btn').eq(1).off('click'); $('#'+treatment_method[i]+' .cancer_table_btn').off('click').click(function(){
$('#'+treatmeny_method[i]+' .cancer_table_btn').eq(1).click(function(){
var index = $(this).index()/2;
try{
$(this).parent().find('>input').attr('value',0);
$(this).parent().find('>input').eq(index).attr('value',1);
$(this).parent().find('>button').removeClass('active');
$(this).parent().removeClass('cancertable_empty');
if($('.cancertable_empty').length == 0){
$('#danger_texts').remove();
};
}catch(e){};
$(this).addClass('active');
if(!click_flag){
if(!active_treatment.includes($(this).parent().attr('id'))){
click_flag = true;
active_treatment.push($(this).parent().attr('id'));
click_flag = false;
};
}
});
$('#'+treatmeny_method[i]+' .cancer_table_btn').eq(0).off('click');
$('#'+treatmeny_method[i]+' .cancer_table_btn').eq(0).click(function(){
var index = $(this).index()/2; var index = $(this).index()/2;
try{ try{
$(this).parent().find('>input').attr('value',0); $(this).parent().find('>input').attr('value',0);
@ -523,6 +521,26 @@ $(document).ready(function(){
}; };
}; };
}); });
$('#'+treatment_method[i]+' .cancer_table_btn').eq(treatment_method_active_indices[i]).off('click').click(function(){
var index = $(this).index()/2;
try{
$(this).parent().find('>input').attr('value',0);
$(this).parent().find('>input').eq(index).attr('value',1);
$(this).parent().find('>button').removeClass('active');
$(this).parent().removeClass('cancertable_empty');
if($('.cancertable_empty').length == 0){
$('#danger_texts').remove();
};
}catch(e){};
$(this).addClass('active');
if(!click_flag){
if(!active_treatment.includes($(this).parent().attr('id'))){
click_flag = true;
active_treatment.push($(this).parent().attr('id'));
click_flag = false;
};
}
});
}; };
$('#current_year').change(function(){ $('#current_year').change(function(){
year = $(this).attr('value'); year = $(this).attr('value');
@ -592,134 +610,82 @@ $(document).ready(function(){
}; };
}; };
/* auto add start */ /* auto add start */
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( i == 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( i == 0 ){
var index_val = v.indexOf(temp_value);
if( index_val != -1 ){
temp_index = index_val;
}else{
closest_value = v.get_nearest_value(temp_value);
temp_index = v.indexOf(closest_value)
}
}
result[k] = v[temp_index];
index++;
});
result['calAH'] = Number(result_json['calAH']);
mapping_hash = mapping_data_from_csv['calAH'];
temp_index = 0;
temp_value = result[calAH];
index = 0;
$.each(mapping_hash,function(k,v){
if( i == 0 ){
var index_val = v.indexOf(temp_value);
if( index_val != -1 ){
temp_index = index_val;
}else{
closest_value = v.get_nearest_value(temp_value);
temp_index = v.indexOf(closest_value)
}
}
result[k] = v[temp_index];
index++;
});
result['calDH'] = Number(result_json['calDH']);
mapping_hash = mapping_data_from_csv['calDH'];
temp_index = 0;
temp_value = result[calDH];
index = 0;
$.each(mapping_hash,function(k,v){
if( i == 0 ){
var index_val = v.indexOf(temp_value);
if( index_val != -1 ){
temp_index = index_val;
}else{
closest_value = v.get_nearest_value(temp_value);
temp_index = v.indexOf(closest_value)
}
}
result[k] = v[temp_index];
index++;
});
result['fat'] = Number(result_json['fat']);
mapping_hash = mapping_data_from_csv['fat'];
temp_index = 0;
temp_value = result[fat];
index = 0;
$.each(mapping_hash,function(k,v){
if( i == 0 ){
var index_val = v.indexOf(temp_value);
if( index_val != -1 ){
temp_index = index_val;
}else{
closest_value = v.get_nearest_value(temp_value);
temp_index = v.indexOf(closest_value)
}
}
result[k] = v[temp_index];
index++;
});
result['N4'] = (2 - Number(result_json['N4']));
result['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){
if(Number.isNaN(result[k])){
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{
result['lpv'] = (A = 0.1327868* (result["sex_value"]- 0.4858824) + 0.0371720* (result["age_test1"] - 61.56000) -0.07447278* (result["age_test2"] - 13.10152) + 0.4315686* (result["age_test3"] - 0.9844332) + 0.0009163615*( result["calH_test1"] - 182.9347) -0.0007536899*( result["calH_test2"] - 124.8706) -0.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)); 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)
}catch(e){result['lpv'] = "error"}; )
console.log(result['lpv']); }catch(e){console.log(e)};
result['lpv_variable']['A'] = A; result['lpv_variable'] = {};
result['lpv_variable']['lpv'] = lpv;
result['lpv'] = 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((1-(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+'%');
$('.'+obj.active_treatment[i]+'.Overall_Survival').html(servive_ratio); $('.'+obj.active_treatment[i]+'.Overall_Survival').html(Math.round(servive_ratio));
if(i != 0){ if(i != 0){
$('tr.'+obj.active_treatment[i]+' td.Additional_Benefit').html(round(benefit,2)+'%'); $('tr.'+obj.active_treatment[i]+' td.Additional_Benefit').html(round(benefit,2)+'%');
$('.'+obj.active_treatment[i]+'.Additional_Benefit').html(Math.round(benefit)); $('.'+obj.active_treatment[i]+'.Additional_Benefit').html(Math.round(benefit));
@ -730,19 +696,16 @@ function calculate_first_lpv(result_json){
function calculate_servive_ratio(year,obj){ function calculate_servive_ratio(year,obj){
var servive_ratio; var servive_ratio;
var A = obj['A']; var lpv = obj['lpv'];
switch(year) { switch(year) {
case '1': case '1':
servive_ratio = 0.8095037**( Math.exp(A) ); servive_ratio = Math.exp(-0.001476145)**( Math.exp(lpv) );
break; break;
case '1.5': case '3':
servive_ratio = 0.729158**( Math.exp(A) ); servive_ratio = Math.exp(-0.01261639)**( Math.exp(lpv) );
break; break;
case '2': case '5':
servive_ratio = 0.6717211**( Math.exp(A) ); servive_ratio = Math.exp(-0.02519608)**( Math.exp(lpv) );
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

@ -385,8 +385,6 @@ div.texts_show{
margin-top: 1em; margin-top: 1em;
} }
} }
@media print { .print_only{
* { display: none;
-webkit-print-color-adjust: exact !important;
}
} }

View File

@ -60,7 +60,7 @@ div.num_group{
.cencer_table_name{ .cencer_table_name{
display: inline-block; display: inline-block;
vertical-align: middle; vertical-align: middle;
color:#5d7ca2; color:#5d7ca2 !important;
} }
#cancer_table .cencer_table_name{ #cancer_table .cencer_table_name{
width: 16.25em; width: 16.25em;
@ -68,10 +68,18 @@ div.num_group{
#cancer_predict_result_block .cencer_table_name{ #cancer_predict_result_block .cencer_table_name{
width: 5em; width: 5em;
} }
.cancer_help_btn{
background-color: rgb(210, 106, 2) !important;
border-color: rgb(210, 106, 2) !important;
color: white !important;
}
.cancer_help_btn i:before {
color: white !important;
}
.cancer_table_btn{ .cancer_table_btn{
margin-right: 0.5em; margin-right: 0.5em;
color:#5d7ca2; color:#5d7ca2 !important;
border-color: #5d7ca2; border-color: #5d7ca2 !important;
font-weight: 600; font-weight: 600;
} }
.cancer_table_btn::last-of-type{ .cancer_table_btn::last-of-type{
@ -81,6 +89,7 @@ div.num_group{
font-size:0.825em; font-size:0.825em;
color:#5d7ca2; color:#5d7ca2;
} }
@media print{
#cancer_table_top{ #cancer_table_top{
padding-bottom: 4em; padding-bottom: 4em;
} }
@ -120,7 +129,7 @@ input.num_only{
border-left: 0.125em solid rgb(221, 221, 221); border-left: 0.125em solid rgb(221, 221, 221);
text-align: center; text-align: center;
font-size: 0.875em; font-size: 0.875em;
background-color: rgb(255, 255, 255); background-color: rgb(255, 255, 255) !important;
height: 2.25em; height: 2.25em;
position: absolute; position: absolute;
left:0.625em; left:0.625em;
@ -137,8 +146,8 @@ input.float_num{
#cancer_table_submit{ #cancer_table_submit{
margin-left: 1em; margin-left: 1em;
float: right; float: right;
background-color: rgb(210, 105, 0); background-color: rgb(210, 105, 0) !important;
color: white; color: white !important;
border: 0em; border: 0em;
padding: 0.125em 0.5em; padding: 0.125em 0.5em;
border-radius: 0.5em; border-radius: 0.5em;
@ -146,8 +155,8 @@ input.float_num{
} }
#cancer_table_reset{ #cancer_table_reset{
float: right; float: right;
background-color: rgb(210, 105, 0); background-color: rgb(210, 105, 0) !important;
color: white; color: white !important;
border: 0em; border: 0em;
padding: 0.125em 0.5em; padding: 0.125em 0.5em;
border-radius: 0.5em; border-radius: 0.5em;
@ -186,9 +195,9 @@ input.float_num{
border-color: #8c8c8c !important; border-color: #8c8c8c !important;
} }
.cancer_table_btn.active{ .cancer_table_btn.active{
color: #5d7ca2; color: #5d7ca2 !important;
background-color: #9dc3e6; background-color: #9dc3e6 !important;
border-color: #8c8c8c; border-color: #8c8c8c !important;
} }
.cancertable_empty{ .cancertable_empty{
border: 0.25em solid pink !important; border: 0.25em solid pink !important;
@ -196,8 +205,8 @@ input.float_num{
padding: 0.125em !important; padding: 0.125em !important;
} }
.result_title{ .result_title{
background-color: rgb(210, 105, 0); background-color: rgb(210, 105, 0) !important;
color: white; color: white !important;
border: 0em; border: 0em;
padding: 0.125em 0.5em; padding: 0.125em 0.5em;
border-radius: 0.5em; border-radius: 0.5em;
@ -205,8 +214,8 @@ input.float_num{
float: left; float: left;
} }
.result_tab{ .result_tab{
background: #023d79; background: #023d79 !important;
background: linear-gradient(135deg, transparent 0.3em, #023d79 0); background: linear-gradient(135deg, transparent 0.3em, #023d79 0) !important;
border: none; border: none;
float:right; float:right;
padding: 0.5em 0.125em 0.5em 0.5em; padding: 0.5em 0.125em 0.5em 0.5em;
@ -230,30 +239,28 @@ input.float_num{
margin-left: -0.5em; margin-left: -0.5em;
} }
.result_tab.active{ .result_tab.active{
background: #d16801; background: #d16801 !important;
background: linear-gradient(135deg, transparent 0.3em, #d16801 0); background: linear-gradient(135deg, transparent 0.3em, #d16801 0) !important;
padding: 0.8em 0.125em 0.5em 1em; padding: 0.8em 0.125em 0.5em 1em;
margin-left: -0.5em; margin-left: -0.5em;
} }
.result_tab > a{ .result_tab > a{
writing-mode: vertical-lr; writing-mode: vertical-lr !important;
-webkit-writing-mode: vertical-lr; -webkit-writing-mode: vertical-lr !important;
color: white; color: white !important;
} }
.result_tab_group{ .result_tab_group{
width: 15%; display: none;
margin: 0;
float: left;
} }
.result_content_group{ .result_content_group{
width: 85%; width: 100%;
margin: 0; margin: 0;
float: right; float: none;
} }
.result_content{ .result_content{
display: none; display: block;
min-height: 25em; min-height: 25em;
border: 0.125em solid #c0cbdd; border: 0.125em solid #c0cbdd !important;
padding: 0.5em; padding: 0.5em;
} }
.result_content:first-of-type{ .result_content:first-of-type{
@ -315,13 +322,13 @@ input.float_num{
color:white; color:white;
} }
.cancer_th{ .cancer_th{
color: white; color: white !important;
background-color: #003d79; background-color: #003d79 !important;
border-right: 0.375em solid white; border-right: 0.375em solid white;
border-top: 0.375em solid white; border-top: 0.375em solid white;
} }
.cancer_td { .cancer_td {
background-color: #e9eaf5; background-color: #e9eaf5 !important;
border-right: 0.375em solid white; border-right: 0.375em solid white;
border-top: 0.375em solid white; border-top: 0.375em solid white;
} }
@ -362,30 +369,32 @@ div.texts_show{
width: 80%; width: 80%;
} }
#cancer_table_right{ #cancer_table_right{
float:right; float:right;
width:50%; width:50%;
} }
#cancer_table_left{ #cancer_table_left{
float:left; float:left;
width:50%; width:50%;
} }
#cancer_table_right_result{ #cancer_table_right_result{
width: 50%; width: 50%;
float: right; float: right;
} }
#cancer_table_left_result{ #cancer_table_left_result{
width: 50%; width: 50%;
float: left; float: left;
} }
#cancer_predict_result{ #cancer_predict_result{
width: 50%; width: 50%;
float: left; float: left;
} }
.result_title{ .result_title{
margin-top: 1em; margin-top: 1em;
}
* {
-webkit-print-color-adjust: exact !important;
}
.layout-content{
background: #fff !important;
} }
@media print {
* {
-webkit-print-color-adjust: exact !important;
}
} }

View File

@ -27,11 +27,11 @@ class Admin::CancerpredictsController < OrbitAdminController
@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?)
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?
@ -59,41 +59,57 @@ class Admin::CancerpredictsController < OrbitAdminController
end end
next if key.include?("_file") next if key.include?("_file")
if (key != "old_num") if (key != "old_num")
if value != "0" && value != "1" if key != params[:locale]
if key != params[:locale] @form_to_show.form_show[num.to_s] = {} if @form_to_show.form_show[num.to_s].nil?
@form_to_show.form_show[num.to_s] = {} if @form_to_show.form_show[num.to_s].nil? type = Cancerpredictfields::FIELDINFO[key.to_s]
type = Cancerpredictfields::FIELDINFO[key.to_s].constantize rescue String if type && Cancerpredictfields::Field_relations[type]
if @form_to_show.form_show[num.to_s][key.to_s].class != Array && type != Array type = Cancerpredictfields::Field_relations[type]
@form_to_show.form_show[num.to_s][key.to_s] = value end
type = type.constantize rescue String
if @form_to_show.form_show[num.to_s][key.to_s].class != Array && type != Array
if type == Fixnum
@form_to_show.form_show[num.to_s][key.to_s] = value.to_i rescue 0
elsif type == Float
@form_to_show.form_show[num.to_s][key.to_s] = value.to_f rescue 0.0
else else
if value.length > 2 @form_to_show.form_show[num.to_s][key.to_s] = value
@form_to_show.form_show[num.to_s][key.to_s] = YAML.load(value)
else
@form_to_show.form_show[num.to_s][key.to_s] = []
end
end end
else else
value.each do |sub_property,sub_value| if value.length > 2
type = Cancerpredictfields::FIELDINFO[sub_property.to_s].constantize rescue String @form_to_show.form_show[num.to_s][key.to_s] = YAML.load(value)
@form_to_show.form_show[ num.to_s ][ sub_property ] = {} if @form_to_show.form_show[num.to_s][ sub_property ].nil? else
if @form_to_show.form_show[ num.to_s ][ sub_property ][params[:locale].to_s].class != Array && type != Array @form_to_show.form_show[num.to_s][key.to_s] = []
@form_to_show.form_show[ num.to_s ][ sub_property ][params[:locale].to_s] = sub_value
else
if sub_value.length > 2
@form_to_show.form_show[ num.to_s ][ sub_property ][params[:locale].to_s] = YAML.load(sub_value)
else
@form_to_show.form_show[ num.to_s ][ sub_property ][params[:locale].to_s] = []
end
end
if(property["old_num"].present? && property["old_num"] != num.to_s)
other_in_use_locales.each do |locale|
@form_to_show.form_show[ num.to_s ][ sub_property ][locale] = @form_to_show.form_show_was[ property["old_num"] ][ sub_property ][locale]
end
end
end end
end end
else else
@form_to_show.form_show[num.to_s][key.to_s] = value.to_i value.each do |sub_property,sub_value|
type = Cancerpredictfields::FIELDINFO[sub_property.to_s]
if type && Cancerpredictfields::Field_relations[type]
type = Cancerpredictfields::Field_relations[type]
end
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?
if @form_to_show.form_show[ num.to_s ][ sub_property ][params[:locale].to_s].class != Array && type != Array
if type == Fixnum
@form_to_show.form_show[ num.to_s ][ sub_property ][params[:locale].to_s] = sub_value.to_i rescue 0
elsif type == Float
@form_to_show.form_show[ num.to_s ][ sub_property ][params[:locale].to_s] = sub_value.to_f rescue 0.0
else
@form_to_show.form_show[ num.to_s ][ sub_property ][params[:locale].to_s] = sub_value
end
else
if sub_value.length > 2
@form_to_show.form_show[ num.to_s ][ sub_property ][params[:locale].to_s] = YAML.load(sub_value)
else
@form_to_show.form_show[ num.to_s ][ sub_property ][params[:locale].to_s] = []
end
end
if(property["old_num"] != nil && property["old_num"] != num.to_s)
other_in_use_locales.each do |locale|
@form_to_show.form_show[ num.to_s ][ sub_property ][locale] = @form_to_show.form_show_was[ property["old_num"] ][ sub_property ][locale]
end
end
end
end end
end end
end end
@ -128,42 +144,62 @@ class Admin::CancerpredictsController < OrbitAdminController
if value[:_destroy] == "1" if value[:_destroy] == "1"
mapping_file = CancerPredictMappingFile.find(value[:id]) mapping_file = CancerPredictMappingFile.find(value[:id])
mapping_file.destroy mapping_file.destroy
@form_to_show.form_show[num.to_s][key.to_s] = "" @form_to_show.form_show_in_result[num.to_s][key.to_s] = ""
end end
end end
next if key.include?("_file") next if key.include?("_file")
if (key != "old_num") if (key != "old_num")
if value != "0" && value != "1" if key != params[:locale]
if key != params[:locale] @form_to_show.form_show_in_result[num.to_s] = {} if @form_to_show.form_show_in_result[num.to_s].nil?
if @form_to_show.form_show_in_result[num.to_s][key.to_s].class != Array type = Cancerpredictfields::FIELDINFO[key.to_s]
@form_to_show.form_show_in_result[num.to_s][key.to_s] = value if type && Cancerpredictfields::Field_relations[type]
type = Cancerpredictfields::Field_relations[type]
end
type = type.constantize rescue String
if @form_to_show.form_show_in_result[num.to_s][key.to_s].class != Array && type != Array
if type == Fixnum
@form_to_show.form_show_in_result[num.to_s][key.to_s] = value.to_i rescue 0
elsif type == Float
@form_to_show.form_show_in_result[num.to_s][key.to_s] = value.to_f rescue 0.0
else else
if value.length > 2 @form_to_show.form_show_in_result[num.to_s][key.to_s] = value
@form_to_show.form_show_in_result[num.to_s][key.to_s] = YAML.load(value)
else
@form_to_show.form_show_in_result[num.to_s][key.to_s] = []
end
end end
else else
value.each do |sub_property,sub_value| if value.length > 2
if @form_to_show.form_show_in_result[ num.to_s ][ sub_property ][params[:locale].to_s].class != Array @form_to_show.form_show_in_result[num.to_s][key.to_s] = YAML.load(value)
@form_to_show.form_show_in_result[ num.to_s ][ sub_property ][params[:locale].to_s] = sub_value else
else @form_to_show.form_show_in_result[num.to_s][key.to_s] = []
if sub_value.length > 2
@form_to_show.form_show_in_result[ num.to_s ][ sub_property ][params[:locale].to_s] = YAML.load(sub_value)
else
@form_to_show.form_show_in_result[ num.to_s ][ sub_property ][params[:locale].to_s] = []
end
end
if(property["old_num"] != nil && property["old_num"] != num.to_s)
other_in_use_locales.each do |locale|
@form_to_show.form_show_in_result[ num.to_s ][ sub_property ][locale] = @form_to_show.form_show_in_result_was[ property["old_num"] ][ sub_property ][locale]
end
end
end end
end end
else else
@form_to_show.form_show_in_result[num.to_s][key.to_s] = value.to_i value.each do |sub_property,sub_value|
type = Cancerpredictfields::FIELDINFO[sub_property.to_s]
if type && Cancerpredictfields::Field_relations[type]
type = Cancerpredictfields::Field_relations[type]
end
type = type.constantize rescue String
@form_to_show.form_show_in_result[ num.to_s ][ sub_property ] = {} if @form_to_show.form_show[num.to_s][ sub_property ].nil?
if @form_to_show.form_show_in_result[ num.to_s ][ sub_property ][params[:locale].to_s].class != Array && type != Array
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
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
else
@form_to_show.form_show_in_result[ num.to_s ][ sub_property ][params[:locale].to_s] = sub_value
end
else
if sub_value.length > 2
@form_to_show.form_show_in_result[ num.to_s ][ sub_property ][params[:locale].to_s] = YAML.load(sub_value)
else
@form_to_show.form_show_in_result[ num.to_s ][ sub_property ][params[:locale].to_s] = []
end
end
if(property["old_num"] != nil && property["old_num"] != num.to_s)
other_in_use_locales.each do |locale|
@form_to_show.form_show_in_result[ num.to_s ][ sub_property ][locale] = @form_to_show.form_show_was[ property["old_num"] ][ sub_property ][locale]
end
end
end
end end
end end
end end
@ -175,7 +211,7 @@ class Admin::CancerpredictsController < OrbitAdminController
end end
end end
end end
@create_items = ['title_texts','form_result_is_right','text_descibe','years','table_above_texts','text_above_texts','surgery_only_texts','extra_texts','extra_therapy_texts','danger_texts','texts_between_Result_and_result_block','prediction_formula'] @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']
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)
@ -269,7 +305,7 @@ class Admin::CancerpredictsController < OrbitAdminController
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.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|
@ -342,14 +378,14 @@ class Admin::CancerpredictsController < OrbitAdminController
@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"] != "" 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)
@site_locales.each do |locale| @site_locales.each do |locale|
next if property["comment_text"][locale.to_s] == "" next if property["comment_text"][locale.to_s].blank?
@field_property["comment_text"] = property["comment_text"][locale.to_s] @field_property["comment_text"] = property["comment_text"][locale.to_s]
break break
end end
@ -370,7 +406,6 @@ class Admin::CancerpredictsController < OrbitAdminController
@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"] != []
@ -402,14 +437,14 @@ class Admin::CancerpredictsController < OrbitAdminController
@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"] != "" 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)
@site_locales.each do |locale| @site_locales.each do |locale|
next if property["comment_text"][locale.to_s] == "" next if property["comment_text"][locale.to_s].blank?
@field_property["comment_text"] = property["comment_text"][locale.to_s] @field_property["comment_text"] = property["comment_text"][locale.to_s]
break break
end end
@ -493,18 +528,18 @@ class Admin::CancerpredictsController < OrbitAdminController
@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"] != "" 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)
@site_locales.each do |locale| @site_locales.each do |locale|
next if property["comment_text"][locale.to_s] == "" next if property["comment_text"][locale.to_s].blank?
@field_property["comment_text"] = property["comment_text"][locale.to_s] @field_property["comment_text"] = property["comment_text"][locale.to_s]
break break
end end
if @field_property["comment_text"] != "" 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
@ -587,7 +622,7 @@ class Admin::CancerpredictsController < OrbitAdminController
@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).asc(: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
@ -662,21 +697,21 @@ class Admin::CancerpredictsController < OrbitAdminController
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
end end
end end
return infos return infos
else else
return {} return {}
end end
end end
end end

View File

@ -8,7 +8,6 @@ class CancerpredictsController < ApplicationController
end end
def calculate def calculate
create_first_field create_first_field
#begin
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'
@ -41,7 +40,7 @@ class CancerpredictsController < ApplicationController
@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[: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]}
@ -53,14 +52,10 @@ class CancerpredictsController < ApplicationController
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 = {}
# result['sex_value'] = params['data']['sex'].to_i - 1
# result['Age_value'] = params['data']['age'].to_i
# if params['data']['calcification_score'].to_i < 1400
# result['cal_value'] = 0
# else
# result['cal_value'] = 1
# end
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|
result[v] = 0
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?
@ -71,17 +66,21 @@ class CancerpredictsController < ApplicationController
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 property[:map_values].class == Array && property[:choice_fields].class == Array && property[:map_values].length == property[:choice_fields].length if !(@form_to_show.advance_mode)
result[@variable] = property[:map_values][params['data'][@variable].to_i - 1] result[@variable] = params['data'][@variable].to_i rescue 0
else else
if property[:revert_value].to_i != 1 if property[:need_map_values] == 1
result[@variable] = params['data'][@variable].to_i - 1 result[@variable] = property[:map_values][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) if property[:revert_value] != 1
result[@variable] = params['data'][@variable].to_i - 1
else
result[@variable] = ((property[:choice_fields].length - params['data'][@variable].to_i) rescue params['data'][@variable].to_i)
end
end end
end end
end end
if property[:cancer_predict_mapping_file].present? if @form_to_show.advance_mode && property[:cancer_predict_mapping_file].present?
if (mapping_data_from_csv != {}) if (mapping_data_from_csv != {})
mapping_hash = mapping_data_from_csv[@variable] mapping_hash = mapping_data_from_csv[@variable]
temp_index = 0 temp_index = 0
@ -102,43 +101,32 @@ class CancerpredictsController < ApplicationController
end end
end end
end end
#result['lpv'] = -0.51427548* (result['sex_value']- 0.508312) + 0.05764604* (result['Age_value'] - 61.894501) + 0.49138819*(result['cal_value'] - 0.334399) rescue 'error'
formula_variables = @form_to_show.tmp_lpv_variables formula_variables = @form_to_show.tmp_lpv_variables
begin
eval_hidden_variables(result)
rescue => e
@form_to_show.generate_eval_formula
eval_hidden_variables(result)
end
begin begin
eval_formula(result) eval_formula(result)
rescue => e rescue => e
@form_to_show.generate_eval_formula @form_to_show.generate_eval_formula
eval_formula(result) eval_formula(result)
end end
result['lpv'] = instance_variable_get(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[1..-1]}"] = instance_variable_get(variable_name) result['lpv_variable']["#{variable_name}"] = result[variable_name]
end end
@years = @form_to_show.years @years = @form_to_show.years
result['table'] = '<input id="current_year" type="hidden" value="'+@years[0].to_s+'" index="0"/><p id="cancer_table_texts">'+@form_to_show.table_above_texts[locale].to_s+'</p>'
result['table'] += ('<a style="display: inline-block;">'+(locale == 'zh_tw' ? '第' : '')+'</a><a style="display: inline-block;">')
result['years'] = @years result['years'] = @years
@years.each{|year| result['table'] += ('<button class="cancer_years cancer_table_btn btn btn-default btn-sm">'+year.to_s+'</button>')}
result['table'] += ('</a><a style="display: inline-block;">'+(locale == 'zh_tw' ? '年' : '')+'</a>')
#@head_name = ['Treatment','Additional_Benefit','Overall_Survival']
@head_name = ['Treatment','Overall_Survival']
@table_head = @head_name.map{|name| I18n.t('cancerpredict.table.'+name)}
@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 = ['Surgery_only'] @therapy_names = @form_to_show.treatment_method
@form_to_show.form_show_in_result.values.each{|choice| @therapy_names.push choice["variable"]} result['treatment_method'] = @therapy_names
result['treatmeny_method'] = @therapy_names result['treatment_method_active_indices'] = @form_to_show.treatment_method_active_indices
result['table'] += '<table><thead><tr>' result['table'] = @form_to_show.result_table_translations[locale]
@table_head.each_with_index{|head,index| result['table'] += ('<th class="cancer_th '+@head_name[index]+'">' + head + '</th>')}
result['table'] += '</tr></thead><tbody>'
@therapy_choices.each_with_index do |choice,i|
result['table'] += '<tr class="'+@therapy_names[i].to_s+'">'
@table_head.each_with_index do |head,index|
result['table'] += ('<td class="cancer_td '+ @head_name[index]+'">' + ((index == 0) ? (((i==0)? '' : '+') + choice) : '-') + '</td>')
end
result['table'] += '</tr>'
end
year = params['data']['year'] rescue nil year = params['data']['year'] rescue nil
if year.nil? if year.nil?
year = @years.first.to_f year = @years.first.to_f
@ -148,35 +136,12 @@ class CancerpredictsController < ApplicationController
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 = ((1 - @servive_ratio) * 100).round(2) @servive_ratio = ((1 - @servive_ratio) * 100).round(2)
@texts = @form_to_show.text_above_texts[locale].to_s.gsub('<br/>','</span><br/><span>').gsub('{{Surgery_only}}','<span class="'+@therapy_names[0]+' Overall_Survival">'+@servive_ratio.round(2).to_s+'</span>') result['texts'] = @form_to_show.result_text_translations[locale]
@texts = @texts.split('{{years}}')
@texts.delete('')
result['texts'] = '<span>'+@texts[0]
@years.each{|year| result['texts'] += ('<button class="cancer_years cancer_table_btn btn btn-default btn-sm" style="float:none;">'+year.to_s+'</button>')}
if @texts.count > 1
result['texts'] += (@texts[1]+'</span>') if @texts.count > 1
else
result['texts'] += '</span>'
end
if !@form_to_show.surgery_only_texts[locale].blank?
@surgery_only_texts = @form_to_show.surgery_only_texts[locale]
@surgery_only_texts.insert(0,'<p class="show"><span>')
@surgery_only_texts = @surgery_only_texts.gsub('{{Surgery_only}}','<span class="'+@therapy_names[0]+' Overall_Survival">'+@servive_ratio.round.to_s+'</span><span>')
@surgery_only_texts = @surgery_only_texts.gsub('{{surgery_year}}','</span><span class="surgery_year">'+@years[-1].to_s+'</span><span>')
@surgery_only_texts += '</span>'
else
@surgery_only_texts = ''
end
result['texts'] += @surgery_only_texts
result['texts'] += '<span class="addition">'+@form_to_show.extra_texts[locale]+'</span><div class="extra-text" style="display:none;"><div class="texts_show" style="clear:both;"></div></div></p>'
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
# rescue
# render :json=> params
#end
end end
def index def index
uid = OrbitHelper.params[:uid] rescue "" uid = OrbitHelper.params[:uid] rescue ""

View File

@ -1,41 +1,62 @@
class Cancerpredictfields class Cancerpredictfields
require 'pathname' require "pathname"
require 'json' require 'json'
include Mongoid::Document include Mongoid::Document
include Mongoid::Timestamps include Mongoid::Timestamps
include OrbitModel::Status Field_relations = {"number_field"=>"Fixnum","text_area"=>"String"}
include OrbitModel::Impression FIELDINFO = {"variable"=>"String","name"=>"String","is_num"=>"Fixnum","hint"=>"String","comment_text"=>"String","choice_fields"=>"Array","range"=>"Array","right"=>"Fixnum","is_float"=>"Fixnum","revert_value"=>"Fixnum","map_values"=>"Array","cancer_predict_mapping_file"=>"String","lpv_impact"=>"Float","active_choice"=>"number_field","disable_condition"=>"text_area"}
# encoding: utf-8 NonLoclaized = ["variable","is_num","range","right","is_float","revert_value","map_values","cancer_predict_mapping_file","lpv_impact","active_choice","disable_condition"]
include OrbitTag::Taggable AdvanceFields = ["revert_value","map_values","cancer_predict_mapping_file"]
include OrbitCategory::Categorizable TherapyFields = ["variable","name","hint","comment_text","choice_fields","lpv_impact","active_choice","disable_condition"]
FIELDINFO = {"variable"=>"String","name"=>"String","is_num"=>"Fixnum","hint"=>"String","comment_text"=>"String","choice_fields"=>"Array","range"=>"Array","right"=>"Fixnum","is_float"=>"Fixnum","revert_value"=>"Fixnum","map_values"=>"Array","cancer_predict_mapping_file"=>"String"} TherapyOnly = ["lpv_impact","active_choice","disable_condition"]
NonLoclaized = ["variable","is_num","range","right","is_float","revert_value","map_values","cancer_predict_mapping_file"]
field :title ,type:String ,default:"" field :title ,type:String ,default:""
field :form_show , :type=> Hash ,default:{0=>{:variable=>"sex",: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=>0,:map_values=>[],:cancer_predict_mapping_file=>""}, field :advance_mode, type: Boolean, default: true
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=>""}, field :form_show , :type=> Hash ,default:{
2=>{:variable=>"calcification_score",:name=>{"zh_tw"=>"鈣化指數<br/>(Calcification score)","en"=>"Calcification score"},:is_num=>1,:hint=>{'zh_tw'=>'請輸入0到5000的數字','en'=>'Please enter a number between 0 and 5000'}, :comment_text=>{'zh_tw'=>'','en'=>''}, :choice_fields=> {"zh_tw"=>[],"en"=>[]},:range=>[0,5000],:right=>0,:is_float=>1,:revert_value=>0,:map_values=>[],:cancer_predict_mapping_file=>""} "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"=>"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},
field :form_show_in_result , :type=> Hash ,default:{}#{0=>{:variable=>"hormone_therapy",:name=>{"zh_tw"=>"賀爾蒙治療","en"=>"Hormone/Steroid therapy"},:is_num=>0, :hint=>{'zh_tw'=>'適用賀爾蒙受體陽性病人','en'=>'Hormone/ steroid therapy is available when ER status is positive'} , :comment_text=>{'zh_tw'=>'','en'=>''}, :choice_fields=> {"zh_tw"=>['否','是'],"en"=>['No','Yes']},:range=>[]}, "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},
#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=>[]}, "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},
#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=>[]}, "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},
#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=>[]} "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"=>"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"=>"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"=>"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"=>"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"=>"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"=>"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},
"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},
"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},
"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},
"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},
"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:{"zh_tw"=>"歡迎使用台灣心血管疾病預後預測系統<br />本預測系統由全民健保資料庫2017年~2020年間共1964位病人電腦斷層影像所建立之預測模型<br />請在下方填入相關資訊","en"=>"Welcome to the Taiwan Breast Cancer Prediction System!<br/>The 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/>To start, please select the information below."} field :text_descibe ,type:Hash ,default: {
"zh_tw"=>"歡迎使用台灣心血管 疾病預後預測系統<br />\r\n本預測系統由全民健保資料庫2017年~2020年間共1700位病人電腦斷層影像所建立之預測模型<br />\r\n請 在下方填入相關資訊",
"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: [] field :head_images_id ,type:Array , default: []
field :title_images_id ,type:Array , default: [] field :title_images_id ,type:Array , default: []
field :title_texts ,type:Hash ,default:{'zh_tw'=>'臺灣心血管疾病存活預測','en'=>'Cardiovascular Disease Survival Forecast in Taiwan'} field :title_texts ,type:Hash ,default: {"zh_tw"=>"臺灣心血管疾病存活預測", "en"=>"Cardiovascular Disease Survival Forecast in Taiwan"}
field :table_above_texts ,type:Hash ,default:{'zh_tw'=>"下表之分析為針對手術後病人,根據選定的術後治療,分別估計在半年、一年及一年半的再住院或死亡機率。",'en'=>'The analysis is for women who had undergone surgery.The table shows the 0.5-, 1- and 1.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'=>"此研究分析來自於照射胸部電腦斷層所得之結果,根據您所輸入的資訊,在第{{years}}年內有2.69%的機率可能再住院或死亡{{Surgery_only}}%。",'en'=>'此研究分析來自於照射胸部電腦斷層所得之結果,根據您所輸入的資訊,在第{{years}}年內有2.69%的機率可能再住院或死亡{{Surgery_only}}%。'} 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'=>'','en'=>''} 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,1.5,2,2.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: "A = 0.1327868* (sex_value- 0.4858824) field :prediction_formula , type: String ,default: "A = 0.1327868* (sex_value- 0.4858824)
@ -49,59 +70,64 @@ class Cancerpredictfields
+ 0.0001401325*( calAH_test1 - 700.7824) + 0.0001401325*( calAH_test1 - 700.7824)
-0.001349783*( calAH_test2 - 634.2167) +0.001753832*( calAH_test3 -419.3361) -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.0001906046*( calDH_test1 -835.2894) -0.000251567*( calDH_test2 - 213.1630)
-0.002173942*( fat_test1 -108.4149)+0.003066541*( fat_test2 - 28.33497) -0.002173942*( fat_test1 -108.4149)+0.003066541*( fat_test2 - 28.33497)
+0.6700708*(N4-0.3241176) +0.6700708*(N4-0.3241176)
+0.3336162*(O3-0.4994118) +0.3336162*(O3-0.4994118)
+0.1322476*(O20-0.1741176) +0.1322476*(O20-0.1741176)
+0.9084972*(O18-0.008823529) +0.9084972*(O18-0.008823529)
+0.2978388*(N12-0.1152941) +0.2978388*(N12-0.1152941)
+0.1777935*(N20-0.3582353) +0.1777935*(N20-0.3582353)
+1.588042*(N31-0.002352941) +1.588042*(N31-0.002352941)
+0.2197419*(O6-0.07823529) +0.2197419*(O6-0.07823529)
+1.791159*(N34-0.001176471) +1.791159*(N34-0.001176471)
+0.4305973*(N14-0.02176471) +0.4305973*(N14-0.02176471)
-0.4472885*(N29-0.02411765) -0.4472885*(N29-0.02411765)
+0.2601319*(N26-0.04941176) +0.2601319*(N26-0.04941176)
-0.2364269*(O11-0.1164706) -0.2364269*(O11-0.1164706)
+0.1784179*(N6-0.1070588) +0.1784179*(N6-0.1070588)
+0.6023170*(O14-0.01294118)
+0.6023170*(O14-0.01294118) -1.031959*(N43-0.007058824)
-1.031959*(N43-0.007058824) +0.4257809*(O17-0.01823529)
+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) )"]
+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: ""
field :fix_hidden_variables, type: Array, default: []
field :tmp_hidden_variables_for_ruby, type: String, default: ""
field :tmp_hidden_variables_for_js, type: String, default: ""
field :lpv_calc, type: Hash, default: {} #for js code field :lpv_calc, type: Hash, default: {} #for js code
field :tmp_lpv_ruby_code, type: String, default: "" field :tmp_lpv_ruby_code, type: String, default: ""
field :tmp_lpv_variables, type: Array, default: [] field :tmp_lpv_variables, type: Array, default: []
field :mapping_data_from_csv , type: String ,default: "" field :mapping_data_from_csv , type: String ,default: ""
scope :can_display, ->{where(:is_hidden=>false,:is_preview => false).any_of({:postdate.lt=>Time.now, :deadline.gt=>Time.now},{:postdate.lt=>Time.now, :deadline=>nil}).order_by([:is_top, :desc],[:postdate, :desc])} field :all_variables, type: Array, default: []
scope :is_approved, ->{where(:approved => true)} field :treatment_method, type: Array, default: ['Surgery_only']
field :treatment_method_active_indices, type: Array, default: [1]
field :result_table, type: String, default: "", localize: true
field :result_text, type: String, default: "", localize: true
field :therapy_lpv, type: Array, default: [0]
#before_create :set_expire #before_create :set_expire
before_save do before_save do
self.form_show.each do |num,property| self.form_show.each do |num,property|
@ -114,104 +140,174 @@ class Cancerpredictfields
result_keys << variable_name result_keys << variable_name
end end
end end
self.form_show_in_result.each do |num,property|
variable_name = property[:variable]
if variable_name.present?
result_keys << variable_name
end
end
mapping_data = JSON.parse(self.mapping_data_from_csv) rescue {} mapping_data = JSON.parse(self.mapping_data_from_csv) rescue {}
if mapping_data.present? if self.advance_mode && mapping_data.present?
mapping_data.each do |k,v| mapping_data.each do |k,v|
result_keys += (v.keys rescue []) result_keys += (v.keys rescue [])
end end
end end
formula = self.prediction_formula.gsub("\r\n"," ").gsub("^","**") result_keys = result_keys.uniq
self.all_variables = result_keys
formula = text_to_math(self.prediction_formula)
tmp_hidden_variables = text_to_math(self.hidden_variables)
result_keys.each do |k| result_keys.each do |k|
formula = formula.gsub(/#{k}?(-|\+|\*|\/|\s|\=)/){ "result[\"#{k}\"]#{$1}" } formula = formula.gsub(/(\A|[^\w])#{k}($|[^\w])/){|f| "#{$1}result[\"#{k.strip}\"]#{$2}" }
tmp_hidden_variables = tmp_hidden_variables.gsub(/(\A|[^\w])#{k}($|[^\w])/){|f| "#{$1}result[\"#{k.strip}\"]#{$2}" }
end end
formula = formula.split(/^([^=]+)=([^=])/).select{|s| s.present?}.each_slice(2).map do |a,b| self.tmp_hidden_variables_for_js = tmp_hidden_variables.rstrip.gsub(/\n\s+/,"\n ").gsub("\n",";\n") + ";"
self.fix_hidden_variables = []
self.tmp_hidden_variables_for_ruby = tmp_hidden_variables.split(/^([^=!]+)=([^=!])/).select{|s| s.present?}.each_slice(2).map do |a,b|
a = a.strip
self.fix_hidden_variables << a
if b if b
("@"+ a + "=" + b) ("result[\"#{a}\"]=" + b.gsub("\n",""))
else else
"@"+ a a
end end
end.join("\n") end.join("\n")
self.fix_hidden_variables = self.fix_hidden_variables.uniq
formula = formula.split(/^([^=!]+)=([^=!])/).select{|s| s.present?}.each_slice(2).map do |a,b|
a = a.strip
if b
("result[\"#{a}\"]=" + b.gsub("\n",""))
else
a
end
end.join("\n")
self.fix_hidden_variables.each do |v|
formula = formula.gsub(/(\A|[^\w\"])#{v}($|[^\w])/){|f| "#{$1}result[\"#{v.strip}\"]#{$2}"}
self.tmp_hidden_variables_for_ruby = self.tmp_hidden_variables_for_ruby.gsub(/(\A|[^\w\"])#{v}($|[^\w])/){|f| "#{$1}result[\"#{v.strip}\"]#{$2}"}
end
self.tmp_lpv_ruby_code = formula self.tmp_lpv_ruby_code = formula
formula_variables = formula.enum_for(:scan,/([^\=\(\)]+)?=[^=]/).map {|x| x[-1] }.compact.map{|s| s.strip} formula_variables = formula.enum_for(:scan,/([^\=\(\)]+)?=[^=]/).map {|x| x[-1] }.compact.map{|s| s.strip[8..-3]}
self.tmp_lpv_variables = formula_variables self.tmp_lpv_variables = formula_variables
self.tmp_years_settings = self.years_settings.map do |s| self.tmp_years_settings = self.years_settings.map do |s|
s.gsub('^','**').gsub('exp','Math.exp') text_to_math(s)
end end
self.tmp_years_settings_for_ruby = self.tmp_years_settings.clone self.tmp_years_settings_for_ruby = self.tmp_years_settings.clone
formula_variables.each do |variable_name| formula_variables.each do |variable_name|
self.tmp_years_settings_for_ruby = self.tmp_years_settings_for_ruby.map do |y| self.tmp_years_settings_for_ruby = self.tmp_years_settings_for_ruby.map do |y|
y.gsub(variable_name[1..-1],variable_name) y.gsub(variable_name,"result[\"#{variable_name}\"]")
end
end
self.treatment_method = ['Surgery_only']
self.form_show_in_result.values.each do |choice|
variable = choice["variable"]
if variable.present?
self.treatment_method << variable
end
end
tmp_table_translations = {}
tmp_text_translations = {}
@years = self.years
# @head_name = ['Treatment','Additional_Benefit','Overall_Survival']
@head_name = ['Treatment','Overall_Survival']
@table_head = @head_name.map{|name| I18n.t('cancerpredict.table.'+name)}
@therapy_names = self.treatment_method
I18n.available_locales.each do |locale|
I18n.with_locale(locale) do
@therapy_choices = [I18n.t('cancerpredict.table.Surgeryonly')]
self.form_show_in_result.values.each{|choice| @therapy_choices.push choice["name"][locale]}
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[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;">')
@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 += '<table><thead><tr>'
@table_head.each_with_index{|head,index| tmp_table += ('<th class="cancer_th '+@head_name[index]+'">' + head + '</th>')}
tmp_table += '</tr></thead><tbody>'
@therapy_choices.each_with_index do |choice,i|
tmp_table += '<tr class="'+@therapy_names[i].to_s+'">'
@table_head.each_with_index do |head,index|
tmp_table += ('<td class="cancer_td '+ @head_name[index]+'">' + ((index == 0) ? (((i==0)? '' : '+') + choice) : '-') + '</td>')
end
tmp_table += '</tr>'
end
tmp_table_translations[locale] = tmp_table
@texts = self.text_above_texts[locale].to_s.gsub('<br/>','</span><br/><span>').gsub('{{Surgery_only}}','<span class="'+@therapy_names[0]+' Overall_Survival"></span>')
@texts = @texts.split('{{years}}')
@texts.delete('')
tmp_text = "<span class=\"result_title print_only\">#{I18n.t("cancerpredict.table.text")}</span><div style=\"clear: both\"></div>"
tmp_text += ('<span>'+@texts[0])
@years.each{|year| tmp_text += ('<button class="cancer_years cancer_table_btn btn btn-default btn-sm" style="float:none;">'+year.to_s+'</button>')}
if @texts.count > 1
tmp_text += (@texts[1]+'</span>') if @texts.count > 1
else
tmp_text += '</span>'
end
if !self.surgery_only_texts[locale].blank?
@surgery_only_texts = self.surgery_only_texts[locale]
@surgery_only_texts.insert(0,'<p class="show"><span>')
@surgery_only_texts = @surgery_only_texts.gsub('{{Surgery_only}}','<span class="'+@therapy_names[0]+' Overall_Survival"></span><span>')
@surgery_only_texts = @surgery_only_texts.gsub('{{surgery_year}}','</span><span class="surgery_year">'+@years[-1].to_s+'</span><span>')
@surgery_only_texts += '</span>'
else
@surgery_only_texts = ''
end
tmp_text += @surgery_only_texts
tmp_text += '<span class="addition">'+self.extra_texts[locale]+'</span><div class="extra-text" style="display:none;"><div class="texts_show" style="clear:both;"></div></div></p>'
tmp_text_translations[locale] = tmp_text
end
end
self.result_table_translations = tmp_table_translations
self.result_text_translations = tmp_text_translations
self.treatment_method_active_indices = [1]
self.form_show_in_result.each do |num, property|
v = property[:active_choice]
if v.present?
self.treatment_method_active_indices << (v - 1)
else
self.treatment_method_active_indices << 1
end end
end end
self.lpv_calc = get_years_settings_dict self.lpv_calc = get_years_settings_dict
self.generate_eval_formula self.generate_eval_formula
end end
def generate_eval_formula def generate_eval_formula
eval_hidden_variables = "def eval_hidden_variables(result); #{self.tmp_hidden_variables_for_ruby}; end"
CancerpredictsController.module_eval(eval_hidden_variables)
eval_formula = "def eval_formula(result); #{self.tmp_lpv_ruby_code}; end" eval_formula = "def eval_formula(result); #{self.tmp_lpv_ruby_code}; end"
CancerpredictsController.module_eval(eval_formula) CancerpredictsController.module_eval(eval_formula)
end end
def update_user
User.find(update_user_id) rescue nil
end
def update_user=(user)
self.update_user_id = user.id
end
def email_members
MemberProfile.find(self.email_member_ids) rescue []
end
def email_addresses
addresses = self.email_members.collect{|member| member.email} rescue []
addresses = addresses +[self.other_mailaddress] if !self.other_mailaddress.blank?
addresses.flatten
end
def email
mail = Email.find(self.email_id) rescue nil
end
def expired?
(self.deadline < Time.now) rescue false
end
def destroy_email
mail = Email.find(self.email_id) rescue nil
mail.destroy if !mail.nil?
end
def self.remove_expired_status
self.where(:is_top => true, :top_end_date.ne => nil, :top_end_date.lt => Time.now).each do |b|
b.is_top = false
b.top_end_date = nil
b.save
end
end
def generate_jscode def generate_jscode
js_code = "var map_values , mapping_hash , temp_index ,temp_value , index , closest_value;\r\n" js_code = "var map_values , mapping_hash , temp_index ,temp_value , index , closest_value;\r\n"
mapping_data_from_csv = YAML.load(self.mapping_data_from_csv) rescue {} mapping_data_from_csv = JSON.parse(self.mapping_data_from_csv) rescue {}
variable_keys = [] tmp_hash = self.form_show.values + self.form_show_in_result.values
self.form_show.each do |num,property| tmp_hash.each do |property|
@variable = property[:variable] @variable = property[:variable]
if @variable.present? if @variable.present?
if property[:is_num] == 1 if property[:is_num] == 1
js_code += "\t\t\t\tresult['#{@variable}'] = Number(result_json['#{@variable}']);\r\n" js_code += " result['#{@variable}'] = Number(result_json['#{@variable}']);\r\n"
elsif property[:choice_fields].present? elsif property[:choice_fields].present?
if property[:need_map_values] == 1 if !(self.advance_mode)
js_code += "\t\t\t\tmap_values = #{property[:map_values]};\r\n" js_code += " result['#{@variable}'] = Number(result_json['#{@variable}']);\r\n"
js_code += "\t\t\t\tresult['#{@variable}'] = map_values[Number(result_json['#{@variable}'']) - 1];\r\n"
else else
if property[:revert_value] != 1 if property[:need_map_values] == 1
js_code += "\t\t\t\tresult['#{@variable}'] = Number(result_json['#{@variable}']) - 1;\r\n" js_code += " map_values = #{property[:map_values]};\r\n"
js_code += " result['#{@variable}'] = map_values[Number(result_json['#{@variable}'']) - 1];\r\n"
else else
js_code += "\t\t\t\tresult['#{@variable}'] = (#{property[:choice_fields].length} - Number(result_json['#{@variable}']));\r\n" if property[:revert_value] != 1
js_code += " result['#{@variable}'] = Number(result_json['#{@variable}']) - 1;\r\n"
else
js_code += " result['#{@variable}'] = (#{property[:choice_fields].length} - Number(result_json['#{@variable}']));\r\n"
end
end end
end end
end end
variable_keys.push(@variable) if self.advance_mode && property[:cancer_predict_mapping_file].present?
if property[:cancer_predict_mapping_file].present?
if (mapping_data_from_csv != {} && !mapping_data_from_csv[@variable].blank?) if (mapping_data_from_csv != {} && !mapping_data_from_csv[@variable].blank?)
variable_keys.concat(mapping_data_from_csv[@variable].keys) js_code += " mapping_hash = mapping_data_from_csv['#{@variable}'];\r\n"
js_code += "\t\t\t\tmapping_hash = mapping_data_from_csv['#{@variable}'];\r\n" js_code += " temp_index = 0;\r\n"
js_code += "\t\t\t\ttemp_index = 0;\r\n" js_code += " temp_value = result['#{@variable}'];\r\n"
js_code += "\t\t\t\ttemp_value = result[#{@variable}];\r\n" js_code += " index = 0;
js_code += "\t\t\t\tindex = 0;
$.each(mapping_hash,function(k,v){ $.each(mapping_hash,function(k,v){
if( i == 0 ){ if( index == 0 ){
var index_val = v.indexOf(temp_value); var index_val = v.indexOf(temp_value);
if( index_val != -1 ){ if( index_val != -1 ){
temp_index = index_val; temp_index = index_val;
@ -227,29 +323,37 @@ class Cancerpredictfields
end end
end end
end end
formula = self.prediction_formula.gsub("\r\n"," ").gsub("^","**") js_code += "\n Object.keys(result).forEach(function(k){
variable_keys.each do |k| if(Number.isNaN(result[k])){
formula = formula.gsub(/#{k}?(-|\+|\*|\s|\=)/){ "result[\"#{k}\"]#{$1}" } result[k] = 0;
}
})"
js_code += "\n #{self.tmp_hidden_variables_for_js}"
formula = text_to_math(self.prediction_formula)
self.all_variables.each do |k|
formula = formula.gsub(/#{k}?(-|\+|\*|\s|\=)/){ "result[\"#{k.strip}\"]#{$1}" }
end end
formula_variables = formula.enum_for(:scan,/([^\=]*)?=/).map { ::Regexp.last_match[1] }.map{|s| s.strip.split(/(\s*|;\r\n)/).last} formula_variables = self.tmp_lpv_variables.map{|v| v}
js_code = "function calculate_first_lpv(result_json){ js_code = "\n function calculate_first_lpv(result_json){
result = {}; result = {};
#{js_code} #{js_code}
try{ try{
result['lpv'] = (#{formula.gsub(/\s{2,10}/," ")}); #{formula.gsub(/\s{2,10}/," ").gsub("\n","\n ")}
}catch(e){result['lpv'] = \"error\"}; }catch(e){console.log(e)};
console.log(result['lpv']); result['lpv_variable'] = {};
#{formula_variables.map{|v| "result['lpv_variable']['#{v}'] = #{v};"}.join("\r\n\t\t\t\t") } #{formula_variables.map{|v| "result['lpv_variable']['#{v}'] = #{v};"}.join("\n ") }
result['lpv'] = #{formula_variables.count == 0 ? 0 : formula_variables.last};
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((1-(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+'%');
$('.'+obj.active_treatment[i]+'.Overall_Survival').html(servive_ratio); $('.'+obj.active_treatment[i]+'.Overall_Survival').html(Math.round(servive_ratio));
if(i != 0){ if(i != 0){
$('tr.'+obj.active_treatment[i]+' td.Additional_Benefit').html(round(benefit,2)+'%'); $('tr.'+obj.active_treatment[i]+' td.Additional_Benefit').html(round(benefit,2)+'%');
$('.'+obj.active_treatment[i]+'.Additional_Benefit').html(Math.round(benefit)); $('.'+obj.active_treatment[i]+'.Additional_Benefit').html(Math.round(benefit));
@ -266,7 +370,7 @@ class Cancerpredictfields
switch_texts += switch_texts +=
" "
case '#{year}': case '#{year}':
servive_ratio = #{self.tmp_years_settings[year_index]}; servive_ratio = #{text_to_math(self.years_settings[year_index])};
break;" break;"
end end
switch_texts += " switch_texts += "
@ -282,22 +386,79 @@ class Cancerpredictfields
" "
return js_code return js_code
end end
def text_to_math(text)
text.gsub("\r\n","\n").gsub('^','**').gsub('exp','Math.exp').gsub('log','Math.log')
end
def replace_str_with_idx(org_str,st, ed, replace_str)
org_str.slice!(st, ed - st + 1)
org_str.insert(st, replace_str)
org_str
end
def auto_write_predict_js def auto_write_predict_js
js_codes = generate_jscode js_codes = generate_jscode
module_app_path = Pathname.new(File.expand_path(__dir__)).dirname.dirname.to_s module_app_path = Pathname.new(File.expand_path(__dir__)).dirname.dirname.to_s
save_path = module_app_path + '/app/assets/javascripts/cancer_predict.js' 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
str1 = "/* auto add start */" str1 = "/* auto add start */"
index1 = file_texts.index(str1) index1 = file_texts.index(str1)
str2 = "/* auto add end */" str2 = "/* auto add end */"
index2 = file_texts.index(str2) index2 = file_texts.index(str2)
if (!index1.nil? && !index2.nil?)
file_texts = replace_str_with_idx(file_texts, index1 + str1.length, index2 - 1, js_codes)
need_write = true
end
str3 = "/*lpv_calc_formula_start*/" str3 = "/*lpv_calc_formula_start*/"
index3 = file_texts.index(str3) index3 = file_texts.index(str3)
str4 = "/*lpv_calc_formula_end*/" str4 = "/*lpv_calc_formula_end*/"
index4 = file_texts.index(str4) index4 = file_texts.index(str4)
file_texts = file_texts.sub(file_texts[(index1+str1.length+2) .. (index2 - 1)] , js_codes) if (!index3.nil? && !index4.nil?)
file_texts = file_texts.sub(file_texts[(index3+str3.length) .. (index4 - 1)] , self.lpv_calc.to_json.gsub("@",".")) file_texts = replace_str_with_idx(file_texts, index3 + str3.length, index4 - 1, self.lpv_calc.to_json.gsub("@",".") + ';')
if (!index1.nil? && !index2.nil?) || (!index3.nil? && !index4.nil?) need_write = true
end
tmp_disable_jscodes = ""
str5 = "/*disable_condition start*/"
index5 = file_texts.index(str5)
str6 = "/*disable_condition end*/"
index6 = file_texts.index(str6)
self.form_show_in_result.each do |num,property|
if property[:disable_condition].present?
tmp = property[:disable_condition].clone
self.all_variables.each do |k|
tmp = tmp.gsub(/(\A|[^\w])#{k}($|[^\w])/){|f| "#{$1}post_json[\"#{k}\"]#{$2}" }
end
variable = property[:variable]
tmp_disable_jscodes += "\n if(#{tmp}){
$('##{variable} .cancer_table_btn').attr('disabled','disabled');
$('[for=\"#{variable}\"]').css('color','rgb(204, 204, 204)');
}else{
$('##{variable} .cancer_table_btn').removeAttr('disabled');
$('[for=\"#{variable}\"]').css('color','');
}"
end
end
if (!index5.nil? && !index6.nil?)
tmp_disable_jscodes += "\n\t\t\t"
file_texts = replace_str_with_idx(file_texts, index5 + str5.length, index6 - 1, tmp_disable_jscodes)
need_write = true
end
str7 = "/*therapy_lpv start*/"
index7 = file_texts.index(str7)
str8 = "/*therapy_lpv end*/"
index8 = file_texts.index(str8)
self.therapy_lpv = [0]
self.form_show_in_result.each do |num,property|
if property[:lpv_impact].present?
self.therapy_lpv << property[:lpv_impact]
else
self.therapy_lpv << 0
end
end
if (!index7.nil? && !index8.nil?)
file_texts = replace_str_with_idx(file_texts, index7 + str7.length, index8 - 1, self.therapy_lpv.to_s + ';')
need_write = true
end
if need_write
File.write(save_path,file_texts) File.write(save_path,file_texts)
end end
end end

View File

@ -17,10 +17,11 @@ wb.add_worksheet(name: "school_class") do |sheet|
temp_row << result.created_at.to_s temp_row << result.created_at.to_s
result.result.each do |key,value| result.result.each do |key,value|
if key != "locale" if key != "locale"
if result.values[key][I18n.locale.to_s].length == 0 if (result.values[key][I18n.locale.to_s].length == 0 rescue true)
temp_row << value temp_row << value
else else
temp_row << (result.values[key][I18n.locale.to_s][value.to_i-1] rescue value) v = result.values[key][I18n.locale.to_s][value.to_i-1] rescue nil
temp_row << (v.nil? ? value : v)
end end
end end
end end

View File

@ -2,38 +2,36 @@
<td class="remove_div">❌</td> <td class="remove_div">❌</td>
<td class="sort_div"></td> <td class="sort_div"></td>
<% keys.each do |key| %> <% keys.each do |key| %>
<td class="<%=key%>">
<% if key.include? "_file" %> <% if key.include? "_file" %>
<td> <%= render :partial => 'form_file', :object => (CancerPredictMappingFile.where(:id=> property[key]).first rescue nil), :locals => {:f => make_fields, :key=>key} %>
<%= render :partial => 'form_file', :object => (CancerPredictMappingFile.where(:id=> property[key]).first rescue nil), :locals => {:f => make_fields, :key=>key} %>
</td>
<% else %> <% else %>
<% value = property[key] %> <% value = property[key] %>
<% if property == {} %> <% value_type = Cancerpredictfields::FIELDINFO[key] %>
<% value_type = Cancerpredictfields::FIELDINFO[key].constantize rescue String %> <% value = "[]" if property == {} && value_type == 'Array' %>
<% value = "[]" if value_type == Array %> <% is_localized = Cancerpredictfields::NonLoclaized.exclude?(key) %>
<% else %>
<% value_type = value.class %>
<% end %>
<% @value= value %> <% @value= value %>
<% if value_type == BSON::Document || value_type == Hash %> <% if is_localized %>
<% @disp_value = @value[I18n.locale.to_s] rescue "" %> <% @disp_value = @value[I18n.locale.to_s] rescue "" %>
<%else%> <%else%>
<% @disp_value = @value %> <% @disp_value = @value %>
<%end%> <%end%>
<% if value_type == Fixnum %> <% field_type = ((value_type == 'String' || value_type == 'Array' || value_type == 'Float') ? "text_field" : value_type) %>
<% if value_type == 'Fixnum' %>
<% if @value == 1%> <% if @value == 1%>
<td><%= make_fields.check_box key,{:checked=>true,:class=>"checkbox",:style=>"float:left;"}%></td> <%= make_fields.check_box key,{:checked=>true,:class=>"checkbox",:style=>"float:left;"}%>
<% else%> <% else%>
<td><%= make_fields.check_box key,{:checked=>false,:class=>"checkbox",:style=>"float:left;"}%></td> <%= make_fields.check_box key,{:checked=>false,:class=>"checkbox",:style=>"float:left;"}%>
<%end%> <%end%>
<% elsif Cancerpredictfields::NonLoclaized.exclude?(key) %> <% elsif is_localized %>
<%=make_fields.fields_for I18n.locale.to_s do |locale_fields|%> <%=make_fields.fields_for I18n.locale.to_s do |locale_fields|%>
<td><%= locale_fields.text_field key,{:value=>@disp_value}%></td> <%= locale_fields.send(field_type, key,{:value=>@disp_value}) %>
<%end%> <%end%>
<% else %> <% else %>
<td><%= make_fields.text_field key,{:value=>@disp_value}%></td> <%= make_fields.send(field_type, key,{:value=>@disp_value})%>
<%end%> <%end%>
<%end%> <%end%>
</td>
<%end%> <%end%>
<td><%= make_fields.hidden_field :old_num,:value=>num.to_s %></td> <td><%= make_fields.hidden_field :old_num,:value=>num.to_s %></td>
</tr> </tr>

View File

@ -1,4 +1,5 @@
<%= stylesheet_link_tag "lib/fileupload"%> <%= stylesheet_link_tag "lib/fileupload"%>
<%= stylesheet_link_tag "lib/togglebox"%>
<% content_for :page_specific_javascript do %> <% content_for :page_specific_javascript do %>
<%= javascript_include_tag "lib/bootstrap-fileupload" %> <%= javascript_include_tag "lib/bootstrap-fileupload" %>
<%#= javascript_include_tag "lib/bootstrap-datetimepicker" %> <%#= javascript_include_tag "lib/bootstrap-datetimepicker" %>
@ -26,7 +27,53 @@
.remove_div:hover{ .remove_div:hover{
font-size: 1.3em; font-size: 1.3em;
} }
<% Cancerpredictfields::AdvanceFields.each do |field| %>
table .<%=field%>{
display: none;
}
table.advance_mode .<%=field%>{
display: block;
}
<% end%>
.solid_line_hr{
margin: 0.3em;
border-top: 0.2em dashed;
}
.sort_table input, .sort_table textarea{
font-family: sans-serif;
}
.advance_mode_help_btn{
float:left;
cursor: pointer;
padding: 0em 0.475em;
font-size: 1.25em;
border-radius: 1.5em;
background-color: rgb(210, 106, 2);
border-color: rgb(210, 106, 2);
color: white;
width: 1.8em;
height: 1.8em;
line-height: 1em;
}
</style> </style>
<div id="show_advance_mode_modal" class="modal fade">
<div class='modal-dialog'>
<div class='modal-content'>
<div class='modal-header'>
<button type='button' aria-hidden='true' class='close'>×</button>
<h4 class='modal-title'>
<%= t("cancerpredict.module_mode") %>
</h4>
</div>
<div class="modal-body">
<%= t("cancerpredict.advance_mode_hint2").html_safe %>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default">Close</button>
</div>
</div>
</div>
</div>
<div style="clear:both;"></div> <div style="clear:both;"></div>
<%=form_for @form_to_show ,:url=>{:controller=>"cancerpredicts" ,:action=>"edit"} do |form|%> <%=form_for @form_to_show ,:url=>{:controller=>"cancerpredicts" ,:action=>"edit"} do |form|%>
<span class="show_span"><%= t('cancerpredict.title') %></span> <span class="show_span"><%= t('cancerpredict.title') %></span>
@ -181,17 +228,28 @@
<%end%> <%end%>
<%end%> <%end%>
<%end%> <%end%>
<span class="show_span"><%= t('cancerpredict.module_mode') %></span>
<div style="clear:both;"></div>
<div class="control-group">
<label class="control-label" for="advance_mode" style="float: left; line-height: 30px;margin-right: 1em;">
<span style="float: left;"><%= t('cancerpredict.advance_mode') %></span>
<button type="button" class="advance_mode_help_btn" data-target="#show_advance_mode_modal"><i aria-hidden="true" class="fa fa-question"></i></button>
</label>
<div class="controls">
<input id="advance_mode" name="<%=form.object_name%>[advance_mode]" type="checkbox" class="toggle-check" data-disabled="<%=form.object.advance_mode == false%>">
</div>
</div>
<div style="clear:both;"></div>
<span class="show_span"><%= t('cancerpredict.Input_fields') %></span> <span class="show_span"><%= t('cancerpredict.Input_fields') %></span>
<div style="clear:both;"></div> <div style="clear:both;"></div>
<table id="fields_table" class="sort_table"> <table id="fields_table" class="sort_table <%=@form_to_show.advance_mode ? 'advance_mode' : '' %>">
<% keys = @form_to_show.form_show.values[0].keys rescue [] %> <% keys = Cancerpredictfields::FIELDINFO.keys - Cancerpredictfields::TherapyOnly %>
<% keys = Cancerpredictfields::FIELDINFO.keys if keys.blank? %>
<thead> <thead>
<tr> <tr>
<th></th> <th></th>
<th></th> <th></th>
<% keys.each do |key|%> <% keys.each do |key|%>
<th><%=t("cancerpredict.table.#{key}")%></th> <th class="<%=key%>"><%=t("cancerpredict.table.#{key}")%></th>
<%end%> <%end%>
</tr> </tr>
</thead> </thead>
@ -228,15 +286,14 @@
<% end %> <% end %>
<div style="clear:both;"></div> <div style="clear:both;"></div>
<% end %> <% end %>
<table id="therapies_table" class="sort_table"> <table id="therapies_table" class="sort_table <%=@form_to_show.advance_mode ? 'advance_mode' : '' %>">
<thead> <thead>
<tr> <tr>
<th></th> <th></th>
<th></th> <th></th>
<% keys = @form_to_show.form_show_in_result.values[0].keys rescue [] %> <% keys = Cancerpredictfields::TherapyFields %>
<% keys = Cancerpredictfields::FIELDINFO.keys if keys.blank? %>
<% keys.each do |key,vlaue|%> <% keys.each do |key,vlaue|%>
<th><%=t("cancerpredict.table.#{key}")%></th> <th class="<%=key%>"><%=t("cancerpredict.table.#{key}")%></th>
<%end%> <%end%>
</tr> </tr>
</thead> </thead>
@ -244,38 +301,7 @@
<%= form.fields_for :form_show_in_result do |formfield|%> <%= form.fields_for :form_show_in_result do |formfield|%>
<% @form_to_show.form_show_in_result.each do |num,property| %> <% @form_to_show.form_show_in_result.each do |num,property| %>
<%=formfield.fields_for num.to_s do |make_fields|%> <%=formfield.fields_for num.to_s do |make_fields|%>
<tr> <%= render :partial => 'form', :locals=>{:make_fields=>make_fields,:property=>property,:num=>num,:keys => Cancerpredictfields::TherapyFields} %>
<td class="remove_div">❌</td>
<td class="sort_div"></td>
<% property.each do |key,value|%>
<% if key.include? "_file" %>
<td>
<%= render :partial => 'form_file', :object => (CancerPredictMappingFile.where(:id=> property[key]).first rescue nil), :locals => {:f => make_fields, :key=>key} %>
</td>
<% else %>
<% @value= value %>
<% if @value.class == BSON::Document || @value.class == Hash %>
<% @disp_value = @value[I18n.locale.to_s] rescue "" %>
<%else%>
<% @disp_value = @value %>
<%end%>
<% if Cancerpredictfields::FIELDINFO[key] == "Fixnum" %>
<% if @value == 1%>
<td><%= make_fields.check_box key,{:checked=>true,:class=>"checkbox",:style=>"float:left;"}%></td>
<% else%>
<td><%= make_fields.check_box key,{:checked=>false,:class=>"checkbox",:style=>"float:left;"}%></td>
<%end%>
<% elsif Cancerpredictfields::NonLoclaized.exclude?(key) %>
<%=make_fields.fields_for I18n.locale.to_s do |locale_fields|%>
<td><%= locale_fields.text_field key,{:value=>@disp_value}%></td>
<%end%>
<% else %>
<td><%= make_fields.text_field key,{:value=>@disp_value}%></td>
<%end%>
<%end%>
<%end%>
<td><%= make_fields.hidden_field :old_num,:value=>num.to_s %></td>
</tr>
<%end%> <%end%>
<%end%> <%end%>
<%end%> <%end%>
@ -285,23 +311,32 @@
<div style="clear:both;"></div> <div style="clear:both;"></div>
<span class="show_span"><%=t('cancerpredict.table.calculate_settings')%></span> <span class="show_span"><%=t('cancerpredict.table.calculate_settings')%></span>
<div style="clear:both;"></div> <div style="clear:both;"></div>
<div class="control-group">
<div class="control-label" style="float: left;margin-right: 1em;width: 11em;">
<label><%= t('cancerpredict.hidden_variables') %></label>
</div>
<div class="controls">
<%= form.text_area :hidden_variables, :rows=>"5", :style=> 'width: 100%;font-family: sans-serif;' %>
</div>
</div>
<div style="clear:both;"></div>
<div class="control-group"> <div class="control-group">
<div class="control-label" style="float: left;margin-right: 1em;width: 11em;"> <div class="control-label" style="float: left;margin-right: 1em;width: 11em;">
<label><%= t('cancerpredict.table.prediction_formula') %></label> <label><%= t('cancerpredict.table.prediction_formula') %></label>
</div> </div>
<div class="controls"> <div class="controls">
<%= form.text_area :prediction_formula, :rows=>"5", :style=> 'width: calc(100% - 12em);' %> <%= form.text_area :prediction_formula, :rows=>"5", :style=> 'width: 100%;font-family: sans-serif;' %>
</div> </div>
</div> </div>
<div id="years_settings"> <div id="years_settings">
<% years = @form_to_show.years %> <% years = @form_to_show.years %>
<% years.each_with_index do |year,i| %> <% years.each_with_index do |year,i| %>
<div data-year="<%= year.to_s.strip %>"> <div data-year="<%= year.to_s.strip %>">
<div class="control-label" style="float: left;margin-right: 1em;width: 11em;"> <div class="control-label" style="float: left;margin-right: 1em;width: 13em;">
<label>P(t=<%=year%>) <%=year%> Year</label> <label style="font-family: sans-serif;"><%=t("cancerpredict.Overall_Survival")%>(t=<%=year%> Year)</label>
</div> </div>
<div class="controls"> <div class="controls">
<textarea name="<%= form.object_name %>[years_settings][]" style= "width: calc(100% - 12em);" value="<%= @form_to_show.years_settings[i] rescue '' %>"><%= @form_to_show.years_settings[i] rescue '' %></textarea> <textarea name="<%= form.object_name %>[years_settings][]" style= "width: calc(100% - 16em);" value="<%= @form_to_show.years_settings[i] rescue '' %>"><%= @form_to_show.years_settings[i] rescue '' %></textarea>
</div> </div>
</div> </div>
<% end %> <% end %>
@ -310,6 +345,19 @@
<%end%> <%end%>
<link href="/assets/admin/cancerpredict.css" media="screen" rel="stylesheet"> <link href="/assets/admin/cancerpredict.css" media="screen" rel="stylesheet">
<script> <script>
$(".advance_mode_help_btn").click(function(){
$("#show_advance_mode_modal").modal();
})
$("#show_advance_mode_modal button").click(function(){
$("#show_advance_mode_modal").modal("hide");
})
$("#advance_mode").click(function(){
if(window.confirm("<%=t('cancerpredict.advance_mode_hint1').gsub("\n","\\n")%>")){
$("#fields_table,#therapies_table").toggleClass("advance_mode");
}else{
return false;
}
})
$('.text_choice').click(function(){ $('.text_choice').click(function(){
$('.text_choice').prop('checked' , false); $('.text_choice').prop('checked' , false);
$(this).prop('checked' , true); $(this).prop('checked' , true);
@ -319,8 +367,7 @@
<%= fields_for :cancerpredictfields do |form|%> <%= fields_for :cancerpredictfields do |form|%>
<%= form.fields_for :form_show do |formfield|%> <%= form.fields_for :form_show do |formfield|%>
<%=formfield.fields_for :new_index do |make_fields|%> <%=formfield.fields_for :new_index do |make_fields|%>
<% keys = @form_to_show.form_show.values[0].keys rescue [] %> <% keys = Cancerpredictfields::FIELDINFO.keys - Cancerpredictfields::TherapyOnly %>
<% keys = Cancerpredictfields::FIELDINFO.keys if keys.blank? %>
var html = "<%= "#{render :partial => 'form', :locals=>{:make_fields=>make_fields,:property=>{},:num=>'',:keys => keys}}".gsub(/(\r\n|\n)/,"").gsub("\"","\\\"").html_safe %>"; var html = "<%= "#{render :partial => 'form', :locals=>{:make_fields=>make_fields,:property=>{},:num=>'',:keys => keys}}".gsub(/(\r\n|\n)/,"").gsub("\"","\\\"").html_safe %>";
$("#fields_table tbody").append(html.replaceAll('new_index',index)); $("#fields_table tbody").append(html.replaceAll('new_index',index));
<% end %> <% end %>
@ -337,8 +384,7 @@
<%= fields_for :cancerpredictfields do |form|%> <%= fields_for :cancerpredictfields do |form|%>
<%= form.fields_for :form_show_in_result do |formfield|%> <%= form.fields_for :form_show_in_result do |formfield|%>
<%=formfield.fields_for :new_index do |make_fields|%> <%=formfield.fields_for :new_index do |make_fields|%>
<% keys = @form_to_show.form_show_in_result.values[0].keys rescue [] %> <% keys = Cancerpredictfields::TherapyFields %>
<% keys = Cancerpredictfields::FIELDINFO.keys if keys.blank? %>
var html = "<%= "#{render :partial => 'form', :locals=>{:make_fields=>make_fields,:property=>{},:num=>'',:keys => keys}}".gsub(/(\r\n|\n)/,"").gsub("\"","\\\"").html_safe %>"; var html = "<%= "#{render :partial => 'form', :locals=>{:make_fields=>make_fields,:property=>{},:num=>'',:keys => keys}}".gsub(/(\r\n|\n)/,"").gsub("\"","\\\"").html_safe %>";
$("#therapies_table tbody").append(html.replaceAll('new_index',index)); $("#therapies_table tbody").append(html.replaceAll('new_index',index));
<% end %> <% end %>
@ -401,11 +447,11 @@
years.forEach(function(year){ years.forEach(function(year){
if($("#years_settings [data-year='"+year+"']").length == 0){ if($("#years_settings [data-year='"+year+"']").length == 0){
var year_text = ('<div data-year="'+year+'">'+ var year_text = ('<div data-year="'+year+'">'+
'<div class="control-label" style="float: left;margin-right: 1em;width: 11em;">'+ '<div class="control-label" style="float: left;margin-right: 1em;width: 13em;">'+
'<label> P(t='+year+') '+year+' Year</label>'+ '<label style="font-family: sans-serif;"><%=t("cancerpredict.Overall_Survival")%>(t='+year+' Year)</label>'+
'</div>'+ '</div>'+
'<div class="controls">'+ '<div class="controls">'+
'<textarea name="cancerpredictfields[years_settings][]" style= "width: calc(100% - 12em);"></textarea>'+ '<textarea name="cancerpredictfields[years_settings][]" style= "width: calc(100% - 16em);"></textarea>'+
'</div>'+ '</div>'+
'</div>'); '</div>');
if(index != 0){ if(index != 0){

View File

@ -36,7 +36,7 @@
<% if result.values[key][I18n.locale.to_s].length == 0 %> <% if result.values[key][I18n.locale.to_s].length == 0 %>
<td><%= value.to_s %></td> <td><%= value.to_s %></td>
<% else %> <% else %>
<td><%= result.values[key][I18n.locale.to_s][value.to_i-1] rescue value %></td> <td><% v = result.values[key][I18n.locale.to_s][value.to_i-1] rescue nil %><%= v.nil? ? value : v %></td>
<% end %> <% end %>
<% end %> <% end %>
<%end%> <%end%>

View File

@ -1,37 +1,40 @@
# -*- encoding: utf-8 -*- # -*- encoding: utf-8 -*-
# stub: cancerpredict 0.0.1 ruby lib # stub: cancerpredict 0.0.1 ruby lib
insert_flag = 0 bundle_update_flag = ARGV[0]=='update' || ARGV[0]=='install'
app_path = File.expand_path(__dir__) if bundle_update_flag
template_path = ENV['PWD'] + '/app/templates' insert_flag = 0
all_template = Dir.glob(template_path+'/*/') app_path = File.expand_path(__dir__)
puts 'copying module' template_path = ENV['PWD'] + '/app/templates'
check_texts = '<%= javascript_include_tag "//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.2/js/bootstrap.min.js"%>' all_template = Dir.glob(template_path+'/*/')
edit_texts = '<%= javascript_include_tag "//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"%>' puts 'copying module'
all_template.each do |folder| check_texts = '<%= javascript_include_tag "//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.2/js/bootstrap.min.js"%>'
if !folder.include?('mobile') edit_texts = '<%= javascript_include_tag "//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"%>'
begin all_template.each do |folder|
if folder.split('/')[-1] != 'mobile' if !folder.include?('mobile')
begin begin
system ('cp -r '+ app_path + '/modules/. ' + folder+'/modules/.') if folder.split('/')[-1] != 'mobile'
puts "finish copy module cancerpredict to #{folder}" begin
rescue system ('cp -r '+ app_path + '/modules/. ' + folder+'/modules/.')
puts 'error copy' puts "finish copy module cancerpredict to #{folder}"
rescue
puts 'error copy'
end
end end
texts = File.read(folder+'partial/_head.html.erb')
insert_flag = 0
if texts.include?(check_texts)
texts = texts.gsub(check_texts,edit_texts)
insert_flag = 1
end
if insert_flag == 1
puts 'editing _head.html.erb'
f = File.open(folder+'partial/_head.html.erb','w')
f.write(texts)
f.close
end
rescue
puts "not found _head.html.erb in #{folder}"
end end
texts = File.read(folder+'partial/_head.html.erb')
insert_flag = 0
if texts.include?(check_texts)
texts = texts.gsub(check_texts,edit_texts)
insert_flag = 1
end
if insert_flag == 1
puts 'editing _head.html.erb'
f = File.open(folder+'partial/_head.html.erb','w')
f.write(texts)
f.close
end
rescue
puts "not found _head.html.erb in #{folder}"
end end
end end
end end

View File

@ -2,6 +2,12 @@ en:
module_name: module_name:
cancerpredict: Cardiovascular Disease Survival Forecast in Taiwan Tool cancerpredict: Cardiovascular Disease Survival Forecast in Taiwan Tool
cancerpredict: cancerpredict:
hidden_variables: "Hidden Variables"
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列)的值,其餘生成的變數值則為對應之後的同一橫列的值。"
module_mode: Module Mode
advance_mode: Advance Mode
Overall_Survival: Probability
cancerpredict: Adjust Cardiovascular Disease Survival Forecast in Taiwan 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?
@ -58,4 +64,6 @@ en:
curve: Curves curve: Curves
text: Texts text: Texts
Therapy_choice: Treatment options Therapy_choice: Treatment options
lpv_impact: "lpv Impact(Input: Float)"
active_choice: "Active choice(input 1 present choice 1 is regarded as therapy enable)"
disable_condition: "Disable Condition"

View File

@ -2,6 +2,12 @@ zh_tw:
module_name: module_name:
cancerpredict: 臺灣心血管疾病存活預測工具 cancerpredict: 臺灣心血管疾病存活預測工具
cancerpredict: cancerpredict:
hidden_variables: "隱藏的變數"
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列)的值,其餘生成的變數值則為對應之後的同一橫列的值。"
module_mode: 模組模式
advance_mode: 進階模式
Overall_Survival: Probability
cancerpredict: 臺灣心血管疾病存活預測工具調整 cancerpredict: 臺灣心血管疾病存活預測工具調整
submitResult: 查看用戶繳交表單結果 submitResult: 查看用戶繳交表單結果
result_is_right: 治療選項在結果的右邊? result_is_right: 治療選項在結果的右邊?
@ -49,7 +55,7 @@ zh_tw:
Treatment: Event(事件) Treatment: Event(事件)
Additional_Benefit: 額外治療效益 Additional_Benefit: 額外治療效益
Overall_Survival: Probability(機率)(%) Overall_Survival: Probability(機率)(%)
Surgeryonly: 心血管疾病住院或死亡 Surgeryonly: 純手術
Hormonetherapy: 賀爾蒙治療 Hormonetherapy: 賀爾蒙治療
Chemotherapy: 化學治療 Chemotherapy: 化學治療
years: years:
@ -68,10 +74,12 @@ zh_tw:
right: 顯示在右側 right: 顯示在右側
is_float: 可輸入小數 is_float: 可輸入小數
revert_value: 選項值從大到小(ex:有兩個選項則選項值依序為1和0) revert_value: 選項值從大到小(ex:有兩個選項則選項值依序為1和0)
map_values: 選項對應到的值(若無,則使用初始值) map_values: 選項對應到的值(若無,則使用初始值)
cancer_predict_mapping_file: 欄位對應檔案 cancer_predict_mapping_file: 欄位對應檔案
calculate_settings: 計算設定 calculate_settings: 計算設定
prediction_formula: 預測公式 prediction_formula: 預測公式
add_field: 新增填寫欄位 add_field: 新增填寫欄位
add_therapy: 新增治療選項 add_therapy: 新增治療選項
lpv_impact: "lpv 影響(輸入浮點數)"
active_choice: "啟用治療選項(輸入1代表第1個選項視為啟用治療)"
disable_condition: "禁用條件"

View File

@ -2,6 +2,7 @@ Rails.application.routes.draw do
Thread.new do Thread.new do
c = Cancerpredictfields.last c = Cancerpredictfields.last
if c if c
sleep(5)
c.save c.save
c.auto_write_predict_js c.auto_write_predict_js
end end

View File

@ -3,5 +3,5 @@
<script type="text/javascript" src="/assets/cancer_predict.js"></script> <script type="text/javascript" src="/assets/cancer_predict.js"></script>
{{table}} {{table}}
<link href="/assets/cancer_predict.scss" media="screen" rel="stylesheet"> <link href="/assets/cancer_predict.scss" media="screen" rel="stylesheet">
<link href="/assets/bootstrap.min.print.css" media="print" rel="stylesheet"> <%= stylesheet_link_tag "bootstrap.min.print", media: "print" %>
<link href="/assets/cancer_predict_print.scss" media="print" rel="stylesheet"> <%= stylesheet_link_tag "cancer_predict_print", media: "print" %>

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"
} }