患者信息SQL v1
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的更多相关文章
- PHP基础示例:商品信息管理系统v1.1
实现目标:使用php和mysql写一个商品信息管理系统,并带有购物车功能 一.创建数据库和表 1.创建数据库和表:demodb 2.创建表格:goods 字段:商品编号,商品名称,商品类型,商品图片, ...
- 获取客户信息SQL
/*取客户信息SQL*/ --客户信息 SELECT hou.name 业务实体, hca.account_number 客户编号, hp.party_name 客户名称, arp_addr_pkg. ...
- DedeCMS版权信息SQL命令删除
dedecms织梦系统底部会自动带有官方链接power by dedecms字样,很多新用户想去除官方的链接,底部调用标签为{dede:global.cfg_poweby/},方法很多,但不鼓励大家删 ...
- PHP基础示例:商品信息管理系统v1.1[转]
实现目标:使用php和mysql写一个商品信息管理系统,并带有购物车功能 一.创建数据库和表 1.创建数据库和表:demodb 2.创建表格:goods 字段:商品编号,商品名称,商品类型,商品图 ...
- 供应商和管理员查看供应商地址簿信息SQL
--管理员查看地址簿 SELECT hps.party_site_id, hps.party_site_name AS address_name, 'CURRENT' AS status, hzl.a ...
- 学生信息管理系统v1.0
昨天一个教师朋友找到我,告诉我现在学期末他工作比较忙.需要统计处理很多学生信息,想让我帮他做一个管理系统.实现的功能就是把WPS表格转化成Word文档,将每一个学生的信息都能够分开,并且要根据名字找到 ...
- Oracle EBS-SQL (SYS-13):查询DBA在系统中的打Patch的信息.SQL
查询DBA在系统中的打补丁信息 1. select * from ad_patch_drivers /*查看已经打了哪些Patch*/ 2. select * from ad_pat ...
- SQL Server查询数据库所有存储过程、触发器、索引信息SQL分享
1. 查询所有存储过程 1 select Pr_Name as [存储过程], [参数]=stuff((select ','+[Parameter] 2 from ( 3 select Pr.Name ...
- mysql查看锁等信息SQL
查看锁等信息,包括锁信息: select "HOLD:",ph.id h_processid,trh.trx_id h_trx_id,trh.trx_started h_start ...
随机推荐
- js日期格式转换的相关问题探讨
探讨问题1: 如何将 2017年8月22日 转换成 2017-8-22 / 2017-08-22呢 '2017年8月22日'.replace(/[年月日]/g,'-'); '2017年8月22日'.m ...
- docker-compose.yml(3)
ELK:version: '2' services: elasticsearch: build: context: elasticsearch/ volumes: - ./elasticsearch/ ...
- Chinese Mahjong UVA - 11210 (DFS)
先记录下每一种麻将出现的次数,然后枚举每一种可能得到的麻将,对于这个新的麻将牌,去判断可不可能胡,如果可以胡,就可以把这张牌输出出来. 因为eye只能有一张,所以这个是最好枚举的,就枚举每张牌成为ey ...
- centos7下安装vnc更改vnc默认端口号
应用场景:某些情景下,需要用的linux的桌面环境,Ubuntu的桌面性能在linux发行版中算是数一数二的,如果不熟悉Debian系统,Centos/RHEL系列也行: 我这里的场景是开发人员不 ...
- 使用python简单连接并操作数据库
python中连接并操作数据库 图示操作流程 一.使用的完整流程 # 1. 导入模块 from pymysql import connect # 2. 创建和数据库服务器的连接,自行设置 服务器地址, ...
- 编写高质量代码:改善Java程序的151个建议 --[26~36]
提防包装类型的null值 public static int testMethod(List<Integer> list) { int count = 0; for (Integer i ...
- Why I don't want use JPA anymore
转自:https://dev.to/alagrede/why-i-dont-want-use-jpa-anymore-fl Great words for what is considered by ...
- A1136. Delayed Palindrome
Consider a positive integer N written in standard notation with k+1 digits ai as ak⋯a1a0 ...
- [luogu1552][派遣]
题目链接 思路 首先肯定要树形dp,一直没想到怎么用左偏树.如果不断弹出又不断地合并复杂度不就太高了.瞄了眼题解才知道可以直接用大根树.然后记录出当前这棵左偏树的大小(树里面所有点的薪水之和)以及点的 ...
- YII 框架在windows系统下的安装
第一步,下载yiii框架 http://www.yiichina.com 第二步安装: 1.首先需要下载应用模板,分为基础模板和高级应用模板,这里我以高级应用模板为例子 : 去这里现在高级应用模板 h ...