Location: PHPKode > projects > OpenEMR Mobile > mobile/data.php
<?php
/*
Copyright: 2010 Capraro Technologies Inc.
License: Licensed under The GPL
Website: http://www.caprarotechnologies.com
Email: hide@address.com
Author: James Scherzi
*/
?>
<?php
session_start();
if (!(isset($_SESSION['login']) && $_SESSION['login'] != '')) {
header ("Location: index.php");
}

?>

<?php
require_once($_SERVER['DOCUMENT_ROOT']."/mobile/db/dbfunc.php");

$db = new EMRDbConn();
if (!$db->connect())
{
	die("ERROR: Couldn't connect to database.");
}

$date = $_GET['date'];
$doc = $_GET['doc'];

$date = stripslashes($date);
$doc = stripslashes($doc);
$date = mysql_real_escape_string($date);
$doc = mysql_real_escape_string($doc);


//use today's date
if(is_null($date) || empty($date) || is_numeric($date)) $qs = "SELECT pid, concat(fname,' ',lname) as name, pc_startTime, pc_catname, pc_hometext FROM openemr_postcalendar_events
LEFT JOIN patient_data ON openemr_postcalendar_events.pc_pid = patient_data.id
LEFT JOIN openemr_postcalendar_categories ON  openemr_postcalendar_events.pc_catid = openemr_postcalendar_categories.pc_catid
WHERE pc_eventDate = CURDATE()";

else {
//fix date issue
list($year, $month, $day) = split('[-.-]', $date);
$month=$month+1;

$date = $year."-".$month."-".$day;

//use a user specified date
$qs = "SELECT pid, concat(fname,' ',lname) as name, pc_startTime, pc_catname, pc_hometext  FROM openemr_postcalendar_events
LEFT JOIN patient_data ON openemr_postcalendar_events.pc_pid = patient_data.id
LEFT JOIN openemr_postcalendar_categories ON  openemr_postcalendar_events.pc_catid = openemr_postcalendar_categories.pc_catid
WHERE pc_eventDate = '$date'";
}

//filter by provider if need be
if(!is_null($doc) && !empty($doc) && $doc != "" && is_numeric($doc)) $qs .= " AND pc_aid=$doc";

//order the results by start time
$qs .= " ORDER BY pc_startTime asc";

//die($qs);
$qy = $db->addQuery($qs);
$rs = $qy->execute();

if (is_null($rs))
{
  die("ERROR: Couldn't execute query.");
}
$rs->move_first();


$output = '<ResultSet>';
//if there are no patients for this date create a single result
if($rs->eof()) $output .= "<Result><Pid>1</Pid><Name>No Patients Found</Name><Cat>OfficeVisit</Cat><Text>No Notes</Text></Result>";

//loop and generate one <Result> for each appointment
while(!$rs->eof()){	

$output .= "<Result>";
//save the patient id incase we want to do something with it later on
$output .= "<Pid>".$rs->fields("pid")."</Pid>";

//reformat the start time for easier viewing
$output .= "<StartTime>".date("g:i a", strtotime($rs->fields("pc_startTime")))."</StartTime>";

//remove some characters and spaces from the category names so we can match them
$tmp = str_replace(' ','',$rs->fields('pc_catname'));
$tmp = str_replace('/','',$tmp);
$output .= "<Cat>".str_replace('.','',$tmp)."</Cat>";

//add the name or category name if there is no patient and notes from the appointment
//if there are notes for the appointment, add a start next to the name
$hometext = $rs->fields("pc_hometext");
if(empty($hometext)){
	if(is_null($rs->fields("name"))){
		$output .= "<Name>".$rs->fields("pc_catname")."</Name>";
	}
	else $output .= "<Name>".$rs->fields("name")."</Name>";
	$output .= "<Text>No Notes</Text>";
	}
else {	
	if(is_null($rs->fields("name"))){
		$output .= "<Name>".$rs->fields("pc_catname")." *</Name>";
	}
	else $output .= "<Name>".$rs->fields("name")." *</Name>";
	$output .= "<Text>".$rs->fields("pc_hometext")."</Text>";
	}

$output .= "</Result>";
$rs->move_next();
}
$output .= "</ResultSet>";

$db->close();

//set the content type as xml so it is readable by the datasource and echo it out
$type = "text/xml";
header("Content-Type: ".$type);
echo $output;
?>
Return current item: OpenEMR Mobile