Building a HealthVault-connected ASP.NET MVC application 

This is how-to guide for creating HealthVault-enabled applications with ASP.NET MVC. At the end of this article, you should have a working sample application that can login a HealthVault user, authorize a HealthVault record to the sample application, and read/write data from the record. This article is part of the HealthVault ASP.NET MVC Sample project.

Step 1: Register the Application with HealthVault

  • Install the HealthVault .NET SDK
  • Once installed, start the HealthVault Application Manager and select Create New Application.
  • Uncheck Automatically create Visual Studio website for this Application. We’ll create the MVC project in Step 2.
  • Give your application a name, i.e. Hello World MVC, and select Create and Register Application.
    • This will launch the HealthVault Application Configuration Center (ACC) in a browser.
    • Also, notice the Application Manager displays a new certificate for your application. 
  • In ACC, read and accept the terms of use and select Create application
    • This registers your application in the HealthVault Pre-Production Environment. Your application should now be listed in the Applications section of ACC.
    • Click the Application ID for the new app and navigate to the Online rules tab and edit the rule. This sample uses the Basic Demographic Information data type so make sure the corresponding check box is selected. You can select other data types for your application now or at a later time.
  • Back in the HealthVault Application Manager, right click the certificate name corresponding to your newly created application and select Export public and private keys (.pfx), and save the file to your computer.

 Step 2: Create the ASP.NET MVC Project 

  • Open Visual Studio. (If you don’t have it you can get the free Visual Studio Express for Web)
  • Select File->New->Project. Navigate to Visual C#->Web and create a new ASP.NET MVC 3 Web Application.
    • The instructions assume ASP.NET MVC 3. They should also work with ASP.NET MVC 4 and beyond.
    • If ASP.NET MVC 3 is not installed, you can install it from: http://www.asp.net/mvc/mvc3
  • When prompted choose the Empty project template. The skeleton app should now be created. Next, we’ll setup the project for HealthVault.  

Step 3: Setup the ASP.NET MVC project for HealthVault 

  • Download the HealthVault MVC Sample package. This includes an object model for integrating HealthVault concepts into an ASP.NET MVC application.
  • Right click the Visual Studio solution created in Step2, select Add->Existing Project and import Microsoft.Health.Web.Mvc.csproj which is part of the HealthVault MVC sample package.
    • In the Microsoft.Health.Web.Mvc project, add references to the HealthVault .NET SDK assemblies. Specifically, Microsoft.Health.dll and Microsoft.Health.Web.dll (see Step1 to download)
  • In the MVC project, add references to the HealthVault .NET SDK assemblies
    • Specifically, to Microsoft.Health.dll, Microsoft.Health.Web.dll, and Microsoft.Health.ItemTypes.dll.
    • Also add a project reference to the Microsoft.Health.Web.Mvc project.
  • Modifications are necessary to the web.config and global.asax.cs files in the MVC project to integrate the HealthVault components.
    • Replace the web.config file in the MVC project with /app/web.config from the HealthVault MVC Sample.
      • Make sure to set the ApplicationId config to the application ID created earlier in Step 1.
      • Make sure to set the ApplicationCertificateFileName config to the file path of the PFX file you exported in Step1.
    • Replace the global.asax.cs file in the MVC project with /app/global.asax.cs from the HealthVault MVC Sample.
    • If you’re interested in the specific changes to the default web.config and global.asax.cs files see  HealthVault ASP.NET MVC configuration changes.

Step 4: Add views and controllers

The HealthVault MVC sample contains example view and controllers. This includes:

  • An AccountController showing how to log users in and out of HealthVault, and a HomeController used to display data from HealthVault. Add these to the project. They can be found in /app/controllers.
  • Home views. Create a Home folder in the Views section of the project and include the views found in /app/views/Home.  

Step 5: Run the ASP.NET MVC application!

  • Run or debug the project from Visual Studio. Navigate to http://localhost/home/basic.
  • This will demonstrate user login to HealthVault and reading Basic Demographic Information.
  • You can access HealthVault data as you normally would with the HealthVault .NET SDK. For example:  
User.PersonInfo().SelectedRecord.GetItemsByType(Medication.TypeId)

Last edited Oct 25, 2012 at 7:02 AM by ali_emami, version 24

Comments

No comments yet.