print_data_api_controller.go 13KB

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