check_weight_api_controller.go 71KB

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