Example #1
0
def reports_anc_coverages_list(request):
    if 'logged' not in request.session:
        return {'ok': 0, 'msg': 'Please login.'}
    else:
        if request.is_xhr:  # is ajax request
            csrf_token = request.params['csrf_token']
            is_token = (csrf_token == unicode(request.session.get_csrf_token()))

            if is_token:

                anc = AncModel(request)
                person = PersonModel(request)

                # 1 = All
                # 2 = Cover
                # 3 = Not cover

                t = request.params['t'] if 't' in request.params else '1'
                start = request.params['start']
                stop = request.params['stop']

                limit = int(stop) - int(start)

                if t == '2':
                    rs = anc.get_anc_coverages(request.session['hospcode'], int(start), int(limit))
                elif t == '3':
                    rs = anc.get_anc_not_coverages(request.session['hospcode'], int(start), int(limit))
                else:
                    rs = anc.get_anc_coverages_all(request.session['hospcode'], int(start), int(limit))

                if rs:
                    rows = []

                    for r in rs:
                        p = person.get_person_detail(r['pid'], r['hospcode'])
                        obj = {
                            'fullname': p['name'] + '  ' + p['lname'],
                            'cid': p['cid'],
                            'birth': h.to_thai_date(p['birth']),
                            'age': h.count_age(p['birth']),
                            'sex': p['sex'],
                            'address': h.get_address(request, p['hid'], r['hospcode']),
                            'hospcode': r['hospcode'],
                            'pid': r['pid'],
                            'total': r['total']
                        }

                        rows.append(obj)

                    return {'ok': 1, 'rows': rows}
                else:
                    return {'ok': 0, 'msg': 'ไม่พบรายการ'}
            else:
                return {'ok': 0, 'msg': 'Invalid token key.'}
Example #2
0
def reports_anc_coverages_list(request):
    if 'logged' not in request.session:
        return {'ok': 0, 'msg': 'Please login.'}
    else:
        if request.is_xhr:  # is ajax request
            csrf_token = request.params['csrf_token']
            is_token = (csrf_token == unicode(
                request.session.get_csrf_token()))

            if is_token:

                anc = AncModel(request)
                person = PersonModel(request)

                # 1 = All
                # 2 = Cover
                # 3 = Not cover

                t = request.params['t'] if 't' in request.params else '1'
                start = request.params['start']
                stop = request.params['stop']

                limit = int(stop) - int(start)

                if t == '2':
                    rs = anc.get_anc_coverages(request.session['hospcode'],
                                               int(start), int(limit))
                elif t == '3':
                    rs = anc.get_anc_not_coverages(request.session['hospcode'],
                                                   int(start), int(limit))
                else:
                    rs = anc.get_anc_coverages_all(request.session['hospcode'],
                                                   int(start), int(limit))

                if rs:
                    rows = []

                    for r in rs:
                        p = person.get_person_detail(r['pid'], r['hospcode'])
                        obj = {
                            'fullname':
                            p['name'] + '  ' + p['lname'],
                            'cid':
                            p['cid'],
                            'birth':
                            h.to_thai_date(p['birth']),
                            'age':
                            h.count_age(p['birth']),
                            'sex':
                            p['sex'],
                            'address':
                            h.get_address(request, p['hid'], r['hospcode']),
                            'hospcode':
                            r['hospcode'],
                            'pid':
                            r['pid'],
                            'total':
                            r['total']
                        }

                        rows.append(obj)

                    return {'ok': 1, 'rows': rows}
                else:
                    return {'ok': 0, 'msg': 'ไม่พบรายการ'}
            else:
                return {'ok': 0, 'msg': 'Invalid token key.'}