Quantcast
Channel: Sensors
Viewing all articles
Browse latest Browse all 82

NFC Usage in Windows* Store Apps – a Healthcare App Case Study

$
0
0

Download


NFC Usage in Windows* Store Apps – a Healthcare App Case Study [PDF 526.46 KB]

Abstract


Modern mobile apps take advantage of a myriad of sensor types available on the platform. NFC is one such feature that is becoming increasingly popular, as it is very versatile and allows several types of use cases. In this article we will look at how a sample healthcare app uses NFC to enhance the user experience and enable new usage models. By the end of this article, you will learn how to add NFC usage to Windows* Store apps. Specifically, we will cover how to do protocol activation, how to automatically open your app when a user taps a custom-programmed NFC tag, and how to use a NFC tag as a check-in/check-out mechanism in a hypothetical patient room.

Contents


Overview
NFC and protocol activation in Windows Store Apps
A Healthcare Line of Business Windows Store App
Adding NFC to a sample healthcare app – a case study
           Adding Proximity Capability to the app Manifest
           Adding Protocol Activation Extension to the app Manifest
           Handling Protocol activation inside the app
           Detecting NFC availability and Subscribing for message(s)
           Reading and parsing NFC tag information
Summary

Overview


Near Field Communication (NFC) enables short-range wireless connectivity with data speeds of 106, 212, or 424 kbps and requires the device(s) to be in close proximity (e.g.: less than 4 cm). The connection is quick, simple, and automatic. In addition, the connection requires little configuration on the user’s part, unlike other connectivity technologies like Bluetooth. This renders it extremely convenient for different use cases.

At a higher level, NFC usage can be divided into three use cases: acquiring Information (e.g.: read URI from NFC tag), exchanging information (e.g.: send/receive photo), and connecting devices (e.g.: tap device to configure Bluetooth or other connection configuration). These three categories together can enable a plethora of NFC use cases. For an in-depth discussion on NFC technology, please refer to this article:
http://www.radio-electronics.com/info/wireless/nfc/near-field-communications-tutorial.php

NFC usage is getting more popular by the day. Most of the new generation mobile hardware supports NFC. In this article, we will discuss how NFC enables new user experiences in a sample healthcare app. We will focus on how to use NFC tags for automatically activating (opening) our sample healthcare app and how to use the information embedded in the tag to identify and take additional steps.

NFC and Protocol Activation in Windows Store Apps


Windows Store apps can use NFC functionality via the Windows.Networking.Proximity namespace. The proximity namespace classes allow a device to discover another device nearby, and publish/subscribe messages between them[?].

The reference for the Windows Store apps proximity namespace is given below.
http://msdn.microsoft.com/EN-US/library/windows/apps/windows.networking.proximity

Before we can use the proximity APIs, we first need to declare the ‘proximity’ capability in the app manifest, which allows Windows to enforce security and user permissions for an app. Additionally, the app must be running in the foreground for it to be able to use proximity related APIs. In the following sections we will walk through these steps as part of a healthcare sample case study. For a detailed reference on NFC in Windows Store apps, please refer to the following article.
http://msdn.microsoft.com/EN-US/library/windows/apps/hh465221

We will also take advantage of another feature in Windows Store apps—protocol activation. Protocol activation allows us to register our app to be activated for a particular URI scheme. We can even define our own custom URI scheme that our app registers for. This URI can be fed to the device from anywhere—including a tap of NFC tag, which we will use in our case study. Please refer to the reference below for more details on protocol activation in Windows Store apps.
http://msdn.microsoft.com/library/windows/apps/hh779670.aspx

A Healthcare Windows Store App


As seen in several other articles in this forum, we will build the case study around a healthcare Line of Business Windows Store app. We will extend it with the capability to do protocol activation and use NFC tags to implement a sample patient room check-in/check-out mechanism.

Some of the previous articles include:

The application allows the user to login to the system, view the list of patients (Figure 1), and access patient medical records, profiles, doctor’s notes, lab test results, and vital graphs.


