Exemple #1
0
def anc_search(request):
    if 'logged' not in request.session:
        return {'ok': 0, 'msg': 'Please login.'}
    else:
        rpt = ReportModel(request)
        person = PersonModel(request)

        cid = request.params['cid']

        rs = rpt.get_anc_search(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, r['hid'], r['hospcode']),
                    'coverages': r['coverages'] if 'coverages' in r else None
                }

                rows.append(obj)

            return {'ok': 1, 'rows': rows}
        else:
            return {'ok': 0, 'msg': 'ไม่พบรายการ'}
Exemple #2
0
def get_list_by_birth(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']
            start_date = h.jsdate_to_string(request.params['start_date'])
            end_date = h.jsdate_to_string(request.params['end_date'])

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

            if is_token:

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

                limit = int(stop) - int(start)

                mch = MchModel(request)
                person = PersonModel(request)

                rs = mch.get_list_by_birth(request.session['hospcode'], start_date, end_date, int(start), int(limit))
                rows = []

                if rs:
                    for r in rs:
                        p = person.get_person_detail(r['pid'], r['hospcode'])
                        obj = {
                            'pid': r['pid'],
                            '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'], r['bdate']),
                            'bdate': h.to_thai_date(r['bdate']),
                            'bplace': r['bplace'],
                            'bhospcode': r['bhosp'],
                            'bhospname': h.get_hospital_name(request, r['bhosp']),
                            'sborn': r['sborn'],
                            'lborn': r['lborn'],
                            'btype': r['btype'],
                            'typearea': r['typearea'],
                            'count_postnatal': mch.get_count_postnatal(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': 'Token not found.'}

        else:
            return {'ok': 0, 'msg': 'Not ajax request.'}
Exemple #3
0
def get_list_by_birth(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:

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

                limit = int(stop) - int(start)

                babies = BabiesModel(request)
                person = PersonModel(request)

                rs = babies.get_list_by_birth(start_date, end_date, int(start), int(limit))
                rows = []

                if rs:
                    for r in rs:
                        p = person.get_person_detail(r["pid"], request.session["hospcode"])
                        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"]),
                            "sex": p["sex"],
                            "bdate": h.to_thai_date(r["bdate"]),
                            "bplace": r["bplace"],
                            "bhospcode": r["bhosp"],
                            "bhospname": h.get_hospital_name(request, r["bhosp"]),
                            "btype": r["btype"],
                            "bweight": r["bweight"],
                            "mother": babies.get_mother(r["mpid"], r["hospcode"]),
                            "care": babies.get_count_care(r["pid"], r["hospcode"]),
                        }
                        rows.append(obj)

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

        else:
            return {"ok": 0, "msg": "Not ajax request."}
Exemple #4
0
def get_info(request):
    if 'logged' not in request.session:
        return HTTPFound(location='/signin')
    else:
        if request.is_xhr:
            csrf_token = request.params['csrf_token']
            is_token = (csrf_token == unicode(request.session.get_csrf_token()))

            if is_token:

                hospcode = request.params['hospcode']
                pid = request.params['pid']
                seq = request.params['seq']
                diagcode = request.params['diagcode']

                epidem = EpidemModel(request)
                person = PersonModel(request)

                rs = epidem.get_info(hospcode, pid, seq, diagcode)
                p = person.get_person_detail(pid, hospcode)

                if rs:
                    if p:
                        village = '0%s' % rs['illvillage'] if len(rs['illvillage']) < 2 else rs['illvillage']
                        catm = '%s%s%s%s' % (rs['illchanwat'], rs['illampur'], rs['illtambon'], village)

                        obj = {
                            'an': rs['an'],
                            'cid': rs['cid'],
                            'pid': rs['pid'],
                            'fullname': '%s %s' % (p['name'], p['lname']),
                            'sex': p['sex'],
                            'birth': h.to_thai_date(p['birth']),
                            'age': h.count_age(p['birth']),
                            'code506': '[%s] %s' % (rs['code506'], h.get_code506_name(request, rs['code506'])),
                            'diag': '[%s] %s' % (rs['diagcode'], h.get_diag_name(request, rs['diagcode'])),
                            'date_death': h.to_thai_date(rs['date_death']),
                            'date_serv': h.to_thai_date(rs['date_serv']),
                            'illdate': h.to_thai_date(rs['illdate']),
                            'ill_address': '%s %s' % (rs['illhouse'], h.get_address_from_catm(request, catm)),
                            'latLng': '%s, %s' % (rs['latitude'], rs['longitude']),
                            'ptstatus': rs['ptstatus'],
                            'complication': h.get_complication_name(request, rs['complication']),
                        }
                        return {
                            'ok': 1, 'rows': obj
                        }
                    else:
                        return {
                            'ok': 0, 'msg': u'ไม่พบข้อมูลบุคคล'
                        }
                else:
                    return {'ok': 0, 'msg': u'ไม่พบข้อมูล'}
            else:
                return {'ok': 0, 'msg': 'Invalid token.'}
Exemple #5
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.'}
Exemple #6
0
def get_history(request):
    if 'logged' not in request.session:
        return HTTPFound(location='/signin')
    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:

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

                limit = int(stop) - int(start)

                ncdscreen = NCDScreenModel(request)
                person = PersonModel(request)

                rs = ncdscreen.get_history(cid, int(start), int(limit))
                rows = []

                if rs:
                    for r in rs:

                        p = person.get_person_detail(r['pid'], r['hospcode'])

                        obj = {
                            'pid': r['pid'],
                            'fullname': p['name'] + '  ' + p['lname'],
                            'cid': p['cid'],
                            'birth': h.to_thai_date(p['birth']),
                            'age': h.count_age(p['birth']),
                            'hospcode': r['hospcode'],
                            'hospname': h.get_hospital_name(request, r['hospcode']),
                            'date_serv_th': h.to_thai_date(r['date_serv']),
                            'date_serv': r['date_serv'],
                            'sbp_1': r['sbp_1'],
                            'dbp_1': r['dbp_1'],
                            'bslevel': r['bslevel'],
                            'weight': r['weight'],
                            'height': r['height'],
                            'bslevel': r['bslevel']
                        }
                        rows.append(obj)

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

        else:
            return {'ok': 0, 'msg': 'Not ajax request.'}
Exemple #7
0
def get_anc_risk_list(request):
    if 'logged' not in request.session:
        return {'ok': 0, 'msg': 'Please login.'}
    else:
        rpt = ReportModel(request)
        hospcode = request.session['hospcode']
        t = request.params['t']

        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)

        #All
        if t == '0':
            rs = rpt.get_risk_all_list(int(start), int(limit), hospcode)
        #Risk
        else:
            rs = rpt.get_risk_filter_list(int(start), int(limit), hospcode, t)

        if rs:
            person = PersonModel(request)
            rows = []

            for r in rs:
                p = person.get_person_detail(r['pid'], r['hospcode'])
                scrn = []

                for s in rpt.get_risk_screen_list(p['cid']):
                    obj_screen = {
                        'last_update': s['last_update'],
                        'id': str(s['_id'])
                    }

                    scrn.append(obj_screen)

                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'],
                    'is_risk': r['is_risk'] if 'is_risk' in r else None,
                    'screen_date': scrn,
                    'address': h.get_address(request, p['hid'], p['hospcode'])
                }

                rows.append(obj)

            return {'ok': 1, 'rows': rows}
        else:
            return {'ok': 0, 'msg': 'ไม่พบรายการ'}
