dialysis_record_api_controller.go 51KB

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