doctors_api_controller.go 8.3KB

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