export_data_service.go 10.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. package service
  2. import (
  3. "XT_New/models"
  4. "github.com/jinzhu/gorm"
  5. )
  6. type ExportPatient struct {
  7. ID int64 `gorm:"column:id" json:"id" form:"id"`
  8. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  9. Name string `gorm:"column:name" json:"name" form:"name"`
  10. Lapseto int64 `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
  11. Status int64 `gorm:"column:status" json:"status" form:"status"`
  12. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  13. XtCount int64 `gorm:"column:-" json:"xt_count" form:"xt_count"`
  14. SettleOrder []*SettleOrder `gorm:"ForeignKey:PatientID;AssociationForeignKey:ID" json:"orders"`
  15. }
  16. func (ExportPatient) TableName() string {
  17. return "xt_patients"
  18. }
  19. type SettleOrder struct {
  20. ID int64 `gorm:"column:id" json:"id" form:"id"`
  21. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  22. Status int64 `gorm:"column:status" json:"status" form:"status"`
  23. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  24. OrderStatus int64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  25. MdtrtId string `gorm:"column:mdtrt_id" json:"mdtrt_id" form:"mdtrt_id"`
  26. Number string `gorm:"column:number" json:"number" form:"number"`
  27. SetlId string `gorm:"column:setl_id" json:"setl_id" form:"setl_id"`
  28. Insutype string `gorm:"column:insutype" json:"insutype" form:"insutype"`
  29. SetlTime string `gorm:"column:setl_time" json:"setl_time" form:"setl_time"`
  30. MedfeeSumamt float64 `gorm:"column:medfee_sumamt" json:"medfee_sumamt" form:"medfee_sumamt"`
  31. FulamtOwnpayAmt float64 `gorm:"column:fulamt_ownpay_amt" json:"fulamt_ownpay_amt" form:"fulamt_ownpay_amt"`
  32. OverlmtSelfPay float64 `gorm:"column:overlmt_self_pay" json:"overlmt_self_pay" form:"overlmt_self_pay"`
  33. PreselfpayAmt float64 `gorm:"column:preselfpay_amt" json:"preselfpay_amt" form:"preselfpay_amt"`
  34. InscpScpAmt float64 `gorm:"column:inscp_scp_amt" json:"inscp_scp_amt" form:"inscp_scp_amt"`
  35. ActPayDedc float64 `gorm:"column:act_pay_dedc" json:"act_pay_dedc" form:"act_pay_dedc"`
  36. HifpPay float64 `gorm:"column:hifp_pay" json:"hifp_pay" form:"hifp_pay"`
  37. CvlservPay float64 `gorm:"column:cvlserv_pay" json:"cvlserv_pay" form:"cvlserv_pay"`
  38. PoolPropSelfpay float64 `gorm:"column:pool_prop_selfpay" json:"pool_prop_selfpay" form:"pool_prop_selfpay"`
  39. HifesPay float64 `gorm:"column:hifes_pay" json:"hifes_pay" form:"hifes_pay"`
  40. HifmiPay float64 `gorm:"column:hifmi_pay" json:"hifmi_pay" form:"hifmi_pay"`
  41. HifobPay float64 `gorm:"column:hifob_pay" json:"hifob_pay" form:"hifob_pay"`
  42. MafPay float64 `gorm:"column:maf_pay" json:"maf_pay" form:"maf_pay"`
  43. OthPay float64 `gorm:"column:oth_pay" json:"oth_pay" form:"oth_pay"`
  44. FundPaySumamt float64 `gorm:"column:fund_pay_sumamt" json:"fund_pay_sumamt" form:"fund_pay_sumamt"`
  45. PsnPartAmt float64 `gorm:"column:psn_part_amt" json:"psn_part_amt" form:"psn_part_amt"`
  46. AcctPay float64 `gorm:"column:acct_pay" json:"acct_pay" form:"acct_pay"`
  47. PsnCashPay float64 `gorm:"column:psn_cash_pay" json:"psn_cash_pay" form:"psn_cash_pay"`
  48. HospPartAmt float64 `gorm:"column:hosp_part_amt" json:"hosp_part_amt" form:"hosp_part_amt"`
  49. IsMedicineInsurance int64 `gorm:"column:is_medicine_insurance" json:"is_medicine_insurance" form:"is_medicine_insurance"`
  50. OrderInfo9919 []*OrderInfo9919 `gorm:"ForeignKey:OrderNumber;AssociationForeignKey:Number" json:"info"`
  51. }
  52. func (SettleOrder) TableName() string {
  53. return "his_order"
  54. }
  55. type OrderInfo9919 struct {
  56. ID int64 `gorm:"column:id" json:"id" form:"id"`
  57. OrderNumber string `gorm:"column:order_number" json:"order_number" form:"order_number"`
  58. UploadDate int64 `gorm:"column:upload_date" json:"upload_date" form:"upload_date"`
  59. AdviceId int64 `gorm:"column:advice_id" json:"advice_id" form:"advice_id"`
  60. DetItemFeeSumamt float64 `gorm:"column:det_item_fee_sumamt" json:"det_item_fee_sumamt" form:"det_item_fee_sumamt"`
  61. Cnt float64 `gorm:"column:cnt" json:"cnt" form:"cnt"`
  62. Pric float64 `gorm:"column:pric" json:"pric" form:"pric"`
  63. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  64. PricUplmtAmt float64 `gorm:"column:pric_uplmt_amt" json:"pric_uplmt_amt" form:"pric_uplmt_amt"`
  65. SelfpayProp float64 `gorm:"column:selfpay_prop" json:"selfpay_prop" form:"selfpay_prop"`
  66. FulamtOwnpayAmt float64 `gorm:"column:fulamt_ownpay_amt" json:"fulamt_ownpay_amt" form:"fulamt_ownpay_amt"`
  67. OverlmtAmt float64 `gorm:"column:overlmt_amt" json:"overlmt_amt" form:"overlmt_amt"`
  68. PreselfpayAmt float64 `gorm:"column:preselfpay_amt" json:"preselfpay_amt" form:"preselfpay_amt"`
  69. BasMednFlag string `gorm:"column:bas_medn_flag" json:"bas_medn_flag" form:"bas_medn_flag"`
  70. MedChrgitmType string `gorm:"column:med_chrgitm_type" json:"med_chrgitm_type" form:"med_chrgitm_type"`
  71. HiNegoDrugFlag string `gorm:"column:hi_nego_drug_flag" json:"hi_nego_drug_flag" form:"hi_nego_drug_flag"`
  72. Status int64 `gorm:"column:status" json:"status" form:"status"`
  73. Memo string `gorm:"column:memo" json:"memo" form:"memo"`
  74. FeedetlSn string `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
  75. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  76. InscpScpAmt float64 `gorm:"column:inscp_scp_amt" json:"inscp_scp_amt" form:"inscp_scp_amt"`
  77. DrtReimFlag string `gorm:"column:drt_reim_flag" json:"drt_reim_flag" form:"drt_reim_flag"`
  78. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  79. ListSpItemFlag string `gorm:"column:list_sp_item_flag" json:"list_sp_item_flag" form:"list_sp_item_flag"`
  80. ChldMedcFlag string `gorm:"column:chld_medc_flag" json:"chld_medc_flag" form:"chld_medc_flag"`
  81. LmtUsedFlag string `gorm:"column:lmt_used_flag" json:"lmt_used_flag" form:"lmt_used_flag"`
  82. ChrgitmLv string `gorm:"column:chrgitm_lv" json:"chrgitm_lv" form:"chrgitm_lv"`
  83. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  84. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  85. OrderId int64 `gorm:"column:order_id" json:"order_id" form:"order_id"`
  86. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  87. Type int64 `gorm:"column:type" json:"type" form:"type"`
  88. ItemId int64 `gorm:"column:item_id" json:"item_id" form:"item_id"`
  89. SettleType int64 `gorm:"column:settle_type" json:"settle_type" form:"settle_type"`
  90. }
  91. func (OrderInfo9919) TableName() string {
  92. return "his_order_info"
  93. }
  94. func GetHisOrderDetailFor310(start_time string, end_time string, org_id int64) (patients []*ExportPatient, err error) {
  95. 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 {
  96. 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")
  97. }).Where("p.status = 1 AND p.user_org_id = ?", org_id).Group("id").Find(&patients).Error
  98. for _, item := range patients {
  99. var total int64
  100. 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)
  101. item.XtCount = total
  102. }
  103. return
  104. }
  105. func GetHisOrderDetailFor390(start_time string, end_time string, org_id int64) (patients []*ExportPatient, err error) {
  106. 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 {
  107. 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")
  108. }).Where("p.status = 1 AND p.user_org_id = ?", org_id).Group("id").Find(&patients).Error
  109. for _, item := range patients {
  110. var total int64
  111. 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)
  112. item.XtCount = total
  113. }
  114. return
  115. }
  116. func GetHisOrderByTime(patient_id int64, start_time string, end_time string) (order []models.HisOrder, err error) {
  117. err = readDb.Model(&models.HisOrder{}).Where("patient_id = ? AND status = 1 and order_status = 2 and setl_time >= ? and setl_time <= ?", patient_id, start_time+" 00:00:00", end_time+" 23:59:00").Find(&order).Error
  118. return
  119. }
  120. func GetBatchHisOrderInfoByNumber(order_number string) (order []models.BatchHisOrderInfo, err error) {
  121. err = readDb.Model(&models.BatchHisOrderInfo{}).Where("order_number = ? and status = 1", order_number).Find(&order).Error
  122. return
  123. }