Cannot retrieve blood pressure value

Aug 8, 2013 at 3:23 PM
Hi robmay, i was ablse to put bloodpressure data but was not able to get it, below is my code for retrieving systolic value from bloodpressure, am i missing something??

private List<String> getBP()
{
    Record record = selectedRecord;

    SimpleRequestTemplate template = new SimpleRequestTemplate(
            service.getConnection(),
            record.getPersonId(),
            record.getId());

    String info = "<info><group max=\"5\"><filter><type-id>" +
        BloodPressure.TYPE +
        "</type-id></filter><format><section>core</section>" +
        "<xml/></format></group></info>";

    Request request = new Request();
    request.setMethodName("GetThings");
    request.setInfo(info);

    return (List<String>)template.makeRequest(request, new RequestMarshaller() {
        public Object marshal(InputStream istream) throws Exception {
            XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
            factory.setNamespaceAware(false);
            XmlPullParser parser= factory.newPullParser();    
            parser.setInput(istream, "utf8");

            XmlUtils.nextStartTag(parser, "response");
            XmlUtils.nextStartTag(parser, "status");
            XmlUtils.skipSubTree(parser);
            XmlUtils.nextStartTag(parser, "wc:info");
            XmlUtils.nextStartTag(parser, "group");

            List<String> systolic = new ArrayList<String>();
            List<String> diastolic = new ArrayList<String>();
            List<String> pulse = new ArrayList<String>();

            while (parser.nextTag() == XmlPullParser.START_TAG) {
              if ("thing".equals(parser.getName())) {
                  int thingDepth = parser.getDepth();
                  while (parser.nextTag() == XmlPullParser.START_TAG
                          && parser.getDepth() > thingDepth) {
                      if ("data-xml".equals(parser.getName()))
                      {
                          int dataXmlDepth = parser.getDepth();
                          while (parser.nextTag() == XmlPullParser.START_TAG
                                  && parser.getDepth() > dataXmlDepth) {
                              if ("systolic".equals(parser.getName())) {
                                  systolic.add(
                                      String.valueOf(Weight.createFromXml(parser).getValue()));
                              }
// else if ("diastolic".equals(parser.getName())) {
// diastolic.add(
// String.valueOf(Weight.createFromXml(parser).getValue()));
// }
// else if ("pulse".equals(parser.getName())) {
// pulse.add(
// String.valueOf(Weight.createFromXml(parser).getValue()));
// }
                              else {
                                  XmlUtils.skipSubTree(parser);
                              }
                          }
                      }
                      else
                      {
                          XmlUtils.skipSubTree(parser);
                      }
                  }
              } else {
                 XmlUtils.skipSubTree(parser);
              }
            }

            return systolic;

        }
    });
}
and this is my BloodPressure Class
package com.sanjan.trackhealth;

import java.util.Calendar;

import org.xmlpull.v1.XmlPullParser;

import android.R.string;

import com.microsoft.hsg.HVException;
import com.microsoft.hsg.android.XmlUtils;

public class BloodPressure {
public static String TYPE = "ca3c57f4-f4c1-4e15-be67-0a3caf5414ed";

private Calendar calendar;

private int systolicValue, diastolicValue,pulse;


public BloodPressure(int systolicValue, int diastolicValue, int pulse)
{
    calendar = Calendar.getInstance();
    this.systolicValue = systolicValue;
    this.diastolicValue=diastolicValue;
    this.pulse=pulse;
}

//public double getValue() {
  //  return value;
//}

public String toXml()
{    
    StringBuilder infoBuilder = new StringBuilder(256);
    infoBuilder.append("<blood-pressure><when><date><y>");
    infoBuilder.append(calendar.get(Calendar.YEAR));
    infoBuilder.append("</y><m>");
    infoBuilder.append(calendar.get(Calendar.MONTH) + 1);
    infoBuilder.append("</m><d>");
    infoBuilder.append(calendar.get(Calendar.DATE));
    infoBuilder.append("</d></date><time><h>");
    infoBuilder.append(calendar.get(Calendar.HOUR_OF_DAY));
    infoBuilder.append("</h><m>");
    infoBuilder.append(calendar.get(Calendar.MINUTE));
    infoBuilder.append("</m><s>");
    infoBuilder.append(calendar.get(Calendar.SECOND));
    infoBuilder.append("</s></time></when><systolic>");
    infoBuilder.append(systolicValue);
    infoBuilder.append("</systolic><diastolic>");
    infoBuilder.append(diastolicValue);
    infoBuilder.append("</diastolic><pulse>");
    infoBuilder.append(pulse);
    infoBuilder.append("</pulse><irregular-heartbeat>false</irregular-heartbeat>");
    infoBuilder.append("</blood-pressure>");

    return infoBuilder.toString();
}

public static BloodPressure createFromXml(XmlPullParser parser) throws Exception
{
    String systolic = "";
    String diastolic = "";
    String pulse = "";
    //string systolicValue, diastolicValue, pulse;
    int depth = parser.getDepth();
    while (parser.nextTag() == XmlPullParser.START_TAG
        && parser.getDepth() > depth) {
        if ("value".equals(parser.getName())) {
            int valueDepth = parser.getDepth();
            while (parser.nextTag() == XmlPullParser.START_TAG
                    && parser.getDepth() > valueDepth) {
                if ("systolic".equals(parser.getName())) {
                    systolic = parser.nextText();
                }
                else if ("diastolic".equals(parser.getName())) {
                    diastolic = parser.nextText();
                }
                else if ("pulse".equals(parser.getName())) {
                    pulse = parser.nextText();
                }
                else {
                    XmlUtils.skipSubTree(parser);
                }
            }
        }
        else {
            XmlUtils.skipSubTree(parser);
        }
    }
    //return null;

    return new BloodPressure(Integer.parseInt(systolic),Integer.parseInt(diastolic),Integer.parseInt(pulse));
}
}

