print_data_api_controller.go 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. service "XT_New/service/print_data_service/schedule_dialysis"
  5. "XT_New/utils"
  6. "fmt"
  7. "strings"
  8. "time"
  9. "github.com/astaxie/beego"
  10. )
  11. func PrintDataAPIControllerRegistRouters() {
  12. beego.Router("/api/print/schedule/dialysis", &PrintDataAPIController{}, "get:ScheduleDialysisRecordPrintData")
  13. beego.Router("/api/print/stock", &PrintDataAPIController{}, "get:StockRecordPrintData")
  14. beego.Router("/api/print/course", &PrintDataAPIController{}, "get:CourseRecordPrintData")
  15. beego.Router("/api/print/getlastafterweight", &PrintDataAPIController{}, "get:GetLastAfterWeight")
  16. beego.Router("/api/stock/getgooddetailprintlist", &PrintDataAPIController{}, "get:GetGoodDetailPrintList")
  17. }
  18. type PrintDataAPIController struct {
  19. BaseAuthAPIController
  20. }
  21. // /api/print/schedule/dialysis [get]
  22. // @param ids:string 排班 id,以逗号隔开 ("1,2,3")
  23. func (this *PrintDataAPIController) ScheduleDialysisRecordPrintData() {
  24. schIDStr := this.GetString("ids")
  25. if len(schIDStr) == 0 {
  26. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  27. return
  28. }
  29. idStrs := strings.Split(schIDStr, ",")
  30. adminUserInfo := this.GetAdminUserInfo()
  31. if this.GetAdminUserInfo().CurrentOrgId == 10016 || this.GetAdminUserInfo().CurrentOrgId == 9671 {
  32. schedules, getScheduleErr := service.GetSchedulesSeven(adminUserInfo.CurrentOrgId, idStrs)
  33. for _, item := range schedules {
  34. //获取透析上机
  35. order, _ := service.GetBatchDialysisOrder(this.GetAdminUserInfo().CurrentOrgId, item.PatientID, item.ScheduleDate)
  36. item.DialysisOrder = order
  37. //获取透析处方
  38. prescription, _ := service.GetBatchPrescription(this.GetAdminUserInfo().CurrentOrgId, item.PatientID, item.ScheduleDate)
  39. item.Prescription = prescription
  40. //接诊评估
  41. receiveTreatmentAsses, _ := service.GetBatchReceiveTreatmentAsses(this.GetAdminUserInfo().CurrentOrgId, item.PatientID, item.ScheduleDate)
  42. item.ReceiveAssessment = receiveTreatmentAsses
  43. //透前评估
  44. assessmentBeforeDislysisVM, _ := service.GetBatchAssessmentBeforeDislysisVM(this.GetAdminUserInfo().CurrentOrgId, item.PatientID, item.ScheduleDate)
  45. item.AssessmentBeforeDislysis = assessmentBeforeDislysisVM
  46. //透后评估
  47. assessmentAfterDislysisVM, _ := service.GetBatchAssessmentAfterDislysisVM(this.GetAdminUserInfo().CurrentOrgId, item.PatientID, item.ScheduleDate)
  48. item.AssessmentAfterDislysis = assessmentAfterDislysisVM
  49. //上次透后体重
  50. lastAfterWeight, _ := service.GetBatchLastAfterWeight(this.GetAdminUserInfo().CurrentOrgId, item.PatientID, item.ScheduleDate)
  51. item.LastAfterWeight = lastAfterWeight
  52. //透析监测
  53. monitor, _ := service.GetBatchMonitor(this.GetAdminUserInfo().CurrentOrgId, item.PatientID, item.ScheduleDate)
  54. item.MonitoringRecords = monitor
  55. //透析医嘱
  56. advice, _ := service.GetBatchDoctorAdvice(this.GetAdminUserInfo().CurrentOrgId, item.PatientID, item.ScheduleDate)
  57. item.Advices = advice
  58. //双人核对
  59. dobuleCheck, _ := service.GetBatchDobuleCheck(this.GetAdminUserInfo().CurrentOrgId, item.PatientID, item.ScheduleDate)
  60. item.DoubleCheck = dobuleCheck
  61. //透析小结
  62. summerVM, _ := service.GetBatchSummerVM(this.GetAdminUserInfo().CurrentOrgId, item.PatientID, item.ScheduleDate)
  63. item.Summer = summerVM
  64. list, _ := service.GetDialysisOrderCountSeven(item.PatientID, item.ScheduleDate)
  65. if this.GetAdminUserInfo().CurrentOrgId != 10101 && this.GetAdminUserInfo().CurrentOrgId != 9671 {
  66. item.Count = list.Count
  67. }
  68. if this.GetAdminUserInfo().CurrentOrgId == 10101 || this.GetAdminUserInfo().CurrentOrgId == 9671 {
  69. if item.ScheduleDate <= 1640966400 {
  70. listOne, _ := service.GetDialysisOrderCountEight(adminUserInfo.CurrentOrgId, item.PatientID, item.ScheduleDate)
  71. item.Patient.TotalDialysis = listOne.Count
  72. item.Count = listOne.Count
  73. }
  74. if item.ScheduleDate >= 1672502400 {
  75. listOne, _ := service.GetDialysisOrderCountNight(adminUserInfo.CurrentOrgId, item.PatientID, item.ScheduleDate)
  76. item.Patient.TotalDialysis = listOne.Count
  77. item.Count = listOne.Count
  78. }
  79. }
  80. }
  81. if getScheduleErr != nil {
  82. this.ErrorLog("获取打印透析记录失败:%v", getScheduleErr)
  83. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  84. return
  85. }
  86. medicalStaffs, getMedicalStaffErr := service.GetMedicalStaffs(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  87. if getMedicalStaffErr != nil {
  88. this.ErrorLog("获取医护人员失败:%v", getMedicalStaffErr)
  89. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  90. return
  91. }
  92. adminUser, _ := service.GetAllAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  93. name, getScheduleErr := service.GetAllName(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  94. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  95. this.ServeSuccessJSON(map[string]interface{}{
  96. "schedules": schedules,
  97. "medical_staffs": medicalStaffs,
  98. "users": adminUser,
  99. "templateInfo": templateInfo,
  100. "name": name,
  101. })
  102. }
  103. if this.GetAdminUserInfo().CurrentOrgId != 10016 && this.GetAdminUserInfo().CurrentOrgId != 9671 {
  104. schedules, getScheduleErr := service.GetSchedules(adminUserInfo.CurrentOrgId, idStrs)
  105. for _, item := range schedules {
  106. list, _ := service.GetDialysisOrderCountSeven(item.PatientID, item.ScheduleDate)
  107. if this.GetAdminUserInfo().CurrentOrgId != 10101 && this.GetAdminUserInfo().CurrentOrgId != 9671 {
  108. item.Count = list.Count
  109. }
  110. if this.GetAdminUserInfo().CurrentOrgId == 10101 || this.GetAdminUserInfo().CurrentOrgId == 9671 {
  111. listOne, _ := service.GetDialysisOrderCountEight(adminUserInfo.CurrentOrgId, item.PatientID, item.ScheduleDate)
  112. item.Patient.TotalDialysis = listOne.Count
  113. item.Count = listOne.Count
  114. }
  115. }
  116. if getScheduleErr != nil {
  117. this.ErrorLog("获取打印透析记录失败:%v", getScheduleErr)
  118. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  119. return
  120. }
  121. medicalStaffs, getMedicalStaffErr := service.GetMedicalStaffs(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  122. if getMedicalStaffErr != nil {
  123. this.ErrorLog("获取医护人员失败:%v", getMedicalStaffErr)
  124. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  125. return
  126. }
  127. adminUser, _ := service.GetAllAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  128. name, getScheduleErr := service.GetAllName(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  129. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  130. this.ServeSuccessJSON(map[string]interface{}{
  131. "schedules": schedules,
  132. "medical_staffs": medicalStaffs,
  133. "users": adminUser,
  134. "templateInfo": templateInfo,
  135. "name": name,
  136. })
  137. }
  138. }
  139. func (this *PrintDataAPIController) StockRecordPrintData() {
  140. types, _ := this.GetInt("type", 0)
  141. start_time := this.GetString("start_time")
  142. end_time := this.GetString("end_time")
  143. adminUserInfo := this.GetAdminUserInfo()
  144. timeLayout := "2006-01-02"
  145. loc, _ := time.LoadLocation("Local")
  146. var startTime int64
  147. if len(start_time) > 0 {
  148. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  149. if err != nil {
  150. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  151. return
  152. }
  153. startTime = theTime.Unix()
  154. }
  155. var endTime int64
  156. if len(end_time) > 0 {
  157. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  158. if err != nil {
  159. utils.ErrorLog(err.Error())
  160. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  161. return
  162. }
  163. endTime = theTime.Unix()
  164. }
  165. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, adminUserInfo.CurrentOrgId)
  166. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, adminUserInfo.CurrentOrgId)
  167. info, err := service.GetCoutWareseOutInfo(startTime, endTime, adminUserInfo.CurrentOrgId)
  168. infomationList, err := service.GetGoodInfomationList(adminUserInfo.CurrentOrgId)
  169. if err != nil {
  170. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  171. } else {
  172. this.ServeSuccessJSON(map[string]interface{}{
  173. "list": list,
  174. "type": types,
  175. "stockTotal": stockTotal,
  176. "info": info,
  177. "orgid": adminUserInfo.CurrentOrgId,
  178. "infomationList": infomationList,
  179. })
  180. }
  181. }
  182. func (this *PrintDataAPIController) CourseRecordPrintData() {
  183. ids_str := this.GetString("ids")
  184. ids_arr := strings.Split(ids_str, ",")
  185. adminUserInfo := this.GetAdminUserInfo()
  186. patient_id, _ := this.GetInt64("patient_id")
  187. record, err := service.GetPatientCoursesRecords(adminUserInfo.CurrentOrgId, ids_arr)
  188. //patient, _ := service.FindPatientWithDeviceById(adminUserInfo.CurrentOrgId, patient_id)
  189. patient, _ := service.GetPatientDetail(adminUserInfo.CurrentOrgId, patient_id)
  190. if err != nil {
  191. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  192. return
  193. } else {
  194. this.ServeSuccessJSON(map[string]interface{}{
  195. "record": record,
  196. "patient": patient,
  197. })
  198. }
  199. }
  200. func (this *PrintDataAPIController) GetLastAfterWeight() {
  201. id, _ := this.GetInt64("id")
  202. fmt.Print("id", id)
  203. assmentdate, _ := this.GetInt64("assmentdate")
  204. adminUserInfo := this.GetAdminUserInfo()
  205. org_id := adminUserInfo.CurrentOrgId
  206. weight, err := service.GetLastAfterWeight(org_id, id, assmentdate)
  207. //fmt.Print("errr-------------",err)
  208. if err != nil {
  209. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  210. return
  211. }
  212. this.ServeSuccessJSON(map[string]interface{}{
  213. "weight": weight,
  214. })
  215. }
  216. func (this *PrintDataAPIController) GetGoodDetailPrintList() {
  217. types, _ := this.GetInt("type", 0)
  218. start_time := this.GetString("start_time")
  219. end_time := this.GetString("end_time")
  220. adminUserInfo := this.GetAdminUserInfo()
  221. timeLayout := "2006-01-02"
  222. loc, _ := time.LoadLocation("Local")
  223. var startTime int64
  224. if len(start_time) > 0 {
  225. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  226. if err != nil {
  227. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  228. return
  229. }
  230. startTime = theTime.Unix()
  231. }
  232. var endTime int64
  233. if len(end_time) > 0 {
  234. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  235. if err != nil {
  236. utils.ErrorLog(err.Error())
  237. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  238. return
  239. }
  240. endTime = theTime.Unix()
  241. }
  242. limit, _ := this.GetInt64("limit")
  243. page, _ := this.GetInt64("page")
  244. //入库详情
  245. if types == 1 {
  246. list, err := service.GetWarehouseInfoGoodDetailPrintList(adminUserInfo.CurrentOrgId, startTime, endTime, limit, page)
  247. if err != nil {
  248. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  249. return
  250. }
  251. this.ServeSuccessJSON(map[string]interface{}{
  252. "list": list,
  253. })
  254. }
  255. //出库详情
  256. if types == 2 {
  257. //list, err := service.GetWarehouseOutInfoGoodDetailPrintList(adminUserInfo.CurrentOrgId, startTime, endTime, limit, page)
  258. list, _ := service.GetWarehouseOutInfoPrintList(adminUserInfo.CurrentOrgId, startTime, endTime)
  259. fmt.Println("list23323232233232", list)
  260. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, adminUserInfo.CurrentOrgId)
  261. if err != nil {
  262. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  263. return
  264. }
  265. this.ServeSuccessJSON(map[string]interface{}{
  266. "list": list,
  267. "stockTotal": stockTotal,
  268. })
  269. }
  270. //退库详情
  271. if types == 4 {
  272. list, _ := service.GetWarehouseCancelPrintList(adminUserInfo.CurrentOrgId, startTime, endTime)
  273. this.ServeSuccessJSON(map[string]interface{}{
  274. "list": list,
  275. })
  276. }
  277. }