xcx_api_controller.go 26KB

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