staff_schedule_api_controller.go 41KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312
  1. package new_mobile_api_controllers
  2. import (
  3. "XT_New/controllers/mobile_api_controllers"
  4. "XT_New/enums"
  5. "XT_New/models"
  6. "XT_New/service"
  7. "XT_New/utils"
  8. "encoding/json"
  9. "fmt"
  10. "github.com/jinzhu/gorm"
  11. "reflect"
  12. "strconv"
  13. "strings"
  14. "time"
  15. )
  16. type StaffScheduleApiController struct {
  17. mobile_api_controllers.MobileBaseAPIAuthController
  18. }
  19. func (this *StaffScheduleApiController) GetMobileDoctorList() {
  20. orgId := this.GetMobileAdminUserInfo().Org.Id
  21. appId := this.GetMobileAdminUserInfo().App.Id
  22. staffList, err := service.GetDoctorList(orgId, appId)
  23. //获取所有的医生
  24. doctorList, err := service.GetAllDoctorList(orgId, appId)
  25. //获取所有的护士
  26. nurseList, err := service.GetAllNurseList(orgId, appId)
  27. if err != nil {
  28. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  29. return
  30. }
  31. if err != nil {
  32. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  33. return
  34. }
  35. this.ServeSuccessJSON(map[string]interface{}{
  36. "staffList": staffList,
  37. "doctorList": doctorList,
  38. "nurseList": nurseList,
  39. })
  40. }
  41. func (this *StaffScheduleApiController) GetMobileStaffScheduleList() {
  42. orgId := this.GetMobileAdminUserInfo().Org.Id
  43. //start_time, _ := this.GetInt64("start_time")
  44. //fmt.Println("staft_time", start_time)
  45. //end_time, _ := this.GetInt64("end_time")
  46. //fmt.Println("start_time",start_time)
  47. //fmt.Println("end_time",end_time)
  48. start_time_one := this.GetString("start_time_one")
  49. end_time_one := this.GetString("end_time_one")
  50. timeLayout := "2006-01-02"
  51. loc, _ := time.LoadLocation("Local")
  52. var startTime int64
  53. if len(start_time_one) > 0 {
  54. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_one+" 00:00:00", loc)
  55. if err != nil {
  56. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  57. return
  58. }
  59. startTime = theTime.Unix()
  60. }
  61. var endTime int64
  62. if len(end_time_one) > 0 {
  63. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_one+" 23:59:59", loc)
  64. if err != nil {
  65. utils.ErrorLog(err.Error())
  66. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  67. return
  68. }
  69. endTime = theTime.Unix()
  70. }
  71. staffList, err := service.GetStaffScheduleList(orgId, startTime, endTime)
  72. if err != nil {
  73. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  74. return
  75. }
  76. this.ServeSuccessJSON(map[string]interface{}{
  77. "staffList": staffList,
  78. })
  79. }
  80. func (this *StaffScheduleApiController) GetMobileNextWeekScheduleLIst() {
  81. orgId := this.GetMobileAdminUserInfo().Org.Id
  82. //start_time, _ := this.GetInt64("start_time")
  83. //end_time, _ := this.GetInt64("end_time")
  84. start_time_one := this.GetString("start_time_one")
  85. end_time_one := this.GetString("end_time_one")
  86. timeLayout := "2006-01-02"
  87. loc, _ := time.LoadLocation("Local")
  88. var startTime int64
  89. if len(start_time_one) > 0 {
  90. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_one+" 00:00:00", loc)
  91. if err != nil {
  92. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  93. return
  94. }
  95. startTime = theTime.Unix()
  96. }
  97. var endTime int64
  98. if len(end_time_one) > 0 {
  99. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_one+" 23:59:59", loc)
  100. if err != nil {
  101. utils.ErrorLog(err.Error())
  102. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  103. return
  104. }
  105. endTime = theTime.Unix()
  106. }
  107. staffList, err := service.GetStaffScheduleList(orgId, startTime, endTime)
  108. if err != nil {
  109. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  110. return
  111. }
  112. this.ServeSuccessJSON(map[string]interface{}{
  113. "staffList": staffList,
  114. })
  115. }
  116. func (this *StaffScheduleApiController) GetScheduleByUserType() {
  117. doctor_id, _ := this.GetInt64("doctor_id")
  118. //start_time, _ := this.GetInt64("start_time")
  119. //end_time, _ := this.GetInt64("end_time")
  120. start_time_one := this.GetString("start_time_one")
  121. end_time_one := this.GetString("end_time_one")
  122. timeLayout := "2006-01-02"
  123. loc, _ := time.LoadLocation("Local")
  124. var startTime int64
  125. if len(start_time_one) > 0 {
  126. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_one+" 00:00:00", loc)
  127. if err != nil {
  128. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  129. return
  130. }
  131. startTime = theTime.Unix()
  132. }
  133. var endTime int64
  134. if len(end_time_one) > 0 {
  135. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_one+" 23:59:59", loc)
  136. if err != nil {
  137. utils.ErrorLog(err.Error())
  138. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  139. return
  140. }
  141. endTime = theTime.Unix()
  142. }
  143. orgId := this.GetMobileAdminUserInfo().Org.Id
  144. staffList, err := service.GetScheduleByDoctorId(doctor_id, startTime, endTime, orgId)
  145. if err != nil {
  146. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  147. return
  148. }
  149. this.ServeSuccessJSON(map[string]interface{}{
  150. "staffList": staffList,
  151. })
  152. }
  153. func (this *StaffScheduleApiController) GetSearchPatientByDoctorId() {
  154. orgId := this.GetMobileAdminUserInfo().Org.Id
  155. user_name := this.GetString("user_name")
  156. //start_time, _ := this.GetInt64("start_time")
  157. //end_time, _ := this.GetInt64("end_time")
  158. start_time_one := this.GetString("start_time_one")
  159. end_time_one := this.GetString("end_time_one")
  160. timeLayout := "2006-01-02"
  161. loc, _ := time.LoadLocation("Local")
  162. var startTime int64
  163. if len(start_time_one) > 0 {
  164. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_one+" 00:00:00", loc)
  165. if err != nil {
  166. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  167. return
  168. }
  169. startTime = theTime.Unix()
  170. }
  171. var endTime int64
  172. if len(end_time_one) > 0 {
  173. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_one+" 23:59:59", loc)
  174. if err != nil {
  175. utils.ErrorLog(err.Error())
  176. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  177. return
  178. }
  179. endTime = theTime.Unix()
  180. }
  181. //
  182. staffList, err := service.ToSearchSeacheduleList(user_name, startTime, endTime, orgId)
  183. if err != nil {
  184. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  185. return
  186. }
  187. this.ServeSuccessJSON(map[string]interface{}{
  188. "staffList": staffList,
  189. })
  190. }
  191. func (this *StaffScheduleApiController) GetMobileSchedulelist() {
  192. orgId := this.GetMobileAdminUserInfo().Org.Id
  193. list, err := service.GetScheduleList(orgId)
  194. if err != nil {
  195. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  196. return
  197. }
  198. this.ServeSuccessJSON(map[string]interface{}{
  199. "list": list,
  200. })
  201. }
  202. func (this *StaffScheduleApiController) GetMobileScheduleListTotal() {
  203. start_time, _ := this.GetInt64("start_time")
  204. end_time, _ := this.GetInt64("end_time")
  205. orgId := this.GetMobileAdminUserInfo().Org.Id
  206. //统计班次
  207. scheudletotal, err := service.GetScheduleListTotal(orgId, start_time, end_time)
  208. //统计总工时
  209. list, err := service.GetTotalMinutes(orgId, start_time, end_time)
  210. //统计出勤天数
  211. workDay, err := service.GetTotalWorkDay(orgId, start_time, end_time)
  212. //统计缺勤天数
  213. noWorkDay, err := service.GetTotalNoWorkDay(orgId, start_time, end_time)
  214. if err != nil {
  215. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  216. return
  217. }
  218. this.ServeSuccessJSON(map[string]interface{}{
  219. "scheudletotal": scheudletotal,
  220. "list": list,
  221. "workDay": workDay,
  222. "noWorkDay": noWorkDay,
  223. })
  224. }
  225. func (this *StaffScheduleApiController) GetMySchedule() {
  226. start_time, _ := this.GetInt64("start_time")
  227. end_time, _ := this.GetInt64("end_time")
  228. orgId := this.GetMobileAdminUserInfo().Org.Id
  229. creator, _ := this.GetInt64("creator")
  230. schedule, err := service.GetMySchedule(start_time, end_time, orgId, creator)
  231. if err != nil {
  232. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  233. return
  234. }
  235. this.ServeSuccessJSON(map[string]interface{}{
  236. "schedule": schedule,
  237. })
  238. }
  239. func (this *StaffScheduleApiController) GetMobileChartList() {
  240. start_time, _ := this.GetInt64("start_time")
  241. end_time, _ := this.GetInt64("end_time")
  242. orgId := this.GetMobileAdminUserInfo().Org.Id
  243. //统计总工时
  244. list, err := service.GetTotalMinutesOne(orgId, start_time, end_time)
  245. //统计出勤的总工时
  246. workDaylist, err := service.GetTotalMinutesTwo(orgId, start_time, end_time)
  247. if err != nil {
  248. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  249. return
  250. }
  251. this.ServeSuccessJSON(map[string]interface{}{
  252. "list": list,
  253. "workDaylist": workDaylist,
  254. })
  255. }
  256. func (this *StaffScheduleApiController) ToSearchMobileTotal() {
  257. start_time, _ := this.GetInt64("start_time")
  258. end_time, _ := this.GetInt64("end_time")
  259. orgId := this.GetMobileAdminUserInfo().Org.Id
  260. keyword := this.GetString("keyword")
  261. //统计表
  262. scheduletotal, err := service.GetSearchScheduleListTotal(orgId, start_time, end_time, keyword)
  263. list, err := service.GeSearchtTotalMinutes(orgId, start_time, end_time, keyword)
  264. workDay, err := service.GetSearchWorkDay(orgId, start_time, end_time, keyword)
  265. noWorkDay, err := service.GetSearchWorkNoDay(orgId, start_time, end_time, keyword)
  266. //统计图
  267. chartTotalMinute, err := service.GetChartTotalMinutesOne(orgId, start_time, end_time, keyword)
  268. chartWorkDayMinute, err := service.GetChartTotalMinutesTwo(orgId, start_time, end_time, keyword)
  269. if err != nil {
  270. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  271. return
  272. }
  273. this.ServeSuccessJSON(map[string]interface{}{
  274. "scheduletotal": scheduletotal,
  275. "list": list,
  276. "workDay": workDay,
  277. "noWorkDay": noWorkDay,
  278. "chartTotalMinute": chartTotalMinute,
  279. "chartWorkDayMinute": chartWorkDayMinute,
  280. })
  281. }
  282. func (this *StaffScheduleApiController) ChangeMobileOption() {
  283. start_time, _ := this.GetInt64("start_time")
  284. end_time, _ := this.GetInt64("end_time")
  285. orgId := this.GetMobileAdminUserInfo().Org.Id
  286. doctor_type, _ := this.GetInt64("doctor_type")
  287. //统计图
  288. scheduletotal, err := service.ChagneScheduleListTotal(orgId, start_time, end_time, doctor_type)
  289. list, err := service.ChangeScheduleMinute(orgId, start_time, end_time, doctor_type)
  290. workday, err := service.ChangeWorkDay(orgId, start_time, end_time, doctor_type)
  291. worknoday, err := service.ChangeNoWorkDay(orgId, start_time, end_time, doctor_type)
  292. //统计表
  293. chartotalminute, err := service.ChartTotalMinute(orgId, start_time, end_time, doctor_type)
  294. chartworkdayminute, err := service.ChartWorkDayMinute(orgId, start_time, end_time, doctor_type)
  295. if err != nil {
  296. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  297. return
  298. }
  299. this.ServeSuccessJSON(map[string]interface{}{
  300. "scheduletotal": scheduletotal,
  301. "list": list,
  302. "workday": workday,
  303. "worknoday": worknoday,
  304. "chartotalminute": chartotalminute,
  305. "chartworkdayminute": chartworkdayminute,
  306. })
  307. }
  308. func (this *StaffScheduleApiController) GetAllZone() {
  309. id := this.GetMobileAdminUserInfo().Org.Id
  310. zone, err := service.GetAllMobileZone(id)
  311. if err != nil {
  312. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  313. return
  314. }
  315. this.ServeSuccessJSON(map[string]interface{}{
  316. "zone": zone,
  317. })
  318. }
  319. func (this *StaffScheduleApiController) GetAllZonePb() {
  320. orgid := this.GetMobileAdminUserInfo().Org.Id
  321. timeLayout := "2006-01-02"
  322. loc, _ := time.LoadLocation("Local")
  323. start_time := this.GetString("start_time")
  324. var startTime int64
  325. if len(start_time) > 0 {
  326. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  327. if err != nil {
  328. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  329. return
  330. }
  331. startTime = theTime.Unix()
  332. }
  333. zoneid, _ := this.GetInt64("zoneid")
  334. classtype, _ := this.GetInt64("classtype")
  335. // is_open, _ := this.GetInt64("is_open")
  336. //获取空床位的排班数据
  337. list, _ := service.GetPatientScheduleByPd(startTime, zoneid, orgid, classtype)
  338. if len(list) > 0 {
  339. for _, item := range list {
  340. for _, device := range item.DeviceNumber {
  341. item.TotalBed += 1
  342. for _, schedule := range device.Schedule {
  343. if schedule.ScheduleType == 1 {
  344. item.SwBed += 1
  345. }
  346. if schedule.ScheduleType == 2 {
  347. item.XwBed += 1
  348. }
  349. if schedule.ScheduleType == 3 {
  350. item.WsBed += 1
  351. }
  352. }
  353. }
  354. }
  355. }
  356. //针对百霖和贝尔
  357. if orgid == 10138 || orgid == 10278 || orgid == 3877 {
  358. //获取今日的排班数据
  359. list, _ := service.GetMobileScheduleListByScheduleDate(orgid, startTime)
  360. for _, item := range list {
  361. solution, _ := service.GetLongSolutionByModeId(item.PatientId, item.ModeId, item.UserOrgId)
  362. var str = solution.DialysisDialyszers + "/" + solution.DialysisIrrigation
  363. service.UpdateScheduleByDialysis(item.PatientId, item.ModeId, item.ScheduleDate, item.UserOrgId, str, item.ScheduleType)
  364. }
  365. }
  366. // stockType, _ := service.GetStockType(orgid)
  367. //zonelist, _ := service.GetPatientScheduleListByZone(startTime, classtype, orgid)
  368. // if err != nil {
  369. // this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  370. // return
  371. // }
  372. this.ServeSuccessJSON(map[string]interface{}{
  373. "schedule": list,
  374. // "stockType": stockType,
  375. //"zonelist": zonelist,
  376. })
  377. // id := this.GetMobileAdminUserInfo().Org.Id
  378. // zone, err := service.GetAllMobileZonePb(id)
  379. // if err != nil {
  380. // this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  381. // return
  382. // }
  383. // this.ServeSuccessJSON(map[string]interface{}{
  384. // "zone": zone,
  385. // })
  386. }
  387. func (this *StaffScheduleApiController) GetPatientScheduleList() {
  388. orgid := this.GetMobileAdminUserInfo().Org.Id
  389. fmt.Println("orgid", orgid)
  390. timeLayout := "2006-01-02"
  391. loc, _ := time.LoadLocation("Local")
  392. start_time := this.GetString("start_time")
  393. var startTime int64
  394. if len(start_time) > 0 {
  395. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  396. if err != nil {
  397. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  398. return
  399. }
  400. startTime = theTime.Unix()
  401. }
  402. zoneid, _ := this.GetInt64("zoneid")
  403. fmt.Println(zoneid)
  404. classtype, _ := this.GetInt64("classtype")
  405. is_open, _ := this.GetInt64("is_open")
  406. if is_open == 0 {
  407. //获取当天排班的病人情况
  408. schedule, err := service.GetPatientSchedule(startTime, zoneid, classtype, orgid)
  409. zonelist, _ := service.GetPatientScheduleListByZone(startTime, classtype, orgid)
  410. if err != nil {
  411. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  412. return
  413. }
  414. this.ServeSuccessJSON(map[string]interface{}{
  415. "schedule": schedule,
  416. "zonelist": zonelist,
  417. })
  418. }
  419. if is_open == 1 {
  420. //获取空床位的排班数据
  421. list, err := service.GetPatientScheduleByBed(startTime, zoneid, orgid, classtype)
  422. stockType, _ := service.GetStockType(orgid)
  423. zonelist, _ := service.GetPatientScheduleListByZone(startTime, classtype, orgid)
  424. if err != nil {
  425. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  426. return
  427. }
  428. this.ServeSuccessJSON(map[string]interface{}{
  429. "schedule": list,
  430. "stockType": stockType,
  431. "zonelist": zonelist,
  432. })
  433. }
  434. }
  435. func (this *StaffScheduleApiController) DeleteSchedule() {
  436. id, _ := this.GetInt64("id")
  437. org_id := this.GetMobileAdminUserInfo().Org.Id
  438. err := service.DeleteSchedule(id)
  439. if err == nil {
  440. schedule, _ := service.GetScheduleNight(org_id, id)
  441. //记录日志
  442. byterequest, _ := json.Marshal(schedule)
  443. xtScheduleLog := models.XtScheduleLog{
  444. UserOrgId: org_id,
  445. RecordDate: schedule.ScheduleDate,
  446. Status: 1,
  447. PatientId: schedule.PatientId,
  448. Ctime: time.Now().Unix(),
  449. Mtime: 0,
  450. ErrLog: string(byterequest),
  451. Source: "手机端删除排班",
  452. Module: 5,
  453. AdminUserId: this.GetMobileAdminUserInfo().AdminUser.Id,
  454. }
  455. service.CreateScheduleLog(xtScheduleLog)
  456. //针对凤凰医院
  457. if org_id == 10579 || org_id == 10344 || org_id == 10206 {
  458. advice, _ := service.GetDoctorAdviceListTwenty(schedule.PatientId, schedule.ScheduleDate, org_id)
  459. if len(advice) > 0 {
  460. service.UpdateAdviceObj(schedule.PatientId, schedule.ScheduleDate, org_id)
  461. }
  462. }
  463. if org_id == 10206 {
  464. advice, _ := service.GetHisDoctorAdviceListTwenty(schedule.PatientId, schedule.ScheduleDate, org_id)
  465. if len(advice) > 0 {
  466. service.UpdateHisAdviceObj(schedule.PatientId, schedule.ScheduleDate, org_id)
  467. }
  468. }
  469. redis := service.RedisClient()
  470. //处方
  471. keyOne := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":prescriptions_list_all"
  472. redis.Set(keyOne, "", time.Second)
  473. //医嘱
  474. keyTwo := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":advice_list_all"
  475. redis.Set(keyTwo, "", time.Second)
  476. keySix := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_befores_list_all"
  477. redis.Set(keySix, "", time.Second)
  478. keyThree := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_after_dislysis_list_all"
  479. redis.Set(keyThree, "", time.Second)
  480. keyFour := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":monitor_record_list_all"
  481. redis.Set(keyFour, "", time.Second)
  482. keyFive := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":treatment_summarys_list_all"
  483. redis.Set(keyFive, "", time.Second)
  484. keySeven := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":dialysis_orders_list_all"
  485. redis.Set(keySeven, "", time.Second)
  486. defer redis.Close()
  487. fmt.Println(err)
  488. returnData := make(map[string]interface{}, 0)
  489. returnData["msg"] = "ok"
  490. this.ServeSuccessJSON(returnData)
  491. return
  492. } else {
  493. this.ServeFailJsonSend(enums.ErrorCodeDataException, "删除失败")
  494. return
  495. }
  496. }
  497. func (this *StaffScheduleApiController) SearchPatient() {
  498. timeLayout := "2006-01-02"
  499. loc, _ := time.LoadLocation("Local")
  500. keyword := this.GetString("keyword")
  501. fmt.Println(keyword)
  502. orgId := this.GetMobileAdminUserInfo().Org.Id
  503. start_time := this.GetString("start_time")
  504. var startTime int64
  505. if len(start_time) > 0 {
  506. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  507. if err != nil {
  508. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  509. return
  510. }
  511. startTime = theTime.Unix()
  512. }
  513. schedule, err := service.GetSearchPatient(keyword, orgId, startTime)
  514. if err != nil {
  515. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  516. return
  517. }
  518. this.ServeSuccessJSON(map[string]interface{}{
  519. "schedule": schedule,
  520. })
  521. }
  522. func (this *StaffScheduleApiController) UpdatePatientScheduleById() {
  523. ids := this.GetString("ids")
  524. idSplit := strings.Split(ids, ",")
  525. var err error
  526. //查询患者信息
  527. list, _ := service.GetStaffScheduleById(idSplit)
  528. if len(list) > 0 {
  529. for index, _ := range list {
  530. fmt.Println("index2322332", index)
  531. schedule := models.XtSchedule{
  532. PatientId: list[0].PatientId,
  533. ModeId: list[0].ModeId,
  534. DialysisMachineName: list[0].DialysisMachineName,
  535. }
  536. xtSchedule := models.WeekSchedule{
  537. PatientId: list[1].PatientId,
  538. ModeId: list[1].ModeId,
  539. DialysisMachineName: list[1].DialysisMachineName,
  540. }
  541. err = service.UpdateStaffSchedule(list[1].ID, schedule)
  542. fmt.Println("errrrrrrr2323323232323", err)
  543. service.UpdateStaffScheduleOne(list[0].ID, xtSchedule)
  544. }
  545. }
  546. fmt.Println(err)
  547. this.ServeSuccessJSON(map[string]interface{}{
  548. "msg": "切换成功",
  549. })
  550. }
  551. func (this *StaffScheduleApiController) UpdateDialysisPrescription() {
  552. patient_id, _ := this.GetInt64("patient_id")
  553. start_time, _ := this.GetInt64("start_time")
  554. mode_id, _ := this.GetInt64("mode_id")
  555. dialyzer_perfusion_apparatus := this.GetString("dialyzer_perfusion_apparatus")
  556. dialysis_irrigation := this.GetString("dialysis_irrigation")
  557. //更改透析模式
  558. _, errcode := service.GetDialyisSolution(patient_id, start_time)
  559. if errcode == gorm.ErrRecordNotFound {
  560. orgId := this.GetMobileAdminUserInfo().Org.Id
  561. prescription := models.DialysisPrescription{
  562. DialysisDialyszers: dialyzer_perfusion_apparatus,
  563. DialysisIrrigation: dialysis_irrigation,
  564. PatientId: patient_id,
  565. UserOrgId: orgId,
  566. Status: 1,
  567. RecordDate: start_time,
  568. CreatedTime: time.Now().Unix(),
  569. ModeId: mode_id,
  570. }
  571. err := service.CreateDialysisPrescription(&prescription)
  572. if err != nil {
  573. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  574. return
  575. }
  576. this.ServeSuccessJSON(map[string]interface{}{
  577. "msg": "保存成功",
  578. })
  579. } else if errcode == nil {
  580. prescription := models.DialysisPrescription{
  581. DialysisDialyszers: dialyzer_perfusion_apparatus,
  582. DialysisIrrigation: dialysis_irrigation,
  583. ModeId: mode_id,
  584. }
  585. err := service.UpdateDialysisPrescriptionOne(prescription, patient_id, start_time, mode_id)
  586. if err != nil {
  587. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  588. return
  589. }
  590. this.ServeSuccessJSON(map[string]interface{}{
  591. "msg": "保存成功",
  592. })
  593. }
  594. }
  595. func (this *StaffScheduleApiController) UpdateBloodScheduleMode() {
  596. id, _ := this.GetInt64("id")
  597. mode_id, _ := this.GetInt64("mode_id")
  598. schedule := models.XtSchedule{
  599. ModeId: mode_id,
  600. }
  601. service.UpdatedScheduleMode(schedule, id)
  602. orgId := this.GetMobileAdminUserInfo().Org.Id
  603. //记录日志
  604. byterequest, _ := json.Marshal(schedule)
  605. scheduleLog := models.XtScheduleLog{
  606. UserOrgId: orgId,
  607. RecordDate: schedule.ScheduleDate,
  608. Status: 1,
  609. PatientId: schedule.PatientId,
  610. Ctime: time.Now().Unix(),
  611. Mtime: 0,
  612. ErrLog: string(byterequest),
  613. Source: "手机端修改排班模式",
  614. Module: 5,
  615. AdminUserId: this.GetMobileAdminUserInfo().AdminUser.Id,
  616. }
  617. service.CreateScheduleLog(scheduleLog)
  618. this.ServeSuccessJSON(map[string]interface{}{
  619. "msg": "保存成功",
  620. })
  621. }
  622. func (this *StaffScheduleApiController) UpdateBloodSchedule() {
  623. patient_id, _ := this.GetInt64("patient_id")
  624. mode_id, _ := this.GetInt64("mode_id")
  625. schedule_type, _ := this.GetInt64("schedule_type")
  626. start_time, _ := this.GetInt64("start_time")
  627. bed_id, _ := this.GetInt64("bed_id")
  628. orgid := this.GetMobileAdminUserInfo().Org.Id
  629. //更改排班
  630. schedule := models.XtSchedule{
  631. ScheduleType: schedule_type,
  632. ModeId: mode_id,
  633. }
  634. //查询该床位该班次是否存在排班
  635. _, errschedulecode := service.GetPatientScheduleIsExist(start_time, schedule_type, bed_id, orgid)
  636. if errschedulecode == gorm.ErrRecordNotFound {
  637. service.UpdatedSchedule(schedule, patient_id, start_time, schedule_type, bed_id)
  638. //记录日志
  639. byterequest, _ := json.Marshal(schedule)
  640. scheduleLog := models.XtScheduleLog{
  641. UserOrgId: orgid,
  642. RecordDate: schedule.ScheduleDate,
  643. Status: 1,
  644. PatientId: schedule.PatientId,
  645. Ctime: time.Now().Unix(),
  646. Mtime: 0,
  647. ErrLog: string(byterequest),
  648. Source: "手机修改排班班次",
  649. Module: 5,
  650. AdminUserId: this.GetMobileAdminUserInfo().AdminUser.Id,
  651. }
  652. service.CreateScheduleLog(scheduleLog)
  653. this.ServeSuccessJSON(map[string]interface{}{
  654. "msgerr": "保存成功",
  655. })
  656. } else if errschedulecode == nil {
  657. this.ServeSuccessJSON(map[string]interface{}{
  658. "msg": "1",
  659. "msgerr": "排班已存在",
  660. })
  661. }
  662. }
  663. func (this *StaffScheduleApiController) GetSchedulePatient() {
  664. schedule, _ := this.GetInt64("schedule", 0) //1已2未
  665. contagion, _ := this.GetInt64("contagion", 0)
  666. keywords := this.GetString("keywords", "")
  667. adminInfo := this.GetMobileAdminUserInfo()
  668. thisTime := time.Now()
  669. weekDay := int(thisTime.Weekday())
  670. if weekDay == 0 {
  671. weekDay = 7
  672. }
  673. thisWeekEnd := 7 - weekDay
  674. weekStartPoint := thisWeekEnd - 6
  675. weekStartDay := thisTime.AddDate(0, 0, weekStartPoint)
  676. weekEndPoint := thisWeekEnd + 7
  677. weekEndDay := thisTime.AddDate(0, 0, weekEndPoint)
  678. fmt.Println(weekStartPoint, weekStartDay, weekEndPoint, weekEndDay)
  679. weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
  680. weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
  681. fmt.Println(weekStartTime, weekEndTime)
  682. timeLayout := "2006-01-02 15:04:05"
  683. loc, _ := time.LoadLocation("Local")
  684. theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
  685. theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
  686. weekStart := theStarTime.Unix()
  687. weekEnd := theEndTime.Unix()
  688. patients, _ := service.GetPatientWithScheduleAndSolutionTwo(adminInfo.Org.Id, keywords, weekStart, weekEnd, schedule, contagion)
  689. this.ServeSuccessJSON(map[string]interface{}{
  690. "patients": patients,
  691. })
  692. return
  693. }
  694. func (c *StaffScheduleApiController) CreateMobileSchedulePatient() {
  695. patientID, _ := c.GetInt64("patient_id", 0)
  696. if patientID <= 0 {
  697. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  698. return
  699. }
  700. adminUserInfo := c.GetMobileAdminUserInfo()
  701. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patientID)
  702. if patientInfo.ID == 0 {
  703. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  704. return
  705. }
  706. var schedule models.Schedule
  707. dataBody := make(map[string]interface{}, 0)
  708. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  709. if err != nil {
  710. utils.ErrorLog(err.Error())
  711. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  712. return
  713. }
  714. if dataBody["schedule_date"] == nil || reflect.TypeOf(dataBody["schedule_date"]).String() != "string" {
  715. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  716. return
  717. }
  718. scheduleDate, _ := dataBody["schedule_date"].(string)
  719. if len(scheduleDate) == 0 {
  720. utils.ErrorLog("len(schedule_date) == 0")
  721. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  722. return
  723. }
  724. timeLayout := "2006-01-02"
  725. loc, _ := time.LoadLocation("Local")
  726. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", scheduleDate+" 00:00:00", loc)
  727. if err != nil {
  728. utils.ErrorLog(err.Error())
  729. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  730. return
  731. }
  732. schedule.ScheduleDate = theTime.Unix()
  733. timeNow := time.Now().Format("2006-01-02")
  734. if timeNow > scheduleDate {
  735. utils.ErrorLog(timeNow)
  736. utils.ErrorLog(scheduleDate)
  737. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleBeforeNow)
  738. return
  739. }
  740. if dataBody["schedule_type"] == nil || reflect.TypeOf(dataBody["schedule_type"]).String() != "float64" {
  741. utils.ErrorLog("schedule_type")
  742. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  743. return
  744. }
  745. scheduleType := int64(dataBody["schedule_type"].(float64))
  746. if scheduleType < 1 || scheduleType > 3 {
  747. utils.ErrorLog("scheduleType < 3")
  748. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  749. return
  750. }
  751. schedule.ScheduleType = scheduleType
  752. if dataBody["bed_id"] == nil || reflect.TypeOf(dataBody["bed_id"]).String() != "float64" {
  753. utils.ErrorLog("bed_id")
  754. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  755. return
  756. }
  757. bedId := int64(dataBody["bed_id"].(float64))
  758. if bedId < 1 {
  759. utils.ErrorLog("bedId < 1")
  760. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  761. return
  762. }
  763. schedule.BedId = bedId
  764. if dataBody["partition_id"] == nil || reflect.TypeOf(dataBody["partition_id"]).String() != "float64" {
  765. utils.ErrorLog("partition_id")
  766. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  767. return
  768. }
  769. partitionId := int64(dataBody["partition_id"].(float64))
  770. if partitionId < 1 {
  771. utils.ErrorLog("partitionId < 1")
  772. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  773. return
  774. }
  775. schedule.PartitionId = partitionId
  776. if dataBody["schedule_week"] == nil || reflect.TypeOf(dataBody["schedule_week"]).String() != "float64" {
  777. utils.ErrorLog("schedule_week")
  778. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  779. return
  780. }
  781. scheduleWeek := int64(dataBody["schedule_week"].(float64))
  782. if scheduleWeek < 1 || scheduleWeek > 7 {
  783. utils.ErrorLog("scheduleWeek < 1")
  784. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  785. return
  786. }
  787. schedule.ScheduleWeek = scheduleWeek
  788. if dataBody["mode_id"] == nil || reflect.TypeOf(dataBody["mode_id"]).String() != "float64" {
  789. utils.ErrorLog("mode_id")
  790. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  791. return
  792. }
  793. modeId := int64(dataBody["mode_id"].(float64))
  794. if modeId < 1 && modeId > 14 {
  795. utils.ErrorLog("modeId < 1")
  796. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  797. return
  798. }
  799. schedule.ModeId = modeId
  800. schedule.PatientId = patientID
  801. schedule.CreatedTime = time.Now().Unix()
  802. schedule.UpdatedTime = time.Now().Unix()
  803. schedule.Status = 1
  804. schedule.IsExport = 6000
  805. schedule.UserOrgId = adminUserInfo.Org.Id
  806. bed, _ := service.GetDeviceNumberByID(adminUserInfo.Org.Id, schedule.BedId)
  807. if bed == nil {
  808. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotExist)
  809. return
  810. }
  811. if bed.ZoneID != schedule.PartitionId {
  812. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotTheZone)
  813. return
  814. }
  815. scheduleDateStart := scheduleDate + " 00:00:00"
  816. scheduleDateEnd := scheduleDate + " 23:59:59"
  817. timeLayout = "2006-01-02 15:04:05"
  818. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  819. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  820. startTime := theStartTime.Unix()
  821. endTime := theEndTime.Unix()
  822. //一天只有排班一次
  823. daySchedule, err := service.GetDaySchedule(adminUserInfo.Org.Id, startTime, endTime, patientID)
  824. if daySchedule.ID > 0 {
  825. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleAgainOneDay)
  826. return
  827. }
  828. //同天同位置只能排一个
  829. pointSchedule, err := service.GetPointSchedule(adminUserInfo.Org.Id, schedule.ScheduleDate, schedule.ScheduleWeek, schedule.ScheduleType, schedule.BedId)
  830. if err != nil {
  831. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  832. return
  833. }
  834. if pointSchedule.ID > 0 {
  835. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePointScheduleExist)
  836. return
  837. }
  838. redis := service.RedisClient()
  839. err = service.CreateScheduleTwo(&schedule)
  840. service.UpdateRepeatSchStatus(adminUserInfo.Org.Id, schedule.ScheduleDate)
  841. key := "scheduals_" + scheduleDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  842. redis.Set(key, "", time.Second)
  843. defer redis.Close()
  844. fmt.Println(err)
  845. if err != nil {
  846. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateScheduleFail)
  847. return
  848. }
  849. schedule.Patient = patientInfo.Name
  850. c.ServeSuccessJSON(map[string]interface{}{
  851. "msg": "ok",
  852. "schedule": schedule,
  853. })
  854. return
  855. }
  856. func (c *StaffScheduleApiController) GetSolutionSchedule() {
  857. orgId := c.GetMobileAdminUserInfo().Org.Id
  858. scheduleDate := c.GetString("start_time")
  859. zoneid, _ := c.GetInt64("zoneid")
  860. classtype, _ := c.GetInt64("classtype")
  861. timeLayout := "2006-01-02"
  862. loc, _ := time.LoadLocation("Local")
  863. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", scheduleDate+" 00:00:00", loc)
  864. schedule, _ := service.GetSolutionScheduleBySchedule(orgId, zoneid, classtype, theTime.Unix())
  865. c.ServeSuccessJSON(map[string]interface{}{
  866. "schedule": schedule,
  867. })
  868. }
  869. func (c *StaffScheduleApiController) GetAllBedList() {
  870. orgId := c.GetMobileAdminUserInfo().Org.Id
  871. partition_id, _ := c.GetInt64("partition_id")
  872. list, _ := service.GetAllBedNumberTen(orgId, partition_id)
  873. c.ServeSuccessJSON(map[string]interface{}{
  874. "list": list,
  875. })
  876. }
  877. func (c *StaffScheduleApiController) ChangeScheduleById() {
  878. id, _ := c.GetInt64("id")
  879. mode_id, _ := c.GetInt64("mode_id")
  880. schedule_date, _ := c.GetInt64("schedule_date")
  881. patient_id, _ := c.GetInt64("patient_id")
  882. org_id := c.GetMobileAdminUserInfo().Org.Id
  883. err := service.ChangeScheduleById(id, mode_id)
  884. fmt.Println("err", err)
  885. err = service.ChangeDialysisSolution(patient_id, schedule_date, org_id, mode_id)
  886. c.ServeSuccessJSON(map[string]interface{}{
  887. "msg": "ok",
  888. })
  889. }
  890. func (c *StaffScheduleApiController) ChangeScheduleType() {
  891. schedule_type, _ := c.GetInt64("schedule_type")
  892. schedule_date, _ := c.GetInt64("schedule_date")
  893. patient_id, _ := c.GetInt64("patient_id")
  894. bed_id, _ := c.GetInt64("bed_id")
  895. //schedule_week, _ := c.GetInt64("schedule_week")
  896. mode_id, _ := c.GetInt64("mode_id")
  897. id, _ := c.GetInt64("id")
  898. org_id := c.GetMobileAdminUserInfo().Org.Id
  899. //查询该班次该床位是否已经存在患者
  900. schedule, _ := service.GetScheduleByClassType(schedule_type, schedule_date, bed_id, org_id)
  901. //查询该床位所属分区
  902. //numberlist, _ := service.GetPartionId(bed_id, org_id)
  903. //存在
  904. if schedule.ID > 0 {
  905. order, _ := service.GetDialysisOrder(schedule.ScheduleDate, schedule.PatientId, schedule.UserOrgId)
  906. if order.ID > 0 {
  907. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSchedule)
  908. return
  909. }
  910. //调换位置
  911. sch := models.Schedule{
  912. PatientId: schedule.PatientId,
  913. ModeId: schedule.ModeId,
  914. }
  915. var DialysisMachineName string
  916. so, _ := service.GetDialysisSolutionTwo(org_id, sch.PatientId, sch.ModeId)
  917. filedRecordOne, _ := service.FindFiledBy(org_id, "透析器")
  918. filedRecordTwo, _ := service.FindFiledBy(org_id, "灌流器")
  919. filedRecordThree, _ := service.FindFiledBy(org_id, "透析器/灌流器")
  920. if filedRecordOne.IsShow == 1 {
  921. DialysisMachineName = so.DialysisDialyszers
  922. }
  923. if filedRecordThree.IsShow == 1 {
  924. if len(DialysisMachineName) > 0 {
  925. DialysisMachineName = DialysisMachineName + "*" + so.DialyzerPerfusionApparatus
  926. } else {
  927. DialysisMachineName = so.DialyzerPerfusionApparatus
  928. }
  929. }
  930. if filedRecordTwo.IsShow == 1 {
  931. if len(DialysisMachineName) > 0 {
  932. DialysisMachineName = DialysisMachineName + "*" + so.DialysisIrrigation
  933. } else {
  934. DialysisMachineName = so.DialysisIrrigation
  935. }
  936. }
  937. sch.DialysisMachineName = DialysisMachineName
  938. schedu := models.Schedule{
  939. PatientId: patient_id,
  940. ModeId: mode_id,
  941. }
  942. var DialysisMachineName1 string
  943. so1, _ := service.GetDialysisSolutionTwo(org_id, schedu.PatientId, schedu.ModeId)
  944. filedRecordOne1, _ := service.FindFiledBy(org_id, "透析器")
  945. filedRecordTwo1, _ := service.FindFiledBy(org_id, "灌流器")
  946. filedRecordThree1, _ := service.FindFiledBy(org_id, "透析器/灌流器")
  947. if filedRecordOne1.IsShow == 1 {
  948. DialysisMachineName1 = so1.DialysisDialyszers
  949. }
  950. if filedRecordThree1.IsShow == 1 {
  951. if len(DialysisMachineName1) > 0 {
  952. DialysisMachineName1 = DialysisMachineName1 + "*" + so1.DialyzerPerfusionApparatus
  953. } else {
  954. DialysisMachineName1 = so1.DialyzerPerfusionApparatus
  955. }
  956. }
  957. if filedRecordTwo1.IsShow == 1 {
  958. if len(DialysisMachineName1) > 0 {
  959. DialysisMachineName1 = DialysisMachineName1 + "*" + so1.DialysisIrrigation
  960. } else {
  961. DialysisMachineName1 = so1.DialysisIrrigation
  962. }
  963. }
  964. schedu.DialysisMachineName = DialysisMachineName1
  965. err := service.UpdateScheduleById(schedule.ID, schedu, id, sch)
  966. if err == nil {
  967. c.ServeSuccessJSON(map[string]interface{}{
  968. "msg": "ok",
  969. })
  970. } else {
  971. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  972. return
  973. }
  974. } else {
  975. xtSchedule := models.Schedule{
  976. ScheduleDate: schedule_date,
  977. ScheduleType: schedule_type,
  978. PatientId: patient_id,
  979. UserOrgId: org_id,
  980. }
  981. err := service.ChangeScheduleClass(xtSchedule)
  982. if err == nil {
  983. c.ServeSuccessJSON(map[string]interface{}{
  984. "msg": "ok",
  985. })
  986. } else {
  987. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  988. return
  989. }
  990. }
  991. }
  992. func (c *StaffScheduleApiController) ChangeScheduleBed() {
  993. schedule_type, _ := c.GetInt64("schedule_type")
  994. schedule_date, _ := c.GetInt64("schedule_date")
  995. patient_id, _ := c.GetInt64("patient_id")
  996. bed_id, _ := c.GetInt64("bed_id")
  997. schedule_week, _ := c.GetInt64("schedule_week")
  998. mode_id, _ := c.GetInt64("mode_id")
  999. id, _ := c.GetInt64("id")
  1000. org_id := c.GetMobileAdminUserInfo().Org.Id
  1001. temp_schedule, _ := service.GetScheduleByClassTypeTwo(schedule_type, schedule_date, patient_id, org_id)
  1002. id = temp_schedule.ID
  1003. //查询该班次该床位是否已经存在患者
  1004. schedule, _ := service.GetScheduleByClassType(schedule_type, schedule_date, bed_id, org_id)
  1005. //查询该床位所属分区
  1006. numberlist, _ := service.GetPartionId(bed_id, org_id)
  1007. //存在
  1008. if schedule.ID > 0 {
  1009. order, _ := service.GetDialysisOrder(schedule.ScheduleDate, schedule.PatientId, schedule.UserOrgId)
  1010. if order.ID > 0 {
  1011. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSchedule)
  1012. return
  1013. }
  1014. //调换位置
  1015. sch := models.Schedule{
  1016. PatientId: schedule.PatientId,
  1017. ModeId: schedule.ModeId,
  1018. DialysisMachineName: schedule.DialysisMachineName,
  1019. }
  1020. var DialysisMachineName string
  1021. so, _ := service.GetDialysisSolutionTwo(org_id, sch.PatientId, sch.ModeId)
  1022. filedRecordOne, _ := service.FindFiledBy(org_id, "透析器")
  1023. filedRecordTwo, _ := service.FindFiledBy(org_id, "灌流器")
  1024. filedRecordThree, _ := service.FindFiledBy(org_id, "透析器/灌流器")
  1025. if filedRecordOne.IsShow == 1 {
  1026. DialysisMachineName = so.DialysisDialyszers
  1027. }
  1028. if filedRecordThree.IsShow == 1 {
  1029. if len(DialysisMachineName) > 0 {
  1030. DialysisMachineName = DialysisMachineName + "-" + so.DialyzerPerfusionApparatus
  1031. } else {
  1032. DialysisMachineName = so.DialyzerPerfusionApparatus
  1033. }
  1034. }
  1035. if filedRecordTwo.IsShow == 1 {
  1036. if len(DialysisMachineName) > 0 {
  1037. DialysisMachineName = DialysisMachineName + "-" + so.DialysisIrrigation
  1038. } else {
  1039. DialysisMachineName = so.DialysisIrrigation
  1040. }
  1041. }
  1042. sch.DialysisMachineName = DialysisMachineName
  1043. schedu := models.Schedule{
  1044. PatientId: patient_id,
  1045. ModeId: mode_id,
  1046. DialysisMachineName: schedule.DialysisMachineName,
  1047. }
  1048. var DialysisMachineName1 string
  1049. so1, _ := service.GetDialysisSolutionTwo(org_id, schedu.PatientId, schedu.ModeId)
  1050. filedRecordOne1, _ := service.FindFiledBy(org_id, "透析器")
  1051. filedRecordTwo1, _ := service.FindFiledBy(org_id, "灌流器")
  1052. filedRecordThree1, _ := service.FindFiledBy(org_id, "透析器/灌流器")
  1053. if filedRecordOne1.IsShow == 1 {
  1054. DialysisMachineName1 = so1.DialysisDialyszers
  1055. }
  1056. if filedRecordThree1.IsShow == 1 {
  1057. if len(DialysisMachineName1) > 0 {
  1058. DialysisMachineName1 = DialysisMachineName1 + "-" + so1.DialyzerPerfusionApparatus
  1059. } else {
  1060. DialysisMachineName1 = so1.DialyzerPerfusionApparatus
  1061. }
  1062. }
  1063. if filedRecordTwo1.IsShow == 1 {
  1064. if len(DialysisMachineName1) > 0 {
  1065. DialysisMachineName1 = DialysisMachineName1 + "-" + so1.DialysisIrrigation
  1066. } else {
  1067. DialysisMachineName1 = so1.DialysisIrrigation
  1068. }
  1069. }
  1070. schedu.DialysisMachineName = DialysisMachineName1
  1071. err := service.UpdateScheduleById(schedule.ID, schedu, id, sch)
  1072. //记录日志
  1073. byterequest, _ := json.Marshal(schedule)
  1074. scheduleLog := models.XtScheduleLog{
  1075. UserOrgId: org_id,
  1076. RecordDate: schedule.ScheduleDate,
  1077. Status: 1,
  1078. PatientId: schedule.PatientId,
  1079. Ctime: time.Now().Unix(),
  1080. Mtime: 0,
  1081. ErrLog: string(byterequest),
  1082. Source: "手机端修改调班",
  1083. Module: 4,
  1084. AdminUserId: c.GetMobileAdminUserInfo().AdminUser.Id,
  1085. }
  1086. service.UpdateRepeatSchStatus(org_id, schedule_date)
  1087. service.CreateScheduleLog(scheduleLog)
  1088. if err == nil {
  1089. c.ServeSuccessJSON(map[string]interface{}{
  1090. "msg": "ok",
  1091. })
  1092. } else {
  1093. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1094. return
  1095. }
  1096. } else {
  1097. var str string
  1098. //查找该机构用的是什么透析器
  1099. filedConfig, _ := service.GetFiledConfig(org_id)
  1100. if filedConfig.ID > 0 {
  1101. solutionType, _ := service.GetLastDialysisSolutionType(org_id, patient_id, mode_id)
  1102. str = solutionType.DialyzerPerfusionApparatus
  1103. } else {
  1104. solutionType, _ := service.GetLastDialysisSolutionType(org_id, patient_id, mode_id)
  1105. str = solutionType.DialysisDialyszers + "/" + solutionType.DialysisIrrigation
  1106. }
  1107. xtSchedule := models.Schedule{
  1108. UserOrgId: org_id,
  1109. PartitionId: numberlist.ZoneId,
  1110. BedId: bed_id,
  1111. PatientId: patient_id,
  1112. ScheduleDate: schedule_date,
  1113. ScheduleType: schedule_type,
  1114. ScheduleWeek: schedule_week,
  1115. ModeId: mode_id,
  1116. Status: 1,
  1117. CreatedTime: time.Now().Unix(),
  1118. UpdatedTime: 0,
  1119. IsExport: 20000,
  1120. DialysisMachineName: str,
  1121. }
  1122. var err error
  1123. err = service.CreateSchedule(&xtSchedule, id)
  1124. service.UpdateRepeatSchStatus(org_id, schedule_date)
  1125. //记录日志
  1126. byterequest, _ := json.Marshal(schedule)
  1127. scheduleLog := models.XtScheduleLog{
  1128. UserOrgId: org_id,
  1129. RecordDate: schedule.ScheduleDate,
  1130. Status: 1,
  1131. PatientId: schedule.PatientId,
  1132. Ctime: time.Now().Unix(),
  1133. Mtime: 0,
  1134. ErrLog: string(byterequest),
  1135. Source: "手机端新建调班",
  1136. Module: 1,
  1137. AdminUserId: c.GetMobileAdminUserInfo().AdminUser.Id,
  1138. }
  1139. service.CreateScheduleLog(scheduleLog)
  1140. if err == nil {
  1141. c.ServeSuccessJSON(map[string]interface{}{
  1142. "msg": "ok",
  1143. })
  1144. return
  1145. } else {
  1146. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1147. return
  1148. }
  1149. }
  1150. }
  1151. func (c *StaffScheduleApiController) UpdateMobileSchedule() {
  1152. id_one, _ := c.GetInt64("id_one")
  1153. id_two, _ := c.GetInt64("id_two")
  1154. schedule_date := c.GetString("schedule_date")
  1155. timeLayout := "2006-01-02"
  1156. loc, _ := time.LoadLocation("Local")
  1157. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", schedule_date+" 00:00:00", loc)
  1158. mode_id, _ := c.GetInt64("mode_id")
  1159. bed_id, _ := c.GetInt64("bed_id")
  1160. zone_id, _ := c.GetInt64("zone_id")
  1161. schedule_type, _ := c.GetInt64("schedule_type")
  1162. orgId := c.GetMobileAdminUserInfo().Org.Id
  1163. schedule, _ := service.GetSchedulePatientIdByPatient(id_one, startTime.Unix(), orgId)
  1164. if schedule.ID > 0 {
  1165. service.UpdateMobileSchedule(id_two, mode_id, bed_id, zone_id, schedule_type, schedule.ID)
  1166. }
  1167. c.ServeSuccessJSON(map[string]interface{}{
  1168. "msg": "ok",
  1169. })
  1170. return
  1171. }