dialysis_record_api_controller.go 103KB

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