示例#1
0
文件: anc.py 项目: siteslave/iCare
def anc_get_list_map(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']
            stop = request.params['stop']
            by = request.params['by']
            vid = request.params['vid'] if 'vid' in request.params else False

            limit = int(stop) - int(start)

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

            if vid:
                home = HomeModel(request)
                hids = home.get_hid_from_village(request.session['hospcode'],
                                                 vid)
                rs = anc.get_list_map_anc_by_vid(request.session['hospcode'],
                                                 hids, int(by), int(start),
                                                 int(limit))
            else:
                rs = anc.get_list_map_anc(request.session['hospcode'], int(by),
                                          int(start), int(limit))

            rows = []
            if rs:
                for r in rs:
                    p = person.get_person_detail(r['pid'],
                                                 request.session['hospcode'])

                    obj = {
                        'cid':
                        p['cid'],
                        'pid':
                        p['pid'],
                        'hid':
                        p['hid'],
                        'fullname':
                        '%s %s' % (p['name'], p['lname']),
                        'age':
                        h.count_age(p['birth']),
                        'gravida':
                        r['gravida'],
                        'hospcode':
                        r['hospcode'],
                        'latlng':
                        anc.get_latlng_from_pid(p['pid'],
                                                request.session['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 anc_get_list_map(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"]
            stop = request.params["stop"]
            by = request.params["by"]
            vid = request.params["vid"] if "vid" in request.params else False

            limit = int(stop) - int(start)

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

            if vid:
                home = HomeModel(request)
                hids = home.get_hid_from_village(request.session["hospcode"], vid)
                rs = anc.get_list_map_anc_by_vid(request.session["hospcode"], hids, int(by), int(start), int(limit))
            else:
                rs = anc.get_list_map_anc(request.session["hospcode"], int(by), int(start), int(limit))

            rows = []
            if rs:
                for r in rs:
                    p = person.get_person_detail(r["pid"], request.session["hospcode"])

                    obj = {
                        "cid": p["cid"],
                        "pid": p["pid"],
                        "hid": p["hid"],
                        "fullname": "%s %s" % (p["name"], p["lname"]),
                        "age": h.count_age(p["birth"]),
                        "gravida": r["gravida"],
                        "hospcode": r["hospcode"],
                        "latlng": anc.get_latlng_from_pid(p["pid"], request.session["hospcode"]),
                    }

                    rows.append(obj)

                return {"ok": 1, "rows": rows}
            else:
                return {"ok": 0, "msg": u"ไม่พบข้อมูล"}
        else:
            return {"ok": 0, "msg": "Not ajax request."}
示例#3
0
文件: anc.py 项目: siteslave/iCare
def anc_all_latlng(request):
    if 'logged' not in request.session:
        return {'ok': 0, 'msg': 'Please login.'}
    else:
        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)

            by = request.params['by']
            vid = request.params['vid'] if 'vid' in request.params else False

            if vid:
                home = HomeModel(request)
                hids = home.get_hid_from_village(request.session['hospcode'],
                                                 vid)
                pids = anc.get_list_map_anc_all_by_vid(
                    request.session['hospcode'], hids, int(by))
            else:
                pids = anc.get_list_map_anc_all(request.session['hospcode'],
                                                int(by))
            #try:
            #rs = anc.get_all_latlng(request.session['hospcode'], pids)
            rows = []

            if pids:
                for r in pids:
                    p = person.get_person_detail(r,
                                                 request.session['hospcode'])
                    prenatal = anc.get_prenatal_all(
                        request.session['hospcode'], r)
                    obj_pre = []

                    if prenatal:
                        for rp in prenatal:
                            obj_prenatal = {
                                'gravida': rp['gravida'],
                                'date_hct': h.to_thai_date(rp['date_hct']),
                                'edc': h.to_thai_date(rp['edc']),
                                'hb_result': rp['hb_result'],
                                'hct_result': rp['hct_result'],
                                'hiv_result': rp['hiv_result'],
                                'lmp': h.to_thai_date(rp['lmp']),
                                'thalassemia': rp['thalassemia'],
                                'vdrl_result': rp['vdrl_result']
                            }
                            obj_pre.append(obj_prenatal)
                    else:
                        obj_pre = []

                    obj = {
                        'cid':
                        p['cid'],
                        'pid':
                        p['pid'],
                        'hid':
                        p['hid'],
                        'hospcode':
                        p['hospcode'],
                        'fullname':
                        '%s %s' % (p['name'], p['lname']),
                        'birth':
                        h.to_thai_date(p['birth']),
                        'age':
                        h.count_age(p['birth']),
                        'latlng':
                        anc.get_latlng_from_pid(r,
                                                request.session['hospcode']),
                        'prenatal':
                        obj_pre
                    }

                    rows.append(obj)

            return {'ok': 1, 'rows': rows}
            #except Exception as e:
            #    return {'ok': 0, 'msg': e.message}
        else:
            return {'ok': 0, 'msg': 'Not authorized'}
示例#4
0
文件: anc.py 项目: siteslave/iCare
def anc_all_latlng(request):
    if "logged" not in request.session:
        return {"ok": 0, "msg": "Please login."}
    else:
        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)

            by = request.params["by"]
            vid = request.params["vid"] if "vid" in request.params else False

            if vid:
                home = HomeModel(request)
                hids = home.get_hid_from_village(request.session["hospcode"], vid)
                pids = anc.get_list_map_anc_all_by_vid(request.session["hospcode"], hids, int(by))
            else:
                pids = anc.get_list_map_anc_all(request.session["hospcode"], int(by))
            # try:
            # rs = anc.get_all_latlng(request.session['hospcode'], pids)
            rows = []

            if pids:
                for r in pids:
                    p = person.get_person_detail(r, request.session["hospcode"])
                    prenatal = anc.get_prenatal_all(request.session["hospcode"], r)
                    obj_pre = []

                    if prenatal:
                        for rp in prenatal:
                            obj_prenatal = {
                                "gravida": rp["gravida"],
                                "date_hct": h.to_thai_date(rp["date_hct"]),
                                "edc": h.to_thai_date(rp["edc"]),
                                "hb_result": rp["hb_result"],
                                "hct_result": rp["hct_result"],
                                "hiv_result": rp["hiv_result"],
                                "lmp": h.to_thai_date(rp["lmp"]),
                                "thalassemia": rp["thalassemia"],
                                "vdrl_result": rp["vdrl_result"],
                            }
                            obj_pre.append(obj_prenatal)
                    else:
                        obj_pre = []

                    obj = {
                        "cid": p["cid"],
                        "pid": p["pid"],
                        "hid": p["hid"],
                        "hospcode": p["hospcode"],
                        "fullname": "%s %s" % (p["name"], p["lname"]),
                        "birth": h.to_thai_date(p["birth"]),
                        "age": h.count_age(p["birth"]),
                        "latlng": anc.get_latlng_from_pid(r, request.session["hospcode"]),
                        "prenatal": obj_pre,
                    }

                    rows.append(obj)

            return {"ok": 1, "rows": rows}
            # except Exception as e:
            #    return {'ok': 0, 'msg': e.message}
        else:
            return {"ok": 0, "msg": "Not authorized"}