|
|
|
|
#!/usr/bin/env python
|
|
|
|
|
# -*- encoding: utf-8 -*-
|
|
|
|
|
'''
|
|
|
|
|
@Date: 2022/12/14 15:17:57
|
|
|
|
|
'''
|
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
sys.path.append('.')
|
|
|
|
|
|
|
|
|
|
import json
|
|
|
|
|
from flask import Blueprint, request, jsonify, g
|
|
|
|
|
from sqlalchemy import and_, or_
|
|
|
|
|
from db_logic.user_temporary_auth import BllUserTemporaryAuth
|
|
|
|
|
from db_logic.user_apply import BllUserApply
|
|
|
|
|
from db_logic.medicament import BllMedicament
|
|
|
|
|
from db_logic.client import BllClient
|
|
|
|
|
from db_logic.user import BllUser
|
|
|
|
|
from models.client_models import EntityClient
|
|
|
|
|
from models.medicament_models import EntityMedicament
|
|
|
|
|
from models.power_models import EntityUserApply, EntityUserTemporaryAuth
|
|
|
|
|
from Common.Utils import Utils, PageParam
|
|
|
|
|
from Common.auth import token_auth
|
|
|
|
|
from Common.Utils import DooropenUser
|
|
|
|
|
|
|
|
|
|
temporary_bp = Blueprint("temporary_auth", __name__)
|
|
|
|
|
|
|
|
|
|
temp_list=['乌头碱','次乌头碱','新乌头碱','苯甲酰新乌头原碱','苯甲酰乌头原碱','苯甲酰次乌头原碱','盐酸麻黄碱','盐酸伪麻黄碱'
|
|
|
|
|
,'黄曲霉毒素B1溶液标准品','黄曲霉毒素B2溶液标准品','黄曲霉毒素G1溶液标准品','黄曲霉毒素混合对照品','黄曲霉毒素G2溶液标准品'
|
|
|
|
|
,'麻黄(草麻黄)','咖啡因','咖啡因(熔点用)'
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 获取试剂分组列表
|
|
|
|
|
@temporary_bp.route("/get_drug_group_list", methods=["POST"])
|
|
|
|
|
def get_use_drug_list():
|
|
|
|
|
client_id = request.values.get("client_id")
|
|
|
|
|
seach_word = request.values.get("seach_word")
|
|
|
|
|
page = request.values.get("page")
|
|
|
|
|
page_size = request.values.get("page_size")
|
|
|
|
|
page_param = PageParam(int(page), int(page_size))
|
|
|
|
|
data = BllMedicament().use_drug_info_list(client_id=client_id, seach_word=seach_word, page_param=page_param)
|
|
|
|
|
data_list = Utils.msyql_table_model(data_list=data)
|
|
|
|
|
return jsonify(Utils.true_return(data={"data_list": data_list, "total_count": page_param.totalRecords}))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 创建申请记录
|
|
|
|
|
@temporary_bp.route("/add", methods=["POST"])
|
|
|
|
|
@token_auth.login_required
|
|
|
|
|
def user_apply_log():
|
|
|
|
|
# user_id = request.values.get("user_id")
|
|
|
|
|
user_id_pt = request.values.get("user_id_pt")
|
|
|
|
|
func_type = request.values.get("func_type")
|
|
|
|
|
use_doc = request.values.get("use_doc")
|
|
|
|
|
use_content = request.values.get("use_content")
|
|
|
|
|
tag =0
|
|
|
|
|
|
|
|
|
|
# drug_name = request.values.get("drug_name")
|
|
|
|
|
# drug_num = request.values.get("drug_num")
|
|
|
|
|
# client_id = request.values.get("client_id")
|
|
|
|
|
# try:
|
|
|
|
|
# client_code = BllClient().findEntity(EntityClient.client_id==client_id).client_code
|
|
|
|
|
# except:
|
|
|
|
|
# client_code = ''
|
|
|
|
|
if not use_content:
|
|
|
|
|
return jsonify(Utils.false_return(msg='内容为空,无需提交'))
|
|
|
|
|
else:
|
|
|
|
|
data_obj= json.loads(use_content)
|
|
|
|
|
for i in data_obj:
|
|
|
|
|
if i["name"] in temp_list:
|
|
|
|
|
tag=1
|
|
|
|
|
print(i["client_id"])
|
|
|
|
|
client_obj =BllClient().findEntity(EntityClient.client_id ==i["client_id"])
|
|
|
|
|
print(client_obj,'11223')
|
|
|
|
|
if client_obj:
|
|
|
|
|
i["client_name"]=client_obj.client_name
|
|
|
|
|
else:
|
|
|
|
|
i["client_name"]=''
|
|
|
|
|
use_content =json.dumps(data_obj)
|
|
|
|
|
solve_user_id_sh ="-"
|
|
|
|
|
if tag ==1:
|
|
|
|
|
solve_user_id_sh = ''
|
|
|
|
|
obj = EntityUserApply(
|
|
|
|
|
user_id=g.current_user.user_id,
|
|
|
|
|
user_id_pt=user_id_pt,
|
|
|
|
|
# drug_name = drug_name,
|
|
|
|
|
# drug_num = drug_num,
|
|
|
|
|
create_date=Utils.get_str_datetime(),
|
|
|
|
|
is_solve=0,
|
|
|
|
|
solve_user_id_sh=solve_user_id_sh,
|
|
|
|
|
use_content=use_content,
|
|
|
|
|
# client_id = client_id,
|
|
|
|
|
func_type=func_type,
|
|
|
|
|
# client_code=client_code,
|
|
|
|
|
use_doc=use_doc
|
|
|
|
|
)
|
|
|
|
|
BllUserApply().insert(obj)
|
|
|
|
|
return jsonify(Utils.true_return())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 修改个人申请
|
|
|
|
|
@temporary_bp.route("/update_itself_apply", methods=["POST"])
|
|
|
|
|
@token_auth.login_required
|
|
|
|
|
def update_itself_apply():
|
|
|
|
|
apply_id = request.values.get("id")
|
|
|
|
|
# func_type = request.values.get("func_type")
|
|
|
|
|
use_content = request.values.get("use_content")
|
|
|
|
|
if not use_content:
|
|
|
|
|
return jsonify(Utils.false_return(msg='内容为空,无需提交'))
|
|
|
|
|
user = g.current_user
|
|
|
|
|
user_apply_obj = BllUserApply().findEntity(
|
|
|
|
|
and_(
|
|
|
|
|
EntityUserApply.id == apply_id,
|
|
|
|
|
EntityUserApply.user_id == user.user_id
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
if not user_apply_obj:
|
|
|
|
|
return jsonify(Utils.false_return(msg="只能修改自己的申请!"))
|
|
|
|
|
user_apply_obj.use_content = use_content
|
|
|
|
|
BllUserApply().update(user_apply_obj)
|
|
|
|
|
return jsonify(Utils.true_return())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 展示
|
|
|
|
|
@temporary_bp.route("/get_list", methods=["POST"])
|
|
|
|
|
# @token_auth.login_required
|
|
|
|
|
@token_auth.login_required
|
|
|
|
|
def get_info_list():
|
|
|
|
|
# client_id = request.values.get("client_id")
|
|
|
|
|
func_type = request.values.get("func_type")
|
|
|
|
|
page = request.values.get("page")
|
|
|
|
|
page_size = request.values.get("page_size")
|
|
|
|
|
user = g.current_user
|
|
|
|
|
page_param = PageParam(int(page), int(page_size))
|
|
|
|
|
data = BllUserApply().get_list_info(func_type=func_type, page_param=page_param, user=user)
|
|
|
|
|
user_list = BllUser().findList()
|
|
|
|
|
user_dict = {}
|
|
|
|
|
for i in user_list:
|
|
|
|
|
user_dict[i.user_id] = i.real_name
|
|
|
|
|
data_list = []
|
|
|
|
|
for i in data:
|
|
|
|
|
i_dict = dict(i._mapping)
|
|
|
|
|
# i_dict = dict(zip(i.keys(), [(x if x is not None else '') for x in i.values()]))
|
|
|
|
|
i_dict['user_name'] = user_dict.get(i_dict["user_id"])
|
|
|
|
|
i_dict["user_name_pt"] = user_dict.get(i_dict["user_id_pt"])
|
|
|
|
|
i_dict["solve_user_name"] = user_dict.get(i_dict["solve_user_id"], '')
|
|
|
|
|
i_dict["solve_user_pt_name"] = user_dict.get(i_dict["solve_user_id_pt"], '')
|
|
|
|
|
i_dict["solve_user_sh_name"] = user_dict.get(i_dict["solve_user_id_sh"], '')
|
|
|
|
|
if i_dict["solve_user_id_sh"] =='-':
|
|
|
|
|
i_dict["solve_user_sh_name"]='-'
|
|
|
|
|
data_list.append(i_dict)
|
|
|
|
|
return jsonify(Utils.true_return(data={"data_list": data_list, "total_count": page_param.totalRecords}))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 删除
|
|
|
|
|
@temporary_bp.route("/del", methods=["POST"])
|
|
|
|
|
@token_auth.login_required
|
|
|
|
|
def del_user_apply():
|
|
|
|
|
user_json = request.values.get("user_ids")
|
|
|
|
|
user_id_list = user_json.split(",")
|
|
|
|
|
for i in user_id_list:
|
|
|
|
|
BllUserApply().delete(EntityUserApply.id == i)
|
|
|
|
|
return jsonify(Utils.true_return())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 处理消息
|
|
|
|
|
@temporary_bp.route("/update_solve", methods=["POST"])
|
|
|
|
|
@token_auth.login_required
|
|
|
|
|
def solve_apply():
|
|
|
|
|
apply_id = request.values.get("id")
|
|
|
|
|
# user_id = request.values.get("user_id")
|
|
|
|
|
user_id = g.current_user.user_id
|
|
|
|
|
# user_id_pt = request.values.get("user_id_pt")
|
|
|
|
|
t = request.values.get("t")
|
|
|
|
|
obj = BllUserApply().findEntity(EntityUserApply.id == apply_id)
|
|
|
|
|
if obj.is_solve == 1 or obj.is_solve == 2:
|
|
|
|
|
msg = "驳回" if obj.is_solve == 2 else "受理"
|
|
|
|
|
return jsonify(Utils.false_return(msg=f"已{msg},无需重复处理"))
|
|
|
|
|
if user_id == obj.user_id:
|
|
|
|
|
return jsonify(Utils.false_return(msg="申请人与审批人不能为同一人"))
|
|
|
|
|
if user_id in [obj.solve_user_id_sh, obj.solve_user_id, obj.solve_user_id_sh]:
|
|
|
|
|
return jsonify(Utils.false_return(msg="不能为同一人审批"))
|
|
|
|
|
|
|
|
|
|
if not obj.solve_user_id_sh:
|
|
|
|
|
obj.solve_user_id_sh = user_id
|
|
|
|
|
elif not obj.solve_user_id:
|
|
|
|
|
obj.solve_user_id = user_id
|
|
|
|
|
else:
|
|
|
|
|
obj.solve_user_id_pt = user_id
|
|
|
|
|
|
|
|
|
|
if str(request.values.get('result')) == "0":
|
|
|
|
|
obj.information = request.values.get("information")
|
|
|
|
|
obj.is_solve = 2
|
|
|
|
|
else:
|
|
|
|
|
if obj.solve_user_id_pt:
|
|
|
|
|
obj.is_solve = 1
|
|
|
|
|
obj.time_hour = t
|
|
|
|
|
BllUserTemporaryAuth().create_temporary_auth(user_ids=[obj.user_id, obj.user_id_pt], auth_type=2, t=t)
|
|
|
|
|
obj.solve_date = Utils.get_str_datetime()
|
|
|
|
|
BllUserApply().update(obj)
|
|
|
|
|
return jsonify(Utils.true_return())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 展示待登记列表
|
|
|
|
|
@temporary_bp.route("/register_drug_list", methods=["GET", "POST"])
|
|
|
|
|
@token_auth.login_required
|
|
|
|
|
def get_register_drug():
|
|
|
|
|
page = request.values.get("page")
|
|
|
|
|
page_size = request.values.get("page_size")
|
|
|
|
|
page_param = PageParam(int(page), int(page_size))
|
|
|
|
|
data = BllMedicament().get_register_list(user=g.current_user, page_param=page_param)
|
|
|
|
|
return jsonify(
|
|
|
|
|
Utils.true_return(data={"data_list": Utils.msyql_table_model(data), "total_count": page_param.totalRecords}))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 登记接口
|
|
|
|
|
@temporary_bp.route("/set_register", methods=["POST"])
|
|
|
|
|
@token_auth.login_required
|
|
|
|
|
def set_register():
|
|
|
|
|
bar_code = request.values.get("bar_code")
|
|
|
|
|
is_empty = request.values.get("is_empty",0)
|
|
|
|
|
print(bar_code,'1111111111111111111111111111')
|
|
|
|
|
bar_code, new_code = Utils.get_bar_code_reverse(bar_code)
|
|
|
|
|
obj = BllMedicament().findEntity(
|
|
|
|
|
or_(
|
|
|
|
|
EntityMedicament.bar_code == bar_code,
|
|
|
|
|
EntityMedicament.bar_code == new_code
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
if not obj:
|
|
|
|
|
return jsonify(Utils.false_return())
|
|
|
|
|
|
|
|
|
|
# drug_id = request.values.get("medicament_id")
|
|
|
|
|
remain = request.values.get("remain")
|
|
|
|
|
# obj = BllMedicament().findEntity(EntityMedicament.medicament_id==drug_id)
|
|
|
|
|
if obj:
|
|
|
|
|
# 开瓶日期
|
|
|
|
|
if not obj.remark13:
|
|
|
|
|
setattr(obj, "remark13", Utils.get_str_datetime())
|
|
|
|
|
setattr(obj, "remain", remain)
|
|
|
|
|
# print(is_empty==0,'777777777777777777777777')
|
|
|
|
|
if int(is_empty) ==0:
|
|
|
|
|
setattr(obj, "status", 2)
|
|
|
|
|
else:
|
|
|
|
|
setattr(obj, "status", 3)
|
|
|
|
|
BllMedicament().update(obj)
|
|
|
|
|
# 登记
|
|
|
|
|
BllUserApply().update_use_content(client_id=obj.client_id, user=g.current_user, drug_info=obj)
|
|
|
|
|
|
|
|
|
|
BllMedicament().drugRegister(
|
|
|
|
|
entityDrug=obj,
|
|
|
|
|
entityClient=BllClient().findEntity(EntityClient.client_id == obj.client_id),
|
|
|
|
|
entityUser=g.current_user
|
|
|
|
|
)
|
|
|
|
|
# 试剂有效期更改
|
|
|
|
|
BllMedicament().update_expiration_date(obj)
|
|
|
|
|
return jsonify(Utils.true_return())
|
|
|
|
|
else:
|
|
|
|
|
return jsonify(Utils.false_return())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 获取待领用试剂列表
|
|
|
|
|
@temporary_bp.route("/get_stay_use_list", methods=["GET", "POST"])
|
|
|
|
|
def get_stay_use_list():
|
|
|
|
|
client_id = request.values.get("client_id")
|
|
|
|
|
data_list = BllUserApply().get_stay_use_list(client_id=client_id, user_id=DooropenUser.user_id)
|
|
|
|
|
return jsonify(Utils.true_return(data=data_list))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@temporary_bp.route("/get_check_last_drug", methods=["GET", "POST"])
|
|
|
|
|
@token_auth.login_required
|
|
|
|
|
def get_check_last_drug():
|
|
|
|
|
"""
|
|
|
|
|
检查获取是否为最早入库试剂,先进先出
|
|
|
|
|
:return {"is_last": True, "medicament": 最早入库试剂信息} True:不存在更早试剂 False:存在更早试剂
|
|
|
|
|
"""
|
|
|
|
|
medicament_id = request.values.get("medicament_id")
|
|
|
|
|
func_type = request.values.get("func_type")
|
|
|
|
|
drug_name = request.values.get("name")
|
|
|
|
|
put_in_date = request.values.get("put_in_date")
|
|
|
|
|
client_id = request.values.get("client_id")
|
|
|
|
|
medicament_obj = BllMedicament().get_last_drug(client_id=client_id, drug_name=drug_name,
|
|
|
|
|
put_in_date=put_in_date, func_type=func_type)
|
|
|
|
|
if not medicament_obj:
|
|
|
|
|
return jsonify(Utils.except_return(msg="未查询到相关信息", data={"is_last": True}))
|
|
|
|
|
|
|
|
|
|
# True: 当前选择试剂为最早入库试剂
|
|
|
|
|
# False: 当前选择试剂不是最早入库试剂
|
|
|
|
|
data = {
|
|
|
|
|
"is_last": True if medicament_obj.medicament_id == medicament_id else False,
|
|
|
|
|
"medicament": dict(medicament_obj._mapping)
|
|
|
|
|
}
|
|
|
|
|
return jsonify(Utils.true_return(data=data))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 添加未领用说明
|
|
|
|
|
@temporary_bp.route("/update_notes", methods=["POST"])
|
|
|
|
|
def update_notes():
|
|
|
|
|
apply_id = request.values.get("id")
|
|
|
|
|
bar_code = request.values.get("bar_code")
|
|
|
|
|
info = request.values.get("info")
|
|
|
|
|
obj = BllUserApply().findEntity(EntityUserApply.id == apply_id)
|
|
|
|
|
if obj:
|
|
|
|
|
data_obj =json.loads(obj.use_content)
|
|
|
|
|
for i in data_obj:
|
|
|
|
|
if i["bar_code"] ==bar_code:
|
|
|
|
|
print('5555')
|
|
|
|
|
i["info"] =info
|
|
|
|
|
obj.use_content =json.dumps(data_obj)
|
|
|
|
|
BllUserApply().update(obj)
|
|
|
|
|
return jsonify(Utils.true_return(data=obj))
|