check_weight_api_controller.go 71KB

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