print_data_api_controller.go 11KB

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