|
|
@ -15,27 +15,15 @@ from models.medicament_models import EntityMedicament, EntityMedicamentRecord, E
|
|
|
|
from models.client_models import EntityClient
|
|
|
|
from models.client_models import EntityClient
|
|
|
|
from models.user_models import EntityUser
|
|
|
|
from models.user_models import EntityUser
|
|
|
|
from db_logic.meidcament_variety import BllMedicamentVariety
|
|
|
|
from db_logic.meidcament_variety import BllMedicamentVariety
|
|
|
|
from Common.Utils import Utils, DrugStatus, DrugRecordType, PageParam
|
|
|
|
from Common.Utils import Utils, DrugStatus, DrugRecordType
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#药剂流程业务逻辑类
|
|
|
|
#药剂流程业务逻辑类
|
|
|
|
class BllMedicament(Repository):
|
|
|
|
class BllMedicament(Repository):
|
|
|
|
#_instance_lock = threading.Lock()
|
|
|
|
|
|
|
|
##实现单例模式
|
|
|
|
|
|
|
|
#def __new__(cls, *args, **kwargs):
|
|
|
|
|
|
|
|
# if not hasattr(BllMedicament, "_instance"):
|
|
|
|
|
|
|
|
# with BllMedicament._instance_lock:
|
|
|
|
|
|
|
|
# if not hasattr(BllMedicament, "_instance"):
|
|
|
|
|
|
|
|
# BllMedicament._instance = object.__new__(cls)
|
|
|
|
|
|
|
|
# return BllMedicament._instance
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, entityType=EntityMedicament):
|
|
|
|
def __init__(self, entityType=EntityMedicament):
|
|
|
|
return super().__init__(entityType)
|
|
|
|
return super().__init__(entityType)
|
|
|
|
|
|
|
|
|
|
|
|
def sql_paging_assemble(self, sql_all, page_param):
|
|
|
|
|
|
|
|
sql_all += ' limit ' + str((page_param.curPage - 1) * page_param.pageRows) + ',' + str(page_param.pageRows)
|
|
|
|
|
|
|
|
return sql_all
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 获取离保质期最近的同类药剂
|
|
|
|
# 获取离保质期最近的同类药剂
|
|
|
|
def getDrugNearExpired(self, varietyId, customerId):
|
|
|
|
def getDrugNearExpired(self, varietyId, customerId):
|
|
|
@ -67,7 +55,7 @@ class BllMedicament(Repository):
|
|
|
|
# 组装sql
|
|
|
|
# 组装sql
|
|
|
|
sql_all = sql_all % where_base
|
|
|
|
sql_all = sql_all % where_base
|
|
|
|
# 调用分页组装sql
|
|
|
|
# 调用分页组装sql
|
|
|
|
sql_all = self.sql_paging_assemble(sql_all, page_param)
|
|
|
|
sql_all = Utils.sql_paging_assemble(sql_all, page_param)
|
|
|
|
data_list = self.execute(sql_all).fetchall()
|
|
|
|
data_list = self.execute(sql_all).fetchall()
|
|
|
|
# 查询页总数
|
|
|
|
# 查询页总数
|
|
|
|
count_sql = f"SELECT count(*) FROM rms_medicament %s GROUP BY `name`, cas_number, purity" % where_base
|
|
|
|
count_sql = f"SELECT count(*) FROM rms_medicament %s GROUP BY `name`, cas_number, purity" % where_base
|
|
|
@ -126,7 +114,7 @@ class BllMedicament(Repository):
|
|
|
|
where_base = "where" + where_base
|
|
|
|
where_base = "where" + where_base
|
|
|
|
# 组装最终sql
|
|
|
|
# 组装最终sql
|
|
|
|
run_sql = sql_all % ("*", where_base+group_base)
|
|
|
|
run_sql = sql_all % ("*", where_base+group_base)
|
|
|
|
run_sql = self.sql_paging_assemble(run_sql, page_param)
|
|
|
|
run_sql = Utils.sql_paging_assemble(run_sql, page_param)
|
|
|
|
run_sql_data = self.execute(run_sql).fetchall()
|
|
|
|
run_sql_data = self.execute(run_sql).fetchall()
|
|
|
|
page_param.totalRecords = self.execute(
|
|
|
|
page_param.totalRecords = self.execute(
|
|
|
|
sql_all % ("count(*)", where_base + group_base)).fetchone()[0]
|
|
|
|
sql_all % ("count(*)", where_base + group_base)).fetchone()[0]
|
|
|
@ -231,10 +219,7 @@ class BllMedicament(Repository):
|
|
|
|
|
|
|
|
|
|
|
|
count_sql = f"SELECT count(*) FROM rms_medicament where status={status}"
|
|
|
|
count_sql = f"SELECT count(*) FROM rms_medicament where status={status}"
|
|
|
|
page_param.totalRecords = self.execute(count_sql).fetchone()[0]
|
|
|
|
page_param.totalRecords = self.execute(count_sql).fetchone()[0]
|
|
|
|
|
|
|
|
sql_all = Utils.sql_paging_assemble(sql_all, page_param)
|
|
|
|
sql_all += ' limit ' + \
|
|
|
|
|
|
|
|
str((page_param.curPage - 1) * page_param.pageRows) + \
|
|
|
|
|
|
|
|
',' + str(page_param.pageRows)
|
|
|
|
|
|
|
|
data_list = self.execute(sql_all).fetchall()
|
|
|
|
data_list = self.execute(sql_all).fetchall()
|
|
|
|
count_sql = f"SELECT count(*) FROM rms_medicament where status={status}"
|
|
|
|
count_sql = f"SELECT count(*) FROM rms_medicament where status={status}"
|
|
|
|
page_param.totalRecords = self.execute(count_sql).fetchone()[0]
|
|
|
|
page_param.totalRecords = self.execute(count_sql).fetchone()[0]
|
|
|
@ -255,42 +240,49 @@ class BllMedicament(Repository):
|
|
|
|
|
|
|
|
|
|
|
|
filter_base += " GROUP BY `name`, cas_number, net_weight_unit"
|
|
|
|
filter_base += " GROUP BY `name`, cas_number, net_weight_unit"
|
|
|
|
sql_all = sql_all % filter_base
|
|
|
|
sql_all = sql_all % filter_base
|
|
|
|
sql_all = self.sql_paging_assemble(sql_all, page_param)
|
|
|
|
sql_all = Utils.sql_paging_assemble(sql_all, page_param)
|
|
|
|
sql_data = self.execute(sql_all).fetchall()
|
|
|
|
sql_data = self.execute(sql_all).fetchall()
|
|
|
|
|
|
|
|
|
|
|
|
count_sql = f"SELECT count(medicament_id) FROM rms_medicament GROUP BY `name`, cas_number, net_weight_unit "
|
|
|
|
count_sql = f"SELECT count(medicament_id) FROM rms_medicament GROUP BY `name`, cas_number, net_weight_unit "
|
|
|
|
page_param.totalRecords = len(self.execute(count_sql).fetchone())
|
|
|
|
try:
|
|
|
|
|
|
|
|
count_number = len(self.execute(count_sql).fetchall())
|
|
|
|
|
|
|
|
except Exception:
|
|
|
|
|
|
|
|
count_number = 0
|
|
|
|
|
|
|
|
page_param.totalRecords = count_number
|
|
|
|
|
|
|
|
|
|
|
|
return sql_data
|
|
|
|
return sql_data
|
|
|
|
#获取所有药剂列表
|
|
|
|
#获取所有药剂列表
|
|
|
|
def getAllDrugList(self, search_word, page_param, customer_id=None, client_id=None):
|
|
|
|
def getAllDrugList(self, search_word, page_param, customer_id=None, client_id=None):
|
|
|
|
# (Name like :searchWord or BarCode like :searchWord or EnglishName like :searchWord)
|
|
|
|
# (Name like :searchWord or BarCode like :searchWord or EnglishName like :searchWord)
|
|
|
|
sql_all = """
|
|
|
|
sql_all = """
|
|
|
|
select `name`, distributor, net_weight_unit, remain, production_date, expiration_date,
|
|
|
|
select `name`, manufacturer, distributor, net_weight_unit, remain, production_date, expiration_date,
|
|
|
|
shelf_life, put_in_user_name, put_in_date, english_name, purity, is_supervise, by_user_name
|
|
|
|
shelf_life, put_in_user_name, put_in_date, english_name, purity, is_supervise, by_user_name
|
|
|
|
from rms_medicament %s
|
|
|
|
from rms_medicament %s
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
# 动态添加查询条件
|
|
|
|
filter_base = ""
|
|
|
|
filter_base = ""
|
|
|
|
if customer_id:
|
|
|
|
if customer_id:
|
|
|
|
filter_base = f"customer_id='{customer_id}'"
|
|
|
|
filter_base = f"customer_id='{customer_id}'"
|
|
|
|
# filter_base.append(self.entityType.customer_id == customer_id)
|
|
|
|
|
|
|
|
if client_id:
|
|
|
|
if client_id:
|
|
|
|
if filter_base:
|
|
|
|
if filter_base:
|
|
|
|
filter_base += " and "
|
|
|
|
filter_base += " and "
|
|
|
|
filter_base += f"client_id='{client_id}'"
|
|
|
|
filter_base += f"client_id='{client_id}'"
|
|
|
|
# filter_base.append(self.entityType.client_id == client_id)
|
|
|
|
# 模糊搜索
|
|
|
|
if search_word:
|
|
|
|
if search_word:
|
|
|
|
seach_w = f"%{search_word}%"
|
|
|
|
seach_w = f"%{search_word}%"
|
|
|
|
if filter_base:
|
|
|
|
if filter_base:
|
|
|
|
filter_base += " and "
|
|
|
|
filter_base += " and "
|
|
|
|
filter_base += f" `name` like '{seach_w}' or english_name like '{seach_w}' or english_name like '{seach_w}'"
|
|
|
|
filter_base += f" `name` like '{seach_w}' or english_name like '{seach_w}' or manufacturer like '{seach_w}'"
|
|
|
|
if filter_base:
|
|
|
|
if filter_base:
|
|
|
|
filter_base = "where " + filter_base
|
|
|
|
filter_base = "where " + filter_base
|
|
|
|
sql_all = sql_all % filter_base
|
|
|
|
sql_all = sql_all % filter_base
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
count_number= len(self.execute(sql_all).fetchall())
|
|
|
|
|
|
|
|
except Exception:
|
|
|
|
|
|
|
|
count_number = 0
|
|
|
|
|
|
|
|
page_param.totalRecords = count_number
|
|
|
|
|
|
|
|
sql_all = Utils.sql_paging_assemble(sql_all, page_param)
|
|
|
|
data_list = self.execute(sql_all).fetchall()
|
|
|
|
data_list = self.execute(sql_all).fetchall()
|
|
|
|
count_sql = f"SELECT count(medicament_id) FROM rms_medicament"
|
|
|
|
|
|
|
|
page_param.totalRecords = self.execute(count_sql).fetchone()[0]
|
|
|
|
|
|
|
|
data_list = Utils.msyql_table_model(data_list)
|
|
|
|
data_list = Utils.msyql_table_model(data_list)
|
|
|
|
return data_list
|
|
|
|
return data_list
|
|
|
|
|
|
|
|
|
|
|
@ -331,12 +323,37 @@ class BllMedicament(Repository):
|
|
|
|
# EntityMedicament.ByUserId == userId, EntityMedicament.Status == DrugStatus.Out).all()
|
|
|
|
# EntityMedicament.ByUserId == userId, EntityMedicament.Status == DrugStatus.Out).all()
|
|
|
|
# return drugList
|
|
|
|
# return drugList
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
def inster_log_shiji(self):
|
|
|
|
from db_logic.medicament import BllMedicament
|
|
|
|
import random
|
|
|
|
from Common.Utils import PageParam
|
|
|
|
name_list = ["砷", "硫酸", "氧化钠"]
|
|
|
|
page_param = PageParam(1, 10)
|
|
|
|
obj_list = []
|
|
|
|
data = BllMedicament().get_drug_use_classify()
|
|
|
|
for i in range(100):
|
|
|
|
print(data)
|
|
|
|
obj = EntityMedicament(
|
|
|
|
|
|
|
|
bar_code= 10000 + i,
|
|
|
|
|
|
|
|
client_id='1c39cb24-07f8-11ed-abd4-f47b094925e1',
|
|
|
|
|
|
|
|
client_code="12345",
|
|
|
|
|
|
|
|
name=random.choice(name_list),
|
|
|
|
|
|
|
|
production_date=Utils.get_str_datetime(),
|
|
|
|
|
|
|
|
shelf_life=10,
|
|
|
|
|
|
|
|
remain=100,
|
|
|
|
|
|
|
|
total=500,
|
|
|
|
|
|
|
|
net_weight_unit="g",
|
|
|
|
|
|
|
|
net_weight=100,
|
|
|
|
|
|
|
|
purity="国标",
|
|
|
|
|
|
|
|
put_in_date=Utils.get_str_datetime(),
|
|
|
|
|
|
|
|
put_in_user_id='4cea74ee-0d8b-11ed-943e-f47b094925e1',
|
|
|
|
|
|
|
|
put_in_user_name="admin",
|
|
|
|
|
|
|
|
status=random.randint(1,3)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
obj_list.append(obj)
|
|
|
|
|
|
|
|
self.insert_many(obj_list)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# if __name__ == '__main__':
|
|
|
|
|
|
|
|
# from db_logic.medicament import BllMedicament
|
|
|
|
|
|
|
|
# from Common.Utils import PageParam
|
|
|
|
|
|
|
|
# page_param = PageParam(1, 10)
|
|
|
|
|
|
|
|
# data = BllMedicament().inster_log_shiji()
|
|
|
|
|
|
|
|
# print(data)
|
|
|
|
# values= {}
|
|
|
|
# values= {}
|
|
|
|
# page = values.get("page", 1)
|
|
|
|
# page = values.get("page", 1)
|
|
|
|
# page_size = values.get("page_size", 10)
|
|
|
|
# page_size = values.get("page_size", 10)
|
|
|
|