export_data_service.go 39KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759
  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. PsnName string `gorm:"column:姓名"` // 姓名
  280. TypeName string `gorm:"column:类型"` // 姓名
  281. Total float64 `gorm:"column:合计次数"` // 姓名
  282. XtCount float64 `gorm:"column:血透"`
  283. XlCount float64 `gorm:"column:血滤"`
  284. GlCount float64 `gorm:"column:灌流"`
  285. WesternMedicineFee float64 `gorm:"column:西药费"` // 西药费
  286. ChinesePatentMedicineFee float64 `gorm:"column:中成药费"` // 中成药费
  287. HealthMaterialsFee float64 `gorm:"column:耗材费"` // 卫生材料费
  288. RegistrationFee float64 `gorm:"column:挂号费"` // 挂号费
  289. TreatmentFee float64 `gorm:"column:治疗费"` // 治疗费
  290. ExaminationFee float64 `gorm:"column:检查费"` // 检查费
  291. LaboratoryFee float64 `gorm:"column:化验费"` // 化验费
  292. NursingFee float64 `gorm:"column:护理费"` // 护理费
  293. OtherFee float64 `gorm:"column:其他费"` // 其他费
  294. BedsFee float64 `gorm:"column:床位费"` // 床位费
  295. ConsultationFee float64 `gorm:"column:诊察费"` // 诊察费
  296. ChineseMedicineFee float64 `gorm:"column:中药饮片费"` // 中药饮片费
  297. GeneralTreatmentFee float64 `gorm:"column:一般诊疗费"` // 一般诊疗费
  298. TotalMedicalFee float64 `gorm:"column:合计"` // 医疗费总额
  299. SelfPay float64 `gorm:"column:自费金额"` // 个人自付金额
  300. AcctPay float64 `gorm:"column:个人账户支付"` // 基本账户支付
  301. Return string `gorm:"column:退费"` // 共济账户支付
  302. YouHui string `gorm:"column:优惠"` // 公务员补助
  303. YingShou float64 `gorm:"column:应收"` // 统筹支付金额
  304. GuaZhang string `gorm:"column:挂账"` // 医疗救助
  305. ChongZhang string `gorm:"column:冲账"` // 大病支付
  306. ShiShou float64 `gorm:"column:实收"` // 企业补充支付
  307. YiShou float64 `gorm:"column:已收"` // 重大疾病补充 (Empty in SQL, will be left blank in Go)
  308. }
  309. func GetHisOrderBy10697Summary(start_time string, end_time string, ins string) (results []MedicalCharges, err error) {
  310. err = readDb.Table("his_order").
  311. Select(`
  312. "" AS 编号,
  313. his_order.certno AS 医疗保险号,
  314. his_order.psn_name AS 姓名,
  315. SUM(CASE WHEN i.med_chrgitm_type = '01' THEN i.det_item_fee_sumamt ELSE 0 END) AS 床位费,
  316. SUM(CASE WHEN i.med_chrgitm_type = '02' THEN i.det_item_fee_sumamt ELSE 0 END) AS 诊察费,
  317. SUM(CASE WHEN i.med_chrgitm_type = '03' THEN i.det_item_fee_sumamt ELSE 0 END) AS 检查费,
  318. SUM(CASE WHEN i.med_chrgitm_type = '04' THEN i.det_item_fee_sumamt ELSE 0 END) AS 化验费,
  319. SUM(CASE WHEN i.med_chrgitm_type = '05' THEN i.det_item_fee_sumamt ELSE 0 END) AS 治疗费,
  320. SUM(CASE WHEN i.med_chrgitm_type = '07' THEN i.det_item_fee_sumamt ELSE 0 END) AS 护理费,
  321. SUM(CASE WHEN i.med_chrgitm_type = '08' THEN i.det_item_fee_sumamt ELSE 0 END) AS 卫生材料费,
  322. SUM(CASE WHEN i.med_chrgitm_type = '09' THEN i.det_item_fee_sumamt ELSE 0 END) AS 西药费,
  323. SUM(CASE WHEN i.med_chrgitm_type = '10' THEN i.det_item_fee_sumamt ELSE 0 END) AS 中药饮片费,
  324. SUM(CASE WHEN i.med_chrgitm_type = '11' THEN i.det_item_fee_sumamt ELSE 0 END) AS 中成药费,
  325. SUM(CASE WHEN i.med_chrgitm_type = '12' THEN i.det_item_fee_sumamt ELSE 0 END) AS 一般诊疗费,
  326. SUM(CASE WHEN i.med_chrgitm_type = '13' THEN i.det_item_fee_sumamt ELSE 0 END) AS 挂号费,
  327. SUM(CASE WHEN i.med_chrgitm_type = '14' THEN i.det_item_fee_sumamt ELSE 0 END) AS 其他费,
  328. SUM(his_order.medfee_sumamt) AS 医疗费总额,
  329. SUM(his_order.psn_cash_pay) AS 个人自付金额,
  330. SUM(his_order.acct_pay) AS 基本账户支付,
  331. SUM(his_order.acct_mulaid_pay) AS 共济账户支付,
  332. SUM(his_order.cvlserv_pay) AS 公务员补助,
  333. SUM(his_order.hifp_pay) AS 统筹支付金额,
  334. SUM(his_order.maf_pay) AS 医疗救助,
  335. SUM(his_order.hifmi_pay) AS 大病支付,
  336. SUM(his_order.hifes_pay) AS 企业补充支付,
  337. 0 AS 重大疾病补充,
  338. SUM(his_order.oth_pay) AS 其它支付
  339. `).
  340. Joins("JOIN his_order_info i ON his_order.number = i.order_number").
  341. 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 = ?",
  342. 10697, 2, start_time+" 00:00:00", end_time+" 23:59:59", 1, ins, 1).
  343. Group("his_order.patient_id").
  344. Scan(&results).Error
  345. return
  346. }
  347. func GetHisOrderBy10697SummaryTwo(startTime, endTime, ins string, st_stamp, end_stamp int64) ([]MedicalCharges, error) {
  348. var results []MedicalCharges
  349. // 改为字符串数组
  350. medChargeTypes := []string{"01", "02", "03", "04", "05", "07", "08", "09", "10", "11", "12", "13", "14"}
  351. // 定义子查询
  352. subQuery := readDb.Table("his_order_info").
  353. Select(`
  354. order_number,
  355. med_chrgitm_type,
  356. SUM(det_item_fee_sumamt) AS det_item_fee_sumamt`).
  357. Where("user_org_id = ? AND STATUS = ? AND (upload_date) >= ? AND (upload_date) <= ? AND med_chrgitm_type IN (?)",
  358. 10697, 1,
  359. st_stamp,
  360. end_stamp,
  361. medChargeTypes).
  362. Group("order_number, med_chrgitm_type").
  363. SubQuery() // 作为临时表
  364. // 执行主查询
  365. err := readDb.Table("his_order").
  366. Select(`
  367. "" AS 编号,
  368. his_order.certno AS 医疗保险号,
  369. his_order.psn_name AS 姓名,
  370. SUM(CASE WHEN i.med_chrgitm_type = '01' THEN i.det_item_fee_sumamt ELSE 0 END) AS 床位费,
  371. SUM(CASE WHEN i.med_chrgitm_type = '02' THEN i.det_item_fee_sumamt ELSE 0 END) AS 诊察费,
  372. SUM(CASE WHEN i.med_chrgitm_type = '03' THEN i.det_item_fee_sumamt ELSE 0 END) AS 检查费,
  373. SUM(CASE WHEN i.med_chrgitm_type = '04' THEN i.det_item_fee_sumamt ELSE 0 END) AS 化验费,
  374. SUM(CASE WHEN i.med_chrgitm_type = '05' THEN i.det_item_fee_sumamt ELSE 0 END) AS 治疗费,
  375. SUM(CASE WHEN i.med_chrgitm_type = '07' THEN i.det_item_fee_sumamt ELSE 0 END) AS 护理费,
  376. SUM(CASE WHEN i.med_chrgitm_type = '08' THEN i.det_item_fee_sumamt ELSE 0 END) AS 卫生材料费,
  377. SUM(CASE WHEN i.med_chrgitm_type = '09' THEN i.det_item_fee_sumamt ELSE 0 END) AS 西药费,
  378. SUM(CASE WHEN i.med_chrgitm_type = '10' THEN i.det_item_fee_sumamt ELSE 0 END) AS 中药饮片费,
  379. SUM(CASE WHEN i.med_chrgitm_type = '11' THEN i.det_item_fee_sumamt ELSE 0 END) AS 中成药费,
  380. SUM(CASE WHEN i.med_chrgitm_type = '12' THEN i.det_item_fee_sumamt ELSE 0 END) AS 一般诊疗费,
  381. SUM(CASE WHEN i.med_chrgitm_type = '13' THEN i.det_item_fee_sumamt ELSE 0 END) AS 挂号费,
  382. SUM(CASE WHEN i.med_chrgitm_type = '14' THEN i.det_item_fee_sumamt ELSE 0 END) AS 其他费,
  383. SUM(distinct his_order.medfee_sumamt) AS 医疗费总额,
  384. SUM(distinct his_order.psn_cash_pay) AS 个人自付金额,
  385. SUM(distinct his_order.acct_pay) AS 基本账户支付,
  386. SUM(distinct his_order.acct_mulaid_pay) AS 共济账户支付,
  387. SUM(distinct his_order.cvlserv_pay) AS 公务员补助,
  388. SUM(distinct his_order.hifp_pay) AS 统筹支付金额,
  389. SUM(distinct his_order.maf_pay) AS 医疗救助,
  390. SUM(distinct his_order.hifmi_pay) AS 大病支付,
  391. SUM(distinct his_order.hifes_pay) AS 企业补充支付,
  392. 0 AS 重大疾病补充,
  393. SUM(distinct his_order.oth_pay) AS 其它支付
  394. `).
  395. Joins("JOIN (?) i ON his_order.number = i.order_number", subQuery). // 使用子查询
  396. 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 = ?",
  397. 10697, 2, startTime+" 00:00:00", endTime+" 23:59:59", 1, ins, 1).
  398. Group("his_order.patient_id").
  399. Scan(&results).Error
  400. if err != nil {
  401. return nil, err
  402. }
  403. return results, nil
  404. }
  405. func GetHisOrderBy10697SummaryThree(startTime, endTime string, st_stamp, end_stamp int64, org_id int64) ([]*MedicalChargesThree, error) {
  406. var results []*MedicalChargesThree
  407. // 改为字符串数组
  408. medChargeTypes := []string{"01", "02", "03", "04", "05", "07", "08", "09", "10", "11", "12", "13", "14"}
  409. // 定义子查询
  410. subQuery := readDb.Table("his_order_info").
  411. Select(`
  412. order_number,
  413. med_chrgitm_type,
  414. SUM(det_item_fee_sumamt) AS det_item_fee_sumamt`).
  415. Where("user_org_id = ? AND STATUS = ? AND (upload_date) >= ? AND (upload_date) <= ? AND med_chrgitm_type IN (?)",
  416. org_id, 1,
  417. st_stamp,
  418. end_stamp,
  419. medChargeTypes).
  420. Group("order_number, med_chrgitm_type").
  421. SubQuery() // 作为临时表
  422. // 执行主查询
  423. err := readDb.Table("his_order").
  424. Select(`p.id as ID, p.name AS 姓名,
  425. CASE his_order.insutype
  426. WHEN '390' THEN '城乡'
  427. WHEN '310' THEN '职工'
  428. ELSE '未知'
  429. END AS "类型",
  430. SUM(CASE i.med_chrgitm_type WHEN '09' THEN i.det_item_fee_sumamt ELSE 0 END) AS 西药费,
  431. 0 AS 成药费,
  432. SUM(CASE i.med_chrgitm_type WHEN '11' THEN i.det_item_fee_sumamt ELSE 0 END) AS 中成药费,
  433. SUM(CASE i.med_chrgitm_type WHEN '08' THEN i.det_item_fee_sumamt ELSE 0 END) AS 耗材费,
  434. SUM(CASE i.med_chrgitm_type WHEN '13' THEN i.det_item_fee_sumamt ELSE 0 END) AS 挂号费,
  435. SUM(CASE i.med_chrgitm_type WHEN '05' THEN i.det_item_fee_sumamt ELSE 0 END) AS 治疗费,
  436. SUM(CASE i.med_chrgitm_type WHEN '03' THEN i.det_item_fee_sumamt ELSE 0 END) AS 检查费,
  437. SUM(CASE i.med_chrgitm_type WHEN '04' THEN i.det_item_fee_sumamt ELSE 0 END) AS 化验费,
  438. SUM(CASE i.med_chrgitm_type WHEN '07' THEN i.det_item_fee_sumamt ELSE 0 END) AS 护理费,
  439. SUM(CASE i.med_chrgitm_type WHEN '14' THEN i.det_item_fee_sumamt ELSE 0 END) AS 其他费,
  440. 0 AS 合计, -- 移除不必要的DISTINCT
  441. 0 AS 自费金额,
  442. 0 AS 个人账户支付,
  443. 0 AS 医保报销金额,
  444. "" AS 退费,
  445. "" AS 优惠,
  446. 0 AS 应收,
  447. "" AS 挂账,
  448. "" AS 冲账,
  449. 0 AS 实收`).
  450. Joins("JOIN (?) i ON his_order.number = i.order_number", subQuery). // 使用子查询
  451. Joins("JOIN xt_patients p on p.id = his_order.patient_id and p.user_org_id = ?", org_id). // 使用子查询
  452. 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 = ?",
  453. org_id, 2, startTime+" 00:00:00", endTime+" 23:59:59", 1).
  454. Group("his_order.patient_id").
  455. Scan(&results).Error
  456. if err != nil {
  457. return nil, err
  458. }
  459. type CusTotal struct {
  460. MedfeeSumamt float64
  461. PsnCashPay float64
  462. AcctPay float64
  463. FunPay float64
  464. }
  465. // To store totals per patient
  466. patientTotals := make(map[string]CusTotal)
  467. var grandTotal CusTotal
  468. for _, item := range results {
  469. var tempTotal CusTotal
  470. err := readDb.Model(models.HisOrder{}).
  471. Select("sum(medfee_sumamt) as medfee_sumamt, "+
  472. "sum(psn_cash_pay) as psn_cash_pay, "+
  473. "sum(acct_pay) as acct_pay, "+
  474. "sum(fund_pay_sumamt) as fun_pay").
  475. Where("patient_id = ? and user_org_id = ? "+
  476. "and setl_time >= ? and setl_time <= ? "+
  477. "and status = 1 and order_status = 2",
  478. item.PatientID, org_id,
  479. startTime+" 00:00:00", endTime+" 23:59:59").
  480. Scan(&tempTotal).Error
  481. if err != nil {
  482. log.Printf("Error querying for patient %s: %v", item.PatientID, err)
  483. continue
  484. }
  485. // Store this patient's total
  486. patientTotals[item.PatientID] = tempTotal
  487. // Accumulate to grand total
  488. grandTotal.MedfeeSumamt += tempTotal.MedfeeSumamt
  489. grandTotal.PsnCashPay += tempTotal.PsnCashPay
  490. grandTotal.AcctPay += tempTotal.AcctPay
  491. grandTotal.FunPay += tempTotal.FunPay
  492. }
  493. // Print totals per patient
  494. for patientID, total := range patientTotals {
  495. //fmt.Printf("Patient %s total: %+v\n", patientID, total)
  496. for _, item := range results {
  497. if patientID == item.PatientID {
  498. item.TotalMedicalFee = total.MedfeeSumamt
  499. item.SelfPay = total.PsnCashPay
  500. item.AcctPay = total.AcctPay
  501. item.YingShou = total.MedfeeSumamt
  502. item.ShiShou = total.MedfeeSumamt
  503. item.YiShou = total.PsnCashPay
  504. fmt.Println(item)
  505. }
  506. }
  507. }
  508. type CusTotalTwo struct {
  509. XT float64 `gorm:"column:XT"`
  510. XL float64 `gorm:"column:XL"`
  511. GL float64 `gorm:"column:GL"`
  512. }
  513. // To store totals per patient
  514. patientTotals_two := make(map[string]CusTotalTwo)
  515. var grandTotal_two CusTotalTwo
  516. for _, item := range results {
  517. if org_id == 9478 {
  518. var tempTotal CusTotalTwo
  519. readDb.Table("his_order_info as oi").Select(`
  520. COALESCE(SUM(CASE WHEN project.project_name = '血液透析(用)' THEN p.count ELSE 0 END), 0) as XT,
  521. COALESCE(SUM(CASE WHEN project.project_name = '血液透析滤过(用)' THEN p.count ELSE 0 END), 0) as XL,
  522. COALESCE(SUM(CASE WHEN project.project_name = '血液灌流(用)' THEN p.count ELSE 0 END), 0) as GL
  523. `).
  524. 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").
  525. Joins("JOIN his_prescription_project p ON oi.project_id = p.id").
  526. Joins("LEFT JOIN xt_his_project project ON p.project_id = project.id").
  527. Joins("JOIN xt_patients pp ON oi.patient_id = pp.id").
  528. Where(`
  529. oi.patient_id = ?
  530. AND oi.project_id > 0
  531. AND oi.user_org_id = ?
  532. AND oi.upload_date >= ?
  533. AND oi.upload_date <= ?
  534. AND oi.status = 1
  535. AND p.type = 2
  536. AND project.project_name IN ('血液透析(用)','血液透析滤过(用)','血液灌流(用)')
  537. `, item.PatientID, org_id, st_stamp, end_stamp).
  538. Scan(&tempTotal)
  539. patientTotals_two[item.PatientID] = tempTotal
  540. grandTotal_two.GL += tempTotal.GL
  541. grandTotal_two.XT += tempTotal.XT
  542. grandTotal_two.XL += tempTotal.XL
  543. } else {
  544. var tempTotal CusTotalTwo
  545. readDb.Table("his_order_info as oi").Select(`
  546. COALESCE(SUM(CASE WHEN project.project_name = '血液透析' THEN p.count ELSE 0 END), 0) as XT,
  547. COALESCE(SUM(CASE WHEN project.project_name = '血液透析滤过' THEN p.count ELSE 0 END), 0) as XL,
  548. COALESCE(SUM(CASE WHEN project.project_name = '血液灌流' THEN p.count ELSE 0 END), 0) as GL
  549. `).
  550. 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").
  551. Joins("JOIN his_prescription_project p ON oi.project_id = p.id").
  552. Joins("LEFT JOIN xt_his_project project ON p.project_id = project.id").
  553. Joins("JOIN xt_patients pp ON oi.patient_id = pp.id").
  554. Where(`
  555. oi.patient_id = ?
  556. AND oi.project_id > 0
  557. AND oi.user_org_id = ?
  558. AND oi.upload_date >= ?
  559. AND oi.upload_date <= ?
  560. AND oi.status = 1
  561. AND p.type = 2
  562. AND project.project_name IN ('血液透析','血液透析滤过','血液灌流')
  563. `, item.PatientID, org_id, st_stamp, end_stamp).
  564. Scan(&tempTotal)
  565. patientTotals_two[item.PatientID] = tempTotal
  566. grandTotal_two.GL += tempTotal.GL
  567. grandTotal_two.XT += tempTotal.XT
  568. grandTotal_two.XL += tempTotal.XL
  569. }
  570. }
  571. fmt.Println(patientTotals_two)
  572. for patientID, total := range patientTotals_two {
  573. //fmt.Printf("Patient %s total: %+v\n", patientID, total)
  574. for _, item := range results {
  575. if patientID == item.PatientID {
  576. item.Total = total.XL + total.GL + total.XT
  577. item.XtCount = total.XT
  578. item.XlCount = total.XL
  579. item.GlCount = total.GL
  580. }
  581. }
  582. }
  583. // Print grand total
  584. //fmt.Printf("Grand total for all patients: %+v\n", grandTotal)
  585. return results, nil
  586. }
  587. func GetHisOrderBySummary(startTime, endTime string, st_stamp, end_stamp int64, org_id int64) ([]MedicalChargesThree, error) {
  588. var results []MedicalChargesThree
  589. medChargeTypes := []string{"01", "02", "03", "04", "05", "07", "08", "09", "10", "11", "12", "13", "14"}
  590. // 优化后的费用聚合子查询(使用覆盖索引)
  591. subQuery := readDb.Table("his_order_info").
  592. Select(`order_number, med_chrgitm_type, SUM(det_item_fee_sumamt) AS det_item_fee_sumamt`).
  593. Where("user_org_id = ? AND status = ? AND upload_date BETWEEN ? AND ?",
  594. org_id, 1, st_stamp, end_stamp).
  595. Where("med_chrgitm_type IN (?)", medChargeTypes).
  596. Group("order_number, med_chrgitm_type").
  597. SubQuery()
  598. // 处理时间范围格式
  599. startTimeFull := fmt.Sprintf("%s 00:00:00", startTime)
  600. endTimeFull := fmt.Sprintf("%s 23:59:59", endTime)
  601. err := readDb.Table("his_order").
  602. Select(`his_order.psn_name AS 姓名,
  603. CASE his_order.insutype
  604. WHEN '390' THEN '城乡'
  605. WHEN '310' THEN '职工'
  606. ELSE '未知'
  607. END AS "类型",
  608. SUM(CASE i.med_chrgitm_type WHEN '09' THEN i.det_item_fee_sumamt ELSE 0 END) AS 西药费,
  609. 0 AS 成药费,
  610. SUM(CASE i.med_chrgitm_type WHEN '11' THEN i.det_item_fee_sumamt ELSE 0 END) AS 中成药费,
  611. SUM(CASE i.med_chrgitm_type WHEN '08' THEN i.det_item_fee_sumamt ELSE 0 END) AS 耗材费,
  612. SUM(CASE i.med_chrgitm_type WHEN '13' THEN i.det_item_fee_sumamt ELSE 0 END) AS 挂号费,
  613. SUM(CASE i.med_chrgitm_type WHEN '05' THEN i.det_item_fee_sumamt ELSE 0 END) AS 治疗费,
  614. SUM(CASE i.med_chrgitm_type WHEN '03' THEN i.det_item_fee_sumamt ELSE 0 END) AS 检查费,
  615. SUM(CASE i.med_chrgitm_type WHEN '04' THEN i.det_item_fee_sumamt ELSE 0 END) AS 化验费,
  616. SUM(CASE i.med_chrgitm_type WHEN '07' THEN i.det_item_fee_sumamt ELSE 0 END) AS 护理费,
  617. SUM(CASE i.med_chrgitm_type WHEN '14' THEN i.det_item_fee_sumamt ELSE 0 END) AS 其他费,
  618. SUM(his_order.medfee_sumamt) AS 合计, -- 移除不必要的DISTINCT
  619. SUM(his_order.psn_cash_pay) AS 自费金额,
  620. SUM(his_order.acct_pay) AS 个人账户支付,
  621. SUM(his_order.fund_pay_sumamt) AS 医保报销金额,
  622. "" AS 退费,
  623. "" AS 优惠,
  624. SUM(his_order.medfee_sumamt) AS 应收,
  625. "" AS 挂账,
  626. "" AS 冲账,
  627. SUM(his_order.medfee_sumamt) AS 实收`).
  628. Joins("JOIN (?) i ON his_order.number = i.order_number", subQuery).
  629. //Joins("LEFTJOIN (?) p ON his_order.number = p.order_number", projectJoinQuery).
  630. Where("his_order.user_org_id = ?", org_id).
  631. Where("his_order.order_status = ?", 2).
  632. Where("his_order.setl_time BETWEEN ? AND ?", startTimeFull, endTimeFull).
  633. Where("his_order.is_medicine_insurance = ?", 1).
  634. Where("his_order.status = ?", 1).
  635. Group("his_order.patient_id").
  636. Scan(&results).Error
  637. if err != nil {
  638. return nil, err
  639. }
  640. return results, nil
  641. }
  642. // 建议的索引方案(MySQL语法示例)
  643. /*
  644. -- his_order_info 表
  645. ALTER TABLE his_order_info
  646. ADD INDEX idx_org_status_upload (user_org_id, status, upload_date),
  647. ADD INDEX idx_order_medtype (order_number, med_chrgitm_type);
  648. -- his_order 表
  649. ALTER TABLE his_order
  650. ADD INDEX idx_org_status_setltime (user_org_id, order_status, setl_time),
  651. ADD INDEX idx_patient_setltime (patient_id, setl_time);
  652. -- his_prescription_project 表
  653. ALTER TABLE his_prescription_project
  654. ADD INDEX idx_org_record_project (user_org_id, record_date, project_id),
  655. ADD INDEX idx_status_project (status, project_id);
  656. -- xt_his_project 表
  657. ALTER TABLE xt_his_project
  658. ADD INDEX idx_org_project (id, user_org_id);
  659. */
  660. type MedicalChargesTwo struct {
  661. TotalMedicalFee float64 `gorm:"column:医疗费总额"` // 医疗费总额
  662. Fund float64 `gorm:"column:基金支付总金额"` // 个人自付金额
  663. AcctPay float64 `gorm:"column:个人账户支付总金额"` // 基本账户支付
  664. PsnPay float64 `gorm:"column:个人自付总金额"` // 基本账户支付
  665. PoolFundPay float64 `gorm:"column:基金统筹总金额"` // 统筹支付金额
  666. DaE float64 `gorm:"column:大额支付总金额"` // 统筹支付金额
  667. XianXing float64 `gorm:"column:先行自付总金额"` // 统筹支付金额
  668. QuanZiFei float64 `gorm:"column:全自费总金额"` // 统筹支付金额
  669. YiLiaoJiuZhu float64 `gorm:"column:医疗救助基金总额"` // 统筹支付金额
  670. DaBing float64 `gorm:"column:大病基金总额"` // 统筹支付金额
  671. GongWuYuan float64 `gorm:"column:公务员补助"` // 统筹支付金额
  672. QiYe float64 `gorm:"column:企业补充支付"` // 统筹支付金额
  673. QiTa float64 `gorm:"column:其它支付"` // 统筹支付金额
  674. }
  675. func GetHisOrderSummary(org_id int64, start_time string, end_time string) (results []MedicalChargesTwo, err error) {
  676. err = readDb.Table("his_order").
  677. Select(`
  678. SUM(his_order.medfee_sumamt) AS 医疗费总额,
  679. SUM(his_order.fund_pay_sumamt) AS 基金支付总金额,
  680. SUM(his_order.acct_pay) AS 个人账户支付总金额,
  681. SUM(his_order.psn_cash_pay) AS 个人自付总金额,
  682. SUM(his_order.hifp_pay) AS 基金统筹总金额,
  683. SUM(his_order.hifob_pay) AS 大额支付总金额,
  684. SUM(his_order.preselfpay_amt) AS 先行自付总金额,
  685. SUM(his_order.fulamt_ownpay_amt) AS 全自费总金额,
  686. SUM(his_order.maf_pay) AS 医疗救助基金总额,
  687. SUM(his_order.hifmi_pay) AS 大病支付,
  688. SUM(his_order.cvlserv_pay) AS 公务员补助,
  689. SUM(his_order.hifes_pay) AS 企业补充支付,
  690. SUM(his_order.oth_pay) AS 其它支付
  691. `).
  692. 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 = ?",
  693. org_id, 2, start_time+" 00:00:00", end_time+" 23:59:59", 1).
  694. Scan(&results).Error
  695. return
  696. }