コード例 #1
0
ファイル: anc.py プロジェクト: siteslave/iCare
def get_list(request):
    if "logged" not in request.session:
        return {"ok": 0, "msg": "Please login."}
    else:
        if request.is_xhr:  # is ajax request
            start = request.params["start"] if "start" in request.params else 0
            stop = request.params["stop"] if "stop" in request.params else 25

            limit = int(stop) - int(start)

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

            rs = anc.get_list(int(start), int(limit))

            rows = []
            if rs:
                for r in rs:
                    labor = anc.get_labor_detail(r["pid"], r["gravida"], r["hospcode"])
                    prenatal = anc.get_prenatal_detail(r["pid"], r["gravida"], r["hospcode"])
                    p = person.get_person_detail(r["pid"], r["hospcode"])

                    bdate = h.to_thai_date(labor["bdate"]) if labor else "-"
                    edc = h.to_thai_date(prenatal["edc"]) if prenatal else "-"
                    lmp = h.to_thai_date(prenatal["lmp"]) if prenatal else "-"

                    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"], anc.get_first_anc(p["pid"], r["gravida"], r["hospcode"])),
                        "first_visit": h.to_thai_date(anc.get_first_anc(p["pid"], r["gravida"], r["hospcode"])),
                        "last_visit": h.to_thai_date(anc.get_last_anc(p["pid"], r["gravida"], r["hospcode"])),
                        "bdate": bdate,
                        "edc": edc,
                        "lmp": lmp,
                        "anc_count": anc.get_anc_count(r["pid"], r["hospcode"], r["gravida"]),
                        "is_survey": anc.get_survey_status(r["pid"], r["gravida"], r["hospcode"]),
                    }
                    rows.append(obj)

                return {"ok": 1, "rows": rows}
            else:
                return {"ok": 0, "msg": u"ไม่พบข้อมูล"}
        else:
            return {"ok": 0, "msg": "Not ajax request."}
コード例 #2
0
ファイル: anc.py プロジェクト: siteslave/iCare
def get_list(request):
    if 'logged' not in request.session:
        return {'ok': 0, 'msg': 'Please login.'}
    else:
        if request.is_xhr:  # is ajax request
            start = request.params['start'] if 'start' in request.params else 0
            stop = request.params['stop'] if 'stop' in request.params else 25

            limit = int(stop) - int(start)

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

            rs = anc.get_list(int(start), int(limit))

            rows = []
            if rs:
                for r in rs:
                    labor = anc.get_labor_detail(r['pid'], r['gravida'],
                                                 r['hospcode'])
                    prenatal = anc.get_prenatal_detail(r['pid'], r['gravida'],
                                                       r['hospcode'])
                    p = person.get_person_detail(r['pid'], r['hospcode'])

                    bdate = h.to_thai_date(labor['bdate']) if labor else '-'
                    edc = h.to_thai_date(prenatal['edc']) if prenatal else '-'
                    lmp = h.to_thai_date(prenatal['lmp']) if prenatal else '-'

                    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'],
                            anc.get_first_anc(p['pid'], r['gravida'],
                                              r['hospcode'])),
                        'first_visit':
                        h.to_thai_date(
                            anc.get_first_anc(p['pid'], r['gravida'],
                                              r['hospcode'])),
                        'last_visit':
                        h.to_thai_date(
                            anc.get_last_anc(p['pid'], r['gravida'],
                                             r['hospcode'])),
                        'bdate':
                        bdate,
                        'edc':
                        edc,
                        'lmp':
                        lmp,
                        'anc_count':
                        anc.get_anc_count(r['pid'], r['hospcode'],
                                          r['gravida']),
                        'is_survey':
                        anc.get_survey_status(r['pid'], r['gravida'],
                                              r['hospcode']),
                    }
                    rows.append(obj)

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