print_data_api_controller.go 16KB

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