﻿/* 
 
	check_lungs.js
 	
 	lungs check 
	javascript
	
	2008/03/12
	2010/05/13 update by tanaka-printing



*/

/* sex_check */
function sex_check(id) {
	var form = document.getElementById(id);
	var sextype  =  form.sex_type[0].checked;
	form.check.value = sextype;
	return sextype;
}

/* round */
function roundlunx(value) {
	return Math.round(value * 100) / 100;
}

function roundage(value) {

/*	return Math.round(value); 
2010/05/13 update by tanaka-printing
*/
	return Math.round(Math.round(value * 100) / 100) ;
}

/* average */
function viewlcAvg_n(id, sextype) {
	var form = document.getElementById(id);
	form.fev_normal.value = roundlunx(get_fev_normal(form.height.value, form.age.value, sextype));
}
function get_fev_normal(height, age, sexflag) {
	if (sexflag) {
		return 0.036 * height - 0.028 * age - 1.178;
	} else {
		return 0.022 * height - 0.022 * age - 0.005;
	}
}

/* lungs */
function viewLungs(id, sextype) {
	var form = document.getElementById(id);
	form.lungs_age.value = lcLungs(form, sextype);
	form.comment_1.value = lcCom1(form, sextype);
	form.comment_2.value = lcCom2(form, sextype);
}

function lcLungs(form, sextype) {
	if(sextype){
		return lcLungs_male(form);
	} else {
		return lcLungs_female(form);
	}
}

function lcCom1(form, sextype) {
	return sextype ? lcCom1_male(form) : lcCom1_female(form);
}

function lcCom2(form, sextype) {
	return sextype ? lcCom2_male(form) : lcCom2_female(form);
}



/* male */
function lcLungs_male(form) {
	var height = form.height.value;
	var age = form.age.value;
	var fev = form.fev.value;
	var fvc = form.fvc.value;
	
	if ( fev/fvc>=0.7 && (0.036*height-1.178-fev)/0.028>=95 ) {
		return "95歳以上";
	} else if ( (fev/fvc>=0.7 && (0.036*height-1.178-fev)/0.028>=18) && (0.036*height-1.178-fev)/0.028<95 ) {
		return roundage( (0.036*height-1.178-fev)/0.028 );
	} else if ( fev/fvc>=0.7 && (0.036*height-1.178-fev)/0.028<18 ) {
		return "18歳未満";
	} else if ( fev/fvc<0.7 && fev/(0.036*height-0.028*age-1.178)>=1 ) {
		return age;
	} else if ( fev/fvc<0.7 && fev/(0.036*height-0.028*age-1.178)<1 && (0.036*height-1.178-fev)/0.028>95 ) {
		return "95歳以上";
	} else if ( fev/fvc<0.7 && fev/(0.036*height-0.028*age-1.178)<1 && (0.036*height-1.178-fev)/0.028<95 ) {
		return roundage( (0.036*height-1.178-fev)/0.028 );
	}

	return " ";
}


/* female */
function lcLungs_female(form) {
	var height = form.height.value;
	var age = form.age.value;
	var fev = form.fev.value;
	var fvc = form.fvc.value;
	
	if ( fev/fvc>=0.7 && (0.022*height-0.005-fev)/0.022>=95 ) {
		return "95歳以上";
	} else if ( fev/fvc>=0.7 && (0.022*height-0.005-fev)/0.022>=18 && (0.022*height-0.005-fev)/0.022<95 ) {
		return roundage( (0.022*height-0.005-fev)/0.022 );
	} else if (fev/fvc>=0.7 && (0.022*height-0.005-fev)/0.022<18) {
		return "18歳未満";
	} else if ( fev/fvc<0.7 && fev/(0.022*height-0.022*age-0.005)>=1 ) {
		return age;
	} else if ( fev/fvc<0.7 && fev/(0.022*height-0.022*age-0.005)<1 && (0.022*height-0.005-fev)/0.022>95 ) {
		return "95歳以上";
	} else if ( fev/fvc<0.7 && fev/(0.022*height-0.022*age-0.005)<1 && (0.022*height-0.005-fev)/0.022<95 ) {
		return roundage( (0.022*height-0.005-fev)/0.022 );
	}

	return " ";
}


