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的更多相关文章

  1. 帆软报表FineReport SQLServer数据库连接失败常见解决方案

    1. 问题描述 帆软报表FineReport客户端连接SQLServer(2000.2005等),常常会出现如下错误:com.microsoft.sqlserver.jdbc.SQLServerExc ...

  2. 帆软报表FineReport中数据连接之Websphere配置JNDI连接

    以oracle9i数据源制作的模板jndi.cpt为例来说明如何在FineReport中的Websphere配置JNDI连接.由于常用服务器的JNDI驱动过大,帆软报表FineReport中没有自带, ...

  3. 帆软报表FineReport中数据连接之Tomcat配置JNDI连接

    1. 问题描述 在帆软报表FineReport中,通过JNDI方式定义数据连接,首先在Tomcat服务器配置好JNDI,然后在设计器中直接调用JNDI的名字,即可成功使用JNDI连接,连接步骤如下: ...

  4. JEECG与帆软报表集成

    将FineReport 集成到自己的web项目中,生成报表,可以方便快捷的和自己的项目融合在一起.简化了利用poi的导出遇到的问题. 1.首先在FR中建立好一个模板      例如:我的这张模板是连接 ...

  5. 帆软报表FineReport中数据连接之Weblogic配置JNDI连接

    1. 制作报表的原理 在帆软报表FineReport设计器中先用JDBC连接到数据库,建立数据库连接,然后用SQL或者其他方法创建数据集,使用数据集制作报表,然后把建立的数据库连接从JDBC连接改成J ...

  6. 帆软报表FineReport中数据连接之Jboss配置JNDI连接

    使用sqlsever 2000数据库数据源来做实例讲解,帆软报表FineReport数据连接中Jboss配置JNDI大概的过程和WEBSPHERE以及WEBLOGIC基本相同,用JDBC连接数据库制作 ...

  7. 帆软报表FineReport中数据连接的JDBC连接池属性问题

    连接池原理 在帆软报表FineReport中,连接池主要由三部分组成:连接池的建立.连接池中连接使用的治理.连接池的关闭.下面就着重讨论这三部分及连接池的配置问题. 1. 连接池原理 连接池技术的核心 ...

  8. 帆软报表(finereport)单元格中各颜色标识的含义

    帆软报表(finereport)单元格中,可根据单元格角标的颜色判断单元格进行的操作 过滤:单元格左下角黄色三角形 条件属性:单元格左上角红色三角形.  控件:单元格右侧中间的各种矩形.  左父格:单 ...

  9. 帆软报表(finereport)安装/配置

    1.首先是安装帆软报表软件 下载地址:http://www.finereport.com/product/download           激活码注册格账号就有了 2.启动软件,新建连接数据库 点 ...

随机推荐

  1. 【LOJ#6073】距离(主席树)

    [LOJ#6073]距离(主席树) 题面 LOJ 题解 两点间的距离是\(dep[x]+dep[y]-2dep[LCA]\). 那么题目要求的东西拆开维护,唯一不好做的就是\(2dep[LCA]\). ...

  2. 654. Maximum Binary Tree

    654. Maximum Binary Tree 题目大意: 意思就是给你一组数,先选一个最大的作为根,这个数左边的数组作为左子树,右边的数组作为右子树,重复上一步. 读完就知道是递归了. 这个题真尼 ...

  3. [SCOI2007]压缩(区间dp)

    神仙题,看了半天题解才看明白... 因为题目里说如果没有m,会自动默认m在最前面. 我们设计状态为dp[l][r][0/1]为在区间l到r中有没有m的最小长度. 转移:枚举我们要压缩的起点,dp[l] ...

  4. Linux的wget命令详解【转载】

    Linux wget是一个下载文件的工具,它用在命令行下.对于Linux用户是必不可少的工具,尤其对于网络管理员,经常要下载一些软件或从远程服务器恢复备份到本地服务器.如果我们使用虚拟主机,处理这样的 ...

  5. 洛谷P1880 石子合并

    经典水题....... 断环为链长度乘二,求前缀和区间DP. #include <cstdio> #include <cstring> #include <algorit ...

  6. 没有上司的舞会 codevs 1380

    上树DP,记忆化搜索. 本题老师讲的方法是直接树形DP,但是由于我对树并不够了解,什么dfs也不想尝试(虽然感觉自己可以搞),于是搞了个结构体存点以及该点的信息,用f[i][j]作为记忆化数组.以后最 ...

  7. bzoj2553 禁忌

    题目链接 题意 给出一个\(n\)个字符串的字典.对于一个字符串,他的贡献是这个字符串中最多的在字典中出现的不重叠子串的数量. 然后问一个长度为\(len\)的,字符集为前\(alphabet\)个字 ...

  8. JavaScript(JS)之Javascript对象DOM之增删改查(四)

    创建节点:var ele_a = document.createElement('a');添加节点:ele_parent.appendChild(ele_img);删除节点:ele_parent.re ...

  9. PHP数组大全

    一.数组操作的基本函数 数组的键名和值 array_values($arr);获得数组的值 array_keys($arr);获得数组的键名 array_flip($arr);数组中的值与键名互换(如 ...

  10. 第二十节,使用RNN网络拟合回声信号序列

    这一节使用TensorFlow中的函数搭建一个简单的RNN网络,使用一串随机的模拟数据作为原始信号,让RNN网络来拟合其对应的回声信号. 样本数据为一串随机的由0,1组成的数字,将其当成发射出去的一串 ...