his_charge_api_controller.go 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  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. adminUser := c.GetAdminUserInfo()
  254. timeLayout := "2006-01-02"
  255. loc, _ := time.LoadLocation("Local")
  256. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  257. if err != nil {
  258. }
  259. record_time := startTime.Unix()
  260. labels, total, err := service.GetLabelPrintList(page, limit, adminUser.CurrentOrgId, record_time, is_print, keyword)
  261. if err == nil {
  262. c.ServeSuccessJSON(map[string]interface{}{
  263. "labels": labels,
  264. "total": total,
  265. })
  266. return
  267. } else {
  268. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  269. return
  270. }
  271. }
  272. func (c *HisChargeApiController) GetHisInspectionInfo() {
  273. id, _ := c.GetInt64("id")
  274. label, err := service.GetLabelPrintInfo(id)
  275. if err == nil {
  276. c.ServeSuccessJSON(map[string]interface{}{
  277. "label": label,
  278. })
  279. return
  280. } else {
  281. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  282. return
  283. }
  284. }
  285. func (c *HisChargeApiController) GetHisYidiClearRecord() {
  286. records, err := service.FindHisYidiClearRecord(c.GetAdminUserInfo().CurrentOrgId)
  287. if err == nil {
  288. c.ServeSuccessJSON(map[string]interface{}{
  289. "list": records,
  290. })
  291. return
  292. } else {
  293. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  294. return
  295. }
  296. }
  297. func (c *HisChargeApiController) GetAllPatient() {
  298. patients, err := service.GetAllPatientTwo(c.GetAdminUserInfo().CurrentOrgId)
  299. if err == nil {
  300. c.ServeSuccessJSON(map[string]interface{}{
  301. "list": patients,
  302. })
  303. return
  304. } else {
  305. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  306. return
  307. }
  308. }
  309. func (c *HisChargeApiController) GetStatisticsDetail() {
  310. start_time := c.GetString("start_time")
  311. end_time := c.GetString("end_time")
  312. keyword := c.GetString("keyword")
  313. item_type, _ := c.GetInt64("type")
  314. p_type, _ := c.GetInt64("p_type")
  315. patinet_id, _ := c.GetInt64("patinet_id")
  316. adminUser := c.GetAdminUserInfo()
  317. timeLayout := "2006-01-02"
  318. loc, _ := time.LoadLocation("Local")
  319. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  320. if err != nil {
  321. }
  322. startRecordDateTime := startTime.Unix()
  323. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  324. if err != nil {
  325. }
  326. endRecordDateTime := endTime.Unix()
  327. chargePatient, err := service.GetPatientChargeDetails(patinet_id, adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, keyword, item_type, p_type)
  328. if err == nil {
  329. c.ServeSuccessJSON(map[string]interface{}{
  330. "patients": chargePatient,
  331. })
  332. return
  333. } else {
  334. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  335. return
  336. }
  337. }
  338. func (c *HisChargeApiController) GetStatisticsGather() {
  339. start_time := c.GetString("start_time")
  340. end_time := c.GetString("end_time")
  341. keyword := c.GetString("keyword")
  342. item_type, _ := c.GetInt64("type")
  343. adminUser := c.GetAdminUserInfo()
  344. timeLayout := "2006-01-02"
  345. loc, _ := time.LoadLocation("Local")
  346. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  347. if err != nil {
  348. }
  349. startRecordDateTime := startTime.Unix()
  350. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  351. if err != nil {
  352. }
  353. endRecordDateTime := endTime.Unix()
  354. chargePatient, err := service.GetAllPatientChargeDetails(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, keyword, item_type)
  355. if err == nil {
  356. c.ServeSuccessJSON(map[string]interface{}{
  357. "patients": chargePatient,
  358. })
  359. return
  360. } else {
  361. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  362. return
  363. }
  364. }