// =========================================================================
$query = new Zend_Gdata_Health_Query();
$query->setDigest("true");
$profileFeed = $healthService->getHealthProfileFeed($query);';
$snippet2 = '
$entries = $profileFeed->getEntries();
$ccr = $entries[0]->getCcr();
$xmlStr = $ccr->saveXML($ccr);
echo "" . xmlpp($xmlStr) . "
";';
echo '' . htmlentities($snippet . $snippet2) . '
';
eval($snippet);
} catch(Zend_Gdata_App_Exception $e) {
echo 'Error: ' . $e->getMessage();
}
echo '';
echo 'num entries: ' . count($profileFeed->getEntries());
eval($snippet2);
echo '
';
// =============================================================================
// Return a user's medication from the entire CCR
// =============================================================================
try {
$snippet = '
// =========================================================================
// Return a user\'s medication for the entire CCR
// =========================================================================
$profileFeed = $healthService->getHealthProfileFeed();';
$snippet2 = '
foreach ($profileFeed->entry as $entry) {
$medications = $entry->getCcr()->getMedications();
foreach ($medications as $med) {
$xmlStr = $med->ownerDocument->saveXML($med);
echo "" . xmlpp($xmlStr) . "
";
}
}';
} catch(Zend_Gdata_App_Exception $e) {
echo 'Error: ' . $e->getMessage();
}
echo '' . htmlentities($snippet . $snippet2) . '
';
eval($snippet);
echo '';
eval($snippet2);
echo '
';
// =============================================================================
// Category query: return a user's medication
// =============================================================================
try {
$snippet = '
// =========================================================================
// Category query: return a user\'s medication
// =========================================================================
$query = new Zend_Gdata_Health_Query(SCOPE . "profile/default");
$query->setCategory("medication");
$profileFeed = $healthService->getHealthProfileFeed($query);';
$snippet2 = '
foreach ($profileFeed->entry as $entry) {
$medications = $entry->getCcr()->getMedications();
foreach ($medications as $med) {
$xmlStr = $med->ownerDocument->saveXML($med);
echo "" . xmlpp($xmlStr) . "
";
}
}';
} catch(Zend_Gdata_App_Exception $e) {
echo 'Error: ' . $e->getMessage();
}
echo '' . htmlentities($snippet . $snippet2) . '
';
eval($snippet);
echo '';
echo 'query: ' . $query->getQueryUrl() . '
';
echo 'num entries: ' . count($profileFeed->getEntries());
eval($snippet2);
echo '
';
// =============================================================================
// Query for a specific item within a category: allgergy A-Fil
// =============================================================================
try {
$snippet = '
// =========================================================================
// Query for a specific item within a category: allgergy A-Fil
// =========================================================================
$query = new Zend_Gdata_Health_Query(SCOPE . "profile/default");
$query->setCategory("allergy", "A-Fil");
$query->setGrouped("true");
$profileFeed = $healthService->getHealthProfileFeed($query);';
$snippet2 = '
foreach ($profileFeed->getEntries() as $entry) {
$allergies = $entry->getCcr()->getAllergies();
foreach ($allergies as $allergy) {
$xmlStr = $allergy->ownerDocument->saveXML($allergy);
echo "" . xmlpp($xmlStr) . "
";
}
}';
} catch(Zend_Gdata_App_Exception $e) {
echo 'Error: ' . $e->getMessage();
}
echo '' . htmlentities($snippet . $snippet2) . '
';
eval($snippet);
echo '';
echo 'query: ' . $query->getQueryUrl() . '
';
echo 'num entries: ' . count($profileFeed->getEntries());
eval($snippet2);
echo '
';
// =============================================================================
// Query (and return) the user\'s medications OR conditions
// =============================================================================
try {
$snippet = '
// =========================================================================
// Query (and return) the user\'s medications OR conditions
// =========================================================================
$queryStr = SCOPE . "profile/default/-/medication%7Ccondition?digest=false";
$profileFeed = $healthService->getHealthProfileFeed($queryStr);';
$snippet2 = '
$entries = $profileFeed->getEntries();
foreach ($entries as $entry) {
$ccr = $entry->getCcr();
$xmlStr = $ccr->saveXML($ccr);
echo "" . xmlpp($xmlStr) . "
";
}';
echo '' . htmlentities($snippet . $snippet2) . '
';
eval($snippet);
} catch(Zend_Gdata_App_Exception $e) {
echo 'Error: ' . $e->getMessage();
}
echo '';
echo 'num entries: ' . count($profileFeed->getEntries());
eval($snippet2);
echo '
';
// =============================================================================
// Send a notice to the user's profile that includes a CCR payload
// =============================================================================
try {
$snippet = '
// =========================================================================
// Send a notice to the user\'s profile that includes a CCR payload
// =========================================================================
$subject = "Title of your notice goes here";
$body = "Notice body can contain html entities";
$ccr = \'
Start date
2007-04-04T07:00:00Z
Aortic valve disorders
410.10
ICD9
2004
Active
\';
$responseEntry = $healthService->sendHealthNotice($subject, $body, "html", $ccr);';
} catch(Zend_Gdata_App_Exception $e) {
echo 'Error: ' . $e->getMessage();
}
echo '' . htmlentities($snippet) . '
';
eval($snippet);
echo '';
echo xmlpp($responseEntry->getXML());
echo '
';
// =============================================================================
// Revoke the AuthSub session token
// =============================================================================
//$revoked = Zend_Gdata_AuthSub::AuthSubRevokeToken($client->getAuthSubToken(), $client) ? 'yes' : 'no';
//echo 'Token revoked: ' . @$revoked;
//unset($_SESSION['sessionToken']);
?>
Link your Google Health Account';
exit();
}
$client = new Zend_Gdata_HttpClient();
$client->setAuthSubPrivateKeyFile(HEALTH_PRIVATE_KEY, null, true);
// Convert an AuthSub one-time token into a session token if needed
if ($singleUseToken && !$sessionToken) {
$sessionToken =
Zend_Gdata_AuthSub::getAuthSubSessionToken($singleUseToken, $client);
$_SESSION['sessionToken'] = $sessionToken;
}
$client->setAuthSubToken($sessionToken);
return $client;
}
function getTokenInfo($client) {
$sessionToken = $client->getAuthSubToken();
return Zend_Gdata_AuthSub::getAuthSubTokenInfo($sessionToken, $client);
}
function revokeToken($client) {
$sessionToken = $client->getAuthSubToken();
return Zend_Gdata_AuthSub::AuthSubRevokeToken($sessionToken, $client);
}
/** Prettifies an XML string into a human-readable and indented work of art
* @param string $xml The XML as a string
* @param boolean $html_output True if the output should be escaped (for use in HTML)
*/
function xmlpp($xml, $html_output=true) {
$xml_obj = new SimpleXMLElement($xml);
$level = 4;
$indent = 0; // current indentation level
$pretty = array();
// get an array containing each XML element
$xml = explode("\n", preg_replace('/>\s*', ">\n<", $xml_obj->asXML()));
// shift off opening XML tag if present
if (count($xml) && preg_match('/^<\?\s*xml/', $xml[0])) {
$pretty[] = array_shift($xml);
}
foreach ($xml as $el) {
if (preg_match('/^<([\w])+[^>\/]*>$/U', $el)) {
// opening tag, increase indent
$pretty[] = str_repeat(' ', $indent) . $el;
$indent += $level;
} else {
if (preg_match('/^<\/.+>$/', $el)) {
$indent -= $level; // closing tag, decrease indent
}
if ($indent < 0) {
$indent += $level;
}
$pretty[] = str_repeat(' ', $indent) . $el;
}
}
$xml = implode("\n", $pretty);
return ($html_output) ? htmlentities($xml) : $xml;
}
?>