dialysis_record_api_controller.go 58KB

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