his_charge_api_controller.go 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782
  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. if err == nil {
  497. c.ServeSuccessJSON(map[string]interface{}{
  498. "patients": chargePatient,
  499. })
  500. return
  501. } else {
  502. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  503. return
  504. }
  505. }
  506. func (c *HisChargeApiController) GetHisInspectionList() {
  507. record_date := c.GetString("record_date")
  508. keyword := c.GetString("keyword")
  509. is_print, _ := c.GetInt64("is_print")
  510. page, _ := c.GetInt64("page")
  511. limit, _ := c.GetInt64("limit")
  512. tube_color, _ := c.GetInt64("tube_color")
  513. adminUser := c.GetAdminUserInfo()
  514. timeLayout := "2006-01-02"
  515. loc, _ := time.LoadLocation("Local")
  516. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  517. if err != nil {
  518. }
  519. record_time := startTime.Unix()
  520. var labels []*models.HisLabelPrintInfo
  521. var labels_two []*models.HisLabelPrintInfo
  522. var total int64
  523. var total_two int64
  524. //var err error
  525. if tube_color == 0 {
  526. labels, total, err = service.GetLabelPrintList(page, limit, adminUser.CurrentOrgId, record_time, is_print, keyword, tube_color)
  527. } else {
  528. labels, total, err = service.GetLabelPrintList(page, limit, adminUser.CurrentOrgId, record_time, is_print, keyword, tube_color)
  529. labels_two, total_two, err = service.GetLabelPrintListTwo(page, limit, adminUser.CurrentOrgId, record_time, is_print, keyword, tube_color)
  530. total = total + total_two
  531. labels = append(labels, labels_two...)
  532. }
  533. if err == nil {
  534. c.ServeSuccessJSON(map[string]interface{}{
  535. "labels": labels,
  536. "total": total,
  537. })
  538. return
  539. } else {
  540. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  541. return
  542. }
  543. }
  544. func (c *HisChargeApiController) GetHisInspectionListTwo() {
  545. record_date := c.GetString("record_date")
  546. keyword := c.GetString("keyword")
  547. is_print, _ := c.GetInt64("is_print")
  548. tube_color, _ := c.GetInt64("tube_color")
  549. adminUser := c.GetAdminUserInfo()
  550. timeLayout := "2006-01-02"
  551. loc, _ := time.LoadLocation("Local")
  552. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  553. if err != nil {
  554. }
  555. record_time := startTime.Unix()
  556. var labels []*models.HisLabelPrintInfo
  557. //var labels_two []*models.HisLabelPrintInfo
  558. //var total int64
  559. //var total_two int64
  560. labels, _, err = service.GetLabelPrintListThree(adminUser.CurrentOrgId, record_time, is_print, keyword, tube_color)
  561. //labels_two, total_two, err = service.GetLabelPrintListFour(adminUser.CurrentOrgId, record_time, is_print, keyword, tube_color)
  562. //total = total + total_two
  563. //labels = append(labels, labels_two...)
  564. if err == nil {
  565. c.ServeSuccessJSON(map[string]interface{}{
  566. "labels": labels,
  567. //"total": total,
  568. })
  569. return
  570. } else {
  571. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  572. return
  573. }
  574. }
  575. func (c *HisChargeApiController) GetHisInspectionInfo() {
  576. id, _ := c.GetInt64("id")
  577. label, err := service.GetLabelPrintInfo(id)
  578. if err == nil {
  579. c.ServeSuccessJSON(map[string]interface{}{
  580. "label": label,
  581. })
  582. return
  583. } else {
  584. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  585. return
  586. }
  587. }
  588. func (c *HisChargeApiController) GetHisYidiClearRecord() {
  589. records, err := service.FindHisYidiClearRecord(c.GetAdminUserInfo().CurrentOrgId)
  590. if err == nil {
  591. c.ServeSuccessJSON(map[string]interface{}{
  592. "list": records,
  593. })
  594. return
  595. } else {
  596. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  597. return
  598. }
  599. }
  600. func (c *HisChargeApiController) GetAllPatient() {
  601. patients, err := service.GetAllPatientTwo(c.GetAdminUserInfo().CurrentOrgId)
  602. if err == nil {
  603. c.ServeSuccessJSON(map[string]interface{}{
  604. "list": patients,
  605. })
  606. return
  607. } else {
  608. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  609. return
  610. }
  611. }
  612. func (c *HisChargeApiController) GetStatisticsDetail() {
  613. start_time := c.GetString("start_time")
  614. end_time := c.GetString("end_time")
  615. keyword := c.GetString("keyword")
  616. item_type, _ := c.GetInt64("type")
  617. p_type, _ := c.GetInt64("p_type")
  618. patinet_id, _ := c.GetInt64("patinet_id")
  619. adminUser := c.GetAdminUserInfo()
  620. timeLayout := "2006-01-02"
  621. loc, _ := time.LoadLocation("Local")
  622. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  623. if err != nil {
  624. }
  625. startRecordDateTime := startTime.Unix()
  626. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  627. if err != nil {
  628. }
  629. endRecordDateTime := endTime.Unix()
  630. chargePatient, err := service.GetPatientChargeDetails(patinet_id, adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, keyword, item_type, p_type)
  631. if err == nil {
  632. c.ServeSuccessJSON(map[string]interface{}{
  633. "patients": chargePatient,
  634. })
  635. return
  636. } else {
  637. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  638. return
  639. }
  640. }
  641. func (c *HisChargeApiController) GetStatisticsGather() {
  642. start_time := c.GetString("start_time")
  643. end_time := c.GetString("end_time")
  644. keyword := c.GetString("keyword")
  645. item_type, _ := c.GetInt64("type")
  646. adminUser := c.GetAdminUserInfo()
  647. timeLayout := "2006-01-02"
  648. loc, _ := time.LoadLocation("Local")
  649. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  650. if err != nil {
  651. }
  652. startRecordDateTime := startTime.Unix()
  653. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  654. if err != nil {
  655. }
  656. endRecordDateTime := endTime.Unix()
  657. chargePatient, err := service.GetAllPatientChargeDetails(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, keyword, item_type)
  658. if err == nil {
  659. c.ServeSuccessJSON(map[string]interface{}{
  660. "patients": chargePatient,
  661. })
  662. return
  663. } else {
  664. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  665. return
  666. }
  667. }