def insert_mid_prescription_detail(pres_details): message = {} pres_detail_lists = [] session = get_local_session()[1] logging.info("插入中间表==>处方明细表:") for pres_detail in pres_details: detail_info = PresDetails(pres_num=pres_detail['pres_num'], goods_num=pres_detail['goods_num'], medicines=pres_detail['medicines'], dose=pres_detail['dose'], unit=pres_detail['unit'], m_usage=pres_detail['m_usage'], goods_norms=pres_detail['goods_norms'], goods_orgin=pres_detail['goods_orgin'], remark=pres_detail['remark'], dose_that=pres_detail['dose_that'], unit_price=pres_detail.get('unit_price'), MedPerDay=pres_detail.get('MedPerDay'), MedPerDos=pres_detail.get('MedPerDos')) pres_detail_lists.append(detail_info) session.add_all(pres_detail_lists) try: session.commit() logging.info("处方详情插入中间处方明细表成功!") message['status'] = 'success' except SQLAlchemyError as e: session.rollback() logging.info("处方详情插入中间处方明细表失败!") message['status'] = 'fail' logging.info(e) session.close() return message
def insert_mid_prescription(prescription): message = {} session = get_local_session()[1] logging.info("插入中间表==>处方表:") prescription_info = Prescription( pres_num=prescription['pres_num'], pres_time=prescription['pres_time'], treat_card=prescription['treat_card'], reg_num=prescription['reg_num'], province=prescription['province'], city=prescription['city'], zone=prescription['zone'], addr_detail=prescription['addr_detail'], consignee=prescription['consignee'], con_tel=prescription['con_tel'], send_goods_time=prescription['send_goods_time'], user_name=prescription['user_name'], age=prescription['age'], gender=prescription['gender'], tel=prescription['tel'], is_suffering=prescription['is_suffering'], amount=prescription['amount'], suffering_num=prescription['suffering_num'], ji_fried=prescription['ji_fried'], per_pack_num=prescription['per_pack_num'], per_pack_dose=prescription['per_pack_dose'], type=prescription['type'], is_within=prescription['is_within'], other_pres_num=prescription.get('other_pres_num', prescription['pres_num']), special_instru=prescription['special_instru'], bed_num=prescription.get('bed_num'), hos_depart=prescription.get('hos_depart'), hospital_num=prescription.get('hospital_num'), disease_code=prescription.get('disease_code'), doctor=prescription['doctor'], prescript_remark=prescription['prescript_remark'], is_hos_addr=prescription['is_hos_addr'], medication_methods=prescription['medication_methods'], medication_instruction=prescription['medication_instruction'], source=prescription['source']) session.add(prescription_info) try: session.commit() message['status'] = 'success' logging.info("处方表成功插入中间表!") except SQLAlchemyError as e: session.rollback() logging.info("处方表插入中间表失败!") message['status'] = 'fail' logging.info(e) session.close() return message
def find_prescription_details(pres): session = get_local_session()[1] logging.info("从中间表查询处方详情:") pres_detail_query = session.query(PresDetails).filter( PresDetails.pres_num == pres.pres_num) sql = str( pres_detail_query.statement.compile( dialect=mysql.dialect(), compile_kwargs={"literal_binds": True})) logging.info('==> executing:%s' % sql) pres_detail_res = pres_detail_query.all() logging.info("==> Parameters:%s" % pres_detail_res) session.close() return pres_detail_res
def update_consignee_status(pres_num): message = {} session = get_local_session()[1] logging.info("更新写入中间表状态:") is_write_mid_update = session.query(Consignee).filter( Consignee.pres_num == pres_num).update({'is_write_mid': 1}) logging.info("==> Parameters:影响行:%s" % is_write_mid_update) try: session.commit() logging.info('写入中间表状态更新成功!') message['status'] = 'success' except SQLAlchemyError as e: session.rollback() logging.info('写入中间表状态更新失败!') message['status'] = 'fail' logging.info(e) session.close() return message
def get_pres_addr(pres_num): session = get_local_session()[1] pres_addr_info = session.query(Consignee).filter( Consignee.pres_num == pres_num).all() session.close() return pres_addr_info
def get_addr(custom_num): session = get_local_session()[1] addr_lists = session.query(Address).filter( Address.custom_num == custom_num).order_by(Address.addr_id).all() session.close() return addr_lists
def list_pres(request): upload_status = request.POST.get('upload_status') pres_num = request.POST.get('pres_num') order_id = request.POST.get('order_id') user_name = request.POST.get('user_name') doctor = request.POST.get('doctor') start_time = request.POST.get('start_time') end_time = request.POST.get('end_time') page = request.POST.get('page', 1) param = [] session = get_local_session()[1] if pres_num: param.append(Prescription.pres_num == pres_num) if order_id: param.append(Prescription.order_id == order_id) if user_name: param.append(Prescription.user_name == user_name) if doctor: param.append(Prescription.doctor == doctor) if start_time: param.append(Prescription.pres_time >= start_time) if end_time: param.append(Prescription.pres_time <= end_time) if upload_status: param.append(Prescription.upload_status == upload_status) for item in param: logging.info(item) if len(param) == 1 and upload_status == 'all': prescription_query = session.query(Prescription) else: prescription_query = session.query(Prescription).filter(*param) sql = str( prescription_query.statement.compile( dialect=mysql.dialect(), compile_kwargs={"literal_binds": True})) logging.info('==> executing:%s' % sql) prescription_data = prescription_query.all() logging.info("==> Parameters:%s" % prescription_data) ''' paginator = Paginator(prescription_data, 10) print(paginator) pag_num = paginator.num_pages # 获取总页数 print(pag_num) total_rows = paginator.count # 获取总的记录数 print(total_rows) current_page_num = int(page) # 当前页数 current_page = paginator.page(current_page_num) # 获取当前页的数据 print(current_page) pag_range = [] if pag_num < 11: pag_range = list(paginator.page_range) # 页数小于11,获取页码列表 elif pag_num > 11: if current_page_num < 6: pag_range = list(range(1, 11)) # 当前页码小于6,设置页码列表为1-10 ` elif current_page_num > pag_num - 5: pag_range = list(range(pag_num - 9, pag_num + 1)) else: pag_range = list(range(current_page_num - 5, current_page_num + 5)) # 当前页码+5大于最大页数时 ''' print(prescription_data[0]) paginator = Pagination(page, prescription_data) print(paginator) pag_num = paginator.all_pager # 获取总页数 print(pag_num) total_rows = paginator.all_count # 获取总的记录数 print(total_rows) print(paginator.page_html()) page_data = prescription_data[paginator.start:paginator.end] msgs = [] for msg in page_data: msgs.append(msg.to_json()) msgs.append({ 'current_page_num': page, 'total_rows': total_rows, 'page_html': paginator.page_html() }) print(msgs) return HttpResponse(json.dumps(msgs, cls=DateEncoder, ensure_ascii=False), content_type='application/json')
from hospital_test.models import Consignee, Address, Prescription, init_db, \ mysql_connect, save_custom_addr, del_custom_addr, save_pres_addr, get_local_session, update_addr_state, \ update_address from hospital_test.pagination import Pagination # Create your views here. log_path = './log' log_name = log_path + '//' + time.strftime('%Y%m%d', time.localtime()) + '.log' logging.basicConfig( level=logging.DEBUG, filename=log_name, format="%(asctime)s %(name)s:%(levelname)s:%(module)s:%(funcName)s:" "%(processName)s:%(process)d:%(message)s") logging.getLogger(__name__).setLevel(logging.DEBUG) es = get_local_session() init_db(es[0]) def entry_addr(request): pres_num = request.GET['pres_num'] custom_num = request.GET['custom_num'] if pres_num.split('_')[0] == 'MZ': sql = "select p.treat_card,p.username,p.tel from MZ_hosp_prescriptions_view p " \ "where p.pres_num ='"+pres_num+"'and p.treat_card ='"+custom_num+"';" else: sql = "select p.treat_card,p.username,p.tel from ZY_hosp_prescriptions_view p " \ "where p.pres_num ='"+pres_num+"'and p.treat_card ='"+custom_num+"';" result = mysql_connect(sql) context = dict(zip(sql_to_dict(sql), list(result[0]))) context['pres_num'] = pres_num