dialysis_record_api_controller.go 58KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386
  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. if template.TemplateId == 6 && adminUserInfo.CurrentOrgId == 10234 {
  723. if evaluation.ID > 0 {
  724. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration) / float64(totalMin) * 60 * 1000)
  725. }
  726. }
  727. // 只针对方济医院
  728. if template.TemplateId == 1 && adminUserInfo.CurrentOrgId != 9849 {
  729. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  730. ultrafiltration_rate = value
  731. }
  732. //针对监利大垸医院
  733. if adminUserInfo.CurrentOrgId == 10101 {
  734. if evaluation.ID > 0 {
  735. ultrafiltration_rate = math.Ceil(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  736. fmt.Println("ultrafiltration_rate", ultrafiltration_rate)
  737. }
  738. }
  739. fmt.Println("hhh233223323223232332233233223323223323232322332322323", adminUserInfo.CurrentOrgId)
  740. //针对肇庆三鹤血液透析中心
  741. if adminUserInfo.CurrentOrgId == 10215 || template.TemplateId == 43 {
  742. if evaluation.ID > 0 {
  743. ultrafiltration_rate = math.Ceil(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  744. fmt.Println("hhhh2323323223322323323232", ultrafiltration_rate)
  745. }
  746. }
  747. }
  748. }
  749. record := models.MonitoringRecord{
  750. UserOrgId: adminUserInfo.CurrentOrgId,
  751. PatientId: patientID,
  752. DialysisOrderId: dialysisRecord.ID,
  753. MonitoringDate: schedulestartTime,
  754. OperateTime: startDate.Unix(),
  755. // MonitoringTime: recordTime,
  756. MonitoringNurse: nurseID,
  757. Dispose: tempdispose,
  758. UltrafiltrationRate: ultrafiltration_rate,
  759. UltrafiltrationVolume: 0,
  760. Status: 1,
  761. CreatedTime: time.Now().Unix(),
  762. UpdatedTime: time.Now().Unix(),
  763. }
  764. // 如果当天有插入数据,则不再往透析纪录里插入数据
  765. if newdialysisRecord.ID > 0 {
  766. err := service.CreateMonitor(&record)
  767. if err != nil {
  768. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  769. return
  770. }
  771. }
  772. go func() {
  773. ssoDomain := beego.AppConfig.String("call_domain")
  774. api := ssoDomain + "/index/uppatient"
  775. values := make(url.Values)
  776. values.Set("org_id", strconv.FormatInt(adminUserInfo.CurrentOrgId, 10))
  777. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  778. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  779. values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
  780. http.PostForm(api, values)
  781. }()
  782. this.ServeSuccessJSON(map[string]interface{}{
  783. "dialysis_order": dialysisRecord,
  784. "monitor": record,
  785. })
  786. }
  787. }
  788. // /api/dialysis/finish [post]
  789. // @param patient_id:int
  790. // @param date:string 排班时间 (yyyy-mm-dd)
  791. // @param nurse:int 下机护士
  792. func (this *DialysisRecordAPIController) FinishDialysis() {
  793. patientID, _ := this.GetInt64("patient_id")
  794. recordDateStr := this.GetString("date")
  795. nurseID, _ := this.GetInt64("nurse")
  796. end_time := this.GetString("end_time")
  797. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 {
  798. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  799. return
  800. }
  801. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  802. if parseErr != nil {
  803. this.ErrorLog("时间解析失败:%v", parseErr)
  804. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  805. return
  806. }
  807. //if parseEndDateErr != nil {
  808. // this.ErrorLog("时间解析失败:%v", parseEndDateErr)
  809. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  810. // return
  811. //}
  812. adminUserInfo := this.GetAdminUserInfo()
  813. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.CurrentOrgId, patientID)
  814. if getPatientErr != nil {
  815. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  816. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  817. return
  818. } else if patient == nil {
  819. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  820. return
  821. }
  822. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  823. if getNurseErr != nil {
  824. this.ErrorLog("获取护士失败:%v", getNurseErr)
  825. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  826. return
  827. } else if nurse == nil {
  828. this.ErrorLog("护士不存在")
  829. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  830. return
  831. }
  832. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  833. if getRecordErr != nil {
  834. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  835. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  836. return
  837. }
  838. if dialysisRecord.Stage == 2 {
  839. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  840. return
  841. }
  842. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04", end_time)
  843. if parseEndDateErr != nil {
  844. this.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  845. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  846. return
  847. }
  848. // 获取当天的第一条透析纪录
  849. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  850. if getMonitorRecordsErr != nil {
  851. this.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  852. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  853. return
  854. }
  855. // 获取当前的最后一条透析纪录
  856. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecord(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  857. if getMonitorRecordsErr != nil {
  858. this.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  859. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  860. return
  861. }
  862. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysis(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  863. if getAADErr != nil {
  864. this.ErrorLog("获取透后评估失败:%v", getAADErr)
  865. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  866. return
  867. }
  868. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysis(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  869. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  870. if assessmentAfterDislysis != nil {
  871. tempassessmentAfterDislysis = *assessmentAfterDislysis
  872. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  873. } else {
  874. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  875. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  876. tempassessmentAfterDislysis.Status = 1
  877. tempassessmentAfterDislysis.PatientId = patientID
  878. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.CurrentOrgId
  879. }
  880. if dialysisRecord.Stage == 1 {
  881. temp_time := (float64(endDate.Unix()) - float64(dialysisRecord.StartTime)) / 3600
  882. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  883. fmt.Println(value)
  884. a, b := math.Modf(value)
  885. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  886. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  887. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  888. fmt.Println(hour)
  889. fmt.Println(minute)
  890. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  891. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  892. }
  893. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  894. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  895. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  896. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  897. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  898. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  899. if adminUserInfo.CurrentOrgId == 10101 {
  900. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  901. } else {
  902. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  903. }
  904. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  905. }
  906. if adminUserInfo.CurrentOrgId == 9583 {
  907. //获取最后一条透析处方数据
  908. prescription, parseErr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  909. if parseErr != nil {
  910. this.ErrorLog("获取透析处方失败:%v", getMonitorRecordsErr)
  911. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  912. return
  913. }
  914. if prescription.ID > 0 && adminUserInfo.CurrentOrgId == 9583 {
  915. tempassessmentAfterDislysis.ActualUltrafiltration = prescription.TargetUltrafiltration
  916. }
  917. if endmonitorRecords.ID > 0 && adminUserInfo.CurrentOrgId == 10060 {
  918. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  919. }
  920. }
  921. if lastAssessmentAfterDislysis != nil {
  922. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  923. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  924. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  925. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  926. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  927. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  928. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  929. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  930. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  931. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  932. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  933. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  934. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  935. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  936. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  937. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  938. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  939. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  940. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  941. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  942. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  943. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  944. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  945. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  946. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  947. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  948. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  949. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  950. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  951. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  952. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  953. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  954. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  955. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  956. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  957. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  958. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  959. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  960. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  961. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  962. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  963. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  964. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  965. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  966. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  967. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  968. }
  969. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  970. if err != nil {
  971. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  972. return
  973. }
  974. go func() {
  975. ssoDomain := beego.AppConfig.String("call_domain")
  976. api := ssoDomain + "/index/downpatient"
  977. values := make(url.Values)
  978. values.Set("org_id", strconv.FormatInt(adminUserInfo.CurrentOrgId, 10))
  979. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  980. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  981. http.PostForm(api, values)
  982. }()
  983. updateErr := service.ModifyDialysisRecord(dialysisRecord.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id)
  984. if updateErr != nil {
  985. this.ErrorLog("下机失败:%v", updateErr)
  986. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  987. return
  988. } else {
  989. dialysisRecord.Stage = 2
  990. dialysisRecord.FinishNurse = nurseID
  991. dialysisRecord.FinishCreator = adminUserInfo.AdminUser.Id
  992. dialysisRecord.FinishModifier = adminUserInfo.AdminUser.Id
  993. dialysisRecord.EndTime = endDate.Unix()
  994. // 结束时候透析次数加1
  995. service.UpdateSolutionByPatientId(patientID)
  996. this.ServeSuccessJSON(map[string]interface{}{
  997. "dialysis_order": dialysisRecord,
  998. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  999. })
  1000. }
  1001. }
  1002. func (this *DialysisRecordAPIController) ModifyStartDialysis() {
  1003. record_id, _ := this.GetInt64("id")
  1004. nurseID, _ := this.GetInt64("nurse")
  1005. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  1006. bedID, _ := this.GetInt64("bed")
  1007. start_time := this.GetString("start_time")
  1008. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  1009. schedual_type, _ := this.GetInt64("schedual_type")
  1010. change_nurse, _ := this.GetInt64("change_nurse")
  1011. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  1012. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  1013. if record_id == 0 {
  1014. this.ErrorLog("id:%v", record_id)
  1015. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1016. return
  1017. }
  1018. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04", start_time)
  1019. if parseStartDateErr != nil {
  1020. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  1021. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1022. return
  1023. }
  1024. adminUserInfo := this.GetAdminUserInfo()
  1025. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  1026. if getNurseErr != nil {
  1027. this.ErrorLog("获取护士失败:%v", getNurseErr)
  1028. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1029. return
  1030. } else if nurse == nil {
  1031. this.ErrorLog("护士不存在")
  1032. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1033. return
  1034. }
  1035. //nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  1036. //if getNurseErr != nil {
  1037. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  1038. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1039. // return
  1040. //} else if nurse == nil {
  1041. // this.ErrorLog("护士不存在")
  1042. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1043. // return
  1044. //}
  1045. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.CurrentOrgId, bedID)
  1046. if getDeviceNumberErr != nil {
  1047. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  1048. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1049. return
  1050. } else if deviceNumber == nil {
  1051. this.ErrorLog("床位号不存在")
  1052. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1053. return
  1054. }
  1055. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  1056. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  1057. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1058. // if getPermissionErr != nil {
  1059. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1060. // return
  1061. // } else if headNursePermission == nil {
  1062. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1063. // return
  1064. // }
  1065. //}
  1066. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  1067. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  1068. timeLayout := "2006-01-02 15:04:05"
  1069. loc, _ := time.LoadLocation("Local")
  1070. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  1071. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  1072. schedulestartTime := theStartTime.Unix()
  1073. scheduleendTime := theEndTime.Unix()
  1074. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  1075. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.CurrentOrgId, schedulestartTime, bedID, schedual_type)
  1076. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  1077. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  1078. if err == gorm.ErrRecordNotFound { //空床位
  1079. // 修改了床位逻辑
  1080. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  1081. if daySchedule.ID > 0 {
  1082. daySchedule.BedId = bedID
  1083. daySchedule.PartitionId = deviceNumber.ZoneID
  1084. daySchedule.ScheduleType = schedual_type
  1085. daySchedule.UpdatedTime = time.Now().Unix()
  1086. err := service.UpdateSchedule(&daySchedule)
  1087. if err != nil {
  1088. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1089. return
  1090. }
  1091. }
  1092. } else if err == nil {
  1093. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  1094. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  1095. if daySchedule.ID > 0 {
  1096. daySchedule.BedId = bedID
  1097. daySchedule.PartitionId = deviceNumber.ZoneID
  1098. daySchedule.ScheduleType = schedual_type
  1099. daySchedule.UpdatedTime = time.Now().Unix()
  1100. err := service.UpdateSchedule(&daySchedule)
  1101. if err != nil {
  1102. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1103. return
  1104. }
  1105. }
  1106. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  1107. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  1108. return
  1109. }
  1110. } else if err != nil {
  1111. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1112. return
  1113. }
  1114. }
  1115. dialysisRecord := &models.DialysisOrder{
  1116. ID: record_id,
  1117. UserOrgId: adminUserInfo.CurrentOrgId,
  1118. BedID: bedID,
  1119. StartNurse: nurseID,
  1120. StartTime: startDate.Unix(),
  1121. PunctureNurse: puncture_nurse,
  1122. Creator: adminUserInfo.AdminUser.Id,
  1123. Modifier: adminUserInfo.AdminUser.Id,
  1124. SchedualType: schedual_type,
  1125. WashpipeNurse: washpipe_nurse,
  1126. ChangeNurse: change_nurse,
  1127. DifficultPunctureNurse: difficult_puncture_nurse,
  1128. NewFistulaNurse: new_fistula_nurse,
  1129. }
  1130. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  1131. if updateErr != nil {
  1132. this.ErrorLog("修改上机失败:%v", updateErr)
  1133. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1134. return
  1135. }
  1136. if updateErr == nil {
  1137. if tempDialysisRecord.Stage == 2 {
  1138. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  1139. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  1140. fmt.Println(value)
  1141. a, b := math.Modf(value)
  1142. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  1143. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  1144. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  1145. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  1146. if updateAssessmentErr != nil {
  1147. utils.ErrorLog("%v", updateAssessmentErr)
  1148. }
  1149. after, _ := service.FindAssessmentAfterDislysisById(tempDialysisRecord.UserOrgId, tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  1150. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  1151. this.ServeSuccessJSON(map[string]interface{}{
  1152. "dialysis_order": dialysisRecords,
  1153. "after": after,
  1154. })
  1155. } else {
  1156. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  1157. this.ServeSuccessJSON(map[string]interface{}{
  1158. "dialysis_order": dialysisRecords,
  1159. })
  1160. }
  1161. }
  1162. }
  1163. func (c *DialysisRecordAPIController) ModifyFinishDialysis() {
  1164. record_id, _ := c.GetInt64("id")
  1165. nurseID, _ := c.GetInt64("nurse")
  1166. end_time := c.GetString("end_time")
  1167. if record_id <= 0 || nurseID <= 0 {
  1168. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1169. return
  1170. }
  1171. adminUserInfo := c.GetAdminUserInfo()
  1172. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  1173. if getNurseErr != nil {
  1174. c.ErrorLog("获取护士失败:%v", getNurseErr)
  1175. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1176. return
  1177. } else if nurse == nil {
  1178. c.ErrorLog("护士不存在")
  1179. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1180. return
  1181. }
  1182. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04", end_time)
  1183. if parseEndDateErr != nil {
  1184. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  1185. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1186. return
  1187. }
  1188. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  1189. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  1190. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1191. // if getPermissionErr != nil {
  1192. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1193. // return
  1194. // } else if headNursePermission == nil {
  1195. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1196. // return
  1197. // }
  1198. //}
  1199. dialysisRecord := &models.DialysisOrder{
  1200. ID: record_id,
  1201. UserOrgId: adminUserInfo.CurrentOrgId,
  1202. EndTime: endDate.Unix(),
  1203. FinishNurse: nurseID,
  1204. FinishModifier: adminUserInfo.AdminUser.Id,
  1205. }
  1206. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  1207. if updateErr != nil {
  1208. c.ErrorLog("修改下机失败:%v", updateErr)
  1209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1210. return
  1211. }
  1212. if updateErr == nil {
  1213. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  1214. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  1215. fmt.Println(value)
  1216. a, b := math.Modf(value)
  1217. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  1218. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  1219. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  1220. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  1221. if updateAssessmentErr != nil {
  1222. utils.ErrorLog("%v", updateAssessmentErr)
  1223. }
  1224. }
  1225. after, _ := service.FindAssessmentAfterDislysisById(tempDialysisRecords.UserOrgId, tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate)
  1226. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  1227. c.ServeSuccessJSON(map[string]interface{}{
  1228. "dialysis_order": dialysisRecords,
  1229. "after": after,
  1230. })
  1231. }