can you help me, thanks
Coordinator
Aug 8, 2013 at 9:22 PM
This code doesn't look quite right:
if ("systolic".equals(parser.getName())) {
                                  systolic.add(
                                      String.valueOf(Weight.createFromXml(parser).getValue()));
Don't you mean BloodPressure.createFromXml(...)?

--Rob
Aug 9, 2013 at 3:04 AM
yeah i missed that, but still i cant retrieve anything, and i did uncomment the getvalue() function that should be working.
Aug 9, 2013 at 3:40 AM
hi robmay, thanks for pointing that out. i did some work and i found out that the layout of the bloodpressure xml is a bit different that the weight thing, so i modified my getBP() method and BloodPressure class, but i still cannot get any value, i get the "could not marshal response" error message thanks

private List<String> getBP()
{
    Record record = selectedRecord;

    SimpleRequestTemplate template = new SimpleRequestTemplate(
            service.getConnection(),
            record.getPersonId(),
            record.getId());

    String info = "<info><group max=\"5\"><filter><type-id>" +
        BloodPressure.TYPE +
        "</type-id></filter><format><section>core</section>" +
        "<xml/></format></group></info>";

    Request request = new Request();
    request.setMethodName("GetThings");
    request.setInfo(info);

    return (List<String>)template.makeRequest(request, new RequestMarshaller() {
        public Object marshal(InputStream istream) throws Exception {
            XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
            factory.setNamespaceAware(false);
            XmlPullParser parser= factory.newPullParser();    
            parser.setInput(istream, "utf8");

            XmlUtils.nextStartTag(parser, "response");
            XmlUtils.nextStartTag(parser, "status");
            XmlUtils.skipSubTree(parser);
            XmlUtils.nextStartTag(parser, "wc:info");
            XmlUtils.nextStartTag(parser, "group");

            List<String> systolic = new ArrayList<String>();

            while (parser.nextTag() == XmlPullParser.START_TAG) {
              if ("thing".equals(parser.getName())) {
                  int thingDepth = parser.getDepth();
                  while (parser.nextTag() == XmlPullParser.START_TAG
                          && parser.getDepth() > thingDepth) {
                      if ("data-xml".equals(parser.getName()))
                      {
                          int dataXmlDepth = parser.getDepth();
                          while (parser.nextTag() == XmlPullParser.START_TAG
                                  && parser.getDepth() > dataXmlDepth) {
                              if ("blood-pressure".equals(parser.getName())) {
                                  systolic.add(
                                      String.valueOf(BloodPressure.createFromXml(parser).getValue()));
                              }
                              else {
                                  XmlUtils.skipSubTree(parser);
                              }
                          }
                      }
                      else
                      {
                          XmlUtils.skipSubTree(parser);
                      }
                  }
              } else {
                 XmlUtils.skipSubTree(parser);
              }
            }
            systolic.add("55");
            return systolic;

        }
    });
} 

and my BloodPressure class


package com.sanjan.trackhealth;

import java.util.Calendar;

import org.xmlpull.v1.XmlPullParser;

import android.R.string;

import com.microsoft.hsg.HVException;
import com.microsoft.hsg.android.XmlUtils;

public class BloodPressure {
public static String TYPE = "ca3c57f4-f4c1-4e15-be67-0a3caf5414ed";

private Calendar calendar;

private int systolicValue, diastolicValue,pulse;


public BloodPressure(int systolicValue, int diastolicValue, int pulse)
{
    calendar = Calendar.getInstance();
    this.systolicValue = systolicValue;
    this.diastolicValue=diastolicValue;
    this.pulse=pulse;
}

public int getValue() {
    return systolicValue;
}

public String toXml()
{    
    StringBuilder infoBuilder = new StringBuilder(256);
    infoBuilder.append("<blood-pressure><when><date><y>");
    infoBuilder.append(calendar.get(Calendar.YEAR));
    infoBuilder.append("</y><m>");
    infoBuilder.append(calendar.get(Calendar.MONTH) + 1);
    infoBuilder.append("</m><d>");
    infoBuilder.append(calendar.get(Calendar.DATE));
    infoBuilder.append("</d></date><time><h>");
    infoBuilder.append(calendar.get(Calendar.HOUR_OF_DAY));
    infoBuilder.append("</h><m>");
    infoBuilder.append(calendar.get(Calendar.MINUTE));
    infoBuilder.append("</m><s>");
    infoBuilder.append(calendar.get(Calendar.SECOND));
    infoBuilder.append("</s></time></when><systolic>");
    infoBuilder.append(systolicValue);
    infoBuilder.append("</systolic><diastolic>");
    infoBuilder.append(diastolicValue);
    infoBuilder.append("</diastolic><pulse>");
    infoBuilder.append(pulse);
    infoBuilder.append("</pulse><irregular-heartbeat>false</irregular-heartbeat>");
    infoBuilder.append("</blood-pressure>");

    return infoBuilder.toString();
}

public static BloodPressure createFromXml(XmlPullParser parser) throws Exception
{
    String systolic = "";
    String diastolic = "";
    String pulse = "";

    int depth = parser.getDepth();
    while (parser.nextTag() == XmlPullParser.START_TAG
        && parser.getDepth() > depth) {
        if ("systolic".equals(parser.getName())) {

                    systolic = parser.nextText();
                }
                else {
                    XmlUtils.skipSubTree(parser);
                }
            }

    return new BloodPressure(Integer.parseInt(systolic),Integer.parseInt(diastolic),Integer.parseInt(pulse));
}
}


i modified the createFromXml methodand the getBP method, can you find any errors here please, thanks in advance.
Aug 22, 2013 at 10:31 AM
Edited Aug 22, 2013 at 10:43 AM
Hi
This code is Working Fine for me

Note- If you Want to see what will be the Response of Your blood pressure Request. Just go Flow the process
  1. login in Health vaulth
  2. Add Blood pressure Data
  3. Click on Blood Pressure
  4. Click on "Details" At right corner
  5. Click on "View as XML"
// Method To get Blood pressure Data




public class GetHVData {

public static List<BloodPressureData> RBP;
public static List<BloodPressureData> getBP(Record selectedRecord,HealthVaultService service)
    {

         RBP = new ArrayList<BloodPressureData>();

             // create object of BloodPressure class which contain Actual Parsing logic

        final BloodPressure mBloodPressure = new BloodPressure();

        Record record = selectedRecord;

        SimpleRequestTemplate template = new SimpleRequestTemplate(
                service.getConnection(),
                record.getPersonId(),
                record.getId());

        String info = "<info><group max=\"20\"><filter><type-id>" +
            "ca3c57f4-f4c1-4e15-be67-0a3caf5414ed" +
            "</type-id></filter><format><section>core</section>" +
            "<xml/></format></group></info>";

        Request request = new Request();
        request.setMethodName("GetThings");
        request.setInfo(info);

        return (List<String>)template.makeRequest(request, new RequestMarshaller() {
            public Object marshal(InputStream istream) throws Exception {
                XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
                factory.setNamespaceAware(false);
                XmlPullParser parser= factory.newPullParser();    
                parser.setInput(istream, "utf8");

                XmlUtils.nextStartTag(parser, "response");
                XmlUtils.nextStartTag(parser, "status");
                XmlUtils.skipSubTree(parser);
                XmlUtils.nextStartTag(parser, "wc:info");
                XmlUtils.nextStartTag(parser, "group");

                List<String> systolic = new ArrayList<String>();

                while (parser.nextTag() == XmlPullParser.START_TAG) {
                  if ("thing".equals(parser.getName())) {
                      int thingDepth = parser.getDepth();
                      while (parser.nextTag() == XmlPullParser.START_TAG
                              && parser.getDepth() > thingDepth) {
                          if ("data-xml".equals(parser.getName()))
                          {
                              int dataXmlDepth = parser.getDepth();
                              while (parser.nextTag() == XmlPullParser.START_TAG
                                      && parser.getDepth() > dataXmlDepth) {
                                  if ("blood-pressure".equals(parser.getName())) {


                                      List<BloodPressureData> lBP = mBloodPressure.createFromBloodPressureXml(parser);


                                      for(int i=0;i<lBP.size();i++){

                                          RBP.add(new BloodPressureData(lBP.get(i).getYear(),lBP.get(i).getMonth(),
                                                  lBP.get(i).getDate(),lBP.get(i).getHour(),lBP.get(i).getSystolic(),
                                                  lBP.get(i).getDiastolic(),lBP.get(i).getPulse()
                                            ));
                                                        }

                                  }
                                  else {
                                      XmlUtils.skipSubTree(parser);
                                  }
                              }
                          }
                          else
                          {
                              XmlUtils.skipSubTree(parser);
                          }
                      }
                  } else {
                     XmlUtils.skipSubTree(parser);
                  }
                }

          // Print the month value here
                for(int i=0;i<RBP.size();i++){

                  Log.d("DATE", RBP.get(i).getMonth()+"");

              }


                return RBP;

            }
        });


    } 
} // end of class
    //  Parse Health vault Blood pressure Data One By One 


    public class BloodPressure {

public BloodPressure(){

}

BloodPressureData mBloodPressureData = new BloodPressureData();

private  List<BloodPressureData> lBP = new ArrayList<BloodPressureData>();

public List<BloodPressureData> createFromBloodPressureXml(
        XmlPullParser parser) throws Exception {
    String value = "";
    lBP.clear();
    int depth = parser.getDepth();
    while (parser.nextTag() == XmlPullParser.START_TAG
            && parser.getDepth() > depth) {
        if ("when".equals(parser.getName())) {
            int whenDepth = parser.getDepth();
            while (parser.nextTag() == XmlPullParser.START_TAG
                    && parser.getDepth() > whenDepth) {
                if ("date".equals(parser.getName())) {

                    int dateDepth = parser.getDepth();

                    while (parser.nextTag() == XmlPullParser.START_TAG
                            && parser.getDepth() > dateDepth) {

                        if ("y".equals(parser.getName())) {



                            mBloodPressureData.setYear(Integer.parseInt(parser.nextText()));



                        } else if ("m".equals(parser.getName())) {
                            mBloodPressureData.setMonth(Integer.parseInt(parser.nextText()));

                        } else if ("d".equals(parser.getName())) {
                            mBloodPressureData.setDate(Integer.parseInt(parser.nextText()));

                        } else {
                            XmlUtils.skipSubTree(parser);
                        }

                    }
                    // value = parser.nextText();
                } else if ("time".equals(parser.getName())) {

                    int timeDepth = parser.getDepth();

                    while (parser.nextTag() == XmlPullParser.START_TAG
                            && parser.getDepth() > timeDepth) {

                        if ("h".equals(parser.getName())) {
                            mBloodPressureData.setHour(Integer.parseInt(parser.nextText()));


                        } else {
                            XmlUtils.skipSubTree(parser);
                        }

                    }

                } else {
                    XmlUtils.skipSubTree(parser);
                }
            }
        } else if ("systolic".equals(parser.getName())) {
                             // here we get systolic value
            mBloodPressureData.setSystolic(Integer.parseInt(parser.nextText()));

        } else if ("diastolic".equals(parser.getName())) {
            mBloodPressureData.setDiastolic(Integer.parseInt(parser.nextText()));
        } else if ("pulse".equals(parser.getName())) {
            mBloodPressureData.setPulse(Integer.parseInt(parser.nextText()));
        } else {
            XmlUtils.skipSubTree(parser);
        }
    }

    lBP.add(new BloodPressureData(mBloodPressureData.getYear(),
            mBloodPressureData.getMonth(), mBloodPressureData.getDate(),
            mBloodPressureData.getHour(), mBloodPressureData.getSystolic(),
            mBloodPressureData.getDiastolic(), mBloodPressureData
                    .getPulse()));

    return lBP;
}


// Get Set Method For Blood Pressure Data


public class BloodPressureData {

int year;
int month;
int date;
int hour;
double systolic;
double diastolic;
double pulse;

public BloodPressureData(){

     year = 0;
     month = 0;
     date = 0;
     hour = 0;
     systolic = 0;
     diastolic = 0;
     pulse = 0;

}

public void clear(){
     year = 0;
     month = 0;
     date = 0;
     hour = 0;
     systolic = 0;
     diastolic = 0;
     pulse = 0;
}

public BloodPressureData(int year, int month, int date, int hour,
        double systolic, double diastolic, double pulse) {
    super();
    this.year = year;
    this.month = month;
    this.date = date;
    this.hour = hour;
    this.systolic = systolic;
    this.diastolic = diastolic;
    this.pulse = pulse;
}

public int getYear() {
    return year;
}

public void setYear(int year) {
    this.year = year;
}

public int getMonth() {
    return month;
}

public void setMonth(int month) {
    this.month = month;
}

public int getDate() {
    return date;
}

public void setDate(int date) {
    this.date = date;
}

public int getHour() {
    return hour;
}

public void setHour(int hour) {
    this.hour = hour;
}

public double getSystolic() {
    return systolic;
}

public void setSystolic(double systolic) {
    this.systolic = systolic;
}

public double getDiastolic() {
    return diastolic;
}

public void setDiastolic(double diastolic) {
    this.diastolic = diastolic;
}

public double getPulse() {
    return pulse;
}

public void setPulse(double pulse) {
    this.pulse = pulse;
}



}
Aug 29, 2013 at 11:33 AM
thanks santosh390, i was able to get the bloodpressure data, but now using the same logic i cannot get the weight data, it gives could not marshall response error.

is there something wrong with this method:

private List<Weight> lBP = new ArrayList<Weight>();
public List<Weight> createFromXml(XmlPullParser parser) throws Exception
{
    String value = "";

    int depth = parser.getDepth();
    while (parser.nextTag() == XmlPullParser.START_TAG
        && parser.getDepth() > depth) {
         if ("when".equals(parser.getName())) {
             int whenDepth = parser.getDepth();
             while (parser.nextTag() == XmlPullParser.START_TAG
                     && parser.getDepth() > whenDepth) {
                 if ("date".equals(parser.getName())) {

                     int dateDepth = parser.getDepth();

                     while (parser.nextTag() == XmlPullParser.START_TAG
                             && parser.getDepth() > dateDepth) {

                         if ("y".equals(parser.getName())) {
                             year=(Integer.parseInt(parser.nextText()));
                         } else if ("m".equals(parser.getName())) {
                             month=(Integer.parseInt(parser.nextText()));
                         } else if ("d".equals(parser.getName())) {
                             date=(Integer.parseInt(parser.nextText()));
                         } else {
                             XmlUtils.skipSubTree(parser);
                         }
                     }
                 }  else {
                     XmlUtils.skipSubTree(parser);
                 }
             }
         } else if("value".equals(parser.getName())) {
           int valueDepth = parser.getDepth();
           while (parser.nextTag() == XmlPullParser.START_TAG
                   && parser.getDepth() > valueDepth) {
               if ("kg".equals(parser.getName())) {
                   value = parser.nextText();
               }
               else {
                   XmlUtils.skipSubTree(parser);
               }
           }    
         }
         else {
             XmlUtils.skipSubTree(parser);
         }
     }

     lBP.add(new Weight(year,month,date,hour,Integer.parseInt(value)));
    return lBP;
}
}
Sep 4, 2013 at 6:13 PM
Hi eakstickpiya



could not marshall response error means Error in your Parsing code,

also check your Type id(for weight = 3d34d87e-7fc1-4153-800f-f56592cb0d17) in

String info = "<info><group max=\"5\"><filter><type-id>" +
    BloodPressure.TYPE +
    "</type-id></filter><format><section>core</section>" +
    "<xml/></format></group></info>";
You can print your response using below code, And try to write code according to response

String _str = convertStreamToString(
                    istream).toString());
            St = St.replaceAll("\"", "\\\"");
            Log.d("parseString", _str)


public static String convertStreamToString(InputStream is) {
    Scanner s = new Scanner(is).useDelimiter("\\A");
    return s.hasNext() ? s.next() : "";
}

It also possible The application you are using has not been authorized for weight

For your app-id, go to https://config.healthvault-ppe.com and edit the offline rules to include the type-ids your application needs. It may take up to 20 minutes for the change to take affect. You will also need to reauthorize your application -- the use needs to accept the new permissions. In your case, it's easiest to clear your application from your device and start over so that the user will authorize it again.