I didn't test it myself, but something like that should be fine.

Eric

On Jan 10, 6:23 pm, Josh <[email protected]> wrote:
> Is this a reasonable way to go about it?
>
>        $tests = $entry->getCcr()->getResults();
>        $testnames = array();
>        $testdates = array();
>        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");
>           $i = 0;
>           $j = 0;
>           foreach ($resultName as $name) {
>              $testnames[$i] = $name->nodeValue;
>              $i = $i + 1;
>           }
>           foreach ($resultDate as $date) {
>              $testdates[$j] = $date->nodeValue;
>              $j = $j + 1;
>           }
>        }
>        $testresults = array();
>        for ($z = 0; $z<=(count($testnames)-1); $z++) {
>             $testresults[$z] = array('name'=>$testnames[$z],'date'=>
> $testdates[$z]);
>        }
>
> //And then print out the results and dates
> foreach ($testresults as $test) {
>   echo "Test result: " . $test['name'] . ", Date: " . $test['date'];
>
> }
>
> On Jan 9, 10:49 am, "Eric (Google)" <[email protected]> wrote:
>
> > Hi Josh,
>
> > It's ok to use item(0) with the xpath approach.  I was discouraging
> > the
> > way you were finding the <Text> nodes with getElementsByTagName(),
> > since that would return all <Text> nodes in the CCR's section.
>
> > With xpath, you can be more procise.  I've posted a sample 
> > here:http://code.google.com/apis/health/docs/1.0/developers_guide_php.html...
>
> > Eric
>
> > On Jan 9, 8:10 am, Josh <[email protected]> wrote:
>
> > > 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to