xcx_api_controller.go 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. package xcx_mobile_api_controller_go
  2. import (
  3. "Xcx_New/controllers/mobile_api_controllers"
  4. "Xcx_New/enums"
  5. "Xcx_New/models"
  6. "Xcx_New/service"
  7. "Xcx_New/utils"
  8. "fmt"
  9. "github.com/astaxie/beego"
  10. "github.com/jinzhu/gorm"
  11. "strconv"
  12. "time"
  13. )
  14. func XcxApiControllersRegisterRouters() {
  15. ////传送codeinit
  16. beego.Router("/xcx/m/api/code", &XcxApiController{}, "Get:GetCodeInit")
  17. //获取验证码
  18. beego.Router("/xcx/api/mobile/code", &XcxApiController{}, "Get:GetCodeInfo")
  19. //用户绑定
  20. beego.Router("/xcx/api/mobile/register", &XcxApiController{}, "Get:GetUserRegister")
  21. //登录
  22. beego.Router("/xcx/api/mobile/login", &XcxApiController{}, "Get:GetLoginInfor")
  23. //获取二维码信息
  24. beego.Router("/xcx/api/mobile/patient", &XcxApiController{}, "Get:GetPatientList")
  25. //获取登录后的信息
  26. beego.Router("/xcx/api/mobile/getdatainfo", &XcxApiController{}, "Get:GetDataInfo")
  27. //获取排班数据
  28. beego.Router("/xcx/api/mobile/schedule", &XcxApiController{}, "Get:GetScheduleInfo")
  29. //获取透析记录
  30. beego.Router("/xcx/api/mobile/dialysis", &XcxApiController{}, "Get:GetMobileSchedule")
  31. //获取患者的电子病历
  32. beego.Router("/xcx/api/mobile/getpatientinfo", &XcxApiController{}, "Get:GetPatientInfo")
  33. //获取机构名称
  34. beego.Router("/xcx/api/mobile/getorginfo", &XcxApiController{}, "Get:GetOrgInfo")
  35. }
  36. type XcxApiController struct {
  37. mobile_api_controllers.MobileBaseAPIController
  38. }
  39. func (this *XcxApiController) GetCodeInit() {
  40. redisClient := service.RedisClient()
  41. defer redisClient.Close()
  42. req := this.Ctx.Request
  43. addr := utils.GetIP(req)
  44. cur_time := time.Now().Format("2006-01-02")
  45. _, err := redisClient.Get("ip:host_" + cur_time + "_" + addr).Result()
  46. if err != nil {
  47. redisClient.Set("ip:host_"+cur_time+"_"+addr, 0, time.Second*24*60*60)
  48. }
  49. //将客户端的ip加密传给前端,作为短信验证的密钥,来验证短信发送的IP地址
  50. aespass := utils.AESEncrypt(addr)
  51. fmt.Println("hhhhhhh3223323232332", aespass)
  52. this.ServeSuccessJSON(map[string]interface{}{
  53. "aespass": aespass,
  54. })
  55. }
  56. func (this *XcxApiController) GetUserRegister() {
  57. //用户绑定
  58. name := this.GetString("name")
  59. id_card_no := this.GetString("id_card_no")
  60. fmt.Println("id_card_no", id_card_no)
  61. mobile := this.GetString("mobile")
  62. code := this.GetString("code")
  63. patient, errcodes := service.GetMobilePatient(id_card_no)
  64. fmt.Println("errcodes2323232232", errcodes)
  65. if errcodes == nil {
  66. role := models.XcxAdminUserRole{
  67. PatientName: name,
  68. IdCardNo: id_card_no,
  69. Mobile: mobile,
  70. Code: code,
  71. PatientId: patient.ID,
  72. UserOrgId: patient.UserOrgId,
  73. Status: 1,
  74. Ctime: time.Now().Unix(),
  75. Mtime: 0,
  76. Appid: "",
  77. Appsecret: "",
  78. SessionKey: "",
  79. }
  80. //查找该电话号码是否存在
  81. _, errcode := service.GetMobilePatient(mobile)
  82. if errcode == gorm.ErrRecordNotFound {
  83. err := service.CreateXcxAdminUser(role)
  84. if err == nil {
  85. mobilePatient, _ := service.GetMobilePatient(id_card_no)
  86. this.ServeSuccessJSON(map[string]interface{}{
  87. "role": role,
  88. "is_bind": true,
  89. "patient": mobilePatient,
  90. })
  91. } else {
  92. this.ServeSuccessJSON(map[string]interface{}{
  93. "is_bind": false,
  94. "msg": "绑定失败",
  95. })
  96. }
  97. } else if errcode == nil {
  98. mobilePatient, _ := service.GetMobilePatient(id_card_no)
  99. this.ServeSuccessJSON(map[string]interface{}{
  100. "is_bind": true,
  101. "patient": mobilePatient,
  102. })
  103. }
  104. fmt.Println("roler", role)
  105. } else if errcodes == gorm.ErrRecordNotFound {
  106. this.ServeSuccessJSON(map[string]interface{}{
  107. "is_bind": false,
  108. })
  109. }
  110. }
  111. func (this *XcxApiController) GetCodeInfo() {
  112. //mobile := this.GetString("phone")
  113. //aespass := this.GetString("aespass")
  114. //utils.TraceLog("mobile:%v aespass:%v", mobile, aespass)
  115. //if utils.CellPhoneRegexp().MatchString(mobile) == false {
  116. // this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeMobileFormat)
  117. // this.ServeJSON()
  118. // return
  119. //}
  120. //if err := service.SendVerificationCodeSMS(mobile, aespass); err != nil {
  121. // this.Data["json"] = enums.MakeFailResponseJSON(err.Error(), 600)
  122. // this.ServeJSON()
  123. //} else {
  124. // this.Data["json"] = enums.MakeSuccessResponseJSON(map[string]interface{}{
  125. // "msg": "短信发送成功,有效期为10分钟",
  126. //
  127. // })
  128. // this.ServeJSON()
  129. //}
  130. this.ServeSuccessJSON(map[string]interface{}{
  131. "code": "100100",
  132. })
  133. }
  134. func (this *XcxApiController) GetLoginInfor() {
  135. mobile := this.GetString("mobile")
  136. fmt.Println(mobile)
  137. user_admin, errcodes := service.GetXcxMobileInformation(mobile)
  138. if errcodes == gorm.ErrRecordNotFound {
  139. info, _ := service.GetMobilePatientInfo(mobile)
  140. this.ServeSuccessJSON(map[string]interface{}{
  141. "patient": info,
  142. "role": user_admin,
  143. "is_bind": false,
  144. })
  145. } else if errcodes == nil {
  146. info, _ := service.GetPatientListByPatientId(user_admin.PatientId)
  147. this.ServeSuccessJSON(map[string]interface{}{
  148. "patient": info,
  149. "role": user_admin,
  150. "is_bind": true,
  151. })
  152. }
  153. }
  154. func (this *XcxApiController) GetPatientList() {
  155. appid := "wx20b60369111b063a"
  156. key := "Yz1HgsFX3yJvWPJSEdwJDA=="
  157. strs := "uSevGQ5ShkiHjQuqz7s36SKZisVGA4fHH/dy+etg0W7ibVeidl6TyFS+kQZ6B9AI2T+1kOtKXeyveQR7q2TXJdu3fhKCFoLKVFzICNEvkiHMnchJ0T0OpRO3oT+icYq80+egvT+jMSgP7yi0cAgmiKaK/4QURD7+nvxRAj9drzz77sbeFt8KElb1LN/+Wn8dIoQzisxbON9G1VJYYtyBkQ=="
  158. iv := "JgsbDhJ613uaAgAoBVh0Zw=="
  159. //data, err := service.Dncrypt(strs, key, iv)
  160. //fmt.Println(err)
  161. data, err := service.DecryptData(appid, key, iv, strs)
  162. patient_id, _ := this.GetInt64("patient_id")
  163. patient, err := service.GetPatientListByPatientId(patient_id)
  164. if err == nil {
  165. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  166. return
  167. }
  168. this.ServeSuccessJSON(map[string]interface{}{
  169. "patient": patient,
  170. "data": data,
  171. })
  172. }
  173. func (this *XcxApiController) GetDataInfo() {
  174. appid := this.GetString("appid")
  175. fmt.Println(appid)
  176. key := this.GetString("key")
  177. iv := this.GetString("iv")
  178. encryptedData := this.GetString("encryptedData")
  179. list, _ := service.DecryptData(appid, key, iv, encryptedData)
  180. //list, _ := service.Dncrypt(encryptedData, key, iv)
  181. this.ServeSuccessJSON(map[string]interface{}{
  182. "list": list,
  183. })
  184. }
  185. func (this *XcxApiController) GetScheduleInfo() {
  186. patient_id, _ := this.GetInt64("patient_id")
  187. fmt.Println(patient_id)
  188. thisWeekMonday := service.GetFirstDateOfWeek()
  189. weekDayWeek := service.GetWeekDayOfWeek()
  190. TimeMonday, _ := time.Parse("2006-01-02", thisWeekMonday)
  191. weekDays, _ := time.Parse("2006-01-02", weekDayWeek)
  192. lastWeekMonday := TimeMonday.AddDate(0, 0, -7)
  193. nextWeekMonday := weekDays.AddDate(0, 0, +13)
  194. var weekMonday = lastWeekMonday.Format("2006-01-02")
  195. var weekDay = nextWeekMonday.Format("2006-01-02")
  196. fmt.Println("weekmodonday", weekMonday)
  197. fmt.Println("nextweeekday", weekDay)
  198. timeLayout := "2006-01-02"
  199. loc, _ := time.LoadLocation("Local")
  200. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", weekMonday+" 00:00:00", loc)
  201. fmt.Println("startiem", startTime)
  202. endTime, _ := time.ParseInLocation(timeLayout+"15:04:05", weekDay+"00:00:00", loc)
  203. fmt.Println(startTime.Unix(), endTime.Unix())
  204. schedule, err := service.GetScheduleInfo(startTime.Unix(), endTime.Unix(), patient_id)
  205. //获取当前今日的排班日期
  206. time_now := time.Now().Format("2006-01-02")
  207. fmt.Println("time_now", time_now)
  208. timeNowUnix, _ := time.ParseInLocation(timeLayout+"15:04:05", time_now+"00:00:00", loc)
  209. fmt.Println("timeNowUnix", timeNowUnix.Unix())
  210. //获取今日下机日期
  211. order, _ := service.GetTodayDialysis(timeNowUnix.Unix(), patient_id)
  212. //获取下一次排班信息
  213. patientSchedule, _ := service.GetNextPatientSchedule(1, timeNowUnix.Unix())
  214. if err != nil {
  215. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  216. return
  217. }
  218. var one = startTime.Unix() + 86400
  219. fmt.Println("one2322332", one)
  220. var two = one + 86400
  221. var three = two + 86400
  222. var four = three + 86400
  223. var five = four + 86400
  224. var six = five + 86400
  225. var seven = six + 86400
  226. var nextOne = seven + 86400
  227. var nexttwo = nextOne + 86400
  228. var nextthree = nexttwo + 86400
  229. var nextfour = nextthree + 86400
  230. var nextfive = nextfour + 86400
  231. var nextsix = nextfive + 86400
  232. var nextseven = nextsix + 86400
  233. var lastOne = nextseven + 86400
  234. var lastwo = lastOne + 86400
  235. var lasthree = lastwo + 86400
  236. var lastfour = lasthree + 86400
  237. var lastfive = lastfour + 86400
  238. var lastsix = lastfive + 86400
  239. var lastseven = lastsix + 86400
  240. fmt.Println("各地好当家232332323232", lastseven)
  241. array := []interface{}{
  242. map[string]string{"schedule_type": "1", "schedule_date": strconv.FormatInt(one, 10), "schedule_week": "1", "mode_id": "", "name": ""},
  243. map[string]string{"schedule_type": "2", "schedule_date": strconv.FormatInt(one, 10), "schedule_week": "1", "mode_id": "", "name": ""},
  244. map[string]string{"schedule_type": "3", "schedule_date": strconv.FormatInt(one, 10), "schedule_week": "1", "mode_id": "", "name": ""},
  245. map[string]string{"schedule_type": "1", "schedule_date": strconv.FormatInt(two, 10), "schedule_week": "2", "mode_id": "", "name": ""},
  246. map[string]string{"schedule_type": "2", "schedule_date": strconv.FormatInt(two, 10), "schedule_week": "2", "mode_id": "", "name": ""},
  247. map[string]string{"schedule_type": "3", "schedule_date": strconv.FormatInt(two, 10), "schedule_week": "2", "mode_id": "", "name": ""},
  248. map[string]string{"schedule_type": "1", "schedule_date": strconv.FormatInt(three, 10), "schedule_week": "3", "mode_id": "", "name": ""},
  249. map[string]string{"schedule_type": "2", "schedule_date": strconv.FormatInt(three, 10), "schedule_week": "3", "mode_id": "", "name": ""},
  250. map[string]string{"schedule_type": "3", "schedule_date": strconv.FormatInt(three, 10), "schedule_week": "3", "mode_id": "", "name": ""},
  251. map[string]string{"schedule_type": "1", "schedule_date": strconv.FormatInt(four, 10), "schedule_week": "4", "mode_id": "", "name": ""},
  252. map[string]string{"schedule_type": "2", "schedule_date": strconv.FormatInt(four, 10), "schedule_week": "4", "mode_id": "", "name": ""},
  253. map[string]string{"schedule_type": "3", "schedule_date": strconv.FormatInt(four, 10), "schedule_week": "4", "mode_id": "", "name": ""},
  254. map[string]string{"schedule_type": "1", "schedule_date": strconv.FormatInt(five, 10), "schedule_week": "5", "mode_id": "", "name": ""},
  255. map[string]string{"schedule_type": "2", "schedule_date": strconv.FormatInt(five, 10), "schedule_week": "5", "mode_id": "", "name": ""},
  256. map[string]string{"schedule_type": "3", "schedule_date": strconv.FormatInt(five, 10), "schedule_week": "5", "mode_id": "", "name": ""},
  257. map[string]string{"schedule_type": "1", "schedule_date": strconv.FormatInt(six, 10), "schedule_week": "6", "mode_id": "", "name": ""},
  258. map[string]string{"schedule_type": "2", "schedule_date": strconv.FormatInt(six, 10), "schedule_week": "6", "mode_id": "", "name": ""},
  259. map[string]string{"schedule_type": "3", "schedule_date": strconv.FormatInt(six, 10), "schedule_week": "6", "mode_id": "", "name": ""},
  260. map[string]string{"schedule_type": "1", "schedule_date": strconv.FormatInt(seven, 10), "schedule_week": "7", "mode_id": "", "name": ""},
  261. map[string]string{"schedule_type": "2", "schedule_date": strconv.FormatInt(seven, 10), "schedule_week": "7", "mode_id": "", "name": ""},
  262. map[string]string{"schedule_type": "3", "schedule_date": strconv.FormatInt(seven, 10), "schedule_week": "7", "mode_id": "", "name": ""},
  263. map[string]string{"schedule_type": "1", "schedule_date": strconv.FormatInt(nextOne, 10), "schedule_week": "1", "mode_id": "", "name": ""},
  264. map[string]string{"schedule_type": "2", "schedule_date": strconv.FormatInt(nextOne, 10), "schedule_week": "1", "mode_id": "", "name": ""},
  265. map[string]string{"schedule_type": "3", "schedule_date": strconv.FormatInt(nextOne, 10), "schedule_week": "1", "mode_id": "", "name": ""},
  266. map[string]string{"schedule_type": "1", "schedule_date": strconv.FormatInt(nexttwo, 10), "schedule_week": "2", "mode_id": "", "name": ""},
  267. map[string]string{"schedule_type": "2", "schedule_date": strconv.FormatInt(nexttwo, 10), "schedule_week": "2", "mode_id": "", "name": ""},
  268. map[string]string{"schedule_type": "3", "schedule_date": strconv.FormatInt(nexttwo, 10), "schedule_week": "2", "mode_id": "", "name": ""},
  269. map[string]string{"schedule_type": "1", "schedule_date": strconv.FormatInt(nextthree, 10), "schedule_week": "3", "mode_id": "", "name": ""},
  270. map[string]string{"schedule_type": "2", "schedule_date": strconv.FormatInt(nextthree, 10), "schedule_week": "3", "mode_id": "", "name": ""},
  271. map[string]string{"schedule_type": "3", "schedule_date": strconv.FormatInt(nextthree, 10), "schedule_week": "3", "mode_id": "", "name": ""},
  272. map[string]string{"schedule_type": "1", "schedule_date": strconv.FormatInt(nextfour, 10), "schedule_week": "4", "mode_id": "", "name": ""},
  273. map[string]string{"schedule_type": "2", "schedule_date": strconv.FormatInt(nextfour, 10), "schedule_week": "4", "mode_id": "", "name": ""},
  274. map[string]string{"schedule_type": "3", "schedule_date": strconv.FormatInt(nextfour, 10), "schedule_week": "4", "mode_id": "", "name": ""},
  275. map[string]string{"schedule_type": "1", "schedule_date": strconv.FormatInt(nextfive, 10), "schedule_week": "5", "mode_id": "", "name": ""},
  276. map[string]string{"schedule_type": "2", "schedule_date": strconv.FormatInt(nextfive, 10), "schedule_week": "5", "mode_id": "", "name": ""},
  277. map[string]string{"schedule_type": "3", "schedule_date": strconv.FormatInt(nextfive, 10), "schedule_week": "5", "mode_id": "", "name": ""},
  278. map[string]string{"schedule_type": "1", "schedule_date": strconv.FormatInt(nextsix, 10), "schedule_week": "6", "mode_id": "", "name": ""},
  279. map[string]string{"schedule_type": "2", "schedule_date": strconv.FormatInt(nextsix, 10), "schedule_week": "6", "mode_id": "", "name": ""},
  280. map[string]string{"schedule_type": "3", "schedule_date": strconv.FormatInt(nextsix, 10), "schedule_week": "6", "mode_id": "", "name": ""},
  281. map[string]string{"schedule_type": "1", "schedule_date": strconv.FormatInt(nextseven, 10), "schedule_week": "7", "mode_id": "", "name": ""},
  282. map[string]string{"schedule_type": "2", "schedule_date": strconv.FormatInt(nextseven, 10), "schedule_week": "7", "mode_id": "", "name": ""},
  283. map[string]string{"schedule_type": "3", "schedule_date": strconv.FormatInt(nextseven, 10), "schedule_week": "7", "mode_id": "", "name": ""},
  284. map[string]string{"schedule_type": "1", "schedule_date": strconv.FormatInt(lastOne, 10), "schedule_week": "1", "mode_id": "", "name": ""},
  285. map[string]string{"schedule_type": "2", "schedule_date": strconv.FormatInt(lastOne, 10), "schedule_week": "1", "mode_id": "", "name": ""},
  286. map[string]string{"schedule_type": "3", "schedule_date": strconv.FormatInt(lastOne, 10), "schedule_week": "1", "mode_id": "", "name": ""},
  287. map[string]string{"schedule_type": "1", "schedule_date": strconv.FormatInt(lastwo, 10), "schedule_week": "2", "mode_id": "", "name": ""},
  288. map[string]string{"schedule_type": "2", "schedule_date": strconv.FormatInt(lastwo, 10), "schedule_week": "2", "mode_id": "", "name": ""},
  289. map[string]string{"schedule_type": "3", "schedule_date": strconv.FormatInt(lastwo, 10), "schedule_week": "2", "mode_id": "", "name": ""},
  290. map[string]string{"schedule_type": "1", "schedule_date": strconv.FormatInt(lasthree, 10), "schedule_week": "3", "mode_id": "", "name": ""},
  291. map[string]string{"schedule_type": "2", "schedule_date": strconv.FormatInt(lasthree, 10), "schedule_week": "3", "mode_id": "", "name": ""},
  292. map[string]string{"schedule_type": "3", "schedule_date": strconv.FormatInt(lasthree, 10), "schedule_week": "3", "mode_id": "", "name": ""},
  293. map[string]string{"schedule_type": "1", "schedule_date": strconv.FormatInt(lastfour, 10), "schedule_week": "4", "mode_id": "", "name": ""},
  294. map[string]string{"schedule_type": "2", "schedule_date": strconv.FormatInt(lastfour, 10), "schedule_week": "4", "mode_id": "", "name": ""},
  295. map[string]string{"schedule_type": "3", "schedule_date": strconv.FormatInt(lastfour, 10), "schedule_week": "4", "mode_id": "", "name": ""},
  296. map[string]string{"schedule_type": "1", "schedule_date": strconv.FormatInt(lastfive, 10), "schedule_week": "5", "mode_id": "", "name": ""},
  297. map[string]string{"schedule_type": "2", "schedule_date": strconv.FormatInt(lastfive, 10), "schedule_week": "5", "mode_id": "", "name": ""},
  298. map[string]string{"schedule_type": "3", "schedule_date": strconv.FormatInt(lastfive, 10), "schedule_week": "5", "mode_id": "", "name": ""},
  299. map[string]string{"schedule_type": "1", "schedule_date": strconv.FormatInt(lastsix, 10), "schedule_week": "6", "mode_id": "", "name": ""},
  300. map[string]string{"schedule_type": "2", "schedule_date": strconv.FormatInt(lastsix, 10), "schedule_week": "6", "mode_id": "", "name": ""},
  301. map[string]string{"schedule_type": "3", "schedule_date": strconv.FormatInt(lastsix, 10), "schedule_week": "6", "mode_id": "", "name": ""},
  302. map[string]string{"schedule_type": "1", "schedule_date": strconv.FormatInt(lastseven, 10), "schedule_week": "7", "mode_id": "", "name": ""},
  303. map[string]string{"schedule_type": "2", "schedule_date": strconv.FormatInt(lastseven, 10), "schedule_week": "7", "mode_id": "", "name": ""},
  304. map[string]string{"schedule_type": "3", "schedule_date": strconv.FormatInt(lastseven, 10), "schedule_week": "7", "mode_id": "", "name": ""},
  305. }
  306. this.ServeSuccessJSON(map[string]interface{}{
  307. "list": schedule,
  308. "array": array,
  309. "order": order,
  310. "patientSchedule": patientSchedule,
  311. })
  312. }
  313. func (this *XcxApiController) GetMobileSchedule() {
  314. patientID, _ := this.GetInt64("patient_id")
  315. recordDateStr := this.GetString("date")
  316. if patientID <= 0 {
  317. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  318. return
  319. }
  320. if len(recordDateStr) == 0 {
  321. recordDateStr = time.Now().Format("2006-01-02")
  322. }
  323. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  324. if parseDateErr != nil {
  325. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  326. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  327. return
  328. }
  329. adminInfo := this.GetMobileAdminUserInfo()
  330. patient, getPatientErr := service.MobileGetPatientDetail(adminInfo.Org.Id, patientID)
  331. if getPatientErr != nil {
  332. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  333. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  334. return
  335. } else if patient == nil {
  336. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  337. return
  338. }
  339. schedual, getSchedualErr := service.MobileGetSchedualDetail(adminInfo.Org.Id, patientID, date.Unix())
  340. if getSchedualErr != nil {
  341. this.ErrorLog("获取患者排班信息失败:%v", getSchedualErr)
  342. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  343. return
  344. }
  345. receiverTreatmentAccess, getRTARErr := service.MobileGetReceiverTreatmentAccessRecord(adminInfo.Org.Id, patientID, date.Unix())
  346. if getRTARErr != nil {
  347. this.ErrorLog("获取接诊评估失败:%v", getRTARErr)
  348. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  349. return
  350. }
  351. predialysisEvaluation, getPEErr := service.MobileGetPredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  352. if getPEErr != nil {
  353. this.ErrorLog("获取透前评估失败:%v", getPEErr)
  354. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  355. return
  356. }
  357. lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  358. if getLPEErr != nil {
  359. this.ErrorLog("获取上一次透前评估失败:%v", getLPEErr)
  360. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  361. return
  362. }
  363. doctorAdvices, getDoctorAdvicesErr := service.MobileGetDoctorAdvicesByGroups(adminInfo.Org.Id, patientID, date.Unix())
  364. if getDoctorAdvicesErr != nil {
  365. this.ErrorLog("获取临时医嘱失败:%v", getDoctorAdvicesErr)
  366. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  367. return
  368. }
  369. dialysisOrder, getDialysisOrderErr := service.MobileGetSchedualDialysisRecord(adminInfo.Org.Id, patientID, date.Unix())
  370. if getDialysisOrderErr != nil {
  371. this.ErrorLog("获取透析记录失败:%v", getDialysisOrderErr)
  372. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  373. return
  374. }
  375. doubleCheck, getDoubleCheckErr := service.MobileGetDoubleCheck(adminInfo.Org.Id, patientID, date.Unix())
  376. if getDoubleCheckErr != nil {
  377. this.ErrorLog("获取双人核对记录失败:%v", getDoubleCheckErr)
  378. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  379. return
  380. }
  381. monitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecords(adminInfo.Org.Id, patientID, date.Unix())
  382. if getMonitorRecordsErr != nil {
  383. this.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  384. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  385. return
  386. }
  387. var lastMonitorRecord *models.MonitoringRecord
  388. lastMonitorRecord, getLastErr := service.MobileGetLastMonitorRecord(adminInfo.Org.Id, patientID, date.Unix())
  389. if getLastErr != nil {
  390. this.ErrorLog("获取上一次透析的监测记录失败:%v", getLastErr)
  391. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  392. return
  393. }
  394. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  395. if getAADErr != nil {
  396. this.ErrorLog("获取透后评估失败:%v", getAADErr)
  397. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  398. return
  399. }
  400. lastAssessmentAfterDislysis, getLAADErr := service.MobileGetLastTimeAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  401. if getLAADErr != nil {
  402. this.ErrorLog("获取上一次透后评估失败:%v", getLAADErr)
  403. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  404. return
  405. }
  406. treatmentSummary, getTreatmentSummaryErr := service.MobileGetTreatmentSummary(adminInfo.Org.Id, patientID, date.Unix())
  407. if getTreatmentSummaryErr != nil {
  408. this.ErrorLog("获取治疗小结失败:%v", getTreatmentSummaryErr)
  409. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  410. return
  411. }
  412. dialysisPrescribe, _ := service.MobileGetDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, date.Unix(), schedual.ModeId)
  413. dialysisSolution, _ := service.MobileGetDialysisSolutionByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
  414. lastDialysisPrescribe, _ := service.MobileGetLastDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
  415. //获取系统透析处方模版
  416. systemDialysisPrescribe, _ := service.MobileGetSystemDialysisPrescribeByModeId(adminInfo.Org.Id, schedual.ModeId)
  417. _, is_open_config := service.FindXTHisRecordByOrgId(adminInfo.Org.Id)
  418. _, is_project_open_config := service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  419. projects, _ := service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  420. stockType, _ := service.GetStockType(adminInfo.Org.Id)
  421. prepare, _ := service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  422. //获取最后一次血管通路
  423. lastAssessment, parseDateErr := service.GetLastPassWayAssessment(adminInfo.Org.Id, patientID)
  424. prescribeOne, parseDateErr := service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  425. var his_advices []*models.HisDoctorAdviceInfo
  426. if is_open_config.IsOpen == 1 {
  427. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  428. }
  429. if getLPEErr != nil {
  430. this.ErrorLog("获取上一次透前评估失败:%v", getLPEErr)
  431. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  432. return
  433. }
  434. lastDryWeightDislysis, getDryErr := service.MobileGetLastDryWeight(adminInfo.Org.Id, patientID)
  435. if getDryErr != nil {
  436. this.ErrorLog("获取最后一条干体重失败:%v", getDryErr)
  437. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  438. return
  439. }
  440. _, gobalConfig := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  441. operators, _ := service.GetAllStarfEs(adminInfo.Org.Id)
  442. returnData := map[string]interface{}{
  443. "patient": patient,
  444. "schedual": schedual,
  445. "prescription": dialysisPrescribe,
  446. "solution": dialysisSolution,
  447. "last_prescription": lastDialysisPrescribe,
  448. "receiver_treatment_access": receiverTreatmentAccess,
  449. "predialysis_evaluation": predialysisEvaluation,
  450. "doctor_advices": doctorAdvices,
  451. "double_check": doubleCheck,
  452. "assessment_after_dislysis": assessmentAfterDislysis,
  453. "treatment_summary": treatmentSummary,
  454. "monitor_records": monitorRecords,
  455. "dialysis_order": dialysisOrder,
  456. "operators": operators,
  457. "last_predialysis_evaluation": lastPredialysisEvaluation,
  458. "last_assessment_after_dislysis": lastAssessmentAfterDislysis,
  459. "last_monitor_record": lastMonitorRecord,
  460. "config": gobalConfig,
  461. "dry_weight": lastDryWeightDislysis,
  462. "system_prescription": systemDialysisPrescribe,
  463. "his_advices": his_advices,
  464. "is_open_config": is_open_config,
  465. "stockType": stockType,
  466. "prepare": prepare,
  467. "lastAssessment": lastAssessment,
  468. "prescribeOne": prescribeOne,
  469. "is_project_open_config": is_project_open_config,
  470. "project": projects,
  471. }
  472. this.ServeSuccessJSON(returnData)
  473. }
  474. func (this *XcxApiController) GetPatientInfo() {
  475. patient_id, _ := this.GetInt64("patient_id")
  476. patient, _ := service.GetXcxPatientInfo(patient_id)
  477. this.ServeSuccessJSON(map[string]interface{}{
  478. "patient": patient,
  479. })
  480. }
  481. func (this *XcxApiController) GetOrgInfo() {
  482. patient_id, _ := this.GetInt64("patient_id")
  483. info, _ := service.GetXcxPatientInfo(patient_id)
  484. orgInfo, _ := service.GetOrgInfo(info.UserOrgId)
  485. this.ServeSuccessJSON(map[string]interface{}{
  486. "orgInfo": orgInfo,
  487. })
  488. }