print_data_api_controller.go 15KB

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