Fighting Malnutrition
with SMS and Django



            Andy McKay
             clearwind consulting
              andy@c...
clearwind consulting




Lots of Plone sites
Wrote book
clearwind consulting




Prinicpal of Clear wind
Been doing Python for about 9 years
co-founder of Enfold Systems
clearwind consulting
clearwind consulting




existing project
clearwind consulting




rapidsms
clearwind consulting




Schuyler Erle
  Matt Berg
Adam McKaig
 and others...
clearwind consulting




deployment help?
clearwind consulting




4 days, 32 hours flight...
clearwind consulting
clearwind consulting




and yes this area is home
to a certain famous
family....
clearwind consulting




 health care workers
for community health
care workers in the field

large number of children
to ...
clearwind consulting
clearwind consulting




                   identify and help
sometimes not easy to spot malnurished kids

maybe no record...
clearwind consulting




                            disclaimer
I am not a health care
worked or related to
development

i...
clearwind consulting




Robbed of vital nutrients as
children, they grow up stunted and
sickly, weaklings in a land that ...
clearwind consulting




muac
mid upper arm
circumfrence




                        Matt Berg
clearwind consulting




       muac


children   worker
clearwind consulting




       muac     sms


children   worker     django
clearwind consulting




       muac     sms            sms


children   worker     django         clinic
clearwind consulting




serial

spomskyd
clearwind consulting




serial

spomskyd

http


django route
clearwind consulting
clearwind consulting




                            serial

                            pygsm

                          ...
clearwind consulting




serial
           workers
pygsm

http
         custom ui

django route
         django runserver
clearwind consulting




  Note: test data
clearwind consulting




  Note: test data
clearwind consulting




  Note: test data
clearwind consulting




serial
           workers admins
pygsm

http
         custom ui         admin

django route
     ...
clearwind consulting




7654321 > +26 105 d v f




child 26
MUAC 105
diarrheoa
vomiting
fever
clearwind consulting




    7654321 > +26 105 d v f

   7654321 < MUAC> SAM+ Patient requires
IMMEDIATE inpatient care. +...
clearwind consulting




    7654321 > +26 105 d v f

   7654321 < MUAC> SAM+ Patient requires
IMMEDIATE inpatient care. +...
clearwind consulting




malaria
clearwind consulting




7654321 > mrdt +34 y n f




                malaria rapid
                diagnosis

           ...
clearwind consulting




    7654321 > mrdt +34 y n f

     7654321 < MRDT> Child +34, MADISON, Molly,
F/12m has MALARIA. ...
clearwind consulting




              Matt Berg
clearwind consulting




flew back
clearwind consulting




   slept
   moved house
   slept, slept




http://www.flickr.com/photos/chris_gin/2388032929/size...
clearwind consulting




                          technical details

some of these are based on later work for Malawi

ta...
clearwind consulting




rapidsms
clearwind consulting




from rapidsms.message import Message


message.text
message.person   rapidsms api




message.sen...
clearwind consulting




decorator for routing
clearwind consulting




