check_weight_api_controller.go 45KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221
  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 {
  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. }
  574. } else {
  575. evaluation.UpdatedTime = time.Now().Unix()
  576. }
  577. evaluation.WeightBefore = weighing_before
  578. evaluation.AssessmentTime = time.Now().Unix()
  579. err := service.UpadatePredialysisEvaluation(&evaluation)
  580. if err != nil {
  581. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  582. return
  583. }
  584. c.ServeSuccessJSON(map[string]interface{}{
  585. "msg": "ok",
  586. "evaluation": evaluation,
  587. })
  588. return
  589. } else {
  590. // 保存透后相关数据
  591. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysis(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  592. if getAADErr != nil {
  593. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  594. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  595. return
  596. }
  597. var afterevaluation models.AssessmentAfterDislysis
  598. if assessmentAfterDislysis != nil {
  599. afterevaluation = *assessmentAfterDislysis
  600. }
  601. if assessmentAfterDislysis == nil {
  602. afterevaluation.CreatedTime = time.Now().Unix()
  603. afterevaluation.Status = 1
  604. afterevaluation.AssessmentDate = theAssessmentDateTime
  605. afterevaluation.PatientId = id
  606. afterevaluation.UserOrgId = adminUserInfo.Org.Id
  607. } else {
  608. afterevaluation.UpdatedTime = time.Now().Unix()
  609. }
  610. afterevaluation.WeightAfter = weight_after
  611. afterevaluation.WeightLoss = weight_loss
  612. // if (adminUserInfo.Org.Id == 9538){
  613. // afterevaluation.ActualUltrafiltration = weight_loss * 1000 //中能建的计量单位是毫升(ml)
  614. // } else {
  615. // afterevaluation.ActualUltrafiltration = weight_loss // 计量单位是L
  616. // }
  617. err := service.UpdateAssessmentAfterDislysisRecord(&afterevaluation)
  618. if err == nil {
  619. c.ServeSuccessJSON(map[string]interface{}{
  620. "assessmentAfterDislysis": afterevaluation,
  621. })
  622. }
  623. }
  624. }
  625. func (c *CheckWeightApiController) SetSyncTime(){
  626. sn := c.GetString("sn")
  627. if len(sn) > 0 {
  628. redis := service.RedisClient()
  629. defer redis.Close()
  630. redis.Set(sn, 0,0)
  631. }
  632. serviceTime := time.Now().Unix()
  633. c.ServeSuccessJSON(map[string]interface{}{
  634. "status": 1,
  635. "servicetime": serviceTime,
  636. })
  637. }
  638. func (c *CheckWeightApiController) GetPatientList() {
  639. ftype,_ := c.GetInt64("type",0)
  640. sn := c.GetString("sn")
  641. syncTime := int64(0)
  642. redis := service.RedisClient()
  643. defer redis.Close()
  644. if len(sn) > 0 {
  645. syncTimeStr, _ := redis.Get(sn).Result()
  646. syncTime,_ = strconv.ParseInt(syncTimeStr, 10, 64)
  647. }
  648. if ftype == 1 {
  649. timeNow := time.Now().Unix()
  650. redis.Set(sn, timeNow,0)
  651. }
  652. adminUserInfo := c.GetMobileAdminUserInfo()
  653. need_update := 0
  654. patientList, total, error := service.GetPatientListByUpdateTime(adminUserInfo.Org.Id, int64(syncTime))
  655. if len(patientList) > 0 {
  656. need_update = 1
  657. }
  658. if error != nil {
  659. c.ErrorLog("获取病人列表失败:%v", error)
  660. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  661. return
  662. }
  663. serviceTime := time.Now().Unix()
  664. c.ServeSuccessJSON(map[string]interface{}{
  665. "need_update" : need_update,
  666. "patientlist": patientList,
  667. "total": total,
  668. "servicetime": serviceTime,
  669. })
  670. }
  671. func (c *CheckWeightApiController) GetPatientListForSchedules() {
  672. thisTime := time.Now()
  673. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  674. timeLayout := "2006-01-02 15:04:05"
  675. loc, _ := time.LoadLocation("Local")
  676. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  677. syncTime := theStartTime.Unix()
  678. adminUserInfo := c.GetMobileAdminUserInfo()
  679. patientList, total, error := service.GetPatientListBySchedules(adminUserInfo.Org.Id, syncTime)
  680. patientSchedule := make([]map[string]interface{}, 0)
  681. for _, item := range patientList {
  682. patientTemp := make(map[string]interface{})
  683. patientTemp["patient_id"] = item.PatientId
  684. patientTemp["patient_name"] = item.Patient.Name
  685. patientTemp["schedule_type"] = item.ScheduleType
  686. patientSchedule = append(patientSchedule, patientTemp)
  687. }
  688. if error != nil {
  689. c.ErrorLog("获取病人列表失败:%v", error)
  690. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  691. return
  692. }
  693. serviceTime := time.Now().Unix()
  694. c.ServeSuccessJSON(map[string]interface{}{
  695. "patientlist": patientSchedule,
  696. "total": total,
  697. "servicetime": serviceTime,
  698. })
  699. }
  700. func (c *CheckWeightApiController) GetPatientListForSchedulesFind() {
  701. patient_name := c.GetString("patient_name") //脉率
  702. thisTime := time.Now()
  703. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  704. timeLayout := "2006-01-02 15:04:05"
  705. loc, _ := time.LoadLocation("Local")
  706. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  707. syncTime := theStartTime.Unix()
  708. adminUserInfo := c.GetMobileAdminUserInfo()
  709. if len(patient_name) == 0 {
  710. patientList, total, error := service.GetPatientListBySchedules(adminUserInfo.Org.Id, syncTime)
  711. patientSchedule := make([]map[string]interface{}, 0)
  712. for _, item := range patientList {
  713. patientTemp := make(map[string]interface{})
  714. patientTemp["patient_id"] = item.PatientId
  715. patientTemp["patient_name"] = item.Patient.Name
  716. patientTemp["schedule_type"] = item.ScheduleType
  717. patientSchedule = append(patientSchedule, patientTemp)
  718. }
  719. if error != nil {
  720. c.ErrorLog("获取病人列表失败:%v", error)
  721. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  722. return
  723. }
  724. serviceTime := time.Now().Unix()
  725. c.ServeSuccessJSON(map[string]interface{}{
  726. "patientlist": patientSchedule,
  727. "total": total,
  728. "servicetime": serviceTime,
  729. })
  730. } else {
  731. patientList, total, error := service.GetPatientListBySchedulesFind(adminUserInfo.Org.Id, syncTime,patient_name)
  732. patientSchedule := make([]map[string]interface{},0)
  733. for _, item := range patientList {
  734. if item.Patient.ID > 0 {
  735. patientTemp := make(map[string]interface{})
  736. patientTemp["patient_id"] = item.PatientId
  737. patientTemp["patient_name"] = item.Patient.Name
  738. patientTemp["schedule_type"] = item.ScheduleType
  739. patientSchedule = append(patientSchedule, patientTemp)
  740. }
  741. }
  742. if error != nil {
  743. c.ErrorLog("获取病人列表失败:%v", error)
  744. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  745. return
  746. }
  747. serviceTime := time.Now().Unix()
  748. c.ServeSuccessJSON(map[string]interface{}{
  749. "patientlist": patientSchedule,
  750. "total": total,
  751. "servicetime": serviceTime,
  752. })
  753. }
  754. }
  755. func (c *CheckWeightApiController) GetPatientListById() {
  756. patientId, _ := c.GetInt64("patient_id", 0)
  757. if patientId <= 0 {
  758. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  759. return
  760. }
  761. adminUserInfo := c.GetMobileAdminUserInfo()
  762. patient, error := service.GetPatientListById(adminUserInfo.Org.Id, patientId)
  763. if error != nil {
  764. c.ErrorLog("获取病人详情失败:%v", error)
  765. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  766. return
  767. }
  768. c.ServeSuccessJSON(map[string]interface{}{
  769. "patientinfo": patient,
  770. })
  771. }
  772. func (c *CheckWeightApiController) GetPatientInfoDialysis() {
  773. id, _ := c.GetInt64("patient", 0)
  774. if id <= 0 {
  775. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  776. return
  777. }
  778. adminUserInfo := c.GetMobileAdminUserInfo()
  779. patient, _ := service.FindPatientByIdWithDiseases(adminUserInfo.Org.Id, id)
  780. if patient.ID <= 0 {
  781. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  782. return
  783. }
  784. var dialysisinfo map[string]interface{}
  785. dialysisinfo = make(map[string]interface{})
  786. dialysisinfo["id"] = patient.ID
  787. dialysisinfo["name"] = patient.Name
  788. dialysisinfo["dialysis_no"] = patient.DialysisNo
  789. thisTime := time.Now()
  790. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  791. scheduleDateEnd := thisTime.Format("2006-01-02") + " 23:59:59"
  792. timeLayout := "2006-01-02 15:04:05"
  793. loc, _ := time.LoadLocation("Local")
  794. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  795. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  796. startTime := theStartTime.Unix()
  797. endTime := theEndTime.Unix()
  798. // 判断当前用户是透析前还是透析后
  799. var dialysistype int
  800. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, startTime)
  801. if dialysisOrder == nil {
  802. dialysistype = 1
  803. } else {
  804. dialysistype = 2
  805. }
  806. // 获取当前或者下次排班信息
  807. var sc map[string]interface{}
  808. sc = make(map[string]interface{})
  809. if dialysistype == 1 {
  810. daySchedule, _ := service.GetPatientScheduleFormDay(adminUserInfo.Org.Id, startTime, endTime, id)
  811. if len(daySchedule) <= 0 {
  812. sc["code"] = 1
  813. sc["msg"] = "抱歉,您今天没有排版!"
  814. sc["mode"] = 0
  815. sc["data"] = daySchedule
  816. } else {
  817. if daySchedule[0].Schedule.ID > 0 {
  818. sc["code"] = 0
  819. sc["msg"] = ""
  820. sc["mode"] = daySchedule[0].Schedule.ModeId
  821. sc["data"] = daySchedule
  822. } else {
  823. sc["code"] = 1
  824. sc["msg"] = "抱歉,您今天没有排版!"
  825. sc["mode"] = 0
  826. sc["data"] = daySchedule
  827. }
  828. }
  829. // 排队叫号的签到
  830. go func (){
  831. ssoDomain := beego.AppConfig.String("call_domain")
  832. api := ssoDomain + "/index/patientsign/" + strconv.FormatInt(adminUserInfo.Org.Id, 10) + "/" + strconv.FormatInt(id, 10)
  833. values := make(url.Values)
  834. http.PostForm(api, values)
  835. } ()
  836. } else {
  837. nextSchedule, _ := service.GetNextSchedule(adminUserInfo.Org.Id, endTime, id)
  838. if len(nextSchedule) <= 0 {
  839. sc["code"] = 1
  840. sc["msg"] = "抱歉,您后续没有排版!"
  841. sc["mode"] = 0
  842. sc["data"] = nextSchedule
  843. } else {
  844. if nextSchedule[0].Schedule.ID > 0 {
  845. sc["code"] = 0
  846. sc["msg"] = ""
  847. sc["mode"] = nextSchedule[0].Schedule.ModeId
  848. sc["data"] = nextSchedule
  849. } else {
  850. sc["code"] = 1
  851. sc["msg"] = "抱歉,您后续没有排版!"
  852. sc["mode"] = 0
  853. sc["data"] = nextSchedule
  854. }
  855. }
  856. }
  857. switch sc["mode"] {
  858. case 1:
  859. sc["mode"] = "HD"
  860. case 2:
  861. sc["mode"] = "HDF"
  862. case 3:
  863. sc["mode"] = "HD+HP"
  864. case 4:
  865. sc["mode"] = "HP"
  866. case 5:
  867. sc["mode"] = "HF"
  868. case 6:
  869. sc["mode"] = "SCUF"
  870. case 7:
  871. sc["mode"] = "IUF"
  872. case 8:
  873. sc["mode"] = "HFHD"
  874. case 9:
  875. sc["mode"] = "HFHD+HP"
  876. case 10:
  877. sc["mode"] = "PHF"
  878. case 11:
  879. sc["mode"] = "HFR"
  880. case 12:
  881. sc["mode"] = "HDF+HP"
  882. case 13:
  883. sc["mode"] = "CRRT"
  884. case 14:
  885. sc["mode"] = "腹水回输"
  886. case 15:
  887. sc["mode"] = "HD前置换"
  888. case 16:
  889. sc["mode"] = "HD后置换"
  890. case 17:
  891. sc["mode"] = "HDF前置换"
  892. case 18:
  893. sc["mode"] = "HDF后置换"
  894. default:
  895. sc["mode"] = "HD"
  896. }
  897. // 获取患者透前干体重或者获取患者透前体重
  898. var dry_weight map[string]interface{}
  899. dry_weight = make(map[string]interface{})
  900. var after_dry_weight map[string]interface{}
  901. after_dry_weight = make(map[string]interface{})
  902. if dialysistype == 1 {
  903. lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminUserInfo.Org.Id, id, endTime)
  904. weight, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, id)
  905. if err == gorm.ErrRecordNotFound {
  906. if getLPEErr != nil {
  907. dry_weight["code"] = 1
  908. dry_weight["dry_weight"] = nil
  909. } else {
  910. if lastPredialysisEvaluation == nil {
  911. dry_weight["code"] = 1
  912. dry_weight["dry_weight"] = nil
  913. } else {
  914. // 传输的干体重实际为干体重加上衣服重
  915. dry_weight["code"] = 0
  916. dry_weight["dry_weight"] = lastPredialysisEvaluation.DryWeight + lastPredialysisEvaluation.AdditionalWeight
  917. }
  918. }
  919. } else {
  920. if err != nil {
  921. dry_weight["code"] = 1
  922. dry_weight["dry_weight"] = nil
  923. } else {
  924. dry_weight["code"] = 0
  925. if getLPEErr != nil {
  926. dry_weight["code"] = 0
  927. dry_weight["dry_weight"] = weight.DryWeight
  928. } else {
  929. if lastPredialysisEvaluation == nil {
  930. dry_weight["code"] = 1
  931. dry_weight["dry_weight"] = weight.DryWeight
  932. } else {
  933. // 传输的干体重实际为干体重加上衣服重
  934. dry_weight["code"] = 0
  935. dry_weight["dry_weight"] = weight.DryWeight + lastPredialysisEvaluation.AdditionalWeight
  936. }
  937. }
  938. }
  939. }
  940. } else {
  941. predialysisEvaluation, getPEErr := service.MobileGetPredialysisEvaluation(adminUserInfo.Org.Id, id, startTime)
  942. if getPEErr != nil {
  943. dry_weight["code"] = 1
  944. dry_weight["dry_weight"] = nil
  945. } else {
  946. if predialysisEvaluation == nil {
  947. dry_weight["code"] = 1
  948. dry_weight["dry_weight"] = nil
  949. } else {
  950. dry_weight["code"] = 0
  951. dry_weight["dry_weight"] = predialysisEvaluation.WeightBefore
  952. }
  953. }
  954. lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminUserInfo.Org.Id, id, endTime)
  955. weight, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, id)
  956. if err == gorm.ErrRecordNotFound {
  957. if getLPEErr != nil {
  958. after_dry_weight["code"] = 1
  959. after_dry_weight["dry_weight"] = nil
  960. } else {
  961. if lastPredialysisEvaluation == nil {
  962. after_dry_weight["code"] = 1
  963. after_dry_weight["dry_weight"] = nil
  964. } else {
  965. // 传输的干体重实际为干体重加上衣服重
  966. after_dry_weight["code"] = 0
  967. after_dry_weight["dry_weight"] = lastPredialysisEvaluation.DryWeight + lastPredialysisEvaluation.AdditionalWeight
  968. }
  969. }
  970. } else {
  971. if err != nil {
  972. after_dry_weight["code"] = 1
  973. after_dry_weight["dry_weight"] = nil
  974. } else {
  975. after_dry_weight["code"] = 0
  976. if getLPEErr != nil {
  977. after_dry_weight["code"] = 0
  978. after_dry_weight["dry_weight"] = weight.DryWeight
  979. } else {
  980. if lastPredialysisEvaluation == nil {
  981. after_dry_weight["code"] = 1
  982. after_dry_weight["dry_weight"] = weight.DryWeight
  983. } else {
  984. // 传输的干体重实际为干体重加上衣服重
  985. after_dry_weight["code"] = 0
  986. after_dry_weight["dry_weight"] = weight.DryWeight + lastPredialysisEvaluation.AdditionalWeight
  987. }
  988. }
  989. }
  990. }
  991. }
  992. c.ServeSuccessJSON(map[string]interface{}{
  993. "dialysistype": dialysistype,
  994. "patient": dialysisinfo,
  995. "schedule": sc,
  996. "dryweight": dry_weight,
  997. "after_dry_weight": after_dry_weight,
  998. })
  999. return
  1000. }
  1001. func (c *CheckWeightApiController) GetPatientInfoBeforeDialysis() {
  1002. id, _ := c.GetInt64("patient", 0)
  1003. if id <= 0 {
  1004. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1005. return
  1006. }
  1007. adminUserInfo := c.GetMobileAdminUserInfo()
  1008. patient, _ := service.FindPatientByIdWithDiseases(adminUserInfo.Org.Id, id)
  1009. if patient.ID == 0 {
  1010. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1011. return
  1012. }
  1013. var dialysisinfo map[string]interface{}
  1014. dialysisinfo = make(map[string]interface{})
  1015. dialysisinfo["id"] = patient.ID
  1016. dialysisinfo["name"] = patient.Name
  1017. dialysisinfo["dialysis_no"] = patient.DialysisNo
  1018. thisTime := time.Now()
  1019. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  1020. scheduleDateEnd := thisTime.Format("2006-01-02") + " 23:59:59"
  1021. fmt.Println(scheduleDateStart, scheduleDateEnd)
  1022. timeLayout := "2006-01-02 15:04:05"
  1023. loc, _ := time.LoadLocation("Local")
  1024. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  1025. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  1026. fmt.Println(theStartTime, theEndTime)
  1027. startTime := theStartTime.Unix()
  1028. endTime := theEndTime.Unix()
  1029. var sc map[string]interface{}
  1030. sc = make(map[string]interface{})
  1031. //一天只有排班一次
  1032. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, startTime, endTime, id)
  1033. if daySchedule.ID > 0 {
  1034. switch daySchedule.ModeId {
  1035. case 1:
  1036. sc["mode"] = "HD"
  1037. case 2:
  1038. sc["mode"] = "HDF"
  1039. case 3:
  1040. sc["mode"] = "HD+HP"
  1041. case 4:
  1042. sc["mode"] = "HP"
  1043. case 5:
  1044. sc["mode"] = "HF"
  1045. case 6:
  1046. sc["mode"] = "SCUF"
  1047. case 7:
  1048. sc["mode"] = "IUF"
  1049. case 8:
  1050. sc["mode"] = "HFHD"
  1051. case 9:
  1052. sc["mode"] = "HFHD+HP"
  1053. case 10:
  1054. sc["mode"] = "PHF"
  1055. case 11:
  1056. sc["mode"] = "HFR"
  1057. case 12:
  1058. sc["mode"] = "HDF+HP"
  1059. case 13:
  1060. sc["mode"] = "CRRT"
  1061. case 14:
  1062. sc["mode"] = "腹水回输"
  1063. case 15:
  1064. sc["mode"] = "HD前置换"
  1065. case 16:
  1066. sc["mode"] = "HD后置换"
  1067. case 17:
  1068. sc["mode"] = "HDF前置换"
  1069. case 18:
  1070. sc["mode"] = "HDF后置换"
  1071. default:
  1072. sc["mode"] = "HD"
  1073. }
  1074. sc["code"] = 0
  1075. sc["msg"] = ""
  1076. sc["data"] = daySchedule
  1077. } else {
  1078. sc["code"] = 1
  1079. sc["msg"] = "抱歉,您今天没有排版!"
  1080. sc["mode"] = ""
  1081. sc["data"] = daySchedule
  1082. }
  1083. fmt.Println(sc)
  1084. type dryWeight struct {
  1085. code int
  1086. dry_weight float64
  1087. }
  1088. var dry_weight map[string]interface{}
  1089. dry_weight = make(map[string]interface{})
  1090. lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminUserInfo.Org.Id, id, startTime)
  1091. if getLPEErr != nil {
  1092. dry_weight["code"] = 1
  1093. dry_weight["dry_weight"] = nil
  1094. } else {
  1095. if lastPredialysisEvaluation == nil {
  1096. dry_weight["code"] = 1
  1097. dry_weight["dry_weight"] = nil
  1098. } else {
  1099. dry_weight["code"] = 0
  1100. dry_weight["dry_weight"] = lastPredialysisEvaluation.DryWeight
  1101. }
  1102. }
  1103. c.ServeSuccessJSON(map[string]interface{}{
  1104. "patient": dialysisinfo,
  1105. "schedule": sc,
  1106. "dryweight": dry_weight,
  1107. })
  1108. return
  1109. }