Intercepting SMS Messages
When a new event occurs (such as patient admissions/discharges), this information can be transmitted instantly to the nurse using SMS messages.
Add the controls shown in Figure 2 to Form1.
SMS messages sent to the nurses will be in the following format:
TSK_REQ|<PatientID>|<WardNo>|<Description>
The following list shows sample SMS messages:
- TSK_REQ|123|6|Prepare patient for discharge
- TSK_REQ|456|5|Prepare patient for admission
- TSK_REQ|009|2|Prepare patient for surgery
Each message will begin with the
TSK_REQ identifier, followed by the patient ID, ward number, and the description of the task.

Figure 2. Task Information: Adding the controls to Form1 to display task information. | |  Figure 3. Task Messages: Receiving SMS task messages and displaying the individual task. |
In the code-behind of Form1, import the following namespace:
using Microsoft.WindowsMobile.PocketOutlook.MessageInterception;
Declare a variable of type MessageInterceptor:
public partial class Form1 : Form
{
const string HQPhoneNo = "651234567";
MessageInterceptor msgInterceptor;
The MessageInterceptor class allows you to intercept an incoming SMS message and raise an event.
In the Form1_Load event handler, create a new instance of the MessageInterceptor class and wire up the MessageReceived event with an event handler:
private void Form1_Load(object sender, EventArgs e)
{
msgInterceptor = new MessageInterceptor(
InterceptionAction.NotifyAndDelete, true);
msgInterceptor.MessageReceived += new
MessageInterceptorEventHandler(
msgInterceptor_MessageReceived);
}
The
MessageReceived event is fired whenever an incoming SMS message is received. In this event, you will first typecast the message received (via the
SmsMessage object. This is necessary so that you can retrieve the body of the SMS message received. You then add the content of the message into the ListBox control (shown in
Listing 1).
In this event, you also send an acknowledgement back to the sender by using another instance of the SmsMessage class.
When a nurse clicks on the ListBox control, you will display the details of the tasks in the various label controls (see also Figure 3):
private void listBox1_SelectedIndexChanged(
object sender, EventArgs e)
{
string task = listBox1.SelectedItem.ToString();
string[] field = task.Split('|');
if (field.Length == 4)
{
lblPatientID.Text = field[1];
lblWardNo.Text = field[2];
lblDescription.Text = field[3];
}
}