<?php
//We've included ../Includes/FusionCharts.php and ../Includes/DBConn.php, which contains
//functions to help us easily embed the charts and connect to a database.
include("../includes/FusionCharts.php");
include("../includes/conndb.php");
include("../includes/config.inc.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $titleweb; ?></title>
<!--[if IE 6]>
<script>
<script type="text/javascript" src="../assets/ui/js/DD_belatedPNG_0.0.8a-min.js"></script>
/* select the element name, css selector, background etc */
DD_belatedPNG.fix('img');
/* string argument can be any CSS selector */
</script>
<![endif]-->
<style type="text/css">
h2.headline {
font: normal 110%/137.5% "Trebuchet MS", Arial, Helvetica, sans-serif;
padding: 0;
margin: 25px 0 25px 0;
color: #7d7c8b;
text-align: center;
}
p.small {
font: normal 68.75%/150% Verdana, Geneva, sans-serif;
color: #919191;
padding: 0;
margin: 0 auto;
width: 664px;
text-align: center;
}
</style>
<?php
//You need to include the following JS file, if you intend to embed the chart using JavaScript.
//Embedding using JavaScripts avoids the "Click to Activate..." issue in Internet Explorer
//When you make your own charts, make sure that the path to this JS file is correct. Else, you
//would get JavaScript errors.
?>
<SCRIPT LANGUAGE="Javascript" SRC="FusionCharts/FusionCharts.js"></SCRIPT>
</head>
<BODY>
<?php
//In this example, we show how to connect FusionCharts to a database.
//For the sake of ease, we've used an MySQL databases containing two
//tables.
// Connect to the DB
$sql = "SELECT
concat('สถานบริการ(สถานีอนามัย/PCU): ',chospital.`hosname`,' หมู่ที่:',ifnull(chospital.`mu`,'...'),' ต.',
ifnull(csubdistrict.`subdistname`,' ...'),' อ.',ifnull(cdistrict.`distname`,' ...'),' จ.',
ifnull(cprovince.`provname`,'...')) AS chospital_hosname
FROM
`chospital` chospital
INNER JOIN `office` office ON chospital.`hoscode` = office.`offid`
left outer join `csubdistrict` csubdistrict ON chospital.`provcode` = csubdistrict.`provcode`
AND chospital.`distcode` = csubdistrict.`distcode`
AND chospital.`subdistcode` = csubdistrict.`subdistcode`
left outer JOIN `cdistrict` cdistrict ON chospital.`provcode` = cdistrict.`provcode`
AND chospital.`distcode` = cdistrict.`distcode`
INNER JOIN `cprovince` cprovince ON chospital.`provcode` = cprovince.`provcode`";
$result = mysql_query($sql);
$row=mysql_fetch_array($result);
$hosp=$row[chospital_hosname];
// SQL query for category labels
$strQueryCategories = "SELECT
village.villname as villname
FROM
village
WHERE
right(village.villcode,2) <> '00' and village.villname is not null
order by village.villcode";
// Query database
$resultCategories = mysql_query($strQueryCategories) or die(mysql_error());
$villcode = $_GET[village];
if($villcode == "00000000"){
$wvill = "";
}else{
$wvill = "and house.villcode='$villcode' ";
}
if($villcode == "00000000"){
$mu = "ทุกหมู่บ้าน";
}else{
$mu = getvillagename($villcode);
}
$str = retDate($_GET[str]);
$sto = retDate($_GET[sto]);
// SQL query for factory output data
$strQueryData = "select
pcucodeperson,
villcode,
villname,
'ผู้ป่วยโรคเรื้อรังทั้งหมด' as mark,
count(distinct pid) as per
from
(SELECT
person.pcucodeperson,
person.pid,
person.fname,
CONCAT(ctitle.titlename,person.fname,' ',person.lname) AS pname,
person.birth,
getageyearnum(person.birth,now()) as age,
house.hcode,
house.hno,
right(house.villcode,2) as moo,
house.villcode,
village.villname,
house.xgis,
house.ygis,
group_concat(personchronic.chroniccode) as chronic_code,
group_concat(cdiseasechronic.groupname) as chronic_name
FROM
personchronic
inner Join person ON personchronic.pcucodeperson = person.pcucodeperson AND personchronic.pid = person.pid
Inner Join house ON person.pcucodeperson = house.pcucode AND person.hcode = house.hcode
Inner Join village ON house.pcucode = village.pcucode AND house.villcode = village.villcode
left Join ctitle ON person.prename = ctitle.titlecode
Inner Join cdisease ON personchronic.chroniccode = cdisease.diseasecode
Inner Join cdiseasechronic ON cdisease.codechronic = cdiseasechronic.groupcode
where person.pid NOT IN (SELECT persondeath.pid FROM persondeath WHERE persondeath.pcucodeperson= person.pcucodeperson and (persondeath.deaddate IS NULL OR persondeath.deaddate<=now())) and right(house.villcode,2) <> '00' $wvill
group by personchronic.pcucodeperson,personchronic.pid
order by house.villcode,person.fname) as per_chronic
left join
(SELECT
visit.pcucodeperson as pcucodeperson1,
visit.pid as pid1,
visit.visitno,
visit.visitdate,
chomehealthtype.homehealthmeaning,
visithomehealthindividual.patientsign,
visithomehealthindividual.homehealthdetail,
visithomehealthindividual.homehealthresult,
visithomehealthindividual.homehealthplan,
visithomehealthindividual.dateappoint,
concat(ctitle.titlename,`user`.fname,`user`.lname) as userh,
visithomehealthindividual.`user`
FROM
visit
Inner Join visithomehealthindividual ON visit.pcucode = visithomehealthindividual.pcucode AND visit.visitno = visithomehealthindividual.visitno
Inner Join chomehealthtype ON visithomehealthindividual.homehealthtype = chomehealthtype.homehealthcode
INNER JOIN `user` ON visit.pcucodeperson = `user`.pcucode AND visithomehealthindividual.`user` = `user`.username
left JOIN ctitle ON `user`.prename = ctitle.titlecode
where visit.visitdate between '$str' and '$sto' and (visit.flagservice <'04' OR visit.flagservice is null OR length(trim(visit.flagservice))=0)) as per_homevisit
on per_chronic.pcucodeperson = per_homevisit.pcucodeperson1 and per_chronic.pid = per_homevisit.pid1
group by villcode
union
select
pcucodeperson,
villcode,
villname,
'ผู้ป่วยโรคเรื้อรังได้รับการเยี่ยมบ้าน' as mark,
count(distinct pid1) as per
from
(SELECT
person.pcucodeperson,
person.pid,
person.fname,
CONCAT(ctitle.titlename,person.fname,' ',person.lname) AS pname,
person.birth,
getageyearnum(person.birth,now()) as age,
house.hcode,
house.hno,
right(house.villcode,2) as moo,
house.villcode,
village.villname,
house.xgis,
house.ygis,
group_concat(personchronic.chroniccode) as chronic_code,
group_concat(cdiseasechronic.groupname) as chronic_name
FROM
personchronic
inner Join person ON personchronic.pcucodeperson = person.pcucodeperson AND personchronic.pid = person.pid
Inner Join house ON person.pcucodeperson = house.pcucode AND person.hcode = house.hcode
Inner Join village ON house.pcucode = village.pcucode AND house.villcode = village.villcode
left Join ctitle ON person.prename = ctitle.titlecode
Inner Join cdisease ON personchronic.chroniccode = cdisease.diseasecode
Inner Join cdiseasechronic ON cdisease.codechronic = cdiseasechronic.groupcode
where person.pid NOT IN (SELECT persondeath.pid FROM persondeath WHERE persondeath.pcucodeperson= person.pcucodeperson and (persondeath.deaddate IS NULL OR persondeath.deaddate<=now())) and right(house.villcode,2) <> '00' $wvill
group by personchronic.pcucodeperson,personchronic.pid
order by house.villcode,person.fname) as per_chronic
left join
(SELECT
visit.pcucodeperson as pcucodeperson1,
visit.pid as pid1,
visit.visitno,
visit.visitdate,
chomehealthtype.homehealthmeaning,
visithomehealthindividual.patientsign,
visithomehealthindividual.homehealthdetail,
visithomehealthindividual.homehealthresult,
visithomehealthindividual.homehealthplan,
visithomehealthindividual.dateappoint,
concat(ctitle.titlename,`user`.fname,`user`.lname) as userh,
visithomehealthindividual.`user`
FROM
visit
Inner Join visithomehealthindividual ON visit.pcucode = visithomehealthindividual.pcucode AND visit.visitno = visithomehealthindividual.visitno
Inner Join chomehealthtype ON visithomehealthindividual.homehealthtype = chomehealthtype.homehealthcode
INNER JOIN `user` ON visit.pcucodeperson = `user`.pcucode AND visithomehealthindividual.`user` = `user`.username
left JOIN ctitle ON `user`.prename = ctitle.titlecode
where visit.visitdate between '$str' and '$sto' and (visit.flagservice <'04' OR visit.flagservice is null OR length(trim(visit.flagservice))=0)) as per_homevisit
on per_chronic.pcucodeperson = per_homevisit.pcucodeperson1 and per_chronic.pid = per_homevisit.pid1
group by villcode";
// Query database
$resultData = mysql_query($strQueryData) or die(mysql_error());
//We also keep a flag to specify whether we've to animate the chart or not.
//If the user is viewing the detailed chart and comes back to this page, he shouldn't
//see the animation again.
$animateChart = @$_GET['animate'];
//Set default value of 1
if ($animateChart=="")
$animateChart = "1";
//$strXML will be used to store the entire XML document generated
//Generate the chart element
$strXML = "<chart legendPostion='' caption='ผู้ป่วยโรคเรื้อรังที่ได้รับการเยี่ยมบ้าน ข้อมูลระหว่างวันที่ ".$_GET[str]." ถึง ".$_GET[sto]." ".$mu ."' subCaption='".$hosp."' xAxisName='' yAxisName='คน' showValues='1' formatNumberScale='0' rotateValues='1' animation=' " . $animateChart . "'>";
// Build category XML
$strXML .= buildCategories ($resultCategories, "villname");
// Build datasets XML
$strXML .= buildDatasets ( $resultData, "per", "mark");
//Finally, close <chart> element
$strXML .= "</chart>";
//Create the chart - Pie 3D Chart with data from strXML
echo renderChart("FusionCharts/MSColumn2D.swf", "", $strXML, "FactorySum", 750, 450, false, false);
// Free database resource
mysql_free_result($resultCategories);
mysql_free_result($resultData);
mysql_close($link);
/***********************************************************************************************
* Function to build XML for categories
* @param $result Database resource
* @param $labelField Field name as String that contains value for chart category labels
*
* @return categories XML node
*/
function buildCategories ( $result, $labelField ) {
$strXML = "";
if ($result) {
$strXML = "<categories>";
while($ors = mysql_fetch_array($result)) {
$strXML .= "<category label='" . $ors[$labelField]. "'/>";
}
$strXML .= "</categories>";
}
return $strXML;
}
/***********************************************************************************************
* Function to build XML for datesets that would contain chart data
* @param $result Database resource. The data should come ordered by a control break
field which would require to identify datasets and set its value to
dataset's series name
* @param $valueField Field name as String that contains value for chart dataplots
* @param $controlBreak Field name as String that contains value for chart dataplots
*
* @return Dataset XML node
*/
function buildDatasets ($result, $valueField, $controlBreak ) {
$strXML = "";
if ($result) {
$controlBreakValue ="";
while( $ors = mysql_fetch_array($result) ) {
if( $controlBreakValue != $ors[$controlBreak] ) {
$controlBreakValue = $ors[$controlBreak];
$strXML .= ( $strXML =="" ? "" : "</dataset>") . ( "<dataset seriesName='" . $controlBreakValue . "'>" ) ;
}
$strXML .= "<set value='" . $ors[$valueField] . "'/>";
}
$strXML .= "</dataset>";
}
return $strXML;
}
?>
</BODY>
</HTML>