check_weight_api_controller.go 67KB

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