How to to request new Medication/Immunization data types
- Hello,
I recently upgraded Healthvault SDK to version 1.0. I had the allergies, conditions, immunization and medications synced with Healthvault with older SDK. Now after the SDK upgrade, I am using query with filters to request new data types related records. I am getting the allergies and conditions records properly but the query returns NULL for medications and immuniztions. Here are few code fragments that I am using.
if (( this .allergies = GetValues< Allergy >( Allergy .TypeId)) == null )
{
msgList.Add(
"WARNING: ALLERGY record not found." );
}
if (( this .conditions = GetValues< Condition >( Condition .TypeId)) == null )
{
msgList.Add(
"WARNING: CONDITION record not found." );
}
if
if(( this .immunizations = GetValues< Immunization >( Immunization .TypeId)) == null )
{
msgList.Add(
"WARNING: IMMUNIZATION record not found." );
}
if (( this .medications = GetValues< Medication >( Medication .TypeId)) == null )
{
msgList.Add(
"WARNING: MEDICATION record not found." );
}
Where allergies, conditions, immunizations and medications are the list of corresponding types. And here is the GetValues function that I am calling
List
<T> GetValues<T>( Guid typeID) where T : HealthRecordItem
{
HealthRecordSearcher searcher = this .personInfo.SelectedRecord.CreateSearcher();
HealthRecordFilter filter = new HealthRecordFilter (typeID);
searcher.Filters.Add(filter);
HealthRecordItemCollection items = searcher.GetMatchingItems()[0];
if (items != null && items.Count > 0)
{
List <T> typedList = new List <T>();
foreach ( HealthRecordItem item in items)
{
try
{
typedList.Add((T)item);
}
catch ( Exception )
{
}}
return typedList;
}
else
{
return null ;
}
}
Any suggestions on this is highly appreciated.
Thanks
-Devesh
Answers
- Here's what's going on...
The application configuration (set up in the online HealthVault application configuration center) defines which types your application is able to handle. When you make a request for a data type, you are making a request for the data that is all versions of that data type, and then, if necessary, the platform converts those versions to the versions your app said it could handle.
In this case, you are asking for Medication (the new version), and the app is returning what your app configuration said it could accept (the old version). You get back the collection of MedicationV1 items, and then in your foreach loop, the following line throws an exception:
typedList.Add((T)item);typedList.Add((T)item);
which is swallowed by the catch (Exception)
There are two ways to remedy this.
The first is through modifying your application configuration, so that it specifies the new vesrsion of the type. You can do that in the application configuration center.
The second is by modifying the filter to override the application configuration and specify the type that your code is expecting. You can do that by making the following modification to GetValues:
HealthRecordFilter filter = new HealthRecordFilter(typeID);
searcher.Filters.Add(filter);
filter.View.TypeVersionFormat.Add(typeID);
where the last line sets the override.
I also highly recommend that you get rid of that empty catch statement. That's an evil thing to have in code, since it can hide things.
Hope that helps.- Marked As Answer byDevesh Koirala Friday, September 25, 2009 10:59 PM
All Replies
- Here's what's going on...
The application configuration (set up in the online HealthVault application configuration center) defines which types your application is able to handle. When you make a request for a data type, you are making a request for the data that is all versions of that data type, and then, if necessary, the platform converts those versions to the versions your app said it could handle.
In this case, you are asking for Medication (the new version), and the app is returning what your app configuration said it could accept (the old version). You get back the collection of MedicationV1 items, and then in your foreach loop, the following line throws an exception:
typedList.Add((T)item);typedList.Add((T)item);
which is swallowed by the catch (Exception)
There are two ways to remedy this.
The first is through modifying your application configuration, so that it specifies the new vesrsion of the type. You can do that in the application configuration center.
The second is by modifying the filter to override the application configuration and specify the type that your code is expecting. You can do that by making the following modification to GetValues:
HealthRecordFilter filter = new HealthRecordFilter(typeID);
searcher.Filters.Add(filter);
filter.View.TypeVersionFormat.Add(typeID);
where the last line sets the override.
I also highly recommend that you get rid of that empty catch statement. That's an evil thing to have in code, since it can hide things.
Hope that helps.- Marked As Answer byDevesh Koirala Friday, September 25, 2009 10:59 PM
- Thanks...That was indeed due to the App configuration.

