コード例 #1
0
ファイル: anc.py プロジェクト: siteslave/iCare
def search(request):

    if 'logged' not in request.session:
        return {'ok': 0, 'msg': 'Please login.'}
    else:
        if request.is_xhr:

            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)

                query = request.params['query']
                if len(query) == 13:
                    # search by cid
                    rs = anc.search_by_cid(query, request.session['hospcode'])

                else:
                    #search by pid
                    rs = anc.search_by_pid(query, request.session['hospcode'])

                rows = []
                if rs:
                    for r in rs:
                        labor = anc.get_labor_detail(
                            r['pid'], r['gravida'],
                            request.session['hospcode'])
                        prenatal = anc.get_prenatal_detail(
                            r['pid'], r['gravida'],
                            request.session['hospcode'])
                        p = person.get_person_detail(
                            r['pid'], request.session['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']),
                            '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,
                            'is_survey':
                            anc.get_survey_status(r['pid'], r['gravida'],
                                                  r['hospcode']),
                            'anc_count':
                            anc.get_anc_count(r['pid'], r['hospcode'],
                                              r['gravida'])
                        }
                        rows.append(obj)

                    return {'ok': 1, 'rows': rows}
                else:
                    return {'ok': 0, 'msg': u'ไม่พบข้อมูล'}
            else:
                return {'ok': 0, 'msg': 'Not authorized.'}
        else:
            return {'ok': 0, 'msg': 'Not ajax.'}
コード例 #2
0
ファイル: anc.py プロジェクト: siteslave/iCare
def search(request):

    if "logged" not in request.session:
        return {"ok": 0, "msg": "Please login."}
    else:
        if request.is_xhr:

            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)

                query = request.params["query"]
                if len(query) == 13:
                    # search by cid
                    rs = anc.search_by_cid(query, request.session["hospcode"])

                else:
                    # search by pid
                    rs = anc.search_by_pid(query, request.session["hospcode"])

                rows = []
                if rs:
                    for r in rs:
                        labor = anc.get_labor_detail(r["pid"], r["gravida"], request.session["hospcode"])
                        prenatal = anc.get_prenatal_detail(r["pid"], r["gravida"], request.session["hospcode"])
                        p = person.get_person_detail(r["pid"], request.session["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"]),
                            "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,
                            "is_survey": anc.get_survey_status(r["pid"], r["gravida"], r["hospcode"]),
                            "anc_count": anc.get_anc_count(r["pid"], r["hospcode"], r["gravida"]),
                        }
                        rows.append(obj)

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