check_weight_api_controller.go 44KB

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