Thanks Eric,
This code is very helpful but i have one problem; In the sample you sent me you
are using args from static void Main(string[] args) to findValue() of the pID.
I am using a GUI and my code is behind the login button and there is no main
method. How can i get the right args to use here?
My code is shown below:
private void Login_Click(object sender, System.EventArgs e)
{
this.service.setUserCredentials(this.Username.Text,
this.Password.Text);
this.authToken = this.service.QueryAuthenticationToken();
this.Close();
string pid = findValue(args, "pid", null);
string pname = findValue(args, "pname", null);
//HealthService service = new
HealthService("exampleCo-exampleApp-1");
//service.setUserCredentials("[email protected]",
"jakaveli");
GAuthSubRequestFactory authFactory = new
GAuthSubRequestFactory("weaver", "exampleCo-exampleApp-1");
HealthService service = new
HealthService(authFactory.ApplicationName);
service.RequestFactory = authFactory;
service.setUserCredentials("[email protected]",
"jakaveli");
AtomEntry newNotice = new AtomEntry();
newNotice.Title.Text = "A test message";
newNotice.Content.Content = "This is a test message.";
// Set the content type if you're using HTML in your message body
newNotice.Content.Type = "html";
String ccrXmlString = @"<ContinuityOfCareRecord
xmlns='urn:astm-org:CCR'>
<Body>
<Problems>
<Problem>
<DateTime>
<Type>
<Text>Start
date</Text>
</Type>
<ExactDateTime>2007-04-04T07:00:00Z</ExactDateTime>
</DateTime>
<DateTime>
<Type>
<Text>Stop
date</Text>
</Type>
<ExactDateTime>2008-07-20T07:00:00Z</ExactDateTime>
</DateTime>
<Description>
<Code>
<Value>346.80</Value>
<CodingSystem>ICD9</CodingSystem>
<Version>2004</Version>
</Code>
</Description>
<Status><Text>Active</Text></Status>
<Source>
<Actor>
<ActorID>Harris
Smith</ActorID>
<ActorRole>
<Text>Treating
clinician</Text>
</ActorRole>
</Actor>
</Source>
</Problem>
</Problems>
</Body>
</ContinuityOfCareRecord>";
XmlDocument ccrDoc = new XmlDocument();
ccrDoc.LoadXml(ccrXmlString);
newNotice.ExtensionElements.Add(new
XmlExtension(ccrDoc.DocumentElement));
//service.Insert(new
Uri("https://www.google.com/health/feeds/register/default"), newNotice);
//service.Insert(new
Uri("https://www.google.com/h9/feeds/register/ui/profileID"), newNotice);
if (pid == null && pname != null)
{
// need to find the ID first.
// so we get the list feed, find the name in the TITLE, and
then
// get the ID out of the content field
HealthFeed feed = service.Query(new
HealthQuery(HealthQuery.ProfileListFeed));
foreach (AtomEntry entry in feed.Entries)
{
if (entry.Title.Text == pname)
{
pid = entry.Content.Content;
}
}
}
try
{
//service.Insert(new
Uri("https://www.google.com/h9/feeds/register/default"), newNotice);
service.Insert(new
Uri("https://www.google.com/h9/feeds/register/ui/profileID"), newNotice);
}
catch (GDataRequestException err)
{
MessageBox.Show(err.ResponseString);
//MessageBox.Show(err.);
//err.Response.GetResponseStream();
//err.Response.GetType();
}
//HealthQuery profileQuery = new
HealthQuery("https://www.google.com/health/feeds/profile/default");
//HealthQuery profileQuery = new
HealthQuery("https://www.google.com/h9/feeds/profile/default");
HealthQuery profileQuery = new
HealthQuery("https://www.google.com/h9/feeds/profile/ui/profileID");
profileQuery.Digest = true;
// returns a single <atom:entry> containing the user's CCR
try
{
HealthFeed feed = service.Query(profileQuery);
foreach (HealthEntry entry in feed.Entries)
{
XmlNode ccr = (XmlExtension)
entry.FindExtension("ContinuityOfCareRecord", "urn:astm-org:CCR");
if (ccr != null)
{
System.Web.HttpContext.Current.Response.Write("<pre>");
StringWriter sw = new StringWriter();
XmlTextWriter xw = new XmlTextWriter(sw);
xw.Formatting = Formatting.Indented;
ccr.WriteTo(xw);
System.Web.HttpContext.Current.Response.Write(HttpUtility.HtmlEncode(sw.ToString()));
System.Web.HttpContext.Current.Response.Write("</pre>");
Console.WriteLine("ccr is not null");
}
}
}
catch (GDataRequestException err)
{
MessageBox.Show(err.ResponseString);
}
}
Thanks very much in advance for any help,
Aidan.
----- Original Message -----
From: "Eric (Google)" <[email protected]>
To: "Google Health Developers" <[email protected]>
Sent: Tuesday, 3 March, 2009 01:02:16 GMT +00:00 GMT Britain, Ireland, Portugal
Subject: [Google-Health-API] Re: GDataRequestException in .Net
See the sample app for some hints:
http://code.google.com/p/google-gdata/source/browse/trunk/clients/cs/samples/health/main.cs#100
Eric
On Mar 2, 4:13 am, Aidan P Calnan
<[email protected]> wrote:
> Thanks Eric,
>
> I have replaced //service.Insert(new
> Uri("https://www.google.com/h9/feeds/register/default"), newNotice);
> with service.Insert(new
> Uri("https://www.google.com/h9/feeds/register/ui/profileID"), newNotice);
> in my code and i am getting the same exceptions. I know i have to get the
> profile ID for a particular user by querying the profile/list feed but I am
> unsure of how and where to do this in my code. Thanks again in advance for
> any help.
>
> Thanks,
> Aidan.
>
> ----- Original Message -----
> From: "Eric (Google)" <[email protected]>
> To: "Google Health Developers" <[email protected]>
> Sent: Monday, 2 March, 2009 07:01:39 GMT +00:00 GMT Britain, Ireland, Portugal
> Subject: [Google-Health-API] Re: GDataRequestException in .Net
>
> Since you're using ClientLogin, use the /ui
> feeds:http://code.google.com/apis/health/docs/2.0/reference.html#ClientLogi...
>
> First use the profile/list feed to obtain a particular profile's id,
> and then use the /register/ui/profileID or /profile/ui/profileID
> feeds as needed.
>
> Eric
>
> On Mar 1, 6:18 am, Dub---C <[email protected]>
> wrote:
> > Hi All,
>
> > I am trying to do a basic retrieve and update of ccr data to a
> > profile
> > on google health. i am getting the following: A first chance
> > exception
> > of type 'Google.GData.Client.GDataRequestException' occurred in
> > Google.GData.Client.dll
>
> > my code is shown below: thanks very much in advance to any1 who can
> > see my problem.
>
> > HealthService service = new HealthService("exampleCo-exampleApp-1");
> > service.setUserCredentials
> > ("username", "password");
>
> > AtomEntry newNotice = new AtomEntry();
> > newNotice.Title.Text = "A test message";
> > newNotice.Content.Content = "This is a test message.";
> > // Set the content type if you're using HTML in your
> > message body
> > //newNotice.Content.Type = "html";
> > String ccrXmlString = @"<ContinuityOfCareRecord
> > xmlns='urn:astm-org:CCR'>
> > <Body>
> > <Problems>
> > <Problem>
>
> > <DateTime>
>
> > <Type>
>
> > <Text>Start date</Text>
> > </
> > Type>
>
> > <ExactDateTime>2007-04-04T07:00:00Z</ExactDateTime>
> > </
> > DateTime>
>
> > <DateTime>
>
> > <Type>
>
> > <Text>Stop
> > date</Text>
> > </
> > Type>
>
> > <ExactDateTime>2008-07-20T07:00:00Z</ExactDateTime>
> > </
> > DateTime>
>
> > <Description>
>
> > <Code>
>
> > <Value>346.80</Value>
>
> > <CodingSystem>ICD9</CodingSystem>
>
> > <Version>2004</Version>
> > </
> > Code>
> > </
> > Description>
>
> > <Status><Text>Active</Text></Status>
>
> > <Source>
>
> > <Actor>
>
> > <ActorID>Harris Smith</ActorID>
>
> > <ActorRole>
>
> > <Text>Treating clinician</Text>
> > </
> > ActorRole>
> > </
> > Actor>
> > </
> > Source>
> > </Problem>
> > </Problems>
> > </Body>
> > </ContinuityOfCareRecord>";
> > XmlDocument ccrDoc = new XmlDocument();
> > ccrDoc.LoadXml(ccrXmlString);
> > newNotice.ExtensionElements.Add(new XmlExtension
> > (ccrDoc.DocumentElement));
> > //service.Insert(new Uri("https://www.google.com/health/
> > feeds/register/default"), newNotice);
> > try
> > {
> > service.Insert(new Uri("https://www.google.com/h9/
> > feeds/register/default"), newNotice);
> > }
> > catch (GDataRequestException err)
> > {
> > }
>
> > //HealthQuery profileQuery = new
> > HealthQuery("https://www.google.com/health/feeds/profile/default");
> > HealthQuery profileQuery = new
> > HealthQuery("https://www.google.com/h9/feeds/profile/default");
> > profileQuery.Digest = true;
> > // returns a single <atom:entry> containing the user's
> > CCR
> > try
> > {
> > HealthFeed feed = service.Query(profileQuery);
> > foreach (HealthEntry entry in feed.Entries)
> > {
> > XmlNode ccr = (XmlExtension) entry.FindExtension
> > ("ContinuityOfCareRecord", "urn:astm-org:CCR");
> > if (ccr != null)
> > {
> > System.Web.HttpContext.Current.Response.Write
> > ("<pre>");
> > StringWriter sw = new StringWriter();
> > XmlTextWriter xw = new XmlTextWriter
> > (sw);
> > xw.Formatting = Formatting.Indented;
> > ccr.WriteTo(xw);
> > System.Web.HttpContext.Current.Response.Write
> > (HttpUtility.HtmlEncode(sw.ToString()));
> > System.Web.HttpContext.Current.Response.Write
> > ("</pre>");
>
> > Console.WriteLine("ccr is not null");
> > }
> > }
> > }
> > catch (GDataRequestException err)
> > {
> > }
>
> > thanks very much in advance to any1 who can see my problem.
>
> --------------------------------------------------------------------------
> Ta an r-phost seo fe reir an tseanta / na seanta seo leanas ata le fail ag
> This e-mail is subject to the following disclaimer(s) available at
>
> http://www.ittralee.ie/EmailDisclaimer.html
>
> Smaoinigh ar an dtimpeallacht sula bpriontaileann tu an r-phost seo
> Please consider the environment before printing this e-mail
> --------------------------------------------------------------------------
>
>
--------------------------------------------------------------------------
Ta an r-phost seo fe reir an tseanta / na seanta seo leanas ata le fail ag
This e-mail is subject to the following disclaimer(s) available at
http://www.ittralee.ie/EmailDisclaimer.html
Smaoinigh ar an dtimpeallacht sula bpriontaileann tu an r-phost seo
Please consider the environment before printing this e-mail
--------------------------------------------------------------------------
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Health Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/googlehealthdevelopers?hl=en
-~----------~----~----~----~------~----~------~--~---