doctors_api_controller.go 8.4KB

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