患者信息SQL v1
生活随笔
收集整理的這篇文章主要介紹了
患者信息SQL v1
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?
selectCASE 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.idWHERE 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 docnameFROM thc_warehouse.staff_record uLEFT 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, -- 部門IDa.orderId, -- 訂單IDa.order_item_id, -- 訂單明細ida.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.idleft join (select aa.id,round((ff.preFee - ff.discountFee - ff.promotionBenefitFee - ff.couponFee - ff.itemBenefitFee - ff.memberCardBenefitFee - ff.itemComInvBenefitFee) * ff.discount,2) AS realFeefrom `thc_arrange`.`bpm_appointment` aainner join `thc_sob`.`bpm_service_order` b on aa.orderId = b.idinner 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 = 0inner join `thc_rcm`.`Cs_AccountBillDetail` ee on dd.id = ee.AccountBillId and ee.itemClass = 1 and ee.returnFlag is NULLinner join `thc_rcm`.`Cs_SettlementDetail` ff on ff.accountBillID = dd.id and ff.accountBillDetailID = ee.idinner 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.idleft 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星期日晚
selectCASE 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.idWHERE 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 docnameFROM thc_warehouse.staff_record uLEFT 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, -- 部門IDa.orderId, -- 訂單IDa.order_item_id, -- 訂單明細ida.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.idleft join (select aa.id,round((ff.preFee - ff.discountFee - ff.promotionBenefitFee - ff.couponFee - ff.itemBenefitFee - ff.memberCardBenefitFee - ff.itemComInvBenefitFee) * ff.discount,2) AS realFeefrom `thc_arrange`.`bpm_appointment` aainner join `thc_sob`.`bpm_service_order` b on aa.orderId = b.idinner 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 = 0inner join `thc_rcm`.`Cs_AccountBillDetail` ee on dd.id = ee.AccountBillId and ee.itemClass = 1 and ee.returnFlag is NULLinner join `thc_rcm`.`Cs_SettlementDetail` ff on ff.accountBillID = dd.id and ff.accountBillDetailID = ee.idinner 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.idleft 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?
轉載于:https://www.cnblogs.com/guchunchao/p/10164925.html
總結
以上是生活随笔為你收集整理的患者信息SQL v1的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 侧滑抽屉菜单 FlowingDrawer
- 下一篇: mysql 主从同步配置