export_data_service.go 40KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769
  1. package service
  2. import (
  3. "XT_New/models"
  4. "fmt"
  5. "github.com/jinzhu/gorm"
  6. "log"
  7. )
  8. type ExportPatient struct {
  9. ID int64 `gorm:"column:id" json:"id" form:"id"`
  10. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  11. Name string `gorm:"column:name" json:"name" form:"name"`
  12. Lapseto int64 `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
  13. Status int64 `gorm:"column:status" json:"status" form:"status"`
  14. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  15. XtCount int64 `gorm:"column:-" json:"xt_count" form:"xt_count"`
  16. SettleOrder []*SettleOrder `gorm:"ForeignKey:PatientID;AssociationForeignKey:ID" json:"orders"`
  17. }
  18. func (ExportPatient) TableName() string {
  19. return "xt_patients"
  20. }
  21. type SettleOrder struct {
  22. ID int64 `gorm:"column:id" json:"id" form:"id"`
  23. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  24. Status int64 `gorm:"column:status" json:"status" form:"status"`
  25. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  26. OrderStatus int64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  27. MdtrtId string `gorm:"column:mdtrt_id" json:"mdtrt_id" form:"mdtrt_id"`
  28. Number string `gorm:"column:number" json:"number" form:"number"`
  29. SetlId string `gorm:"column:setl_id" json:"setl_id" form:"setl_id"`
  30. Insutype string `gorm:"column:insutype" json:"insutype" form:"insutype"`
  31. SetlTime string `gorm:"column:setl_time" json:"setl_time" form:"setl_time"`
  32. MedfeeSumamt float64 `gorm:"column:medfee_sumamt" json:"medfee_sumamt" form:"medfee_sumamt"`
  33. FulamtOwnpayAmt float64 `gorm:"column:fulamt_ownpay_amt" json:"fulamt_ownpay_amt" form:"fulamt_ownpay_amt"`
  34. OverlmtSelfPay float64 `gorm:"column:overlmt_self_pay" json:"overlmt_self_pay" form:"overlmt_self_pay"`
  35. PreselfpayAmt float64 `gorm:"column:preselfpay_amt" json:"preselfpay_amt" form:"preselfpay_amt"`
  36. InscpScpAmt float64 `gorm:"column:inscp_scp_amt" json:"inscp_scp_amt" form:"inscp_scp_amt"`
  37. ActPayDedc float64 `gorm:"column:act_pay_dedc" json:"act_pay_dedc" form:"act_pay_dedc"`
  38. HifpPay float64 `gorm:"column:hifp_pay" json:"hifp_pay" form:"hifp_pay"`
  39. CvlservPay float64 `gorm:"column:cvlserv_pay" json:"cvlserv_pay" form:"cvlserv_pay"`
  40. PoolPropSelfpay float64 `gorm:"column:pool_prop_selfpay" json:"pool_prop_selfpay" form:"pool_prop_selfpay"`
  41. HifesPay float64 `gorm:"column:hifes_pay" json:"hifes_pay" form:"hifes_pay"`
  42. HifmiPay float64 `gorm:"column:hifmi_pay" json:"hifmi_pay" form:"hifmi_pay"`
  43. HifobPay float64 `gorm:"column:hifob_pay" json:"hifob_pay" form:"hifob_pay"`
  44. MafPay float64 `gorm:"column:maf_pay" json:"maf_pay" form:"maf_pay"`
  45. OthPay float64 `gorm:"column:oth_pay" json:"oth_pay" form:"oth_pay"`
  46. FundPaySumamt float64 `gorm:"column:fund_pay_sumamt" json:"fund_pay_sumamt" form:"fund_pay_sumamt"`
  47. PsnPartAmt float64 `gorm:"column:psn_part_amt" json:"psn_part_amt" form:"psn_part_amt"`
  48. AcctPay float64 `gorm:"column:acct_pay" json:"acct_pay" form:"acct_pay"`
  49. PsnCashPay float64 `gorm:"column:psn_cash_pay" json:"psn_cash_pay" form:"psn_cash_pay"`
  50. HospPartAmt float64 `gorm:"column:hosp_part_amt" json:"hosp_part_amt" form:"hosp_part_amt"`
  51. IsMedicineInsurance int64 `gorm:"column:is_medicine_insurance" json:"is_medicine_insurance" form:"is_medicine_insurance"`
  52. OrderInfo9919 []*OrderInfo9919 `gorm:"ForeignKey:OrderNumber;AssociationForeignKey:Number" json:"info"`
  53. }
  54. func (SettleOrder) TableName() string {
  55. return "his_order"
  56. }
  57. type OrderInfo9919 struct {
  58. ID int64 `gorm:"column:id" json:"id" form:"id"`
  59. OrderNumber string `gorm:"column:order_number" json:"order_number" form:"order_number"`
  60. UploadDate int64 `gorm:"column:upload_date" json:"upload_date" form:"upload_date"`
  61. AdviceId int64 `gorm:"column:advice_id" json:"advice_id" form:"advice_id"`
  62. DetItemFeeSumamt float64 `gorm:"column:det_item_fee_sumamt" json:"det_item_fee_sumamt" form:"det_item_fee_sumamt"`
  63. Cnt float64 `gorm:"column:cnt" json:"cnt" form:"cnt"`
  64. Pric float64 `gorm:"column:pric" json:"pric" form:"pric"`
  65. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  66. PricUplmtAmt float64 `gorm:"column:pric_uplmt_amt" json:"pric_uplmt_amt" form:"pric_uplmt_amt"`
  67. SelfpayProp float64 `gorm:"column:selfpay_prop" json:"selfpay_prop" form:"selfpay_prop"`
  68. FulamtOwnpayAmt float64 `gorm:"column:fulamt_ownpay_amt" json:"fulamt_ownpay_amt" form:"fulamt_ownpay_amt"`
  69. OverlmtAmt float64 `gorm:"column:overlmt_amt" json:"overlmt_amt" form:"overlmt_amt"`
  70. PreselfpayAmt float64 `gorm:"column:preselfpay_amt" json:"preselfpay_amt" form:"preselfpay_amt"`
  71. BasMednFlag string `gorm:"column:bas_medn_flag" json:"bas_medn_flag" form:"bas_medn_flag"`
  72. MedChrgitmType string `gorm:"column:med_chrgitm_type" json:"med_chrgitm_type" form:"med_chrgitm_type"`
  73. HiNegoDrugFlag string `gorm:"column:hi_nego_drug_flag" json:"hi_nego_drug_flag" form:"hi_nego_drug_flag"`
  74. Status int64 `gorm:"column:status" json:"status" form:"status"`
  75. Memo string `gorm:"column:memo" json:"memo" form:"memo"`
  76. FeedetlSn string `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
  77. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  78. InscpScpAmt float64 `gorm:"column:inscp_scp_amt" json:"inscp_scp_amt" form:"inscp_scp_amt"`
  79. DrtReimFlag string `gorm:"column:drt_reim_flag" json:"drt_reim_flag" form:"drt_reim_flag"`
  80. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  81. ListSpItemFlag string `gorm:"column:list_sp_item_flag" json:"list_sp_item_flag" form:"list_sp_item_flag"`
  82. ChldMedcFlag string `gorm:"column:chld_medc_flag" json:"chld_medc_flag" form:"chld_medc_flag"`
  83. LmtUsedFlag string `gorm:"column:lmt_used_flag" json:"lmt_used_flag" form:"lmt_used_flag"`
  84. ChrgitmLv string `gorm:"column:chrgitm_lv" json:"chrgitm_lv" form:"chrgitm_lv"`
  85. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  86. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  87. OrderId int64 `gorm:"column:order_id" json:"order_id" form:"order_id"`
  88. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  89. Type int64 `gorm:"column:type" json:"type" form:"type"`
  90. ItemId int64 `gorm:"column:item_id" json:"item_id" form:"item_id"`
  91. SettleType int64 `gorm:"column:settle_type" json:"settle_type" form:"settle_type"`
  92. }
  93. func (OrderInfo9919) TableName() string {
  94. return "his_order_info"
  95. }
  96. func GetHisOrderDetailFor310(start_time string, end_time string, org_id int64) (patients []*ExportPatient, err error) {
  97. err = readDb2.Table("xt_patients as p").Select("p.id,p.user_org_id,p.name,p.lapseto,p.status,p.id_card_no").Joins("JOIN his_order AS orders ON orders.patient_id = p.id AND orders.status = 1 AND FROM_UNIXTIME(orders.ctime) >= ? AND FROM_UNIXTIME(orders.ctime) <= ? AND orders.user_org_id = ? AND orders.order_status = 2 and orders.insutype = 310", start_time, end_time, org_id).Preload("SettleOrder", func(db *gorm.DB) *gorm.DB {
  98. return db.Where("status = 1 AND setl_time >= ? AND setl_time <= ? AND user_org_id = ? AND order_status = 2 and insutype = 310", start_time, end_time, org_id).Preload("OrderInfo9919", "status = 1").Order("ctime")
  99. }).Where("p.status = 1 AND p.user_org_id = ?", org_id).Group("id").Find(&patients).Error
  100. for _, item := range patients {
  101. var total int64
  102. readDb.Model(&models.DialysisOrder{}).Where("patient_id = ? AND status = 1 AND stage = 2 AND FROM_UNIXTIME(dialysis_date) <= ? AND FROM_UNIXTIME(dialysis_date) >= ?", item.ID, end_time, start_time).Count(&total)
  103. item.XtCount = total
  104. }
  105. return
  106. }
  107. func GetHisOrderDetailFor390(start_time string, end_time string, org_id int64) (patients []*ExportPatient, err error) {
  108. err = readDb2.Table("xt_patients as p").Select("p.id,p.user_org_id,p.name,p.lapseto,p.status,p.id_card_no").Joins("JOIN his_order AS orders ON orders.patient_id = p.id AND orders.status = 1 AND FROM_UNIXTIME(orders.ctime) >= ? AND FROM_UNIXTIME(orders.ctime) <= ? AND orders.user_org_id = ? AND orders.order_status = 2 and orders.insutype = 390", start_time, end_time, org_id).Preload("SettleOrder", func(db *gorm.DB) *gorm.DB {
  109. return db.Where("status = 1 AND setl_time >= ? AND setl_time <= ? AND user_org_id = ? AND order_status = 2 and insutype = 390", start_time, end_time, org_id).Preload("OrderInfo9919", "status = 1").Order("ctime")
  110. }).Where("p.status = 1 AND p.user_org_id = ?", org_id).Group("id").Find(&patients).Error
  111. for _, item := range patients {
  112. var total int64
  113. readDb.Model(&models.DialysisOrder{}).Where("patient_id = ? AND status = 1 AND stage = 2 AND FROM_UNIXTIME(dialysis_date) <= ? AND FROM_UNIXTIME(dialysis_date) >= ?", item.ID, end_time, start_time).Count(&total)
  114. item.XtCount = total
  115. }
  116. return
  117. }
  118. func GetHisOrderByTime(patient_id int64, start_time string, end_time string) (order []models.HisOrder, err error) {
  119. err = readDb.Model(&models.HisOrder{}).Where("patient_id = ? AND status = 1 and order_status = 2 and FROM_UNIXTIME(settle_accounts_date) >= ? and FROM_UNIXTIME(settle_accounts_date) <= ?", patient_id, start_time+" 00:00:00", end_time+" 23:59:00").Find(&order).Error
  120. return
  121. }
  122. func GetBatchHisOrderInfoByNumber(order_number string) (order []models.BatchHisOrderInfo, err error) {
  123. err = readDb.Model(&models.BatchHisOrderInfo{}).Where("order_number = ? and status = 1", order_number).Find(&order).Error
  124. return
  125. }
  126. type Results struct {
  127. SerialNo string `gorm:"column:序号"`
  128. MedicalArea string `gorm:"column:医疗区划"`
  129. CertNo string `gorm:"column:证件号码"`
  130. PsnName string `gorm:"column:姓名"`
  131. Gender string `gorm:"column:性别"`
  132. Occupation string `gorm:"column:职业"`
  133. MedicalType string `gorm:"column:医疗类别"`
  134. AdmissionTime string `gorm:"column:入院时间"`
  135. DischargeTime string `gorm:"column:出院时间"`
  136. SettlementTime string `gorm:"column:结算时间"`
  137. DischargeDiagnosis string `gorm:"column:出院诊断"`
  138. InpatientDays int `gorm:"column:住院天数"`
  139. MedicalFeeTotal float64 `gorm:"column:医疗费总额"`
  140. HifpPay float64 `gorm:"column:统筹支付金额"`
  141. ActPayDedc float64 `gorm:"column:起付线"`
  142. HifobPay float64 `gorm:"column:职工大额基金支付"`
  143. HifmiPay float64 `gorm:"column:居民大病基金支出"`
  144. HifesPay float64 `gorm:"column:企业补充"`
  145. CvlservPay float64 `gorm:"column:公务员补助"`
  146. MafPay float64 `gorm:"column:医疗救助"`
  147. OthPay float64 `gorm:"column:其他支付"`
  148. HospPartAmt float64 `gorm:"column:医院负担"`
  149. AcctPay float64 `gorm:"column:个账支付"`
  150. AcctMulaidPay float64 `gorm:"column:共济支付"`
  151. FundPaySumamt float64 `gorm:"column:基金支付金额"`
  152. PsnCashPay float64 `gorm:"column:现金支付"`
  153. }
  154. type SummaryResults struct {
  155. InsuranceType string `gorm:"column:险种类型"` // 险种类型
  156. MedicalArea string `gorm:"column:统筹区"` // 统筹区
  157. SettlementCategory string `gorm:"column:清算类别"` // 清算类别
  158. PeopleCount int `gorm:"column:人数"` // 人数
  159. VisitCount int `gorm:"column:人次"` // 人次
  160. TotalMedicalFee float64 `gorm:"column:医保费用合计"` // 医保费用合计
  161. PoolFundPay float64 `gorm:"column:统筹支付金额"` // 统筹支付金额
  162. BigDiseaseFundPay float64 `gorm:"column:大病基金支付"` // 大病基金支付
  163. PublicServantPay float64 `gorm:"column:公务员补助"` // 公务员补助
  164. MedicalAssistance float64 `gorm:"column:医疗救助"` // 医疗救助
  165. OtherPay float64 `gorm:"column:其他支付"` // 其他支付
  166. AcctPay float64 `gorm:"column:个账支付"` // 个账支付
  167. MutualAidPay float64 `gorm:"column:共济支付"` // 共济支付
  168. CashPay float64 `gorm:"column:现金支付"` // 现金支付
  169. }
  170. func GetHisOrderBy10726Detail(start_time string, end_time string) ([]Results, error) {
  171. //err = readDb.Model(&models.HisOrder10726{}).Select("").Where("setl_time >= ? and setl_time <= ? AND status = 1 and order_status = 2 and user_org_id = 10721", start_time+" 00:00:00", end_time+" 23:59:00").Find(&order).Error
  172. var result []Results
  173. readDb.Table("his_order").Select(`
  174. '' AS 序号,
  175. '乐安县' AS 医疗区划,
  176. certno AS 证件号码,
  177. psn_name AS 姓名,
  178. CASE
  179. WHEN gend = '1' THEN '男'
  180. WHEN gend = '2' THEN '女'
  181. END AS 性别,
  182. CASE
  183. WHEN psn_type IN ('14', '15') THEN '居民(成年)'
  184. END AS 职业,
  185. CASE
  186. WHEN med_type = '990101' THEN '单病种门诊'
  187. WHEN med_type = '14' THEN '门诊慢特病'
  188. END AS 医疗类别,
  189. setl_time AS 入院时间,
  190. setl_time AS 出院时间,
  191. setl_time AS 结算时间,
  192. CASE
  193. WHEN med_type = '990101' THEN '尿毒症(免费透析)'
  194. WHEN med_type = '14' THEN '尿毒症期'
  195. END AS 出院诊断,
  196. 1 AS 住院天数,
  197. medfee_sumamt AS 医疗费总额,
  198. hifp_pay AS 统筹支付金额,
  199. act_pay_dedc AS 起付线,
  200. hifob_pay AS 职工大额基金支付,
  201. hifmi_pay AS 居民大病基金支出,
  202. hifes_pay AS 企业补充,
  203. cvlserv_pay AS 公务员补助,
  204. maf_pay AS 医疗救助,
  205. oth_pay AS 其他支付,
  206. hosp_part_amt AS 医院负担,
  207. acct_pay AS 个账支付,
  208. acct_mulaid_pay AS 共济支付,
  209. fund_pay_sumamt AS 基金支付金额,
  210. psn_cash_pay AS 现金支付
  211. `).Where("user_org_id = ?", 10726).
  212. Where("order_status = ?", 2).
  213. Where("setl_time >= ?", start_time+" 00:00:00").
  214. Where("setl_time <= ?", end_time+" 23:59:59").
  215. Where("is_medicine_insurance = ?", 1).
  216. Where("status = ?", 1).
  217. Scan(&result)
  218. return result, err
  219. }
  220. func GetHisOrderBy10726Summary(start_time string, end_time string) ([]SummaryResults, error) {
  221. var result []SummaryResults
  222. err = readDb.Table("his_order").
  223. Select(`
  224. CASE
  225. WHEN insutype = "390" THEN "城乡居民"
  226. WHEN insutype = "310" THEN "职工"
  227. END AS "险种类型",
  228. "乐安县" AS 统筹区,
  229. "门诊" AS 清算类别,
  230. COUNT(DISTINCT patient_id) AS 人数,
  231. COUNT(id) AS 人次,
  232. SUM(medfee_sumamt) AS 医保费用合计,
  233. SUM(hifp_pay) AS 统筹支付金额,
  234. SUM(hifmi_pay) AS 大病基金支付,
  235. SUM(cvlserv_pay) AS 公务员补助,
  236. SUM(maf_pay) AS 医疗救助,
  237. SUM(oth_pay) AS 其他支付,
  238. SUM(acct_pay) AS 个账支付,
  239. SUM(acct_mulaid_pay) AS 共济支付,
  240. SUM(psn_cash_pay) AS 现金支付
  241. `).
  242. Where("user_org_id = ? AND order_status = ? AND setl_time >= ? AND setl_time <= ? AND is_medicine_insurance = ? AND status = ?",
  243. 10726, 2, start_time+" 00:00:00", end_time+" 23:59:59", 1, 1).
  244. Group("insutype").
  245. Scan(&result).Error
  246. return result, err
  247. }
  248. type MedicalCharges struct {
  249. SerialNo string `gorm:"column:编号"` // 编号
  250. MedicalInsuranceNo string `gorm:"column:医疗保险号"` // 医疗保险号
  251. PsnName string `gorm:"column:姓名"` // 姓名
  252. BedsFee float64 `gorm:"column:床位费"` // 床位费
  253. ConsultationFee float64 `gorm:"column:诊察费"` // 诊察费
  254. ExaminationFee float64 `gorm:"column:检查费"` // 检查费
  255. LaboratoryFee float64 `gorm:"column:化验费"` // 化验费
  256. TreatmentFee float64 `gorm:"column:治疗费"` // 治疗费
  257. NursingFee float64 `gorm:"column:护理费"` // 护理费
  258. HealthMaterialsFee float64 `gorm:"column:卫生材料费"` // 卫生材料费
  259. WesternMedicineFee float64 `gorm:"column:西药费"` // 西药费
  260. ChineseMedicineFee float64 `gorm:"column:中药饮片费"` // 中药饮片费
  261. ChinesePatentMedicineFee float64 `gorm:"column:中成药费"` // 中成药费
  262. GeneralTreatmentFee float64 `gorm:"column:一般诊疗费"` // 一般诊疗费
  263. RegistrationFee float64 `gorm:"column:挂号费"` // 挂号费
  264. OtherFee float64 `gorm:"column:其他费"` // 其他费
  265. TotalMedicalFee float64 `gorm:"column:医疗费总额"` // 医疗费总额
  266. SelfPay float64 `gorm:"column:个人自付金额"` // 个人自付金额
  267. AcctPay float64 `gorm:"column:基本账户支付"` // 基本账户支付
  268. MutualAidAcctPay float64 `gorm:"column:共济账户支付"` // 共济账户支付
  269. PublicServantPay float64 `gorm:"column:公务员补助"` // 公务员补助
  270. PoolFundPay float64 `gorm:"column:统筹支付金额"` // 统筹支付金额
  271. MedicalAssistance float64 `gorm:"column:医疗救助"` // 医疗救助
  272. BigDiseasePay float64 `gorm:"column:大病支付"` // 大病支付
  273. EnterpriseSupplement float64 `gorm:"column:企业补充支付"` // 企业补充支付
  274. MajorDiseaseSupplement float64 `gorm:"column:重大疾病补充"` // 重大疾病补充 (Empty in SQL, will be left blank in Go)
  275. OtherPayment float64 `gorm:"column:其它支付"` // 其它支付
  276. }
  277. type MedicalChargesThree struct {
  278. PatientID string `gorm:"column:ID"` // 姓名
  279. CanBaoDi string `gorm:"column:参保地"` // 姓名
  280. PsnName string `gorm:"column:姓名"` // 姓名
  281. TypeName string `gorm:"column:类型"` // 姓名
  282. Total float64 `gorm:"column:合计次数"` // 姓名
  283. XtCount float64 `gorm:"column:血透"`
  284. XlCount float64 `gorm:"column:血滤"`
  285. GlCount float64 `gorm:"column:灌流"`
  286. WesternMedicineFee float64 `gorm:"column:西药费"` // 西药费
  287. ChinesePatentMedicineFee float64 `gorm:"column:中成药费"` // 中成药费
  288. HealthMaterialsFee float64 `gorm:"column:耗材费"` // 卫生材料费
  289. RegistrationFee float64 `gorm:"column:挂号费"` // 挂号费
  290. TreatmentFee float64 `gorm:"column:治疗费"` // 治疗费
  291. ExaminationFee float64 `gorm:"column:检查费"` // 检查费
  292. LaboratoryFee float64 `gorm:"column:化验费"` // 化验费
  293. NursingFee float64 `gorm:"column:护理费"` // 护理费
  294. OtherFee float64 `gorm:"column:其他费"` // 其他费
  295. BedsFee float64 `gorm:"column:床位费"` // 床位费
  296. ConsultationFee float64 `gorm:"column:诊察费"` // 诊察费
  297. ChineseMedicineFee float64 `gorm:"column:中药饮片费"` // 中药饮片费
  298. GeneralTreatmentFee float64 `gorm:"column:一般诊疗费"` // 一般诊疗费
  299. TotalMedicalFee float64 `gorm:"column:合计"` // 医疗费总额
  300. TC float64 `gorm:"column:医保统筹基金支出"` // 医疗费总额
  301. Func float64 `gorm:"column:医保基金支付金额"` // 医疗费总额
  302. SelfPay float64 `gorm:"column:自费金额"` // 个人自付金额
  303. AcctPay float64 `gorm:"column:个人账户支付"` // 基本账户支付
  304. Return string `gorm:"column:退费"` // 共济账户支付
  305. YouHui string `gorm:"column:优惠"` // 公务员补助
  306. YingShou float64 `gorm:"column:应收"` // 统筹支付金额
  307. GuaZhang string `gorm:"column:挂账"` // 医疗救助
  308. ChongZhang string `gorm:"column:冲账"` // 大病支付
  309. ShiShou float64 `gorm:"column:实收"` // 企业补充支付
  310. YiShou float64 `gorm:"column:已收"` // 重大疾病补充 (Empty in SQL, will be left blank in Go)
  311. }
  312. func GetHisOrderBy10697Summary(start_time string, end_time string, ins string) (results []MedicalCharges, err error) {
  313. err = readDb.Table("his_order").
  314. Select(`
  315. "" AS 编号,
  316. his_order.certno AS 医疗保险号,
  317. his_order.psn_name AS 姓名,
  318. SUM(CASE WHEN i.med_chrgitm_type = '01' THEN i.det_item_fee_sumamt ELSE 0 END) AS 床位费,
  319. SUM(CASE WHEN i.med_chrgitm_type = '02' THEN i.det_item_fee_sumamt ELSE 0 END) AS 诊察费,
  320. SUM(CASE WHEN i.med_chrgitm_type = '03' THEN i.det_item_fee_sumamt ELSE 0 END) AS 检查费,
  321. SUM(CASE WHEN i.med_chrgitm_type = '04' THEN i.det_item_fee_sumamt ELSE 0 END) AS 化验费,
  322. SUM(CASE WHEN i.med_chrgitm_type = '05' THEN i.det_item_fee_sumamt ELSE 0 END) AS 治疗费,
  323. SUM(CASE WHEN i.med_chrgitm_type = '07' THEN i.det_item_fee_sumamt ELSE 0 END) AS 护理费,
  324. SUM(CASE WHEN i.med_chrgitm_type = '08' THEN i.det_item_fee_sumamt ELSE 0 END) AS 卫生材料费,
  325. SUM(CASE WHEN i.med_chrgitm_type = '09' THEN i.det_item_fee_sumamt ELSE 0 END) AS 西药费,
  326. SUM(CASE WHEN i.med_chrgitm_type = '10' THEN i.det_item_fee_sumamt ELSE 0 END) AS 中药饮片费,
  327. SUM(CASE WHEN i.med_chrgitm_type = '11' THEN i.det_item_fee_sumamt ELSE 0 END) AS 中成药费,
  328. SUM(CASE WHEN i.med_chrgitm_type = '12' THEN i.det_item_fee_sumamt ELSE 0 END) AS 一般诊疗费,
  329. SUM(CASE WHEN i.med_chrgitm_type = '13' THEN i.det_item_fee_sumamt ELSE 0 END) AS 挂号费,
  330. SUM(CASE WHEN i.med_chrgitm_type = '14' THEN i.det_item_fee_sumamt ELSE 0 END) AS 其他费,
  331. SUM(his_order.medfee_sumamt) AS 医疗费总额,
  332. SUM(his_order.psn_cash_pay) AS 个人自付金额,
  333. SUM(his_order.acct_pay) AS 基本账户支付,
  334. SUM(his_order.acct_mulaid_pay) AS 共济账户支付,
  335. SUM(his_order.cvlserv_pay) AS 公务员补助,
  336. SUM(his_order.hifp_pay) AS 统筹支付金额,
  337. SUM(his_order.maf_pay) AS 医疗救助,
  338. SUM(his_order.hifmi_pay) AS 大病支付,
  339. SUM(his_order.hifes_pay) AS 企业补充支付,
  340. 0 AS 重大疾病补充,
  341. SUM(his_order.oth_pay) AS 其它支付
  342. `).
  343. Joins("JOIN his_order_info i ON his_order.number = i.order_number").
  344. Where("his_order.user_org_id = ? AND his_order.order_status = ? AND his_order.setl_time >= ? AND his_order.setl_time <= ? AND his_order.is_medicine_insurance = ? AND his_order.insutype = ? AND his_order.STATUS = ?",
  345. 10697, 2, start_time+" 00:00:00", end_time+" 23:59:59", 1, ins, 1).
  346. Group("his_order.patient_id").
  347. Scan(&results).Error
  348. return
  349. }
  350. func GetHisOrderBy10697SummaryTwo(startTime, endTime, ins string, st_stamp, end_stamp int64) ([]MedicalCharges, error) {
  351. var results []MedicalCharges
  352. // 改为字符串数组
  353. medChargeTypes := []string{"01", "02", "03", "04", "05", "07", "08", "09", "10", "11", "12", "13", "14"}
  354. // 定义子查询
  355. subQuery := readDb.Table("his_order_info").
  356. Select(`
  357. order_number,
  358. med_chrgitm_type,
  359. SUM(det_item_fee_sumamt) AS det_item_fee_sumamt`).
  360. Where("user_org_id = ? AND STATUS = ? AND (upload_date) >= ? AND (upload_date) <= ? AND med_chrgitm_type IN (?)",
  361. 10697, 1,
  362. st_stamp,
  363. end_stamp,
  364. medChargeTypes).
  365. Group("order_number, med_chrgitm_type").
  366. SubQuery() // 作为临时表
  367. // 执行主查询
  368. err := readDb.Table("his_order").
  369. Select(`
  370. "" AS 编号,
  371. his_order.certno AS 医疗保险号,
  372. his_order.psn_name AS 姓名,
  373. SUM(CASE WHEN i.med_chrgitm_type = '01' THEN i.det_item_fee_sumamt ELSE 0 END) AS 床位费,
  374. SUM(CASE WHEN i.med_chrgitm_type = '02' THEN i.det_item_fee_sumamt ELSE 0 END) AS 诊察费,
  375. SUM(CASE WHEN i.med_chrgitm_type = '03' THEN i.det_item_fee_sumamt ELSE 0 END) AS 检查费,
  376. SUM(CASE WHEN i.med_chrgitm_type = '04' THEN i.det_item_fee_sumamt ELSE 0 END) AS 化验费,
  377. SUM(CASE WHEN i.med_chrgitm_type = '05' THEN i.det_item_fee_sumamt ELSE 0 END) AS 治疗费,
  378. SUM(CASE WHEN i.med_chrgitm_type = '07' THEN i.det_item_fee_sumamt ELSE 0 END) AS 护理费,
  379. SUM(CASE WHEN i.med_chrgitm_type = '08' THEN i.det_item_fee_sumamt ELSE 0 END) AS 卫生材料费,
  380. SUM(CASE WHEN i.med_chrgitm_type = '09' THEN i.det_item_fee_sumamt ELSE 0 END) AS 西药费,
  381. SUM(CASE WHEN i.med_chrgitm_type = '10' THEN i.det_item_fee_sumamt ELSE 0 END) AS 中药饮片费,
  382. SUM(CASE WHEN i.med_chrgitm_type = '11' THEN i.det_item_fee_sumamt ELSE 0 END) AS 中成药费,
  383. SUM(CASE WHEN i.med_chrgitm_type = '12' THEN i.det_item_fee_sumamt ELSE 0 END) AS 一般诊疗费,
  384. SUM(CASE WHEN i.med_chrgitm_type = '13' THEN i.det_item_fee_sumamt ELSE 0 END) AS 挂号费,
  385. SUM(CASE WHEN i.med_chrgitm_type = '14' THEN i.det_item_fee_sumamt ELSE 0 END) AS 其他费,
  386. SUM(distinct his_order.medfee_sumamt) AS 医疗费总额,
  387. SUM(distinct his_order.psn_cash_pay) AS 个人自付金额,
  388. SUM(distinct his_order.acct_pay) AS 基本账户支付,
  389. SUM(distinct his_order.acct_mulaid_pay) AS 共济账户支付,
  390. SUM(distinct his_order.cvlserv_pay) AS 公务员补助,
  391. SUM(distinct his_order.hifp_pay) AS 统筹支付金额,
  392. SUM(distinct his_order.maf_pay) AS 医疗救助,
  393. SUM(distinct his_order.hifmi_pay) AS 大病支付,
  394. SUM(distinct his_order.hifes_pay) AS 企业补充支付,
  395. 0 AS 重大疾病补充,
  396. SUM(distinct his_order.oth_pay) AS 其它支付
  397. `).
  398. Joins("JOIN (?) i ON his_order.number = i.order_number", subQuery). // 使用子查询
  399. Where("his_order.user_org_id = ? AND his_order.order_status = ? AND his_order.setl_time >= ? AND his_order.setl_time <= ? AND his_order.is_medicine_insurance = ? AND his_order.insutype = ? AND his_order.STATUS = ?",
  400. 10697, 2, startTime+" 00:00:00", endTime+" 23:59:59", 1, ins, 1).
  401. Group("his_order.patient_id").
  402. Scan(&results).Error
  403. if err != nil {
  404. return nil, err
  405. }
  406. return results, nil
  407. }
  408. func GetHisOrderBy10697SummaryThree(startTime, endTime string, st_stamp, end_stamp int64, org_id int64) ([]*MedicalChargesThree, error) {
  409. var results []*MedicalChargesThree
  410. // 改为字符串数组
  411. medChargeTypes := []string{"01", "02", "03", "04", "05", "07", "08", "09", "10", "11", "12", "13", "14"}
  412. // 定义子查询
  413. subQuery := readDb.Table("his_order_info").
  414. Select(`
  415. order_number,
  416. med_chrgitm_type,
  417. SUM(det_item_fee_sumamt) AS det_item_fee_sumamt`).
  418. Where("user_org_id = ? AND STATUS = ? AND (upload_date) >= ? AND (upload_date) <= ? AND med_chrgitm_type IN (?)",
  419. org_id, 1,
  420. st_stamp,
  421. end_stamp,
  422. medChargeTypes).
  423. Group("order_number, med_chrgitm_type").
  424. SubQuery() // 作为临时表
  425. // 执行主查询
  426. err := readDb.Table("his_order").
  427. Select(`p.id as ID, p.name AS 姓名,
  428. pp.insuplc_admdvs as 参保地,
  429. CASE his_order.insutype
  430. WHEN '390' THEN '城乡'
  431. WHEN '310' THEN '职工'
  432. ELSE '未知'
  433. END AS "类型",
  434. SUM(CASE i.med_chrgitm_type WHEN '09' THEN i.det_item_fee_sumamt ELSE 0 END) AS 西药费,
  435. 0 AS 成药费,
  436. SUM(CASE i.med_chrgitm_type WHEN '11' THEN i.det_item_fee_sumamt ELSE 0 END) AS 中成药费,
  437. SUM(CASE i.med_chrgitm_type WHEN '08' THEN i.det_item_fee_sumamt ELSE 0 END) AS 耗材费,
  438. SUM(CASE i.med_chrgitm_type WHEN '13' THEN i.det_item_fee_sumamt ELSE 0 END) AS 挂号费,
  439. SUM(CASE i.med_chrgitm_type WHEN '05' THEN i.det_item_fee_sumamt ELSE 0 END) AS 治疗费,
  440. SUM(CASE i.med_chrgitm_type WHEN '03' THEN i.det_item_fee_sumamt ELSE 0 END) AS 检查费,
  441. SUM(CASE i.med_chrgitm_type WHEN '04' THEN i.det_item_fee_sumamt ELSE 0 END) AS 化验费,
  442. SUM(CASE i.med_chrgitm_type WHEN '07' THEN i.det_item_fee_sumamt ELSE 0 END) AS 护理费,
  443. SUM(CASE i.med_chrgitm_type WHEN '14' THEN i.det_item_fee_sumamt ELSE 0 END) AS 其他费,
  444. 0 AS 合计, -- 移除不必要的DISTINCT
  445. 0 AS 自费金额,
  446. 0 AS 个人账户支付,
  447. 0 AS 医保报销金额,
  448. "" AS 退费,
  449. "" AS 优惠,
  450. 0 AS 应收,
  451. "" AS 挂账,
  452. "" AS 冲账,
  453. 0 AS 实收`).
  454. Joins("JOIN (?) i ON his_order.number = i.order_number", subQuery). // 使用子查询
  455. Joins("JOIN xt_patients p on p.id = his_order.patient_id and p.user_org_id = ?", org_id). // 使用子查询
  456. Joins("JOIN his_patient pp on pp.number = his_order.mdtrt_id and p.user_org_id = ?", org_id). // 使用子查询
  457. Where("his_order.user_org_id = ? AND his_order.order_status = ? AND his_order.setl_time >= ? AND his_order.setl_time <= ? AND his_order.STATUS = ?",
  458. org_id, 2, startTime+" 00:00:00", endTime+" 23:59:59", 1).
  459. Group("his_order.patient_id").
  460. Scan(&results).Error
  461. if err != nil {
  462. return nil, err
  463. }
  464. type CusTotal struct {
  465. MedfeeSumamt float64
  466. PsnCashPay float64
  467. AcctPay float64
  468. FunPay float64
  469. TcPay float64
  470. }
  471. // To store totals per patient
  472. patientTotals := make(map[string]CusTotal)
  473. var grandTotal CusTotal
  474. for _, item := range results {
  475. var tempTotal CusTotal
  476. err := readDb.Model(models.HisOrder{}).
  477. Select("sum(medfee_sumamt) as medfee_sumamt, "+
  478. "sum(psn_cash_pay) as psn_cash_pay, "+
  479. "sum(hifp_pay) as tc_pay, "+
  480. "sum(acct_pay) as acct_pay, "+
  481. "sum(fund_pay_sumamt) as fun_pay").
  482. Where("patient_id = ? and user_org_id = ? "+
  483. "and setl_time >= ? and setl_time <= ? "+
  484. "and status = 1 and order_status = 2",
  485. item.PatientID, org_id,
  486. startTime+" 00:00:00", endTime+" 23:59:59").
  487. Scan(&tempTotal).Error
  488. if err != nil {
  489. log.Printf("Error querying for patient %s: %v", item.PatientID, err)
  490. continue
  491. }
  492. // Store this patient's total
  493. patientTotals[item.PatientID] = tempTotal
  494. // Accumulate to grand total
  495. grandTotal.MedfeeSumamt += tempTotal.MedfeeSumamt
  496. grandTotal.PsnCashPay += tempTotal.PsnCashPay
  497. grandTotal.AcctPay += tempTotal.AcctPay
  498. grandTotal.FunPay += tempTotal.FunPay
  499. grandTotal.TcPay += tempTotal.TcPay
  500. }
  501. // Print totals per patient
  502. for patientID, total := range patientTotals {
  503. //fmt.Printf("Patient %s total: %+v\n", patientID, total)
  504. for _, item := range results {
  505. if patientID == item.PatientID {
  506. item.TotalMedicalFee = total.MedfeeSumamt
  507. item.SelfPay = total.PsnCashPay
  508. item.AcctPay = total.AcctPay
  509. item.YingShou = total.MedfeeSumamt
  510. item.ShiShou = total.MedfeeSumamt
  511. item.YiShou = total.PsnCashPay
  512. item.Func = total.FunPay
  513. item.TC = total.TcPay
  514. fmt.Println(item)
  515. }
  516. }
  517. }
  518. type CusTotalTwo struct {
  519. XT float64 `gorm:"column:XT"`
  520. XL float64 `gorm:"column:XL"`
  521. GL float64 `gorm:"column:GL"`
  522. }
  523. // To store totals per patient
  524. patientTotals_two := make(map[string]CusTotalTwo)
  525. var grandTotal_two CusTotalTwo
  526. for _, item := range results {
  527. if org_id == 9478 {
  528. var tempTotal CusTotalTwo
  529. readDb.Table("his_order_info as oi").Select(`
  530. COALESCE(SUM(CASE WHEN project.project_name = '血液透析(用)' THEN p.count ELSE 0 END), 0) as XT,
  531. COALESCE(SUM(CASE WHEN project.project_name = '血液透析滤过(用)' THEN p.count ELSE 0 END), 0) as XL,
  532. COALESCE(SUM(CASE WHEN project.project_name = '血液灌流(用)' THEN p.count ELSE 0 END), 0) as GL
  533. `).
  534. Joins("JOIN his_order o ON oi.order_number = o.number AND o.setl_time BETWEEN ? AND ? AND o.order_status = 2 AND o.status = 1", startTime+" 00:00:00", endTime+" 23:59:59").
  535. Joins("JOIN his_prescription_project p ON oi.project_id = p.id").
  536. Joins("LEFT JOIN xt_his_project project ON p.project_id = project.id").
  537. Joins("JOIN xt_patients pp ON oi.patient_id = pp.id").
  538. Where(`
  539. oi.patient_id = ?
  540. AND oi.project_id > 0
  541. AND oi.user_org_id = ?
  542. AND oi.upload_date >= ?
  543. AND oi.upload_date <= ?
  544. AND oi.status = 1
  545. AND p.type = 2
  546. AND project.project_name IN ('血液透析(用)','血液透析滤过(用)','血液灌流(用)')
  547. `, item.PatientID, org_id, st_stamp, end_stamp).
  548. Scan(&tempTotal)
  549. patientTotals_two[item.PatientID] = tempTotal
  550. grandTotal_two.GL += tempTotal.GL
  551. grandTotal_two.XT += tempTotal.XT
  552. grandTotal_two.XL += tempTotal.XL
  553. } else {
  554. var tempTotal CusTotalTwo
  555. readDb.Table("his_order_info as oi").Select(`
  556. COALESCE(SUM(CASE WHEN project.project_name = '血液透析' THEN p.count ELSE 0 END), 0) as XT,
  557. COALESCE(SUM(CASE WHEN project.project_name = '血液透析滤过' THEN p.count ELSE 0 END), 0) as XL,
  558. COALESCE(SUM(CASE WHEN project.project_name = '血液灌流' THEN p.count ELSE 0 END), 0) as GL
  559. `).
  560. Joins("JOIN his_order o ON oi.order_number = o.number AND o.setl_time BETWEEN ? AND ? AND o.order_status = 2 AND o.status = 1", startTime+" 00:00:00", endTime+" 23:59:59").
  561. Joins("JOIN his_prescription_project p ON oi.project_id = p.id").
  562. Joins("LEFT JOIN xt_his_project project ON p.project_id = project.id").
  563. Joins("JOIN xt_patients pp ON oi.patient_id = pp.id").
  564. Where(`
  565. oi.patient_id = ?
  566. AND oi.project_id > 0
  567. AND oi.user_org_id = ?
  568. AND oi.upload_date >= ?
  569. AND oi.upload_date <= ?
  570. AND oi.status = 1
  571. AND p.type = 2
  572. AND project.project_name IN ('血液透析','血液透析滤过','血液灌流')
  573. `, item.PatientID, org_id, st_stamp, end_stamp).
  574. Scan(&tempTotal)
  575. patientTotals_two[item.PatientID] = tempTotal
  576. grandTotal_two.GL += tempTotal.GL
  577. grandTotal_two.XT += tempTotal.XT
  578. grandTotal_two.XL += tempTotal.XL
  579. }
  580. }
  581. fmt.Println(patientTotals_two)
  582. for patientID, total := range patientTotals_two {
  583. //fmt.Printf("Patient %s total: %+v\n", patientID, total)
  584. for _, item := range results {
  585. if patientID == item.PatientID {
  586. item.Total = total.XL + total.GL + total.XT
  587. item.XtCount = total.XT
  588. item.XlCount = total.XL
  589. item.GlCount = total.GL
  590. }
  591. }
  592. }
  593. // Print grand total
  594. //fmt.Printf("Grand total for all patients: %+v\n", grandTotal)
  595. return results, nil
  596. }
  597. func GetHisOrderBySummary(startTime, endTime string, st_stamp, end_stamp int64, org_id int64) ([]MedicalChargesThree, error) {
  598. var results []MedicalChargesThree
  599. medChargeTypes := []string{"01", "02", "03", "04", "05", "07", "08", "09", "10", "11", "12", "13", "14"}
  600. // 优化后的费用聚合子查询(使用覆盖索引)
  601. subQuery := readDb.Table("his_order_info").
  602. Select(`order_number, med_chrgitm_type, SUM(det_item_fee_sumamt) AS det_item_fee_sumamt`).
  603. Where("user_org_id = ? AND status = ? AND upload_date BETWEEN ? AND ?",
  604. org_id, 1, st_stamp, end_stamp).
  605. Where("med_chrgitm_type IN (?)", medChargeTypes).
  606. Group("order_number, med_chrgitm_type").
  607. SubQuery()
  608. // 处理时间范围格式
  609. startTimeFull := fmt.Sprintf("%s 00:00:00", startTime)
  610. endTimeFull := fmt.Sprintf("%s 23:59:59", endTime)
  611. err := readDb.Table("his_order").
  612. Select(`his_order.psn_name AS 姓名,
  613. CASE his_order.insutype
  614. WHEN '390' THEN '城乡'
  615. WHEN '310' THEN '职工'
  616. ELSE '未知'
  617. END AS "类型",
  618. SUM(CASE i.med_chrgitm_type WHEN '09' THEN i.det_item_fee_sumamt ELSE 0 END) AS 西药费,
  619. 0 AS 成药费,
  620. SUM(CASE i.med_chrgitm_type WHEN '11' THEN i.det_item_fee_sumamt ELSE 0 END) AS 中成药费,
  621. SUM(CASE i.med_chrgitm_type WHEN '08' THEN i.det_item_fee_sumamt ELSE 0 END) AS 耗材费,
  622. SUM(CASE i.med_chrgitm_type WHEN '13' THEN i.det_item_fee_sumamt ELSE 0 END) AS 挂号费,
  623. SUM(CASE i.med_chrgitm_type WHEN '05' THEN i.det_item_fee_sumamt ELSE 0 END) AS 治疗费,
  624. SUM(CASE i.med_chrgitm_type WHEN '03' THEN i.det_item_fee_sumamt ELSE 0 END) AS 检查费,
  625. SUM(CASE i.med_chrgitm_type WHEN '04' THEN i.det_item_fee_sumamt ELSE 0 END) AS 化验费,
  626. SUM(CASE i.med_chrgitm_type WHEN '07' THEN i.det_item_fee_sumamt ELSE 0 END) AS 护理费,
  627. SUM(CASE i.med_chrgitm_type WHEN '14' THEN i.det_item_fee_sumamt ELSE 0 END) AS 其他费,
  628. SUM(his_order.medfee_sumamt) AS 合计, -- 移除不必要的DISTINCT
  629. SUM(his_order.psn_cash_pay) AS 自费金额,
  630. SUM(his_order.acct_pay) AS 个人账户支付,
  631. SUM(his_order.fund_pay_sumamt) AS 医保报销金额,
  632. "" AS 退费,
  633. "" AS 优惠,
  634. SUM(his_order.medfee_sumamt) AS 应收,
  635. "" AS 挂账,
  636. "" AS 冲账,
  637. SUM(his_order.medfee_sumamt) AS 实收`).
  638. Joins("JOIN (?) i ON his_order.number = i.order_number", subQuery).
  639. //Joins("LEFTJOIN (?) p ON his_order.number = p.order_number", projectJoinQuery).
  640. Where("his_order.user_org_id = ?", org_id).
  641. Where("his_order.order_status = ?", 2).
  642. Where("his_order.setl_time BETWEEN ? AND ?", startTimeFull, endTimeFull).
  643. Where("his_order.is_medicine_insurance = ?", 1).
  644. Where("his_order.status = ?", 1).
  645. Group("his_order.patient_id").
  646. Scan(&results).Error
  647. if err != nil {
  648. return nil, err
  649. }
  650. return results, nil
  651. }
  652. // 建议的索引方案(MySQL语法示例)
  653. /*
  654. -- his_order_info 表
  655. ALTER TABLE his_order_info
  656. ADD INDEX idx_org_status_upload (user_org_id, status, upload_date),
  657. ADD INDEX idx_order_medtype (order_number, med_chrgitm_type);
  658. -- his_order 表
  659. ALTER TABLE his_order
  660. ADD INDEX idx_org_status_setltime (user_org_id, order_status, setl_time),
  661. ADD INDEX idx_patient_setltime (patient_id, setl_time);
  662. -- his_prescription_project 表
  663. ALTER TABLE his_prescription_project
  664. ADD INDEX idx_org_record_project (user_org_id, record_date, project_id),
  665. ADD INDEX idx_status_project (status, project_id);
  666. -- xt_his_project 表
  667. ALTER TABLE xt_his_project
  668. ADD INDEX idx_org_project (id, user_org_id);
  669. */
  670. type MedicalChargesTwo struct {
  671. TotalMedicalFee float64 `gorm:"column:医疗费总额"` // 医疗费总额
  672. Fund float64 `gorm:"column:基金支付总金额"` // 个人自付金额
  673. AcctPay float64 `gorm:"column:个人账户支付总金额"` // 基本账户支付
  674. PsnPay float64 `gorm:"column:个人自付总金额"` // 基本账户支付
  675. PoolFundPay float64 `gorm:"column:基金统筹总金额"` // 统筹支付金额
  676. DaE float64 `gorm:"column:大额支付总金额"` // 统筹支付金额
  677. XianXing float64 `gorm:"column:先行自付总金额"` // 统筹支付金额
  678. QuanZiFei float64 `gorm:"column:全自费总金额"` // 统筹支付金额
  679. YiLiaoJiuZhu float64 `gorm:"column:医疗救助基金总额"` // 统筹支付金额
  680. DaBing float64 `gorm:"column:大病基金总额"` // 统筹支付金额
  681. GongWuYuan float64 `gorm:"column:公务员补助"` // 统筹支付金额
  682. QiYe float64 `gorm:"column:企业补充支付"` // 统筹支付金额
  683. QiTa float64 `gorm:"column:其它支付"` // 统筹支付金额
  684. }
  685. func GetHisOrderSummary(org_id int64, start_time string, end_time string) (results []MedicalChargesTwo, err error) {
  686. err = readDb.Table("his_order").
  687. Select(`
  688. SUM(his_order.medfee_sumamt) AS 医疗费总额,
  689. SUM(his_order.fund_pay_sumamt) AS 基金支付总金额,
  690. SUM(his_order.acct_pay) AS 个人账户支付总金额,
  691. SUM(his_order.psn_cash_pay) AS 个人自付总金额,
  692. SUM(his_order.hifp_pay) AS 基金统筹总金额,
  693. SUM(his_order.hifob_pay) AS 大额支付总金额,
  694. SUM(his_order.preselfpay_amt) AS 先行自付总金额,
  695. SUM(his_order.fulamt_ownpay_amt) AS 全自费总金额,
  696. SUM(his_order.maf_pay) AS 医疗救助基金总额,
  697. SUM(his_order.hifmi_pay) AS 大病支付,
  698. SUM(his_order.cvlserv_pay) AS 公务员补助,
  699. SUM(his_order.hifes_pay) AS 企业补充支付,
  700. SUM(his_order.oth_pay) AS 其它支付
  701. `).
  702. Where("his_order.user_org_id = ? AND his_order.order_status = ? AND his_order.setl_time >= ? AND his_order.setl_time <= ? AND his_order.STATUS = ?",
  703. org_id, 2, start_time+" 00:00:00", end_time+" 23:59:59", 1).
  704. Scan(&results).Error
  705. return
  706. }