Exemple #8
0
def labor_other_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']
            stop = request.params['stop']

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

            start = int(start)
            limit = int(stop) - int(start)

            hospcode = request.params['hospcode']
            person = PersonModel(request)

            labor_other = LaborOtherModel(request)

            rs = labor_other.get_list(hospcode, start_date, end_date, start, limit)

            rows = []
            if rs:
                for r in rs:
                    p = person.get_person_detail(r['pid'], hospcode)
                    labor = labor_other.get_labor_detail(r['pid'], r['gravida'], r['hospcode'])
                    obj = {
                        'cid': p['cid'],
                        'pid': p['pid'],
                        'fullname': '%s %s' % (p['name'], p['lname']),
                        'age': h.count_age(p['birth']),
                        'birth': h.to_thai_date(p['birth']),
                        'bdate': h.to_thai_date(r['bdate']),
                        #'bresult': labor['bresult'],
                        #'btype': labor['btype'],
                        'bhospname': h.get_hospital_name(request, labor['bhosp']),
                        'bhospcode': labor['bhosp'],
                        'gravida': r['gravida'],
                        'hospcode': r['hospcode'],
                        'hospname': h.get_hospital_name(request, r['hospcode']),
                        'address': h.get_address_from_catm(request, r['address']['vid']),
                        'house': r['address']['house'] if 'house' in r['address'] else '00'
                    }

                    rows.append(obj)

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

        else:
            return {'ok': 0, 'msg': 'Not ajax request.'}
Exemple #9
0
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."}
Exemple #10
0
    def do_process_12weeks(self, hospcode):

        reducer = Code("""
                function(curr, result) {
                    //curr.ga;
                }
        """)

        data = self.request.db['anc'].group(
            key={
                'hospcode': 1,
                'pid': 1,
                'gravida': 1
            },
            condition={
                'hospcode': hospcode,
                'ga': {'$lte': '12'}
            },
            initial={},
            reduce=reducer)

        if data:

            self.request.db['anc_12weeks'].remove({'hospcode': hospcode})

            try:
                person = PersonModel(self.request)

                for i in data:

                    p = person.get_person_detail(i['pid'], i['hospcode'])
                    doc = {
                        'hospcode': i['hospcode'],
                        'pid': i['pid'],
                        'cid': p['cid'],
                        'gravida': i['gravida'],
                        'typearea': p['typearea']
                    }

                    self.request.db['anc_12weeks'].insert(doc)

                return True
            except Exception as ex:
                #print(ex.message)
                return False

        else:
            return False
Exemple #11
0
def labor_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:
                pid = request.params['pid']
                gravida = request.params['gravida']
                hospcode = request.params['hospcode']

                labor_other = LaborOtherModel(request)
                person = PersonModel(request)

                r = labor_other.get_labor_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']),
                        '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': 'Invalid token.'}
