HB A1C Invalid xml

Oct 24, 2011 at 1:23 PM

Hi,

I was trying sync HB A1C with HealthVault but I got the following exception.

 

com.microsoft.hsg.HVInvalidXmlException: Invalid xml for thing. The element 'HbA1C' in namespace 'urn:com.microsoft.wc.thing.HbA1C' has invalid child element 'value'. List of possible elements expected: 'when'. -- The element 'HbA1C' in namespace 'urn:com.microsoft.wc.thing.HbA1C' has invalid child element 'value'. List of possible elements expected: 'when'.
	at com.microsoft.hsg.DefaultResponseCodeTranslator.translate(DefaultResponseCodeTranslator.java:54)
	at com.microsoft.hsg.DefaultResponseStrategy.checkResponseCode(DefaultResponseStrategy.java:96)
	at com.microsoft.hsg.DefaultResponseStrategy.doWithResponse(DefaultResponseStrategy.java:87)
	at com.microsoft.hsg.HVAccessor$1$1.handleResponse(HVAccessor.java:104)
	at com.microsoft.hsg.URLConnectionTransport.doRequest(URLConnectionTransport.java:57)
	at com.microsoft.hsg.Connection.makeRequest(Connection.java:195)
	at com.microsoft.hsg.Connection.send(Connection.java:156)
	at com.microsoft.hsg.HVAccessor$1.send(HVAccessor.java:101)
	at com.microsoft.hsg.DefaultSendStrategy.doWithSender(DefaultSendStrategy.java:36)
	at com.microsoft.hsg.HVAccessor.send(HVAccessor.java:99)
	at com.microsoft.hsg.request.SimpleRequestTemplate.makeRequest(SimpleRequestTemplate.java:141)
	at com.microsoft.hsg.methods.jaxb.SimpleRequestTemplate.makeRequest(SimpleRequestTemplate.java:69)
	at com.microsoft.hsg.methods.jaxb.SimpleRequestTemplate.makeRequest(SimpleRequestTemplate.java:38)
	at com.microsoft.hsg.jaxb.PutThingsTest.PutThing(PutThingsTest.java:61)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:66)
	at org.jmock.integration.junit4.JMock$1.invoke(JMock.java:37)
	at org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:105)
	at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:86)
	at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:94)
	at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:84)
	at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:49)
	at org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:96)
	at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:59)
	at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:52)
	at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:34)
	at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:44)
	at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:50)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

 

Response from HealthVault

DEBUG - ResponseStrategy           - <!--?xml version="1.0" encoding="utf-8"?-->3Invalid xml for thing. The element 'HbA1C' in namespace 'urn:com.microsoft.wc.thing.HbA1C' has invalid child element 'value'. List of possible elements expected: 'when'. -- The element 'HbA1C' in namespace 'urn:com.microsoft.wc.thing.HbA1C' has invalid child element 'value'. List of possible elements expected: 'when'.failed-item-index=0

My Test code:

package com.microsoft.hsg.jaxb;

import junit.framework.Assert;

import org.jmock.Mockery;
import org.jmock.integration.junit4.JMock;
import org.jmock.integration.junit4.JUnit4Mockery;
import org.jmock.lib.legacy.ClassImposteriser;
import org.junit.Test;
import org.junit.runner.RunWith;

import com.microsoft.hsg.ConnectionFactory;
import com.microsoft.hsg.methods.jaxb.SimpleRequestTemplate;
import com.microsoft.hsg.methods.jaxb.putthings.request.PutThingsRequest;
import com.microsoft.hsg.methods.jaxb.putthings.response.PutThingsResponse;
import com.microsoft.hsg.thing.oxm.jaxb.hba1x.HbA1C;
import com.microsoft.hsg.thing.oxm.jaxb.thing.Thing;

@RunWith(JMock.class)
public class PutThingsTest {
	

	private Mockery context = new JUnit4Mockery() {{
        setImposteriser(ClassImposteriser.INSTANCE);
    }};

	/**
     * Create the test case
     *
     */
    public PutThingsTest()
    {
    }
    
    @Test
    public void PutThing() throws Exception
    {
    	SimpleRequestTemplate requestTemplate = new SimpleRequestTemplate(
    			ConnectionFactory.getConnection());
    	requestTemplate.setPersonId("b84ea658-d48b-4c8a-acc6-f903c0394ed6");
    	requestTemplate.setRecordId("0ddd8062-26e6-4acb-858a-ee77d678b759");
    	
    	HbA1C a1c = new HbA1C();
    	a1c.setValue(20.0);
    	
    	Thing thing = new Thing();
    	thing.setData(a1c);
    	
    	PutThingsRequest request = new PutThingsRequest();
    	request.getThing().add(thing);
    	
    	PutThingsResponse response = (PutThingsResponse)requestTemplate.makeRequest(request);
    	
    	Assert.assertNotNull(response);
    }
}

Thanks for your help in advance.

Coordinator
Oct 26, 2011 at 8:03 PM

Hi bachi,

The response is telling you that you submitted an incomplete type object.  The XSD requires a "when" element.

You can set the when element through the HbA1C.setWhen(...) method. 

You can find the type schemas in the documentation for the Jaxb classes or at http://developer.healthvault.com.

--Rob

Oct 27, 2011 at 12:45 AM

Hi Rob,

Thats my bad. I am sorry for that.

Here is another problem expecting 'value' datatype is Percentage but it is declared as double in HbA1C.java

@XmlElement(required = true)
    protected DateTime when;
    protected double value;
    @XmlElement(name = "HbA1C-assay-method")
    protected CodableValue hbA1CAssayMethod;
    @XmlElement(name = "device-id")
    protected String deviceId;

Response

DEBUG - ResponseStrategy - <!--?xml version="1.0" encoding="utf-8"?-->3Invalid xml for thing. The 'value' element is invalid - The value '20.0' is invalid according to its datatype 'urn:com.microsoft.wc.thing.types:percentage' - The MaxInclusive constraint failed. -- The 'value' element is invalid - The value '20.0' is invalid according to its datatype 'urn:com.microsoft.wc.thing.types:percentage' - The MaxInclusive constraint failed.failed-item-index=0

Thanks,

Bachi

 

Coordinator
Oct 27, 2011 at 5:30 AM

percentage is declared by the schema like this:

   <simpleType name="percentage">
        <annotation>
            <documentation>
                <summary>
                    A decimal number between zero and one.
                </summary>
                <remarks>
                    This type derives from double and ensures that all
                    values are between zero and one inclusive.
                </remarks>
            </documentation>
        </annotation>
        <restriction base="double">
            <minInclusive value="0"/>
            <maxInclusive value="1"/>
        </restriction>
    </simpleType>

 

Basically, this says that percentage is of type double and its value must be between 0 and 1.  So 20 percent would be set as the double 0.20.  I see that is kind of misleading but the XML binding classes stay true to the schemas.

--Rob