doctors_api_controller.go 8.5KB

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