his_charge_api_controller.go 8.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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/inspectionlist/get", &HisChargeApiController{}, "get:GetHisInspectionList")
  17. beego.Router("/api/his/inspectioninfo/get", &HisChargeApiController{}, "get:GetHisInspectionInfo")
  18. //发票
  19. beego.Router("/api/fapiao/create", &HisChargeApiController{}, "post:CreateFaPiaoRecord")
  20. beego.Router("/api/fapiao/modify", &HisChargeApiController{}, "post:ModifyFaPiaoRecord")
  21. beego.Router("/api/fapiao/list", &HisChargeApiController{}, "get:GetFaPiaoRecordList")
  22. beego.Router("/api/fapiao/delete", &HisChargeApiController{}, "post:DeleteFaPiaoRecord")
  23. beego.Router("/api/fapiao", &HisChargeApiController{}, "get:GetFaPiaoRecord")
  24. beego.Router("/api/fapiao/is_use", &HisChargeApiController{}, "post:UpdateFaPiaoRecordIsUse")
  25. }
  26. func (c *HisChargeApiController) UpdateFaPiaoRecordIsUse() {
  27. id, _ := c.GetInt64("id", 0)
  28. is_use, _ := c.GetInt64("is_use")
  29. if id <= 0 {
  30. utils.ErrorLog("id == 0")
  31. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  32. return
  33. }
  34. record, _ := service.FindFapiaoById(id)
  35. adminUserInfo := c.GetAdminUserInfo()
  36. service.UpdateFapiaoIsUse(adminUserInfo.CurrentOrgId)
  37. records := models.HisFapiaoRecord{
  38. ID: id,
  39. FapiaoCode: record.FapiaoCode,
  40. FapiaoNumber: record.FapiaoNumber,
  41. Ctime: time.Now().Unix(),
  42. Mtime: time.Now().Unix(),
  43. UserOrgId: adminUserInfo.CurrentOrgId,
  44. Status: 1,
  45. IsUse: is_use,
  46. }
  47. err := service.ModifyFapiao(&records)
  48. if err == nil {
  49. c.ServeSuccessJSON(map[string]interface{}{
  50. "fapiao_record": records,
  51. })
  52. } else {
  53. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  54. }
  55. }
  56. func (c *HisChargeApiController) CreateFaPiaoRecord() {
  57. fapiao_code := c.GetString("fapiao_code")
  58. fapiao_number := c.GetString("fapiao_number")
  59. if len(fapiao_code) <= 0 {
  60. utils.ErrorLog("len(fapiao_code) == 0")
  61. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  62. return
  63. }
  64. if len(fapiao_number) <= 0 {
  65. utils.ErrorLog("len(fapiao_number) == 0")
  66. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  67. return
  68. }
  69. adminUserInfo := c.GetAdminUserInfo()
  70. record := models.HisFapiaoRecord{
  71. FapiaoCode: fapiao_code,
  72. FapiaoNumber: fapiao_number,
  73. Ctime: time.Now().Unix(),
  74. Mtime: time.Now().Unix(),
  75. UserOrgId: adminUserInfo.CurrentOrgId,
  76. Status: 1,
  77. IsUse: 0,
  78. }
  79. err, records := service.AddSigleFapiaoRecord(&record)
  80. if err == nil {
  81. c.ServeSuccessJSON(map[string]interface{}{
  82. "fapiao_record": records,
  83. })
  84. } else {
  85. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  86. }
  87. }
  88. func (c *HisChargeApiController) ModifyFaPiaoRecord() {
  89. id, _ := c.GetInt64("id", 0)
  90. fapiao_code := c.GetString("fapiao_code")
  91. fapiao_number := c.GetString("fapiao_number")
  92. if id <= 0 {
  93. utils.ErrorLog("id == 0")
  94. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  95. return
  96. }
  97. if len(fapiao_code) <= 0 {
  98. utils.ErrorLog("len(fapiao_code) == 0")
  99. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  100. return
  101. }
  102. if len(fapiao_number) <= 0 {
  103. utils.ErrorLog("len(fapiao_number) == 0")
  104. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  105. return
  106. }
  107. record, _ := service.FindFapiaoById(id)
  108. adminUserInfo := c.GetAdminUserInfo()
  109. records := models.HisFapiaoRecord{
  110. ID: id,
  111. FapiaoCode: fapiao_code,
  112. FapiaoNumber: fapiao_number,
  113. Ctime: time.Now().Unix(),
  114. Mtime: time.Now().Unix(),
  115. UserOrgId: adminUserInfo.CurrentOrgId,
  116. Status: 1,
  117. IsUse: record.IsUse,
  118. }
  119. err := service.ModifyFapiao(&records)
  120. if err == nil {
  121. c.ServeSuccessJSON(map[string]interface{}{
  122. "fapiao_record": records,
  123. })
  124. } else {
  125. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  126. }
  127. }
  128. func (c *HisChargeApiController) GetFaPiaoRecordList() {
  129. page, _ := c.GetInt64("page", 1)
  130. limit, _ := c.GetInt64("limit", 7)
  131. adminUserInfo := c.GetAdminUserInfo()
  132. fapiaoRecord, total, err := service.FindAllFapiaoList(adminUserInfo.CurrentOrgId, page, limit)
  133. if err == nil {
  134. c.ServeSuccessJSON(map[string]interface{}{
  135. "fapiao_record": fapiaoRecord,
  136. "total": total,
  137. })
  138. } else {
  139. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  140. }
  141. }
  142. func (c *HisChargeApiController) DeleteFaPiaoRecord() {
  143. id, _ := c.GetInt64("id", 0)
  144. err := service.DeleteFapiaoById(id)
  145. if err == nil {
  146. c.ServeSuccessJSON(map[string]interface{}{
  147. "msg": "删除成功",
  148. })
  149. } else {
  150. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  151. }
  152. }
  153. func (c *HisChargeApiController) GetFaPiaoRecord() {
  154. id, _ := c.GetInt64("id", 0)
  155. fapiaoRecord, err := service.FindFapiaoById(id)
  156. if err == nil {
  157. c.ServeSuccessJSON(map[string]interface{}{
  158. "fapiao_record": fapiaoRecord,
  159. })
  160. } else {
  161. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  162. }
  163. }
  164. func (c *HisChargeApiController) GetChargeStatisticsDetail() {
  165. start_time := c.GetString("start_time")
  166. end_time := c.GetString("end_time")
  167. keyword := c.GetString("keyword")
  168. item_type, _ := c.GetInt64("type")
  169. adminUser := c.GetAdminUserInfo()
  170. timeLayout := "2006-01-02"
  171. loc, _ := time.LoadLocation("Local")
  172. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  173. if err != nil {
  174. }
  175. startRecordDateTime := startTime.Unix()
  176. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  177. if err != nil {
  178. }
  179. endRecordDateTime := endTime.Unix()
  180. chargePatient, err := service.GetAllPatientChargeDetails(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, keyword, item_type)
  181. if err == nil {
  182. c.ServeSuccessJSON(map[string]interface{}{
  183. "patients": chargePatient,
  184. })
  185. return
  186. } else {
  187. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  188. return
  189. }
  190. }
  191. func (c *HisChargeApiController) GetChargeStatisticsSettle() {
  192. start_time := c.GetString("start_time")
  193. end_time := c.GetString("end_time")
  194. keyword := c.GetString("keyword")
  195. item_type, _ := c.GetInt64("type")
  196. adminUser := c.GetAdminUserInfo()
  197. timeLayout := "2006-01-02"
  198. loc, _ := time.LoadLocation("Local")
  199. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  200. if err != nil {
  201. }
  202. startRecordDateTime := startTime.Unix()
  203. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  204. if err != nil {
  205. }
  206. endRecordDateTime := endTime.Unix()
  207. chargePatient, err := service.GetAllPatientChargeSettle(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, keyword, item_type)
  208. if err == nil {
  209. c.ServeSuccessJSON(map[string]interface{}{
  210. "patients": chargePatient,
  211. })
  212. return
  213. } else {
  214. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  215. return
  216. }
  217. }
  218. func (c *HisChargeApiController) GetHisInspectionList() {
  219. record_date := c.GetString("record_date")
  220. keyword := c.GetString("keyword")
  221. is_print, _ := c.GetInt64("is_print")
  222. page, _ := c.GetInt64("page")
  223. limit, _ := c.GetInt64("limit")
  224. adminUser := c.GetAdminUserInfo()
  225. timeLayout := "2006-01-02"
  226. loc, _ := time.LoadLocation("Local")
  227. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  228. if err != nil {
  229. }
  230. record_time := startTime.Unix()
  231. labels, total, err := service.GetLabelPrintList(page, limit, adminUser.CurrentOrgId, record_time, is_print, keyword)
  232. if err == nil {
  233. c.ServeSuccessJSON(map[string]interface{}{
  234. "labels": labels,
  235. "total": total,
  236. })
  237. return
  238. } else {
  239. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  240. return
  241. }
  242. }
  243. func (c *HisChargeApiController) GetHisInspectionInfo() {
  244. id, _ := c.GetInt64("id")
  245. label, err := service.GetLabelPrintInfo(id)
  246. if err == nil {
  247. c.ServeSuccessJSON(map[string]interface{}{
  248. "label": label,
  249. })
  250. return
  251. } else {
  252. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  253. return
  254. }
  255. }