check_weight_api_controller.go 64KB

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