sign_weigh_api_controller.go 47KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "reflect"
  6. "strconv"
  7. "time"
  8. "XT_New/enums"
  9. "XT_New/models"
  10. "XT_New/service"
  11. "github.com/astaxie/beego"
  12. "github.com/jinzhu/gorm"
  13. )
  14. func SignWeighAPIControllerRegistRouters() {
  15. beego.Router("/api/sign/patients", &SignWeighAPIController{}, "Get:GetPatients")
  16. beego.Router("/api/sign/patientsign", &SignWeighAPIController{}, "Get:GetPatientSign")
  17. beego.Router("/api/signweign", &SignWeighAPIController{}, "Post:EditPatientSign")
  18. beego.Router("/api/sign/getDialysisInforInfomation", &SignWeighAPIController{}, "Get:GetPatientList")
  19. beego.Router("/api/sign/getDialysisAfterInfomation", &SignWeighAPIController{}, "Get:GetInforByPatientId")
  20. beego.Router("/api/sign/savaData", &SignWeighAPIController{}, "Post:SaveData")
  21. beego.Router("/api/sign/editdata", &SignWeighAPIController{}, "Post:EditData")
  22. beego.Router("/api/sigh/sighdata", &SignWeighAPIController{}, "Post:Sighdata")
  23. beego.Router("/api/sign/updateSignweight", &SignWeighAPIController{}, "Post:UpdateSignweight")
  24. }
  25. type SignWeighAPIController struct {
  26. BaseAuthAPIController
  27. }
  28. // /api/sign/patients [get]
  29. func (c *SignWeighAPIController) GetPatients() {
  30. keywrods := c.GetString("keywords")
  31. scheduleType, _ := c.GetInt64("schedule_type", 0)
  32. needScheduleType, _ := c.GetInt64("need_schedule_type", 0)
  33. nowDateTime := time.Now()
  34. nowDate := nowDateTime.Format("2006-01-02")
  35. today := nowDate
  36. nowDate += " 00:00:00"
  37. //认为没有选择{0:'全部',1:'上午',2:'下午'3:'晚上' }中的一个
  38. if scheduleType < 0 || scheduleType > 3 {
  39. nowH := nowDateTime.Hour()
  40. if nowH < 12 {
  41. scheduleType = 1
  42. } else if nowH < 18 {
  43. scheduleType = 2
  44. } else {
  45. scheduleType = 3
  46. }
  47. }
  48. timeLayout := "2006-01-02"
  49. loc, _ := time.LoadLocation("Local")
  50. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", nowDate, loc)
  51. if err != nil {
  52. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  53. return
  54. }
  55. dateTime := theTime.Unix()
  56. fmt.Println("dataTime是多少", dateTime)
  57. adminUserInfo := c.GetAdminUserInfo()
  58. patients, err := service.GetSignPatients(adminUserInfo.CurrentOrgId, keywrods, dateTime, scheduleType)
  59. fmt.Println("病人信息", patients)
  60. if err != nil {
  61. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  62. return
  63. }
  64. panel := make(map[int64]map[string]int64, 0)
  65. if needScheduleType == 1 {
  66. panel, _ = service.GetSignPanels(adminUserInfo.CurrentOrgId, dateTime)
  67. fmt.Println("panel是什么", panel)
  68. }
  69. c.ServeSuccessJSON(map[string]interface{}{
  70. "patients": patients,
  71. "today": today,
  72. "schedule_type": scheduleType,
  73. "panel": panel,
  74. })
  75. return
  76. }
  77. func (c *SignWeighAPIController) GetPatientSign() {
  78. patientID, _ := c.GetInt64("patient_id", 0)
  79. dateTime := c.GetString("date_time")
  80. timeLayout := "2006-01-02"
  81. loc, _ := time.LoadLocation("Local")
  82. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", dateTime+" 00:00:00", loc)
  83. if err != nil {
  84. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  85. return
  86. }
  87. dateTimeStam := theTime.Unix()
  88. adminUserInfo := c.GetAdminUserInfo()
  89. sign, err := service.GetPatientDateSign(adminUserInfo.CurrentOrgId, dateTimeStam, patientID)
  90. if err != nil {
  91. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  92. return
  93. }
  94. c.ServeSuccessJSON(map[string]interface{}{
  95. "sign": sign,
  96. })
  97. return
  98. }
  99. func (c *SignWeighAPIController) EditPatientSign() {
  100. patientID, _ := c.GetInt64("patient_id", 0)
  101. dateTime := c.GetString("date_time")
  102. timeLayout := "2006-01-02"
  103. loc, _ := time.LoadLocation("Local")
  104. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", dateTime+" 00:00:00", loc)
  105. if err != nil {
  106. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  107. return
  108. }
  109. dateTimeStam := theTime.Unix()
  110. adminUserInfo := c.GetAdminUserInfo()
  111. sign, err := service.GetPatientDateSign(adminUserInfo.CurrentOrgId, dateTimeStam, patientID)
  112. if err != nil {
  113. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  114. return
  115. }
  116. var signForm models.SigninAndWeigh
  117. if sign != nil {
  118. signForm = *sign
  119. signForm.UpdatedTime = time.Now().Unix()
  120. } else {
  121. signForm.PatientId = patientID
  122. signForm.RecordDate = dateTimeStam
  123. signForm.UserOrgId = adminUserInfo.CurrentOrgId
  124. signForm.SignTime = time.Now().Unix()
  125. signForm.Status = 1
  126. signForm.CreatedTime = time.Now().Unix()
  127. signForm.UpdatedTime = time.Now().Unix()
  128. }
  129. signData := make(map[string]interface{}, 0)
  130. err = json.Unmarshal(c.Ctx.Input.RequestBody, &signData)
  131. if err != nil {
  132. //utils.ErrorLog(err.Error())
  133. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamFormatWrong)
  134. }
  135. if signData["dry_weight"] == nil || reflect.TypeOf(signData["dry_weight"]).String() != "string" {
  136. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  137. return
  138. }
  139. dryWeight, _ := strconv.ParseFloat(signData["dry_weight"].(string), 64)
  140. signForm.DryWeight = dryWeight
  141. if signData["clothes_weight"] == nil || reflect.TypeOf(signData["clothes_weight"]).String() != "string" {
  142. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  143. return
  144. }
  145. clothesWeight, _ := strconv.ParseFloat(signData["clothes_weight"].(string), 64)
  146. signForm.ClothingWeight = clothesWeight
  147. if signData["weigh_before"] == nil || reflect.TypeOf(signData["weigh_before"]).String() != "string" {
  148. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  149. return
  150. }
  151. weighBefore, _ := strconv.ParseFloat(signData["weigh_before"].(string), 64)
  152. signForm.WeighingBefore = weighBefore
  153. if signData["dehydrated_weight"] == nil || reflect.TypeOf(signData["dehydrated_weight"]).String() != "string" {
  154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  155. return
  156. }
  157. dehydratedWeight, _ := strconv.ParseFloat(signData["dehydrated_weight"].(string), 64)
  158. signForm.TargetDewatering = dehydratedWeight
  159. if signData["weight_before"] == nil || reflect.TypeOf(signData["weight_before"]).String() != "string" {
  160. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  161. return
  162. }
  163. weightBefore, _ := strconv.ParseFloat(signData["weight_before"].(string), 64)
  164. signForm.WeightBefore = weightBefore
  165. if signData["temperature_before"] == nil || reflect.TypeOf(signData["temperature_before"]).String() != "string" {
  166. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  167. return
  168. }
  169. temperatureBefore, _ := strconv.ParseFloat(signData["temperature_before"].(string), 64)
  170. signForm.TemperatureBefore = temperatureBefore
  171. if signData["pulse_rate_before"] == nil || reflect.TypeOf(signData["pulse_rate_before"]).String() != "string" {
  172. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  173. return
  174. }
  175. pulseRateBefore, _ := strconv.ParseFloat(signData["pulse_rate_before"].(string), 64)
  176. signForm.PulseFrequencyBefore = pulseRateBefore
  177. if signData["respiratory_rate_before"] == nil || reflect.TypeOf(signData["respiratory_rate_before"]).String() != "string" {
  178. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  179. return
  180. }
  181. respiratoryRateBefore, _ := strconv.ParseFloat(signData["respiratory_rate_before"].(string), 64)
  182. signForm.BreathingRateBefore = respiratoryRateBefore
  183. if signData["DBP_before"] == nil || reflect.TypeOf(signData["DBP_before"]).String() != "string" {
  184. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  185. return
  186. }
  187. DBPBefore, _ := strconv.ParseFloat(signData["DBP_before"].(string), 64)
  188. signForm.DiastolicBloodPressureBefore = DBPBefore
  189. if signData["SBP_before"] == nil || reflect.TypeOf(signData["SBP_before"]).String() != "string" {
  190. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  191. return
  192. }
  193. SBPBefore, _ := strconv.ParseFloat(signData["SBP_before"].(string), 64)
  194. signForm.SystolicBloodPressureBefore = SBPBefore
  195. if signData["weigh_after"] == nil || reflect.TypeOf(signData["weigh_after"]).String() != "string" {
  196. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  197. return
  198. }
  199. weighAfter, _ := strconv.ParseFloat(signData["weigh_after"].(string), 64)
  200. signForm.WeighingAfter = weighAfter
  201. if signData["weight_reduce_after"] == nil || reflect.TypeOf(signData["weight_reduce_after"]).String() != "string" {
  202. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  203. return
  204. }
  205. weightReduceAfter, _ := strconv.ParseFloat(signData["weight_reduce_after"].(string), 64)
  206. signForm.WeightLoss = weightReduceAfter
  207. if signData["weight_after"] == nil || reflect.TypeOf(signData["weight_after"]).String() != "string" {
  208. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  209. return
  210. }
  211. weightAfter, _ := strconv.ParseFloat(signData["weight_after"].(string), 64)
  212. signForm.WeightAfter = weightAfter
  213. if signData["temperature_after"] == nil || reflect.TypeOf(signData["temperature_after"]).String() != "string" {
  214. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  215. return
  216. }
  217. temperatureAfter, _ := strconv.ParseFloat(signData["temperature_after"].(string), 64)
  218. signForm.TemperatureAfter = temperatureAfter
  219. if signData["pulse_rate_after"] == nil || reflect.TypeOf(signData["pulse_rate_after"]).String() != "string" {
  220. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  221. return
  222. }
  223. pulseRateAfter, _ := strconv.ParseFloat(signData["pulse_rate_after"].(string), 64)
  224. signForm.PulseFrequencyAfter = pulseRateAfter
  225. if signData["respiratory_rate_after"] == nil || reflect.TypeOf(signData["respiratory_rate_after"]).String() != "string" {
  226. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  227. return
  228. }
  229. respiratoryRateAfter, _ := strconv.ParseFloat(signData["respiratory_rate_after"].(string), 64)
  230. signForm.BreathingRateAfter = respiratoryRateAfter
  231. if signData["DBP_after"] == nil || reflect.TypeOf(signData["DBP_after"]).String() != "string" {
  232. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  233. return
  234. }
  235. DBPAfter, _ := strconv.ParseFloat(signData["DBP_after"].(string), 64)
  236. signForm.DiastolicBloodPressureAfter = DBPAfter
  237. if signData["SBP_after"] == nil || reflect.TypeOf(signData["SBP_after"]).String() != "string" {
  238. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  239. return
  240. }
  241. SBPAfter, _ := strconv.ParseFloat(signData["SBP_after"].(string), 64)
  242. signForm.SystolicBloodPressureAfter = SBPAfter
  243. if signForm.WeighingAfter > 0 {
  244. signForm.WeighTime = time.Now().Unix()
  245. }
  246. if signForm.WeighingBefore > 0 {
  247. signForm.WeighBeforeTime = time.Now().Unix()
  248. }
  249. err = service.EditPatientSign(&signForm)
  250. if err != nil {
  251. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  252. return
  253. }
  254. c.ServeSuccessJSON(map[string]interface{}{
  255. "sign": signForm,
  256. })
  257. return
  258. }
  259. func (c *SignWeighAPIController) GetPatientList() {
  260. patientID, _ := c.GetInt64("patient_id", 0)
  261. adminUserInfo := c.GetAdminUserInfo()
  262. nowDateTime := time.Now()
  263. nowDate := nowDateTime.Format("2006-01-02")
  264. nowDate += " 00:00:00"
  265. timeLayout := "2006-01-02"
  266. loc, _ := time.LoadLocation("Local")
  267. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", nowDate, loc)
  268. datetime := theTime.Unix()
  269. list := service.GetPatientInformationList(adminUserInfo.CurrentOrgId, patientID, datetime)
  270. dryWeight, _ := service.GetPatientLastDryWeight(patientID, adminUserInfo.CurrentOrgId)
  271. c.ServeSuccessJSON(map[string]interface{}{
  272. "patientlist": list,
  273. "dryWeight": dryWeight,
  274. })
  275. return
  276. }
  277. func (c *SignWeighAPIController) GetInforByPatientId() {
  278. patientID, _ := c.GetInt64("patient_id", 0)
  279. adminUserInfo := c.GetAdminUserInfo()
  280. nowDateTime := time.Now()
  281. nowDate := nowDateTime.Format("2006-01-02")
  282. nowDate += " 00:00:00"
  283. timeLayout := "2006-01-02"
  284. loc, _ := time.LoadLocation("Local")
  285. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", nowDate, loc)
  286. datetime := theTime.Unix()
  287. patient := service.GetInforByPatient(adminUserInfo.CurrentOrgId, patientID, datetime)
  288. fmt.Println("patient是什么", patient)
  289. c.ServeSuccessJSON(map[string]interface{}{
  290. "patientinfor": patient,
  291. })
  292. }
  293. func (c *SignWeighAPIController) SaveData() {
  294. adminUserInfo := c.GetAdminUserInfo()
  295. orgId := adminUserInfo.CurrentOrgId
  296. patient_id, _ := c.GetInt64("patient_id", 0)
  297. weight_before, _ := c.GetFloat("weight_before", 0)
  298. dry_weight, _ := c.GetFloat("dry_weight", 0)
  299. temperature, _ := c.GetFloat("temperature", 0)
  300. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  301. breathing_rate := c.GetString("breathing_rate")
  302. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  303. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  304. predialysisevaluation := &models.PredialysisEvaluation{
  305. WeightBefore: weight_before,
  306. DryWeight: dry_weight,
  307. Temperature: temperature,
  308. PulseFrequency: pulse_frequency,
  309. BreathingRate: breathing_rate,
  310. SystolicBloodPressure: systolic_blood_pressure,
  311. DiastolicBloodPressure: diastolic_blood_pressure,
  312. }
  313. data := service.SaveData(predialysisevaluation, patient_id, orgId)
  314. c.ServeSuccessJSON(map[string]interface{}{
  315. "params": data,
  316. })
  317. }
  318. func (c *SignWeighAPIController) EditData() {
  319. adminUserInfo := c.GetAdminUserInfo()
  320. orgId := adminUserInfo.CurrentOrgId
  321. patient_id, _ := c.GetInt64("patient_id", 0)
  322. weight_after, _ := c.GetFloat("weight_after", 0)
  323. dry_weight, _ := c.GetFloat("dry_weight", 0)
  324. temperature, _ := c.GetFloat("temperature", 0)
  325. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  326. breathing_rate := c.GetString("breathing_rate")
  327. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  328. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  329. assessmentafterdislysis := &models.AssessmentAfterDislysis{
  330. WeightAfter: weight_after,
  331. DryWeight: dry_weight,
  332. Temperature: temperature,
  333. PulseFrequency: pulse_frequency,
  334. BreathingRate: breathing_rate,
  335. SystolicBloodPressure: systolic_blood_pressure,
  336. DiastolicBloodPressure: diastolic_blood_pressure,
  337. }
  338. editdata := service.Editdata(assessmentafterdislysis, patient_id, orgId)
  339. c.ServeSuccessJSON(map[string]interface{}{
  340. "params": editdata,
  341. })
  342. }
  343. func (c *SignWeighAPIController) Sighdata() {
  344. patientID, _ := c.GetInt64("patient_id", 0)
  345. fmt.Println("patientID", patientID)
  346. dateTime := c.GetString("date_time")
  347. fmt.Println(patientID, dateTime)
  348. timeLayout := "2006-01-02"
  349. loc, _ := time.LoadLocation("Local")
  350. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", dateTime+" 00:00:00", loc)
  351. if err != nil {
  352. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  353. return
  354. }
  355. dateTimeStam := theTime.Unix()
  356. adminUserInfo := c.GetAdminUserInfo()
  357. sign, errord := service.GetSign(adminUserInfo.CurrentOrgId, dateTimeStam, patientID)
  358. fmt.Println("sign", sign)
  359. fmt.Println(err)
  360. weighbefore, _ := c.GetFloat("weight_before", 0)
  361. dryweightbefore, _ := c.GetFloat("dry_weight", 0)
  362. temperaturebefore, _ := c.GetFloat("temperature", 0)
  363. pulsefrequencybefore, _ := c.GetFloat("pulse_frequency", 0)
  364. breathinratebefore, _ := c.GetFloat("breathing_rate", 0)
  365. systolicbloodpressurebefore, _ := c.GetFloat("systolic_blood_pressure", 0)
  366. diastorlicbloodpressurebefore, _ := c.GetFloat("diastolic_blood_pressure", 0)
  367. weightafter, _ := c.GetFloat("weight_after", 0)
  368. temperatureafter, _ := c.GetFloat("temperatureafter", 0)
  369. pulsefrequencyafter, _ := c.GetFloat("pulse_frequencyafter", 0)
  370. breathingrateafter, _ := c.GetFloat("breathing_rateafter", 0)
  371. systolicbloodpressureafter, _ := c.GetFloat("systolic_blood_pressureafter", 0)
  372. diastolicbloodpressureafter, _ := c.GetFloat("diastolic_blood_pressureafter", 0)
  373. var sighForm models.SignWeight
  374. sighForm.WeightBefore = weighbefore
  375. sighForm.DryWeightBefore = dryweightbefore
  376. sighForm.TemperatureBefore = temperaturebefore
  377. sighForm.PulseFrequencyBefore = pulsefrequencybefore
  378. sighForm.BreathingRateBefore = breathinratebefore
  379. sighForm.SystolicBloodPressureBefore = systolicbloodpressurebefore
  380. sighForm.DiastolicBloodPressureBefore = diastorlicbloodpressurebefore
  381. sighForm.WeightAfter = weightafter
  382. sighForm.TemperatureAfter = temperatureafter
  383. sighForm.PulseFrequencyAfter = pulsefrequencyafter
  384. sighForm.BreathingRateAfter = breathingrateafter
  385. sighForm.SystolicBloodPressureAfter = systolicbloodpressureafter
  386. sighForm.DiastolicBloodPressureAfter = diastolicbloodpressureafter
  387. sighForm.PatientId = patientID
  388. sighForm.RecordDate = dateTimeStam
  389. sighForm.UserOrgId = adminUserInfo.CurrentOrgId
  390. sighForm.SignTime = time.Now().Unix()
  391. sighForm.Status = 1
  392. sighForm.CreatedTime = time.Now().Unix()
  393. if sighForm.WeightBefore > 0 {
  394. sighForm.WeighBeforeTime = time.Now().Unix()
  395. }
  396. if sighForm.WeightAfter > 0 {
  397. sighForm.WeighTime = time.Now().Unix()
  398. }
  399. if errord == gorm.ErrRecordNotFound {
  400. savesignweigh := service.Savesignweigh(&sighForm)
  401. fmt.Println("savesignweight", savesignweigh)
  402. c.ServeSuccessJSON(map[string]interface{}{
  403. "signs": sighForm,
  404. })
  405. } else if errord == nil {
  406. service.Updatesignweigh(&sighForm, patientID, adminUserInfo.CurrentOrgId)
  407. c.ServeSuccessJSON(map[string]interface{}{
  408. "signs": sighForm,
  409. })
  410. } else {
  411. service.Updatesignweigh(&sighForm, patientID, adminUserInfo.CurrentOrgId)
  412. c.ServeSuccessJSON(map[string]interface{}{
  413. "signs": sighForm,
  414. })
  415. }
  416. return
  417. }
  418. func (c *SignWeighAPIController) UpdateSignweight() {
  419. patientID, _ := c.GetInt64("patient_id", 0)
  420. dateTime := c.GetString("date_time")
  421. timeLayout := "2006-01-02"
  422. loc, _ := time.LoadLocation("Local")
  423. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", dateTime+" 00:00:00", loc)
  424. if err != nil {
  425. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  426. return
  427. }
  428. dateTimeStam := theTime.Unix()
  429. fmt.Println("datatimestam是什么", dateTimeStam)
  430. adminUserInfo := c.GetAdminUserInfo()
  431. fmt.Println(adminUserInfo.CurrentOrgId, dateTimeStam, patientID)
  432. //透前
  433. weight_before, _ := c.GetFloat("weight_before", 0)
  434. dry_weight, _ := c.GetFloat("dry_weight", 0)
  435. temperature, _ := c.GetFloat("temperature", 0)
  436. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  437. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  438. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  439. var predialysisevaluation models.PredialysisEvaluation
  440. predialysisevaluation.PatientId = patientID
  441. predialysisevaluation.UserOrgId = adminUserInfo.CurrentOrgId
  442. predialysisevaluation.AssessmentDate = dateTimeStam
  443. predialysisevaluation.WeightBefore = weight_before
  444. predialysisevaluation.DryWeight = dry_weight
  445. predialysisevaluation.Temperature = temperature
  446. predialysisevaluation.PulseFrequency = pulse_frequency
  447. predialysisevaluation.SystolicBloodPressure = systolic_blood_pressure
  448. predialysisevaluation.DiastolicBloodPressure = diastolic_blood_pressure
  449. predialysisevaluation.CreatedTime = time.Now().Unix()
  450. predialysisevaluation.Status = 1
  451. predialysis, errcode := service.GetDislysisBerfore(adminUserInfo.CurrentOrgId, dateTimeStam, patientID)
  452. fmt.Println("sigh", predialysis)
  453. fmt.Println("错误:", errcode)
  454. lastPredialysisEvaluation, _ := service.MobileGetLastTimePredialysisEvaluationOne(adminUserInfo.CurrentOrgId, patientID, dateTimeStam)
  455. if lastPredialysisEvaluation != nil {
  456. predialysisevaluation.DryWeight = lastPredialysisEvaluation.DryWeight
  457. predialysisevaluation.InternalFistula = lastPredialysisEvaluation.InternalFistula
  458. predialysisevaluation.InternalFistulaSkin = lastPredialysisEvaluation.InternalFistulaSkin
  459. predialysisevaluation.VenousCatheterization = lastPredialysisEvaluation.VenousCatheterization
  460. predialysisevaluation.Catheter = lastPredialysisEvaluation.Catheter
  461. predialysisevaluation.CatheterBend = lastPredialysisEvaluation.CatheterBend
  462. predialysisevaluation.PunctureNeedle = lastPredialysisEvaluation.PunctureNeedle
  463. predialysisevaluation.PunctureNeedleDirection = lastPredialysisEvaluation.PunctureNeedleDirection
  464. predialysisevaluation.PunctureWay = lastPredialysisEvaluation.PunctureWay
  465. predialysisevaluation.PointPuncture = lastPredialysisEvaluation.PointPuncture
  466. predialysisevaluation.IsHemorrhage = lastPredialysisEvaluation.IsHemorrhage
  467. predialysisevaluation.ThromubusType = lastPredialysisEvaluation.ThromubusType
  468. predialysisevaluation.Skin = lastPredialysisEvaluation.Skin
  469. predialysisevaluation.Complication = lastPredialysisEvaluation.Complication
  470. predialysisevaluation.SymptomBeforeDialysis = lastPredialysisEvaluation.SymptomBeforeDialysis
  471. predialysisevaluation.LastPostDialysisOther = lastPredialysisEvaluation.LastPostDialysisOther
  472. }
  473. if errcode == gorm.ErrRecordNotFound {
  474. service.SaveDislysisiBefore(&predialysisevaluation)
  475. } else if errcode == nil {
  476. service.UpdataDislysisiBefore(&predialysisevaluation, patientID, adminUserInfo.CurrentOrgId, dateTimeStam)
  477. } else {
  478. service.UpdataDislysisiBefore(&predialysisevaluation, patientID, adminUserInfo.CurrentOrgId, dateTimeStam)
  479. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  480. }
  481. // 计算透析处方的相关超滤量
  482. schedual, _ := service.MobileGetSchedualDetailSix(adminUserInfo.CurrentOrgId, patientID, dateTimeStam)
  483. var lastDialysisPrescribe *models.DialysisPrescription
  484. var dialysisSolution *models.DialysisSolution
  485. var dialysisPrescribe *models.DialysisPrescription
  486. var system_dialysisPrescribe *models.SystemPrescription
  487. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patientID, dateTimeStam)
  488. var dewater_amount float64
  489. dewater_amount = predialysisevaluation.WeightBefore - predialysisevaluation.DryWeight - predialysisevaluation.AdditionalWeight
  490. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.CurrentOrgId, patientID, schedual.ModeId)
  491. // 插入透析处方
  492. if dialysisPrescribe == nil && dialysisSolution != nil {
  493. var newprescribe models.DialysisPrescription
  494. newprescribe.UserOrgId = dialysisSolution.UserOrgId
  495. newprescribe.PatientId = dialysisSolution.PatientId
  496. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  497. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  498. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  499. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  500. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  501. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  502. newprescribe.ModeId = dialysisSolution.ModeId
  503. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  504. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  505. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  506. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  507. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  508. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  509. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  510. newprescribe.Glucose = dialysisSolution.Glucose
  511. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  512. newprescribe.Kalium = dialysisSolution.Kalium
  513. newprescribe.Sodium = dialysisSolution.Sodium
  514. newprescribe.Calcium = dialysisSolution.Calcium
  515. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  516. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  517. newprescribe.Conductivity = dialysisSolution.Conductivity
  518. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  519. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  520. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  521. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  522. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  523. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  524. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  525. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  526. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  527. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  528. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  529. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  530. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  531. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  532. newprescribe.DialysisIrrigation = dialysisSolution.DialysisIrrigation
  533. newprescribe.DialysisDialyszers = dialysisSolution.DialysisDialyszers
  534. newprescribe.DialysisStrainer = dialysisSolution.DialysisStrainer
  535. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  536. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  537. newprescribe.CreatedTime = time.Now().Unix()
  538. newprescribe.UpdatedTime = time.Now().Unix()
  539. newprescribe.RecordDate = dateTimeStam
  540. newprescribe.DewaterAmount = dewater_amount
  541. newprescribe.TargetUltrafiltration = dewater_amount
  542. newprescribe.PrescriptionWater = dewater_amount
  543. newprescribe.Chaptalization = dialysisSolution.Chaptalization
  544. newprescribe.PrescribingNumber = 1
  545. newprescribe.BloodAccessPartId = dialysisSolution.BloodAccessPartId
  546. newprescribe.Status = 1
  547. if adminUserInfo.CurrentOrgId != 10013 && adminUserInfo.CurrentOrgId != 10014 && adminUserInfo.CurrentOrgId != 10016 {
  548. newprescribe.Remark = dialysisSolution.Remark
  549. }
  550. if adminUserInfo.CurrentOrgId == 10340 {
  551. newprescribe.TargetUltrafiltration = 0
  552. newprescribe.Sodium = 138
  553. newprescribe.Bicarbonate = 31.1
  554. newprescribe.DialysateFlow = 500
  555. newprescribe.TargetUltrafiltration = 0
  556. }
  557. // 针对新化博翔
  558. if adminUserInfo.CurrentOrgId == 10447 {
  559. newprescribe.DisplaceLiquiPart = 1
  560. newprescribe.DisplaceLiquiValue = 32
  561. newprescribe.DialysateFlow = 500
  562. }
  563. if adminUserInfo.CurrentOrgId == 10121 {
  564. newprescribe.DialysisDurationHour = 4
  565. newprescribe.DialysisDurationMinute = 0
  566. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  567. }
  568. if adminUserInfo.CurrentOrgId == 10445 {
  569. lastDialysisPrescription, _ := service.GetLastDialysisPrescription(patientID, adminUserInfo.CurrentOrgId)
  570. newprescribe.Remark = lastDialysisPrescription.Remark
  571. }
  572. //恒泰
  573. if adminUserInfo.CurrentOrgId == 10490 || adminUserInfo.CurrentOrgId == 10016 {
  574. newprescribe.Remark = ""
  575. }
  576. if adminUserInfo.CurrentOrgId == 10599 {
  577. // 获取透析模版
  578. solutionone, _ := service.MobileGetDialysisSolutionByModeIdSevenTwety(adminUserInfo.CurrentOrgId, patientID, schedual.ModeId)
  579. if solutionone.Anticoagulant > 0 {
  580. newprescribe.Anticoagulant = solutionone.Anticoagulant
  581. newprescribe.AnticoagulantShouji = solutionone.AnticoagulantShouji
  582. newprescribe.AnticoagulantWeichi = solutionone.AnticoagulantWeichi
  583. newprescribe.AnticoagulantZongliang = solutionone.AnticoagulantZongliang
  584. newprescribe.BloodAccess = solutionone.BloodAccess
  585. newprescribe.DialysisDurationHour = solutionone.DialysisDurationHour
  586. newprescribe.DialysisDurationMinute = solutionone.DialysisDurationMinute
  587. newprescribe.DialysisIrrigation = solutionone.DialysisIrrigation
  588. newprescribe.DialysisDialyszers = solutionone.DialysisDialyszers
  589. newprescribe.DialysisStrainer = solutionone.DialysisStrainer
  590. }
  591. }
  592. //针对普宁和揭阳
  593. if adminUserInfo.CurrentOrgId == 10597 || adminUserInfo.CurrentOrgId == 10599 {
  594. prescriptionTwenty, _ := service.GetLastDialysisPrescriptionTwenty(newprescribe.PatientId, newprescribe.RecordDate, newprescribe.UserOrgId)
  595. if prescriptionTwenty.ID == 0 {
  596. //插入透析处方
  597. service.AddSigleRecord(&newprescribe)
  598. } else {
  599. //插入透析处方
  600. service.UpdateAddSigleRecord(prescriptionTwenty.ID, newprescribe.TargetUltrafiltration)
  601. }
  602. } else {
  603. //插入透析处方
  604. service.AddSigleRecord(&newprescribe)
  605. }
  606. //记录日志
  607. byterequest, _ := json.Marshal(newprescribe)
  608. prescriptionLog := models.XtDialysisPrescriptionLog{
  609. UserOrgId: newprescribe.UserOrgId,
  610. Ctime: time.Now().Unix(),
  611. Mtime: 0,
  612. ErrLog: string(byterequest),
  613. AdminUserId: adminUserInfo.AdminUser.Id,
  614. RecordDate: newprescribe.RecordDate,
  615. PatientId: newprescribe.PatientId,
  616. Source: "物联网上传",
  617. Status: 1,
  618. }
  619. service.CreatePrescriptionLog(prescriptionLog)
  620. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(dateTimeStam, 10) + ":" + strconv.FormatInt(schedual.ModeId, 10) + ":dialysis_prescribe"
  621. redis := service.RedisClient()
  622. //清空key 值
  623. redis.Set(key, "", time.Second)
  624. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(dateTimeStam, 10) + ":prescriptions_list_all"
  625. redis.Set(keyTwo, "", time.Second)
  626. thisTime := time.Now()
  627. scheduleDateStartOne := thisTime.Format("2006-01-02")
  628. keyThree := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  629. redis.Set(keyThree, "", time.Second)
  630. defer redis.Close()
  631. }
  632. if dialysisPrescribe == nil && dialysisSolution == nil {
  633. if lastDialysisPrescribe != nil {
  634. var newprescribe models.DialysisPrescription
  635. newprescribe.UserOrgId = lastDialysisPrescribe.UserOrgId
  636. newprescribe.PatientId = lastDialysisPrescribe.PatientId
  637. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  638. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  639. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  640. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  641. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  642. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  643. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  644. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  645. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  646. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  647. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  648. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  649. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  650. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  651. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  652. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  653. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  654. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  655. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  656. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  657. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  658. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  659. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  660. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  661. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  662. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  663. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  664. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  665. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  666. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  667. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  668. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  669. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  670. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  671. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  672. newprescribe.DialysisDialyszers = lastDialysisPrescribe.DialysisDialyszers
  673. newprescribe.DialysisIrrigation = lastDialysisPrescribe.DialysisIrrigation
  674. newprescribe.DialysisStrainer = lastDialysisPrescribe.DialysisStrainer
  675. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  676. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  677. newprescribe.BloodAccessPartId = lastDialysisPrescribe.BloodAccessPartId
  678. newprescribe.CreatedTime = time.Now().Unix()
  679. newprescribe.UpdatedTime = time.Now().Unix()
  680. newprescribe.RecordDate = dateTimeStam
  681. newprescribe.DewaterAmount = dewater_amount
  682. newprescribe.TargetUltrafiltration = dewater_amount
  683. newprescribe.PrescriptionWater = dewater_amount
  684. newprescribe.Status = 1
  685. if adminUserInfo.CurrentOrgId == 10490 || adminUserInfo.CurrentOrgId == 10016 {
  686. newprescribe.Remark = ""
  687. }
  688. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  689. newprescribe.PrescribingNumber = 1
  690. if adminUserInfo.CurrentOrgId == 10340 {
  691. newprescribe.TargetUltrafiltration = 0
  692. }
  693. if adminUserInfo.CurrentOrgId == 10121 {
  694. newprescribe.DialysisDurationHour = 4
  695. newprescribe.DialysisDurationMinute = 0
  696. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  697. }
  698. if adminUserInfo.CurrentOrgId == 10445 {
  699. lastDialysisPrescription, _ := service.GetLastDialysisPrescription(patientID, adminUserInfo.CurrentOrgId)
  700. newprescribe.Remark = lastDialysisPrescription.Remark
  701. }
  702. //err := service.AddSigleRecord(&newprescribe)
  703. var err error
  704. if adminUserInfo.CurrentOrgId == 10597 || adminUserInfo.CurrentOrgId == 10599 || adminUserInfo.CurrentOrgId == 3877 {
  705. prescriptionTwenty, _ := service.GetLastDialysisPrescriptionTwenty(newprescribe.PatientId, newprescribe.RecordDate, newprescribe.UserOrgId)
  706. if prescriptionTwenty.ID == 0 {
  707. //插入透析处方
  708. service.AddSigleRecord(&newprescribe)
  709. } else {
  710. //插入透析处方
  711. service.UpdateAddSigleRecord(prescriptionTwenty.ID, newprescribe.TargetUltrafiltration)
  712. }
  713. } else {
  714. //插入透析处方
  715. err = service.AddSigleRecord(&newprescribe)
  716. }
  717. //记录日志
  718. byterequest, _ := json.Marshal(newprescribe)
  719. prescriptionLog := models.XtDialysisPrescriptionLog{
  720. UserOrgId: adminUserInfo.CurrentOrgId,
  721. Ctime: time.Now().Unix(),
  722. Mtime: 0,
  723. ErrLog: string(byterequest),
  724. AdminUserId: adminUserInfo.AdminUser.Id,
  725. RecordDate: newprescribe.RecordDate,
  726. PatientId: patientID,
  727. Source: "物联网上传",
  728. Status: 1,
  729. }
  730. service.CreatePrescriptionLog(prescriptionLog)
  731. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(dateTimeStam, 10) + ":" + strconv.FormatInt(schedual.ModeId, 10) + ":dialysis_prescribe"
  732. redis := service.RedisClient()
  733. //清空key 值
  734. redis.Set(key, "", time.Second)
  735. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(dateTimeStam, 10) + ":prescriptions_list_all"
  736. redis.Set(keyTwo, "", time.Second)
  737. thisTime := time.Now()
  738. scheduleDateStartOne := thisTime.Format("2006-01-02")
  739. keyThree := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  740. redis.Set(keyThree, "", time.Second)
  741. defer redis.Close()
  742. if err != nil {
  743. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  744. }
  745. } else if system_dialysisPrescribe != nil {
  746. var newprescribe models.DialysisPrescription
  747. newprescribe.UserOrgId = system_dialysisPrescribe.UserOrgId
  748. newprescribe.PatientId = patientID
  749. newprescribe.Anticoagulant = system_dialysisPrescribe.Anticoagulant
  750. newprescribe.AnticoagulantShouji = system_dialysisPrescribe.AnticoagulantShouji
  751. newprescribe.AnticoagulantWeichi = system_dialysisPrescribe.AnticoagulantWeichi
  752. newprescribe.AnticoagulantZongliang = system_dialysisPrescribe.AnticoagulantZongliang
  753. newprescribe.AnticoagulantGaimingcheng = system_dialysisPrescribe.AnticoagulantGaimingcheng
  754. newprescribe.AnticoagulantGaijiliang = system_dialysisPrescribe.AnticoagulantGaijiliang
  755. newprescribe.ModeId = system_dialysisPrescribe.ModeId
  756. newprescribe.DialysisDuration = system_dialysisPrescribe.DialysisDuration
  757. newprescribe.ReplacementWay = system_dialysisPrescribe.ReplacementWay
  758. newprescribe.HemodialysisMachine = system_dialysisPrescribe.HemodialysisMachine
  759. newprescribe.BloodFilter = system_dialysisPrescribe.BloodFilter
  760. newprescribe.PerfusionApparatus = system_dialysisPrescribe.PerfusionApparatus
  761. newprescribe.BloodFlowVolume = system_dialysisPrescribe.BloodFlowVolume
  762. newprescribe.DisplaceLiqui = system_dialysisPrescribe.DisplaceLiqui
  763. newprescribe.Glucose = system_dialysisPrescribe.Glucose
  764. newprescribe.DialysateFlow = system_dialysisPrescribe.DialysateFlow
  765. newprescribe.Kalium = system_dialysisPrescribe.Kalium
  766. newprescribe.Sodium = system_dialysisPrescribe.Sodium
  767. newprescribe.Calcium = system_dialysisPrescribe.Calcium
  768. newprescribe.Bicarbonate = system_dialysisPrescribe.Bicarbonate
  769. newprescribe.DialysateTemperature = system_dialysisPrescribe.DialysateTemperature
  770. newprescribe.Conductivity = system_dialysisPrescribe.Conductivity
  771. newprescribe.BodyFluid = system_dialysisPrescribe.BodyFluid
  772. newprescribe.SpecialMedicine = system_dialysisPrescribe.SpecialMedicine
  773. newprescribe.SpecialMedicineOther = system_dialysisPrescribe.SpecialMedicineOther
  774. newprescribe.DisplaceLiquiPart = system_dialysisPrescribe.DisplaceLiquiPart
  775. newprescribe.DisplaceLiquiValue = system_dialysisPrescribe.DisplaceLiquiValue
  776. newprescribe.BloodAccess = system_dialysisPrescribe.BloodAccess
  777. newprescribe.Ultrafiltration = system_dialysisPrescribe.Ultrafiltration
  778. newprescribe.DialysisDurationHour = system_dialysisPrescribe.DialysisDurationHour
  779. newprescribe.DialysisDurationMinute = system_dialysisPrescribe.DialysisDurationMinute
  780. newprescribe.DialysateFormulation = system_dialysisPrescribe.DialysateFormulation
  781. newprescribe.Dialyzer = system_dialysisPrescribe.Dialyzer
  782. newprescribe.ReplacementTotal = system_dialysisPrescribe.ReplacementTotal
  783. newprescribe.DialyzerPerfusionApparatus = system_dialysisPrescribe.DialyzerPerfusionApparatus
  784. newprescribe.DialysisIrrigation = system_dialysisPrescribe.DialysisIrrigation
  785. newprescribe.DialysisDialyszers = system_dialysisPrescribe.DialysisDialyszers
  786. newprescribe.BodyFluidOther = system_dialysisPrescribe.BodyFluidOther
  787. newprescribe.TargetKtv = system_dialysisPrescribe.TargetKtv
  788. newprescribe.CreatedTime = time.Now().Unix()
  789. newprescribe.UpdatedTime = time.Now().Unix()
  790. newprescribe.RecordDate = dateTimeStam
  791. newprescribe.DewaterAmount = dewater_amount
  792. newprescribe.TargetUltrafiltration = dewater_amount
  793. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  794. newprescribe.BloodAccessPartId = lastDialysisPrescribe.BloodAccessPartId
  795. newprescribe.Status = 1
  796. newprescribe.PrescribingNumber = 1
  797. if adminUserInfo.CurrentOrgId == 10340 {
  798. newprescribe.TargetUltrafiltration = 0
  799. }
  800. if adminUserInfo.CurrentOrgId == 10121 {
  801. newprescribe.DialysisDurationHour = 4
  802. newprescribe.DialysisDurationMinute = 0
  803. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  804. }
  805. if adminUserInfo.CurrentOrgId == 10445 {
  806. lastDialysisPrescription, _ := service.GetLastDialysisPrescription(patientID, adminUserInfo.CurrentOrgId)
  807. newprescribe.Remark = lastDialysisPrescription.Remark
  808. }
  809. if adminUserInfo.CurrentOrgId == 10597 || adminUserInfo.CurrentOrgId == 10599 || adminUserInfo.CurrentOrgId == 3877 {
  810. prescriptionTwenty, _ := service.GetLastDialysisPrescriptionTwenty(newprescribe.PatientId, newprescribe.RecordDate, newprescribe.UserOrgId)
  811. if prescriptionTwenty.ID == 0 {
  812. //插入透析处方
  813. service.AddSigleRecord(&newprescribe)
  814. } else {
  815. //插入透析处方
  816. service.UpdateAddSigleRecord(prescriptionTwenty.ID, newprescribe.TargetUltrafiltration)
  817. }
  818. } else {
  819. service.AddSigleRecord(&newprescribe)
  820. }
  821. //记录日志
  822. byterequest, _ := json.Marshal(newprescribe)
  823. prescriptionLog := models.XtDialysisPrescriptionLog{
  824. UserOrgId: adminUserInfo.CurrentOrgId,
  825. Ctime: time.Now().Unix(),
  826. Mtime: 0,
  827. ErrLog: string(byterequest),
  828. AdminUserId: adminUserInfo.AdminUser.Id,
  829. RecordDate: newprescribe.RecordDate,
  830. PatientId: patientID,
  831. Source: "物联网上传",
  832. Status: 1,
  833. }
  834. service.CreatePrescriptionLog(prescriptionLog)
  835. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(dateTimeStam, 10) + ":" + strconv.FormatInt(schedual.ModeId, 10) + ":dialysis_prescribe"
  836. redis := service.RedisClient()
  837. //清空key 值
  838. redis.Set(key, "", time.Second)
  839. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(dateTimeStam, 10) + ":prescriptions_list_all"
  840. redis.Set(keyTwo, "", time.Second)
  841. thisTime := time.Now()
  842. scheduleDateStartOne := thisTime.Format("2006-01-02")
  843. keyThree := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  844. redis.Set(keyThree, "", time.Second)
  845. defer redis.Close()
  846. } else {
  847. var newprescribe models.DialysisPrescription
  848. newprescribe.UserOrgId = adminUserInfo.CurrentOrgId
  849. newprescribe.PatientId = patientID
  850. newprescribe.ModeId = schedual.ModeId
  851. newprescribe.CreatedTime = time.Now().Unix()
  852. newprescribe.UpdatedTime = time.Now().Unix()
  853. newprescribe.RecordDate = dateTimeStam
  854. newprescribe.DewaterAmount = dewater_amount
  855. newprescribe.TargetUltrafiltration = dewater_amount
  856. newprescribe.Status = 1
  857. if adminUserInfo.CurrentOrgId == 10445 {
  858. lastDialysisPrescription, _ := service.GetLastDialysisPrescription(patientID, adminUserInfo.CurrentOrgId)
  859. newprescribe.Remark = lastDialysisPrescription.Remark
  860. }
  861. err := service.AddSigleRecord(&newprescribe)
  862. //记录日志
  863. byterequest, _ := json.Marshal(newprescribe)
  864. prescriptionLog := models.XtDialysisPrescriptionLog{
  865. UserOrgId: adminUserInfo.CurrentOrgId,
  866. Ctime: time.Now().Unix(),
  867. Mtime: 0,
  868. ErrLog: string(byterequest),
  869. AdminUserId: adminUserInfo.AdminUser.Id,
  870. RecordDate: newprescribe.RecordDate,
  871. PatientId: patientID,
  872. Source: "物联网上传",
  873. Status: 1,
  874. }
  875. service.CreatePrescriptionLog(prescriptionLog)
  876. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(dateTimeStam, 10) + ":" + strconv.FormatInt(schedual.ModeId, 10) + ":dialysis_prescribe"
  877. redis := service.RedisClient()
  878. //清空key 值
  879. redis.Set(key, "", time.Second)
  880. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(dateTimeStam, 10) + ":prescriptions_list_all"
  881. redis.Set(keyTwo, "", time.Second)
  882. thisTime := time.Now()
  883. scheduleDateStartOne := thisTime.Format("2006-01-02")
  884. keyThree := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  885. redis.Set(keyThree, "", time.Second)
  886. defer redis.Close()
  887. if err != nil {
  888. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  889. }
  890. }
  891. }
  892. if dialysisPrescribe != nil && dialysisPrescribe.TargetUltrafiltration == 0 {
  893. dialysisPrescribe.UpdatedTime = time.Now().Unix()
  894. dialysisPrescribe.RecordDate = dateTimeStam
  895. dialysisPrescribe.DewaterAmount = dewater_amount
  896. dialysisPrescribe.TargetUltrafiltration = dewater_amount
  897. dialysisPrescribe.Status = 1
  898. if adminUserInfo.CurrentOrgId == 10340 {
  899. dialysisPrescribe.TargetUltrafiltration = 0
  900. }
  901. if adminUserInfo.CurrentOrgId == 10445 {
  902. lastDialysisPrescription, _ := service.GetLastDialysisPrescription(patientID, adminUserInfo.CurrentOrgId)
  903. dialysisPrescribe.Remark = lastDialysisPrescription.Remark
  904. }
  905. updateErr := service.UpDateDialysisPrescription(dialysisPrescribe)
  906. //记录日志
  907. byterequest, _ := json.Marshal(dialysisPrescribe)
  908. prescriptionLog := models.XtDialysisPrescriptionLog{
  909. UserOrgId: adminUserInfo.CurrentOrgId,
  910. Ctime: time.Now().Unix(),
  911. Mtime: 0,
  912. ErrLog: string(byterequest),
  913. AdminUserId: adminUserInfo.AdminUser.Id,
  914. RecordDate: dialysisPrescribe.RecordDate,
  915. PatientId: patientID,
  916. Source: "物联网上传",
  917. Status: 1,
  918. }
  919. service.CreatePrescriptionLog(prescriptionLog)
  920. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(dateTimeStam, 10) + ":" + strconv.FormatInt(schedual.ModeId, 10) + ":dialysis_prescribe"
  921. redis := service.RedisClient()
  922. //清空key 值
  923. redis.Set(key, "", time.Second)
  924. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(dateTimeStam, 10) + ":prescriptions_list_all"
  925. redis.Set(keyTwo, "", time.Second)
  926. thisTime := time.Now()
  927. scheduleDateStartOne := thisTime.Format("2006-01-02")
  928. keyThree := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  929. redis.Set(keyThree, "", time.Second)
  930. defer redis.Close()
  931. if updateErr != nil {
  932. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  933. }
  934. }
  935. //透后
  936. weight_after, _ := c.GetFloat("weight_after", 0)
  937. temperatureafter, _ := c.GetFloat("temperatureafter", 0)
  938. pulsefrequencyafter, _ := c.GetFloat("pulse_frequencyafter", 0)
  939. systolicbloodpressureafter, _ := c.GetFloat("systolic_blood_pressureafter", 0)
  940. diastolicbloodpressureafter, _ := c.GetFloat("diastolic_blood_pressureafter", 0)
  941. var assessmentafterdislysis models.AssessmentAfterDislysis
  942. assessmentafterdislysis.PatientId = patientID
  943. assessmentafterdislysis.UserOrgId = adminUserInfo.CurrentOrgId
  944. assessmentafterdislysis.AssessmentDate = dateTimeStam
  945. assessmentafterdislysis.WeightAfter = weight_after
  946. assessmentafterdislysis.Temperature = temperatureafter
  947. assessmentafterdislysis.PulseFrequency = pulsefrequencyafter
  948. assessmentafterdislysis.SystolicBloodPressure = systolicbloodpressureafter
  949. assessmentafterdislysis.DiastolicBloodPressure = diastolicbloodpressureafter
  950. assessmentafterdislysis.CreatedTime = time.Now().Unix()
  951. assessmentafterdislysis.Status = 1
  952. dislysis, errcoder := service.GetAssessmentaafterdislysis(adminUserInfo.CurrentOrgId, dateTimeStam, patientID)
  953. fmt.Println("sigh", dislysis)
  954. fmt.Println("错误装太:", errcoder)
  955. if errcoder == gorm.ErrRecordNotFound {
  956. service.SaveAssessmentafter(&assessmentafterdislysis)
  957. c.ServeSuccessJSON(map[string]interface{}{
  958. "signs": predialysisevaluation,
  959. })
  960. } else if errcoder == nil {
  961. service.UpdataAssessment(&assessmentafterdislysis, patientID, adminUserInfo.CurrentOrgId, dateTimeStam)
  962. c.ServeSuccessJSON(map[string]interface{}{
  963. "signs": predialysisevaluation,
  964. })
  965. } else {
  966. service.UpdataAssessment(&assessmentafterdislysis, patientID, adminUserInfo.CurrentOrgId, dateTimeStam)
  967. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  968. }
  969. }
  970. //func (c *SignWeighAPIController) GetForenoonData() {
  971. // nowDateTime := time.Now()
  972. // nowDate := nowDateTime.Format("2006-01-02")
  973. // nowDate += " 00:00:00"
  974. // timeLayout := "2006-01-02"
  975. // loc, _ := time.LoadLocation("Local")
  976. // theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", nowDate, loc)
  977. // datetime := theTime.Unix()
  978. // fmt.Println("hhhhhhhhhhhhhhhhhhh")
  979. // fmt.Println("datetime",datetime)
  980. // adminUserInfo := c.GetAdminUserInfo()
  981. // orgId := adminUserInfo.CurrentOrgId
  982. // fmt.Println("orgid是什么",orgId)
  983. // total, schedule, err := service.GetForenoonData(datetime, orgId, 1)
  984. // fmt.Println("total",total)
  985. // fmt.Println("schedule",schedule)
  986. // if err != nil {
  987. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  988. // return
  989. // }
  990. //
  991. // c.ServeSuccessJSON(map[string]interface{}{
  992. // "total": total,
  993. // })
  994. //
  995. //}