Exemplo n.º 1
0
    def vitamines_summary(self, message):
        """Send vitamines summary to health facilitators
        and those who are to receive alerts
        """
        header = _("Vitamines Summary by clinic:")
        result = []

        summary = ReportCHWStatus.vitamines_mini_summary()

        tmp = header
        for info in summary:

            if info["eligible_cases"] != 0:
                info["percentage"] = round(
                    float(float(info["vaccinated_cases"]) / float(info["eligible_cases"])) * 100, 2
                )
            else:
                info["percentage"] = 0
            item = " %(clinic)s: %(vaccinated_cases)s/%(eligible_cases)s " "%(percentage)s, " % info
            if len(tmp) + len(item) + 2 >= self.MAX_MSG_LEN:
                result.append(tmp)
                tmp = header

            tmp += item

        if tmp != header:
            result.append(tmp)

        subscribers = Reporter.objects.all()

        for text in result:

            for subscriber in subscribers:

                try:
                    if (
                        subscriber.registered_self
                        and ReporterGroup.objects.get(title="vitamines_summary") in subscriber.groups.only()
                    ):

                        # mobile = subscriber.connection().identity
                        # message.forward(mobile, _("%(msg)s") % {'msg': text})
                        message.respond(_("%(msg)s") % {"msg": text})
                except:
                    """Alert Developer

                    The group might have not been created,
                    need to alert the developer/in charge here
                    """
                    message.forward(
                        Cfg.get("developer_mobile"),
                        _("The group %(group)s has not been created.") % {"group": "measles_summary"},
                    )
        return True