Exemple #12
0
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."}
Exemple #13
0
def reports_newborn_weight_less_than_2500(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:

                babies = BabiesModel(request)
                person = PersonModel(request)

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

                limit = int(stop) - int(start)

                rs = babies.get_newborn_weight_less_than_2500(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'],
                            'birth': h.to_thai_date(p['birth']),
                            'address': h.get_address(request, p['hid'], r['hospcode']),
                            'bweight': r['bweight'],
                            '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.'}
Exemple #14
0
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."}
Exemple #15
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."}
Exemple #16
0
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."}
Exemple #17
0
    def update_pcare(self, hospcode, pid, gravida, pcares):
        self.request.db['labor'].ensure_index('hospcode', pymongo.ASCENDING)
        self.request.db['labor'].ensure_index('pid', pymongo.ASCENDING)
        self.request.db['labor'].ensure_index('gravida', pymongo.ASCENDING)

        person = PersonModel(self.request)
        typearea = person.get_type_area(pid, hospcode)

        self.request.db['labor'].update({
            'hospcode': hospcode,
            'pid': pid,
            'gravida': gravida
        }, {
            '$set': {
                'ppcares': pcares,
                'typearea': typearea
            }
        })
Exemple #18
0
def anc_get_list(request):
    if 'logged' not in request.session:
        return {'ok': 0, 'msg': 'Please login.'}
    else:
        t = request.params['t'] if 't' in request.params else '-1'

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

        limit = int(stop) - int(start)

        rpt = ReportModel(request)

        if t == '1':
            #get success
            rs = rpt.get_anc_list_success(request.session['hospcode'], int(start), int(limit))
        elif t == '0':
            #get not success
            rs = rpt.get_anc_list_not_success(request.session['hospcode'], int(start), int(limit))
        else:
            #get all
            rs = rpt.get_anc_list_all(request.session['hospcode'], int(start), int(limit))

        if rs:
            person = PersonModel(request)
            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, r['hid'], r['hospcode']),
                    'coverages': r['coverages'] if 'coverages' in r else None
                }

                rows.append(obj)

            return {'ok': 1, 'rows': rows}
        else:
            return {'ok': 0, 'msg': 'Not success'}
Exemple #19
0
def report_mch_target_per_month(request):
    if 'logged' not in request.session:
        return {'ok': 0, 'msg': 'Please login.'}
    else:
        mch = MchModel(request)
        person = PersonModel(request)

        current_date = datetime.now()
        current_month = datetime.strftime(current_date, '%m')
        current_year = datetime.strftime(current_date, '%Y')
        end_day_of_month = calendar.monthrange(int(current_year),
                                               int(current_month))[1]

        start_date = date(int(current_year), int(current_month), 1)
        end_date = date(int(current_year), int(current_month),
                        int(end_day_of_month))

        start_date = datetime.strftime(start_date, '%Y%m%d')
        end_date = datetime.strftime(end_date, '%Y%m%d')

        rs = mch.get_target_per_month(request.session['hospcode'], start_date,
                                      end_date)

        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'],
                    #'bdate': h.to_thai_date(r['bdate']),
                    #'address': h.get_address(request, r['hid'], r['hospcode']),
                    #'ppcares': r['ppcares'] if 'ppcares' in r else None
                }

                rows.append(obj)

            return {'ok': 1, 'rows': rows}
        else:
            return {'ok': 0, 'msg': 'ไม่พบรายการ'}
Exemple #20
0
def report_mch_list(request):
    if 'logged' not in request.session:
        return {'ok': 0, 'msg': 'Please login.'}
    else:
        start = request.params['start']
        stop = request.params['stop']

        limit = int(stop) - int(start)

        mch = MchModel(request)
        person = PersonModel(request)

        if request.params['s'] != "" and request.params['e'] != "":
            #Get by date
            start_date = h.jsdate_to_string(request.params['s'])
            end_date = h.jsdate_to_string(request.params['e'])

            rs = mch.get_labor_forecast_filter_list(request.session['hospcode'], start_date, end_date,
                                                    int(start), int(limit))
        else:
            rs = mch.get_labor_forecast_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'],
                    'bdate': h.to_thai_date(r['bdate']),
                    #'address': h.get_address(request, r['hid'], r['hospcode']),
                    'ppcares': r['ppcares'] if 'ppcares' in r else None
                }

                rows.append(obj)

            return {'ok': 1, 'rows': rows}
        else:
            return {'ok': 0, 'msg': 'ไม่พบรายการ'}
Exemple #21
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.'}
Exemple #22
0
def get_anc_risk_list_search(request):
    if 'logged' not in request.session:
        return {'ok': 0, 'msg': 'Please login.'}
    else:
        rpt = ReportModel(request)

        cid = request.params['cid']
        rs = rpt.get_risk_search(cid)

        if rs:
            person = PersonModel(request)
            rows = []

            for r in rs:
                p = person.get_person_detail(r['pid'], r['hospcode'])
                scrn = []

                for s in rpt.get_risk_screen_list(p['cid']):
                    obj_screen = {
                        'last_update': s['last_update'],
                        'id': str(s['_id'])
                    }

                    scrn.append(obj_screen)

                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'],
                    'is_risk': r['is_risk'],
                    'screen_date': scrn,
                    'address': h.get_address(request, p['hid'], p['hospcode'])
                }

                rows.append(obj)

            return {'ok': 1, 'rows': rows}
        else:
            return {'ok': 0, 'msg': 'ไม่พบรายการ'}
