예제 #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': 'ไม่พบรายการ'}
예제 #2
0
파일: reports.py 프로젝트: siteslave/iCare
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': 'ไม่พบรายการ'}
예제 #3
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.'}
예제 #4
0
파일: anc.py 프로젝트: siteslave/iCare
def anc_get_list_map(request):
    if 'logged' not in request.session:
        return {'ok': 0, 'msg': 'Please login.'}
    else:
        if request.is_xhr:  # is ajax request
            start = request.params['start']
            stop = request.params['stop']
            by = request.params['by']
            vid = request.params['vid'] if 'vid' in request.params else False

            limit = int(stop) - int(start)

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

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

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

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

                    rows.append(obj)

                return {'ok': 1, 'rows': rows}
            else:
                return {'ok': 0, 'msg': u'ไม่พบข้อมูล'}
        else:
            return {'ok': 0, 'msg': 'Not ajax request.'}
예제 #5
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.'}
예제 #6
0
파일: mch.py 프로젝트: siteslave/iCare
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.'}
예제 #7
0
파일: babies.py 프로젝트: siteslave/iCare
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."}
예제 #8
0
파일: epidem.py 프로젝트: siteslave/iCare
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.'}
예제 #9
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.'}
예제 #10
0
파일: reports.py 프로젝트: siteslave/iCare
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.'}
예제 #11
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.'}
예제 #12
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': 'ไม่พบรายการ'}
예제 #13
0
파일: reports.py 프로젝트: siteslave/iCare
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': 'ไม่พบรายการ'}
예제 #14
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.'}
예제 #15
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.'}
예제 #16
0
파일: anc.py 프로젝트: siteslave/iCare
def get_labor(request):

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

            csrf_token = request.params['csrf_token']
            is_token = (csrf_token == unicode(
                request.session.get_csrf_token()))

            if is_token:
                cid = request.params['cid']
                gravida = request.params['gravida']

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

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

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

                    return {'ok': 1, 'rows': [obj]}
                else:
                    return {'ok': 0, 'msg': u'ไม่พบรายการ'}
            else:
                return {'ok': 0, 'msg': 'Not authorized.'}
        else:
            return {'ok': 0, 'msg': 'Not Ajax.'}
예제 #17
0
파일: anc.py 프로젝트: siteslave/iCare
def anc_get_risk_list_by_type(request):

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

            csrf_token = request.params['csrf_token']
            is_token = (csrf_token == unicode(
                request.session.get_csrf_token()))

            if is_token:

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

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

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

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

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

                        rows.append(obj)

                    return {'ok': 1, 'rows': rows}

                else:
                    return {'ok': 0, 'msg': u'ไม่พบรายการ'}
            else:
                return {'ok': 0, 'msg': 'Not authorized.'}

        else:
            return {'ok': 0, 'msg': 'Not ajax.'}
