his_charge_api_controller.go 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "github.com/astaxie/beego"
  8. "time"
  9. )
  10. type HisChargeApiController struct {
  11. BaseAuthAPIController
  12. }
  13. func HisChargeApiRegistRouters() {
  14. beego.Router("/api/his/chargestatistics/detail", &HisChargeApiController{}, "get:GetChargeStatisticsDetail")
  15. beego.Router("/api/his/chargestatistics/settle", &HisChargeApiController{}, "get:GetChargeStatisticsSettle")
  16. beego.Router("/api/his/patient", &HisChargeApiController{}, "get:GetAllPatient")
  17. //beego.Router("/api/his/chargestatistics/settle", &HisChargeApiController{}, "get:GetChargeStatisticsSettle")
  18. beego.Router("/api/his/inspectionlist/get", &HisChargeApiController{}, "get:GetHisInspectionList")
  19. beego.Router("/api/his/inspectionlisttwo/get", &HisChargeApiController{}, "get:GetHisInspectionListTwo")
  20. beego.Router("/api/his/inspectioninfo/get", &HisChargeApiController{}, "get:GetHisInspectionInfo")
  21. //发票
  22. beego.Router("/api/fapiao/create", &HisChargeApiController{}, "post:CreateFaPiaoRecord")
  23. beego.Router("/api/fapiao/modify", &HisChargeApiController{}, "post:ModifyFaPiaoRecord")
  24. beego.Router("/api/fapiao/list", &HisChargeApiController{}, "get:GetFaPiaoRecordList")
  25. beego.Router("/api/fapiao/delete", &HisChargeApiController{}, "post:DeleteFaPiaoRecord")
  26. beego.Router("/api/fapiao", &HisChargeApiController{}, "get:GetFaPiaoRecord")
  27. beego.Router("/api/fapiao/is_use", &HisChargeApiController{}, "post:UpdateFaPiaoRecordIsUse")
  28. beego.Router("/api/his/getyidiclear", &HisChargeApiController{}, "get:GetHisYidiClearRecord")
  29. beego.Router("/api/his/getexportdata", &HisChargeApiController{}, "get:GetExportData")
  30. }
  31. func (c *HisChargeApiController) GetExportData() {
  32. start_time := c.GetString("start_time")
  33. end_time := c.GetString("end_time")
  34. adminUser := c.GetAdminUserInfo()
  35. timeLayout := "2006-01-02"
  36. loc, _ := time.LoadLocation("Local")
  37. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  38. if err != nil {
  39. }
  40. startRecordDateTime := startTime.Unix()
  41. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  42. if err != nil {
  43. }
  44. endRecordDateTime := endTime.Unix()
  45. chargePatient, err := service.GetAllChargeDetailsTwo(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime)
  46. if err == nil {
  47. c.ServeSuccessJSON(map[string]interface{}{
  48. "patients": chargePatient,
  49. })
  50. return
  51. } else {
  52. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  53. return
  54. }
  55. }
  56. func (c *HisChargeApiController) UpdateFaPiaoRecordIsUse() {
  57. id, _ := c.GetInt64("id", 0)
  58. is_use, _ := c.GetInt64("is_use")
  59. if id <= 0 {
  60. utils.ErrorLog("id == 0")
  61. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  62. return
  63. }
  64. record, _ := service.FindFapiaoById(id)
  65. adminUserInfo := c.GetAdminUserInfo()
  66. service.UpdateFapiaoIsUse(adminUserInfo.CurrentOrgId)
  67. records := models.HisFapiaoRecord{
  68. ID: id,
  69. FapiaoCode: record.FapiaoCode,
  70. FapiaoNumber: record.FapiaoNumber,
  71. Ctime: time.Now().Unix(),
  72. Mtime: time.Now().Unix(),
  73. UserOrgId: adminUserInfo.CurrentOrgId,
  74. Status: 1,
  75. IsUse: is_use,
  76. }
  77. err := service.ModifyFapiao(&records)
  78. if err == nil {
  79. c.ServeSuccessJSON(map[string]interface{}{
  80. "fapiao_record": records,
  81. })
  82. } else {
  83. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  84. }
  85. }
  86. func (c *HisChargeApiController) CreateFaPiaoRecord() {
  87. fapiao_code := c.GetString("fapiao_code")
  88. fapiao_number := c.GetString("fapiao_number")
  89. if len(fapiao_code) <= 0 {
  90. utils.ErrorLog("len(fapiao_code) == 0")
  91. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  92. return
  93. }
  94. if len(fapiao_number) <= 0 {
  95. utils.ErrorLog("len(fapiao_number) == 0")
  96. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  97. return
  98. }
  99. adminUserInfo := c.GetAdminUserInfo()
  100. record := models.HisFapiaoRecord{
  101. FapiaoCode: fapiao_code,
  102. FapiaoNumber: fapiao_number,
  103. Ctime: time.Now().Unix(),
  104. Mtime: time.Now().Unix(),
  105. UserOrgId: adminUserInfo.CurrentOrgId,
  106. Status: 1,
  107. IsUse: 0,
  108. }
  109. err, records := service.AddSigleFapiaoRecord(&record)
  110. if err == nil {
  111. c.ServeSuccessJSON(map[string]interface{}{
  112. "fapiao_record": records,
  113. })
  114. } else {
  115. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  116. }
  117. }
  118. func (c *HisChargeApiController) ModifyFaPiaoRecord() {
  119. id, _ := c.GetInt64("id", 0)
  120. fapiao_code := c.GetString("fapiao_code")
  121. fapiao_number := c.GetString("fapiao_number")
  122. if id <= 0 {
  123. utils.ErrorLog("id == 0")
  124. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  125. return
  126. }
  127. if len(fapiao_code) <= 0 {
  128. utils.ErrorLog("len(fapiao_code) == 0")
  129. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  130. return
  131. }
  132. if len(fapiao_number) <= 0 {
  133. utils.ErrorLog("len(fapiao_number) == 0")
  134. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  135. return
  136. }
  137. record, _ := service.FindFapiaoById(id)
  138. adminUserInfo := c.GetAdminUserInfo()
  139. records := models.HisFapiaoRecord{
  140. ID: id,
  141. FapiaoCode: fapiao_code,
  142. FapiaoNumber: fapiao_number,
  143. Ctime: time.Now().Unix(),
  144. Mtime: time.Now().Unix(),
  145. UserOrgId: adminUserInfo.CurrentOrgId,
  146. Status: 1,
  147. IsUse: record.IsUse,
  148. }
  149. err := service.ModifyFapiao(&records)
  150. if err == nil {
  151. c.ServeSuccessJSON(map[string]interface{}{
  152. "fapiao_record": records,
  153. })
  154. } else {
  155. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  156. }
  157. }
  158. func (c *HisChargeApiController) GetFaPiaoRecordList() {
  159. page, _ := c.GetInt64("page", 1)
  160. limit, _ := c.GetInt64("limit", 7)
  161. adminUserInfo := c.GetAdminUserInfo()
  162. fapiaoRecord, total, err := service.FindAllFapiaoList(adminUserInfo.CurrentOrgId, page, limit)
  163. if err == nil {
  164. c.ServeSuccessJSON(map[string]interface{}{
  165. "fapiao_record": fapiaoRecord,
  166. "total": total,
  167. })
  168. } else {
  169. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  170. }
  171. }
  172. func (c *HisChargeApiController) DeleteFaPiaoRecord() {
  173. id, _ := c.GetInt64("id", 0)
  174. err := service.DeleteFapiaoById(id)
  175. if err == nil {
  176. c.ServeSuccessJSON(map[string]interface{}{
  177. "msg": "删除成功",
  178. })
  179. } else {
  180. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  181. }
  182. }
  183. func (c *HisChargeApiController) GetFaPiaoRecord() {
  184. id, _ := c.GetInt64("id", 0)
  185. fapiaoRecord, err := service.FindFapiaoById(id)
  186. if err == nil {
  187. c.ServeSuccessJSON(map[string]interface{}{
  188. "fapiao_record": fapiaoRecord,
  189. })
  190. } else {
  191. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  192. }
  193. }
  194. func (c *HisChargeApiController) GetChargeStatisticsDetail() {
  195. c.ServeSuccessJSON(map[string]interface{}{
  196. "msg": "接口优化升级,如有数据需要,请联系客服!",
  197. })
  198. return
  199. start_time := c.GetString("start_time")
  200. end_time := c.GetString("end_time")
  201. keyword := c.GetString("keyword")
  202. item_type, _ := c.GetInt64("type")
  203. adminUser := c.GetAdminUserInfo()
  204. timeLayout := "2006-01-02"
  205. loc, _ := time.LoadLocation("Local")
  206. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  207. if err != nil {
  208. }
  209. startRecordDateTime := startTime.Unix()
  210. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  211. if err != nil {
  212. }
  213. endRecordDateTime := endTime.Unix()
  214. chargePatient, err := service.GetAllPatientChargeDetails(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, keyword, item_type)
  215. if err == nil {
  216. c.ServeSuccessJSON(map[string]interface{}{
  217. "patients": chargePatient,
  218. })
  219. return
  220. } else {
  221. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  222. return
  223. }
  224. }
  225. func (c *HisChargeApiController) GetChargeStatisticsSettle() {
  226. start_time := c.GetString("start_time")
  227. end_time := c.GetString("end_time")
  228. keyword := c.GetString("keyword")
  229. item_type, _ := c.GetInt64("type")
  230. adminUser := c.GetAdminUserInfo()
  231. timeLayout := "2006-01-02"
  232. loc, _ := time.LoadLocation("Local")
  233. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  234. if err != nil {
  235. }
  236. startRecordDateTime := startTime.Unix()
  237. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  238. if err != nil {
  239. }
  240. endRecordDateTime := endTime.Unix()
  241. chargePatient, err := service.GetAllPatientChargeSettle(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, keyword, item_type)
  242. if err == nil {
  243. c.ServeSuccessJSON(map[string]interface{}{
  244. "patients": chargePatient,
  245. })
  246. return
  247. } else {
  248. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  249. return
  250. }
  251. }
  252. func (c *HisChargeApiController) GetHisInspectionList() {
  253. record_date := c.GetString("record_date")
  254. keyword := c.GetString("keyword")
  255. is_print, _ := c.GetInt64("is_print")
  256. page, _ := c.GetInt64("page")
  257. limit, _ := c.GetInt64("limit")
  258. tube_color, _ := c.GetInt64("tube_color")
  259. adminUser := c.GetAdminUserInfo()
  260. timeLayout := "2006-01-02"
  261. loc, _ := time.LoadLocation("Local")
  262. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  263. if err != nil {
  264. }
  265. record_time := startTime.Unix()
  266. var labels []*models.HisLabelPrintInfo
  267. var labels_two []*models.HisLabelPrintInfo
  268. var total int64
  269. var total_two int64
  270. //var err error
  271. if tube_color == 0 {
  272. labels, total, err = service.GetLabelPrintList(page, limit, adminUser.CurrentOrgId, record_time, is_print, keyword, tube_color)
  273. } else {
  274. labels, total, err = service.GetLabelPrintList(page, limit, adminUser.CurrentOrgId, record_time, is_print, keyword, tube_color)
  275. labels_two, total_two, err = service.GetLabelPrintListTwo(page, limit, adminUser.CurrentOrgId, record_time, is_print, keyword, tube_color)
  276. total = total + total_two
  277. labels = append(labels, labels_two...)
  278. }
  279. if err == nil {
  280. c.ServeSuccessJSON(map[string]interface{}{
  281. "labels": labels,
  282. "total": total,
  283. })
  284. return
  285. } else {
  286. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  287. return
  288. }
  289. }
  290. func (c *HisChargeApiController) GetHisInspectionListTwo() {
  291. record_date := c.GetString("record_date")
  292. keyword := c.GetString("keyword")
  293. is_print, _ := c.GetInt64("is_print")
  294. tube_color, _ := c.GetInt64("tube_color")
  295. adminUser := c.GetAdminUserInfo()
  296. timeLayout := "2006-01-02"
  297. loc, _ := time.LoadLocation("Local")
  298. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  299. if err != nil {
  300. }
  301. record_time := startTime.Unix()
  302. var labels []*models.HisLabelPrintInfo
  303. //var labels_two []*models.HisLabelPrintInfo
  304. //var total int64
  305. //var total_two int64
  306. labels, _, err = service.GetLabelPrintListThree(adminUser.CurrentOrgId, record_time, is_print, keyword, tube_color)
  307. //labels_two, total_two, err = service.GetLabelPrintListFour(adminUser.CurrentOrgId, record_time, is_print, keyword, tube_color)
  308. //total = total + total_two
  309. //labels = append(labels, labels_two...)
  310. if err == nil {
  311. c.ServeSuccessJSON(map[string]interface{}{
  312. "labels": labels,
  313. //"total": total,
  314. })
  315. return
  316. } else {
  317. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  318. return
  319. }
  320. }
  321. func (c *HisChargeApiController) GetHisInspectionInfo() {
  322. id, _ := c.GetInt64("id")
  323. label, err := service.GetLabelPrintInfo(id)
  324. if err == nil {
  325. c.ServeSuccessJSON(map[string]interface{}{
  326. "label": label,
  327. })
  328. return
  329. } else {
  330. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  331. return
  332. }
  333. }
  334. func (c *HisChargeApiController) GetHisYidiClearRecord() {
  335. records, err := service.FindHisYidiClearRecord(c.GetAdminUserInfo().CurrentOrgId)
  336. if err == nil {
  337. c.ServeSuccessJSON(map[string]interface{}{
  338. "list": records,
  339. })
  340. return
  341. } else {
  342. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  343. return
  344. }
  345. }
  346. func (c *HisChargeApiController) GetAllPatient() {
  347. patients, err := service.GetAllPatientTwo(c.GetAdminUserInfo().CurrentOrgId)
  348. if err == nil {
  349. c.ServeSuccessJSON(map[string]interface{}{
  350. "list": patients,
  351. })
  352. return
  353. } else {
  354. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  355. return
  356. }
  357. }
  358. func (c *HisChargeApiController) GetStatisticsDetail() {
  359. start_time := c.GetString("start_time")
  360. end_time := c.GetString("end_time")
  361. keyword := c.GetString("keyword")
  362. item_type, _ := c.GetInt64("type")
  363. p_type, _ := c.GetInt64("p_type")
  364. patinet_id, _ := c.GetInt64("patinet_id")
  365. adminUser := c.GetAdminUserInfo()
  366. timeLayout := "2006-01-02"
  367. loc, _ := time.LoadLocation("Local")
  368. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  369. if err != nil {
  370. }
  371. startRecordDateTime := startTime.Unix()
  372. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  373. if err != nil {
  374. }
  375. endRecordDateTime := endTime.Unix()
  376. chargePatient, err := service.GetPatientChargeDetails(patinet_id, adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, keyword, item_type, p_type)
  377. if err == nil {
  378. c.ServeSuccessJSON(map[string]interface{}{
  379. "patients": chargePatient,
  380. })
  381. return
  382. } else {
  383. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  384. return
  385. }
  386. }
  387. func (c *HisChargeApiController) GetStatisticsGather() {
  388. start_time := c.GetString("start_time")
  389. end_time := c.GetString("end_time")
  390. keyword := c.GetString("keyword")
  391. item_type, _ := c.GetInt64("type")
  392. adminUser := c.GetAdminUserInfo()
  393. timeLayout := "2006-01-02"
  394. loc, _ := time.LoadLocation("Local")
  395. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  396. if err != nil {
  397. }
  398. startRecordDateTime := startTime.Unix()
  399. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  400. if err != nil {
  401. }
  402. endRecordDateTime := endTime.Unix()
  403. chargePatient, err := service.GetAllPatientChargeDetails(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, keyword, item_type)
  404. if err == nil {
  405. c.ServeSuccessJSON(map[string]interface{}{
  406. "patients": chargePatient,
  407. })
  408. return
  409. } else {
  410. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  411. return
  412. }
  413. }