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. 【转】分享两个基于MDK IDE的调试输出技巧

    我们在STM32开发调试过程中,常常需要做些直观的输出,如果手头没有相关的设备或仪器,我们可以使用 IDE自带的工具.这里分享两个基于MDK  IDE的调试输出技巧. 一.使用其自带的逻辑分析仪查看波 ...

  2. STL之set和map

    by attack666      set与map   map 内部实现是一棵红黑树 定义 key和value分别对应着两种类型 map<key, value> mp; 内部函数 直观的理 ...

  3. Expand the scale swarm 副本增减实现负载均衡

    #创建好了swarm集群后,我们可以部署一个httpd应用来了解工作情况:#执行以下命令来部署应用: docker service create --name web_server httpd --n ...

  4. zabbix3.2添加web页面监控(Web monitoring)

    应用场景: 存在一种情况:nginx或者httpd服务本身运行正常,但是网页挂了,类似于网页被黑,或者40X之类的... 可以用zabbix把web页面访问也监控起来,第一时间得知web崩溃信息并做相 ...

  5. Cannot set property 'innerHTML' of null

    异常处理汇总-前端系列 http://www.cnblogs.com/dunitian/p/4523015.html 看如下错误代码: 知道是加载的问题就好解决了

  6. 清流,获取点击的img路径

    清流: <div style="clear:both"></div> 获取img的路径到TextBox3内: //获取展示的头像的集合var _heads ...

  7. B1018. 锤子剪刀布

    大家应该都会玩“锤子剪刀布”的游戏:两人同时给出手势,胜负规则如图所示: 现给出两人的交锋记录,请统计双方的胜.平.负次数,并且给出双方分别出什么手势的胜算最大. 输入格式: 输入第1行给出正整数N( ...

  8. 第三十一篇-TextInputLayout(增强文本输入)的使用

    效果图: 密码使用的是增强文本输入类型,当密码长度小于6或者密码长度大于10的时候就会给出提示. main.xml 当添加TextInputLayout时,旁边会有一个下载符号,如果点不动,可以右键点 ...

  9. 第十二节,TensorFlow读取数据的几种方法以及队列的使用

    TensorFlow程序读取数据一共有3种方法: 供给数据(Feeding): 在TensorFlow程序运行的每一步, 让Python代码来供给数据. 从文件读取数据: 在TensorFlow图的起 ...

  10. Good Bye 2018 B. New Year and the Treasure Geolocation

    传送门 https://www.cnblogs.com/violet-acmer/p/10201535.html 题意: 在二维空间中有 n 个 obelisk 点,n 个 p 点: 存在坐标T(x, ...