About •  Books •  Apps •  Jobs •   Feeds •  Twitter
Login
Django Ski: a Django conference with a difference. Whistler, March 2010.

Django, Malnutrition, SMS and Kenya

How I ended up doing one of most interesting and important projects I've been involved with.

Kisumu SunsetA while back I got home from dinner to find a quick Skype chat from a friend, Nate Aune that basically went "you free to go to Kenya to do some Django - oh and you have to leave on Sunday" (that was in about 4 days time). The response was "is this for real?". But as it turns out it was and about 6 days later I was leaving on a plane to Kenya, to work on a Django project.

The person behind this project is Matt Berg, who works at Columbia University on the Millennium Villages project. This particular project was already in the works and was based on excellent work from Schuyler Erle, I was to provide support on site and add in some new features.

The goal of this particular Django project is to help health care workers resolve cases of malnutrition (and as it turned out malaria and other diseases) faster and help more children get treatment faster. To do this, the project uses cell phones.

So when a health care worker using the project finds a child with malnutrition, they enter the details into a their cell phone and send a text message to a phone number. For all you twitterers out there, you will realize we hit the downside, those details entered ideally need to be under 140 chars.

Set up is a modem listening to that number, it feeds into a Ruby daemon called spomsky which is part of the RapidSMS project. That pushes a request over to a RapidSMS project written in Django and that's where it get's relevant to this blog.

RapidSMS is a cool project that "is UNICEF's open source platform for data collection, logistics coordination and communication allowing any mobile phone to interact with the web". You can get the source here: http://rapidsms.org/.

Once the message comes in, it hits a Django process, unlike most Django web applications there are two processes running. The first is a RapidSMS process called route and this is a process that connects to spomsky and listens for text's coming in. The second is the standard Django runserver which provides a web interface for managers to see what is going on.

So the message is evaluated, for example: does this child one of the levels of malnutrition that warrant attention. If it does then we send a message back to the health care worked asking for the child to be sent to the clinic. It will also route messages to the clinic and to the local health care co-ordinator.

This routing is done using a very clever decorator that allows you to assign what text message goes to what method, eg:

 @keyword(r'n(?:ote)? \+(\d+) (.+)')
    @authenticated
    def note_case (self, message, ref_id, note):         
        [...]

Sending out a message is a simple in RapidSMS as doing:

    message.respond("Thanks")

Here's a phone getting messages, with the logs in the background:

It works

In this example, you can send in a text message that reads (for example):

note +12 has malnutrition and needs care now

Where +12 is the child's ID. The + was chosen to signify an ID, because on the particular phones used, the + is easy to get to without hitting too many buttons. Real messages would be more complicated and involve use of a MUAC measurement for example:

muac +26 7.5 2150 1.4 n

That rather cryptic text would give you back (new lines added for readability):

MUAC> SAM Patient requires OTP care. 
  +26 MADISON, M, F/4 (Sally). 
  MUAC 75 mm, 2.1 kg, 140 cm

These responses would go to health care facilitator's or co-ordinator's or to the clinics as relevant. Not only then does this give people the notification to follow up and make sure that the children get the treatment, but allows recording of the data.

On the back end in the office, there's that second Django process which serves out a front end, that allows them to search, find and get data on the users. As that UI evolves it will let the users look up that data by clinic, district and so on.

This might sound simple, but for all those incoming messages, we wrote a lot of tests. I've done some mission critical code before, but knowing that I could miss a child with a serious medical condition, made me even more paranoid than normal. RapidSMS includes the really nice ability to write tests in a simple way.

For example here's an example of an incoming malaria test of a child from phone number 7654321 (signified by the >). It is then sent to back to the reporter and also to a supervisor at 7654322 (signified by the <)

7654321 > mrdt +26 y n f
7654321 < MRDT> Child +26, MADISON, Molly, F/4 has MALARIA. 
    Child is 4. Please provide 2 tabs of Coartem (ACT) 
    twice a day for 3 days
7654322 < MRDT> Child +26, MADISON, Molly, F/4 (None) has MALARIA. 
    CHW: @jdoe 7654321

Training

And that's it. For about 6 days I worked with Matt adding in new features, new forms and new tools for the health care workers. On one day I got the chance to go out into the field and watch the health care workers get trained. It was great to see the health care workers pick this system up quickly and get used to using the system. The first few times sending messages took a little bit of time, but after a while they picked up quickly and really got the hang of the system and really seemed to appreciate it.

A brief aside here, the use of cell phones for this is absolutely brilliant. In Kenya there are lots and lots of cell phones. I won't go as far to say everyone has one, but lots do. One image that struck me was a farmer clearing a field and taking a call on his cell phone at the time. Africa skipped the whole "stringing copper wires from poles" step that Western societies took. In Canada on every street corner there's a Starbucks. In Nairobi it's a cell phone store or pre-paid top up.

And that's it, a few days later I was on a plane back over to Canada (well 4 planes). Leaving some people with the task of driving adoption and training users in the field how to use the project.

Of all the projects I've done, it's got the potential for being the most important project I've done - and that's really cool. And the real potential of RapidSMS spreads way beyond just this project. The ability to set up a sophisticated distributed system quickly using SMS has so many possible applications. It could great for inventory management, disaster management, anything. With RapidSMS and Django it becomes a real possibility to set this system up quickly. Of course these sorts of systems have existed in the past, but I doubt they have been set up as quickly and easily as RapidSMS allows.

A big thanks by the way to Matt and Jess and other Millenium Villages people for looking after this muzungu while I was in Africa. Also thanks to Schuyler for doing lots of great work and helping out on RapidSMS, spomsky and git.

Note: The personal details of getting to Kenya and back and can be found over on my personal blog, the focus here is on the technical side. Further if you looking for details on the efficiency of malnutrition programs or this program in general, I don't have them either, I don't know anything about that, Django stuff only.

Comments

There are no comments.

Login to add comments