check_weight_api_controller.go 47KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254
  1. package mobile_api_controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. _ "XT_New/utils"
  7. _ "encoding/json"
  8. "fmt"
  9. "github.com/astaxie/beego"
  10. _ "github.com/astaxie/beego"
  11. "github.com/jinzhu/gorm"
  12. "net/http"
  13. "net/url"
  14. "strconv"
  15. _ "strings"
  16. // "fmt"
  17. _ "reflect"
  18. "time"
  19. )
  20. type CheckWeightApiController struct {
  21. MobileBaseAPIAuthController
  22. }
  23. func (c *CheckWeightApiController) SaveBloodPressure() {
  24. id, _ := c.GetInt64("patient", 0)
  25. dialysistype, _ := c.GetInt64("dialysistype", 0)
  26. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0) //收缩压
  27. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0) //舒张压
  28. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0) //脉率
  29. if id <= 0 {
  30. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  31. return
  32. }
  33. if dialysistype <= 0 {
  34. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  35. return
  36. }
  37. if systolic_blood_pressure <= 0 {
  38. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  39. return
  40. }
  41. if diastolic_blood_pressure <= 0 {
  42. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  43. return
  44. }
  45. adminUserInfo := c.GetMobileAdminUserInfo()
  46. patient, _ := service.FindPatientByIdWithDiseases(adminUserInfo.Org.Id, id)
  47. if patient.ID == 0 {
  48. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  49. return
  50. }
  51. thisTime := time.Now()
  52. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  53. timeLayout := "2006-01-02 15:04:05"
  54. loc, _ := time.LoadLocation("Local")
  55. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  56. theAssessmentDateTime := theStartTime.Unix()
  57. if dialysistype == 1 {
  58. // 保存透前相关数据
  59. // 获取透析处方
  60. //dialysisPrescribe, getDialysisPrescribeErr := service.MobileGetDialysisPrescribe(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  61. //if getDialysisPrescribeErr != nil {
  62. // c.ErrorLog("获取透析处方失败:%v", getDialysisPrescribeErr)
  63. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  64. // return
  65. //}
  66. //
  67. //// 获取透析模版
  68. //dialysisSolution, getDialysisSolutionErr := service.MobileGetDialysisSolution(adminUserInfo.Org.Id, id)
  69. //if getDialysisSolutionErr != nil {
  70. // c.ErrorLog("获取透析方案失败:%v", getDialysisSolutionErr)
  71. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  72. // return
  73. //}
  74. // 插入透析处方
  75. //if dialysisPrescribe == nil && dialysisSolution != nil {
  76. // var newprescribe models.DialysisPrescription
  77. // newprescribe.UserOrgId = dialysisSolution.UserOrgId
  78. // newprescribe.PatientId = dialysisSolution.PatientId
  79. // newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  80. // newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  81. // newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  82. // newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  83. // newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  84. // newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  85. // newprescribe.ModeId = dialysisSolution.ModeId
  86. // newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  87. // newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  88. // newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  89. // newprescribe.BloodFilter = dialysisSolution.BloodFilter
  90. // newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  91. // newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  92. // newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  93. // newprescribe.Glucose = dialysisSolution.Glucose
  94. // newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  95. // newprescribe.Kalium = dialysisSolution.Kalium
  96. // newprescribe.Sodium = dialysisSolution.Sodium
  97. // newprescribe.Calcium = dialysisSolution.Calcium
  98. // newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  99. // newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  100. // newprescribe.Conductivity = dialysisSolution.Conductivity
  101. // newprescribe.BodyFluid = dialysisSolution.BodyFluid
  102. // newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  103. // newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  104. // newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  105. // newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  106. // newprescribe.BloodAccess = dialysisSolution.BloodAccess
  107. // newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  108. // newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  109. // newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  110. // newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  111. // newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  112. // newprescribe.Dialyzer = dialysisSolution.Dialyzer
  113. // newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  114. // newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  115. // newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  116. // newprescribe.TargetKtv = dialysisSolution.TargetKtv
  117. //
  118. // newprescribe.CreatedTime = time.Now().Unix()
  119. // newprescribe.UpdatedTime = time.Now().Unix()
  120. // newprescribe.RecordDate = theAssessmentDateTime
  121. // // newprescribe.DewaterAmount = dewater_amount
  122. // // newprescribe.TargetUltrafiltration = dewater_amount
  123. // newprescribe.Status = 1
  124. //
  125. // err := service.AddSigleRecord(&newprescribe)
  126. // if err != nil {
  127. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  128. // }
  129. //}
  130. //if dialysisPrescribe == nil && dialysisSolution == nil {
  131. // var newprescribe models.DialysisPrescription
  132. // newprescribe.UserOrgId = adminUserInfo.Org.Id
  133. // newprescribe.PatientId = id
  134. // newprescribe.CreatedTime = time.Now().Unix()
  135. // newprescribe.UpdatedTime = time.Now().Unix()
  136. // newprescribe.RecordDate = theAssessmentDateTime
  137. // // newprescribe.DewaterAmount = dewater_amount
  138. // // newprescribe.TargetUltrafiltration = dewater_amount
  139. // newprescribe.Status = 1
  140. //
  141. // err := service.AddSigleRecord(&newprescribe)
  142. // if err != nil {
  143. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  144. // }
  145. //}
  146. //if dialysisPrescribe != nil {
  147. // dialysisPrescribe.UpdatedTime = time.Now().Unix()
  148. // dialysisPrescribe.RecordDate = theAssessmentDateTime
  149. // // dialysisPrescribe.DewaterAmount = dewater_amount
  150. // // dialysisPrescribe.TargetUltrafiltration = dewater_amount
  151. // dialysisPrescribe.Status = 1
  152. // updateErr := service.UpDateDialysisPrescription(dialysisPrescribe)
  153. // if updateErr != nil {
  154. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  155. // }
  156. //}
  157. theEvaluation, getPEErr := service.MobileGetPredialysisEvaluation(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  158. if getPEErr != nil {
  159. c.ErrorLog("获取透前评估失败:%v", getPEErr)
  160. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  161. return
  162. }
  163. var evaluation models.PredialysisEvaluation
  164. if theEvaluation != nil {
  165. evaluation = *theEvaluation
  166. }
  167. // 如果今天没有透前评估,则插入新的数据
  168. if theEvaluation == nil {
  169. evaluation.CreatedTime = time.Now().Unix()
  170. evaluation.Status = 1
  171. evaluation.AssessmentDate = theAssessmentDateTime
  172. evaluation.PatientId = id
  173. evaluation.UserOrgId = adminUserInfo.Org.Id
  174. // 获取上一次透前评估信息,部分数据是需要从上一次透前评估继承
  175. lastPredialysisEvaluation, _ := service.MobileGetLastTimePredialysisEvaluation(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  176. // 获取上一次透后评估,插入本次透前评估的上次透后体重(weight_after_last_transparency)字段
  177. assessmentAfterDislysis, getAADErr := service.MobileGetLastTimeAssessmentAfterDislysis(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  178. if getAADErr != nil {
  179. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  180. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  181. return
  182. }
  183. // 获取干体重,先从干体重配置里去读,如果没有,则读取上一次透前评估的干体重
  184. weight, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, id)
  185. if err == gorm.ErrRecordNotFound {
  186. if lastPredialysisEvaluation != nil {
  187. evaluation.DryWeight = lastPredialysisEvaluation.DryWeight
  188. } else {
  189. evaluation.DryWeight = 0
  190. }
  191. } else {
  192. evaluation.DryWeight = weight.DryWeight
  193. }
  194. if assessmentAfterDislysis != nil {
  195. evaluation.WeightAfterLastTransparency = assessmentAfterDislysis.WeightAfter
  196. }
  197. if lastPredialysisEvaluation != nil {
  198. evaluation.BloodAccessPartId = lastPredialysisEvaluation.BloodAccessPartId
  199. evaluation.BloodAccessPartOperaId = lastPredialysisEvaluation.BloodAccessPartOperaId
  200. evaluation.AdditionalWeight = lastPredialysisEvaluation.AdditionalWeight // 衣物重
  201. }
  202. } else {
  203. evaluation.UpdatedTime = time.Now().Unix()
  204. }
  205. evaluation.SystolicBloodPressure = systolic_blood_pressure // 收缩压
  206. evaluation.DiastolicBloodPressure = diastolic_blood_pressure // 舒张压
  207. evaluation.PulseFrequency = pulse_frequency // 脉率
  208. evaluation.AssessmentTime = time.Now().Unix()
  209. err := service.UpadatePredialysisEvaluation(&evaluation)
  210. if err != nil {
  211. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  212. return
  213. }
  214. c.ServeSuccessJSON(map[string]interface{}{
  215. "msg": "ok",
  216. "evaluation": evaluation,
  217. })
  218. return
  219. } else {
  220. // 保存透后相关数据
  221. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysis(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  222. if getAADErr != nil {
  223. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  224. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  225. return
  226. }
  227. var afterevaluation models.AssessmentAfterDislysis
  228. if assessmentAfterDislysis != nil {
  229. afterevaluation = *assessmentAfterDislysis
  230. }
  231. if assessmentAfterDislysis == nil {
  232. afterevaluation.CreatedTime = time.Now().Unix()
  233. afterevaluation.Status = 1
  234. afterevaluation.AssessmentDate = theAssessmentDateTime
  235. afterevaluation.PatientId = id
  236. afterevaluation.UserOrgId = adminUserInfo.Org.Id
  237. } else {
  238. afterevaluation.UpdatedTime = time.Now().Unix()
  239. }
  240. afterevaluation.SystolicBloodPressure = systolic_blood_pressure // 收缩压
  241. afterevaluation.DiastolicBloodPressure = diastolic_blood_pressure // 舒张压
  242. afterevaluation.PulseFrequency = pulse_frequency // 脉率
  243. if adminUserInfo.Org.Id == 10138 {
  244. afterevaluation.LeaveOfficeMethod = assessmentAfterDislysis.LeaveOfficeMethod //离科方式
  245. afterevaluation.Lapse = assessmentAfterDislysis.Lapse //转归
  246. afterevaluation.Consciousness = assessmentAfterDislysis.Consciousness //意识
  247. afterevaluation.Fallrisk = assessmentAfterDislysis.Fallrisk //跌倒风险
  248. }
  249. err := service.UpdateAssessmentAfterDislysisRecord(&afterevaluation)
  250. if err == nil {
  251. c.ServeSuccessJSON(map[string]interface{}{
  252. "assessmentAfterDislysis": afterevaluation,
  253. })
  254. }
  255. }
  256. }
  257. func (c *CheckWeightApiController) SavePatientInfoDialysis() {
  258. id, _ := c.GetInt64("patient", 0)
  259. dialysistype, _ := c.GetInt64("dialysistype", 0)
  260. if id <= 0 {
  261. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  262. return
  263. }
  264. if dialysistype <= 0 {
  265. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  266. return
  267. }
  268. adminUserInfo := c.GetMobileAdminUserInfo()
  269. patient, _ := service.FindPatientByIdWithDiseases(adminUserInfo.Org.Id, id)
  270. if patient.ID == 0 {
  271. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  272. return
  273. }
  274. thisTime := time.Now()
  275. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  276. // scheduleDateEnd := thisTime.Format("2006-01-02") + " 23:59:59"
  277. timeLayout := "2006-01-02 15:04:05"
  278. loc, _ := time.LoadLocation("Local")
  279. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  280. // theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  281. theAssessmentDateTime := theStartTime.Unix()
  282. // endTime := theEndTime.Unix()
  283. // dry_weight,_ := c.GetFloat("dry_weight",0) // 干体重
  284. weighing_before, _ := c.GetFloat("weighing_before", 0) // 透前体重
  285. dewater_amount, _ := c.GetFloat("dewater_amount", 0) // 目标脱水量(L)
  286. weight_after, _ := c.GetFloat("weight_after", 0) // 透后体重
  287. weight_loss, _ := c.GetFloat("weight_loss", 0) // 体重减少
  288. schedual, _ := service.MobileGetSchedualDetail(adminUserInfo.Org.Id, patient.ID, theStartTime.Unix())
  289. //dialysisSolution,_ := service.MobileGetDialysisSolutionByModeId(adminUserInfo.Org.Id,patient.ID,schedual.ModeId)
  290. //dialysisPrescribe, _ := service.MobileGetDialysisPrescribeByModeId(adminUserInfo.Org.Id, patient.ID, theStartTime.Unix(),schedual.ModeId)
  291. //dialysisPrescribe, _ := service.MobileGetDialysisPrescribeByModeId(adminUserInfo.Org.Id, patient.ID, theStartTime.Unix(),schedual.ModeId)
  292. //dialysisPrescribe, _ := service.MobileGetDialysisPrescribeByModeId(adminUserInfo.Org.Id, patient.ID, theStartTime.Unix(),schedual.ModeId)
  293. // 查询当前用户今天有没有排班,没有排班,则不处理
  294. // daySchedule, _ := service.GetPatientScheduleFormDay(adminUserInfo.Org.Id, theAssessmentDateTime, endTime, id)
  295. // if(len(daySchedule) <= 0) {
  296. // c.ServeSuccessJSON(map[string]interface{}{
  297. // "msg": "ok",
  298. // })
  299. // return
  300. // }
  301. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  302. if template.TemplateId == 22 || template.TemplateId == 17 || template.TemplateId == 21 || template.TemplateId == 26 || template.TemplateId == 27 || template.TemplateId == 34 || template.TemplateId == 30 || template.TemplateId == 32 || template.TemplateId == 36 || template.TemplateId == 40 || template.TemplateId == 38 || template.TemplateId == 43 {
  303. dewater_amount = dewater_amount * 1000
  304. }
  305. if dewater_amount < 0 {
  306. dewater_amount = 0
  307. }
  308. if dialysistype == 1 {
  309. // 保存透前相关数据
  310. // 获取透析处方
  311. var lastDialysisPrescribe *models.DialysisPrescription
  312. var dialysisSolution *models.DialysisSolution
  313. var dialysisPrescribe *models.DialysisPrescription
  314. var system_dialysisPrescribe *models.SystemPrescription
  315. var mode_id int64
  316. //weightfirst, _ := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, id)
  317. //if weightfirst.DryWeight > weighing_before {
  318. // return
  319. //}
  320. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  321. if schedual != nil {
  322. // 获取透析模版
  323. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeId(adminUserInfo.Org.Id, id, schedual.ModeId)
  324. system_dialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeId(adminUserInfo.Org.Id, schedual.ModeId)
  325. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeId(adminUserInfo.Org.Id, id, schedual.ModeId)
  326. mode_id = schedual.ModeId
  327. } else {
  328. // 获取透析模版
  329. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.Org.Id, id)
  330. if dialysisPrescribe == nil && dialysisSolution != nil {
  331. mode_id = dialysisSolution.ModeId
  332. }
  333. if dialysisPrescribe == nil && dialysisSolution == nil {
  334. mode_id = 0
  335. }
  336. }
  337. // 插入透析处方
  338. if dialysisPrescribe == nil && dialysisSolution != nil {
  339. var newprescribe models.DialysisPrescription
  340. newprescribe.UserOrgId = dialysisSolution.UserOrgId
  341. newprescribe.PatientId = dialysisSolution.PatientId
  342. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  343. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  344. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  345. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  346. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  347. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  348. newprescribe.ModeId = dialysisSolution.ModeId
  349. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  350. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  351. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  352. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  353. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  354. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  355. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  356. newprescribe.Glucose = dialysisSolution.Glucose
  357. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  358. newprescribe.Kalium = dialysisSolution.Kalium
  359. newprescribe.Sodium = dialysisSolution.Sodium
  360. newprescribe.Calcium = dialysisSolution.Calcium
  361. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  362. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  363. newprescribe.Conductivity = dialysisSolution.Conductivity
  364. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  365. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  366. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  367. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  368. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  369. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  370. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  371. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  372. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  373. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  374. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  375. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  376. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  377. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  378. newprescribe.DialysisIrrigation = dialysisSolution.DialysisIrrigation
  379. newprescribe.DialysisDialyszers = dialysisSolution.DialysisDialyszers
  380. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  381. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  382. newprescribe.CreatedTime = time.Now().Unix()
  383. newprescribe.UpdatedTime = time.Now().Unix()
  384. newprescribe.RecordDate = theAssessmentDateTime
  385. newprescribe.DewaterAmount = dewater_amount
  386. newprescribe.TargetUltrafiltration = dewater_amount
  387. newprescribe.Status = 1
  388. err := service.AddSigleRecord(&newprescribe)
  389. if err != nil {
  390. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  391. }
  392. }
  393. if dialysisPrescribe == nil && dialysisSolution == nil {
  394. if lastDialysisPrescribe != nil {
  395. var newprescribe models.DialysisPrescription
  396. newprescribe.UserOrgId = lastDialysisPrescribe.UserOrgId
  397. newprescribe.PatientId = lastDialysisPrescribe.PatientId
  398. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  399. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  400. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  401. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  402. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  403. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  404. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  405. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  406. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  407. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  408. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  409. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  410. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  411. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  412. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  413. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  414. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  415. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  416. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  417. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  418. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  419. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  420. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  421. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  422. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  423. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  424. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  425. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  426. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  427. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  428. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  429. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  430. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  431. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  432. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  433. newprescribe.DialysisDialyszers = lastDialysisPrescribe.DialysisDialyszers
  434. newprescribe.DialysisIrrigation = lastDialysisPrescribe.DialysisIrrigation
  435. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  436. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  437. newprescribe.CreatedTime = time.Now().Unix()
  438. newprescribe.UpdatedTime = time.Now().Unix()
  439. newprescribe.RecordDate = theAssessmentDateTime
  440. newprescribe.DewaterAmount = dewater_amount
  441. newprescribe.TargetUltrafiltration = dewater_amount
  442. newprescribe.Status = 1
  443. err := service.AddSigleRecord(&newprescribe)
  444. if err != nil {
  445. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  446. }
  447. } else if system_dialysisPrescribe != nil {
  448. var newprescribe models.DialysisPrescription
  449. newprescribe.UserOrgId = system_dialysisPrescribe.UserOrgId
  450. newprescribe.PatientId = id
  451. newprescribe.Anticoagulant = system_dialysisPrescribe.Anticoagulant
  452. newprescribe.AnticoagulantShouji = system_dialysisPrescribe.AnticoagulantShouji
  453. newprescribe.AnticoagulantWeichi = system_dialysisPrescribe.AnticoagulantWeichi
  454. newprescribe.AnticoagulantZongliang = system_dialysisPrescribe.AnticoagulantZongliang
  455. newprescribe.AnticoagulantGaimingcheng = system_dialysisPrescribe.AnticoagulantGaimingcheng
  456. newprescribe.AnticoagulantGaijiliang = system_dialysisPrescribe.AnticoagulantGaijiliang
  457. newprescribe.ModeId = system_dialysisPrescribe.ModeId
  458. newprescribe.DialysisDuration = system_dialysisPrescribe.DialysisDuration
  459. newprescribe.ReplacementWay = system_dialysisPrescribe.ReplacementWay
  460. newprescribe.HemodialysisMachine = system_dialysisPrescribe.HemodialysisMachine
  461. newprescribe.BloodFilter = system_dialysisPrescribe.BloodFilter
  462. newprescribe.PerfusionApparatus = system_dialysisPrescribe.PerfusionApparatus
  463. newprescribe.BloodFlowVolume = system_dialysisPrescribe.BloodFlowVolume
  464. newprescribe.DisplaceLiqui = system_dialysisPrescribe.DisplaceLiqui
  465. newprescribe.Glucose = system_dialysisPrescribe.Glucose
  466. newprescribe.DialysateFlow = system_dialysisPrescribe.DialysateFlow
  467. newprescribe.Kalium = system_dialysisPrescribe.Kalium
  468. newprescribe.Sodium = system_dialysisPrescribe.Sodium
  469. newprescribe.Calcium = system_dialysisPrescribe.Calcium
  470. newprescribe.Bicarbonate = system_dialysisPrescribe.Bicarbonate
  471. newprescribe.DialysateTemperature = system_dialysisPrescribe.DialysateTemperature
  472. newprescribe.Conductivity = system_dialysisPrescribe.Conductivity
  473. newprescribe.BodyFluid = system_dialysisPrescribe.BodyFluid
  474. newprescribe.SpecialMedicine = system_dialysisPrescribe.SpecialMedicine
  475. newprescribe.SpecialMedicineOther = system_dialysisPrescribe.SpecialMedicineOther
  476. newprescribe.DisplaceLiquiPart = system_dialysisPrescribe.DisplaceLiquiPart
  477. newprescribe.DisplaceLiquiValue = system_dialysisPrescribe.DisplaceLiquiValue
  478. newprescribe.BloodAccess = system_dialysisPrescribe.BloodAccess
  479. newprescribe.Ultrafiltration = system_dialysisPrescribe.Ultrafiltration
  480. newprescribe.DialysisDurationHour = system_dialysisPrescribe.DialysisDurationHour
  481. newprescribe.DialysisDurationMinute = system_dialysisPrescribe.DialysisDurationMinute
  482. newprescribe.DialysateFormulation = system_dialysisPrescribe.DialysateFormulation
  483. newprescribe.Dialyzer = system_dialysisPrescribe.Dialyzer
  484. newprescribe.ReplacementTotal = system_dialysisPrescribe.ReplacementTotal
  485. newprescribe.DialyzerPerfusionApparatus = system_dialysisPrescribe.DialyzerPerfusionApparatus
  486. newprescribe.DialysisIrrigation = system_dialysisPrescribe.DialysisIrrigation
  487. newprescribe.DialysisDialyszers = system_dialysisPrescribe.DialysisDialyszers
  488. newprescribe.BodyFluidOther = system_dialysisPrescribe.BodyFluidOther
  489. newprescribe.TargetKtv = system_dialysisPrescribe.TargetKtv
  490. newprescribe.CreatedTime = time.Now().Unix()
  491. newprescribe.UpdatedTime = time.Now().Unix()
  492. newprescribe.RecordDate = theAssessmentDateTime
  493. newprescribe.DewaterAmount = dewater_amount
  494. newprescribe.TargetUltrafiltration = dewater_amount
  495. newprescribe.Status = 1
  496. fmt.Println(newprescribe.DewaterAmount)
  497. fmt.Println(newprescribe.TargetUltrafiltration)
  498. err := service.AddSigleRecord(&newprescribe)
  499. if err != nil {
  500. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  501. }
  502. } else {
  503. var newprescribe models.DialysisPrescription
  504. newprescribe.UserOrgId = adminUserInfo.Org.Id
  505. newprescribe.PatientId = id
  506. newprescribe.ModeId = mode_id
  507. newprescribe.CreatedTime = time.Now().Unix()
  508. newprescribe.UpdatedTime = time.Now().Unix()
  509. newprescribe.RecordDate = theAssessmentDateTime
  510. newprescribe.DewaterAmount = dewater_amount
  511. newprescribe.TargetUltrafiltration = dewater_amount
  512. newprescribe.Status = 1
  513. err := service.AddSigleRecord(&newprescribe)
  514. if err != nil {
  515. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  516. }
  517. }
  518. }
  519. if dialysisPrescribe != nil && dialysisPrescribe.TargetUltrafiltration == 0 {
  520. dialysisPrescribe.UpdatedTime = time.Now().Unix()
  521. dialysisPrescribe.RecordDate = theAssessmentDateTime
  522. dialysisPrescribe.DewaterAmount = dewater_amount
  523. dialysisPrescribe.TargetUltrafiltration = dewater_amount
  524. dialysisPrescribe.Status = 1
  525. updateErr := service.UpDateDialysisPrescription(dialysisPrescribe)
  526. if updateErr != nil {
  527. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  528. }
  529. }
  530. theEvaluation, getPEErr := service.MobileGetPredialysisEvaluation(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  531. if getPEErr != nil {
  532. c.ErrorLog("获取透前评估失败:%v", getPEErr)
  533. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  534. return
  535. }
  536. var evaluation models.PredialysisEvaluation
  537. if theEvaluation != nil {
  538. evaluation = *theEvaluation
  539. }
  540. // 如果今天没有透前评估,则插入新的数据
  541. if theEvaluation == nil {
  542. evaluation.CreatedTime = time.Now().Unix()
  543. evaluation.Status = 1
  544. evaluation.AssessmentDate = theAssessmentDateTime
  545. evaluation.PatientId = id
  546. evaluation.UserOrgId = adminUserInfo.Org.Id
  547. // 获取上一次透前评估信息,部分数据是需要从上一次透前评估继承
  548. lastPredialysisEvaluation, _ := service.MobileGetLastTimePredialysisEvaluation(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  549. // 获取上一次透后评估,插入本次透前评估的上次透后体重(weight_after_last_transparency)字段
  550. assessmentAfterDislysis, getAADErr := service.MobileGetLastTimeAssessmentAfterDislysis(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  551. if getAADErr != nil {
  552. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  553. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  554. return
  555. }
  556. // 获取干体重,先从干体重配置里去读,如果没有,则读取上一次透前评估的干体重
  557. weight, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, id)
  558. if err == gorm.ErrRecordNotFound {
  559. if lastPredialysisEvaluation != nil {
  560. evaluation.DryWeight = lastPredialysisEvaluation.DryWeight
  561. } else {
  562. evaluation.DryWeight = 0
  563. }
  564. } else {
  565. evaluation.DryWeight = weight.DryWeight
  566. }
  567. if assessmentAfterDislysis != nil {
  568. evaluation.WeightAfterLastTransparency = assessmentAfterDislysis.WeightAfter
  569. }
  570. if lastPredialysisEvaluation != nil {
  571. evaluation.BloodAccessPartId = lastPredialysisEvaluation.BloodAccessPartId
  572. evaluation.BloodAccessPartOperaId = lastPredialysisEvaluation.BloodAccessPartOperaId
  573. evaluation.AdditionalWeight = lastPredialysisEvaluation.AdditionalWeight
  574. evaluation.Temperature = lastPredialysisEvaluation.Temperature
  575. evaluation.BreathingRate = lastPredialysisEvaluation.BreathingRate
  576. evaluation.Catheter = lastPredialysisEvaluation.Catheter
  577. evaluation.InternalFistula = lastPredialysisEvaluation.InternalFistula
  578. evaluation.PulseFrequency = lastPredialysisEvaluation.PulseFrequency
  579. evaluation.Complication = lastPredialysisEvaluation.Complication
  580. evaluation.LastPostDialysis = lastPredialysisEvaluation.LastPostDialysis
  581. evaluation.DialysisInterphase = lastPredialysisEvaluation.DialysisInterphase
  582. evaluation.SymptomBeforeDialysis = lastPredialysisEvaluation.SymptomBeforeDialysis
  583. evaluation.PunctureNeedle = lastPredialysisEvaluation.PunctureNeedle
  584. evaluation.PunctureWay = lastPredialysisEvaluation.PunctureWay
  585. evaluation.InternalFistulaSkin = lastPredialysisEvaluation.InternalFistulaSkin //血透通路皮肤情况
  586. evaluation.CatheterBend = lastPredialysisEvaluation.CatheterBend //导管打折
  587. evaluation.IsHemorrhage = lastPredialysisEvaluation.IsHemorrhage //出血
  588. evaluation.IsInfect = lastPredialysisEvaluation.IsInfect //感染
  589. evaluation.Exposed = lastPredialysisEvaluation.Exposed // 外漏
  590. evaluation.DialysisCount = lastPredialysisEvaluation.DialysisCount //呼吸频次
  591. evaluation.Phinholing = lastPredialysisEvaluation.Phinholing //针眼
  592. }
  593. } else {
  594. evaluation.UpdatedTime = time.Now().Unix()
  595. }
  596. evaluation.WeightBefore = weighing_before
  597. evaluation.AssessmentTime = time.Now().Unix()
  598. err := service.UpadatePredialysisEvaluation(&evaluation)
  599. if err != nil {
  600. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  601. return
  602. }
  603. c.ServeSuccessJSON(map[string]interface{}{
  604. "msg": "ok",
  605. "evaluation": evaluation,
  606. })
  607. return
  608. } else {
  609. // 保存透后相关数据
  610. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysis(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  611. if getAADErr != nil {
  612. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  613. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  614. return
  615. }
  616. var afterevaluation models.AssessmentAfterDislysis
  617. if assessmentAfterDislysis != nil {
  618. afterevaluation = *assessmentAfterDislysis
  619. }
  620. if assessmentAfterDislysis == nil {
  621. afterevaluation.CreatedTime = time.Now().Unix()
  622. afterevaluation.Status = 1
  623. afterevaluation.AssessmentDate = theAssessmentDateTime
  624. afterevaluation.PatientId = id
  625. afterevaluation.UserOrgId = adminUserInfo.Org.Id
  626. } else {
  627. afterevaluation.UpdatedTime = time.Now().Unix()
  628. }
  629. afterevaluation.WeightAfter = weight_after
  630. afterevaluation.WeightLoss = weight_loss
  631. if adminUserInfo.Org.Id == 10138 {
  632. afterevaluation.LeaveOfficeMethod = assessmentAfterDislysis.LeaveOfficeMethod //离科方式
  633. afterevaluation.Lapse = assessmentAfterDislysis.Lapse //转归
  634. afterevaluation.Consciousness = assessmentAfterDislysis.Consciousness //意识
  635. afterevaluation.Fallrisk = assessmentAfterDislysis.Fallrisk
  636. }
  637. // if (adminUserInfo.Org.Id == 9538){
  638. // afterevaluation.ActualUltrafiltration = weight_loss * 1000 //中能建的计量单位是毫升(ml)
  639. // } else {
  640. // afterevaluation.ActualUltrafiltration = weight_loss // 计量单位是L
  641. // }
  642. err := service.UpdateAssessmentAfterDislysisRecord(&afterevaluation)
  643. if err == nil {
  644. c.ServeSuccessJSON(map[string]interface{}{
  645. "assessmentAfterDislysis": afterevaluation,
  646. })
  647. }
  648. }
  649. }
  650. func (c *CheckWeightApiController) SetSyncTime() {
  651. sn := c.GetString("sn")
  652. if len(sn) > 0 {
  653. redis := service.RedisClient()
  654. defer redis.Close()
  655. redis.Set(sn, 0, 0)
  656. }
  657. serviceTime := time.Now().Unix()
  658. c.ServeSuccessJSON(map[string]interface{}{
  659. "status": 1,
  660. "servicetime": serviceTime,
  661. })
  662. }
  663. func (c *CheckWeightApiController) GetPatientList() {
  664. ftype, _ := c.GetInt64("type", 0)
  665. sn := c.GetString("sn")
  666. syncTime := int64(0)
  667. redis := service.RedisClient()
  668. defer redis.Close()
  669. if len(sn) > 0 {
  670. syncTimeStr, _ := redis.Get(sn).Result()
  671. syncTime, _ = strconv.ParseInt(syncTimeStr, 10, 64)
  672. }
  673. if ftype == 1 {
  674. timeNow := time.Now().Unix()
  675. redis.Set(sn, timeNow, 0)
  676. }
  677. adminUserInfo := c.GetMobileAdminUserInfo()
  678. patientList, total, error := service.GetPatientListByUpdateTime(adminUserInfo.Org.Id, int64(syncTime))
  679. need_update := 0
  680. if syncTime == 0 {
  681. need_update = 1
  682. }
  683. if error != nil {
  684. c.ErrorLog("获取病人列表失败:%v", error)
  685. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  686. return
  687. }
  688. serviceTime := time.Now().Unix()
  689. c.ServeSuccessJSON(map[string]interface{}{
  690. "need_update": need_update,
  691. "patientlist": patientList,
  692. "total": total,
  693. "servicetime": serviceTime,
  694. })
  695. }
  696. func (c *CheckWeightApiController) GetPatientListForSchedules() {
  697. thisTime := time.Now()
  698. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  699. timeLayout := "2006-01-02 15:04:05"
  700. loc, _ := time.LoadLocation("Local")
  701. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  702. syncTime := theStartTime.Unix()
  703. adminUserInfo := c.GetMobileAdminUserInfo()
  704. patientList, total, error := service.GetPatientListBySchedules(adminUserInfo.Org.Id, syncTime)
  705. patientSchedule := make([]map[string]interface{}, 0)
  706. for _, item := range patientList {
  707. patientTemp := make(map[string]interface{})
  708. patientTemp["patient_id"] = item.PatientId
  709. patientTemp["patient_name"] = item.Patient.Name
  710. patientTemp["schedule_type"] = item.ScheduleType
  711. patientSchedule = append(patientSchedule, patientTemp)
  712. }
  713. if error != nil {
  714. c.ErrorLog("获取病人列表失败:%v", error)
  715. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  716. return
  717. }
  718. serviceTime := time.Now().Unix()
  719. c.ServeSuccessJSON(map[string]interface{}{
  720. "patientlist": patientSchedule,
  721. "total": total,
  722. "servicetime": serviceTime,
  723. })
  724. }
  725. func (c *CheckWeightApiController) GetPatientListForSchedulesFind() {
  726. patient_name := c.GetString("patient_name") //脉率
  727. thisTime := time.Now()
  728. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  729. timeLayout := "2006-01-02 15:04:05"
  730. loc, _ := time.LoadLocation("Local")
  731. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  732. syncTime := theStartTime.Unix()
  733. adminUserInfo := c.GetMobileAdminUserInfo()
  734. if len(patient_name) == 0 {
  735. patientList, total, error := service.GetPatientListBySchedules(adminUserInfo.Org.Id, syncTime)
  736. patientSchedule := make([]map[string]interface{}, 0)
  737. for _, item := range patientList {
  738. patientTemp := make(map[string]interface{})
  739. patientTemp["patient_id"] = item.PatientId
  740. patientTemp["patient_name"] = item.Patient.Name
  741. patientTemp["schedule_type"] = item.ScheduleType
  742. patientSchedule = append(patientSchedule, patientTemp)
  743. }
  744. if error != nil {
  745. c.ErrorLog("获取病人列表失败:%v", error)
  746. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  747. return
  748. }
  749. serviceTime := time.Now().Unix()
  750. c.ServeSuccessJSON(map[string]interface{}{
  751. "patientlist": patientSchedule,
  752. "total": total,
  753. "servicetime": serviceTime,
  754. })
  755. } else {
  756. patientList, total, error := service.GetPatientListBySchedulesFind(adminUserInfo.Org.Id, syncTime, patient_name)
  757. patientSchedule := make([]map[string]interface{}, 0)
  758. for _, item := range patientList {
  759. if item.Patient.ID > 0 {
  760. patientTemp := make(map[string]interface{})
  761. patientTemp["patient_id"] = item.PatientId
  762. patientTemp["patient_name"] = item.Patient.Name
  763. patientTemp["schedule_type"] = item.ScheduleType
  764. patientSchedule = append(patientSchedule, patientTemp)
  765. }
  766. }
  767. if error != nil {
  768. c.ErrorLog("获取病人列表失败:%v", error)
  769. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  770. return
  771. }
  772. serviceTime := time.Now().Unix()
  773. c.ServeSuccessJSON(map[string]interface{}{
  774. "patientlist": patientSchedule,
  775. "total": total,
  776. "servicetime": serviceTime,
  777. })
  778. }
  779. }
  780. func (c *CheckWeightApiController) GetPatientListById() {
  781. patientId, _ := c.GetInt64("patient_id", 0)
  782. if patientId <= 0 {
  783. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  784. return
  785. }
  786. adminUserInfo := c.GetMobileAdminUserInfo()
  787. patient, error := service.GetPatientListById(adminUserInfo.Org.Id, patientId)
  788. if error != nil {
  789. c.ErrorLog("获取病人详情失败:%v", error)
  790. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  791. return
  792. }
  793. c.ServeSuccessJSON(map[string]interface{}{
  794. "patientinfo": patient,
  795. })
  796. }
  797. func (c *CheckWeightApiController) GetPatientInfoDialysis() {
  798. id, _ := c.GetInt64("patient", 0)
  799. if id <= 0 {
  800. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  801. return
  802. }
  803. adminUserInfo := c.GetMobileAdminUserInfo()
  804. patient, _ := service.FindPatientByIdWithDiseases(adminUserInfo.Org.Id, id)
  805. if patient.ID <= 0 {
  806. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  807. return
  808. }
  809. var dialysisinfo map[string]interface{}
  810. dialysisinfo = make(map[string]interface{})
  811. dialysisinfo["id"] = patient.ID
  812. dialysisinfo["name"] = patient.Name
  813. dialysisinfo["dialysis_no"] = patient.DialysisNo
  814. thisTime := time.Now()
  815. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  816. scheduleDateEnd := thisTime.Format("2006-01-02") + " 23:59:59"
  817. timeLayout := "2006-01-02 15:04:05"
  818. loc, _ := time.LoadLocation("Local")
  819. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  820. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  821. startTime := theStartTime.Unix()
  822. endTime := theEndTime.Unix()
  823. // 判断当前用户是透析前还是透析后
  824. var dialysistype int
  825. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, startTime)
  826. if dialysisOrder == nil {
  827. dialysistype = 1
  828. } else {
  829. dialysistype = 2
  830. }
  831. // 获取当前或者下次排班信息
  832. var sc map[string]interface{}
  833. sc = make(map[string]interface{})
  834. if dialysistype == 1 {
  835. daySchedule, _ := service.GetPatientScheduleFormDay(adminUserInfo.Org.Id, startTime, endTime, id)
  836. if len(daySchedule) <= 0 {
  837. sc["code"] = 1
  838. sc["msg"] = "抱歉,您今天没有排版!"
  839. sc["mode"] = 0
  840. sc["data"] = daySchedule
  841. } else {
  842. if daySchedule[0].Schedule.ID > 0 {
  843. sc["code"] = 0
  844. sc["msg"] = ""
  845. sc["mode"] = daySchedule[0].Schedule.ModeId
  846. sc["data"] = daySchedule
  847. } else {
  848. sc["code"] = 1
  849. sc["msg"] = "抱歉,您今天没有排版!"
  850. sc["mode"] = 0
  851. sc["data"] = daySchedule
  852. }
  853. }
  854. // 排队叫号的签到
  855. go func() {
  856. ssoDomain := beego.AppConfig.String("call_domain")
  857. api := ssoDomain + "/index/patientsign/" + strconv.FormatInt(adminUserInfo.Org.Id, 10) + "/" + strconv.FormatInt(id, 10)
  858. values := make(url.Values)
  859. http.PostForm(api, values)
  860. }()
  861. } else {
  862. nextSchedule, _ := service.GetNextSchedule(adminUserInfo.Org.Id, endTime, id)
  863. if len(nextSchedule) <= 0 {
  864. sc["code"] = 1
  865. sc["msg"] = "抱歉,您后续没有排版!"
  866. sc["mode"] = 0
  867. sc["data"] = nextSchedule
  868. } else {
  869. if nextSchedule[0].Schedule.ID > 0 {
  870. sc["code"] = 0
  871. sc["msg"] = ""
  872. sc["mode"] = nextSchedule[0].Schedule.ModeId
  873. sc["data"] = nextSchedule
  874. } else {
  875. sc["code"] = 1
  876. sc["msg"] = "抱歉,您后续没有排版!"
  877. sc["mode"] = 0
  878. sc["data"] = nextSchedule
  879. }
  880. }
  881. }
  882. switch sc["mode"] {
  883. case 1:
  884. sc["mode"] = "HD"
  885. case 2:
  886. sc["mode"] = "HDF"
  887. case 3:
  888. sc["mode"] = "HD+HP"
  889. case 4:
  890. sc["mode"] = "HP"
  891. case 5:
  892. sc["mode"] = "HF"
  893. case 6:
  894. sc["mode"] = "SCUF"
  895. case 7:
  896. sc["mode"] = "IUF"
  897. case 8:
  898. sc["mode"] = "HFHD"
  899. case 9:
  900. sc["mode"] = "HFHD+HP"
  901. case 10:
  902. sc["mode"] = "PHF"
  903. case 11:
  904. sc["mode"] = "HFR"
  905. case 12:
  906. sc["mode"] = "HDF+HP"
  907. case 13:
  908. sc["mode"] = "CRRT"
  909. case 14:
  910. sc["mode"] = "腹水回输"
  911. case 15:
  912. sc["mode"] = "HD前置换"
  913. case 16:
  914. sc["mode"] = "HD后置换"
  915. case 17:
  916. sc["mode"] = "HDF前置换"
  917. case 18:
  918. sc["mode"] = "HDF后置换"
  919. default:
  920. sc["mode"] = "HD"
  921. }
  922. // 获取患者透前干体重或者获取患者透前体重
  923. var dry_weight map[string]interface{}
  924. dry_weight = make(map[string]interface{})
  925. var after_dry_weight map[string]interface{}
  926. after_dry_weight = make(map[string]interface{})
  927. if dialysistype == 1 {
  928. lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminUserInfo.Org.Id, id, endTime)
  929. weight, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, id)
  930. if err == gorm.ErrRecordNotFound {
  931. if getLPEErr != nil {
  932. dry_weight["code"] = 1
  933. dry_weight["dry_weight"] = nil
  934. } else {
  935. if lastPredialysisEvaluation == nil {
  936. dry_weight["code"] = 1
  937. dry_weight["dry_weight"] = nil
  938. } else {
  939. // 传输的干体重实际为干体重加上衣服重
  940. dry_weight["code"] = 0
  941. dry_weight["dry_weight"] = lastPredialysisEvaluation.DryWeight + lastPredialysisEvaluation.AdditionalWeight
  942. }
  943. }
  944. } else {
  945. if err != nil {
  946. dry_weight["code"] = 1
  947. dry_weight["dry_weight"] = nil
  948. } else {
  949. dry_weight["code"] = 0
  950. if getLPEErr != nil {
  951. dry_weight["code"] = 0
  952. dry_weight["dry_weight"] = weight.DryWeight
  953. } else {
  954. if lastPredialysisEvaluation == nil {
  955. dry_weight["code"] = 1
  956. dry_weight["dry_weight"] = weight.DryWeight
  957. } else {
  958. // 传输的干体重实际为干体重加上衣服重
  959. dry_weight["code"] = 0
  960. dry_weight["dry_weight"] = weight.DryWeight + lastPredialysisEvaluation.AdditionalWeight
  961. }
  962. }
  963. }
  964. }
  965. } else {
  966. predialysisEvaluation, getPEErr := service.MobileGetPredialysisEvaluation(adminUserInfo.Org.Id, id, startTime)
  967. if getPEErr != nil {
  968. dry_weight["code"] = 1
  969. dry_weight["dry_weight"] = nil
  970. } else {
  971. if predialysisEvaluation == nil {
  972. dry_weight["code"] = 1
  973. dry_weight["dry_weight"] = nil
  974. } else {
  975. dry_weight["code"] = 0
  976. dry_weight["dry_weight"] = predialysisEvaluation.WeightBefore
  977. }
  978. }
  979. lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminUserInfo.Org.Id, id, endTime)
  980. weight, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, id)
  981. if err == gorm.ErrRecordNotFound {
  982. if getLPEErr != nil {
  983. after_dry_weight["code"] = 1
  984. after_dry_weight["dry_weight"] = nil
  985. } else {
  986. if lastPredialysisEvaluation == nil {
  987. after_dry_weight["code"] = 1
  988. after_dry_weight["dry_weight"] = nil
  989. } else {
  990. // 传输的干体重实际为干体重加上衣服重
  991. after_dry_weight["code"] = 0
  992. after_dry_weight["dry_weight"] = lastPredialysisEvaluation.DryWeight + lastPredialysisEvaluation.AdditionalWeight
  993. }
  994. }
  995. } else {
  996. if err != nil {
  997. after_dry_weight["code"] = 1
  998. after_dry_weight["dry_weight"] = nil
  999. } else {
  1000. after_dry_weight["code"] = 0
  1001. if getLPEErr != nil {
  1002. after_dry_weight["code"] = 0
  1003. after_dry_weight["dry_weight"] = weight.DryWeight
  1004. } else {
  1005. if lastPredialysisEvaluation == nil {
  1006. after_dry_weight["code"] = 1
  1007. after_dry_weight["dry_weight"] = weight.DryWeight
  1008. } else {
  1009. // 传输的干体重实际为干体重加上衣服重
  1010. after_dry_weight["code"] = 0
  1011. after_dry_weight["dry_weight"] = weight.DryWeight + lastPredialysisEvaluation.AdditionalWeight
  1012. }
  1013. }
  1014. }
  1015. }
  1016. }
  1017. c.ServeSuccessJSON(map[string]interface{}{
  1018. "dialysistype": dialysistype,
  1019. "patient": dialysisinfo,
  1020. "schedule": sc,
  1021. "dryweight": dry_weight,
  1022. "after_dry_weight": after_dry_weight,
  1023. })
  1024. return
  1025. }
  1026. func (c *CheckWeightApiController) GetPatientInfoBeforeDialysis() {
  1027. id, _ := c.GetInt64("patient", 0)
  1028. if id <= 0 {
  1029. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1030. return
  1031. }
  1032. adminUserInfo := c.GetMobileAdminUserInfo()
  1033. patient, _ := service.FindPatientByIdWithDiseases(adminUserInfo.Org.Id, id)
  1034. if patient.ID == 0 {
  1035. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1036. return
  1037. }
  1038. var dialysisinfo map[string]interface{}
  1039. dialysisinfo = make(map[string]interface{})
  1040. dialysisinfo["id"] = patient.ID
  1041. dialysisinfo["name"] = patient.Name
  1042. dialysisinfo["dialysis_no"] = patient.DialysisNo
  1043. thisTime := time.Now()
  1044. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  1045. scheduleDateEnd := thisTime.Format("2006-01-02") + " 23:59:59"
  1046. fmt.Println(scheduleDateStart, scheduleDateEnd)
  1047. timeLayout := "2006-01-02 15:04:05"
  1048. loc, _ := time.LoadLocation("Local")
  1049. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  1050. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  1051. fmt.Println(theStartTime, theEndTime)
  1052. startTime := theStartTime.Unix()
  1053. endTime := theEndTime.Unix()
  1054. var sc map[string]interface{}
  1055. sc = make(map[string]interface{})
  1056. //一天只有排班一次
  1057. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, startTime, endTime, id)
  1058. if daySchedule.ID > 0 {
  1059. switch daySchedule.ModeId {
  1060. case 1:
  1061. sc["mode"] = "HD"
  1062. case 2:
  1063. sc["mode"] = "HDF"
  1064. case 3:
  1065. sc["mode"] = "HD+HP"
  1066. case 4:
  1067. sc["mode"] = "HP"
  1068. case 5:
  1069. sc["mode"] = "HF"
  1070. case 6:
  1071. sc["mode"] = "SCUF"
  1072. case 7:
  1073. sc["mode"] = "IUF"
  1074. case 8:
  1075. sc["mode"] = "HFHD"
  1076. case 9:
  1077. sc["mode"] = "HFHD+HP"
  1078. case 10:
  1079. sc["mode"] = "PHF"
  1080. case 11:
  1081. sc["mode"] = "HFR"
  1082. case 12:
  1083. sc["mode"] = "HDF+HP"
  1084. case 13:
  1085. sc["mode"] = "CRRT"
  1086. case 14:
  1087. sc["mode"] = "腹水回输"
  1088. case 15:
  1089. sc["mode"] = "HD前置换"
  1090. case 16:
  1091. sc["mode"] = "HD后置换"
  1092. case 17:
  1093. sc["mode"] = "HDF前置换"
  1094. case 18:
  1095. sc["mode"] = "HDF后置换"
  1096. default:
  1097. sc["mode"] = "HD"
  1098. }
  1099. sc["code"] = 0
  1100. sc["msg"] = ""
  1101. sc["data"] = daySchedule
  1102. } else {
  1103. sc["code"] = 1
  1104. sc["msg"] = "抱歉,您今天没有排版!"
  1105. sc["mode"] = ""
  1106. sc["data"] = daySchedule
  1107. }
  1108. fmt.Println(sc)
  1109. type dryWeight struct {
  1110. code int
  1111. dry_weight float64
  1112. }
  1113. var dry_weight map[string]interface{}
  1114. dry_weight = make(map[string]interface{})
  1115. lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminUserInfo.Org.Id, id, startTime)
  1116. if getLPEErr != nil {
  1117. dry_weight["code"] = 1
  1118. dry_weight["dry_weight"] = nil
  1119. } else {
  1120. if lastPredialysisEvaluation == nil {
  1121. dry_weight["code"] = 1
  1122. dry_weight["dry_weight"] = nil
  1123. } else {
  1124. dry_weight["code"] = 0
  1125. dry_weight["dry_weight"] = lastPredialysisEvaluation.DryWeight
  1126. }
  1127. }
  1128. c.ServeSuccessJSON(map[string]interface{}{
  1129. "patient": dialysisinfo,
  1130. "schedule": sc,
  1131. "dryweight": dry_weight,
  1132. })
  1133. return
  1134. }