dialysis_record_api_controller.go 76KB

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