Associating Mood Tracker With HealthVault #3

Sorry for the delay in installment #3 in the series of how to write a WP7 app for HealthVault! The code for this application is now hosted on github.

In order for the Mood Tracker application to work with HealthVault we will get appropriate application creation credentials from the HealthVault Service and authorize them through the user with HealthVault Shell.

1. To get the credential from HealthVault Service the application contacts the HealthVault service to get application creation Url.

The code for that is outlined in MyMood.xaml.cs

 void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            App.HealthVaultService.LoadSettings(SettingsFilename);
            App.HealthVaultService.BeginAuthenticationCheck(AuthenticationCompleted,
                DoShellAuthentication);
            SetProgressBarVisibility(true);
        }

void DoShellAuthentication(object sender, HealthVaultResponseEventArgs e)
        {
            SetProgressBarVisibility(false);

            App.HealthVaultService.SaveSettings(SettingsFilename);

            string url;

            if (_addingRecord)
            {
                url = App.HealthVaultService.GetUserAuthorizationUrl();
            }
...

2. The application creation needs to be validated on behalf of the user.

The best mechanism to achieve this is by having a page with a hosted browser which redirect appropriately to HealthVault and closes the browsers and navigated back to page on a successful authorization.

Following is the code in HostedBrowserPage.xaml :

      void c_webBrowser_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
        {
            if (e.Uri.OriginalString.Contains("target=AppAuthSuccess"))
            {
                Uri pageUri = new Uri("/MyMood.xaml", UriKind.RelativeOrAbsolute);

                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    NavigationService.Navigate(pageUri);
                });
            }
        }

        void HealthVaultWebPage_Loaded(object sender, RoutedEventArgs e)
        {
            string url = App.HealthVaultShellUrl;

            c_webBrowser.Navigate(new Uri(url));
        }

Note that on success the Application is being redirected to MyMood.xaml which is our landing page!

Here is flow of how the above authentication works!

imageimageimage

Step1. Home page      Step2.Sign-in & Auth  Step3. Mood track in action!

Next time: Adding the emotional state data type to Mood Tracker

Previous Post: Getting Started

Getting Started with Mood Tracker #2

In the last post, we sort of defined what our emotion tracking application should do. Lets get started with building it. I assume you have visual studio installed with WP7 tools, if not you can get them from here.

image

Fig 1. Windows Phone 7 SDK

Next, we go over to codeplex, and download the HealthVault library with the sample.

image

Fig 2. HealthVault WP7 library.

I extracted the library to my desktop and the folder structure looks like following -

image

Fig 3. HealthVault WP7 library extracted.

I open the MobileSDK solution in visual studio and hit F5, the library compiles and the WeightTracker demo starts -

image

Fig 4. Compiling and running HealthVault WP7 Sample Application

Without further ado lets create our new Silverlight for Windows phone project in our solution for MoodTracker, and reference the HVMobilePhone library in that project.

image

Fig 5. Beginnings of MoodTracker

First things first, lets get the application setup to talk to HealthVault, in App.xaml.cs class we add reference to HealthVaultService & HealthVault Shell, we also need to make sure we get a unique application ID in the developer environment of HealthVault, to do that we head over to HealthVault Application Configuration Center, and create a new application by clicking on the button –

image

Fig 6. Creating a new application in Application Configuration Center

We create an application of type SODA and pick the name Mood Tracker for it –

image

Fig 7. Creating Mood tracker as a SODA application

One the application is created we click on the app link and assign appropriate data-type for this application using the SODA-

image

Fig 8. Adding Emotional State to our Mood tracker application.

