none
problem in retrieving back medication data type RRS feed

  • Question

  • Hi,

     

     i am using medicationnew data type .

    i am able to insert the medication value successfully. I confirmed this directly in my health vault preproduction environment. But i am not able to retrieve the data back successfully.

    I am using the below method to get data from health vault.

     private List<T> GetValueBasedOnClientId<T>(Guid typeID, PersonInfo objPersonInfo, String clientId) where T : HealthRecordItem
            {
                List<T> typedList = new List<T>();
                try
                {
                    HealthRecordSearcher searcher = objPersonInfo.SelectedRecord.CreateSearcher();
                    HealthRecordFilter filter = new HealthRecordFilter(typeID);
                    filter.ClientItemIds.Add(clientId);
                    searcher.Filters.Add(filter);
                    HealthRecordItemCollection items = searcher.GetMatchingItems()[0];
                    foreach (HealthRecordItem item in items)
                    {
                        typedList.Add(
    item as T);
                    }
                }
                catch (Exception objException)
                {
                    LoggerDetails.TraceException.Info(DateTime.Now.ToString() + ": " + objException.Message);
                }
                return typedList;
            }

     

    This above method is working perfectly for the Problem, Allergy etc data types. but only when i try to get medication data type i am getting error saying "Unable to cast HealthRecordItem as Health.ItemTypes.Medication" in the above piece of code which is highlighted in red color.

    But some times it is working for the medication itself. So it is really confusing me, what is wrong and where it is wrong.

    Is there any problem in the above code?

    Really getting confused why this medication type is behaving differently.

     

    Kindly help me in this issue.

     

    Thanks in advance,

    Sathya N

    Tuesday, January 27, 2009 12:25 PM

Answers

  • I missed the fact that you are writing a windows service.  Instead of global.asax (which is unavailable), try calling the function once on service startup.

    I have kind of hit the same problem atleast a couple of times and calling Microsoft.Health.ItemTypes.ItemTypeRegistrar.RegisterAssemblyHealthRecordItemTypes();
    manually did solve my issue.

    Raj


    Raj HealthVault Developer Tool http://xray.getrealconsulting.com
    Thursday, January 29, 2009 4:01 PM

All replies

  • There could be few reasons I can think of why you see this behaviour.

    The problem is usually because of presence of multiple versions of Medication type in the person's HealthVault record and you have enabled BOTH types of medication in application configuration.

    What is the version of API you are using? What are the application permissions you have enabled?

    Have a look at the blog below to understand how versioning works.

    http://blogs.msdn.com/ericgu/archive/2008/10/13/versioning-in-healthvault.aspx

    For ex, if you have enabled permissions for BOTH old and new versions of medications (Exposed as MedicationOld and Medication in SDK), HV assumes that your application can handle different medication types correctly and when you search for a given medication type, it will NOT do any type changes and will give you objects of BOTH MedicationOld and Medication).  Ideally you may only need to enable new Medication type and use the new API.

    If you are using new API and have enabled only ONE medication type in application configuration, try the following global.asax solution below and let me know if it works. I am suggesting this since you mentioned it works at times....

    http://social.msdn.microsoft.com/forums/en-US/healthvault/thread/63ae6d79-cba1-4de1-aea6-bbd79f72e761/

    Hope this helps


    Rajesh

     

     

     

     

     



    Raj HealthVault Developer Tool http://xray.getrealconsulting.com
    Tuesday, January 27, 2009 1:27 PM
  • To expand on what Rajesh said, if you run in the debugger, you can examine the underlying type of the item that is causing you trouble.
    Tuesday, January 27, 2009 4:31 PM
  • Thanks for your Response Rajesh and Eric.

     

     I am using the latest SDK only.

    Now it is geting typecasted as medication only. the type casted medication is null.

    i debug and checked the item.GetItemXml(); method inside that foreach loop. i got the below result.

     <thing><thing-id version-stamp="59bd0cd6-1755-4bc4-96eb-e888b83879dc">ec942c6e-6082-4b07-913b-5f4ba64af766</thing-id><type-id name="Medication">30cafccc-047d-4288-94ef-643571f7919d</type-id><thing-state>Active</thing-state><eff-date>2009-01-27T01:33:52.136Z</eff-date><data-xml><medication><name><text>AMMONIUM CHLORIDE</text></name><generic-name><text>AMMONIUM CHLORIDE</text></generic-name><strength><display>500MG</display></strength><route><text>ORAL - ORAL</text></route><indication><text>Cholera</text></indication><date-started><structured><date><y>2004</y><m>10</m><d>8</d></date><time><h>0</h><m>0</m><s>0</s></time></structured></date-started><date-discontinued><structured><date><y>2005</y><m>10</m><d>8</d></date><time><h>0</h><m>0</m><s>0</s></time></structured></date-discontinued></medication><common><client-thing-id>123</client-thing-id></common></data-xml></thing>

     

    So from the above xml i guess that search is returning my medication data correctly but what happens to the data when it is converted back to medication. I am using this in my windows service application. is this anything to do with the problem.

     

    I am really blinking what is happening day to day.

    Mean while when i just copy and paste the same code to any other web applications it working at times. So need help on this issue.

     

     

    Thanks

    Sathya N

     

    Thursday, January 29, 2009 12:39 PM
  • Can you add the following line to your project's global.asax, do iisreset and try again.  

     

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


    Raj HealthVault Developer Tool http://xray.getrealconsulting.com
    Thursday, January 29, 2009 3:21 PM
  • I missed the fact that you are writing a windows service.  Instead of global.asax (which is unavailable), try calling the function once on service startup.

    I have kind of hit the same problem atleast a couple of times and calling Microsoft.Health.ItemTypes.ItemTypeRegistrar.RegisterAssemblyHealthRecordItemTypes();
    manually did solve my issue.

    Raj


    Raj HealthVault Developer Tool http://xray.getrealconsulting.com
    Thursday, January 29, 2009 4:01 PM
  • Thanks Rajesh

    Ur solution worked for me

     

    Friday, January 30, 2009 10:33 AM