コード例 #1
0
ファイル: births.py プロジェクト: pivotaccess2007/mch
    def get_tables(self):
        cnds    = self.navb.conditions()
        cnds.update({"(birth_date) <= '%s'" % (self.navb.finish) : ''})
        cnds.update({"(birth_date) >= '%s'" % (self.navb.start) : ''})
        
        cnds, markup, cols = self.navb.neater_tables(cnds = cnds, extras = [
                                              ('national_id',            'Mother ID'),
                                              ('user_phone',            'Reporter Phone'),
                                              ('birth_date', 'Birth date'),
                                              ('child_weight', 'Weight'),
                                              ('recent_muac', 'Muac'),
                                              ('created_at', 'Submission Date'),
                                              ('indexcol', 'ID')
                                            ])

        markup.update({'indexcol': lambda x, _, __: '<a href="/dashboards/report?tbl=bir&id=%s">View</a>' % (x), })
        
        cnds.update({queries.DELIVERY_DATA['query_str']: ''})
        INDICS = [('all', 'total', 'Total')] + [(makecol(x[0]), x[0], x[1]) for x in queries.DELIVERY_DATA['attrs']]
        INDICSDICT = {x[0]: (x[1], x[2]) for x in INDICS}

        title, sc, group, attrs, nat, tabular, locateds, INDICS_HEADERS = ('', '', '', [], [], [],[],[])

        if self.navb.kw.get('subcat') is not None:
            sc = self.navb.kw.get('subcat')
            dcols = [x[0] for x in cols]
            wcl = INDICSDICT.get(sc)#; print wcl, PREDICT
            INDICS = [(sc, wcl[0], wcl[1])] if wcl else []
            INDICS_HEADERS = dict([ ( makecol(x[0]), x[2]) for x in INDICS])
            if wcl and wcl[0] != 'total':   cnds.update({wcl[0]: ''})
            nat = Birth.fetch_log_births(cnds, dcols)            
            #print wcl, INDICSDICT, INDICS
        else:
            dcols   = [x[0] for x in cols]
            nat = Birth.fetch_log_births(cnds, dcols)

        if self.navb.kw.get('view') == 'table' or self.navb.kw.get('view') != 'log' :
            group_by = []
            group_by += ['province_pk']  if self.navb.kw.get('nation') or not group_by else []
            group_by += ['district_pk'] if self.navb.kw.get('province') else []
            group_by += ['referral_facility_pk'] if self.navb.kw.get('district') else []
            group_by += ['facility_pk'] if self.navb.kw.get('hd') else [] 
            #print "\nGROUP BY: %s \n" % group_by
            LOCS = {'nation': self.navb.kw.get('nation'),
                    'province': self.navb.kw.get('province'),
                    'district': self.navb.kw.get('district'),
                    'hospital': self.navb.kw.get('hd'),
                    'location': self.navb.kw.get('hc')
                    }
                        
            locateds = Birth.fetch_births_by_location(cnds, group_by = group_by, INDICS = INDICS)
            #print [[y.__dict__ for y in x] for x in locateds]#, INDICS, LOCS, self.navb.locs()
            tabular = give_me_table(locateds, self.navb.locs(),  INDICS = INDICS, LOCS = LOCS)
            #print locateds, "\n", tabular

        INDICS_HEADERS = dict([ ( makecol(x[0]), x[2]) for x in INDICS])
        desc  = 'Deliveries%s' % (' (%s)' % ( self.navb.find_descr( [(makecol(x[0]), x[2]) for x in INDICS], sc ) ) )
 
        #print INDICS_HEADERS, tabular, locateds
        return (title, desc, group, attrs, markup, cols, nat, tabular, locateds, INDICS_HEADERS)
コード例 #2
0
ファイル: births.py プロジェクト: pivotaccess2007/mch
 def get_stats(self):
     cnds    = self.navb.conditions()
     cnds.update({"(birth_date) <= '%s'" % (self.navb.finish) : ''})
     cnds.update({"(birth_date) >= '%s'" % (self.navb.start) : ''})
     exts    = {}
     attrs   = [(makecol(x[0]), x[1]) for x in queries.DELIVERY_DATA['attrs']]
     cnds.update({queries.DELIVERY_DATA['query_str']: ''})
     exts.update(dict([(makecol(x[0]), ('COUNT(*)', x[0])) for x in queries.DELIVERY_DATA['attrs']]))#;print exts
     cols    = ['COUNT(*) AS total']
     nat     = Birth.fetch_births(cnds, cols, exts)
     return [attrs, nat]
コード例 #3
0
class Childmapper(object):
    """ Childmapper map the sms report appropriately to db columns structure """
    def __init__(self, report):
        self.deliv = Birth(report.nid, report.birth_date, report.child_number)
        self.__dict__.update(report.__dict__)
        self.FIELDS = {}
        self.mother = Mothermapper(report)

    def get(self):
        try:
            return self.deliv.get()
        except Exception, e:
            print "CHILD NOT FOUND: %s" % e
            pass
        return None
コード例 #4
0
 def __init__(self, report):
     self.deliv = Birth(report.nid, report.birth_date, report.child_number)
     self.__dict__.update(report.__dict__)
     self.FIELDS = {}
     self.mother = Mothermapper(report)
コード例 #5
0
ファイル: births.py プロジェクト: pivotaccess2007/mch
 def get_total(self):
     cnds    = self.navb.conditions()
     exts = {}
     cols = ['COUNT(*) AS total'] 
     total = Birth.fetch_births(cnds, cols, exts)[0]
     return total
コード例 #6
0
 def fetch_children_by_location(cnds, group_by=[], INDICS=[]):
     return Birth.fetch_births_by_location(cnds,
                                           group_by=group_by,
                                           INDICS=INDICS)
コード例 #7
0
 def fetch_log_children(cnds, cols):
     return Birth.fetch_log_births(cnds, cols)
コード例 #8
0
 def fetch_children(cnds, cols, exts):
     return Birth.fetch_births(cnds, cols, exts)
コード例 #9
0
ファイル: reports.py プロジェクト: pivotaccess2007/mch
    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
コード例 #10
0
 def __init__(self, report):
     self.bir = Birth(report.nid, report.birth_date, report.child_number)
     self.__dict__.update(report.__dict__)
     self.FIELDS = {}
     self.child = Childmapper(report)