dialysis_record_api_controller.go 65KB

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