sign_weigh_api_controller.go 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  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. fmt.Println("关键字" + keywrods)
  32. scheduleType, _ := c.GetInt64("schedule_type", 0)
  33. needScheduleType, _ := c.GetInt64("need_schedule_type", 0)
  34. nowDateTime := time.Now()
  35. nowDate := nowDateTime.Format("2006-01-02")
  36. today := nowDate
  37. nowDate += " 00:00:00"
  38. //认为没有选择{0:'全部',1:'上午',2:'下午'3:'晚上' }中的一个
  39. if scheduleType < 0 || scheduleType > 3 {
  40. nowH := nowDateTime.Hour()
  41. if nowH < 12 {
  42. scheduleType = 1
  43. } else if nowH < 18 {
  44. scheduleType = 2
  45. } else {
  46. scheduleType = 3
  47. }
  48. }
  49. timeLayout := "2006-01-02"
  50. loc, _ := time.LoadLocation("Local")
  51. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", nowDate, loc)
  52. if err != nil {
  53. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  54. return
  55. }
  56. dateTime := theTime.Unix()
  57. fmt.Println("dataTime是多少", dateTime)
  58. adminUserInfo := c.GetAdminUserInfo()
  59. patients, err := service.GetSignPatients(adminUserInfo.CurrentOrgId, keywrods, dateTime, scheduleType)
  60. fmt.Println("病人信息", patients)
  61. if err != nil {
  62. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  63. return
  64. }
  65. panel := make(map[int64]map[string]int64, 0)
  66. if needScheduleType == 1 {
  67. panel, _ = service.GetSignPanels(adminUserInfo.CurrentOrgId, dateTime)
  68. fmt.Println("panel是什么", panel)
  69. }
  70. c.ServeSuccessJSON(map[string]interface{}{
  71. "patients": patients,
  72. "today": today,
  73. "schedule_type": scheduleType,
  74. "panel": panel,
  75. })
  76. return
  77. }
  78. func (c *SignWeighAPIController) GetPatientSign() {
  79. patientID, _ := c.GetInt64("patient_id", 0)
  80. dateTime := c.GetString("date_time")
  81. timeLayout := "2006-01-02"
  82. loc, _ := time.LoadLocation("Local")
  83. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", dateTime+" 00:00:00", loc)
  84. if err != nil {
  85. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  86. return
  87. }
  88. dateTimeStam := theTime.Unix()
  89. adminUserInfo := c.GetAdminUserInfo()
  90. sign, err := service.GetPatientDateSign(adminUserInfo.CurrentOrgId, dateTimeStam, patientID)
  91. if err != nil {
  92. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  93. return
  94. }
  95. c.ServeSuccessJSON(map[string]interface{}{
  96. "sign": sign,
  97. })
  98. return
  99. }
  100. func (c *SignWeighAPIController) EditPatientSign() {
  101. patientID, _ := c.GetInt64("patient_id", 0)
  102. dateTime := c.GetString("date_time")
  103. timeLayout := "2006-01-02"
  104. loc, _ := time.LoadLocation("Local")
  105. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", dateTime+" 00:00:00", loc)
  106. if err != nil {
  107. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  108. return
  109. }
  110. dateTimeStam := theTime.Unix()
  111. adminUserInfo := c.GetAdminUserInfo()
  112. sign, err := service.GetPatientDateSign(adminUserInfo.CurrentOrgId, dateTimeStam, patientID)
  113. if err != nil {
  114. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  115. return
  116. }
  117. var signForm models.SigninAndWeigh
  118. if sign != nil {
  119. signForm = *sign
  120. signForm.UpdatedTime = time.Now().Unix()
  121. } else {
  122. signForm.PatientId = patientID
  123. signForm.RecordDate = dateTimeStam
  124. signForm.UserOrgId = adminUserInfo.CurrentOrgId
  125. signForm.SignTime = time.Now().Unix()
  126. signForm.Status = 1
  127. signForm.CreatedTime = time.Now().Unix()
  128. signForm.UpdatedTime = time.Now().Unix()
  129. }
  130. signData := make(map[string]interface{}, 0)
  131. err = json.Unmarshal(c.Ctx.Input.RequestBody, &signData)
  132. if err != nil {
  133. //utils.ErrorLog(err.Error())
  134. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamFormatWrong)
  135. }
  136. if signData["dry_weight"] == nil || reflect.TypeOf(signData["dry_weight"]).String() != "string" {
  137. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  138. return
  139. }
  140. dryWeight, _ := strconv.ParseFloat(signData["dry_weight"].(string), 64)
  141. signForm.DryWeight = dryWeight
  142. if signData["clothes_weight"] == nil || reflect.TypeOf(signData["clothes_weight"]).String() != "string" {
  143. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  144. return
  145. }
  146. clothesWeight, _ := strconv.ParseFloat(signData["clothes_weight"].(string), 64)
  147. signForm.ClothingWeight = clothesWeight
  148. if signData["weigh_before"] == nil || reflect.TypeOf(signData["weigh_before"]).String() != "string" {
  149. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  150. return
  151. }
  152. weighBefore, _ := strconv.ParseFloat(signData["weigh_before"].(string), 64)
  153. signForm.WeighingBefore = weighBefore
  154. if signData["dehydrated_weight"] == nil || reflect.TypeOf(signData["dehydrated_weight"]).String() != "string" {
  155. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  156. return
  157. }
  158. dehydratedWeight, _ := strconv.ParseFloat(signData["dehydrated_weight"].(string), 64)
  159. signForm.TargetDewatering = dehydratedWeight
  160. if signData["weight_before"] == nil || reflect.TypeOf(signData["weight_before"]).String() != "string" {
  161. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  162. return
  163. }
  164. weightBefore, _ := strconv.ParseFloat(signData["weight_before"].(string), 64)
  165. signForm.WeightBefore = weightBefore
  166. if signData["temperature_before"] == nil || reflect.TypeOf(signData["temperature_before"]).String() != "string" {
  167. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  168. return
  169. }
  170. temperatureBefore, _ := strconv.ParseFloat(signData["temperature_before"].(string), 64)
  171. signForm.TemperatureBefore = temperatureBefore
  172. if signData["pulse_rate_before"] == nil || reflect.TypeOf(signData["pulse_rate_before"]).String() != "string" {
  173. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  174. return
  175. }
  176. pulseRateBefore, _ := strconv.ParseFloat(signData["pulse_rate_before"].(string), 64)
  177. signForm.PulseFrequencyBefore = pulseRateBefore
  178. if signData["respiratory_rate_before"] == nil || reflect.TypeOf(signData["respiratory_rate_before"]).String() != "string" {
  179. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  180. return
  181. }
  182. respiratoryRateBefore, _ := strconv.ParseFloat(signData["respiratory_rate_before"].(string), 64)
  183. signForm.BreathingRateBefore = respiratoryRateBefore
  184. if signData["DBP_before"] == nil || reflect.TypeOf(signData["DBP_before"]).String() != "string" {
  185. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  186. return
  187. }
  188. DBPBefore, _ := strconv.ParseFloat(signData["DBP_before"].(string), 64)
  189. signForm.DiastolicBloodPressureBefore = DBPBefore
  190. if signData["SBP_before"] == nil || reflect.TypeOf(signData["SBP_before"]).String() != "string" {
  191. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  192. return
  193. }
  194. SBPBefore, _ := strconv.ParseFloat(signData["SBP_before"].(string), 64)
  195. signForm.SystolicBloodPressureBefore = SBPBefore
  196. if signData["weigh_after"] == nil || reflect.TypeOf(signData["weigh_after"]).String() != "string" {
  197. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  198. return
  199. }
  200. weighAfter, _ := strconv.ParseFloat(signData["weigh_after"].(string), 64)
  201. signForm.WeighingAfter = weighAfter
  202. if signData["weight_reduce_after"] == nil || reflect.TypeOf(signData["weight_reduce_after"]).String() != "string" {
  203. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  204. return
  205. }
  206. weightReduceAfter, _ := strconv.ParseFloat(signData["weight_reduce_after"].(string), 64)
  207. signForm.WeightLoss = weightReduceAfter
  208. if signData["weight_after"] == nil || reflect.TypeOf(signData["weight_after"]).String() != "string" {
  209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  210. return
  211. }
  212. weightAfter, _ := strconv.ParseFloat(signData["weight_after"].(string), 64)
  213. signForm.WeightAfter = weightAfter
  214. if signData["temperature_after"] == nil || reflect.TypeOf(signData["temperature_after"]).String() != "string" {
  215. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  216. return
  217. }
  218. temperatureAfter, _ := strconv.ParseFloat(signData["temperature_after"].(string), 64)
  219. signForm.TemperatureAfter = temperatureAfter
  220. if signData["pulse_rate_after"] == nil || reflect.TypeOf(signData["pulse_rate_after"]).String() != "string" {
  221. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  222. return
  223. }
  224. pulseRateAfter, _ := strconv.ParseFloat(signData["pulse_rate_after"].(string), 64)
  225. signForm.PulseFrequencyAfter = pulseRateAfter
  226. if signData["respiratory_rate_after"] == nil || reflect.TypeOf(signData["respiratory_rate_after"]).String() != "string" {
  227. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  228. return
  229. }
  230. respiratoryRateAfter, _ := strconv.ParseFloat(signData["respiratory_rate_after"].(string), 64)
  231. signForm.BreathingRateAfter = respiratoryRateAfter
  232. if signData["DBP_after"] == nil || reflect.TypeOf(signData["DBP_after"]).String() != "string" {
  233. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  234. return
  235. }
  236. DBPAfter, _ := strconv.ParseFloat(signData["DBP_after"].(string), 64)
  237. signForm.DiastolicBloodPressureAfter = DBPAfter
  238. if signData["SBP_after"] == nil || reflect.TypeOf(signData["SBP_after"]).String() != "string" {
  239. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  240. return
  241. }
  242. SBPAfter, _ := strconv.ParseFloat(signData["SBP_after"].(string), 64)
  243. signForm.SystolicBloodPressureAfter = SBPAfter
  244. if signForm.WeighingAfter > 0 {
  245. signForm.WeighTime = time.Now().Unix()
  246. }
  247. if signForm.WeighingBefore > 0 {
  248. signForm.WeighBeforeTime = time.Now().Unix()
  249. }
  250. err = service.EditPatientSign(&signForm)
  251. if err != nil {
  252. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  253. return
  254. }
  255. c.ServeSuccessJSON(map[string]interface{}{
  256. "sign": signForm,
  257. })
  258. return
  259. }
  260. func (c *SignWeighAPIController) GetPatientList() {
  261. patientID, _ := c.GetInt64("patient_id", 0)
  262. fmt.Println("patientID是设么", patientID)
  263. adminUserInfo := c.GetAdminUserInfo()
  264. nowDateTime := time.Now()
  265. nowDate := nowDateTime.Format("2006-01-02")
  266. nowDate += " 00:00:00"
  267. timeLayout := "2006-01-02"
  268. loc, _ := time.LoadLocation("Local")
  269. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", nowDate, loc)
  270. datetime := theTime.Unix()
  271. list := service.GetPatientInformationList(adminUserInfo.CurrentOrgId, patientID, datetime)
  272. c.ServeSuccessJSON(map[string]interface{}{
  273. "patientlist": list,
  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.GetFloat("breathing_rate", 0)
  302. breathing_rate := c.GetString("breathing_rate")
  303. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  304. //breathing_rate, _ := c.GetFloat("breathing_rate", 0)
  305. breathing_rate := c.GetString("breathing_rate")
  306. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  307. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  308. predialysisevaluation := &models.PredialysisEvaluation{
  309. WeightBefore: weight_before,
  310. DryWeight: dry_weight,
  311. Temperature: temperature,
  312. PulseFrequency: pulse_frequency,
  313. BreathingRate: breathing_rate,
  314. SystolicBloodPressure: systolic_blood_pressure,
  315. DiastolicBloodPressure: diastolic_blood_pressure,
  316. }
  317. data := service.SaveData(predialysisevaluation, patient_id, orgId)
  318. c.ServeSuccessJSON(map[string]interface{}{
  319. "params": data,
  320. })
  321. }
  322. func (c *SignWeighAPIController) EditData() {
  323. adminUserInfo := c.GetAdminUserInfo()
  324. orgId := adminUserInfo.CurrentOrgId
  325. patient_id, _ := c.GetInt64("patient_id", 0)
  326. weight_after, _ := c.GetFloat("weight_after", 0)
  327. dry_weight, _ := c.GetFloat("dry_weight", 0)
  328. temperature, _ := c.GetFloat("temperature", 0)
  329. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  330. //breathing_rate, _ := c.GetFloat("breathing_rate", 0)
  331. breathing_rate := c.GetString("breathing_rate")
  332. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  333. //breathing_rate, _ := c.GetFloat("breathing_rate", 0)
  334. breathing_rate := c.GetString("breathing_rate")
  335. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  336. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  337. assessmentafterdislysis := &models.AssessmentAfterDislysis{
  338. WeightAfter: weight_after,
  339. DryWeight: dry_weight,
  340. Temperature: temperature,
  341. PulseFrequency: pulse_frequency,
  342. BreathingRate: breathing_rate,
  343. SystolicBloodPressure: systolic_blood_pressure,
  344. DiastolicBloodPressure: diastolic_blood_pressure,
  345. }
  346. editdata := service.Editdata(assessmentafterdislysis, patient_id, orgId)
  347. c.ServeSuccessJSON(map[string]interface{}{
  348. "params": editdata,
  349. })
  350. }
  351. func (c *SignWeighAPIController) Sighdata() {
  352. patientID, _ := c.GetInt64("patient_id", 0)
  353. fmt.Println("patientID", patientID)
  354. dateTime := c.GetString("date_time")
  355. fmt.Println(patientID, dateTime)
  356. timeLayout := "2006-01-02"
  357. loc, _ := time.LoadLocation("Local")
  358. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", dateTime+" 00:00:00", loc)
  359. if err != nil {
  360. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  361. return
  362. }
  363. dateTimeStam := theTime.Unix()
  364. adminUserInfo := c.GetAdminUserInfo()
  365. sign, errord := service.GetSign(adminUserInfo.CurrentOrgId, dateTimeStam, patientID)
  366. fmt.Println("sign", sign)
  367. fmt.Println(err)
  368. weighbefore, _ := c.GetFloat("weight_before", 0)
  369. dryweightbefore, _ := c.GetFloat("dry_weight", 0)
  370. temperaturebefore, _ := c.GetFloat("temperature", 0)
  371. pulsefrequencybefore, _ := c.GetFloat("pulse_frequency", 0)
  372. breathinratebefore, _ := c.GetFloat("breathing_rate", 0)
  373. systolicbloodpressurebefore, _ := c.GetFloat("systolic_blood_pressure", 0)
  374. diastorlicbloodpressurebefore, _ := c.GetFloat("diastolic_blood_pressure", 0)
  375. weightafter, _ := c.GetFloat("weight_after", 0)
  376. temperatureafter, _ := c.GetFloat("temperatureafter", 0)
  377. pulsefrequencyafter, _ := c.GetFloat("pulse_frequencyafter", 0)
  378. breathingrateafter, _ := c.GetFloat("breathing_rateafter", 0)
  379. systolicbloodpressureafter, _ := c.GetFloat("systolic_blood_pressureafter", 0)
  380. diastolicbloodpressureafter, _ := c.GetFloat("diastolic_blood_pressureafter", 0)
  381. var sighForm models.SignWeight
  382. sighForm.WeightBefore = weighbefore
  383. sighForm.DryWeightBefore = dryweightbefore
  384. sighForm.TemperatureBefore = temperaturebefore
  385. sighForm.PulseFrequencyBefore = pulsefrequencybefore
  386. sighForm.BreathingRateBefore = breathinratebefore
  387. sighForm.SystolicBloodPressureBefore = systolicbloodpressurebefore
  388. sighForm.DiastolicBloodPressureBefore = diastorlicbloodpressurebefore
  389. sighForm.WeightAfter = weightafter
  390. sighForm.TemperatureAfter = temperatureafter
  391. sighForm.PulseFrequencyAfter = pulsefrequencyafter
  392. sighForm.BreathingRateAfter = breathingrateafter
  393. sighForm.SystolicBloodPressureAfter = systolicbloodpressureafter
  394. sighForm.DiastolicBloodPressureAfter = diastolicbloodpressureafter
  395. sighForm.PatientId = patientID
  396. sighForm.RecordDate = dateTimeStam
  397. sighForm.UserOrgId = adminUserInfo.CurrentOrgId
  398. sighForm.SignTime = time.Now().Unix()
  399. sighForm.Status = 1
  400. sighForm.CreatedTime = time.Now().Unix()
  401. if sighForm.WeightBefore > 0 {
  402. sighForm.WeighBeforeTime = time.Now().Unix()
  403. }
  404. if sighForm.WeightAfter > 0 {
  405. sighForm.WeighTime = time.Now().Unix()
  406. }
  407. if errord == gorm.ErrRecordNotFound {
  408. savesignweigh := service.Savesignweigh(&sighForm)
  409. fmt.Println("savesignweight", savesignweigh)
  410. c.ServeSuccessJSON(map[string]interface{}{
  411. "signs": sighForm,
  412. })
  413. } else if errord == nil {
  414. service.Updatesignweigh(&sighForm, patientID, adminUserInfo.CurrentOrgId)
  415. } else {
  416. service.Updatesignweigh(&sighForm, patientID, adminUserInfo.CurrentOrgId)
  417. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  418. }
  419. return
  420. }
  421. func (c *SignWeighAPIController) UpdateSignweight() {
  422. patientID, _ := c.GetInt64("patient_id", 0)
  423. dateTime := c.GetString("date_time")
  424. fmt.Println("病人ID", patientID, dateTime)
  425. timeLayout := "2006-01-02"
  426. loc, _ := time.LoadLocation("Local")
  427. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", dateTime+" 00:00:00", loc)
  428. if err != nil {
  429. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  430. return
  431. }
  432. dateTimeStam := theTime.Unix()
  433. fmt.Println("datatimestam是什么", dateTimeStam)
  434. adminUserInfo := c.GetAdminUserInfo()
  435. fmt.Println(adminUserInfo.CurrentOrgId, dateTimeStam, patientID)
  436. //透前
  437. weight_before, _ := c.GetFloat("weight_before", 0)
  438. dry_weight, _ := c.GetFloat("dry_weight", 0)
  439. temperature, _ := c.GetFloat("temperature", 0)
  440. fmt.Println("温度", temperature)
  441. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  442. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  443. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  444. fmt.Println("dry_weight", dry_weight)
  445. var predialysisevaluation models.PredialysisEvaluation
  446. predialysisevaluation.PatientId = patientID
  447. predialysisevaluation.UserOrgId = adminUserInfo.CurrentOrgId
  448. predialysisevaluation.AssessmentDate = dateTimeStam
  449. predialysisevaluation.WeightBefore = weight_before
  450. predialysisevaluation.DryWeight = dry_weight
  451. predialysisevaluation.Temperature = temperature
  452. predialysisevaluation.PulseFrequency = pulse_frequency
  453. predialysisevaluation.SystolicBloodPressure = systolic_blood_pressure
  454. predialysisevaluation.DiastolicBloodPressure = diastolic_blood_pressure
  455. predialysisevaluation.CreatedTime = time.Now().Unix()
  456. predialysisevaluation.Status = 1
  457. predialysis, errcode := service.GetDislysisBerfore(adminUserInfo.CurrentOrgId, dateTimeStam, patientID)
  458. fmt.Println("sigh", predialysis)
  459. fmt.Println("错误:", errcode)
  460. if errcode == gorm.ErrRecordNotFound {
  461. service.SaveDislysisiBefore(&predialysisevaluation)
  462. } else if errcode == nil {
  463. service.UpdataDislysisiBefore(&predialysisevaluation, patientID, adminUserInfo.CurrentOrgId, dateTimeStam)
  464. } else {
  465. service.UpdataDislysisiBefore(&predialysisevaluation, patientID, adminUserInfo.CurrentOrgId, dateTimeStam)
  466. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  467. }
  468. //透后
  469. weight_after, _ := c.GetFloat("weight_after", 0)
  470. temperatureafter, _ := c.GetFloat("temperatureafter", 0)
  471. pulsefrequencyafter, _ := c.GetFloat("pulse_frequencyafter", 0)
  472. systolicbloodpressureafter, _ := c.GetFloat("systolic_blood_pressureafter", 0)
  473. diastolicbloodpressureafter, _ := c.GetFloat("diastolic_blood_pressureafter", 0)
  474. var assessmentafterdislysis models.AssessmentAfterDislysis
  475. assessmentafterdislysis.PatientId = patientID
  476. assessmentafterdislysis.UserOrgId = adminUserInfo.CurrentOrgId
  477. assessmentafterdislysis.AssessmentDate = dateTimeStam
  478. assessmentafterdislysis.WeightAfter = weight_after
  479. assessmentafterdislysis.Temperature = temperatureafter
  480. assessmentafterdislysis.PulseFrequency = pulsefrequencyafter
  481. assessmentafterdislysis.SystolicBloodPressure = systolicbloodpressureafter
  482. assessmentafterdislysis.DiastolicBloodPressure = diastolicbloodpressureafter
  483. assessmentafterdislysis.CreatedTime = time.Now().Unix()
  484. assessmentafterdislysis.Status = 1
  485. dislysis, errcoder := service.GetAssessmentaafterdislysis(adminUserInfo.CurrentOrgId, dateTimeStam, patientID)
  486. fmt.Println("sigh", dislysis)
  487. fmt.Println("错误装太:", errcoder)
  488. if errcoder == gorm.ErrRecordNotFound {
  489. service.SaveAssessmentafter(&assessmentafterdislysis)
  490. c.ServeSuccessJSON(map[string]interface{}{
  491. "signs": predialysisevaluation,
  492. })
  493. } else if errcoder == nil {
  494. service.UpdataAssessment(&assessmentafterdislysis, patientID, adminUserInfo.CurrentOrgId, dateTimeStam)
  495. c.ServeSuccessJSON(map[string]interface{}{
  496. "signs": predialysisevaluation,
  497. })
  498. } else {
  499. service.UpdataAssessment(&assessmentafterdislysis, patientID, adminUserInfo.CurrentOrgId, dateTimeStam)
  500. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  501. }
  502. }
  503. //func (c *SignWeighAPIController) GetForenoonData() {
  504. // nowDateTime := time.Now()
  505. // nowDate := nowDateTime.Format("2006-01-02")
  506. // nowDate += " 00:00:00"
  507. // timeLayout := "2006-01-02"
  508. // loc, _ := time.LoadLocation("Local")
  509. // theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", nowDate, loc)
  510. // datetime := theTime.Unix()
  511. // fmt.Println("hhhhhhhhhhhhhhhhhhh")
  512. // fmt.Println("datetime",datetime)
  513. // adminUserInfo := c.GetAdminUserInfo()
  514. // orgId := adminUserInfo.CurrentOrgId
  515. // fmt.Println("orgid是什么",orgId)
  516. // total, schedule, err := service.GetForenoonData(datetime, orgId, 1)
  517. // fmt.Println("total",total)
  518. // fmt.Println("schedule",schedule)
  519. // if err != nil {
  520. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  521. // return
  522. // }
  523. //
  524. // c.ServeSuccessJSON(map[string]interface{}{
  525. // "total": total,
  526. // })
  527. //
  528. //}