dialysis_record_api_controller.go 68KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685
  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 float64 `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. bedID, _ := this.GetInt64("bed")
  694. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  695. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  696. return
  697. }
  698. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  699. if parseErr != nil {
  700. this.ErrorLog("时间解析失败:%v", parseErr)
  701. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  702. return
  703. }
  704. startDate, parseErr := utils.ParseTimeStringToTime("2006-01-02 15:04", startDateStr)
  705. if parseErr != nil {
  706. this.ErrorLog("时间解析失败:%v", parseErr)
  707. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  708. return
  709. }
  710. adminUserInfo := this.GetAdminUserInfo()
  711. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.CurrentOrgId, patientID)
  712. if getPatientErr != nil {
  713. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  714. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  715. return
  716. } else if patient == nil {
  717. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  718. return
  719. }
  720. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  721. if getNurseErr != nil {
  722. this.ErrorLog("获取护士失败:%v", getNurseErr)
  723. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  724. return
  725. } else if nurse == nil {
  726. this.ErrorLog("护士不存在")
  727. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  728. return
  729. }
  730. //nurse, getNurseErr = service.GetAdminUserByUserID(punctureNurseId)
  731. //
  732. //if getNurseErr != nil {
  733. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  734. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  735. // return
  736. //} else if nurse == nil {
  737. // this.ErrorLog("护士不存在")
  738. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  739. // return
  740. //}
  741. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.CurrentOrgId, bedID)
  742. if getDeviceNumberErr != nil {
  743. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  744. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  745. return
  746. } else if deviceNumber == nil {
  747. this.ErrorLog("床位号不存在")
  748. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  749. return
  750. }
  751. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  752. if getRecordErr != nil {
  753. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  754. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  755. return
  756. } else if dialysisRecord != nil {
  757. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  758. return
  759. }
  760. template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  761. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  762. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  763. timeLayout := "2006-01-02 15:04:05"
  764. loc, _ := time.LoadLocation("Local")
  765. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  766. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  767. schedulestartTime := theStartTime.Unix()
  768. scheduleendTime := theEndTime.Unix()
  769. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  770. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.CurrentOrgId, schedulestartTime, bedID, schedual_type)
  771. //查询该床位是否有人用了
  772. order, order_err := service.GetDialysisOrderByBedId(adminUserInfo.CurrentOrgId, schedulestartTime, bedID, schedual_type)
  773. if err == gorm.ErrRecordNotFound { //空床位
  774. // 修改了床位逻辑
  775. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, patientID)
  776. if daySchedule.ID > 0 {
  777. //daySchedule.PartitionId = deviceNumber.ZoneID
  778. //daySchedule.BedId = bedID
  779. //daySchedule.ScheduleType = schedual_type
  780. //daySchedule.UpdatedTime = time.Now().Unix()
  781. //err := service.UpdateSchedule(&daySchedule)
  782. xtSchedule := models.Schedule{
  783. PartitionId: deviceNumber.ZoneID,
  784. BedId: bedID,
  785. ScheduleType: schedual_type,
  786. UpdatedTime: time.Now().Unix(),
  787. }
  788. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  789. if err != nil {
  790. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  791. return
  792. }
  793. }
  794. } else if err == nil {
  795. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  796. if order_err == nil {
  797. if order.ID > 0 { //该机位被其他人占用了
  798. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  799. return
  800. } else {
  801. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, patientID)
  802. if daySchedule.ID > 0 {
  803. //daySchedule.PartitionId = deviceNumber.ZoneID
  804. //daySchedule.BedId = bedID
  805. //daySchedule.ScheduleType = schedual_type
  806. //daySchedule.UpdatedTime = time.Now().Unix()
  807. //err := service.UpdateSchedule(&daySchedule)
  808. xtSchedule := models.Schedule{
  809. PartitionId: deviceNumber.ZoneID,
  810. BedId: bedID,
  811. ScheduleType: schedual_type,
  812. UpdatedTime: time.Now().Unix(),
  813. }
  814. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  815. if err != nil {
  816. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  817. return
  818. }
  819. }
  820. }
  821. } else if order_err == gorm.ErrRecordNotFound { //该床位没被占用
  822. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, patientID)
  823. if daySchedule.ID > 0 {
  824. //daySchedule.PartitionId = deviceNumber.ZoneID
  825. //daySchedule.BedId = bedID
  826. //daySchedule.ScheduleType = schedual_type
  827. //daySchedule.UpdatedTime = time.Now().Unix()
  828. //err := service.UpdateSchedule(&daySchedule)
  829. xtSchedule := models.Schedule{
  830. PartitionId: deviceNumber.ZoneID,
  831. BedId: bedID,
  832. ScheduleType: schedual_type,
  833. UpdatedTime: time.Now().Unix(),
  834. }
  835. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  836. if err != nil {
  837. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  838. return
  839. }
  840. }
  841. } else if order_err != nil {
  842. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  843. return
  844. }
  845. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  846. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  847. return
  848. }
  849. } else if err != nil {
  850. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  851. return
  852. }
  853. dialysisRecord = &models.DialysisOrder{
  854. DialysisDate: recordDate.Unix(),
  855. UserOrgId: adminUserInfo.CurrentOrgId,
  856. PatientId: patientID,
  857. Stage: 1,
  858. BedID: bedID,
  859. StartNurse: nurseID,
  860. Status: 1,
  861. StartTime: startDate.Unix(),
  862. CreatedTime: time.Now().Unix(),
  863. UpdatedTime: time.Now().Unix(),
  864. PunctureNurse: punctureNurseId,
  865. Creator: adminUserInfo.AdminUser.Id,
  866. Modifier: adminUserInfo.AdminUser.Id,
  867. SchedualType: schedual_type,
  868. WashpipeNurse: washpipe_nurse,
  869. ChangeNurse: change_nurse,
  870. DifficultPunctureNurse: difficult_puncture_nurse,
  871. NewFistulaNurse: new_fistula_nurse,
  872. }
  873. createErr := service.MobileCreateDialysisOrder(adminUserInfo.CurrentOrgId, patientID, dialysisRecord)
  874. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  875. redis := service.RedisClient()
  876. //清空key 值
  877. redis.Set(key, "", time.Second)
  878. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  879. redis.Set(keyOne, "", time.Second)
  880. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  881. //清空key 值
  882. redis.Set(keyTwo, "", time.Second)
  883. defer redis.Close()
  884. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  885. if createErr != nil {
  886. this.ErrorLog("上机失败:%v", createErr)
  887. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  888. return
  889. } else if createErr == nil {
  890. var tempdispose string
  891. // 只针对中能建
  892. if blood_drawing > 0 && adminUserInfo.CurrentOrgId == 9538 { //adminUserInfo.CurrentOrgId == 9538
  893. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  894. }
  895. if blood_drawing > 0 && adminUserInfo.CurrentOrgId == 10318 { //adminUserInfo.CurrentOrgId == 9538
  896. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  897. }
  898. var ultrafiltration_rate float64
  899. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.CurrentOrgId)
  900. //获取预增水量
  901. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, schedulestartTime, adminUserInfo.CurrentOrgId)
  902. if prescription.ID > 0 {
  903. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  904. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  905. fmt.Println("total23232323232322332", totalMin)
  906. if (template.TemplateId == 6 || template.TemplateId == 20 || template.TemplateId == 22 || template.TemplateId == 32 || template.TemplateId == 36) && adminUserInfo.CurrentOrgId != 9671 {
  907. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  908. }
  909. //针对福建医师汇
  910. if template.TemplateId == 6 && adminUserInfo.CurrentOrgId == 10121 {
  911. if evaluation.ID > 0 {
  912. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  913. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  914. }
  915. }
  916. if template.TemplateId == 6 && adminUserInfo.CurrentOrgId == 10234 {
  917. if evaluation.ID > 0 {
  918. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  919. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  920. }
  921. }
  922. // 只针对方济医院
  923. if template.TemplateId == 1 && adminUserInfo.CurrentOrgId != 9849 {
  924. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  925. ultrafiltration_rate = value
  926. }
  927. //针对监利大垸医院
  928. if adminUserInfo.CurrentOrgId == 10101 {
  929. if evaluation.ID > 0 {
  930. ultrafiltration_rate = math.Ceil(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  931. fmt.Println("ultrafiltration_rate", ultrafiltration_rate)
  932. }
  933. }
  934. //针对肇庆三鹤血液透析中心
  935. if adminUserInfo.CurrentOrgId == 10215 || template.TemplateId == 43 {
  936. if evaluation.ID > 0 {
  937. ultrafiltration_rate = math.Ceil(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  938. fmt.Println("hhhh2323323223322323323232", ultrafiltration_rate)
  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. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 {
  1012. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1013. return
  1014. }
  1015. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1016. if parseErr != nil {
  1017. this.ErrorLog("时间解析失败:%v", parseErr)
  1018. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1019. return
  1020. }
  1021. //if parseEndDateErr != nil {
  1022. // this.ErrorLog("时间解析失败:%v", parseEndDateErr)
  1023. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1024. // return
  1025. //}
  1026. adminUserInfo := this.GetAdminUserInfo()
  1027. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.CurrentOrgId, patientID)
  1028. if getPatientErr != nil {
  1029. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  1030. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1031. return
  1032. } else if patient == nil {
  1033. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1034. return
  1035. }
  1036. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  1037. if getNurseErr != nil {
  1038. this.ErrorLog("获取护士失败:%v", getNurseErr)
  1039. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1040. return
  1041. } else if nurse == nil {
  1042. this.ErrorLog("护士不存在")
  1043. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1044. return
  1045. }
  1046. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1047. if getRecordErr != nil {
  1048. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  1049. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1050. return
  1051. }
  1052. if dialysisRecord.Stage == 2 {
  1053. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  1054. return
  1055. }
  1056. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04", end_time)
  1057. if parseEndDateErr != nil {
  1058. this.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  1059. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1060. return
  1061. }
  1062. // 获取当天的第一条透析纪录
  1063. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1064. if getMonitorRecordsErr != nil {
  1065. this.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  1066. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1067. return
  1068. }
  1069. // 获取当前的最后一条透析纪录
  1070. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecord(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1071. if getMonitorRecordsErr != nil {
  1072. this.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  1073. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1074. return
  1075. }
  1076. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysis(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1077. if getAADErr != nil {
  1078. this.ErrorLog("获取透后评估失败:%v", getAADErr)
  1079. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1080. return
  1081. }
  1082. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysis(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1083. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  1084. if assessmentAfterDislysis != nil {
  1085. tempassessmentAfterDislysis = *assessmentAfterDislysis
  1086. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  1087. } else {
  1088. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  1089. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  1090. tempassessmentAfterDislysis.Status = 1
  1091. tempassessmentAfterDislysis.PatientId = patientID
  1092. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.CurrentOrgId
  1093. }
  1094. if dialysisRecord.Stage == 1 {
  1095. temp_time := (float64(endDate.Unix()) - float64(dialysisRecord.StartTime)) / 3600
  1096. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  1097. fmt.Println(value)
  1098. a, b := math.Modf(value)
  1099. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  1100. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  1101. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  1102. fmt.Println(hour)
  1103. fmt.Println(minute)
  1104. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  1105. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  1106. }
  1107. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  1108. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  1109. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  1110. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  1111. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  1112. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  1113. if adminUserInfo.CurrentOrgId == 10101 {
  1114. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  1115. } else {
  1116. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  1117. }
  1118. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  1119. }
  1120. if adminUserInfo.CurrentOrgId == 9583 {
  1121. //获取最后一条透析处方数据
  1122. prescription, parseErr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1123. if parseErr != nil {
  1124. this.ErrorLog("获取透析处方失败:%v", getMonitorRecordsErr)
  1125. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1126. return
  1127. }
  1128. if prescription.ID > 0 && adminUserInfo.CurrentOrgId == 9583 {
  1129. tempassessmentAfterDislysis.ActualUltrafiltration = prescription.TargetUltrafiltration
  1130. }
  1131. if endmonitorRecords.ID > 0 && adminUserInfo.CurrentOrgId == 10060 {
  1132. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  1133. }
  1134. }
  1135. if lastAssessmentAfterDislysis != nil {
  1136. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  1137. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  1138. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  1139. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  1140. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  1141. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  1142. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  1143. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  1144. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  1145. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  1146. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  1147. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  1148. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  1149. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  1150. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  1151. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  1152. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  1153. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  1154. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  1155. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  1156. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  1157. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  1158. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  1159. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  1160. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  1161. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  1162. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  1163. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  1164. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  1165. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  1166. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  1167. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  1168. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  1169. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  1170. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  1171. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  1172. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  1173. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  1174. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  1175. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  1176. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  1177. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  1178. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  1179. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  1180. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  1181. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  1182. }
  1183. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  1184. if err != nil {
  1185. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1186. return
  1187. }
  1188. go func() {
  1189. ssoDomain := beego.AppConfig.String("call_domain")
  1190. api := ssoDomain + "/index/downpatient"
  1191. values := make(url.Values)
  1192. values.Set("org_id", strconv.FormatInt(adminUserInfo.CurrentOrgId, 10))
  1193. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  1194. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  1195. http.PostForm(api, values)
  1196. }()
  1197. updateErr := service.ModifyDialysisRecord(dialysisRecord.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id)
  1198. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  1199. redis := service.RedisClient()
  1200. defer redis.Close()
  1201. //清空key 值
  1202. redis.Set(key, "", time.Second)
  1203. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  1204. redis.Set(keyOne, "", time.Second)
  1205. if updateErr != nil {
  1206. this.ErrorLog("下机失败:%v", updateErr)
  1207. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1208. return
  1209. } else {
  1210. dialysisRecord.Stage = 2
  1211. dialysisRecord.FinishNurse = nurseID
  1212. dialysisRecord.FinishCreator = adminUserInfo.AdminUser.Id
  1213. dialysisRecord.FinishModifier = adminUserInfo.AdminUser.Id
  1214. dialysisRecord.EndTime = endDate.Unix()
  1215. // 结束时候透析次数加1
  1216. service.UpdateSolutionByPatientId(patientID)
  1217. this.ServeSuccessJSON(map[string]interface{}{
  1218. "dialysis_order": dialysisRecord,
  1219. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  1220. })
  1221. }
  1222. }
  1223. func (this *DialysisRecordAPIController) ModifyStartDialysis() {
  1224. record_id, _ := this.GetInt64("id")
  1225. nurseID, _ := this.GetInt64("nurse")
  1226. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  1227. bedID, _ := this.GetInt64("bed")
  1228. start_time := this.GetString("start_time")
  1229. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  1230. schedual_type, _ := this.GetInt64("schedual_type")
  1231. change_nurse, _ := this.GetInt64("change_nurse")
  1232. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  1233. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  1234. if record_id == 0 {
  1235. this.ErrorLog("id:%v", record_id)
  1236. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1237. return
  1238. }
  1239. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04", start_time)
  1240. if parseStartDateErr != nil {
  1241. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  1242. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1243. return
  1244. }
  1245. adminUserInfo := this.GetAdminUserInfo()
  1246. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  1247. if getNurseErr != nil {
  1248. this.ErrorLog("获取护士失败:%v", getNurseErr)
  1249. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1250. return
  1251. } else if nurse == nil {
  1252. this.ErrorLog("护士不存在")
  1253. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1254. return
  1255. }
  1256. //nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  1257. //if getNurseErr != nil {
  1258. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  1259. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1260. // return
  1261. //} else if nurse == nil {
  1262. // this.ErrorLog("护士不存在")
  1263. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1264. // return
  1265. //}
  1266. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.CurrentOrgId, bedID)
  1267. if getDeviceNumberErr != nil {
  1268. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  1269. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1270. return
  1271. } else if deviceNumber == nil {
  1272. this.ErrorLog("床位号不存在")
  1273. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1274. return
  1275. }
  1276. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  1277. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  1278. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1279. // if getPermissionErr != nil {
  1280. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1281. // return
  1282. // } else if headNursePermission == nil {
  1283. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1284. // return
  1285. // }
  1286. //}
  1287. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  1288. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  1289. timeLayout := "2006-01-02 15:04:05"
  1290. loc, _ := time.LoadLocation("Local")
  1291. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  1292. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  1293. schedulestartTime := theStartTime.Unix()
  1294. scheduleendTime := theEndTime.Unix()
  1295. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  1296. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.CurrentOrgId, schedulestartTime, bedID, schedual_type)
  1297. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  1298. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  1299. if err == gorm.ErrRecordNotFound { //空床位
  1300. // 修改了床位逻辑
  1301. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  1302. if daySchedule.ID > 0 {
  1303. //daySchedule.BedId = bedID
  1304. //daySchedule.PartitionId = deviceNumber.ZoneID
  1305. //daySchedule.ScheduleType = schedual_type
  1306. //daySchedule.UpdatedTime = time.Now().Unix()
  1307. //err := service.UpdateSchedule(&daySchedule)
  1308. xtSchedule := models.Schedule{
  1309. PartitionId: deviceNumber.ZoneID,
  1310. BedId: bedID,
  1311. ScheduleType: schedual_type,
  1312. UpdatedTime: time.Now().Unix(),
  1313. }
  1314. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  1315. if err != nil {
  1316. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1317. return
  1318. }
  1319. }
  1320. } else if err == nil {
  1321. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  1322. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  1323. if daySchedule.ID > 0 {
  1324. //daySchedule.BedId = bedID
  1325. //daySchedule.PartitionId = deviceNumber.ZoneID
  1326. //
  1327. //daySchedule.ScheduleType = schedual_type
  1328. //daySchedule.UpdatedTime = time.Now().Unix()
  1329. //err := service.UpdateSchedule(&daySchedule)
  1330. xtSchedule := models.Schedule{
  1331. PartitionId: deviceNumber.ZoneID,
  1332. BedId: bedID,
  1333. ScheduleType: schedual_type,
  1334. UpdatedTime: time.Now().Unix(),
  1335. }
  1336. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  1337. if err != nil {
  1338. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1339. return
  1340. }
  1341. }
  1342. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  1343. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  1344. return
  1345. }
  1346. } else if err != nil {
  1347. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1348. return
  1349. }
  1350. }
  1351. dialysisRecord := &models.DialysisOrder{
  1352. ID: record_id,
  1353. UserOrgId: adminUserInfo.CurrentOrgId,
  1354. BedID: bedID,
  1355. StartNurse: nurseID,
  1356. StartTime: startDate.Unix(),
  1357. PunctureNurse: puncture_nurse,
  1358. Creator: adminUserInfo.AdminUser.Id,
  1359. Modifier: adminUserInfo.AdminUser.Id,
  1360. SchedualType: schedual_type,
  1361. WashpipeNurse: washpipe_nurse,
  1362. ChangeNurse: change_nurse,
  1363. DifficultPunctureNurse: difficult_puncture_nurse,
  1364. NewFistulaNurse: new_fistula_nurse,
  1365. }
  1366. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  1367. redis := service.RedisClient()
  1368. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(startDate.Unix(), 10) + ":dialysis_orders_list_all"
  1369. redis.Set(key, "", time.Second)
  1370. redis.Close()
  1371. if updateErr != nil {
  1372. this.ErrorLog("修改上机失败:%v", updateErr)
  1373. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1374. return
  1375. }
  1376. if updateErr == nil {
  1377. if tempDialysisRecord.Stage == 2 {
  1378. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  1379. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  1380. fmt.Println(value)
  1381. a, b := math.Modf(value)
  1382. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  1383. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  1384. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  1385. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  1386. redis := service.RedisClient()
  1387. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":assessment_after_dislysis_list_all"
  1388. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":dialysis_orders_list_all"
  1389. redis.Set(key, "", time.Second)
  1390. redis.Set(keyThree, "", time.Second)
  1391. redis.Close()
  1392. if updateAssessmentErr != nil {
  1393. utils.ErrorLog("%v", updateAssessmentErr)
  1394. }
  1395. after, _ := service.FindAssessmentAfterDislysisById(tempDialysisRecord.UserOrgId, tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  1396. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  1397. this.ServeSuccessJSON(map[string]interface{}{
  1398. "dialysis_order": dialysisRecords,
  1399. "after": after,
  1400. })
  1401. } else {
  1402. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  1403. this.ServeSuccessJSON(map[string]interface{}{
  1404. "dialysis_order": dialysisRecords,
  1405. })
  1406. }
  1407. }
  1408. }
  1409. func (c *DialysisRecordAPIController) ModifyFinishDialysis() {
  1410. record_id, _ := c.GetInt64("id")
  1411. nurseID, _ := c.GetInt64("nurse")
  1412. end_time := c.GetString("end_time")
  1413. if record_id <= 0 || nurseID <= 0 {
  1414. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1415. return
  1416. }
  1417. adminUserInfo := c.GetAdminUserInfo()
  1418. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  1419. if getNurseErr != nil {
  1420. c.ErrorLog("获取护士失败:%v", getNurseErr)
  1421. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1422. return
  1423. } else if nurse == nil {
  1424. c.ErrorLog("护士不存在")
  1425. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1426. return
  1427. }
  1428. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04", end_time)
  1429. if parseEndDateErr != nil {
  1430. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  1431. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1432. return
  1433. }
  1434. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  1435. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  1436. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1437. // if getPermissionErr != nil {
  1438. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1439. // return
  1440. // } else if headNursePermission == nil {
  1441. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1442. // return
  1443. // }
  1444. //}
  1445. dialysisRecord := &models.DialysisOrder{
  1446. ID: record_id,
  1447. UserOrgId: adminUserInfo.CurrentOrgId,
  1448. EndTime: endDate.Unix(),
  1449. FinishNurse: nurseID,
  1450. FinishModifier: adminUserInfo.AdminUser.Id,
  1451. }
  1452. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  1453. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_order"
  1454. redis := service.RedisClient()
  1455. defer redis.Close()
  1456. //清空key 值
  1457. redis.Set(key, "", time.Second)
  1458. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + ":dialysis_orders_list_all"
  1459. redis.Set(keyOne, "", time.Second)
  1460. if updateErr != nil {
  1461. c.ErrorLog("修改下机失败:%v", updateErr)
  1462. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1463. return
  1464. }
  1465. if updateErr == nil {
  1466. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  1467. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  1468. fmt.Println(value)
  1469. a, b := math.Modf(value)
  1470. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  1471. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  1472. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  1473. monitor, _ := service.GetLastMonitorRecord(tempDialysisRecords.UserOrgId, tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate)
  1474. updateAssessmentErr := service.UpdateAssessmentAfterDateOne(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute, monitor.BreathingRate)
  1475. if updateAssessmentErr != nil {
  1476. utils.ErrorLog("%v", updateAssessmentErr)
  1477. }
  1478. }
  1479. after, _ := service.FindAssessmentAfterDislysisById(tempDialysisRecords.UserOrgId, tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate)
  1480. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  1481. c.ServeSuccessJSON(map[string]interface{}{
  1482. "dialysis_order": dialysisRecords,
  1483. "after": after,
  1484. })
  1485. }