dialysis_record_api_controller.go 75KB

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