new_manage_api_controller.go 7.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. package new_mobile_api_controllers
  2. import (
  3. "Xcx_New/controllers/mobile_api_controllers"
  4. "Xcx_New/enums"
  5. "Xcx_New/models"
  6. "Xcx_New/service"
  7. "Xcx_New/utils"
  8. "fmt"
  9. "github.com/jinzhu/gorm"
  10. "strconv"
  11. "time"
  12. )
  13. type NewManageApiController struct {
  14. mobile_api_controllers.MobileBaseAPIAuthController
  15. }
  16. func (this *NewManageApiController) GetEquitAutoInfo() {
  17. adminUser := this.GetMobileAdminUserInfo()
  18. orgid := adminUser.Org.Id
  19. remander, err := service.GetRemanderData(orgid)
  20. if err != nil {
  21. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  22. return
  23. }
  24. this.ServeSuccessJSON(map[string]interface{}{
  25. "remander": remander,
  26. })
  27. }
  28. func (this *NewManageApiController) GetDisInfectionTime() {
  29. adminUser := this.GetMobileAdminUserInfo()
  30. orgid := adminUser.Org.Id
  31. bedid, _ := this.GetInt64("bed_id")
  32. scheduletype, _ := this.GetInt64("schedule_type")
  33. scheduleweek, _ := this.GetInt64("schedule_week")
  34. fmt.Println(scheduleweek)
  35. scheduledate, _ := this.GetInt64("schedule_date")
  36. //根据床位号获取设备型号
  37. unitType, _ := service.GetUnitType(bedid, orgid)
  38. //查询使用登记最后一条消毒记录
  39. infomation, err := service.GetLaseDeviceInfomation(orgid, bedid, scheduledate, scheduletype)
  40. fmt.Println("err", err)
  41. if err == gorm.ErrRecordNotFound {
  42. //查询改设备是否有消毒计划
  43. plan, errcode := service.GetDisInfectionTime(orgid, unitType.UnitType, scheduletype, scheduleweek)
  44. //如果没有消毒计划,去查询该设备的上次消毒时间
  45. if errcode == gorm.ErrRecordNotFound {
  46. infor, errco := service.GetLaseDeviceInfomationTwo(orgid, bedid, scheduletype)
  47. if errco != nil {
  48. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  49. return
  50. }
  51. this.ServeSuccessJSON(map[string]interface{}{
  52. "plan": infor.LongTime,
  53. })
  54. } else if errcode == nil {
  55. this.ServeSuccessJSON(map[string]interface{}{
  56. "plan": plan.DisinfecTime,
  57. })
  58. }
  59. } else if err == nil {
  60. this.ServeSuccessJSON(map[string]interface{}{
  61. "plan": infomation.LongTime,
  62. "infomation": infomation,
  63. })
  64. }
  65. //查询改设备是否有消毒计划
  66. //plan, err := service.GetDisInfectionTime(orgid, bedid, scheduletype, scheduleweek)
  67. //if err == gorm.ErrRecordNotFound {
  68. // //去查询使用登记最后一条数据
  69. // infomation, err := service.GetLaseDeviceInfomation(orgid, bedid)
  70. // if err != nil {
  71. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  72. // return
  73. // }
  74. // this.ServeSuccessJSON(map[string]interface{}{
  75. // "plan": infomation.LongTime,
  76. // })
  77. //} else if err == nil {
  78. // if err != nil {
  79. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  80. // return
  81. // }
  82. // this.ServeSuccessJSON(map[string]interface{}{
  83. // "plan": plan.DisinfecTime,
  84. // })
  85. //} else {
  86. //
  87. //}
  88. }
  89. func (this *NewManageApiController) SaveDisInfectionInfo() {
  90. adminUser := this.GetMobileAdminUserInfo()
  91. orgid := adminUser.Org.Id
  92. bedid, _ := this.GetInt64("bed_id")
  93. start_time := this.GetString("start_time")
  94. startdate, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", start_time)
  95. startdateunix := startdate.Unix()
  96. disinfectime, _ := this.GetInt64("disinfec_time")
  97. endtime := this.GetString("end_time")
  98. enddate, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", endtime)
  99. enddateunix := enddate.Unix()
  100. scheduledate, _ := this.GetInt64("schedule_date")
  101. zoneid, _ := this.GetInt64("zone_id")
  102. patientid, _ := this.GetInt64("patient_id")
  103. modeid, _ := this.GetInt64("mode_id")
  104. scheduletype, _ := this.GetInt64("schedule_type")
  105. //查询病人信息
  106. patients, _ := service.GetPatientInfoMation(patientid)
  107. var con = ""
  108. if patients.IsInfectious == 0 {
  109. con = ""
  110. }
  111. if patients.IsInfectious == 1 {
  112. con = "无"
  113. }
  114. if patients.IsInfectious == 2 {
  115. con = "有"
  116. }
  117. //查询病人上机信息
  118. order, _ := service.GetPatientOrderInfo(scheduledate, patientid, orgid)
  119. //查询病人今日透后评估数据
  120. dislysis, _ := service.GetAssessmentAfterDissDataTwo(patientid, orgid, scheduledate)
  121. fmt.Println("透析减少", dislysis.WeightLoss)
  122. // //根据床位号获取设备id
  123. addmacher, _ := service.GetEquimentIDTwo(bedid, orgid)
  124. //unitype, _ := strconv.ParseInt(addmacher.UnitType, 10, 64)
  125. //fmt.Println(unitype)
  126. plan, errplan := service.GetDisinfectionTwo(addmacher.UnitType, scheduletype, orgid)
  127. //counts, errplan := service.GetUserTotalCount(orgid, bedid)
  128. //var usertoal int64
  129. //fmt.Println(usertoal)
  130. //for index, count := range counts {
  131. // if(index == 0){
  132. // usertoal = count.Total
  133. // }
  134. //}
  135. //usertotalint, errplan := strconv.ParseInt(addmacher.UserTotal, 10, 64)
  136. //var total = usertoal + usertotalint
  137. //totals := strconv.FormatInt(total, 10)
  138. if errplan == gorm.ErrRecordNotFound {
  139. returnData := make(map[string]interface{}, 0)
  140. returnData["msstatus"] = "2"
  141. this.ServeSuccessJSON(returnData)
  142. return
  143. } else {
  144. _, errcode := service.GetInforTwo(patientid, scheduledate, orgid, scheduletype)
  145. if errcode == gorm.ErrRecordNotFound {
  146. information := models.DeviceInformation{
  147. Date: scheduledate,
  148. Zone: zoneid,
  149. Class: scheduletype,
  150. BedNumber: bedid,
  151. PatientId: patientid,
  152. DialysisMode: modeid,
  153. LongTime: strconv.FormatInt(disinfectime, 10),
  154. Disinfection: 1,
  155. DialysisConcentration: 1,
  156. DisinfectionStatus: 1,
  157. Move: 1,
  158. UserOrgId: orgid,
  159. DisinfectType: plan.Way,
  160. DisinfectantType: plan.MachineDisinfectant,
  161. FluidPath: plan.DisinfectanWay, //液路消毒方式
  162. Disinfectant: plan.Disinfectant,
  163. Ctime: time.Now().Unix(),
  164. Status: 1,
  165. SignName: order.FinishNurse,
  166. EquimentId: addmacher.ID,
  167. DisinfectionResidue: 2,
  168. Bed: addmacher.BedNumber,
  169. StartTime: order.StartTime,
  170. EndTime: order.EndTime,
  171. Contagion: con,
  172. WeightLoss: dislysis.WeightLoss,
  173. Hyperfiltratio: dislysis.ActualUltrafiltration,
  174. DialysisHour: strconv.FormatInt(dislysis.ActualTreatmentHour, 10),
  175. MachineRun: 1,
  176. DisinfecStartime: startdateunix,
  177. DisinfecEndtime: enddateunix,
  178. }
  179. err := service.CreateInformationTwo(&information)
  180. fmt.Println("报错", err)
  181. if err != nil {
  182. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  183. return
  184. }
  185. this.ServeSuccessJSON(map[string]interface{}{
  186. "information": information,
  187. })
  188. } else if errcode == nil {
  189. information := models.DeviceInformation{
  190. DisinfecStartime: startdateunix,
  191. DisinfecEndtime: enddateunix,
  192. LongTime: strconv.FormatInt(disinfectime, 10),
  193. }
  194. errcode := service.UpdateInformation(&information, scheduledate, bedid, scheduletype)
  195. if errcode != nil {
  196. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  197. return
  198. }
  199. this.ServeSuccessJSON(map[string]interface{}{
  200. "information": information,
  201. })
  202. } else {
  203. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  204. return
  205. }
  206. }
  207. }
  208. func (this *NewManageApiController) GetDeviceInformation() {
  209. adminUser := this.GetMobileAdminUserInfo()
  210. orgid := adminUser.Org.Id
  211. scheduleDate := this.GetString("schedule_date")
  212. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", scheduleDate)
  213. if parseErr != nil {
  214. this.ErrorLog("时间解析失败:%v", parseErr)
  215. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  216. return
  217. }
  218. fmt.Println("recordDate2222222", recordDate.Unix())
  219. //查询今日所有设备使用登记
  220. information, err := service.GetDeviceInfomation(orgid, recordDate.Unix())
  221. if err != nil {
  222. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  223. return
  224. }
  225. this.ServeSuccessJSON(map[string]interface{}{
  226. "information": information,
  227. })
  228. }