Exemple #23
0
def report_anc_target_per_month(request):
    if 'logged' not in request.session:
        return {'ok': 0, 'msg': 'Please login.'}
    else:
        rpt = ReportModel(request)
        person = PersonModel(request)

        current_date = datetime.now()
        current_month = datetime.strftime(current_date, '%m')
        current_year = datetime.strftime(current_date, '%Y')
        end_day_of_month = calendar.monthrange(int(current_year), int(current_month))[1]

        start_date = date(int(current_year), int(current_month), 1)
        end_date = date(int(current_year), int(current_month), int(end_day_of_month))

        start_date = datetime.strftime(start_date, '%Y%m%d')
        end_date = datetime.strftime(end_date, '%Y%m%d')

        rs = rpt.get_anc_target_per_month(request.session['hospcode'], start_date, end_date)

        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'],
                    #'bdate': h.to_thai_date(r['bdate']),
                    #'address': h.get_address(request, r['hid'], r['hospcode']),
                    #'ppcares': r['ppcares'] if 'ppcares' in r else None
                }

                rows.append(obj)

            return {'ok': 1, 'rows': rows}
        else:
            return {'ok': 0, 'msg': 'ไม่พบรายการ'}
Exemple #24
0
    def do_process_list(self, hospcode, start_date, end_date):

        reducer = Code("""
                function(curr, result) {
                    //result.total++;
                }
        """)

        data = self.request.db['labor'].group(key={
            'hospcode': 1,
            'pid': 1,
            'gravida': 1,
            'bdate': 1
        },
                                              condition={
                                                  'hospcode': hospcode,
                                                  'bdate': {
                                                      '$gte': start_date,
                                                      '$lte': end_date
                                                  }
                                              },
                                              initial={},
                                              reduce=reducer)

        if data:

            self.request.db['labor_other'].remove(
                {'process_hospcode': self.request.session['hospcode']})

            person = PersonModel(self.request)

            for r in data:

                typearea = person.get_type_area(r['pid'], r['hospcode'])

                if typearea in ['2', '4']:
                    address = person.get_vid_from_address(
                        r['pid'], r['hospcode'])
                else:
                    hid = person.get_hid_from_pid(r['pid'], r['hospcode'])
                    address = person.get_vid_from_home(hid, r['hospcode'])

                obj = {
                    'hospcode': r['hospcode'],
                    'process_hospcode': self.request.session['hospcode'],
                    'pid': r['pid'],
                    'gravida': r['gravida'],
                    'bdate': r['bdate'],
                    'address': address,
                    'typearea': person.get_type_area(r['pid'], r['hospcode'])
                }

                self.request.db['labor_other'].insert(obj)

        else:
            return False
Exemple #25
0
def get_anc_risk_list_search(request):
    if 'logged' not in request.session:
        return {'ok': 0, 'msg': 'Please login.'}
    else:
        rpt = ReportModel(request)

        cid = request.params['cid']
        rs = rpt.get_risk_search(cid)

        if rs:
            person = PersonModel(request)
            rows = []

            for r in rs:
                p = person.get_person_detail(r['pid'], r['hospcode'])
                scrn = []

                for s in rpt.get_risk_screen_list(p['cid']):
                    obj_screen = {
                        'last_update': s['last_update'],
                        'id': str(s['_id'])
                    }

                    scrn.append(obj_screen)

                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'],
                    'is_risk': r['is_risk'],
                    'screen_date': scrn,
                    'address': h.get_address(request, p['hid'], p['hospcode'])
                }

                rows.append(obj)

            return {'ok': 1, 'rows': rows}
        else:
            return {'ok': 0, 'msg': 'ไม่พบรายการ'}
Exemple #26
0
    def process_milk(self, hospcode):
        self.request.db['newborncare'].ensure_index('hospcode', pymongo.ASCENDING)

        reducer = Code("""
                        function(curr, result) {
                            result.total++
                        }
                    """)

        data = self.request.db['newborncare'].group(
            key={
                'hospcode': 1,
                'pid': 1,
            },
            condition={
                'hospcode': hospcode,
                'food': '1'
            },
            initial={'total': 0},
            reduce=reducer)

        if data:
            self.request.db['newborn_milks'].remove({'hospcode': hospcode})
            person = PersonModel(self.request)

            for r in data:
                p = person.get_person_detail(r['pid'], r['hospcode'])
                obj = {
                    'cid': p['cid'],
                    'pid': r['pid'],
                    'hospcode': r['hospcode'],
                    'total': r['total']
                }

                self.request.db['newborn_milks'].insert(obj)

            return True
        else:
            return False
