Medication retrievs same Jaxb object for both versions

Sep 27, 2011 at 6:49 PM

Hi,

I am trying to retrieve medication by using the following code

 

@Test
    public void GetThing() throws Exception
    {
    	SimpleRequestTemplate requestTemplate = new SimpleRequestTemplate(
    			ConnectionFactory.getConnection());
    	requestTemplate.setPersonId("b84ea658-d48b-4c8a-acc6-f903c0394ed6");
    	requestTemplate.setRecordId("0ddd8062-26e6-4acb-858a-ee77d678b759");
    	
    	ThingRequestGroup group = new ThingRequestGroup();
    	
    	ThingFilterSpec filter = new ThingFilterSpec();
    	filter.getTypeId().add("5c5f1223-f63c-4464-870c-3e36ba471def");
    	group.getFilter().add(filter);
    	group.setMax(BigInteger.valueOf(30));
    	
    	ThingFormatSpec format = new ThingFormatSpec();
    	format.getSection().add(ThingSectionSpec.CORE);
    	format.getXml().add("");
    	group.setFormat(format);    	
    	
    	GetThingsRequest info = new GetThingsRequest();
    	info.getGroup().add(group);
    	
    	GetThingsResponse response = 
    		(GetThingsResponse)requestTemplate.makeRequest(info);
    	
    	@SuppressWarnings("unused")
		com.microsoft.hsg.thing.oxm.jaxb.medication1.Medication weight = (com.microsoft.hsg.thing.oxm.jaxb.medication1.Medication)response.getGroup().get(0).getThing().get(0).getData();
    	System.out.println((weight.getName()));
    }

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.

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

Hi,

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 https://platform.healthvault-ppe.com/platform/XSD/method-getthings.xsd.

                            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

ThingFormatSpec.typeVersionFormat.

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
                            down-versioned.
                            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

com.microsoft.hsg.HVException: com.microsoft.hsg.HVUncategorizedException: 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.

Coordinator
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.

--Rob

Sep 30, 2011 at 12:17 PM

Hi Robmay,

I tried using OverwriteThings but got the following exception

com.microsoft.hsg.HVException: com.microsoft.hsg.HVAccessDeniedException: 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();
		    	overwriteThingsRequest.getThing().add(thing);
		    	OverwriteThingsResponse putThingsResponse = (OverwriteThingsResponse)requestTemplate.makeRequest(overwriteThingsRequest);

Thanks for your help in advance.

Coordinator
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.

--Rob

Sep 30, 2011 at 6:07 PM

So What is my option now? Any idea

Coordinator
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.