xcx_api_controller.go 25KB

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