Exemple #27
0
    def process_milk(self, hospcode):
        self.request.db['newborncare'].ensure_index('hospcode',
                                                    pymongo.ASCENDING)

        reducer = Code("""
                        function(curr, result) {
                            result.total++
                        }
                    """)

        data = self.request.db['newborncare'].group(key={
            'hospcode': 1,
            'pid': 1,
        },
                                                    condition={
                                                        'hospcode': hospcode,
                                                        'food': '1'
                                                    },
                                                    initial={'total': 0},
                                                    reduce=reducer)

        if data:
            self.request.db['newborn_milks'].remove({'hospcode': hospcode})
            person = PersonModel(self.request)

            for r in data:
                p = person.get_person_detail(r['pid'], r['hospcode'])
                obj = {
                    'cid': p['cid'],
                    'pid': r['pid'],
                    'hospcode': r['hospcode'],
                    'total': r['total']
                }

                self.request.db['newborn_milks'].insert(obj)

            return True
        else:
            return False
Exemple #28
0
    def do_process_list(self, hospcode, start_date, end_date):

        reducer = Code("""
                function(curr, result) {
                    //result.total++;
                }
        """)

        data = self.request.db['labor'].group(
            key={
                'hospcode': 1,
                'pid': 1,
                'gravida': 1,
                'bdate': 1
            },
            condition={
                'hospcode': hospcode,
                'bdate': {
                    '$gte': start_date,
                    '$lte': end_date
                }
            },
            initial={},
            reduce=reducer)

        if data:

            self.request.db['labor_other'].remove({'process_hospcode': self.request.session['hospcode']})

            person = PersonModel(self.request)

            for r in data:

                typearea = person.get_type_area(r['pid'], r['hospcode'])

                if typearea in ['2', '4']:
                    address = person.get_vid_from_address(r['pid'], r['hospcode'])
                else:
                    hid = person.get_hid_from_pid(r['pid'], r['hospcode'])
                    address = person.get_vid_from_home(hid, r['hospcode'])

                obj = {
                    'hospcode': r['hospcode'],
                    'process_hospcode': self.request.session['hospcode'],
                    'pid': r['pid'],
                    'gravida': r['gravida'],
                    'bdate': r['bdate'],
                    'address': address,
                    'typearea': person.get_type_area(r['pid'], r['hospcode'])
                }

                self.request.db['labor_other'].insert(obj)

        else:
            return False
Exemple #29
0
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"}
Exemple #30
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.'}
Exemple #31
0
def labor_other_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']
            stop = request.params['stop']

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

            start = int(start)
            limit = int(stop) - int(start)

            hospcode = request.params['hospcode']
            person = PersonModel(request)

            labor_other = LaborOtherModel(request)

            rs = labor_other.get_list(hospcode, start_date, end_date, start,
                                      limit)

            rows = []
            if rs:
                for r in rs:
                    p = person.get_person_detail(r['pid'], hospcode)
                    labor = labor_other.get_labor_detail(
                        r['pid'], r['gravida'], r['hospcode'])
                    obj = {
                        'cid':
                        p['cid'],
                        'pid':
                        p['pid'],
                        'fullname':
                        '%s %s' % (p['name'], p['lname']),
                        'age':
                        h.count_age(p['birth']),
                        'birth':
                        h.to_thai_date(p['birth']),
                        'bdate':
                        h.to_thai_date(r['bdate']),
                        #'bresult': labor['bresult'],
                        #'btype': labor['btype'],
                        'bhospname':
                        h.get_hospital_name(request, labor['bhosp']),
                        'bhospcode':
                        labor['bhosp'],
                        'gravida':
                        r['gravida'],
                        'hospcode':
                        r['hospcode'],
                        'hospname':
                        h.get_hospital_name(request, r['hospcode']),
                        'address':
                        h.get_address_from_catm(request, r['address']['vid']),
                        'house':
                        r['address']['house']
                        if 'house' in r['address'] else '00'
                    }

                    rows.append(obj)

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

        else:
            return {'ok': 0, 'msg': 'Not ajax request.'}
