예제 #1
0
def get_list_by_birth(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:

                start = request.params['start']
                stop = request.params['stop']
                start_date = h.jsdate_to_string(request.params['start_date'])
                end_date = h.jsdate_to_string(request.params['end_date'])

                limit = int(stop) - int(start)

                babies = BabiesModel(request)
                person = PersonModel(request)

                rs = babies.get_list_by_birth(start_date, end_date, int(start), int(limit))
                rows = []

                if rs:
                    for r in rs:
                        p = person.get_person_detail(r['pid'], request.session['hospcode'])
                        obj = {
                            'pid': r['pid'],
                            'cid': r['cid'],
                            'hospcode': r['hospcode'],
                            'gravida': r['gravida'],
                            'fullname': p['name'] + '  ' + p['lname'],
                            'cid': p['cid'],
                            'birth': h.to_thai_date(p['birth']),
                            'age': h.count_age(p['birth']),
                            'sex': p['sex'],
                            'bdate': h.to_thai_date(r['bdate']),
                            'bplace': r['bplace'],
                            'bhospcode': r['bhosp'],
                            'bhospname': h.get_hospital_name(request, r['bhosp']),
                            'btype': r['btype'],
                            'bweight': r['bweight'],
                            'mother': babies.get_mother(r['mpid'], r['hospcode']),
                            'care': babies.get_count_care(r['pid'], r['hospcode'])
                        }
                        rows.append(obj)

                    return {'ok': 1, 'rows': rows}
                else:
                    return {'ok': 0, 'msg': u'ไม่พบข้อมูล'}
            else:
                return {'ok': 0, 'msg': 'Token not found.'}

        else:
            return {'ok': 0, 'msg': 'Not ajax request.'}
예제 #2
0
파일: babies.py 프로젝트: siteslave/iCare
def get_list_by_birth(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:

                start = request.params["start"]
                stop = request.params["stop"]
                start_date = h.jsdate_to_string(request.params["start_date"])
                end_date = h.jsdate_to_string(request.params["end_date"])

                limit = int(stop) - int(start)

                babies = BabiesModel(request)
                person = PersonModel(request)

                rs = babies.get_list_by_birth(start_date, end_date, int(start), int(limit))
                rows = []

                if rs:
                    for r in rs:
                        p = person.get_person_detail(r["pid"], request.session["hospcode"])
                        obj = {
                            "pid": r["pid"],
                            "cid": r["cid"],
                            "hospcode": r["hospcode"],
                            "gravida": r["gravida"],
                            "fullname": p["name"] + "  " + p["lname"],
                            "cid": p["cid"],
                            "birth": h.to_thai_date(p["birth"]),
                            "age": h.count_age(p["birth"]),
                            "sex": p["sex"],
                            "bdate": h.to_thai_date(r["bdate"]),
                            "bplace": r["bplace"],
                            "bhospcode": r["bhosp"],
                            "bhospname": h.get_hospital_name(request, r["bhosp"]),
                            "btype": r["btype"],
                            "bweight": r["bweight"],
                            "mother": babies.get_mother(r["mpid"], r["hospcode"]),
                            "care": babies.get_count_care(r["pid"], r["hospcode"]),
                        }
                        rows.append(obj)

                    return {"ok": 1, "rows": rows}
                else:
                    return {"ok": 0, "msg": u"ไม่พบข้อมูล"}
            else:
                return {"ok": 0, "msg": "Token not found."}

        else:
            return {"ok": 0, "msg": "Not ajax request."}