print_data_api_controller.go 15KB

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