One we create the SODA application, and appropriate data type rules we are all set! Now we can configure our base page to work with HealthVault Pre-production environment. Here is my initial code for it –

    public partial class App : Application
    {
        public static HealthVaultService HealthVaultService { get; set; }
        public static string HealthVaultShellUrl { get; set; }

        static string platformUrl = @"https://platform.healthvault-ppe.com/platform/wildcat.ashx";
        static string shellUrl = @"https://account.healthvault-ppe.com";
        static string masterAppId = "83bf507d-9186-407f-a6cd-b2d65f558690";

        // Code to execute when the application is launching (eg, from Start)
        // This code will not execute when the application is reactivated
        private void Application_Launching(object sender, LaunchingEventArgs e)
        {
            HealthVaultService = new HealthVaultService(platformUrl, shellUrl, new Guid(masterAppId));
        }
        // Code to execute when the application is activated (brought to foreground)
        // This code will not execute when the application is first launched
        private void Application_Activated(object sender, ActivatedEventArgs e)
        {
            HealthVaultService = new HealthVaultService(platformUrl, shellUrl, new Guid(masterAppId));
        }

..

We make this project as startup project and hit F5, and get to the first page of our application!

image

Fig 9. A start with HealthVault Service configure in base page

We have lots more to do!

Next time, we will focus on authenticating this application with HealthVault Shell!

Developing HealthVault WP7 Mobile Application #1

Yesterday, HealthVault released developer preview of support for mobile applications. The associated Windows Phone 7 library is available on codeplex as well.

In this multi-part series, I’ll try to cover the details of building a Windows Phone 7 mobile application for HealthVault.

Now, the first question is what should we build?
Our product management team has recently been tracking their happiness and stress level on a daily basis. I have been thinking of providing a tool which helps them to track their happiness & stress levels and of course build great products..

Having said above there are a few applications in the Health & Fitness category of WP7 application store which help a user to track mood, but none of them combines happiness and stress, and stores it in HealthVault.

image
Fig 1. Mood swing application in Windows Phone 7 Store

Hopefully over-time we can make the application a fun one, may be add a social game aspect to it!

Well, how will the application look like?

The application would allow the user to input their happiness and stress level, and perhaps look at history and may be display a social game avatar of their well-being.

Here is a sketch of what the app might look like –

image

Fig 2. White board wire-frame of our mood application

Where to store the data?

While developing a HealthVault application a relevant question is which part of the HealthVault data store the application should store data in. As we browse the HealthVault Data Types, we immediately see a relevant data type – Emotional State.

Turn out there is also a handy tool to input sample data for this data type after clicking the “View & Edit” button next to the type -

image

Fig 3. Emotional State Data type

On further analysis it turns out that this type is almost perfect for our use, except the fact that we have to use a scale of 1-5 and there is an additional element – well-being, which we can ignore for now.

Next Step?

Now that we have defined this application, the next step would be to get our hands dirty and start working with Windows Phone 7 tools for Visual studio and the HealthVault WP7 library.

Next Post: Mood Tracker – Getting Started #2

Mingling @ Microsoft Connected Health Conference

image

I’ll be presenting and speaking at the Microsoft Connected Health conference on Thursday, April 28th with my colleague – Eric Gunnerson,  our talk is titled Developing HealthVault Enabled Solutions in 2011 and Beyond. We will be demonstrating and explaining plethora of features released (or to be soon released) in the Microsoft HealthVault product line over the last year!

Its always exciting to mingle with consumers of your products. Sometimes its reflective, sometimes its fulfilling and most of the time its insightful!

I’m looking forward to meet our partners and customers over the next few days. So if you are at the conference feel free to reach out!

Windows Phone 7 Health and Life Sciences App Contest

Get your creative geek on and be part of the Health and Life Sciences application contest. The ten winning entries get an XBOX 360 console with Kinect for each team participant and a chance to make difference in Healthcare!

image

In addition to the application ideas on the contest website feel free to use the resources from Health hack-a-thons. Perhaps it will be great to see some mash-ups using data from http://www.data.gov/health.

Drop me a note if you need help connecting your mobile applications with HealthVault or are trying to explore the Health datasets.

Update: If you want to take your project to the next level, RockHealth might have some seed funding for you!