Figure 1.The “Patients” page of the Healthcare Line of Business app provides a list of all patients. Selecting an individual patient provides access to the patient’s medical records.

Adding NFC to a Sample Healthcare App – a Case Study


In this sample app, we can use NFC tags for uniquely identifying patient or lab room(s) that the logged-in user (healthcare provider or doctor) visits. When the user is about to enter the room, he/she can tap on the NFC tag at the entrance. If our sample app is not in the foreground, Windows will automatically activate it (via protocol activation), thereby bringing it to the foreground. We could additionally navigate to the appropriate screen inside the app depending on the reason for app activation (in this case NFC). Next, the app can read the room number embedded inside the NFC tag and log the timestamp and room details for check-in. When the user is about to leave the room, he/she will tap again and the app will log the check-out details. All results will be summarized on the user’s home screen.

Before we start adding these features to our sample app, first we need to modify the app manifest.

Adding Proximity Capability to the app Manifest

Double clicking on the Package.appxmanifest in your Visual Studio* 2012 project should bring up a manifest UI allowing you to tweak the settings. Figure 2 shows the Proximity capability enabled in the manifest, which lets us use the NFC feature.


Figure 2. App manifest showing the Proximity package capability (captured from Visual Studio* 2012)

Our project should now be ready to access the NFC feature.

Adding Protocol Activation Extension to the app Manifest

We also want our sample healthcare app to be activated (open the app, bringing it to the foreground) whenever we tap a NFC tag. This is very useful for enhancing the user experience since the NFC-based proximity namespace classes only work when our app is in the foreground. To achieve this feature, we will need to enable protocol activation.

In the app manifest window, click on “Declarations.” Here we can add a new “protocol” declaration for our sample app.  We can define our own custom URI scheme; in our sample app we use ‘prapp’ as the URI that we register for. You can choose the custom URI depending on your app requirements. Please refer to screen shot in Figure 3.


Figure 3.Protocol declaration for sample app (captured from Visual Studio* 2012)

Our sample app should now be ready for NFC and protocol activation features.

Handling Protocol activation inside the app

Our sample app will get invoked automatically every time a URI with the ‘prapp’ scheme is triggered on the device. In our case study, we custom program a NFC tag with a URI scheme of the format ‘prapp://rm=????’ where “????” is any patient or lab room number. When a user taps on this NFC tag, Windows automatically reads in the URI, notices the ‘prapp’ URI scheme, and triggers activation for our sample app. The activation ‘kind’ is ‘Protocol’. To handle the app activation, we need to override ‘OnActivated’ method in our Application class. Please refer to the code listing below.

