Heart Rate Monitoring App

Objectives

In this tutorial, developers will learn:

  • How to initiate collaborations
  • How to add and configure collaboration roles
  • How to add and configure collaboration activity patterns
  • How to close and verify closed collaborations

Tutorial Overview:

This Tutorial imagines a scenario where an at-risk patient wears a heart rate monitor. If an unusual heart rate is detected
(either dangerously low or dangerously high), the patient is sent a notification to assess their status. If the patient
responds that they are in distress, or fails to respond within a predetermined amount of time, a first responder is
notified immediately.

All lessons assume the developer has a working knowledge of the Vantiq IDE. It is recommended that a new
developer completes the lessons in the Introductory Tutorial before starting the lessons in this tutorial.
In addition, please see the Collaboration Overview guide for introductory information about the Vantiq collaboration system.

Note: if needed, you can import a finished version of this project using the Projects -> Import menu item. Just select Tutorials for Import Type, then select Introduction to Collaboration from the second drop-down, then click Import.

1: Creating a Patient Monitoring Project

The first task in building the heart rate monitor system is to create a project in the Vantiq IDE. A Project is a container
for your development resources.

Use the Projects button and select New Project to display the New Project Wizard. Either create a new Namespace
(recommended) or add a new project to the current Namespace, select Empty as the Project type, and title the project PatientMonitor.

New Project

The rest of the lessons take place inside this Project.

2: Creating a Patient Monitoring Service

Using the Add button, select Service and click + New Service. Set the service name to HeartRate and the package
name to patient.monitoring.

Create Service

Click OK to create the Service.

3: Defining an Inbound Event Type and Handler

In the patient.monitoring.HeartRate Service, navigate to the Implement tab. Click on the + button next to Inbound
and select Add Visual Event Handler.

Add Visual Event Handler

Set the Event Type name to MonitorReading and click OK. This
creates an Inbound Event Type in the Service Interface and its visual Event Handler in one step!

Inbound Event Type Name

Click Save in the title bar for the Service.

Next, enhance the Event Type definition by defining an Event Schema. Click on the Interface tab and expand the Inbound
section. Click on MonitorReading to open the Event Type Interface definition.

In the Event Schema section select New Type. Define the following properties as the event schema:

  • patientId (String)
  • name (String)
  • heartRate (Integer)
  • location (GeoJSON)

Inbound Event Type Schema

Click Save in the title bar for the Service.

4: Filtering for Unusual Readings

Navigate back to the Event Handler by clicking on the Implement tab, expanding the Inbound section, and clicking on
MonitorReading. Drag and drop a Filter task from the Filters section of the palette over the EventStream.

Click on the Filter task and in the configuration slideout rename the task isUnusualHeartRate.

isUnusualHeartRate Filter Task

Click Click to Edit next to the Configuration label. Click on <null> next to the condition property. Set the condition to:

event.heartRate < 40 OR event.heartRate > 200

isUnusualHeartRate Filter Condition

Click OK twice to close the pop-ups.

Click Save in the title bar for the Service.

5: Simulating Monitor Readings

Before going any further, create a Procedure that simulates heart rate monitor readings to interactively test and debug
the App.

Click on the + button next to the Procedure Section and click New Procedure.

Add Procedure

Set the procedure text to:

package patient.monitoring
PROCEDURE HeartRate.generateHeartRate(heartRate Integer)

var event = {
    name: Context.preferredUsername(),
    patientId: Context.username(),
    heartRate: heartRate,
    location: {
        "type": "Point",
        "coordinates": [
            -122.0651683957521,
            37.90793522730274
         ]
    }
}

PUBLISH event TO SERVICE EVENT "patient.monitoring.HeartRate/MonitorReading"

Click Save to save the Service with the new procedure. You will see a message slide in from the right that the Services’s Interface has been repaired.

GenerateHeartRateText

Right-click on the generateHeartRate Procedure entry and select Open In New Pane.

Open In New Pane

Navigate back to the Event Handler by clicking on the Implement tab, expanding the Inbound section, and clicking on
MonitorReading.

Click the Play button in the Procedure pane to execute the procedure and pass 100 as the current heart rate. After clicking Execute, Click
OK to close the resulting pop-up. Notice that there is an event badge on the EventStream but not on the Filter task.
That is because the heart rate is in the “normal” range and therefore was filtered out.

Normal Heart Rate Event

Click the Play button in the Procedure pane again, but this time pass in 30 as the heart rate. Notice that this time
there are event badges on both the EventStream and Filter tasks since the event passed through the filter.