xcx_api_controller.go 30KB

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