Beispiel #1
0
def parse_hospital_list(response):
    global code_department_map
    global code_name_map
    if api.is_success_response(response):
        data = response['data']
        if isinstance(data, dict):
            if 'list' in data:
                data_list = data['list']
                if isinstance(data_list, list):
                    for item in data_list:
                        code = None
                        if 'hosCode' in item:
                            code = item['hosCode']
                            code_name_map[code] = item['hosName']
                        elif 'code' in item:
                            code = item['code']
                            code_name_map[code] = item['name']
                        if 'depts' in item:
                            departments = item['depts']
                            if isinstance(departments, list):
                                for dep in departments:
                                    code_department_map[code] = dep
                                    break
    else:
        return False
    return True
Beispiel #2
0
def save_order(code, department, date, key, sms_code='', duty_time='0'):
    card = g_patient_info['cardList'][0]
    post_content_map = {
        'hosCode': code,
        'firstDeptCode': department['firstDeptCode'],
        'secondDeptCode': department['secondDeptCode'],
        'treatmentDay': date,
        'uniqProductKey': key,
        'cardType': card['cardType'],
        'cardNo': card['cardNo'],
        'smsCode': sms_code,
        'jytCardId': '',
        'hospitalCardId': '',
        'phone': g_patient_info['phone'],
        'dutyTime': duty_time,
    }
    if g_topic_key is not None and len(str(g_topic_key).split('-')) > 1:
        post_content_map['orderFrom'] = str(g_topic_key).split('-')[1]

    post_content = bytes(json.dumps(post_content_map), encoding='utf-8')
    resp = api.api_call(api_config.API_114_ORDER_SAVE, post_data=post_content)
    if api.is_success_response(resp):
        data = resp['data']
        if isinstance(data, dict) and 'orderNo' in data:
            order_no = data['orderNo']
            print(f'预约成功,订单号 {order_no}')
            order_detail(code, order_no)
    else:
        msg = resp['msg']
        notification_util.show_notification('预约失败', msg)
        print(f'提交预约单失败 : {msg}')
Beispiel #3
0
def parse_department_day_duty_info(hospital, duty_info):
    if api.is_success_response(duty_info):
        data = duty_info['data']
        if isinstance(data, list):
            for item in data:
                duty_code = None
                if 'dutyCode' in item:
                    duty_code = item['dutyCode']
                if 'detail' in item and isinstance(item['detail'], list):
                    for detail_item in item['detail']:
                        if isinstance(detail_item, dict):
                            if 'fcode' in detail_item and 'ncode' in detail_item:
                                fcode = detail_item['fcode']
                                ncode = detail_item['ncode']
                                if fcode != ncode:
                                    if str(fcode).endswith(str(ncode)):
                                        print(
                                            f'{hospital} {duty_code} fcode endwith ncode'
                                        )
                                        continue
                                    # 医生头衔 普通医生或专家
                                    doctor_title_name = detail_item[
                                        'doctorTitleName']
                                    # key 上午下午不一样
                                    # unique_product_key = detail_item['uniqProductKey']
                                    if 'MORNING' == duty_code:
                                        print(
                                            f'{hospital} 上午 {doctor_title_name} 可预约'
                                        )
                                    elif 'AFTERNOON' == duty_code:
                                        print(
                                            f'{hospital} 下午 {doctor_title_name} 可预约'
                                        )
                                    return detail_item
    return None
Beispiel #4
0
def order_detail(code, order_no):
    query = {
        'orderNo': order_no,
        'hosCode': code,
    }
    resp = api.api_call(api_config.API_114_ORDER_DETAIL, query)
    if api.is_success_response(resp):
        print(resp)