# Register a new patient
@keyword(r'new (S+) (S+) ([MF]) ([d-]+)
( D+)?( d+)?( zd+)?')
@authentic...
clearwind consulting




i like urls.py
clearwind consulting




1. see what's going where
2. route to different
                  its a django standard,
        ...
clearwind consulting




urlpatterns = patterns('',
    (r'^new (.*)',
    "apps.mctc.views.joining.new_case"),
)
        ...
clearwind consulting




try:
  callback, args, kwargs = resolver.resolve
(message.text.lower())
except Resolver404:
   me...
clearwind consulting




form handling
clearwind consulting




   full of checking
code, views were full of
checking and validation

in django this is done by
f...
clearwind consulting




parse string into form
clearwind consulting




# NEW 70 1201 M 19102008 123124124

class NewForm(Form):
    child = StringField(valid="(d+)")
  ...
clearwind consulting




   class based views
http://www.slideshare.net/simon/
classbased-views-with-django
clearwind consulting




class based view that does repetitive
work
→ validate form
→ process form
→ what to do if it goes...
clearwind consulting


class MalawiNew(New):
    @authenticated
    def post_init(self):
        self.form = NewForm
    
...
clearwind consulting




testing
clearwind consulting




tests really matter
clearwind consulting



                                        brillianty done format

test_05_cancelling = """          ...
clearwind consulting




     reusable table
http://github.com/andymckay/
django-reusable-tables/tree/master
clearwind consulting




  Note: test data
clearwind consulting




liking it less
clearwind consulting




register("case", Case, [
 ["Id", "ref_id", "{{object.ref_id}}"],
 ["Name", "last_name", "{{object...
clearwind consulting




what challenges?
clearwind consulting




another framework?

      designed for a non-technical audience

      as a techy that can be ann...
clearwind consulting




                       not enough time
schuyler, adam, matt
clearwind consulting




infrastructure

this is the pavement in
the main street
clearwind consulting




We have over 5000 kids in the
system now and counting. It's
been used to catch over 100 kids
with...
clearwind consulting




thank you, django
clearwind consulting




volunteers wanted

 5-10
 Hour projects we would
 love volunteer help with
clearwind consulting




       more info
www.rapidsms.org/rapidresponse
  mberg@ei.columbia.edu
clearwind consulting




questions
            Andy McKay
            clearwind consulting
             andy@clearwind.ca
...
Fighting Malnutrition with SMS and Django
Upcoming SlideShare
Loading in …5
×

Fighting Malnutrition with SMS and Django

3,346 views
3,182 views

Published on

Published in: Technology, Business
1 Comment
3 Likes
Statistics
Notes
  • if you are looking for sending SMS from django using gateways, see django-smsgate application http://bitbucket.org/vgavro/django-smsgate/
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total views
3,346
On SlideShare
0
From Embeds
0
Number of Embeds
224
Actions
Shares
0
Downloads
83
Comments
1
Likes
3
Embeds 0
No embeds

No notes for slide

Fighting Malnutrition with SMS and Django

  1. 1. Fighting Malnutrition with SMS and Django Andy McKay clearwind consulting andy@clearwind.ca @clearwind
  2. 2. clearwind consulting Lots of Plone sites Wrote book
  3. 3. clearwind consulting Prinicpal of Clear wind Been doing Python for about 9 years co-founder of Enfold Systems
  4. 4. clearwind consulting
  5. 5. clearwind consulting existing project
  6. 6. clearwind consulting rapidsms
  7. 7. clearwind consulting Schuyler Erle Matt Berg Adam McKaig and others...
  8. 8. clearwind consulting deployment help?
  9. 9. clearwind consulting 4 days, 32 hours flight...
  10. 10. clearwind consulting
  11. 11. clearwind consulting and yes this area is home to a certain famous family....
  12. 12. clearwind consulting health care workers for community health care workers in the field large number of children to look after in village (not in clinics)
  13. 13. clearwind consulting
  14. 14. clearwind consulting identify and help sometimes not easy to spot malnurished kids maybe no records let other people know the kid needs help parents sometimes have enough trouble feeding rest of the family
  15. 15. clearwind consulting disclaimer I am not a health care worked or related to development i know the techy bits can't speak about efficiency of the program
  16. 16. clearwind consulting Robbed of vital nutrients as children, they grow up stunted and sickly, weaklings in a land that still runs on manual labor. http://www.nytimes.com/2006/12/28/world/africa/ 28malnutrition.html
  17. 17. clearwind consulting muac mid upper arm circumfrence Matt Berg
  18. 18. clearwind consulting muac children worker
  19. 19. clearwind consulting muac sms children worker django
  20. 20. clearwind consulting muac sms sms children worker django clinic
  21. 21. clearwind consulting serial spomskyd
  22. 22. clearwind consulting serial spomskyd http django route
  23. 23. clearwind consulting
  24. 24. clearwind consulting serial pygsm http since then spomskyd has been replaced by pygsm django route pygsm do a lot of work sorting out all those sms quirks
  25. 25. clearwind consulting serial workers pygsm http custom ui django route django runserver
  26. 26. clearwind consulting Note: test data
  27. 27. clearwind consulting Note: test data
  28. 28. clearwind consulting Note: test data
  29. 29. clearwind consulting serial workers admins pygsm http custom ui admin django route django runserver
  30. 30. clearwind consulting 7654321 > +26 105 d v f child 26 MUAC 105 diarrheoa vomiting fever
  31. 31. clearwind consulting 7654321 > +26 105 d v f 7654321 < MUAC> SAM+ Patient requires IMMEDIATE inpatient care. +26 MADISON, M, F/4 (Sally). MUAC 105 mm, Diarrhea, Fever, Vomiting
  32. 32. clearwind consulting 7654321 > +26 105 d v f 7654321 < MUAC> SAM+ Patient requires IMMEDIATE inpatient care. +26 MADISON, M, F/4 (Sally). MUAC 105 mm, Diarrhea, Fever, Vomiting 7654322 < @jdoe reports +26: SAM+, MUAC 105 mm, Diarrhea, Fever, Vomiting
  33. 33. clearwind consulting malaria
  34. 34. clearwind consulting 7654321 > mrdt +34 y n f malaria rapid diagnosis child 34 y has malari n has no bednet f has a fever
  35. 35. clearwind consulting 7654321 > mrdt +34 y n f 7654321 < MRDT> Child +34, MADISON, Molly, F/12m has MALARIA. Child is less than 3. Please provide 1 tab of Coartem (ACT) twice a day for 3 days
  36. 36. clearwind consulting Matt Berg
  37. 37. clearwind consulting flew back
  38. 38. clearwind consulting slept moved house slept, slept http://www.flickr.com/photos/chris_gin/2388032929/sizes/l/
  39. 39. clearwind consulting technical details some of these are based on later work for Malawi talk about a few of the bits i worked on interesting
  40. 40. clearwind consulting rapidsms
  41. 41. clearwind consulting from rapidsms.message import Message message.text message.person rapidsms api message.send() message.respond(text) message.forward(identity, text=None)
  42. 42. clearwind consulting decorator for routing
  43. 43. clearwind consulting # Register a new patient @keyword(r'new (S+) (S+) ([MF]) ([d-]+) ( D+)?( d+)?( zd+)?') @authenticated def new_case (self, message,...[snip]): # Do something with the new patient
  44. 44. clearwind consulting i like urls.py
  45. 45. clearwind consulting 1. see what's going where 2. route to different its a django standard, more friendly for other users easier to change sms without having to change the code
  46. 46. clearwind consulting urlpatterns = patterns('', (r'^new (.*)', "apps.mctc.views.joining.new_case"), ) despite the name, url patterns can be used for more than just urls
  47. 47. clearwind consulting try: callback, args, kwargs = resolver.resolve (message.text.lower()) except Resolver404: message.respond(_("Unknown command: %(msg) s...) % {"msg":message.text[:10]})
  48. 48. clearwind consulting form handling
  49. 49. clearwind consulting full of checking code, views were full of checking and validation in django this is done by forms
  50. 50. clearwind consulting parse string into form
  51. 51. clearwind consulting # NEW 70 1201 M 19102008 123124124 class NewForm(Form): child = StringField(valid="(d+)") gmc = StringField(valid="(d+)") sex = GenderField() dob = DateField(format="%m%d%Y") contact = StringField(valid="(d+)", required=False)
  52. 52. clearwind consulting class based views http://www.slideshare.net/simon/ classbased-views-with-django
  53. 53. clearwind consulting class based view that does repetitive work → validate form → process form → what to do if it goes wrong subclassed for different country (eg. Malawi)
  54. 54. clearwind consulting class MalawiNew(New):     @authenticated     def post_init(self):         self.form = NewForm          def pre_process(self):         # malawi specific request         years, months = years_months(self.form.clean.dob.data.strftime.data)         if years > 5:             raise FormFailed, "You have attempted to register child #%s. However, "                 "the date of birth entered is %s. The age of this "                 "child is above 5 years. Please resend SMS with corrected "                 "age." % (self.form.clean.child.data, self.form.clean.dob.data.strftime("%m. %d.%Y"))          def post_process(self):         if self.form.clean.contact.data:             self.data.case.mobile = self.form.clean.contact          def error_already_exists(self):         # malawi specific code         return "You have attempted to register child #%s in %s GMC. However, this child already exists. If this is an error, please resend SMS with correct information. If this patient is new or a replacement, please use the EXIT command first, then re-register." % (self.form.clean.child.data, self.data.provider.clinic.name)
  55. 55. clearwind consulting testing
  56. 56. clearwind consulting tests really matter
  57. 57. clearwind consulting brillianty done format test_05_cancelling = """ allows easy reading by non technical users 1234567 > REPORT 70 25.2 95.5 13.5 N Y 1234567 < Thank you Mariam Coulibaly for reporting child #70, weight = 25.2 kg, height = 95.5 cm, MUAC = 13.5 cm, no oedema, yes diarrhea...[snip] 1234567 > CANCEL 70 1234567 < Report for 70 cancelcel... [snip]"""
  58. 58. clearwind consulting reusable table http://github.com/andymckay/ django-reusable-tables/tree/master
  59. 59. clearwind consulting Note: test data
  60. 60. clearwind consulting liking it less
  61. 61. clearwind consulting register("case", Case, [ ["Id", "ref_id", "{{object.ref_id}}"], ["Name", "last_name", "{{object.first_name}} {{object.last_name}}"], ...[snip] ])
  62. 62. clearwind consulting what challenges?
  63. 63. clearwind consulting another framework? designed for a non-technical audience as a techy that can be annoying, eg settings.py if you just want to speak to SMS and nothing else, maybe better way to go
  64. 64. clearwind consulting not enough time schuyler, adam, matt
  65. 65. clearwind consulting infrastructure this is the pavement in the main street
  66. 66. clearwind consulting We have over 5000 kids in the system now and counting. It's been used to catch over 100 kids with malnutrition and about 400 with malaria. Matt Berg
  67. 67. clearwind consulting thank you, django
  68. 68. clearwind consulting volunteers wanted 5-10 Hour projects we would love volunteer help with
  69. 69. clearwind consulting more info www.rapidsms.org/rapidresponse mberg@ei.columbia.edu
  70. 70. clearwind consulting questions Andy McKay clearwind consulting andy@clearwind.ca @clearwind

×