xcx_api_controller.go 35KB

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