check_weight_api_controller.go 58KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548
  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. _ "encoding/json"
  9. "fmt"
  10. "github.com/astaxie/beego"
  11. _ "github.com/astaxie/beego"
  12. "github.com/jinzhu/gorm"
  13. "net/http"
  14. "net/url"
  15. "strconv"
  16. _ "strings"
  17. // "fmt"
  18. _ "reflect"
  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. theEvaluation, getPEErr := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  60. if getPEErr != nil {
  61. c.ErrorLog("获取透前评估失败:%v", getPEErr)
  62. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  63. return
  64. }
  65. var evaluation models.PredialysisEvaluation
  66. if theEvaluation != nil {
  67. evaluation = *theEvaluation
  68. }
  69. // 如果今天没有透前评估,则插入新的数据
  70. if theEvaluation == nil {
  71. evaluation.CreatedTime = time.Now().Unix()
  72. evaluation.Status = 1
  73. evaluation.AssessmentDate = theAssessmentDateTime
  74. evaluation.PatientId = id
  75. evaluation.UserOrgId = adminUserInfo.Org.Id
  76. // 获取上一次透前评估信息,部分数据是需要从上一次透前评估继承
  77. lastPredialysisEvaluation, _ := service.MobileGetLastTimePredialysisEvaluationOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  78. // 获取上一次透后评估,插入本次透前评估的上次透后体重(weight_after_last_transparency)字段
  79. assessmentAfterDislysis, getAADErr := service.MobileGetLastTimeAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  80. if getAADErr != nil {
  81. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  82. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  83. return
  84. }
  85. // 获取干体重,先从干体重配置里去读,如果没有,则读取上一次透前评估的干体重
  86. weight, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, id)
  87. if err == gorm.ErrRecordNotFound {
  88. if lastPredialysisEvaluation != nil {
  89. evaluation.DryWeight = lastPredialysisEvaluation.DryWeight
  90. } else {
  91. evaluation.DryWeight = 0
  92. }
  93. } else {
  94. evaluation.DryWeight = weight.DryWeight
  95. }
  96. if assessmentAfterDislysis != nil {
  97. evaluation.WeightAfterLastTransparency = assessmentAfterDislysis.WeightAfter
  98. }
  99. if lastPredialysisEvaluation != nil {
  100. evaluation.BloodAccessPartId = lastPredialysisEvaluation.BloodAccessPartId
  101. evaluation.BloodAccessPartOperaId = lastPredialysisEvaluation.BloodAccessPartOperaId
  102. evaluation.AdditionalWeight = lastPredialysisEvaluation.AdditionalWeight // 衣物重
  103. //从化益达 备注默认上一次数据
  104. if adminUserInfo.Org.Id == 10318 {
  105. evaluation.Remark = lastPredialysisEvaluation.Remark
  106. }
  107. }
  108. } else {
  109. evaluation.UpdatedTime = time.Now().Unix()
  110. }
  111. evaluation.SystolicBloodPressure = systolic_blood_pressure // 收缩压
  112. evaluation.DiastolicBloodPressure = diastolic_blood_pressure // 舒张压
  113. evaluation.PulseFrequency = pulse_frequency // 脉率
  114. evaluation.AssessmentTime = time.Now().Unix()
  115. err := service.UpadatePredialysisEvaluation(&evaluation)
  116. //记录日志
  117. byterequest, _ := json.Marshal(evaluation)
  118. assessmentBeforeDislysisLog := models.XtAssessmentBeforeDislysisLog{
  119. UserOrgId: adminUserInfo.Org.Id,
  120. AdminUserId: adminUserInfo.AdminUser.Id,
  121. ErrLog: string(byterequest),
  122. PatientId: evaluation.PatientId,
  123. RecordDate: evaluation.AssessmentDate,
  124. Ctime: time.Now().Unix(),
  125. Mtime: 0,
  126. Status: 1,
  127. Source: "物联网上传透前血压",
  128. }
  129. service.CreateBeforLog(assessmentBeforeDislysisLog)
  130. assessdateDateStart := thisTime.Format("2006-01-02")
  131. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_before_dislysis"
  132. redis := service.RedisClient()
  133. defer redis.Close()
  134. //清空key 值
  135. redis.Set(key, "", time.Second)
  136. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_befores_list_all"
  137. redis.Set(keyOne, "", time.Second)
  138. keyTwo := "scheduals_" + assessdateDateStart + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  139. redis.Set(keyTwo, "", time.Second)
  140. redis.Close()
  141. if err != nil {
  142. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  143. return
  144. }
  145. c.ServeSuccessJSON(map[string]interface{}{
  146. "msg": "ok",
  147. "evaluation": evaluation,
  148. })
  149. return
  150. } else {
  151. // 保存透后相关数据
  152. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  153. if getAADErr != nil {
  154. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  155. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  156. return
  157. }
  158. var afterevaluation models.AssessmentAfterDislysis
  159. if assessmentAfterDislysis != nil {
  160. afterevaluation = *assessmentAfterDislysis
  161. }
  162. if assessmentAfterDislysis == nil {
  163. afterevaluation.CreatedTime = time.Now().Unix()
  164. afterevaluation.Status = 1
  165. afterevaluation.AssessmentDate = theAssessmentDateTime
  166. afterevaluation.PatientId = id
  167. afterevaluation.UserOrgId = adminUserInfo.Org.Id
  168. } else {
  169. afterevaluation.UpdatedTime = time.Now().Unix()
  170. }
  171. afterevaluation.SystolicBloodPressure = systolic_blood_pressure // 收缩压
  172. afterevaluation.DiastolicBloodPressure = diastolic_blood_pressure // 舒张压
  173. afterevaluation.PulseFrequency = pulse_frequency // 脉率
  174. if adminUserInfo.Org.Id == 10138 {
  175. afterevaluation.LeaveOfficeMethod = assessmentAfterDislysis.LeaveOfficeMethod //离科方式
  176. afterevaluation.Lapse = assessmentAfterDislysis.Lapse //转归
  177. afterevaluation.Consciousness = assessmentAfterDislysis.Consciousness //意识
  178. afterevaluation.Fallrisk = assessmentAfterDislysis.Fallrisk //跌倒风险
  179. }
  180. err := service.UpdateAssessmentAfterDislysisRecord(&afterevaluation)
  181. //记录日志
  182. byterequest, _ := json.Marshal(afterevaluation)
  183. afterLog := models.XtAssessmentAfterDialysisLog{
  184. UserOrgId: adminUserInfo.Org.Id,
  185. AdminUserId: adminUserInfo.AdminUser.Id,
  186. ErrLog: string(byterequest),
  187. PatientId: afterevaluation.PatientId,
  188. RecordDate: afterevaluation.AssessmentDate,
  189. Ctime: time.Now().Unix(),
  190. Mtime: 0,
  191. Status: 1,
  192. Source: "物联网上传透后血压",
  193. }
  194. service.CreateAfterDialysisLog(afterLog)
  195. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_after_dislysis"
  196. redis := service.RedisClient()
  197. //清空key 值
  198. redis.Set(key, "", time.Second)
  199. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_after_dislysis_list_all"
  200. redis.Set(keyThree, "", time.Second)
  201. assessdateDateStart := thisTime.Format("2006-01-02")
  202. keyTwo := "scheduals_" + assessdateDateStart + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  203. redis.Set(keyTwo, "", time.Second)
  204. defer redis.Close()
  205. if err == nil {
  206. c.ServeSuccessJSON(map[string]interface{}{
  207. "assessmentAfterDislysis": afterevaluation,
  208. })
  209. }
  210. }
  211. }
  212. func (c *CheckWeightApiController) SavePatientInfoDialysis() {
  213. id, _ := c.GetInt64("patient", 0)
  214. dialysistype, _ := c.GetInt64("dialysistype", 0)
  215. if id <= 0 {
  216. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  217. return
  218. }
  219. if dialysistype <= 0 {
  220. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  221. return
  222. }
  223. adminUserInfo := c.GetMobileAdminUserInfo()
  224. patient, _ := service.FindPatientByIdWithDiseases(adminUserInfo.Org.Id, id)
  225. if patient.ID == 0 {
  226. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  227. return
  228. }
  229. thisTime := time.Now()
  230. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  231. // scheduleDateEnd := thisTime.Format("2006-01-02") + " 23:59:59"
  232. timeLayout := "2006-01-02 15:04:05"
  233. loc, _ := time.LoadLocation("Local")
  234. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  235. // theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  236. theAssessmentDateTime := theStartTime.Unix()
  237. // endTime := theEndTime.Unix()
  238. // dry_weight,_ := c.GetFloat("dry_weight",0) // 干体重
  239. weighing_before, _ := c.GetFloat("weighing_before", 0) // 透前体重
  240. dewater_amount, _ := c.GetFloat("dewater_amount", 0) // 目标脱水量(L)
  241. weight_after, _ := c.GetFloat("weight_after", 0) // 透后体重
  242. weight_loss, _ := c.GetFloat("weight_loss", 0) // 体重减少
  243. schedual, _ := service.MobileGetSchedualDetail(adminUserInfo.Org.Id, patient.ID, theStartTime.Unix())
  244. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  245. if template.TemplateId == 22 || template.TemplateId == 17 || template.TemplateId == 21 || template.TemplateId == 26 || template.TemplateId == 27 || template.TemplateId == 34 || template.TemplateId == 30 || template.TemplateId == 32 || template.TemplateId == 36 || template.TemplateId == 40 || template.TemplateId == 38 || template.TemplateId == 43 || template.TemplateId == 46 || template.TemplateId == 53 || template.TemplateId == 48 || adminUserInfo.Org.Id == 10345 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10138 || adminUserInfo.Org.Id == 10278 || adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10440 || adminUserInfo.Org.Id == 10469 || adminUserInfo.Org.Id == 10471 {
  246. if adminUserInfo.Org.Id != 10447 {
  247. dewater_amount = dewater_amount * 1000
  248. }
  249. }
  250. if dewater_amount < 0 {
  251. dewater_amount = 0
  252. }
  253. if dialysistype == 1 {
  254. // 保存透前相关数据
  255. // 获取透析处方
  256. var lastDialysisPrescribe *models.DialysisPrescription
  257. var dialysisSolution *models.DialysisSolution
  258. var dialysisPrescribe *models.DialysisPrescription
  259. var system_dialysisPrescribe *models.SystemPrescription
  260. var mode_id int64
  261. //weightfirst, _ := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, id)
  262. //if weightfirst.DryWeight > weighing_before {
  263. // return
  264. //}
  265. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  266. if schedual != nil {
  267. // 获取透析模版
  268. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.Org.Id, id, schedual.ModeId)
  269. system_dialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeIdSix(adminUserInfo.Org.Id, schedual.ModeId)
  270. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.Org.Id, id, schedual.ModeId)
  271. //判断透析模式,针对河间咸的
  272. if adminUserInfo.Org.Id == 10090 {
  273. if dialysisSolution.ModeId != 2 && dialysisSolution.ModeId != 5 && dialysisSolution.ModeId != 12 {
  274. dialysisSolution.DisplaceLiquiPart = 0
  275. dialysisSolution.DisplaceLiquiValue = 0
  276. }
  277. if lastDialysisPrescribe.ModeId != 2 && lastDialysisPrescribe.ModeId != 5 && lastDialysisPrescribe.ModeId != 12 {
  278. dialysisSolution.DisplaceLiquiPart = 0
  279. dialysisSolution.DisplaceLiquiValue = 0
  280. }
  281. }
  282. mode_id = schedual.ModeId
  283. } else {
  284. // 获取透析模版
  285. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.Org.Id, id)
  286. if dialysisPrescribe == nil && dialysisSolution != nil {
  287. mode_id = dialysisSolution.ModeId
  288. }
  289. if dialysisPrescribe == nil && dialysisSolution == nil {
  290. mode_id = 0
  291. }
  292. }
  293. // 插入透析处方
  294. if dialysisPrescribe == nil && dialysisSolution != nil {
  295. var newprescribe models.DialysisPrescription
  296. newprescribe.UserOrgId = dialysisSolution.UserOrgId
  297. newprescribe.PatientId = dialysisSolution.PatientId
  298. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  299. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  300. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  301. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  302. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  303. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  304. newprescribe.ModeId = dialysisSolution.ModeId
  305. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  306. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  307. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  308. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  309. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  310. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  311. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  312. newprescribe.Glucose = dialysisSolution.Glucose
  313. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  314. newprescribe.Kalium = dialysisSolution.Kalium
  315. newprescribe.Sodium = dialysisSolution.Sodium
  316. newprescribe.Calcium = dialysisSolution.Calcium
  317. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  318. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  319. newprescribe.Conductivity = dialysisSolution.Conductivity
  320. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  321. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  322. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  323. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  324. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  325. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  326. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  327. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  328. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  329. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  330. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  331. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  332. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  333. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  334. newprescribe.DialysisIrrigation = dialysisSolution.DialysisIrrigation
  335. newprescribe.DialysisDialyszers = dialysisSolution.DialysisDialyszers
  336. newprescribe.DialysisStrainer = dialysisSolution.DialysisStrainer
  337. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  338. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  339. newprescribe.CreatedTime = time.Now().Unix()
  340. newprescribe.UpdatedTime = time.Now().Unix()
  341. newprescribe.RecordDate = theAssessmentDateTime
  342. newprescribe.DewaterAmount = dewater_amount
  343. newprescribe.TargetUltrafiltration = dewater_amount
  344. newprescribe.PrescriptionWater = dewater_amount
  345. newprescribe.Chaptalization = dialysisSolution.Chaptalization
  346. newprescribe.PrescribingNumber = 1
  347. newprescribe.BloodAccessPartId = dialysisSolution.BloodAccessPartId
  348. newprescribe.Status = 1
  349. if adminUserInfo.Org.Id != 10013 && adminUserInfo.Org.Id != 10014 {
  350. newprescribe.Remark = dialysisSolution.Remark
  351. }
  352. if adminUserInfo.Org.Id == 10340 {
  353. newprescribe.TargetUltrafiltration = 0
  354. newprescribe.Sodium = 138
  355. newprescribe.Bicarbonate = 31.1
  356. newprescribe.DialysateFlow = 500
  357. }
  358. // 针对新化博翔
  359. if adminUserInfo.Org.Id == 10447 {
  360. newprescribe.DisplaceLiquiPart = 1
  361. newprescribe.DisplaceLiquiValue = 32
  362. newprescribe.DialysateFlow = 500
  363. }
  364. if adminUserInfo.Org.Id == 10121 {
  365. newprescribe.DialysisDurationHour = 4
  366. newprescribe.DialysisDurationMinute = 0
  367. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  368. }
  369. if adminUserInfo.Org.Id == 10445 {
  370. lastDialysisPrescription, _ := service.GetLastDialysisPrescription(id, adminUserInfo.Org.Id)
  371. newprescribe.Remark = lastDialysisPrescription.Remark
  372. }
  373. //针对普宁和揭阳
  374. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 10599 {
  375. prescriptionTwenty, _ := service.GetLastDialysisPrescriptionTwenty(newprescribe.PatientId, newprescribe.RecordDate, newprescribe.UserOrgId)
  376. if prescriptionTwenty.ID == 0 {
  377. //插入透析处方
  378. service.AddSigleRecord(&newprescribe)
  379. } else {
  380. //插入透析处方
  381. service.UpdateAddSigleRecord(prescriptionTwenty.ID, newprescribe.TargetUltrafiltration)
  382. }
  383. } else {
  384. //插入透析处方
  385. service.AddSigleRecord(&newprescribe)
  386. }
  387. //记录日志
  388. byterequest, _ := json.Marshal(newprescribe)
  389. prescriptionLog := models.XtDialysisPrescriptionLog{
  390. UserOrgId: newprescribe.UserOrgId,
  391. Ctime: time.Now().Unix(),
  392. Mtime: 0,
  393. ErrLog: string(byterequest),
  394. AdminUserId: adminUserInfo.AdminUser.Id,
  395. RecordDate: newprescribe.RecordDate,
  396. PatientId: newprescribe.PatientId,
  397. Source: "物联网上传",
  398. Status: 1,
  399. }
  400. service.CreatePrescriptionLog(prescriptionLog)
  401. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  402. redis := service.RedisClient()
  403. //清空key 值
  404. redis.Set(key, "", time.Second)
  405. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  406. redis.Set(keyTwo, "", time.Second)
  407. scheduleDateStartOne := thisTime.Format("2006-01-02")
  408. keyThree := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  409. redis.Set(keyThree, "", time.Second)
  410. defer redis.Close()
  411. }
  412. if dialysisPrescribe == nil && dialysisSolution == nil {
  413. if lastDialysisPrescribe != nil {
  414. var newprescribe models.DialysisPrescription
  415. newprescribe.UserOrgId = lastDialysisPrescribe.UserOrgId
  416. newprescribe.PatientId = lastDialysisPrescribe.PatientId
  417. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  418. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  419. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  420. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  421. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  422. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  423. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  424. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  425. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  426. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  427. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  428. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  429. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  430. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  431. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  432. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  433. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  434. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  435. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  436. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  437. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  438. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  439. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  440. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  441. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  442. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  443. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  444. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  445. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  446. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  447. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  448. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  449. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  450. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  451. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  452. newprescribe.DialysisDialyszers = lastDialysisPrescribe.DialysisDialyszers
  453. newprescribe.DialysisIrrigation = lastDialysisPrescribe.DialysisIrrigation
  454. newprescribe.DialysisStrainer = lastDialysisPrescribe.DialysisStrainer
  455. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  456. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  457. newprescribe.BloodAccessPartId = lastDialysisPrescribe.BloodAccessPartId
  458. newprescribe.CreatedTime = time.Now().Unix()
  459. newprescribe.UpdatedTime = time.Now().Unix()
  460. newprescribe.RecordDate = theAssessmentDateTime
  461. newprescribe.DewaterAmount = dewater_amount
  462. newprescribe.TargetUltrafiltration = dewater_amount
  463. newprescribe.PrescriptionWater = dewater_amount
  464. newprescribe.Status = 1
  465. if adminUserInfo.Org.Id != 10490 {
  466. newprescribe.Remark = lastDialysisPrescribe.Remark
  467. } else {
  468. newprescribe.Remark = ""
  469. }
  470. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  471. newprescribe.PrescribingNumber = 1
  472. if adminUserInfo.Org.Id == 10340 {
  473. newprescribe.TargetUltrafiltration = 0
  474. }
  475. if adminUserInfo.Org.Id == 10121 {
  476. newprescribe.DialysisDurationHour = 4
  477. newprescribe.DialysisDurationMinute = 0
  478. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  479. }
  480. if adminUserInfo.Org.Id == 10445 {
  481. lastDialysisPrescription, _ := service.GetLastDialysisPrescription(id, adminUserInfo.Org.Id)
  482. newprescribe.Remark = lastDialysisPrescription.Remark
  483. }
  484. //err := service.AddSigleRecord(&newprescribe)
  485. var err error
  486. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 10599 {
  487. prescriptionTwenty, _ := service.GetLastDialysisPrescriptionTwenty(newprescribe.PatientId, newprescribe.RecordDate, newprescribe.UserOrgId)
  488. if prescriptionTwenty.ID == 0 {
  489. //插入透析处方
  490. service.AddSigleRecord(&newprescribe)
  491. } else {
  492. //插入透析处方
  493. service.UpdateAddSigleRecord(prescriptionTwenty.ID, newprescribe.TargetUltrafiltration)
  494. }
  495. } else {
  496. //插入透析处方
  497. err = service.AddSigleRecord(&newprescribe)
  498. }
  499. //记录日志
  500. byterequest, _ := json.Marshal(newprescribe)
  501. prescriptionLog := models.XtDialysisPrescriptionLog{
  502. UserOrgId: adminUserInfo.Org.Id,
  503. Ctime: time.Now().Unix(),
  504. Mtime: 0,
  505. ErrLog: string(byterequest),
  506. AdminUserId: adminUserInfo.AdminUser.Id,
  507. RecordDate: newprescribe.RecordDate,
  508. PatientId: id,
  509. Source: "物联网上传",
  510. Status: 1,
  511. }
  512. service.CreatePrescriptionLog(prescriptionLog)
  513. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  514. redis := service.RedisClient()
  515. //清空key 值
  516. redis.Set(key, "", time.Second)
  517. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  518. redis.Set(keyTwo, "", time.Second)
  519. scheduleDateStartOne := thisTime.Format("2006-01-02")
  520. keyThree := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  521. redis.Set(keyThree, "", time.Second)
  522. defer redis.Close()
  523. if err != nil {
  524. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  525. }
  526. } else if system_dialysisPrescribe != nil {
  527. var newprescribe models.DialysisPrescription
  528. newprescribe.UserOrgId = system_dialysisPrescribe.UserOrgId
  529. newprescribe.PatientId = id
  530. newprescribe.Anticoagulant = system_dialysisPrescribe.Anticoagulant
  531. newprescribe.AnticoagulantShouji = system_dialysisPrescribe.AnticoagulantShouji
  532. newprescribe.AnticoagulantWeichi = system_dialysisPrescribe.AnticoagulantWeichi
  533. newprescribe.AnticoagulantZongliang = system_dialysisPrescribe.AnticoagulantZongliang
  534. newprescribe.AnticoagulantGaimingcheng = system_dialysisPrescribe.AnticoagulantGaimingcheng
  535. newprescribe.AnticoagulantGaijiliang = system_dialysisPrescribe.AnticoagulantGaijiliang
  536. newprescribe.ModeId = system_dialysisPrescribe.ModeId
  537. newprescribe.DialysisDuration = system_dialysisPrescribe.DialysisDuration
  538. newprescribe.ReplacementWay = system_dialysisPrescribe.ReplacementWay
  539. newprescribe.HemodialysisMachine = system_dialysisPrescribe.HemodialysisMachine
  540. newprescribe.BloodFilter = system_dialysisPrescribe.BloodFilter
  541. newprescribe.PerfusionApparatus = system_dialysisPrescribe.PerfusionApparatus
  542. newprescribe.BloodFlowVolume = system_dialysisPrescribe.BloodFlowVolume
  543. newprescribe.DisplaceLiqui = system_dialysisPrescribe.DisplaceLiqui
  544. newprescribe.Glucose = system_dialysisPrescribe.Glucose
  545. newprescribe.DialysateFlow = system_dialysisPrescribe.DialysateFlow
  546. newprescribe.Kalium = system_dialysisPrescribe.Kalium
  547. newprescribe.Sodium = system_dialysisPrescribe.Sodium
  548. newprescribe.Calcium = system_dialysisPrescribe.Calcium
  549. newprescribe.Bicarbonate = system_dialysisPrescribe.Bicarbonate
  550. newprescribe.DialysateTemperature = system_dialysisPrescribe.DialysateTemperature
  551. newprescribe.Conductivity = system_dialysisPrescribe.Conductivity
  552. newprescribe.BodyFluid = system_dialysisPrescribe.BodyFluid
  553. newprescribe.SpecialMedicine = system_dialysisPrescribe.SpecialMedicine
  554. newprescribe.SpecialMedicineOther = system_dialysisPrescribe.SpecialMedicineOther
  555. newprescribe.DisplaceLiquiPart = system_dialysisPrescribe.DisplaceLiquiPart
  556. newprescribe.DisplaceLiquiValue = system_dialysisPrescribe.DisplaceLiquiValue
  557. newprescribe.BloodAccess = system_dialysisPrescribe.BloodAccess
  558. newprescribe.Ultrafiltration = system_dialysisPrescribe.Ultrafiltration
  559. newprescribe.DialysisDurationHour = system_dialysisPrescribe.DialysisDurationHour
  560. newprescribe.DialysisDurationMinute = system_dialysisPrescribe.DialysisDurationMinute
  561. newprescribe.DialysateFormulation = system_dialysisPrescribe.DialysateFormulation
  562. newprescribe.Dialyzer = system_dialysisPrescribe.Dialyzer
  563. newprescribe.ReplacementTotal = system_dialysisPrescribe.ReplacementTotal
  564. newprescribe.DialyzerPerfusionApparatus = system_dialysisPrescribe.DialyzerPerfusionApparatus
  565. newprescribe.DialysisIrrigation = system_dialysisPrescribe.DialysisIrrigation
  566. newprescribe.DialysisDialyszers = system_dialysisPrescribe.DialysisDialyszers
  567. newprescribe.BodyFluidOther = system_dialysisPrescribe.BodyFluidOther
  568. newprescribe.TargetKtv = system_dialysisPrescribe.TargetKtv
  569. newprescribe.CreatedTime = time.Now().Unix()
  570. newprescribe.UpdatedTime = time.Now().Unix()
  571. newprescribe.RecordDate = theAssessmentDateTime
  572. newprescribe.DewaterAmount = dewater_amount
  573. newprescribe.TargetUltrafiltration = dewater_amount
  574. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  575. newprescribe.BloodAccessPartId = lastDialysisPrescribe.BloodAccessPartId
  576. newprescribe.Status = 1
  577. newprescribe.PrescribingNumber = 1
  578. if adminUserInfo.Org.Id == 10340 {
  579. newprescribe.TargetUltrafiltration = 0
  580. }
  581. if adminUserInfo.Org.Id == 10121 {
  582. newprescribe.DialysisDurationHour = 4
  583. newprescribe.DialysisDurationMinute = 0
  584. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  585. }
  586. if adminUserInfo.Org.Id == 10445 {
  587. lastDialysisPrescription, _ := service.GetLastDialysisPrescription(id, adminUserInfo.Org.Id)
  588. newprescribe.Remark = lastDialysisPrescription.Remark
  589. }
  590. err := service.AddSigleRecord(&newprescribe)
  591. //记录日志
  592. byterequest, _ := json.Marshal(newprescribe)
  593. prescriptionLog := models.XtDialysisPrescriptionLog{
  594. UserOrgId: adminUserInfo.Org.Id,
  595. Ctime: time.Now().Unix(),
  596. Mtime: 0,
  597. ErrLog: string(byterequest),
  598. AdminUserId: adminUserInfo.AdminUser.Id,
  599. RecordDate: newprescribe.RecordDate,
  600. PatientId: id,
  601. Source: "物联网上传",
  602. Status: 1,
  603. }
  604. service.CreatePrescriptionLog(prescriptionLog)
  605. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  606. redis := service.RedisClient()
  607. //清空key 值
  608. redis.Set(key, "", time.Second)
  609. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  610. redis.Set(keyTwo, "", time.Second)
  611. scheduleDateStartOne := thisTime.Format("2006-01-02")
  612. keyThree := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  613. redis.Set(keyThree, "", time.Second)
  614. defer redis.Close()
  615. if err != nil {
  616. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  617. }
  618. } else {
  619. var newprescribe models.DialysisPrescription
  620. newprescribe.UserOrgId = adminUserInfo.Org.Id
  621. newprescribe.PatientId = id
  622. newprescribe.ModeId = mode_id
  623. newprescribe.CreatedTime = time.Now().Unix()
  624. newprescribe.UpdatedTime = time.Now().Unix()
  625. newprescribe.RecordDate = theAssessmentDateTime
  626. newprescribe.DewaterAmount = dewater_amount
  627. newprescribe.TargetUltrafiltration = dewater_amount
  628. newprescribe.Status = 1
  629. if adminUserInfo.Org.Id == 10445 {
  630. lastDialysisPrescription, _ := service.GetLastDialysisPrescription(id, adminUserInfo.Org.Id)
  631. newprescribe.Remark = lastDialysisPrescription.Remark
  632. }
  633. err := service.AddSigleRecord(&newprescribe)
  634. //记录日志
  635. byterequest, _ := json.Marshal(newprescribe)
  636. prescriptionLog := models.XtDialysisPrescriptionLog{
  637. UserOrgId: adminUserInfo.Org.Id,
  638. Ctime: time.Now().Unix(),
  639. Mtime: 0,
  640. ErrLog: string(byterequest),
  641. AdminUserId: adminUserInfo.AdminUser.Id,
  642. RecordDate: newprescribe.RecordDate,
  643. PatientId: id,
  644. Source: "物联网上传",
  645. Status: 1,
  646. }
  647. service.CreatePrescriptionLog(prescriptionLog)
  648. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  649. redis := service.RedisClient()
  650. //清空key 值
  651. redis.Set(key, "", time.Second)
  652. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  653. redis.Set(keyTwo, "", time.Second)
  654. scheduleDateStartOne := thisTime.Format("2006-01-02")
  655. keyThree := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  656. redis.Set(keyThree, "", time.Second)
  657. defer redis.Close()
  658. if err != nil {
  659. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  660. }
  661. }
  662. }
  663. if dialysisPrescribe != nil && dialysisPrescribe.TargetUltrafiltration == 0 {
  664. dialysisPrescribe.UpdatedTime = time.Now().Unix()
  665. dialysisPrescribe.RecordDate = theAssessmentDateTime
  666. dialysisPrescribe.DewaterAmount = dewater_amount
  667. dialysisPrescribe.TargetUltrafiltration = dewater_amount
  668. dialysisPrescribe.Status = 1
  669. if adminUserInfo.Org.Id == 10340 {
  670. dialysisPrescribe.TargetUltrafiltration = 0
  671. }
  672. if adminUserInfo.Org.Id == 10445 {
  673. lastDialysisPrescription, _ := service.GetLastDialysisPrescription(id, adminUserInfo.Org.Id)
  674. dialysisPrescribe.Remark = lastDialysisPrescription.Remark
  675. }
  676. updateErr := service.UpDateDialysisPrescription(dialysisPrescribe)
  677. //记录日志
  678. byterequest, _ := json.Marshal(dialysisPrescribe)
  679. prescriptionLog := models.XtDialysisPrescriptionLog{
  680. UserOrgId: adminUserInfo.Org.Id,
  681. Ctime: time.Now().Unix(),
  682. Mtime: 0,
  683. ErrLog: string(byterequest),
  684. AdminUserId: adminUserInfo.AdminUser.Id,
  685. RecordDate: dialysisPrescribe.RecordDate,
  686. PatientId: id,
  687. Source: "物联网上传",
  688. Status: 1,
  689. }
  690. service.CreatePrescriptionLog(prescriptionLog)
  691. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  692. redis := service.RedisClient()
  693. //清空key 值
  694. redis.Set(key, "", time.Second)
  695. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  696. redis.Set(keyTwo, "", time.Second)
  697. scheduleDateStartOne := thisTime.Format("2006-01-02")
  698. keyThree := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  699. redis.Set(keyThree, "", time.Second)
  700. defer redis.Close()
  701. if updateErr != nil {
  702. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  703. }
  704. }
  705. theEvaluation, getPEErr := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  706. if getPEErr != nil {
  707. c.ErrorLog("获取透前评估失败:%v", getPEErr)
  708. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  709. return
  710. }
  711. var evaluation models.PredialysisEvaluation
  712. if theEvaluation != nil {
  713. evaluation = *theEvaluation
  714. }
  715. // 如果今天没有透前评估,则插入新的数据
  716. if theEvaluation == nil {
  717. evaluation.CreatedTime = time.Now().Unix()
  718. evaluation.Status = 1
  719. evaluation.AssessmentDate = theAssessmentDateTime
  720. evaluation.PatientId = id
  721. evaluation.UserOrgId = adminUserInfo.Org.Id
  722. // 获取上一次透前评估信息,部分数据是需要从上一次透前评估继承
  723. lastPredialysisEvaluation, _ := service.MobileGetLastTimePredialysisEvaluationOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  724. // 获取上一次透后评估,插入本次透前评估的上次透后体重(weight_after_last_transparency)字段
  725. assessmentAfterDislysis, getAADErr := service.MobileGetLastTimeAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  726. if getAADErr != nil {
  727. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  728. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  729. return
  730. }
  731. // 获取干体重,先从干体重配置里去读,如果没有,则读取上一次透前评估的干体重
  732. weight, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, id)
  733. if err == gorm.ErrRecordNotFound {
  734. if lastPredialysisEvaluation != nil {
  735. evaluation.DryWeight = lastPredialysisEvaluation.DryWeight
  736. } else {
  737. evaluation.DryWeight = 0
  738. }
  739. } else {
  740. evaluation.DryWeight = weight.DryWeight
  741. }
  742. if assessmentAfterDislysis != nil {
  743. evaluation.WeightAfterLastTransparency = assessmentAfterDislysis.WeightAfter
  744. }
  745. if lastPredialysisEvaluation != nil {
  746. evaluation.BloodAccessPartId = lastPredialysisEvaluation.BloodAccessPartId
  747. evaluation.BloodAccessPartOperaId = lastPredialysisEvaluation.BloodAccessPartOperaId
  748. evaluation.AdditionalWeight = lastPredialysisEvaluation.AdditionalWeight
  749. evaluation.Temperature = lastPredialysisEvaluation.Temperature
  750. evaluation.BreathingRate = lastPredialysisEvaluation.BreathingRate
  751. evaluation.Catheter = lastPredialysisEvaluation.Catheter
  752. evaluation.InternalFistula = lastPredialysisEvaluation.InternalFistula
  753. evaluation.PulseFrequency = lastPredialysisEvaluation.PulseFrequency
  754. evaluation.Complication = lastPredialysisEvaluation.Complication
  755. evaluation.LastPostDialysis = lastPredialysisEvaluation.LastPostDialysis
  756. evaluation.DialysisInterphase = lastPredialysisEvaluation.DialysisInterphase
  757. evaluation.SymptomBeforeDialysis = lastPredialysisEvaluation.SymptomBeforeDialysis
  758. evaluation.PunctureNeedle = lastPredialysisEvaluation.PunctureNeedle
  759. evaluation.PunctureWay = lastPredialysisEvaluation.PunctureWay
  760. evaluation.InternalFistulaSkin = lastPredialysisEvaluation.InternalFistulaSkin //血透通路皮肤情况
  761. evaluation.CatheterBend = lastPredialysisEvaluation.CatheterBend //导管打折
  762. evaluation.IsHemorrhage = lastPredialysisEvaluation.IsHemorrhage //出血
  763. evaluation.IsInfect = lastPredialysisEvaluation.IsInfect //感染
  764. evaluation.Exposed = lastPredialysisEvaluation.Exposed // 外漏
  765. evaluation.DialysisCount = lastPredialysisEvaluation.DialysisCount //呼吸频次
  766. evaluation.Phinholing = lastPredialysisEvaluation.Phinholing //针眼
  767. evaluation.Remark = lastPredialysisEvaluation.Remark
  768. if adminUserInfo.Org.Id == 10318 || adminUserInfo.Org.Id == 10490 {
  769. evaluation.Remark = ""
  770. }
  771. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10447 {
  772. evaluation.BreathingRate = "20"
  773. }
  774. if adminUserInfo.Org.Id == 10445 {
  775. evaluation.VenousCatheterization = lastPredialysisEvaluation.VenousCatheterization
  776. }
  777. if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 || adminUserInfo.Org.Id == 10471 {
  778. evaluation.PulseFrequency = 80
  779. }
  780. if adminUserInfo.Org.Id == 10440 {
  781. evaluation.Temperature = 36.5
  782. }
  783. if adminUserInfo.Org.Id == 10469 {
  784. evaluation.Temperature = 36.5
  785. }
  786. if adminUserInfo.Org.Id == 10471 {
  787. evaluation.Temperature = 36.5
  788. }
  789. }
  790. } else {
  791. evaluation.UpdatedTime = time.Now().Unix()
  792. }
  793. evaluation.WeightBefore = weighing_before
  794. evaluation.AssessmentTime = time.Now().Unix()
  795. err := service.UpadatePredialysisEvaluation(&evaluation)
  796. //记录日志
  797. byterequest, _ := json.Marshal(evaluation)
  798. beforLog := models.XtAssessmentBeforeDislysisLog{
  799. UserOrgId: adminUserInfo.Org.Id,
  800. Ctime: time.Now().Unix(),
  801. Mtime: 0,
  802. ErrLog: string(byterequest),
  803. AdminUserId: adminUserInfo.AdminUser.Id,
  804. RecordDate: evaluation.AssessmentDate,
  805. PatientId: id,
  806. Source: "物联网上传",
  807. Status: 1,
  808. }
  809. service.CreateBeforLog(beforLog)
  810. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_before_dislysis"
  811. redis := service.RedisClient()
  812. //清空key 值
  813. redis.Set(key, "", time.Second)
  814. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_befores_list_all"
  815. redis.Set(keyOne, "", time.Second)
  816. assessdateDateStart := thisTime.Format("2006-01-02")
  817. keyTwo := "scheduals_" + assessdateDateStart + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  818. redis.Set(keyTwo, "", time.Second)
  819. redis.Close()
  820. if err != nil {
  821. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  822. return
  823. }
  824. c.ServeSuccessJSON(map[string]interface{}{
  825. "msg": "ok",
  826. "evaluation": evaluation,
  827. })
  828. return
  829. } else {
  830. // 保存透后相关数据
  831. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  832. if getAADErr != nil {
  833. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  834. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  835. return
  836. }
  837. var afterevaluation models.AssessmentAfterDislysis
  838. if assessmentAfterDislysis != nil {
  839. afterevaluation = *assessmentAfterDislysis
  840. }
  841. if assessmentAfterDislysis == nil {
  842. afterevaluation.CreatedTime = time.Now().Unix()
  843. afterevaluation.Status = 1
  844. afterevaluation.AssessmentDate = theAssessmentDateTime
  845. afterevaluation.PatientId = id
  846. afterevaluation.UserOrgId = adminUserInfo.Org.Id
  847. } else {
  848. afterevaluation.UpdatedTime = time.Now().Unix()
  849. }
  850. afterevaluation.WeightAfter = weight_after
  851. afterevaluation.WeightLoss = weight_loss
  852. if adminUserInfo.Org.Id == 10138 {
  853. afterevaluation.LeaveOfficeMethod = assessmentAfterDislysis.LeaveOfficeMethod //离科方式
  854. afterevaluation.Lapse = assessmentAfterDislysis.Lapse //转归
  855. afterevaluation.Consciousness = assessmentAfterDislysis.Consciousness //意识
  856. afterevaluation.Fallrisk = assessmentAfterDislysis.Fallrisk
  857. }
  858. if adminUserInfo.Org.Id == 10307 || adminUserInfo.Org.Id == 10445 {
  859. afterevaluation.ActualUltrafiltration = weight_loss * 1000 //中能建的计量单位是毫升(ml)
  860. }
  861. //北方营口
  862. if adminUserInfo.Org.Id == 10445 {
  863. prescribe, _ := service.MobileGetDialysisPrescribe(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  864. afterevaluation.ActualDisplacement = prescribe.DisplaceLiquiValue
  865. }
  866. //蓬安济民
  867. if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 {
  868. afterevaluation.PulseFrequency = 80
  869. }
  870. err := service.UpdateAssessmentAfterDislysisRecord(&afterevaluation)
  871. //记录日志
  872. byterequest, _ := json.Marshal(afterevaluation)
  873. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  874. UserOrgId: afterevaluation.UserOrgId,
  875. PatientId: afterevaluation.PatientId,
  876. RecordDate: afterevaluation.AssessmentDate,
  877. Status: 1,
  878. ErrLog: string(byterequest),
  879. AdminUserId: adminUserInfo.AdminUser.Id,
  880. Ctime: time.Now().Unix(),
  881. Mtime: 0,
  882. Source: "物联网称重",
  883. }
  884. service.CreateAfterDialysisLog(afterDialysisLog)
  885. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_after_dislysis"
  886. redis := service.RedisClient()
  887. //清空key 值
  888. redis.Set(key, "", time.Second)
  889. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_after_dislysis_list_all"
  890. redis.Set(keyThree, "", time.Second)
  891. assessdateDateStart := thisTime.Format("2006-01-02")
  892. keyTwo := "scheduals_" + assessdateDateStart + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  893. redis.Set(keyTwo, "", time.Second)
  894. redis.Close()
  895. if err == nil {
  896. c.ServeSuccessJSON(map[string]interface{}{
  897. "assessmentAfterDislysis": afterevaluation,
  898. })
  899. }
  900. }
  901. }
  902. func (c *CheckWeightApiController) SetSyncTime() {
  903. sn := c.GetString("sn")
  904. if len(sn) > 0 {
  905. redis := service.RedisClient()
  906. defer redis.Close()
  907. redis.Set(sn, 0, 0)
  908. }
  909. serviceTime := time.Now().Unix()
  910. c.ServeSuccessJSON(map[string]interface{}{
  911. "status": 1,
  912. "servicetime": serviceTime,
  913. })
  914. }
  915. func (c *CheckWeightApiController) GetPatientList() {
  916. ftype, _ := c.GetInt64("type", 0)
  917. sn := c.GetString("sn")
  918. syncTime := int64(0)
  919. redis := service.RedisClient()
  920. defer redis.Close()
  921. if len(sn) > 0 {
  922. syncTimeStr, _ := redis.Get(sn).Result()
  923. syncTime, _ = strconv.ParseInt(syncTimeStr, 10, 64)
  924. }
  925. if ftype == 1 {
  926. timeNow := time.Now().Unix()
  927. redis.Set(sn, timeNow, 0)
  928. }
  929. adminUserInfo := c.GetMobileAdminUserInfo()
  930. patientList, total, error := service.GetPatientListByUpdateTime(adminUserInfo.Org.Id, int64(syncTime))
  931. need_update := 0
  932. if syncTime == 0 {
  933. need_update = 1
  934. }
  935. if error != nil {
  936. c.ErrorLog("获取病人列表失败:%v", error)
  937. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  938. return
  939. }
  940. serviceTime := time.Now().Unix()
  941. c.ServeSuccessJSON(map[string]interface{}{
  942. "need_update": need_update,
  943. "patientlist": patientList,
  944. "total": total,
  945. "servicetime": serviceTime,
  946. })
  947. }
  948. func (c *CheckWeightApiController) GetPatientListForSchedules() {
  949. thisTime := time.Now()
  950. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  951. timeLayout := "2006-01-02 15:04:05"
  952. loc, _ := time.LoadLocation("Local")
  953. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  954. syncTime := theStartTime.Unix()
  955. adminUserInfo := c.GetMobileAdminUserInfo()
  956. patientList, total, error := service.GetPatientListBySchedules(adminUserInfo.Org.Id, syncTime)
  957. patientSchedule := make([]map[string]interface{}, 0)
  958. for _, item := range patientList {
  959. patientTemp := make(map[string]interface{})
  960. patientTemp["patient_id"] = item.PatientId
  961. patientTemp["patient_name"] = item.Patient.Name
  962. patientTemp["schedule_type"] = item.ScheduleType
  963. patientSchedule = append(patientSchedule, patientTemp)
  964. }
  965. if error != nil {
  966. c.ErrorLog("获取病人列表失败:%v", error)
  967. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  968. return
  969. }
  970. serviceTime := time.Now().Unix()
  971. c.ServeSuccessJSON(map[string]interface{}{
  972. "patientlist": patientSchedule,
  973. "total": total,
  974. "servicetime": serviceTime,
  975. })
  976. }
  977. func (c *CheckWeightApiController) GetPatientListForSchedulesFind() {
  978. patient_name := c.GetString("patient_name") //脉率
  979. thisTime := time.Now()
  980. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  981. timeLayout := "2006-01-02 15:04:05"
  982. loc, _ := time.LoadLocation("Local")
  983. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  984. syncTime := theStartTime.Unix()
  985. adminUserInfo := c.GetMobileAdminUserInfo()
  986. if len(patient_name) == 0 {
  987. patientList, total, error := service.GetPatientListBySchedules(adminUserInfo.Org.Id, syncTime)
  988. patientSchedule := make([]map[string]interface{}, 0)
  989. for _, item := range patientList {
  990. patientTemp := make(map[string]interface{})
  991. patientTemp["patient_id"] = item.PatientId
  992. patientTemp["patient_name"] = item.Patient.Name
  993. patientTemp["schedule_type"] = item.ScheduleType
  994. patientSchedule = append(patientSchedule, patientTemp)
  995. }
  996. if error != nil {
  997. c.ErrorLog("获取病人列表失败:%v", error)
  998. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  999. return
  1000. }
  1001. serviceTime := time.Now().Unix()
  1002. c.ServeSuccessJSON(map[string]interface{}{
  1003. "patientlist": patientSchedule,
  1004. "total": total,
  1005. "servicetime": serviceTime,
  1006. })
  1007. } else {
  1008. patientList, total, error := service.GetPatientListBySchedulesFind(adminUserInfo.Org.Id, syncTime, patient_name)
  1009. patientSchedule := make([]map[string]interface{}, 0)
  1010. for _, item := range patientList {
  1011. if item.Patient.ID > 0 {
  1012. patientTemp := make(map[string]interface{})
  1013. patientTemp["patient_id"] = item.PatientId
  1014. patientTemp["patient_name"] = item.Patient.Name
  1015. patientTemp["schedule_type"] = item.ScheduleType
  1016. patientSchedule = append(patientSchedule, patientTemp)
  1017. }
  1018. }
  1019. if error != nil {
  1020. c.ErrorLog("获取病人列表失败:%v", error)
  1021. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1022. return
  1023. }
  1024. serviceTime := time.Now().Unix()
  1025. c.ServeSuccessJSON(map[string]interface{}{
  1026. "patientlist": patientSchedule,
  1027. "total": total,
  1028. "servicetime": serviceTime,
  1029. })
  1030. }
  1031. }
  1032. func (c *CheckWeightApiController) GetPatientListById() {
  1033. patientId, _ := c.GetInt64("patient_id", 0)
  1034. if patientId <= 0 {
  1035. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1036. return
  1037. }
  1038. adminUserInfo := c.GetMobileAdminUserInfo()
  1039. patient, error := service.GetPatientListById(adminUserInfo.Org.Id, patientId)
  1040. if error != nil {
  1041. c.ErrorLog("获取病人详情失败:%v", error)
  1042. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1043. return
  1044. }
  1045. c.ServeSuccessJSON(map[string]interface{}{
  1046. "patientinfo": patient,
  1047. })
  1048. }
  1049. func (c *CheckWeightApiController) GetPatientInfoDialysis() {
  1050. id, _ := c.GetInt64("patient", 0)
  1051. if id <= 0 {
  1052. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1053. return
  1054. }
  1055. adminUserInfo := c.GetMobileAdminUserInfo()
  1056. patient, _ := service.FindPatientByIdWithDiseases(adminUserInfo.Org.Id, id)
  1057. if patient.ID <= 0 {
  1058. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1059. return
  1060. }
  1061. var dialysisinfo map[string]interface{}
  1062. dialysisinfo = make(map[string]interface{})
  1063. dialysisinfo["id"] = patient.ID
  1064. dialysisinfo["name"] = patient.Name
  1065. dialysisinfo["dialysis_no"] = patient.DialysisNo
  1066. thisTime := time.Now()
  1067. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  1068. scheduleDateEnd := thisTime.Format("2006-01-02") + " 23:59:59"
  1069. timeLayout := "2006-01-02 15:04:05"
  1070. loc, _ := time.LoadLocation("Local")
  1071. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  1072. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  1073. startTime := theStartTime.Unix()
  1074. endTime := theEndTime.Unix()
  1075. // 判断当前用户是透析前还是透析后
  1076. var dialysistype int
  1077. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, startTime)
  1078. if dialysisOrder == nil {
  1079. dialysistype = 1
  1080. } else {
  1081. dialysistype = 2
  1082. }
  1083. // 获取当前或者下次排班信息
  1084. var sc map[string]interface{}
  1085. sc = make(map[string]interface{})
  1086. var mode_id int64
  1087. if dialysistype == 1 {
  1088. daySchedule, _ := service.GetPatientScheduleFormDay(adminUserInfo.Org.Id, startTime, endTime, id)
  1089. println(daySchedule[0].Schedule.ModeId)
  1090. if len(daySchedule) <= 0 {
  1091. sc["code"] = 1
  1092. sc["msg"] = "抱歉,您今天没有排版!"
  1093. mode_id = 0
  1094. sc["data"] = daySchedule
  1095. } else {
  1096. if daySchedule[0].Schedule.ID > 0 {
  1097. sc["code"] = 0
  1098. sc["msg"] = ""
  1099. mode_id = daySchedule[0].Schedule.ModeId
  1100. sc["data"] = daySchedule
  1101. } else {
  1102. sc["code"] = 1
  1103. sc["msg"] = "抱歉,您今天没有排版!"
  1104. mode_id = 0
  1105. sc["data"] = daySchedule
  1106. }
  1107. }
  1108. // 排队叫号的签到
  1109. go func() {
  1110. ssoDomain := beego.AppConfig.String("call_domain")
  1111. api := ssoDomain + "/index/patientsign/" + strconv.FormatInt(adminUserInfo.Org.Id, 10) + "/" + strconv.FormatInt(id, 10)
  1112. values := make(url.Values)
  1113. http.PostForm(api, values)
  1114. }()
  1115. } else {
  1116. nextSchedule, _ := service.GetNextSchedule(adminUserInfo.Org.Id, endTime, id)
  1117. if len(nextSchedule) <= 0 {
  1118. sc["code"] = 1
  1119. sc["msg"] = "抱歉,您后续没有排版!"
  1120. mode_id = 0
  1121. sc["data"] = nextSchedule
  1122. } else {
  1123. if nextSchedule[0].Schedule.ID > 0 {
  1124. sc["code"] = 0
  1125. sc["msg"] = ""
  1126. mode_id = nextSchedule[0].Schedule.ModeId
  1127. sc["data"] = nextSchedule
  1128. } else {
  1129. sc["code"] = 1
  1130. sc["msg"] = "抱歉,您后续没有排版!"
  1131. mode_id = 0
  1132. sc["data"] = nextSchedule
  1133. }
  1134. }
  1135. }
  1136. switch mode_id {
  1137. case 1:
  1138. sc["mode"] = "HD"
  1139. break
  1140. case 2:
  1141. sc["mode"] = "HDF"
  1142. break
  1143. case 3:
  1144. sc["mode"] = "HD+HP"
  1145. break
  1146. case 4:
  1147. sc["mode"] = "HP"
  1148. break
  1149. case 5:
  1150. sc["mode"] = "HF"
  1151. break
  1152. case 6:
  1153. sc["mode"] = "SCUF"
  1154. break
  1155. case 7:
  1156. sc["mode"] = "IUF"
  1157. break
  1158. case 8:
  1159. sc["mode"] = "HFHD"
  1160. break
  1161. case 9:
  1162. sc["mode"] = "HFHD+HP"
  1163. break
  1164. case 10:
  1165. sc["mode"] = "PHF"
  1166. break
  1167. case 11:
  1168. sc["mode"] = "HFR"
  1169. break
  1170. case 12:
  1171. sc["mode"] = "HDF+HP"
  1172. break
  1173. case 13:
  1174. sc["mode"] = "CRRT"
  1175. break
  1176. case 14:
  1177. sc["mode"] = "腹水回输"
  1178. break
  1179. case 15:
  1180. sc["mode"] = "HD前置换"
  1181. break
  1182. case 16:
  1183. sc["mode"] = "HD后置换"
  1184. break
  1185. case 17:
  1186. sc["mode"] = "HDF前置换"
  1187. break
  1188. case 18:
  1189. sc["mode"] = "HDF后置换"
  1190. break
  1191. default:
  1192. sc["mode"] = "HD"
  1193. break
  1194. }
  1195. // 获取患者透前干体重或者获取患者透前体重
  1196. var dry_weight map[string]interface{}
  1197. dry_weight = make(map[string]interface{})
  1198. var after_dry_weight map[string]interface{}
  1199. after_dry_weight = make(map[string]interface{})
  1200. if dialysistype == 1 {
  1201. lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminUserInfo.Org.Id, id, endTime)
  1202. weight, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, id)
  1203. if err == gorm.ErrRecordNotFound {
  1204. if getLPEErr != nil {
  1205. dry_weight["code"] = 1
  1206. dry_weight["dry_weight"] = nil
  1207. } else {
  1208. if lastPredialysisEvaluation == nil {
  1209. dry_weight["code"] = 1
  1210. dry_weight["dry_weight"] = nil
  1211. } else {
  1212. // 传输的干体重实际为干体重加上衣服重
  1213. dry_weight["code"] = 0
  1214. dry_weight["dry_weight"] = lastPredialysisEvaluation.DryWeight + lastPredialysisEvaluation.AdditionalWeight
  1215. }
  1216. }
  1217. } else {
  1218. if err != nil {
  1219. dry_weight["code"] = 1
  1220. dry_weight["dry_weight"] = nil
  1221. } else {
  1222. dry_weight["code"] = 0
  1223. if getLPEErr != nil {
  1224. dry_weight["code"] = 0
  1225. dry_weight["dry_weight"] = weight.DryWeight
  1226. } else {
  1227. if lastPredialysisEvaluation == nil {
  1228. dry_weight["code"] = 1
  1229. dry_weight["dry_weight"] = weight.DryWeight
  1230. } else {
  1231. // 传输的干体重实际为干体重加上衣服重
  1232. dry_weight["code"] = 0
  1233. dry_weight["dry_weight"] = weight.DryWeight + lastPredialysisEvaluation.AdditionalWeight
  1234. }
  1235. }
  1236. }
  1237. }
  1238. } else {
  1239. predialysisEvaluation, getPEErr := service.MobileGetPredialysisEvaluation(adminUserInfo.Org.Id, id, startTime)
  1240. if getPEErr != nil {
  1241. dry_weight["code"] = 1
  1242. dry_weight["dry_weight"] = nil
  1243. } else {
  1244. if predialysisEvaluation == nil {
  1245. dry_weight["code"] = 1
  1246. dry_weight["dry_weight"] = nil
  1247. } else {
  1248. dry_weight["code"] = 0
  1249. dry_weight["dry_weight"] = predialysisEvaluation.WeightBefore
  1250. }
  1251. }
  1252. lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminUserInfo.Org.Id, id, endTime)
  1253. weight, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, id)
  1254. if err == gorm.ErrRecordNotFound {
  1255. if getLPEErr != nil {
  1256. after_dry_weight["code"] = 1
  1257. after_dry_weight["dry_weight"] = nil
  1258. } else {
  1259. if lastPredialysisEvaluation == nil {
  1260. after_dry_weight["code"] = 1
  1261. after_dry_weight["dry_weight"] = nil
  1262. } else {
  1263. // 传输的干体重实际为干体重加上衣服重
  1264. after_dry_weight["code"] = 0
  1265. after_dry_weight["dry_weight"] = lastPredialysisEvaluation.DryWeight + lastPredialysisEvaluation.AdditionalWeight
  1266. }
  1267. }
  1268. } else {
  1269. if err != nil {
  1270. after_dry_weight["code"] = 1
  1271. after_dry_weight["dry_weight"] = nil
  1272. } else {
  1273. after_dry_weight["code"] = 0
  1274. if getLPEErr != nil {
  1275. after_dry_weight["code"] = 0
  1276. after_dry_weight["dry_weight"] = weight.DryWeight
  1277. } else {
  1278. if lastPredialysisEvaluation == nil {
  1279. after_dry_weight["code"] = 1
  1280. after_dry_weight["dry_weight"] = weight.DryWeight
  1281. } else {
  1282. // 传输的干体重实际为干体重加上衣服重
  1283. after_dry_weight["code"] = 0
  1284. after_dry_weight["dry_weight"] = weight.DryWeight + lastPredialysisEvaluation.AdditionalWeight
  1285. }
  1286. }
  1287. }
  1288. }
  1289. }
  1290. c.ServeSuccessJSON(map[string]interface{}{
  1291. "dialysistype": dialysistype,
  1292. "patient": dialysisinfo,
  1293. "schedule": sc,
  1294. "dryweight": dry_weight,
  1295. "after_dry_weight": after_dry_weight,
  1296. })
  1297. return
  1298. }
  1299. func (c *CheckWeightApiController) GetPatientInfoBeforeDialysis() {
  1300. id, _ := c.GetInt64("patient", 0)
  1301. if id <= 0 {
  1302. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1303. return
  1304. }
  1305. adminUserInfo := c.GetMobileAdminUserInfo()
  1306. patient, _ := service.FindPatientByIdWithDiseases(adminUserInfo.Org.Id, id)
  1307. if patient.ID == 0 {
  1308. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1309. return
  1310. }
  1311. var dialysisinfo map[string]interface{}
  1312. dialysisinfo = make(map[string]interface{})
  1313. dialysisinfo["id"] = patient.ID
  1314. dialysisinfo["name"] = patient.Name
  1315. dialysisinfo["dialysis_no"] = patient.DialysisNo
  1316. thisTime := time.Now()
  1317. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  1318. scheduleDateEnd := thisTime.Format("2006-01-02") + " 23:59:59"
  1319. fmt.Println(scheduleDateStart, scheduleDateEnd)
  1320. timeLayout := "2006-01-02 15:04:05"
  1321. loc, _ := time.LoadLocation("Local")
  1322. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  1323. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  1324. fmt.Println(theStartTime, theEndTime)
  1325. startTime := theStartTime.Unix()
  1326. endTime := theEndTime.Unix()
  1327. var sc map[string]interface{}
  1328. sc = make(map[string]interface{})
  1329. //一天只有排班一次
  1330. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, startTime, endTime, id)
  1331. if daySchedule.ID > 0 {
  1332. switch daySchedule.ModeId {
  1333. case 1:
  1334. sc["mode"] = "HD"
  1335. case 2:
  1336. sc["mode"] = "HDF"
  1337. case 3:
  1338. sc["mode"] = "HD+HP"
  1339. case 4:
  1340. sc["mode"] = "HP"
  1341. case 5:
  1342. sc["mode"] = "HF"
  1343. case 6:
  1344. sc["mode"] = "SCUF"
  1345. case 7:
  1346. sc["mode"] = "IUF"
  1347. case 8:
  1348. sc["mode"] = "HFHD"
  1349. case 9:
  1350. sc["mode"] = "HFHD+HP"
  1351. case 10:
  1352. sc["mode"] = "PHF"
  1353. case 11:
  1354. sc["mode"] = "HFR"
  1355. case 12:
  1356. sc["mode"] = "HDF+HP"
  1357. case 13:
  1358. sc["mode"] = "CRRT"
  1359. case 14:
  1360. sc["mode"] = "腹水回输"
  1361. case 15:
  1362. sc["mode"] = "HD前置换"
  1363. case 16:
  1364. sc["mode"] = "HD后置换"
  1365. case 17:
  1366. sc["mode"] = "HDF前置换"
  1367. case 18:
  1368. sc["mode"] = "HDF后置换"
  1369. default:
  1370. sc["mode"] = "HD"
  1371. }
  1372. sc["code"] = 0
  1373. sc["msg"] = ""
  1374. sc["data"] = daySchedule
  1375. } else {
  1376. sc["code"] = 1
  1377. sc["msg"] = "抱歉,您今天没有排版!"
  1378. sc["mode"] = ""
  1379. sc["data"] = daySchedule
  1380. }
  1381. fmt.Println(sc)
  1382. type dryWeight struct {
  1383. code int
  1384. dry_weight float64
  1385. }
  1386. var dry_weight map[string]interface{}
  1387. dry_weight = make(map[string]interface{})
  1388. lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminUserInfo.Org.Id, id, startTime)
  1389. if getLPEErr != nil {
  1390. dry_weight["code"] = 1
  1391. dry_weight["dry_weight"] = nil
  1392. } else {
  1393. if lastPredialysisEvaluation == nil {
  1394. dry_weight["code"] = 1
  1395. dry_weight["dry_weight"] = nil
  1396. } else {
  1397. dry_weight["code"] = 0
  1398. dry_weight["dry_weight"] = lastPredialysisEvaluation.DryWeight
  1399. }
  1400. }
  1401. c.ServeSuccessJSON(map[string]interface{}{
  1402. "patient": dialysisinfo,
  1403. "schedule": sc,
  1404. "dryweight": dry_weight,
  1405. })
  1406. return
  1407. }