sign_weigh_api_controller.go 21KB

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