check_weight_api_controller.go 46KB

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