Thanks for the input, I appreciate the help. It does look like your
method gets the information into a usable array. But it also looks
like you are using the "item(0)" again, which is the problem I was
trying to tackle at the beginning of this post. I'm not sure what the
problem with this is, but it sounded like Eric did not think this was
the proper way to grab the information from Google. Ideas as to how
the "item(0)" could be avoided, yet a similar result accomplished?
Again, my ultimate goal is to be able to implement something like:
echo "Test result: " . $name->nodeValue . " , Date: " . $date-
>nodeValue . "<br>";
Thanks.
On Jan 9, 3:43 am, Fred Trotter <[email protected]> wrote:
> Hey Josh,
> Looks like you are having some of the same types of issues I
> am. I am used to working in arrays, but now I am working with xpath,
> and it is very unfamliar. I have recently had an equivilent problem,
> and I think sharing it might help you solve yours....
>
> What follows is a way to get the Allergies information into a sensible
> array.
>
> foreach ($profileFeed->getEntries() as $entry) {
>
> $allergies = $entry->getCcr()->getAllergies()->item(0);
> $xpath = new DOMXpath($allergies->ownerDocument);
> $elements = $xpath->query("//ccr:Alerts/ccr:Alert/*");
> foreach($elements as $element){
> // echo $element->nodeName . " " . $element-
>
> >textContent . "<br>";
>
> if(strcmp($element->nodeName,'Type')== 0){
> $count++;
> }
>
> $results[$count][$element->nodeName] = $element->textContent;
>
> }
> }
>
> foreach($results as $result_array){
> $allergy_array[$result_array['Description']] =
> $result_array;
> }
>
> var_export($allergy_array);
>
> Note that the * matches everything under Alert, which means that I
> will loop over every sub-entry. I know that when I see "Type" that
> means I am in a new Alert. Which means by counting them I can separate
> the xml entries into separate php arrays.
>
> HTH,
> -FT
>
> On Jan 6, 10:52 pm, Josh <[email protected]> wrote:
>
>
>
> > Hi,
>
> > Thanks for the help. I am able to grab the Result description text
> > using your method, but how can I grab this and the Date together?
>
> > $tests = $entry->getCcr()->getResults();
> > foreach ($tests as $test) {
> > $xpath= new DOMXpath($test->ownerDocument);
> > $resultName = $xpath->query("//ccr:Results/ccr:Result/ccr:Test/
> > ccr:Description/ccr:Text");
> > //$resultDate = $xpath->query("//ccr:Results/ccr:Result/ccr:DateTime/
> > ccr:ExactDateTime");
> > foreach ($resultName as $name) {
> > echo "Test result: " . $name->nodeValue . "<br>";
> > }
> > }
>
> > I need to be able to implement something like:
> > echo "Test result: " . $name->nodeValue . " , Date: " . $date-
>
> > >nodeValue . "<br>";
>
> > How can I accomplish this? (Two separate "foreach" clauses cannot
> > bring the two data sets, Date and Name, together in the same spot.)
>
> > Thanks.
>
> > On Jan 6, 8:48 pm, Josh <[email protected]> wrote:
>
> > > Hi,
>
> > > Thanks for the help. I am able to grab the Result description text
> > > using your method, but how can I grab this and the Date together?
>
> > > $tests = $entry->getCcr()->getResults();
> > > foreach ($tests as $test) {
> > > $xpath= new DOMXpath($test->ownerDocument);
> > > $resultName = $xpath->query("//ccr:Results/ccr:Result/ccr:Test/
> > > ccr:Description/ccr:Text");
> > > //$resultDate = $xpath->query("//ccr:Results/ccr:Result/ccr:DateTime/
> > > ccr:ExactDateTime");
> > > foreach ($resultName as $name => $date) {
> > > echo "Test result: " . $name->nodeValue . "<br>";
> > > }
> > > }
>
> > > I need to be able to implement something like:
> > > echo "Test result: " . $name->nodeValue . " , Date: " . $date-
>
> > > >nodeValue . "<br>";
>
> > > How can I accomplish this? (Two separate "foreach" clauses cannot
> > > bring the two data sets, Date and Name, together in the same spot.)
>
> > > Thanks.
>
> > > On Jan 6, 2:05 pm, "Eric (Google)" <[email protected]> wrote:
>
> > > > Hi Josh,
>
> > > > You should not rely on the position of elements in the CCR data.
>
> > > > Instead, I would usexpathto extract the elements you're looking for:
> > > > foreach ($tests as $test) {
> > > > $xpath= new DOMXpath($test->ownerDocument);
> > > > $resultName = $xpath->query("//ccr:Results/ccr:Result/ccr:Test/
> > > > ccr:Description/ccr:Text");
> > > > foreach ($resultName as $name) {
> > > > echo "Test result: " . $name->nodeValue . "<br>";
> > > > }
>
> > > > }
>
> > > > On Jan 5, 5:54 pm, Josh <[email protected]> wrote:
>
> > > > > I am working on grabbing information from Google for use on my site,
> > > > > and I have a question about getting Test Results.
>
> > > > > For procedures and immunizations, I have been able to get the
> > > > > information using code similar to that seen below, except for the
> > > > > change in the first line's "getTest()" to the appropriate category,
> > > > > and the change in the third line's "Text" to Procedure and ProductName
> > > > > respectively.
>
> > > > > The difference that concerns me is the "item" number on line 3. For
> > > > > procedures and immunizations, "item(0)" worked fine. For Test Results,
> > > > > I have to use "item(1)". Is this stable code? Is the order of the
> > > > > Google CCR static, and will the item number remain consistent for
> > > > > grabbing the desired data? If yes, then I'll leave it as is. But if
> > > > > not, what is the better way to accomplish this?
>
> > > > > code fragment:
> > > > > $tests = $entry->getCcr()->getTest();
> > > > > foreach ($tests as $test) {
> > > > > $edesc =
> > > > > $test->getElementsByTagName("Text")->item(1)->nodeValue;
>
> > > > > $edate = $test->getElementsByTagName("ExactDateTime")->item
> > > > > (0)->nodeValue;
> > > > > echo $edesc.' on '.$edate;
> > > > > .........etc.........
>
> > > > > Thanks.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---