
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--
Template Name: Internet Business
Author: <a href="http://www.os-templates.com/">OS Templates</a>
Author URI: http://www.os-templates.com/
Licence: Free to use under our free template licence terms
Licence URI: http://www.os-templates.com/template-terms
-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Internet Business | Style Demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" href="layout/styles/layout.css" type="text/css" />
<link rel="stylesheet" href="form.css" type="text/css" />
<link rel="stylesheet" href="table.css" type="text/css" />

</head>
<body id="top">
<div id="header">
  <div class="wrapper">
    <div class="fl_left">
      <h1><a href="index.html">Sistem Cerdas</a></h1>
      <p>Deteksi Dini Penyakit Jantung</p>
    </div>
    <div class="fl_right"> <a href="#"><img src="images/demo/468x60.gif" alt="" /></a> </div>
    <br class="clear" />
  </div>
</div>
<!-- ####################################################################################################### -->
<div id="topbar">
  <div class="wrapper">
    <div id="topnav">
      <ul>
         <li class="active"><a href="index_admin.html">Home</a></li>
        <li><a href="tambah_user.php">User</a></li>
        <li><a href="tambah_gejala.php">Gejala</a></li>
        <li><a href="tambah_penyakit.php">Penyakit</a></li>
        <li><a href="tambah_solusi.php">Solusi</a></li>
		<li><a href="laporan.php">Laporan</a></li>
        <li><a href="index.html">Log Out</a></li>
        
      </ul>
    </div>
    <div id="search">
      <form action="#" method="post">
        <fieldset>
          <legend>Site Search</legend>
            <input type="submit" name="go" id="go" value="Log Out" />
        </fieldset>
      </form>
    </div>
    <br class="clear" />
  </div>
</div>
<!-- ####################################################################################################### -->
<div id="breadcrumb">
  <div class="wrapper">
    <ul>
      <li class="first">You Are Here</li>
      <li>&#187;</li>
      <li><a href="#">Gejala</a></li>
      <li>&#187;</li>
      <li><a href="tabel_gejala.php">Tabel gejala</a></li>
    </ul>
  </div>
</div>
<!-- ####################################################################################################### -->
<div id="container">
  <div class="wrapper">
    <div id="content">
	

	
<H3>
	  <P align="center"><b> KONSULTASI GEJALA </b></P></H3>


	  <?php 
include_once "library/inc.connection.php";
include_once "library/inc.library.php";
$sql9 = mysql_query("TRUNCATE TABLE hasil_diagnosa");

# ID = no IP komputer, atau No HP, User ID
$ID		= str_replace(".","",$_SERVER['REMOTE_ADDR']);
$HiHasil = array();
error_reporting(0);
 
 
// echo $jum;
 //echo $HiHasil;
 //exit();

