xcx_api_controller.go 36KB

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