예제 #1
0
    def get_stats(self):
        cnds = self.navb.conditions()
        cnds.update({"(created_at) <= '%s'" % (self.navb.finish): ''})
        cnds.update({"(created_at) >= '%s'" % (self.navb.start): ''})
        red_exts = {}
        red_attrs = [(makecol(x[0]), x[1]) for x in queries.RED_DATA['attrs']]
        red_exts.update(
            dict([(makecol(x[0]), ('COUNT(*)', x[0]))
                  for x in queries.RED_DATA['attrs']]))
        cols = ['COUNT(*) AS total']
        red = Redalert.fetch_redalerts(cnds, cols, red_exts)

        rar_exts = {}
        rar_attrs = [(makecol(x[0]), x[1]) for x in queries.RAR_DATA['attrs']]
        rar_outs = [(makecol(x[0]), x[1]) for x in queries.RAR_DATA['outs']]
        rar_exts.update(
            dict([(makecol(x[0]), ('COUNT(*)', x[0]))
                  for x in queries.RAR_DATA['attrs']]))
        rar_exts.update(
            dict([(makecol(x[0]), ('COUNT(*)', x[0]))
                  for x in queries.RAR_DATA['outs']]))
        rar = Redalert.fetch_redresults(cnds, cols, rar_exts)
        #print red_attrs, rar_attrs, red[0].__dict__, rar[0].__dict__
        return [red_attrs, rar_attrs, rar_outs, red, rar]
예제 #2
0
    def get_stats(self):
        cnds = self.navb.conditions()
        cnds.update({"(created_at) <= '%s'" % (self.navb.finish): ''})
        cnds.update({"(created_at) >= '%s'" % (self.navb.start): ''})
        cols = ['COUNT(*) AS total']
        exts = {}
        nat = [
            ("pre", "Pregnancy", Pregnancy.fetch_pregnancies(cnds, cols,
                                                             exts)),
            ("anc", "Antenatal Consultation",
             Ancvisit.fetch_ancvisits(cnds, cols, exts)),
            ("ref", "Refusal", Refusal.fetch_refusals(cnds, cols, exts)),
            ("red", "Red Alert", Redalert.fetch_redalerts(cnds, cols, exts)),
            ("rar", "Red Alert Result",
             Redalert.fetch_redresults(cnds, cols, exts)),
            ("risk", "Risk", Risk.fetch_risks(cnds, cols, exts)),
            ("res", "Risk Result", Risk.fetch_riskresults(cnds, cols, exts)),
            ("dep", "Departure", Departure.fetch_departures(cnds, cols, exts)),
            ("bir", "Birth", Birth.fetch_births(cnds, cols, exts)),
            ("pnc", "Postnatal Care",
             Pncvisit.fetch_pncvisits(cnds, cols, exts)),
            ("nbc", "Newborn Care", Nbcvisit.fetch_nbcvisits(cnds, cols,
                                                             exts)),
            ("chi", "Child Health",
             Childhealth.fetch_childhealths(cnds, cols, exts)),
            ("cbn", "Community Based Nutrition",
             Nutrition.fetch_nutritions(cnds, cols, exts)),
            ("ccm", "Community Case Management",
             CCM.fetch_ccms(cnds, cols, exts)),
            ("cmr", "Case Management Response",
             CCM.fetch_cmrs(cnds, cols, exts)),
            ("dth", "Death", Death.fetch_deaths(cnds, cols, exts)),
            ("smn", "Severe Malaria",
             Malaria.fetch_malaria(
                 self.extra_cnds(cnds, extra={"keyword = 'SMN'": ''}), cols,
                 exts)),
            ("smr", "Severe Malaria Result",
             Malaria.fetch_malaria(
                 self.extra_cnds(cnds, extra={"keyword = 'SMR'": ''}), cols,
                 exts)),
            ("rso", "Risk Of Stock Out",
             Stock.fetch_stock(
                 self.extra_cnds(cnds, extra={"keyword = 'RSO'": ''}), cols,
                 exts)),
            ("so", "Stock out",
             Stock.fetch_stock(
                 self.extra_cnds(cnds, extra={"keyword = 'SO'": ''}), cols,
                 exts)),
            ("ss", "Stock Supplied",
             Stock.fetch_stock(
                 self.extra_cnds(cnds, extra={"keyword = 'SS'": ''}), cols,
                 exts)),
        ]

        data = {}
        attrs = [(x[0], x[1]) for x in nat]
        total = 0
        for an in nat:
            try:
                value = an[2][0].total
                print value, an[0]
                data.update({an[0]: value})
                total += value
            except Exception, e:
                print e
                data.update({an[0]: 0})
                continue