check_weight_api_controller.go 70KB

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