doctors_api_controller.go 8.2KB

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