dialysis_record_api_controller.go 90KB

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