xcx_api_controller.go 28KB

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