Family Health Guy

In which Sean talks about HealthVault and other cool ideas in Personal Health

More Windows 8 “Sharing” and HealthVault

More Windows 8 “Sharing” and HealthVault

  • Comments 2

In my last post, I talked about how our Windows 8 HealthVault app integrates with the new “Sharing Charm” to do some pretty cool stuff, like sharing photos and other files directly from the Camera to HealthVault. But as great as that stuff is, there is an even better feature hiding in our Sharing implementation that I wanted to spend some time on. Fair warning --- this is a geeky developer zone, so feel free to bail now if that’s not your bag.

You can read a ton about Windows 8 Sharing here, but the core of it is simply that applications can register to “receive” sharing requests for certain data formats. Common formats are text, images, etc. --- but applications can also define their own formats.

Other applications then make their data available for sharing. For example, when you’re looking at a picture in your photos library, that app makes the picture available for sharing. If the user chooses the Share charm, they’ll see a list of applications that can accept them. The user picks one, the target app is activated and passed the data, and we’re off to the races. Basically a super-clipboard.

OK … so the cool thing we did with the HealthVault app is to register to receive any HealthVault-formatted items, and automatically push them up to the right HealthVault record in the cloud. In other words, Windows 8 apps can use our HealthVault app as a programmatic channel to push data up to HealthVault – with no HealthVault software or “go live” involved.

Want to build an app to upload blood pressure values from an Excel file? No problem. Are you that reviewer that wished we let you set your height from the app? Kachow. This isn’t a substitute for using the SDK to build great, interactive HealthVault experiences --- but it opens up a TON of cool stuff with virtually no hassle. Pretty awesome.

To make this happen is crazy simple. Here’s how it works in Javascript:

1. Register yourself as able to provide data for Sharing.

    var dataTransfer = Windows.ApplicationModel.DataTransfer;
    var dataTransferManager = dataTransfer.DataTransferManager.getForCurrentView();
    dataTransferManager.addEventListener("datarequested", dataRequestedHandler);

2. Implement the handler to return data when requested.

    function dataRequestedHandler(eventInfo) {
        var thingXml = /* construct your healthvault xml here */
        var request = eventInfo.request;
        request.data.properties.title = "HealthVault";
        request.data.properties.description = "Information to share with HealthVault";
        request.data.setData("HealthVault.Types.RecordItem", thingXml);
    }

3. If you want, manually kick of sharing at the appropriate point in your application. Note that Microsoft discourages using this method in most cases, because we’re trying to teach people to use the sharing charm to initiate the action. But there are times when it makes sense; you can do so with a simple call:

    Windows.ApplicationModel.DataTransfer.DataTransferManager.showShareUI();

The only part of this that’s at all challenging is building the HealthVault XML in the right format. For the super-hardcore, our “thing” XML is defined in our service specification and there’s a full reference to all of the type-specific XML here on MSDN. But it’s much easier to either use our Windows 8 SDK to build the XML from objects --- just use the Serialize functions on the HealthVault.Types.RecordItem class.

Even easier, if you already have an item in HealthVault of the type you care about, just use your browser to view the item at http://healthvault.com, expand for details, and look for the “View as XML” link to get yourself a nifty sample.

Once you have the <thing> element(s) the way you like them, wrap them up in an <ArrayOfThing> tag and you’re good to go. Here’s an example of a very simple weight reading:

<ArrayOfThing>
    <thing>
        <type-id>3d34d87e-7fc1-4153-800f-f56592cb0d17</type-id>
        <thing-state>Active</thing-state>
        <flags>0</flags>
            <data-xml>
                <weight>
                    <when>
                        <date><y>2013</y><m>3</m><d>10</d></date>
                        <time><h>10</h><m>50</m><s>55</s><f>340</f></time>
                    </when>
                    <value><kg>75</kg></value>
                </weight>
                <common />
            </data-xml>
        </thing>
</ArrayOfThing>

You can download sample code, which is a bit more complicated but mostly just in the window dressing, at my HealthVault Toys site. It’s pretty neat … works like a champ and barely took a couple of hours to get rolling … and did I mention it’s my first real Windows 8 app? Hooray for me….

Relentlessly better every day. That is how we help real people!

 

PS. One note pointed out to me by our Win8 PM Sam ... the app is able to push any HealthVault type via sharing, even those that the app itself doesn't know how to display (like glucose in my sample). This makes the feature way more useful, but can be a bit confusing. All is well --- that data goes up to HealthVault in the cloud and can be viewed on the web or any other app that can work with it. We'll be adding more functionality to the Win8 app over time as well. Just didn't want anyone to be confused!

 

Update 3/25/2013 --- the team just posted official documentation on sharing to and from the HealthVault app. Check it out here!

Leave a Comment
  • Please add 2 and 2 and type the answer here:
  • Post
  • What would be great would be to have access to the HealthVault Message Center within the app and then add a share target to enable easy sharing via the Direct protocol to a physician. Any chance we'll see Microsoft add Direct secure email support to the app?

  • Scott, this is a great idea... I don't think Direct was on this project's radar, but interestingly improvements to Direct messaging overall for HealthVault are being worked on --- I will make the connection to see if we can't incorporate Win8 stuff too. The team loves it when I give them new work ;) ... thanks!

Page 1 of 1 (2 items)