dialysis_record_api_controller.go 93KB

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