|
|
|
@ -25,19 +25,34 @@ class BllMedicament(Repository):
|
|
|
|
|
def update(self, entity):
|
|
|
|
|
entity.remark30 = '0'
|
|
|
|
|
return super().update(entity)
|
|
|
|
|
|
|
|
|
|
def get_register_list(self, user, page_param):
|
|
|
|
|
sql_all = f"""
|
|
|
|
|
select * from rms_medicament where status=4 and by_user_id='{user.user_id}'
|
|
|
|
|
"""
|
|
|
|
|
try:
|
|
|
|
|
total_count = self.execute(f"select count(*) num from rms_medicament where status=4 and by_user_id='{user.user_id}'").fetchone().num
|
|
|
|
|
except Exception:
|
|
|
|
|
total_count = 0
|
|
|
|
|
page_param.totalRecords = total_count
|
|
|
|
|
# 调用分页组装sql
|
|
|
|
|
sql_all = Utils.sql_paging_assemble(sql_all, page_param)
|
|
|
|
|
return self.execute(sql_all).fetchall()
|
|
|
|
|
|
|
|
|
|
# 获取可入库层数据
|
|
|
|
|
def get_drug_save_db_info(self, drug_name, func_type):
|
|
|
|
|
sql_all = f"""
|
|
|
|
|
|
|
|
|
|
select name, IFNULL(num,0) number, c.client_id, cell_code, cell_speci from (
|
|
|
|
|
select name, IFNULL(num,0) number, c.client_name, c.client_id, cell_code, cell_speci from (
|
|
|
|
|
select cell_code, a.client_id, cell_speci, client_name from (
|
|
|
|
|
select * from rms_client_cell
|
|
|
|
|
) a LEFT JOIN(
|
|
|
|
|
select client_id, client_name from rms_client
|
|
|
|
|
) b on a.client_id = b.client_id
|
|
|
|
|
) c LEFT JOIN(
|
|
|
|
|
select NAME, client_id, flow_position_code, count(*) num from rms_medicament where `name` like '%{drug_name}%' and status=1, func_type={func_type} GROUP BY client_id, flow_position_code
|
|
|
|
|
select name, client_id, flow_position_code, count(*) num
|
|
|
|
|
from rms_medicament where `name` like '%{drug_name}%' and status=1 and func_type={func_type}
|
|
|
|
|
GROUP BY client_id, flow_position_code
|
|
|
|
|
) d on c.client_id=d.client_id and c.cell_code=d.flow_position_code
|
|
|
|
|
|
|
|
|
|
HAVING number < 40
|
|
|
|
@ -48,9 +63,12 @@ class BllMedicament(Repository):
|
|
|
|
|
if i.client_id in data_dict.keys():
|
|
|
|
|
data_dict[i.client_id]["client_cell"].append(i.cell_speci)
|
|
|
|
|
else:
|
|
|
|
|
data_dict[i.client_id]["client_id"] = i.client_id
|
|
|
|
|
data_dict[i.client_id]["client_name"] = i.client_name
|
|
|
|
|
data_dict[i.client_id]["client_cell"] = [i.cell_speci]
|
|
|
|
|
client_dict = {
|
|
|
|
|
"client_id": i.client_id,
|
|
|
|
|
"client_name": i.client_name,
|
|
|
|
|
"client_cell": [i.cell_speci]
|
|
|
|
|
}
|
|
|
|
|
data_dict[i.client_id] = client_dict
|
|
|
|
|
data_list = []
|
|
|
|
|
for k,v in data_dict.items():
|
|
|
|
|
data_list.append(v)
|
|
|
|
@ -253,6 +271,7 @@ class BllMedicament(Repository):
|
|
|
|
|
# 创建事务
|
|
|
|
|
self.beginTrans()
|
|
|
|
|
entityDrug.remark30 = '0'
|
|
|
|
|
entityDrug.client_code = entityClient.client_code
|
|
|
|
|
self.session.add(entityDrug)
|
|
|
|
|
if entityDrug.status == 1:
|
|
|
|
|
self.session.add(entityDrugRecord)
|
|
|
|
@ -371,7 +390,7 @@ class BllMedicament(Repository):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 获取库存信息总览
|
|
|
|
|
def get_stock_all_info(self, page_param, func_type, name=None):
|
|
|
|
|
def get_stock_all_info(self, page_param, func_type,client_id, name=None, client_place=None):
|
|
|
|
|
filter_base = ""
|
|
|
|
|
if name:
|
|
|
|
|
filter_base = f" `name` LIKE '%{name}%'"
|
|
|
|
@ -379,17 +398,43 @@ class BllMedicament(Repository):
|
|
|
|
|
if filter_base:
|
|
|
|
|
filter_base += " and "
|
|
|
|
|
filter_base += f" func_type='{func_type}' "
|
|
|
|
|
if client_id:
|
|
|
|
|
if filter_base:
|
|
|
|
|
filter_base += " and "
|
|
|
|
|
filter_base += f" client_id='{client_id}' "
|
|
|
|
|
if filter_base:
|
|
|
|
|
filter_base = f" where {filter_base}"
|
|
|
|
|
sql_all =f"""
|
|
|
|
|
select DISTINCT
|
|
|
|
|
`name`, speci, cas_number,net_weight_unit, purity,
|
|
|
|
|
manufacturer, distributor, net_weight, net_weight_unit,
|
|
|
|
|
client_id, put_in_user_name,category,expiration_date
|
|
|
|
|
|
|
|
|
|
sum(CASE WHEN `status`=1 THEN 1 ELSE 0 END) count_number,
|
|
|
|
|
sum(CASE WHEN `status`=1 THEN remain ELSE 0 END) sum_remain
|
|
|
|
|
FROM rms_medicament {filter_base} GROUP BY `name`, speci, purity order by put_in_date desc
|
|
|
|
|
#TODO 添加房间筛选
|
|
|
|
|
filter_base1 = ""
|
|
|
|
|
if client_place:
|
|
|
|
|
filter_base1 += f"where client_speci='{client_place}'"
|
|
|
|
|
|
|
|
|
|
# sql_all =f"""
|
|
|
|
|
# select DISTINCT
|
|
|
|
|
# `name`, speci, cas_number,net_weight_unit, purity,
|
|
|
|
|
# manufacturer, distributor, net_weight, net_weight_unit,
|
|
|
|
|
# client_id, put_in_user_name,category,expiration_date
|
|
|
|
|
|
|
|
|
|
# sum(CASE WHEN `status`=1 THEN 1 ELSE 0 END) count_number,
|
|
|
|
|
# sum(CASE WHEN `status`=1 THEN remain ELSE 0 END) sum_remain
|
|
|
|
|
# FROM rms_medicament {filter_base} GROUP BY `name`, speci, purity order by put_in_date desc
|
|
|
|
|
# """
|
|
|
|
|
sql_all = f"""
|
|
|
|
|
|
|
|
|
|
select a.*, b.client_name from (
|
|
|
|
|
select DISTINCT
|
|
|
|
|
`name`, speci, cas_number, purity,
|
|
|
|
|
manufacturer, distributor, net_weight, net_weight_unit,
|
|
|
|
|
client_id, put_in_user_name,category,expiration_date,put_in_date,
|
|
|
|
|
|
|
|
|
|
sum(CASE WHEN `status`=1 THEN 1 ELSE 0 END) count_number,
|
|
|
|
|
sum(CASE WHEN `status`=1 THEN remain ELSE 0 END) sum_remain
|
|
|
|
|
FROM rms_medicament {filter_base} GROUP BY `name`, speci, purity
|
|
|
|
|
)a LEFT JOIN (
|
|
|
|
|
select * from rms_client {filter_base1}
|
|
|
|
|
) b on a.client_id=b.client_id
|
|
|
|
|
where b.client_name is not null
|
|
|
|
|
order by a.put_in_date desc
|
|
|
|
|
"""
|
|
|
|
|
# 首次查询,判断长度,做分页使用
|
|
|
|
|
try:
|
|
|
|
@ -403,7 +448,7 @@ class BllMedicament(Repository):
|
|
|
|
|
return self.execute(sql_all).fetchall()
|
|
|
|
|
|
|
|
|
|
#获取所有药剂列表
|
|
|
|
|
def getAllDrugList(self, search_word, manufacturer, start_time, end_time, func_type, page_param, customer_id=None, client_id=None, client_speci=None):
|
|
|
|
|
def getAllDrugList(self, search_word, manufacturer, start_time, end_time, func_type, page_param, seach_user, customer_id=None, client_id=None, client_speci=None):
|
|
|
|
|
# (Name like :searchWord or BarCode like :searchWord or EnglishName like :searchWord)
|
|
|
|
|
filter_base = ""
|
|
|
|
|
if customer_id:
|
|
|
|
@ -436,19 +481,22 @@ class BllMedicament(Repository):
|
|
|
|
|
if filter_base:
|
|
|
|
|
filter_base += " and "
|
|
|
|
|
filter_base += f" func_type={func_type}"
|
|
|
|
|
|
|
|
|
|
if seach_user:
|
|
|
|
|
if filter_base:
|
|
|
|
|
filter_base += " and "
|
|
|
|
|
filter_base += f" put_in_user_name like '%{seach_user}%'"
|
|
|
|
|
if filter_base:
|
|
|
|
|
filter_base = "where " + filter_base
|
|
|
|
|
# select * from rms_medicament {filter_base}
|
|
|
|
|
#TODO 添加房间筛选
|
|
|
|
|
filter_base1 = ""
|
|
|
|
|
# if client_speci:
|
|
|
|
|
# filter_base1 += f"where client_speci='{client_speci}'"
|
|
|
|
|
if client_speci:
|
|
|
|
|
filter_base1 += f"where client_speci='{client_speci}'"
|
|
|
|
|
sql_all = f"""
|
|
|
|
|
select a.*,b.client_name from (
|
|
|
|
|
select
|
|
|
|
|
name, english_name,bar_code,manufacturer,speci,remain,purity,production_date,shelf_life,expiration_date,put_in_date,put_in_user_name,
|
|
|
|
|
status,by_user_name,client_id, count(*) count_number
|
|
|
|
|
status,by_user_name,client_id
|
|
|
|
|
from rms_medicament {filter_base}
|
|
|
|
|
) a LEFT JOIN(
|
|
|
|
|
select client_id,client_name from rms_client {filter_base1}
|
|
|
|
@ -474,13 +522,14 @@ class BllMedicament(Repository):
|
|
|
|
|
return self.execute(sql_all).fetchall()
|
|
|
|
|
|
|
|
|
|
# 入库、领用、归还记录
|
|
|
|
|
def drug_show_type_info(self, record_type, start_time, end_time, put_in_user_name, name, func_type, statue_type, page_param):
|
|
|
|
|
def drug_show_type_info(self, record_type, start_time, end_time, put_in_user_name, name, func_type, client_id, statue_type, page_param, client_place):
|
|
|
|
|
filter_base1 = f" WHERE record_type={record_type} "
|
|
|
|
|
if put_in_user_name:
|
|
|
|
|
filter_base1 += f" and create_user_name like '%{put_in_user_name}%'"
|
|
|
|
|
if start_time and end_time:
|
|
|
|
|
filter_base1 += f" and create_date >= '{start_time}' and create_date <= '{end_time}'"
|
|
|
|
|
|
|
|
|
|
if client_id:
|
|
|
|
|
filter_base1 += f" and client_id='{client_id}'"
|
|
|
|
|
filter_base2 = ''
|
|
|
|
|
if name:
|
|
|
|
|
name = f"%{name}%"
|
|
|
|
@ -497,6 +546,10 @@ class BllMedicament(Repository):
|
|
|
|
|
filter_base2 += f" func_type='{func_type}' "
|
|
|
|
|
if filter_base2:
|
|
|
|
|
filter_base2 = f" where {filter_base2}"
|
|
|
|
|
#TODO 添加房间筛选
|
|
|
|
|
filter_base = ""
|
|
|
|
|
if client_place:
|
|
|
|
|
filter_base += f"where client_speci='{client_place}'"
|
|
|
|
|
sql_all = f"""
|
|
|
|
|
select
|
|
|
|
|
`name`, english_name, bar_code, purity,
|
|
|
|
@ -511,8 +564,8 @@ class BllMedicament(Repository):
|
|
|
|
|
by_user_date, by_user_name, unit_code
|
|
|
|
|
FROM rms_medicament {filter_base2}
|
|
|
|
|
) as b on a.medicament_id=b.medicament_id
|
|
|
|
|
LEFT JOIN(select client_id,client_name from rms_client) c on a.client_id=c.client_id
|
|
|
|
|
where name is not null GROUP BY create_date desc
|
|
|
|
|
LEFT JOIN(select client_id,client_name from rms_client {filter_base}) c on a.client_id=c.client_id
|
|
|
|
|
where name is not null and client_name is not null ORDER BY create_date desc
|
|
|
|
|
"""
|
|
|
|
|
try:
|
|
|
|
|
count_number = len(self.execute(sql_all).fetchall())
|
|
|
|
@ -558,20 +611,17 @@ class BllMedicament(Repository):
|
|
|
|
|
return self.execute(sql_all).fetchall()
|
|
|
|
|
|
|
|
|
|
# 可领用试剂列表
|
|
|
|
|
def use_drug_info_list(self, client_id, page_param):
|
|
|
|
|
def use_drug_info_list(self, client_id, seach_word, page_param):
|
|
|
|
|
filter_base = ""
|
|
|
|
|
if client_id:
|
|
|
|
|
filter_base += f"client_id='{client_id}'"
|
|
|
|
|
if seach_word:
|
|
|
|
|
if filter_base:
|
|
|
|
|
filter_base += " and "
|
|
|
|
|
name = f"%{seach_word}%"
|
|
|
|
|
filter_base += f" (`name` like '{name}' or english_name like '{name}') "
|
|
|
|
|
if filter_base:
|
|
|
|
|
filter_base = f" and {filter_base}"
|
|
|
|
|
"""
|
|
|
|
|
select
|
|
|
|
|
`name`, speci, purity, count(*) drug_num, manufacturer, distributor
|
|
|
|
|
from
|
|
|
|
|
rms_medicament WHERE `status`=1 {filter_base}
|
|
|
|
|
GROUP BY
|
|
|
|
|
`name`, speci, purity, client_id
|
|
|
|
|
"""
|
|
|
|
|
sql_all = f"""
|
|
|
|
|
select a.*,b.client_name from (
|
|
|
|
|
select
|
|
|
|
|