Beispiel #5
0
def check_save_order(code, department, date, key, sms_code='', duty_time='0'):
    if len(g_patient_info) == 0 or g_patient_info['cardList'] is None or len(
            g_patient_info['cardList']) == 0:
        print('无就诊卡相关信息')
        return False
    card = g_patient_info['cardList'][0]
    post_content_map = {
        'hosCode': code,
        'firstDeptCode': department['firstDeptCode'],
        'secondDeptCode': department['secondDeptCode'],
        'treatmentDay': date,
        'uniqProductKey': key,
        'cardType': card['cardType'],
        'cardNo': card['cardNo'],
        'smsCode': sms_code,
        'jytCardId': '',
        'hospitalCardId': '',
        'phone': g_patient_info['phone'],
        'dutyTime': duty_time
    }
    post_content = bytes(json.dumps(post_content_map), encoding='utf-8')
    resp = api.api_call(api_config.API_114_ORDER_SAVE_CHECK,
                        post_data=post_content)
    if api.is_success_response(resp):
        data = resp['data']
        if isinstance(data, dict):
            if 'state' in data:
                state = data['state']
                if state == 'OK' or state == 'NEED_CONFIRM':
                    save_order(code, department, date, key, sms_code,
                               duty_time)
                    return True
                elif state == 'TOAST':
                    msg = data['msg']
                    if '请重新选择就诊时段' == msg:
                        print('需要重新选择就诊时段')
                        resp = get_department_day_duty_detail(
                            date, g_topic_key, code, department)
                        duty_detail = parse_department_day_duty_info(
                            code_name_map[code], resp)
                        if 'period' in duty_detail:
                            period = duty_detail['period']
                            if isinstance(period, dict):
                                period_duty_time = period['dutyTime']
                                print(f'新的就诊时段 {period_duty_time}')
                                check_save_order(code, department, date, key,
                                                 period_duty_time)
                            elif isinstance(period, list):
                                for period_item in period:
                                    period_duty_time = period_item['dutyTime']
                                    print(f'新的就诊时段 {period_duty_time}')
                                    check_save_order(code, department, date,
                                                     key, period_duty_time)
                                    break
Beispiel #6
0
def parse_register_confirm_info(resp, code, date, department, key):
    if api.is_success_response(resp):
        data = resp['data']
        if isinstance(data, dict):
            name = data['hospitalName']
            depart = data['departmentName']
            title = data['doctorTitleName']
            fee = data['serviceFee']
            visit_time = data['visitTime']
            print(f'{visit_time} {name} {depart} {title} {fee}')
            if 'dataItem' in data:
                data_item = data['dataItem']
                if isinstance(data_item, dict):
                    sms_code = data_item['smsCode']
                    if sms_code == NEED_SMS_CODE:
                        print('需要短信验证码')
                        sms_code_resp = get_sms_verify_code(key)
                        if api.is_success_response(sms_code_resp):
                            # 等待验证码
                            notification_util.show_notification(
                                '短信验证码', '请注意查看短信验证码并输入')
                            g_order_save_info['code'] = code
                            g_order_save_info['department'] = department
                            g_order_save_info['date'] = date
                            g_order_save_info['key'] = key
                            handle_sms_code.input_sms_code(
                                submit_sms_code_callback)
                    else:
                        # 不需要短信验证码
                        resp = order_check()
                        if api.is_success_response(resp):
                            data = resp['data']
                            if isinstance(data, dict) and 'pass' in data:
                                result = data['pass']
                                if result or result == 'true':
                                    duty_time = '0'
                                    if 'dutyTime' in g_order_save_info:
                                        duty_time = g_order_save_info[
                                            'dutyTime']
                                    check_save_order(code, department, date,
                                                     key, duty_time)
Beispiel #7
0
def get_hospital_department_list(hos_code):
    global department_name_code_map
    target_department = api.config_dict[DEPARTMENT]
    query = {
        'hosCode': hos_code,
    }
    rsp = api.api_call(api_config.API_114_HOSPITAL_DEPARTMENT_LIST, query)
    if api.is_success_response(rsp):
        rsp_data = rsp['data']
        if isinstance(rsp_data, dict) and 'list' in rsp_data:
            depart_list = rsp_data['list']
            if isinstance(depart_list, list):
                for department_info in depart_list:
                    if isinstance(department_info, dict):
                        department_code = department_info['code']
                        department_name_code_map[
                            department_code] = department_info
    if len(department_name_code_map) > 0:
        for key in department_name_code_map:
            info = department_name_code_map[key]
            dep_name = info['name']
            dep_1_code = info['code']
            dep_2_code = ''
            sub_list = info['subList']
            if isinstance(sub_list, list):
                if len(sub_list) == 1:
                    dep_2_code = sub_list[0]['code']
                for sub in sub_list:
                    sub_name = sub['name']
                    sub_dep_1_code = sub['dept1Code']
                    sub_dep_2_code = sub['code']
                    print(f'{sub_name} {sub_dep_1_code} {sub_dep_2_code}')
                    if len(str(target_department)) > 0 and str(
                            sub_name).__contains__(target_department):
                        if loop == 0:
                            found = check_duty_and_register(
                                hos_code, sub_dep_1_code, sub_dep_2_code)
                            if not found:
                                notification_util.show_notification(
                                    '是否可预约', '暂无可预约的号')
                        else:
                            repeat_timer = timer.RepeatingTimer(
                                loop_query_delay,
                                check_duty_and_register,
                                args=[
                                    hos_code, sub_dep_1_code, sub_dep_2_code
                                ])
                            repeat_timer.start()
                        return True
            print(f'{dep_name} {dep_1_code} {dep_2_code}')
    return False
