locked
Not able to cast old Immunization datatype to new Immunization datatype. RRS feed

  • Question

  • As new datatype is introduced for Immunization, I am not able to convert/cast the old Immuniations to new datatype or viceversa. Below code stopped working for me:

                // create and add the filter
                HealthRecordFilter filter = new HealthRecordFilter();
                filter.TypeIds.Add(new Guid(ImmunizationGUID));
                filter.TypeIds.Add(Microsoft.Health.ItemTypes.Immunization.TypeId);
                filter.View.Sections = HealthRecordItemSections.All;
                searcher.Filters.Add(filter);

                HealthRecordItemCollection hvItems = searcher.GetMatchingItems()[0];
                foreach (HealthRecordItem item in hvItems)
                {
                    Microsoft.Health.ItemTypes.Immunization hvImm = item as Microsoft.Health.ItemTypes.Immunization;
                }

    Here, for the new Immunization datatypes, it is working fine, but it turns out to be NULL for the old ones. Any way to covert it?


    Wednesday, July 22, 2009 11:18 AM

Answers

  • To specifically answer your question, SDK object instances of old and new versions of same datatypes are not cross castable.    Take a look at the link what Aneesh has sent and that should explain the finer details of the versioning feature.

    I further see that you are searching for BOTH versions of Immunization objects.  You dont have to do that (unless there is a specific reason) if your intention is to obtain all the immunization data (old and new). In the application configuration, just request for new Immunization data type access and NOT request for old immunization data type access (wait for 30 mts after this). From now, the platform will automatically convert old immunization objects to new types for you.  So you can expect all the immunization instances are instances of new type. 

    Raj




    Raj HealthVault Developer Tool http://xray.getrealconsulting.com
    Wednesday, July 22, 2009 3:43 PM
  • I definitely agree with Raj's suggestion here-- if you only set up data type rules for one of the versions (the new one, OR the old one), the HealthVault web service will convert them all for you.  You don't have to handle multiple versions in your own code.

    If you set up rules to get access to both versions, the HV platform will return data in each version independently-- but the only reason why you would want to do that is if you wanted to handle the versions differently.  That is why you can't (shouldn't) cast one version to another.  If you want to treat them all the same, let the platform do the conversion for you.
    Wednesday, July 22, 2009 5:11 PM

All replies

  • Hello,

    To be on the same plain can you please clarify one doubt? While using the hvItems have you tried casting the object to the old type also?
    You can refer to Eric's link on versioning. Please refer to the section Version-Aware applications.

    I think you are trying to cast even the old type objects into the new Immunization datatype.

    Thanks and Regards,
    Aneesh D.
    Wednesday, July 22, 2009 3:26 PM
  • To specifically answer your question, SDK object instances of old and new versions of same datatypes are not cross castable.    Take a look at the link what Aneesh has sent and that should explain the finer details of the versioning feature.

    I further see that you are searching for BOTH versions of Immunization objects.  You dont have to do that (unless there is a specific reason) if your intention is to obtain all the immunization data (old and new). In the application configuration, just request for new Immunization data type access and NOT request for old immunization data type access (wait for 30 mts after this). From now, the platform will automatically convert old immunization objects to new types for you.  So you can expect all the immunization instances are instances of new type. 

    Raj




    Raj HealthVault Developer Tool http://xray.getrealconsulting.com
    Wednesday, July 22, 2009 3:43 PM
  • I definitely agree with Raj's suggestion here-- if you only set up data type rules for one of the versions (the new one, OR the old one), the HealthVault web service will convert them all for you.  You don't have to handle multiple versions in your own code.

    If you set up rules to get access to both versions, the HV platform will return data in each version independently-- but the only reason why you would want to do that is if you wanted to handle the versions differently.  That is why you can't (shouldn't) cast one version to another.  If you want to treat them all the same, let the platform do the conversion for you.
    Wednesday, July 22, 2009 5:11 PM