dialysis_record_api_controller.go 90KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234
  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. }
  488. // /api/dislysis/monitor/edit [post]
  489. // @param patient_id:int 患者id
  490. // @param schedule_date:int 排班日期
  491. // 下面的参数放到 body
  492. // @param id?:int 监测记录ID(id为0时为创建记录,不为0时为修改记录)
  493. // @param monitoring_date:int 排班日期
  494. // @param operate_time:int 实际测量日期
  495. // @param monitoring_time:string (HH:mm) 监测时间 废弃
  496. // @param systolic_bp?:float 收缩压
  497. // @param diastolic_bp?:float 舒张压
  498. // @param pulse_frequency?:float 心率
  499. // @param breathing_rated?:float 呼吸频率
  500. // @param blood_flow_volume?:float 血流量
  501. // @param venous_pressure?:float 静脉压
  502. // @param transmembrane_pressure?:float 跨膜压
  503. // @param ultrafiltration_volume?:float 超滤量
  504. // @param ultrafiltration_rate?:float 超滤率
  505. // @param arterial_pressure?:float 动脉压
  506. // @param sodium_concentration?:float 钠浓度
  507. // @param dialysate_temperature?:float 透析液温度
  508. // @param replacement_rate?:float 置换率
  509. // @param displacement_quantity?:float 置换量
  510. // @param ktv?:float KT/V
  511. // @param symptom?:string 病情变化
  512. // @param dispose?:string 处理
  513. // @param result?:string 结果
  514. func (this *DialysisRecordAPIController) EditMonitor() {
  515. patientID, _ := this.GetInt64("patient_id")
  516. scheduleDate, _ := this.GetInt64("schedule_date")
  517. if patientID <= 0 || scheduleDate <= 0 {
  518. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  519. return
  520. }
  521. var monitorParam EditMonitorParamObject
  522. if parseErr := json.Unmarshal(this.Ctx.Input.RequestBody, &monitorParam); parseErr != nil {
  523. this.ErrorLog("参数解析失败:%v", parseErr)
  524. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamFormatWrong)
  525. return
  526. }
  527. if monitorParam.MonitoringDate != scheduleDate {
  528. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  529. return
  530. }
  531. adminUserInfo := this.GetAdminUserInfo()
  532. schedule, getScheduleErr := service.MobileGetSchedualDetail(adminUserInfo.CurrentOrgId, patientID, scheduleDate)
  533. if getScheduleErr != nil {
  534. this.ErrorLog("获取排班信息失败:%v", getScheduleErr)
  535. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  536. return
  537. } else if schedule == nil {
  538. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist)
  539. return
  540. }
  541. // TODO 其实这里合理的逻辑是“透析记录存在的情况下才能添加监测记录的”
  542. dialysisOrder, getDialysisOrderErr := service.MobileGetDialysisRecord(adminUserInfo.CurrentOrgId, patientID, scheduleDate)
  543. if getDialysisOrderErr != nil {
  544. this.ErrorLog("获取透析记录失败:%v", getDialysisOrderErr)
  545. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  546. return
  547. }
  548. orderID := int64(0)
  549. if dialysisOrder != nil {
  550. orderID = dialysisOrder.ID
  551. }
  552. // 查询信息规挡的设置天数
  553. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  554. if infor.ID > 0 && infor.WeekDay > 0 {
  555. var cha_time int64
  556. timeNowStr := time.Now().Format("2006-01-02")
  557. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  558. //今日的日期减去设置的日期
  559. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  560. if cha_time >= scheduleDate && infor.WeekDay != 0 {
  561. //查询审核是否允许
  562. infor, _ := service.GetDialysisInformationByRecordDate(patientID, scheduleDate, adminUserInfo.CurrentOrgId, 7)
  563. //申请状态不允许的情况 拒绝修改
  564. if infor.ApplicationStatus != 1 {
  565. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  566. return
  567. }
  568. }
  569. }
  570. if monitorParam.ID <= 0 { // 新建记录
  571. monitor := models.MonitoringRecord{
  572. UserOrgId: adminUserInfo.CurrentOrgId,
  573. PatientId: patientID,
  574. DialysisOrderId: orderID,
  575. MonitoringDate: monitorParam.MonitoringDate,
  576. OperateTime: monitorParam.OperateTime,
  577. // MonitoringTime: monitorParam.MonitoringTime,
  578. PulseFrequency: monitorParam.PulseFrequency,
  579. BreathingRate: monitorParam.BreathingRated,
  580. SystolicBloodPressure: monitorParam.SystolicBP,
  581. DiastolicBloodPressure: monitorParam.DiastolicBP,
  582. BloodFlowVolume: monitorParam.BloodFlowVolume,
  583. VenousPressure: monitorParam.VenousPressure,
  584. VenousPressureType: monitorParam.VenousPressureType,
  585. ArterialPressure: monitorParam.ArterialPressure,
  586. ArterialPressureType: monitorParam.ArterialPressureType,
  587. TransmembranePressure: monitorParam.TransmembranePressure,
  588. TransmembranePressureType: monitorParam.TransmembranePressureType,
  589. UltrafiltrationRate: monitorParam.UltrafiltrationRate,
  590. UltrafiltrationVolume: monitorParam.UltrafiltrationVolume,
  591. SodiumConcentration: monitorParam.SodiumConcentration,
  592. DialysateTemperature: monitorParam.DialysateTemperature,
  593. Temperature: monitorParam.Temperature,
  594. ReplacementRate: monitorParam.ReplacementRate,
  595. DisplacementQuantity: monitorParam.DisplacementQuantity,
  596. Ktv: monitorParam.KTV,
  597. Symptom: monitorParam.Symptom,
  598. Dispose: monitorParam.Dispose,
  599. Result: monitorParam.Result,
  600. MonitoringNurse: adminUserInfo.AdminUser.Id,
  601. Conductivity: monitorParam.Conductivity,
  602. DisplacementFlowQuantity: monitorParam.DisplacementFlowQuantity,
  603. Status: 1,
  604. CreatedTime: time.Now().Unix(),
  605. UpdatedTime: time.Now().Unix(),
  606. BloodOxygenSaturation: monitorParam.BloodOxygenSaturation,
  607. Creator: adminUserInfo.AdminUser.Id,
  608. Heparin: monitorParam.Heparin,
  609. DialysateFlow: monitorParam.DialysateFlow,
  610. Urr: monitorParam.Urr,
  611. BloodSugar: monitorParam.BloodSugar,
  612. MonitorAnticoagulant: monitorParam.MonitorAnticoagulant,
  613. MonitorAnticoagulantValue: monitorParam.MonitorAnticoagulantValue,
  614. BloodPressureMonitoringSite: monitorParam.BloodPressureMonitoringSite,
  615. Complication: monitorParam.Complication,
  616. AccumulatedBloodVolume: monitorParam.AccumulatedBloodVolume,
  617. BloodTemperature: monitorParam.BloodTemperature,
  618. UreaMonitoring: monitorParam.UreaMonitoring,
  619. BloodThickness: monitorParam.BloodThickness,
  620. BloodMonitor: monitorParam.BloodMonitor,
  621. HeparinAmount: monitorParam.HeparinAmount,
  622. Dehydration: monitorParam.Dehydration,
  623. FilterPressure: monitorParam.FilterPressure,
  624. ReplacementSpeed: monitorParam.ReplacementSpeed,
  625. Dicarbonate: monitorParam.Dicarbonate,
  626. }
  627. createErr := service.CreateMonitor(&monitor)
  628. //记录日志
  629. byterequest, _ := json.Marshal(monitor)
  630. monitorRecordLog := models.XtMonitorRecordLog{
  631. RecordDate: monitor.MonitoringDate,
  632. PatientId: monitor.PatientId,
  633. Module: 1,
  634. AdminUserId: adminUserInfo.AdminUser.Id,
  635. Ctime: time.Now().Unix(),
  636. Mtime: 0,
  637. Status: 1,
  638. UserOrgId: monitor.UserOrgId,
  639. ErrLog: string(byterequest),
  640. Source: "电脑端新增监测",
  641. }
  642. service.CreateMonitorRecordLog(monitorRecordLog)
  643. finish := models.XtDialysisFinish{
  644. IsFinish: 1,
  645. UserOrgId: adminUserInfo.CurrentOrgId,
  646. Status: 1,
  647. Ctime: time.Now().Unix(),
  648. Mtime: 0,
  649. Module: 7,
  650. RecordDate: monitorParam.MonitoringDate,
  651. Sourse: 1,
  652. PatientId: patientID,
  653. }
  654. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, monitorParam.MonitoringDate, 7, patientID)
  655. if dialysisFinish.ID == 0 {
  656. service.CreateDialysisFinish(finish)
  657. }
  658. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":monitor_records"
  659. redis := service.RedisClient()
  660. //清空key 值
  661. redis.Set(key, "", time.Second)
  662. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(monitorParam.MonitoringDate, 10) + ":monitor_record_list_all"
  663. redis.Set(keyOne, "", time.Second)
  664. defer redis.Close()
  665. if createErr != nil {
  666. this.ErrorLog("创建监测记录失败:%v", createErr)
  667. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  668. return
  669. }
  670. this.ServeSuccessJSON(map[string]interface{}{
  671. "monitor": monitor,
  672. })
  673. } else { // 修改记录
  674. monitor, getMonitorErr := service.GetMonitor(adminUserInfo.CurrentOrgId, patientID, monitorParam.ID)
  675. if getMonitorErr != nil {
  676. this.ErrorLog("获取透析监测记录失败:%v", getMonitorErr)
  677. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  678. return
  679. } else if monitor == nil {
  680. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorNotExist)
  681. return
  682. }
  683. //if monitor.MonitoringNurse != adminUserInfo.AdminUser.Id {
  684. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  685. // if getPermissionErr != nil {
  686. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  687. // return
  688. // } else if headNursePermission == nil {
  689. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  690. // return
  691. // }
  692. //}
  693. monitor.OperateTime = monitorParam.OperateTime
  694. monitor.PulseFrequency = monitorParam.PulseFrequency
  695. monitor.BreathingRate = monitorParam.BreathingRated
  696. monitor.SystolicBloodPressure = monitorParam.SystolicBP
  697. monitor.DiastolicBloodPressure = monitorParam.DiastolicBP
  698. monitor.BloodFlowVolume = monitorParam.BloodFlowVolume
  699. monitor.VenousPressure = monitorParam.VenousPressure
  700. monitor.VenousPressureType = monitorParam.VenousPressureType
  701. monitor.ArterialPressure = monitorParam.ArterialPressure
  702. monitor.ArterialPressureType = monitorParam.ArterialPressureType
  703. monitor.TransmembranePressure = monitorParam.TransmembranePressure
  704. monitor.TransmembranePressureType = monitorParam.TransmembranePressureType
  705. monitor.UltrafiltrationRate = monitorParam.UltrafiltrationRate
  706. monitor.UltrafiltrationVolume = monitorParam.UltrafiltrationVolume
  707. monitor.SodiumConcentration = monitorParam.SodiumConcentration
  708. monitor.DialysateTemperature = monitorParam.DialysateTemperature
  709. monitor.Temperature = monitorParam.Temperature
  710. monitor.ReplacementRate = monitorParam.ReplacementRate
  711. monitor.DisplacementQuantity = monitorParam.DisplacementQuantity
  712. monitor.Conductivity = monitorParam.Conductivity
  713. monitor.DisplacementFlowQuantity = monitorParam.DisplacementFlowQuantity
  714. monitor.Ktv = monitorParam.KTV
  715. monitor.Symptom = monitorParam.Symptom
  716. monitor.Dispose = monitorParam.Dispose
  717. monitor.Result = monitorParam.Result
  718. monitor.MonitoringNurse = adminUserInfo.AdminUser.Id
  719. monitor.UpdatedTime = time.Now().Unix()
  720. monitor.Modify = adminUserInfo.AdminUser.Id
  721. monitor.BloodOxygenSaturation = monitorParam.BloodOxygenSaturation
  722. monitor.Heparin = monitorParam.Heparin
  723. monitor.DialysateFlow = monitorParam.DialysateFlow
  724. monitor.Urr = monitorParam.Urr
  725. monitor.BloodSugar = monitorParam.BloodSugar
  726. monitor.MonitorAnticoagulant = monitorParam.MonitorAnticoagulant
  727. monitor.MonitorAnticoagulantValue = monitorParam.MonitorAnticoagulantValue
  728. monitor.AccumulatedBloodVolume = monitorParam.AccumulatedBloodVolume
  729. monitor.BloodTemperature = monitorParam.BloodTemperature
  730. monitor.UreaMonitoring = monitorParam.UreaMonitoring
  731. monitor.BloodThickness = monitorParam.BloodThickness
  732. monitor.BloodMonitor = monitorParam.BloodMonitor
  733. monitor.HeparinAmount = monitorParam.HeparinAmount
  734. monitor.Dehydration = monitorParam.Dehydration
  735. monitor.FilterPressure = monitorParam.FilterPressure
  736. monitor.ReplacementSpeed = monitorParam.ReplacementSpeed
  737. monitor.Dicarbonate = monitorParam.Dicarbonate
  738. updateErr := service.UpdateMonitor(monitor)
  739. //记录日志
  740. byterequest, _ := json.Marshal(monitor)
  741. monitorRecordLog := models.XtMonitorRecordLog{
  742. RecordDate: monitor.MonitoringDate,
  743. PatientId: monitor.PatientId,
  744. Module: 1,
  745. AdminUserId: adminUserInfo.AdminUser.Id,
  746. Ctime: time.Now().Unix(),
  747. Mtime: 0,
  748. Status: 1,
  749. UserOrgId: monitor.UserOrgId,
  750. ErrLog: string(byterequest),
  751. Source: "电脑端修改监测",
  752. }
  753. service.CreateMonitorRecordLog(monitorRecordLog)
  754. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":monitor_records"
  755. redis := service.RedisClient()
  756. defer redis.Close()
  757. //清空key 值
  758. redis.Set(key, "", time.Second)
  759. if updateErr != nil {
  760. this.ErrorLog("修改透析监测记录失败:%v", updateErr)
  761. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  762. return
  763. }
  764. this.ServeSuccessJSON(map[string]interface{}{
  765. "monitor": monitor,
  766. })
  767. }
  768. }
  769. // /api/dialysis/start_record [post]
  770. // @param patient_id:int
  771. // @param date:string 排班时间 (yyyy-mm-dd)
  772. // @param nurse:int 上机护士
  773. // @param bed:int 上机床位号
  774. func (this *DialysisRecordAPIController) StartDialysis() {
  775. patientID, _ := this.GetInt64("patient_id")
  776. recordDateStr := this.GetString("date")
  777. nurseID, _ := this.GetInt64("nurse")
  778. punctureNurseId, _ := this.GetInt64("puncture_nurse")
  779. startDateStr := this.GetString("start_time")
  780. blood_drawing, _ := this.GetInt64("blood_drawing")
  781. schedual_type, _ := this.GetInt64("schedual_type")
  782. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  783. change_nurse, _ := this.GetInt64("change_nurse")
  784. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  785. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  786. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  787. puncture_needle := this.GetString("puncture_needle")
  788. puncture_way := this.GetString("puncture_way")
  789. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  790. dialysis_irrigation := this.GetString("dialysis_irrigation")
  791. blood_access_id, _ := this.GetInt64("blood_access_id")
  792. bedID, _ := this.GetInt64("bed")
  793. nuclein_date := this.GetString("nuclein_date")
  794. schedule_remark := this.GetString("schedule_remark")
  795. order_remark := this.GetString("order_remark")
  796. catheter_operation := this.GetString("catheter_operation")
  797. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  798. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  799. return
  800. }
  801. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  802. if parseErr != nil {
  803. this.ErrorLog("时间解析失败:%v", parseErr)
  804. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  805. return
  806. }
  807. startDate, parseErr := utils.ParseTimeStringToTime("2006-01-02 15:04", startDateStr)
  808. if parseErr != nil {
  809. this.ErrorLog("时间解析失败:%v", parseErr)
  810. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  811. return
  812. }
  813. adminUserInfo := this.GetAdminUserInfo()
  814. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.CurrentOrgId, patientID)
  815. if getPatientErr != nil {
  816. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  817. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  818. return
  819. } else if patient == nil {
  820. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  821. return
  822. }
  823. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  824. if getNurseErr != nil {
  825. this.ErrorLog("获取护士失败:%v", getNurseErr)
  826. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  827. return
  828. } else if nurse == nil {
  829. this.ErrorLog("护士不存在")
  830. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  831. return
  832. }
  833. //nurse, getNurseErr = service.GetAdminUserByUserID(punctureNurseId)
  834. //
  835. //if getNurseErr != nil {
  836. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  837. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  838. // return
  839. //} else if nurse == nil {
  840. // this.ErrorLog("护士不存在")
  841. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  842. // return
  843. //}
  844. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.CurrentOrgId, bedID)
  845. if getDeviceNumberErr != nil {
  846. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  847. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  848. return
  849. } else if deviceNumber == nil {
  850. this.ErrorLog("床位号不存在")
  851. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  852. return
  853. }
  854. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  855. if getRecordErr != nil {
  856. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  857. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  858. return
  859. } else if dialysisRecord != nil {
  860. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  861. return
  862. }
  863. template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  864. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  865. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  866. timeLayout := "2006-01-02 15:04:05"
  867. loc, _ := time.LoadLocation("Local")
  868. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  869. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  870. schedulestartTime := theStartTime.Unix()
  871. scheduleendTime := theEndTime.Unix()
  872. var theNucleinDate int64
  873. timeLayoutOne := "2006-01-02"
  874. if len(nuclein_date) > 0 {
  875. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date+" 00:00:00", loc)
  876. if err != nil {
  877. utils.ErrorLog(err.Error())
  878. }
  879. theNucleinDate = theTime.Unix()
  880. }
  881. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  882. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.CurrentOrgId, schedulestartTime, bedID, schedual_type)
  883. //查询该床位是否有人上机
  884. order, order_err := service.GetDialysisOrderByBedId(adminUserInfo.CurrentOrgId, schedulestartTime, bedID, schedual_type)
  885. if err == gorm.ErrRecordNotFound { //空床位
  886. // 修改了床位逻辑
  887. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, patientID)
  888. if daySchedule.ID > 0 {
  889. //daySchedule.PartitionId = deviceNumber.ZoneID
  890. //daySchedule.BedId = bedID
  891. //daySchedule.ScheduleType = schedual_type
  892. //daySchedule.UpdatedTime = time.Now().Unix()
  893. //err := service.UpdateSchedule(&daySchedule)
  894. xtSchedule := models.Schedule{
  895. PartitionId: deviceNumber.ZoneID,
  896. BedId: bedID,
  897. ScheduleType: schedual_type,
  898. UpdatedTime: time.Now().Unix(),
  899. }
  900. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  901. if err != nil {
  902. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  903. return
  904. }
  905. }
  906. } else if err == nil {
  907. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  908. if order_err == nil {
  909. if order.ID > 0 { //该机位被其他人占用了
  910. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  911. return
  912. } else {
  913. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, patientID)
  914. if daySchedule.ID > 0 {
  915. //daySchedule.PartitionId = deviceNumber.ZoneID
  916. //daySchedule.BedId = bedID
  917. //daySchedule.ScheduleType = schedual_type
  918. //daySchedule.UpdatedTime = time.Now().Unix()
  919. //err := service.UpdateSchedule(&daySchedule)
  920. xtSchedule := models.Schedule{
  921. PartitionId: deviceNumber.ZoneID,
  922. BedId: bedID,
  923. ScheduleType: schedual_type,
  924. UpdatedTime: time.Now().Unix(),
  925. }
  926. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  927. if err != nil {
  928. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  929. return
  930. }
  931. }
  932. }
  933. } else if order_err == gorm.ErrRecordNotFound { //该床位没被占用
  934. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, patientID)
  935. if daySchedule.ID > 0 {
  936. //daySchedule.PartitionId = deviceNumber.ZoneID
  937. //daySchedule.BedId = bedID
  938. //daySchedule.ScheduleType = schedual_type
  939. //daySchedule.UpdatedTime = time.Now().Unix()
  940. //err := service.UpdateSchedule(&daySchedule)
  941. xtSchedule := models.Schedule{
  942. PartitionId: deviceNumber.ZoneID,
  943. BedId: bedID,
  944. ScheduleType: schedual_type,
  945. UpdatedTime: time.Now().Unix(),
  946. }
  947. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  948. if err != nil {
  949. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  950. return
  951. }
  952. }
  953. } else if order_err != nil {
  954. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  955. return
  956. }
  957. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  958. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  959. return
  960. }
  961. } else if err != nil {
  962. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  963. return
  964. }
  965. // 查询信息规挡的设置天数
  966. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  967. if infor.ID > 0 && infor.WeekDay > 0 {
  968. var cha_time int64
  969. timeNowStr := time.Now().Format("2006-01-02")
  970. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  971. //今日的日期减去设置的日期
  972. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  973. if cha_time >= recordDate.Unix() {
  974. //查询审核是否允许
  975. infor, _ := service.GetDialysisInformationByRecordDate(patientID, recordDate.Unix(), adminUserInfo.CurrentOrgId, 6)
  976. //申请状态不允许的情况 拒绝修改
  977. if infor.ApplicationStatus != 1 {
  978. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  979. return
  980. }
  981. }
  982. }
  983. dialysisRecord = &models.DialysisOrder{
  984. DialysisDate: recordDate.Unix(),
  985. UserOrgId: adminUserInfo.CurrentOrgId,
  986. PatientId: patientID,
  987. Stage: 1,
  988. BedID: bedID,
  989. StartNurse: nurseID,
  990. Status: 1,
  991. StartTime: startDate.Unix(),
  992. CreatedTime: time.Now().Unix(),
  993. UpdatedTime: time.Now().Unix(),
  994. PunctureNurse: punctureNurseId,
  995. Creator: adminUserInfo.AdminUser.Id,
  996. Modifier: adminUserInfo.AdminUser.Id,
  997. SchedualType: schedual_type,
  998. WashpipeNurse: washpipe_nurse,
  999. ChangeNurse: change_nurse,
  1000. DifficultPunctureNurse: difficult_puncture_nurse,
  1001. NewFistulaNurse: new_fistula_nurse,
  1002. QualityNurseId: quality_nurse_id,
  1003. PunctureNeedle: puncture_needle,
  1004. PunctureWay: puncture_way,
  1005. DialysisDialyszers: dialysis_dialyszers,
  1006. DialysisIrrigation: dialysis_irrigation,
  1007. BloodAccessId: blood_access_id,
  1008. NucleinDate: theNucleinDate,
  1009. ScheduleRemark: schedule_remark,
  1010. OrderRemark: order_remark,
  1011. CatheterOperation: catheter_operation,
  1012. }
  1013. createErr := service.MobileCreateDialysisOrder(adminUserInfo.CurrentOrgId, patientID, dialysisRecord)
  1014. finish := models.XtDialysisFinish{
  1015. IsFinish: 1,
  1016. UserOrgId: adminUserInfo.CurrentOrgId,
  1017. Status: 1,
  1018. Ctime: time.Now().Unix(),
  1019. Mtime: 0,
  1020. Module: 6,
  1021. RecordDate: recordDate.Unix(),
  1022. Sourse: 1,
  1023. PatientId: patientID,
  1024. }
  1025. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 6, patientID)
  1026. if dialysisFinish.ID == 0 {
  1027. service.CreateDialysisFinish(finish)
  1028. }
  1029. //更新患者表排班备注
  1030. service.UpdateMobilePatient(adminUserInfo.CurrentOrgId, patientID, schedule_remark)
  1031. ////统计该患者总次数
  1032. //dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.CurrentOrgId, patientID)
  1033. //
  1034. //service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.CurrentOrgId, dialysisCount.Count)
  1035. if adminUserInfo.CurrentOrgId != 10101 && adminUserInfo.CurrentOrgId != 10445 && adminUserInfo.CurrentOrgId != 3877 && adminUserInfo.CurrentOrgId != 10345 {
  1036. //统计该患者总次数
  1037. dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.CurrentOrgId, patientID)
  1038. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.CurrentOrgId, dialysisCount.Count)
  1039. }
  1040. if adminUserInfo.CurrentOrgId == 10101 || adminUserInfo.CurrentOrgId == 10445 || adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 10345 {
  1041. //统计该患者总次数
  1042. dialysisCount, _ := service.GetDialysisTotalCountOne(adminUserInfo.CurrentOrgId, patientID)
  1043. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.CurrentOrgId, dialysisCount.Count)
  1044. }
  1045. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  1046. redis := service.RedisClient()
  1047. //清空key 值
  1048. redis.Set(key, "", time.Second)
  1049. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  1050. redis.Set(keyOne, "", time.Second)
  1051. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1052. //清空key 值
  1053. redis.Set(keyTwo, "", time.Second)
  1054. defer redis.Close()
  1055. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1056. if createErr != nil {
  1057. this.ErrorLog("上机失败:%v", createErr)
  1058. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1059. return
  1060. } else if createErr == nil {
  1061. var tempdispose string
  1062. // 只针对中能建
  1063. if blood_drawing > 0 && adminUserInfo.CurrentOrgId == 9538 { //adminUserInfo.CurrentOrgId == 9538
  1064. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  1065. }
  1066. if blood_drawing > 0 && adminUserInfo.CurrentOrgId == 10318 { //adminUserInfo.CurrentOrgId == 9538
  1067. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  1068. }
  1069. var ultrafiltration_rate float64
  1070. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.CurrentOrgId)
  1071. //获取预增水量
  1072. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, schedulestartTime, adminUserInfo.CurrentOrgId)
  1073. if prescription.ID > 0 {
  1074. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  1075. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  1076. //fmt.Println("total23232323232322332", totalMin)
  1077. if (template.TemplateId == 6 || template.TemplateId == 20 || template.TemplateId == 22 || template.TemplateId == 32 || template.TemplateId == 36) && adminUserInfo.CurrentOrgId != 9671 {
  1078. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  1079. }
  1080. //针对福建医师汇
  1081. if template.TemplateId == 6 && adminUserInfo.CurrentOrgId == 10121 {
  1082. if evaluation.ID > 0 {
  1083. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  1084. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  1085. }
  1086. }
  1087. if template.TemplateId == 6 && adminUserInfo.CurrentOrgId == 10234 {
  1088. if evaluation.ID > 0 {
  1089. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  1090. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  1091. }
  1092. }
  1093. // 只针对方济医院
  1094. if template.TemplateId == 1 && adminUserInfo.CurrentOrgId != 9849 {
  1095. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  1096. ultrafiltration_rate = value
  1097. }
  1098. //针对监利大垸医院
  1099. if adminUserInfo.CurrentOrgId == 10101 {
  1100. if evaluation.ID > 0 {
  1101. ultrafiltration_rate = math.Ceil(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  1102. }
  1103. }
  1104. //针对肇庆三鹤血液透析中心
  1105. if adminUserInfo.CurrentOrgId == 10215 || template.TemplateId == 43 || adminUserInfo.CurrentOrgId == 10441 || adminUserInfo.CurrentOrgId == 10445 || adminUserInfo.CurrentOrgId == 10469 {
  1106. if evaluation.ID > 0 {
  1107. ultrafiltration_rate = math.Ceil(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  1108. }
  1109. }
  1110. }
  1111. }
  1112. record := models.MonitoringRecord{
  1113. UserOrgId: adminUserInfo.CurrentOrgId,
  1114. PatientId: patientID,
  1115. DialysisOrderId: dialysisRecord.ID,
  1116. MonitoringDate: schedulestartTime,
  1117. OperateTime: startDate.Unix(),
  1118. // MonitoringTime: recordTime,
  1119. MonitoringNurse: nurseID,
  1120. Dispose: tempdispose,
  1121. UltrafiltrationRate: ultrafiltration_rate,
  1122. UltrafiltrationVolume: 0,
  1123. Status: 1,
  1124. CreatedTime: time.Now().Unix(),
  1125. UpdatedTime: time.Now().Unix(),
  1126. }
  1127. //只针对广慈医院
  1128. 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 {
  1129. // 查询病人是否有透前评估数据
  1130. befor, errcode := service.GetAssessmentBefor(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1131. //如果有数据就插入
  1132. if errcode == nil {
  1133. record.SystolicBloodPressure = befor.SystolicBloodPressure
  1134. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  1135. record.BreathingRate = befor.BreathingRate
  1136. record.PulseFrequency = befor.PulseFrequency
  1137. record.Temperature = befor.Temperature
  1138. }
  1139. }
  1140. // 如果当天有插入数据,则不再往透析纪录里插入数据
  1141. if newdialysisRecord.ID > 0 {
  1142. //针对长沙南雅医院
  1143. if adminUserInfo.CurrentOrgId == 9675 || adminUserInfo.CurrentOrgId == 10340 {
  1144. record.Temperature = 36.5
  1145. record.ArterialPressure = -100
  1146. record.Conductivity = 14
  1147. record.BreathingRate = "20"
  1148. record.DialysateTemperature = 36.5
  1149. record.VenousPressure = 80
  1150. record.TransmembranePressure = 60
  1151. }
  1152. // 针对灵山圣康
  1153. if adminUserInfo.CurrentOrgId == 10375 {
  1154. record.DialysateTemperature = 37
  1155. record.Conductivity = 13.8
  1156. record.DialysateFlow = 500
  1157. record.BloodFlowVolume = 200
  1158. record.BreathingRate = "18"
  1159. record.SodiumConcentration = 140
  1160. }
  1161. //针对新化博翔
  1162. if adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 10447 {
  1163. record.BloodOxygenSaturation = "99"
  1164. record.Conductivity = 14
  1165. record.DialysateTemperature = 36.5
  1166. record.BreathingRate = "20"
  1167. }
  1168. //针对蓬安济民
  1169. if adminUserInfo.CurrentOrgId == 9829 || adminUserInfo.CurrentOrgId == 10440 {
  1170. record.Temperature = 36.5
  1171. record.PulseFrequency = 80
  1172. }
  1173. //针对兰溪人民医院的需求
  1174. if adminUserInfo.CurrentOrgId == 10432 {
  1175. befor, _ := service.GetAssessmentBefor(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1176. record.SystolicBloodPressure = befor.SystolicBloodPressure
  1177. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  1178. record.Temperature = befor.Temperature
  1179. record.PulseFrequency = befor.PulseFrequency
  1180. }
  1181. err := service.CreateMonitor(&record)
  1182. //记录日志
  1183. byterequest, _ := json.Marshal(record)
  1184. monitorRecordLog := models.XtMonitorRecordLog{
  1185. RecordDate: record.MonitoringDate,
  1186. PatientId: record.PatientId,
  1187. Module: 1,
  1188. AdminUserId: adminUserInfo.AdminUser.Id,
  1189. Ctime: time.Now().Unix(),
  1190. Mtime: 0,
  1191. Status: 1,
  1192. UserOrgId: record.UserOrgId,
  1193. ErrLog: string(byterequest),
  1194. Source: "电脑端执行上机新建监测",
  1195. }
  1196. service.CreateMonitorRecordLog(monitorRecordLog)
  1197. finish := models.XtDialysisFinish{
  1198. IsFinish: 1,
  1199. UserOrgId: adminUserInfo.CurrentOrgId,
  1200. Status: 1,
  1201. Ctime: time.Now().Unix(),
  1202. Mtime: 0,
  1203. Module: 7,
  1204. RecordDate: recordDate.Unix(),
  1205. Sourse: 1,
  1206. PatientId: patientID,
  1207. }
  1208. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 7, patientID)
  1209. if dialysisFinish.ID == 0 {
  1210. service.CreateDialysisFinish(finish)
  1211. }
  1212. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_records"
  1213. redis := service.RedisClient()
  1214. //清空key 值
  1215. redis.Set(key, "", time.Second)
  1216. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_record_list_all"
  1217. redis.Set(keyOne, "", time.Second)
  1218. defer redis.Close()
  1219. if err != nil {
  1220. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  1221. return
  1222. }
  1223. }
  1224. go func() {
  1225. ssoDomain := beego.AppConfig.String("call_domain")
  1226. api := ssoDomain + "/index/uppatient"
  1227. values := make(url.Values)
  1228. values.Set("org_id", strconv.FormatInt(adminUserInfo.CurrentOrgId, 10))
  1229. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  1230. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  1231. values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
  1232. http.PostForm(api, values)
  1233. }()
  1234. this.ServeSuccessJSON(map[string]interface{}{
  1235. "dialysis_order": dialysisRecord,
  1236. "monitor": record,
  1237. })
  1238. }
  1239. }
  1240. // /api/dialysis/finish [post]
  1241. // @param patient_id:int
  1242. // @param date:string 排班时间 (yyyy-mm-dd)
  1243. // @param nurse:int 下机护士
  1244. func (this *DialysisRecordAPIController) FinishDialysis() {
  1245. patientID, _ := this.GetInt64("patient_id")
  1246. recordDateStr := this.GetString("date")
  1247. nurseID, _ := this.GetInt64("nurse")
  1248. end_time := this.GetString("end_time")
  1249. puncture_point_haematoma, _ := this.GetInt64("puncture_point_haematoma")
  1250. internal_fistula := this.GetString("internal_fistula")
  1251. catheter := this.GetString("catheter")
  1252. cruor := this.GetString("cruor")
  1253. mission := this.GetString("mission")
  1254. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 {
  1255. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1256. return
  1257. }
  1258. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1259. if parseErr != nil {
  1260. this.ErrorLog("时间解析失败:%v", parseErr)
  1261. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1262. return
  1263. }
  1264. //if parseEndDateErr != nil {
  1265. // this.ErrorLog("时间解析失败:%v", parseEndDateErr)
  1266. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1267. // return
  1268. //}
  1269. adminUserInfo := this.GetAdminUserInfo()
  1270. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.CurrentOrgId, patientID)
  1271. if getPatientErr != nil {
  1272. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  1273. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1274. return
  1275. } else if patient == nil {
  1276. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1277. return
  1278. }
  1279. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  1280. if getNurseErr != nil {
  1281. this.ErrorLog("获取护士失败:%v", getNurseErr)
  1282. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1283. return
  1284. } else if nurse == nil {
  1285. this.ErrorLog("护士不存在")
  1286. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1287. return
  1288. }
  1289. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1290. if getRecordErr != nil {
  1291. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  1292. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1293. return
  1294. }
  1295. if dialysisRecord.Stage == 2 {
  1296. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  1297. return
  1298. }
  1299. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04", end_time)
  1300. if parseEndDateErr != nil {
  1301. this.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  1302. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1303. return
  1304. }
  1305. // 获取当天的第一条透析纪录
  1306. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1307. if getMonitorRecordsErr != nil {
  1308. this.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  1309. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1310. return
  1311. }
  1312. // 获取当前的最后一条透析纪录
  1313. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecord(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1314. if getMonitorRecordsErr != nil {
  1315. this.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  1316. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1317. return
  1318. }
  1319. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysis(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1320. if getAADErr != nil {
  1321. this.ErrorLog("获取透后评估失败:%v", getAADErr)
  1322. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1323. return
  1324. }
  1325. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysis(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1326. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  1327. if assessmentAfterDislysis != nil {
  1328. tempassessmentAfterDislysis = *assessmentAfterDislysis
  1329. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  1330. } else {
  1331. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  1332. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  1333. tempassessmentAfterDislysis.Status = 1
  1334. tempassessmentAfterDislysis.PatientId = patientID
  1335. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.CurrentOrgId
  1336. }
  1337. if dialysisRecord.Stage == 1 {
  1338. temp_time := (float64(endDate.Unix()) - float64(dialysisRecord.StartTime)) / 3600
  1339. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  1340. fmt.Println(value)
  1341. a, b := math.Modf(value)
  1342. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  1343. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  1344. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  1345. fmt.Println(hour)
  1346. fmt.Println(minute)
  1347. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  1348. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  1349. }
  1350. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  1351. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  1352. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  1353. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  1354. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  1355. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  1356. //长沙南雅
  1357. if adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 9675 || adminUserInfo.CurrentOrgId == 10340 {
  1358. //获取最后一条透析处方数据
  1359. prescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1360. evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1361. tempassessmentAfterDislysis.WeightAfter = evaluation.WeightBefore - prescription.TargetUltrafiltration/1000
  1362. }
  1363. if adminUserInfo.CurrentOrgId == 10101 {
  1364. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  1365. } else {
  1366. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  1367. }
  1368. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  1369. //新化博翔
  1370. if adminUserInfo.CurrentOrgId == 10447 || adminUserInfo.CurrentOrgId == 9675 {
  1371. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  1372. }
  1373. //针对蓬安
  1374. if adminUserInfo.CurrentOrgId == 9829 || adminUserInfo.CurrentOrgId == 10440 {
  1375. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  1376. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  1377. }
  1378. }
  1379. if adminUserInfo.CurrentOrgId == 9583 {
  1380. //获取最后一条透析处方数据
  1381. prescription, parseErr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1382. if parseErr != nil {
  1383. this.ErrorLog("获取透析处方失败:%v", getMonitorRecordsErr)
  1384. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1385. return
  1386. }
  1387. if prescription.ID > 0 && adminUserInfo.CurrentOrgId == 9583 {
  1388. tempassessmentAfterDislysis.ActualUltrafiltration = prescription.TargetUltrafiltration
  1389. }
  1390. if endmonitorRecords.ID > 0 && adminUserInfo.CurrentOrgId == 10060 {
  1391. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  1392. }
  1393. }
  1394. if lastAssessmentAfterDislysis != nil {
  1395. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  1396. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  1397. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  1398. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  1399. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  1400. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  1401. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  1402. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  1403. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  1404. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  1405. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  1406. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  1407. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  1408. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  1409. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  1410. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  1411. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  1412. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  1413. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  1414. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  1415. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  1416. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  1417. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  1418. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  1419. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  1420. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  1421. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  1422. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  1423. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  1424. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  1425. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  1426. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  1427. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  1428. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  1429. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  1430. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  1431. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  1432. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  1433. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  1434. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  1435. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  1436. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  1437. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  1438. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  1439. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  1440. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  1441. if adminUserInfo.CurrentOrgId == 10375 {
  1442. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  1443. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  1444. }
  1445. }
  1446. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  1447. finishS := models.XtDialysisFinish{
  1448. IsFinish: 1,
  1449. UserOrgId: adminUserInfo.CurrentOrgId,
  1450. Status: 1,
  1451. Ctime: time.Now().Unix(),
  1452. Mtime: 0,
  1453. Module: 9,
  1454. RecordDate: recordDate.Unix(),
  1455. Sourse: 1,
  1456. PatientId: patientID,
  1457. }
  1458. dialysisFinishs, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 9, patientID)
  1459. if dialysisFinishs.ID == 0 {
  1460. service.CreateDialysisFinish(finishS)
  1461. }
  1462. 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 {
  1463. evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1464. if evaluation.SystolicBloodPressure == 0 {
  1465. pre := models.PredialysisEvaluation{
  1466. SystolicBloodPressure: fmonitorRecords.SystolicBloodPressure,
  1467. }
  1468. fmt.Println("prew", pre)
  1469. getNurseErr := service.UpdatePredialysisEvaluation(&pre, evaluation.ID)
  1470. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  1471. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  1472. redis := service.RedisClient()
  1473. redis.Set(key, "", time.Second)
  1474. redis.Set(keyOne, "", time.Second)
  1475. defer redis.Close()
  1476. fmt.Println(getNurseErr)
  1477. }
  1478. if evaluation.DiastolicBloodPressure == 0 {
  1479. pres := models.PredialysisEvaluation{
  1480. DiastolicBloodPressure: fmonitorRecords.DiastolicBloodPressure,
  1481. }
  1482. getNurseErr := service.UpdatePredialysisEvaluationTwo(&pres, evaluation.ID)
  1483. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  1484. redis := service.RedisClient()
  1485. redis.Set(key, "", time.Second)
  1486. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  1487. redis.Set(keyOne, "", time.Second)
  1488. defer redis.Close()
  1489. fmt.Println(getNurseErr)
  1490. }
  1491. if evaluation.PulseFrequency == 0 {
  1492. evaluation.PulseFrequency = fmonitorRecords.PulseFrequency
  1493. press := models.PredialysisEvaluation{
  1494. PulseFrequency: evaluation.PulseFrequency,
  1495. }
  1496. getNurseErr := service.UpdatePredialysisEvaluationThree(&press, evaluation.ID)
  1497. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  1498. redis := service.RedisClient()
  1499. redis.Set(key, "", time.Second)
  1500. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  1501. redis.Set(keyOne, "", time.Second)
  1502. defer redis.Close()
  1503. fmt.Println(getNurseErr)
  1504. }
  1505. if evaluation.Temperature == 0 {
  1506. evaluation.Temperature = fmonitorRecords.Temperature
  1507. press := models.PredialysisEvaluation{
  1508. Temperature: evaluation.Temperature,
  1509. }
  1510. getNurseErr := service.UpdatePredialysisEvaluationFour(&press, evaluation.ID)
  1511. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  1512. redis := service.RedisClient()
  1513. redis.Set(key, "", time.Second)
  1514. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  1515. redis.Set(keyOne, "", time.Second)
  1516. defer redis.Close()
  1517. fmt.Println(getNurseErr)
  1518. }
  1519. }
  1520. if err != nil {
  1521. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1522. return
  1523. }
  1524. go func() {
  1525. ssoDomain := beego.AppConfig.String("call_domain")
  1526. api := ssoDomain + "/index/downpatient"
  1527. values := make(url.Values)
  1528. values.Set("org_id", strconv.FormatInt(adminUserInfo.CurrentOrgId, 10))
  1529. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  1530. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  1531. http.PostForm(api, values)
  1532. }()
  1533. // 查询信息规挡的设置天数
  1534. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  1535. if infor.ID > 0 && infor.WeekDay > 0 {
  1536. var cha_time int64
  1537. timeNowStr := time.Now().Format("2006-01-02")
  1538. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1539. //今日的日期减去设置的日期
  1540. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1541. if cha_time >= recordDate.Unix() {
  1542. //查询审核是否允许
  1543. infor, _ := service.GetDialysisInformationByRecordDate(patientID, recordDate.Unix(), adminUserInfo.CurrentOrgId, 8)
  1544. //申请状态不允许的情况 拒绝修改
  1545. if infor.ApplicationStatus != 1 {
  1546. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1547. return
  1548. }
  1549. }
  1550. }
  1551. //执行下机
  1552. updateErr := service.ModifyDialysisRecord(dialysisRecord.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id, puncture_point_haematoma, internal_fistula, catheter, cruor, mission)
  1553. finish := models.XtDialysisFinish{
  1554. IsFinish: 1,
  1555. UserOrgId: adminUserInfo.CurrentOrgId,
  1556. Status: 1,
  1557. Ctime: time.Now().Unix(),
  1558. Mtime: 0,
  1559. Module: 8,
  1560. RecordDate: recordDate.Unix(),
  1561. Sourse: 1,
  1562. PatientId: patientID,
  1563. }
  1564. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 8, patientID)
  1565. if dialysisFinish.ID == 0 {
  1566. service.CreateDialysisFinish(finish)
  1567. }
  1568. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  1569. redis := service.RedisClient()
  1570. defer redis.Close()
  1571. //清空key 值
  1572. redis.Set(key, "", time.Second)
  1573. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  1574. redis.Set(keyOne, "", time.Second)
  1575. if updateErr != nil {
  1576. this.ErrorLog("下机失败:%v", updateErr)
  1577. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1578. return
  1579. } else {
  1580. dialysisRecord.Stage = 2
  1581. dialysisRecord.FinishNurse = nurseID
  1582. dialysisRecord.FinishCreator = adminUserInfo.AdminUser.Id
  1583. dialysisRecord.FinishModifier = adminUserInfo.AdminUser.Id
  1584. dialysisRecord.EndTime = endDate.Unix()
  1585. // 结束时候透析次数加1
  1586. service.UpdateSolutionByPatientId(patientID)
  1587. this.ServeSuccessJSON(map[string]interface{}{
  1588. "dialysis_order": dialysisRecord,
  1589. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  1590. })
  1591. }
  1592. }
  1593. func (this *DialysisRecordAPIController) ModifyStartDialysis() {
  1594. record_id, _ := this.GetInt64("id")
  1595. nurseID, _ := this.GetInt64("nurse")
  1596. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  1597. bedID, _ := this.GetInt64("bed")
  1598. start_time := this.GetString("start_time")
  1599. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  1600. schedual_type, _ := this.GetInt64("schedual_type")
  1601. change_nurse, _ := this.GetInt64("change_nurse")
  1602. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  1603. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  1604. quality_nurse, _ := this.GetInt64("quality_nurse")
  1605. puncture_needle := this.GetString("puncture_needle")
  1606. puncture_way := this.GetString("puncture_way")
  1607. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  1608. dialysis_irrigation := this.GetString("dialysis_irrigation")
  1609. blood_access_id, _ := this.GetInt64("blood_access_id")
  1610. nuclein_date := this.GetString("nuclein_date")
  1611. schedule_remark := this.GetString("schedule_remark")
  1612. order_remark := this.GetString("order_remark")
  1613. catheter_operation := this.GetString("catheter_operation")
  1614. if record_id == 0 {
  1615. this.ErrorLog("id:%v", record_id)
  1616. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1617. return
  1618. }
  1619. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04", start_time)
  1620. if parseStartDateErr != nil {
  1621. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  1622. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1623. return
  1624. }
  1625. adminUserInfo := this.GetAdminUserInfo()
  1626. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  1627. if getNurseErr != nil {
  1628. this.ErrorLog("获取护士失败:%v", getNurseErr)
  1629. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1630. return
  1631. } else if nurse == nil {
  1632. this.ErrorLog("护士不存在")
  1633. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1634. return
  1635. }
  1636. //nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  1637. //if getNurseErr != nil {
  1638. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  1639. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1640. // return
  1641. //} else if nurse == nil {
  1642. // this.ErrorLog("护士不存在")
  1643. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1644. // return
  1645. //}
  1646. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.CurrentOrgId, bedID)
  1647. if getDeviceNumberErr != nil {
  1648. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  1649. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1650. return
  1651. } else if deviceNumber == nil {
  1652. this.ErrorLog("床位号不存在")
  1653. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1654. return
  1655. }
  1656. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  1657. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  1658. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1659. // if getPermissionErr != nil {
  1660. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1661. // return
  1662. // } else if headNursePermission == nil {
  1663. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1664. // return
  1665. // }
  1666. //}
  1667. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  1668. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  1669. timeLayout := "2006-01-02 15:04:05"
  1670. loc, _ := time.LoadLocation("Local")
  1671. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  1672. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  1673. schedulestartTime := theStartTime.Unix()
  1674. scheduleendTime := theEndTime.Unix()
  1675. var theNucleinDate int64
  1676. timeLayoutOne := "2006-01-02"
  1677. if len(nuclein_date) > 0 {
  1678. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date+" 00:00:00", loc)
  1679. if err != nil {
  1680. utils.ErrorLog(err.Error())
  1681. }
  1682. theNucleinDate = theTime.Unix()
  1683. }
  1684. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  1685. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.CurrentOrgId, schedulestartTime, bedID, schedual_type)
  1686. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  1687. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  1688. if err == gorm.ErrRecordNotFound { //空床位
  1689. // 修改了床位逻辑
  1690. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  1691. if daySchedule.ID > 0 {
  1692. //daySchedule.BedId = bedID
  1693. //daySchedule.PartitionId = deviceNumber.ZoneID
  1694. //daySchedule.ScheduleType = schedual_type
  1695. //daySchedule.UpdatedTime = time.Now().Unix()
  1696. //err := service.UpdateSchedule(&daySchedule)
  1697. xtSchedule := models.Schedule{
  1698. PartitionId: deviceNumber.ZoneID,
  1699. BedId: bedID,
  1700. ScheduleType: schedual_type,
  1701. UpdatedTime: time.Now().Unix(),
  1702. }
  1703. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  1704. if err != nil {
  1705. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1706. return
  1707. }
  1708. }
  1709. } else if err == nil {
  1710. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  1711. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  1712. if daySchedule.ID > 0 {
  1713. //daySchedule.BedId = bedID
  1714. //daySchedule.PartitionId = deviceNumber.ZoneID
  1715. //
  1716. //daySchedule.ScheduleType = schedual_type
  1717. //daySchedule.UpdatedTime = time.Now().Unix()
  1718. //err := service.UpdateSchedule(&daySchedule)
  1719. xtSchedule := models.Schedule{
  1720. PartitionId: deviceNumber.ZoneID,
  1721. BedId: bedID,
  1722. ScheduleType: schedual_type,
  1723. UpdatedTime: time.Now().Unix(),
  1724. }
  1725. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  1726. if err != nil {
  1727. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1728. return
  1729. }
  1730. }
  1731. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  1732. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  1733. return
  1734. }
  1735. } else if err != nil {
  1736. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1737. return
  1738. }
  1739. }
  1740. dialysisRecord := &models.DialysisOrder{
  1741. ID: record_id,
  1742. UserOrgId: adminUserInfo.CurrentOrgId,
  1743. BedID: bedID,
  1744. StartNurse: nurseID,
  1745. StartTime: startDate.Unix(),
  1746. PunctureNurse: puncture_nurse,
  1747. Creator: adminUserInfo.AdminUser.Id,
  1748. Modifier: adminUserInfo.AdminUser.Id,
  1749. SchedualType: schedual_type,
  1750. WashpipeNurse: washpipe_nurse,
  1751. ChangeNurse: change_nurse,
  1752. DifficultPunctureNurse: difficult_puncture_nurse,
  1753. NewFistulaNurse: new_fistula_nurse,
  1754. QualityNurseId: quality_nurse,
  1755. PunctureWay: puncture_way,
  1756. PunctureNeedle: puncture_needle,
  1757. DialysisDialyszers: dialysis_dialyszers,
  1758. DialysisIrrigation: dialysis_irrigation,
  1759. BloodAccessId: blood_access_id,
  1760. NucleinDate: theNucleinDate,
  1761. ScheduleRemark: schedule_remark,
  1762. OrderRemark: order_remark,
  1763. CatheterOperation: catheter_operation,
  1764. }
  1765. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  1766. if infor.ID > 0 && infor.WeekDay > 0 {
  1767. var cha_time int64
  1768. timeNowStr := time.Now().Format("2006-01-02")
  1769. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1770. //今日的日期减去设置的日期
  1771. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1772. if cha_time >= tempDialysisRecord.DialysisDate {
  1773. //查询审核是否允许
  1774. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate, adminUserInfo.CurrentOrgId, 6)
  1775. //申请状态不允许的情况 拒绝修改
  1776. if infor.ApplicationStatus != 1 {
  1777. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1778. return
  1779. }
  1780. }
  1781. }
  1782. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  1783. order, _ := service.GetLastPatientOrder(record_id)
  1784. service.UpdateMobilePatient(adminUserInfo.CurrentOrgId, order.PatientId, schedule_remark)
  1785. redis := service.RedisClient()
  1786. key := strconv.FormatInt(tempDialysisRecord.UserOrgId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":dialysis_order"
  1787. redis.Set(key, "", time.Second)
  1788. keyOne := strconv.FormatInt(tempDialysisRecord.UserOrgId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":dialysis_orders_list_all"
  1789. //清空key 值
  1790. redis.Set(keyOne, "", time.Second)
  1791. scheduleDateStartOne := startDate.Format("2006-01-02")
  1792. keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(tempDialysisRecord.UserOrgId, 10)
  1793. redis.Set(keyTwo, "", time.Second)
  1794. keyThree := strconv.FormatInt(tempDialysisRecord.UserOrgId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":doctor_advices"
  1795. redis.Set(keyThree, "", time.Second)
  1796. keyFour := strconv.FormatInt(tempDialysisRecord.UserOrgId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_records"
  1797. redis.Set(keyFour, "", time.Second)
  1798. keyFive := strconv.FormatInt(tempDialysisRecord.UserOrgId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":patient_info"
  1799. redis.Set(keyFive, "", time.Second)
  1800. keySix := strconv.FormatInt(tempDialysisRecord.UserOrgId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":his_doctor_advice"
  1801. redis.Set(keySix, "", time.Second)
  1802. keySeven := strconv.FormatInt(tempDialysisRecord.UserOrgId, 10) + ":" + ":device_list_all"
  1803. redis.Set(keySeven, "", time.Second)
  1804. if updateErr != nil {
  1805. this.ErrorLog("修改上机失败:%v", updateErr)
  1806. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1807. return
  1808. }
  1809. if updateErr == nil {
  1810. if tempDialysisRecord.Stage == 2 {
  1811. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  1812. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  1813. fmt.Println(value)
  1814. a, b := math.Modf(value)
  1815. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  1816. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  1817. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  1818. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  1819. redis := service.RedisClient()
  1820. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":assessment_after_dislysis_list_all"
  1821. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":dialysis_orders_list_all"
  1822. redis.Set(key, "", time.Second)
  1823. redis.Set(keyThree, "", time.Second)
  1824. redis.Close()
  1825. if updateAssessmentErr != nil {
  1826. utils.ErrorLog("%v", updateAssessmentErr)
  1827. }
  1828. after, _ := service.FindAssessmentAfterDislysisById(tempDialysisRecord.UserOrgId, tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  1829. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  1830. this.ServeSuccessJSON(map[string]interface{}{
  1831. "dialysis_order": dialysisRecords,
  1832. "after": after,
  1833. })
  1834. } else {
  1835. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  1836. this.ServeSuccessJSON(map[string]interface{}{
  1837. "dialysis_order": dialysisRecords,
  1838. })
  1839. }
  1840. }
  1841. }
  1842. func (c *DialysisRecordAPIController) ModifyFinishDialysis() {
  1843. record_id, _ := c.GetInt64("id")
  1844. nurseID, _ := c.GetInt64("nurse")
  1845. end_time := c.GetString("end_time")
  1846. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  1847. internal_fistula := c.GetString("internal_fistula")
  1848. catheter := c.GetString("catheter")
  1849. cruor := c.GetString("cruor")
  1850. mission := c.GetString("mission")
  1851. if record_id <= 0 || nurseID <= 0 {
  1852. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1853. return
  1854. }
  1855. adminUserInfo := c.GetAdminUserInfo()
  1856. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  1857. if getNurseErr != nil {
  1858. c.ErrorLog("获取护士失败:%v", getNurseErr)
  1859. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1860. return
  1861. } else if nurse == nil {
  1862. c.ErrorLog("护士不存在")
  1863. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1864. return
  1865. }
  1866. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04", end_time)
  1867. if parseEndDateErr != nil {
  1868. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  1869. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1870. return
  1871. }
  1872. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  1873. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  1874. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1875. // if getPermissionErr != nil {
  1876. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1877. // return
  1878. // } else if headNursePermission == nil {
  1879. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1880. // return
  1881. // }
  1882. //}
  1883. dialysisRecord := &models.DialysisOrder{
  1884. ID: record_id,
  1885. UserOrgId: adminUserInfo.CurrentOrgId,
  1886. EndTime: endDate.Unix(),
  1887. FinishNurse: nurseID,
  1888. FinishModifier: adminUserInfo.AdminUser.Id,
  1889. PuncturePointHaematoma: puncture_point_haematoma,
  1890. BloodAccessInternalFistula: internal_fistula,
  1891. Catheter: catheter,
  1892. Cruor: cruor,
  1893. Mission: mission,
  1894. }
  1895. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  1896. // 查询信息规挡的设置天数
  1897. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  1898. if infor.ID > 0 && infor.WeekDay > 0 {
  1899. var cha_time int64
  1900. timeNowStr := time.Now().Format("2006-01-02")
  1901. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1902. //今日的日期减去设置的日期
  1903. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1904. if cha_time >= tempDialysisRecords.DialysisDate {
  1905. //查询审核是否允许
  1906. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate, adminUserInfo.CurrentOrgId, 6)
  1907. //申请状态不允许的情况 拒绝修改
  1908. if infor.ApplicationStatus != 1 {
  1909. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1910. return
  1911. }
  1912. }
  1913. }
  1914. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_order"
  1915. redis := service.RedisClient()
  1916. defer redis.Close()
  1917. //清空key 值
  1918. redis.Set(key, "", time.Second)
  1919. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + ":dialysis_orders_list_all"
  1920. redis.Set(keyOne, "", time.Second)
  1921. if updateErr != nil {
  1922. c.ErrorLog("修改下机失败:%v", updateErr)
  1923. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1924. return
  1925. }
  1926. if updateErr == nil {
  1927. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  1928. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  1929. fmt.Println(value)
  1930. a, b := math.Modf(value)
  1931. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  1932. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  1933. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  1934. monitor, _ := service.GetLastMonitorRecord(tempDialysisRecords.UserOrgId, tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate)
  1935. updateAssessmentErr := service.UpdateAssessmentAfterDateOne(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute, monitor.BreathingRate)
  1936. if updateAssessmentErr != nil {
  1937. utils.ErrorLog("%v", updateAssessmentErr)
  1938. }
  1939. }
  1940. after, _ := service.FindAssessmentAfterDislysisById(tempDialysisRecords.UserOrgId, tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate)
  1941. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  1942. c.ServeSuccessJSON(map[string]interface{}{
  1943. "dialysis_order": dialysisRecords,
  1944. "after": after,
  1945. })
  1946. }