doctors_api_controller.go 9.4KB

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