Exemplo n.º 1
0
    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"
        report = ChildReport()

        # extract and record the weight
        weight, text = extract_weight(text)
        if weight is not None:
            report.weight = weight
            resp += " at %.1f kilos" % (weight)

        # extract and record the muac
        muac, text = extract_length(text)
        if muac is not None:
            report.muac = muac
            resp += " with a MUAC of %.1f cm" % (muac)


        try:
            person = PregnantPerson.objects.get(
                code=text.strip())

        except PregnantPerson.DoesNotExist:
            self.respond("You must register the pregnancy before reporting.")
            return True


        try:
            birth_report = BirthReport.objects.get(
                person=person)

        except BirthReport.DoesNotExist:
            self.respond("You must report the birth before reporting.")
            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)
Exemplo n.º 2
0
    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.")
        report = ChildReport()

        # extract and record the 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 muac
        muac, text = extract_length(text)
        if muac is not None:
            resp.append("MUAC: %(muac)sCM", muac=("%.1f" % muac))
            report.muac = muac


        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.")
        #    return True

        #person = persons[0]


        birth_report = BirthReport.objects.get_or_create(
            person=person)

        #if len(birth_reports) == 0:
        #    self.respond("You must report the birth before reporting.")
        #    return True

        #birth_report = birth_reports[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)
Exemplo n.º 3
0
    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)
Exemplo n.º 4
0
    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)