his_charge_api_controller.go 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "bytes"
  8. "compress/gzip"
  9. "encoding/json"
  10. "github.com/astaxie/beego"
  11. "net/http"
  12. "time"
  13. )
  14. type HisChargeApiController struct {
  15. BaseAuthAPIController
  16. }
  17. func HisChargeApiRegistRouters() {
  18. beego.Router("/api/his/chargestatistics/detail", &HisChargeApiController{}, "get:GetChargeStatisticsDetail")
  19. beego.Router("/api/his/chargestatistics/settle", &HisChargeApiController{}, "get:GetChargeStatisticsSettle")
  20. beego.Router("/api/his/prescription/detail", &HisChargeApiController{}, "get:GetPrescriptionStatisticsDetail")
  21. beego.Router("/api/his/prescription/initdata", &HisChargeApiController{}, "get:GetPrescriptionInitData")
  22. //beego.InsertFilter("/api/his/chargestatistics/detail", beego.BeforeRouter, GzipFilter)
  23. beego.Router("/api/his/patient", &HisChargeApiController{}, "get:GetAllPatient")
  24. //beego.Router("/api/his/chargestatistics/settle", &HisChargeApiController{}, "get:GetChargeStatisticsSettle")
  25. beego.Router("/api/his/inspectionlist/get", &HisChargeApiController{}, "get:GetHisInspectionList")
  26. beego.Router("/api/his/inspectionlisttwo/get", &HisChargeApiController{}, "get:GetHisInspectionListTwo")
  27. beego.Router("/api/his/inspectioninfo/get", &HisChargeApiController{}, "get:GetHisInspectionInfo")
  28. //发票
  29. beego.Router("/api/fapiao/create", &HisChargeApiController{}, "post:CreateFaPiaoRecord")
  30. beego.Router("/api/fapiao/modify", &HisChargeApiController{}, "post:ModifyFaPiaoRecord")
  31. beego.Router("/api/fapiao/list", &HisChargeApiController{}, "get:GetFaPiaoRecordList")
  32. beego.Router("/api/fapiao/delete", &HisChargeApiController{}, "post:DeleteFaPiaoRecord")
  33. beego.Router("/api/fapiao", &HisChargeApiController{}, "get:GetFaPiaoRecord")
  34. beego.Router("/api/fapiao/is_use", &HisChargeApiController{}, "post:UpdateFaPiaoRecordIsUse")
  35. beego.Router("/api/his/getyidiclear", &HisChargeApiController{}, "get:GetHisYidiClearRecord")
  36. beego.Router("/api/his/getexportdata", &HisChargeApiController{}, "get:GetExportData")
  37. }
  38. func (c *HisChargeApiController) GetExportData() {
  39. start_time := c.GetString("start_time")
  40. end_time := c.GetString("end_time")
  41. adminUser := c.GetAdminUserInfo()
  42. timeLayout := "2006-01-02"
  43. loc, _ := time.LoadLocation("Local")
  44. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  45. if err != nil {
  46. }
  47. startRecordDateTime := startTime.Unix()
  48. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  49. if err != nil {
  50. }
  51. endRecordDateTime := endTime.Unix()
  52. chargePatient, err := service.GetAllChargeDetailsTwo(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime)
  53. if err == nil {
  54. c.ServeSuccessJSON(map[string]interface{}{
  55. "patients": chargePatient,
  56. })
  57. return
  58. } else {
  59. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  60. return
  61. }
  62. }
  63. func (c *HisChargeApiController) UpdateFaPiaoRecordIsUse() {
  64. id, _ := c.GetInt64("id", 0)
  65. is_use, _ := c.GetInt64("is_use")
  66. if id <= 0 {
  67. utils.ErrorLog("id == 0")
  68. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  69. return
  70. }
  71. record, _ := service.FindFapiaoById(id)
  72. adminUserInfo := c.GetAdminUserInfo()
  73. service.UpdateFapiaoIsUse(adminUserInfo.CurrentOrgId)
  74. records := models.HisFapiaoRecord{
  75. ID: id,
  76. FapiaoCode: record.FapiaoCode,
  77. FapiaoNumber: record.FapiaoNumber,
  78. Ctime: time.Now().Unix(),
  79. Mtime: time.Now().Unix(),
  80. UserOrgId: adminUserInfo.CurrentOrgId,
  81. Status: 1,
  82. IsUse: is_use,
  83. }
  84. err := service.ModifyFapiao(&records)
  85. if err == nil {
  86. c.ServeSuccessJSON(map[string]interface{}{
  87. "fapiao_record": records,
  88. })
  89. } else {
  90. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  91. }
  92. }
  93. func (c *HisChargeApiController) CreateFaPiaoRecord() {
  94. fapiao_code := c.GetString("fapiao_code")
  95. fapiao_number := c.GetString("fapiao_number")
  96. if len(fapiao_code) <= 0 {
  97. utils.ErrorLog("len(fapiao_code) == 0")
  98. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  99. return
  100. }
  101. if len(fapiao_number) <= 0 {
  102. utils.ErrorLog("len(fapiao_number) == 0")
  103. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  104. return
  105. }
  106. adminUserInfo := c.GetAdminUserInfo()
  107. record := models.HisFapiaoRecord{
  108. FapiaoCode: fapiao_code,
  109. FapiaoNumber: fapiao_number,
  110. Ctime: time.Now().Unix(),
  111. Mtime: time.Now().Unix(),
  112. UserOrgId: adminUserInfo.CurrentOrgId,
  113. Status: 1,
  114. IsUse: 0,
  115. }
  116. err, records := service.AddSigleFapiaoRecord(&record)
  117. if err == nil {
  118. c.ServeSuccessJSON(map[string]interface{}{
  119. "fapiao_record": records,
  120. })
  121. } else {
  122. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  123. }
  124. }
  125. func (c *HisChargeApiController) ModifyFaPiaoRecord() {
  126. id, _ := c.GetInt64("id", 0)
  127. fapiao_code := c.GetString("fapiao_code")
  128. fapiao_number := c.GetString("fapiao_number")
  129. if id <= 0 {
  130. utils.ErrorLog("id == 0")
  131. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  132. return
  133. }
  134. if len(fapiao_code) <= 0 {
  135. utils.ErrorLog("len(fapiao_code) == 0")
  136. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  137. return
  138. }
  139. if len(fapiao_number) <= 0 {
  140. utils.ErrorLog("len(fapiao_number) == 0")
  141. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  142. return
  143. }
  144. record, _ := service.FindFapiaoById(id)
  145. adminUserInfo := c.GetAdminUserInfo()
  146. records := models.HisFapiaoRecord{
  147. ID: id,
  148. FapiaoCode: fapiao_code,
  149. FapiaoNumber: fapiao_number,
  150. Ctime: time.Now().Unix(),
  151. Mtime: time.Now().Unix(),
  152. UserOrgId: adminUserInfo.CurrentOrgId,
  153. Status: 1,
  154. IsUse: record.IsUse,
  155. }
  156. err := service.ModifyFapiao(&records)
  157. if err == nil {
  158. c.ServeSuccessJSON(map[string]interface{}{
  159. "fapiao_record": records,
  160. })
  161. } else {
  162. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  163. }
  164. }
  165. func (c *HisChargeApiController) GetFaPiaoRecordList() {
  166. page, _ := c.GetInt64("page", 1)
  167. limit, _ := c.GetInt64("limit", 7)
  168. adminUserInfo := c.GetAdminUserInfo()
  169. fapiaoRecord, total, err := service.FindAllFapiaoList(adminUserInfo.CurrentOrgId, page, limit)
  170. if err == nil {
  171. c.ServeSuccessJSON(map[string]interface{}{
  172. "fapiao_record": fapiaoRecord,
  173. "total": total,
  174. })
  175. } else {
  176. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  177. }
  178. }
  179. func (c *HisChargeApiController) DeleteFaPiaoRecord() {
  180. id, _ := c.GetInt64("id", 0)
  181. err := service.DeleteFapiaoById(id)
  182. if err == nil {
  183. c.ServeSuccessJSON(map[string]interface{}{
  184. "msg": "删除成功",
  185. })
  186. } else {
  187. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  188. }
  189. }
  190. func (c *HisChargeApiController) GetFaPiaoRecord() {
  191. id, _ := c.GetInt64("id", 0)
  192. fapiaoRecord, err := service.FindFapiaoById(id)
  193. if err == nil {
  194. c.ServeSuccessJSON(map[string]interface{}{
  195. "fapiao_record": fapiaoRecord,
  196. })
  197. } else {
  198. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  199. }
  200. }
  201. func (c *HisChargeApiController) GetChargeStatisticsDetail() {
  202. //c.ServeSuccessJSON(map[string]interface{}{
  203. // "msg": "接口优化升级,如有数据需要,请联系客服!",
  204. //})
  205. //return
  206. start_time := c.GetString("start_time")
  207. end_time := c.GetString("end_time")
  208. time_type := c.GetString("time_type")
  209. keyword := c.GetString("keyword")
  210. item_type, _ := c.GetInt64("type")
  211. adminUser := c.GetAdminUserInfo()
  212. timeLayout := "2006-01-02"
  213. loc, _ := time.LoadLocation("Local")
  214. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  215. if err != nil {
  216. }
  217. startRecordDateTime := startTime.Unix()
  218. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  219. if err != nil {
  220. }
  221. endRecordDateTime := endTime.Unix()
  222. switch item_type {
  223. case 0:
  224. chargeDrug, err := service.GetNewAllPatientDrugChargeDetails(adminUser.CurrentOrgId, start_time+" 00:00:00", end_time+" 23:59:59", startRecordDateTime, endRecordDateTime, keyword, item_type, time_type)
  225. chargeProject, err := service.GetNewAllPatientProjectAndGoodChargeDetails(adminUser.CurrentOrgId, start_time+" 00:00:00", end_time+" 23:59:59", startRecordDateTime, endRecordDateTime, keyword, item_type, time_type)
  226. chargeDrug = append(chargeDrug, chargeProject...)
  227. b, _ := structToBytes(chargeDrug)
  228. //cd, _ := compressData(b)
  229. // 使用 Gzip 压缩数据
  230. var compressedData bytes.Buffer
  231. writer := gzip.NewWriter(&compressedData)
  232. _, err = writer.Write(b)
  233. if err != nil {
  234. c.Ctx.ResponseWriter.WriteHeader(http.StatusInternalServerError)
  235. c.Ctx.WriteString(err.Error())
  236. return
  237. }
  238. writer.Close()
  239. // 设置响应头,表明数据经过了 Gzip 压缩
  240. c.Ctx.Output.Header("Content-Encoding", "gzip")
  241. // 发送压缩后的数据
  242. c.Ctx.ResponseWriter.Write(compressedData.Bytes())
  243. break
  244. case 1:
  245. chargeDrug, err := service.GetNewAllPatientDrugChargeDetails(adminUser.CurrentOrgId, start_time+" 00:00:00", end_time+" 23:59:59", startRecordDateTime, endRecordDateTime, keyword, item_type, time_type)
  246. //chargeProject, err := service.GetNewAllPatientProjectAndGoodChargeDetails(adminUser.CurrentOrgId, start_time+" 00:00:00", end_time+" 23:59:59", startRecordDateTime, endRecordDateTime, keyword, item_type)
  247. //chargeDrug = append(chargeDrug, chargeProject...)
  248. b, _ := structToBytes(chargeDrug)
  249. //cd, _ := compressData(b)
  250. // 使用 Gzip 压缩数据
  251. var compressedData bytes.Buffer
  252. writer := gzip.NewWriter(&compressedData)
  253. _, err = writer.Write(b)
  254. if err != nil {
  255. c.Ctx.ResponseWriter.WriteHeader(http.StatusInternalServerError)
  256. c.Ctx.WriteString(err.Error())
  257. return
  258. }
  259. writer.Close()
  260. // 设置响应头,表明数据经过了 Gzip 压缩
  261. c.Ctx.Output.Header("Content-Encoding", "gzip")
  262. // 发送压缩后的数据
  263. c.Ctx.ResponseWriter.Write(compressedData.Bytes())
  264. break
  265. case 2:
  266. //chargeDrug, err := service.GetNewAllPatientDrugChargeDetails(adminUser.CurrentOrgId, start_time+" 00:00:00", end_time+" 23:59:59", startRecordDateTime, endRecordDateTime, keyword, item_type)
  267. chargeProject, err := service.GetNewAllPatientProjectAndGoodChargeDetails(adminUser.CurrentOrgId, start_time+" 00:00:00", end_time+" 23:59:59", startRecordDateTime, endRecordDateTime, keyword, item_type, time_type)
  268. //chargeDrug = append(chargeDrug, chargeProject...)
  269. b, _ := structToBytes(chargeProject)
  270. //cd, _ := compressData(b)
  271. // 使用 Gzip 压缩数据
  272. var compressedData bytes.Buffer
  273. writer := gzip.NewWriter(&compressedData)
  274. _, err = writer.Write(b)
  275. if err != nil {
  276. c.Ctx.ResponseWriter.WriteHeader(http.StatusInternalServerError)
  277. c.Ctx.WriteString(err.Error())
  278. return
  279. }
  280. writer.Close()
  281. // 设置响应头,表明数据经过了 Gzip 压缩
  282. c.Ctx.Output.Header("Content-Encoding", "gzip")
  283. // 发送压缩后的数据
  284. c.Ctx.ResponseWriter.Write(compressedData.Bytes())
  285. break
  286. case 3:
  287. //chargeDrug, err := service.GetNewAllPatientDrugChargeDetails(adminUser.CurrentOrgId, start_time+" 00:00:00", end_time+" 23:59:59", startRecordDateTime, endRecordDateTime, keyword, item_type)
  288. chargeProject, err := service.GetNewAllPatientProjectAndGoodChargeDetails(adminUser.CurrentOrgId, start_time+" 00:00:00", end_time+" 23:59:59", startRecordDateTime, endRecordDateTime, keyword, item_type, time_type)
  289. //chargeDrug = append(chargeDrug, chargeProject...)
  290. b, _ := structToBytes(chargeProject)
  291. //cd, _ := compressData(b)
  292. // 使用 Gzip 压缩数据
  293. var compressedData bytes.Buffer
  294. writer := gzip.NewWriter(&compressedData)
  295. _, err = writer.Write(b)
  296. if err != nil {
  297. c.Ctx.ResponseWriter.WriteHeader(http.StatusInternalServerError)
  298. c.Ctx.WriteString(err.Error())
  299. return
  300. }
  301. writer.Close()
  302. // 设置响应头,表明数据经过了 Gzip 压缩
  303. c.Ctx.Output.Header("Content-Encoding", "gzip")
  304. // 发送压缩后的数据
  305. c.Ctx.ResponseWriter.Write(compressedData.Bytes())
  306. break
  307. case 4:
  308. //chargeDrug, err := service.GetNewAllPatientDrugChargeDetails(adminUser.CurrentOrgId, start_time+" 00:00:00", end_time+" 23:59:59", startRecordDateTime, endRecordDateTime, keyword, item_type)
  309. chargeProject, err := service.GetNewAllPatientProjectAndGoodChargeDetails(adminUser.CurrentOrgId, start_time+" 00:00:00", end_time+" 23:59:59", startRecordDateTime, endRecordDateTime, keyword, item_type, time_type)
  310. //chargeDrug = append(chargeDrug, chargeProject...)
  311. b, _ := structToBytes(chargeProject)
  312. //cd, _ := compressData(b)
  313. // 使用 Gzip 压缩数据
  314. var compressedData bytes.Buffer
  315. writer := gzip.NewWriter(&compressedData)
  316. _, err = writer.Write(b)
  317. if err != nil {
  318. c.Ctx.ResponseWriter.WriteHeader(http.StatusInternalServerError)
  319. c.Ctx.WriteString(err.Error())
  320. return
  321. }
  322. writer.Close()
  323. // 设置响应头,表明数据经过了 Gzip 压缩
  324. c.Ctx.Output.Header("Content-Encoding", "gzip")
  325. // 发送压缩后的数据
  326. c.Ctx.ResponseWriter.Write(compressedData.Bytes())
  327. break
  328. case 5:
  329. //chargeDrug, err := service.GetNewAllPatientDrugChargeDetails(adminUser.CurrentOrgId, start_time+" 00:00:00", end_time+" 23:59:59", startRecordDateTime, endRecordDateTime, keyword, item_type)
  330. chargeProject, err := service.GetNewAllPatientProjectAndGoodChargeDetails(adminUser.CurrentOrgId, start_time+" 00:00:00", end_time+" 23:59:59", startRecordDateTime, endRecordDateTime, keyword, item_type, time_type)
  331. //chargeDrug = append(chargeDrug, chargeProject...)
  332. b, _ := structToBytes(chargeProject)
  333. //cd, _ := compressData(b)
  334. // 使用 Gzip 压缩数据
  335. var compressedData bytes.Buffer
  336. writer := gzip.NewWriter(&compressedData)
  337. _, err = writer.Write(b)
  338. if err != nil {
  339. c.Ctx.ResponseWriter.WriteHeader(http.StatusInternalServerError)
  340. c.Ctx.WriteString(err.Error())
  341. return
  342. }
  343. writer.Close()
  344. // 设置响应头,表明数据经过了 Gzip 压缩
  345. c.Ctx.Output.Header("Content-Encoding", "gzip")
  346. // 发送压缩后的数据
  347. c.Ctx.ResponseWriter.Write(compressedData.Bytes())
  348. break
  349. case 6:
  350. //chargeDrug, err := service.GetNewAllPatientDrugChargeDetails(adminUser.CurrentOrgId, start_time+" 00:00:00", end_time+" 23:59:59", startRecordDateTime, endRecordDateTime, keyword, item_type)
  351. chargeProject, err := service.GetNewAllPatientProjectAndGoodChargeDetails(adminUser.CurrentOrgId, start_time+" 00:00:00", end_time+" 23:59:59", startRecordDateTime, endRecordDateTime, keyword, item_type, time_type)
  352. //chargeDrug = append(chargeDrug, chargeProject...)
  353. b, _ := structToBytes(chargeProject)
  354. //cd, _ := compressData(b)
  355. // 使用 Gzip 压缩数据
  356. var compressedData bytes.Buffer
  357. writer := gzip.NewWriter(&compressedData)
  358. _, err = writer.Write(b)
  359. if err != nil {
  360. c.Ctx.ResponseWriter.WriteHeader(http.StatusInternalServerError)
  361. c.Ctx.WriteString(err.Error())
  362. return
  363. }
  364. writer.Close()
  365. // 设置响应头,表明数据经过了 Gzip 压缩
  366. c.Ctx.Output.Header("Content-Encoding", "gzip")
  367. // 发送压缩后的数据
  368. c.Ctx.ResponseWriter.Write(compressedData.Bytes())
  369. break
  370. case 7:
  371. //chargeDrug, err := service.GetNewAllPatientDrugChargeDetails(adminUser.CurrentOrgId, start_time+" 00:00:00", end_time+" 23:59:59", startRecordDateTime, endRecordDateTime, keyword, item_type)
  372. chargeProject, err := service.GetNewAllPatientProjectAndGoodChargeDetails(adminUser.CurrentOrgId, start_time+" 00:00:00", end_time+" 23:59:59", startRecordDateTime, endRecordDateTime, keyword, item_type, time_type)
  373. //chargeDrug = append(chargeDrug, chargeProject...)
  374. b, _ := structToBytes(chargeProject)
  375. //cd, _ := compressData(b)
  376. // 使用 Gzip 压缩数据
  377. var compressedData bytes.Buffer
  378. writer := gzip.NewWriter(&compressedData)
  379. _, err = writer.Write(b)
  380. if err != nil {
  381. c.Ctx.ResponseWriter.WriteHeader(http.StatusInternalServerError)
  382. c.Ctx.WriteString(err.Error())
  383. return
  384. }
  385. writer.Close()
  386. // 设置响应头,表明数据经过了 Gzip 压缩
  387. c.Ctx.Output.Header("Content-Encoding", "gzip")
  388. // 发送压缩后的数据
  389. c.Ctx.ResponseWriter.Write(compressedData.Bytes())
  390. break
  391. }
  392. }
  393. func (c *HisChargeApiController) GetPrescriptionStatisticsDetail() {
  394. start_time := c.GetString("start_time")
  395. end_time := c.GetString("end_time")
  396. patient_id, _ := c.GetInt64("patient_id")
  397. item_type, _ := c.GetInt64("type")
  398. date1, _ := time.Parse("2006-01-02", start_time)
  399. date2, _ := time.Parse("2006-01-02", end_time)
  400. // 计算日期间隔
  401. duration := date2.Sub(date1)
  402. // 一个月的时间跨度为30天 * 24小时 * 60分钟 * 60秒
  403. oneMonthDuration := 30 * 24 * time.Hour
  404. if duration <= oneMonthDuration {
  405. } else {
  406. c.ServeFailJSONWithSGJErrorCode(enums.ErrorTimeCodeParamWrong)
  407. return
  408. }
  409. adminUser := c.GetAdminUserInfo()
  410. timeLayout := "2006-01-02"
  411. loc, _ := time.LoadLocation("Local")
  412. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  413. if err != nil {
  414. }
  415. startRecordDateTime := startTime.Unix()
  416. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  417. if err != nil {
  418. }
  419. endRecordDateTime := endTime.Unix()
  420. chargeDrug, err := service.GetHisPrescriptionDrugDetails(adminUser.CurrentOrgId, start_time+" 00:00:00", end_time+" 23:59:59", startRecordDateTime, endRecordDateTime, patient_id, item_type)
  421. chargeProject, err := service.GetHisPrescriptionProjectDetails(adminUser.CurrentOrgId, start_time+" 00:00:00", end_time+" 23:59:59", startRecordDateTime, endRecordDateTime, patient_id, item_type)
  422. chargeDrug = append(chargeDrug, chargeProject...)
  423. b, _ := structpToBytes(chargeDrug)
  424. //cd, _ := compressData(b)
  425. // 使用 Gzip 压缩数据
  426. var compressedData bytes.Buffer
  427. writer := gzip.NewWriter(&compressedData)
  428. _, err = writer.Write(b)
  429. if err != nil {
  430. c.Ctx.ResponseWriter.WriteHeader(http.StatusInternalServerError)
  431. c.Ctx.WriteString(err.Error())
  432. return
  433. }
  434. writer.Close()
  435. // 设置响应头,表明数据经过了 Gzip 压缩
  436. c.Ctx.Output.Header("Content-Encoding", "gzip")
  437. // 发送压缩后的数据
  438. c.Ctx.ResponseWriter.Write(compressedData.Bytes())
  439. }
  440. func (c *HisChargeApiController) GetPrescriptionInitData() {
  441. var drugType = "药品类型"
  442. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  443. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, c.GetAdminUserInfo().CurrentOrgId)
  444. var costClassify = "费用类别"
  445. costClassifyParent, _ := service.GetDrugDataConfig(0, costClassify)
  446. costClassifyList, _ := service.GetParentDataConfig(costClassifyParent.ID, c.GetAdminUserInfo().CurrentOrgId)
  447. c.ServeSuccessJSON(map[string]interface{}{
  448. "drugTypeList": drugTypeList,
  449. "costClassifyList": costClassifyList,
  450. })
  451. }
  452. func structpToBytes(p []*models.NewPDetail) ([]byte, error) {
  453. data, err := json.Marshal(p)
  454. if err != nil {
  455. return nil, err
  456. }
  457. return data, nil
  458. }
  459. func structToBytes(p []*models.NewChargeDetail) ([]byte, error) {
  460. data, err := json.Marshal(p)
  461. if err != nil {
  462. return nil, err
  463. }
  464. return data, nil
  465. }
  466. func compressData(data []byte) ([]byte, error) {
  467. var compressedData bytes.Buffer
  468. writer := gzip.NewWriter(&compressedData)
  469. _, err := writer.Write(data)
  470. if err != nil {
  471. return nil, err
  472. }
  473. err = writer.Close()
  474. if err != nil {
  475. return nil, err
  476. }
  477. return compressedData.Bytes(), nil
  478. }
  479. func (c *HisChargeApiController) GetChargeStatisticsSettle() {
  480. start_time := c.GetString("start_time")
  481. end_time := c.GetString("end_time")
  482. keyword := c.GetString("keyword")
  483. item_type, _ := c.GetInt64("type")
  484. adminUser := c.GetAdminUserInfo()
  485. timeLayout := "2006-01-02"
  486. loc, _ := time.LoadLocation("Local")
  487. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  488. if err != nil {
  489. }
  490. startRecordDateTime := startTime.Unix()
  491. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  492. if err != nil {
  493. }
  494. endRecordDateTime := endTime.Unix()
  495. chargePatient, err := service.GetAllPatientChargeSettle(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, keyword, item_type)
  496. sick, _, _ := service.FindAllMZSickList(adminUser.CurrentOrgId, 1, 10000)
  497. config, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  498. if err == nil {
  499. c.ServeSuccessJSON(map[string]interface{}{
  500. "patients": chargePatient,
  501. "config": config,
  502. "sick": sick,
  503. })
  504. return
  505. } else {
  506. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  507. return
  508. }
  509. }
  510. func (c *HisChargeApiController) GetHisInspectionList() {
  511. record_date := c.GetString("record_date")
  512. keyword := c.GetString("keyword")
  513. is_print, _ := c.GetInt64("is_print")
  514. page, _ := c.GetInt64("page")
  515. limit, _ := c.GetInt64("limit")
  516. tube_color, _ := c.GetInt64("tube_color")
  517. adminUser := c.GetAdminUserInfo()
  518. timeLayout := "2006-01-02"
  519. loc, _ := time.LoadLocation("Local")
  520. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  521. if err != nil {
  522. }
  523. record_time := startTime.Unix()
  524. var labels []*models.HisLabelPrintInfo
  525. var labels_two []*models.HisLabelPrintInfo
  526. var total int64
  527. var total_two int64
  528. //var err error
  529. if tube_color == 0 {
  530. labels, total, err = service.GetLabelPrintList(page, limit, adminUser.CurrentOrgId, record_time, is_print, keyword, tube_color)
  531. } else {
  532. labels, total, err = service.GetLabelPrintList(page, limit, adminUser.CurrentOrgId, record_time, is_print, keyword, tube_color)
  533. labels_two, total_two, err = service.GetLabelPrintListTwo(page, limit, adminUser.CurrentOrgId, record_time, is_print, keyword, tube_color)
  534. total = total + total_two
  535. labels = append(labels, labels_two...)
  536. }
  537. if err == nil {
  538. c.ServeSuccessJSON(map[string]interface{}{
  539. "labels": labels,
  540. "total": total,
  541. })
  542. return
  543. } else {
  544. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  545. return
  546. }
  547. }
  548. func (c *HisChargeApiController) GetHisInspectionListTwo() {
  549. record_date := c.GetString("record_date")
  550. keyword := c.GetString("keyword")
  551. is_print, _ := c.GetInt64("is_print")
  552. tube_color, _ := c.GetInt64("tube_color")
  553. adminUser := c.GetAdminUserInfo()
  554. timeLayout := "2006-01-02"
  555. loc, _ := time.LoadLocation("Local")
  556. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  557. if err != nil {
  558. }
  559. record_time := startTime.Unix()
  560. var labels []*models.HisLabelPrintInfo
  561. //var labels_two []*models.HisLabelPrintInfo
  562. //var total int64
  563. //var total_two int64
  564. labels, _, err = service.GetLabelPrintListThree(adminUser.CurrentOrgId, record_time, is_print, keyword, tube_color)
  565. //labels_two, total_two, err = service.GetLabelPrintListFour(adminUser.CurrentOrgId, record_time, is_print, keyword, tube_color)
  566. //total = total + total_two
  567. //labels = append(labels, labels_two...)
  568. if err == nil {
  569. c.ServeSuccessJSON(map[string]interface{}{
  570. "labels": labels,
  571. //"total": total,
  572. })
  573. return
  574. } else {
  575. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  576. return
  577. }
  578. }
  579. func (c *HisChargeApiController) GetHisInspectionInfo() {
  580. id, _ := c.GetInt64("id")
  581. label, err := service.GetLabelPrintInfo(id)
  582. if err == nil {
  583. c.ServeSuccessJSON(map[string]interface{}{
  584. "label": label,
  585. })
  586. return
  587. } else {
  588. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  589. return
  590. }
  591. }
  592. func (c *HisChargeApiController) GetHisYidiClearRecord() {
  593. records, err := service.FindHisYidiClearRecord(c.GetAdminUserInfo().CurrentOrgId)
  594. if err == nil {
  595. c.ServeSuccessJSON(map[string]interface{}{
  596. "list": records,
  597. })
  598. return
  599. } else {
  600. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  601. return
  602. }
  603. }
  604. func (c *HisChargeApiController) GetAllPatient() {
  605. patients, err := service.GetAllPatientTwo(c.GetAdminUserInfo().CurrentOrgId)
  606. if err == nil {
  607. c.ServeSuccessJSON(map[string]interface{}{
  608. "list": patients,
  609. })
  610. return
  611. } else {
  612. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  613. return
  614. }
  615. }
  616. func (c *HisChargeApiController) GetStatisticsDetail() {
  617. start_time := c.GetString("start_time")
  618. end_time := c.GetString("end_time")
  619. keyword := c.GetString("keyword")
  620. item_type, _ := c.GetInt64("type")
  621. p_type, _ := c.GetInt64("p_type")
  622. patinet_id, _ := c.GetInt64("patinet_id")
  623. adminUser := c.GetAdminUserInfo()
  624. timeLayout := "2006-01-02"
  625. loc, _ := time.LoadLocation("Local")
  626. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  627. if err != nil {
  628. }
  629. startRecordDateTime := startTime.Unix()
  630. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  631. if err != nil {
  632. }
  633. endRecordDateTime := endTime.Unix()
  634. chargePatient, err := service.GetPatientChargeDetails(patinet_id, adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, keyword, item_type, p_type)
  635. if err == nil {
  636. c.ServeSuccessJSON(map[string]interface{}{
  637. "patients": chargePatient,
  638. })
  639. return
  640. } else {
  641. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  642. return
  643. }
  644. }
  645. func (c *HisChargeApiController) GetStatisticsGather() {
  646. start_time := c.GetString("start_time")
  647. end_time := c.GetString("end_time")
  648. keyword := c.GetString("keyword")
  649. item_type, _ := c.GetInt64("type")
  650. adminUser := c.GetAdminUserInfo()
  651. timeLayout := "2006-01-02"
  652. loc, _ := time.LoadLocation("Local")
  653. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  654. if err != nil {
  655. }
  656. startRecordDateTime := startTime.Unix()
  657. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  658. if err != nil {
  659. }
  660. endRecordDateTime := endTime.Unix()
  661. chargePatient, err := service.GetAllPatientChargeDetails(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, keyword, item_type)
  662. if err == nil {
  663. c.ServeSuccessJSON(map[string]interface{}{
  664. "patients": chargePatient,
  665. })
  666. return
  667. } else {
  668. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  669. return
  670. }
  671. }