dialysis_record_api_controller.go 62KB

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