// protocol activation
        protected async override void OnActivated(IActivatedEventArgs args)
        {
            if (args.Kind == ActivationKind.Protocol)
            {
                ProtocolActivatedEventArgs protocolArgs = args as ProtocolActivatedEventArgs;

                await InitMainPage(args);

                var frame = Window.Current.Content as Frame;

                var loggedinuser = SessionSettingsViewModel.SessionSettings.Loginuser;
                if (loggedinuser == null || !loggedinuser.LoginState)
                {
                    frame.Navigate(typeof(Login));
                    return;
                }
                if (frame.CurrentSourcePageType != typeof(UserPage)) frame.Navigate(typeof(UserPage));
 

Figure 4. Handling the app activation for custom URI  protocol scheme that we registered for ++

Our sample app gets activated only when our specified URI scheme is triggered. Inside the ‘OnActivated’ method we also check for the kind of activation. If it is ‘Protocol,’ we can proceed to redirect the user to the appropriate UI screen.

In this case study, we first check if the user is already logged into the app. If the user is not logged in, we redirect the user to the login page. If the user is already logged in, we redirect the user to his/her home screen where he/she can see the NFC room information summarized. Depending on the app requirements, additional checks and verifications can be performed at this step.

Detecting NFC availability and subscribing for message(s)

Using the Windows Runtime proximity namespace classes, we can detect the presence of NFC capability on the device. If NFC capability is present, we can subscribe for specific types of messages. We can use the ProximityDevice.GetDefault static method for the default instance of NFC on the device.

In our case study, we subscribe for messages of type WindowsUri. Please refer to the article linked below for different message types supported.
http://msdn.microsoft.com/EN-US/library/windows/apps/hh701129

Below is a sample code snippet from the case study.

protected override void OnWindowCreated(WindowCreatedEventArgs args)
        {  
            var proxmityDev = ProximityDevice.GetDefault();
            if (proxmityDev != null)
            {                
                nfcmsgsubid = ProximityDevice.GetDefault().SubscribeForMessage("WindowsUri", MessageReceivedHandler);
                System.Diagnostics.Debug.WriteLine("prxDev found and registered");
            }
        }

        private void MessageReceivedHandler(ProximityDevice sender, ProximityMessage message)
        {
            PRAppUtil.ShowMsg("URI: " + message.DataAsString);
        }

Figure 5.Sample code snippet for NFC check and subscribe message ++

Additional steps can be performed in the Message handler, depending on your app requirements.

Reading and parsing NFC tag information

Since we encoded the patient or lab room information as part of our custom URI (on NFC tag) itself, we can parse the URI to decode the room number and log the check-in details. When our sample app gets activated, the full absolute URI that was obtained from the NFC tag is passed on to the OnActivated method call via the Uri.AbsoluteUri property of the args.

The code snippet below parses the room information and updates the user view model with check-in and check-out details.

protected async override void OnActivated(IActivatedEventArgs args)
        {
            if (args.Kind == ActivationKind.Protocol)
            {
                ProtocolActivatedEventArgs protocolArgs = args as ProtocolActivatedEventArgs;

                await InitMainPage(args);

                var frame = Window.Current.Content as Frame;

                var loggedinuser = SessionSettingsViewModel.SessionSettings.Loginuser;
                if (loggedinuser == null || !loggedinuser.LoginState)
                {
                    frame.Navigate(typeof(Login));
                    return;
                }
                if (frame.CurrentSourcePageType != typeof(UserPage)) frame.Navigate(typeof(UserPage));

                int rm = Convert.ToInt32(protocolArgs.Uri.AbsoluteUri.Split('=')[1]);
                if (ru.rm != 0 && ru.rm != rm) ru.rm = 0; 
                if (ru.rm == 0)
                {
                    ru.rm = rm;
                    ru.cin = DateTime.Now;
                }
                else
                {
                    ru.cout = DateTime.Now;
                    RoomUsageViewModel.AddRoomUsage(ru.rm, ru.cin, ru.cout);
                    ru.rm = 0;                    
                }
                
            }
        }

Figure 6.Sample code for parsing the NFC URI for room information and updating user view model ++

In our case study, we have a separate user home page where all the room check-in/check-out information is displayed. It automatically gets updated every time the user taps the room identifier NFC tag with our custom URI scheme. Please refer to the screen shot in Figure 7 for additional details.


Figure 7.Default camera UI dialog (captured from Windows* 8)

Summary


NFC enables several types of use cases. In this article, we discussed how a sample healthcare app incorporates NFC into its workflow to provide an enhanced user experience and enable new types of usage models. We discussed how you can easily add protocol activation and simple NFC usage to your Windows Store apps.

Intel, the Intel logo are trademarks of Intel Corporation in the US and/or other countries.
Copyright © 2013 Intel Corporation. All rights reserved.
*Other names and brands may be claimed as the property of others.

 

  • ultrabook
  • store
  • applications
  • Notebooks
  • near field communication
  • Apps
  • NFC
  • Intel AppUp® Developers
  • Microsoft Windows* 8
  • Microsoft Windows* 8 Style UI
  • Sensors
  • Laptop
  • Tablet
  • URL

  • Viewing all articles
    Browse latest Browse all 82

    Trending Articles



    <script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>