dialysis_record_api_controller.go 65KB

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