locked
Conversion problem with LabTestResults? RRS feed

  • Question

  • Hi,

    I'm trying to retrieve some LabTestResult {f57746af-9631-49dc-944e-2c92bee0d1e9} objects from my health record. According to "Developer's X-ray", my record contains two items of these items LabTestResults.

    I retrieve the items programmatically in the following way:

    HealthRecordFilter filter = new HealthRecordFilter(maxItemsToReturn);
    filter.TypeIds.Add(LabTestResults.TypeId);
    filter.EffectiveDateMin = startDate.Value;
    filter.EffectiveDateMax = endDate.Value;
    HealthRecordSearcher searcher = record.CreateSearcher();
            searcher.Filters.Add(filter);
    ReadOnlyCollection<HealthRecordItemCollection> searchResultsGroup = searcher.GetMatchingItems();
    The resulting searchResultsGroup contains one Collection. This collection contains two HealthRecordItems, with typeId {f57746af-9631-49dc-944e-2c92bee0d1e9} (corresponding to LabTestResults). However, when debugging, the type is not seen as LabTestResult, and casting the items to the LabTestResults yields a null value... does anyone know why this is the case?

    I have installed the latest version of the SDK that is downloadable from the HealthVault site.

    Thursday, April 2, 2009 10:02 AM

Answers

  • Some times the type handlers  does not get registered properly.

    Can you try the following fix?

    On the global.asax add the following code

    protected void Application_Start(object sender, EventArgs e)
    {
                Microsoft.Health.ItemTypes.ItemTypeRegistrar.RegisterAssemblyHealthRecordItemTypes();
    }


    Restart the ASP.Net development server / IIS

    Let me know if the problem persists even after doing this. 

    Raj
    Raj HealthVault Developer Tool http://xray.getrealconsulting.com
    Thursday, April 2, 2009 12:36 PM

All replies

  • Some times the type handlers  does not get registered properly.

    Can you try the following fix?

    On the global.asax add the following code

    protected void Application_Start(object sender, EventArgs e)
    {
                Microsoft.Health.ItemTypes.ItemTypeRegistrar.RegisterAssemblyHealthRecordItemTypes();
    }


    Restart the ASP.Net development server / IIS

    Let me know if the problem persists even after doing this. 

    Raj
    Raj HealthVault Developer Tool http://xray.getrealconsulting.com
    Thursday, April 2, 2009 12:36 PM
  • In the debugger, what type do the objects appear as (if not LabTestResult)?  It does sound like the the Microsoft.Health.ItemTypes DLL may not be registered or visible in your application... could you take a look in your bin folder and see if all the DLLs are present as well?
    Thursday, April 2, 2009 6:14 PM
  • I think the Microsoft.Health.ItemTypes is properly referenced - other wise the following code wont compile - (since the LabTestResults is defined in that dll)

    filter.TypeIds.Add(LabTestResults.TypeId);

    My 2 cents : I noticed during the RegisterExternalTypeHandlers() call in ThingTypeManager (in SDK source) is that it ignores any exception that is thrown during that process.  If an execption occurs (for whatever reason), few types would not register correctly  (I have seen that happening in my code but couldnt reproduce it reliably) -  In such cases for a LabTestResults item type in HealthVault a HealthRecordItem type will be instantiated locally and the cast to LabTestResults  will fail -  You will see objects of HealthRecordItem types instead of LabTestResults type in the HealthRecordItemCollection returned by searcher...

    -Raj


    Raj HealthVault Developer Tool http://xray.getrealconsulting.com
    Thursday, April 2, 2009 7:16 PM
  • Hi Raj,

    indeed, adding the RegisterAssemblyHealthRecordItemTypes function at application startup fixes the problem!
    Thanks a lot, I would have never thought of this :)

    Kind regards

    Jeroen
    Friday, April 3, 2009 5:42 AM
  • Hi Lowell,

    The dll is registered, otherwise compiling wouldn't work.
    The objects appeared as HealthRecordItem, with the TypeId of LabTestResults.

    Jeroen
    Friday, April 3, 2009 5:44 AM
  • Jeroen,

    Sorry that this tripped you up. We're going to spend some time to see if we can make this situation more discoverable.
    Friday, April 3, 2009 5:28 PM