dialysis_record_api_controller.go 77KB

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