doctors_api_controller.go 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. package controllers
  2. import (
  3. "XT_New/service"
  4. "XT_New/models"
  5. "XT_New/utils"
  6. "fmt"
  7. "github.com/astaxie/beego"
  8. "github.com/jinzhu/gorm"
  9. "time"
  10. )
  11. type DoctorsApiController struct {
  12. BaseAuthAPIController
  13. }
  14. func DoctorApiRegistRouters() {
  15. beego.Router("/api/alldoctors", &DoctorsApiController{}, "get:GetAllDoctorAndNurse")
  16. beego.Router("/api/admin/users", &DoctorsApiController{}, "get:GetAllAdminUsers")
  17. beego.Router("/api/patient/getdryweightdata", &DoctorsApiController{}, "Get:GetDryWeightData")
  18. beego.Router("/api/patient/getAllDoctor", &DoctorsApiController{}, "Get:GetAllDoctor")
  19. beego.Router("/api/patient/updatedryweightdata", &DoctorsApiController{}, "Post:UpdatedDryWeightData")
  20. beego.Router("/api/patient/getalldata", &DoctorsApiController{}, "Get:GetAllData")
  21. }
  22. func (c *DoctorsApiController) GetAllDoctorAndNurse() {
  23. adminUserInfo := c.GetAdminUserInfo()
  24. doctors, nursers, _ := service.GetAllDoctorAndNurse(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  25. c.ServeSuccessJSON(map[string]interface{}{
  26. "doctors": doctors,
  27. "nursers": nursers,
  28. })
  29. return
  30. }
  31. func (c *DoctorsApiController) GetAllAdminUsers() {
  32. adminUserInfo := c.GetAdminUserInfo()
  33. users, _ := service.GetAllAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  34. c.ServeSuccessJSON(map[string]interface{}{
  35. "users": users,
  36. })
  37. return
  38. }
  39. func (c *DoctorsApiController) GetDryWeightData() {
  40. adminUserInfo := c.GetAdminUserInfo()
  41. orgid := adminUserInfo.CurrentOrgId
  42. patientid, _ := c.GetInt64("patientid")
  43. fmt.Println("patientid", patientid)
  44. id := adminUserInfo.AdminUser.Id
  45. fmt.Println("id", id)
  46. recordDateStr := time.Now().Format("2006-01-02")
  47. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  48. fmt.Scan("parseDateErr", parseDateErr)
  49. nowtime := recordDate.Unix()
  50. fmt.Println("nowtime", nowtime)
  51. pre, err := service.GetDryWeightByPatientId(patientid, orgid)
  52. fmt.Println("错误", err)
  53. c.ServeSuccessJSON(map[string]interface{}{
  54. "pre": pre,
  55. })
  56. }
  57. func (c *DoctorsApiController) GetAllDoctor() {
  58. adminUserInfo := c.GetAdminUserInfo()
  59. orgid := adminUserInfo.CurrentOrgId
  60. appid := adminUserInfo.CurrentAppId
  61. fmt.Println("appid", appid)
  62. appRole, err := service.GetAllDoctor(orgid, appid)
  63. fmt.Println("appRole", appRole)
  64. fmt.Println("错误", err)
  65. c.ServeSuccessJSON(map[string]interface{}{
  66. "appRole": appRole,
  67. })
  68. }
  69. func (c *DoctorsApiController) UpdatedDryWeightData() {
  70. adminUserInfo := c.GetAdminUserInfo()
  71. orgid := adminUserInfo.CurrentOrgId
  72. userid := adminUserInfo.AdminUser.Id
  73. fmt.Println("userid", userid)
  74. dry_weight, _ := c.GetFloat("dry_weight")
  75. fmt.Println("dry_weight", dry_weight)
  76. doctors, _ := c.GetInt64("doctors")
  77. fmt.Println("doctors", doctors)
  78. remarks := c.GetString("remarks")
  79. fmt.Println("remarks", remarks)
  80. patientid, _ := c.GetInt64("patient_id")
  81. fmt.Println("patientid", patientid)
  82. //透前数据
  83. dryweight, _ := c.GetFloat("dryweight")
  84. fmt.Println("dryweight", dryweight)
  85. var weight = dryweight - dry_weight
  86. weights := fmt.Sprintf("%.1f", weight)
  87. //weights := strconv.FormatFloat(sprintf, 'E', -1, 64)
  88. fmt.Println("weight", weights)
  89. fmt.Println("weight", weight)
  90. var sum string
  91. dryWeight, errcode := service.QueryDryWeight(orgid, patientid)
  92. fmt.Println("errcode", errcode)
  93. fmt.Println("dryWeight", dryWeight)
  94. if errcode == gorm.ErrRecordNotFound {
  95. sum = "/"
  96. patientDryweight := models.SgjPatientDryweight{
  97. DryWeight: dry_weight,
  98. Creator: doctors,
  99. Remakes: remarks,
  100. AdjustedValue: sum,
  101. PatientId: patientid,
  102. Ctime: time.Now().Unix(),
  103. UserOrgId: orgid,
  104. Status: 1,
  105. UserId: userid,
  106. }
  107. err := service.CreatePatientWeight(&patientDryweight)
  108. fmt.Println("err", err)
  109. c.ServeSuccessJSON(map[string]interface{}{
  110. "patientDryweight": patientDryweight,
  111. })
  112. return
  113. }
  114. fmt.Println("sum", sum)
  115. if weight == 0 {
  116. sum = "/"
  117. }
  118. if weight > 0 {
  119. sum = weights + "(" + "下调" + ")"
  120. }
  121. if weight < 0 {
  122. var sums = dry_weight - dryweight
  123. float := fmt.Sprintf("%.1f", sums)
  124. //float := strconv.FormatFloat(sums, 'E', -1, 64)
  125. sum = float + "(" + "上调" + ")"
  126. }
  127. patientDryweight := models.SgjPatientDryweight{
  128. DryWeight: dry_weight,
  129. Creator: doctors,
  130. Remakes: remarks,
  131. AdjustedValue: sum,
  132. PatientId: patientid,
  133. Ctime: time.Now().Unix(),
  134. UserOrgId: orgid,
  135. Status: 1,
  136. UserId: userid,
  137. }
  138. err := service.CreatePatientWeight(&patientDryweight)
  139. //sgjPatientDryweight, _ := service.GetLastData(orgid)
  140. //fmt.Println("fffffffffffffffffffffffffffffffffffffffffffff")
  141. //fmt.Println("sgjPatientDryWeight",sgjPatientDryweight)s
  142. recordDateStr := time.Now().Format("2006-01-02")
  143. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  144. fmt.Scan("parseDateErr", parseDateErr)
  145. nowtime := recordDate.Unix()
  146. fmt.Println("nowtime", nowtime)
  147. //prescription := models.PredialysisEvaluation{
  148. // DryWeight: dryweight,
  149. //}
  150. //errors := service.UpdateDialysisPrescription( sgjPatientDryweight.PatientId, sgjPatientDryweight.UserOrgId, sgjPatientDryweight.DryWeight, prescription)
  151. //fmt.Println("error",errors)
  152. fmt.Println("err", err)
  153. fmt.Println("patientdryweight", patientDryweight)
  154. c.ServeSuccessJSON(map[string]interface{}{
  155. "patientDryweight": patientDryweight,
  156. })
  157. }
  158. func (c *DoctorsApiController) GetAllData() {
  159. id, _ := c.GetInt64("id")
  160. page, _ := c.GetInt64("page")
  161. fmt.Println("page", page)
  162. limit, _ := c.GetInt64("limit")
  163. fmt.Println("limit", limit)
  164. fmt.Println("id", id)
  165. adminUserInfo := c.GetAdminUserInfo()
  166. orgid := adminUserInfo.CurrentOrgId
  167. dry, total, err := service.GetAllData(orgid, id, page, limit)
  168. fmt.Println("total是是多少", total)
  169. fmt.Println("错误是什么", err)
  170. fmt.Println("dry", err)
  171. c.ServeSuccessJSON(map[string]interface{}{
  172. "dry": dry,
  173. "total": total,
  174. })
  175. }