print_data_api_controller.go 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  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 == 9882 || this.GetAdminUserInfo().CurrentOrgId == 10138 || this.GetAdminUserInfo().CurrentOrgId == 10278 || this.GetAdminUserInfo().CurrentOrgId == 9841 || this.GetAdminUserInfo().CurrentOrgId == 9845 || this.GetAdminUserInfo().CurrentOrgId == 10081 || this.GetAdminUserInfo().CurrentOrgId == 10215 || this.GetAdminUserInfo().CurrentOrgId == 10121 || this.GetAdminUserInfo().CurrentOrgId == 10234 || this.GetAdminUserInfo().CurrentOrgId == 10188 || this.GetAdminUserInfo().CurrentOrgId == 10217 || this.GetAdminUserInfo().CurrentOrgId == 10340 || this.GetAdminUserInfo().CurrentOrgId == 9905 || this.GetAdminUserInfo().CurrentOrgId == 10346 || this.GetAdminUserInfo().CurrentOrgId == 10441 || this.GetAdminUserInfo().CurrentOrgId == 9970 || this.GetAdminUserInfo().CurrentOrgId == 10101 || this.GetAdminUserInfo().CurrentOrgId == 10495 || this.GetAdminUserInfo().CurrentOrgId == 10013 || this.GetAdminUserInfo().CurrentOrgId == 10014 {
  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. //获取His医嘱
  59. doctorAdvice, _ := service.GetHisBatchDoctorAdvice(this.GetAdminUserInfo().CurrentOrgId, item.PatientID, item.ScheduleDate)
  60. item.HisAdvices = doctorAdvice
  61. //获取项目
  62. project, _ := service.GetHisBatchProject(this.GetAdminUserInfo().CurrentOrgId, item.PatientID, item.ScheduleDate)
  63. item.HisPrescriptionProject = project
  64. //双人核对
  65. dobuleCheck, _ := service.GetBatchDobuleCheck(this.GetAdminUserInfo().CurrentOrgId, item.PatientID, item.ScheduleDate)
  66. item.DoubleCheck = dobuleCheck
  67. //透析小结
  68. summerVM, _ := service.GetBatchSummerVM(this.GetAdminUserInfo().CurrentOrgId, item.PatientID, item.ScheduleDate)
  69. item.Summer = summerVM
  70. list, _ := service.GetDialysisOrderCountSeven(item.PatientID, item.ScheduleDate)
  71. if this.GetAdminUserInfo().CurrentOrgId != 10101 && this.GetAdminUserInfo().CurrentOrgId != 9671 && this.GetAdminUserInfo().CurrentOrgId != 10345 && this.GetAdminUserInfo().CurrentOrgId != 9970 && this.GetAdminUserInfo().CurrentOrgId != 10495 {
  72. item.Count = list.Count
  73. }
  74. lastSchedule, _ := service.FindLastSchedule(this.GetAdminUserInfo().CurrentOrgId, item.PatientID, item.ScheduleDate)
  75. item.Schedule = &lastSchedule
  76. if this.GetAdminUserInfo().CurrentOrgId == 10101 || this.GetAdminUserInfo().CurrentOrgId == 9671 || this.GetAdminUserInfo().CurrentOrgId == 10345 || this.GetAdminUserInfo().CurrentOrgId == 9970 || this.GetAdminUserInfo().CurrentOrgId == 10495 || this.GetAdminUserInfo().CurrentOrgId == 10013 || this.GetAdminUserInfo().CurrentOrgId == 10014 {
  77. if item.ScheduleDate <= 1672416000 {
  78. listOne, _ := service.GetDialysisOrderCountEight(adminUserInfo.CurrentOrgId, item.PatientID, item.ScheduleDate)
  79. item.Patient.TotalDialysis = listOne.Count
  80. item.Count = listOne.Count
  81. }
  82. if item.ScheduleDate >= 1672502400 {
  83. listOne, _ := service.GetDialysisOrderCountNight(adminUserInfo.CurrentOrgId, item.PatientID, item.ScheduleDate)
  84. item.Patient.TotalDialysis = listOne.Count
  85. item.Count = listOne.Count
  86. }
  87. }
  88. }
  89. if getScheduleErr != nil {
  90. this.ErrorLog("获取打印透析记录失败:%v", getScheduleErr)
  91. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  92. return
  93. }
  94. medicalStaffs, getMedicalStaffErr := service.GetMedicalStaffs(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  95. if getMedicalStaffErr != nil {
  96. this.ErrorLog("获取医护人员失败:%v", getMedicalStaffErr)
  97. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  98. return
  99. }
  100. adminUser, _ := service.GetAllAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  101. name, getScheduleErr := service.GetAllName(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  102. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  103. this.ServeSuccessJSON(map[string]interface{}{
  104. "schedules": schedules,
  105. "medical_staffs": medicalStaffs,
  106. "users": adminUser,
  107. "templateInfo": templateInfo,
  108. "name": name,
  109. })
  110. }
  111. if this.GetAdminUserInfo().CurrentOrgId != 10016 && this.GetAdminUserInfo().CurrentOrgId != 9882 && this.GetAdminUserInfo().CurrentOrgId != 10138 && this.GetAdminUserInfo().CurrentOrgId != 10278 && this.GetAdminUserInfo().CurrentOrgId != 9841 && this.GetAdminUserInfo().CurrentOrgId != 9845 && this.GetAdminUserInfo().CurrentOrgId != 10081 && this.GetAdminUserInfo().CurrentOrgId != 10215 && this.GetAdminUserInfo().CurrentOrgId != 10121 && this.GetAdminUserInfo().CurrentOrgId != 10234 && this.GetAdminUserInfo().CurrentOrgId != 10188 && this.GetAdminUserInfo().CurrentOrgId != 10217 && this.GetAdminUserInfo().CurrentOrgId != 10340 && this.GetAdminUserInfo().CurrentOrgId != 9905 && this.GetAdminUserInfo().CurrentOrgId != 10346 && this.GetAdminUserInfo().CurrentOrgId != 10441 && this.GetAdminUserInfo().CurrentOrgId != 9970 && this.GetAdminUserInfo().CurrentOrgId != 10101 && this.GetAdminUserInfo().CurrentOrgId != 10495 && this.GetAdminUserInfo().CurrentOrgId != 10013 && this.GetAdminUserInfo().CurrentOrgId != 10014 {
  112. schedules, getScheduleErr := service.GetSchedules(adminUserInfo.CurrentOrgId, idStrs)
  113. for _, item := range schedules {
  114. list, _ := service.GetDialysisOrderCountSeven(item.PatientID, item.ScheduleDate)
  115. if this.GetAdminUserInfo().CurrentOrgId != 10101 && this.GetAdminUserInfo().CurrentOrgId != 9671 && this.GetAdminUserInfo().CurrentOrgId != 10345 {
  116. if this.GetAdminUserInfo().CurrentOrgId == 10445 {
  117. listOrder, _ := service.GetDialysisOrderCountTen(item.PatientID, item.ScheduleDate)
  118. item.Count = listOrder.DialysisTotal
  119. }
  120. if this.GetAdminUserInfo().CurrentOrgId != 10445 {
  121. item.Count = list.Count
  122. }
  123. }
  124. lastSchedule, _ := service.FindLastSchedule(this.GetAdminUserInfo().CurrentOrgId, item.PatientID, item.ScheduleDate)
  125. item.Schedule = &lastSchedule
  126. if this.GetAdminUserInfo().CurrentOrgId == 10101 || this.GetAdminUserInfo().CurrentOrgId == 9671 || this.GetAdminUserInfo().CurrentOrgId == 10345 {
  127. //listOne, _ := service.GetDialysisOrderCountEight(adminUserInfo.CurrentOrgId, item.PatientID, item.ScheduleDate)
  128. //item.Patient.TotalDialysis = listOne.Count
  129. //item.Count = listOne.Count
  130. if item.ScheduleDate <= 1640966400 {
  131. listOne, _ := service.GetDialysisOrderCountEight(adminUserInfo.CurrentOrgId, item.PatientID, item.ScheduleDate)
  132. item.Patient.TotalDialysis = listOne.Count
  133. item.Count = listOne.Count
  134. }
  135. if item.ScheduleDate >= 1672502400 {
  136. listOne, _ := service.GetDialysisOrderCountNight(adminUserInfo.CurrentOrgId, item.PatientID, item.ScheduleDate)
  137. item.Patient.TotalDialysis = listOne.Count
  138. item.Count = listOne.Count
  139. }
  140. }
  141. }
  142. if getScheduleErr != nil {
  143. this.ErrorLog("获取打印透析记录失败:%v", getScheduleErr)
  144. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  145. return
  146. }
  147. medicalStaffs, getMedicalStaffErr := service.GetMedicalStaffs(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  148. if getMedicalStaffErr != nil {
  149. this.ErrorLog("获取医护人员失败:%v", getMedicalStaffErr)
  150. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  151. return
  152. }
  153. adminUser, _ := service.GetAllAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  154. name, getScheduleErr := service.GetAllName(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  155. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  156. this.ServeSuccessJSON(map[string]interface{}{
  157. "schedules": schedules,
  158. "medical_staffs": medicalStaffs,
  159. "users": adminUser,
  160. "templateInfo": templateInfo,
  161. "name": name,
  162. })
  163. }
  164. }
  165. func (this *PrintDataAPIController) StockRecordPrintData() {
  166. types, _ := this.GetInt("type", 0)
  167. start_time := this.GetString("start_time")
  168. end_time := this.GetString("end_time")
  169. adminUserInfo := this.GetAdminUserInfo()
  170. timeLayout := "2006-01-02"
  171. loc, _ := time.LoadLocation("Local")
  172. var startTime int64
  173. if len(start_time) > 0 {
  174. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  175. if err != nil {
  176. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  177. return
  178. }
  179. startTime = theTime.Unix()
  180. }
  181. var endTime int64
  182. if len(end_time) > 0 {
  183. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  184. if err != nil {
  185. utils.ErrorLog(err.Error())
  186. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  187. return
  188. }
  189. endTime = theTime.Unix()
  190. }
  191. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, adminUserInfo.CurrentOrgId)
  192. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, adminUserInfo.CurrentOrgId)
  193. info, err := service.GetCoutWareseOutInfo(startTime, endTime, adminUserInfo.CurrentOrgId)
  194. infomationList, err := service.GetGoodInfomationList(adminUserInfo.CurrentOrgId)
  195. if err != nil {
  196. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  197. } else {
  198. this.ServeSuccessJSON(map[string]interface{}{
  199. "list": list,
  200. "type": types,
  201. "stockTotal": stockTotal,
  202. "info": info,
  203. "orgid": adminUserInfo.CurrentOrgId,
  204. "infomationList": infomationList,
  205. })
  206. }
  207. }
  208. func (this *PrintDataAPIController) CourseRecordPrintData() {
  209. ids_str := this.GetString("ids")
  210. ids_arr := strings.Split(ids_str, ",")
  211. adminUserInfo := this.GetAdminUserInfo()
  212. patient_id, _ := this.GetInt64("patient_id")
  213. record, err := service.GetPatientCoursesRecords(adminUserInfo.CurrentOrgId, ids_arr)
  214. //patient, _ := service.FindPatientWithDeviceById(adminUserInfo.CurrentOrgId, patient_id)
  215. patient, _ := service.GetPatientDetail(adminUserInfo.CurrentOrgId, patient_id)
  216. adminUser, _ := service.GetAllAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  217. operators, err := service.GetAdminUserEsTwo(adminUserInfo.CurrentOrgId)
  218. if err != nil {
  219. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  220. return
  221. } else {
  222. this.ServeSuccessJSON(map[string]interface{}{
  223. "record": record,
  224. "patient": patient,
  225. "adminUser": adminUser,
  226. "operators": operators,
  227. })
  228. }
  229. }
  230. func (this *PrintDataAPIController) GetLastAfterWeight() {
  231. id, _ := this.GetInt64("id")
  232. fmt.Print("id", id)
  233. assmentdate, _ := this.GetInt64("assmentdate")
  234. adminUserInfo := this.GetAdminUserInfo()
  235. org_id := adminUserInfo.CurrentOrgId
  236. weight, err := service.GetLastAfterWeight(org_id, id, assmentdate)
  237. //fmt.Print("errr-------------",err)
  238. if err != nil {
  239. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  240. return
  241. }
  242. this.ServeSuccessJSON(map[string]interface{}{
  243. "weight": weight,
  244. })
  245. }
  246. func (this *PrintDataAPIController) GetGoodDetailPrintList() {
  247. types, _ := this.GetInt("type", 0)
  248. start_time := this.GetString("start_time")
  249. end_time := this.GetString("end_time")
  250. adminUserInfo := this.GetAdminUserInfo()
  251. timeLayout := "2006-01-02"
  252. loc, _ := time.LoadLocation("Local")
  253. var startTime int64
  254. if len(start_time) > 0 {
  255. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  256. if err != nil {
  257. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  258. return
  259. }
  260. startTime = theTime.Unix()
  261. }
  262. var endTime int64
  263. if len(end_time) > 0 {
  264. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  265. if err != nil {
  266. utils.ErrorLog(err.Error())
  267. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  268. return
  269. }
  270. endTime = theTime.Unix()
  271. }
  272. limit, _ := this.GetInt64("limit")
  273. page, _ := this.GetInt64("page")
  274. //入库详情
  275. if types == 1 {
  276. list, err := service.GetWarehouseInfoGoodDetailPrintList(adminUserInfo.CurrentOrgId, startTime, endTime, limit, page)
  277. if err != nil {
  278. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  279. return
  280. }
  281. this.ServeSuccessJSON(map[string]interface{}{
  282. "list": list,
  283. })
  284. }
  285. //出库详情
  286. if types == 2 {
  287. //list, err := service.GetWarehouseOutInfoGoodDetailPrintList(adminUserInfo.CurrentOrgId, startTime, endTime, limit, page)
  288. list, _ := service.GetWarehouseOutInfoPrintList(adminUserInfo.CurrentOrgId, startTime, endTime)
  289. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, adminUserInfo.CurrentOrgId)
  290. if err != nil {
  291. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  292. return
  293. }
  294. this.ServeSuccessJSON(map[string]interface{}{
  295. "list": list,
  296. "stockTotal": stockTotal,
  297. })
  298. }
  299. //退库详情
  300. if types == 4 {
  301. list, _ := service.GetWarehouseCancelPrintList(adminUserInfo.CurrentOrgId, startTime, endTime)
  302. this.ServeSuccessJSON(map[string]interface{}{
  303. "list": list,
  304. })
  305. }
  306. }