select
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 '疫苗'
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, -- 证件号码 p.address, -- 住址
p.household, -- 户籍
p.household_address, -- 区(户口所在地) a.patient_phone, -- 患者电话号
a.creator, -- 挂号员
(select t.docname from (
SELECT u.clinic_id AS clinicid, 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 and a.dept_id = t.clinicid) AS creater2,
a.appointment_starttime, -- 预约时间
CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
a.dept_id, -- 部门ID
a.orderId, -- 订单ID
a.order_item_id, -- 订单明细id
a.medical_card_number, -- 社保卡号
a.description, -- 备注
CASE a.data_source WHEN 1 THEN '网站' WHEN 2 THEN 'APP' END as dataSource -- 数据来源
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_passport`.`patient` p on a.patient_id = p.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` b on aa.orderId = b.id
inner join `thc_sob`.`bpm_service_order_item` cc on cc.service_order_id = b.id and cc.id = aa.`order_item_id`
inner join `thc_rcm`.`Cs_AccountBill` dd on dd.orderID = b.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 `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

SQLV2.0 20181223星期日晚

select
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 '疫苗'
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, -- 证件号码
p.address,
-- 住址 if(p.address is null,null, TRIM(BOTH '"' FROM JSON_EXTRACT(p.address,'$.province'))) as province,
if(p.address is null,null, TRIM(BOTH '"' FROM JSON_EXTRACT(p.address,'$.city'))) as city,
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, -- 户籍
if(p.household is null,null, TRIM(BOTH '"' FROM JSON_EXTRACT(p.household,'$.province'))) as province2,
if(p.household is null,null, TRIM(BOTH '"' FROM JSON_EXTRACT(p.household,'$.city'))) as city2,
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, p.household, -- 户籍 p.household_address, -- 区(户口所在地) a.patient_phone, -- 患者电话号
a.creator, -- 挂号员
(select t.docname from (
SELECT u.clinic_id AS clinicid, 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 and a.dept_id = t.clinicid) AS creater2,
a.appointment_starttime, -- 预约时间
CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
a.dept_id, -- 部门ID
a.orderId, -- 订单ID
a.order_item_id, -- 订单明细id
a.medical_card_number, -- 社保卡号
a.description, -- 备注
CASE a.data_source WHEN 1 THEN '网站' WHEN 2 THEN 'APP' END as dataSource -- 数据来源
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_passport`.`patient` p on a.patient_id = p.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` b on aa.orderId = b.id
inner join `thc_sob`.`bpm_service_order_item` cc on cc.service_order_id = b.id and cc.id = aa.`order_item_id`
inner join `thc_rcm`.`Cs_AccountBill` dd on dd.orderID = b.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 `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

患者信息SQL v1的更多相关文章

  1. PHP基础示例:商品信息管理系统v1.1

    实现目标:使用php和mysql写一个商品信息管理系统,并带有购物车功能 一.创建数据库和表 1.创建数据库和表:demodb 2.创建表格:goods 字段:商品编号,商品名称,商品类型,商品图片, ...

  2. 获取客户信息SQL

    /*取客户信息SQL*/ --客户信息 SELECT hou.name 业务实体, hca.account_number 客户编号, hp.party_name 客户名称, arp_addr_pkg. ...

  3. DedeCMS版权信息SQL命令删除

    dedecms织梦系统底部会自动带有官方链接power by dedecms字样,很多新用户想去除官方的链接,底部调用标签为{dede:global.cfg_poweby/},方法很多,但不鼓励大家删 ...

  4. PHP基础示例:商品信息管理系统v1.1[转]

      实现目标:使用php和mysql写一个商品信息管理系统,并带有购物车功能 一.创建数据库和表 1.创建数据库和表:demodb 2.创建表格:goods 字段:商品编号,商品名称,商品类型,商品图 ...

  5. 供应商和管理员查看供应商地址簿信息SQL

    --管理员查看地址簿 SELECT hps.party_site_id, hps.party_site_name AS address_name, 'CURRENT' AS status, hzl.a ...

  6. 学生信息管理系统v1.0

    昨天一个教师朋友找到我,告诉我现在学期末他工作比较忙.需要统计处理很多学生信息,想让我帮他做一个管理系统.实现的功能就是把WPS表格转化成Word文档,将每一个学生的信息都能够分开,并且要根据名字找到 ...

  7. Oracle EBS-SQL (SYS-13):查询DBA在系统中的打Patch的信息.SQL

    查询DBA在系统中的打补丁信息 1. select * from ad_patch_drivers          /*查看已经打了哪些Patch*/ 2. select * from ad_pat ...

  8. SQL Server查询数据库所有存储过程、触发器、索引信息SQL分享

    1. 查询所有存储过程 1 select Pr_Name as [存储过程], [参数]=stuff((select ','+[Parameter] 2 from ( 3 select Pr.Name ...

  9. mysql查看锁等信息SQL

    查看锁等信息,包括锁信息: select "HOLD:",ph.id h_processid,trh.trx_id h_trx_id,trh.trx_started h_start ...

随机推荐

  1. ⌈洛谷1505⌋⌈BZOJ2157⌋⌈国家集训队⌋旅游【树链剖分】

    题目链接 [洛谷] [BZOJ] 题目描述 Ray 乐忠于旅游,这次他来到了T 城.T 城是一个水上城市,一共有 N 个景点,有些景点之间会用一座桥连接.为了方便游客到达每个景点但又为了节约成本,T ...

  2. Star sky CodeForces - 835C

    用一个三维数组cnt[x][y][k]表示从(1, 1)到(x, y)亮度为k的个数,然后查询的时候就是对于每一个亮度,计算出这个亮度t秒后的亮度和当前这个亮度的个数,答案就是他们的乘积, 然后遍历每 ...

  3. 牛客练习赛28 E迎风舞 (三分查找)

    链接:https://www.nowcoder.com/acm/contest/200/E来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言5242 ...

  4. A1046. Shortest Distance

    The task is really simple: given N exits on a highway which forms a simple cycle, you are supposed t ...

  5. [luogu4309][最长上升子序列]

    题目链接 思路 因为这些数字是从小到大加进去的,所以以当前数字结尾的最长上升子序列可以从前面位置的任何一个数字转移过来.所以只要能知道每个数字最终位于哪个位置就行了. 没想到出了treap还有什么办法 ...

  6. JMeter请求执行次数 你想执行几次就执行几次

    今天介绍下JMeter如何控制请求执行次数 主要有两种方式: 方式一:通过循环控制器控制每个请求的执行次数 例如:脚本执行规律是这样的,login-->customerPage-->sea ...

  7. VMware Workstation 14 激活码

    激活码: 1.FF31K-AHZD1-H8ETZ-8WWEZ-WUUVA 2.CV7T2-6WY5Q-48EWP-ZXY7X-QGUWD

  8. c++ stl sort

    两者相等时,必须为false. 满足拟序. 群里大佬666.

  9. Methods for follow-up research of exome analysis:外显子后续分析研究思路总结

    外显子后续分析研究思路一般有以下几种(Methods for follow-up research of exome analysis): 1.对突变频率.突变类型.突变方式进行统计分析 Mutati ...

  10. 2019-1-17 script(1)

    伪终端(Pseudo Terminal)是成对的逻辑终端设备. grant  授予 tty是teletype(电传打字机)的缩写,后来便成了终端设备的代名词 虚拟终端pty(pseudo-tty) p ...