print_data_api_controller.go 12KB

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