dialysis_record_api_controller.go 79KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905
  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. ////统计该患者总次数
  907. //dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.CurrentOrgId, patientID)
  908. //
  909. //service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.CurrentOrgId, dialysisCount.Count)
  910. if adminUserInfo.CurrentOrgId != 10101 && adminUserInfo.CurrentOrgId != 10445 && adminUserInfo.CurrentOrgId != 3877 {
  911. //统计该患者总次数
  912. dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.CurrentOrgId, patientID)
  913. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.CurrentOrgId, dialysisCount.Count)
  914. }
  915. if adminUserInfo.CurrentOrgId == 10101 || adminUserInfo.CurrentOrgId == 10445 || adminUserInfo.CurrentOrgId == 3877 {
  916. //统计该患者总次数
  917. dialysisCount, _ := service.GetDialysisTotalCountOne(adminUserInfo.CurrentOrgId, patientID)
  918. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.CurrentOrgId, dialysisCount.Count)
  919. }
  920. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  921. redis := service.RedisClient()
  922. //清空key 值
  923. redis.Set(key, "", time.Second)
  924. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  925. redis.Set(keyOne, "", time.Second)
  926. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  927. //清空key 值
  928. redis.Set(keyTwo, "", time.Second)
  929. defer redis.Close()
  930. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  931. if createErr != nil {
  932. this.ErrorLog("上机失败:%v", createErr)
  933. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  934. return
  935. } else if createErr == nil {
  936. var tempdispose string
  937. // 只针对中能建
  938. if blood_drawing > 0 && adminUserInfo.CurrentOrgId == 9538 { //adminUserInfo.CurrentOrgId == 9538
  939. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  940. }
  941. if blood_drawing > 0 && adminUserInfo.CurrentOrgId == 10318 { //adminUserInfo.CurrentOrgId == 9538
  942. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  943. }
  944. var ultrafiltration_rate float64
  945. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.CurrentOrgId)
  946. //获取预增水量
  947. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, schedulestartTime, adminUserInfo.CurrentOrgId)
  948. if prescription.ID > 0 {
  949. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  950. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  951. //fmt.Println("total23232323232322332", totalMin)
  952. if (template.TemplateId == 6 || template.TemplateId == 20 || template.TemplateId == 22 || template.TemplateId == 32 || template.TemplateId == 36) && adminUserInfo.CurrentOrgId != 9671 {
  953. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  954. }
  955. //针对福建医师汇
  956. if template.TemplateId == 6 && adminUserInfo.CurrentOrgId == 10121 {
  957. if evaluation.ID > 0 {
  958. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  959. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  960. }
  961. }
  962. if template.TemplateId == 6 && adminUserInfo.CurrentOrgId == 10234 {
  963. if evaluation.ID > 0 {
  964. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  965. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  966. }
  967. }
  968. // 只针对方济医院
  969. if template.TemplateId == 1 && adminUserInfo.CurrentOrgId != 9849 {
  970. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  971. ultrafiltration_rate = value
  972. }
  973. //针对监利大垸医院
  974. if adminUserInfo.CurrentOrgId == 10101 {
  975. if evaluation.ID > 0 {
  976. ultrafiltration_rate = math.Ceil(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  977. }
  978. }
  979. //针对肇庆三鹤血液透析中心
  980. if adminUserInfo.CurrentOrgId == 10215 || template.TemplateId == 43 || adminUserInfo.CurrentOrgId == 10441 || adminUserInfo.CurrentOrgId == 10445 {
  981. if evaluation.ID > 0 {
  982. ultrafiltration_rate = math.Ceil(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  983. }
  984. }
  985. }
  986. }
  987. record := models.MonitoringRecord{
  988. UserOrgId: adminUserInfo.CurrentOrgId,
  989. PatientId: patientID,
  990. DialysisOrderId: dialysisRecord.ID,
  991. MonitoringDate: schedulestartTime,
  992. OperateTime: startDate.Unix(),
  993. // MonitoringTime: recordTime,
  994. MonitoringNurse: nurseID,
  995. Dispose: tempdispose,
  996. UltrafiltrationRate: ultrafiltration_rate,
  997. UltrafiltrationVolume: 0,
  998. Status: 1,
  999. CreatedTime: time.Now().Unix(),
  1000. UpdatedTime: time.Now().Unix(),
  1001. }
  1002. //只针对广慈医院
  1003. 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 {
  1004. // 查询病人是否有透前评估数据
  1005. befor, errcode := service.GetAssessmentBefor(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1006. //如果有数据就插入
  1007. if errcode == nil {
  1008. record.SystolicBloodPressure = befor.SystolicBloodPressure
  1009. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  1010. record.BreathingRate = befor.BreathingRate
  1011. record.PulseFrequency = befor.PulseFrequency
  1012. record.Temperature = befor.Temperature
  1013. }
  1014. }
  1015. // 如果当天有插入数据,则不再往透析纪录里插入数据
  1016. if newdialysisRecord.ID > 0 {
  1017. //针对长沙南雅医院
  1018. if adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 9675 || adminUserInfo.CurrentOrgId == 10340 {
  1019. record.Temperature = 36.5
  1020. record.ArterialPressure = -100
  1021. record.Conductivity = 14
  1022. record.BreathingRate = "20"
  1023. record.DialysateTemperature = 36.5
  1024. record.VenousPressure = 80
  1025. record.TransmembranePressure = 60
  1026. }
  1027. //针对兰溪人民医院的需求
  1028. if adminUserInfo.CurrentOrgId == 10432 {
  1029. befor, _ := service.GetAssessmentBefor(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1030. record.SystolicBloodPressure = befor.SystolicBloodPressure
  1031. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  1032. record.Temperature = befor.Temperature
  1033. record.PulseFrequency = befor.PulseFrequency
  1034. }
  1035. err := service.CreateMonitor(&record)
  1036. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_records"
  1037. redis := service.RedisClient()
  1038. //清空key 值
  1039. redis.Set(key, "", time.Second)
  1040. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_record_list_all"
  1041. redis.Set(keyOne, "", time.Second)
  1042. defer redis.Close()
  1043. if err != nil {
  1044. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  1045. return
  1046. }
  1047. }
  1048. go func() {
  1049. ssoDomain := beego.AppConfig.String("call_domain")
  1050. api := ssoDomain + "/index/uppatient"
  1051. values := make(url.Values)
  1052. values.Set("org_id", strconv.FormatInt(adminUserInfo.CurrentOrgId, 10))
  1053. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  1054. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  1055. values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
  1056. http.PostForm(api, values)
  1057. }()
  1058. this.ServeSuccessJSON(map[string]interface{}{
  1059. "dialysis_order": dialysisRecord,
  1060. "monitor": record,
  1061. })
  1062. }
  1063. }
  1064. // /api/dialysis/finish [post]
  1065. // @param patient_id:int
  1066. // @param date:string 排班时间 (yyyy-mm-dd)
  1067. // @param nurse:int 下机护士
  1068. func (this *DialysisRecordAPIController) FinishDialysis() {
  1069. patientID, _ := this.GetInt64("patient_id")
  1070. recordDateStr := this.GetString("date")
  1071. nurseID, _ := this.GetInt64("nurse")
  1072. end_time := this.GetString("end_time")
  1073. puncture_point_haematoma, _ := this.GetInt64("puncture_point_haematoma")
  1074. internal_fistula := this.GetString("internal_fistula")
  1075. catheter := this.GetString("catheter")
  1076. cruor := this.GetString("cruor")
  1077. mission := this.GetString("mission")
  1078. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 {
  1079. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1080. return
  1081. }
  1082. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1083. if parseErr != nil {
  1084. this.ErrorLog("时间解析失败:%v", parseErr)
  1085. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1086. return
  1087. }
  1088. //if parseEndDateErr != nil {
  1089. // this.ErrorLog("时间解析失败:%v", parseEndDateErr)
  1090. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1091. // return
  1092. //}
  1093. adminUserInfo := this.GetAdminUserInfo()
  1094. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.CurrentOrgId, patientID)
  1095. if getPatientErr != nil {
  1096. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  1097. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1098. return
  1099. } else if patient == nil {
  1100. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1101. return
  1102. }
  1103. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  1104. if getNurseErr != nil {
  1105. this.ErrorLog("获取护士失败:%v", getNurseErr)
  1106. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1107. return
  1108. } else if nurse == nil {
  1109. this.ErrorLog("护士不存在")
  1110. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1111. return
  1112. }
  1113. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1114. if getRecordErr != nil {
  1115. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  1116. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1117. return
  1118. }
  1119. if dialysisRecord.Stage == 2 {
  1120. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  1121. return
  1122. }
  1123. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04", end_time)
  1124. if parseEndDateErr != nil {
  1125. this.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  1126. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1127. return
  1128. }
  1129. // 获取当天的第一条透析纪录
  1130. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1131. if getMonitorRecordsErr != nil {
  1132. this.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  1133. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1134. return
  1135. }
  1136. // 获取当前的最后一条透析纪录
  1137. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecord(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1138. if getMonitorRecordsErr != nil {
  1139. this.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  1140. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1141. return
  1142. }
  1143. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysis(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1144. if getAADErr != nil {
  1145. this.ErrorLog("获取透后评估失败:%v", getAADErr)
  1146. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1147. return
  1148. }
  1149. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysis(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1150. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  1151. if assessmentAfterDislysis != nil {
  1152. tempassessmentAfterDislysis = *assessmentAfterDislysis
  1153. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  1154. } else {
  1155. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  1156. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  1157. tempassessmentAfterDislysis.Status = 1
  1158. tempassessmentAfterDislysis.PatientId = patientID
  1159. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.CurrentOrgId
  1160. }
  1161. if dialysisRecord.Stage == 1 {
  1162. temp_time := (float64(endDate.Unix()) - float64(dialysisRecord.StartTime)) / 3600
  1163. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  1164. fmt.Println(value)
  1165. a, b := math.Modf(value)
  1166. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  1167. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  1168. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  1169. fmt.Println(hour)
  1170. fmt.Println(minute)
  1171. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  1172. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  1173. }
  1174. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  1175. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  1176. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  1177. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  1178. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  1179. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  1180. //长沙南雅
  1181. if adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 9675 || adminUserInfo.CurrentOrgId == 10340 {
  1182. //获取最后一条透析处方数据
  1183. prescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1184. evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1185. tempassessmentAfterDislysis.WeightAfter = evaluation.WeightBefore - prescription.TargetUltrafiltration/1000
  1186. }
  1187. if adminUserInfo.CurrentOrgId == 10101 {
  1188. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  1189. } else {
  1190. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  1191. }
  1192. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  1193. }
  1194. if adminUserInfo.CurrentOrgId == 9583 {
  1195. //获取最后一条透析处方数据
  1196. prescription, parseErr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1197. if parseErr != nil {
  1198. this.ErrorLog("获取透析处方失败:%v", getMonitorRecordsErr)
  1199. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1200. return
  1201. }
  1202. if prescription.ID > 0 && adminUserInfo.CurrentOrgId == 9583 {
  1203. tempassessmentAfterDislysis.ActualUltrafiltration = prescription.TargetUltrafiltration
  1204. }
  1205. if endmonitorRecords.ID > 0 && adminUserInfo.CurrentOrgId == 10060 {
  1206. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  1207. }
  1208. }
  1209. if lastAssessmentAfterDislysis != nil {
  1210. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  1211. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  1212. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  1213. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  1214. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  1215. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  1216. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  1217. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  1218. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  1219. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  1220. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  1221. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  1222. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  1223. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  1224. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  1225. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  1226. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  1227. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  1228. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  1229. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  1230. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  1231. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  1232. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  1233. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  1234. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  1235. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  1236. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  1237. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  1238. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  1239. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  1240. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  1241. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  1242. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  1243. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  1244. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  1245. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  1246. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  1247. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  1248. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  1249. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  1250. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  1251. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  1252. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  1253. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  1254. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  1255. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  1256. }
  1257. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  1258. if adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 9675 || adminUserInfo.CurrentOrgId == 10164 || adminUserInfo.CurrentOrgId == 10340 || adminUserInfo.CurrentOrgId == 10414 || adminUserInfo.CurrentOrgId == 10432 || adminUserInfo.CurrentOrgId == 10445 {
  1259. evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1260. if evaluation.SystolicBloodPressure == 0 {
  1261. pre := models.PredialysisEvaluation{
  1262. SystolicBloodPressure: fmonitorRecords.SystolicBloodPressure,
  1263. }
  1264. fmt.Println("prew", pre)
  1265. getNurseErr := service.UpdatePredialysisEvaluation(&pre, evaluation.ID)
  1266. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  1267. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  1268. redis := service.RedisClient()
  1269. redis.Set(key, "", time.Second)
  1270. redis.Set(keyOne, "", time.Second)
  1271. defer redis.Close()
  1272. fmt.Println(getNurseErr)
  1273. }
  1274. if evaluation.DiastolicBloodPressure == 0 {
  1275. pres := models.PredialysisEvaluation{
  1276. DiastolicBloodPressure: fmonitorRecords.DiastolicBloodPressure,
  1277. }
  1278. getNurseErr := service.UpdatePredialysisEvaluationTwo(&pres, 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.PulseFrequency == 0 {
  1288. evaluation.PulseFrequency = fmonitorRecords.PulseFrequency
  1289. press := models.PredialysisEvaluation{
  1290. PulseFrequency: evaluation.PulseFrequency,
  1291. }
  1292. getNurseErr := service.UpdatePredialysisEvaluationThree(&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. if evaluation.Temperature == 0 {
  1302. evaluation.Temperature = fmonitorRecords.Temperature
  1303. press := models.PredialysisEvaluation{
  1304. Temperature: evaluation.Temperature,
  1305. }
  1306. getNurseErr := service.UpdatePredialysisEvaluationFour(&press, evaluation.ID)
  1307. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  1308. redis := service.RedisClient()
  1309. redis.Set(key, "", time.Second)
  1310. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  1311. redis.Set(keyOne, "", time.Second)
  1312. defer redis.Close()
  1313. fmt.Println(getNurseErr)
  1314. }
  1315. }
  1316. if err != nil {
  1317. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1318. return
  1319. }
  1320. go func() {
  1321. ssoDomain := beego.AppConfig.String("call_domain")
  1322. api := ssoDomain + "/index/downpatient"
  1323. values := make(url.Values)
  1324. values.Set("org_id", strconv.FormatInt(adminUserInfo.CurrentOrgId, 10))
  1325. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  1326. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  1327. http.PostForm(api, values)
  1328. }()
  1329. //执行下机
  1330. updateErr := service.ModifyDialysisRecord(dialysisRecord.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id, puncture_point_haematoma, internal_fistula, catheter, cruor, mission)
  1331. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  1332. redis := service.RedisClient()
  1333. defer redis.Close()
  1334. //清空key 值
  1335. redis.Set(key, "", time.Second)
  1336. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  1337. redis.Set(keyOne, "", time.Second)
  1338. if updateErr != nil {
  1339. this.ErrorLog("下机失败:%v", updateErr)
  1340. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1341. return
  1342. } else {
  1343. dialysisRecord.Stage = 2
  1344. dialysisRecord.FinishNurse = nurseID
  1345. dialysisRecord.FinishCreator = adminUserInfo.AdminUser.Id
  1346. dialysisRecord.FinishModifier = adminUserInfo.AdminUser.Id
  1347. dialysisRecord.EndTime = endDate.Unix()
  1348. // 结束时候透析次数加1
  1349. service.UpdateSolutionByPatientId(patientID)
  1350. this.ServeSuccessJSON(map[string]interface{}{
  1351. "dialysis_order": dialysisRecord,
  1352. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  1353. })
  1354. }
  1355. }
  1356. func (this *DialysisRecordAPIController) ModifyStartDialysis() {
  1357. record_id, _ := this.GetInt64("id")
  1358. nurseID, _ := this.GetInt64("nurse")
  1359. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  1360. bedID, _ := this.GetInt64("bed")
  1361. start_time := this.GetString("start_time")
  1362. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  1363. schedual_type, _ := this.GetInt64("schedual_type")
  1364. change_nurse, _ := this.GetInt64("change_nurse")
  1365. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  1366. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  1367. quality_nurse, _ := this.GetInt64("quality_nurse")
  1368. puncture_needle := this.GetString("puncture_needle")
  1369. puncture_way := this.GetString("puncture_way")
  1370. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  1371. dialysis_irrigation := this.GetString("dialysis_irrigation")
  1372. blood_access_id, _ := this.GetInt64("blood_access_id")
  1373. nuclein_date := this.GetString("nuclein_date")
  1374. schedule_remark := this.GetString("schedule_remark")
  1375. order_remark := this.GetString("order_remark")
  1376. if record_id == 0 {
  1377. this.ErrorLog("id:%v", record_id)
  1378. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1379. return
  1380. }
  1381. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04", start_time)
  1382. if parseStartDateErr != nil {
  1383. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  1384. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1385. return
  1386. }
  1387. adminUserInfo := this.GetAdminUserInfo()
  1388. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  1389. if getNurseErr != nil {
  1390. this.ErrorLog("获取护士失败:%v", getNurseErr)
  1391. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1392. return
  1393. } else if nurse == nil {
  1394. this.ErrorLog("护士不存在")
  1395. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1396. return
  1397. }
  1398. //nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  1399. //if getNurseErr != nil {
  1400. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  1401. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1402. // return
  1403. //} else if nurse == nil {
  1404. // this.ErrorLog("护士不存在")
  1405. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1406. // return
  1407. //}
  1408. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.CurrentOrgId, bedID)
  1409. if getDeviceNumberErr != nil {
  1410. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  1411. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1412. return
  1413. } else if deviceNumber == nil {
  1414. this.ErrorLog("床位号不存在")
  1415. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1416. return
  1417. }
  1418. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  1419. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  1420. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1421. // if getPermissionErr != nil {
  1422. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1423. // return
  1424. // } else if headNursePermission == nil {
  1425. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1426. // return
  1427. // }
  1428. //}
  1429. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  1430. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  1431. timeLayout := "2006-01-02 15:04:05"
  1432. loc, _ := time.LoadLocation("Local")
  1433. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  1434. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  1435. schedulestartTime := theStartTime.Unix()
  1436. scheduleendTime := theEndTime.Unix()
  1437. var theNucleinDate int64
  1438. timeLayoutOne := "2006-01-02"
  1439. if len(nuclein_date) > 0 {
  1440. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date+" 00:00:00", loc)
  1441. if err != nil {
  1442. utils.ErrorLog(err.Error())
  1443. }
  1444. theNucleinDate = theTime.Unix()
  1445. }
  1446. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  1447. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.CurrentOrgId, schedulestartTime, bedID, schedual_type)
  1448. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  1449. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  1450. if err == gorm.ErrRecordNotFound { //空床位
  1451. // 修改了床位逻辑
  1452. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  1453. if daySchedule.ID > 0 {
  1454. //daySchedule.BedId = bedID
  1455. //daySchedule.PartitionId = deviceNumber.ZoneID
  1456. //daySchedule.ScheduleType = schedual_type
  1457. //daySchedule.UpdatedTime = time.Now().Unix()
  1458. //err := service.UpdateSchedule(&daySchedule)
  1459. xtSchedule := models.Schedule{
  1460. PartitionId: deviceNumber.ZoneID,
  1461. BedId: bedID,
  1462. ScheduleType: schedual_type,
  1463. UpdatedTime: time.Now().Unix(),
  1464. }
  1465. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  1466. if err != nil {
  1467. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1468. return
  1469. }
  1470. }
  1471. } else if err == nil {
  1472. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  1473. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  1474. if daySchedule.ID > 0 {
  1475. //daySchedule.BedId = bedID
  1476. //daySchedule.PartitionId = deviceNumber.ZoneID
  1477. //
  1478. //daySchedule.ScheduleType = schedual_type
  1479. //daySchedule.UpdatedTime = time.Now().Unix()
  1480. //err := service.UpdateSchedule(&daySchedule)
  1481. xtSchedule := models.Schedule{
  1482. PartitionId: deviceNumber.ZoneID,
  1483. BedId: bedID,
  1484. ScheduleType: schedual_type,
  1485. UpdatedTime: time.Now().Unix(),
  1486. }
  1487. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  1488. if err != nil {
  1489. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1490. return
  1491. }
  1492. }
  1493. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  1494. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  1495. return
  1496. }
  1497. } else if err != nil {
  1498. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1499. return
  1500. }
  1501. }
  1502. dialysisRecord := &models.DialysisOrder{
  1503. ID: record_id,
  1504. UserOrgId: adminUserInfo.CurrentOrgId,
  1505. BedID: bedID,
  1506. StartNurse: nurseID,
  1507. StartTime: startDate.Unix(),
  1508. PunctureNurse: puncture_nurse,
  1509. Creator: adminUserInfo.AdminUser.Id,
  1510. Modifier: adminUserInfo.AdminUser.Id,
  1511. SchedualType: schedual_type,
  1512. WashpipeNurse: washpipe_nurse,
  1513. ChangeNurse: change_nurse,
  1514. DifficultPunctureNurse: difficult_puncture_nurse,
  1515. NewFistulaNurse: new_fistula_nurse,
  1516. QualityNurseId: quality_nurse,
  1517. PunctureWay: puncture_way,
  1518. PunctureNeedle: puncture_needle,
  1519. DialysisDialyszers: dialysis_dialyszers,
  1520. DialysisIrrigation: dialysis_irrigation,
  1521. BloodAccessId: blood_access_id,
  1522. NucleinDate: theNucleinDate,
  1523. ScheduleRemark: schedule_remark,
  1524. OrderRemark: order_remark,
  1525. }
  1526. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  1527. order, _ := service.GetLastPatientOrder(record_id)
  1528. service.UpdateMobilePatient(adminUserInfo.CurrentOrgId, order.PatientId, schedule_remark)
  1529. redis := service.RedisClient()
  1530. key := strconv.FormatInt(tempDialysisRecord.UserOrgId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":dialysis_order"
  1531. redis.Set(key, "", time.Second)
  1532. keyOne := strconv.FormatInt(tempDialysisRecord.UserOrgId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":dialysis_orders_list_all"
  1533. //清空key 值
  1534. redis.Set(keyOne, "", time.Second)
  1535. scheduleDateStartOne := startDate.Format("2006-01-02")
  1536. keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(tempDialysisRecord.UserOrgId, 10)
  1537. redis.Set(keyTwo, "", time.Second)
  1538. keyThree := strconv.FormatInt(tempDialysisRecord.UserOrgId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":doctor_advices"
  1539. redis.Set(keyThree, "", time.Second)
  1540. keyFour := strconv.FormatInt(tempDialysisRecord.UserOrgId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_records"
  1541. redis.Set(keyFour, "", time.Second)
  1542. keyFive := strconv.FormatInt(tempDialysisRecord.UserOrgId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":patient_info"
  1543. redis.Set(keyFive, "", time.Second)
  1544. keySix := strconv.FormatInt(tempDialysisRecord.UserOrgId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":his_doctor_advice"
  1545. redis.Set(keySix, "", time.Second)
  1546. keySeven := strconv.FormatInt(tempDialysisRecord.UserOrgId, 10) + ":" + ":device_list_all"
  1547. redis.Set(keySeven, "", time.Second)
  1548. if updateErr != nil {
  1549. this.ErrorLog("修改上机失败:%v", updateErr)
  1550. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1551. return
  1552. }
  1553. if updateErr == nil {
  1554. if tempDialysisRecord.Stage == 2 {
  1555. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  1556. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  1557. fmt.Println(value)
  1558. a, b := math.Modf(value)
  1559. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  1560. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  1561. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  1562. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  1563. redis := service.RedisClient()
  1564. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":assessment_after_dislysis_list_all"
  1565. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":dialysis_orders_list_all"
  1566. redis.Set(key, "", time.Second)
  1567. redis.Set(keyThree, "", time.Second)
  1568. redis.Close()
  1569. if updateAssessmentErr != nil {
  1570. utils.ErrorLog("%v", updateAssessmentErr)
  1571. }
  1572. after, _ := service.FindAssessmentAfterDislysisById(tempDialysisRecord.UserOrgId, tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  1573. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  1574. this.ServeSuccessJSON(map[string]interface{}{
  1575. "dialysis_order": dialysisRecords,
  1576. "after": after,
  1577. })
  1578. } else {
  1579. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  1580. this.ServeSuccessJSON(map[string]interface{}{
  1581. "dialysis_order": dialysisRecords,
  1582. })
  1583. }
  1584. }
  1585. }
  1586. func (c *DialysisRecordAPIController) ModifyFinishDialysis() {
  1587. record_id, _ := c.GetInt64("id")
  1588. nurseID, _ := c.GetInt64("nurse")
  1589. end_time := c.GetString("end_time")
  1590. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  1591. internal_fistula := c.GetString("internal_fistula")
  1592. catheter := c.GetString("catheter")
  1593. cruor := c.GetString("cruor")
  1594. mission := c.GetString("mission")
  1595. if record_id <= 0 || nurseID <= 0 {
  1596. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1597. return
  1598. }
  1599. adminUserInfo := c.GetAdminUserInfo()
  1600. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  1601. if getNurseErr != nil {
  1602. c.ErrorLog("获取护士失败:%v", getNurseErr)
  1603. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1604. return
  1605. } else if nurse == nil {
  1606. c.ErrorLog("护士不存在")
  1607. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1608. return
  1609. }
  1610. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04", end_time)
  1611. if parseEndDateErr != nil {
  1612. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  1613. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1614. return
  1615. }
  1616. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  1617. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  1618. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1619. // if getPermissionErr != nil {
  1620. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1621. // return
  1622. // } else if headNursePermission == nil {
  1623. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1624. // return
  1625. // }
  1626. //}
  1627. dialysisRecord := &models.DialysisOrder{
  1628. ID: record_id,
  1629. UserOrgId: adminUserInfo.CurrentOrgId,
  1630. EndTime: endDate.Unix(),
  1631. FinishNurse: nurseID,
  1632. FinishModifier: adminUserInfo.AdminUser.Id,
  1633. PuncturePointHaematoma: puncture_point_haematoma,
  1634. BloodAccessInternalFistula: internal_fistula,
  1635. Catheter: catheter,
  1636. Cruor: cruor,
  1637. Mission: mission,
  1638. }
  1639. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  1640. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_order"
  1641. redis := service.RedisClient()
  1642. defer redis.Close()
  1643. //清空key 值
  1644. redis.Set(key, "", time.Second)
  1645. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + ":dialysis_orders_list_all"
  1646. redis.Set(keyOne, "", time.Second)
  1647. if updateErr != nil {
  1648. c.ErrorLog("修改下机失败:%v", updateErr)
  1649. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1650. return
  1651. }
  1652. if updateErr == nil {
  1653. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  1654. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  1655. fmt.Println(value)
  1656. a, b := math.Modf(value)
  1657. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  1658. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  1659. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  1660. monitor, _ := service.GetLastMonitorRecord(tempDialysisRecords.UserOrgId, tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate)
  1661. updateAssessmentErr := service.UpdateAssessmentAfterDateOne(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute, monitor.BreathingRate)
  1662. if updateAssessmentErr != nil {
  1663. utils.ErrorLog("%v", updateAssessmentErr)
  1664. }
  1665. }
  1666. after, _ := service.FindAssessmentAfterDislysisById(tempDialysisRecords.UserOrgId, tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate)
  1667. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  1668. c.ServeSuccessJSON(map[string]interface{}{
  1669. "dialysis_order": dialysisRecords,
  1670. "after": after,
  1671. })
  1672. }