Beispiel #1
0
 def get_stats(self):
     cnds = self.navb.conditions()
     cnds.update({
         "(created_at) >= '%s'" % (self.navb.start): '',
         "(created_at) <= '%s'" % (self.navb.finish): ''
     })
     exts = {}
     attrs = [(makecol(x[0]), x[1]) for x in queries.STOCK_DATA['attrs']]
     exts.update(
         dict([(makecol(x[0]), ('COUNT(*)', x[0]))
               for x in queries.STOCK_DATA['attrs']]))  #;print exts
     cols = ['COUNT(*) AS total']
     nat = Stock.fetch_stock(cnds, cols, exts)
     #print attrs, "NAT: ", nat[0].__dict__
     return [attrs, nat]
Beispiel #2
0
 def get_total(self):
     cnds = self.navb.conditions()
     exts = {}
     cols = ['COUNT(*) AS total']
     total = Stock.fetch_stock(cnds, cols, exts)[0]
     return total
Beispiel #3
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