sign_weigh_api_controller.go 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "encoding/json"
  7. "fmt"
  8. "github.com/astaxie/beego"
  9. "github.com/jinzhu/gorm"
  10. "reflect"
  11. "strconv"
  12. "time"
  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. fmt.Println("病人ID", patientID, dateTime)
  422. timeLayout := "2006-01-02"
  423. loc, _ := time.LoadLocation("Local")
  424. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", dateTime+" 00:00:00", loc)
  425. if err != nil {
  426. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  427. return
  428. }
  429. dateTimeStam := theTime.Unix()
  430. fmt.Println("datatimestam是什么", dateTimeStam)
  431. adminUserInfo := c.GetAdminUserInfo()
  432. fmt.Println(adminUserInfo.CurrentOrgId, dateTimeStam, patientID)
  433. //透前
  434. weight_before, _ := c.GetFloat("weight_before", 0)
  435. dry_weight, _ := c.GetFloat("dry_weight", 0)
  436. temperature, _ := c.GetFloat("temperature", 0)
  437. fmt.Println("温度", temperature)
  438. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  439. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  440. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  441. fmt.Println("dry_weight", dry_weight)
  442. var predialysisevaluation models.PredialysisEvaluation
  443. predialysisevaluation.PatientId = patientID
  444. predialysisevaluation.UserOrgId = adminUserInfo.CurrentOrgId
  445. predialysisevaluation.AssessmentDate = dateTimeStam
  446. predialysisevaluation.WeightBefore = weight_before
  447. predialysisevaluation.DryWeight = dry_weight
  448. predialysisevaluation.Temperature = temperature
  449. predialysisevaluation.PulseFrequency = pulse_frequency
  450. predialysisevaluation.SystolicBloodPressure = systolic_blood_pressure
  451. predialysisevaluation.DiastolicBloodPressure = diastolic_blood_pressure
  452. predialysisevaluation.CreatedTime = time.Now().Unix()
  453. predialysisevaluation.Status = 1
  454. predialysis, errcode := service.GetDislysisBerfore(adminUserInfo.CurrentOrgId, dateTimeStam, patientID)
  455. fmt.Println("sigh", predialysis)
  456. fmt.Println("错误:", errcode)
  457. if errcode == gorm.ErrRecordNotFound {
  458. service.SaveDislysisiBefore(&predialysisevaluation)
  459. } else if errcode == nil {
  460. service.UpdataDislysisiBefore(&predialysisevaluation, patientID, adminUserInfo.CurrentOrgId, dateTimeStam)
  461. } else {
  462. service.UpdataDislysisiBefore(&predialysisevaluation, patientID, adminUserInfo.CurrentOrgId, dateTimeStam)
  463. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  464. }
  465. //透后
  466. weight_after, _ := c.GetFloat("weight_after", 0)
  467. temperatureafter, _ := c.GetFloat("temperatureafter", 0)
  468. pulsefrequencyafter, _ := c.GetFloat("pulse_frequencyafter", 0)
  469. systolicbloodpressureafter, _ := c.GetFloat("systolic_blood_pressureafter", 0)
  470. diastolicbloodpressureafter, _ := c.GetFloat("diastolic_blood_pressureafter", 0)
  471. var assessmentafterdislysis models.AssessmentAfterDislysis
  472. assessmentafterdislysis.PatientId = patientID
  473. assessmentafterdislysis.UserOrgId = adminUserInfo.CurrentOrgId
  474. assessmentafterdislysis.AssessmentDate = dateTimeStam
  475. assessmentafterdislysis.WeightAfter = weight_after
  476. assessmentafterdislysis.Temperature = temperatureafter
  477. assessmentafterdislysis.PulseFrequency = pulsefrequencyafter
  478. assessmentafterdislysis.SystolicBloodPressure = systolicbloodpressureafter
  479. assessmentafterdislysis.DiastolicBloodPressure = diastolicbloodpressureafter
  480. assessmentafterdislysis.CreatedTime = time.Now().Unix()
  481. assessmentafterdislysis.Status = 1
  482. dislysis, errcoder := service.GetAssessmentaafterdislysis(adminUserInfo.CurrentOrgId, dateTimeStam, patientID)
  483. fmt.Println("sigh", dislysis)
  484. fmt.Println("错误装太:", errcoder)
  485. if errcoder == gorm.ErrRecordNotFound {
  486. service.SaveAssessmentafter(&assessmentafterdislysis)
  487. c.ServeSuccessJSON(map[string]interface{}{
  488. "signs": predialysisevaluation,
  489. })
  490. } else if errcoder == nil {
  491. service.UpdataAssessment(&assessmentafterdislysis, patientID, adminUserInfo.CurrentOrgId, dateTimeStam)
  492. c.ServeSuccessJSON(map[string]interface{}{
  493. "signs": predialysisevaluation,
  494. })
  495. } else {
  496. service.UpdataAssessment(&assessmentafterdislysis, patientID, adminUserInfo.CurrentOrgId, dateTimeStam)
  497. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  498. }
  499. }
  500. //func (c *SignWeighAPIController) GetForenoonData() {
  501. // nowDateTime := time.Now()
  502. // nowDate := nowDateTime.Format("2006-01-02")
  503. // nowDate += " 00:00:00"
  504. // timeLayout := "2006-01-02"
  505. // loc, _ := time.LoadLocation("Local")
  506. // theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", nowDate, loc)
  507. // datetime := theTime.Unix()
  508. // fmt.Println("hhhhhhhhhhhhhhhhhhh")
  509. // fmt.Println("datetime",datetime)
  510. // adminUserInfo := c.GetAdminUserInfo()
  511. // orgId := adminUserInfo.CurrentOrgId
  512. // fmt.Println("orgid是什么",orgId)
  513. // total, schedule, err := service.GetForenoonData(datetime, orgId, 1)
  514. // fmt.Println("total",total)
  515. // fmt.Println("schedule",schedule)
  516. // if err != nil {
  517. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  518. // return
  519. // }
  520. //
  521. // c.ServeSuccessJSON(map[string]interface{}{
  522. // "total": total,
  523. // })
  524. //
  525. //}