Exemple #32
0
    def do_process_list(self, hospcode):

        reducer = Code("""
                function(curr, result) {
                    result.total++;
                }
        """)

        data = self.request.db['anc'].group(key={
            'hospcode': 1,
            'pid': 1,
            'gravida': 1
        },
                                            condition={'hospcode': hospcode},
                                            initial={'total': 0},
                                            reduce=reducer)

        if data:

            self.request.db['anc_coverages'].remove({'hospcode': hospcode})

            try:
                person = PersonModel(self.request)

                for i in data:
                    #get anc detail
                    anc01 = self.get_anc_detail(i['hospcode'], i['pid'],
                                                i['gravida'], '1')
                    anc02 = self.get_anc_detail(i['hospcode'], i['pid'],
                                                i['gravida'], '2')
                    anc03 = self.get_anc_detail(i['hospcode'], i['pid'],
                                                i['gravida'], '3')
                    anc04 = self.get_anc_detail(i['hospcode'], i['pid'],
                                                i['gravida'], '4')
                    anc05 = self.get_anc_detail(i['hospcode'], i['pid'],
                                                i['gravida'], '5')

                    #print(anc04)
                    p = person.get_person_detail(i['pid'], i['hospcode'])
                    doc = {
                        'hospcode':
                        i['hospcode'],
                        'pid':
                        i['pid'],
                        'cid':
                        p['cid'],
                        'gravida':
                        i['gravida'],
                        'total':
                        i['total'],
                        'hid':
                        p['hid'],
                        'typearea':
                        p['typearea'],
                        'is_labor':
                        self.is_labor(i['hospcode'], i['pid'], i['gravida']),
                        #get anc coverages
                        'coverages': [{
                            'ancno':
                            '1',
                            'ga':
                            anc01['ga'] if 'ga' in anc01 else None,
                            'date_serv':
                            anc01['date_serv']
                            if 'date_serv' in anc01 else None,
                            'forecast':
                            None
                            if 'date_serv' in anc01 else self.get_anc_forecast(
                                anc01, anc02, anc03, anc04, anc05, '1')
                        }, {
                            'ancno':
                            '2',
                            'ga':
                            anc02['ga'] if 'ga' in anc02 else None,
                            'date_serv':
                            anc02['date_serv']
                            if 'date_serv' in anc02 else None,
                            'forecast':
                            None
                            if 'date_serv' in anc02 else self.get_anc_forecast(
                                anc01, anc02, anc03, anc04, anc05, '2')
                        }, {
                            'ancno':
                            '3',
                            'ga':
                            anc03['ga'] if 'ga' in anc03 else None,
                            'date_serv':
                            anc03['date_serv']
                            if 'date_serv' in anc03 else None,
                            'forecast':
                            None
                            if 'date_serv' in anc03 else self.get_anc_forecast(
                                anc01, anc02, anc03, anc04, anc05, '3')
                        }, {
                            'ancno':
                            '4',
                            'ga':
                            anc04['ga'] if 'ga' in anc04 else None,
                            'date_serv':
                            anc04['date_serv']
                            if 'date_serv' in anc04 else None,
                            'forecast':
                            None
                            if 'date_serv' in anc04 else self.get_anc_forecast(
                                anc01, anc02, anc03, anc04, anc05, '4')
                        }, {
                            'ancno':
                            '5',
                            'ga':
                            anc05['ga'] if 'ga' in anc05 else None,
                            'date_serv':
                            anc05['date_serv']
                            if 'date_serv' in anc05 else None,
                            'forecast':
                            None
                            if 'date_serv' in anc05 else self.get_anc_forecast(
                                anc01, anc02, anc03, anc04, anc05, '5')
                        }]
                    }

                    self.request.db['anc_coverages'].insert(doc)

                return True
            except Exception as ex:
                #print(ex.message)
                return False

        else:
            return False
Exemple #33
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'}
Exemple #34
0
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.'}
Exemple #35
0
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.'}
Exemple #36
0
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'}
Exemple #37
0
def get_info(request):
    if 'logged' not in request.session:
        return HTTPFound(location='/signin')
    else:
        if request.is_xhr:
            csrf_token = request.params['csrf_token']
            is_token = (csrf_token == unicode(
                request.session.get_csrf_token()))

            if is_token:

                hospcode = request.params['hospcode']
                pid = request.params['pid']
                seq = request.params['seq']
                diagcode = request.params['diagcode']

                epidem = EpidemModel(request)
                person = PersonModel(request)

                rs = epidem.get_info(hospcode, pid, seq, diagcode)
                p = person.get_person_detail(pid, hospcode)

                if rs:
                    if p:
                        village = '0%s' % rs['illvillage'] if len(
                            rs['illvillage']) < 2 else rs['illvillage']
                        catm = '%s%s%s%s' % (rs['illchanwat'], rs['illampur'],
                                             rs['illtambon'], village)

                        obj = {
                            'an':
                            rs['an'],
                            'cid':
                            rs['cid'],
                            'pid':
                            rs['pid'],
                            'fullname':
                            '%s %s' % (p['name'], p['lname']),
                            'sex':
                            p['sex'],
                            'birth':
                            h.to_thai_date(p['birth']),
                            'age':
                            h.count_age(p['birth']),
                            'code506':
                            '[%s] %s' %
                            (rs['code506'],
                             h.get_code506_name(request, rs['code506'])),
                            'diag':
                            '[%s] %s' %
                            (rs['diagcode'],
                             h.get_diag_name(request, rs['diagcode'])),
                            'date_death':
                            h.to_thai_date(rs['date_death']),
                            'date_serv':
                            h.to_thai_date(rs['date_serv']),
                            'illdate':
                            h.to_thai_date(rs['illdate']),
                            'ill_address':
                            '%s %s' % (rs['illhouse'],
                                       h.get_address_from_catm(request, catm)),
                            'latLng':
                            '%s, %s' % (rs['latitude'], rs['longitude']),
                            'ptstatus':
                            rs['ptstatus'],
                            'complication':
                            h.get_complication_name(request,
                                                    rs['complication']),
                        }
                        return {'ok': 1, 'rows': obj}
                    else:
                        return {'ok': 0, 'msg': u'ไม่พบข้อมูลบุคคล'}
                else:
                    return {'ok': 0, 'msg': u'ไม่พบข้อมูล'}
            else:
                return {'ok': 0, 'msg': 'Invalid token.'}
