dialysis_record_api_controller.go 81KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962
  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. }
  486. // /api/dislysis/monitor/edit [post]
  487. // @param patient_id:int 患者id
  488. // @param schedule_date:int 排班日期
  489. // 下面的参数放到 body
  490. // @param id?:int 监测记录ID(id为0时为创建记录,不为0时为修改记录)
  491. // @param monitoring_date:int 排班日期
  492. // @param operate_time:int 实际测量日期
  493. // @param monitoring_time:string (HH:mm) 监测时间 废弃
  494. // @param systolic_bp?:float 收缩压
  495. // @param diastolic_bp?:float 舒张压
  496. // @param pulse_frequency?:float 心率
  497. // @param breathing_rated?:float 呼吸频率
  498. // @param blood_flow_volume?:float 血流量
  499. // @param venous_pressure?:float 静脉压
  500. // @param transmembrane_pressure?:float 跨膜压
  501. // @param ultrafiltration_volume?:float 超滤量
  502. // @param ultrafiltration_rate?:float 超滤率
  503. // @param arterial_pressure?:float 动脉压
  504. // @param sodium_concentration?:float 钠浓度
  505. // @param dialysate_temperature?:float 透析液温度
  506. // @param replacement_rate?:float 置换率
  507. // @param displacement_quantity?:float 置换量
  508. // @param ktv?:float KT/V
  509. // @param symptom?:string 病情变化
  510. // @param dispose?:string 处理
  511. // @param result?:string 结果
  512. func (this *DialysisRecordAPIController) EditMonitor() {
  513. patientID, _ := this.GetInt64("patient_id")
  514. scheduleDate, _ := this.GetInt64("schedule_date")
  515. if patientID <= 0 || scheduleDate <= 0 {
  516. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  517. return
  518. }
  519. var monitorParam EditMonitorParamObject
  520. if parseErr := json.Unmarshal(this.Ctx.Input.RequestBody, &monitorParam); parseErr != nil {
  521. this.ErrorLog("参数解析失败:%v", parseErr)
  522. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamFormatWrong)
  523. return
  524. }
  525. if monitorParam.MonitoringDate != scheduleDate {
  526. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  527. return
  528. }
  529. adminUserInfo := this.GetAdminUserInfo()
  530. schedule, getScheduleErr := service.MobileGetSchedualDetail(adminUserInfo.CurrentOrgId, patientID, scheduleDate)
  531. if getScheduleErr != nil {
  532. this.ErrorLog("获取排班信息失败:%v", getScheduleErr)
  533. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  534. return
  535. } else if schedule == nil {
  536. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist)
  537. return
  538. }
  539. // TODO 其实这里合理的逻辑是“透析记录存在的情况下才能添加监测记录的”
  540. dialysisOrder, getDialysisOrderErr := service.MobileGetDialysisRecord(adminUserInfo.CurrentOrgId, patientID, scheduleDate)
  541. if getDialysisOrderErr != nil {
  542. this.ErrorLog("获取透析记录失败:%v", getDialysisOrderErr)
  543. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  544. return
  545. }
  546. orderID := int64(0)
  547. if dialysisOrder != nil {
  548. orderID = dialysisOrder.ID
  549. }
  550. if monitorParam.ID <= 0 { // 新建记录
  551. monitor := models.MonitoringRecord{
  552. UserOrgId: adminUserInfo.CurrentOrgId,
  553. PatientId: patientID,
  554. DialysisOrderId: orderID,
  555. MonitoringDate: monitorParam.MonitoringDate,
  556. OperateTime: monitorParam.OperateTime,
  557. // MonitoringTime: monitorParam.MonitoringTime,
  558. PulseFrequency: monitorParam.PulseFrequency,
  559. BreathingRate: monitorParam.BreathingRated,
  560. SystolicBloodPressure: monitorParam.SystolicBP,
  561. DiastolicBloodPressure: monitorParam.DiastolicBP,
  562. BloodFlowVolume: monitorParam.BloodFlowVolume,
  563. VenousPressure: monitorParam.VenousPressure,
  564. VenousPressureType: monitorParam.VenousPressureType,
  565. ArterialPressure: monitorParam.ArterialPressure,
  566. ArterialPressureType: monitorParam.ArterialPressureType,
  567. TransmembranePressure: monitorParam.TransmembranePressure,
  568. TransmembranePressureType: monitorParam.TransmembranePressureType,
  569. UltrafiltrationRate: monitorParam.UltrafiltrationRate,
  570. UltrafiltrationVolume: monitorParam.UltrafiltrationVolume,
  571. SodiumConcentration: monitorParam.SodiumConcentration,
  572. DialysateTemperature: monitorParam.DialysateTemperature,
  573. Temperature: monitorParam.Temperature,
  574. ReplacementRate: monitorParam.ReplacementRate,
  575. DisplacementQuantity: monitorParam.DisplacementQuantity,
  576. Ktv: monitorParam.KTV,
  577. Symptom: monitorParam.Symptom,
  578. Dispose: monitorParam.Dispose,
  579. Result: monitorParam.Result,
  580. MonitoringNurse: adminUserInfo.AdminUser.Id,
  581. Conductivity: monitorParam.Conductivity,
  582. DisplacementFlowQuantity: monitorParam.DisplacementFlowQuantity,
  583. Status: 1,
  584. CreatedTime: time.Now().Unix(),
  585. UpdatedTime: time.Now().Unix(),
  586. BloodOxygenSaturation: monitorParam.BloodOxygenSaturation,
  587. Creator: adminUserInfo.AdminUser.Id,
  588. Heparin: monitorParam.Heparin,
  589. DialysateFlow: monitorParam.DialysateFlow,
  590. Urr: monitorParam.Urr,
  591. BloodSugar: monitorParam.BloodSugar,
  592. MonitorAnticoagulant: monitorParam.MonitorAnticoagulant,
  593. MonitorAnticoagulantValue: monitorParam.MonitorAnticoagulantValue,
  594. BloodPressureMonitoringSite: monitorParam.BloodPressureMonitoringSite,
  595. Complication: monitorParam.Complication,
  596. AccumulatedBloodVolume: monitorParam.AccumulatedBloodVolume,
  597. BloodTemperature: monitorParam.BloodTemperature,
  598. UreaMonitoring: monitorParam.UreaMonitoring,
  599. BloodThickness: monitorParam.BloodThickness,
  600. BloodMonitor: monitorParam.BloodMonitor,
  601. HeparinAmount: monitorParam.HeparinAmount,
  602. Dehydration: monitorParam.Dehydration,
  603. FilterPressure: monitorParam.FilterPressure,
  604. }
  605. createErr := service.CreateMonitor(&monitor)
  606. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":monitor_records"
  607. redis := service.RedisClient()
  608. //清空key 值
  609. redis.Set(key, "", time.Second)
  610. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(monitorParam.MonitoringDate, 10) + ":monitor_record_list_all"
  611. redis.Set(keyOne, "", time.Second)
  612. defer redis.Close()
  613. if createErr != nil {
  614. this.ErrorLog("创建监测记录失败:%v", createErr)
  615. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  616. return
  617. }
  618. this.ServeSuccessJSON(map[string]interface{}{
  619. "monitor": monitor,
  620. })
  621. } else { // 修改记录
  622. monitor, getMonitorErr := service.GetMonitor(adminUserInfo.CurrentOrgId, patientID, monitorParam.ID)
  623. if getMonitorErr != nil {
  624. this.ErrorLog("获取透析监测记录失败:%v", getMonitorErr)
  625. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  626. return
  627. } else if monitor == nil {
  628. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorNotExist)
  629. return
  630. }
  631. //if monitor.MonitoringNurse != adminUserInfo.AdminUser.Id {
  632. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  633. // if getPermissionErr != nil {
  634. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  635. // return
  636. // } else if headNursePermission == nil {
  637. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  638. // return
  639. // }
  640. //}
  641. monitor.OperateTime = monitorParam.OperateTime
  642. monitor.PulseFrequency = monitorParam.PulseFrequency
  643. monitor.BreathingRate = monitorParam.BreathingRated
  644. monitor.SystolicBloodPressure = monitorParam.SystolicBP
  645. monitor.DiastolicBloodPressure = monitorParam.DiastolicBP
  646. monitor.BloodFlowVolume = monitorParam.BloodFlowVolume
  647. monitor.VenousPressure = monitorParam.VenousPressure
  648. monitor.VenousPressureType = monitorParam.VenousPressureType
  649. monitor.ArterialPressure = monitorParam.ArterialPressure
  650. monitor.ArterialPressureType = monitorParam.ArterialPressureType
  651. monitor.TransmembranePressure = monitorParam.TransmembranePressure
  652. monitor.TransmembranePressureType = monitorParam.TransmembranePressureType
  653. monitor.UltrafiltrationRate = monitorParam.UltrafiltrationRate
  654. monitor.UltrafiltrationVolume = monitorParam.UltrafiltrationVolume
  655. monitor.SodiumConcentration = monitorParam.SodiumConcentration
  656. monitor.DialysateTemperature = monitorParam.DialysateTemperature
  657. monitor.Temperature = monitorParam.Temperature
  658. monitor.ReplacementRate = monitorParam.ReplacementRate
  659. monitor.DisplacementQuantity = monitorParam.DisplacementQuantity
  660. monitor.Conductivity = monitorParam.Conductivity
  661. monitor.DisplacementFlowQuantity = monitorParam.DisplacementFlowQuantity
  662. monitor.Ktv = monitorParam.KTV
  663. monitor.Symptom = monitorParam.Symptom
  664. monitor.Dispose = monitorParam.Dispose
  665. monitor.Result = monitorParam.Result
  666. monitor.MonitoringNurse = adminUserInfo.AdminUser.Id
  667. monitor.UpdatedTime = time.Now().Unix()
  668. monitor.Modify = adminUserInfo.AdminUser.Id
  669. monitor.BloodOxygenSaturation = monitorParam.BloodOxygenSaturation
  670. monitor.Heparin = monitorParam.Heparin
  671. monitor.DialysateFlow = monitorParam.DialysateFlow
  672. monitor.Urr = monitorParam.Urr
  673. monitor.BloodSugar = monitorParam.BloodSugar
  674. monitor.MonitorAnticoagulant = monitorParam.MonitorAnticoagulant
  675. monitor.MonitorAnticoagulantValue = monitorParam.MonitorAnticoagulantValue
  676. monitor.AccumulatedBloodVolume = monitorParam.AccumulatedBloodVolume
  677. monitor.BloodTemperature = monitorParam.BloodTemperature
  678. monitor.UreaMonitoring = monitorParam.UreaMonitoring
  679. monitor.BloodThickness = monitorParam.BloodThickness
  680. monitor.BloodMonitor = monitorParam.BloodMonitor
  681. monitor.HeparinAmount = monitorParam.HeparinAmount
  682. monitor.Dehydration = monitorParam.Dehydration
  683. monitor.FilterPressure = monitorParam.FilterPressure
  684. updateErr := service.UpdateMonitor(monitor)
  685. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":monitor_records"
  686. redis := service.RedisClient()
  687. defer redis.Close()
  688. //清空key 值
  689. redis.Set(key, "", time.Second)
  690. if updateErr != nil {
  691. this.ErrorLog("修改透析监测记录失败:%v", updateErr)
  692. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  693. return
  694. }
  695. this.ServeSuccessJSON(map[string]interface{}{
  696. "monitor": monitor,
  697. })
  698. }
  699. }
  700. // /api/dialysis/start_record [post]
  701. // @param patient_id:int
  702. // @param date:string 排班时间 (yyyy-mm-dd)
  703. // @param nurse:int 上机护士
  704. // @param bed:int 上机床位号
  705. func (this *DialysisRecordAPIController) StartDialysis() {
  706. patientID, _ := this.GetInt64("patient_id")
  707. recordDateStr := this.GetString("date")
  708. nurseID, _ := this.GetInt64("nurse")
  709. punctureNurseId, _ := this.GetInt64("puncture_nurse")
  710. startDateStr := this.GetString("start_time")
  711. blood_drawing, _ := this.GetInt64("blood_drawing")
  712. schedual_type, _ := this.GetInt64("schedual_type")
  713. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  714. change_nurse, _ := this.GetInt64("change_nurse")
  715. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  716. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  717. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  718. puncture_needle := this.GetString("puncture_needle")
  719. puncture_way := this.GetString("puncture_way")
  720. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  721. dialysis_irrigation := this.GetString("dialysis_irrigation")
  722. blood_access_id, _ := this.GetInt64("blood_access_id")
  723. bedID, _ := this.GetInt64("bed")
  724. nuclein_date := this.GetString("nuclein_date")
  725. schedule_remark := this.GetString("schedule_remark")
  726. order_remark := this.GetString("order_remark")
  727. catheter_operation := this.GetString("catheter_operation")
  728. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  729. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  730. return
  731. }
  732. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  733. if parseErr != nil {
  734. this.ErrorLog("时间解析失败:%v", parseErr)
  735. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  736. return
  737. }
  738. startDate, parseErr := utils.ParseTimeStringToTime("2006-01-02 15:04", startDateStr)
  739. if parseErr != nil {
  740. this.ErrorLog("时间解析失败:%v", parseErr)
  741. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  742. return
  743. }
  744. adminUserInfo := this.GetAdminUserInfo()
  745. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.CurrentOrgId, patientID)
  746. if getPatientErr != nil {
  747. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  748. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  749. return
  750. } else if patient == nil {
  751. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  752. return
  753. }
  754. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  755. if getNurseErr != nil {
  756. this.ErrorLog("获取护士失败:%v", getNurseErr)
  757. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  758. return
  759. } else if nurse == nil {
  760. this.ErrorLog("护士不存在")
  761. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  762. return
  763. }
  764. //nurse, getNurseErr = service.GetAdminUserByUserID(punctureNurseId)
  765. //
  766. //if getNurseErr != nil {
  767. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  768. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  769. // return
  770. //} else if nurse == nil {
  771. // this.ErrorLog("护士不存在")
  772. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  773. // return
  774. //}
  775. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.CurrentOrgId, bedID)
  776. if getDeviceNumberErr != nil {
  777. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  778. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  779. return
  780. } else if deviceNumber == nil {
  781. this.ErrorLog("床位号不存在")
  782. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  783. return
  784. }
  785. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  786. if getRecordErr != nil {
  787. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  788. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  789. return
  790. } else if dialysisRecord != nil {
  791. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  792. return
  793. }
  794. template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  795. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  796. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  797. timeLayout := "2006-01-02 15:04:05"
  798. loc, _ := time.LoadLocation("Local")
  799. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  800. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  801. schedulestartTime := theStartTime.Unix()
  802. scheduleendTime := theEndTime.Unix()
  803. var theNucleinDate int64
  804. timeLayoutOne := "2006-01-02"
  805. if len(nuclein_date) > 0 {
  806. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date+" 00:00:00", loc)
  807. if err != nil {
  808. utils.ErrorLog(err.Error())
  809. }
  810. theNucleinDate = theTime.Unix()
  811. }
  812. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  813. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.CurrentOrgId, schedulestartTime, bedID, schedual_type)
  814. //查询该床位是否有人上机
  815. order, order_err := service.GetDialysisOrderByBedId(adminUserInfo.CurrentOrgId, schedulestartTime, bedID, schedual_type)
  816. if err == gorm.ErrRecordNotFound { //空床位
  817. // 修改了床位逻辑
  818. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, patientID)
  819. if daySchedule.ID > 0 {
  820. //daySchedule.PartitionId = deviceNumber.ZoneID
  821. //daySchedule.BedId = bedID
  822. //daySchedule.ScheduleType = schedual_type
  823. //daySchedule.UpdatedTime = time.Now().Unix()
  824. //err := service.UpdateSchedule(&daySchedule)
  825. xtSchedule := models.Schedule{
  826. PartitionId: deviceNumber.ZoneID,
  827. BedId: bedID,
  828. ScheduleType: schedual_type,
  829. UpdatedTime: time.Now().Unix(),
  830. }
  831. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  832. if err != nil {
  833. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  834. return
  835. }
  836. }
  837. } else if err == nil {
  838. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  839. if order_err == nil {
  840. if order.ID > 0 { //该机位被其他人占用了
  841. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  842. return
  843. } else {
  844. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, patientID)
  845. if daySchedule.ID > 0 {
  846. //daySchedule.PartitionId = deviceNumber.ZoneID
  847. //daySchedule.BedId = bedID
  848. //daySchedule.ScheduleType = schedual_type
  849. //daySchedule.UpdatedTime = time.Now().Unix()
  850. //err := service.UpdateSchedule(&daySchedule)
  851. xtSchedule := models.Schedule{
  852. PartitionId: deviceNumber.ZoneID,
  853. BedId: bedID,
  854. ScheduleType: schedual_type,
  855. UpdatedTime: time.Now().Unix(),
  856. }
  857. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  858. if err != nil {
  859. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  860. return
  861. }
  862. }
  863. }
  864. } else if order_err == gorm.ErrRecordNotFound { //该床位没被占用
  865. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, patientID)
  866. if daySchedule.ID > 0 {
  867. //daySchedule.PartitionId = deviceNumber.ZoneID
  868. //daySchedule.BedId = bedID
  869. //daySchedule.ScheduleType = schedual_type
  870. //daySchedule.UpdatedTime = time.Now().Unix()
  871. //err := service.UpdateSchedule(&daySchedule)
  872. xtSchedule := models.Schedule{
  873. PartitionId: deviceNumber.ZoneID,
  874. BedId: bedID,
  875. ScheduleType: schedual_type,
  876. UpdatedTime: time.Now().Unix(),
  877. }
  878. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  879. if err != nil {
  880. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  881. return
  882. }
  883. }
  884. } else if order_err != nil {
  885. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  886. return
  887. }
  888. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  889. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  890. return
  891. }
  892. } else if err != nil {
  893. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  894. return
  895. }
  896. dialysisRecord = &models.DialysisOrder{
  897. DialysisDate: recordDate.Unix(),
  898. UserOrgId: adminUserInfo.CurrentOrgId,
  899. PatientId: patientID,
  900. Stage: 1,
  901. BedID: bedID,
  902. StartNurse: nurseID,
  903. Status: 1,
  904. StartTime: startDate.Unix(),
  905. CreatedTime: time.Now().Unix(),
  906. UpdatedTime: time.Now().Unix(),
  907. PunctureNurse: punctureNurseId,
  908. Creator: adminUserInfo.AdminUser.Id,
  909. Modifier: adminUserInfo.AdminUser.Id,
  910. SchedualType: schedual_type,
  911. WashpipeNurse: washpipe_nurse,
  912. ChangeNurse: change_nurse,
  913. DifficultPunctureNurse: difficult_puncture_nurse,
  914. NewFistulaNurse: new_fistula_nurse,
  915. QualityNurseId: quality_nurse_id,
  916. PunctureNeedle: puncture_needle,
  917. PunctureWay: puncture_way,
  918. DialysisDialyszers: dialysis_dialyszers,
  919. DialysisIrrigation: dialysis_irrigation,
  920. BloodAccessId: blood_access_id,
  921. NucleinDate: theNucleinDate,
  922. ScheduleRemark: schedule_remark,
  923. OrderRemark: order_remark,
  924. CatheterOperation: catheter_operation,
  925. }
  926. createErr := service.MobileCreateDialysisOrder(adminUserInfo.CurrentOrgId, patientID, dialysisRecord)
  927. //更新患者表排班备注
  928. service.UpdateMobilePatient(adminUserInfo.CurrentOrgId, patientID, schedule_remark)
  929. ////统计该患者总次数
  930. //dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.CurrentOrgId, patientID)
  931. //
  932. //service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.CurrentOrgId, dialysisCount.Count)
  933. if adminUserInfo.CurrentOrgId != 10101 && adminUserInfo.CurrentOrgId != 10445 && adminUserInfo.CurrentOrgId != 3877 && adminUserInfo.CurrentOrgId != 10345 {
  934. //统计该患者总次数
  935. dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.CurrentOrgId, patientID)
  936. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.CurrentOrgId, dialysisCount.Count)
  937. }
  938. if adminUserInfo.CurrentOrgId == 10101 || adminUserInfo.CurrentOrgId == 10445 || adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 10345 {
  939. //统计该患者总次数
  940. dialysisCount, _ := service.GetDialysisTotalCountOne(adminUserInfo.CurrentOrgId, patientID)
  941. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.CurrentOrgId, dialysisCount.Count)
  942. }
  943. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  944. redis := service.RedisClient()
  945. //清空key 值
  946. redis.Set(key, "", time.Second)
  947. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  948. redis.Set(keyOne, "", time.Second)
  949. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  950. //清空key 值
  951. redis.Set(keyTwo, "", time.Second)
  952. defer redis.Close()
  953. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  954. if createErr != nil {
  955. this.ErrorLog("上机失败:%v", createErr)
  956. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  957. return
  958. } else if createErr == nil {
  959. var tempdispose string
  960. // 只针对中能建
  961. if blood_drawing > 0 && adminUserInfo.CurrentOrgId == 9538 { //adminUserInfo.CurrentOrgId == 9538
  962. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  963. }
  964. if blood_drawing > 0 && adminUserInfo.CurrentOrgId == 10318 { //adminUserInfo.CurrentOrgId == 9538
  965. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  966. }
  967. var ultrafiltration_rate float64
  968. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.CurrentOrgId)
  969. //获取预增水量
  970. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, schedulestartTime, adminUserInfo.CurrentOrgId)
  971. if prescription.ID > 0 {
  972. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  973. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  974. //fmt.Println("total23232323232322332", totalMin)
  975. if (template.TemplateId == 6 || template.TemplateId == 20 || template.TemplateId == 22 || template.TemplateId == 32 || template.TemplateId == 36) && adminUserInfo.CurrentOrgId != 9671 {
  976. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  977. }
  978. //针对福建医师汇
  979. if template.TemplateId == 6 && adminUserInfo.CurrentOrgId == 10121 {
  980. if evaluation.ID > 0 {
  981. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  982. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  983. }
  984. }
  985. if template.TemplateId == 6 && adminUserInfo.CurrentOrgId == 10234 {
  986. if evaluation.ID > 0 {
  987. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  988. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  989. }
  990. }
  991. // 只针对方济医院
  992. if template.TemplateId == 1 && adminUserInfo.CurrentOrgId != 9849 {
  993. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  994. ultrafiltration_rate = value
  995. }
  996. //针对监利大垸医院
  997. if adminUserInfo.CurrentOrgId == 10101 {
  998. if evaluation.ID > 0 {
  999. ultrafiltration_rate = math.Ceil(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  1000. }
  1001. }
  1002. //针对肇庆三鹤血液透析中心
  1003. if adminUserInfo.CurrentOrgId == 10215 || template.TemplateId == 43 || adminUserInfo.CurrentOrgId == 10441 || adminUserInfo.CurrentOrgId == 10445 || adminUserInfo.CurrentOrgId == 10469 {
  1004. if evaluation.ID > 0 {
  1005. ultrafiltration_rate = math.Ceil(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  1006. }
  1007. }
  1008. }
  1009. }
  1010. record := models.MonitoringRecord{
  1011. UserOrgId: adminUserInfo.CurrentOrgId,
  1012. PatientId: patientID,
  1013. DialysisOrderId: dialysisRecord.ID,
  1014. MonitoringDate: schedulestartTime,
  1015. OperateTime: startDate.Unix(),
  1016. // MonitoringTime: recordTime,
  1017. MonitoringNurse: nurseID,
  1018. Dispose: tempdispose,
  1019. UltrafiltrationRate: ultrafiltration_rate,
  1020. UltrafiltrationVolume: 0,
  1021. Status: 1,
  1022. CreatedTime: time.Now().Unix(),
  1023. UpdatedTime: time.Now().Unix(),
  1024. }
  1025. //只针对广慈医院
  1026. 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 {
  1027. // 查询病人是否有透前评估数据
  1028. befor, errcode := service.GetAssessmentBefor(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1029. //如果有数据就插入
  1030. if errcode == nil {
  1031. record.SystolicBloodPressure = befor.SystolicBloodPressure
  1032. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  1033. record.BreathingRate = befor.BreathingRate
  1034. record.PulseFrequency = befor.PulseFrequency
  1035. record.Temperature = befor.Temperature
  1036. }
  1037. }
  1038. // 如果当天有插入数据,则不再往透析纪录里插入数据
  1039. if newdialysisRecord.ID > 0 {
  1040. //针对长沙南雅医院
  1041. if adminUserInfo.CurrentOrgId == 9675 || adminUserInfo.CurrentOrgId == 10340 {
  1042. record.Temperature = 36.5
  1043. record.ArterialPressure = -100
  1044. record.Conductivity = 14
  1045. record.BreathingRate = "20"
  1046. record.DialysateTemperature = 36.5
  1047. record.VenousPressure = 80
  1048. record.TransmembranePressure = 60
  1049. }
  1050. //针对新化博翔
  1051. if adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 10447 {
  1052. record.BloodOxygenSaturation = "99"
  1053. record.Conductivity = 14
  1054. record.DialysateTemperature = 36.5
  1055. record.BreathingRate = "20"
  1056. }
  1057. //针对蓬安济民
  1058. if adminUserInfo.CurrentOrgId == 9829 || adminUserInfo.CurrentOrgId == 10440 {
  1059. record.Temperature = 36.5
  1060. record.PulseFrequency = 80
  1061. }
  1062. //针对兰溪人民医院的需求
  1063. if adminUserInfo.CurrentOrgId == 10432 {
  1064. befor, _ := service.GetAssessmentBefor(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1065. record.SystolicBloodPressure = befor.SystolicBloodPressure
  1066. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  1067. record.Temperature = befor.Temperature
  1068. record.PulseFrequency = befor.PulseFrequency
  1069. }
  1070. err := service.CreateMonitor(&record)
  1071. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_records"
  1072. redis := service.RedisClient()
  1073. //清空key 值
  1074. redis.Set(key, "", time.Second)
  1075. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_record_list_all"
  1076. redis.Set(keyOne, "", time.Second)
  1077. defer redis.Close()
  1078. if err != nil {
  1079. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  1080. return
  1081. }
  1082. }
  1083. go func() {
  1084. ssoDomain := beego.AppConfig.String("call_domain")
  1085. api := ssoDomain + "/index/uppatient"
  1086. values := make(url.Values)
  1087. values.Set("org_id", strconv.FormatInt(adminUserInfo.CurrentOrgId, 10))
  1088. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  1089. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  1090. values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
  1091. http.PostForm(api, values)
  1092. }()
  1093. this.ServeSuccessJSON(map[string]interface{}{
  1094. "dialysis_order": dialysisRecord,
  1095. "monitor": record,
  1096. })
  1097. }
  1098. }
  1099. // /api/dialysis/finish [post]
  1100. // @param patient_id:int
  1101. // @param date:string 排班时间 (yyyy-mm-dd)
  1102. // @param nurse:int 下机护士
  1103. func (this *DialysisRecordAPIController) FinishDialysis() {
  1104. patientID, _ := this.GetInt64("patient_id")
  1105. recordDateStr := this.GetString("date")
  1106. nurseID, _ := this.GetInt64("nurse")
  1107. end_time := this.GetString("end_time")
  1108. puncture_point_haematoma, _ := this.GetInt64("puncture_point_haematoma")
  1109. internal_fistula := this.GetString("internal_fistula")
  1110. catheter := this.GetString("catheter")
  1111. cruor := this.GetString("cruor")
  1112. mission := this.GetString("mission")
  1113. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 {
  1114. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1115. return
  1116. }
  1117. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1118. if parseErr != nil {
  1119. this.ErrorLog("时间解析失败:%v", parseErr)
  1120. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1121. return
  1122. }
  1123. //if parseEndDateErr != nil {
  1124. // this.ErrorLog("时间解析失败:%v", parseEndDateErr)
  1125. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1126. // return
  1127. //}
  1128. adminUserInfo := this.GetAdminUserInfo()
  1129. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.CurrentOrgId, patientID)
  1130. if getPatientErr != nil {
  1131. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  1132. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1133. return
  1134. } else if patient == nil {
  1135. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1136. return
  1137. }
  1138. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  1139. if getNurseErr != nil {
  1140. this.ErrorLog("获取护士失败:%v", getNurseErr)
  1141. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1142. return
  1143. } else if nurse == nil {
  1144. this.ErrorLog("护士不存在")
  1145. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1146. return
  1147. }
  1148. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1149. if getRecordErr != nil {
  1150. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  1151. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1152. return
  1153. }
  1154. if dialysisRecord.Stage == 2 {
  1155. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  1156. return
  1157. }
  1158. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04", end_time)
  1159. if parseEndDateErr != nil {
  1160. this.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  1161. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1162. return
  1163. }
  1164. // 获取当天的第一条透析纪录
  1165. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1166. if getMonitorRecordsErr != nil {
  1167. this.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  1168. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1169. return
  1170. }
  1171. // 获取当前的最后一条透析纪录
  1172. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecord(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1173. if getMonitorRecordsErr != nil {
  1174. this.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  1175. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1176. return
  1177. }
  1178. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysis(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1179. if getAADErr != nil {
  1180. this.ErrorLog("获取透后评估失败:%v", getAADErr)
  1181. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1182. return
  1183. }
  1184. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysis(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1185. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  1186. if assessmentAfterDislysis != nil {
  1187. tempassessmentAfterDislysis = *assessmentAfterDislysis
  1188. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  1189. } else {
  1190. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  1191. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  1192. tempassessmentAfterDislysis.Status = 1
  1193. tempassessmentAfterDislysis.PatientId = patientID
  1194. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.CurrentOrgId
  1195. }
  1196. if dialysisRecord.Stage == 1 {
  1197. temp_time := (float64(endDate.Unix()) - float64(dialysisRecord.StartTime)) / 3600
  1198. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  1199. fmt.Println(value)
  1200. a, b := math.Modf(value)
  1201. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  1202. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  1203. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  1204. fmt.Println(hour)
  1205. fmt.Println(minute)
  1206. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  1207. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  1208. }
  1209. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  1210. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  1211. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  1212. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  1213. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  1214. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  1215. //长沙南雅
  1216. if adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 9675 || adminUserInfo.CurrentOrgId == 10340 {
  1217. //获取最后一条透析处方数据
  1218. prescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1219. evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1220. tempassessmentAfterDislysis.WeightAfter = evaluation.WeightBefore - prescription.TargetUltrafiltration/1000
  1221. }
  1222. if adminUserInfo.CurrentOrgId == 10101 {
  1223. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  1224. } else {
  1225. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  1226. }
  1227. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  1228. //新化博翔
  1229. if adminUserInfo.CurrentOrgId == 10447 || adminUserInfo.CurrentOrgId == 9675 {
  1230. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  1231. }
  1232. //针对蓬安
  1233. if adminUserInfo.CurrentOrgId == 9829 || adminUserInfo.CurrentOrgId == 10440 {
  1234. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  1235. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  1236. }
  1237. }
  1238. if adminUserInfo.CurrentOrgId == 9583 {
  1239. //获取最后一条透析处方数据
  1240. prescription, parseErr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1241. if parseErr != nil {
  1242. this.ErrorLog("获取透析处方失败:%v", getMonitorRecordsErr)
  1243. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1244. return
  1245. }
  1246. if prescription.ID > 0 && adminUserInfo.CurrentOrgId == 9583 {
  1247. tempassessmentAfterDislysis.ActualUltrafiltration = prescription.TargetUltrafiltration
  1248. }
  1249. if endmonitorRecords.ID > 0 && adminUserInfo.CurrentOrgId == 10060 {
  1250. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  1251. }
  1252. }
  1253. if lastAssessmentAfterDislysis != nil {
  1254. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  1255. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  1256. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  1257. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  1258. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  1259. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  1260. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  1261. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  1262. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  1263. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  1264. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  1265. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  1266. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  1267. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  1268. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  1269. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  1270. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  1271. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  1272. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  1273. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  1274. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  1275. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  1276. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  1277. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  1278. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  1279. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  1280. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  1281. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  1282. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  1283. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  1284. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  1285. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  1286. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  1287. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  1288. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  1289. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  1290. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  1291. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  1292. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  1293. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  1294. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  1295. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  1296. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  1297. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  1298. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  1299. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  1300. }
  1301. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  1302. 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 {
  1303. evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1304. if evaluation.SystolicBloodPressure == 0 {
  1305. pre := models.PredialysisEvaluation{
  1306. SystolicBloodPressure: fmonitorRecords.SystolicBloodPressure,
  1307. }
  1308. fmt.Println("prew", pre)
  1309. getNurseErr := service.UpdatePredialysisEvaluation(&pre, evaluation.ID)
  1310. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  1311. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  1312. redis := service.RedisClient()
  1313. redis.Set(key, "", time.Second)
  1314. redis.Set(keyOne, "", time.Second)
  1315. defer redis.Close()
  1316. fmt.Println(getNurseErr)
  1317. }
  1318. if evaluation.DiastolicBloodPressure == 0 {
  1319. pres := models.PredialysisEvaluation{
  1320. DiastolicBloodPressure: fmonitorRecords.DiastolicBloodPressure,
  1321. }
  1322. getNurseErr := service.UpdatePredialysisEvaluationTwo(&pres, evaluation.ID)
  1323. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  1324. redis := service.RedisClient()
  1325. redis.Set(key, "", time.Second)
  1326. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  1327. redis.Set(keyOne, "", time.Second)
  1328. defer redis.Close()
  1329. fmt.Println(getNurseErr)
  1330. }
  1331. if evaluation.PulseFrequency == 0 {
  1332. evaluation.PulseFrequency = fmonitorRecords.PulseFrequency
  1333. press := models.PredialysisEvaluation{
  1334. PulseFrequency: evaluation.PulseFrequency,
  1335. }
  1336. getNurseErr := service.UpdatePredialysisEvaluationThree(&press, evaluation.ID)
  1337. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  1338. redis := service.RedisClient()
  1339. redis.Set(key, "", time.Second)
  1340. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  1341. redis.Set(keyOne, "", time.Second)
  1342. defer redis.Close()
  1343. fmt.Println(getNurseErr)
  1344. }
  1345. if evaluation.Temperature == 0 {
  1346. evaluation.Temperature = fmonitorRecords.Temperature
  1347. press := models.PredialysisEvaluation{
  1348. Temperature: evaluation.Temperature,
  1349. }
  1350. getNurseErr := service.UpdatePredialysisEvaluationFour(&press, evaluation.ID)
  1351. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  1352. redis := service.RedisClient()
  1353. redis.Set(key, "", time.Second)
  1354. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  1355. redis.Set(keyOne, "", time.Second)
  1356. defer redis.Close()
  1357. fmt.Println(getNurseErr)
  1358. }
  1359. }
  1360. if err != nil {
  1361. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1362. return
  1363. }
  1364. go func() {
  1365. ssoDomain := beego.AppConfig.String("call_domain")
  1366. api := ssoDomain + "/index/downpatient"
  1367. values := make(url.Values)
  1368. values.Set("org_id", strconv.FormatInt(adminUserInfo.CurrentOrgId, 10))
  1369. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  1370. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  1371. http.PostForm(api, values)
  1372. }()
  1373. //执行下机
  1374. updateErr := service.ModifyDialysisRecord(dialysisRecord.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id, puncture_point_haematoma, internal_fistula, catheter, cruor, mission)
  1375. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  1376. redis := service.RedisClient()
  1377. defer redis.Close()
  1378. //清空key 值
  1379. redis.Set(key, "", time.Second)
  1380. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  1381. redis.Set(keyOne, "", time.Second)
  1382. if updateErr != nil {
  1383. this.ErrorLog("下机失败:%v", updateErr)
  1384. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1385. return
  1386. } else {
  1387. dialysisRecord.Stage = 2
  1388. dialysisRecord.FinishNurse = nurseID
  1389. dialysisRecord.FinishCreator = adminUserInfo.AdminUser.Id
  1390. dialysisRecord.FinishModifier = adminUserInfo.AdminUser.Id
  1391. dialysisRecord.EndTime = endDate.Unix()
  1392. // 结束时候透析次数加1
  1393. service.UpdateSolutionByPatientId(patientID)
  1394. this.ServeSuccessJSON(map[string]interface{}{
  1395. "dialysis_order": dialysisRecord,
  1396. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  1397. })
  1398. }
  1399. }
  1400. func (this *DialysisRecordAPIController) ModifyStartDialysis() {
  1401. record_id, _ := this.GetInt64("id")
  1402. nurseID, _ := this.GetInt64("nurse")
  1403. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  1404. bedID, _ := this.GetInt64("bed")
  1405. start_time := this.GetString("start_time")
  1406. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  1407. schedual_type, _ := this.GetInt64("schedual_type")
  1408. change_nurse, _ := this.GetInt64("change_nurse")
  1409. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  1410. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  1411. quality_nurse, _ := this.GetInt64("quality_nurse")
  1412. puncture_needle := this.GetString("puncture_needle")
  1413. puncture_way := this.GetString("puncture_way")
  1414. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  1415. dialysis_irrigation := this.GetString("dialysis_irrigation")
  1416. blood_access_id, _ := this.GetInt64("blood_access_id")
  1417. nuclein_date := this.GetString("nuclein_date")
  1418. schedule_remark := this.GetString("schedule_remark")
  1419. order_remark := this.GetString("order_remark")
  1420. catheter_operation := this.GetString("catheter_operation")
  1421. if record_id == 0 {
  1422. this.ErrorLog("id:%v", record_id)
  1423. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1424. return
  1425. }
  1426. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04", start_time)
  1427. if parseStartDateErr != nil {
  1428. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  1429. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1430. return
  1431. }
  1432. adminUserInfo := this.GetAdminUserInfo()
  1433. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  1434. if getNurseErr != nil {
  1435. this.ErrorLog("获取护士失败:%v", getNurseErr)
  1436. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1437. return
  1438. } else if nurse == nil {
  1439. this.ErrorLog("护士不存在")
  1440. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1441. return
  1442. }
  1443. //nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  1444. //if getNurseErr != nil {
  1445. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  1446. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1447. // return
  1448. //} else if nurse == nil {
  1449. // this.ErrorLog("护士不存在")
  1450. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1451. // return
  1452. //}
  1453. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.CurrentOrgId, bedID)
  1454. if getDeviceNumberErr != nil {
  1455. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  1456. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1457. return
  1458. } else if deviceNumber == nil {
  1459. this.ErrorLog("床位号不存在")
  1460. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1461. return
  1462. }
  1463. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  1464. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  1465. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1466. // if getPermissionErr != nil {
  1467. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1468. // return
  1469. // } else if headNursePermission == nil {
  1470. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1471. // return
  1472. // }
  1473. //}
  1474. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  1475. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  1476. timeLayout := "2006-01-02 15:04:05"
  1477. loc, _ := time.LoadLocation("Local")
  1478. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  1479. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  1480. schedulestartTime := theStartTime.Unix()
  1481. scheduleendTime := theEndTime.Unix()
  1482. var theNucleinDate int64
  1483. timeLayoutOne := "2006-01-02"
  1484. if len(nuclein_date) > 0 {
  1485. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date+" 00:00:00", loc)
  1486. if err != nil {
  1487. utils.ErrorLog(err.Error())
  1488. }
  1489. theNucleinDate = theTime.Unix()
  1490. }
  1491. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  1492. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.CurrentOrgId, schedulestartTime, bedID, schedual_type)
  1493. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  1494. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  1495. if err == gorm.ErrRecordNotFound { //空床位
  1496. // 修改了床位逻辑
  1497. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  1498. if daySchedule.ID > 0 {
  1499. //daySchedule.BedId = bedID
  1500. //daySchedule.PartitionId = deviceNumber.ZoneID
  1501. //daySchedule.ScheduleType = schedual_type
  1502. //daySchedule.UpdatedTime = time.Now().Unix()
  1503. //err := service.UpdateSchedule(&daySchedule)
  1504. xtSchedule := models.Schedule{
  1505. PartitionId: deviceNumber.ZoneID,
  1506. BedId: bedID,
  1507. ScheduleType: schedual_type,
  1508. UpdatedTime: time.Now().Unix(),
  1509. }
  1510. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  1511. if err != nil {
  1512. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1513. return
  1514. }
  1515. }
  1516. } else if err == nil {
  1517. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  1518. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  1519. if daySchedule.ID > 0 {
  1520. //daySchedule.BedId = bedID
  1521. //daySchedule.PartitionId = deviceNumber.ZoneID
  1522. //
  1523. //daySchedule.ScheduleType = schedual_type
  1524. //daySchedule.UpdatedTime = time.Now().Unix()
  1525. //err := service.UpdateSchedule(&daySchedule)
  1526. xtSchedule := models.Schedule{
  1527. PartitionId: deviceNumber.ZoneID,
  1528. BedId: bedID,
  1529. ScheduleType: schedual_type,
  1530. UpdatedTime: time.Now().Unix(),
  1531. }
  1532. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  1533. if err != nil {
  1534. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1535. return
  1536. }
  1537. }
  1538. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  1539. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  1540. return
  1541. }
  1542. } else if err != nil {
  1543. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1544. return
  1545. }
  1546. }
  1547. dialysisRecord := &models.DialysisOrder{
  1548. ID: record_id,
  1549. UserOrgId: adminUserInfo.CurrentOrgId,
  1550. BedID: bedID,
  1551. StartNurse: nurseID,
  1552. StartTime: startDate.Unix(),
  1553. PunctureNurse: puncture_nurse,
  1554. Creator: adminUserInfo.AdminUser.Id,
  1555. Modifier: adminUserInfo.AdminUser.Id,
  1556. SchedualType: schedual_type,
  1557. WashpipeNurse: washpipe_nurse,
  1558. ChangeNurse: change_nurse,
  1559. DifficultPunctureNurse: difficult_puncture_nurse,
  1560. NewFistulaNurse: new_fistula_nurse,
  1561. QualityNurseId: quality_nurse,
  1562. PunctureWay: puncture_way,
  1563. PunctureNeedle: puncture_needle,
  1564. DialysisDialyszers: dialysis_dialyszers,
  1565. DialysisIrrigation: dialysis_irrigation,
  1566. BloodAccessId: blood_access_id,
  1567. NucleinDate: theNucleinDate,
  1568. ScheduleRemark: schedule_remark,
  1569. OrderRemark: order_remark,
  1570. CatheterOperation: catheter_operation,
  1571. }
  1572. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  1573. order, _ := service.GetLastPatientOrder(record_id)
  1574. service.UpdateMobilePatient(adminUserInfo.CurrentOrgId, order.PatientId, schedule_remark)
  1575. redis := service.RedisClient()
  1576. key := strconv.FormatInt(tempDialysisRecord.UserOrgId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":dialysis_order"
  1577. redis.Set(key, "", time.Second)
  1578. keyOne := strconv.FormatInt(tempDialysisRecord.UserOrgId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":dialysis_orders_list_all"
  1579. //清空key 值
  1580. redis.Set(keyOne, "", time.Second)
  1581. scheduleDateStartOne := startDate.Format("2006-01-02")
  1582. keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(tempDialysisRecord.UserOrgId, 10)
  1583. redis.Set(keyTwo, "", time.Second)
  1584. keyThree := strconv.FormatInt(tempDialysisRecord.UserOrgId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":doctor_advices"
  1585. redis.Set(keyThree, "", time.Second)
  1586. keyFour := strconv.FormatInt(tempDialysisRecord.UserOrgId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_records"
  1587. redis.Set(keyFour, "", time.Second)
  1588. keyFive := strconv.FormatInt(tempDialysisRecord.UserOrgId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":patient_info"
  1589. redis.Set(keyFive, "", time.Second)
  1590. keySix := strconv.FormatInt(tempDialysisRecord.UserOrgId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":his_doctor_advice"
  1591. redis.Set(keySix, "", time.Second)
  1592. keySeven := strconv.FormatInt(tempDialysisRecord.UserOrgId, 10) + ":" + ":device_list_all"
  1593. redis.Set(keySeven, "", time.Second)
  1594. if updateErr != nil {
  1595. this.ErrorLog("修改上机失败:%v", updateErr)
  1596. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1597. return
  1598. }
  1599. if updateErr == nil {
  1600. if tempDialysisRecord.Stage == 2 {
  1601. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  1602. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  1603. fmt.Println(value)
  1604. a, b := math.Modf(value)
  1605. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  1606. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  1607. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  1608. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  1609. redis := service.RedisClient()
  1610. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":assessment_after_dislysis_list_all"
  1611. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":dialysis_orders_list_all"
  1612. redis.Set(key, "", time.Second)
  1613. redis.Set(keyThree, "", time.Second)
  1614. redis.Close()
  1615. if updateAssessmentErr != nil {
  1616. utils.ErrorLog("%v", updateAssessmentErr)
  1617. }
  1618. after, _ := service.FindAssessmentAfterDislysisById(tempDialysisRecord.UserOrgId, tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  1619. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  1620. this.ServeSuccessJSON(map[string]interface{}{
  1621. "dialysis_order": dialysisRecords,
  1622. "after": after,
  1623. })
  1624. } else {
  1625. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  1626. this.ServeSuccessJSON(map[string]interface{}{
  1627. "dialysis_order": dialysisRecords,
  1628. })
  1629. }
  1630. }
  1631. }
  1632. func (c *DialysisRecordAPIController) ModifyFinishDialysis() {
  1633. record_id, _ := c.GetInt64("id")
  1634. nurseID, _ := c.GetInt64("nurse")
  1635. end_time := c.GetString("end_time")
  1636. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  1637. internal_fistula := c.GetString("internal_fistula")
  1638. catheter := c.GetString("catheter")
  1639. cruor := c.GetString("cruor")
  1640. mission := c.GetString("mission")
  1641. if record_id <= 0 || nurseID <= 0 {
  1642. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1643. return
  1644. }
  1645. adminUserInfo := c.GetAdminUserInfo()
  1646. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  1647. if getNurseErr != nil {
  1648. c.ErrorLog("获取护士失败:%v", getNurseErr)
  1649. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1650. return
  1651. } else if nurse == nil {
  1652. c.ErrorLog("护士不存在")
  1653. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1654. return
  1655. }
  1656. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04", end_time)
  1657. if parseEndDateErr != nil {
  1658. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  1659. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1660. return
  1661. }
  1662. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  1663. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  1664. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1665. // if getPermissionErr != nil {
  1666. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1667. // return
  1668. // } else if headNursePermission == nil {
  1669. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1670. // return
  1671. // }
  1672. //}
  1673. dialysisRecord := &models.DialysisOrder{
  1674. ID: record_id,
  1675. UserOrgId: adminUserInfo.CurrentOrgId,
  1676. EndTime: endDate.Unix(),
  1677. FinishNurse: nurseID,
  1678. FinishModifier: adminUserInfo.AdminUser.Id,
  1679. PuncturePointHaematoma: puncture_point_haematoma,
  1680. BloodAccessInternalFistula: internal_fistula,
  1681. Catheter: catheter,
  1682. Cruor: cruor,
  1683. Mission: mission,
  1684. }
  1685. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  1686. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_order"
  1687. redis := service.RedisClient()
  1688. defer redis.Close()
  1689. //清空key 值
  1690. redis.Set(key, "", time.Second)
  1691. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + ":dialysis_orders_list_all"
  1692. redis.Set(keyOne, "", time.Second)
  1693. if updateErr != nil {
  1694. c.ErrorLog("修改下机失败:%v", updateErr)
  1695. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1696. return
  1697. }
  1698. if updateErr == nil {
  1699. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  1700. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  1701. fmt.Println(value)
  1702. a, b := math.Modf(value)
  1703. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  1704. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  1705. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  1706. monitor, _ := service.GetLastMonitorRecord(tempDialysisRecords.UserOrgId, tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate)
  1707. updateAssessmentErr := service.UpdateAssessmentAfterDateOne(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute, monitor.BreathingRate)
  1708. if updateAssessmentErr != nil {
  1709. utils.ErrorLog("%v", updateAssessmentErr)
  1710. }
  1711. }
  1712. after, _ := service.FindAssessmentAfterDislysisById(tempDialysisRecords.UserOrgId, tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate)
  1713. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  1714. c.ServeSuccessJSON(map[string]interface{}{
  1715. "dialysis_order": dialysisRecords,
  1716. "after": after,
  1717. })
  1718. }