xcx_api_controller.go 37KB

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