dialysis_record_api_controller.go 103KB

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