his_export_data_controller.go 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "github.com/astaxie/beego"
  7. "github.com/shopspring/decimal"
  8. "strings"
  9. )
  10. type HisExportDataController struct {
  11. BaseAuthAPIController
  12. }
  13. func HisExportDataApiRegistRouters() {
  14. beego.Router("/api/export", &HisExportDataController{}, "Get:GetExportData")
  15. beego.Router("/api/batchsettle/get", &HisExportDataController{}, "Get:GetExportSettleData")
  16. }
  17. func (c *HisExportDataController) GetExportSettleData() {
  18. patient_id, _ := c.GetInt64("patient_id", 0)
  19. start_time := c.GetString("start_time")
  20. end_time := c.GetString("end_time")
  21. admin_user_id, _ := c.GetInt64("admin_user_id")
  22. var order models.HisOrder
  23. orders, _ := service.GetHisOrderByTime(patient_id, start_time, end_time)
  24. order = orders[len(orders)-1]
  25. order.MedfeeSumamt = 0
  26. order.FundPaySumamt = 0
  27. order.PsnCashPay = 0
  28. order.ActPayDedc = 0
  29. order.PreselfpayAmt = 0
  30. order.HifpPay = 0
  31. order.HifmiPay = 0
  32. order.HifesPay = 0
  33. order.MafPay = 0
  34. order.CvlservPay = 0
  35. order.OthPay = 0
  36. order.AcctPay = 0
  37. decimal.DivisionPrecision = 2
  38. var orderInfos []models.BatchHisOrderInfo
  39. for _, item := range orders {
  40. order.MedfeeSumamt, _ = decimal.NewFromFloat(order.MedfeeSumamt).Add(decimal.NewFromFloat(item.MedfeeSumamt)).Float64()
  41. order.FundPaySumamt, _ = decimal.NewFromFloat(order.FundPaySumamt).Add(decimal.NewFromFloat(item.FundPaySumamt)).Float64()
  42. order.PsnCashPay, _ = decimal.NewFromFloat(order.PsnCashPay).Add(decimal.NewFromFloat(item.PsnCashPay)).Float64()
  43. order.ActPayDedc, _ = decimal.NewFromFloat(order.ActPayDedc).Add(decimal.NewFromFloat(item.ActPayDedc)).Float64()
  44. order.PreselfpayAmt, _ = decimal.NewFromFloat(order.PreselfpayAmt).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  45. order.HifpPay, _ = decimal.NewFromFloat(order.HifpPay).Add(decimal.NewFromFloat(item.HifpPay)).Float64()
  46. order.HifmiPay, _ = decimal.NewFromFloat(order.HifmiPay).Add(decimal.NewFromFloat(item.HifmiPay)).Float64()
  47. order.HifesPay, _ = decimal.NewFromFloat(order.HifesPay).Add(decimal.NewFromFloat(item.HifesPay)).Float64()
  48. order.MafPay, _ = decimal.NewFromFloat(order.MafPay).Add(decimal.NewFromFloat(item.MafPay)).Float64()
  49. order.CvlservPay, _ = decimal.NewFromFloat(order.CvlservPay).Add(decimal.NewFromFloat(item.CvlservPay)).Float64()
  50. order.OthPay, _ = decimal.NewFromFloat(order.OthPay).Add(decimal.NewFromFloat(item.OthPay)).Float64()
  51. order.AcctPay, _ = decimal.NewFromFloat(order.AcctPay).Add(decimal.NewFromFloat(item.AcctPay)).Float64()
  52. orderInfo, _ := service.GetBatchHisOrderInfoByNumber(item.Number)
  53. orderInfos = append(orderInfos, orderInfo...)
  54. }
  55. //role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  56. if order.ID == 0 {
  57. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  58. return
  59. }
  60. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  61. org_id := c.GetAdminUserInfo().CurrentOrgId
  62. //adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  63. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  64. printor_admin, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  65. charge_admin, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, order.Creator)
  66. var bedCostTotal float64 = 0 //床位总费
  67. var bedCostSelfTotal float64 = 0 //床位自费
  68. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  69. var operationCostTotal float64 = 0 //手术费
  70. var operationCostSelfTotal float64 = 0 //手术费
  71. var operationCostPartSelfTotal float64 = 0 //手术费
  72. var otherCostTotal float64 = 0 //其他费用
  73. var otherCostSelfTotal float64 = 0 //其他费用
  74. var otherCostPartSelfTotal float64 = 0 //其他费用
  75. var materialCostTotal float64 = 0 //材料费
  76. var materialCostSelfTotal float64 = 0 //材料费
  77. var materialCostPartSelfTotal float64 = 0 //材料费
  78. var westernMedicineCostTotal float64 = 0 //西药费
  79. var westernMedicineCostSelfTotal float64 = 0 //西药费
  80. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  81. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  82. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  83. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  84. var checkCostTotal float64 = 0 //检查费
  85. var checkCostSelfTotal float64 = 0 //检查费
  86. var checkCostPartSelfTotal float64 = 0 //检查费
  87. var laboratoryCostTotal float64 = 0 //化验费
  88. var laboratoryCostSelfTotal float64 = 0 //化验费
  89. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  90. var treatCostTotal float64 = 0 //治疗费用
  91. var treatCostSelfTotal float64 = 0 //治疗费用
  92. var treatCostPartSelfTotal float64 = 0 //治疗费用
  93. var hiliCostTotal float64 = 0 //护理费
  94. var hiliCostSelfTotal float64 = 0 //护理费
  95. var hiliCostPartSelfTotal float64 = 0 //护理费
  96. decimal.DivisionPrecision = 2
  97. for _, item := range orderInfos {
  98. if item.MedChrgitmType == "01" { //床位费
  99. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  100. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  101. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  102. }
  103. if item.MedChrgitmType == "07" { //床位费
  104. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  105. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  106. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  107. //hiliCostSelfTotal = hiliCostTotal
  108. }
  109. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  110. if item.MedChrgitmType == "03" { //检查费
  111. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  112. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  113. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  114. }
  115. } else {
  116. if item.MedChrgitmType == "03" { //检查费
  117. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  118. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  119. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  120. }
  121. }
  122. if item.MedChrgitmType == "04" { //化验费
  123. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  124. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  125. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  126. }
  127. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  128. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  129. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  130. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  131. }
  132. if item.MedChrgitmType == "06" { //手术费
  133. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  134. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  135. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  136. }
  137. if item.MedChrgitmType == "08" { //材料费
  138. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  139. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  140. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  141. }
  142. if item.MedChrgitmType == "09" { //西药费
  143. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  144. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  145. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  146. }
  147. if item.MedChrgitmType == "11" { //中成费
  148. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  149. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  150. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  151. }
  152. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  153. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  154. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  155. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  156. }
  157. }
  158. c.ServeSuccessJSON(map[string]interface{}{
  159. "order_infos": orderInfos,
  160. "number": order.MdtrtId,
  161. "date": order.SettleAccountsDate,
  162. "charge_admin": charge_admin,
  163. "printor_admin": printor_admin,
  164. "info": order,
  165. "bedCostTotal": bedCostTotal,
  166. "bedCostSelfTotal": bedCostSelfTotal,
  167. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  168. "operationCostTotal": operationCostTotal,
  169. "operationCostSelfTotal": operationCostSelfTotal,
  170. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  171. "otherCostTotal": otherCostTotal,
  172. "otherCostSelfTotal": otherCostSelfTotal,
  173. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  174. "materialCostTotal": materialCostTotal,
  175. "materialCostSelfTotal": materialCostSelfTotal,
  176. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  177. "westernMedicineCostTotal": westernMedicineCostTotal,
  178. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  179. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  180. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  181. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  182. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  183. "checkCostTotal": checkCostTotal,
  184. "checkCostSelfTotal": checkCostSelfTotal,
  185. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  186. "laboratoryCostTotal": laboratoryCostTotal,
  187. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  188. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  189. "treatCostTotal": treatCostTotal,
  190. "treatCostSelfTotal": treatCostSelfTotal,
  191. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  192. "hiliCostTotal": hiliCostTotal,
  193. "hiliCostSelfTotal": hiliCostSelfTotal,
  194. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  195. "patient": patient,
  196. "org_name": miConfig.OrgName,
  197. "org_code": miConfig.Code,
  198. "num": len(orders),
  199. "f_time": strings.Split(orders[0].SetlTime, " ")[0],
  200. "l_time": strings.Split(orders[len(orders)-1].SetlTime, " ")[0],
  201. })
  202. }
  203. func (this *HisExportDataController) GetExportData() {
  204. start_time := this.GetString("start_time")
  205. start_time = start_time + " 00:00:00"
  206. end_time := this.GetString("end_time")
  207. end_time = end_time + " 23:59:59"
  208. type_str := this.GetString("type")
  209. if type_str == "1" {
  210. ps, _ := service.GetHisOrderDetailFor310(start_time, end_time, this.GetAdminUserInfo().CurrentOrgId)
  211. this.ServeSuccessJSON(map[string]interface{}{
  212. "order": ps,
  213. })
  214. } else {
  215. ps, _ := service.GetHisOrderDetailFor390(start_time, end_time, this.GetAdminUserInfo().CurrentOrgId)
  216. this.ServeSuccessJSON(map[string]interface{}{
  217. "order": ps,
  218. })
  219. }
  220. }