Beispiel #8
0
def parse_hospital_department_duty_info(code, department, resp, deadline,
                                        available_map):
    if api.is_success_response(resp):
        res_data = resp['data']
        if isinstance(res_data, dict) and 'calendars' in res_data:
            calendars = res_data['calendars']
            if isinstance(calendars, list):
                for day in calendars:
                    if isinstance(day, dict) and 'status' in day:
                        # print(f'{day}')
                        status = day['status']
                        date = day['dutyDate']
                        # 指定就要挂某一天的号时
                        if 'date' in api.config_dict and len(str(api.config_dict['date'])) == 10 and\
                                date != api.config_dict['date']:
                            continue

                        if date > deadline:
                            continue
                        # if status != 'NO_INVENTORY' and
                        # status != 'SOLD_OUT' and status != 'TOMORROW_OPEN':
                        if status == 'AVAILABLE':
                            available_map[code_name_map[code]] = date
                            notification_util.show_notification(
                                '可预约', f'{date} {code_name_map[code]} 可预约')
                            duty_info = get_department_day_duty_detail(
                                date, g_topic_key, code, department)
                            duty_detail = parse_department_day_duty_info(
                                code_name_map[code], duty_info)
                            if duty_detail is not None:
                                duty_time = '0'
                                key = duty_detail['uniqProductKey']
                                if 'period' in duty_detail:
                                    period = duty_detail['period']
                                    if isinstance(period, dict):
                                        duty_time = period['dutyTime']
                                        print(f'dict 就诊时段 {duty_time}')
                                    elif isinstance(period, list):
                                        for period_item in period:
                                            duty_time = period_item['dutyTime']
                                            print(f'list 就诊时段 {duty_time}')
                                            break
                                g_order_save_info['dutyTime'] = duty_time
                                confirm_resp = register_confirm(
                                    key, date, g_topic_key, code, department,
                                    duty_time)
                                parse_register_confirm_info(
                                    confirm_resp, code, date, department, key)
                                return True
    return False
Beispiel #9
0
def get_patient_list():
    global g_patient_info
    resp = api.api_call(api_config.API_114_PATIENT_LIST)
    if api.is_success_response(resp):
        data = resp['data']
        if isinstance(data, dict):
            count = data['count']
            if count == 0:
                print('需要添加就诊卡信息')
                return None
            patient_list = data['list']
            if isinstance(patient_list, list):
                for patient in patient_list:
                    if isinstance(patient, dict):
                        if patient['patientName'] == api.config_dict['name']:
                            card_list = patient['cardList']
                            if isinstance(card_list, list):
                                for card in card_list:
                                    card_type = card['cardTypeView']
                                    card_no = card['cardNo']
                                    print(f'{card_type} {card_no}')
                            g_patient_info = patient
                            return patient
Beispiel #10
0
    api.load_config_info()
    if LOOP_QUERY_DELAY in api.config_dict:
        loop_query_delay = api.config_dict[LOOP_QUERY_DELAY]
        if len(loop_query_delay) > 0:
            loop_query_delay = int(loop_query_delay)
    deadline = api.config_dict['deadline']
    if LOOP in api.config_dict:
        loop_config = api.config_dict[LOOP]
        if str(loop_config) != '0' and len(str(loop_config)) > 0:
            loop = 1
    register.get_patient_list()
    # 检查是否配置指定医院
    keyword = ''
    if KEYWORD in api.config_dict:
        keyword = api.config_dict[KEYWORD]
        if len(str(keyword)) > 0:
            resp = get_hospital_list(keyword)
            if api.is_success_response(resp):
                register.parse_hospital_list(resp)
                data = resp['data']
                if isinstance(data, dict) and 'list' in data:
                    hos_list = data['list']
                    if isinstance(hos_list, list):
                        for hospital in hos_list:
                            name = hospital['name']
                            code = hospital['code']
                            hospital_code_name_map[code] = name
                            print(hospital)
                            get_hospital_department_list(code)