his_charge_service.go 41KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  1. package service
  2. import (
  3. "XT_New/models"
  4. "github.com/jinzhu/gorm"
  5. "time"
  6. )
  7. func GetAllPatientChargeDetails(org_id int64, start_time int64, end_time int64, keyword string, item_type int64) (patients []*models.ChargePatient, err error) {
  8. if len(keyword) == 0 {
  9. switch item_type {
  10. case 0:
  11. err = readDb2.Table("xt_patients as p").Select("p.id,p.user_org_id,p.name,p.lapseto,p.status").Joins("JOIN his_order AS orders ON orders.patient_id = p.id AND orders.status = 1 AND orders.ctime >= ? AND orders.ctime <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeOrder", func(db *gorm.DB) *gorm.DB {
  12. return db.Select("id,user_org_id,his_patient_id,settle_accounts_date,status,number,order_status,mdtrt_id,patient_id").
  13. Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
  14. return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").
  15. Preload("HisChargeDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  16. return db.Preload("Drug", "status = 1").Where("status = 1")
  17. }).Preload("HisChargePrescriptionProject", func(db *gorm.DB) *gorm.DB {
  18. return db.Select("id,project_id,user_org_id,status,patient_id,record_date,count,type").Preload("HisChargeProject", func(db *gorm.DB) *gorm.DB {
  19. return db.Select("id,project_name,unit").Where("status = 1 ")
  20. }).Preload("HisChargeGoodInfo", func(db *gorm.DB) *gorm.DB {
  21. return db.Select("id,good_name,good_unit,specification_name").Where("status = 1 ")
  22. }).Where("status = 1 ")
  23. })
  24. }).Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2", start_time, end_time, org_id)
  25. }).Where("p.status = 1 AND p.user_org_id = ?", org_id).Group("id").Find(&patients).Error
  26. break
  27. case 1:
  28. err = readDb2.Table("xt_patients as p").Select("p.id,p.user_org_id,p.name,p.lapseto,p.status").Joins("JOIN his_order AS orders ON orders.patient_id = p.id AND orders.status = 1 AND orders.ctime >= ? AND orders.ctime <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeOrder", func(db *gorm.DB) *gorm.DB {
  29. return db.Select("id,user_org_id,his_patient_id,settle_accounts_date,status,number,order_status,mdtrt_id,patient_id").
  30. Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
  31. return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").Where("advice_id > 0 AND project_id = 0").Preload("HisChargeDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  32. return db.Preload("Drug", "status = 1").Where("status = 1")
  33. }).Preload("HisChargePrescriptionProject", func(db *gorm.DB) *gorm.DB {
  34. return db.Select("id,project_id,user_org_id,status,patient_id,record_date,count,type").Preload("HisChargeProject", func(db *gorm.DB) *gorm.DB {
  35. return db.Select("id,project_name,unit").Where("status = 1 ")
  36. }).Preload("HisChargeGoodInfo", func(db *gorm.DB) *gorm.DB {
  37. return db.Select("id,good_name,good_unit,specification_name").Where("status = 1 ")
  38. }).Where("status = 1 ")
  39. })
  40. }).Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2", start_time, end_time, org_id)
  41. }).Where("p.status = 1 AND p.user_org_id = ?", org_id).Group("id").Find(&patients).Error
  42. break
  43. case 2:
  44. err = readDb2.Table("xt_patients as p").Select("p.id,p.user_org_id,p.name,p.lapseto,p.status").Joins("JOIN his_order AS orders ON orders.patient_id = p.id AND orders.status = 1 AND orders.ctime >= ? AND orders.ctime <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeOrder", func(db *gorm.DB) *gorm.DB {
  45. return db.Select("id,user_org_id,his_patient_id,settle_accounts_date,status,number,order_status,mdtrt_id,patient_id").
  46. Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
  47. return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").Where("advice_id = 0 AND project_id > 0").Preload("HisChargeDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  48. return db.Preload("Drug", "status = 1").Where("status = 1")
  49. }).Preload("HisChargePrescriptionProject", func(db *gorm.DB) *gorm.DB {
  50. return db.Select("id,project_id,user_org_id,status,patient_id,record_date,count,type").Preload("HisChargeProject", func(db *gorm.DB) *gorm.DB {
  51. return db.Select("id,project_name,unit").Where("status = 1 ")
  52. }).Where("status = 1 ")
  53. })
  54. }).Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2", start_time, end_time, org_id)
  55. }).Where("p.status = 1 AND p.user_org_id = ?", org_id).Group("id").Find(&patients).Error
  56. break
  57. case 3:
  58. err = readDb2.Table("xt_patients as p").Select("p.id,p.user_org_id,p.name,p.lapseto,p.status").Joins("JOIN his_order AS orders ON orders.patient_id = p.id AND orders.status = 1 AND orders.ctime >= ? AND orders.ctime <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeOrder", func(db *gorm.DB) *gorm.DB {
  59. return db.Select("id,user_org_id,his_patient_id,settle_accounts_date,status,number,order_status,mdtrt_id,patient_id").
  60. Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
  61. return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").Where("advice_id = 0 AND project_id > 0").Preload("HisChargeDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  62. return db.Preload("Drug", "status = 1").Where("status = 1")
  63. }).Preload("HisChargePrescriptionProject", func(db *gorm.DB) *gorm.DB {
  64. return db.Select("id,project_id,user_org_id,status,patient_id,record_date,count,type").Preload("HisChargeGoodInfo", func(db *gorm.DB) *gorm.DB {
  65. return db.Select("id,good_name,good_unit,specification_name").Where("status = 1 ")
  66. }).Where("status = 1 ")
  67. })
  68. }).Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2", start_time, end_time, org_id)
  69. }).Where("p.status = 1 AND p.user_org_id = ?", org_id).Group("id").Find(&patients).Error
  70. break
  71. }
  72. } else {
  73. keyword := "%" + keyword + "%"
  74. switch item_type {
  75. case 0:
  76. err = readDb2.Table("xt_patients as p").Select("p.id,p.user_org_id,p.name,p.lapseto,p.status").Joins("JOIN his_order AS orders ON orders.patient_id = p.id AND orders.status = 1 AND orders.ctime >= ? AND orders.ctime <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeOrder", func(db *gorm.DB) *gorm.DB {
  77. return db.Select("id,user_org_id,his_patient_id,settle_accounts_date,status,number,order_status,mdtrt_id,patient_id").
  78. Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
  79. return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").Preload("HisChargeDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  80. return db.Preload("Drug", "status = 1").Where("status = 1")
  81. }).Preload("HisChargePrescriptionProject", func(db *gorm.DB) *gorm.DB {
  82. return db.Select("id,project_id,user_org_id,status,patient_id,record_date,count,type").Preload("HisChargeProject", func(db *gorm.DB) *gorm.DB {
  83. return db.Select("id,project_name,unit").Where("status = 1 ")
  84. }).Preload("HisChargeGoodInfo", func(db *gorm.DB) *gorm.DB {
  85. return db.Select("id,good_name,good_unit,specification_name").Where("status = 1 ")
  86. }).Where("status = 1 ")
  87. })
  88. }).Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2", start_time, end_time, org_id)
  89. }).Where("p.status = 1 AND p.user_org_id = ? AND p.name LIKE ?", org_id, keyword).Group("id").Find(&patients).Error
  90. break
  91. case 1:
  92. err = readDb2.Table("xt_patients as p").Select("p.id,p.user_org_id,p.name,p.lapseto,p.status").Joins("JOIN his_order AS orders ON orders.patient_id = p.id AND orders.status = 1 AND orders.ctime >= ? AND orders.ctime <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeOrder", func(db *gorm.DB) *gorm.DB {
  93. return db.Select("id,user_org_id,his_patient_id,settle_accounts_date,status,number,order_status,mdtrt_id,patient_id").
  94. Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
  95. return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").Where("advice_id > 0 AND project_id = 0").Preload("HisChargeDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  96. return db.Preload("Drug", "status = 1").Where("status = 1")
  97. }).Preload("HisChargePrescriptionProject", func(db *gorm.DB) *gorm.DB {
  98. return db.Select("id,project_id,user_org_id,status,patient_id,record_date,count,type").Preload("HisChargeProject", func(db *gorm.DB) *gorm.DB {
  99. return db.Select("id,project_name,unit").Where("status = 1 ")
  100. }).Preload("HisChargeGoodInfo", func(db *gorm.DB) *gorm.DB {
  101. return db.Select("id,good_name,good_unit,specification_name").Where("status = 1 ")
  102. }).Where("status = 1 ")
  103. })
  104. }).Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2", start_time, end_time, org_id)
  105. }).Where("p.status = 1 AND p.user_org_id = ? AND p.name LIKE ?", org_id, keyword).Group("id").Find(&patients).Error
  106. break
  107. case 2:
  108. err = readDb2.Table("xt_patients as p").Select("p.id,p.user_org_id,p.name,p.lapseto,p.status").Joins("JOIN his_order AS orders ON orders.patient_id = p.id AND orders.status = 1 AND orders.ctime >= ? AND orders.ctime <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeOrder", func(db *gorm.DB) *gorm.DB {
  109. return db.Select("id,user_org_id,his_patient_id,settle_accounts_date,status,number,order_status,mdtrt_id,patient_id").
  110. Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
  111. return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").Where("advice_id = 0 AND project_id > 0").Preload("HisChargeDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  112. return db.Preload("Drug", "status = 1").Where("status = 1")
  113. }).Preload("HisChargePrescriptionProject", func(db *gorm.DB) *gorm.DB {
  114. return db.Select("id,project_id,user_org_id,status,patient_id,record_date,count,type").Preload("HisChargeProject", func(db *gorm.DB) *gorm.DB {
  115. return db.Select("id,project_name,unit").Where("status = 1 ")
  116. }).Where("status = 1 ")
  117. })
  118. }).Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2", start_time, end_time, org_id)
  119. }).Where("p.status = 1 AND p.user_org_id = ? AND p.name LIKE ?", org_id, keyword).Group("id").Find(&patients).Error
  120. break
  121. case 3:
  122. err = readDb2.Table("xt_patients as p").Select("p.id,p.user_org_id,p.name,p.lapseto,p.status").Joins("JOIN his_order AS orders ON orders.patient_id = p.id AND orders.status = 1 AND orders.ctime >= ? AND orders.ctime <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeOrder", func(db *gorm.DB) *gorm.DB {
  123. return db.Select("id,user_org_id,his_patient_id,settle_accounts_date,status,number,order_status,mdtrt_id,patient_id").
  124. Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
  125. return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").Where("advice_id = 0 AND project_id > 0").Preload("HisChargeDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  126. return db.Preload("Drug", "status = 1").Where("status = 1")
  127. }).Preload("HisChargePrescriptionProject", func(db *gorm.DB) *gorm.DB {
  128. return db.Select("id,project_id,user_org_id,status,patient_id,record_date,count,type").Preload("HisChargeGoodInfo", func(db *gorm.DB) *gorm.DB {
  129. return db.Select("id,good_name,good_unit,specification_name").Where("status = 1 ")
  130. }).Where("status = 1 ")
  131. })
  132. }).Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2", start_time, end_time, org_id)
  133. }).Where("p.status = 1 AND p.user_org_id = ? AND p.name LIKE ?", org_id, keyword).Group("id").Find(&patients).Error
  134. break
  135. }
  136. }
  137. return
  138. }
  139. func GetAllPatientChargeSettle(org_id int64, start_time int64, end_time int64, keyword string, item_type int64) (patients []*models.SettlePatient, err error) {
  140. if len(keyword) == 0 {
  141. switch item_type {
  142. case 0:
  143. 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 orders.ctime >= ? AND orders.ctime <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeSettleOrder", func(db *gorm.DB) *gorm.DB {
  144. return db.Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2", start_time, end_time, org_id)
  145. }).Where("p.status = 1 AND p.user_org_id = ?", org_id).Group("id").Find(&patients).Error
  146. break
  147. case 1:
  148. 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 orders.ctime >= ? AND orders.ctime <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeSettleOrder", func(db *gorm.DB) *gorm.DB {
  149. return db.Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2 AND is_medicine_insurance = 1 ", start_time, end_time, org_id)
  150. }).Where("p.status = 1 AND p.user_org_id = ?", org_id).Group("id").Find(&patients).Error
  151. break
  152. case 2:
  153. 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 orders.ctime >= ? AND orders.ctime <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeSettleOrder", func(db *gorm.DB) *gorm.DB {
  154. return db.Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2 AND is_medicine_insurance = 0", start_time, end_time, org_id)
  155. }).Where("p.status = 1 AND p.user_org_id = ?", org_id).Group("id").Find(&patients).Error
  156. break
  157. case 3:
  158. 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 orders.ctime >= ? AND orders.ctime <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeSettleOrder", func(db *gorm.DB) *gorm.DB {
  159. return db.Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2 AND med_type = 14", start_time, end_time, org_id)
  160. }).Where("p.status = 1 AND p.user_org_id = ?", org_id).Group("id").Find(&patients).Error
  161. break
  162. case 4:
  163. 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 orders.ctime >= ? AND orders.ctime <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeSettleOrder", func(db *gorm.DB) *gorm.DB {
  164. return db.Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2 AND med_type = 11", start_time, end_time, org_id)
  165. }).Where("p.status = 1 AND p.user_org_id = ?", org_id).Group("id").Find(&patients).Error
  166. break
  167. case 5:
  168. 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 orders.ctime >= ? AND orders.ctime <= ? AND orders.user_org_id = ? AND orders.order_status = 2 AND orders.insutype = 390", start_time, end_time, org_id).Preload("HisChargeSettleOrder", func(db *gorm.DB) *gorm.DB {
  169. return db.Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2 ", start_time, end_time, org_id)
  170. }).Where("p.status = 1 AND p.user_org_id = ?", org_id).Group("id").Find(&patients).Error
  171. break
  172. case 6:
  173. 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 orders.ctime >= ? AND orders.ctime <= ? AND orders.user_org_id = ? AND orders.order_status = 2 AND orders.insutype = 310 ", start_time, end_time, org_id).Preload("HisChargeSettleOrder", func(db *gorm.DB) *gorm.DB {
  174. return db.Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2", start_time, end_time, org_id)
  175. }).Where("p.status = 1 AND p.user_org_id = ?", org_id).Group("id").Find(&patients).Error
  176. break
  177. }
  178. } else {
  179. keyword = "%" + keyword + "%"
  180. switch item_type {
  181. case 0:
  182. 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 orders.ctime >= ? AND orders.ctime <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeSettleOrder", func(db *gorm.DB) *gorm.DB {
  183. return db.Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2", start_time, end_time, org_id)
  184. }).Where("p.status = 1 AND p.user_org_id = ? AND p.name LIKE ?", org_id, keyword).Group("id").Find(&patients).Error
  185. break
  186. case 1:
  187. 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 orders.ctime >= ? AND orders.ctime <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeSettleOrder", func(db *gorm.DB) *gorm.DB {
  188. return db.Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2 AND is_medicine_insurance = 1 ", start_time, end_time, org_id)
  189. }).Where("p.status = 1 AND p.user_org_id = ? AND p.name LIKE ?", org_id, keyword).Group("id").Find(&patients).Error
  190. break
  191. case 2:
  192. 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 orders.ctime >= ? AND orders.ctime <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeSettleOrder", func(db *gorm.DB) *gorm.DB {
  193. return db.Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2 AND is_medicine_insurance = 0", start_time, end_time, org_id)
  194. }).Where("p.status = 1 AND p.user_org_id = ? AND p.name LIKE ?", org_id, keyword).Group("id").Find(&patients).Error
  195. break
  196. case 3:
  197. 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 orders.ctime >= ? AND orders.ctime <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeSettleOrder", func(db *gorm.DB) *gorm.DB {
  198. return db.Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2 AND med_type = 14", start_time, end_time, org_id)
  199. }).Where("p.status = 1 AND p.user_org_id = ? AND p.name LIKE ?", org_id, keyword).Group("id").Find(&patients).Error
  200. break
  201. case 4:
  202. 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 orders.ctime >= ? AND orders.ctime <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeSettleOrder", func(db *gorm.DB) *gorm.DB {
  203. return db.Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2 AND med_type = 11", start_time, end_time, org_id)
  204. }).Where("p.status = 1 AND p.user_org_id = ? AND p.name LIKE ?", org_id, keyword).Group("id").Find(&patients).Error
  205. break
  206. }
  207. }
  208. return
  209. }
  210. func GetLabelPrintList(page int64, limit int64, user_org_id int64, record_time int64, is_print int64, keywors string) (labels []*models.HisLabelPrintInfo, total int64, err error) {
  211. offset := (page - 1) * limit
  212. db := readDb.Model(&models.HisLabelPrintInfo{})
  213. if is_print > 0 {
  214. db = db.Where("is_print = ?", is_print)
  215. }
  216. if len(keywors) > 0 {
  217. keywors = "%" + keywors + "%"
  218. db = db.Where("patient_name Like ?", keywors)
  219. }
  220. err = db.Where("user_org_id = ? AND record_date = ? AND status = 1 ", user_org_id, record_time).Count(&total).Offset(offset).Limit(limit).Find(&labels).Error
  221. return
  222. }
  223. func GetLabelPrintInfo(id int64) (labels models.HisLabelPrintInfo, err error) {
  224. db := readDb.Model(&models.HisLabelPrintInfo{})
  225. err = db.Where("id = ?", id).First(&labels).Error
  226. return
  227. }
  228. func AddSigleFapiaoRecord(dealer *models.HisFapiaoRecord) (err error, record *models.HisFapiaoRecord) {
  229. err = writeDb.Create(&dealer).Error
  230. return err, dealer
  231. }
  232. func ModifyFapiao(mesick *models.HisFapiaoRecord) error {
  233. err := writeDb.Save(&mesick).Error
  234. return err
  235. }
  236. func UpdateFapiaoIsUse(org_id int64) {
  237. writeDb.Model(&models.HisFapiaoRecord{}).Where("user_org_id = ?", org_id).Updates(map[string]interface{}{"mtime": time.Now().Unix(), "is_use": 0})
  238. }
  239. func FindAllFapiaoList(orgId int64, page int64, limit int64) (list []*models.HisFapiaoRecord, total int64, err error) {
  240. offset := (page - 1) * limit
  241. db := readDb.Model(&models.HisFapiaoRecord{})
  242. db = db.Where("user_org_id = ? AND status = 1", orgId)
  243. err = db.Count(&total).Offset(offset).Limit(limit).Order("ctime desc").Find(&list).Error
  244. return
  245. }
  246. func DeleteFapiaoById(id int64) error {
  247. err := writeDb.Model(&models.HisFapiaoRecord{}).Where("id = ? AND status = 1", id).Updates(map[string]interface{}{"mtime": time.Now().Unix(), "status": 0}).Error
  248. return err
  249. }
  250. func FindFapiaoById(id int64) (*models.HisFapiaoRecord, error) {
  251. dealer := &models.HisFapiaoRecord{}
  252. err := readDb.Model(&models.HisFapiaoRecord{}).Where("id = ? AND status = 1", id).First(&dealer).Error
  253. return dealer, err
  254. }
  255. func FindFapiaoByIsUse(org_id int64) (models.HisFapiaoRecord, error) {
  256. record := models.HisFapiaoRecord{}
  257. err := readDb.Model(&models.HisFapiaoRecord{}).Where("user_org_id = ? AND status = 1 AND is_use = 1", org_id).First(&record).Error
  258. return record, err
  259. }
  260. func FindHisYidiClearRecord(org_id int64) (records []*models.HisYidiClearRecord, err error) {
  261. err = readDb.Model(&models.HisYidiClearRecord{}).Where("user_org_id = ? AND status = 1", org_id).Find(&records).Error
  262. return
  263. }
  264. func GetHisYidiClearRecordById(org_id int64, id int64) (record models.HisYidiClearRecord, err error) {
  265. err = readDb.Model(&models.HisYidiClearRecord{}).Where("user_org_id = ? AND status = 1 AND id = ?", org_id, id).First(&record).Error
  266. return
  267. }
  268. func GetAllPatientTwo(org_id int64) (patients []*models.ChargePatientTwo, err error) {
  269. err = readDb.Model(&models.ChargePatientTwo{}).Where("user_org_id = ? AND status = 1", org_id).Find(&patients).Error
  270. return
  271. }
  272. func GetPatientChargeDetails(patient_id int64, org_id int64, start_time int64, end_time int64, keyword string, item_type int64, settle_type int64) (patients []*models.HisChargeOrderTwo, err error) {
  273. if len(keyword) == 0 {
  274. switch item_type {
  275. case 0:
  276. readDb2.Model(&models.HisChargeOrderTwo{}).Joins("join his_patient his on his.number = his_order.mdtrt_id AND his.patient_id = ").Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
  277. return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").
  278. Preload("HisChargeDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  279. return db.Preload("Drug", "status = 1").Where("status = 1")
  280. }).Preload("HisChargePrescriptionProject", func(db *gorm.DB) *gorm.DB {
  281. return db.Select("id,project_id,user_org_id,status,patient_id,record_date,count,type").Preload("HisChargeProject", func(db *gorm.DB) *gorm.DB {
  282. return db.Select("id,project_name,unit").Where("status = 1 ")
  283. }).Preload("HisChargeGoodInfo", func(db *gorm.DB) *gorm.DB {
  284. return db.Select("id,good_name,good_unit,specification_name").Where("status = 1 ")
  285. }).Where("status = 1 ")
  286. })
  287. }).Where("status = 1 AND settle_accounts_date >= ? AND settle_accounts_date <= ? AND user_org_id = ? AND order_status = 2 AND patient_id = ? AND p_type=?", start_time, end_time, org_id, patient_id, settle_type)
  288. break
  289. case 1:
  290. readDb2.Model(&models.HisChargeOrderTwo{}).Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
  291. return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").
  292. Preload("HisChargeDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  293. return db.Preload("Drug", "status = 1").Where("status = 1")
  294. }).Where("status = 1 AND advice_id > 0 AND project_id = 0")
  295. }).Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2 AND patient_id = ? AND p_type=?", start_time, end_time, org_id, patient_id, settle_type)
  296. break
  297. case 2:
  298. readDb2.Model(&models.HisChargeOrderTwo{}).Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
  299. return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").
  300. Preload("HisChargePrescriptionProject", func(db *gorm.DB) *gorm.DB {
  301. return db.Select("id,project_id,user_org_id,status,patient_id,record_date,count,type").Preload("HisChargeProject", func(db *gorm.DB) *gorm.DB {
  302. return db.Select("id,project_name,unit").Where("status = 1 ")
  303. }).Preload("HisChargeGoodInfo", func(db *gorm.DB) *gorm.DB {
  304. return db.Select("id,good_name,good_unit,specification_name").Where("status = 1 ")
  305. }).Where("status = 1 AND advice_id = 0 AND project_id > 0 ")
  306. })
  307. }).Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2 AND patient_id = ? AND p_type = ?", start_time, end_time, org_id, patient_id, settle_type)
  308. break
  309. case 3:
  310. readDb2.Model(&models.HisChargeOrderTwo{}).Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
  311. return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").
  312. Preload("HisChargePrescriptionProject", func(db *gorm.DB) *gorm.DB {
  313. return db.Select("id,project_id,user_org_id,status,patient_id,record_date,count,type").Preload("HisChargeProject", func(db *gorm.DB) *gorm.DB {
  314. return db.Select("id,project_name,unit").Where("status = 1 ")
  315. }).Preload("HisChargeGoodInfo", func(db *gorm.DB) *gorm.DB {
  316. return db.Select("id,good_name,good_unit,specification_name").Where("status = 1 ")
  317. }).Where("status = 1 AND advice_id = 0 AND project_id > 0 ")
  318. })
  319. }).Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2 AND patient_id = ? AND p_type = ?", start_time, end_time, org_id, patient_id, settle_type)
  320. break
  321. }
  322. } else {
  323. //keyword := "%" + keyword + "%"
  324. switch item_type {
  325. case 0:
  326. readDb2.Model(&models.HisChargeOrderTwo{}).Joins("join his_patient his on his.number = his_order.mdtrt_id AND his.patient_id = ").Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
  327. return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").
  328. Preload("HisChargeDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  329. return db.Preload("Drug", "status = 1").Where("status = 1")
  330. }).Preload("HisChargePrescriptionProject", func(db *gorm.DB) *gorm.DB {
  331. return db.Select("id,project_id,user_org_id,status,patient_id,record_date,count,type").Preload("HisChargeProject", func(db *gorm.DB) *gorm.DB {
  332. return db.Select("id,project_name,unit").Where("status = 1 ")
  333. }).Preload("HisChargeGoodInfo", func(db *gorm.DB) *gorm.DB {
  334. return db.Select("id,good_name,good_unit,specification_name").Where("status = 1 ")
  335. }).Where("status = 1 ")
  336. })
  337. }).Where("status = 1 AND settle_accounts_date >= ? AND settle_accounts_date <= ? AND user_org_id = ? AND order_status = 2 AND patient_id = ? AND p_type=?", start_time, end_time, org_id, patient_id, settle_type)
  338. break
  339. case 1:
  340. readDb2.Model(&models.HisChargeOrderTwo{}).Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
  341. return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").
  342. Preload("HisChargeDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  343. return db.Preload("Drug", "status = 1").Where("status = 1")
  344. }).Where("status = 1 AND advice_id > 0 AND project_id = 0")
  345. }).Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2 AND patient_id = ? AND p_type=?", start_time, end_time, org_id, patient_id, settle_type)
  346. break
  347. case 2:
  348. readDb2.Model(&models.HisChargeOrderTwo{}).Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
  349. return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").
  350. Preload("HisChargePrescriptionProject", func(db *gorm.DB) *gorm.DB {
  351. return db.Select("id,project_id,user_org_id,status,patient_id,record_date,count,type").Preload("HisChargeProject", func(db *gorm.DB) *gorm.DB {
  352. return db.Select("id,project_name,unit").Where("status = 1 ")
  353. }).Preload("HisChargeGoodInfo", func(db *gorm.DB) *gorm.DB {
  354. return db.Select("id,good_name,good_unit,specification_name").Where("status = 1 ")
  355. }).Where("status = 1 AND advice_id = 0 AND project_id > 0 ")
  356. })
  357. }).Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2 AND patient_id = ? AND p_type = ?", start_time, end_time, org_id, patient_id, settle_type)
  358. break
  359. case 3:
  360. readDb2.Model(&models.HisChargeOrderTwo{}).Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
  361. return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").
  362. Preload("HisChargePrescriptionProject", func(db *gorm.DB) *gorm.DB {
  363. return db.Select("id,project_id,user_org_id,status,patient_id,record_date,count,type").Preload("HisChargeProject", func(db *gorm.DB) *gorm.DB {
  364. return db.Select("id,project_name,unit").Where("status = 1 ")
  365. }).Preload("HisChargeGoodInfo", func(db *gorm.DB) *gorm.DB {
  366. return db.Select("id,good_name,good_unit,specification_name").Where("status = 1 ")
  367. }).Where("status = 1 AND advice_id = 0 AND project_id > 0 ")
  368. })
  369. }).Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2 AND patient_id = ? AND p_type = ?", start_time, end_time, org_id, patient_id, settle_type)
  370. break
  371. }
  372. }
  373. return
  374. }
  375. func GetPatientGather(patient_id int64, org_id int64, start_time int64, end_time int64, keyword string, item_type int64, settle_type int64) (patients []*models.HisChargeOrderTwo, err error) {
  376. if len(keyword) == 0 {
  377. switch item_type {
  378. case 0:
  379. readDb2.Model(&models.HisChargeOrderTwo{}).Joins("join his_patient his on his.number = his_order.mdtrt_id AND his.patient_id = ").Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
  380. return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").
  381. Preload("HisChargeDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  382. return db.Preload("Drug", "status = 1").Where("status = 1")
  383. }).Preload("HisChargePrescriptionProject", func(db *gorm.DB) *gorm.DB {
  384. return db.Select("id,project_id,user_org_id,status,patient_id,record_date,count,type").Preload("HisChargeProject", func(db *gorm.DB) *gorm.DB {
  385. return db.Select("id,project_name,unit").Where("status = 1 ")
  386. }).Preload("HisChargeGoodInfo", func(db *gorm.DB) *gorm.DB {
  387. return db.Select("id,good_name,good_unit,specification_name").Where("status = 1 ")
  388. }).Where("status = 1 ")
  389. })
  390. }).Where("status = 1 AND settle_accounts_date >= ? AND settle_accounts_date <= ? AND user_org_id = ? AND order_status = 2 AND patient_id = ? AND p_type=?", start_time, end_time, org_id, patient_id, settle_type)
  391. break
  392. case 1:
  393. readDb2.Model(&models.HisChargeOrderTwo{}).Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
  394. return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").
  395. Preload("HisChargeDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  396. return db.Preload("Drug", "status = 1").Where("status = 1")
  397. }).Where("status = 1 AND advice_id > 0 AND project_id = 0")
  398. }).Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2 AND patient_id = ? AND p_type=?", start_time, end_time, org_id, patient_id, settle_type)
  399. break
  400. case 2:
  401. readDb2.Model(&models.HisChargeOrderTwo{}).Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
  402. return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").
  403. Preload("HisChargePrescriptionProject", func(db *gorm.DB) *gorm.DB {
  404. return db.Select("id,project_id,user_org_id,status,patient_id,record_date,count,type").Preload("HisChargeProject", func(db *gorm.DB) *gorm.DB {
  405. return db.Select("id,project_name,unit").Where("status = 1 ")
  406. }).Preload("HisChargeGoodInfo", func(db *gorm.DB) *gorm.DB {
  407. return db.Select("id,good_name,good_unit,specification_name").Where("status = 1 ")
  408. }).Where("status = 1 AND advice_id = 0 AND project_id > 0 ")
  409. })
  410. }).Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2 AND patient_id = ? AND p_type = ?", start_time, end_time, org_id, patient_id, settle_type)
  411. break
  412. case 3:
  413. readDb2.Model(&models.HisChargeOrderTwo{}).Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
  414. return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").
  415. Preload("HisChargePrescriptionProject", func(db *gorm.DB) *gorm.DB {
  416. return db.Select("id,project_id,user_org_id,status,patient_id,record_date,count,type").Preload("HisChargeProject", func(db *gorm.DB) *gorm.DB {
  417. return db.Select("id,project_name,unit").Where("status = 1 ")
  418. }).Preload("HisChargeGoodInfo", func(db *gorm.DB) *gorm.DB {
  419. return db.Select("id,good_name,good_unit,specification_name").Where("status = 1 ")
  420. }).Where("status = 1 AND advice_id = 0 AND project_id > 0 ")
  421. })
  422. }).Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2 AND patient_id = ? AND p_type = ?", start_time, end_time, org_id, patient_id, settle_type)
  423. break
  424. }
  425. } else {
  426. //keyword := "%" + keyword + "%"
  427. switch item_type {
  428. case 0:
  429. readDb2.Model(&models.HisChargeOrderTwo{}).Joins("join his_patient his on his.number = his_order.mdtrt_id AND his.patient_id = ").Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
  430. return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").
  431. Preload("HisChargeDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  432. return db.Preload("Drug", "status = 1").Where("status = 1")
  433. }).Preload("HisChargePrescriptionProject", func(db *gorm.DB) *gorm.DB {
  434. return db.Select("id,project_id,user_org_id,status,patient_id,record_date,count,type").Preload("HisChargeProject", func(db *gorm.DB) *gorm.DB {
  435. return db.Select("id,project_name,unit").Where("status = 1 ")
  436. }).Preload("HisChargeGoodInfo", func(db *gorm.DB) *gorm.DB {
  437. return db.Select("id,good_name,good_unit,specification_name").Where("status = 1 ")
  438. }).Where("status = 1 ")
  439. })
  440. }).Where("status = 1 AND settle_accounts_date >= ? AND settle_accounts_date <= ? AND user_org_id = ? AND order_status = 2 AND patient_id = ? AND p_type=?", start_time, end_time, org_id, patient_id, settle_type)
  441. break
  442. case 1:
  443. readDb2.Model(&models.HisChargeOrderTwo{}).Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
  444. return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").
  445. Preload("HisChargeDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  446. return db.Preload("Drug", "status = 1").Where("status = 1")
  447. }).Where("status = 1 AND advice_id > 0 AND project_id = 0")
  448. }).Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2 AND patient_id = ? AND p_type=?", start_time, end_time, org_id, patient_id, settle_type)
  449. break
  450. case 2:
  451. readDb2.Model(&models.HisChargeOrderTwo{}).Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
  452. return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").
  453. Preload("HisChargePrescriptionProject", func(db *gorm.DB) *gorm.DB {
  454. return db.Select("id,project_id,user_org_id,status,patient_id,record_date,count,type").Preload("HisChargeProject", func(db *gorm.DB) *gorm.DB {
  455. return db.Select("id,project_name,unit").Where("status = 1 ")
  456. }).Preload("HisChargeGoodInfo", func(db *gorm.DB) *gorm.DB {
  457. return db.Select("id,good_name,good_unit,specification_name").Where("status = 1 ")
  458. }).Where("status = 1 AND advice_id = 0 AND project_id > 0 ")
  459. })
  460. }).Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2 AND patient_id = ? AND p_type = ?", start_time, end_time, org_id, patient_id, settle_type)
  461. break
  462. case 3:
  463. readDb2.Model(&models.HisChargeOrderTwo{}).Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
  464. return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").
  465. Preload("HisChargePrescriptionProject", func(db *gorm.DB) *gorm.DB {
  466. return db.Select("id,project_id,user_org_id,status,patient_id,record_date,count,type").Preload("HisChargeProject", func(db *gorm.DB) *gorm.DB {
  467. return db.Select("id,project_name,unit").Where("status = 1 ")
  468. }).Preload("HisChargeGoodInfo", func(db *gorm.DB) *gorm.DB {
  469. return db.Select("id,good_name,good_unit,specification_name").Where("status = 1 ")
  470. }).Where("status = 1 AND advice_id = 0 AND project_id > 0 ")
  471. })
  472. }).Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2 AND patient_id = ? AND p_type = ?", start_time, end_time, org_id, patient_id, settle_type)
  473. break
  474. }
  475. }
  476. return
  477. }
  478. func GetAllChargeDetailsTwo(org_id int64, start_time int64, end_time int64) (patients []*models.HisChargeOrder, err error) {
  479. err = readDb2.Model(&models.HisChargeOrder{}).Preload("Patients", "status = 1").Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
  480. return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").
  481. Preload("HisChargeDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  482. return db.Preload("Drug", "status = 1").Where("status = 1")
  483. }).
  484. Preload("HisChargePrescriptionProject", func(db *gorm.DB) *gorm.DB {
  485. return db.Select("id,project_id,user_org_id,status,patient_id,record_date,count,type").
  486. Preload("HisChargeProject", func(db *gorm.DB) *gorm.DB {
  487. return db.Select("id,project_name,unit").Where("status = 1 ")
  488. }).
  489. Preload("HisChargeGoodInfo", func(db *gorm.DB) *gorm.DB {
  490. return db.Select("id,good_name,good_unit,specification_name").Where("status = 1 ")
  491. }).Where("status = 1 ")
  492. }).Where("status = 1")
  493. }).Where("status = 1 AND user_org_id = ? AND settle_accounts_date >= ? AND settle_accounts_date <= ? AND order_status = 2", org_id, start_time, end_time).Group("id").Find(&patients).Error
  494. return
  495. }