dialysis_record_api_controller.go 51KB

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