print_data_api_controller.go 17KB

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