dialysis_record_api_controller.go 52KB

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