示例#1
0
def reports_anc_coverages_total(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:
                anc = AncModel(request)

                t = request.params['t'] if 't' in request.params else '1'

                if t == '2':
                    total = anc.get_anc_coverages_count(
                        request.session['hospcode'])
                elif t == '3':
                    total = anc.get_anc_not_coverages_count(
                        request.session['hospcode'])
                else:
                    total = anc.get_anc_coverages_all_count(
                        request.session['hospcode'])

                return {'ok': 1, 'total': total}
            else:
                return {'ok': 0, 'msg': 'Invalid token key'}
        else:
            return {'ok': 0, 'msg': 'Not ajax request.'}
示例#2
0
文件: anc.py 项目: siteslave/iCare
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"}
示例#3
0
def reports_anc_coverages_total(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:
                anc = AncModel(request)

                t = request.params['t'] if 't' in request.params else '1'

                if t == '2':
                    total = anc.get_anc_coverages_count(request.session['hospcode'])
                elif t == '3':
                    total = anc.get_anc_not_coverages_count(request.session['hospcode'])
                else:
                    total = anc.get_anc_coverages_all_count(request.session['hospcode'])

                return {'ok': 1, 'total': total}
            else:
                return {'ok': 0, 'msg': 'Invalid token key'}
        else:
            return {'ok': 0, 'msg': 'Not ajax request.'}
示例#4
0
文件: anc.py 项目: siteslave/iCare
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'}
示例#5
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.'}
示例#6
0
def reports_anc_12ws_list(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:

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

                start = request.params['start']
                stop = request.params['stop']

                limit = int(stop) - int(start)

                rs = anc.get_anc_12ws_list(request.session['hospcode'],
                                           int(start), int(limit))

                if rs:
                    rows = []

                    for r in rs:
                        p = person.get_person_detail(r['pid'], r['hospcode'])
                        obj = {
                            'fullname':
                            p['name'] + '  ' + p['lname'],
                            'cid':
                            p['cid'],
                            'birth':
                            h.to_thai_date(p['birth']),
                            'age':
                            h.count_age(p['birth']),
                            'sex':
                            p['sex'],
                            'address':
                            h.get_address(request, p['hid'], r['hospcode']),
                            'hospcode':
                            r['hospcode'],
                            'pid':
                            r['pid'],
                            'gravida':
                            r['gravida']
                        }

                        rows.append(obj)

                    return {'ok': 1, 'rows': rows}
                else:
                    return {'ok': 0, 'msg': 'ไม่พบรายการ'}
            else:
                return {'ok': 0, 'msg': 'Invalid token key.'}
示例#7
0
def reports_anc_coverages_list(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:

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

                # 1 = All
                # 2 = Cover
                # 3 = Not cover

                t = request.params['t'] if 't' in request.params else '1'
                start = request.params['start']
                stop = request.params['stop']

                limit = int(stop) - int(start)

                if t == '2':
                    rs = anc.get_anc_coverages(request.session['hospcode'], int(start), int(limit))
                elif t == '3':
                    rs = anc.get_anc_not_coverages(request.session['hospcode'], int(start), int(limit))
                else:
                    rs = anc.get_anc_coverages_all(request.session['hospcode'], int(start), int(limit))

                if rs:
                    rows = []

                    for r in rs:
                        p = person.get_person_detail(r['pid'], r['hospcode'])
                        obj = {
                            'fullname': p['name'] + '  ' + p['lname'],
                            'cid': p['cid'],
                            'birth': h.to_thai_date(p['birth']),
                            'age': h.count_age(p['birth']),
                            'sex': p['sex'],
                            'address': h.get_address(request, p['hid'], r['hospcode']),
                            'hospcode': r['hospcode'],
                            'pid': r['pid'],
                            'total': r['total']
                        }

                        rows.append(obj)

                    return {'ok': 1, 'rows': rows}
                else:
                    return {'ok': 0, 'msg': 'ไม่พบรายการ'}
            else:
                return {'ok': 0, 'msg': 'Invalid token key.'}
示例#8
0
文件: anc.py 项目: siteslave/iCare
def anc_get_visit_all(request):
    if 'logged' not in request.session:
        return {'ok': 0, 'msg': 'Please login.'}
    else:
        if request.is_xhr:
            cid = request.params['cid']
            csrf_token = request.params['csrf_token']

            is_token = (csrf_token == unicode(
                request.session.get_csrf_token()))

            if is_token:
                anc = AncModel(request)
                visit = anc.get_visit_all(cid)
                rows = []

                for v in visit:

                    obj = {
                        'pid':
                        v['pid'],
                        'cid':
                        v['cid'],
                        'seq':
                        v['seq'],
                        'date_serv':
                        h.to_thai_date(v['date_serv']),
                        'gravida':
                        v['gravida'],
                        'ancno':
                        v['ancno'],
                        'ga':
                        v['ga'],
                        'ancresult':
                        v['ancresult'],
                        'hospcode':
                        v['hospcode'],
                        'ancplace':
                        v['ancplace'],
                        'hospname':
                        h.get_hospital_name(request, v['hospcode']),
                        'ancplace_name':
                        h.get_hospital_name(request, v['ancplace']),
                    }

                    rows.append(obj)

                return {'ok': 1, 'rows': rows}
            else:
                return {'ok': 0, 'msg': 'Not authorized.'}
        else:
            return {'ok': 0, 'msg': 'Not ajax request'}
示例#9
0
文件: anc.py 项目: siteslave/iCare
def get_visit(request):
    if "logged" not in request.session:
        return {"ok": 0, "msg": "Please login."}
    else:
        if request.is_xhr:
            cid = request.params["query"]
            start = request.params["start"]
            stop = request.params["stop"]

            limit = int(stop) - int(start)

            csrf_token = request.params["csrf_token"]

            is_token = csrf_token == unicode(request.session.get_csrf_token())

            if is_token:
                anc = AncModel(request)
                mch = MchModel(request)

                visit = anc.get_visit_list(cid, int(start), int(limit))
                rows = []

                for v in visit:
                    labor = anc.get_labor_detail(v["pid"], v["gravida"], v["hospcode"])
                    is_labor = 1 if labor else 0

                    obj = {
                        "pid": v["pid"],
                        "cid": v["cid"],
                        "seq": v["seq"],
                        "date_serv": h.to_thai_date(v["date_serv"]),
                        "gravida": v["gravida"],
                        "ancno": v["ancno"],
                        "ga": v["ga"],
                        "ancresult": v["ancresult"],
                        "hospcode": v["hospcode"],
                        "ancplace": v["ancplace"],
                        "hospname": h.get_hospital_name(request, v["hospcode"]),
                        "ancplace_name": h.get_hospital_name(request, v["ancplace"]),
                        "is_survey": anc.get_survey_status(v["pid"], v["gravida"], v["hospcode"]),
                        "is_labor": is_labor,
                        "appoint": mch.count_appointment(v["pid"], v["hospcode"], v["seq"]),
                    }

                    rows.append(obj)

                return {"ok": 1, "rows": rows}
            else:
                return {"ok": 0, "msg": "Not authorized."}
        else:
            return {"ok": 0, "msg": "Not ajax request"}
示例#10
0
文件: anc.py 项目: siteslave/iCare
def get_labor(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:
                cid = request.params['cid']
                gravida = request.params['gravida']

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

                r = anc.get_labor_detail_by_cid(cid, gravida,
                                                request.session['hospcode'])
                p = person.get_person_detail(r['pid'],
                                             request.session['hospcode'])

                if r:
                    obj = {
                        'pฟืแid': r['pid'],
                        'cid': p['cid'],
                        'fullname': p['name'] + ' ' + p['lname'],
                        'birth': h.to_thai_date(p['birth']),
                        'edc': h.to_thai_date(r['edc']),
                        'lmp': h.to_thai_date(r['lmp']),
                        'bdate': h.to_thai_date(r['bdate']),
                        'bresultcode': r['bresult'],
                        'bresultname': h.get_diag_name(request, r['bresult']),
                        'bplace': r['bplace'],
                        'bhospcode': r['bhosp'],
                        'bhospname': h.get_hospital_name(request, r['bhosp']),
                        'btype': r['btype'],
                        'bdoctor': r['bdoctor'],
                        'lborn': r['lborn'],
                        'sborn': r['sborn'],
                        'gravida': r['gravida']
                    }

                    return {'ok': 1, 'rows': [obj]}
                else:
                    return {'ok': 0, 'msg': u'ไม่พบรายการ'}
            else:
                return {'ok': 0, 'msg': 'Not authorized.'}
        else:
            return {'ok': 0, 'msg': 'Not Ajax.'}
示例#11
0
文件: anc.py 项目: siteslave/iCare
def anc_get_risk_list_by_type(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:

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

                hospcode = request.params[
                    'hospcode'] if 'hospcode' in request.params else request.session[
                        'hospcode']

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

                rs = anc.get_risk_list_by_type(hospcode, choice, start_date,
                                               end_date)

                if rs:
                    rows = []
                    for r in rs:
                        p = person.get_person_detail(
                            r['pid'], request.session['hospcode'])
                        obj = {
                            'pid': r['pid'],
                            'cid': p['cid'],
                            'fullname': p['name'] + ' ' + p['lname'],
                            'birth': h.to_thai_date(p['birth']),
                            'age': h.count_age(p['birth'])
                        }

                        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.'}
示例#12
0
def reports_anc_coverages_search(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:

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

                cid = request.params['cid']

                rs = anc.search_anc_coverages(request.session['hospcode'], cid)

                if rs:
                    rows = []

                    for r in rs:
                        p = person.get_person_detail(r['pid'], r['hospcode'])
                        obj = {
                            'fullname':
                            p['name'] + '  ' + p['lname'],
                            'cid':
                            p['cid'],
                            'birth':
                            h.to_thai_date(p['birth']),
                            'age':
                            h.count_age(p['birth']),
                            'sex':
                            p['sex'],
                            'address':
                            h.get_address(request, p['hid'], r['hospcode']),
                            'hospcode':
                            r['hospcode'],
                            'pid':
                            r['pid'],
                            'total':
                            r['total']
                        }

                        rows.append(obj)

                    return {'ok': 1, 'rows': rows}
                else:
                    return {'ok': 0, 'msg': 'ไม่พบรายการ'}
            else:
                return {'ok': 0, 'msg': 'Invalid token key.'}
示例#13
0
文件: anc.py 项目: siteslave/iCare
def get_survey(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:

                pid = request.params["pid"]
                gravida = request.params["gravida"]
                hospcode = request.params["hospcode"] if "hospcode" in request.params else request.session["hospcode"]

                anc = AncModel(request)
                rs = anc.get_survey(pid, gravida, hospcode)

                if rs:
                    obj = {
                        "ch1": rs["ch1"] if rs["ch1"] else None,
                        "ch2": rs["ch2"] if rs["ch2"] else None,
                        "ch3": rs["ch3"] if rs["ch3"] else None,
                        "ch4": rs["ch4"] if rs["ch4"] else None,
                        "ch5": rs["ch5"] if rs["ch5"] else None,
                        "ch6": rs["ch6"] if rs["ch6"] else None,
                        "ch7": rs["ch7"] if rs["ch7"] else None,
                        "ch8": rs["ch8"] if rs["ch8"] else None,
                        "ch9": rs["ch9"] if rs["ch9"] else None,
                        "ch10": rs["ch10"] if rs["ch10"] else None,
                        "ch11": rs["ch11"] if rs["ch11"] else None,
                        "ch12": rs["ch12"] if rs["ch12"] else None,
                        "ch13": rs["ch13"] if rs["ch13"] else None,
                        "ch14": rs["ch14"] if rs["ch14"] else None,
                        "ch15": rs["ch15"] if rs["ch15"] else None,
                        "ch16": rs["ch16"] if rs["ch16"] else None,
                        "ch17": rs["ch17"] if rs["ch17"] else None,
                        "ch18": rs["ch18"] if rs["ch18"] else None,
                        "other_ill": rs["other_ill"] if "other_ill" in rs else None,
                    }

                    return {"ok": 1, "rows": [obj]}
                else:
                    return {"ok": 0, "msg": u"ไม่พบรายการ"}
            else:
                return {"ok": 0, "msg": "Not authorized."}
        else:
            return {"ok": 0, "msg": "Not Ajax."}
示例#14
0
文件: anc.py 项目: siteslave/iCare
def get_prenatal(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:
                pid = request.params['pid']
                gravida = request.params['gravida']
                hospcode = request.params[
                    'hospcode'] if 'hospcode' in request.params else request.session[
                        'hospcode']

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

                r = anc.get_prenatal_detail(pid, gravida, hospcode)
                p = person.get_person_detail(pid, hospcode)

                if r:
                    obj = {
                        'pid': r['pid'],
                        'cid': p['cid'],
                        'fullname': p['name'] + ' ' + p['lname'],
                        'birth': h.to_thai_date(p['birth']),
                        'edc': h.to_thai_date(r['edc']),
                        'lmp': h.to_thai_date(r['lmp']),
                        'vdrl_result': r['vdrl_result'],
                        'hb_result': r['hb_result'],
                        'hiv_result': r['hiv_result'],
                        'date_hct': h.to_thai_date(r['date_hct']),
                        'hct_result': r['hct_result'],
                        'thalassemia': r['thalassemia'],
                        'gravida': r['gravida']
                    }

                    return {'ok': 1, 'rows': [obj]}
                else:
                    return {'ok': 0, 'msg': u'ไม่พบรายการ'}
            else:
                return {'ok': 0, 'msg': 'Not authorized.'}
        else:
            return {'ok': 0, 'msg': 'Not Ajax.'}
示例#15
0
文件: anc.py 项目: siteslave/iCare
def get_labor(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:
                cid = request.params["cid"]
                gravida = request.params["gravida"]

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

                r = anc.get_labor_detail_by_cid(cid, gravida, request.session["hospcode"])
                p = person.get_person_detail(r["pid"], request.session["hospcode"])

                if r:
                    obj = {
                        "pฟืแid": r["pid"],
                        "cid": p["cid"],
                        "fullname": p["name"] + " " + p["lname"],
                        "birth": h.to_thai_date(p["birth"]),
                        "edc": h.to_thai_date(r["edc"]),
                        "lmp": h.to_thai_date(r["lmp"]),
                        "bdate": h.to_thai_date(r["bdate"]),
                        "bresultcode": r["bresult"],
                        "bresultname": h.get_diag_name(request, r["bresult"]),
                        "bplace": r["bplace"],
                        "bhospcode": r["bhosp"],
                        "bhospname": h.get_hospital_name(request, r["bhosp"]),
                        "btype": r["btype"],
                        "bdoctor": r["bdoctor"],
                        "lborn": r["lborn"],
                        "sborn": r["sborn"],
                        "gravida": r["gravida"],
                    }

                    return {"ok": 1, "rows": [obj]}
                else:
                    return {"ok": 0, "msg": u"ไม่พบรายการ"}
            else:
                return {"ok": 0, "msg": "Not authorized."}
        else:
            return {"ok": 0, "msg": "Not Ajax."}
示例#16
0
文件: anc.py 项目: siteslave/iCare
def anc_do_process_12weeks(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)
                rs = anc.do_process_12weeks(request.session["hospcode"])

                return {"ok": 1} if rs else {"ok": 0, "msg": "ไม่สามารถประมวลผลได้"}
            else:
                return {"ok": 0, "msg": "Not authorized "}
        else:
            return {"ok": 0, "msg": "Not ajax request"}
示例#17
0
文件: anc.py 项目: siteslave/iCare
def anc_get_risk_list_by_type(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:

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

                hospcode = request.params["hospcode"] if "hospcode" in request.params else request.session["hospcode"]

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

                rs = anc.get_risk_list_by_type(hospcode, choice, start_date, end_date)

                if rs:
                    rows = []
                    for r in rs:
                        p = person.get_person_detail(r["pid"], request.session["hospcode"])
                        obj = {
                            "pid": r["pid"],
                            "cid": p["cid"],
                            "fullname": p["name"] + " " + p["lname"],
                            "birth": h.to_thai_date(p["birth"]),
                            "age": h.count_age(p["birth"]),
                        }

                        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."}
示例#18
0
文件: anc.py 项目: siteslave/iCare
def get_list_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)
            try:
                total = anc.get_list_total()
                return {"ok": 1, "total": total}
            except Exception as e:
                return {"ok": 0, "msg": e.message}
        else:
            return {"ok": 0, "msg": "Not ajax request"}
示例#19
0
文件: anc.py 项目: siteslave/iCare
def get_list_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)
            try:
                total = anc.get_list_total()
                return {'ok': 1, 'total': total}
            except Exception as e:
                return {'ok': 0, 'msg': e.message}
        else:
            return {'ok': 0, 'msg': 'Not ajax request'}
示例#20
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."}
示例#21
0
文件: anc.py 项目: siteslave/iCare
def get_prenatal(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:
                pid = request.params["pid"]
                gravida = request.params["gravida"]
                hospcode = request.params["hospcode"] if "hospcode" in request.params else request.session["hospcode"]

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

                r = anc.get_prenatal_detail(pid, gravida, hospcode)
                p = person.get_person_detail(pid, hospcode)

                if r:
                    obj = {
                        "pid": r["pid"],
                        "cid": p["cid"],
                        "fullname": p["name"] + " " + p["lname"],
                        "birth": h.to_thai_date(p["birth"]),
                        "edc": h.to_thai_date(r["edc"]),
                        "lmp": h.to_thai_date(r["lmp"]),
                        "vdrl_result": r["vdrl_result"],
                        "hb_result": r["hb_result"],
                        "hiv_result": r["hiv_result"],
                        "date_hct": h.to_thai_date(r["date_hct"]),
                        "hct_result": r["hct_result"],
                        "thalassemia": r["thalassemia"],
                        "gravida": r["gravida"],
                    }

                    return {"ok": 1, "rows": [obj]}
                else:
                    return {"ok": 0, "msg": u"ไม่พบรายการ"}
            else:
                return {"ok": 0, "msg": "Not authorized."}
        else:
            return {"ok": 0, "msg": "Not Ajax."}
示例#22
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."}
示例#23
0
def reports_anc_12ws_total(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:
                anc = AncModel(request)

                total = anc.get_anc_12ws_total(request.session['hospcode'])

                return {'ok': 1, 'total': total}
            else:
                return {'ok': 0, 'msg': 'Invalid token key'}
        else:
            return {'ok': 0, 'msg': 'Not ajax request.'}
示例#24
0
def reports_anc_12ws_total(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:
                anc = AncModel(request)

                total = anc.get_anc_12ws_total(request.session['hospcode'])

                return {'ok': 1, 'total': total}
            else:
                return {'ok': 0, 'msg': 'Invalid token key'}
        else:
            return {'ok': 0, 'msg': 'Not ajax request.'}
示例#25
0
def reports_anc_coverages_search(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:

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

                cid = request.params['cid']

                rs = anc.search_anc_coverages(request.session['hospcode'], cid)

                if rs:
                    rows = []

                    for r in rs:
                        p = person.get_person_detail(r['pid'], r['hospcode'])
                        obj = {
                            'fullname': p['name'] + '  ' + p['lname'],
                            'cid': p['cid'],
                            'birth': h.to_thai_date(p['birth']),
                            'age': h.count_age(p['birth']),
                            'sex': p['sex'],
                            'address': h.get_address(request, p['hid'], r['hospcode']),
                            'hospcode': r['hospcode'],
                            'pid': r['pid'],
                            'total': r['total']
                        }

                        rows.append(obj)

                    return {'ok': 1, 'rows': rows}
                else:
                    return {'ok': 0, 'msg': 'ไม่พบรายการ'}
            else:
                return {'ok': 0, 'msg': 'Invalid token key.'}
示例#26
0
文件: anc.py 项目: siteslave/iCare
def anc_get_visit_all(request):
    if "logged" not in request.session:
        return {"ok": 0, "msg": "Please login."}
    else:
        if request.is_xhr:
            cid = request.params["cid"]
            csrf_token = request.params["csrf_token"]

            is_token = csrf_token == unicode(request.session.get_csrf_token())

            if is_token:
                anc = AncModel(request)
                visit = anc.get_visit_all(cid)
                rows = []

                for v in visit:

                    obj = {
                        "pid": v["pid"],
                        "cid": v["cid"],
                        "seq": v["seq"],
                        "date_serv": h.to_thai_date(v["date_serv"]),
                        "gravida": v["gravida"],
                        "ancno": v["ancno"],
                        "ga": v["ga"],
                        "ancresult": v["ancresult"],
                        "hospcode": v["hospcode"],
                        "ancplace": v["ancplace"],
                        "hospname": h.get_hospital_name(request, v["hospcode"]),
                        "ancplace_name": h.get_hospital_name(request, v["ancplace"]),
                    }

                    rows.append(obj)

                return {"ok": 1, "rows": rows}
            else:
                return {"ok": 0, "msg": "Not authorized."}
        else:
            return {"ok": 0, "msg": "Not ajax request"}
示例#27
0
文件: anc.py 项目: siteslave/iCare
def anc_do_process_12weeks(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)
                rs = anc.do_process_12weeks(request.session['hospcode'])

                return {
                    'ok': 1
                } if rs else {
                    'ok': 0,
                    'msg': 'ไม่สามารถประมวลผลได้'
                }
            else:
                return {'ok': 0, 'msg': 'Not authorized '}
        else:
            return {'ok': 0, 'msg': 'Not ajax request'}
示例#28
0
文件: index.py 项目: siteslave/iCare
def do_login(request):

    from icare.helpers.icare_helper import ICHelper

    h = ICHelper()

    csrf_token = request.params['csrf_token']
    username = request.params['username']
    password = h.get_hash(request.params['password'])
    is_process = True if 'isProcess' in request.params else False

    auth = Auth()

    is_token = (csrf_token == unicode(request.session.get_csrf_token()))
    if is_token:
        #do login
        users = auth.do_login(username, password, request)
        if users:
            session = request.session
            session['logged'] = True
            session['hospcode'] = users['hospcode']
            session['owner'] = users['owner']
            session['fullname'] = users['fullname']
            session['user_type'] = users['user_type']
            session['id'] = str(users['_id'])

            if is_process:
                #process data
                anc = AncModel(request)
                mch = MchModel(request)
                babies = BabiesModel(request)

                anc.do_process_list(users['hospcode'])
                anc.do_process_12weeks(users['hospcode'])

                mch.do_process_forecast(users['hospcode'])
                babies.process_milk(users['hospcode'])

            if users['user_type'] == '1':
                return HTTPFound(location='/admins/users')
            else:
                return HTTPFound(location='/')
        else:
            return HTTPFound(location='/signin')
    else:
        raise HTTPUnauthorized
示例#29
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.'}
示例#30
0
文件: anc.py 项目: siteslave/iCare
def get_survey(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:

                pid = request.params['pid']
                gravida = request.params['gravida']
                hospcode = request.params[
                    'hospcode'] if 'hospcode' in request.params else request.session[
                        'hospcode']

                anc = AncModel(request)
                rs = anc.get_survey(pid, gravida, hospcode)

                if rs:
                    obj = {
                        'ch1':
                        rs['ch1'] if rs['ch1'] else None,
                        'ch2':
                        rs['ch2'] if rs['ch2'] else None,
                        'ch3':
                        rs['ch3'] if rs['ch3'] else None,
                        'ch4':
                        rs['ch4'] if rs['ch4'] else None,
                        'ch5':
                        rs['ch5'] if rs['ch5'] else None,
                        'ch6':
                        rs['ch6'] if rs['ch6'] else None,
                        'ch7':
                        rs['ch7'] if rs['ch7'] else None,
                        'ch8':
                        rs['ch8'] if rs['ch8'] else None,
                        'ch9':
                        rs['ch9'] if rs['ch9'] else None,
                        'ch10':
                        rs['ch10'] if rs['ch10'] else None,
                        'ch11':
                        rs['ch11'] if rs['ch11'] else None,
                        'ch12':
                        rs['ch12'] if rs['ch12'] else None,
                        'ch13':
                        rs['ch13'] if rs['ch13'] else None,
                        'ch14':
                        rs['ch14'] if rs['ch14'] else None,
                        'ch15':
                        rs['ch15'] if rs['ch15'] else None,
                        'ch16':
                        rs['ch16'] if rs['ch16'] else None,
                        'ch17':
                        rs['ch17'] if rs['ch17'] else None,
                        'ch18':
                        rs['ch18'] if rs['ch18'] else None,
                        'other_ill':
                        rs['other_ill'] if 'other_ill' in rs else None,
                    }

                    return {'ok': 1, 'rows': [obj]}
                else:
                    return {'ok': 0, 'msg': u'ไม่พบรายการ'}
            else:
                return {'ok': 0, 'msg': 'Not authorized.'}
        else:
            return {'ok': 0, 'msg': 'Not Ajax.'}
示例#31
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.'}
示例#32
0
文件: anc.py 项目: siteslave/iCare
def save_survey(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:
                ch1 = request.params['ch1']
                ch2 = request.params['ch2']
                ch3 = request.params['ch3']
                ch4 = request.params['ch4']
                ch5 = request.params['ch5']
                ch6 = request.params['ch6']
                ch7 = request.params['ch7']
                ch8 = request.params['ch8']
                ch9 = request.params['ch9']
                ch10 = request.params['ch10']
                ch11 = request.params['ch11']
                ch12 = request.params['ch12']
                ch13 = request.params['ch13']
                ch14 = request.params['ch14']
                ch15 = request.params['ch15']
                ch16 = request.params['ch16']
                ch17 = request.params['ch17']
                ch18 = request.params['ch18']
                pid = request.params['pid']
                gravida = request.params['gravida']
                other_ill = request.params['other_ill']

                is_risk = 'N'

                if ch1 == '1':
                    is_risk = 'Y'
                elif ch2 == '1':
                    is_risk = 'Y'
                elif ch3 == '1':
                    is_risk = 'Y'
                elif ch4 == '1':
                    is_risk = 'Y'
                elif ch5 == '1':
                    is_risk = 'Y'
                elif ch6 == '1':
                    is_risk = 'Y'
                elif ch7 == '1':
                    is_risk = 'Y'
                elif ch8 == '1':
                    is_risk = 'Y'
                elif ch9 == '1':
                    is_risk = 'Y'
                elif ch10 == '1':
                    is_risk = 'Y'
                elif ch11 == '1':
                    is_risk = 'Y'
                elif ch12 == '1':
                    is_risk = 'Y'
                elif ch13 == '1':
                    is_risk = 'Y'
                elif ch14 == '1':
                    is_risk = 'Y'
                elif ch15 == '1':
                    is_risk = 'Y'
                elif ch16 == '1':
                    is_risk = 'Y'
                elif ch17 == '1':
                    is_risk = 'Y'
                elif ch18 == '1':
                    is_risk = 'Y'
                else:
                    is_risk = 'N'

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

                doc = {
                    'ch1':
                    ch1,
                    'ch2':
                    ch2,
                    'ch3':
                    ch3,
                    'ch4':
                    ch4,
                    'ch5':
                    ch5,
                    'ch6':
                    ch6,
                    'ch7':
                    ch7,
                    'ch8':
                    ch8,
                    'ch9':
                    ch9,
                    'ch10':
                    ch10,
                    'ch11':
                    ch11,
                    'ch12':
                    ch12,
                    'ch13':
                    ch13,
                    'ch14':
                    ch14,
                    'ch15':
                    ch15,
                    'ch16':
                    ch16,
                    'ch17':
                    ch17,
                    'ch18':
                    ch18,
                    'is_risk':
                    is_risk,
                    'pid':
                    pid,
                    'other_ill':
                    other_ill,
                    'gravida':
                    gravida,
                    'cid':
                    person.get_cid_from_pid(pid, request.session['hospcode']),
                    'hospcode':
                    request.session['hospcode'],
                    'last_update':
                    h.get_current_stringdate()
                }

                anc.save_survey(doc)

                return {'ok': 1}

            else:
                return {'ok': 0, 'msg': 'Not authorized.'}

        else:
            return {'ok': 0, 'msg': 'Not ajax request'}
示例#33
0
文件: anc.py 项目: siteslave/iCare
def save_survey(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:
                ch1 = request.params["ch1"]
                ch2 = request.params["ch2"]
                ch3 = request.params["ch3"]
                ch4 = request.params["ch4"]
                ch5 = request.params["ch5"]
                ch6 = request.params["ch6"]
                ch7 = request.params["ch7"]
                ch8 = request.params["ch8"]
                ch9 = request.params["ch9"]
                ch10 = request.params["ch10"]
                ch11 = request.params["ch11"]
                ch12 = request.params["ch12"]
                ch13 = request.params["ch13"]
                ch14 = request.params["ch14"]
                ch15 = request.params["ch15"]
                ch16 = request.params["ch16"]
                ch17 = request.params["ch17"]
                ch18 = request.params["ch18"]
                pid = request.params["pid"]
                gravida = request.params["gravida"]
                other_ill = request.params["other_ill"]

                is_risk = "N"

                if ch1 == "1":
                    is_risk = "Y"
                elif ch2 == "1":
                    is_risk = "Y"
                elif ch3 == "1":
                    is_risk = "Y"
                elif ch4 == "1":
                    is_risk = "Y"
                elif ch5 == "1":
                    is_risk = "Y"
                elif ch6 == "1":
                    is_risk = "Y"
                elif ch7 == "1":
                    is_risk = "Y"
                elif ch8 == "1":
                    is_risk = "Y"
                elif ch9 == "1":
                    is_risk = "Y"
                elif ch10 == "1":
                    is_risk = "Y"
                elif ch11 == "1":
                    is_risk = "Y"
                elif ch12 == "1":
                    is_risk = "Y"
                elif ch13 == "1":
                    is_risk = "Y"
                elif ch14 == "1":
                    is_risk = "Y"
                elif ch15 == "1":
                    is_risk = "Y"
                elif ch16 == "1":
                    is_risk = "Y"
                elif ch17 == "1":
                    is_risk = "Y"
                elif ch18 == "1":
                    is_risk = "Y"
                else:
                    is_risk = "N"

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

                doc = {
                    "ch1": ch1,
                    "ch2": ch2,
                    "ch3": ch3,
                    "ch4": ch4,
                    "ch5": ch5,
                    "ch6": ch6,
                    "ch7": ch7,
                    "ch8": ch8,
                    "ch9": ch9,
                    "ch10": ch10,
                    "ch11": ch11,
                    "ch12": ch12,
                    "ch13": ch13,
                    "ch14": ch14,
                    "ch15": ch15,
                    "ch16": ch16,
                    "ch17": ch17,
                    "ch18": ch18,
                    "is_risk": is_risk,
                    "pid": pid,
                    "other_ill": other_ill,
                    "gravida": gravida,
                    "cid": person.get_cid_from_pid(pid, request.session["hospcode"]),
                    "hospcode": request.session["hospcode"],
                    "last_update": h.get_current_stringdate(),
                }

                anc.save_survey(doc)

                return {"ok": 1}

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

        else:
            return {"ok": 0, "msg": "Not ajax request"}
示例#34
0
文件: anc.py 项目: siteslave/iCare
def get_visit(request):
    if 'logged' not in request.session:
        return {'ok': 0, 'msg': 'Please login.'}
    else:
        if request.is_xhr:
            cid = request.params['query']
            start = request.params['start']
            stop = request.params['stop']

            limit = int(stop) - int(start)

            csrf_token = request.params['csrf_token']

            is_token = (csrf_token == unicode(
                request.session.get_csrf_token()))

            if is_token:
                anc = AncModel(request)
                mch = MchModel(request)

                visit = anc.get_visit_list(cid, int(start), int(limit))
                rows = []

                for v in visit:
                    labor = anc.get_labor_detail(v['pid'], v['gravida'],
                                                 v['hospcode'])
                    is_labor = 1 if labor else 0

                    obj = {
                        'pid':
                        v['pid'],
                        'cid':
                        v['cid'],
                        'seq':
                        v['seq'],
                        'date_serv':
                        h.to_thai_date(v['date_serv']),
                        'gravida':
                        v['gravida'],
                        'ancno':
                        v['ancno'],
                        'ga':
                        v['ga'],
                        'ancresult':
                        v['ancresult'],
                        'hospcode':
                        v['hospcode'],
                        'ancplace':
                        v['ancplace'],
                        'hospname':
                        h.get_hospital_name(request, v['hospcode']),
                        'ancplace_name':
                        h.get_hospital_name(request, v['ancplace']),
                        'is_survey':
                        anc.get_survey_status(v['pid'], v['gravida'],
                                              v['hospcode']),
                        'is_labor':
                        is_labor,
                        'appoint':
                        mch.count_appointment(v['pid'], v['hospcode'],
                                              v['seq'])
                    }

                    rows.append(obj)

                return {'ok': 1, 'rows': rows}
            else:
                return {'ok': 0, 'msg': 'Not authorized.'}
        else:
            return {'ok': 0, 'msg': 'Not ajax request'}
示例#35
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."}
示例#36
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"}
示例#37
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'}
示例#38
0
文件: anc.py 项目: siteslave/iCare
def get_risk_by_group(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()))

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

            if is_token:

                hospcode = request.params[
                    'hospcode'] if 'hospcode' in request.params else request.session[
                        'hospcode']

                anc = AncModel(request)

                rs01 = anc.count_risk01(hospcode, start_date, end_date)
                rs02 = anc.count_risk02(hospcode, start_date, end_date)
                rs03 = anc.count_risk03(hospcode, start_date, end_date)
                rs04 = anc.count_risk04(hospcode, start_date, end_date)
                rs05 = anc.count_risk05(hospcode, start_date, end_date)
                rs06 = anc.count_risk06(hospcode, start_date, end_date)
                rs07 = anc.count_risk07(hospcode, start_date, end_date)
                rs08 = anc.count_risk08(hospcode, start_date, end_date)
                rs09 = anc.count_risk09(hospcode, start_date, end_date)
                rs10 = anc.count_risk10(hospcode, start_date, end_date)
                rs11 = anc.count_risk11(hospcode, start_date, end_date)
                rs12 = anc.count_risk12(hospcode, start_date, end_date)
                rs13 = anc.count_risk13(hospcode, start_date, end_date)
                rs14 = anc.count_risk14(hospcode, start_date, end_date)
                rs15 = anc.count_risk15(hospcode, start_date, end_date)
                rs16 = anc.count_risk16(hospcode, start_date, end_date)
                rs17 = anc.count_risk17(hospcode, start_date, end_date)
                rs18 = anc.count_risk18(hospcode, start_date, end_date)

                obj = {
                    "risk01": rs01,
                    "risk02": rs02,
                    "risk03": rs03,
                    "risk04": rs04,
                    "risk05": rs05,
                    "risk06": rs06,
                    "risk07": rs07,
                    "risk08": rs08,
                    "risk09": rs09,
                    "risk10": rs10,
                    "risk11": rs11,
                    "risk12": rs12,
                    "risk13": rs13,
                    "risk14": rs14,
                    "risk15": rs15,
                    "risk16": rs16,
                    "risk17": rs17,
                    "risk18": rs18,
                }

                return {'ok': 1, 'rows': [obj]}
        else:
            return {'ok': 0, 'msg': 'Not authorized.'}
示例#39
0
文件: anc.py 项目: siteslave/iCare
def get_risk_by_group(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())

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

            if is_token:

                hospcode = request.params["hospcode"] if "hospcode" in request.params else request.session["hospcode"]

                anc = AncModel(request)

                rs01 = anc.count_risk01(hospcode, start_date, end_date)
                rs02 = anc.count_risk02(hospcode, start_date, end_date)
                rs03 = anc.count_risk03(hospcode, start_date, end_date)
                rs04 = anc.count_risk04(hospcode, start_date, end_date)
                rs05 = anc.count_risk05(hospcode, start_date, end_date)
                rs06 = anc.count_risk06(hospcode, start_date, end_date)
                rs07 = anc.count_risk07(hospcode, start_date, end_date)
                rs08 = anc.count_risk08(hospcode, start_date, end_date)
                rs09 = anc.count_risk09(hospcode, start_date, end_date)
                rs10 = anc.count_risk10(hospcode, start_date, end_date)
                rs11 = anc.count_risk11(hospcode, start_date, end_date)
                rs12 = anc.count_risk12(hospcode, start_date, end_date)
                rs13 = anc.count_risk13(hospcode, start_date, end_date)
                rs14 = anc.count_risk14(hospcode, start_date, end_date)
                rs15 = anc.count_risk15(hospcode, start_date, end_date)
                rs16 = anc.count_risk16(hospcode, start_date, end_date)
                rs17 = anc.count_risk17(hospcode, start_date, end_date)
                rs18 = anc.count_risk18(hospcode, start_date, end_date)

                obj = {
                    "risk01": rs01,
                    "risk02": rs02,
                    "risk03": rs03,
                    "risk04": rs04,
                    "risk05": rs05,
                    "risk06": rs06,
                    "risk07": rs07,
                    "risk08": rs08,
                    "risk09": rs09,
                    "risk10": rs10,
                    "risk11": rs11,
                    "risk12": rs12,
                    "risk13": rs13,
                    "risk14": rs14,
                    "risk15": rs15,
                    "risk16": rs16,
                    "risk17": rs17,
                    "risk18": rs18,
                }

                return {"ok": 1, "rows": [obj]}
        else:
            return {"ok": 0, "msg": "Not authorized."}