print_data_api_controller.go 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. package controllers
  2. import (
  3. "fmt"
  4. "strings"
  5. "time"
  6. "XT_New/enums"
  7. service "XT_New/service/print_data_service/schedule_dialysis"
  8. "XT_New/utils"
  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 || this.GetAdminUserInfo().CurrentOrgId == 10307 {
  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 <= 1703952000 {
  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 >= 1704038400 {
  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. numberList, _ := service.GetAllBedNumberList(adminUserInfo.CurrentOrgId)
  104. this.ServeSuccessJSON(map[string]interface{}{
  105. "schedules": schedules,
  106. "medical_staffs": medicalStaffs,
  107. "users": adminUser,
  108. "templateInfo": templateInfo,
  109. "name": name,
  110. "numberList": numberList,
  111. })
  112. }
  113. 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 && this.GetAdminUserInfo().CurrentOrgId != 10307 {
  114. schedules, getScheduleErr := service.GetSchedules(adminUserInfo.CurrentOrgId, idStrs)
  115. for _, item := range schedules {
  116. list, _ := service.GetDialysisOrderCountSeven(item.PatientID, item.ScheduleDate)
  117. if this.GetAdminUserInfo().CurrentOrgId != 10101 && this.GetAdminUserInfo().CurrentOrgId != 9671 && this.GetAdminUserInfo().CurrentOrgId != 10345 {
  118. if this.GetAdminUserInfo().CurrentOrgId == 10445 {
  119. if item.ScheduleDate <= 1703952000 {
  120. listOne, _ := service.GetDialysisOrderCountEight(adminUserInfo.CurrentOrgId, item.PatientID, item.ScheduleDate)
  121. item.Patient.TotalDialysis = listOne.Count
  122. item.Count = listOne.Count
  123. }
  124. if item.ScheduleDate >= 1704038400 {
  125. fmt.Println("寄哪里地方阿道夫阿道夫")
  126. //listOrder, _ := service.GetDialysisOrderCountNight(item.PatientID, item.ScheduleDate)
  127. //fmt.Println("")
  128. //item.Count = listOrder.DialysisTotal
  129. listOne, _ := service.GetDialysisOrderCountNight(adminUserInfo.CurrentOrgId, item.PatientID, item.ScheduleDate)
  130. item.Patient.TotalDialysis = listOne.Count
  131. item.Count = listOne.Count
  132. }
  133. }
  134. if this.GetAdminUserInfo().CurrentOrgId != 10445 {
  135. item.Count = list.Count
  136. }
  137. }
  138. lastSchedule, _ := service.FindLastSchedule(this.GetAdminUserInfo().CurrentOrgId, item.PatientID, item.ScheduleDate)
  139. item.Schedule = &lastSchedule
  140. if this.GetAdminUserInfo().CurrentOrgId == 10101 || this.GetAdminUserInfo().CurrentOrgId == 9671 || this.GetAdminUserInfo().CurrentOrgId == 10345 {
  141. if item.ScheduleDate <= 1640966400 {
  142. listOne, _ := service.GetDialysisOrderCountEight(adminUserInfo.CurrentOrgId, item.PatientID, item.ScheduleDate)
  143. item.Patient.TotalDialysis = listOne.Count
  144. item.Count = listOne.Count
  145. }
  146. if item.ScheduleDate >= 1672502400 {
  147. listOne, _ := service.GetDialysisOrderCountNight(adminUserInfo.CurrentOrgId, item.PatientID, item.ScheduleDate)
  148. item.Patient.TotalDialysis = listOne.Count
  149. item.Count = listOne.Count
  150. }
  151. }
  152. //上次透后体重
  153. lastAfterWeight, _ := service.GetBatchLastAfterWeight(this.GetAdminUserInfo().CurrentOrgId, item.PatientID, item.ScheduleDate)
  154. item.LastAfterWeight = lastAfterWeight
  155. }
  156. if getScheduleErr != nil {
  157. this.ErrorLog("获取打印透析记录失败:%v", getScheduleErr)
  158. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  159. return
  160. }
  161. medicalStaffs, getMedicalStaffErr := service.GetMedicalStaffs(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  162. if getMedicalStaffErr != nil {
  163. this.ErrorLog("获取医护人员失败:%v", getMedicalStaffErr)
  164. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  165. return
  166. }
  167. adminUser, _ := service.GetAllAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  168. name, getScheduleErr := service.GetAllName(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  169. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  170. numberList, _ := service.GetAllBedNumberList(adminUserInfo.CurrentOrgId)
  171. this.ServeSuccessJSON(map[string]interface{}{
  172. "schedules": schedules,
  173. "medical_staffs": medicalStaffs,
  174. "users": adminUser,
  175. "templateInfo": templateInfo,
  176. "name": name,
  177. "numberList": numberList,
  178. })
  179. }
  180. }
  181. func (this *PrintDataAPIController) StockRecordPrintData() {
  182. types, _ := this.GetInt("type", 0)
  183. start_time := this.GetString("start_time")
  184. end_time := this.GetString("end_time")
  185. adminUserInfo := this.GetAdminUserInfo()
  186. timeLayout := "2006-01-02"
  187. loc, _ := time.LoadLocation("Local")
  188. var startTime int64
  189. if len(start_time) > 0 {
  190. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  191. if err != nil {
  192. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  193. return
  194. }
  195. startTime = theTime.Unix()
  196. }
  197. var endTime int64
  198. if len(end_time) > 0 {
  199. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  200. if err != nil {
  201. utils.ErrorLog(err.Error())
  202. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  203. return
  204. }
  205. endTime = theTime.Unix()
  206. }
  207. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, adminUserInfo.CurrentOrgId)
  208. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, adminUserInfo.CurrentOrgId)
  209. info, err := service.GetCoutWareseOutInfo(startTime, endTime, adminUserInfo.CurrentOrgId)
  210. infomationList, err := service.GetGoodInfomationList(adminUserInfo.CurrentOrgId)
  211. if err != nil {
  212. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  213. } else {
  214. this.ServeSuccessJSON(map[string]interface{}{
  215. "list": list,
  216. "type": types,
  217. "stockTotal": stockTotal,
  218. "info": info,
  219. "orgid": adminUserInfo.CurrentOrgId,
  220. "infomationList": infomationList,
  221. })
  222. }
  223. }
  224. func (this *PrintDataAPIController) CourseRecordPrintData() {
  225. ids_str := this.GetString("ids")
  226. ids_arr := strings.Split(ids_str, ",")
  227. adminUserInfo := this.GetAdminUserInfo()
  228. patient_id, _ := this.GetInt64("patient_id")
  229. record, err := service.GetPatientCoursesRecords(adminUserInfo.CurrentOrgId, ids_arr)
  230. //patient, _ := service.FindPatientWithDeviceById(adminUserInfo.CurrentOrgId, patient_id)
  231. patient, _ := service.GetPatientDetail(adminUserInfo.CurrentOrgId, patient_id)
  232. adminUser, _ := service.GetAllAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  233. operators, err := service.GetAdminUserEsTwo(adminUserInfo.CurrentOrgId)
  234. if err != nil {
  235. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  236. return
  237. } else {
  238. this.ServeSuccessJSON(map[string]interface{}{
  239. "record": record,
  240. "patient": patient,
  241. "adminUser": adminUser,
  242. "operators": operators,
  243. })
  244. }
  245. }
  246. func (this *PrintDataAPIController) GetLastAfterWeight() {
  247. id, _ := this.GetInt64("id")
  248. fmt.Print("id", id)
  249. assmentdate, _ := this.GetInt64("assmentdate")
  250. adminUserInfo := this.GetAdminUserInfo()
  251. org_id := adminUserInfo.CurrentOrgId
  252. weight, err := service.GetLastAfterWeight(org_id, id, assmentdate)
  253. //fmt.Print("errr-------------",err)
  254. if err != nil {
  255. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  256. return
  257. }
  258. this.ServeSuccessJSON(map[string]interface{}{
  259. "weight": weight,
  260. })
  261. }
  262. func (this *PrintDataAPIController) GetGoodDetailPrintList() {
  263. types, _ := this.GetInt("type", 0)
  264. start_time := this.GetString("start_time")
  265. end_time := this.GetString("end_time")
  266. adminUserInfo := this.GetAdminUserInfo()
  267. timeLayout := "2006-01-02"
  268. loc, _ := time.LoadLocation("Local")
  269. var startTime int64
  270. if len(start_time) > 0 {
  271. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  272. if err != nil {
  273. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  274. return
  275. }
  276. startTime = theTime.Unix()
  277. }
  278. var endTime int64
  279. if len(end_time) > 0 {
  280. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  281. if err != nil {
  282. utils.ErrorLog(err.Error())
  283. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  284. return
  285. }
  286. endTime = theTime.Unix()
  287. }
  288. limit, _ := this.GetInt64("limit")
  289. page, _ := this.GetInt64("page")
  290. //入库详情
  291. if types == 1 {
  292. list, err := service.GetWarehouseInfoGoodDetailPrintList(adminUserInfo.CurrentOrgId, startTime, endTime, limit, page)
  293. if err != nil {
  294. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  295. return
  296. }
  297. this.ServeSuccessJSON(map[string]interface{}{
  298. "list": list,
  299. })
  300. }
  301. //出库详情
  302. if types == 2 {
  303. //list, err := service.GetWarehouseOutInfoGoodDetailPrintList(adminUserInfo.CurrentOrgId, startTime, endTime, limit, page)
  304. list, _ := service.GetWarehouseOutInfoPrintList(adminUserInfo.CurrentOrgId, startTime, endTime)
  305. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, adminUserInfo.CurrentOrgId)
  306. if err != nil {
  307. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  308. return
  309. }
  310. this.ServeSuccessJSON(map[string]interface{}{
  311. "list": list,
  312. "stockTotal": stockTotal,
  313. })
  314. }
  315. //退库详情
  316. if types == 4 {
  317. list, _ := service.GetWarehouseCancelPrintList(adminUserInfo.CurrentOrgId, startTime, endTime)
  318. this.ServeSuccessJSON(map[string]interface{}{
  319. "list": list,
  320. })
  321. }
  322. }