his_charge_api_controller.go 11KB

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