dialysis_record_api_controller.go 51KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245
  1. package controllers
  2. import (
  3. "XT_New/models"
  4. "encoding/json"
  5. "github.com/jinzhu/gorm"
  6. "math"
  7. "strconv"
  8. "time"
  9. "XT_New/enums"
  10. "XT_New/service"
  11. "XT_New/utils"
  12. "fmt"
  13. "github.com/astaxie/beego"
  14. )
  15. func DialysisRecordAPIControllerRegistRouter() {
  16. beego.Router("/api/dialysis/initdata", &DialysisRecordAPIController{}, "get:RecordInitData")
  17. beego.Router("/api/dialysis/schedules", &DialysisRecordAPIController{}, "get:GetSchedules")
  18. beego.Router("/api/dislysis/schedule", &DialysisRecordAPIController{}, "get:DialysisSchedule")
  19. beego.Router("/api/dislysis/monitor/edit", &DialysisRecordAPIController{}, "post:EditMonitor")
  20. beego.Router("/api/dialysis/start_record", &DialysisRecordAPIController{}, "post:StartDialysis")
  21. beego.Router("/api/dialysis/finish", &DialysisRecordAPIController{}, "post:FinishDialysis")
  22. beego.Router("/api/start_dialysis/modify", &DialysisRecordAPIController{}, "post:ModifyStartDialysis")
  23. beego.Router("/api/finish_dialysis/modify", &DialysisRecordAPIController{}, "post:ModifyFinishDialysis")
  24. }
  25. type DialysisRecordAPIController struct {
  26. BaseAuthAPIController
  27. }
  28. // /api/dialysis/initdata [get]
  29. func (this *DialysisRecordAPIController) RecordInitData() {
  30. adminInfo := this.GetAdminUserInfo()
  31. orgID := adminInfo.CurrentOrgId
  32. now := time.Now()
  33. ymdDate, _ := utils.ParseTimeStringToTime("2006-01-02", now.Format("2006-01-02"))
  34. schedules, getSchedulesErr := service.GetDialysisScheduals(orgID, ymdDate.Unix())
  35. if getSchedulesErr != nil {
  36. this.ErrorLog("获取排班信息失败:%v", getSchedulesErr)
  37. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  38. return
  39. }
  40. zones, getZonesErr := service.GetAllValidDeviceZones(orgID)
  41. if getZonesErr != nil {
  42. this.ErrorLog("获取全部分区失败:%v", getZonesErr)
  43. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  44. return
  45. }
  46. this.ServeSuccessJSON(map[string]interface{}{
  47. "schedules": schedules,
  48. "zones": zones,
  49. })
  50. }
  51. // /api/dialysis/schedules [get]
  52. // @param date:string (yyyy-mm-dd)
  53. func (this *DialysisRecordAPIController) GetSchedules() {
  54. schedualDate := this.GetString("date")
  55. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  56. if parseDateErr != nil {
  57. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  58. return
  59. }
  60. adminInfo := this.GetAdminUserInfo()
  61. orgID := adminInfo.CurrentOrgId
  62. schedules, err := service.GetDialysisScheduals(orgID, date.Unix())
  63. if err != nil {
  64. this.ErrorLog("获取排班信息失败:%v", err)
  65. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  66. } else {
  67. this.ServeSuccessJSON(map[string]interface{}{
  68. "schedules": schedules,
  69. })
  70. }
  71. }
  72. // /api/dislysis/schedule [get]
  73. // @param patient_id:int
  74. // @param date:string (yyyy-MM-dd)
  75. func (this *DialysisRecordAPIController) DialysisSchedule() {
  76. patientID, _ := this.GetInt64("patient_id")
  77. recordDateStr := this.GetString("date")
  78. if patientID <= 0 {
  79. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  80. return
  81. }
  82. if len(recordDateStr) == 0 {
  83. recordDateStr = time.Now().Format("2006-01-02")
  84. }
  85. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  86. if parseDateErr != nil {
  87. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  88. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  89. return
  90. }
  91. adminInfo := this.GetAdminUserInfo()
  92. patient, getPatientErr := service.MobileGetPatientDetail(adminInfo.CurrentOrgId, patientID)
  93. if getPatientErr != nil {
  94. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  95. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  96. return
  97. } else if patient == nil {
  98. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  99. return
  100. }
  101. schedual, getSchedualErr := service.MobileGetSchedualDetail(adminInfo.CurrentOrgId, patientID, date.Unix())
  102. if getSchedualErr != nil {
  103. this.ErrorLog("获取患者排班信息失败:%v", getSchedualErr)
  104. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  105. return
  106. }
  107. receiverTreatmentAccess, getRTARErr := service.MobileGetReceiverTreatmentAccessRecord(adminInfo.CurrentOrgId, patientID, date.Unix())
  108. if getRTARErr != nil {
  109. this.ErrorLog("获取接诊评估失败:%v", getRTARErr)
  110. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  111. return
  112. }
  113. predialysisEvaluation, getPEErr := service.MobileGetPredialysisEvaluation(adminInfo.CurrentOrgId, patientID, date.Unix())
  114. fmt.Println("predialysisEvaluatiotion", predialysisEvaluation)
  115. if getPEErr != nil {
  116. this.ErrorLog("获取透前评估失败:%v", getPEErr)
  117. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  118. return
  119. }
  120. doctorAdvices, getDoctorAdvicesErr := service.MobileGetDoctorAdvices(adminInfo.CurrentOrgId, patientID, date.Unix())
  121. if getDoctorAdvicesErr != nil {
  122. this.ErrorLog("获取临时医嘱失败:%v", getDoctorAdvicesErr)
  123. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  124. return
  125. }
  126. dialysisOrder, getDialysisOrderErr := service.MobileGetSchedualDialysisRecord(adminInfo.CurrentOrgId, patientID, date.Unix())
  127. if getDialysisOrderErr != nil {
  128. this.ErrorLog("获取透析记录失败:%v", getDialysisOrderErr)
  129. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  130. return
  131. }
  132. doubleCheck, getDoubleCheckErr := service.MobileGetDoubleCheck(adminInfo.CurrentOrgId, patientID, date.Unix())
  133. if getDoubleCheckErr != nil {
  134. this.ErrorLog("获取双人核对记录失败:%v", getDoubleCheckErr)
  135. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  136. return
  137. }
  138. monitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecords(adminInfo.CurrentOrgId, patientID, date.Unix())
  139. if getMonitorRecordsErr != nil {
  140. this.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  141. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  142. return
  143. }
  144. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysis(adminInfo.CurrentOrgId, patientID, date.Unix())
  145. if getAADErr != nil {
  146. this.ErrorLog("获取透后评估失败:%v", getAADErr)
  147. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  148. return
  149. }
  150. treatmentSummary, getTreatmentSummaryErr := service.MobileGetTreatmentSummary(adminInfo.CurrentOrgId, patientID, date.Unix())
  151. if getTreatmentSummaryErr != nil {
  152. this.ErrorLog("获取治疗小结失败:%v", getTreatmentSummaryErr)
  153. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  154. return
  155. }
  156. admins, getAdminsErr := service.GetAllAdminUsers(adminInfo.CurrentOrgId, adminInfo.CurrentAppId)
  157. if getAdminsErr != nil {
  158. this.ErrorLog("获取医护列表失败:%v", getAdminsErr)
  159. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  160. return
  161. }
  162. devices, getDevicesErr := service.GetValidDevicesBy(adminInfo.CurrentOrgId, 0, 0)
  163. if getDevicesErr != nil {
  164. this.ErrorLog("获取设备列表失败:%v", getDevicesErr)
  165. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  166. return
  167. }
  168. deviceNumbers, getDeviceNumbersErr := service.GetAllValidDeviceNumbers(adminInfo.CurrentOrgId)
  169. if getDeviceNumbersErr != nil {
  170. this.ErrorLog("获取床位号列表失败:%v", getDeviceNumbersErr)
  171. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  172. return
  173. }
  174. lastPredialysisEvaluation, getLPEErr := service.GetLastTimePredialysisEvaluation(adminInfo.CurrentOrgId, patientID, date.Unix())
  175. if getLPEErr != nil {
  176. this.ErrorLog("获取上一次透前评估失败:%v", getLPEErr)
  177. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  178. return
  179. }
  180. var lastMonitorRecord *models.MonitoringRecord
  181. lastMonitorRecord, getLastErr := service.GetLastMonitorRecord(adminInfo.CurrentOrgId, patientID, date.Unix())
  182. if getLastErr != nil {
  183. this.ErrorLog("获取上一次透析的监测记录失败:%v", getLastErr)
  184. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  185. return
  186. }
  187. lastAssessmentAfterDislysis, getLAADErr := service.GetLastTimeAssessmentAfterDislysis(adminInfo.CurrentOrgId, patientID, date.Unix())
  188. if getLAADErr != nil {
  189. this.ErrorLog("获取上一次透后评估失败:%v", getLAADErr)
  190. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  191. return
  192. }
  193. dialysisPrescribe, getDialysisPrescribeErr := service.GetDialysisPrescribe(adminInfo.CurrentOrgId, patientID, date.Unix())
  194. if getDialysisPrescribeErr != nil {
  195. this.ErrorLog("获取透析处方失败:%v", getDialysisPrescribeErr)
  196. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  197. return
  198. }
  199. dialysisSolution, getDialysisSolutionErr := service.GetDialysisSolution(adminInfo.CurrentOrgId, patientID, schedual.ModeId)
  200. if getDialysisSolutionErr != nil {
  201. this.ErrorLog("获取透析方案失败:%v", getDialysisSolutionErr)
  202. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  203. return
  204. }
  205. lastDialysisPrescribe, getDialysisPrescribeErr := service.GetLastDialysisPrescribeByModeId(adminInfo.CurrentOrgId, patientID, schedual.ModeId)
  206. if getDialysisPrescribeErr != nil {
  207. this.ErrorLog("获取透析处方失败:%v", getDialysisPrescribeErr)
  208. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  209. return
  210. }
  211. systemDialysisPrescribe, getSystemDialysisPrescribeErr := service.GetSystemDialysisPrescribeByModeId(adminInfo.CurrentOrgId, schedual.ModeId)
  212. if getSystemDialysisPrescribeErr != nil {
  213. this.ErrorLog("获取系统透析处方失败:%v", getSystemDialysisPrescribeErr)
  214. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  215. return
  216. }
  217. if getLPEErr != nil {
  218. this.ErrorLog("获取上一次透前评估失败:%v", getLPEErr)
  219. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  220. return
  221. }
  222. lastDryWeightDislysis, getDryErr := service.GetLastDryWeight(adminInfo.CurrentOrgId, patientID)
  223. if getDryErr != nil {
  224. this.ErrorLog("获取最后一条干体重失败:%v", getDryErr)
  225. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  226. return
  227. }
  228. headNurses, _ := service.GetAllSpecialPermissionAdminUsersWithoutStatus(adminInfo.CurrentOrgId, adminInfo.CurrentAppId, models.SpecialPermissionTypeHeadNurse)
  229. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.CurrentOrgId)
  230. returnData := map[string]interface{}{
  231. "patient": patient,
  232. "schedual": schedual,
  233. "prescription": dialysisPrescribe,
  234. "solution": dialysisSolution,
  235. "receiver_treatment_access": receiverTreatmentAccess,
  236. "predialysis_evaluation": predialysisEvaluation,
  237. "doctor_advices": doctorAdvices,
  238. "double_check": doubleCheck,
  239. "assessment_after_dislysis": assessmentAfterDislysis,
  240. "treatment_summary": treatmentSummary,
  241. "monitor_records": monitorRecords,
  242. "dialysis_order": dialysisOrder,
  243. "doctors": admins,
  244. "config": record,
  245. "devices": devices,
  246. "device_numbers": deviceNumbers,
  247. "lastPredialysisEvaluation": lastPredialysisEvaluation,
  248. "lastMonitorRecord": lastMonitorRecord,
  249. "lastAssessmentAfterDislysis": lastAssessmentAfterDislysis,
  250. "lastDialysisPrescribe": lastDialysisPrescribe,
  251. "lastDryWeightDislysis": lastDryWeightDislysis,
  252. "headNurses": headNurses,
  253. "system_prescribe": systemDialysisPrescribe,
  254. }
  255. this.ServeSuccessJSON(returnData)
  256. }
  257. type EditMonitorParamObject struct {
  258. ID int64 `json:"id"`
  259. MonitoringDate int64 `json:"monitoring_date"`
  260. OperateTime int64 `json:"operate_time"`
  261. // MonitoringTime string `json:"monitoring_time"`
  262. SystolicBP float64 `json:"systolic_bp"`
  263. DiastolicBP float64 `json:"diastolic_bp"`
  264. PulseFrequency float64 `json:"pulse_frequency"`
  265. BreathingRated float64 `json:"breathing_rated"`
  266. BloodFlowVolume float64 `json:"blood_flow_volume"`
  267. VenousPressure float64 `json:"venous_pressure"`
  268. VenousPressureType int64 `json:"venous_pressure_type"`
  269. TransmembranePressure float64 `json:"transmembrane_pressure"`
  270. TransmembranePressureType int64 `json:"transmembrane_pressure_type"`
  271. UltrafiltrationVolume float64 `json:"ultrafiltration_volume"`
  272. UltrafiltrationRate float64 `json:"ultrafiltration_rate"`
  273. ArterialPressure float64 `json:"arterial_pressure"`
  274. ArterialPressureType int64 `json:"arterial_pressure_type"`
  275. SodiumConcentration float64 `json:"sodium_concentration"`
  276. DialysateTemperature float64 `json:"dialysate_temperature"`
  277. Temperature float64 `json:"temperature"`
  278. ReplacementRate float64 `json:"replacement_rate"`
  279. DisplacementQuantity float64 `json:"displacement_quantity"`
  280. KTV float64 `json:"ktv"`
  281. Symptom string `json:"symptom"`
  282. Dispose string `json:"dispose"`
  283. Result string `json:"result"`
  284. Conductivity float64 `json:"conductivity"`
  285. DisplacementFlowQuantity float64 `json:"displacement_flow_quantity"`
  286. BloodOxygenSaturation string `gorm:"column:blood_oxygen_saturation" json:"blood_oxygen_saturation" form:"blood_oxygen_saturation"`
  287. Heparin float64 `gorm:"column:heparin" json:"heparin" form:"heparin"`
  288. DialysateFlow float64 `gorm:"column:dialysate_flow" json:"dialysate_flow" form:"dialysate_flow"`
  289. Urr string `gorm:"column:urr" json:"urr" form:"urr"`
  290. BloodSugar float64 `gorm:"column:blood_sugar" json:"blood_sugar" form:"blood_sugar"`
  291. }
  292. // /api/dislysis/monitor/edit [post]
  293. // @param patient_id:int 患者id
  294. // @param schedule_date:int 排班日期
  295. // 下面的参数放到 body
  296. // @param id?:int 监测记录ID(id为0时为创建记录,不为0时为修改记录)
  297. // @param monitoring_date:int 排班日期
  298. // @param operate_time:int 实际测量日期
  299. // @param monitoring_time:string (HH:mm) 监测时间 废弃
  300. // @param systolic_bp?:float 收缩压
  301. // @param diastolic_bp?:float 舒张压
  302. // @param pulse_frequency?:float 心率
  303. // @param breathing_rated?:float 呼吸频率
  304. // @param blood_flow_volume?:float 血流量
  305. // @param venous_pressure?:float 静脉压
  306. // @param transmembrane_pressure?:float 跨膜压
  307. // @param ultrafiltration_volume?:float 超滤量
  308. // @param ultrafiltration_rate?:float 超滤率
  309. // @param arterial_pressure?:float 动脉压
  310. // @param sodium_concentration?:float 钠浓度
  311. // @param dialysate_temperature?:float 透析液温度
  312. // @param replacement_rate?:float 置换率
  313. // @param displacement_quantity?:float 置换量
  314. // @param ktv?:float KT/V
  315. // @param symptom?:string 病情变化
  316. // @param dispose?:string 处理
  317. // @param result?:string 结果
  318. func (this *DialysisRecordAPIController) EditMonitor() {
  319. patientID, _ := this.GetInt64("patient_id")
  320. scheduleDate, _ := this.GetInt64("schedule_date")
  321. if patientID <= 0 || scheduleDate <= 0 {
  322. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  323. return
  324. }
  325. var monitorParam EditMonitorParamObject
  326. if parseErr := json.Unmarshal(this.Ctx.Input.RequestBody, &monitorParam); parseErr != nil {
  327. this.ErrorLog("参数解析失败:%v", parseErr)
  328. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamFormatWrong)
  329. return
  330. }
  331. if monitorParam.MonitoringDate != scheduleDate {
  332. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  333. return
  334. }
  335. adminUserInfo := this.GetAdminUserInfo()
  336. schedule, getScheduleErr := service.MobileGetSchedualDetail(adminUserInfo.CurrentOrgId, patientID, scheduleDate)
  337. if getScheduleErr != nil {
  338. this.ErrorLog("获取排班信息失败:%v", getScheduleErr)
  339. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  340. return
  341. } else if schedule == nil {
  342. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist)
  343. return
  344. }
  345. // TODO 其实这里合理的逻辑是“透析记录存在的情况下才能添加监测记录的”
  346. dialysisOrder, getDialysisOrderErr := service.MobileGetDialysisRecord(adminUserInfo.CurrentOrgId, patientID, scheduleDate)
  347. if getDialysisOrderErr != nil {
  348. this.ErrorLog("获取透析记录失败:%v", getDialysisOrderErr)
  349. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  350. return
  351. }
  352. orderID := int64(0)
  353. if dialysisOrder != nil {
  354. orderID = dialysisOrder.ID
  355. }
  356. if monitorParam.ID <= 0 { // 新建记录
  357. monitor := models.MonitoringRecord{
  358. UserOrgId: adminUserInfo.CurrentOrgId,
  359. PatientId: patientID,
  360. DialysisOrderId: orderID,
  361. MonitoringDate: monitorParam.MonitoringDate,
  362. OperateTime: monitorParam.OperateTime,
  363. // MonitoringTime: monitorParam.MonitoringTime,
  364. PulseFrequency: monitorParam.PulseFrequency,
  365. BreathingRate: monitorParam.BreathingRated,
  366. SystolicBloodPressure: monitorParam.SystolicBP,
  367. DiastolicBloodPressure: monitorParam.DiastolicBP,
  368. BloodFlowVolume: monitorParam.BloodFlowVolume,
  369. VenousPressure: monitorParam.VenousPressure,
  370. VenousPressureType: monitorParam.VenousPressureType,
  371. ArterialPressure: monitorParam.ArterialPressure,
  372. ArterialPressureType: monitorParam.ArterialPressureType,
  373. TransmembranePressure: monitorParam.TransmembranePressure,
  374. TransmembranePressureType: monitorParam.TransmembranePressureType,
  375. UltrafiltrationRate: monitorParam.UltrafiltrationRate,
  376. UltrafiltrationVolume: monitorParam.UltrafiltrationVolume,
  377. SodiumConcentration: monitorParam.SodiumConcentration,
  378. DialysateTemperature: monitorParam.DialysateTemperature,
  379. Temperature: monitorParam.Temperature,
  380. ReplacementRate: monitorParam.ReplacementRate,
  381. DisplacementQuantity: monitorParam.DisplacementQuantity,
  382. Ktv: monitorParam.KTV,
  383. Symptom: monitorParam.Symptom,
  384. Dispose: monitorParam.Dispose,
  385. Result: monitorParam.Result,
  386. MonitoringNurse: adminUserInfo.AdminUser.Id,
  387. Conductivity: monitorParam.Conductivity,
  388. DisplacementFlowQuantity: monitorParam.DisplacementFlowQuantity,
  389. Status: 1,
  390. CreatedTime: time.Now().Unix(),
  391. UpdatedTime: time.Now().Unix(),
  392. BloodOxygenSaturation: monitorParam.BloodOxygenSaturation,
  393. Creator: adminUserInfo.AdminUser.Id,
  394. Heparin: monitorParam.Heparin,
  395. DialysateFlow: monitorParam.DialysateFlow,
  396. Urr: monitorParam.Urr,
  397. BloodSugar: monitorParam.BloodSugar,
  398. }
  399. createErr := service.CreateMonitor(&monitor)
  400. if createErr != nil {
  401. this.ErrorLog("创建监测记录失败:%v", createErr)
  402. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  403. return
  404. }
  405. this.ServeSuccessJSON(map[string]interface{}{
  406. "monitor": monitor,
  407. })
  408. } else { // 修改记录
  409. monitor, getMonitorErr := service.GetMonitor(adminUserInfo.CurrentOrgId, patientID, monitorParam.ID)
  410. if getMonitorErr != nil {
  411. this.ErrorLog("获取透析监测记录失败:%v", getMonitorErr)
  412. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  413. return
  414. } else if monitor == nil {
  415. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorNotExist)
  416. return
  417. }
  418. //if monitor.MonitoringNurse != adminUserInfo.AdminUser.Id {
  419. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  420. // if getPermissionErr != nil {
  421. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  422. // return
  423. // } else if headNursePermission == nil {
  424. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  425. // return
  426. // }
  427. //}
  428. monitor.OperateTime = monitorParam.OperateTime
  429. monitor.PulseFrequency = monitorParam.PulseFrequency
  430. monitor.BreathingRate = monitorParam.BreathingRated
  431. monitor.SystolicBloodPressure = monitorParam.SystolicBP
  432. monitor.DiastolicBloodPressure = monitorParam.DiastolicBP
  433. monitor.BloodFlowVolume = monitorParam.BloodFlowVolume
  434. monitor.VenousPressure = monitorParam.VenousPressure
  435. monitor.VenousPressureType = monitorParam.VenousPressureType
  436. monitor.ArterialPressure = monitorParam.ArterialPressure
  437. monitor.ArterialPressureType = monitorParam.ArterialPressureType
  438. monitor.TransmembranePressure = monitorParam.TransmembranePressure
  439. monitor.TransmembranePressureType = monitorParam.TransmembranePressureType
  440. monitor.UltrafiltrationRate = monitorParam.UltrafiltrationRate
  441. monitor.UltrafiltrationVolume = monitorParam.UltrafiltrationVolume
  442. monitor.SodiumConcentration = monitorParam.SodiumConcentration
  443. monitor.DialysateTemperature = monitorParam.DialysateTemperature
  444. monitor.Temperature = monitorParam.Temperature
  445. monitor.ReplacementRate = monitorParam.ReplacementRate
  446. monitor.DisplacementQuantity = monitorParam.DisplacementQuantity
  447. monitor.Conductivity = monitorParam.Conductivity
  448. monitor.DisplacementFlowQuantity = monitorParam.DisplacementFlowQuantity
  449. monitor.Ktv = monitorParam.KTV
  450. monitor.Symptom = monitorParam.Symptom
  451. monitor.Dispose = monitorParam.Dispose
  452. monitor.Result = monitorParam.Result
  453. monitor.MonitoringNurse = adminUserInfo.AdminUser.Id
  454. monitor.UpdatedTime = time.Now().Unix()
  455. monitor.Modify = adminUserInfo.AdminUser.Id
  456. monitor.BloodOxygenSaturation = monitorParam.BloodOxygenSaturation
  457. monitor.Heparin = monitorParam.Heparin
  458. monitor.DialysateFlow = monitorParam.DialysateFlow
  459. monitor.Urr = monitorParam.Urr
  460. monitor.BloodSugar = monitorParam.BloodSugar
  461. updateErr := service.UpdateMonitor(monitor)
  462. if updateErr != nil {
  463. this.ErrorLog("修改透析监测记录失败:%v", updateErr)
  464. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  465. return
  466. }
  467. this.ServeSuccessJSON(map[string]interface{}{
  468. "monitor": monitor,
  469. })
  470. }
  471. }
  472. // /api/dialysis/start_record [post]
  473. // @param patient_id:int
  474. // @param date:string 排班时间 (yyyy-mm-dd)
  475. // @param nurse:int 上机护士
  476. // @param bed:int 上机床位号
  477. func (this *DialysisRecordAPIController) StartDialysis() {
  478. patientID, _ := this.GetInt64("patient_id")
  479. recordDateStr := this.GetString("date")
  480. nurseID, _ := this.GetInt64("nurse")
  481. punctureNurseId, _ := this.GetInt64("puncture_nurse")
  482. startDateStr := this.GetString("start_time")
  483. blood_drawing, _ := this.GetInt64("blood_drawing")
  484. schedual_type, _ := this.GetInt64("schedual_type")
  485. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  486. bedID, _ := this.GetInt64("bed")
  487. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  488. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  489. return
  490. }
  491. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  492. if parseErr != nil {
  493. this.ErrorLog("时间解析失败:%v", parseErr)
  494. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  495. return
  496. }
  497. startDate, parseErr := utils.ParseTimeStringToTime("2006-01-02 15:04", startDateStr)
  498. if parseErr != nil {
  499. this.ErrorLog("时间解析失败:%v", parseErr)
  500. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  501. return
  502. }
  503. adminUserInfo := this.GetAdminUserInfo()
  504. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.CurrentOrgId, patientID)
  505. if getPatientErr != nil {
  506. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  507. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  508. return
  509. } else if patient == nil {
  510. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  511. return
  512. }
  513. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  514. if getNurseErr != nil {
  515. this.ErrorLog("获取护士失败:%v", getNurseErr)
  516. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  517. return
  518. } else if nurse == nil {
  519. this.ErrorLog("护士不存在")
  520. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  521. return
  522. }
  523. nurse, getNurseErr = service.GetAdminUserByUserID(punctureNurseId)
  524. if getNurseErr != nil {
  525. this.ErrorLog("获取护士失败:%v", getNurseErr)
  526. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  527. return
  528. } else if nurse == nil {
  529. this.ErrorLog("护士不存在")
  530. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  531. return
  532. }
  533. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.CurrentOrgId, bedID)
  534. if getDeviceNumberErr != nil {
  535. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  536. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  537. return
  538. } else if deviceNumber == nil {
  539. this.ErrorLog("床位号不存在")
  540. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  541. return
  542. }
  543. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  544. if getRecordErr != nil {
  545. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  546. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  547. return
  548. } else if dialysisRecord != nil {
  549. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  550. return
  551. }
  552. template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  553. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  554. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  555. timeLayout := "2006-01-02 15:04:05"
  556. loc, _ := time.LoadLocation("Local")
  557. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  558. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  559. schedulestartTime := theStartTime.Unix()
  560. scheduleendTime := theEndTime.Unix()
  561. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  562. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.CurrentOrgId, schedulestartTime, bedID, schedual_type)
  563. //查询该床位是否有人用了
  564. order, order_err := service.GetDialysisOrderByBedId(adminUserInfo.CurrentOrgId, schedulestartTime, bedID, schedual_type)
  565. if err == gorm.ErrRecordNotFound { //空床位
  566. // 修改了床位逻辑
  567. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, patientID)
  568. if daySchedule.ID > 0 {
  569. daySchedule.PartitionId = deviceNumber.ZoneID
  570. daySchedule.BedId = bedID
  571. daySchedule.ScheduleType = schedual_type
  572. daySchedule.UpdatedTime = time.Now().Unix()
  573. err := service.UpdateSchedule(&daySchedule)
  574. if err != nil {
  575. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  576. return
  577. }
  578. }
  579. } else if err == nil {
  580. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  581. if order_err == nil {
  582. if order.ID > 0 { //该机位被其他人占用了
  583. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  584. return
  585. } else {
  586. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, patientID)
  587. if daySchedule.ID > 0 {
  588. daySchedule.PartitionId = deviceNumber.ZoneID
  589. daySchedule.BedId = bedID
  590. daySchedule.ScheduleType = schedual_type
  591. daySchedule.UpdatedTime = time.Now().Unix()
  592. err := service.UpdateSchedule(&daySchedule)
  593. if err != nil {
  594. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  595. return
  596. }
  597. }
  598. }
  599. } else if order_err == gorm.ErrRecordNotFound { //该床位没被占用
  600. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, patientID)
  601. if daySchedule.ID > 0 {
  602. daySchedule.PartitionId = deviceNumber.ZoneID
  603. daySchedule.BedId = bedID
  604. daySchedule.ScheduleType = schedual_type
  605. daySchedule.UpdatedTime = time.Now().Unix()
  606. err := service.UpdateSchedule(&daySchedule)
  607. if err != nil {
  608. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  609. return
  610. }
  611. }
  612. } else if order_err != nil {
  613. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  614. return
  615. }
  616. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  617. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  618. return
  619. }
  620. } else if err != nil {
  621. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  622. return
  623. }
  624. dialysisRecord = &models.DialysisOrder{
  625. DialysisDate: recordDate.Unix(),
  626. UserOrgId: adminUserInfo.CurrentOrgId,
  627. PatientId: patientID,
  628. Stage: 1,
  629. BedID: bedID,
  630. StartNurse: nurseID,
  631. Status: 1,
  632. StartTime: startDate.Unix(),
  633. CreatedTime: time.Now().Unix(),
  634. UpdatedTime: time.Now().Unix(),
  635. PunctureNurse: punctureNurseId,
  636. Creator: adminUserInfo.AdminUser.Id,
  637. Modifier: adminUserInfo.AdminUser.Id,
  638. SchedualType: schedual_type,
  639. WashpipeNurse: washpipe_nurse,
  640. }
  641. createErr := service.MobileCreateDialysisOrder(adminUserInfo.CurrentOrgId, patientID, dialysisRecord)
  642. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  643. if createErr != nil {
  644. this.ErrorLog("上机失败:%v", createErr)
  645. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  646. return
  647. } else if createErr == nil {
  648. var tempdispose string
  649. // 只针对中能建
  650. if blood_drawing > 0 && adminUserInfo.CurrentOrgId == 9538 { //adminUserInfo.CurrentOrgId == 9538
  651. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  652. }
  653. var ultrafiltration_rate float64
  654. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.CurrentOrgId)
  655. if prescription.ID > 0 {
  656. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  657. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  658. if template.TemplateId == 6 || template.TemplateId == 20 || template.TemplateId == 22 {
  659. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  660. }
  661. // 只针对方济医院
  662. if template.TemplateId == 1 && adminUserInfo.CurrentOrgId != 9849 {
  663. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  664. ultrafiltration_rate = value
  665. }
  666. }
  667. }
  668. record := models.MonitoringRecord{
  669. UserOrgId: adminUserInfo.CurrentOrgId,
  670. PatientId: patientID,
  671. DialysisOrderId: dialysisRecord.ID,
  672. MonitoringDate: schedulestartTime,
  673. OperateTime: startDate.Unix(),
  674. // MonitoringTime: recordTime,
  675. MonitoringNurse: nurseID,
  676. Dispose: tempdispose,
  677. UltrafiltrationRate: ultrafiltration_rate,
  678. UltrafiltrationVolume: 0,
  679. Status: 1,
  680. CreatedTime: time.Now().Unix(),
  681. UpdatedTime: time.Now().Unix(),
  682. }
  683. // 如果当天有插入数据,则不再往透析纪录里插入数据
  684. if newdialysisRecord.ID > 0 {
  685. err := service.CreateMonitor(&record)
  686. if err != nil {
  687. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  688. return
  689. }
  690. }
  691. this.ServeSuccessJSON(map[string]interface{}{
  692. "dialysis_order": dialysisRecord,
  693. "monitor": record,
  694. })
  695. }
  696. }
  697. // /api/dialysis/finish [post]
  698. // @param patient_id:int
  699. // @param date:string 排班时间 (yyyy-mm-dd)
  700. // @param nurse:int 下机护士
  701. func (this *DialysisRecordAPIController) FinishDialysis() {
  702. patientID, _ := this.GetInt64("patient_id")
  703. recordDateStr := this.GetString("date")
  704. nurseID, _ := this.GetInt64("nurse")
  705. end_time := this.GetString("end_time")
  706. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 {
  707. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  708. return
  709. }
  710. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  711. if parseErr != nil {
  712. this.ErrorLog("时间解析失败:%v", parseErr)
  713. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  714. return
  715. }
  716. //if parseEndDateErr != nil {
  717. // this.ErrorLog("时间解析失败:%v", parseEndDateErr)
  718. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  719. // return
  720. //}
  721. adminUserInfo := this.GetAdminUserInfo()
  722. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.CurrentOrgId, patientID)
  723. if getPatientErr != nil {
  724. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  725. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  726. return
  727. } else if patient == nil {
  728. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  729. return
  730. }
  731. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  732. if getNurseErr != nil {
  733. this.ErrorLog("获取护士失败:%v", getNurseErr)
  734. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  735. return
  736. } else if nurse == nil {
  737. this.ErrorLog("护士不存在")
  738. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  739. return
  740. }
  741. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  742. if getRecordErr != nil {
  743. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  744. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  745. return
  746. }
  747. if dialysisRecord.Stage == 2 {
  748. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  749. return
  750. }
  751. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04", end_time)
  752. if parseEndDateErr != nil {
  753. this.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  754. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  755. return
  756. }
  757. // 获取当天的第一条透析纪录
  758. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  759. if getMonitorRecordsErr != nil {
  760. this.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  761. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  762. return
  763. }
  764. // 获取当前的最后一条透析纪录
  765. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecord(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  766. if getMonitorRecordsErr != nil {
  767. this.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  768. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  769. return
  770. }
  771. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysis(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  772. if getAADErr != nil {
  773. this.ErrorLog("获取透后评估失败:%v", getAADErr)
  774. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  775. return
  776. }
  777. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysis(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  778. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  779. if assessmentAfterDislysis != nil {
  780. tempassessmentAfterDislysis = *assessmentAfterDislysis
  781. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  782. } else {
  783. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  784. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  785. tempassessmentAfterDislysis.Status = 1
  786. tempassessmentAfterDislysis.PatientId = patientID
  787. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.CurrentOrgId
  788. }
  789. if dialysisRecord.Stage == 1 {
  790. temp_time := (float64(endDate.Unix()) - float64(dialysisRecord.StartTime)) / 3600
  791. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  792. fmt.Println(value)
  793. a, b := math.Modf(value)
  794. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  795. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  796. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  797. fmt.Println(hour)
  798. fmt.Println(minute)
  799. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  800. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  801. }
  802. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  803. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  804. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  805. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  806. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  807. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  808. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  809. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  810. }
  811. if lastAssessmentAfterDislysis != nil {
  812. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  813. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  814. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  815. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  816. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  817. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  818. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  819. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  820. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  821. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  822. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  823. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  824. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  825. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  826. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  827. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  828. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  829. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  830. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  831. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  832. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  833. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  834. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  835. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  836. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  837. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  838. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  839. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  840. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  841. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  842. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  843. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  844. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  845. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  846. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  847. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  848. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  849. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  850. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  851. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  852. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  853. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  854. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  855. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  856. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  857. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  858. }
  859. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  860. if err != nil {
  861. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  862. return
  863. }
  864. updateErr := service.ModifyDialysisRecord(dialysisRecord.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id)
  865. if updateErr != nil {
  866. this.ErrorLog("下机失败:%v", updateErr)
  867. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  868. return
  869. } else {
  870. dialysisRecord.Stage = 2
  871. dialysisRecord.FinishNurse = nurseID
  872. dialysisRecord.FinishCreator = adminUserInfo.AdminUser.Id
  873. dialysisRecord.FinishModifier = adminUserInfo.AdminUser.Id
  874. dialysisRecord.EndTime = endDate.Unix()
  875. // 结束时候透析次数加1
  876. service.UpdateSolutionByPatientId(patientID)
  877. this.ServeSuccessJSON(map[string]interface{}{
  878. "dialysis_order": dialysisRecord,
  879. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  880. })
  881. }
  882. }
  883. func (this *DialysisRecordAPIController) ModifyStartDialysis() {
  884. record_id, _ := this.GetInt64("id")
  885. nurseID, _ := this.GetInt64("nurse")
  886. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  887. bedID, _ := this.GetInt64("bed")
  888. start_time := this.GetString("start_time")
  889. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  890. schedual_type, _ := this.GetInt64("schedual_type")
  891. if record_id == 0 {
  892. this.ErrorLog("id:%v", record_id)
  893. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  894. return
  895. }
  896. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04", start_time)
  897. if parseStartDateErr != nil {
  898. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  899. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  900. return
  901. }
  902. adminUserInfo := this.GetAdminUserInfo()
  903. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  904. if getNurseErr != nil {
  905. this.ErrorLog("获取护士失败:%v", getNurseErr)
  906. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  907. return
  908. } else if nurse == nil {
  909. this.ErrorLog("护士不存在")
  910. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  911. return
  912. }
  913. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  914. if getNurseErr != nil {
  915. this.ErrorLog("获取护士失败:%v", getNurseErr)
  916. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  917. return
  918. } else if nurse == nil {
  919. this.ErrorLog("护士不存在")
  920. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  921. return
  922. }
  923. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.CurrentOrgId, bedID)
  924. if getDeviceNumberErr != nil {
  925. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  926. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  927. return
  928. } else if deviceNumber == nil {
  929. this.ErrorLog("床位号不存在")
  930. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  931. return
  932. }
  933. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  934. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  935. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  936. // if getPermissionErr != nil {
  937. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  938. // return
  939. // } else if headNursePermission == nil {
  940. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  941. // return
  942. // }
  943. //}
  944. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  945. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  946. timeLayout := "2006-01-02 15:04:05"
  947. loc, _ := time.LoadLocation("Local")
  948. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  949. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  950. schedulestartTime := theStartTime.Unix()
  951. scheduleendTime := theEndTime.Unix()
  952. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  953. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.CurrentOrgId, schedulestartTime, bedID, schedual_type)
  954. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  955. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  956. if err == gorm.ErrRecordNotFound { //空床位
  957. // 修改了床位逻辑
  958. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  959. if daySchedule.ID > 0 {
  960. daySchedule.BedId = bedID
  961. daySchedule.PartitionId = deviceNumber.ZoneID
  962. daySchedule.ScheduleType = schedual_type
  963. daySchedule.UpdatedTime = time.Now().Unix()
  964. err := service.UpdateSchedule(&daySchedule)
  965. if err != nil {
  966. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  967. return
  968. }
  969. }
  970. } else if err == nil {
  971. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  972. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  973. if daySchedule.ID > 0 {
  974. daySchedule.BedId = bedID
  975. daySchedule.PartitionId = deviceNumber.ZoneID
  976. daySchedule.ScheduleType = schedual_type
  977. daySchedule.UpdatedTime = time.Now().Unix()
  978. err := service.UpdateSchedule(&daySchedule)
  979. if err != nil {
  980. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  981. return
  982. }
  983. }
  984. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  985. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  986. return
  987. }
  988. } else if err != nil {
  989. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  990. return
  991. }
  992. }
  993. dialysisRecord := &models.DialysisOrder{
  994. ID: record_id,
  995. UserOrgId: adminUserInfo.CurrentOrgId,
  996. BedID: bedID,
  997. StartNurse: nurseID,
  998. StartTime: startDate.Unix(),
  999. PunctureNurse: puncture_nurse,
  1000. Creator: adminUserInfo.AdminUser.Id,
  1001. Modifier: adminUserInfo.AdminUser.Id,
  1002. SchedualType: schedual_type,
  1003. WashpipeNurse: washpipe_nurse,
  1004. }
  1005. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  1006. if updateErr != nil {
  1007. this.ErrorLog("修改上机失败:%v", updateErr)
  1008. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1009. return
  1010. }
  1011. if updateErr == nil {
  1012. if tempDialysisRecord.Stage == 2 {
  1013. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  1014. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  1015. fmt.Println(value)
  1016. a, b := math.Modf(value)
  1017. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  1018. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  1019. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  1020. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  1021. if updateAssessmentErr != nil {
  1022. utils.ErrorLog("%v", updateAssessmentErr)
  1023. }
  1024. after, _ := service.FindAssessmentAfterDislysisById(tempDialysisRecord.UserOrgId, tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  1025. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  1026. this.ServeSuccessJSON(map[string]interface{}{
  1027. "dialysis_order": dialysisRecords,
  1028. "after": after,
  1029. })
  1030. } else {
  1031. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  1032. this.ServeSuccessJSON(map[string]interface{}{
  1033. "dialysis_order": dialysisRecords,
  1034. })
  1035. }
  1036. }
  1037. }
  1038. func (c *DialysisRecordAPIController) ModifyFinishDialysis() {
  1039. record_id, _ := c.GetInt64("id")
  1040. nurseID, _ := c.GetInt64("nurse")
  1041. end_time := c.GetString("end_time")
  1042. if record_id <= 0 || nurseID <= 0 {
  1043. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1044. return
  1045. }
  1046. adminUserInfo := c.GetAdminUserInfo()
  1047. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  1048. if getNurseErr != nil {
  1049. c.ErrorLog("获取护士失败:%v", getNurseErr)
  1050. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1051. return
  1052. } else if nurse == nil {
  1053. c.ErrorLog("护士不存在")
  1054. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1055. return
  1056. }
  1057. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04", end_time)
  1058. if parseEndDateErr != nil {
  1059. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  1060. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1061. return
  1062. }
  1063. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  1064. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  1065. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1066. // if getPermissionErr != nil {
  1067. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1068. // return
  1069. // } else if headNursePermission == nil {
  1070. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1071. // return
  1072. // }
  1073. //}
  1074. dialysisRecord := &models.DialysisOrder{
  1075. ID: record_id,
  1076. UserOrgId: adminUserInfo.CurrentOrgId,
  1077. EndTime: endDate.Unix(),
  1078. FinishNurse: nurseID,
  1079. FinishModifier: adminUserInfo.AdminUser.Id,
  1080. }
  1081. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  1082. if updateErr != nil {
  1083. c.ErrorLog("修改下机失败:%v", updateErr)
  1084. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1085. return
  1086. }
  1087. if updateErr == nil {
  1088. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  1089. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  1090. fmt.Println(value)
  1091. a, b := math.Modf(value)
  1092. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  1093. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  1094. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  1095. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  1096. if updateAssessmentErr != nil {
  1097. utils.ErrorLog("%v", updateAssessmentErr)
  1098. }
  1099. }
  1100. after, _ := service.FindAssessmentAfterDislysisById(tempDialysisRecords.UserOrgId, tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate)
  1101. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  1102. c.ServeSuccessJSON(map[string]interface{}{
  1103. "dialysis_order": dialysisRecords,
  1104. "after": after,
  1105. })
  1106. }