function com_list(num){
			if(num == "A1"){
					return "A：異常なし";
	} else if (num == "A2"){
					return "B:境界領域（現時点では異常なし)";
	} else if (num == "A3"){
					return "C:肺疾患の疑い〈要精検〉";
	} else if (num == "A4"){
					return "D:COPDの疑い〈要経過観察/生活改善〉";
	} else if (num == "A5"){
					return "E：COPDの疑い〈要医療/精検〉";

	} else if (num == "B1"){
					return "肺疾患の可能性は低いです。同性同年代の平均値に比べて数値が良く、今後も定期的な呼吸機能検査を続けて健康を維持してください。";
	} else if (num == "B2"){
					return "同性同世代の平均値に比べ数値がやや悪く、今後も定期的な呼吸機能検査を続ける必要があります。";
	} else if (num == "B3"){
					return "COPDの可能性は低いですが、同性同世代の平均値に比べて数値が悪く、他の肺疾患の疑いがあります。専門医による再検査が必要です。";
	} else if (num == "B4"){
					return "軽症COPDの疑い。現段階で自覚症状が無くても放置すると重症化する恐れがあります。専門医による再検査が必要です。";
	} else if (num == "B5"){
					return "中等症以上のCOPDの疑い。専門医による再検査が必須です。適切な治療を早期に行う事で症状を改善し、疾患の進行を抑制することができます。";
	} else {
		return false;
	}
}


/* male */
function lcCom1_male(form) {
	var height 	= form.height.value;
	var age 	= form.age.value;
	var fev 	= form.fev.value;
	var fvc 	= form.fvc.value;
	
	if ( fev/fvc>=0.7 && fev/(0.036*height-0.028*age-1.178)>=1 ) {
		return com_list("A1");
	} else if ( fev/fvc>=0.7 && fev/(0.036*height-0.028*age-1.178)<1 && fev/(0.036*height-0.028*age-1.178)>=0.8 ) {
		return com_list("A2");
	} else if ( fev/fvc>=0.7 && fev/(0.036*height-0.028*age-1.178)<0.8 ) {
		return com_list("A3");
	} else if ( fev/fvc<0.7 && fev/(0.036*height-0.028*age-1.178)>=0.8 ) {
		return com_list("A4");
	} else if ( fev/fvc<0.7 && fev/(0.036*height-0.028*age-1.178)<0.8 ) {
		return com_list("A5");
	} else {
		return "該当無し";
	}
}

function lcCom2_male(form) {
	var height = form.height.value;
	var age = form.age.value;
	var fev = form.fev.value;
	var fvc = form.fvc.value;
	
	if ( fev/fvc>=0.7 && fev/(0.036*height-0.028*age-1.178)>=1 ) {
		return com_list("B1");
	} else if ( fev/fvc>=0.7 && fev/(0.036*height-0.028*age-1.178)<1 && fev/(0.036*height-0.028*age-1.178)>=0.8 ) {
		return com_list("B2");
	} else if ( fev/fvc>=0.7 && fev/(0.036*height-0.028*age-1.178)<0.8 ) {
		return com_list("B3");
	} else if ( fev/fvc<0.7 && fev/(0.036*height-0.028*age-1.178)>=0.8 ) {
		return com_list("B4");
	} else if ( fev/fvc<0.7 && fev/(0.036*height-0.028*age-1.178)<0.8 ) {
		return com_list("B5");
	} else {
		return "該当無し";
	}
}

/* female */
function lcCom1_female(form) {
	var height = form.height.value;
	var age = form.age.value;
	var fev = form.fev.value;
	var fvc = form.fvc.value;
	
	if ( fev/fvc>=0.7 && fev/(0.022*height-0.022*age-0.005)>=1 ) {
		return com_list("A1");
	} else if ( fev/fvc>=0.7 && fev/(0.022*height-0.022*age-0.005)<1 && fev/(0.022*height-0.022*age-0.005)>=0.8 ) {
		return com_list("A2");
	} else if ( fev/fvc>=0.7 && fev/(0.022*height-0.022*age-0.005)<0.8 ) {
		return com_list("A3");
	} else if ( fev/fvc<0.7 && fev/(0.022*height-0.022*age-0.005)>=0.8 ) {
		return com_list("A4");
	} else if ( fev/fvc<0.7 && fev/(0.022*height-0.022*age-0.005)<0.8 ) {
		return com_list("A5");
	} else {
		return "該当無し";
	}
}
function lcCom2_female(form) {
	var height = form.height.value;
	var age = form.age.value;
	var fev = form.fev.value;
	var fvc = form.fvc.value;
	
	if ( fev/fvc>=0.7 && fev/(0.022*height-0.022*age-0.005)>=1 ) {
		return com_list("B1");
	} else if ( fev/fvc>=0.7 && fev/(0.022*height-0.022*age-0.005)<1 && fev/(0.022*height-0.022*age-0.005)>=0.8 ) {
		return com_list("B2");
	} else if ( fev/fvc>=0.7 && fev/(0.022*height-0.022*age-0.005)<0.8 ) {
		return com_list("B3");
	} else if ( fev/fvc<0.7 && fev/(0.022*height-0.022*age-0.005)>=0.8 ) {
		return com_list("B45");
	} else if ( fev/fvc<0.7 && fev/(0.022*height-0.022*age-0.005)<0.8 ) {
		return com_list("B5");
	} else {
		return "該当無し";
	}
}



