def handle(self, text): # abort if the user hasn't identified yet if self.msg.reporter is None: self.must_register() return True # create a new person linked back to the reporter # and their person = PregnantPerson.objects.create() report = PregnancyReport.objects.create( person=person) person.reporters.add(self.msg.reporter) resp = "Thank you for reporting a pregnancy" follow_resp = "Pregnancy reported by %s (%s)" %\ (self.msg.reporter, self.msg.reporter.connection.identity) # explicitly link the reporter's location, # in case they move during the pregnancy loc = self.msg.reporter.location if loc is not None: person.locations.add(loc) follow_resp += " at %s" % (loc) # extract the last menses date, if possible last_menses, text = extract_date(text) if last_menses is not None: person.last_menses = last_menses person.save() # save any tags extracted during # parse phase by the tagging app if hasattr(self.msg, "tags"): if len(self.msg.tags) > 0: for tag in self.msg.tags: report.tags.add(tag) suffix = " with indicators: %s" %\ (", ".join(map(unicode, self.msg.tags))) resp += suffix follow_resp += suffix # assume that the remainder of the text is the # woman's national id (rwanda-specific; sorry) person.code = text.strip() person.save() self.respond("%s." % resp) follower = self.msg.reporter.followers.all()
def handle(self, text): # abort if the user hasn't identified yet if self.msg.reporter is None: self.must_register() return True resp = "Thank you for reporting a birth" report = BirthReport() # extract and record the birth weight weight, text = extract_weight(text) if weight is not None: report.weight = weight resp += " at %.1f kg" % (weight) # extract and record the date of birth date, text = extract_date(text) if date is not None: report.date = date resp += " on %s" %\ format(date, "%d/%m/%Y") # now that the weight and date have been # removed, assume that the rest is the # mother's unique code (todo: __search__) try: person = PregnantPerson.objects.get( code=text.strip()) except PregnantPerson.DoesNotExist: self.respond("You must register the pregnancy before reporting a birth.") return True report.person = person report.save() # save any tags extracted during # parse phase by the tagging app if hasattr(self.msg, "tags"): if len(self.msg.tags) > 0: for tag in self.msg.tags: report.tags.add(tag) resp += " with indicators: %s" %\ (", ".join(map(unicode, self.msg.tags))) self.respond("%s." % resp)
def handle(self, text): # abort if the user hasn't identified yet if self.msg.reporter is None: self.must_register() return True resp = self.respond("Thank you for reporting a birth.") report = BirthReport() # extract and record the birth weight weight, text = extract_weight(text) if weight is not None: resp.append("Weight: %(weight)sKG", weight=("%.1f" % weight)) report.weight = weight # extract and record the date of birth date, text = extract_date(text) if date is not None: resp.append("Date: %(date)s", date=format(date, "%d/%m/%Y")) report.date = date # now that the weight and date have been # removed, assume that the rest is the # mother's unique code (todo: __search__) #code = re.sub(r"[^0-9]", "", text.strip()) code = self._national_id() person, created = PregnantPerson.objects.get_or_create( code=code) #if len(persons) == 0: # self.respond("You must register the pregnancy before reporting a birth.") # return True #person = persons[0] report.person = person report.save() # save any tags extracted during # parse phase by the tagging app if hasattr(self.msg, "tags"): if len(self.msg.tags) > 0: for tag in self.msg.tags: report.tags.add(tag)