check_weight_api_controller.go 71KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956
  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 {
  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 == 10702 {
  843. evaluation.PreDialysisDrugs = "无"
  844. }
  845. evaluation.Remark = lastPredialysisEvaluation.Remark
  846. if adminUserInfo.Org.Id == 10318 || adminUserInfo.Org.Id == 10490 || adminUserInfo.Org.Id == 10016 {
  847. evaluation.Remark = ""
  848. }
  849. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10447 {
  850. evaluation.BreathingRate = "20"
  851. }
  852. if adminUserInfo.Org.Id == 10445 {
  853. evaluation.VenousCatheterization = lastPredialysisEvaluation.VenousCatheterization
  854. }
  855. if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 || adminUserInfo.Org.Id == 10471 {
  856. evaluation.PulseFrequency = 80
  857. }
  858. if adminUserInfo.Org.Id == 10440 {
  859. evaluation.Temperature = 36.5
  860. }
  861. if adminUserInfo.Org.Id == 10469 {
  862. evaluation.Temperature = 36.5
  863. }
  864. if adminUserInfo.Org.Id == 10471 {
  865. evaluation.Temperature = 36.5
  866. }
  867. if adminUserInfo.Org.Id == 10721 {
  868. evaluation.Temperature = 36.5
  869. }
  870. if adminUserInfo.Org.Id == 10702 {
  871. evaluation.PulseFrequency = 0
  872. }
  873. }
  874. } else {
  875. evaluation.UpdatedTime = time.Now().Unix()
  876. }
  877. evaluation.WeightBefore = weighing_before
  878. evaluation.AssessmentTime = time.Now().Unix()
  879. if adminUserInfo.Org.Id == 10644 {
  880. evaluation.PunctureNeedle = ""
  881. }
  882. //针对患者称重两次没有数据的问题
  883. if adminUserInfo.Org.Id == 10702 || adminUserInfo.Org.Id == 10723 || adminUserInfo.Org.Id == 10721 {
  884. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  885. lastDialysisPrescription, _ := service.GetLastDialysisPrescription(id, adminUserInfo.Org.Id)
  886. service.UpdateMobileGetDialysisPrescribeOne(lastDialysisPrescription.ID, dewater_amount)
  887. }
  888. //针对古镇乐生
  889. if adminUserInfo.Org.Id == 10731 {
  890. dewater_amount = (evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight) * 1000
  891. lastDialysisPrescription, _ := service.GetLastDialysisPrescription(id, adminUserInfo.Org.Id)
  892. service.UpdateMobileGetDialysisPrescribeOne(lastDialysisPrescription.ID, dewater_amount)
  893. }
  894. if adminUserInfo.Org.Id == 10206 {
  895. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  896. lastDialysisPrescription, _ := service.GetLastDialysisPrescription(id, adminUserInfo.Org.Id)
  897. service.UpdateMobileGetDialysisPrescribeOne(lastDialysisPrescription.ID, dewater_amount)
  898. }
  899. err := service.UpadatePredialysisEvaluation(&evaluation)
  900. //记录日志
  901. byterequest, _ := json.Marshal(evaluation)
  902. beforLog := models.XtAssessmentBeforeDislysisLog{
  903. UserOrgId: adminUserInfo.Org.Id,
  904. Ctime: time.Now().Unix(),
  905. Mtime: 0,
  906. ErrLog: string(byterequest),
  907. AdminUserId: adminUserInfo.AdminUser.Id,
  908. RecordDate: evaluation.AssessmentDate,
  909. PatientId: id,
  910. Source: "物联网上传",
  911. Status: 1,
  912. }
  913. service.CreateBeforLog(beforLog)
  914. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_before_dislysis"
  915. redis := service.RedisClient()
  916. //清空key 值
  917. redis.Set(key, "", time.Second)
  918. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_befores_list_all"
  919. redis.Set(keyOne, "", time.Second)
  920. assessdateDateStart := thisTime.Format("2006-01-02")
  921. keyTwo := "scheduals_" + assessdateDateStart + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  922. redis.Set(keyTwo, "", time.Second)
  923. redis.Close()
  924. if err != nil {
  925. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  926. return
  927. }
  928. c.ServeSuccessJSON(map[string]interface{}{
  929. "msg": "ok",
  930. "evaluation": evaluation,
  931. })
  932. return
  933. } else {
  934. // 保存透后相关数据
  935. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  936. if getAADErr != nil {
  937. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  938. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  939. return
  940. }
  941. var afterevaluation models.AssessmentAfterDislysis
  942. if assessmentAfterDislysis != nil {
  943. afterevaluation = *assessmentAfterDislysis
  944. }
  945. if assessmentAfterDislysis == nil {
  946. afterevaluation.CreatedTime = time.Now().Unix()
  947. afterevaluation.Status = 1
  948. afterevaluation.AssessmentDate = theAssessmentDateTime
  949. afterevaluation.PatientId = id
  950. afterevaluation.UserOrgId = adminUserInfo.Org.Id
  951. } else {
  952. afterevaluation.UpdatedTime = time.Now().Unix()
  953. }
  954. afterevaluation.WeightAfter = weight_after
  955. afterevaluation.WeightLoss = weight_loss
  956. if adminUserInfo.Org.Id == 10138 {
  957. afterevaluation.LeaveOfficeMethod = assessmentAfterDislysis.LeaveOfficeMethod //离科方式
  958. afterevaluation.Lapse = assessmentAfterDislysis.Lapse //转归
  959. afterevaluation.Consciousness = assessmentAfterDislysis.Consciousness //意识
  960. afterevaluation.Fallrisk = assessmentAfterDislysis.Fallrisk
  961. }
  962. if adminUserInfo.Org.Id == 10307 || adminUserInfo.Org.Id == 10445 {
  963. afterevaluation.ActualUltrafiltration = weight_loss * 1000 //中能建的计量单位是毫升(ml)
  964. }
  965. //北方营口
  966. if adminUserInfo.Org.Id == 10445 {
  967. prescribe, _ := service.MobileGetDialysisPrescribe(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  968. afterevaluation.ActualDisplacement = prescribe.DisplaceLiquiValue
  969. }
  970. //蓬安济民
  971. if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 {
  972. afterevaluation.PulseFrequency = 80
  973. }
  974. if adminUserInfo.Org.Id == 10693 {
  975. afterevaluation.ActualUltrafiltration = assessmentAfterDislysis.ActualUltrafiltration
  976. afterevaluation.SystolicBloodPressure = assessmentAfterDislysis.SystolicBloodPressure
  977. afterevaluation.DiastolicBloodPressure = assessmentAfterDislysis.DiastolicBloodPressure
  978. afterevaluation.PulseFrequency = assessmentAfterDislysis.PulseFrequency
  979. if afterevaluation.ActualUltrafiltration == 0 {
  980. lastRecord, _ := service.GetLastMonitorRecordTwenty(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  981. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(lastRecord.UltrafiltrationVolumeOne, 64)
  982. afterevaluation.ActualUltrafiltration = UltrafiltrationVolumeOne
  983. }
  984. if afterevaluation.SystolicBloodPressure == 0 {
  985. lastRecord, _ := service.GetLastMonitorRecordTwentyOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  986. systolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorSystolicBloodPressureOne, 64)
  987. afterevaluation.SystolicBloodPressure = systolicBloodPressureOne
  988. }
  989. if afterevaluation.DiastolicBloodPressure == 0 {
  990. lastRecord, _ := service.GetLastMonitorRecordTwentyTwo(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  991. MonitorDiastolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorDiastolicBloodPressureOne, 64)
  992. afterevaluation.DiastolicBloodPressure = MonitorDiastolicBloodPressureOne
  993. }
  994. if afterevaluation.PulseFrequency == 0 {
  995. lastRecord, _ := service.GetLastMonitorRecordTwentyThree(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  996. PulseFrequencyOne, _ := strconv.ParseFloat(lastRecord.PulseFrequencyOne, 64)
  997. afterevaluation.PulseFrequency = PulseFrequencyOne
  998. }
  999. if afterevaluation.ActualDisplacement == 0 {
  1000. lastRecord, _ := service.GetLastMonitorRecordTwentyFour(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  1001. DisplacementQuantityOne, _ := strconv.ParseFloat(lastRecord.DisplacementQuantityOne, 64)
  1002. afterevaluation.ActualDisplacement = DisplacementQuantityOne
  1003. }
  1004. }
  1005. if adminUserInfo.Org.Id == 10721 {
  1006. afterevaluation.Temperature = 36.5
  1007. }
  1008. err := service.UpdateAssessmentAfterDislysisRecord(&afterevaluation)
  1009. //记录日志
  1010. byterequest, _ := json.Marshal(afterevaluation)
  1011. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1012. UserOrgId: afterevaluation.UserOrgId,
  1013. PatientId: afterevaluation.PatientId,
  1014. RecordDate: afterevaluation.AssessmentDate,
  1015. Status: 1,
  1016. ErrLog: string(byterequest),
  1017. AdminUserId: adminUserInfo.AdminUser.Id,
  1018. Ctime: time.Now().Unix(),
  1019. Mtime: 0,
  1020. Source: "物联网称重",
  1021. }
  1022. service.CreateAfterDialysisLog(afterDialysisLog)
  1023. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_after_dislysis"
  1024. redis := service.RedisClient()
  1025. //清空key 值
  1026. redis.Set(key, "", time.Second)
  1027. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_after_dislysis_list_all"
  1028. redis.Set(keyThree, "", time.Second)
  1029. assessdateDateStart := thisTime.Format("2006-01-02")
  1030. keyTwo := "scheduals_" + assessdateDateStart + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1031. redis.Set(keyTwo, "", time.Second)
  1032. redis.Close()
  1033. if err == nil {
  1034. c.ServeSuccessJSON(map[string]interface{}{
  1035. "assessmentAfterDislysis": afterevaluation,
  1036. })
  1037. }
  1038. }
  1039. }
  1040. func (c *CheckWeightApiController) SetSyncTime() {
  1041. sn := c.GetString("sn")
  1042. if len(sn) > 0 {
  1043. redis := service.RedisClient()
  1044. defer redis.Close()
  1045. redis.Set(sn, 0, 0)
  1046. }
  1047. serviceTime := time.Now().Unix()
  1048. c.ServeSuccessJSON(map[string]interface{}{
  1049. "status": 1,
  1050. "servicetime": serviceTime,
  1051. })
  1052. }
  1053. func (c *CheckWeightApiController) GetPatientList() {
  1054. ftype, _ := c.GetInt64("type", 0)
  1055. sn := c.GetString("sn")
  1056. syncTime := int64(0)
  1057. redis := service.RedisClient()
  1058. defer redis.Close()
  1059. if len(sn) > 0 {
  1060. syncTimeStr, _ := redis.Get(sn).Result()
  1061. syncTime, _ = strconv.ParseInt(syncTimeStr, 10, 64)
  1062. }
  1063. if ftype == 1 {
  1064. timeNow := time.Now().Unix()
  1065. redis.Set(sn, timeNow, 0)
  1066. }
  1067. adminUserInfo := c.GetMobileAdminUserInfo()
  1068. patientList, total, error := service.GetPatientListByUpdateTime(adminUserInfo.Org.Id, int64(syncTime))
  1069. need_update := 0
  1070. if syncTime == 0 {
  1071. need_update = 1
  1072. }
  1073. if error != nil {
  1074. c.ErrorLog("获取病人列表失败:%v", error)
  1075. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1076. return
  1077. }
  1078. serviceTime := time.Now().Unix()
  1079. c.ServeSuccessJSON(map[string]interface{}{
  1080. "need_update": need_update,
  1081. "patientlist": patientList,
  1082. "total": total,
  1083. "servicetime": serviceTime,
  1084. })
  1085. }
  1086. func (c *CheckWeightApiController) GetPatientListForSchedules() {
  1087. thisTime := time.Now()
  1088. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  1089. timeLayout := "2006-01-02 15:04:05"
  1090. loc, _ := time.LoadLocation("Local")
  1091. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  1092. syncTime := theStartTime.Unix()
  1093. adminUserInfo := c.GetMobileAdminUserInfo()
  1094. patientList, total, error := service.GetPatientListBySchedules(adminUserInfo.Org.Id, syncTime)
  1095. patientSchedule := make([]map[string]interface{}, 0)
  1096. for _, item := range patientList {
  1097. patientTemp := make(map[string]interface{})
  1098. patientTemp["patient_id"] = item.PatientId
  1099. patientTemp["patient_name"] = item.Patient.Name
  1100. patientTemp["schedule_type"] = item.ScheduleType
  1101. patientSchedule = append(patientSchedule, patientTemp)
  1102. }
  1103. if error != nil {
  1104. c.ErrorLog("获取病人列表失败:%v", error)
  1105. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1106. return
  1107. }
  1108. serviceTime := time.Now().Unix()
  1109. c.ServeSuccessJSON(map[string]interface{}{
  1110. "patientlist": patientSchedule,
  1111. "total": total,
  1112. "servicetime": serviceTime,
  1113. })
  1114. }
  1115. func (c *CheckWeightApiController) GetPatientListForSchedulesFind() {
  1116. patient_name := c.GetString("patient_name") //脉率
  1117. thisTime := time.Now()
  1118. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  1119. timeLayout := "2006-01-02 15:04:05"
  1120. loc, _ := time.LoadLocation("Local")
  1121. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  1122. syncTime := theStartTime.Unix()
  1123. adminUserInfo := c.GetMobileAdminUserInfo()
  1124. if len(patient_name) == 0 {
  1125. patientList, total, error := service.GetPatientListBySchedules(adminUserInfo.Org.Id, syncTime)
  1126. patientSchedule := make([]map[string]interface{}, 0)
  1127. for _, item := range patientList {
  1128. patientTemp := make(map[string]interface{})
  1129. patientTemp["patient_id"] = item.PatientId
  1130. patientTemp["patient_name"] = item.Patient.Name
  1131. patientTemp["schedule_type"] = item.ScheduleType
  1132. patientSchedule = append(patientSchedule, patientTemp)
  1133. }
  1134. if error != nil {
  1135. c.ErrorLog("获取病人列表失败:%v", error)
  1136. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1137. return
  1138. }
  1139. serviceTime := time.Now().Unix()
  1140. c.ServeSuccessJSON(map[string]interface{}{
  1141. "patientlist": patientSchedule,
  1142. "total": total,
  1143. "servicetime": serviceTime,
  1144. })
  1145. } else {
  1146. patientList, total, error := service.GetPatientListBySchedulesFind(adminUserInfo.Org.Id, syncTime, patient_name)
  1147. patientSchedule := make([]map[string]interface{}, 0)
  1148. for _, item := range patientList {
  1149. if item.Patient.ID > 0 {
  1150. patientTemp := make(map[string]interface{})
  1151. patientTemp["patient_id"] = item.PatientId
  1152. patientTemp["patient_name"] = item.Patient.Name
  1153. patientTemp["schedule_type"] = item.ScheduleType
  1154. patientSchedule = append(patientSchedule, patientTemp)
  1155. }
  1156. }
  1157. if error != nil {
  1158. c.ErrorLog("获取病人列表失败:%v", error)
  1159. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1160. return
  1161. }
  1162. serviceTime := time.Now().Unix()
  1163. c.ServeSuccessJSON(map[string]interface{}{
  1164. "patientlist": patientSchedule,
  1165. "total": total,
  1166. "servicetime": serviceTime,
  1167. })
  1168. }
  1169. }
  1170. func (c *CheckWeightApiController) GetPatientListById() {
  1171. patientId, _ := c.GetInt64("patient_id", 0)
  1172. if patientId <= 0 {
  1173. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1174. return
  1175. }
  1176. adminUserInfo := c.GetMobileAdminUserInfo()
  1177. patient, error := service.GetPatientListById(adminUserInfo.Org.Id, patientId)
  1178. if error != nil {
  1179. c.ErrorLog("获取病人详情失败:%v", error)
  1180. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1181. return
  1182. }
  1183. c.ServeSuccessJSON(map[string]interface{}{
  1184. "patientinfo": patient,
  1185. })
  1186. }
  1187. func (c *CheckWeightApiController) GetPatientInfoDialysis() {
  1188. id, _ := c.GetInt64("patient", 0)
  1189. if id <= 0 {
  1190. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1191. return
  1192. }
  1193. adminUserInfo := c.GetMobileAdminUserInfo()
  1194. patient, _ := service.FindPatientByIdWithDiseases(adminUserInfo.Org.Id, id)
  1195. if patient.ID <= 0 {
  1196. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1197. return
  1198. }
  1199. var dialysisinfo map[string]interface{}
  1200. dialysisinfo = make(map[string]interface{})
  1201. dialysisinfo["id"] = patient.ID
  1202. dialysisinfo["name"] = patient.Name
  1203. dialysisinfo["dialysis_no"] = patient.DialysisNo
  1204. thisTime := time.Now()
  1205. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  1206. scheduleDateEnd := thisTime.Format("2006-01-02") + " 23:59:59"
  1207. timeLayout := "2006-01-02 15:04:05"
  1208. loc, _ := time.LoadLocation("Local")
  1209. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  1210. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  1211. startTime := theStartTime.Unix()
  1212. endTime := theEndTime.Unix()
  1213. // 判断当前用户是透析前还是透析后
  1214. var dialysistype int
  1215. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, startTime)
  1216. if dialysisOrder == nil {
  1217. dialysistype = 1
  1218. } else {
  1219. dialysistype = 2
  1220. }
  1221. // 获取当前或者下次排班信息
  1222. var sc map[string]interface{}
  1223. sc = make(map[string]interface{})
  1224. if dialysistype == 1 {
  1225. daySchedule, _ := service.GetPatientScheduleFormDay(adminUserInfo.Org.Id, startTime, endTime, id)
  1226. if len(daySchedule) <= 0 {
  1227. sc["code"] = 1
  1228. sc["msg"] = "抱歉,您今天没有排版!"
  1229. sc["mode"] = 0
  1230. sc["data"] = daySchedule
  1231. } else {
  1232. if daySchedule[0].Schedule.ID > 0 {
  1233. sc["code"] = 0
  1234. sc["msg"] = ""
  1235. var mode = "HD"
  1236. if daySchedule[0].Schedule.ModeId == 1 {
  1237. mode = "HD"
  1238. }
  1239. if daySchedule[0].Schedule.ModeId == 2 {
  1240. mode = "HDF"
  1241. }
  1242. if daySchedule[0].Schedule.ModeId == 3 {
  1243. mode = "HD+HP"
  1244. }
  1245. if daySchedule[0].Schedule.ModeId == 4 {
  1246. mode = "HP"
  1247. }
  1248. if daySchedule[0].Schedule.ModeId == 5 {
  1249. mode = "HF"
  1250. }
  1251. if daySchedule[0].Schedule.ModeId == 6 {
  1252. mode = "SCUF"
  1253. }
  1254. if daySchedule[0].Schedule.ModeId == 7 {
  1255. mode = "IUF"
  1256. }
  1257. if daySchedule[0].Schedule.ModeId == 8 {
  1258. mode = "HFHD"
  1259. }
  1260. if daySchedule[0].Schedule.ModeId == 9 {
  1261. mode = "HFHD+HP"
  1262. }
  1263. if daySchedule[0].Schedule.ModeId == 10 {
  1264. mode = "PHF"
  1265. }
  1266. if daySchedule[0].Schedule.ModeId == 11 {
  1267. mode = "HFR"
  1268. }
  1269. if daySchedule[0].Schedule.ModeId == 12 {
  1270. mode = "HDF+HP"
  1271. }
  1272. if daySchedule[0].Schedule.ModeId == 13 {
  1273. mode = "CRRT"
  1274. }
  1275. if daySchedule[0].Schedule.ModeId == 14 {
  1276. mode = "腹水回输"
  1277. }
  1278. if daySchedule[0].Schedule.ModeId == 19 {
  1279. mode = "IUF+HD"
  1280. }
  1281. if daySchedule[0].Schedule.ModeId == 20 {
  1282. mode = "UF"
  1283. }
  1284. if daySchedule[0].Schedule.ModeId == 21 {
  1285. mode = "HD+"
  1286. }
  1287. if daySchedule[0].Schedule.ModeId == 22 {
  1288. mode = "血浆胆红素吸附+HDF"
  1289. }
  1290. if daySchedule[0].Schedule.ModeId == 23 {
  1291. mode = "血浆胆红素吸附"
  1292. }
  1293. if daySchedule[0].Schedule.ModeId == 24 {
  1294. mode = "I-HDF"
  1295. }
  1296. if daySchedule[0].Schedule.ModeId == 25 {
  1297. mode = "HD高通"
  1298. }
  1299. if daySchedule[0].Schedule.ModeId == 26 {
  1300. mode = "CVVH"
  1301. }
  1302. if daySchedule[0].Schedule.ModeId == 27 {
  1303. mode = "CVVHD"
  1304. }
  1305. if daySchedule[0].Schedule.ModeId == 28 {
  1306. mode = "CVVHDF"
  1307. }
  1308. if daySchedule[0].Schedule.ModeId == 29 {
  1309. mode = "PE"
  1310. }
  1311. if daySchedule[0].Schedule.ModeId == 30 {
  1312. mode = "血浆胆红素吸附+HP"
  1313. }
  1314. if daySchedule[0].Schedule.ModeId == 31 {
  1315. mode = "HPD"
  1316. }
  1317. if daySchedule[0].Schedule.ModeId == 32 {
  1318. mode = "HDP"
  1319. }
  1320. if daySchedule[0].Schedule.ModeId == 33 {
  1321. mode = "HFD"
  1322. }
  1323. if daySchedule[0].Schedule.ModeId == 34 {
  1324. mode = "HDF100"
  1325. }
  1326. if daySchedule[0].Schedule.ModeId == 35 {
  1327. mode = "HDF600"
  1328. }
  1329. if daySchedule[0].Schedule.ModeId == 36 {
  1330. mode = "HDF800"
  1331. }
  1332. if daySchedule[0].Schedule.ModeId == 37 {
  1333. mode = "HDF1000"
  1334. }
  1335. sc["mode"] = mode
  1336. sc["data"] = daySchedule
  1337. } else {
  1338. sc["code"] = 1
  1339. sc["msg"] = "抱歉,您今天没有排版!"
  1340. sc["mode"] = "HD"
  1341. sc["data"] = daySchedule
  1342. }
  1343. }
  1344. // 排队叫号的签到
  1345. go func() {
  1346. ssoDomain := beego.AppConfig.String("call_domain")
  1347. api := ssoDomain + "/index/patientsign/" + strconv.FormatInt(adminUserInfo.Org.Id, 10) + "/" + strconv.FormatInt(id, 10)
  1348. values := make(url.Values)
  1349. http.PostForm(api, values)
  1350. }()
  1351. } else {
  1352. nextSchedule, _ := service.GetNextSchedule(adminUserInfo.Org.Id, endTime, id)
  1353. if len(nextSchedule) <= 0 {
  1354. sc["code"] = 1
  1355. sc["msg"] = "抱歉,您后续没有排版!"
  1356. sc["mode"] = "HD"
  1357. sc["data"] = nextSchedule
  1358. } else {
  1359. if nextSchedule[0].Schedule.ID > 0 {
  1360. sc["code"] = 0
  1361. sc["msg"] = ""
  1362. var mode = "HD"
  1363. if nextSchedule[0].Schedule.ModeId == 1 {
  1364. mode = "HD"
  1365. }
  1366. if nextSchedule[0].Schedule.ModeId == 2 {
  1367. mode = "HDF"
  1368. }
  1369. if nextSchedule[0].Schedule.ModeId == 3 {
  1370. mode = "HD+HP"
  1371. }
  1372. if nextSchedule[0].Schedule.ModeId == 4 {
  1373. mode = "HP"
  1374. }
  1375. if nextSchedule[0].Schedule.ModeId == 5 {
  1376. mode = "HF"
  1377. }
  1378. if nextSchedule[0].Schedule.ModeId == 6 {
  1379. mode = "SCUF"
  1380. }
  1381. if nextSchedule[0].Schedule.ModeId == 7 {
  1382. mode = "IUF"
  1383. }
  1384. if nextSchedule[0].Schedule.ModeId == 8 {
  1385. mode = "HFHD"
  1386. }
  1387. if nextSchedule[0].Schedule.ModeId == 9 {
  1388. mode = "HFHD+HP"
  1389. }
  1390. if nextSchedule[0].Schedule.ModeId == 10 {
  1391. mode = "PHF"
  1392. }
  1393. if nextSchedule[0].Schedule.ModeId == 11 {
  1394. mode = "HFR"
  1395. }
  1396. if nextSchedule[0].Schedule.ModeId == 12 {
  1397. mode = "HDF+HP"
  1398. }
  1399. if nextSchedule[0].Schedule.ModeId == 13 {
  1400. mode = "CRRT"
  1401. }
  1402. if nextSchedule[0].Schedule.ModeId == 14 {
  1403. mode = "腹水回输"
  1404. }
  1405. if nextSchedule[0].Schedule.ModeId == 19 {
  1406. mode = "IUF+HD"
  1407. }
  1408. if nextSchedule[0].Schedule.ModeId == 20 {
  1409. mode = "UF"
  1410. }
  1411. if nextSchedule[0].Schedule.ModeId == 21 {
  1412. mode = "HD+"
  1413. }
  1414. if nextSchedule[0].Schedule.ModeId == 22 {
  1415. mode = "血浆胆红素吸附+HDF"
  1416. }
  1417. if nextSchedule[0].Schedule.ModeId == 23 {
  1418. mode = "血浆胆红素吸附"
  1419. }
  1420. if nextSchedule[0].Schedule.ModeId == 24 {
  1421. mode = "I-HDF"
  1422. }
  1423. if nextSchedule[0].Schedule.ModeId == 25 {
  1424. mode = "HD高通"
  1425. }
  1426. if nextSchedule[0].Schedule.ModeId == 26 {
  1427. mode = "CVVH"
  1428. }
  1429. if nextSchedule[0].Schedule.ModeId == 27 {
  1430. mode = "CVVHD"
  1431. }
  1432. if nextSchedule[0].Schedule.ModeId == 28 {
  1433. mode = "CVVHDF"
  1434. }
  1435. if nextSchedule[0].Schedule.ModeId == 29 {
  1436. mode = "PE"
  1437. }
  1438. if nextSchedule[0].Schedule.ModeId == 30 {
  1439. mode = "血浆胆红素吸附+HP"
  1440. }
  1441. if nextSchedule[0].Schedule.ModeId == 31 {
  1442. mode = "HPD"
  1443. }
  1444. if nextSchedule[0].Schedule.ModeId == 32 {
  1445. mode = "HDP"
  1446. }
  1447. if nextSchedule[0].Schedule.ModeId == 33 {
  1448. mode = "HFD"
  1449. }
  1450. if nextSchedule[0].Schedule.ModeId == 34 {
  1451. mode = "HDF100"
  1452. }
  1453. if nextSchedule[0].Schedule.ModeId == 35 {
  1454. mode = "HDF600"
  1455. }
  1456. if nextSchedule[0].Schedule.ModeId == 36 {
  1457. mode = "HDF800"
  1458. }
  1459. if nextSchedule[0].Schedule.ModeId == 37 {
  1460. mode = "HDF1000"
  1461. }
  1462. sc["mode"] = mode
  1463. sc["data"] = nextSchedule
  1464. } else {
  1465. sc["code"] = 1
  1466. sc["msg"] = "抱歉,您后续没有排版!"
  1467. sc["mode"] = "HD"
  1468. sc["data"] = nextSchedule
  1469. }
  1470. }
  1471. }
  1472. //switch sc["mode"] {
  1473. //case 1:
  1474. // sc["mode"] = "HD"
  1475. // break
  1476. //case 2:
  1477. // sc["mode"] = "HDF"
  1478. // break
  1479. //case 3:
  1480. // sc["mode"] = "HD+HP"
  1481. // break
  1482. //case 4:
  1483. // sc["mode"] = "HP"
  1484. // break
  1485. //case 5:
  1486. // sc["mode"] = "HF"
  1487. // break
  1488. //case 6:
  1489. // sc["mode"] = "SCUF"
  1490. // break
  1491. //case 7:
  1492. // sc["mode"] = "IUF"
  1493. // break
  1494. //case 8:
  1495. // sc["mode"] = "HFHD"
  1496. // break
  1497. //case 9:
  1498. // sc["mode"] = "HFHD+HP"
  1499. // break
  1500. //case 10:
  1501. // sc["mode"] = "PHF"
  1502. // break
  1503. //case 11:
  1504. // sc["mode"] = "HFR"
  1505. // break
  1506. //case 12:
  1507. // sc["mode"] = "HDF+HP"
  1508. // break
  1509. //case 13:
  1510. // sc["mode"] = "CRRT"
  1511. // break
  1512. //case 14:
  1513. // sc["mode"] = "腹水回输"
  1514. // break
  1515. //case 15:
  1516. // sc["mode"] = "HD前置换"
  1517. // break
  1518. //case 16:
  1519. // sc["mode"] = "HD后置换"
  1520. // break
  1521. //case 17:
  1522. // sc["mode"] = "HDF前置换"
  1523. // break
  1524. //case 18:
  1525. // sc["mode"] = "HDF后置换"
  1526. // break
  1527. //default:
  1528. // sc["mode"] = "HD"
  1529. // break
  1530. //}
  1531. // 获取患者透前干体重或者获取患者透前体重
  1532. var dry_weight map[string]interface{}
  1533. dry_weight = make(map[string]interface{})
  1534. var after_dry_weight map[string]interface{}
  1535. after_dry_weight = make(map[string]interface{})
  1536. if dialysistype == 1 {
  1537. lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminUserInfo.Org.Id, id, endTime)
  1538. weight, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, id)
  1539. if err == gorm.ErrRecordNotFound {
  1540. if getLPEErr != nil {
  1541. dry_weight["code"] = 1
  1542. dry_weight["dry_weight"] = nil
  1543. } else {
  1544. if lastPredialysisEvaluation == nil {
  1545. dry_weight["code"] = 1
  1546. dry_weight["dry_weight"] = nil
  1547. } else {
  1548. // 传输的干体重实际为干体重加上衣服重
  1549. dry_weight["code"] = 0
  1550. dry_weight["dry_weight"] = lastPredialysisEvaluation.DryWeight + lastPredialysisEvaluation.AdditionalWeight
  1551. }
  1552. }
  1553. } else {
  1554. if err != nil {
  1555. dry_weight["code"] = 1
  1556. dry_weight["dry_weight"] = nil
  1557. } else {
  1558. dry_weight["code"] = 0
  1559. if getLPEErr != nil {
  1560. dry_weight["code"] = 0
  1561. dry_weight["dry_weight"] = weight.DryWeight
  1562. } else {
  1563. if lastPredialysisEvaluation == nil {
  1564. dry_weight["code"] = 1
  1565. dry_weight["dry_weight"] = weight.DryWeight
  1566. } else {
  1567. // 传输的干体重实际为干体重加上衣服重
  1568. dry_weight["code"] = 0
  1569. dry_weight["dry_weight"] = weight.DryWeight + lastPredialysisEvaluation.AdditionalWeight
  1570. }
  1571. }
  1572. }
  1573. }
  1574. } else {
  1575. predialysisEvaluation, getPEErr := service.MobileGetPredialysisEvaluation(adminUserInfo.Org.Id, id, startTime)
  1576. if getPEErr != nil {
  1577. dry_weight["code"] = 1
  1578. dry_weight["dry_weight"] = nil
  1579. } else {
  1580. if predialysisEvaluation == nil {
  1581. dry_weight["code"] = 1
  1582. dry_weight["dry_weight"] = nil
  1583. } else {
  1584. dry_weight["code"] = 0
  1585. dry_weight["dry_weight"] = predialysisEvaluation.WeightBefore
  1586. }
  1587. }
  1588. lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminUserInfo.Org.Id, id, endTime)
  1589. weight, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, id)
  1590. if err == gorm.ErrRecordNotFound {
  1591. if getLPEErr != nil {
  1592. after_dry_weight["code"] = 1
  1593. after_dry_weight["dry_weight"] = nil
  1594. } else {
  1595. if lastPredialysisEvaluation == nil {
  1596. after_dry_weight["code"] = 1
  1597. after_dry_weight["dry_weight"] = nil
  1598. } else {
  1599. // 传输的干体重实际为干体重加上衣服重
  1600. after_dry_weight["code"] = 0
  1601. after_dry_weight["dry_weight"] = lastPredialysisEvaluation.DryWeight + lastPredialysisEvaluation.AdditionalWeight
  1602. }
  1603. }
  1604. } else {
  1605. if err != nil {
  1606. after_dry_weight["code"] = 1
  1607. after_dry_weight["dry_weight"] = nil
  1608. } else {
  1609. after_dry_weight["code"] = 0
  1610. if getLPEErr != nil {
  1611. after_dry_weight["code"] = 0
  1612. after_dry_weight["dry_weight"] = weight.DryWeight
  1613. } else {
  1614. if lastPredialysisEvaluation == nil {
  1615. after_dry_weight["code"] = 1
  1616. after_dry_weight["dry_weight"] = weight.DryWeight
  1617. } else {
  1618. // 传输的干体重实际为干体重加上衣服重
  1619. after_dry_weight["code"] = 0
  1620. after_dry_weight["dry_weight"] = weight.DryWeight + lastPredialysisEvaluation.AdditionalWeight
  1621. }
  1622. }
  1623. }
  1624. }
  1625. }
  1626. c.ServeSuccessJSON(map[string]interface{}{
  1627. "dialysistype": dialysistype,
  1628. "patient": dialysisinfo,
  1629. "schedule": sc,
  1630. "dryweight": dry_weight,
  1631. "after_dry_weight": after_dry_weight,
  1632. })
  1633. return
  1634. }
  1635. func (c *CheckWeightApiController) GetPatientInfoBeforeDialysis() {
  1636. id, _ := c.GetInt64("patient", 0)
  1637. if id <= 0 {
  1638. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1639. return
  1640. }
  1641. adminUserInfo := c.GetMobileAdminUserInfo()
  1642. patient, _ := service.FindPatientByIdWithDiseases(adminUserInfo.Org.Id, id)
  1643. if patient.ID == 0 {
  1644. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1645. return
  1646. }
  1647. var dialysisinfo map[string]interface{}
  1648. dialysisinfo = make(map[string]interface{})
  1649. dialysisinfo["id"] = patient.ID
  1650. dialysisinfo["name"] = patient.Name
  1651. dialysisinfo["dialysis_no"] = patient.DialysisNo
  1652. thisTime := time.Now()
  1653. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  1654. scheduleDateEnd := thisTime.Format("2006-01-02") + " 23:59:59"
  1655. fmt.Println(scheduleDateStart, scheduleDateEnd)
  1656. timeLayout := "2006-01-02 15:04:05"
  1657. loc, _ := time.LoadLocation("Local")
  1658. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  1659. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  1660. fmt.Println(theStartTime, theEndTime)
  1661. startTime := theStartTime.Unix()
  1662. endTime := theEndTime.Unix()
  1663. var sc map[string]interface{}
  1664. sc = make(map[string]interface{})
  1665. //一天只有排班一次
  1666. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, startTime, endTime, id)
  1667. if daySchedule.ID > 0 {
  1668. switch daySchedule.ModeId {
  1669. case 1:
  1670. sc["mode"] = "HD"
  1671. case 2:
  1672. sc["mode"] = "HDF"
  1673. case 3:
  1674. sc["mode"] = "HD+HP"
  1675. case 4:
  1676. sc["mode"] = "HP"
  1677. case 5:
  1678. sc["mode"] = "HF"
  1679. case 6:
  1680. sc["mode"] = "SCUF"
  1681. case 7:
  1682. sc["mode"] = "IUF"
  1683. case 8:
  1684. sc["mode"] = "HFHD"
  1685. case 9:
  1686. sc["mode"] = "HFHD+HP"
  1687. case 10:
  1688. sc["mode"] = "PHF"
  1689. case 11:
  1690. sc["mode"] = "HFR"
  1691. case 12:
  1692. sc["mode"] = "HDF+HP"
  1693. case 13:
  1694. sc["mode"] = "CRRT"
  1695. case 14:
  1696. sc["mode"] = "腹水回输"
  1697. case 15:
  1698. sc["mode"] = "HD前置换"
  1699. case 16:
  1700. sc["mode"] = "HD后置换"
  1701. case 17:
  1702. sc["mode"] = "HDF前置换"
  1703. case 18:
  1704. sc["mode"] = "HDF后置换"
  1705. default:
  1706. sc["mode"] = "HD"
  1707. }
  1708. sc["code"] = 0
  1709. sc["msg"] = ""
  1710. sc["data"] = daySchedule
  1711. } else {
  1712. sc["code"] = 1
  1713. sc["msg"] = "抱歉,您今天没有排版!"
  1714. sc["mode"] = ""
  1715. sc["data"] = daySchedule
  1716. }
  1717. fmt.Println(sc)
  1718. type dryWeight struct {
  1719. code int
  1720. dry_weight float64
  1721. }
  1722. var dry_weight map[string]interface{}
  1723. dry_weight = make(map[string]interface{})
  1724. lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminUserInfo.Org.Id, id, startTime)
  1725. if getLPEErr != nil {
  1726. dry_weight["code"] = 1
  1727. dry_weight["dry_weight"] = nil
  1728. } else {
  1729. if lastPredialysisEvaluation == nil {
  1730. dry_weight["code"] = 1
  1731. dry_weight["dry_weight"] = nil
  1732. } else {
  1733. dry_weight["code"] = 0
  1734. dry_weight["dry_weight"] = lastPredialysisEvaluation.DryWeight
  1735. }
  1736. }
  1737. c.ServeSuccessJSON(map[string]interface{}{
  1738. "patient": dialysisinfo,
  1739. "schedule": sc,
  1740. "dryweight": dry_weight,
  1741. })
  1742. return
  1743. }