EDN Admin
Well-known member
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.Text.RegularExpressions" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="Google.GData.Client" %>
<%@ Import Namespace="Google.GData.Health" %>
<%@ Import Namespace="Google.GData.Extensions" %>
<br/>
<script runat="server
<br/>
void PrintProfile() {
<br/>
GAuthSubRequestFactory authFactory = new GAuthSubRequestFactory("weaver", "exampleCo-exampleApp-1");
authFactory.Token = (String) Session["token"];
<br/>
HealthService service = new HealthService(authFactory.ApplicationName);
service.RequestFactory = authFactory;
HealthQuery profileQuery = new HealthQuery("https://www.google.com/h9/feeds/profile/default");
profileQuery.Digest = true;
<br/>
try
{
HealthFeed feed = service.Query(profileQuery);
foreach (HealthEntry entry in feed.Entries )
{
<span style="white-spacere XmlExtension ccrExt = (XmlExtension) entry.FindExtension("ContinuityOfCareRecord", "urn:astm-org:CCR");
<br/>
XmlDocument ccrXMLDoc = new XmlDocument();
ccrXMLDoc.ImportNode(ccrExt, true);
XmlNamespaceManager ccrNameManager = new XmlNamespaceManager(ccrXMLDoc.NameTable);
ccrNameManager.AddNamespace("ccr", "urn:astm-org:CCR");
<span style="white-spacere //use xpath to extract specific CCR elements
<span style="white-spacere XmlNodeList meds = ccrExt.Node.SelectNodes("//ccr:Body/ccr:Medications/ccr:Medication/ccrroduct/ccrroductName/ccr:Text", ccrNameManager);
<span style="white-spacere XmlNodeList conditions = ccrExt.Node.SelectNodes("//ccr:Body/ccrroblems/ccrroblem/ccrescription/ccr:Text", ccrNameManager);
<span style="white-spacere XmlNodeList allergies = ccrExt.Node.SelectNodes("//ccr:Body/ccr:Alerts/ccr:Alert/ccrescription/ccr:Text", ccrNameManager);
<span style="white-spacere XmlNodeList procedures = ccrExt.Node.SelectNodes("//ccr:Body/ccrrocedures/ccrrocedure/ccrescription/ccr:Text", ccrNameManager);
<span style="white-spacere XmlNodeList immunizations = ccrExt.Node.SelectNodes("//ccr:Body/ccr:Immunizations/ccr:Immunization/ccrroduct/ccrroductName/ccr:Text", ccrNameManager);
//XmlNodeList results = ccrExt.Node.SelectNodes("/Body/Results/Result/Test", ccrNameManager);
PrintElement(meds, "Your Medications");
<span style="white-spacere PrintElement(conditions, "Your Conditions");
<span style="white-spacere PrintElement(allergies, "Your Allergies");
<span style="white-spacere PrintElement(procedures, "Your Procedures");
<span style="white-spacere PrintElement(immunizations, "Your Immunizations");
XmlNode ccr = ccrExt;
<span style="white-spacere if (ccr != null)
{
Response.Write("<div style="clear:both; <h3>Entire profile</h3><pre>");
StringWriter sw = new StringWriter();
XmlTextWriter xw = new XmlTextWriter(sw);
xw.Formatting = Formatting.Indented;
ccr.WriteTo(xw);
Response.Write(HttpUtility.HtmlEncode(sw.ToString()));
Response.Write("[/code]");
}
}
}
catch (GDataRequestException gdre)
{
HttpWebResponse response = (HttpWebResponse)gdre.Response;
//bad auth token, clear session and refresh the page
if (response.StatusCode == HttpStatusCode.Unauthorized)
{
Session.Clear();
Response.Redirect(Request.Url.AbsolutePath, true);
}
else
{
Response.Write("Error processing request: " + gdre.ToString());
}
}
}
void PrintElement(XmlNodeList nodeList, String title) {
<span style="white-spacere Response.Write("<span class="right <b>" + title + "</b><ol>");
<span style="white-spacere foreach (XmlNode element in nodeList)
<span style="white-spacere {
<span style="white-spacere Response.Write("" + HttpUtility.HtmlEncode(element.InnerText) + "");
<span style="white-spacere }
<span style="white-spacere Response.Write("</ol>");
}
</script>
<br/>
<br/>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server
<title>Google Health API .NET - Profile Read Sample</title>
<style type="text/css
ul,ol {
<span style="white-spacere margin:0;
<span style="white-spacere margin-top:10px;
<span style="white-spacere padding:0;
<span style="white-spacere list-style:none;
}
pre {
border:1px solid #ccc;
<span style="white-spacere padding:15px;
}
.right {
<span style="white-spacere float:left;
<span style="white-spacere width:200px;
}
</style>
</head>
<body>
<form id="form1" runat="server
<h1>Google Health API - .NET Profile Read Sample</h1>
<%
GotoAuthSubLink.Visible = false;
if (Session["token"] != null)
{
PrintProfile();
}
else if (Request.QueryString["token"] != null)
{
String token = Request.QueryString["token"];
Session["token"] = AuthSubUtil.exchangeForSessionToken(token, null).ToString();
Response.Redirect(Request.Url.AbsolutePath, true);
}
else //no auth data, print link
{
GotoAuthSubLink.Text = "Login to your Google Account";
GotoAuthSubLink.Visible = true;
String authSubLink = AuthSubUtil.getRequestUrl("http", "www.google.com",
"/h9/authsub", Request.Url.ToString(), "https://www.google.com/h9/feeds/", false, true);
authSubLink += "&permission=1";
GotoAuthSubLink.NavigateUrl = authSubLink;
}
%>
<asp:HyperLink ID="GotoAuthSubLink" runat="server"/>
</form>
</body>
</html>
View the full article
<%@ Import Namespace="System.Text.RegularExpressions" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="Google.GData.Client" %>
<%@ Import Namespace="Google.GData.Health" %>
<%@ Import Namespace="Google.GData.Extensions" %>
<br/>
<script runat="server
<br/>
void PrintProfile() {
<br/>
GAuthSubRequestFactory authFactory = new GAuthSubRequestFactory("weaver", "exampleCo-exampleApp-1");
authFactory.Token = (String) Session["token"];
<br/>
HealthService service = new HealthService(authFactory.ApplicationName);
service.RequestFactory = authFactory;
HealthQuery profileQuery = new HealthQuery("https://www.google.com/h9/feeds/profile/default");
profileQuery.Digest = true;
<br/>
try
{
HealthFeed feed = service.Query(profileQuery);
foreach (HealthEntry entry in feed.Entries )
{
<span style="white-spacere XmlExtension ccrExt = (XmlExtension) entry.FindExtension("ContinuityOfCareRecord", "urn:astm-org:CCR");
<br/>
XmlDocument ccrXMLDoc = new XmlDocument();
ccrXMLDoc.ImportNode(ccrExt, true);
XmlNamespaceManager ccrNameManager = new XmlNamespaceManager(ccrXMLDoc.NameTable);
ccrNameManager.AddNamespace("ccr", "urn:astm-org:CCR");
<span style="white-spacere //use xpath to extract specific CCR elements
<span style="white-spacere XmlNodeList meds = ccrExt.Node.SelectNodes("//ccr:Body/ccr:Medications/ccr:Medication/ccrroduct/ccrroductName/ccr:Text", ccrNameManager);
<span style="white-spacere XmlNodeList conditions = ccrExt.Node.SelectNodes("//ccr:Body/ccrroblems/ccrroblem/ccrescription/ccr:Text", ccrNameManager);
<span style="white-spacere XmlNodeList allergies = ccrExt.Node.SelectNodes("//ccr:Body/ccr:Alerts/ccr:Alert/ccrescription/ccr:Text", ccrNameManager);
<span style="white-spacere XmlNodeList procedures = ccrExt.Node.SelectNodes("//ccr:Body/ccrrocedures/ccrrocedure/ccrescription/ccr:Text", ccrNameManager);
<span style="white-spacere XmlNodeList immunizations = ccrExt.Node.SelectNodes("//ccr:Body/ccr:Immunizations/ccr:Immunization/ccrroduct/ccrroductName/ccr:Text", ccrNameManager);
//XmlNodeList results = ccrExt.Node.SelectNodes("/Body/Results/Result/Test", ccrNameManager);
PrintElement(meds, "Your Medications");
<span style="white-spacere PrintElement(conditions, "Your Conditions");
<span style="white-spacere PrintElement(allergies, "Your Allergies");
<span style="white-spacere PrintElement(procedures, "Your Procedures");
<span style="white-spacere PrintElement(immunizations, "Your Immunizations");
XmlNode ccr = ccrExt;
<span style="white-spacere if (ccr != null)
{
Response.Write("<div style="clear:both; <h3>Entire profile</h3><pre>");
StringWriter sw = new StringWriter();
XmlTextWriter xw = new XmlTextWriter(sw);
xw.Formatting = Formatting.Indented;
ccr.WriteTo(xw);
Response.Write(HttpUtility.HtmlEncode(sw.ToString()));
Response.Write("[/code]");
}
}
}
catch (GDataRequestException gdre)
{
HttpWebResponse response = (HttpWebResponse)gdre.Response;
//bad auth token, clear session and refresh the page
if (response.StatusCode == HttpStatusCode.Unauthorized)
{
Session.Clear();
Response.Redirect(Request.Url.AbsolutePath, true);
}
else
{
Response.Write("Error processing request: " + gdre.ToString());
}
}
}
void PrintElement(XmlNodeList nodeList, String title) {
<span style="white-spacere Response.Write("<span class="right <b>" + title + "</b><ol>");
<span style="white-spacere foreach (XmlNode element in nodeList)
<span style="white-spacere {
<span style="white-spacere Response.Write("" + HttpUtility.HtmlEncode(element.InnerText) + "");
<span style="white-spacere }
<span style="white-spacere Response.Write("</ol>");
}
</script>
<br/>
<br/>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server
<title>Google Health API .NET - Profile Read Sample</title>
<style type="text/css
ul,ol {
<span style="white-spacere margin:0;
<span style="white-spacere margin-top:10px;
<span style="white-spacere padding:0;
<span style="white-spacere list-style:none;
}
pre {
border:1px solid #ccc;
<span style="white-spacere padding:15px;
}
.right {
<span style="white-spacere float:left;
<span style="white-spacere width:200px;
}
</style>
</head>
<body>
<form id="form1" runat="server
<h1>Google Health API - .NET Profile Read Sample</h1>
<%
GotoAuthSubLink.Visible = false;
if (Session["token"] != null)
{
PrintProfile();
}
else if (Request.QueryString["token"] != null)
{
String token = Request.QueryString["token"];
Session["token"] = AuthSubUtil.exchangeForSessionToken(token, null).ToString();
Response.Redirect(Request.Url.AbsolutePath, true);
}
else //no auth data, print link
{
GotoAuthSubLink.Text = "Login to your Google Account";
GotoAuthSubLink.Visible = true;
String authSubLink = AuthSubUtil.getRequestUrl("http", "www.google.com",
"/h9/authsub", Request.Url.ToString(), "https://www.google.com/h9/feeds/", false, true);
authSubLink += "&permission=1";
GotoAuthSubLink.NavigateUrl = authSubLink;
}
%>
<asp:HyperLink ID="GotoAuthSubLink" runat="server"/>
</form>
</body>
</html>
View the full article