Exemple #38
0
def get_list(request):
    if 'logged' not in request.session:
        return HTTPFound(location='/signin')
    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:

                start_date = request.params['start_date']
                end_date = request.params['end_date']

                code506 = request.params['code506']
                ptstatus = request.params['ptstatus']

                start_date = start_date.split('/')
                end_date = end_date.split('/')

                sy = int(start_date[2]) - 543
                ey = int(end_date[2]) - 543

                start_date = str(sy) + start_date[1] + start_date[0]
                end_date = str(ey) + end_date[1] + end_date[0]

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

                limit = int(stop) - int(start)

                epidem = EpidemModel(request)
                person = PersonModel(request)

                if code506 and not ptstatus:
                    rs = epidem.get_list_by_code506(
                        request.session['hospcode'], code506, start_date,
                        end_date, int(start), int(limit))
                elif ptstatus and not code506:
                    rs = epidem.get_list_by_ptstatus(
                        request.session['hospcode'], ptstatus, start_date,
                        end_date, int(start), int(limit))
                elif ptstatus and code506:
                    rs = epidem.get_list_by_code506_ptstatus(
                        request.session['hospcode'], code506, ptstatus,
                        start_date, end_date, int(start), int(limit))
                else:
                    rs = epidem.get_list(request.session['hospcode'],
                                         start_date, end_date, int(start),
                                         int(limit))

                rows = []

                if rs:
                    for r in rs:

                        p = person.get_person_detail(r['pid'], r['hospcode'])

                        if p:

                            village = '0%s' % r['illvillage'] if len(
                                r['illvillage']) < 2 else r['illvillage']
                            catm = '%s%s%s%s' % (r['illchanwat'],
                                                 r['illampur'], r['illtambon'],
                                                 village)

                            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']),
                                'sex':
                                p['sex'],
                                'ill_address':
                                '%s %s' %
                                (r['illhouse'],
                                 h.get_address_from_catm(request, catm)),
                                'illdate':
                                h.to_thai_date(r['illdate']),
                                'date_serv':
                                h.to_thai_date(r['date_serv']),
                                'code506':
                                r['code506'],
                                'code506_name':
                                h.get_code506_name(request, r['code506']),
                                'ptstatus':
                                r['ptstatus'],
                                'seq':
                                r['seq'],
                                'diagcode':
                                r['diagcode'],
                                'diagname':
                                h.get_diag_name(request, r['diagcode']),
                                'hospcode':
                                r['hospcode']
                            }
                        else:
                            obj = {
                                'pid': '-',
                                'cid': '-',
                                'fullname': '-',
                                'birth': '-',
                                'age': '-',
                                'sex': '-',
                                'ill_address': '-',
                                'illdate': '-',
                                'code506': '-',
                                'code506_name': '-',
                                'ptstatus': '-'
                            }
                        rows.append(obj)

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

        else:
            return {'ok': 0, 'msg': 'Not ajax request.'}
Exemple #39
0
    def do_process_list(self, hospcode):

        reducer = Code("""
                function(curr, result) {
                    result.total++;
                }
        """)

        data = self.request.db['anc'].group(
            key={
                'hospcode': 1,
                'pid': 1,
                'gravida': 1
            },
            condition={
                'hospcode': hospcode
            },
            initial={'total': 0},
            reduce=reducer)

        if data:

            self.request.db['anc_coverages'].remove({'hospcode': hospcode})

            try:
                person = PersonModel(self.request)

                for i in data:
                    #get anc detail
                    anc01 = self.get_anc_detail(i['hospcode'], i['pid'], i['gravida'], '1')
                    anc02 = self.get_anc_detail(i['hospcode'], i['pid'], i['gravida'], '2')
                    anc03 = self.get_anc_detail(i['hospcode'], i['pid'], i['gravida'], '3')
                    anc04 = self.get_anc_detail(i['hospcode'], i['pid'], i['gravida'], '4')
                    anc05 = self.get_anc_detail(i['hospcode'], i['pid'], i['gravida'], '5')

                    #print(anc04)
                    p = person.get_person_detail(i['pid'], i['hospcode'])
                    doc = {
                        'hospcode': i['hospcode'],
                        'pid': i['pid'],
                        'cid': p['cid'],
                        'gravida': i['gravida'],
                        'total': i['total'],
                        'hid': p['hid'],
                        'typearea': p['typearea'],
                        'is_labor': self.is_labor(i['hospcode'], i['pid'], i['gravida']),
                        #get anc coverages
                        'coverages': [
                            {
                                'ancno': '1',
                                'ga': anc01['ga'] if 'ga' in anc01 else None,
                                'date_serv': anc01['date_serv'] if 'date_serv' in anc01 else None,
                                'forecast': None if 'date_serv' in anc01 else self.get_anc_forecast(anc01, anc02, anc03, anc04, anc05, '1')
                            },
                            {
                                'ancno': '2',
                                'ga': anc02['ga'] if 'ga' in anc02 else None,
                                'date_serv': anc02['date_serv'] if 'date_serv' in anc02 else None,
                                'forecast': None if 'date_serv' in anc02 else self.get_anc_forecast(anc01, anc02, anc03, anc04, anc05, '2')
                            },
                            {
                                'ancno': '3',
                                'ga': anc03['ga'] if 'ga' in anc03 else None,
                                'date_serv': anc03['date_serv'] if 'date_serv' in anc03 else None,
                                'forecast': None if 'date_serv' in anc03 else self.get_anc_forecast(anc01, anc02, anc03, anc04, anc05, '3')
                            },
                            {
                                'ancno': '4',
                                'ga': anc04['ga'] if 'ga' in anc04 else None,
                                'date_serv': anc04['date_serv'] if 'date_serv' in anc04 else None,
                                'forecast': None if 'date_serv' in anc04 else self.get_anc_forecast(anc01, anc02, anc03, anc04, anc05, '4')
                            },
                            {
                                'ancno': '5',
                                'ga': anc05['ga'] if 'ga' in anc05 else None,
                                'date_serv': anc05['date_serv'] if 'date_serv' in anc05 else None,
                                'forecast': None if 'date_serv' in anc05 else self.get_anc_forecast(anc01, anc02, anc03, anc04, anc05, '5')
                            }
                        ]
                    }

                    self.request.db['anc_coverages'].insert(doc)

                return True
            except Exception as ex:
                #print(ex.message)
                return False

        else:
            return False
