dialysis_record_api_controller.go 81KB

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