his_charge_api_controller.go 12KB

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