his_charge_api_controller.go 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  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. start_time := c.GetString("start_time")
  196. end_time := c.GetString("end_time")
  197. keyword := c.GetString("keyword")
  198. item_type, _ := c.GetInt64("type")
  199. adminUser := c.GetAdminUserInfo()
  200. timeLayout := "2006-01-02"
  201. loc, _ := time.LoadLocation("Local")
  202. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  203. if err != nil {
  204. }
  205. startRecordDateTime := startTime.Unix()
  206. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  207. if err != nil {
  208. }
  209. endRecordDateTime := endTime.Unix()
  210. chargePatient, err := service.GetAllPatientChargeDetails(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, keyword, item_type)
  211. if err == nil {
  212. c.ServeSuccessJSON(map[string]interface{}{
  213. "patients": chargePatient,
  214. })
  215. return
  216. } else {
  217. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  218. return
  219. }
  220. }
  221. func (c *HisChargeApiController) GetChargeStatisticsSettle() {
  222. start_time := c.GetString("start_time")
  223. end_time := c.GetString("end_time")
  224. keyword := c.GetString("keyword")
  225. item_type, _ := c.GetInt64("type")
  226. adminUser := c.GetAdminUserInfo()
  227. timeLayout := "2006-01-02"
  228. loc, _ := time.LoadLocation("Local")
  229. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  230. if err != nil {
  231. }
  232. startRecordDateTime := startTime.Unix()
  233. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  234. if err != nil {
  235. }
  236. endRecordDateTime := endTime.Unix()
  237. chargePatient, err := service.GetAllPatientChargeSettle(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, keyword, item_type)
  238. if err == nil {
  239. c.ServeSuccessJSON(map[string]interface{}{
  240. "patients": chargePatient,
  241. })
  242. return
  243. } else {
  244. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  245. return
  246. }
  247. }
  248. func (c *HisChargeApiController) GetHisInspectionList() {
  249. record_date := c.GetString("record_date")
  250. keyword := c.GetString("keyword")
  251. is_print, _ := c.GetInt64("is_print")
  252. page, _ := c.GetInt64("page")
  253. limit, _ := c.GetInt64("limit")
  254. tube_color, _ := c.GetInt64("tube_color")
  255. adminUser := c.GetAdminUserInfo()
  256. timeLayout := "2006-01-02"
  257. loc, _ := time.LoadLocation("Local")
  258. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  259. if err != nil {
  260. }
  261. record_time := startTime.Unix()
  262. var labels []*models.HisLabelPrintInfo
  263. var labels_two []*models.HisLabelPrintInfo
  264. var total int64
  265. var total_two int64
  266. //var err error
  267. if tube_color == 0 {
  268. labels, total, err = service.GetLabelPrintList(page, limit, adminUser.CurrentOrgId, record_time, is_print, keyword, tube_color)
  269. } else {
  270. labels, total, err = service.GetLabelPrintList(page, limit, adminUser.CurrentOrgId, record_time, is_print, keyword, tube_color)
  271. labels_two, total_two, err = service.GetLabelPrintListTwo(page, limit, adminUser.CurrentOrgId, record_time, is_print, keyword, tube_color)
  272. total = total + total_two
  273. labels = append(labels, labels_two...)
  274. }
  275. if err == nil {
  276. c.ServeSuccessJSON(map[string]interface{}{
  277. "labels": labels,
  278. "total": total,
  279. })
  280. return
  281. } else {
  282. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  283. return
  284. }
  285. }
  286. func (c *HisChargeApiController) GetHisInspectionListTwo() {
  287. record_date := c.GetString("record_date")
  288. keyword := c.GetString("keyword")
  289. is_print, _ := c.GetInt64("is_print")
  290. tube_color, _ := c.GetInt64("tube_color")
  291. adminUser := c.GetAdminUserInfo()
  292. timeLayout := "2006-01-02"
  293. loc, _ := time.LoadLocation("Local")
  294. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  295. if err != nil {
  296. }
  297. record_time := startTime.Unix()
  298. var labels []*models.HisLabelPrintInfo
  299. //var labels_two []*models.HisLabelPrintInfo
  300. //var total int64
  301. //var total_two int64
  302. labels, _, err = service.GetLabelPrintListThree(adminUser.CurrentOrgId, record_time, is_print, keyword, tube_color)
  303. //labels_two, total_two, err = service.GetLabelPrintListFour(adminUser.CurrentOrgId, record_time, is_print, keyword, tube_color)
  304. //total = total + total_two
  305. //labels = append(labels, labels_two...)
  306. if err == nil {
  307. c.ServeSuccessJSON(map[string]interface{}{
  308. "labels": labels,
  309. //"total": total,
  310. })
  311. return
  312. } else {
  313. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  314. return
  315. }
  316. }
  317. func (c *HisChargeApiController) GetHisInspectionInfo() {
  318. id, _ := c.GetInt64("id")
  319. label, err := service.GetLabelPrintInfo(id)
  320. if err == nil {
  321. c.ServeSuccessJSON(map[string]interface{}{
  322. "label": label,
  323. })
  324. return
  325. } else {
  326. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  327. return
  328. }
  329. }
  330. func (c *HisChargeApiController) GetHisYidiClearRecord() {
  331. records, err := service.FindHisYidiClearRecord(c.GetAdminUserInfo().CurrentOrgId)
  332. if err == nil {
  333. c.ServeSuccessJSON(map[string]interface{}{
  334. "list": records,
  335. })
  336. return
  337. } else {
  338. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  339. return
  340. }
  341. }
  342. func (c *HisChargeApiController) GetAllPatient() {
  343. patients, err := service.GetAllPatientTwo(c.GetAdminUserInfo().CurrentOrgId)
  344. if err == nil {
  345. c.ServeSuccessJSON(map[string]interface{}{
  346. "list": patients,
  347. })
  348. return
  349. } else {
  350. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  351. return
  352. }
  353. }
  354. func (c *HisChargeApiController) GetStatisticsDetail() {
  355. start_time := c.GetString("start_time")
  356. end_time := c.GetString("end_time")
  357. keyword := c.GetString("keyword")
  358. item_type, _ := c.GetInt64("type")
  359. p_type, _ := c.GetInt64("p_type")
  360. patinet_id, _ := c.GetInt64("patinet_id")
  361. adminUser := c.GetAdminUserInfo()
  362. timeLayout := "2006-01-02"
  363. loc, _ := time.LoadLocation("Local")
  364. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  365. if err != nil {
  366. }
  367. startRecordDateTime := startTime.Unix()
  368. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  369. if err != nil {
  370. }
  371. endRecordDateTime := endTime.Unix()
  372. chargePatient, err := service.GetPatientChargeDetails(patinet_id, adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, keyword, item_type, p_type)
  373. if err == nil {
  374. c.ServeSuccessJSON(map[string]interface{}{
  375. "patients": chargePatient,
  376. })
  377. return
  378. } else {
  379. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  380. return
  381. }
  382. }
  383. func (c *HisChargeApiController) GetStatisticsGather() {
  384. start_time := c.GetString("start_time")
  385. end_time := c.GetString("end_time")
  386. keyword := c.GetString("keyword")
  387. item_type, _ := c.GetInt64("type")
  388. adminUser := c.GetAdminUserInfo()
  389. timeLayout := "2006-01-02"
  390. loc, _ := time.LoadLocation("Local")
  391. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  392. if err != nil {
  393. }
  394. startRecordDateTime := startTime.Unix()
  395. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  396. if err != nil {
  397. }
  398. endRecordDateTime := endTime.Unix()
  399. chargePatient, err := service.GetAllPatientChargeDetails(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, keyword, item_type)
  400. if err == nil {
  401. c.ServeSuccessJSON(map[string]interface{}{
  402. "patients": chargePatient,
  403. })
  404. return
  405. } else {
  406. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  407. return
  408. }
  409. }