dialysis_record_api_controller.go 78KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887
  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. patients, _ := service.GetAllPcPatientListByListEight(orgID)
  68. scheduals_json_str, _ := redis.Get(key).Result()
  69. if len(scheduals_json_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  70. scheduals, err := service.GetDialysisSchedualsOne(orgID, date.Unix())
  71. if err != nil {
  72. this.ErrorLog("获取排班信息失败:%v", err)
  73. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  74. } else {
  75. if len(scheduals) > 0 {
  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. _, errcodes := service.GetOrgFollowIsExist(orgID)
  138. if errcodes == gorm.ErrRecordNotFound {
  139. information, _ := service.GetAdminUserRoleInformation(0)
  140. this.ServeSuccessJSON(map[string]interface{}{
  141. "schedules": scheduals,
  142. "information": information,
  143. })
  144. } else if errcodes == nil {
  145. information, _ := service.GetAdminUserRoleInformation(orgID)
  146. this.ServeSuccessJSON(map[string]interface{}{
  147. "schedules": scheduals,
  148. "information": information,
  149. })
  150. }
  151. }
  152. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  153. var dat []map[string]interface{}
  154. if err := json.Unmarshal([]byte(scheduals_json_str), &dat); err == nil {
  155. } else {
  156. }
  157. _, errcodes := service.GetOrgFollowIsExist(orgID)
  158. if errcodes == gorm.ErrRecordNotFound {
  159. information, _ := service.GetAdminUserRoleInformation(0)
  160. this.ServeSuccessJSON(map[string]interface{}{
  161. "schedules": dat,
  162. "information": information,
  163. })
  164. } else if errcodes == nil {
  165. information, _ := service.GetAdminUserRoleInformation(orgID)
  166. this.ServeSuccessJSON(map[string]interface{}{
  167. "schedules": dat,
  168. "information": information,
  169. })
  170. }
  171. }
  172. //if err != nil {
  173. // this.ErrorLog("获取排班信息失败:%v", err)
  174. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  175. //} else {
  176. // this.ServeSuccessJSON(map[string]interface{}{
  177. // "schedules": schedules,
  178. // })
  179. //}
  180. }
  181. // /api/dislysis/schedule [get]
  182. // @param patient_id:int
  183. // @param date:string (yyyy-MM-dd)
  184. func (this *DialysisRecordAPIController) DialysisSchedule() {
  185. patientID, _ := this.GetInt64("patient_id")
  186. recordDateStr := this.GetString("date")
  187. if patientID <= 0 {
  188. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  189. return
  190. }
  191. if len(recordDateStr) == 0 {
  192. recordDateStr = time.Now().Format("2006-01-02")
  193. }
  194. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  195. if parseDateErr != nil {
  196. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  197. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  198. return
  199. }
  200. adminInfo := this.GetAdminUserInfo()
  201. ch := make(chan struct{})
  202. count := 15 // count 表示活动的协程个数
  203. var patient *service.MPatient
  204. var schedual *service.MDialysisScheduleVM
  205. var receiverTreatmentAccess *models.ReceiveTreatmentAsses
  206. var predialysisEvaluation *models.PredialysisEvaluation
  207. var doctorAdvices []*models.DoctorAdvice
  208. var dialysisOrder *models.DialysisOrder
  209. var doubleCheck *models.DoubleCheck
  210. var monitorRecords []*models.MonitoringRecord
  211. var assessmentAfterDislysis *models.AssessmentAfterDislysis
  212. var treatmentSummary *models.TreatmentSummary
  213. var record models.GobalConfig
  214. var is_open_config models.XtHisConfig
  215. var stockType []*models.GoodsTypeOne
  216. var prepare []*models.XtDialysisBeforePrepare
  217. var lastAssessment models.XtPatientVascularAccess
  218. go func() {
  219. patient, _ = service.MobileGetPatientDetail(adminInfo.CurrentOrgId, patientID)
  220. ch <- struct{}{}
  221. }()
  222. go func() {
  223. schedual, _ = service.MobileGetSchedualDetail(adminInfo.CurrentOrgId, patientID, date.Unix())
  224. ch <- struct{}{}
  225. }()
  226. go func() {
  227. receiverTreatmentAccess, _ = service.MobileGetReceiverTreatmentAccessRecord(adminInfo.CurrentOrgId, patientID, date.Unix())
  228. ch <- struct{}{}
  229. }()
  230. go func() {
  231. predialysisEvaluation, _ = service.MobileGetPredialysisEvaluation(adminInfo.CurrentOrgId, patientID, date.Unix())
  232. ch <- struct{}{}
  233. }()
  234. go func() {
  235. doctorAdvices, _ = service.MobileGetDoctorAdvices(adminInfo.CurrentOrgId, patientID, date.Unix())
  236. ch <- struct{}{}
  237. }()
  238. go func() {
  239. dialysisOrder, _ = service.MobileGetSchedualDialysisRecord(adminInfo.CurrentOrgId, patientID, date.Unix())
  240. ch <- struct{}{}
  241. }()
  242. go func() {
  243. doubleCheck, _ = service.MobileGetDoubleCheck(adminInfo.CurrentOrgId, patientID, date.Unix())
  244. ch <- struct{}{}
  245. }()
  246. go func() {
  247. monitorRecords, _ = service.MobileGetMonitorRecords(adminInfo.CurrentOrgId, patientID, date.Unix())
  248. ch <- struct{}{}
  249. }()
  250. go func() {
  251. assessmentAfterDislysis, _ = service.MobileGetAssessmentAfterDislysis(adminInfo.CurrentOrgId, patientID, date.Unix())
  252. ch <- struct{}{}
  253. }()
  254. go func() {
  255. treatmentSummary, _ = service.MobileGetTreatmentSummary(adminInfo.CurrentOrgId, patientID, date.Unix())
  256. ch <- struct{}{}
  257. }()
  258. go func() {
  259. _, record = service.FindAutomaticReduceRecordByOrgId(adminInfo.CurrentOrgId)
  260. ch <- struct{}{}
  261. }()
  262. go func() {
  263. _, is_open_config = service.FindXTHisRecordByOrgId(adminInfo.CurrentOrgId)
  264. ch <- struct{}{}
  265. }()
  266. go func() {
  267. //获取耗材类型
  268. stockType, _ = service.GetStockType(adminInfo.CurrentOrgId)
  269. ch <- struct{}{}
  270. }()
  271. go func() {
  272. prepare, _ = service.GetDialyStockOut(adminInfo.CurrentOrgId, date.Unix(), patientID)
  273. ch <- struct{}{}
  274. }()
  275. go func() {
  276. //获取患者的最后一次血管通路数据
  277. lastAssessment, _ = service.GetLastPassWayAssessment(adminInfo.CurrentOrgId, patientID)
  278. ch <- struct{}{}
  279. }()
  280. for range ch {
  281. // 每次从ch中接收数据,表明一个活动的协程结束
  282. count--
  283. // 当所有活动的协程都结束时,关闭管道
  284. if count == 0 {
  285. close(ch)
  286. }
  287. }
  288. admins, getAdminsErr := service.GetAllAdminUsers(adminInfo.CurrentOrgId, adminInfo.CurrentAppId)
  289. if getAdminsErr != nil {
  290. this.ErrorLog("获取医护列表失败:%v", getAdminsErr)
  291. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  292. return
  293. }
  294. devices, getDevicesErr := service.GetValidDevicesBy(adminInfo.CurrentOrgId, 0, 0)
  295. if getDevicesErr != nil {
  296. this.ErrorLog("获取设备列表失败:%v", getDevicesErr)
  297. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  298. return
  299. }
  300. deviceNumbers, getDeviceNumbersErr := service.GetAllValidDeviceNumbers(adminInfo.CurrentOrgId)
  301. if getDeviceNumbersErr != nil {
  302. this.ErrorLog("获取床位号列表失败:%v", getDeviceNumbersErr)
  303. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  304. return
  305. }
  306. lastPredialysisEvaluation, getLPEErr := service.GetLastTimePredialysisEvaluation(adminInfo.CurrentOrgId, patientID, date.Unix())
  307. if getLPEErr != nil {
  308. this.ErrorLog("获取上一次透前评估失败:%v", getLPEErr)
  309. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  310. return
  311. }
  312. var lastMonitorRecord *models.MonitoringRecord
  313. lastMonitorRecord, getLastErr := service.GetLastMonitorRecord(adminInfo.CurrentOrgId, patientID, date.Unix())
  314. if getLastErr != nil {
  315. this.ErrorLog("获取上一次透析的监测记录失败:%v", getLastErr)
  316. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  317. return
  318. }
  319. lastAssessmentAfterDislysis, getLAADErr := service.GetLastTimeAssessmentAfterDislysis(adminInfo.CurrentOrgId, patientID, date.Unix())
  320. if getLAADErr != nil {
  321. this.ErrorLog("获取上一次透后评估失败:%v", getLAADErr)
  322. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  323. return
  324. }
  325. dialysisPrescribe, _ := service.GetDialysisPrescribe(adminInfo.CurrentOrgId, patientID, date.Unix())
  326. dialysisSolution, _ := service.GetDialysisSolution(adminInfo.CurrentOrgId, patientID, schedual.ModeId)
  327. lastDialysisPrescribe, _ := service.GetLastDialysisPrescribeByModeId(adminInfo.CurrentOrgId, patientID, schedual.ModeId)
  328. systemDialysisPrescribe, _ := service.GetSystemDialysisPrescribeByModeId(adminInfo.CurrentOrgId, schedual.ModeId)
  329. lastDryWeightDislysis, getDryErr := service.GetLastDryWeight(adminInfo.CurrentOrgId, patientID)
  330. lastOrder, _ := service.GetLastDilysisOrder(adminInfo.CurrentOrgId, patientID, date.Unix())
  331. if getDryErr != nil {
  332. this.ErrorLog("获取最后一条干体重失败:%v", getDryErr)
  333. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  334. return
  335. }
  336. headNurses, _ := service.GetAllSpecialPermissionAdminUsersWithoutStatus(adminInfo.CurrentOrgId, adminInfo.CurrentAppId, models.SpecialPermissionTypeHeadNurse)
  337. var his_advices []*models.HisDoctorAdviceInfo
  338. if is_open_config.IsOpen == 1 {
  339. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.CurrentOrgId, patientID, date.Unix())
  340. }
  341. //查询是否是开起
  342. adviceConfig, _ := service.FindAdviceSettingById(adminInfo.CurrentOrgId)
  343. if adviceConfig.IsAdviceOpen == 1 {
  344. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.CurrentOrgId, patientID, date.Unix())
  345. }
  346. _, errcode := service.GetOrgFollowIsExist(adminInfo.CurrentOrgId)
  347. if errcode == gorm.ErrRecordNotFound {
  348. information, _ := service.GetAdminUserRoleInformation(0)
  349. returnData := map[string]interface{}{
  350. "patient": patient,
  351. "schedual": schedual,
  352. "prescription": dialysisPrescribe,
  353. "solution": dialysisSolution,
  354. "receiver_treatment_access": receiverTreatmentAccess,
  355. "predialysis_evaluation": predialysisEvaluation,
  356. "doctor_advices": doctorAdvices,
  357. "double_check": doubleCheck,
  358. "assessment_after_dislysis": assessmentAfterDislysis,
  359. "treatment_summary": treatmentSummary,
  360. "monitor_records": monitorRecords,
  361. "dialysis_order": dialysisOrder,
  362. "doctors": admins,
  363. "config": record,
  364. "devices": devices,
  365. "device_numbers": deviceNumbers,
  366. "lastPredialysisEvaluation": lastPredialysisEvaluation,
  367. "lastMonitorRecord": lastMonitorRecord,
  368. "lastAssessmentAfterDislysis": lastAssessmentAfterDislysis,
  369. "lastDialysisPrescribe": lastDialysisPrescribe,
  370. "lastDryWeightDislysis": lastDryWeightDislysis,
  371. "headNurses": headNurses,
  372. "system_prescribe": systemDialysisPrescribe,
  373. "his_advices": his_advices,
  374. "is_open_config": is_open_config,
  375. "stockType": stockType,
  376. "prepare": prepare,
  377. "lastAssessment": lastAssessment,
  378. "information": information,
  379. "is_advice_open": adviceConfig,
  380. "lastOrder": lastOrder,
  381. }
  382. this.ServeSuccessJSON(returnData)
  383. } else if errcode == nil {
  384. information, _ := service.GetAdminUserRoleInformation(adminInfo.CurrentOrgId)
  385. returnData := map[string]interface{}{
  386. "patient": patient,
  387. "schedual": schedual,
  388. "prescription": dialysisPrescribe,
  389. "solution": dialysisSolution,
  390. "receiver_treatment_access": receiverTreatmentAccess,
  391. "predialysis_evaluation": predialysisEvaluation,
  392. "doctor_advices": doctorAdvices,
  393. "double_check": doubleCheck,
  394. "assessment_after_dislysis": assessmentAfterDislysis,
  395. "treatment_summary": treatmentSummary,
  396. "monitor_records": monitorRecords,
  397. "dialysis_order": dialysisOrder,
  398. "doctors": admins,
  399. "config": record,
  400. "devices": devices,
  401. "device_numbers": deviceNumbers,
  402. "lastPredialysisEvaluation": lastPredialysisEvaluation,
  403. "lastMonitorRecord": lastMonitorRecord,
  404. "lastAssessmentAfterDislysis": lastAssessmentAfterDislysis,
  405. "lastDialysisPrescribe": lastDialysisPrescribe,
  406. "lastDryWeightDislysis": lastDryWeightDislysis,
  407. "headNurses": headNurses,
  408. "system_prescribe": systemDialysisPrescribe,
  409. "his_advices": his_advices,
  410. "is_open_config": is_open_config,
  411. "stockType": stockType,
  412. "prepare": prepare,
  413. "lastAssessment": lastAssessment,
  414. "information": information,
  415. "is_advice_open": adviceConfig,
  416. "lastOrder": lastOrder,
  417. }
  418. this.ServeSuccessJSON(returnData)
  419. }
  420. }
  421. type EditMonitorParamObject struct {
  422. ID int64 `json:"id"`
  423. MonitoringDate int64 `json:"monitoring_date"`
  424. OperateTime int64 `json:"operate_time"`
  425. // MonitoringTime string `json:"monitoring_time"`
  426. SystolicBP float64 `json:"systolic_bp"`
  427. DiastolicBP float64 `json:"diastolic_bp"`
  428. PulseFrequency float64 `json:"pulse_frequency"`
  429. BreathingRated string `json:"breathing_rated"`
  430. BloodFlowVolume float64 `json:"blood_flow_volume"`
  431. VenousPressure float64 `json:"venous_pressure"`
  432. VenousPressureType int64 `json:"venous_pressure_type"`
  433. TransmembranePressure float64 `json:"transmembrane_pressure"`
  434. TransmembranePressureType int64 `json:"transmembrane_pressure_type"`
  435. UltrafiltrationVolume float64 `json:"ultrafiltration_volume"`
  436. UltrafiltrationRate float64 `json:"ultrafiltration_rate"`
  437. ArterialPressure float64 `json:"arterial_pressure"`
  438. ArterialPressureType int64 `json:"arterial_pressure_type"`
  439. SodiumConcentration float64 `json:"sodium_concentration"`
  440. DialysateTemperature float64 `json:"dialysate_temperature"`
  441. Temperature float64 `json:"temperature"`
  442. ReplacementRate float64 `json:"replacement_rate"`
  443. DisplacementQuantity float64 `json:"displacement_quantity"`
  444. KTV float64 `json:"ktv"`
  445. Symptom string `json:"symptom"`
  446. Dispose string `json:"dispose"`
  447. Result string `json:"result"`
  448. Conductivity float64 `json:"conductivity"`
  449. DisplacementFlowQuantity float64 `json:"displacement_flow_quantity"`
  450. BloodOxygenSaturation string `gorm:"column:blood_oxygen_saturation" json:"blood_oxygen_saturation" form:"blood_oxygen_saturation"`
  451. Heparin float64 `gorm:"column:heparin" json:"heparin" form:"heparin"`
  452. DialysateFlow float64 `gorm:"column:dialysate_flow" json:"dialysate_flow" form:"dialysate_flow"`
  453. Urr string `gorm:"column:urr" json:"urr" form:"urr"`
  454. BloodSugar float64 `gorm:"column:blood_sugar" json:"blood_sugar" form:"blood_sugar"`
  455. MonitorAnticoagulant int64 `gorm:"column:monitor_anticoagulant" json:"monitor_anticoagulant" form:"monitor_anticoagulant"`
  456. MonitorAnticoagulantValue string `gorm:"column:monitor_anticoagulant_value" json:"monitor_anticoagulant_value" form:"monitor_anticoagulant_value"`
  457. BloodPressureMonitoringSite int64 `gorm:"column:blood_pressure_monitoring_site" json:"blood_pressure_monitoring_site" form:"blood_pressure_monitoring_site"`
  458. Complication int64 `gorm:"column:complication" json:"complication" form:"complication"`
  459. AccumulatedBloodVolume float64 `gorm:"column:accumulated_blood_volume" json:"accumulated_blood_volume" form:"accumulated_blood_volume"`
  460. BloodTemperature float64 `gorm:"column:blood_temperature" json:"blood_temperature" form:"blood_temperature"`
  461. UreaMonitoring float64 `gorm:"column:urea_monitoring" json:"urea_monitoring" form:"urea_monitoring"`
  462. BloodThickness float64 `gorm:"column:blood_thickness" json:"blood_thickness" form:"blood_thickness"`
  463. BloodMonitor float64 `gorm:"column:blood_monitor" json:"blood_monitor" form:"blood_monitor"`
  464. HeparinAmount float64 `gorm:"column:heparin_amount" json:"heparin_amount" form:"heparin_amount"`
  465. Dehydration float64 `gorm:"column:dehydration" json:"dehydration" form:"dehydration"`
  466. }
  467. // /api/dislysis/monitor/edit [post]
  468. // @param patient_id:int 患者id
  469. // @param schedule_date:int 排班日期
  470. // 下面的参数放到 body
  471. // @param id?:int 监测记录ID(id为0时为创建记录,不为0时为修改记录)
  472. // @param monitoring_date:int 排班日期
  473. // @param operate_time:int 实际测量日期
  474. // @param monitoring_time:string (HH:mm) 监测时间 废弃
  475. // @param systolic_bp?:float 收缩压
  476. // @param diastolic_bp?:float 舒张压
  477. // @param pulse_frequency?:float 心率
  478. // @param breathing_rated?:float 呼吸频率
  479. // @param blood_flow_volume?:float 血流量
  480. // @param venous_pressure?:float 静脉压
  481. // @param transmembrane_pressure?:float 跨膜压
  482. // @param ultrafiltration_volume?:float 超滤量
  483. // @param ultrafiltration_rate?:float 超滤率
  484. // @param arterial_pressure?:float 动脉压
  485. // @param sodium_concentration?:float 钠浓度
  486. // @param dialysate_temperature?:float 透析液温度
  487. // @param replacement_rate?:float 置换率
  488. // @param displacement_quantity?:float 置换量
  489. // @param ktv?:float KT/V
  490. // @param symptom?:string 病情变化
  491. // @param dispose?:string 处理
  492. // @param result?:string 结果
  493. func (this *DialysisRecordAPIController) EditMonitor() {
  494. patientID, _ := this.GetInt64("patient_id")
  495. scheduleDate, _ := this.GetInt64("schedule_date")
  496. if patientID <= 0 || scheduleDate <= 0 {
  497. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  498. return
  499. }
  500. var monitorParam EditMonitorParamObject
  501. if parseErr := json.Unmarshal(this.Ctx.Input.RequestBody, &monitorParam); parseErr != nil {
  502. this.ErrorLog("参数解析失败:%v", parseErr)
  503. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamFormatWrong)
  504. return
  505. }
  506. if monitorParam.MonitoringDate != scheduleDate {
  507. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  508. return
  509. }
  510. adminUserInfo := this.GetAdminUserInfo()
  511. schedule, getScheduleErr := service.MobileGetSchedualDetail(adminUserInfo.CurrentOrgId, patientID, scheduleDate)
  512. if getScheduleErr != nil {
  513. this.ErrorLog("获取排班信息失败:%v", getScheduleErr)
  514. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  515. return
  516. } else if schedule == nil {
  517. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist)
  518. return
  519. }
  520. // TODO 其实这里合理的逻辑是“透析记录存在的情况下才能添加监测记录的”
  521. dialysisOrder, getDialysisOrderErr := service.MobileGetDialysisRecord(adminUserInfo.CurrentOrgId, patientID, scheduleDate)
  522. if getDialysisOrderErr != nil {
  523. this.ErrorLog("获取透析记录失败:%v", getDialysisOrderErr)
  524. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  525. return
  526. }
  527. orderID := int64(0)
  528. if dialysisOrder != nil {
  529. orderID = dialysisOrder.ID
  530. }
  531. if monitorParam.ID <= 0 { // 新建记录
  532. monitor := models.MonitoringRecord{
  533. UserOrgId: adminUserInfo.CurrentOrgId,
  534. PatientId: patientID,
  535. DialysisOrderId: orderID,
  536. MonitoringDate: monitorParam.MonitoringDate,
  537. OperateTime: monitorParam.OperateTime,
  538. // MonitoringTime: monitorParam.MonitoringTime,
  539. PulseFrequency: monitorParam.PulseFrequency,
  540. BreathingRate: monitorParam.BreathingRated,
  541. SystolicBloodPressure: monitorParam.SystolicBP,
  542. DiastolicBloodPressure: monitorParam.DiastolicBP,
  543. BloodFlowVolume: monitorParam.BloodFlowVolume,
  544. VenousPressure: monitorParam.VenousPressure,
  545. VenousPressureType: monitorParam.VenousPressureType,
  546. ArterialPressure: monitorParam.ArterialPressure,
  547. ArterialPressureType: monitorParam.ArterialPressureType,
  548. TransmembranePressure: monitorParam.TransmembranePressure,
  549. TransmembranePressureType: monitorParam.TransmembranePressureType,
  550. UltrafiltrationRate: monitorParam.UltrafiltrationRate,
  551. UltrafiltrationVolume: monitorParam.UltrafiltrationVolume,
  552. SodiumConcentration: monitorParam.SodiumConcentration,
  553. DialysateTemperature: monitorParam.DialysateTemperature,
  554. Temperature: monitorParam.Temperature,
  555. ReplacementRate: monitorParam.ReplacementRate,
  556. DisplacementQuantity: monitorParam.DisplacementQuantity,
  557. Ktv: monitorParam.KTV,
  558. Symptom: monitorParam.Symptom,
  559. Dispose: monitorParam.Dispose,
  560. Result: monitorParam.Result,
  561. MonitoringNurse: adminUserInfo.AdminUser.Id,
  562. Conductivity: monitorParam.Conductivity,
  563. DisplacementFlowQuantity: monitorParam.DisplacementFlowQuantity,
  564. Status: 1,
  565. CreatedTime: time.Now().Unix(),
  566. UpdatedTime: time.Now().Unix(),
  567. BloodOxygenSaturation: monitorParam.BloodOxygenSaturation,
  568. Creator: adminUserInfo.AdminUser.Id,
  569. Heparin: monitorParam.Heparin,
  570. DialysateFlow: monitorParam.DialysateFlow,
  571. Urr: monitorParam.Urr,
  572. BloodSugar: monitorParam.BloodSugar,
  573. MonitorAnticoagulant: monitorParam.MonitorAnticoagulant,
  574. MonitorAnticoagulantValue: monitorParam.MonitorAnticoagulantValue,
  575. BloodPressureMonitoringSite: monitorParam.BloodPressureMonitoringSite,
  576. Complication: monitorParam.Complication,
  577. AccumulatedBloodVolume: monitorParam.AccumulatedBloodVolume,
  578. BloodTemperature: monitorParam.BloodTemperature,
  579. UreaMonitoring: monitorParam.UreaMonitoring,
  580. BloodThickness: monitorParam.BloodThickness,
  581. BloodMonitor: monitorParam.BloodMonitor,
  582. HeparinAmount: monitorParam.HeparinAmount,
  583. Dehydration: monitorParam.Dehydration,
  584. }
  585. createErr := service.CreateMonitor(&monitor)
  586. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":monitor_records"
  587. redis := service.RedisClient()
  588. //清空key 值
  589. redis.Set(key, "", time.Second)
  590. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(monitorParam.MonitoringDate, 10) + ":monitor_record_list_all"
  591. redis.Set(keyOne, "", time.Second)
  592. defer redis.Close()
  593. if createErr != nil {
  594. this.ErrorLog("创建监测记录失败:%v", createErr)
  595. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  596. return
  597. }
  598. this.ServeSuccessJSON(map[string]interface{}{
  599. "monitor": monitor,
  600. })
  601. } else { // 修改记录
  602. monitor, getMonitorErr := service.GetMonitor(adminUserInfo.CurrentOrgId, patientID, monitorParam.ID)
  603. if getMonitorErr != nil {
  604. this.ErrorLog("获取透析监测记录失败:%v", getMonitorErr)
  605. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  606. return
  607. } else if monitor == nil {
  608. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorNotExist)
  609. return
  610. }
  611. //if monitor.MonitoringNurse != adminUserInfo.AdminUser.Id {
  612. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  613. // if getPermissionErr != nil {
  614. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  615. // return
  616. // } else if headNursePermission == nil {
  617. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  618. // return
  619. // }
  620. //}
  621. monitor.OperateTime = monitorParam.OperateTime
  622. monitor.PulseFrequency = monitorParam.PulseFrequency
  623. monitor.BreathingRate = monitorParam.BreathingRated
  624. monitor.SystolicBloodPressure = monitorParam.SystolicBP
  625. monitor.DiastolicBloodPressure = monitorParam.DiastolicBP
  626. monitor.BloodFlowVolume = monitorParam.BloodFlowVolume
  627. monitor.VenousPressure = monitorParam.VenousPressure
  628. monitor.VenousPressureType = monitorParam.VenousPressureType
  629. monitor.ArterialPressure = monitorParam.ArterialPressure
  630. monitor.ArterialPressureType = monitorParam.ArterialPressureType
  631. monitor.TransmembranePressure = monitorParam.TransmembranePressure
  632. monitor.TransmembranePressureType = monitorParam.TransmembranePressureType
  633. monitor.UltrafiltrationRate = monitorParam.UltrafiltrationRate
  634. monitor.UltrafiltrationVolume = monitorParam.UltrafiltrationVolume
  635. monitor.SodiumConcentration = monitorParam.SodiumConcentration
  636. monitor.DialysateTemperature = monitorParam.DialysateTemperature
  637. monitor.Temperature = monitorParam.Temperature
  638. monitor.ReplacementRate = monitorParam.ReplacementRate
  639. monitor.DisplacementQuantity = monitorParam.DisplacementQuantity
  640. monitor.Conductivity = monitorParam.Conductivity
  641. monitor.DisplacementFlowQuantity = monitorParam.DisplacementFlowQuantity
  642. monitor.Ktv = monitorParam.KTV
  643. monitor.Symptom = monitorParam.Symptom
  644. monitor.Dispose = monitorParam.Dispose
  645. monitor.Result = monitorParam.Result
  646. monitor.MonitoringNurse = adminUserInfo.AdminUser.Id
  647. monitor.UpdatedTime = time.Now().Unix()
  648. monitor.Modify = adminUserInfo.AdminUser.Id
  649. monitor.BloodOxygenSaturation = monitorParam.BloodOxygenSaturation
  650. monitor.Heparin = monitorParam.Heparin
  651. monitor.DialysateFlow = monitorParam.DialysateFlow
  652. monitor.Urr = monitorParam.Urr
  653. monitor.BloodSugar = monitorParam.BloodSugar
  654. monitor.MonitorAnticoagulant = monitorParam.MonitorAnticoagulant
  655. monitor.MonitorAnticoagulantValue = monitorParam.MonitorAnticoagulantValue
  656. monitor.AccumulatedBloodVolume = monitorParam.AccumulatedBloodVolume
  657. monitor.BloodTemperature = monitorParam.BloodTemperature
  658. monitor.UreaMonitoring = monitorParam.UreaMonitoring
  659. monitor.BloodThickness = monitorParam.BloodThickness
  660. monitor.BloodMonitor = monitorParam.BloodMonitor
  661. monitor.HeparinAmount = monitorParam.HeparinAmount
  662. monitor.Dehydration = monitorParam.Dehydration
  663. updateErr := service.UpdateMonitor(monitor)
  664. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":monitor_records"
  665. redis := service.RedisClient()
  666. defer redis.Close()
  667. //清空key 值
  668. redis.Set(key, "", time.Second)
  669. if updateErr != nil {
  670. this.ErrorLog("修改透析监测记录失败:%v", updateErr)
  671. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  672. return
  673. }
  674. this.ServeSuccessJSON(map[string]interface{}{
  675. "monitor": monitor,
  676. })
  677. }
  678. }
  679. // /api/dialysis/start_record [post]
  680. // @param patient_id:int
  681. // @param date:string 排班时间 (yyyy-mm-dd)
  682. // @param nurse:int 上机护士
  683. // @param bed:int 上机床位号
  684. func (this *DialysisRecordAPIController) StartDialysis() {
  685. patientID, _ := this.GetInt64("patient_id")
  686. recordDateStr := this.GetString("date")
  687. nurseID, _ := this.GetInt64("nurse")
  688. punctureNurseId, _ := this.GetInt64("puncture_nurse")
  689. startDateStr := this.GetString("start_time")
  690. blood_drawing, _ := this.GetInt64("blood_drawing")
  691. schedual_type, _ := this.GetInt64("schedual_type")
  692. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  693. change_nurse, _ := this.GetInt64("change_nurse")
  694. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  695. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  696. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  697. puncture_needle := this.GetString("puncture_needle")
  698. puncture_way := this.GetString("puncture_way")
  699. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  700. dialysis_irrigation := this.GetString("dialysis_irrigation")
  701. blood_access_id, _ := this.GetInt64("blood_access_id")
  702. bedID, _ := this.GetInt64("bed")
  703. nuclein_date := this.GetString("nuclein_date")
  704. schedule_remark := this.GetString("schedule_remark")
  705. order_remark := this.GetString("order_remark")
  706. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  707. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  708. return
  709. }
  710. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  711. if parseErr != nil {
  712. this.ErrorLog("时间解析失败:%v", parseErr)
  713. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  714. return
  715. }
  716. startDate, parseErr := utils.ParseTimeStringToTime("2006-01-02 15:04", startDateStr)
  717. if parseErr != nil {
  718. this.ErrorLog("时间解析失败:%v", parseErr)
  719. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  720. return
  721. }
  722. adminUserInfo := this.GetAdminUserInfo()
  723. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.CurrentOrgId, patientID)
  724. if getPatientErr != nil {
  725. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  726. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  727. return
  728. } else if patient == nil {
  729. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  730. return
  731. }
  732. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  733. if getNurseErr != nil {
  734. this.ErrorLog("获取护士失败:%v", getNurseErr)
  735. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  736. return
  737. } else if nurse == nil {
  738. this.ErrorLog("护士不存在")
  739. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  740. return
  741. }
  742. //nurse, getNurseErr = service.GetAdminUserByUserID(punctureNurseId)
  743. //
  744. //if getNurseErr != nil {
  745. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  746. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  747. // return
  748. //} else if nurse == nil {
  749. // this.ErrorLog("护士不存在")
  750. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  751. // return
  752. //}
  753. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.CurrentOrgId, bedID)
  754. if getDeviceNumberErr != nil {
  755. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  756. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  757. return
  758. } else if deviceNumber == nil {
  759. this.ErrorLog("床位号不存在")
  760. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  761. return
  762. }
  763. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  764. if getRecordErr != nil {
  765. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  766. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  767. return
  768. } else if dialysisRecord != nil {
  769. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  770. return
  771. }
  772. template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  773. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  774. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  775. timeLayout := "2006-01-02 15:04:05"
  776. loc, _ := time.LoadLocation("Local")
  777. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  778. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  779. schedulestartTime := theStartTime.Unix()
  780. scheduleendTime := theEndTime.Unix()
  781. var theNucleinDate int64
  782. timeLayoutOne := "2006-01-02"
  783. if len(nuclein_date) > 0 {
  784. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date+" 00:00:00", loc)
  785. if err != nil {
  786. utils.ErrorLog(err.Error())
  787. }
  788. theNucleinDate = theTime.Unix()
  789. }
  790. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  791. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.CurrentOrgId, schedulestartTime, bedID, schedual_type)
  792. //查询该床位是否有人用了
  793. order, order_err := service.GetDialysisOrderByBedId(adminUserInfo.CurrentOrgId, schedulestartTime, bedID, schedual_type)
  794. if err == gorm.ErrRecordNotFound { //空床位
  795. // 修改了床位逻辑
  796. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, patientID)
  797. if daySchedule.ID > 0 {
  798. //daySchedule.PartitionId = deviceNumber.ZoneID
  799. //daySchedule.BedId = bedID
  800. //daySchedule.ScheduleType = schedual_type
  801. //daySchedule.UpdatedTime = time.Now().Unix()
  802. //err := service.UpdateSchedule(&daySchedule)
  803. xtSchedule := models.Schedule{
  804. PartitionId: deviceNumber.ZoneID,
  805. BedId: bedID,
  806. ScheduleType: schedual_type,
  807. UpdatedTime: time.Now().Unix(),
  808. }
  809. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  810. if err != nil {
  811. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  812. return
  813. }
  814. }
  815. } else if err == nil {
  816. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  817. if order_err == nil {
  818. if order.ID > 0 { //该机位被其他人占用了
  819. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  820. return
  821. } else {
  822. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, patientID)
  823. if daySchedule.ID > 0 {
  824. //daySchedule.PartitionId = deviceNumber.ZoneID
  825. //daySchedule.BedId = bedID
  826. //daySchedule.ScheduleType = schedual_type
  827. //daySchedule.UpdatedTime = time.Now().Unix()
  828. //err := service.UpdateSchedule(&daySchedule)
  829. xtSchedule := models.Schedule{
  830. PartitionId: deviceNumber.ZoneID,
  831. BedId: bedID,
  832. ScheduleType: schedual_type,
  833. UpdatedTime: time.Now().Unix(),
  834. }
  835. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  836. if err != nil {
  837. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  838. return
  839. }
  840. }
  841. }
  842. } else if order_err == gorm.ErrRecordNotFound { //该床位没被占用
  843. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, patientID)
  844. if daySchedule.ID > 0 {
  845. //daySchedule.PartitionId = deviceNumber.ZoneID
  846. //daySchedule.BedId = bedID
  847. //daySchedule.ScheduleType = schedual_type
  848. //daySchedule.UpdatedTime = time.Now().Unix()
  849. //err := service.UpdateSchedule(&daySchedule)
  850. xtSchedule := models.Schedule{
  851. PartitionId: deviceNumber.ZoneID,
  852. BedId: bedID,
  853. ScheduleType: schedual_type,
  854. UpdatedTime: time.Now().Unix(),
  855. }
  856. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  857. if err != nil {
  858. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  859. return
  860. }
  861. }
  862. } else if order_err != nil {
  863. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  864. return
  865. }
  866. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  867. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  868. return
  869. }
  870. } else if err != nil {
  871. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  872. return
  873. }
  874. dialysisRecord = &models.DialysisOrder{
  875. DialysisDate: recordDate.Unix(),
  876. UserOrgId: adminUserInfo.CurrentOrgId,
  877. PatientId: patientID,
  878. Stage: 1,
  879. BedID: bedID,
  880. StartNurse: nurseID,
  881. Status: 1,
  882. StartTime: startDate.Unix(),
  883. CreatedTime: time.Now().Unix(),
  884. UpdatedTime: time.Now().Unix(),
  885. PunctureNurse: punctureNurseId,
  886. Creator: adminUserInfo.AdminUser.Id,
  887. Modifier: adminUserInfo.AdminUser.Id,
  888. SchedualType: schedual_type,
  889. WashpipeNurse: washpipe_nurse,
  890. ChangeNurse: change_nurse,
  891. DifficultPunctureNurse: difficult_puncture_nurse,
  892. NewFistulaNurse: new_fistula_nurse,
  893. QualityNurseId: quality_nurse_id,
  894. PunctureNeedle: puncture_needle,
  895. PunctureWay: puncture_way,
  896. DialysisDialyszers: dialysis_dialyszers,
  897. DialysisIrrigation: dialysis_irrigation,
  898. BloodAccessId: blood_access_id,
  899. NucleinDate: theNucleinDate,
  900. ScheduleRemark: schedule_remark,
  901. OrderRemark: order_remark,
  902. }
  903. createErr := service.MobileCreateDialysisOrder(adminUserInfo.CurrentOrgId, patientID, dialysisRecord)
  904. //更新患者表排班备注
  905. service.UpdateMobilePatient(adminUserInfo.CurrentOrgId, patientID, schedule_remark)
  906. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  907. redis := service.RedisClient()
  908. //清空key 值
  909. redis.Set(key, "", time.Second)
  910. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  911. redis.Set(keyOne, "", time.Second)
  912. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  913. //清空key 值
  914. redis.Set(keyTwo, "", time.Second)
  915. defer redis.Close()
  916. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  917. if createErr != nil {
  918. this.ErrorLog("上机失败:%v", createErr)
  919. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  920. return
  921. } else if createErr == nil {
  922. var tempdispose string
  923. // 只针对中能建
  924. if blood_drawing > 0 && adminUserInfo.CurrentOrgId == 9538 { //adminUserInfo.CurrentOrgId == 9538
  925. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  926. }
  927. if blood_drawing > 0 && adminUserInfo.CurrentOrgId == 10318 { //adminUserInfo.CurrentOrgId == 9538
  928. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  929. }
  930. var ultrafiltration_rate float64
  931. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.CurrentOrgId)
  932. //获取预增水量
  933. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, schedulestartTime, adminUserInfo.CurrentOrgId)
  934. if prescription.ID > 0 {
  935. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  936. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  937. //fmt.Println("total23232323232322332", totalMin)
  938. if (template.TemplateId == 6 || template.TemplateId == 20 || template.TemplateId == 22 || template.TemplateId == 32 || template.TemplateId == 36) && adminUserInfo.CurrentOrgId != 9671 {
  939. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  940. }
  941. //针对福建医师汇
  942. if template.TemplateId == 6 && adminUserInfo.CurrentOrgId == 10121 {
  943. if evaluation.ID > 0 {
  944. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  945. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  946. }
  947. }
  948. if template.TemplateId == 6 && adminUserInfo.CurrentOrgId == 10234 {
  949. if evaluation.ID > 0 {
  950. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  951. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  952. }
  953. }
  954. // 只针对方济医院
  955. if template.TemplateId == 1 && adminUserInfo.CurrentOrgId != 9849 {
  956. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  957. ultrafiltration_rate = value
  958. }
  959. //针对监利大垸医院
  960. if adminUserInfo.CurrentOrgId == 10101 {
  961. if evaluation.ID > 0 {
  962. ultrafiltration_rate = math.Ceil(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  963. }
  964. }
  965. //针对肇庆三鹤血液透析中心
  966. if adminUserInfo.CurrentOrgId == 10215 || template.TemplateId == 43 || adminUserInfo.CurrentOrgId == 10441 || adminUserInfo.CurrentOrgId == 10445 {
  967. if evaluation.ID > 0 {
  968. ultrafiltration_rate = math.Ceil(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  969. }
  970. }
  971. }
  972. }
  973. record := models.MonitoringRecord{
  974. UserOrgId: adminUserInfo.CurrentOrgId,
  975. PatientId: patientID,
  976. DialysisOrderId: dialysisRecord.ID,
  977. MonitoringDate: schedulestartTime,
  978. OperateTime: startDate.Unix(),
  979. // MonitoringTime: recordTime,
  980. MonitoringNurse: nurseID,
  981. Dispose: tempdispose,
  982. UltrafiltrationRate: ultrafiltration_rate,
  983. UltrafiltrationVolume: 0,
  984. Status: 1,
  985. CreatedTime: time.Now().Unix(),
  986. UpdatedTime: time.Now().Unix(),
  987. }
  988. //只针对广慈医院
  989. if template.TemplateId == 26 || template.TemplateId == 25 || template.TemplateId == 28 || adminUserInfo.CurrentOrgId == 9987 || adminUserInfo.CurrentOrgId == 9526 || template.TemplateId == 32 || adminUserInfo.CurrentOrgId == 9918 || adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 4 {
  990. // 查询病人是否有透前评估数据
  991. befor, errcode := service.GetAssessmentBefor(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  992. //如果有数据就插入
  993. if errcode == nil {
  994. record.SystolicBloodPressure = befor.SystolicBloodPressure
  995. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  996. record.BreathingRate = befor.BreathingRate
  997. record.PulseFrequency = befor.PulseFrequency
  998. record.Temperature = befor.Temperature
  999. }
  1000. }
  1001. // 如果当天有插入数据,则不再往透析纪录里插入数据
  1002. if newdialysisRecord.ID > 0 {
  1003. //针对长沙南雅医院
  1004. if adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 9675 || adminUserInfo.CurrentOrgId == 10340 {
  1005. record.Temperature = 36.5
  1006. record.ArterialPressure = -100
  1007. record.Conductivity = 14
  1008. record.BreathingRate = "20"
  1009. record.DialysateTemperature = 36.5
  1010. record.VenousPressure = 80
  1011. record.TransmembranePressure = 60
  1012. }
  1013. //针对兰溪人民医院的需求
  1014. if adminUserInfo.CurrentOrgId == 10432 {
  1015. befor, _ := service.GetAssessmentBefor(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1016. record.SystolicBloodPressure = befor.SystolicBloodPressure
  1017. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  1018. record.Temperature = befor.Temperature
  1019. record.PulseFrequency = befor.PulseFrequency
  1020. }
  1021. err := service.CreateMonitor(&record)
  1022. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_records"
  1023. redis := service.RedisClient()
  1024. //清空key 值
  1025. redis.Set(key, "", time.Second)
  1026. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_record_list_all"
  1027. redis.Set(keyOne, "", time.Second)
  1028. defer redis.Close()
  1029. if err != nil {
  1030. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  1031. return
  1032. }
  1033. }
  1034. go func() {
  1035. ssoDomain := beego.AppConfig.String("call_domain")
  1036. api := ssoDomain + "/index/uppatient"
  1037. values := make(url.Values)
  1038. values.Set("org_id", strconv.FormatInt(adminUserInfo.CurrentOrgId, 10))
  1039. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  1040. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  1041. values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
  1042. http.PostForm(api, values)
  1043. }()
  1044. this.ServeSuccessJSON(map[string]interface{}{
  1045. "dialysis_order": dialysisRecord,
  1046. "monitor": record,
  1047. })
  1048. }
  1049. }
  1050. // /api/dialysis/finish [post]
  1051. // @param patient_id:int
  1052. // @param date:string 排班时间 (yyyy-mm-dd)
  1053. // @param nurse:int 下机护士
  1054. func (this *DialysisRecordAPIController) FinishDialysis() {
  1055. patientID, _ := this.GetInt64("patient_id")
  1056. recordDateStr := this.GetString("date")
  1057. nurseID, _ := this.GetInt64("nurse")
  1058. end_time := this.GetString("end_time")
  1059. puncture_point_haematoma, _ := this.GetInt64("puncture_point_haematoma")
  1060. internal_fistula := this.GetString("internal_fistula")
  1061. catheter := this.GetString("catheter")
  1062. cruor := this.GetString("cruor")
  1063. mission := this.GetString("mission")
  1064. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 {
  1065. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1066. return
  1067. }
  1068. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1069. if parseErr != nil {
  1070. this.ErrorLog("时间解析失败:%v", parseErr)
  1071. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1072. return
  1073. }
  1074. //if parseEndDateErr != nil {
  1075. // this.ErrorLog("时间解析失败:%v", parseEndDateErr)
  1076. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1077. // return
  1078. //}
  1079. adminUserInfo := this.GetAdminUserInfo()
  1080. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.CurrentOrgId, patientID)
  1081. if getPatientErr != nil {
  1082. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  1083. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1084. return
  1085. } else if patient == nil {
  1086. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1087. return
  1088. }
  1089. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  1090. if getNurseErr != nil {
  1091. this.ErrorLog("获取护士失败:%v", getNurseErr)
  1092. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1093. return
  1094. } else if nurse == nil {
  1095. this.ErrorLog("护士不存在")
  1096. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1097. return
  1098. }
  1099. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1100. if getRecordErr != nil {
  1101. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  1102. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1103. return
  1104. }
  1105. if dialysisRecord.Stage == 2 {
  1106. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  1107. return
  1108. }
  1109. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04", end_time)
  1110. if parseEndDateErr != nil {
  1111. this.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  1112. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1113. return
  1114. }
  1115. // 获取当天的第一条透析纪录
  1116. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1117. if getMonitorRecordsErr != nil {
  1118. this.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  1119. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1120. return
  1121. }
  1122. // 获取当前的最后一条透析纪录
  1123. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecord(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1124. if getMonitorRecordsErr != nil {
  1125. this.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  1126. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1127. return
  1128. }
  1129. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysis(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1130. if getAADErr != nil {
  1131. this.ErrorLog("获取透后评估失败:%v", getAADErr)
  1132. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1133. return
  1134. }
  1135. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysis(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1136. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  1137. if assessmentAfterDislysis != nil {
  1138. tempassessmentAfterDislysis = *assessmentAfterDislysis
  1139. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  1140. } else {
  1141. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  1142. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  1143. tempassessmentAfterDislysis.Status = 1
  1144. tempassessmentAfterDislysis.PatientId = patientID
  1145. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.CurrentOrgId
  1146. }
  1147. if dialysisRecord.Stage == 1 {
  1148. temp_time := (float64(endDate.Unix()) - float64(dialysisRecord.StartTime)) / 3600
  1149. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  1150. fmt.Println(value)
  1151. a, b := math.Modf(value)
  1152. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  1153. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  1154. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  1155. fmt.Println(hour)
  1156. fmt.Println(minute)
  1157. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  1158. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  1159. }
  1160. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  1161. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  1162. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  1163. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  1164. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  1165. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  1166. //长沙南雅
  1167. if adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 9675 || adminUserInfo.CurrentOrgId == 10340 {
  1168. //获取最后一条透析处方数据
  1169. prescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1170. evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1171. tempassessmentAfterDislysis.WeightAfter = evaluation.WeightBefore - prescription.TargetUltrafiltration/1000
  1172. }
  1173. if adminUserInfo.CurrentOrgId == 10101 {
  1174. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  1175. } else {
  1176. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  1177. }
  1178. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  1179. }
  1180. if adminUserInfo.CurrentOrgId == 9583 {
  1181. //获取最后一条透析处方数据
  1182. prescription, parseErr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1183. if parseErr != nil {
  1184. this.ErrorLog("获取透析处方失败:%v", getMonitorRecordsErr)
  1185. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1186. return
  1187. }
  1188. if prescription.ID > 0 && adminUserInfo.CurrentOrgId == 9583 {
  1189. tempassessmentAfterDislysis.ActualUltrafiltration = prescription.TargetUltrafiltration
  1190. }
  1191. if endmonitorRecords.ID > 0 && adminUserInfo.CurrentOrgId == 10060 {
  1192. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  1193. }
  1194. }
  1195. if lastAssessmentAfterDislysis != nil {
  1196. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  1197. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  1198. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  1199. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  1200. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  1201. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  1202. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  1203. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  1204. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  1205. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  1206. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  1207. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  1208. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  1209. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  1210. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  1211. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  1212. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  1213. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  1214. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  1215. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  1216. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  1217. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  1218. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  1219. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  1220. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  1221. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  1222. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  1223. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  1224. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  1225. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  1226. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  1227. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  1228. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  1229. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  1230. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  1231. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  1232. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  1233. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  1234. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  1235. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  1236. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  1237. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  1238. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  1239. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  1240. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  1241. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  1242. }
  1243. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  1244. if adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 9675 || adminUserInfo.CurrentOrgId == 10164 || adminUserInfo.CurrentOrgId == 10340 || adminUserInfo.CurrentOrgId == 10414 || adminUserInfo.CurrentOrgId == 10432 || adminUserInfo.CurrentOrgId == 10445 {
  1245. evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1246. if evaluation.SystolicBloodPressure == 0 {
  1247. pre := models.PredialysisEvaluation{
  1248. SystolicBloodPressure: fmonitorRecords.SystolicBloodPressure,
  1249. }
  1250. fmt.Println("prew", pre)
  1251. getNurseErr := service.UpdatePredialysisEvaluation(&pre, evaluation.ID)
  1252. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  1253. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  1254. redis := service.RedisClient()
  1255. redis.Set(key, "", time.Second)
  1256. redis.Set(keyOne, "", time.Second)
  1257. defer redis.Close()
  1258. fmt.Println(getNurseErr)
  1259. }
  1260. if evaluation.DiastolicBloodPressure == 0 {
  1261. pres := models.PredialysisEvaluation{
  1262. DiastolicBloodPressure: fmonitorRecords.DiastolicBloodPressure,
  1263. }
  1264. getNurseErr := service.UpdatePredialysisEvaluationTwo(&pres, evaluation.ID)
  1265. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  1266. redis := service.RedisClient()
  1267. redis.Set(key, "", time.Second)
  1268. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  1269. redis.Set(keyOne, "", time.Second)
  1270. defer redis.Close()
  1271. fmt.Println(getNurseErr)
  1272. }
  1273. if evaluation.PulseFrequency == 0 {
  1274. evaluation.PulseFrequency = fmonitorRecords.PulseFrequency
  1275. press := models.PredialysisEvaluation{
  1276. PulseFrequency: evaluation.PulseFrequency,
  1277. }
  1278. getNurseErr := service.UpdatePredialysisEvaluationThree(&press, evaluation.ID)
  1279. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  1280. redis := service.RedisClient()
  1281. redis.Set(key, "", time.Second)
  1282. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  1283. redis.Set(keyOne, "", time.Second)
  1284. defer redis.Close()
  1285. fmt.Println(getNurseErr)
  1286. }
  1287. if evaluation.Temperature == 0 {
  1288. evaluation.Temperature = fmonitorRecords.Temperature
  1289. press := models.PredialysisEvaluation{
  1290. Temperature: evaluation.Temperature,
  1291. }
  1292. getNurseErr := service.UpdatePredialysisEvaluationFour(&press, evaluation.ID)
  1293. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  1294. redis := service.RedisClient()
  1295. redis.Set(key, "", time.Second)
  1296. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  1297. redis.Set(keyOne, "", time.Second)
  1298. defer redis.Close()
  1299. fmt.Println(getNurseErr)
  1300. }
  1301. }
  1302. if err != nil {
  1303. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1304. return
  1305. }
  1306. go func() {
  1307. ssoDomain := beego.AppConfig.String("call_domain")
  1308. api := ssoDomain + "/index/downpatient"
  1309. values := make(url.Values)
  1310. values.Set("org_id", strconv.FormatInt(adminUserInfo.CurrentOrgId, 10))
  1311. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  1312. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  1313. http.PostForm(api, values)
  1314. }()
  1315. //执行下机
  1316. updateErr := service.ModifyDialysisRecord(dialysisRecord.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id, puncture_point_haematoma, internal_fistula, catheter, cruor, mission)
  1317. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  1318. redis := service.RedisClient()
  1319. defer redis.Close()
  1320. //清空key 值
  1321. redis.Set(key, "", time.Second)
  1322. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  1323. redis.Set(keyOne, "", time.Second)
  1324. if updateErr != nil {
  1325. this.ErrorLog("下机失败:%v", updateErr)
  1326. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1327. return
  1328. } else {
  1329. dialysisRecord.Stage = 2
  1330. dialysisRecord.FinishNurse = nurseID
  1331. dialysisRecord.FinishCreator = adminUserInfo.AdminUser.Id
  1332. dialysisRecord.FinishModifier = adminUserInfo.AdminUser.Id
  1333. dialysisRecord.EndTime = endDate.Unix()
  1334. // 结束时候透析次数加1
  1335. service.UpdateSolutionByPatientId(patientID)
  1336. this.ServeSuccessJSON(map[string]interface{}{
  1337. "dialysis_order": dialysisRecord,
  1338. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  1339. })
  1340. }
  1341. }
  1342. func (this *DialysisRecordAPIController) ModifyStartDialysis() {
  1343. record_id, _ := this.GetInt64("id")
  1344. nurseID, _ := this.GetInt64("nurse")
  1345. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  1346. bedID, _ := this.GetInt64("bed")
  1347. start_time := this.GetString("start_time")
  1348. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  1349. schedual_type, _ := this.GetInt64("schedual_type")
  1350. change_nurse, _ := this.GetInt64("change_nurse")
  1351. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  1352. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  1353. quality_nurse, _ := this.GetInt64("quality_nurse")
  1354. puncture_needle := this.GetString("puncture_needle")
  1355. puncture_way := this.GetString("puncture_way")
  1356. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  1357. dialysis_irrigation := this.GetString("dialysis_irrigation")
  1358. blood_access_id, _ := this.GetInt64("blood_access_id")
  1359. nuclein_date := this.GetString("nuclein_date")
  1360. schedule_remark := this.GetString("schedule_remark")
  1361. order_remark := this.GetString("order_remark")
  1362. if record_id == 0 {
  1363. this.ErrorLog("id:%v", record_id)
  1364. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1365. return
  1366. }
  1367. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04", start_time)
  1368. if parseStartDateErr != nil {
  1369. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  1370. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1371. return
  1372. }
  1373. adminUserInfo := this.GetAdminUserInfo()
  1374. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  1375. if getNurseErr != nil {
  1376. this.ErrorLog("获取护士失败:%v", getNurseErr)
  1377. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1378. return
  1379. } else if nurse == nil {
  1380. this.ErrorLog("护士不存在")
  1381. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1382. return
  1383. }
  1384. //nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  1385. //if getNurseErr != nil {
  1386. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  1387. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1388. // return
  1389. //} else if nurse == nil {
  1390. // this.ErrorLog("护士不存在")
  1391. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1392. // return
  1393. //}
  1394. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.CurrentOrgId, bedID)
  1395. if getDeviceNumberErr != nil {
  1396. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  1397. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1398. return
  1399. } else if deviceNumber == nil {
  1400. this.ErrorLog("床位号不存在")
  1401. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1402. return
  1403. }
  1404. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  1405. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  1406. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1407. // if getPermissionErr != nil {
  1408. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1409. // return
  1410. // } else if headNursePermission == nil {
  1411. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1412. // return
  1413. // }
  1414. //}
  1415. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  1416. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  1417. timeLayout := "2006-01-02 15:04:05"
  1418. loc, _ := time.LoadLocation("Local")
  1419. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  1420. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  1421. schedulestartTime := theStartTime.Unix()
  1422. scheduleendTime := theEndTime.Unix()
  1423. var theNucleinDate int64
  1424. timeLayoutOne := "2006-01-02"
  1425. if len(nuclein_date) > 0 {
  1426. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date+" 00:00:00", loc)
  1427. if err != nil {
  1428. utils.ErrorLog(err.Error())
  1429. }
  1430. theNucleinDate = theTime.Unix()
  1431. }
  1432. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  1433. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.CurrentOrgId, schedulestartTime, bedID, schedual_type)
  1434. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  1435. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  1436. if err == gorm.ErrRecordNotFound { //空床位
  1437. // 修改了床位逻辑
  1438. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  1439. if daySchedule.ID > 0 {
  1440. //daySchedule.BedId = bedID
  1441. //daySchedule.PartitionId = deviceNumber.ZoneID
  1442. //daySchedule.ScheduleType = schedual_type
  1443. //daySchedule.UpdatedTime = time.Now().Unix()
  1444. //err := service.UpdateSchedule(&daySchedule)
  1445. xtSchedule := models.Schedule{
  1446. PartitionId: deviceNumber.ZoneID,
  1447. BedId: bedID,
  1448. ScheduleType: schedual_type,
  1449. UpdatedTime: time.Now().Unix(),
  1450. }
  1451. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  1452. if err != nil {
  1453. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1454. return
  1455. }
  1456. }
  1457. } else if err == nil {
  1458. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  1459. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  1460. if daySchedule.ID > 0 {
  1461. //daySchedule.BedId = bedID
  1462. //daySchedule.PartitionId = deviceNumber.ZoneID
  1463. //
  1464. //daySchedule.ScheduleType = schedual_type
  1465. //daySchedule.UpdatedTime = time.Now().Unix()
  1466. //err := service.UpdateSchedule(&daySchedule)
  1467. xtSchedule := models.Schedule{
  1468. PartitionId: deviceNumber.ZoneID,
  1469. BedId: bedID,
  1470. ScheduleType: schedual_type,
  1471. UpdatedTime: time.Now().Unix(),
  1472. }
  1473. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  1474. if err != nil {
  1475. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1476. return
  1477. }
  1478. }
  1479. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  1480. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  1481. return
  1482. }
  1483. } else if err != nil {
  1484. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1485. return
  1486. }
  1487. }
  1488. dialysisRecord := &models.DialysisOrder{
  1489. ID: record_id,
  1490. UserOrgId: adminUserInfo.CurrentOrgId,
  1491. BedID: bedID,
  1492. StartNurse: nurseID,
  1493. StartTime: startDate.Unix(),
  1494. PunctureNurse: puncture_nurse,
  1495. Creator: adminUserInfo.AdminUser.Id,
  1496. Modifier: adminUserInfo.AdminUser.Id,
  1497. SchedualType: schedual_type,
  1498. WashpipeNurse: washpipe_nurse,
  1499. ChangeNurse: change_nurse,
  1500. DifficultPunctureNurse: difficult_puncture_nurse,
  1501. NewFistulaNurse: new_fistula_nurse,
  1502. QualityNurseId: quality_nurse,
  1503. PunctureWay: puncture_way,
  1504. PunctureNeedle: puncture_needle,
  1505. DialysisDialyszers: dialysis_dialyszers,
  1506. DialysisIrrigation: dialysis_irrigation,
  1507. BloodAccessId: blood_access_id,
  1508. NucleinDate: theNucleinDate,
  1509. ScheduleRemark: schedule_remark,
  1510. OrderRemark: order_remark,
  1511. }
  1512. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  1513. order, _ := service.GetLastPatientOrder(record_id)
  1514. service.UpdateMobilePatient(adminUserInfo.CurrentOrgId, order.PatientId, schedule_remark)
  1515. redis := service.RedisClient()
  1516. key := strconv.FormatInt(tempDialysisRecord.UserOrgId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":dialysis_order"
  1517. redis.Set(key, "", time.Second)
  1518. keyOne := strconv.FormatInt(tempDialysisRecord.UserOrgId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":dialysis_orders_list_all"
  1519. //清空key 值
  1520. redis.Set(keyOne, "", time.Second)
  1521. scheduleDateStartOne := startDate.Format("2006-01-02")
  1522. keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(tempDialysisRecord.UserOrgId, 10)
  1523. redis.Set(keyTwo, "", time.Second)
  1524. keyThree := strconv.FormatInt(tempDialysisRecord.UserOrgId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":doctor_advices"
  1525. redis.Set(keyThree, "", time.Second)
  1526. keyFour := strconv.FormatInt(tempDialysisRecord.UserOrgId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_records"
  1527. redis.Set(keyFour, "", time.Second)
  1528. keyFive := strconv.FormatInt(tempDialysisRecord.UserOrgId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":patient_info"
  1529. redis.Set(keyFive, "", time.Second)
  1530. keySix := strconv.FormatInt(tempDialysisRecord.UserOrgId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":his_doctor_advice"
  1531. redis.Set(keySix, "", time.Second)
  1532. keySeven := strconv.FormatInt(tempDialysisRecord.UserOrgId, 10) + ":" + ":device_list_all"
  1533. redis.Set(keySeven, "", time.Second)
  1534. if updateErr != nil {
  1535. this.ErrorLog("修改上机失败:%v", updateErr)
  1536. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1537. return
  1538. }
  1539. if updateErr == nil {
  1540. if tempDialysisRecord.Stage == 2 {
  1541. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  1542. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  1543. fmt.Println(value)
  1544. a, b := math.Modf(value)
  1545. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  1546. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  1547. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  1548. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  1549. redis := service.RedisClient()
  1550. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":assessment_after_dislysis_list_all"
  1551. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":dialysis_orders_list_all"
  1552. redis.Set(key, "", time.Second)
  1553. redis.Set(keyThree, "", time.Second)
  1554. redis.Close()
  1555. if updateAssessmentErr != nil {
  1556. utils.ErrorLog("%v", updateAssessmentErr)
  1557. }
  1558. after, _ := service.FindAssessmentAfterDislysisById(tempDialysisRecord.UserOrgId, tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  1559. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  1560. this.ServeSuccessJSON(map[string]interface{}{
  1561. "dialysis_order": dialysisRecords,
  1562. "after": after,
  1563. })
  1564. } else {
  1565. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  1566. this.ServeSuccessJSON(map[string]interface{}{
  1567. "dialysis_order": dialysisRecords,
  1568. })
  1569. }
  1570. }
  1571. }
  1572. func (c *DialysisRecordAPIController) ModifyFinishDialysis() {
  1573. record_id, _ := c.GetInt64("id")
  1574. nurseID, _ := c.GetInt64("nurse")
  1575. end_time := c.GetString("end_time")
  1576. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  1577. internal_fistula := c.GetString("internal_fistula")
  1578. catheter := c.GetString("catheter")
  1579. cruor := c.GetString("cruor")
  1580. mission := c.GetString("mission")
  1581. if record_id <= 0 || nurseID <= 0 {
  1582. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1583. return
  1584. }
  1585. adminUserInfo := c.GetAdminUserInfo()
  1586. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  1587. if getNurseErr != nil {
  1588. c.ErrorLog("获取护士失败:%v", getNurseErr)
  1589. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1590. return
  1591. } else if nurse == nil {
  1592. c.ErrorLog("护士不存在")
  1593. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1594. return
  1595. }
  1596. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04", end_time)
  1597. if parseEndDateErr != nil {
  1598. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  1599. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1600. return
  1601. }
  1602. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  1603. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  1604. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1605. // if getPermissionErr != nil {
  1606. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1607. // return
  1608. // } else if headNursePermission == nil {
  1609. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1610. // return
  1611. // }
  1612. //}
  1613. dialysisRecord := &models.DialysisOrder{
  1614. ID: record_id,
  1615. UserOrgId: adminUserInfo.CurrentOrgId,
  1616. EndTime: endDate.Unix(),
  1617. FinishNurse: nurseID,
  1618. FinishModifier: adminUserInfo.AdminUser.Id,
  1619. PuncturePointHaematoma: puncture_point_haematoma,
  1620. BloodAccessInternalFistula: internal_fistula,
  1621. Catheter: catheter,
  1622. Cruor: cruor,
  1623. Mission: mission,
  1624. }
  1625. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  1626. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_order"
  1627. redis := service.RedisClient()
  1628. defer redis.Close()
  1629. //清空key 值
  1630. redis.Set(key, "", time.Second)
  1631. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + ":dialysis_orders_list_all"
  1632. redis.Set(keyOne, "", time.Second)
  1633. if updateErr != nil {
  1634. c.ErrorLog("修改下机失败:%v", updateErr)
  1635. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1636. return
  1637. }
  1638. if updateErr == nil {
  1639. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  1640. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  1641. fmt.Println(value)
  1642. a, b := math.Modf(value)
  1643. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  1644. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  1645. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  1646. monitor, _ := service.GetLastMonitorRecord(tempDialysisRecords.UserOrgId, tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate)
  1647. updateAssessmentErr := service.UpdateAssessmentAfterDateOne(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute, monitor.BreathingRate)
  1648. if updateAssessmentErr != nil {
  1649. utils.ErrorLog("%v", updateAssessmentErr)
  1650. }
  1651. }
  1652. after, _ := service.FindAssessmentAfterDislysisById(tempDialysisRecords.UserOrgId, tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate)
  1653. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  1654. c.ServeSuccessJSON(map[string]interface{}{
  1655. "dialysis_order": dialysisRecords,
  1656. "after": after,
  1657. })
  1658. }