Medication retrievs same Jaxb object for both versions

Sep 27, 2011 at 6:49 PM


I am trying to retrieve medication by using the following code


    public void GetThing() throws Exception
    	SimpleRequestTemplate requestTemplate = new SimpleRequestTemplate(
    	ThingRequestGroup group = new ThingRequestGroup();
    	ThingFilterSpec filter = new ThingFilterSpec();
    	ThingFormatSpec format = new ThingFormatSpec();
    	GetThingsRequest info = new GetThingsRequest();
    	GetThingsResponse response = 
    	@SuppressWarnings("unused") weight = (;

The above code is trying to retrieve medication version 1 but it HV returns the version 1 medication and if change the type id to version 2 still I am getting the same result.


Can any one please help me.

Sep 28, 2011 at 7:40 AM
Edited Sep 28, 2011 at 8:43 AM


When a Thing is added to HealthVault,  the Thing maintains its type version from the original upload.  However, querying for a Thing retrieves instances of multiple versions even when only one type is specified in the request filter.  When an application retrieves Things, it can specify the format for the returned XML.  Here is the documentation straight from GetThings api

                            When a type gets versioned, HealthVault will retrieve instances of 
                            multiple versions even when only one type is specified in the request
                            filter.  By default HealthVault will map the XML of the instance to
                            the version supported by the application based on the base 
                            authorization XML specified in the configuration of the application in
                            HealthVault. However, if multiple versions are supported by the 
                            application, it can use this parameter to state the version format to
                            use when writing out the instance XML.
                            For example, when querying for medications, HealthVault will retrieve
                            medications of both version one and two schemas. If an application
                            only supports version one of the medication schema, then HealthVault
                            will automatically map version two instances down to the version one
                            schema. However, if the application supports both version one and two
                            by declaring both type IDs in the applications configuration, then
                            version one instances will be returned using the version one schema, and
                            version two instances will be returned using the version two schema.
                            If this application wants to retrieve all instances using a common 
                            schema (say version two), then is would specify the version two type
                            ID in this parameter and all instances will be mapped to version two
                            of the medication schema before being returned.

You can force versions to be upversioned or downversions by specifying the desired version in


One of the versioning intents is to make new versions transparently available to applications which have not yet upgraded to newer types.  For example, an application coded to work with Medication V1 will continue working even after HealthVault adds Medication V2.  The application will have access to all Medications, V1 and V2 but will only see V1 data.  That is, all Medications will appear to be V1.  Thing.getFlags will indicate if the Thing has been Upversioned or Downversioned:

                            0x2 (Downversioned) - the thing instance was converted from a newer
                            format to an older format while being written in the response. 
                            Applications should not attempt to update an instance that has been
                            0x4 (Upversioned) - the thing instance was converted from an older
                            format to a newer format while being written in the response.
                            Applications should only attempt to update the instance if given 
                            explicit approval by the user as this will change the stored instance
                            from the older format to the new format. In some cases this may cause
                            data loss.
Sep 29, 2011 at 1:32 PM

Ho Robmay,

Thanks for the response. Now I can force the application to retrieve specific version but when tried to export getting exception Error: 85 The 'Medication' data type has been versioned by HealthVault. The application cannot save the data because the existing instance of this data uses version 2 of the 'Medication' data type whereas the application uses version 1. 
Thanks for your help in advance.

Sep 29, 2011 at 6:21 PM
Edited Sep 29, 2011 at 9:40 PM

That's right.  If you try to update a higher versioned Thing with an older version, HealthVault will complain, although the error message isn't entirely clear about that.  The intent is to avoid data loss.  This scenario is very rare. 

If you really want to overwrite the Thing with an older version, you should get user consent and then use the method OverwriteThings.  I don't think I've written a unit test for that method.


Sep 30, 2011 at 12:17 PM

Hi Robmay,

I tried using OverwriteThings but got the following exception The application does not have permission to call the specified method.

It says I don't have the permission to specified method I can't understand which method because I was able retrieve the medication version 1.


My code:

OverwriteThingsRequest overwriteThingsRequest = new OverwriteThingsRequest();
		    	OverwriteThingsResponse putThingsResponse = (OverwriteThingsResponse)requestTemplate.makeRequest(overwriteThingsRequest);

Thanks for your help in advance.

Sep 30, 2011 at 5:58 PM

The error states that you do not have permissions to call the OverwriteThings method.  And it's right!  I forgot that method isn't handed out very freely.  Actually...not at all.

HealthVault will frown on overwriting a V2 Thing with a V1.  The reason is that the V2 Thing could contain more data that the system would lose in the process.  Sorry about the misdirection.


Sep 30, 2011 at 6:07 PM

So What is my option now? Any idea

Oct 3, 2011 at 6:13 PM

Can you help me understand your end user scenario? 

Oct 11, 2011 at 7:07 AM

Hi Robmay,

I fixed it by passing Prescribed By information as "Unknown".

For Medication version 2 if we pass any data under Prescription Prescribed by is required information that is the reason I wanted to use version 1.