Example #1
0
def anc_get_list_map_total(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)

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

            try:
                if vid:
                    home = HomeModel(request)
                    hids = home.get_hid_from_village(
                        request.session['hospcode'], vid)
                    total = anc.get_list_map_anc_total_by_vid(
                        request.session['hospcode'], hids, int(by))
                else:
                    total = anc.get_list_map_anc_total(
                        request.session['hospcode'], int(by))
                return {'ok': 1, 'total': total}
            except Exception as e:
                return {'ok': 0, 'msg': e.message}
        else:
            return {'ok': 0, 'msg': 'Not ajax request'}
Example #2
0
def anc_get_list_map_total(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)

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

            try:
                if vid:
                    home = HomeModel(request)
                    hids = home.get_hid_from_village(request.session["hospcode"], vid)
                    total = anc.get_list_map_anc_total_by_vid(request.session["hospcode"], hids, int(by))
                else:
                    total = anc.get_list_map_anc_total(request.session["hospcode"], int(by))
                return {"ok": 1, "total": total}
            except Exception as e:
                return {"ok": 0, "msg": e.message}
        else:
            return {"ok": 0, "msg": "Not ajax request"}
Example #3
0
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.'}
Example #4
0
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."}
Example #5
0
def save_latlng(request):
    if 'logged' not in request.session:
        return {'ok': 0, 'msg': 'Please login.'}
    else:
        if request.is_xhr:  # is ajax request
            lat = request.params['lat']
            lng = request.params['lng']
            hid = request.params['hid']
            hospcode = request.params['hospcode']

            home = HomeModel(request)
            #get hid
            #hid = anc.get_hid_from_pid(hospcode, pid)
            home.save_latlng(hid, hospcode, float(lat), float(lng))

            return {'ok': 1}
        else:
            return {'ok': 0, 'msg': 'Not ajax request.'}
Example #6
0
def remove_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:
            home = HomeModel(request)

            hospcode = request.params['hospcode']
            hid = request.params['hid']

            try:
                home.remove_latlng(hospcode, hid)
                return {'ok': 1}
            except:
                return {'ok': 0, 'msg': u'ไม่สามารถลบรายการได้'}
Example #7
0
def save_latlng(request):
    if 'logged' not in request.session:
        return {'ok': 0, 'msg': 'Please login.'}
    else:
        if request.is_xhr:  # is ajax request
            lat = request.params['lat']
            lng = request.params['lng']
            hid = request.params['hid']
            hospcode = request.params['hospcode']

            home = HomeModel(request)
            #get hid
            #hid = anc.get_hid_from_pid(hospcode, pid)
            home.save_latlng(hid, hospcode, float(lat), float(lng))

            return {'ok': 1}
        else:
            return {'ok': 0, 'msg': 'Not ajax request.'}
Example #8
0
def remove_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:
            home = HomeModel(request)

            hospcode = request.params['hospcode']
            hid = request.params['hid']

            try:
                home.remove_latlng(hospcode, hid)
                return {'ok': 1}
            except:
                return {'ok': 0, 'msg': u'ไม่สามารถลบรายการได้'}
Example #9
0
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'}
Example #10
0
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"}