dialysis_record_api_controller.go 90KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247
  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. //统计表
  343. dryWeightList, _ := service.GetPatientDryWeight(adminInfo.CurrentOrgId, patientID)
  344. allDoctor, _ := service.GetAllDoctor(adminInfo.CurrentOrgId, adminInfo.CurrentAppId)
  345. if getDryErr != nil {
  346. this.ErrorLog("获取最后一条干体重失败:%v", getDryErr)
  347. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  348. return
  349. }
  350. headNurses, _ := service.GetAllSpecialPermissionAdminUsersWithoutStatus(adminInfo.CurrentOrgId, adminInfo.CurrentAppId, models.SpecialPermissionTypeHeadNurse)
  351. var his_advices []*models.HisDoctorAdviceInfo
  352. if is_open_config.IsOpen == 1 {
  353. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.CurrentOrgId, patientID, date.Unix())
  354. }
  355. //查询是否是开起
  356. adviceConfig, _ := service.FindAdviceSettingById(adminInfo.CurrentOrgId)
  357. if adviceConfig.IsAdviceOpen == 1 {
  358. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.CurrentOrgId, patientID, date.Unix())
  359. }
  360. _, errcode := service.GetOrgFollowIsExist(adminInfo.CurrentOrgId)
  361. if errcode == gorm.ErrRecordNotFound {
  362. information, _ := service.GetAdminUserRoleInformation(0)
  363. returnData := map[string]interface{}{
  364. "patient": patient,
  365. "schedual": schedual,
  366. "prescription": dialysisPrescribe,
  367. "solution": dialysisSolution,
  368. "receiver_treatment_access": receiverTreatmentAccess,
  369. "predialysis_evaluation": predialysisEvaluation,
  370. "doctor_advices": doctorAdvices,
  371. "double_check": doubleCheck,
  372. "assessment_after_dislysis": assessmentAfterDislysis,
  373. "treatment_summary": treatmentSummary,
  374. "monitor_records": monitorRecords,
  375. "dialysis_order": dialysisOrder,
  376. "doctors": admins,
  377. "config": record,
  378. "devices": devices,
  379. "device_numbers": deviceNumbers,
  380. "lastPredialysisEvaluation": lastPredialysisEvaluation,
  381. "lastMonitorRecord": lastMonitorRecord,
  382. "lastAssessmentAfterDislysis": lastAssessmentAfterDislysis,
  383. "lastDialysisPrescribe": lastDialysisPrescribe,
  384. "lastDryWeightDislysis": lastDryWeightDislysis,
  385. "headNurses": headNurses,
  386. "system_prescribe": systemDialysisPrescribe,
  387. "his_advices": his_advices,
  388. "is_open_config": is_open_config,
  389. "stockType": stockType,
  390. "prepare": prepare,
  391. "lastAssessment": lastAssessment,
  392. "information": information,
  393. "is_advice_open": adviceConfig,
  394. "lastOrder": lastOrder,
  395. "dryWeightList": dryWeightList,
  396. "docList": allDoctor,
  397. }
  398. this.ServeSuccessJSON(returnData)
  399. } else if errcode == nil {
  400. information, _ := service.GetAdminUserRoleInformation(adminInfo.CurrentOrgId)
  401. returnData := map[string]interface{}{
  402. "patient": patient,
  403. "schedual": schedual,
  404. "prescription": dialysisPrescribe,
  405. "solution": dialysisSolution,
  406. "receiver_treatment_access": receiverTreatmentAccess,
  407. "predialysis_evaluation": predialysisEvaluation,
  408. "doctor_advices": doctorAdvices,
  409. "double_check": doubleCheck,
  410. "assessment_after_dislysis": assessmentAfterDislysis,
  411. "treatment_summary": treatmentSummary,
  412. "monitor_records": monitorRecords,
  413. "dialysis_order": dialysisOrder,
  414. "doctors": admins,
  415. "config": record,
  416. "devices": devices,
  417. "device_numbers": deviceNumbers,
  418. "lastPredialysisEvaluation": lastPredialysisEvaluation,
  419. "lastMonitorRecord": lastMonitorRecord,
  420. "lastAssessmentAfterDislysis": lastAssessmentAfterDislysis,
  421. "lastDialysisPrescribe": lastDialysisPrescribe,
  422. "lastDryWeightDislysis": lastDryWeightDislysis,
  423. "headNurses": headNurses,
  424. "system_prescribe": systemDialysisPrescribe,
  425. "his_advices": his_advices,
  426. "is_open_config": is_open_config,
  427. "stockType": stockType,
  428. "prepare": prepare,
  429. "lastAssessment": lastAssessment,
  430. "information": information,
  431. "is_advice_open": adviceConfig,
  432. "lastOrder": lastOrder,
  433. "dryWeightList": dryWeightList,
  434. "docList": allDoctor,
  435. }
  436. this.ServeSuccessJSON(returnData)
  437. }
  438. }
  439. type EditMonitorParamObject struct {
  440. ID int64 `json:"id"`
  441. MonitoringDate int64 `json:"monitoring_date"`
  442. OperateTime int64 `json:"operate_time"`
  443. // MonitoringTime string `json:"monitoring_time"`
  444. SystolicBP float64 `json:"systolic_bp"`
  445. DiastolicBP float64 `json:"diastolic_bp"`
  446. PulseFrequency float64 `json:"pulse_frequency"`
  447. BreathingRated string `json:"breathing_rated"`
  448. BloodFlowVolume float64 `json:"blood_flow_volume"`
  449. VenousPressure float64 `json:"venous_pressure"`
  450. VenousPressureType int64 `json:"venous_pressure_type"`
  451. TransmembranePressure float64 `json:"transmembrane_pressure"`
  452. TransmembranePressureType int64 `json:"transmembrane_pressure_type"`
  453. UltrafiltrationVolume float64 `json:"ultrafiltration_volume"`
  454. UltrafiltrationRate float64 `json:"ultrafiltration_rate"`
  455. ArterialPressure float64 `json:"arterial_pressure"`
  456. ArterialPressureType int64 `json:"arterial_pressure_type"`
  457. SodiumConcentration float64 `json:"sodium_concentration"`
  458. DialysateTemperature float64 `json:"dialysate_temperature"`
  459. Temperature float64 `json:"temperature"`
  460. ReplacementRate float64 `json:"replacement_rate"`
  461. DisplacementQuantity float64 `json:"displacement_quantity"`
  462. KTV float64 `json:"ktv"`
  463. Symptom string `json:"symptom"`
  464. Dispose string `json:"dispose"`
  465. Result string `json:"result"`
  466. Conductivity float64 `json:"conductivity"`
  467. DisplacementFlowQuantity float64 `json:"displacement_flow_quantity"`
  468. BloodOxygenSaturation string `gorm:"column:blood_oxygen_saturation" json:"blood_oxygen_saturation" form:"blood_oxygen_saturation"`
  469. Heparin float64 `gorm:"column:heparin" json:"heparin" form:"heparin"`
  470. DialysateFlow float64 `gorm:"column:dialysate_flow" json:"dialysate_flow" form:"dialysate_flow"`
  471. Urr string `gorm:"column:urr" json:"urr" form:"urr"`
  472. BloodSugar float64 `gorm:"column:blood_sugar" json:"blood_sugar" form:"blood_sugar"`
  473. MonitorAnticoagulant int64 `gorm:"column:monitor_anticoagulant" json:"monitor_anticoagulant" form:"monitor_anticoagulant"`
  474. MonitorAnticoagulantValue string `gorm:"column:monitor_anticoagulant_value" json:"monitor_anticoagulant_value" form:"monitor_anticoagulant_value"`
  475. BloodPressureMonitoringSite int64 `gorm:"column:blood_pressure_monitoring_site" json:"blood_pressure_monitoring_site" form:"blood_pressure_monitoring_site"`
  476. Complication int64 `gorm:"column:complication" json:"complication" form:"complication"`
  477. AccumulatedBloodVolume float64 `gorm:"column:accumulated_blood_volume" json:"accumulated_blood_volume" form:"accumulated_blood_volume"`
  478. BloodTemperature float64 `gorm:"column:blood_temperature" json:"blood_temperature" form:"blood_temperature"`
  479. UreaMonitoring float64 `gorm:"column:urea_monitoring" json:"urea_monitoring" form:"urea_monitoring"`
  480. BloodThickness float64 `gorm:"column:blood_thickness" json:"blood_thickness" form:"blood_thickness"`
  481. BloodMonitor float64 `gorm:"column:blood_monitor" json:"blood_monitor" form:"blood_monitor"`
  482. HeparinAmount float64 `gorm:"column:heparin_amount" json:"heparin_amount" form:"heparin_amount"`
  483. Dehydration float64 `gorm:"column:dehydration" json:"dehydration" form:"dehydration"`
  484. FilterPressure string `gorm:"column:filter_pressure" json:"filter_pressure" form:"filter_pressure"`
  485. ReplacementSpeed float64 `gorm:"column:replacement_speed" json:"replacement_speed" form:"replacement_speed"`
  486. Dicarbonate float64 `gorm:"column:dicarbonate" json:"dicarbonate" form:"dicarbonate"`
  487. IsPressure string `gorm:"column:is_pressure" json:"is_pressure" form:"is_pressure"`
  488. }
  489. // /api/dislysis/monitor/edit [post]
  490. // @param patient_id:int 患者id
  491. // @param schedule_date:int 排班日期
  492. // 下面的参数放到 body
  493. // @param id?:int 监测记录ID(id为0时为创建记录,不为0时为修改记录)
  494. // @param monitoring_date:int 排班日期
  495. // @param operate_time:int 实际测量日期
  496. // @param monitoring_time:string (HH:mm) 监测时间 废弃
  497. // @param systolic_bp?:float 收缩压
  498. // @param diastolic_bp?:float 舒张压
  499. // @param pulse_frequency?:float 心率
  500. // @param breathing_rated?:float 呼吸频率
  501. // @param blood_flow_volume?:float 血流量
  502. // @param venous_pressure?:float 静脉压
  503. // @param transmembrane_pressure?:float 跨膜压
  504. // @param ultrafiltration_volume?:float 超滤量
  505. // @param ultrafiltration_rate?:float 超滤率
  506. // @param arterial_pressure?:float 动脉压
  507. // @param sodium_concentration?:float 钠浓度
  508. // @param dialysate_temperature?:float 透析液温度
  509. // @param replacement_rate?:float 置换率
  510. // @param displacement_quantity?:float 置换量
  511. // @param ktv?:float KT/V
  512. // @param symptom?:string 病情变化
  513. // @param dispose?:string 处理
  514. // @param result?:string 结果
  515. func (this *DialysisRecordAPIController) EditMonitor() {
  516. patientID, _ := this.GetInt64("patient_id")
  517. scheduleDate, _ := this.GetInt64("schedule_date")
  518. if patientID <= 0 || scheduleDate <= 0 {
  519. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  520. return
  521. }
  522. var monitorParam EditMonitorParamObject
  523. if parseErr := json.Unmarshal(this.Ctx.Input.RequestBody, &monitorParam); parseErr != nil {
  524. this.ErrorLog("参数解析失败:%v", parseErr)
  525. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamFormatWrong)
  526. return
  527. }
  528. if monitorParam.MonitoringDate != scheduleDate {
  529. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  530. return
  531. }
  532. adminUserInfo := this.GetAdminUserInfo()
  533. schedule, getScheduleErr := service.MobileGetSchedualDetail(adminUserInfo.CurrentOrgId, patientID, scheduleDate)
  534. if getScheduleErr != nil {
  535. this.ErrorLog("获取排班信息失败:%v", getScheduleErr)
  536. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  537. return
  538. } else if schedule == nil {
  539. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist)
  540. return
  541. }
  542. // TODO 其实这里合理的逻辑是“透析记录存在的情况下才能添加监测记录的”
  543. dialysisOrder, getDialysisOrderErr := service.MobileGetDialysisRecord(adminUserInfo.CurrentOrgId, patientID, scheduleDate)
  544. if getDialysisOrderErr != nil {
  545. this.ErrorLog("获取透析记录失败:%v", getDialysisOrderErr)
  546. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  547. return
  548. }
  549. orderID := int64(0)
  550. if dialysisOrder != nil {
  551. orderID = dialysisOrder.ID
  552. }
  553. // 查询信息规挡的设置天数
  554. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  555. if infor.ID > 0 && infor.WeekDay > 0 {
  556. var cha_time int64
  557. timeNowStr := time.Now().Format("2006-01-02")
  558. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  559. //今日的日期减去设置的日期
  560. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  561. if cha_time >= scheduleDate && infor.WeekDay != 0 {
  562. //查询审核是否允许
  563. infor, _ := service.GetDialysisInformationByRecordDate(patientID, scheduleDate, adminUserInfo.CurrentOrgId, 7)
  564. //申请状态不允许的情况 拒绝修改
  565. if infor.ApplicationStatus != 1 {
  566. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  567. return
  568. }
  569. }
  570. }
  571. if monitorParam.ID <= 0 { // 新建记录
  572. monitor := models.MonitoringRecord{
  573. UserOrgId: adminUserInfo.CurrentOrgId,
  574. PatientId: patientID,
  575. DialysisOrderId: orderID,
  576. MonitoringDate: monitorParam.MonitoringDate,
  577. OperateTime: monitorParam.OperateTime,
  578. // MonitoringTime: monitorParam.MonitoringTime,
  579. PulseFrequency: monitorParam.PulseFrequency,
  580. BreathingRate: monitorParam.BreathingRated,
  581. SystolicBloodPressure: monitorParam.SystolicBP,
  582. DiastolicBloodPressure: monitorParam.DiastolicBP,
  583. BloodFlowVolume: monitorParam.BloodFlowVolume,
  584. VenousPressure: monitorParam.VenousPressure,
  585. VenousPressureType: monitorParam.VenousPressureType,
  586. ArterialPressure: monitorParam.ArterialPressure,
  587. ArterialPressureType: monitorParam.ArterialPressureType,
  588. TransmembranePressure: monitorParam.TransmembranePressure,
  589. TransmembranePressureType: monitorParam.TransmembranePressureType,
  590. UltrafiltrationRate: monitorParam.UltrafiltrationRate,
  591. UltrafiltrationVolume: monitorParam.UltrafiltrationVolume,
  592. SodiumConcentration: monitorParam.SodiumConcentration,
  593. DialysateTemperature: monitorParam.DialysateTemperature,
  594. Temperature: monitorParam.Temperature,
  595. ReplacementRate: monitorParam.ReplacementRate,
  596. DisplacementQuantity: monitorParam.DisplacementQuantity,
  597. Ktv: monitorParam.KTV,
  598. Symptom: monitorParam.Symptom,
  599. Dispose: monitorParam.Dispose,
  600. Result: monitorParam.Result,
  601. MonitoringNurse: adminUserInfo.AdminUser.Id,
  602. Conductivity: monitorParam.Conductivity,
  603. DisplacementFlowQuantity: monitorParam.DisplacementFlowQuantity,
  604. Status: 1,
  605. CreatedTime: time.Now().Unix(),
  606. UpdatedTime: time.Now().Unix(),
  607. BloodOxygenSaturation: monitorParam.BloodOxygenSaturation,
  608. Creator: adminUserInfo.AdminUser.Id,
  609. Heparin: monitorParam.Heparin,
  610. DialysateFlow: monitorParam.DialysateFlow,
  611. Urr: monitorParam.Urr,
  612. BloodSugar: monitorParam.BloodSugar,
  613. MonitorAnticoagulant: monitorParam.MonitorAnticoagulant,
  614. MonitorAnticoagulantValue: monitorParam.MonitorAnticoagulantValue,
  615. BloodPressureMonitoringSite: monitorParam.BloodPressureMonitoringSite,
  616. Complication: monitorParam.Complication,
  617. AccumulatedBloodVolume: monitorParam.AccumulatedBloodVolume,
  618. BloodTemperature: monitorParam.BloodTemperature,
  619. UreaMonitoring: monitorParam.UreaMonitoring,
  620. BloodThickness: monitorParam.BloodThickness,
  621. BloodMonitor: monitorParam.BloodMonitor,
  622. HeparinAmount: monitorParam.HeparinAmount,
  623. Dehydration: monitorParam.Dehydration,
  624. FilterPressure: monitorParam.FilterPressure,
  625. ReplacementSpeed: monitorParam.ReplacementSpeed,
  626. Dicarbonate: monitorParam.Dicarbonate,
  627. IsPressure: monitorParam.IsPressure,
  628. }
  629. createErr := service.CreateMonitor(&monitor)
  630. //记录日志
  631. byterequest, _ := json.Marshal(monitor)
  632. monitorRecordLog := models.XtMonitorRecordLog{
  633. RecordDate: monitor.MonitoringDate,
  634. PatientId: monitor.PatientId,
  635. Module: 1,
  636. AdminUserId: adminUserInfo.AdminUser.Id,
  637. Ctime: time.Now().Unix(),
  638. Mtime: 0,
  639. Status: 1,
  640. UserOrgId: monitor.UserOrgId,
  641. ErrLog: string(byterequest),
  642. Source: "电脑端新增监测",
  643. }
  644. service.CreateMonitorRecordLog(monitorRecordLog)
  645. finish := models.XtDialysisFinish{
  646. IsFinish: 1,
  647. UserOrgId: adminUserInfo.CurrentOrgId,
  648. Status: 1,
  649. Ctime: time.Now().Unix(),
  650. Mtime: 0,
  651. Module: 7,
  652. RecordDate: monitorParam.MonitoringDate,
  653. Sourse: 1,
  654. PatientId: patientID,
  655. }
  656. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, monitorParam.MonitoringDate, 7, patientID)
  657. if dialysisFinish.ID == 0 {
  658. service.CreateDialysisFinish(finish)
  659. }
  660. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":monitor_records"
  661. redis := service.RedisClient()
  662. //清空key 值
  663. redis.Set(key, "", time.Second)
  664. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(monitorParam.MonitoringDate, 10) + ":monitor_record_list_all"
  665. redis.Set(keyOne, "", time.Second)
  666. defer redis.Close()
  667. if createErr != nil {
  668. this.ErrorLog("创建监测记录失败:%v", createErr)
  669. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  670. return
  671. }
  672. this.ServeSuccessJSON(map[string]interface{}{
  673. "monitor": monitor,
  674. })
  675. } else { // 修改记录
  676. monitor, getMonitorErr := service.GetMonitor(adminUserInfo.CurrentOrgId, patientID, monitorParam.ID)
  677. if getMonitorErr != nil {
  678. this.ErrorLog("获取透析监测记录失败:%v", getMonitorErr)
  679. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  680. return
  681. } else if monitor == nil {
  682. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorNotExist)
  683. return
  684. }
  685. //if monitor.MonitoringNurse != adminUserInfo.AdminUser.Id {
  686. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  687. // if getPermissionErr != nil {
  688. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  689. // return
  690. // } else if headNursePermission == nil {
  691. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  692. // return
  693. // }
  694. //}
  695. monitor.OperateTime = monitorParam.OperateTime
  696. monitor.PulseFrequency = monitorParam.PulseFrequency
  697. monitor.BreathingRate = monitorParam.BreathingRated
  698. monitor.SystolicBloodPressure = monitorParam.SystolicBP
  699. monitor.DiastolicBloodPressure = monitorParam.DiastolicBP
  700. monitor.BloodFlowVolume = monitorParam.BloodFlowVolume
  701. monitor.VenousPressure = monitorParam.VenousPressure
  702. monitor.VenousPressureType = monitorParam.VenousPressureType
  703. monitor.ArterialPressure = monitorParam.ArterialPressure
  704. monitor.ArterialPressureType = monitorParam.ArterialPressureType
  705. monitor.TransmembranePressure = monitorParam.TransmembranePressure
  706. monitor.TransmembranePressureType = monitorParam.TransmembranePressureType
  707. monitor.UltrafiltrationRate = monitorParam.UltrafiltrationRate
  708. monitor.UltrafiltrationVolume = monitorParam.UltrafiltrationVolume
  709. monitor.SodiumConcentration = monitorParam.SodiumConcentration
  710. monitor.DialysateTemperature = monitorParam.DialysateTemperature
  711. monitor.Temperature = monitorParam.Temperature
  712. monitor.ReplacementRate = monitorParam.ReplacementRate
  713. monitor.DisplacementQuantity = monitorParam.DisplacementQuantity
  714. monitor.Conductivity = monitorParam.Conductivity
  715. monitor.DisplacementFlowQuantity = monitorParam.DisplacementFlowQuantity
  716. monitor.Ktv = monitorParam.KTV
  717. monitor.Symptom = monitorParam.Symptom
  718. monitor.Dispose = monitorParam.Dispose
  719. monitor.Result = monitorParam.Result
  720. monitor.MonitoringNurse = adminUserInfo.AdminUser.Id
  721. monitor.UpdatedTime = time.Now().Unix()
  722. monitor.Modify = adminUserInfo.AdminUser.Id
  723. monitor.BloodOxygenSaturation = monitorParam.BloodOxygenSaturation
  724. monitor.Heparin = monitorParam.Heparin
  725. monitor.DialysateFlow = monitorParam.DialysateFlow
  726. monitor.Urr = monitorParam.Urr
  727. monitor.BloodSugar = monitorParam.BloodSugar
  728. monitor.MonitorAnticoagulant = monitorParam.MonitorAnticoagulant
  729. monitor.MonitorAnticoagulantValue = monitorParam.MonitorAnticoagulantValue
  730. monitor.AccumulatedBloodVolume = monitorParam.AccumulatedBloodVolume
  731. monitor.BloodTemperature = monitorParam.BloodTemperature
  732. monitor.UreaMonitoring = monitorParam.UreaMonitoring
  733. monitor.BloodThickness = monitorParam.BloodThickness
  734. monitor.BloodMonitor = monitorParam.BloodMonitor
  735. monitor.HeparinAmount = monitorParam.HeparinAmount
  736. monitor.Dehydration = monitorParam.Dehydration
  737. monitor.FilterPressure = monitorParam.FilterPressure
  738. monitor.ReplacementSpeed = monitorParam.ReplacementSpeed
  739. monitor.Dicarbonate = monitorParam.Dicarbonate
  740. monitor.IsPressure = monitorParam.IsPressure
  741. updateErr := service.UpdateMonitor(monitor)
  742. //记录日志
  743. byterequest, _ := json.Marshal(monitor)
  744. monitorRecordLog := models.XtMonitorRecordLog{
  745. RecordDate: monitor.MonitoringDate,
  746. PatientId: monitor.PatientId,
  747. Module: 1,
  748. AdminUserId: adminUserInfo.AdminUser.Id,
  749. Ctime: time.Now().Unix(),
  750. Mtime: 0,
  751. Status: 1,
  752. UserOrgId: monitor.UserOrgId,
  753. ErrLog: string(byterequest),
  754. Source: "电脑端修改监测",
  755. }
  756. service.CreateMonitorRecordLog(monitorRecordLog)
  757. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":monitor_records"
  758. redis := service.RedisClient()
  759. defer redis.Close()
  760. //清空key 值
  761. redis.Set(key, "", time.Second)
  762. if updateErr != nil {
  763. this.ErrorLog("修改透析监测记录失败:%v", updateErr)
  764. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  765. return
  766. }
  767. this.ServeSuccessJSON(map[string]interface{}{
  768. "monitor": monitor,
  769. })
  770. }
  771. }
  772. // /api/dialysis/start_record [post]
  773. // @param patient_id:int
  774. // @param date:string 排班时间 (yyyy-mm-dd)
  775. // @param nurse:int 上机护士
  776. // @param bed:int 上机床位号
  777. func (this *DialysisRecordAPIController) StartDialysis() {
  778. patientID, _ := this.GetInt64("patient_id")
  779. recordDateStr := this.GetString("date")
  780. nurseID, _ := this.GetInt64("nurse")
  781. punctureNurseId, _ := this.GetInt64("puncture_nurse")
  782. startDateStr := this.GetString("start_time")
  783. blood_drawing, _ := this.GetInt64("blood_drawing")
  784. schedual_type, _ := this.GetInt64("schedual_type")
  785. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  786. change_nurse, _ := this.GetInt64("change_nurse")
  787. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  788. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  789. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  790. puncture_needle := this.GetString("puncture_needle")
  791. puncture_way := this.GetString("puncture_way")
  792. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  793. dialysis_irrigation := this.GetString("dialysis_irrigation")
  794. blood_access_id, _ := this.GetInt64("blood_access_id")
  795. bedID, _ := this.GetInt64("bed")
  796. nuclein_date := this.GetString("nuclein_date")
  797. schedule_remark := this.GetString("schedule_remark")
  798. order_remark := this.GetString("order_remark")
  799. catheter_operation := this.GetString("catheter_operation")
  800. blood_flow_volume := this.GetString("blood_flow_volume")
  801. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  802. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  803. return
  804. }
  805. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  806. if parseErr != nil {
  807. this.ErrorLog("时间解析失败:%v", parseErr)
  808. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  809. return
  810. }
  811. startDate, parseErr := utils.ParseTimeStringToTime("2006-01-02 15:04", startDateStr)
  812. if parseErr != nil {
  813. this.ErrorLog("时间解析失败:%v", parseErr)
  814. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  815. return
  816. }
  817. adminUserInfo := this.GetAdminUserInfo()
  818. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.CurrentOrgId, patientID)
  819. if getPatientErr != nil {
  820. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  821. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  822. return
  823. } else if patient == nil {
  824. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  825. return
  826. }
  827. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  828. if getNurseErr != nil {
  829. this.ErrorLog("获取护士失败:%v", getNurseErr)
  830. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  831. return
  832. } else if nurse == nil {
  833. this.ErrorLog("护士不存在")
  834. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  835. return
  836. }
  837. //nurse, getNurseErr = service.GetAdminUserByUserID(punctureNurseId)
  838. //
  839. //if getNurseErr != nil {
  840. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  841. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  842. // return
  843. //} else if nurse == nil {
  844. // this.ErrorLog("护士不存在")
  845. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  846. // return
  847. //}
  848. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.CurrentOrgId, bedID)
  849. if getDeviceNumberErr != nil {
  850. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  851. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  852. return
  853. } else if deviceNumber == nil {
  854. this.ErrorLog("床位号不存在")
  855. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  856. return
  857. }
  858. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  859. if getRecordErr != nil {
  860. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  861. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  862. return
  863. } else if dialysisRecord != nil {
  864. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  865. return
  866. }
  867. template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  868. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  869. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  870. timeLayout := "2006-01-02 15:04:05"
  871. loc, _ := time.LoadLocation("Local")
  872. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  873. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  874. schedulestartTime := theStartTime.Unix()
  875. scheduleendTime := theEndTime.Unix()
  876. var theNucleinDate int64
  877. timeLayoutOne := "2006-01-02"
  878. if len(nuclein_date) > 0 {
  879. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date+" 00:00:00", loc)
  880. if err != nil {
  881. utils.ErrorLog(err.Error())
  882. }
  883. theNucleinDate = theTime.Unix()
  884. }
  885. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  886. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.CurrentOrgId, schedulestartTime, bedID, schedual_type)
  887. //查询该床位是否有人上机
  888. order, order_err := service.GetDialysisOrderByBedId(adminUserInfo.CurrentOrgId, schedulestartTime, bedID, schedual_type)
  889. if err == gorm.ErrRecordNotFound { //空床位
  890. // 修改了床位逻辑
  891. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, patientID)
  892. if daySchedule.ID > 0 {
  893. //daySchedule.PartitionId = deviceNumber.ZoneID
  894. //daySchedule.BedId = bedID
  895. //daySchedule.ScheduleType = schedual_type
  896. //daySchedule.UpdatedTime = time.Now().Unix()
  897. //err := service.UpdateSchedule(&daySchedule)
  898. xtSchedule := models.Schedule{
  899. PartitionId: deviceNumber.ZoneID,
  900. BedId: bedID,
  901. ScheduleType: schedual_type,
  902. UpdatedTime: time.Now().Unix(),
  903. }
  904. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  905. if err != nil {
  906. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  907. return
  908. }
  909. }
  910. } else if err == nil {
  911. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  912. if order_err == nil {
  913. if order.ID > 0 { //该机位被其他人占用了
  914. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  915. return
  916. } else {
  917. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, patientID)
  918. if daySchedule.ID > 0 {
  919. //daySchedule.PartitionId = deviceNumber.ZoneID
  920. //daySchedule.BedId = bedID
  921. //daySchedule.ScheduleType = schedual_type
  922. //daySchedule.UpdatedTime = time.Now().Unix()
  923. //err := service.UpdateSchedule(&daySchedule)
  924. xtSchedule := models.Schedule{
  925. PartitionId: deviceNumber.ZoneID,
  926. BedId: bedID,
  927. ScheduleType: schedual_type,
  928. UpdatedTime: time.Now().Unix(),
  929. }
  930. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  931. if err != nil {
  932. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  933. return
  934. }
  935. }
  936. }
  937. } else if order_err == gorm.ErrRecordNotFound { //该床位没被占用
  938. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, patientID)
  939. if daySchedule.ID > 0 {
  940. //daySchedule.PartitionId = deviceNumber.ZoneID
  941. //daySchedule.BedId = bedID
  942. //daySchedule.ScheduleType = schedual_type
  943. //daySchedule.UpdatedTime = time.Now().Unix()
  944. //err := service.UpdateSchedule(&daySchedule)
  945. xtSchedule := models.Schedule{
  946. PartitionId: deviceNumber.ZoneID,
  947. BedId: bedID,
  948. ScheduleType: schedual_type,
  949. UpdatedTime: time.Now().Unix(),
  950. }
  951. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  952. if err != nil {
  953. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  954. return
  955. }
  956. }
  957. } else if order_err != nil {
  958. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  959. return
  960. }
  961. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  962. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  963. return
  964. }
  965. } else if err != nil {
  966. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  967. return
  968. }
  969. // 查询信息规挡的设置天数
  970. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  971. if infor.ID > 0 && infor.WeekDay > 0 {
  972. var cha_time int64
  973. timeNowStr := time.Now().Format("2006-01-02")
  974. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  975. //今日的日期减去设置的日期
  976. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  977. if cha_time >= recordDate.Unix() {
  978. //查询审核是否允许
  979. infor, _ := service.GetDialysisInformationByRecordDate(patientID, recordDate.Unix(), adminUserInfo.CurrentOrgId, 6)
  980. //申请状态不允许的情况 拒绝修改
  981. if infor.ApplicationStatus != 1 {
  982. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  983. return
  984. }
  985. }
  986. }
  987. dialysisRecord = &models.DialysisOrder{
  988. DialysisDate: recordDate.Unix(),
  989. UserOrgId: adminUserInfo.CurrentOrgId,
  990. PatientId: patientID,
  991. Stage: 1,
  992. BedID: bedID,
  993. StartNurse: nurseID,
  994. Status: 1,
  995. StartTime: startDate.Unix(),
  996. CreatedTime: time.Now().Unix(),
  997. UpdatedTime: time.Now().Unix(),
  998. PunctureNurse: punctureNurseId,
  999. Creator: adminUserInfo.AdminUser.Id,
  1000. Modifier: adminUserInfo.AdminUser.Id,
  1001. SchedualType: schedual_type,
  1002. WashpipeNurse: washpipe_nurse,
  1003. ChangeNurse: change_nurse,
  1004. DifficultPunctureNurse: difficult_puncture_nurse,
  1005. NewFistulaNurse: new_fistula_nurse,
  1006. QualityNurseId: quality_nurse_id,
  1007. PunctureNeedle: puncture_needle,
  1008. PunctureWay: puncture_way,
  1009. DialysisDialyszers: dialysis_dialyszers,
  1010. DialysisIrrigation: dialysis_irrigation,
  1011. BloodAccessId: blood_access_id,
  1012. NucleinDate: theNucleinDate,
  1013. ScheduleRemark: schedule_remark,
  1014. OrderRemark: order_remark,
  1015. CatheterOperation: catheter_operation,
  1016. BloodFlowVolume: blood_flow_volume,
  1017. }
  1018. createErr := service.MobileCreateDialysisOrder(adminUserInfo.CurrentOrgId, patientID, dialysisRecord)
  1019. finish := models.XtDialysisFinish{
  1020. IsFinish: 1,
  1021. UserOrgId: adminUserInfo.CurrentOrgId,
  1022. Status: 1,
  1023. Ctime: time.Now().Unix(),
  1024. Mtime: 0,
  1025. Module: 6,
  1026. RecordDate: recordDate.Unix(),
  1027. Sourse: 1,
  1028. PatientId: patientID,
  1029. }
  1030. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 6, patientID)
  1031. if dialysisFinish.ID == 0 {
  1032. service.CreateDialysisFinish(finish)
  1033. }
  1034. //更新患者表排班备注
  1035. service.UpdateMobilePatient(adminUserInfo.CurrentOrgId, patientID, schedule_remark)
  1036. ////统计该患者总次数
  1037. //dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.CurrentOrgId, patientID)
  1038. //
  1039. //service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.CurrentOrgId, dialysisCount.Count)
  1040. if adminUserInfo.CurrentOrgId != 10101 && adminUserInfo.CurrentOrgId != 10445 && adminUserInfo.CurrentOrgId != 3877 && adminUserInfo.CurrentOrgId != 10345 {
  1041. //统计该患者总次数
  1042. dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.CurrentOrgId, patientID)
  1043. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.CurrentOrgId, dialysisCount.Count)
  1044. }
  1045. if adminUserInfo.CurrentOrgId == 10101 || adminUserInfo.CurrentOrgId == 10445 || adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 10345 {
  1046. //统计该患者总次数
  1047. dialysisCount, _ := service.GetDialysisTotalCountOne(adminUserInfo.CurrentOrgId, patientID)
  1048. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.CurrentOrgId, dialysisCount.Count)
  1049. }
  1050. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  1051. redis := service.RedisClient()
  1052. //清空key 值
  1053. redis.Set(key, "", time.Second)
  1054. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  1055. redis.Set(keyOne, "", time.Second)
  1056. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1057. //清空key 值
  1058. redis.Set(keyTwo, "", time.Second)
  1059. defer redis.Close()
  1060. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1061. if createErr != nil {
  1062. this.ErrorLog("上机失败:%v", createErr)
  1063. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1064. return
  1065. } else if createErr == nil {
  1066. var tempdispose string
  1067. // 只针对中能建
  1068. if blood_drawing > 0 && adminUserInfo.CurrentOrgId == 9538 { //adminUserInfo.CurrentOrgId == 9538
  1069. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  1070. }
  1071. if blood_drawing > 0 && adminUserInfo.CurrentOrgId == 10318 { //adminUserInfo.CurrentOrgId == 9538
  1072. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  1073. }
  1074. var ultrafiltration_rate float64
  1075. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.CurrentOrgId)
  1076. //获取预增水量
  1077. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, schedulestartTime, adminUserInfo.CurrentOrgId)
  1078. if prescription.ID > 0 {
  1079. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  1080. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  1081. //fmt.Println("total23232323232322332", totalMin)
  1082. if (template.TemplateId == 6 || template.TemplateId == 20 || template.TemplateId == 22 || template.TemplateId == 32 || template.TemplateId == 36) && adminUserInfo.CurrentOrgId != 9671 {
  1083. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  1084. }
  1085. //针对福建医师汇
  1086. if template.TemplateId == 6 && adminUserInfo.CurrentOrgId == 10121 {
  1087. if evaluation.ID > 0 {
  1088. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  1089. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  1090. }
  1091. }
  1092. if template.TemplateId == 6 && adminUserInfo.CurrentOrgId == 10234 {
  1093. if evaluation.ID > 0 {
  1094. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  1095. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  1096. }
  1097. }
  1098. // 只针对方济医院
  1099. if template.TemplateId == 1 && adminUserInfo.CurrentOrgId != 9849 {
  1100. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  1101. ultrafiltration_rate = value
  1102. }
  1103. //针对监利大垸医院
  1104. if adminUserInfo.CurrentOrgId == 10101 {
  1105. if evaluation.ID > 0 {
  1106. ultrafiltration_rate = math.Ceil(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  1107. }
  1108. }
  1109. //针对肇庆三鹤血液透析中心
  1110. if adminUserInfo.CurrentOrgId == 10215 || template.TemplateId == 43 || adminUserInfo.CurrentOrgId == 10441 || adminUserInfo.CurrentOrgId == 10445 || adminUserInfo.CurrentOrgId == 10469 {
  1111. if evaluation.ID > 0 {
  1112. ultrafiltration_rate = math.Ceil(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  1113. }
  1114. }
  1115. }
  1116. }
  1117. record := models.MonitoringRecord{
  1118. UserOrgId: adminUserInfo.CurrentOrgId,
  1119. PatientId: patientID,
  1120. DialysisOrderId: dialysisRecord.ID,
  1121. MonitoringDate: schedulestartTime,
  1122. OperateTime: startDate.Unix(),
  1123. // MonitoringTime: recordTime,
  1124. MonitoringNurse: nurseID,
  1125. Dispose: tempdispose,
  1126. UltrafiltrationRate: ultrafiltration_rate,
  1127. UltrafiltrationVolume: 0,
  1128. Status: 1,
  1129. CreatedTime: time.Now().Unix(),
  1130. UpdatedTime: time.Now().Unix(),
  1131. }
  1132. //只针对广慈医院
  1133. 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 {
  1134. // 查询病人是否有透前评估数据
  1135. befor, errcode := service.GetAssessmentBefor(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1136. //如果有数据就插入
  1137. if errcode == nil {
  1138. record.SystolicBloodPressure = befor.SystolicBloodPressure
  1139. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  1140. record.BreathingRate = befor.BreathingRate
  1141. record.PulseFrequency = befor.PulseFrequency
  1142. record.Temperature = befor.Temperature
  1143. }
  1144. }
  1145. // 如果当天有插入数据,则不再往透析纪录里插入数据
  1146. if newdialysisRecord.ID > 0 {
  1147. //针对长沙南雅医院
  1148. if adminUserInfo.CurrentOrgId == 9675 || adminUserInfo.CurrentOrgId == 10340 {
  1149. record.Temperature = 36.5
  1150. record.ArterialPressure = -100
  1151. record.Conductivity = 14
  1152. record.BreathingRate = "20"
  1153. record.DialysateTemperature = 36.5
  1154. record.VenousPressure = 80
  1155. record.TransmembranePressure = 60
  1156. }
  1157. // 针对灵山圣康
  1158. if adminUserInfo.CurrentOrgId == 10375 {
  1159. record.DialysateTemperature = 37
  1160. record.Conductivity = 13.8
  1161. record.DialysateFlow = 500
  1162. record.BloodFlowVolume = 200
  1163. record.BreathingRate = "18"
  1164. record.SodiumConcentration = 140
  1165. }
  1166. //针对新化博翔
  1167. if adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 10447 {
  1168. record.BloodOxygenSaturation = "99"
  1169. record.Conductivity = 14
  1170. record.DialysateTemperature = 36.5
  1171. record.BreathingRate = "20"
  1172. }
  1173. //针对蓬安济民
  1174. if adminUserInfo.CurrentOrgId == 9829 || adminUserInfo.CurrentOrgId == 10440 {
  1175. record.Temperature = 36.5
  1176. record.PulseFrequency = 80
  1177. }
  1178. //针对兰溪人民医院的需求
  1179. if adminUserInfo.CurrentOrgId == 10432 {
  1180. befor, _ := service.GetAssessmentBefor(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1181. record.SystolicBloodPressure = befor.SystolicBloodPressure
  1182. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  1183. record.Temperature = befor.Temperature
  1184. record.PulseFrequency = befor.PulseFrequency
  1185. }
  1186. err := service.CreateMonitor(&record)
  1187. //记录日志
  1188. byterequest, _ := json.Marshal(record)
  1189. monitorRecordLog := models.XtMonitorRecordLog{
  1190. RecordDate: record.MonitoringDate,
  1191. PatientId: record.PatientId,
  1192. Module: 1,
  1193. AdminUserId: adminUserInfo.AdminUser.Id,
  1194. Ctime: time.Now().Unix(),
  1195. Mtime: 0,
  1196. Status: 1,
  1197. UserOrgId: record.UserOrgId,
  1198. ErrLog: string(byterequest),
  1199. Source: "电脑端执行上机新建监测",
  1200. }
  1201. service.CreateMonitorRecordLog(monitorRecordLog)
  1202. finish := models.XtDialysisFinish{
  1203. IsFinish: 1,
  1204. UserOrgId: adminUserInfo.CurrentOrgId,
  1205. Status: 1,
  1206. Ctime: time.Now().Unix(),
  1207. Mtime: 0,
  1208. Module: 7,
  1209. RecordDate: recordDate.Unix(),
  1210. Sourse: 1,
  1211. PatientId: patientID,
  1212. }
  1213. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 7, patientID)
  1214. if dialysisFinish.ID == 0 {
  1215. service.CreateDialysisFinish(finish)
  1216. }
  1217. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_records"
  1218. redis := service.RedisClient()
  1219. //清空key 值
  1220. redis.Set(key, "", time.Second)
  1221. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_record_list_all"
  1222. redis.Set(keyOne, "", time.Second)
  1223. defer redis.Close()
  1224. if err != nil {
  1225. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  1226. return
  1227. }
  1228. }
  1229. go func() {
  1230. ssoDomain := beego.AppConfig.String("call_domain")
  1231. api := ssoDomain + "/index/uppatient"
  1232. values := make(url.Values)
  1233. values.Set("org_id", strconv.FormatInt(adminUserInfo.CurrentOrgId, 10))
  1234. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  1235. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  1236. values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
  1237. http.PostForm(api, values)
  1238. }()
  1239. this.ServeSuccessJSON(map[string]interface{}{
  1240. "dialysis_order": dialysisRecord,
  1241. "monitor": record,
  1242. })
  1243. }
  1244. }
  1245. // /api/dialysis/finish [post]
  1246. // @param patient_id:int
  1247. // @param date:string 排班时间 (yyyy-mm-dd)
  1248. // @param nurse:int 下机护士
  1249. func (this *DialysisRecordAPIController) FinishDialysis() {
  1250. patientID, _ := this.GetInt64("patient_id")
  1251. recordDateStr := this.GetString("date")
  1252. nurseID, _ := this.GetInt64("nurse")
  1253. end_time := this.GetString("end_time")
  1254. puncture_point_haematoma, _ := this.GetInt64("puncture_point_haematoma")
  1255. internal_fistula := this.GetString("internal_fistula")
  1256. catheter := this.GetString("catheter")
  1257. cruor := this.GetString("cruor")
  1258. mission := this.GetString("mission")
  1259. condenser := this.GetString("condenser")
  1260. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 {
  1261. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1262. return
  1263. }
  1264. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1265. if parseErr != nil {
  1266. this.ErrorLog("时间解析失败:%v", parseErr)
  1267. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1268. return
  1269. }
  1270. //if parseEndDateErr != nil {
  1271. // this.ErrorLog("时间解析失败:%v", parseEndDateErr)
  1272. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1273. // return
  1274. //}
  1275. adminUserInfo := this.GetAdminUserInfo()
  1276. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.CurrentOrgId, patientID)
  1277. if getPatientErr != nil {
  1278. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  1279. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1280. return
  1281. } else if patient == nil {
  1282. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1283. return
  1284. }
  1285. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  1286. if getNurseErr != nil {
  1287. this.ErrorLog("获取护士失败:%v", getNurseErr)
  1288. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1289. return
  1290. } else if nurse == nil {
  1291. this.ErrorLog("护士不存在")
  1292. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1293. return
  1294. }
  1295. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1296. if getRecordErr != nil {
  1297. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  1298. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1299. return
  1300. }
  1301. if dialysisRecord.Stage == 2 {
  1302. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  1303. return
  1304. }
  1305. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04", end_time)
  1306. if parseEndDateErr != nil {
  1307. this.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  1308. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1309. return
  1310. }
  1311. // 获取当天的第一条透析纪录
  1312. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1313. if getMonitorRecordsErr != nil {
  1314. this.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  1315. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1316. return
  1317. }
  1318. // 获取当前的最后一条透析纪录
  1319. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecord(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1320. if getMonitorRecordsErr != nil {
  1321. this.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  1322. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1323. return
  1324. }
  1325. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysis(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1326. if getAADErr != nil {
  1327. this.ErrorLog("获取透后评估失败:%v", getAADErr)
  1328. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1329. return
  1330. }
  1331. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysis(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1332. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  1333. if assessmentAfterDislysis != nil {
  1334. tempassessmentAfterDislysis = *assessmentAfterDislysis
  1335. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  1336. } else {
  1337. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  1338. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  1339. tempassessmentAfterDislysis.Status = 1
  1340. tempassessmentAfterDislysis.PatientId = patientID
  1341. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.CurrentOrgId
  1342. }
  1343. if dialysisRecord.Stage == 1 {
  1344. temp_time := (float64(endDate.Unix()) - float64(dialysisRecord.StartTime)) / 3600
  1345. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  1346. fmt.Println(value)
  1347. a, b := math.Modf(value)
  1348. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  1349. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  1350. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  1351. fmt.Println(hour)
  1352. fmt.Println(minute)
  1353. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  1354. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  1355. }
  1356. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  1357. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  1358. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  1359. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  1360. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  1361. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  1362. //长沙南雅
  1363. if adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 9675 || adminUserInfo.CurrentOrgId == 10340 {
  1364. //获取最后一条透析处方数据
  1365. prescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1366. evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1367. tempassessmentAfterDislysis.WeightAfter = evaluation.WeightBefore - prescription.TargetUltrafiltration/1000
  1368. }
  1369. if adminUserInfo.CurrentOrgId == 10101 {
  1370. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  1371. } else {
  1372. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  1373. }
  1374. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  1375. //新化博翔
  1376. if adminUserInfo.CurrentOrgId == 10447 || adminUserInfo.CurrentOrgId == 9675 {
  1377. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  1378. }
  1379. //针对蓬安
  1380. if adminUserInfo.CurrentOrgId == 9829 || adminUserInfo.CurrentOrgId == 10440 {
  1381. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  1382. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  1383. }
  1384. }
  1385. if adminUserInfo.CurrentOrgId == 9583 {
  1386. //获取最后一条透析处方数据
  1387. prescription, parseErr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1388. if parseErr != nil {
  1389. this.ErrorLog("获取透析处方失败:%v", getMonitorRecordsErr)
  1390. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1391. return
  1392. }
  1393. if prescription.ID > 0 && adminUserInfo.CurrentOrgId == 9583 {
  1394. tempassessmentAfterDislysis.ActualUltrafiltration = prescription.TargetUltrafiltration
  1395. }
  1396. if endmonitorRecords.ID > 0 && adminUserInfo.CurrentOrgId == 10060 {
  1397. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  1398. }
  1399. }
  1400. if lastAssessmentAfterDislysis != nil {
  1401. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  1402. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  1403. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  1404. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  1405. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  1406. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  1407. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  1408. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  1409. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  1410. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  1411. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  1412. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  1413. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  1414. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  1415. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  1416. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  1417. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  1418. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  1419. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  1420. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  1421. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  1422. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  1423. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  1424. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  1425. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  1426. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  1427. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  1428. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  1429. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  1430. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  1431. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  1432. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  1433. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  1434. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  1435. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  1436. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  1437. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  1438. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  1439. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  1440. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  1441. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  1442. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  1443. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  1444. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  1445. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  1446. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  1447. if adminUserInfo.CurrentOrgId != 10375 {
  1448. tempassessmentAfterDislysis.SystolicBloodPressure = lastAssessmentAfterDislysis.SystolicBloodPressure
  1449. tempassessmentAfterDislysis.DiastolicBloodPressure = lastAssessmentAfterDislysis.DiastolicBloodPressure
  1450. }
  1451. }
  1452. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  1453. finishS := models.XtDialysisFinish{
  1454. IsFinish: 1,
  1455. UserOrgId: adminUserInfo.CurrentOrgId,
  1456. Status: 1,
  1457. Ctime: time.Now().Unix(),
  1458. Mtime: 0,
  1459. Module: 9,
  1460. RecordDate: recordDate.Unix(),
  1461. Sourse: 1,
  1462. PatientId: patientID,
  1463. }
  1464. dialysisFinishs, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 9, patientID)
  1465. if dialysisFinishs.ID == 0 {
  1466. service.CreateDialysisFinish(finishS)
  1467. }
  1468. 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 || adminUserInfo.CurrentOrgId == 10440 {
  1469. evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1470. if evaluation.SystolicBloodPressure == 0 {
  1471. pre := models.PredialysisEvaluation{
  1472. SystolicBloodPressure: fmonitorRecords.SystolicBloodPressure,
  1473. }
  1474. fmt.Println("prew", pre)
  1475. getNurseErr := service.UpdatePredialysisEvaluation(&pre, evaluation.ID)
  1476. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  1477. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  1478. redis := service.RedisClient()
  1479. redis.Set(key, "", time.Second)
  1480. redis.Set(keyOne, "", time.Second)
  1481. defer redis.Close()
  1482. fmt.Println(getNurseErr)
  1483. }
  1484. if evaluation.DiastolicBloodPressure == 0 {
  1485. pres := models.PredialysisEvaluation{
  1486. DiastolicBloodPressure: fmonitorRecords.DiastolicBloodPressure,
  1487. }
  1488. getNurseErr := service.UpdatePredialysisEvaluationTwo(&pres, evaluation.ID)
  1489. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  1490. redis := service.RedisClient()
  1491. redis.Set(key, "", time.Second)
  1492. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  1493. redis.Set(keyOne, "", time.Second)
  1494. defer redis.Close()
  1495. fmt.Println(getNurseErr)
  1496. }
  1497. if evaluation.PulseFrequency == 0 {
  1498. evaluation.PulseFrequency = fmonitorRecords.PulseFrequency
  1499. press := models.PredialysisEvaluation{
  1500. PulseFrequency: evaluation.PulseFrequency,
  1501. }
  1502. getNurseErr := service.UpdatePredialysisEvaluationThree(&press, evaluation.ID)
  1503. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  1504. redis := service.RedisClient()
  1505. redis.Set(key, "", time.Second)
  1506. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  1507. redis.Set(keyOne, "", time.Second)
  1508. defer redis.Close()
  1509. fmt.Println(getNurseErr)
  1510. }
  1511. if evaluation.Temperature == 0 {
  1512. evaluation.Temperature = fmonitorRecords.Temperature
  1513. press := models.PredialysisEvaluation{
  1514. Temperature: evaluation.Temperature,
  1515. }
  1516. getNurseErr := service.UpdatePredialysisEvaluationFour(&press, evaluation.ID)
  1517. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  1518. redis := service.RedisClient()
  1519. redis.Set(key, "", time.Second)
  1520. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  1521. redis.Set(keyOne, "", time.Second)
  1522. defer redis.Close()
  1523. fmt.Println(getNurseErr)
  1524. }
  1525. }
  1526. if err != nil {
  1527. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1528. return
  1529. }
  1530. go func() {
  1531. ssoDomain := beego.AppConfig.String("call_domain")
  1532. api := ssoDomain + "/index/downpatient"
  1533. values := make(url.Values)
  1534. values.Set("org_id", strconv.FormatInt(adminUserInfo.CurrentOrgId, 10))
  1535. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  1536. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  1537. http.PostForm(api, values)
  1538. }()
  1539. // 查询信息规挡的设置天数
  1540. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  1541. if infor.ID > 0 && infor.WeekDay > 0 {
  1542. var cha_time int64
  1543. timeNowStr := time.Now().Format("2006-01-02")
  1544. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1545. //今日的日期减去设置的日期
  1546. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1547. if cha_time >= recordDate.Unix() {
  1548. //查询审核是否允许
  1549. infor, _ := service.GetDialysisInformationByRecordDate(patientID, recordDate.Unix(), adminUserInfo.CurrentOrgId, 8)
  1550. //申请状态不允许的情况 拒绝修改
  1551. if infor.ApplicationStatus != 1 {
  1552. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1553. return
  1554. }
  1555. }
  1556. }
  1557. //执行下机
  1558. updateErr := service.ModifyDialysisRecord(dialysisRecord.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id, puncture_point_haematoma, internal_fistula, catheter, cruor, mission, condenser)
  1559. finish := models.XtDialysisFinish{
  1560. IsFinish: 1,
  1561. UserOrgId: adminUserInfo.CurrentOrgId,
  1562. Status: 1,
  1563. Ctime: time.Now().Unix(),
  1564. Mtime: 0,
  1565. Module: 8,
  1566. RecordDate: recordDate.Unix(),
  1567. Sourse: 1,
  1568. PatientId: patientID,
  1569. }
  1570. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 8, patientID)
  1571. if dialysisFinish.ID == 0 {
  1572. service.CreateDialysisFinish(finish)
  1573. }
  1574. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  1575. redis := service.RedisClient()
  1576. defer redis.Close()
  1577. //清空key 值
  1578. redis.Set(key, "", time.Second)
  1579. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  1580. redis.Set(keyOne, "", time.Second)
  1581. if updateErr != nil {
  1582. this.ErrorLog("下机失败:%v", updateErr)
  1583. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1584. return
  1585. } else {
  1586. dialysisRecord.Stage = 2
  1587. dialysisRecord.FinishNurse = nurseID
  1588. dialysisRecord.FinishCreator = adminUserInfo.AdminUser.Id
  1589. dialysisRecord.FinishModifier = adminUserInfo.AdminUser.Id
  1590. dialysisRecord.EndTime = endDate.Unix()
  1591. // 结束时候透析次数加1
  1592. service.UpdateSolutionByPatientId(patientID)
  1593. this.ServeSuccessJSON(map[string]interface{}{
  1594. "dialysis_order": dialysisRecord,
  1595. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  1596. })
  1597. }
  1598. }
  1599. func (this *DialysisRecordAPIController) ModifyStartDialysis() {
  1600. record_id, _ := this.GetInt64("id")
  1601. nurseID, _ := this.GetInt64("nurse")
  1602. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  1603. bedID, _ := this.GetInt64("bed")
  1604. start_time := this.GetString("start_time")
  1605. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  1606. schedual_type, _ := this.GetInt64("schedual_type")
  1607. change_nurse, _ := this.GetInt64("change_nurse")
  1608. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  1609. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  1610. quality_nurse, _ := this.GetInt64("quality_nurse")
  1611. puncture_needle := this.GetString("puncture_needle")
  1612. puncture_way := this.GetString("puncture_way")
  1613. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  1614. dialysis_irrigation := this.GetString("dialysis_irrigation")
  1615. blood_access_id, _ := this.GetInt64("blood_access_id")
  1616. nuclein_date := this.GetString("nuclein_date")
  1617. schedule_remark := this.GetString("schedule_remark")
  1618. order_remark := this.GetString("order_remark")
  1619. catheter_operation := this.GetString("catheter_operation")
  1620. blood_flow_volume := this.GetString("blood_flow_volume")
  1621. if record_id == 0 {
  1622. this.ErrorLog("id:%v", record_id)
  1623. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1624. return
  1625. }
  1626. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04", start_time)
  1627. if parseStartDateErr != nil {
  1628. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  1629. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1630. return
  1631. }
  1632. adminUserInfo := this.GetAdminUserInfo()
  1633. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  1634. if getNurseErr != nil {
  1635. this.ErrorLog("获取护士失败:%v", getNurseErr)
  1636. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1637. return
  1638. } else if nurse == nil {
  1639. this.ErrorLog("护士不存在")
  1640. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1641. return
  1642. }
  1643. //nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  1644. //if getNurseErr != nil {
  1645. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  1646. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1647. // return
  1648. //} else if nurse == nil {
  1649. // this.ErrorLog("护士不存在")
  1650. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1651. // return
  1652. //}
  1653. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.CurrentOrgId, bedID)
  1654. if getDeviceNumberErr != nil {
  1655. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  1656. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1657. return
  1658. } else if deviceNumber == nil {
  1659. this.ErrorLog("床位号不存在")
  1660. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1661. return
  1662. }
  1663. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  1664. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  1665. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1666. // if getPermissionErr != nil {
  1667. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1668. // return
  1669. // } else if headNursePermission == nil {
  1670. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1671. // return
  1672. // }
  1673. //}
  1674. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  1675. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  1676. timeLayout := "2006-01-02 15:04:05"
  1677. loc, _ := time.LoadLocation("Local")
  1678. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  1679. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  1680. schedulestartTime := theStartTime.Unix()
  1681. scheduleendTime := theEndTime.Unix()
  1682. var theNucleinDate int64
  1683. timeLayoutOne := "2006-01-02"
  1684. if len(nuclein_date) > 0 {
  1685. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date+" 00:00:00", loc)
  1686. if err != nil {
  1687. utils.ErrorLog(err.Error())
  1688. }
  1689. theNucleinDate = theTime.Unix()
  1690. }
  1691. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  1692. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.CurrentOrgId, schedulestartTime, bedID, schedual_type)
  1693. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  1694. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  1695. if err == gorm.ErrRecordNotFound { //空床位
  1696. // 修改了床位逻辑
  1697. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  1698. if daySchedule.ID > 0 {
  1699. //daySchedule.BedId = bedID
  1700. //daySchedule.PartitionId = deviceNumber.ZoneID
  1701. //daySchedule.ScheduleType = schedual_type
  1702. //daySchedule.UpdatedTime = time.Now().Unix()
  1703. //err := service.UpdateSchedule(&daySchedule)
  1704. xtSchedule := models.Schedule{
  1705. PartitionId: deviceNumber.ZoneID,
  1706. BedId: bedID,
  1707. ScheduleType: schedual_type,
  1708. UpdatedTime: time.Now().Unix(),
  1709. }
  1710. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  1711. if err != nil {
  1712. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1713. return
  1714. }
  1715. }
  1716. } else if err == nil {
  1717. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  1718. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  1719. if daySchedule.ID > 0 {
  1720. //daySchedule.BedId = bedID
  1721. //daySchedule.PartitionId = deviceNumber.ZoneID
  1722. //
  1723. //daySchedule.ScheduleType = schedual_type
  1724. //daySchedule.UpdatedTime = time.Now().Unix()
  1725. //err := service.UpdateSchedule(&daySchedule)
  1726. xtSchedule := models.Schedule{
  1727. PartitionId: deviceNumber.ZoneID,
  1728. BedId: bedID,
  1729. ScheduleType: schedual_type,
  1730. UpdatedTime: time.Now().Unix(),
  1731. }
  1732. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  1733. if err != nil {
  1734. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1735. return
  1736. }
  1737. }
  1738. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  1739. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  1740. return
  1741. }
  1742. } else if err != nil {
  1743. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1744. return
  1745. }
  1746. }
  1747. dialysisRecord := &models.DialysisOrder{
  1748. ID: record_id,
  1749. UserOrgId: adminUserInfo.CurrentOrgId,
  1750. BedID: bedID,
  1751. StartNurse: nurseID,
  1752. StartTime: startDate.Unix(),
  1753. PunctureNurse: puncture_nurse,
  1754. Creator: adminUserInfo.AdminUser.Id,
  1755. Modifier: adminUserInfo.AdminUser.Id,
  1756. SchedualType: schedual_type,
  1757. WashpipeNurse: washpipe_nurse,
  1758. ChangeNurse: change_nurse,
  1759. DifficultPunctureNurse: difficult_puncture_nurse,
  1760. NewFistulaNurse: new_fistula_nurse,
  1761. QualityNurseId: quality_nurse,
  1762. PunctureWay: puncture_way,
  1763. PunctureNeedle: puncture_needle,
  1764. DialysisDialyszers: dialysis_dialyszers,
  1765. DialysisIrrigation: dialysis_irrigation,
  1766. BloodAccessId: blood_access_id,
  1767. NucleinDate: theNucleinDate,
  1768. ScheduleRemark: schedule_remark,
  1769. OrderRemark: order_remark,
  1770. CatheterOperation: catheter_operation,
  1771. BloodFlowVolume: blood_flow_volume,
  1772. }
  1773. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  1774. if infor.ID > 0 && infor.WeekDay > 0 {
  1775. var cha_time int64
  1776. timeNowStr := time.Now().Format("2006-01-02")
  1777. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1778. //今日的日期减去设置的日期
  1779. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1780. if cha_time >= tempDialysisRecord.DialysisDate {
  1781. //查询审核是否允许
  1782. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate, adminUserInfo.CurrentOrgId, 6)
  1783. //申请状态不允许的情况 拒绝修改
  1784. if infor.ApplicationStatus != 1 {
  1785. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1786. return
  1787. }
  1788. }
  1789. }
  1790. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  1791. order, _ := service.GetLastPatientOrder(record_id)
  1792. service.UpdateMobilePatient(adminUserInfo.CurrentOrgId, order.PatientId, schedule_remark)
  1793. redis := service.RedisClient()
  1794. key := strconv.FormatInt(tempDialysisRecord.UserOrgId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":dialysis_order"
  1795. redis.Set(key, "", time.Second)
  1796. keyOne := strconv.FormatInt(tempDialysisRecord.UserOrgId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":dialysis_orders_list_all"
  1797. //清空key 值
  1798. redis.Set(keyOne, "", time.Second)
  1799. scheduleDateStartOne := startDate.Format("2006-01-02")
  1800. keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(tempDialysisRecord.UserOrgId, 10)
  1801. redis.Set(keyTwo, "", time.Second)
  1802. keyThree := strconv.FormatInt(tempDialysisRecord.UserOrgId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":doctor_advices"
  1803. redis.Set(keyThree, "", time.Second)
  1804. keyFour := strconv.FormatInt(tempDialysisRecord.UserOrgId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_records"
  1805. redis.Set(keyFour, "", time.Second)
  1806. keyFive := strconv.FormatInt(tempDialysisRecord.UserOrgId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":patient_info"
  1807. redis.Set(keyFive, "", time.Second)
  1808. keySix := strconv.FormatInt(tempDialysisRecord.UserOrgId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":his_doctor_advice"
  1809. redis.Set(keySix, "", time.Second)
  1810. keySeven := strconv.FormatInt(tempDialysisRecord.UserOrgId, 10) + ":" + ":device_list_all"
  1811. redis.Set(keySeven, "", time.Second)
  1812. if updateErr != nil {
  1813. this.ErrorLog("修改上机失败:%v", updateErr)
  1814. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1815. return
  1816. }
  1817. if updateErr == nil {
  1818. if tempDialysisRecord.Stage == 2 {
  1819. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  1820. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  1821. fmt.Println(value)
  1822. a, b := math.Modf(value)
  1823. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  1824. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  1825. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  1826. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  1827. redis := service.RedisClient()
  1828. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":assessment_after_dislysis_list_all"
  1829. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":dialysis_orders_list_all"
  1830. redis.Set(key, "", time.Second)
  1831. redis.Set(keyThree, "", time.Second)
  1832. redis.Close()
  1833. if updateAssessmentErr != nil {
  1834. utils.ErrorLog("%v", updateAssessmentErr)
  1835. }
  1836. after, _ := service.FindAssessmentAfterDislysisById(tempDialysisRecord.UserOrgId, tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  1837. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  1838. this.ServeSuccessJSON(map[string]interface{}{
  1839. "dialysis_order": dialysisRecords,
  1840. "after": after,
  1841. })
  1842. } else {
  1843. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  1844. this.ServeSuccessJSON(map[string]interface{}{
  1845. "dialysis_order": dialysisRecords,
  1846. })
  1847. }
  1848. }
  1849. }
  1850. func (c *DialysisRecordAPIController) ModifyFinishDialysis() {
  1851. record_id, _ := c.GetInt64("id")
  1852. nurseID, _ := c.GetInt64("nurse")
  1853. end_time := c.GetString("end_time")
  1854. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  1855. internal_fistula := c.GetString("internal_fistula")
  1856. catheter := c.GetString("catheter")
  1857. cruor := c.GetString("cruor")
  1858. mission := c.GetString("mission")
  1859. condenser := c.GetString("condenser")
  1860. if record_id <= 0 || nurseID <= 0 {
  1861. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1862. return
  1863. }
  1864. adminUserInfo := c.GetAdminUserInfo()
  1865. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  1866. if getNurseErr != nil {
  1867. c.ErrorLog("获取护士失败:%v", getNurseErr)
  1868. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1869. return
  1870. } else if nurse == nil {
  1871. c.ErrorLog("护士不存在")
  1872. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1873. return
  1874. }
  1875. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04", end_time)
  1876. if parseEndDateErr != nil {
  1877. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  1878. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1879. return
  1880. }
  1881. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  1882. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  1883. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1884. // if getPermissionErr != nil {
  1885. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1886. // return
  1887. // } else if headNursePermission == nil {
  1888. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1889. // return
  1890. // }
  1891. //}
  1892. dialysisRecord := &models.DialysisOrder{
  1893. ID: record_id,
  1894. UserOrgId: adminUserInfo.CurrentOrgId,
  1895. EndTime: endDate.Unix(),
  1896. FinishNurse: nurseID,
  1897. FinishModifier: adminUserInfo.AdminUser.Id,
  1898. PuncturePointHaematoma: puncture_point_haematoma,
  1899. BloodAccessInternalFistula: internal_fistula,
  1900. Catheter: catheter,
  1901. Cruor: cruor,
  1902. Mission: mission,
  1903. Condenser: condenser,
  1904. }
  1905. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  1906. // 查询信息规挡的设置天数
  1907. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  1908. if infor.ID > 0 && infor.WeekDay > 0 {
  1909. var cha_time int64
  1910. timeNowStr := time.Now().Format("2006-01-02")
  1911. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1912. //今日的日期减去设置的日期
  1913. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1914. if cha_time >= tempDialysisRecords.DialysisDate {
  1915. //查询审核是否允许
  1916. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate, adminUserInfo.CurrentOrgId, 6)
  1917. //申请状态不允许的情况 拒绝修改
  1918. if infor.ApplicationStatus != 1 {
  1919. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1920. return
  1921. }
  1922. }
  1923. }
  1924. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_order"
  1925. redis := service.RedisClient()
  1926. defer redis.Close()
  1927. //清空key 值
  1928. redis.Set(key, "", time.Second)
  1929. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + ":dialysis_orders_list_all"
  1930. redis.Set(keyOne, "", time.Second)
  1931. if updateErr != nil {
  1932. c.ErrorLog("修改下机失败:%v", updateErr)
  1933. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1934. return
  1935. }
  1936. if updateErr == nil {
  1937. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  1938. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  1939. fmt.Println(value)
  1940. a, b := math.Modf(value)
  1941. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  1942. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  1943. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  1944. monitor, _ := service.GetLastMonitorRecord(tempDialysisRecords.UserOrgId, tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate)
  1945. updateAssessmentErr := service.UpdateAssessmentAfterDateOne(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute, monitor.BreathingRate)
  1946. if updateAssessmentErr != nil {
  1947. utils.ErrorLog("%v", updateAssessmentErr)
  1948. }
  1949. }
  1950. after, _ := service.FindAssessmentAfterDislysisById(tempDialysisRecords.UserOrgId, tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate)
  1951. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  1952. c.ServeSuccessJSON(map[string]interface{}{
  1953. "dialysis_order": dialysisRecords,
  1954. "after": after,
  1955. })
  1956. }