예제 #18
0
파일: anc.py 프로젝트: siteslave/iCare
def get_list(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."}
예제 #19
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
예제 #20
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.'}
예제 #21
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
예제 #22
0
파일: anc.py 프로젝트: siteslave/iCare
def get_prenatal(request):

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

            csrf_token = request.params['csrf_token']
            is_token = (csrf_token == unicode(
                request.session.get_csrf_token()))

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

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

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

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

                    return {'ok': 1, 'rows': [obj]}
                else:
                    return {'ok': 0, 'msg': u'ไม่พบรายการ'}
            else:
                return {'ok': 0, 'msg': 'Not authorized.'}
        else:
            return {'ok': 0, 'msg': 'Not Ajax.'}
예제 #23
0
파일: anc.py 프로젝트: siteslave/iCare
def get_labor(request):

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

            csrf_token = request.params["csrf_token"]
            is_token = csrf_token == unicode(request.session.get_csrf_token())

            if is_token:
                cid = request.params["cid"]
                gravida = request.params["gravida"]

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

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

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

                    return {"ok": 1, "rows": [obj]}
                else:
                    return {"ok": 0, "msg": u"ไม่พบรายการ"}
            else:
                return {"ok": 0, "msg": "Not authorized."}
        else:
            return {"ok": 0, "msg": "Not Ajax."}
예제 #24
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.'}
예제 #25
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'}
예제 #26
0
파일: reports.py 프로젝트: siteslave/iCare
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.'}
예제 #27
0
파일: anc.py 프로젝트: siteslave/iCare
def anc_get_risk_list_by_type(request):

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

            csrf_token = request.params["csrf_token"]
            is_token = csrf_token == unicode(request.session.get_csrf_token())

            if is_token:

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

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

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

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

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

                        rows.append(obj)

                    return {"ok": 1, "rows": rows}

                else:
                    return {"ok": 0, "msg": u"ไม่พบรายการ"}
            else:
                return {"ok": 0, "msg": "Not authorized."}

        else:
            return {"ok": 0, "msg": "Not ajax."}
예제 #28
0
파일: anc.py 프로젝트: siteslave/iCare
def anc_get_list_map(request):
    if "logged" not in request.session:
        return {"ok": 0, "msg": "Please login."}
    else:
        if request.is_xhr:  # is ajax request
            start = request.params["start"]
            stop = request.params["stop"]
            by = request.params["by"]
            vid = request.params["vid"] if "vid" in request.params else False

            limit = int(stop) - int(start)

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

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

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

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

                    rows.append(obj)

                return {"ok": 1, "rows": rows}
            else:
                return {"ok": 0, "msg": u"ไม่พบข้อมูล"}
        else:
            return {"ok": 0, "msg": "Not ajax request."}
예제 #29
0
파일: anc.py 프로젝트: siteslave/iCare
def get_prenatal(request):

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

            csrf_token = request.params["csrf_token"]
            is_token = csrf_token == unicode(request.session.get_csrf_token())

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

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

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

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

                    return {"ok": 1, "rows": [obj]}
                else:
                    return {"ok": 0, "msg": u"ไม่พบรายการ"}
            else:
                return {"ok": 0, "msg": "Not authorized."}
        else:
            return {"ok": 0, "msg": "Not Ajax."}
예제 #30
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': 'ไม่พบรายการ'}
예제 #31
0
파일: reports.py 프로젝트: siteslave/iCare
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'}
예제 #32
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': 'ไม่พบรายการ'}
예제 #33
0
파일: reports.py 프로젝트: siteslave/iCare
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': 'ไม่พบรายการ'}
예제 #34
0
파일: reports.py 프로젝트: siteslave/iCare
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': 'ไม่พบรายการ'}
예제 #35
0
파일: reports.py 프로젝트: siteslave/iCare
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.'}
예제 #36
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': 'ไม่พบรายการ'}
예제 #37
0
파일: reports.py 프로젝트: siteslave/iCare
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': 'ไม่พบรายการ'}
예제 #38
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
예제 #39
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
예제 #40
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.'}
예제 #41
0
파일: anc.py 프로젝트: siteslave/iCare
def search(request):

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

            csrf_token = request.params["csrf_token"]
            is_token = csrf_token == unicode(request.session.get_csrf_token())

            if is_token:

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

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

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

                rows = []
                if rs:
                    for r in rs:
                        labor = anc.get_labor_detail(r["pid"], r["gravida"], request.session["hospcode"])
                        prenatal = anc.get_prenatal_detail(r["pid"], r["gravida"], request.session["hospcode"])
                        p = person.get_person_detail(r["pid"], request.session["hospcode"])

                        bdate = h.to_thai_date(labor["bdate"]) if labor else "-"
                        edc = h.to_thai_date(prenatal["edc"]) if prenatal else "-"
                        lmp = h.to_thai_date(prenatal["lmp"]) if prenatal else "-"

                        obj = {
                            "pid": r["pid"],
                            "cid": r["cid"],
                            "hospcode": r["hospcode"],
                            "gravida": r["gravida"],
                            "fullname": p["name"] + "  " + p["lname"],
                            "cid": p["cid"],
                            "birth": h.to_thai_date(p["birth"]),
                            "age": h.count_age(p["birth"]),
                            "first_visit": h.to_thai_date(anc.get_first_anc(p["pid"], r["gravida"], r["hospcode"])),
                            "last_visit": h.to_thai_date(anc.get_last_anc(p["pid"], r["gravida"], r["hospcode"])),
                            "bdate": bdate,
                            "edc": edc,
                            "lmp": lmp,
                            "is_survey": anc.get_survey_status(r["pid"], r["gravida"], r["hospcode"]),
                            "anc_count": anc.get_anc_count(r["pid"], r["hospcode"], r["gravida"]),
                        }
                        rows.append(obj)

                    return {"ok": 1, "rows": rows}
                else:
                    return {"ok": 0, "msg": u"ไม่พบข้อมูล"}
            else:
                return {"ok": 0, "msg": "Not authorized."}
        else:
            return {"ok": 0, "msg": "Not ajax."}
예제 #42
0
파일: anc.py 프로젝트: siteslave/iCare
def anc_all_latlng(request):
    if "logged" not in request.session:
        return {"ok": 0, "msg": "Please login."}
    else:
        csrf_token = request.params["csrf_token"]
        is_token = csrf_token == unicode(request.session.get_csrf_token())

        if is_token:

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

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

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

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

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

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

                    rows.append(obj)

            return {"ok": 1, "rows": rows}
            # except Exception as e:
            #    return {'ok': 0, 'msg': e.message}
        else:
            return {"ok": 0, "msg": "Not authorized"}
예제 #43
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
예제 #44
0
파일: anc.py 프로젝트: siteslave/iCare
def anc_all_latlng(request):
    if 'logged' not in request.session:
        return {'ok': 0, 'msg': 'Please login.'}
    else:
        csrf_token = request.params['csrf_token']
        is_token = (csrf_token == unicode(request.session.get_csrf_token()))

        if is_token:

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

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

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

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

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

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

                    rows.append(obj)

            return {'ok': 1, 'rows': rows}
            #except Exception as e:
            #    return {'ok': 0, 'msg': e.message}
        else:
            return {'ok': 0, 'msg': 'Not authorized'}
예제 #45
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.'}
예제 #46
0
파일: anc.py 프로젝트: siteslave/iCare
def get_list(request):
    if 'logged' not in request.session:
        return {'ok': 0, 'msg': 'Please login.'}
    else:
        if request.is_xhr:  # is ajax request
            start = request.params['start'] if 'start' in request.params else 0
            stop = request.params['stop'] if 'stop' in request.params else 25

            limit = int(stop) - int(start)

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

            rs = anc.get_list(int(start), int(limit))

            rows = []
            if rs:
                for r in rs:
                    labor = anc.get_labor_detail(r['pid'], r['gravida'],
                                                 r['hospcode'])
                    prenatal = anc.get_prenatal_detail(r['pid'], r['gravida'],
                                                       r['hospcode'])
                    p = person.get_person_detail(r['pid'], r['hospcode'])

                    bdate = h.to_thai_date(labor['bdate']) if labor else '-'
                    edc = h.to_thai_date(prenatal['edc']) if prenatal else '-'
                    lmp = h.to_thai_date(prenatal['lmp']) if prenatal else '-'

                    obj = {
                        'pid':
                        r['pid'],
                        'cid':
                        r['cid'],
                        'hospcode':
                        r['hospcode'],
                        'gravida':
                        r['gravida'],
                        'fullname':
                        p['name'] + '  ' + p['lname'],
                        'cid':
                        p['cid'],
                        'birth':
                        h.to_thai_date(p['birth']),
                        'age':
                        h.count_age(
                            p['birth'],
                            anc.get_first_anc(p['pid'], r['gravida'],
                                              r['hospcode'])),
                        'first_visit':
                        h.to_thai_date(
                            anc.get_first_anc(p['pid'], r['gravida'],
                                              r['hospcode'])),
                        'last_visit':
                        h.to_thai_date(
                            anc.get_last_anc(p['pid'], r['gravida'],
                                             r['hospcode'])),
                        'bdate':
                        bdate,
                        'edc':
                        edc,
                        'lmp':
                        lmp,
                        'anc_count':
                        anc.get_anc_count(r['pid'], r['hospcode'],
                                          r['gravida']),
                        'is_survey':
                        anc.get_survey_status(r['pid'], r['gravida'],
                                              r['hospcode']),
                    }
                    rows.append(obj)

                return {'ok': 1, 'rows': rows}
            else:
                return {'ok': 0, 'msg': u'ไม่พบข้อมูล'}
        else:
            return {'ok': 0, 'msg': 'Not ajax request.'}
예제 #47
0
파일: mch.py 프로젝트: siteslave/iCare
def get_list(request):
    if 'logged' not in request.session:
        return {'ok': 0, 'msg': 'Please login.'}
    else:
        if request.is_xhr:  # is ajax request
            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.'}
예제 #48
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
예제 #49
0
파일: epidem.py 프로젝트: siteslave/iCare
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.'}
예제 #50
0
파일: epidem.py 프로젝트: siteslave/iCare
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.'}
예제 #51
0
파일: anc.py 프로젝트: siteslave/iCare
def search(request):

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

            csrf_token = request.params['csrf_token']
            is_token = (csrf_token == unicode(
                request.session.get_csrf_token()))

            if is_token:

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

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

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

                rows = []
                if rs:
                    for r in rs:
                        labor = anc.get_labor_detail(
                            r['pid'], r['gravida'],
                            request.session['hospcode'])
                        prenatal = anc.get_prenatal_detail(
                            r['pid'], r['gravida'],
                            request.session['hospcode'])
                        p = person.get_person_detail(
                            r['pid'], request.session['hospcode'])

                        bdate = h.to_thai_date(
                            labor['bdate']) if labor else '-'
                        edc = h.to_thai_date(
                            prenatal['edc']) if prenatal else '-'
                        lmp = h.to_thai_date(
                            prenatal['lmp']) if prenatal else '-'

                        obj = {
                            'pid':
                            r['pid'],
                            'cid':
                            r['cid'],
                            'hospcode':
                            r['hospcode'],
                            'gravida':
                            r['gravida'],
                            'fullname':
                            p['name'] + '  ' + p['lname'],
                            'cid':
                            p['cid'],
                            'birth':
                            h.to_thai_date(p['birth']),
                            'age':
                            h.count_age(p['birth']),
                            'first_visit':
                            h.to_thai_date(
                                anc.get_first_anc(p['pid'], r['gravida'],
                                                  r['hospcode'])),
                            'last_visit':
                            h.to_thai_date(
                                anc.get_last_anc(p['pid'], r['gravida'],
                                                 r['hospcode'])),
                            'bdate':
                            bdate,
                            'edc':
                            edc,
                            'lmp':
                            lmp,
                            'is_survey':
                            anc.get_survey_status(r['pid'], r['gravida'],
                                                  r['hospcode']),
                            'anc_count':
                            anc.get_anc_count(r['pid'], r['hospcode'],
                                              r['gravida'])
                        }
                        rows.append(obj)

                    return {'ok': 1, 'rows': rows}
                else:
                    return {'ok': 0, 'msg': u'ไม่พบข้อมูล'}
            else:
                return {'ok': 0, 'msg': 'Not authorized.'}
        else:
            return {'ok': 0, 'msg': 'Not ajax.'}
예제 #52
0
파일: epidem.py 프로젝트: siteslave/iCare
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.'}