Exemple #40
0
def get_list(request):
    if 'logged' not in request.session:
        return HTTPFound(location='/signin')
    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:

                start_date = request.params['start_date']
                end_date = request.params['end_date']

                code506 = request.params['code506']
                ptstatus = request.params['ptstatus']

                start_date = start_date.split('/')
                end_date = end_date.split('/')

                sy = int(start_date[2]) - 543
                ey = int(end_date[2]) - 543

                start_date = str(sy) + start_date[1] + start_date[0]
                end_date = str(ey) + end_date[1] + end_date[0]

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

                limit = int(stop) - int(start)

                epidem = EpidemModel(request)
                person = PersonModel(request)

                if code506 and not ptstatus:
                    rs = epidem.get_list_by_code506(request.session['hospcode'], code506, start_date, end_date, int(start), int(limit))
                elif ptstatus and not code506:
                    rs = epidem.get_list_by_ptstatus(request.session['hospcode'], ptstatus, start_date, end_date, int(start), int(limit))
                elif ptstatus and code506:
                    rs = epidem.get_list_by_code506_ptstatus(request.session['hospcode'], code506, ptstatus, start_date, end_date, int(start), int(limit))
                else:
                    rs = epidem.get_list(request.session['hospcode'], start_date, end_date, int(start), int(limit))

                rows = []

                if rs:
                    for r in rs:

                        p = person.get_person_detail(r['pid'], r['hospcode'])

                        if p:

                            village = '0%s' % r['illvillage'] if len(r['illvillage']) < 2 else r['illvillage']
                            catm = '%s%s%s%s' % (r['illchanwat'], r['illampur'], r['illtambon'], village)

                            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']),
                                'sex': p['sex'],
                                'ill_address': '%s %s' % (r['illhouse'], h.get_address_from_catm(request, catm)),
                                'illdate': h.to_thai_date(r['illdate']),
                                'date_serv': h.to_thai_date(r['date_serv']),
                                'code506': r['code506'],
                                'code506_name': h.get_code506_name(request, r['code506']),
                                'ptstatus': r['ptstatus'],
                                'seq': r['seq'],
                                'diagcode': r['diagcode'],
                                'diagname': h.get_diag_name(request, r['diagcode']),
                                'hospcode': r['hospcode']
                            }
                        else:
                            obj = {
                                'pid': '-',
                                'cid': '-',
                                'fullname': '-',
                                'birth': '-',
                                'age': '-',
                                'sex': '-',
                                'ill_address': '-',
                                'illdate': '-',
                                'code506': '-',
                                'code506_name': '-',
                                'ptstatus': '-'
                            }
                        rows.append(obj)

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

        else:
            return {'ok': 0, 'msg': 'Not ajax request.'}
Exemple #41
0
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."}
Exemple #42
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"}
Exemple #43
0
def get_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:

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

                limit = int(stop) - int(start)

                mch = MchModel(request)
                person = PersonModel(request)

                rs = mch.get_list(request.session['hospcode'], int(start),
                                  int(limit))
                rows = []

                if rs:
                    for r in rs:
                        p = person.get_person_detail(
                            r['pid'], request.session['hospcode'])
                        obj = {
                            'pid':
                            r['pid'],
                            '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'], r['bdate']),
                            'bdate':
                            h.to_thai_date(r['bdate']),
                            'bplace':
                            r['bplace'],
                            'bhospcode':
                            r['bhosp'],
                            'bhospname':
                            h.get_hospital_name(request, r['bhosp']),
                            'sborn':
                            r['sborn'],
                            'lborn':
                            r['lborn'],
                            'btype':
                            r['btype'],
                            'typearea':
                            r['typearea'] if 'typearea' in r else '0',
                            'count_postnatal':
                            mch.get_count_postnatal(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': 'Token not found.'}

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