Search for answers or browse our knowledge base.
Advanced Collaborations
Overview
In the Introductory Collaboration Tutorial you created an App that detects whether a patient is in distress
and sends a notification to a first responder. However, the complexity of finding and notifying the correct first responder
was overlooked.
In this tutorial you will compute a list of available first responders sorted by their proximity to the patient. You’ll send a message to a responder,
waiting a specified amount of time before retracting the message and trying the next closest responder. Once a responder
confirms that they are on their way, you will track the first responder’s location until they arrive at the patient.
Import Intro Collaboration Tutorial
This Tutorial will start where the Introductory Collaboration Tutorial left off. It is highly recommended that you
complete the Introductory Collaboration Tutorial before starting this one. To import the final result of the
Introductory Collaboration Tutorial use the Projects button and click Import. Select Tutorials as the
Import Type and select Introduction to Collaboration from the droplist. Click OK to complete the import and then
click Reload once the import completes.
Create First Responder Instances
Start by creating a FirstResponder persistent Type. Use the Add button to select Type and click + New Type.
Set the name to FirstResponder and the Role to standard. Click OK.
Click on the Properties tab in the FirstResponder Type pane and click + Add Property. Set the following properties
on the type:
- name (String)
- username (String)
- location (GeoJSON)
Click OK to close the add property pop-up and then Save the Type.
Next, create a few instances of the FirstResponder Type. The username property is be used
to send Notifications to first responders later in this tutorial. This means that the usernames must point to valid, existing, Vantiq
users. For the sake of this Tutorial, set the username on each instance to your username so that the messages will
be sent to your mobile phone.
However, we’ll give each first responder a unique name as if they are actually separate people. To get your username, click on the
user icon in the Vantiq banner. Hover your mouse over the username until a green plus
icon appears. Clicking on the username copies it to your clickboard.
Click Add New Record at the top of the Type pane. Set the name to John Smith. Paste your username as the username.
Click onto the link to specify the GeoJSON location. Set the location type to Point. Set the longitude to -122.4194 and
latitude 37.7749 Click Add Record.
Add the following additional instances:
"name": "Sarah Brown",
"username": "<your username>",
"location": longitude: -122.27304, latitude: 37.8715
"name": "Robert Johnson",
"username": "<your username>",
"location": longitude: -122.2892 latitude: 37.8395
Recommend First Responder
Drag a Recommend task from the Collaboration section of the palette over the link between GetPatient and NotifyFirstResponder and then drop it.
Rename the Recommend task FindResponders.
Double-click on the new task to open its configuration. Set the Candidate Type to FirstResponder.
Set the returnBehavior to Attach Return value to returnProperty and then set returnProperty to recommendedResponders.
Click OK.
Notify First Responder and wait
Use the results from the Recommend task to Notify first responders one at a time, starting with the closest responder.
If the first responder does not accept the notification within 1 minute, retract the message and notify the next
closest responder.
LoopWhile
Drag a LoopWhile task from the Flow Control section of the palette over the link between FindResponders and NotifyFirstResponder and then drop it.
Select whileTrue as the downstream event. The LoopWhile task is the App Builder’s version of a while loop. It
repeatedly executes the tasks in the whileTrue branch of the task from the whileTrue event to the branch leaf until the condition is false.
For more details on the Loop While activity pattern reference the Loop While documentation.
Click on the new task and open its configuration. Set the condition to counter < length(event.recommendedResponders).
Set the counterProperty to counter. The counter property is attached to the outbound event so that any tasks
in the whileTrue branch have access to the loop counter. Click OK.
Next click on the NotifyFirstResponder task to update the configuration.
Update the body to: event.recommendedResponders[event.counter].name + ": Are you available to assist " + event.name + "?"
.
Click on the users property and update the user to event.recommendedResponders[event.counter].username
. This will index
into the recommendedResponders array and return the event.counter
th username. Click OK to close the pop-up.
Wait For Response
Drag and drop a Delay task from the Flow Control section of the palette onto the NotifyFirstResponder task. Select event as the
downstream event. Notice that the Delay task is directly connected to the NotifyFirstResponder task rather than an asynchronous
downstream event triangle. This means that it is executed as part of the loop root to leaf path. Rename the task AwaitResponse.
Click Click to Edit to configure the Delay task and set the delay to 1 minute.