if(! $_POST) {
	echo "<meta http-equiv='refresh' content='0; url=konsultasi_pilih_gejala.php'>";
}
else if(isset($_POST['btnKonsultasi'])){
   $jum  = count($dataGejala);
  // echo $jum;
   //exit();
   if ($jum==0) {
		//echo "BELUM ADA GEJALA YANG DIPILIH";
		include_once "gagal.php";
   }
   else {
		echo "<b>Gejala yang dihadapi : </b><br><br>";
		foreach ($dataGejala as $nilai) {
			$gejalaSQL = "SELECT * FROM gejala WHERE id_gejala='$nilai'";
			$gejalaQry = mysql_query($gejalaSQL) or die ("Error gejala".mysql_error());
			$gejalaHsl = mysql_fetch_array($gejalaQry);
			$kodegejala1=$gejalaHsl['id_gejala'];
			echo $gejalaHsl['id_gejala'].": ".$gejalaHsl['nama_gejala']."<br>";
			
		}
		
		
		# TAMPILKAN SEMUA DAFTAR PENYAKIT, Sekaligus membuat Rumus berulang sejumlah Penyakit
		//echo "<b> Hasil Diagnosa : </b><hr>";
		$Hi	= 1; $h = 0; $PH	= 0;
		$penyakitSql = "SELECT * FROM penyakit";
		$penyakitQry = mysql_query($penyakitSql) or die ("Error penyakit".mysql_error());
		while ($penyakitData = mysql_fetch_array($penyakitQry)){
			
			#Buat info aja
			//echo "<br> <b> $penyakitData[id_penyakit] $penyakitData[nama_penyakit]</b><br>";
		
			$np_populasi = $penyakitData['np_populasi'];
			
			// Kode untuk mengurai Gejala yang dipilih
			//$Em = 1;
			$bayes2 = 0;
			foreach ($dataGejala as $id_gejala) {
				$aturanSql  = "SELECT * FROM aturan WHERE id_penyakit='$penyakitData[id_penyakit]' AND id_gejala='$id_gejala'";
				$aturanQry  = mysql_query($aturanSql) or die ("Error program".mysql_error());
				$aturanData = mysql_fetch_array($aturanQry);
				
				
				
				$id_gejala = $aturanData['id_gejala'];
				$nilai_probabilitas = $aturanData['nilai_probabilitas'];
				
				//echo $id_gejala,$nilai_probabilitas;
				
				$bayes1=$np_populasi*$nilai_probabilitas;
				$bayes2=$bayes2+$bayes1;
				
				//echo $bayes2;
				//echo "<br>";
				}
				
				
				
				$aturanok  = "SELECT * FROM aturan WHERE id_penyakit='$penyakitData[id_penyakit]'";
				$aturanoke  = mysql_query($aturanok) or die ("Error program".mysql_error());
				$bayes4=0;
				while($aturanokee = mysql_fetch_array($aturanoke)){
				$id_gejalaok = $aturanokee['id_gejala'];
				$nilai_probabilitasok = $aturanokee['nilai_probabilitas'];
				
				//echo $nilai_probabilitasok;
				//echo "<br>";
				//echo $np_populasi;
				$bayes3=$np_populasi*$nilai_probabilitasok;
				//echo "<br>";
				//echo $bayes3;
				//echo "<br>";
				//echo $bayes4;
				$bayes4=$bayes4+$bayes3;
				//$bayes5=$bayes4-$np_populasi-$nilai_probabilitasok;
				}
				
				//echo "<br>";
				$hasilakhir=($bayes2/$bayes4);
				$hasilok=$hasilakhir*100;
				
				
				//echo "$bayes2 / $bayes5";
				//echo "<br>";
				//echo floor($hasilok)."%";
				
				$HiHasil[$penyakitData['id_penyakit']] = $hasilakhir;
				//$hasilsip[$bayes2]=$mantapok;
				
				//echo "<br>";
				
			//exit();
			
		}
		//echo "<br>";
		
		mysql_query("DELETE FROM tmp_diagnosa WHERE ID='$ID'") or die ("Error delete tmp".mysql_error());
		
		
	//$PHitung = array();
		//var_dump($HiHasil);
		foreach ($HiHasil as $kode => $hasilakhir){
			//$PHitung= calcBagi($bayes2, $bayes4);
			// Simpan konsultasi ke Temporary
			//echo $hasilakhir;	
			
			$inTmpSql = "INSERT INTO tmp_diagnosa (ID,id_penyakit,hasil_hitung)Values ('$ID','$kode','$hasilakhir')";
						 //echo $inTmpSql ;
			
			mysql_query($inTmpSql) or die ("Error inTmpSql".mysql_error());
			//echo $inTmpSql;
			}
		
	
echo "<hr>";
echo "Nilai Probabilitas Dari Gejala Yang dipilih: <br> ";

$maxSql2 = "SELECT * FROM tmp_diagnosa order by hasil_hitung = 'asc'";
		$maxQry2 = mysql_query($maxSql2) or die ("Error maxSql".mysql_error());
		
		while($maxHsl2 = mysql_fetch_array($maxQry2))
		{
		$id_penyakit2 = $maxHsl2['id_penyakit'];
		$maxHasil2 = $maxHsl2['hasil_hitung'];
		echo $id_penyakit2," = ",$maxHasil2 ,"<br>" ; 
		}


echo "<hr>";

		$maxSql = "SELECT * FROM tmp_diagnosa WHERE hasil_hitung=(SELECT MAX(hasil_hitung) FROM tmp_diagnosa WHERE ID='$ID') AND ID='$ID'";
		$maxQry = mysql_query($maxSql) or die ("Error maxSql".mysql_error());
		$maxHsl = mysql_fetch_array($maxQry);
		$maxHasil = $maxHsl['hasil_hitung'];
		$maxHasilok = $maxHasil*100;
		
		$penyakit2Sql = "SELECT * FROM penyakit WHERE id_penyakit='$maxHsl[id_penyakit]'";
		$penyakit2Qry = mysql_query($penyakit2Sql) or die ("Error penyakit2Sql".mysql_error());
		$penyakit2Hsl = mysql_fetch_array($penyakit2Qry);
		$nama_penyakit = $penyakit2Hsl['nama_penyakit'];
		$penyebab = $penyakit2Hsl['keterangan'];
		//$pengobatan = $penyakit2Hsl['pengobatan'];
		
		echo "<br>";
		# HITUNG : STEP 7 : INTERPRETASI NILAI PROBABILITAS
		# ========================================================
		//echo "<br><b> Step 3 : </b><hr>";	
		if($maxHasil < 0) {
			$hasil = "Tidak diketahui";
		}
		elseif($maxHasil == -1) {
			$hasil = "Pasti Tidak";
		}
		elseif($maxHasil >  -1 && $maxHasil <= -0.8) {
			$hasil = "Hampir Pasti Tidak";
		}
		elseif($maxHasil >  -0.8 && $maxHasil <= -0.6) {
			$hasil = "Kemungkinan Besar Tidak";
		}
		elseif($maxHasil >  -0.6 && $maxHasil <= -0.4) {
			$hasil = "Kemungkinan Besar Tidak";
		}
		elseif($maxHasil >  -0.4 && $maxHasil <= -0.2) {
			$hasil = "Mungkin Tidak";
		}
		elseif($maxHasil >  -0.2 && $maxHasil <= -0.2) {
			$hasil = "Tidak Tahu";
		}
		elseif($maxHasil >  0.2 && $maxHasil <= 0.4) {
			$hasil = "Mungkin";
		}
		elseif($maxHasil >  0.4 && $maxHasil <= 0.7) {
			$hasil = "Kemungkinan Besar";
		}
		else if($maxHasil >  0.6 && $maxHasil <= 0.8) {
			$hasil = "Hampir Pasti";
		}
		else if($maxHasil >  0.8 && $maxHasil <= 1) {
			$hasil = "pasti";
		}
		else if($maxHasil > 1) {
			$hasil = "Tidak diketahui";
		}
		
		//echo round($zxc,2);
		//echo $cv;
		echo "Hasil Diagnosa Penyakit anda berdasarkan gejala yang dipilih adalah <b>$hasil</b>	menderita penyakit <b> $nama_penyakit </b>dengan nilai probabilitas $maxHasilok %";
		echo "<br><br>Solusi :  $penyebab  ";
		//echo "<br><br>Solusi : <br> $pengobatan  ";
		
		$query = "INSERT INTO hasil_diagnosa (nama_penyakit,maxHasilok) VALUES('$nama_penyakit','$maxHasilok')";
		$hasil = mysql_query($query);
   
		
mysql_close();
	}
}
else {
	echo "<meta http-equiv='refresh' content='0; url=?'>";
}
?>

		
	
	
	
	
	
	
	
			<br></br>
        <thead>
         
        </thead>
        <tbody>
          
        </tbody>
      </table>
      <div id="comments">
        </ul>
      </div>
      
    </div>
    <div id="column">
      <div class="subnav">
       <h2>Secondary Navigation</h2>
        <ul>
          
          <li><a href="#">User</a>
            <ul>
              <li><a href="tambah_user.php">Tambah User</a></li>
              <li><a href="tabel_user.php">Tabel User</a></li>
            </ul>
          </li>
          <li><a href="#">Gejala</a>
            <ul>
              <li><a href="tambah_gejala.php">Tambah Gejala</a></li>
              <li><a href="tabel_gejala.php">Tabel Gejala</a></li>
            </ul>
          </li>
		  <li><a href="#">Penyakit</a>
            <ul>
              <li><a href="tambah_penyakit.php">Tambah Penyakit</a></li>
              <li><a href="tabel_penyakit.php">Tabel Penyakit</a></li>
            </ul>
          </li>
		  		  <li><a href="#">Solusi</a>
            <ul>
              <li><a href="tambah_solusi.php">Tambah Solusi</a></li>
              <li><a href="tabel_solusi.php">Tabel Solusi</a></li>
            </ul>
          </li>
          <li><a href="diagnosa.php">Diagnosa</a></li>
          <li><a href="index.html">Log Out</a></li>
        </ul>
      </div> 
      <div class="holder">
        
        
      </div>
    </div>
    <br class="clear" />
  </div>
