dialysis_record_api_controller.go 91KB

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