海南医院帆软报表 最终版本SQL
1. 挂号微信收入明细
-- WANTED-1283 门诊查询统计报表-挂号微信收入明细
select
p.name as patientName, -- 患者姓名
p.birthday, -- 出生日期
bl.outpatient_number as blNumber, -- 病历号
case p.sex WHEN 1 THEN '男' WHEN 2 THEN '女' END as sex, -- 性别
round((f.preFee - f.discountFee - f.promotionBenefitFee - f.couponFee - f.itemBenefitFee - f.memberCardBenefitFee - f.itemComInvBenefitFee) * f.discount,2) AS guaHaoMoney,
h.type,
h.pay_method,
i.name as payMethod,
h.flow_fee as weiXinMoney, -- 微信到账
h.charge as weiXinCharge, -- 微信手续
h.pay_time as payTime, -- 缴费时间
a.create_time, -- 挂号时间
a.dept_name, -- 挂号科室名称
a.appointment_doctor_name as doctorName, -- 挂号医生
(select t.docname from (
SELECT u.id AS docid,u1.property_value AS docname
FROM thc_warehouse.staff_record u
LEFT JOIN thc_warehouse.staff_record_property u1 ON u1.property_code = 'SXX000083' AND u.id = u1.staff_record_id
) t where t.docid = a.creator) AS creater,
CASE a.subsequent_visit
WHEN 0 THEN '初诊'
WHEN 1 THEN '复诊'
WHEN 2 THEN '转诊'
WHEN 3 THEN '急诊'
WHEN 4 THEN '体检'
WHEN 5 THEN '简易'
WHEN 6 THEN '疫苗'
WHEN 7 THEN '团队体检'
END AS isReVisit -- 初复诊
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.order_item_id
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID
inner JOIN `thc_rcm`.`pay_trade_log` h on h.settlement_id = g.id INNER JOIN `thc_passport`.`patient` p on a.patient_id = p.id left join `thc_passport`.`patient_org` bl on a.patient_id = bl.patient_id
left JOIN `thc_rcm`.`pay_payment` i on h.pay_method = i.value and g.clinicID = i.clinicid
where 1=1
and a.del_flag = 0
and d.isDelete = 0 and d.orderSource = 1 and d.orderType = 3 and d.returnFlag = 0
and e.itemClass = 1 and e.returnFlag is NULL
and g.settlementType=2 and g.`isDelete` = 0 and g.returnFlag = 0 -- 门诊挂号
and h.type = 1 and h.pay_method = 4 -- 微信支付
${if(len(creator) == 0,"","and a.creator = '" + creator + "'")}
${if(len(dept) == 0,"","and a.dept_id = '" + dept + "'")}
${if(len(startTime) == 0,"","and h.pay_time >= '" + startTime + "'")}
${if(len(endTime) == 0,"","and h.pay_time <= '" + endTime + "'")} ORDER BY g.createtime desc,a.create_time desc
2.挂号患者信息查询
-- -----------------------
-- 患者信息查询
-- -----------------------
select DISTINCT
CASE a.appointment_state WHEN -1 THEN '是' ELSE '否' END AS returnFlag, -- 退号标志
CASE a.is_appoint_resource WHEN 0 THEN '否' WHEN 1 THEN '是' END as isAppointResource, -- 指定标志
a.create_time as guaHaoTime, -- 挂号时间
p.create_time as createDocTime, -- 建档时间
-- 挂号实收金额
round((f.preFee - f.discountFee - f.promotionBenefitFee - f.couponFee - f.itemBenefitFee - f.memberCardBenefitFee - f.itemComInvBenefitFee) * f.discount,2) AS realFee,
round(t1.realFee,2) as menZenRealMoney, -- 门诊实收金额
j.outpatient_number as blNumber, -- 病历号
p.name as patientName, -- 患者姓名
a.dept_name, -- 科室名称
a.appointment_doctor_name as doctorName, -- 医生
CASE a.subsequent_visit -- 初复诊
WHEN 0 THEN '初诊'
WHEN 1 THEN '复诊'
WHEN 2 THEN '转诊'
WHEN 3 THEN '急诊'
WHEN 4 THEN '体检'
WHEN 5 THEN '简易'
WHEN 6 THEN '疫苗'
WHEN 7 THEN '团队体检'
END AS isReVisit, -- 初复诊
channel.name as sourceName, -- 信息(渠道)来源
p.birthday, -- 出生日期
if(i.id_no is null, if(i.other_type is null, null,
(select e.name from `thc_warehouse`.`sys_type_info` e
JOIN `thc_warehouse`.`sys_type` f ON e.sys_type_id = f.id
WHERE f.`code` = 'THC_WH_PERSON_CARD' and e.value = i.other_type)
), '身份证') as cardType, -- 证件类型
if(i.id_no is null,i.other_no,i.id_no) as cardNo, -- 证件号码
CONCAT(t2.province,t2.city,t2.county,t2.addressDetail) as liveAddr, -- 住址
CONCAT(t2.province2,t2.city2,t2.county2,t2.addressDetail2) as bornAddr, -- 户籍
if(locate('区',t2.county2) > 0,t2.county2,'') as qu, -- 区
a.patient_phone,
(select t.docname from (
SELECT u.id AS docid,u1.property_value AS docname
FROM thc_warehouse.staff_record u
LEFT JOIN thc_warehouse.staff_record_property u1 ON u1.property_code = 'SXX000083' AND u.id = u1.staff_record_id
) t where t.docid = a.creator) AS creater,
-- a.appointment_starttime,
CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime, -- 预约时间
-- CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
a.referrer_dept_name, -- 爱院科室
a.referrer_name, -- 爱院人
a.description -- 备注
FROM `thc_arrange`.`bpm_appointment` a
INNER JOIN `thc_sob`.`bpm_service_order` b on a.orderId = b.id
INNER JOIN `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id AND c.id = a.order_item_id
INNER JOIN `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id
INNER JOIN `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId
INNER JOIN `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id AND f.accountBillDetailID = e.id
INNER JOIN `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID
INNER JOIN `thc_passport`.`patient` p on a.patient_id = p.id
INNER JOIN `thc_rcm`.`pay_trade_log` h on h.settlement_id = g.id
LEFT JOIN `thc_c_union`.`member_channel` channel on a.channel_id = channel.id
LEFT JOIN `thc_passport`.`contact` i on a.patient_id = i.patient_id
LEFT JOIN `thc_passport`.`patient_org` j on a.patient_id = j.patient_id left join
(
select
aa.id,
round((ff.preFee - ff.discountFee - ff.promotionBenefitFee - ff.couponFee - ff.itemBenefitFee - ff.memberCardBenefitFee - ff.itemComInvBenefitFee) * ff.discount,2) AS realFee
from `thc_arrange`.`bpm_appointment` aa
inner join `thc_sob`.`bpm_service_order` bb on aa.orderId = bb.id
inner join `thc_sob`.`bpm_service_order_item` cc on cc.service_order_id = bb.id and cc.id = aa.`order_item_id`
inner join `thc_rcm`.`Cs_AccountBill` dd on dd.orderID = bb.id and dd.`isDelete` = 0 and dd.orderSource = 1 and dd.orderType = 3 and dd.returnFlag = 0
inner join `thc_rcm`.`Cs_AccountBillDetail` ee on dd.id = ee.AccountBillId and ee.itemClass = 1 and ee.returnFlag is NULL
inner join `thc_rcm`.`Cs_SettlementDetail` ff on ff.accountBillID = dd.id and ff.accountBillDetailID = ee.id
inner join `thc_rcm`.`Cs_Settlement` gg on gg.id = ff.settlementID and gg.`isDelete` = 0 and gg.returnFlag = 0
and gg.settlementType=1 -- 门诊收费
where 1=1 and aa.del_flag = 0
) t1 on a.id = t1.id left join
(
select
aa.id,
-- 住址
(select city.name from `thc_passport`.`city` where city.id =
(if(p.address is null,null, TRIM(BOTH '"' FROM JSON_EXTRACT(p.address,'$.province'))))) as province,
(select city.name from `thc_passport`.`city` where city.id =
(if(p.address is null,null, TRIM(BOTH '"' FROM JSON_EXTRACT(p.address,'$.city'))))) as city,
(select city.name from `thc_passport`.`city` where city.id =
(if(p.address is null,null, TRIM(BOTH '"' FROM JSON_EXTRACT(p.address,'$.county'))))) as county, if(p.address is null,null, TRIM(BOTH '"' FROM JSON_EXTRACT(p.address,'$.addressDetail'))) as addressDetail, -- 户籍
(select city.name from `thc_passport`.`city` where city.id = (if(p.household is null,null, TRIM(BOTH '"' FROM JSON_EXTRACT(p.household,'$.province'))))) as province2,
(select city.name from `thc_passport`.`city` where city.id =
(if(p.household is null,null, TRIM(BOTH '"' FROM JSON_EXTRACT(p.household,'$.city'))))) as city2,
(select city.name from `thc_passport`.`city` where city.id =
(if(p.household is null,null, TRIM(BOTH '"' FROM JSON_EXTRACT(p.household,'$.county'))))) as county2,
if(p.household is null,null, TRIM(BOTH '"' FROM JSON_EXTRACT(p.household,'$.addressDetail'))) as addressDetail2,
round((ff.preFee - ff.discountFee - ff.promotionBenefitFee - ff.couponFee - ff.itemBenefitFee - ff.memberCardBenefitFee - ff.itemComInvBenefitFee) * ff.discount,2) AS realFee
from `thc_arrange`.`bpm_appointment` aa
inner join `thc_sob`.`bpm_service_order` bb on aa.orderId = bb.id
inner join `thc_sob`.`bpm_service_order_item` cc on cc.service_order_id = bb.id and cc.id = aa.`order_item_id`
inner join `thc_rcm`.`Cs_AccountBill` dd on dd.orderID = bb.id and dd.`isDelete` = 0 and dd.orderSource = 1 and dd.orderType = 3 and dd.returnFlag = 0
inner join `thc_rcm`.`Cs_AccountBillDetail` ee on dd.id = ee.AccountBillId and ee.itemClass = 1 and ee.returnFlag is NULL
inner join `thc_rcm`.`Cs_SettlementDetail` ff on ff.accountBillID = dd.id and ff.accountBillDetailID = ee.id
inner join `thc_rcm`.`Cs_Settlement` gg on gg.id = ff.settlementID and gg.`isDelete` = 0 and gg.returnFlag = 0 -- 门诊挂号
and gg.settlementType=2 -- 非挂号消费类型
inner join `thc_passport`.`patient` p on aa.patient_id = p.id
where 1=1 and aa.del_flag = 0 ) t2 on a.id = t2.id WHERE 1=1
AND a.del_flag = 0
AND d.isDelete = 0
AND d.orderSource = 1
AND d.orderType = 3
AND d.returnFlag = 0
AND e.itemClass = 1
AND e.returnFlag is NULL
AND g.settlementType=2
AND g.isDelete = 0
AND g.returnFlag = 0 -- 门诊挂号 ${if(len(startTime) == 0,"","AND a.create_time >= '" + startTime + "'")}
${if(len(endTime) == 0,"","AND a.create_time <= '" + endTime + "'")}
-- 爱院标志
${if(loveYuan == 0,"and a.appointment_state is null","")}
${if(loveYuan == 1,"and a.appointment_state is not null","")} ${if(len(deptId) == 0,"","AND a.dept_id = '" + deptId + "'")} -- 部门
${if(len(doctor) == 0,"","AND a.appointment_doctor_id = '" + doctor + "'")} -- 医生
${if(len(channelId) == 0,"","AND a.channel_id = '" + channelId + "'")} -- 信息来源
${if(len(patientName) == 0,"","AND p.name like '%" + patientName + "%'")} -- 姓名
${if(len(blNumber) == 0,"","AND j.outpatient_number like '%" + blNumber + "%'")} -- 病历号
${if(len(phone) == 0,"","AND a.patient_phone like '%" + phone + "%'")} -- 电话号
${if(len(subVisit) == 0,"","AND a.subsequent_visit = '" + subVisit + "'")} -- 初复诊
${if(len(doctor) == 0,"","and a.appointment_doctor_id = '" + doctor + "'")} -- 接诊员
${if(isReturn == -1,"and a.appointment_state = -1","")} -- 退号标志
${if(isReturn == 0,"and a.appointment_state != -1","")} -- 退号标志
3.挂号按来源统计
select
channel.name as name,
DATE_FORMAT(a.appointment_date,${if(dateType == 1,"'%Y-%m'","'%Y-%m-%d'")}) as date, -- 按日期还是月份展示
IFNULL(count(1),0) as num
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.order_item_id
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID
left join `thc_c_union`.`member_channel` channel on a.channel_id = channel.id
where 1=1
and a.del_flag = 0
and d.isDelete = 0 and d.orderSource = 1 and d.orderType = 3 and d.returnFlag = 0
and e.itemClass = 1 and e.returnFlag is NULL
and g.settlementType=2 and g.`isDelete` = 0 and g.returnFlag = 0 -- 门诊挂号
and g.id in (
SELECT DISTINCT g.id
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.order_item_id
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID
inner JOIN `thc_rcm`.`pay_trade_log` h on h.settlement_id = g.id
where 1=1
and a.del_flag = 0
and d.isDelete = 0 and d.orderSource = 1 and d.orderType = 3 and d.returnFlag = 0
and e.itemClass = 1 and e.returnFlag is NULL
and g.settlementType=2 and g.`isDelete` = 0 and g.returnFlag = 0 -- 门诊挂号
and h.type = 1 and h.pay_state = 1
) and DATE_FORMAT(a.appointment_date,'%Y-%m-%d') >= DATE_FORMAT(${if(len(startTime) == 0, "'0000-01-01'" , "'" + startTime + "'" )},'%Y-%m-%d')
and DATE_FORMAT(a.appointment_date,'%Y-%m-%d') <= DATE_FORMAT(${if(len(endTime) == 0,"'9999-01-01'","'" + endTime + "'")},'%Y-%m-%d')
${if(len(subVisit) == 0,"","and a.subsequent_visit = '" + subVisit + "'")}
-- and channel.name is not null
group by date_format(a.appointment_date, ${if(dateType == 1,"'%Y-%m'","'%Y-%m-%d'")}), channel.name -- 按日期还是月份分组查询
order by a.appointment_date DESC, data_source asc
3.1有交易流水的条件
AND g.id IN (
SELECT DISTINCT g.id
FROM `thc_arrange`.`bpm_appointment` a
INNER JOIN `thc_sob`.`bpm_service_order` b on a.orderId = b.id
INNER JOIN `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id AND c.id = a.order_item_id
INNER JOIN `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id
INNER JOIN `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId
INNER JOIN `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id AND f.accountBillDetailID = e.id
INNER JOIN `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID
INNER JOIN `thc_rcm`.`pay_trade_log` h on h.settlement_id = g.id
WHERE 1=1
AND a.del_flag = 0
AND d.isDelete = 0 AND d.orderSource = 1 AND d.orderType = 3 AND d.returnFlag = 0
AND e.itemClass = 1 AND e.returnFlag is NULL
AND g.settlementType=2 AND g.`isDelete` = 0 AND g.returnFlag = 0 -- 门诊挂号
AND h.type = 1
)
4.挂号按医生统计
select
t0.deptName,
t0.doctorName,
t0.deptId,
t0.doctorId,
t0.startTime,
t0.endTime,
IFNULL(t0.num,0) as num0,
IFNULL(t1.num,0) as num1,
IFNULL(t2.num,0) as num2,
IFNULL(t3.num,0) as num3,
IFNULL(t4.num,0) as num4,
IFNULL(t5.num,0) as num5,
IFNULL(t6.num,0) as num6,
IFNULL(t7.num,0) as num7,
IFNULL(t8.num,0) as num8,
IFNULL(t9.num,0) as num9,
IFNULL(t10.num,0) as num10,
IFNULL(t11.num,0) as num11,
IFNULL(t12.num,0) as num12,
IFNULL(t13.num,0) as num13,
IFNULL(t14.num,0) as num14
from
-- ------------
-- 总挂号数
-- ------------
(
select t.startTime, t.endTime, count(1) as num,t.deptId, doctorId,t.deptName,t.create_time,t.doctorName from
(
select
a.data_source,
a.is_appoint_resource,
a.subsequent_visit,
a.appointment_state,
a.dept_id as deptId,
a.appointment_doctor_id as doctorId,
a.dept_name as deptName,
a.create_time,
a.appointment_doctor_name as doctorName,
CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
f.preFee, -- 原价
(f.preFee - f.discountFee - f.promotionBenefitFee - f.couponFee - f.itemBenefitFee - f.memberCardBenefitFee - f.itemComInvBenefitFee) * f.discount AS realFee,
f.discount
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.`order_item_id`
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id and d.`isDelete` = 0 and d.orderSource = 1 and d.orderType = 3 and d.returnFlag = 0
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId and e.itemClass = 1 and e.returnFlag is NULL
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID and g.settlementType=2 and g.`isDelete` = 0 and g.returnFlag = 0 -- 门诊挂号
where a.del_flag = 0
AND g.id IN (
SELECT DISTINCT g.id
FROM `thc_arrange`.`bpm_appointment` a
INNER JOIN `thc_sob`.`bpm_service_order` b on a.orderId = b.id
INNER JOIN `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id AND c.id = a.order_item_id
INNER JOIN `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id
INNER JOIN `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId
INNER JOIN `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id AND f.accountBillDetailID = e.id
INNER JOIN `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID
INNER JOIN `thc_rcm`.`pay_trade_log` h on h.settlement_id = g.id
WHERE 1=1
AND a.del_flag = 0
AND d.isDelete = 0 AND d.orderSource = 1 AND d.orderType = 3 AND d.returnFlag = 0
AND e.itemClass = 1 AND e.returnFlag is NULL
AND g.settlementType=2 AND g.`isDelete` = 0 AND g.returnFlag = 0 -- 门诊挂号
AND h.type = 1 and h.pay_state = 1 -- 支付成功
)
${if(len(deptId) == 0,"","and a.dept_id = '" + deptId + "'")}
${if(len(doctorId) == 0,"","and a.appointment_doctor_id = '" + doctorId + "'")}
) t
where 1=1
${if(len(startTime) == 0,"","AND t.create_time >= '" + startTime + "'")}
${if(len(endTime) == 0,"","AND t.create_time <= '" + endTime + "'")}
group by t.deptId,t.doctorId
) t0 -- ------------
-- 退号
-- ------------
left join
(
select count(1) as num,t.deptId, doctorId,t.deptName,t.create_time,t.doctorName from
(
select
a.data_source,
a.is_appoint_resource,
a.subsequent_visit,
a.dept_id as deptId,
a.appointment_doctor_id as doctorId,
a.appointment_state,
a.dept_name as deptName,
a.create_time,
a.appointment_doctor_name as doctorName,
CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
f.preFee, -- 原价
(f.preFee - f.discountFee - f.promotionBenefitFee - f.couponFee - f.itemBenefitFee - f.memberCardBenefitFee - f.itemComInvBenefitFee) * f.discount AS realFee,
f.discount
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.`order_item_id`
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id and d.`isDelete` = 0 and d.orderSource = 1 and d.orderType = 3 and d.returnFlag = 0
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId and e.itemClass = 1 and e.returnFlag is NULL
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID and g.settlementType=2 and g.`isDelete` = 0 and g.returnFlag = 0 -- 门诊挂号
where 1=1 and a.del_flag = 0
AND g.id IN (
SELECT DISTINCT g.id
FROM `thc_arrange`.`bpm_appointment` a
INNER JOIN `thc_sob`.`bpm_service_order` b on a.orderId = b.id
INNER JOIN `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id AND c.id = a.order_item_id
INNER JOIN `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id
INNER JOIN `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId
INNER JOIN `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id AND f.accountBillDetailID = e.id
INNER JOIN `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID
INNER JOIN `thc_rcm`.`pay_trade_log` h on h.settlement_id = g.id
WHERE 1=1
AND a.del_flag = 0
AND d.isDelete = 0 AND d.orderSource = 1 AND d.orderType = 3 AND d.returnFlag = 0
AND e.itemClass = 1 AND e.returnFlag is NULL
AND g.settlementType=2 AND g.`isDelete` = 0 AND g.returnFlag = 0 -- 门诊挂号
AND h.type = 1 and h.pay_state = 1 -- 支付成功
)
and a.appointment_state = -1
${if(len(deptId) == 0,"","and a.dept_id = '" + deptId + "'")}
${if(len(doctorId) == 0,"","and a.appointment_doctor_id = '" + doctorId + "'")}
) t
where 1=1
${if(len(startTime) == 0,"","AND t.create_time >= '" + startTime + "'")}
${if(len(endTime) == 0,"","AND t.create_time <= '" + endTime + "'")}
group by t.deptId,t.doctorId
) t1
on t0.deptId = t1.deptId and t0.doctorId = t1.doctorId -- ------------
-- 实际挂号数 = 初诊数 + 复诊数 + 转诊数
-- ------------
left join
(
select count(1) as num,t.deptId, doctorId,t.deptName,t.create_time,t.doctorName from
(
select
a.data_source,
a.is_appoint_resource,
a.subsequent_visit,
a.dept_id as deptId,
a.appointment_doctor_id as doctorId,
a.appointment_state,
a.dept_name as deptName,
a.create_time,
a.appointment_doctor_name as doctorName,
CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
f.preFee, -- 原价
(f.preFee - f.discountFee - f.promotionBenefitFee - f.couponFee - f.itemBenefitFee - f.memberCardBenefitFee - f.itemComInvBenefitFee) * f.discount AS realFee,
f.discount
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.`order_item_id`
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id and d.`isDelete` = 0 and d.orderSource = 1 and d.orderType = 3 and d.returnFlag = 0
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId and e.itemClass = 1 and e.returnFlag is NULL
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID and g.settlementType=2 and g.`isDelete` = 0 and g.returnFlag = 0 -- 门诊挂号
where a.del_flag = 0 and a.subsequent_visit in (0,1,2)
AND g.id IN (
SELECT DISTINCT g.id
FROM `thc_arrange`.`bpm_appointment` a
INNER JOIN `thc_sob`.`bpm_service_order` b on a.orderId = b.id
INNER JOIN `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id AND c.id = a.order_item_id
INNER JOIN `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id
INNER JOIN `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId
INNER JOIN `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id AND f.accountBillDetailID = e.id
INNER JOIN `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID
INNER JOIN `thc_rcm`.`pay_trade_log` h on h.settlement_id = g.id
WHERE 1=1
AND a.del_flag = 0
AND d.isDelete = 0 AND d.orderSource = 1 AND d.orderType = 3 AND d.returnFlag = 0
AND e.itemClass = 1 AND e.returnFlag is NULL
AND g.settlementType=2 AND g.`isDelete` = 0 AND g.returnFlag = 0 -- 门诊挂号
AND h.type = 1 and h.pay_state = 1 -- 支付成功
)
${if(len(deptId) == 0,"","and a.dept_id = '" + deptId + "'")}
${if(len(doctorId) == 0,"","and a.appointment_doctor_id = '" + doctorId + "'")}
) t
where 1=1
${if(len(startTime) == 0,"","AND t.create_time >= '" + startTime + "'")}
${if(len(endTime) == 0,"","AND t.create_time <= '" + endTime + "'")}
group by t.deptId,t.doctorId
) t2
on t0.deptId = t2.deptId and t0.doctorId = t2.doctorId -- ------------
-- 指定
-- ------------
left join
(
select count(1) as num,t.deptId, doctorId,t.deptName,t.create_time,t.doctorName from
(
select
a.data_source,
a.is_appoint_resource,
a.subsequent_visit,
a.dept_id as deptId,
a.appointment_doctor_id as doctorId,
a.appointment_state,
a.dept_name as deptName,
a.create_time,
a.appointment_doctor_name as doctorName,
CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
f.preFee, -- 原价
(f.preFee - f.discountFee - f.promotionBenefitFee - f.couponFee - f.itemBenefitFee - f.memberCardBenefitFee - f.itemComInvBenefitFee) * f.discount AS realFee,
f.discount
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.`order_item_id`
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id and d.`isDelete` = 0 and d.orderSource = 1 and d.orderType = 3 and d.returnFlag = 0
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId and e.itemClass = 1 and e.returnFlag is NULL
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID and g.settlementType=2 and g.`isDelete` = 0 and g.returnFlag = 0 -- 门诊挂号
where a.del_flag = 0 and a.is_appoint_resource = 1
AND g.id IN (
SELECT DISTINCT g.id
FROM `thc_arrange`.`bpm_appointment` a
INNER JOIN `thc_sob`.`bpm_service_order` b on a.orderId = b.id
INNER JOIN `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id AND c.id = a.order_item_id
INNER JOIN `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id
INNER JOIN `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId
INNER JOIN `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id AND f.accountBillDetailID = e.id
INNER JOIN `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID
INNER JOIN `thc_rcm`.`pay_trade_log` h on h.settlement_id = g.id
WHERE 1=1
AND a.del_flag = 0
AND d.isDelete = 0 AND d.orderSource = 1 AND d.orderType = 3 AND d.returnFlag = 0
AND e.itemClass = 1 AND e.returnFlag is NULL
AND g.settlementType=2 AND g.`isDelete` = 0 AND g.returnFlag = 0 -- 门诊挂号
AND h.type = 1 and h.pay_state = 1 -- 支付成功
)
${if(len(deptId) == 0,"","and a.dept_id = '" + deptId + "'")}
${if(len(doctorId) == 0,"","and a.appointment_doctor_id = '" + doctorId + "'")}
) t
where 1=1
${if(len(startTime) == 0,"","AND t.create_time >= '" + startTime + "'")}
${if(len(endTime) == 0,"","AND t.create_time <= '" + endTime + "'")}
group by t.deptId,t.doctorId
) t3
on t0.deptId = t3.deptId and t0.doctorId = t3.doctorId -- ------------
-- 初诊
-- ------------
left join
(
select count(1) as num,t.deptId, doctorId,t.deptName,t.create_time,t.doctorName from
(
select
a.data_source,
a.is_appoint_resource,
a.subsequent_visit,
a.dept_id as deptId,
a.appointment_doctor_id as doctorId,
a.appointment_state,
a.dept_name as deptName,
a.create_time,
a.appointment_doctor_name as doctorName,
CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
f.preFee, -- 原价
(f.preFee - f.discountFee - f.promotionBenefitFee - f.couponFee - f.itemBenefitFee - f.memberCardBenefitFee - f.itemComInvBenefitFee) * f.discount AS realFee,
f.discount
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.`order_item_id`
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id and d.`isDelete` = 0 and d.orderSource = 1 and d.orderType = 3 and d.returnFlag = 0
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId and e.itemClass = 1 and e.returnFlag is NULL
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID and g.settlementType=2 and g.`isDelete` = 0 and g.returnFlag = 0 -- 门诊挂号
where a.del_flag = 0 and a.subsequent_visit = 0
AND g.id IN (
SELECT DISTINCT g.id
FROM `thc_arrange`.`bpm_appointment` a
INNER JOIN `thc_sob`.`bpm_service_order` b on a.orderId = b.id
INNER JOIN `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id AND c.id = a.order_item_id
INNER JOIN `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id
INNER JOIN `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId
INNER JOIN `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id AND f.accountBillDetailID = e.id
INNER JOIN `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID
INNER JOIN `thc_rcm`.`pay_trade_log` h on h.settlement_id = g.id
WHERE 1=1
AND a.del_flag = 0
AND d.isDelete = 0 AND d.orderSource = 1 AND d.orderType = 3 AND d.returnFlag = 0
AND e.itemClass = 1 AND e.returnFlag is NULL
AND g.settlementType=2 AND g.`isDelete` = 0 AND g.returnFlag = 0 -- 门诊挂号
AND h.type = 1 and h.pay_state = 1 -- 支付成功
)
${if(len(deptId) == 0,"","and a.dept_id = '" + deptId + "'")}
${if(len(doctorId) == 0,"","and a.appointment_doctor_id = '" + doctorId + "'")}
) t
where 1=1
${if(len(startTime) == 0,"","AND t.create_time >= '" + startTime + "'")}
${if(len(endTime) == 0,"","AND t.create_time <= '" + endTime + "'")}
group by t.deptId,t.doctorId
) t4
on t0.deptId = t4.deptId and t0.doctorId = t4.doctorId -- ------------
-- 复诊
-- ------------
left join
(
select count(1) as num,t.deptId, doctorId,t.deptName,t.create_time,t.doctorName from
(
select
a.data_source,
a.is_appoint_resource,
a.subsequent_visit,
a.dept_id as deptId,
a.appointment_doctor_id as doctorId,
a.appointment_state,
a.dept_name as deptName,
a.create_time,
a.appointment_doctor_name as doctorName,
CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
f.preFee, -- 原价
(f.preFee - f.discountFee - f.promotionBenefitFee - f.couponFee - f.itemBenefitFee - f.memberCardBenefitFee - f.itemComInvBenefitFee) * f.discount AS realFee,
f.discount
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.`order_item_id`
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id and d.`isDelete` = 0 and d.orderSource = 1 and d.orderType = 3 and d.returnFlag = 0
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId and e.itemClass = 1 and e.returnFlag is NULL
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID and g.settlementType=2 and g.`isDelete` = 0 and g.returnFlag = 0 -- 门诊挂号
where a.del_flag = 0 and a.subsequent_visit = 1
AND g.id IN (
SELECT DISTINCT g.id
FROM `thc_arrange`.`bpm_appointment` a
INNER JOIN `thc_sob`.`bpm_service_order` b on a.orderId = b.id
INNER JOIN `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id AND c.id = a.order_item_id
INNER JOIN `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id
INNER JOIN `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId
INNER JOIN `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id AND f.accountBillDetailID = e.id
INNER JOIN `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID
INNER JOIN `thc_rcm`.`pay_trade_log` h on h.settlement_id = g.id
WHERE 1=1
AND a.del_flag = 0
AND d.isDelete = 0 AND d.orderSource = 1 AND d.orderType = 3 AND d.returnFlag = 0
AND e.itemClass = 1 AND e.returnFlag is NULL
AND g.settlementType=2 AND g.`isDelete` = 0 AND g.returnFlag = 0 -- 门诊挂号
AND h.type = 1 and h.pay_state = 1 -- 支付成功
)
${if(len(deptId) == 0,"","and a.dept_id = '" + deptId + "'")}
${if(len(doctorId) == 0,"","and a.appointment_doctor_id = '" + doctorId + "'")}
) t
where 1=1
${if(len(startTime) == 0,"","AND t.create_time >= '" + startTime + "'")}
${if(len(endTime) == 0,"","AND t.create_time <= '" + endTime + "'")}
group by t.deptId,t.doctorId
) t5
on t0.deptId = t5.deptId and t0.doctorId = t5.doctorId -- ------------
-- 体检
-- ------------
left join
(
select count(1) as num,t.deptId, doctorId,t.deptName,t.create_time,t.doctorName from
(
select
a.data_source,
a.is_appoint_resource,
a.subsequent_visit,
a.dept_id as deptId,
a.appointment_doctor_id as doctorId,
a.appointment_state,
a.dept_name as deptName,
a.create_time,
a.appointment_doctor_name as doctorName,
CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
f.preFee, -- 原价
(f.preFee - f.discountFee - f.promotionBenefitFee - f.couponFee - f.itemBenefitFee - f.memberCardBenefitFee - f.itemComInvBenefitFee) * f.discount AS realFee,
f.discount
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.`order_item_id`
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id and d.`isDelete` = 0 and d.orderSource = 1 and d.orderType = 3 and d.returnFlag = 0
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId and e.itemClass = 1 and e.returnFlag is NULL
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID and g.settlementType=2 and g.`isDelete` = 0 and g.returnFlag = 0 -- 门诊挂号
where a.del_flag = 0 and a.subsequent_visit = 4
AND g.id IN (
SELECT DISTINCT g.id
FROM `thc_arrange`.`bpm_appointment` a
INNER JOIN `thc_sob`.`bpm_service_order` b on a.orderId = b.id
INNER JOIN `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id AND c.id = a.order_item_id
INNER JOIN `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id
INNER JOIN `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId
INNER JOIN `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id AND f.accountBillDetailID = e.id
INNER JOIN `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID
INNER JOIN `thc_rcm`.`pay_trade_log` h on h.settlement_id = g.id
WHERE 1=1
AND a.del_flag = 0
AND d.isDelete = 0 AND d.orderSource = 1 AND d.orderType = 3 AND d.returnFlag = 0
AND e.itemClass = 1 AND e.returnFlag is NULL
AND g.settlementType=2 AND g.`isDelete` = 0 AND g.returnFlag = 0 -- 门诊挂号
AND h.type = 1 and h.pay_state = 1 -- 支付成功
)
${if(len(deptId) == 0,"","and a.dept_id = '" + deptId + "'")}
${if(len(doctorId) == 0,"","and a.appointment_doctor_id = '" + doctorId + "'")}
) t
where 1=1
${if(len(startTime) == 0,"","AND t.create_time >= '" + startTime + "'")}
${if(len(endTime) == 0,"","AND t.create_time <= '" + endTime + "'")}
group by t.deptId,t.doctorId
) t6
on t0.deptId = t6.deptId and t0.doctorId = t6.doctorId -- ------------
-- 团队
-- ------------
left join
(
select count(1) as num,t.deptId, doctorId,t.deptName,t.create_time,t.doctorName from
(
select
a.data_source,
a.is_appoint_resource,
a.subsequent_visit,
a.dept_id as deptId,
a.appointment_doctor_id as doctorId,
a.appointment_state,
a.dept_name as deptName,
a.create_time,
a.appointment_doctor_name as doctorName,
CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
f.preFee, -- 原价
(f.preFee - f.discountFee - f.promotionBenefitFee - f.couponFee - f.itemBenefitFee - f.memberCardBenefitFee - f.itemComInvBenefitFee) * f.discount AS realFee,
f.discount
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.`order_item_id`
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id and d.`isDelete` = 0 and d.orderSource = 1 and d.orderType = 3 and d.returnFlag = 0
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId and e.itemClass = 1 and e.returnFlag is NULL
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID and g.settlementType=2 and g.`isDelete` = 0 and g.returnFlag = 0 -- 门诊挂号
where a.del_flag = 0 and a.subsequent_visit = 7
AND g.id IN (
SELECT DISTINCT g.id
FROM `thc_arrange`.`bpm_appointment` a
INNER JOIN `thc_sob`.`bpm_service_order` b on a.orderId = b.id
INNER JOIN `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id AND c.id = a.order_item_id
INNER JOIN `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id
INNER JOIN `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId
INNER JOIN `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id AND f.accountBillDetailID = e.id
INNER JOIN `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID
INNER JOIN `thc_rcm`.`pay_trade_log` h on h.settlement_id = g.id
WHERE 1=1
AND a.del_flag = 0
AND d.isDelete = 0 AND d.orderSource = 1 AND d.orderType = 3 AND d.returnFlag = 0
AND e.itemClass = 1 AND e.returnFlag is NULL
AND g.settlementType=2 AND g.`isDelete` = 0 AND g.returnFlag = 0 -- 门诊挂号
AND h.type = 1 and h.pay_state = 1 -- 支付成功
)
${if(len(deptId) == 0,"","and a.dept_id = '" + deptId + "'")}
${if(len(doctorId) == 0,"","and a.appointment_doctor_id = '" + doctorId + "'")}
) t
where 1=1
${if(len(startTime) == 0,"","AND t.create_time >= '" + startTime + "'")}
${if(len(endTime) == 0,"","AND t.create_time <= '" + endTime + "'")}
group by t.deptId,t.doctorId
) t7
on t0.deptId = t7.deptId and t0.doctorId = t7.doctorId -- ------------
-- 简易
-- ------------
left join
(
select count(1) as num,t.deptId, doctorId,t.deptName,t.create_time,t.doctorName from
(
select
a.data_source,
a.is_appoint_resource,
a.subsequent_visit,
a.dept_id as deptId,
a.appointment_doctor_id as doctorId,
a.appointment_state,
a.dept_name as deptName,
a.create_time,
a.appointment_doctor_name as doctorName,
CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
f.preFee, -- 原价
(f.preFee - f.discountFee - f.promotionBenefitFee - f.couponFee - f.itemBenefitFee - f.memberCardBenefitFee - f.itemComInvBenefitFee) * f.discount AS realFee,
f.discount
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.`order_item_id`
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id and d.`isDelete` = 0 and d.orderSource = 1 and d.orderType = 3 and d.returnFlag = 0
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId and e.itemClass = 1 and e.returnFlag is NULL
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID and g.settlementType=2 and g.`isDelete` = 0 and g.returnFlag = 0 -- 门诊挂号
where a.del_flag = 0 and a.subsequent_visit = 5
AND g.id IN (
SELECT DISTINCT g.id
FROM `thc_arrange`.`bpm_appointment` a
INNER JOIN `thc_sob`.`bpm_service_order` b on a.orderId = b.id
INNER JOIN `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id AND c.id = a.order_item_id
INNER JOIN `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id
INNER JOIN `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId
INNER JOIN `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id AND f.accountBillDetailID = e.id
INNER JOIN `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID
INNER JOIN `thc_rcm`.`pay_trade_log` h on h.settlement_id = g.id
WHERE 1=1
AND a.del_flag = 0
AND d.isDelete = 0 AND d.orderSource = 1 AND d.orderType = 3 AND d.returnFlag = 0
AND e.itemClass = 1 AND e.returnFlag is NULL
AND g.settlementType=2 AND g.`isDelete` = 0 AND g.returnFlag = 0 -- 门诊挂号
AND h.type = 1 and h.pay_state = 1 -- 支付成功
)
${if(len(deptId) == 0,"","and a.dept_id = '" + deptId + "'")}
${if(len(doctorId) == 0,"","and a.appointment_doctor_id = '" + doctorId + "'")}
) t
where 1=1
${if(len(startTime) == 0,"","AND t.create_time >= '" + startTime + "'")}
${if(len(endTime) == 0,"","AND t.create_time <= '" + endTime + "'")}
group by t.deptId,t.doctorId
) t8
on t0.deptId = t8.deptId and t0.doctorId = t8.doctorId -- ------------
-- 转诊
-- ------------
left join
(
select count(1) as num,t.deptId, doctorId,t.deptName,t.create_time,t.doctorName from
(
select
a.data_source,
a.is_appoint_resource,
a.subsequent_visit,
a.dept_id as deptId,
a.appointment_doctor_id as doctorId,
a.appointment_state,
a.dept_name as deptName,
a.create_time,
a.appointment_doctor_name as doctorName,
CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
f.preFee, -- 原价
(f.preFee - f.discountFee - f.promotionBenefitFee - f.couponFee - f.itemBenefitFee - f.memberCardBenefitFee - f.itemComInvBenefitFee) * f.discount AS realFee,
f.discount
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.`order_item_id`
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id and d.`isDelete` = 0 and d.orderSource = 1 and d.orderType = 3 and d.returnFlag = 0
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId and e.itemClass = 1 and e.returnFlag is NULL
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID and g.settlementType=2 and g.`isDelete` = 0 and g.returnFlag = 0 -- 门诊挂号
where a.del_flag = 0 and a.subsequent_visit = 2
AND g.id IN (
SELECT DISTINCT g.id
FROM `thc_arrange`.`bpm_appointment` a
INNER JOIN `thc_sob`.`bpm_service_order` b on a.orderId = b.id
INNER JOIN `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id AND c.id = a.order_item_id
INNER JOIN `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id
INNER JOIN `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId
INNER JOIN `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id AND f.accountBillDetailID = e.id
INNER JOIN `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID
INNER JOIN `thc_rcm`.`pay_trade_log` h on h.settlement_id = g.id
WHERE 1=1
AND a.del_flag = 0
AND d.isDelete = 0 AND d.orderSource = 1 AND d.orderType = 3 AND d.returnFlag = 0
AND e.itemClass = 1 AND e.returnFlag is NULL
AND g.settlementType=2 AND g.`isDelete` = 0 AND g.returnFlag = 0 -- 门诊挂号
AND h.type = 1 and h.pay_state = 1 -- 支付成功
)
${if(len(deptId) == 0,"","and a.dept_id = '" + deptId + "'")}
${if(len(doctorId) == 0,"","and a.appointment_doctor_id = '" + doctorId + "'")}
) t
where 1=1
${if(len(startTime) == 0,"","AND t.create_time >= '" + startTime + "'")}
${if(len(endTime) == 0,"","AND t.create_time <= '" + endTime + "'")}
group by t.deptId,t.doctorId
) t9
on t0.deptId = t9.deptId and t0.doctorId = t9.doctorId -- ------------
-- 疫苗
-- ------------
left join
(
select count(1) as num,t.deptId, doctorId,t.deptName,t.create_time,t.doctorName from
(
select
a.data_source,
a.is_appoint_resource,
a.subsequent_visit,
a.dept_id as deptId,
a.appointment_doctor_id as doctorId,
a.appointment_state,
a.dept_name as deptName,
a.create_time,
a.appointment_doctor_name as doctorName,
CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
f.preFee, -- 原价
(f.preFee - f.discountFee - f.promotionBenefitFee - f.couponFee - f.itemBenefitFee - f.memberCardBenefitFee - f.itemComInvBenefitFee) * f.discount AS realFee,
f.discount
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.`order_item_id`
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id and d.`isDelete` = 0 and d.orderSource = 1 and d.orderType = 3 and d.returnFlag = 0
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId and e.itemClass = 1 and e.returnFlag is NULL
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID and g.settlementType=2 and g.`isDelete` = 0 and g.returnFlag = 0 -- 门诊挂号
where a.del_flag = 0 and a.subsequent_visit = 2
AND g.id IN (
SELECT DISTINCT g.id
FROM `thc_arrange`.`bpm_appointment` a
INNER JOIN `thc_sob`.`bpm_service_order` b on a.orderId = b.id
INNER JOIN `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id AND c.id = a.order_item_id
INNER JOIN `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id
INNER JOIN `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId
INNER JOIN `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id AND f.accountBillDetailID = e.id
INNER JOIN `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID
INNER JOIN `thc_rcm`.`pay_trade_log` h on h.settlement_id = g.id
WHERE 1=1
AND a.del_flag = 0
AND d.isDelete = 0 AND d.orderSource = 1 AND d.orderType = 3 AND d.returnFlag = 0
AND e.itemClass = 1 AND e.returnFlag is NULL
AND g.settlementType=2 AND g.`isDelete` = 0 AND g.returnFlag = 0 -- 门诊挂号
AND h.type = 1 and h.pay_state = 1 -- 支付成功
)
${if(len(deptId) == 0,"","and a.dept_id = '" + deptId + "'")}
${if(len(doctorId) == 0,"","and a.appointment_doctor_id = '" + doctorId + "'")}
) t
where 1=1
${if(len(startTime) == 0,"","AND t.create_time >= '" + startTime + "'")}
${if(len(endTime) == 0,"","AND t.create_time <= '" + endTime + "'")}
group by t.deptId,t.doctorId
) t10
on t0.deptId = t10.deptId and t0.doctorId = t10.doctorId -- ------------
-- 微信数
-- ------------
left join
(
select count(1) as num,t.deptId, doctorId,t.deptName,t.create_time,t.doctorName from
(
select
a.data_source,
a.is_appoint_resource,
a.subsequent_visit,
a.dept_id as deptId,
a.appointment_doctor_id as doctorId,
a.appointment_state,
a.dept_name as deptName,
a.create_time,
a.appointment_doctor_name as doctorName,
CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
f.preFee, -- 原价
(f.preFee - f.discountFee - f.promotionBenefitFee - f.couponFee - f.itemBenefitFee - f.memberCardBenefitFee - f.itemComInvBenefitFee) * f.discount AS realFee,
f.discount
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.`order_item_id`
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id and d.`isDelete` = 0 and d.orderSource = 1 and d.orderType = 3 and d.returnFlag = 0
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId and e.itemClass = 1 and e.returnFlag is NULL
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID and g.settlementType=2 and g.`isDelete` = 0 and g.returnFlag = 0 -- 门诊挂号
where a.del_flag = 0 and a.data_source = 2
AND g.id IN (
SELECT DISTINCT g.id
FROM `thc_arrange`.`bpm_appointment` a
INNER JOIN `thc_sob`.`bpm_service_order` b on a.orderId = b.id
INNER JOIN `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id AND c.id = a.order_item_id
INNER JOIN `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id
INNER JOIN `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId
INNER JOIN `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id AND f.accountBillDetailID = e.id
INNER JOIN `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID
INNER JOIN `thc_rcm`.`pay_trade_log` h on h.settlement_id = g.id
WHERE 1=1
AND a.del_flag = 0
AND d.isDelete = 0 AND d.orderSource = 1 AND d.orderType = 3 AND d.returnFlag = 0
AND e.itemClass = 1 AND e.returnFlag is NULL
AND g.settlementType=2 AND g.`isDelete` = 0 AND g.returnFlag = 0 -- 门诊挂号
AND h.type = 1 and h.pay_state = 1 -- 支付成功
)
${if(len(deptId) == 0,"","and a.dept_id = '" + deptId + "'")}
${if(len(doctorId) == 0,"","and a.appointment_doctor_id = '" + doctorId + "'")}
) t
where 1=1
${if(len(startTime) == 0,"","AND t.create_time >= '" + startTime + "'")}
${if(len(endTime) == 0,"","AND t.create_time <= '" + endTime + "'")}
group by t.deptId,t.doctorId
) t11
on t0.deptId = t11.deptId and t0.doctorId = t11.doctorId -- ------------
-- 微信金额
-- ------------
left join
(
select round(sum(t.preFee),2) as num,t.deptId, doctorId,t.deptName,t.create_time,t.doctorName from
(
select
a.data_source,
a.is_appoint_resource,
a.subsequent_visit,
a.dept_id as deptId,
a.appointment_doctor_id as doctorId,
a.appointment_state,
a.dept_name as deptName,
a.create_time,
a.appointment_doctor_name as doctorName,
CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
f.preFee, -- 原价
(f.preFee - f.discountFee - f.promotionBenefitFee - f.couponFee - f.itemBenefitFee - f.memberCardBenefitFee - f.itemComInvBenefitFee) * f.discount AS realFee,
f.discount
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.`order_item_id`
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id and d.`isDelete` = 0 and d.orderSource = 1 and d.orderType = 3 and d.returnFlag = 0
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId and e.itemClass = 1 and e.returnFlag is NULL
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID and g.settlementType=2 and g.`isDelete` = 0 and g.returnFlag = 0 -- 门诊挂号
where a.del_flag = 0 and a.data_source = 2
AND g.id IN (
SELECT DISTINCT g.id
FROM `thc_arrange`.`bpm_appointment` a
INNER JOIN `thc_sob`.`bpm_service_order` b on a.orderId = b.id
INNER JOIN `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id AND c.id = a.order_item_id
INNER JOIN `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id
INNER JOIN `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId
INNER JOIN `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id AND f.accountBillDetailID = e.id
INNER JOIN `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID
INNER JOIN `thc_rcm`.`pay_trade_log` h on h.settlement_id = g.id
WHERE 1=1
AND a.del_flag = 0
AND d.isDelete = 0 AND d.orderSource = 1 AND d.orderType = 3 AND d.returnFlag = 0
AND e.itemClass = 1 AND e.returnFlag is NULL
AND g.settlementType=2 AND g.`isDelete` = 0 AND g.returnFlag = 0 -- 门诊挂号
AND h.type = 1 and h.pay_state = 1 AND h.pay_method = 4 -- 微信支付成功
)
${if(len(deptId) == 0,"","and a.dept_id = '" + deptId + "'")}
${if(len(doctorId) == 0,"","and a.appointment_doctor_id = '" + doctorId + "'")}
) t
where 1=1
${if(len(startTime) == 0,"","AND t.create_time >= '" + startTime + "'")}
${if(len(endTime) == 0,"","AND t.create_time <= '" + endTime + "'")}
group by t.deptId,t.doctorId
) t12
on t0.deptId = t12.deptId and t0.doctorId = t12.doctorId -- ------------
-- 应收金额 t12
-- ------------
left join
(
select round(sum(t.preFee),2) as num,t.deptId, doctorId,t.deptName,t.create_time,t.doctorName from
(
select
a.data_source,
a.is_appoint_resource,
a.subsequent_visit,
a.dept_id as deptId,
a.appointment_doctor_id as doctorId,
a.appointment_state,
a.dept_name as deptName,
a.create_time,
a.appointment_doctor_name as doctorName,
CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
f.preFee, -- 原价
(f.preFee - f.discountFee - f.promotionBenefitFee - f.couponFee - f.itemBenefitFee - f.memberCardBenefitFee - f.itemComInvBenefitFee) * f.discount AS realFee,
f.discount
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.`order_item_id`
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id and d.`isDelete` = 0 and d.orderSource = 1 and d.orderType = 3 and d.returnFlag = 0
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId and e.itemClass = 1 and e.returnFlag is NULL
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID and g.settlementType=2 and g.`isDelete` = 0 and g.returnFlag = 0 -- 门诊挂号
where a.del_flag = 0
AND g.id IN (
SELECT DISTINCT g.id
FROM `thc_arrange`.`bpm_appointment` a
INNER JOIN `thc_sob`.`bpm_service_order` b on a.orderId = b.id
INNER JOIN `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id AND c.id = a.order_item_id
INNER JOIN `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id
INNER JOIN `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId
INNER JOIN `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id AND f.accountBillDetailID = e.id
INNER JOIN `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID
INNER JOIN `thc_rcm`.`pay_trade_log` h on h.settlement_id = g.id
WHERE 1=1
AND a.del_flag = 0
AND d.isDelete = 0 AND d.orderSource = 1 AND d.orderType = 3 AND d.returnFlag = 0
AND e.itemClass = 1 AND e.returnFlag is NULL
AND g.settlementType=2 AND g.`isDelete` = 0 AND g.returnFlag = 0 -- 门诊挂号
AND h.type = 1 and h.pay_state = 1 -- 支付成功
)
${if(len(deptId) == 0,"","and a.dept_id = '" + deptId + "'")}
${if(len(doctorId) == 0,"","and a.appointment_doctor_id = '" + doctorId + "'")}
) t
where 1=1
${if(len(startTime) == 0,"","AND t.create_time >= '" + startTime + "'")}
${if(len(endTime) == 0,"","AND t.create_time <= '" + endTime + "'")}
group by t.deptId,t.doctorId
) t13
on t0.deptId = t13.deptId and t0.doctorId = t13.doctorId -- ------------
-- 实收金额 t13
-- ------------
left join
(
select round(sum(t.realFee),2) as num,t.deptId, doctorId,t.deptName,t.create_time,t.doctorName from
(
select
a.data_source,
a.is_appoint_resource,
a.subsequent_visit,
a.dept_id as deptId,
a.appointment_doctor_id as doctorId,
a.appointment_state,
a.dept_name as deptName,
a.create_time,
a.appointment_doctor_name as doctorName,
CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
f.preFee,
(f.preFee - f.discountFee - f.promotionBenefitFee - f.couponFee - f.itemBenefitFee - f.memberCardBenefitFee - f.itemComInvBenefitFee) * f.discount AS realFee,
f.discount
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.`order_item_id`
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id and d.`isDelete` = 0 and d.orderSource = 1 and d.orderType = 3 and d.returnFlag = 0
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId and e.itemClass = 1 and e.returnFlag is NULL
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID and g.settlementType=2 and g.`isDelete` = 0 and g.returnFlag = 0 -- 门诊挂号
where a.del_flag = 0
AND g.id IN (
SELECT DISTINCT g.id
FROM `thc_arrange`.`bpm_appointment` a
INNER JOIN `thc_sob`.`bpm_service_order` b on a.orderId = b.id
INNER JOIN `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id AND c.id = a.order_item_id
INNER JOIN `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id
INNER JOIN `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId
INNER JOIN `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id AND f.accountBillDetailID = e.id
INNER JOIN `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID
INNER JOIN `thc_rcm`.`pay_trade_log` h on h.settlement_id = g.id
WHERE 1=1
AND a.del_flag = 0
AND d.isDelete = 0 AND d.orderSource = 1 AND d.orderType = 3 AND d.returnFlag = 0
AND e.itemClass = 1 AND e.returnFlag is NULL
AND g.settlementType=2 AND g.`isDelete` = 0 AND g.returnFlag = 0 -- 门诊挂号
AND h.type = 1 and h.pay_state = 1 -- 支付成功
)
${if(len(deptId) == 0,"","and a.dept_id = '" + deptId + "'")}
${if(len(doctorId) == 0,"","and a.appointment_doctor_id = '" + doctorId + "'")}
) t
where 1=1
${if(len(startTime) == 0,"","AND t.create_time >= '" + startTime + "'")}
${if(len(endTime) == 0,"","AND t.create_time <= '" + endTime + "'")}
group by t.deptId,t.doctorId
) t14
on t0.deptId = t14.deptId and t0.doctorId = t14.doctorId order by t0.startTime asc
5.挂号按科室统计
select
t0.deptName,
t0.deptId,
t0.startTime,
t0.endTime,
IFNULL(t0.num,0) as num0,
IFNULL(t1.num,0) as num1,
IFNULL(t2.num,0) as num2,
IFNULL(t4.num,0) as num4,
IFNULL(t5.num,0) as num5,
IFNULL(t6.num,0) as num6,
IFNULL(t7.num,0) as num7,
IFNULL(t8.num,0) as num8,
IFNULL(t9.num,0) as num9,
IFNULL(t10.num,0) as num10,
IFNULL(t11.num,0) as num11,
IFNULL(t13.num,0) as num13,
IFNULL(t14.num,0) as num14,
IFNULL(t15.num,0) as num15,
IFNULL(t16.num,0) as num16,
IFNULL(t17.num,0) as num17,
IFNULL(t18.num,0) as num18,
IFNULL(t19.num,0) as num19,
IFNULL(t20.num,0) as num20,
IFNULL(t21.num,0) as num21,
IFNULL(t22.num,0) as num22
from
-- ------------
-- 总挂号数
-- ------------
(
select t.startTime, t.endTime, count(1) as num,t.deptId, t.deptName,t.create_time from
(
select
a.data_source,
a.is_appoint_resource,
a.subsequent_visit,
a.appointment_state,
a.dept_id as deptId, a.dept_name as deptName,
a.create_time,
CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
f.preFee, -- 原价
(f.preFee - f.discountFee - f.promotionBenefitFee - f.couponFee - f.itemBenefitFee - f.memberCardBenefitFee - f.itemComInvBenefitFee) * f.discount AS realFee,
f.discount
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.order_item_id
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id and d.`isDelete` = 0 and d.orderSource = 1 and d.orderType = 3 and d.returnFlag = 0
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId and e.itemClass = 1 and e.returnFlag is NULL
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID and g.settlementType=2 and g.`isDelete` = 0 and g.returnFlag = 0 -- 门诊挂号
where 1=1 and a.del_flag = 0
and g.id in (
SELECT DISTINCT g.id
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.order_item_id
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID
inner JOIN `thc_rcm`.`pay_trade_log` h on h.settlement_id = g.id
where 1=1
and a.del_flag = 0
and d.isDelete = 0 and d.orderSource = 1 and d.orderType = 3 and d.returnFlag = 0
and e.itemClass = 1 and e.returnFlag is NULL
and g.settlementType=2 and g.`isDelete` = 0 and g.returnFlag = 0 -- 门诊挂号
and h.type = 1 and h.pay_state = 1
)
${if(len(deptId) == 0,"","and a.dept_id = '" + deptId + "'")}
${if(len(doctorId) == 0,"","and a.appointment_doctor_id = '" + doctorId + "'")}
) t
where 1=1
${if(len(startTime) == 0,"","AND t.create_time >= '" + startTime + "'")}
${if(len(endTime) == 0,"","AND t.create_time <= '" + endTime + "'")}
group by t.deptId
) t0 -- ------------
-- 退号
-- ------------
left join
(
select count(1) as num,t.deptId, t.deptName,t.create_time from
(
select
a.data_source,
a.is_appoint_resource,
a.subsequent_visit,
a.dept_id as deptId,
a.appointment_state,
a.dept_name as deptName,
a.create_time,
CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
f.preFee, -- 原价
(f.preFee - f.discountFee - f.promotionBenefitFee - f.couponFee - f.itemBenefitFee - f.memberCardBenefitFee - f.itemComInvBenefitFee) * f.discount AS realFee,
f.discount
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.order_item_id
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id and d.`isDelete` = 0 and d.orderSource = 1 and d.orderType = 3 and d.returnFlag = 0
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId and e.itemClass = 1 and e.returnFlag is NULL
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID and g.settlementType=2 and g.`isDelete` = 0 and g.returnFlag = 0 -- 门诊挂号
where 1=1 and a.del_flag = 0 AND a.appointment_state = -1
and g.id in (
SELECT DISTINCT g.id
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.order_item_id
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID
inner JOIN `thc_rcm`.`pay_trade_log` h on h.settlement_id = g.id
where 1=1
and a.del_flag = 0
and d.isDelete = 0 and d.orderSource = 1 and d.orderType = 3 and d.returnFlag = 0
and e.itemClass = 1 and e.returnFlag is NULL
and g.settlementType=2 and g.`isDelete` = 0 and g.returnFlag = 0 -- 门诊挂号
and h.type = 1 and h.pay_state = 1
)
${if(len(deptId) == 0,"","and a.dept_id = '" + deptId + "'")}
${if(len(doctorId) == 0,"","and a.appointment_doctor_id = '" + doctorId + "'")}
) t
where 1=1
${if(len(startTime) == 0,"","AND t.create_time >= '" + startTime + "'")}
${if(len(endTime) == 0,"","AND t.create_time <= '" + endTime + "'")}
group by t.deptId
) t1
on t0.deptId = t1.deptId -- ------------
-- 实际挂号数 = 初诊数 + 复诊数 + 转诊数
-- ------------
left join
(
select count(1) as num,t.deptId, t.deptName,t.create_time from
(
select
a.data_source,
a.is_appoint_resource,
a.subsequent_visit,
a.dept_id as deptId, a.appointment_state,
a.dept_name as deptName,
a.create_time,
CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
f.preFee, -- 原价
(f.preFee - f.discountFee - f.promotionBenefitFee - f.couponFee - f.itemBenefitFee - f.memberCardBenefitFee - f.itemComInvBenefitFee) * f.discount AS realFee,
f.discount
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.order_item_id
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id and d.`isDelete` = 0 and d.orderSource = 1 and d.orderType = 3 and d.returnFlag = 0
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId and e.itemClass = 1 and e.returnFlag is NULL
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID and g.settlementType=2 and g.`isDelete` = 0 and g.returnFlag = 0 -- 门诊挂号
where 1=1 and a.del_flag = 0 AND a.subsequent_visit in (0,1,2)
and g.id in (
SELECT DISTINCT g.id
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.order_item_id
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID
inner JOIN `thc_rcm`.`pay_trade_log` h on h.settlement_id = g.id
where 1=1
and a.del_flag = 0
and d.isDelete = 0 and d.orderSource = 1 and d.orderType = 3 and d.returnFlag = 0
and e.itemClass = 1 and e.returnFlag is NULL
and g.settlementType=2 and g.`isDelete` = 0 and g.returnFlag = 0 -- 门诊挂号
and h.type = 1 and h.pay_state = 1
)
${if(len(deptId) == 0,"","and a.dept_id = '" + deptId + "'")}
${if(len(doctorId) == 0,"","and a.appointment_doctor_id = '" + doctorId + "'")}
) t
where 1=1
${if(len(startTime) == 0,"","AND t.create_time >= '" + startTime + "'")}
${if(len(endTime) == 0,"","AND t.create_time <= '" + endTime + "'")}
group by t.deptId
) t2
on t0.deptId = t2.deptId -- ------------
-- 初诊
-- ------------
left join
(
select count(1) as num,t.deptId, t.deptName,t.create_time from
(
select
a.data_source,
a.is_appoint_resource,
a.subsequent_visit,
a.dept_id as deptId, a.appointment_state,
a.dept_name as deptName,
a.create_time,
CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
f.preFee, -- 原价
(f.preFee - f.discountFee - f.promotionBenefitFee - f.couponFee - f.itemBenefitFee - f.memberCardBenefitFee - f.itemComInvBenefitFee) * f.discount AS realFee,
f.discount
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.order_item_id
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id and d.`isDelete` = 0 and d.orderSource = 1 and d.orderType = 3 and d.returnFlag = 0
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId and e.itemClass = 1 and e.returnFlag is NULL
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID and g.settlementType=2 and g.`isDelete` = 0 and g.returnFlag = 0 -- 门诊挂号
where 1=1 and a.del_flag = 0 AND a.subsequent_visit = 0
and g.id in (
SELECT DISTINCT g.id
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.order_item_id
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID
inner JOIN `thc_rcm`.`pay_trade_log` h on h.settlement_id = g.id
where 1=1
and a.del_flag = 0
and d.isDelete = 0 and d.orderSource = 1 and d.orderType = 3 and d.returnFlag = 0
and e.itemClass = 1 and e.returnFlag is NULL
and g.settlementType=2 and g.`isDelete` = 0 and g.returnFlag = 0 -- 门诊挂号
and h.type = 1 and h.pay_state = 1
)
${if(len(deptId) == 0,"","and a.dept_id = '" + deptId + "'")}
${if(len(doctorId) == 0,"","and a.appointment_doctor_id = '" + doctorId + "'")}
) t
where 1=1
${if(len(startTime) == 0,"","AND t.create_time >= '" + startTime + "'")}
${if(len(endTime) == 0,"","AND t.create_time <= '" + endTime + "'")}
group by t.deptId
) t4
on t0.deptId = t4.deptId -- ------------
-- 复诊
-- ------------
left join
(
select count(1) as num,t.deptId, t.deptName,t.create_time from
(
select
a.data_source,
a.is_appoint_resource,
a.subsequent_visit,
a.dept_id as deptId, a.appointment_state,
a.dept_name as deptName,
a.create_time,
CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
f.preFee, -- 原价
(f.preFee - f.discountFee - f.promotionBenefitFee - f.couponFee - f.itemBenefitFee - f.memberCardBenefitFee - f.itemComInvBenefitFee) * f.discount AS realFee,
f.discount
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.order_item_id
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id and d.`isDelete` = 0 and d.orderSource = 1 and d.orderType = 3 and d.returnFlag = 0
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId and e.itemClass = 1 and e.returnFlag is NULL
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID and g.settlementType=2 and g.`isDelete` = 0 and g.returnFlag = 0 -- 门诊挂号
where 1=1 and a.del_flag = 0 AND a.subsequent_visit = 1
and g.id in (
SELECT DISTINCT g.id
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.order_item_id
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID
inner JOIN `thc_rcm`.`pay_trade_log` h on h.settlement_id = g.id
where 1=1
and a.del_flag = 0
and d.isDelete = 0 and d.orderSource = 1 and d.orderType = 3 and d.returnFlag = 0
and e.itemClass = 1 and e.returnFlag is NULL
and g.settlementType=2 and g.`isDelete` = 0 and g.returnFlag = 0 -- 门诊挂号
and h.type = 1 and h.pay_state = 1
)
${if(len(deptId) == 0,"","and a.dept_id = '" + deptId + "'")}
${if(len(doctorId) == 0,"","and a.appointment_doctor_id = '" + doctorId + "'")}
) t
where 1=1
${if(len(startTime) == 0,"","AND t.create_time >= '" + startTime + "'")}
${if(len(endTime) == 0,"","AND t.create_time <= '" + endTime + "'")}
group by t.deptId
) t5
on t0.deptId = t5.deptId -- ------------
-- 体检
-- ------------
left join
(
select count(1) as num,t.deptId, t.deptName,t.create_time from
(
select
a.data_source,
a.is_appoint_resource,
a.subsequent_visit,
a.dept_id as deptId, a.appointment_state,
a.dept_name as deptName,
a.create_time,
CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
f.preFee, -- 原价
(f.preFee - f.discountFee - f.promotionBenefitFee - f.couponFee - f.itemBenefitFee - f.memberCardBenefitFee - f.itemComInvBenefitFee) * f.discount AS realFee,
f.discount
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.order_item_id
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id and d.`isDelete` = 0 and d.orderSource = 1 and d.orderType = 3 and d.returnFlag = 0
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId and e.itemClass = 1 and e.returnFlag is NULL
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID and g.settlementType=2 and g.`isDelete` = 0 and g.returnFlag = 0 -- 门诊挂号
where 1=1 and a.del_flag = 0 AND a.subsequent_visit = 4
and g.id in (
SELECT DISTINCT g.id
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.order_item_id
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID
inner JOIN `thc_rcm`.`pay_trade_log` h on h.settlement_id = g.id
where 1=1
and a.del_flag = 0
and d.isDelete = 0 and d.orderSource = 1 and d.orderType = 3 and d.returnFlag = 0
and e.itemClass = 1 and e.returnFlag is NULL
and g.settlementType=2 and g.`isDelete` = 0 and g.returnFlag = 0 -- 门诊挂号
and h.type = 1 and h.pay_state = 1
)
${if(len(deptId) == 0,"","and a.dept_id = '" + deptId + "'")}
${if(len(doctorId) == 0,"","and a.appointment_doctor_id = '" + doctorId + "'")}
) t
where 1=1
${if(len(startTime) == 0,"","AND t.create_time >= '" + startTime + "'")}
${if(len(endTime) == 0,"","AND t.create_time <= '" + endTime + "'")}
group by t.deptId
) t6
on t0.deptId = t6.deptId -- ------------
-- 团队
-- ------------
left join
(
select count(1) as num,t.deptId, t.deptName,t.create_time from
(
select
a.data_source,
a.is_appoint_resource,
a.subsequent_visit,
a.dept_id as deptId, a.appointment_state,
a.dept_name as deptName,
a.create_time,
CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
f.preFee, -- 原价
(f.preFee - f.discountFee - f.promotionBenefitFee - f.couponFee - f.itemBenefitFee - f.memberCardBenefitFee - f.itemComInvBenefitFee) * f.discount AS realFee,
f.discount
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.order_item_id
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id and d.`isDelete` = 0 and d.orderSource = 1 and d.orderType = 3 and d.returnFlag = 0
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId and e.itemClass = 1 and e.returnFlag is NULL
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID and g.settlementType=2 and g.`isDelete` = 0 and g.returnFlag = 0 -- 门诊挂号
where 1=1 and a.del_flag = 0 AND a.subsequent_visit = 7
and g.id in (
SELECT DISTINCT g.id
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.order_item_id
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID
inner JOIN `thc_rcm`.`pay_trade_log` h on h.settlement_id = g.id
where 1=1
and a.del_flag = 0
and d.isDelete = 0 and d.orderSource = 1 and d.orderType = 3 and d.returnFlag = 0
and e.itemClass = 1 and e.returnFlag is NULL
and g.settlementType=2 and g.`isDelete` = 0 and g.returnFlag = 0 -- 门诊挂号
and h.type = 1 and h.pay_state = 1
)
${if(len(deptId) == 0,"","and a.dept_id = '" + deptId + "'")}
${if(len(doctorId) == 0,"","and a.appointment_doctor_id = '" + doctorId + "'")}
) t
where 1=1
${if(len(startTime) == 0,"","AND t.create_time >= '" + startTime + "'")}
${if(len(endTime) == 0,"","AND t.create_time <= '" + endTime + "'")}
group by t.deptId
) t7
on t0.deptId = t7.deptId -- ------------
-- 简易
-- ------------
left join
(
select count(1) as num,t.deptId, t.deptName,t.create_time from
(
select
a.data_source,
a.is_appoint_resource,
a.subsequent_visit,
a.dept_id as deptId, a.appointment_state,
a.dept_name as deptName,
a.create_time,
CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
f.preFee, -- 原价
(f.preFee - f.discountFee - f.promotionBenefitFee - f.couponFee - f.itemBenefitFee - f.memberCardBenefitFee - f.itemComInvBenefitFee) * f.discount AS realFee,
f.discount
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.order_item_id
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id and d.`isDelete` = 0 and d.orderSource = 1 and d.orderType = 3 and d.returnFlag = 0
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId and e.itemClass = 1 and e.returnFlag is NULL
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID and g.settlementType=2 and g.`isDelete` = 0 and g.returnFlag = 0 -- 门诊挂号
where 1=1 and a.del_flag = 0 AND a.subsequent_visit = 5
and g.id in (
SELECT DISTINCT g.id
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.order_item_id
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID
inner JOIN `thc_rcm`.`pay_trade_log` h on h.settlement_id = g.id
where 1=1
and a.del_flag = 0
and d.isDelete = 0 and d.orderSource = 1 and d.orderType = 3 and d.returnFlag = 0
and e.itemClass = 1 and e.returnFlag is NULL
and g.settlementType=2 and g.`isDelete` = 0 and g.returnFlag = 0 -- 门诊挂号
and h.type = 1 and h.pay_state = 1
)
${if(len(deptId) == 0,"","and a.dept_id = '" + deptId + "'")}
${if(len(doctorId) == 0,"","and a.appointment_doctor_id = '" + doctorId + "'")}
) t
where 1=1
${if(len(startTime) == 0,"","AND t.create_time >= '" + startTime + "'")}
${if(len(endTime) == 0,"","AND t.create_time <= '" + endTime + "'")}
group by t.deptId
) t8
on t0.deptId = t8.deptId -- ------------
-- 转诊
-- ------------
left join
(
select count(1) as num,t.deptId, t.deptName,t.create_time from
(
select
a.data_source,
a.is_appoint_resource,
a.subsequent_visit,
a.dept_id as deptId, a.appointment_state,
a.dept_name as deptName,
a.create_time,
CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
f.preFee, -- 原价
(f.preFee - f.discountFee - f.promotionBenefitFee - f.couponFee - f.itemBenefitFee - f.memberCardBenefitFee - f.itemComInvBenefitFee) * f.discount AS realFee,
f.discount
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.order_item_id
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id and d.`isDelete` = 0 and d.orderSource = 1 and d.orderType = 3 and d.returnFlag = 0
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId and e.itemClass = 1 and e.returnFlag is NULL
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID and g.settlementType=2 and g.`isDelete` = 0 and g.returnFlag = 0 -- 门诊挂号
where 1=1 and a.del_flag = 0 AND a.subsequent_visit = 2
and g.id in (
SELECT DISTINCT g.id
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.order_item_id
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID
inner JOIN `thc_rcm`.`pay_trade_log` h on h.settlement_id = g.id
where 1=1
and a.del_flag = 0
and d.isDelete = 0 and d.orderSource = 1 and d.orderType = 3 and d.returnFlag = 0
and e.itemClass = 1 and e.returnFlag is NULL
and g.settlementType=2 and g.`isDelete` = 0 and g.returnFlag = 0 -- 门诊挂号
and h.type = 1 and h.pay_state = 1
)
${if(len(deptId) == 0,"","and a.dept_id = '" + deptId + "'")}
${if(len(doctorId) == 0,"","and a.appointment_doctor_id = '" + doctorId + "'")}
) t
where 1=1
${if(len(startTime) == 0,"","AND t.create_time >= '" + startTime + "'")}
${if(len(endTime) == 0,"","AND t.create_time <= '" + endTime + "'")}
group by t.deptId
) t9
on t0.deptId = t9.deptId -- ------------
-- 疫苗
-- ------------
left join
(
select count(1) as num,t.deptId, t.deptName,t.create_time from
(
select
a.data_source,
a.is_appoint_resource,
a.subsequent_visit,
a.dept_id as deptId, a.appointment_state,
a.dept_name as deptName,
a.create_time,
CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
f.preFee, -- 原价
(f.preFee - f.discountFee - f.promotionBenefitFee - f.couponFee - f.itemBenefitFee - f.memberCardBenefitFee - f.itemComInvBenefitFee) * f.discount AS realFee,
f.discount
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.order_item_id
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id and d.`isDelete` = 0 and d.orderSource = 1 and d.orderType = 3 and d.returnFlag = 0
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId and e.itemClass = 1 and e.returnFlag is NULL
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID and g.settlementType=2 and g.`isDelete` = 0 and g.returnFlag = 0 -- 门诊挂号
where 1=1 and a.del_flag = 0 AND a.subsequent_visit = 2
and g.id in (
SELECT DISTINCT g.id
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.order_item_id
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID
inner JOIN `thc_rcm`.`pay_trade_log` h on h.settlement_id = g.id
where 1=1
and a.del_flag = 0
and d.isDelete = 0 and d.orderSource = 1 and d.orderType = 3 and d.returnFlag = 0
and e.itemClass = 1 and e.returnFlag is NULL
and g.settlementType=2 and g.`isDelete` = 0 and g.returnFlag = 0 -- 门诊挂号
and h.type = 1 and h.pay_state = 1
)
${if(len(deptId) == 0,"","and a.dept_id = '" + deptId + "'")}
${if(len(doctorId) == 0,"","and a.appointment_doctor_id = '" + doctorId + "'")}
) t
where 1=1
${if(len(startTime) == 0,"","AND t.create_time >= '" + startTime + "'")}
${if(len(endTime) == 0,"","AND t.create_time <= '" + endTime + "'")}
group by t.deptId
) t10
on t0.deptId = t10.deptId -- ------------
-- t11 微信数
-- ------------
left join
(
select count(1) as num,t.deptId, t.deptName,t.create_time from
(
select
a.data_source,
a.is_appoint_resource,
a.subsequent_visit,
a.dept_id as deptId, a.appointment_state,
a.dept_name as deptName,
a.create_time,
CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
f.preFee, -- 原价
(f.preFee - f.discountFee - f.promotionBenefitFee - f.couponFee - f.itemBenefitFee - f.memberCardBenefitFee - f.itemComInvBenefitFee) * f.discount AS realFee,
f.discount
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.order_item_id
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id and d.`isDelete` = 0 and d.orderSource = 1 and d.orderType = 3 and d.returnFlag = 0
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId and e.itemClass = 1 and e.returnFlag is NULL
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID and g.settlementType=2 and g.`isDelete` = 0 and g.returnFlag = 0 -- 门诊挂号
where 1=1 and a.del_flag = 0 AND a.data_source = 2
and g.id in (
SELECT DISTINCT g.id
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.order_item_id
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID
inner JOIN `thc_rcm`.`pay_trade_log` h on h.settlement_id = g.id
where 1=1
and a.del_flag = 0
and d.isDelete = 0 and d.orderSource = 1 and d.orderType = 3 and d.returnFlag = 0
and e.itemClass = 1 and e.returnFlag is NULL
and g.settlementType=2 and g.`isDelete` = 0 and g.returnFlag = 0 -- 门诊挂号
and h.type = 1 and h.pay_state = 1
)
${if(len(deptId) == 0,"","and a.dept_id = '" + deptId + "'")}
${if(len(doctorId) == 0,"","and a.appointment_doctor_id = '" + doctorId + "'")}
) t
where 1=1
${if(len(startTime) == 0,"","AND t.create_time >= '" + startTime + "'")}
${if(len(endTime) == 0,"","AND t.create_time <= '" + endTime + "'")}
group by t.deptId
) t11
on t0.deptId = t11.deptId -- ------------
-- 挂号费 t13
-- ------------
left join
(
select round(sum(t.preFee),2) as num,t.deptId, t.deptName,t.create_time from
(
select
a.data_source,
a.is_appoint_resource,
a.subsequent_visit,
a.dept_id as deptId, a.appointment_state,
a.dept_name as deptName,
a.create_time,
CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
f.preFee, -- 原价
(f.preFee - f.discountFee - f.promotionBenefitFee - f.couponFee - f.itemBenefitFee - f.memberCardBenefitFee - f.itemComInvBenefitFee) * f.discount AS realFee,
f.discount
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.order_item_id
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id and d.`isDelete` = 0 and d.orderSource = 1 and d.orderType = 3 and d.returnFlag = 0
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId and e.itemClass = 1 and e.returnFlag is NULL
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID and g.settlementType=2 and g.`isDelete` = 0 and g.returnFlag = 0 -- 门诊挂号
where 1=1 and a.del_flag = 0
and g.id in (
SELECT DISTINCT g.id
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.order_item_id
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID
inner JOIN `thc_rcm`.`pay_trade_log` h on h.settlement_id = g.id
where 1=1
and a.del_flag = 0
and d.isDelete = 0 and d.orderSource = 1 and d.orderType = 3 and d.returnFlag = 0
and e.itemClass = 1 and e.returnFlag is NULL
and g.settlementType=2 and g.`isDelete` = 0 and g.returnFlag = 0 -- 门诊挂号
and h.type = 1 and h.pay_state = 1
)
${if(len(deptId) == 0,"","and a.dept_id = '" + deptId + "'")}
${if(len(doctorId) == 0,"","and a.appointment_doctor_id = '" + doctorId + "'")}
) t
where 1=1
${if(len(startTime) == 0,"","AND t.create_time >= '" + startTime + "'")}
${if(len(endTime) == 0,"","AND t.create_time <= '" + endTime + "'")}
group by t.deptId
) t13
on t0.deptId = t13.deptId -- ------------
-- 急诊费 t14
-- ------------
left join
(
select round(sum(t.preFee),2) as num,t.deptId, t.deptName,t.create_time from
(
select
a.data_source,
a.is_appoint_resource,
a.subsequent_visit,
a.dept_id as deptId, a.appointment_state,
a.dept_name as deptName,
a.create_time,
CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
f.preFee, -- 原价
(f.preFee - f.discountFee - f.promotionBenefitFee - f.couponFee - f.itemBenefitFee - f.memberCardBenefitFee - f.itemComInvBenefitFee) * f.discount AS realFee,
f.discount
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id and b.del_flag = 0
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.`order_item_id` AND c.del_flag = 0
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id and d.`isDelete` = 0
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId and e.isDelete = 0
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id and e.isDelete = 0
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID and g.settlementType=2 and g.`isDelete` = 0 -- 门诊挂号
where 1=1 and a.del_flag = 0 AND e.itemCode = 'jiajifei' -- 加急费:急诊费
and g.id in (
SELECT DISTINCT g.id
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.order_item_id
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID
inner JOIN `thc_rcm`.`pay_trade_log` h on h.settlement_id = g.id
where 1=1
and a.del_flag = 0
and d.isDelete = 0 and d.orderSource = 1 and d.orderType = 3 and d.returnFlag = 0
and e.itemClass = 1 and e.returnFlag is NULL
and g.settlementType=2 and g.`isDelete` = 0 and g.returnFlag = 0 -- 门诊挂号
and h.type = 1 and h.pay_state = 1
)
${if(len(deptId) == 0,"","and a.dept_id = '" + deptId + "'")}
${if(len(doctorId) == 0,"","and a.appointment_doctor_id = '" + doctorId + "'")}
) t
where 1=1
${if(len(startTime) == 0,"","AND t.create_time >= '" + startTime + "'")}
${if(len(endTime) == 0,"","AND t.create_time <= '" + endTime + "'")}
group by t.deptId
) t14
on t0.deptId = t14.deptId -- ------------
-- 工本费 t15
-- ------------
left join
(
select round(sum(t.preFee),2) as num,t.deptId, t.deptName,t.create_time from
(
select
a.data_source,
a.is_appoint_resource,
a.subsequent_visit,
a.dept_id as deptId, a.appointment_state,
a.dept_name as deptName,
a.create_time,
CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
f.preFee, -- 原价
(f.preFee - f.discountFee - f.promotionBenefitFee - f.couponFee - f.itemBenefitFee - f.memberCardBenefitFee - f.itemComInvBenefitFee) * f.discount AS realFee,
f.discount
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.order_item_id
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id and d.`isDelete` = 0 and d.orderSource = 1 and d.orderType = 3 and d.returnFlag = 0
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId and e.itemClass = 1 and e.returnFlag is NULL
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID and g.settlementType=2 and g.`isDelete` = 0 and g.returnFlag = 0 -- 门诊挂号
where 1=1 and a.del_flag = 0 AND e.itemCode = 'bingliben' -- 病历本:工本费
and g.id in (
SELECT DISTINCT g.id
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.order_item_id
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID
inner JOIN `thc_rcm`.`pay_trade_log` h on h.settlement_id = g.id
where 1=1
and a.del_flag = 0
and d.isDelete = 0 and d.orderSource = 1 and d.orderType = 3 and d.returnFlag = 0
and e.itemClass = 1 and e.returnFlag is NULL
and g.settlementType=2 and g.`isDelete` = 0 and g.returnFlag = 0 -- 门诊挂号
and h.type = 1 and h.pay_state = 1
)
${if(len(deptId) == 0,"","and a.dept_id = '" + deptId + "'")}
${if(len(doctorId) == 0,"","and a.appointment_doctor_id = '" + doctorId + "'")}
) t
where 1=1
${if(len(startTime) == 0,"","AND t.create_time >= '" + startTime + "'")}
${if(len(endTime) == 0,"","AND t.create_time <= '" + endTime + "'")}
) t15
on t0.deptId = t15.deptId -- ------------
-- 卡费 t16
-- ------------
left join
(
select round(sum(t.preFee),2) as num,t.deptId, t.deptName,t.create_time from
(
select
a.data_source,
a.is_appoint_resource,
a.subsequent_visit,
a.dept_id as deptId, a.appointment_state,
a.dept_name as deptName,
a.create_time,
CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
f.preFee, -- 原价
(f.preFee - f.discountFee - f.promotionBenefitFee - f.couponFee - f.itemBenefitFee - f.memberCardBenefitFee - f.itemComInvBenefitFee) * f.discount AS realFee,
f.discount
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.order_item_id
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id and d.`isDelete` = 0 and d.orderSource = 1 and d.orderType = 3 and d.returnFlag = 0
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId and e.itemClass = 1 and e.returnFlag is NULL
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID and g.settlementType=2 and g.`isDelete` = 0 and g.returnFlag = 0 -- 门诊挂号
where 1=1 and a.del_flag = 0 AND e.itemCode = 'jiuzhenka' -- 就诊卡:卡费
and g.id in (
SELECT DISTINCT g.id
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.order_item_id
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID
inner JOIN `thc_rcm`.`pay_trade_log` h on h.settlement_id = g.id
where 1=1
and a.del_flag = 0
and d.isDelete = 0 and d.orderSource = 1 and d.orderType = 3 and d.returnFlag = 0
and e.itemClass = 1 and e.returnFlag is NULL
and g.settlementType=2 and g.`isDelete` = 0 and g.returnFlag = 0 -- 门诊挂号
and h.type = 1 and h.pay_state = 1
)
${if(len(deptId) == 0,"","and a.dept_id = '" + deptId + "'")}
${if(len(doctorId) == 0,"","and a.appointment_doctor_id = '" + doctorId + "'")}
) t
where 1=1
${if(len(startTime) == 0,"","AND t.create_time >= '" + startTime + "'")}
${if(len(endTime) == 0,"","AND t.create_time <= '" + endTime + "'")}
group by t.deptId
) t16
on t0.deptId = t16.deptId -- ------------
-- 现金 t17
-- ------------
left join
(
select round(sum(t.preFee),2) as num,t.deptId, t.deptName,t.create_time from
(
select
a.data_source,
a.is_appoint_resource,
a.subsequent_visit,
a.dept_id as deptId, a.appointment_state,
a.dept_name as deptName,
a.create_time,
CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
f.preFee, -- 原价
(f.preFee - f.discountFee - f.promotionBenefitFee - f.couponFee - f.itemBenefitFee - f.memberCardBenefitFee - f.itemComInvBenefitFee) * f.discount AS realFee,
f.discount,
h.flow_fee,
h.`charge`,
h.`pay_method`
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.order_item_id
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id and d.`isDelete` = 0 and d.orderSource = 1 and d.orderType = 3 and d.returnFlag = 0
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId and e.itemClass = 1 and e.returnFlag is NULL
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID and g.settlementType=2 and g.`isDelete` = 0 and g.returnFlag = 0 -- 门诊挂号
inner join `thc_rcm`.`pay_trade_log` h on h.`settlement_id` = g.id and h.type = 1
where 1=1 and a.del_flag = 0 -- 门诊
and h.type = 1 and h.pay_state = 1 and h.pay_method = 1 -- 银行卡
${if(len(deptId) == 0,"","and a.dept_id = '" + deptId + "'")}
${if(len(doctorId) == 0,"","and a.appointment_doctor_id = '" + doctorId + "'")}
) t
where 1=1
${if(len(startTime) == 0,"","AND t.create_time >= '" + startTime + "'")}
${if(len(endTime) == 0,"","AND t.create_time <= '" + endTime + "'")}
group by t.deptId
) t17
on t0.deptId = t17.deptId -- ------------
-- 银行卡 t18
-- ------------
left join
(
select round(sum(t.preFee),2) as num,t.deptId, t.deptName,t.create_time from
(
select
a.data_source,
a.is_appoint_resource,
a.subsequent_visit,
a.dept_id as deptId, a.appointment_state,
a.dept_name as deptName,
a.create_time,
CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
f.preFee, -- 原价
(f.preFee - f.discountFee - f.promotionBenefitFee - f.couponFee - f.itemBenefitFee - f.memberCardBenefitFee - f.itemComInvBenefitFee) * f.discount AS realFee,
f.discount,
h.flow_fee,
h.`charge`,
h.`pay_method`
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.order_item_id
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id and d.`isDelete` = 0 and d.orderSource = 1 and d.orderType = 3 and d.returnFlag = 0
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId and e.itemClass = 1 and e.returnFlag is NULL
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID and g.settlementType=2 and g.`isDelete` = 0 and g.returnFlag = 0 -- 门诊挂号
inner join `thc_rcm`.`pay_trade_log` h on h.`settlement_id` = g.id and h.type = 1
where 1=1 and a.del_flag = 0
and h.type = 1 and h.pay_state = 1 and h.pay_method = 2 -- 银行卡
${if(len(deptId) == 0,"","and a.dept_id = '" + deptId + "'")}
${if(len(doctorId) == 0,"","and a.appointment_doctor_id = '" + doctorId + "'")}
) t
where 1=1
${if(len(startTime) == 0,"","AND t.create_time >= '" + startTime + "'")}
${if(len(endTime) == 0,"","AND t.create_time <= '" + endTime + "'")}
group by t.deptId
) t18
on t0.deptId = t18.deptId -- ------------
-- 预检 t19
-- ------------
left join
(
select round(sum(t.preFee),2) as num,t.deptId, t.deptName,t.create_time from
(
select
a.data_source,
a.is_appoint_resource,
a.subsequent_visit,
a.dept_id as deptId, a.appointment_state,
a.dept_name as deptName,
a.create_time,
CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
f.preFee, -- 原价
(f.preFee - f.discountFee - f.promotionBenefitFee - f.couponFee - f.itemBenefitFee - f.memberCardBenefitFee - f.itemComInvBenefitFee) * f.discount AS realFee,
f.discount
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.order_item_id
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id and d.`isDelete` = 0 and d.orderSource = 1 and d.orderType = 3 and d.returnFlag = 0
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId and e.itemClass = 1 and e.returnFlag is NULL
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID and g.settlementType=2 and g.`isDelete` = 0 and g.returnFlag = 0 -- 门诊挂号 where 1=1 and a.del_flag = 0 and e.itemCode = 'yujian' -- 预检:预存款
and g.id in (
SELECT DISTINCT g.id
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.order_item_id
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID
inner JOIN `thc_rcm`.`pay_trade_log` h on h.settlement_id = g.id
where 1=1
and a.del_flag = 0
and d.isDelete = 0 and d.orderSource = 1 and d.orderType = 3 and d.returnFlag = 0
and e.itemClass = 1 and e.returnFlag is NULL
and g.settlementType=2 and g.`isDelete` = 0 and g.returnFlag = 0 -- 门诊挂号
and h.type = 1 and h.pay_state = 1
)
${if(len(deptId) == 0,"","and a.dept_id = '" + deptId + "'")}
${if(len(doctorId) == 0,"","and a.appointment_doctor_id = '" + doctorId + "'")}
) t
where 1=1
${if(len(startTime) == 0,"","AND t.create_time >= '" + startTime + "'")}
${if(len(endTime) == 0,"","AND t.create_time <= '" + endTime + "'")}
group by t.deptId
) t19
on t0.deptId = t19.deptId -- ------------
-- 微信金额t20
-- ------------
left join
(
select round(sum(t.preFee),2) as num,t.deptId, t.deptName,t.create_time from
(
select
a.data_source,
a.is_appoint_resource,
a.subsequent_visit,
a.dept_id as deptId, a.appointment_state,
a.dept_name as deptName,
a.create_time,
CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
f.preFee, -- 原价
(f.preFee - f.discountFee - f.promotionBenefitFee - f.couponFee - f.itemBenefitFee - f.memberCardBenefitFee - f.itemComInvBenefitFee) * f.discount AS realFee,
f.discount
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.order_item_id
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id and d.`isDelete` = 0 and d.orderSource = 1 and d.orderType = 3 and d.returnFlag = 0
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId and e.itemClass = 1 and e.returnFlag is NULL
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID and g.settlementType=2 and g.`isDelete` = 0 and g.returnFlag = 0 -- 门诊挂号
inner JOIN `thc_rcm`.`pay_trade_log` h on h.settlement_id = g.id
where 1=1 and a.del_flag = 0 and a.data_source = 2
and h.type = 1 and h.pay_state = 1 and h.pay_method=4
${if(len(deptId) == 0,"","and a.dept_id = '" + deptId + "'")}
${if(len(doctorId) == 0,"","and a.appointment_doctor_id = '" + doctorId + "'")}
) t
where 1=1
${if(len(startTime) == 0,"","AND t.create_time >= '" + startTime + "'")}
${if(len(endTime) == 0,"","AND t.create_time <= '" + endTime + "'")}
group by t.deptId
) t20
on t0.deptId = t20.deptId -- ------------
-- 应收金额 t21
-- ------------
left join
(
select round(sum(t.preFee),2) as num,t.deptId, t.deptName,t.create_time from
(
select
a.data_source,
a.is_appoint_resource,
a.subsequent_visit,
a.dept_id as deptId, a.appointment_state,
a.dept_name as deptName,
a.create_time,
CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
f.preFee, -- 原价
(f.preFee - f.discountFee - f.promotionBenefitFee - f.couponFee - f.itemBenefitFee - f.memberCardBenefitFee - f.itemComInvBenefitFee) * f.discount AS realFee,
f.discount
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.order_item_id
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id and d.`isDelete` = 0 and d.orderSource = 1 and d.orderType = 3 and d.returnFlag = 0
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId and e.itemClass = 1 and e.returnFlag is NULL
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID and g.settlementType=2 and g.`isDelete` = 0 and g.returnFlag = 0 -- 门诊挂号
where 1=1 and a.del_flag = 0
and g.id in (
SELECT DISTINCT g.id
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.order_item_id
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID
inner JOIN `thc_rcm`.`pay_trade_log` h on h.settlement_id = g.id
where 1=1
and a.del_flag = 0
and d.isDelete = 0 and d.orderSource = 1 and d.orderType = 3 and d.returnFlag = 0
and e.itemClass = 1 and e.returnFlag is NULL
and g.settlementType=2 and g.`isDelete` = 0 and g.returnFlag = 0 -- 门诊挂号
and h.type = 1 and h.pay_state = 1
)
${if(len(deptId) == 0,"","and a.dept_id = '" + deptId + "'")}
${if(len(doctorId) == 0,"","and a.appointment_doctor_id = '" + doctorId + "'")}
) t
where 1=1
${if(len(startTime) == 0,"","AND t.create_time >= '" + startTime + "'")}
${if(len(endTime) == 0,"","AND t.create_time <= '" + endTime + "'")}
group by t.deptId
) t21
on t0.deptId = t21.deptId -- ------------
-- 实收金额 t22
-- ------------
left join
(
select round(sum(t.realFee),2) as num,t.deptId,t.deptName,t.create_time from
(
select
a.data_source,
a.is_appoint_resource,
a.subsequent_visit,
a.dept_id as deptId, a.appointment_state,
a.dept_name as deptName,
a.create_time,
CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
f.preFee,
(f.preFee - f.discountFee - f.promotionBenefitFee - f.couponFee - f.itemBenefitFee - f.memberCardBenefitFee - f.itemComInvBenefitFee) * f.discount AS realFee,
f.discount
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.`order_item_id`
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id and d.`isDelete` = 0 and d.orderSource = 1 and d.orderType = 3 and d.returnFlag = 0
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId and e.itemClass = 1 and e.returnFlag is NULL
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID and g.settlementType=2 and g.`isDelete` = 0 and g.returnFlag = 0 -- 门诊挂号
where 1=1 and a.del_flag = 0
and g.id in (
SELECT DISTINCT g.id
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.order_item_id
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID
inner JOIN `thc_rcm`.`pay_trade_log` h on h.settlement_id = g.id
where 1=1
and a.del_flag = 0
and d.isDelete = 0 and d.orderSource = 1 and d.orderType = 3 and d.returnFlag = 0
and e.itemClass = 1 and e.returnFlag is NULL
and g.settlementType=2 and g.`isDelete` = 0 and g.returnFlag = 0 -- 门诊挂号
and h.type = 1 and h.pay_state = 1
)
${if(len(deptId) == 0,"","and a.dept_id = '" + deptId + "'")}
${if(len(doctorId) == 0,"","and a.appointment_doctor_id = '" + doctorId + "'")}
) t
where 1=1
${if(len(startTime) == 0,"","AND t.create_time >= '" + startTime + "'")}
${if(len(endTime) == 0,"","AND t.create_time <= '" + endTime + "'")}
group by t.deptId
) t22
on t0.deptId = t22.deptId order by t0.startTime asc
海南医院帆软报表 最终版本SQL的更多相关文章
- 帆软报表FineReport SQLServer数据库连接失败常见解决方案
1. 问题描述 帆软报表FineReport客户端连接SQLServer(2000.2005等),常常会出现如下错误:com.microsoft.sqlserver.jdbc.SQLServerExc ...
- 帆软报表FineReport中数据连接之Websphere配置JNDI连接
以oracle9i数据源制作的模板jndi.cpt为例来说明如何在FineReport中的Websphere配置JNDI连接.由于常用服务器的JNDI驱动过大,帆软报表FineReport中没有自带, ...
- 帆软报表FineReport中数据连接之Tomcat配置JNDI连接
1. 问题描述 在帆软报表FineReport中,通过JNDI方式定义数据连接,首先在Tomcat服务器配置好JNDI,然后在设计器中直接调用JNDI的名字,即可成功使用JNDI连接,连接步骤如下: ...
- JEECG与帆软报表集成
将FineReport 集成到自己的web项目中,生成报表,可以方便快捷的和自己的项目融合在一起.简化了利用poi的导出遇到的问题. 1.首先在FR中建立好一个模板 例如:我的这张模板是连接 ...
- 帆软报表FineReport中数据连接之Weblogic配置JNDI连接
1. 制作报表的原理 在帆软报表FineReport设计器中先用JDBC连接到数据库,建立数据库连接,然后用SQL或者其他方法创建数据集,使用数据集制作报表,然后把建立的数据库连接从JDBC连接改成J ...
- 帆软报表FineReport中数据连接之Jboss配置JNDI连接
使用sqlsever 2000数据库数据源来做实例讲解,帆软报表FineReport数据连接中Jboss配置JNDI大概的过程和WEBSPHERE以及WEBLOGIC基本相同,用JDBC连接数据库制作 ...
- 帆软报表FineReport中数据连接的JDBC连接池属性问题
连接池原理 在帆软报表FineReport中,连接池主要由三部分组成:连接池的建立.连接池中连接使用的治理.连接池的关闭.下面就着重讨论这三部分及连接池的配置问题. 1. 连接池原理 连接池技术的核心 ...
- 帆软报表(finereport)单元格中各颜色标识的含义
帆软报表(finereport)单元格中,可根据单元格角标的颜色判断单元格进行的操作 过滤:单元格左下角黄色三角形 条件属性:单元格左上角红色三角形. 控件:单元格右侧中间的各种矩形. 左父格:单 ...
- 帆软报表(finereport)安装/配置
1.首先是安装帆软报表软件 下载地址:http://www.finereport.com/product/download 激活码注册格账号就有了 2.启动软件,新建连接数据库 点 ...
随机推荐
- Mysql 从入门到遗忘
高级数据过滤: WHERE AND OR NOT 总是与其他操作符一起使用,用在要过滤的前面. 通配符过滤: LIKE: %相当于正则中的.*?,_相当于正则中的.. $ select id from ...
- CF1139E Maximize Mex(二分图匹配,匈牙利算法)
好题.不过之前做过的[SCOI2010]连续攻击游戏跟这题一个套路,我怎么没想到…… 题目链接:CF原网 洛谷 题目大意:在一个学校有 $n$ 个学生和 $m$ 个社团,每个学生有一个非负整数能力值 ...
- textarea高度自适应自动展开
在使用之前,推荐两个比较好的事件,分别是oninput和onpropertychange,IE9以下不兼容oninput.在textarea发生变化时,可以通过监听这两个事件来触发你需要的功能. te ...
- bzoj2086 Blocks
题目链接 题面 思路 可以发现其实就是询问一个最长的区间,使得这个区间的平均数大于等于k.所以将区间内所有数字减去k,然后做一遍前缀和.只要是前缀和之差大于等于0的区间.就是满足条件的. 所以现在问题 ...
- Django(十八)Model操作补充
参考博客:http://www.cnblogs.com/wupeiqi/articles/6216618.html 1. 创建类 class UserInfo(model.Model): age = ...
- 常用的git操作
(转)仅供自己学习,特此转发记录 链接:Git命令清单
- python zip()函数的使用
解释: 后缀为zip的文件肯定都见过吧?zip是打包压缩好的一个文件,所以,zip()函数也简单的理解为打包压缩函数,将不同个数相同类型的字段结合在一起. 官方定义为:zip() 函数用于将可迭代的对 ...
- JS中的toString方法
JS中的所有对象都具有toString方法,它把一个变量隐式转换为字符串 Number类型的对象的toString()方法比较特殊,有默认模式和基模式两种 默认模式: 无论我们用什么表示法声明数字变量 ...
- 如何修改Tomcat的默认项目发布路径
tomcat默认的项目发布目录是/webapp/ROOT,如果想自定义发布目录,应该怎么办呢? 修改配置文件 首先,修改$tomcat/conf/server.xml文件. 在server.xml文件 ...
- nginx中间件
Nginx简介 Nginx是一个开源且高性能.可靠的HTTP中间件.代理服务.其特点是占有内存少,并发能力强. Nginx优势:IO多路复用epoll 1.什么是IO复用 它是内核提供的一种同时监控多 ...