</div>
<!-- ####################################################################################################### -->
<div id="footer">
  <div class="wrapper">
    <div id="newsletter">
      <h2>Stay In The Know !</h2>
      <p>Please enter your email to join our mailing list</p>
      <form action="#" method="post">
        <fieldset>
          <legend>News Letter</legend>
          <input type="text" value="Enter Email Here&hellip;"  onfocus="this.value=(this.value=='Enter Email Here&hellip;')? '' : this.value ;" />
          <input type="submit" name="news_go" id="news_go" value="GO" />
        </fieldset>
      </form>
      <p>To unsubscribe please <a href="#">click here &raquo;</a></p>
    </div>
    <div class="footbox">
      <h2>Lacus interdum</h2>
      <ul>
        <li><a href="#">Praesent et eros</a></li>
        <li><a href="#">Praesent et eros</a></li>
        <li><a href="#">Lorem ipsum dolor</a></li>
        <li><a href="#">Suspendisse in neque</a></li>
        <li class="last"><a href="#">Praesent et eros</a></li>
      </ul>
    </div>
    <div class="footbox">
      <h2>Lacus interdum</h2>
      <ul>
        <li><a href="#">Praesent et eros</a></li>
        <li><a href="#">Praesent et eros</a></li>
        <li><a href="#">Lorem ipsum dolor</a></li>
        <li><a href="#">Suspendisse in neque</a></li>
        <li class="last"><a href="#">Praesent et eros</a></li>
      </ul>
    </div>
    <div class="footbox">
      <h2>Lacus interdum</h2>
      <ul>
        <li><a href="#">Praesent et eros</a></li>
        <li><a href="#">Praesent et eros</a></li>
        <li><a href="#">Lorem ipsum dolor</a></li>
        <li><a href="#">Suspendisse in neque</a></li>
        <li class="last"><a href="#">Praesent et eros</a></li>
      </ul>
    </div>
    <br class="clear" />
  </div>
</div>
<!-- ####################################################################################################### -->
<div id="copyright">
  <div class="wrapper">
    <p class="fl_left">Copyright &copy; 2014 - All Rights Reserved - <a href="#">Domain Name</a></p>
    <p class="fl_right">Template by <a target="_blank" href="http://www.os-templates.com/" title="Free Website Templates">OS Templates</a></p>
    <br class="clear" />
  </div>
</div>
</body>
</html>