doctors_api_controller.go 7.0KB

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