staff_schedule_api_controller.go 42KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350
  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. if orgid == 10585 {
  367. //获取今日的排班数据
  368. list, _ := service.GetMobileScheduleListByScheduleDate(orgid, startTime)
  369. for _, item := range list {
  370. solution, _ := service.GetLongSolutionByModeId(item.PatientId, item.ModeId, item.UserOrgId)
  371. var str = solution.DialyzerPerfusionApparatus
  372. service.UpdateScheduleByDialysis(item.PatientId, item.ModeId, item.ScheduleDate, item.UserOrgId, str, item.ScheduleType)
  373. }
  374. }
  375. //查询排班里面的空透析器
  376. if orgid == 10375 {
  377. schedulesFive, _ := service.GetMobileScheduleListByScheduleDateOne(orgid, startTime)
  378. for _, item := range schedulesFive {
  379. solution, _ := service.GetLongSolutionByModeId(item.PatientId, item.ModeId, item.UserOrgId)
  380. var DialysisMachineName string
  381. if len(solution.DialysisDialyszers) > 0 {
  382. DialysisMachineName = solution.DialysisDialyszers
  383. }
  384. if len(solution.DialyzerPerfusionApparatus) > 0 {
  385. DialysisMachineName = DialysisMachineName + "," + solution.DialyzerPerfusionApparatus
  386. }
  387. if len(solution.DialysisIrrigation) > 0 {
  388. DialysisMachineName = DialysisMachineName + "," + solution.DialysisIrrigation
  389. }
  390. item.DialysisMachineName = DialysisMachineName
  391. service.UpdateSchOne(item.ID, item.DialysisMachineName)
  392. }
  393. }
  394. // stockType, _ := service.GetStockType(orgid)
  395. //zonelist, _ := service.GetPatientScheduleListByZone(startTime, classtype, orgid)
  396. // if err != nil {
  397. // this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  398. // return
  399. // }
  400. this.ServeSuccessJSON(map[string]interface{}{
  401. "schedule": list,
  402. // "stockType": stockType,
  403. //"zonelist": zonelist,
  404. })
  405. // id := this.GetMobileAdminUserInfo().Org.Id
  406. // zone, err := service.GetAllMobileZonePb(id)
  407. // if err != nil {
  408. // this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  409. // return
  410. // }
  411. // this.ServeSuccessJSON(map[string]interface{}{
  412. // "zone": zone,
  413. // })
  414. }
  415. func (this *StaffScheduleApiController) GetPatientScheduleList() {
  416. orgid := this.GetMobileAdminUserInfo().Org.Id
  417. fmt.Println("orgid", orgid)
  418. timeLayout := "2006-01-02"
  419. loc, _ := time.LoadLocation("Local")
  420. start_time := this.GetString("start_time")
  421. var startTime int64
  422. if len(start_time) > 0 {
  423. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  424. if err != nil {
  425. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  426. return
  427. }
  428. startTime = theTime.Unix()
  429. }
  430. zoneid, _ := this.GetInt64("zoneid")
  431. fmt.Println(zoneid)
  432. classtype, _ := this.GetInt64("classtype")
  433. is_open, _ := this.GetInt64("is_open")
  434. if is_open == 0 {
  435. //获取当天排班的病人情况
  436. schedule, err := service.GetPatientSchedule(startTime, zoneid, classtype, orgid)
  437. zonelist, _ := service.GetPatientScheduleListByZone(startTime, classtype, orgid)
  438. if err != nil {
  439. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  440. return
  441. }
  442. this.ServeSuccessJSON(map[string]interface{}{
  443. "schedule": schedule,
  444. "zonelist": zonelist,
  445. })
  446. }
  447. if is_open == 1 {
  448. //获取空床位的排班数据
  449. list, err := service.GetPatientScheduleByBed(startTime, zoneid, orgid, classtype)
  450. stockType, _ := service.GetStockType(orgid)
  451. zonelist, _ := service.GetPatientScheduleListByZone(startTime, classtype, orgid)
  452. if err != nil {
  453. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  454. return
  455. }
  456. this.ServeSuccessJSON(map[string]interface{}{
  457. "schedule": list,
  458. "stockType": stockType,
  459. "zonelist": zonelist,
  460. })
  461. }
  462. }
  463. func (this *StaffScheduleApiController) DeleteSchedule() {
  464. id, _ := this.GetInt64("id")
  465. org_id := this.GetMobileAdminUserInfo().Org.Id
  466. err := service.DeleteSchedule(id)
  467. if err == nil {
  468. schedule, _ := service.GetScheduleNight(org_id, id)
  469. //记录日志
  470. byterequest, _ := json.Marshal(schedule)
  471. xtScheduleLog := models.XtScheduleLog{
  472. UserOrgId: org_id,
  473. RecordDate: schedule.ScheduleDate,
  474. Status: 1,
  475. PatientId: schedule.PatientId,
  476. Ctime: time.Now().Unix(),
  477. Mtime: 0,
  478. ErrLog: string(byterequest),
  479. Source: "手机端删除排班",
  480. Module: 5,
  481. AdminUserId: this.GetMobileAdminUserInfo().AdminUser.Id,
  482. }
  483. service.CreateScheduleLog(xtScheduleLog)
  484. //针对凤凰医院
  485. if org_id == 10579 || org_id == 10344 || org_id == 10206 {
  486. advice, _ := service.GetDoctorAdviceListTwenty(schedule.PatientId, schedule.ScheduleDate, org_id)
  487. if len(advice) > 0 {
  488. service.UpdateAdviceObj(schedule.PatientId, schedule.ScheduleDate, org_id)
  489. }
  490. }
  491. if org_id == 10206 {
  492. advice, _ := service.GetHisDoctorAdviceListTwenty(schedule.PatientId, schedule.ScheduleDate, org_id)
  493. if len(advice) > 0 {
  494. service.UpdateHisAdviceObj(schedule.PatientId, schedule.ScheduleDate, org_id)
  495. }
  496. project, _ := service.GetHisPrescriptionProjectList(schedule.PatientId, schedule.ScheduleDate, org_id)
  497. if len(project) > 0 {
  498. service.UpdateProjectObj(schedule.PatientId, schedule.ScheduleDate, org_id)
  499. }
  500. }
  501. redis := service.RedisClient()
  502. //处方
  503. keyOne := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":prescriptions_list_all"
  504. redis.Set(keyOne, "", time.Second)
  505. //医嘱
  506. keyTwo := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":advice_list_all"
  507. redis.Set(keyTwo, "", time.Second)
  508. keySix := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_befores_list_all"
  509. redis.Set(keySix, "", time.Second)
  510. keyThree := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_after_dislysis_list_all"
  511. redis.Set(keyThree, "", time.Second)
  512. keyFour := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":monitor_record_list_all"
  513. redis.Set(keyFour, "", time.Second)
  514. keyFive := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":treatment_summarys_list_all"
  515. redis.Set(keyFive, "", time.Second)
  516. keySeven := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":dialysis_orders_list_all"
  517. redis.Set(keySeven, "", time.Second)
  518. defer redis.Close()
  519. fmt.Println(err)
  520. returnData := make(map[string]interface{}, 0)
  521. returnData["msg"] = "ok"
  522. this.ServeSuccessJSON(returnData)
  523. return
  524. } else {
  525. this.ServeFailJsonSend(enums.ErrorCodeDataException, "删除失败")
  526. return
  527. }
  528. }
  529. func (this *StaffScheduleApiController) SearchPatient() {
  530. timeLayout := "2006-01-02"
  531. loc, _ := time.LoadLocation("Local")
  532. keyword := this.GetString("keyword")
  533. fmt.Println(keyword)
  534. orgId := this.GetMobileAdminUserInfo().Org.Id
  535. start_time := this.GetString("start_time")
  536. var startTime int64
  537. if len(start_time) > 0 {
  538. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  539. if err != nil {
  540. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  541. return
  542. }
  543. startTime = theTime.Unix()
  544. }
  545. schedule, err := service.GetSearchPatient(keyword, orgId, startTime)
  546. if err != nil {
  547. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  548. return
  549. }
  550. this.ServeSuccessJSON(map[string]interface{}{
  551. "schedule": schedule,
  552. })
  553. }
  554. func (this *StaffScheduleApiController) UpdatePatientScheduleById() {
  555. ids := this.GetString("ids")
  556. idSplit := strings.Split(ids, ",")
  557. var err error
  558. //查询患者信息
  559. list, _ := service.GetStaffScheduleById(idSplit)
  560. if len(list) > 0 {
  561. for index, _ := range list {
  562. fmt.Println("index2322332", index)
  563. schedule := models.XtSchedule{
  564. PatientId: list[0].PatientId,
  565. ModeId: list[0].ModeId,
  566. DialysisMachineName: list[0].DialysisMachineName,
  567. }
  568. xtSchedule := models.WeekSchedule{
  569. PatientId: list[1].PatientId,
  570. ModeId: list[1].ModeId,
  571. DialysisMachineName: list[1].DialysisMachineName,
  572. }
  573. err = service.UpdateStaffSchedule(list[1].ID, schedule)
  574. fmt.Println("errrrrrrr2323323232323", err)
  575. service.UpdateStaffScheduleOne(list[0].ID, xtSchedule)
  576. }
  577. }
  578. fmt.Println(err)
  579. this.ServeSuccessJSON(map[string]interface{}{
  580. "msg": "切换成功",
  581. })
  582. }
  583. func (this *StaffScheduleApiController) UpdateDialysisPrescription() {
  584. patient_id, _ := this.GetInt64("patient_id")
  585. start_time, _ := this.GetInt64("start_time")
  586. mode_id, _ := this.GetInt64("mode_id")
  587. dialyzer_perfusion_apparatus := this.GetString("dialyzer_perfusion_apparatus")
  588. dialysis_irrigation := this.GetString("dialysis_irrigation")
  589. //更改透析模式
  590. _, errcode := service.GetDialyisSolution(patient_id, start_time)
  591. if errcode == gorm.ErrRecordNotFound {
  592. orgId := this.GetMobileAdminUserInfo().Org.Id
  593. prescription := models.DialysisPrescription{
  594. DialysisDialyszers: dialyzer_perfusion_apparatus,
  595. DialysisIrrigation: dialysis_irrigation,
  596. PatientId: patient_id,
  597. UserOrgId: orgId,
  598. Status: 1,
  599. RecordDate: start_time,
  600. CreatedTime: time.Now().Unix(),
  601. ModeId: mode_id,
  602. }
  603. err := service.CreateDialysisPrescription(&prescription)
  604. if err != nil {
  605. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  606. return
  607. }
  608. this.ServeSuccessJSON(map[string]interface{}{
  609. "msg": "保存成功",
  610. })
  611. } else if errcode == nil {
  612. prescription := models.DialysisPrescription{
  613. DialysisDialyszers: dialyzer_perfusion_apparatus,
  614. DialysisIrrigation: dialysis_irrigation,
  615. ModeId: mode_id,
  616. }
  617. err := service.UpdateDialysisPrescriptionOne(prescription, patient_id, start_time, mode_id)
  618. if err != nil {
  619. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  620. return
  621. }
  622. this.ServeSuccessJSON(map[string]interface{}{
  623. "msg": "保存成功",
  624. })
  625. }
  626. }
  627. func (this *StaffScheduleApiController) UpdateBloodScheduleMode() {
  628. id, _ := this.GetInt64("id")
  629. mode_id, _ := this.GetInt64("mode_id")
  630. schedule := models.XtSchedule{
  631. ModeId: mode_id,
  632. }
  633. service.UpdatedScheduleMode(schedule, id)
  634. orgId := this.GetMobileAdminUserInfo().Org.Id
  635. //记录日志
  636. byterequest, _ := json.Marshal(schedule)
  637. scheduleLog := models.XtScheduleLog{
  638. UserOrgId: orgId,
  639. RecordDate: schedule.ScheduleDate,
  640. Status: 1,
  641. PatientId: schedule.PatientId,
  642. Ctime: time.Now().Unix(),
  643. Mtime: 0,
  644. ErrLog: string(byterequest),
  645. Source: "手机端修改排班模式",
  646. Module: 5,
  647. AdminUserId: this.GetMobileAdminUserInfo().AdminUser.Id,
  648. }
  649. service.CreateScheduleLog(scheduleLog)
  650. this.ServeSuccessJSON(map[string]interface{}{
  651. "msg": "保存成功",
  652. })
  653. }
  654. func (this *StaffScheduleApiController) UpdateBloodSchedule() {
  655. patient_id, _ := this.GetInt64("patient_id")
  656. mode_id, _ := this.GetInt64("mode_id")
  657. schedule_type, _ := this.GetInt64("schedule_type")
  658. start_time, _ := this.GetInt64("start_time")
  659. bed_id, _ := this.GetInt64("bed_id")
  660. orgid := this.GetMobileAdminUserInfo().Org.Id
  661. //更改排班
  662. schedule := models.XtSchedule{
  663. ScheduleType: schedule_type,
  664. ModeId: mode_id,
  665. }
  666. //查询该床位该班次是否存在排班
  667. _, errschedulecode := service.GetPatientScheduleIsExist(start_time, schedule_type, bed_id, orgid)
  668. if errschedulecode == gorm.ErrRecordNotFound {
  669. service.UpdatedSchedule(schedule, patient_id, start_time, schedule_type, bed_id)
  670. //记录日志
  671. byterequest, _ := json.Marshal(schedule)
  672. scheduleLog := models.XtScheduleLog{
  673. UserOrgId: orgid,
  674. RecordDate: schedule.ScheduleDate,
  675. Status: 1,
  676. PatientId: schedule.PatientId,
  677. Ctime: time.Now().Unix(),
  678. Mtime: 0,
  679. ErrLog: string(byterequest),
  680. Source: "手机修改排班班次",
  681. Module: 5,
  682. AdminUserId: this.GetMobileAdminUserInfo().AdminUser.Id,
  683. }
  684. service.CreateScheduleLog(scheduleLog)
  685. this.ServeSuccessJSON(map[string]interface{}{
  686. "msgerr": "保存成功",
  687. })
  688. } else if errschedulecode == nil {
  689. this.ServeSuccessJSON(map[string]interface{}{
  690. "msg": "1",
  691. "msgerr": "排班已存在",
  692. })
  693. }
  694. }
  695. func (this *StaffScheduleApiController) GetSchedulePatient() {
  696. schedule, _ := this.GetInt64("schedule", 0) //1已2未
  697. contagion, _ := this.GetInt64("contagion", 0)
  698. keywords := this.GetString("keywords", "")
  699. adminInfo := this.GetMobileAdminUserInfo()
  700. thisTime := time.Now()
  701. weekDay := int(thisTime.Weekday())
  702. if weekDay == 0 {
  703. weekDay = 7
  704. }
  705. thisWeekEnd := 7 - weekDay
  706. weekStartPoint := thisWeekEnd - 6
  707. weekStartDay := thisTime.AddDate(0, 0, weekStartPoint)
  708. weekEndPoint := thisWeekEnd + 7
  709. weekEndDay := thisTime.AddDate(0, 0, weekEndPoint)
  710. fmt.Println(weekStartPoint, weekStartDay, weekEndPoint, weekEndDay)
  711. weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
  712. weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
  713. fmt.Println(weekStartTime, weekEndTime)
  714. timeLayout := "2006-01-02 15:04:05"
  715. loc, _ := time.LoadLocation("Local")
  716. theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
  717. theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
  718. weekStart := theStarTime.Unix()
  719. weekEnd := theEndTime.Unix()
  720. patients, _ := service.GetPatientWithScheduleAndSolutionTwo(adminInfo.Org.Id, keywords, weekStart, weekEnd, schedule, contagion)
  721. this.ServeSuccessJSON(map[string]interface{}{
  722. "patients": patients,
  723. })
  724. return
  725. }
  726. func (c *StaffScheduleApiController) CreateMobileSchedulePatient() {
  727. patientID, _ := c.GetInt64("patient_id", 0)
  728. if patientID <= 0 {
  729. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  730. return
  731. }
  732. adminUserInfo := c.GetMobileAdminUserInfo()
  733. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patientID)
  734. if patientInfo.ID == 0 {
  735. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  736. return
  737. }
  738. var schedule models.Schedule
  739. dataBody := make(map[string]interface{}, 0)
  740. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  741. if err != nil {
  742. utils.ErrorLog(err.Error())
  743. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  744. return
  745. }
  746. if dataBody["schedule_date"] == nil || reflect.TypeOf(dataBody["schedule_date"]).String() != "string" {
  747. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  748. return
  749. }
  750. scheduleDate, _ := dataBody["schedule_date"].(string)
  751. if len(scheduleDate) == 0 {
  752. utils.ErrorLog("len(schedule_date) == 0")
  753. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  754. return
  755. }
  756. timeLayout := "2006-01-02"
  757. loc, _ := time.LoadLocation("Local")
  758. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", scheduleDate+" 00:00:00", loc)
  759. if err != nil {
  760. utils.ErrorLog(err.Error())
  761. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  762. return
  763. }
  764. schedule.ScheduleDate = theTime.Unix()
  765. timeNow := time.Now().Format("2006-01-02")
  766. if timeNow > scheduleDate {
  767. utils.ErrorLog(timeNow)
  768. utils.ErrorLog(scheduleDate)
  769. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleBeforeNow)
  770. return
  771. }
  772. if dataBody["schedule_type"] == nil || reflect.TypeOf(dataBody["schedule_type"]).String() != "float64" {
  773. utils.ErrorLog("schedule_type")
  774. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  775. return
  776. }
  777. scheduleType := int64(dataBody["schedule_type"].(float64))
  778. if scheduleType < 1 || scheduleType > 3 {
  779. utils.ErrorLog("scheduleType < 3")
  780. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  781. return
  782. }
  783. schedule.ScheduleType = scheduleType
  784. if dataBody["bed_id"] == nil || reflect.TypeOf(dataBody["bed_id"]).String() != "float64" {
  785. utils.ErrorLog("bed_id")
  786. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  787. return
  788. }
  789. bedId := int64(dataBody["bed_id"].(float64))
  790. if bedId < 1 {
  791. utils.ErrorLog("bedId < 1")
  792. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  793. return
  794. }
  795. schedule.BedId = bedId
  796. if dataBody["partition_id"] == nil || reflect.TypeOf(dataBody["partition_id"]).String() != "float64" {
  797. utils.ErrorLog("partition_id")
  798. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  799. return
  800. }
  801. partitionId := int64(dataBody["partition_id"].(float64))
  802. if partitionId < 1 {
  803. utils.ErrorLog("partitionId < 1")
  804. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  805. return
  806. }
  807. schedule.PartitionId = partitionId
  808. if dataBody["schedule_week"] == nil || reflect.TypeOf(dataBody["schedule_week"]).String() != "float64" {
  809. utils.ErrorLog("schedule_week")
  810. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  811. return
  812. }
  813. scheduleWeek := int64(dataBody["schedule_week"].(float64))
  814. if scheduleWeek < 1 || scheduleWeek > 7 {
  815. utils.ErrorLog("scheduleWeek < 1")
  816. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  817. return
  818. }
  819. schedule.ScheduleWeek = scheduleWeek
  820. if dataBody["mode_id"] == nil || reflect.TypeOf(dataBody["mode_id"]).String() != "float64" {
  821. utils.ErrorLog("mode_id")
  822. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  823. return
  824. }
  825. modeId := int64(dataBody["mode_id"].(float64))
  826. if modeId < 1 && modeId > 14 {
  827. utils.ErrorLog("modeId < 1")
  828. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  829. return
  830. }
  831. schedule.ModeId = modeId
  832. schedule.PatientId = patientID
  833. schedule.CreatedTime = time.Now().Unix()
  834. schedule.UpdatedTime = time.Now().Unix()
  835. schedule.Status = 1
  836. schedule.IsExport = 6000
  837. schedule.UserOrgId = adminUserInfo.Org.Id
  838. bed, _ := service.GetDeviceNumberByID(adminUserInfo.Org.Id, schedule.BedId)
  839. if bed == nil {
  840. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotExist)
  841. return
  842. }
  843. if bed.ZoneID != schedule.PartitionId {
  844. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotTheZone)
  845. return
  846. }
  847. scheduleDateStart := scheduleDate + " 00:00:00"
  848. scheduleDateEnd := scheduleDate + " 23:59:59"
  849. timeLayout = "2006-01-02 15:04:05"
  850. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  851. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  852. startTime := theStartTime.Unix()
  853. endTime := theEndTime.Unix()
  854. //一天只有排班一次
  855. daySchedule, err := service.GetDaySchedule(adminUserInfo.Org.Id, startTime, endTime, patientID)
  856. if daySchedule.ID > 0 {
  857. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleAgainOneDay)
  858. return
  859. }
  860. //同天同位置只能排一个
  861. pointSchedule, err := service.GetPointSchedule(adminUserInfo.Org.Id, schedule.ScheduleDate, schedule.ScheduleWeek, schedule.ScheduleType, schedule.BedId)
  862. if err != nil {
  863. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  864. return
  865. }
  866. if pointSchedule.ID > 0 {
  867. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePointScheduleExist)
  868. return
  869. }
  870. redis := service.RedisClient()
  871. err = service.CreateScheduleTwo(&schedule)
  872. service.UpdateRepeatSchStatus(adminUserInfo.Org.Id, schedule.ScheduleDate)
  873. key := "scheduals_" + scheduleDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  874. redis.Set(key, "", time.Second)
  875. defer redis.Close()
  876. fmt.Println(err)
  877. if err != nil {
  878. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateScheduleFail)
  879. return
  880. }
  881. schedule.Patient = patientInfo.Name
  882. c.ServeSuccessJSON(map[string]interface{}{
  883. "msg": "ok",
  884. "schedule": schedule,
  885. })
  886. return
  887. }
  888. func (c *StaffScheduleApiController) GetSolutionSchedule() {
  889. orgId := c.GetMobileAdminUserInfo().Org.Id
  890. scheduleDate := c.GetString("start_time")
  891. zoneid, _ := c.GetInt64("zoneid")
  892. classtype, _ := c.GetInt64("classtype")
  893. timeLayout := "2006-01-02"
  894. loc, _ := time.LoadLocation("Local")
  895. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", scheduleDate+" 00:00:00", loc)
  896. schedule, _ := service.GetSolutionScheduleBySchedule(orgId, zoneid, classtype, theTime.Unix())
  897. c.ServeSuccessJSON(map[string]interface{}{
  898. "schedule": schedule,
  899. })
  900. }
  901. func (c *StaffScheduleApiController) GetAllBedList() {
  902. orgId := c.GetMobileAdminUserInfo().Org.Id
  903. partition_id, _ := c.GetInt64("partition_id")
  904. list, _ := service.GetAllBedNumberTen(orgId, partition_id)
  905. c.ServeSuccessJSON(map[string]interface{}{
  906. "list": list,
  907. })
  908. }
  909. func (c *StaffScheduleApiController) ChangeScheduleById() {
  910. id, _ := c.GetInt64("id")
  911. mode_id, _ := c.GetInt64("mode_id")
  912. schedule_date, _ := c.GetInt64("schedule_date")
  913. patient_id, _ := c.GetInt64("patient_id")
  914. org_id := c.GetMobileAdminUserInfo().Org.Id
  915. err := service.ChangeScheduleById(id, mode_id)
  916. fmt.Println("err", err)
  917. err = service.ChangeDialysisSolution(patient_id, schedule_date, org_id, mode_id)
  918. c.ServeSuccessJSON(map[string]interface{}{
  919. "msg": "ok",
  920. })
  921. }
  922. func (c *StaffScheduleApiController) ChangeScheduleType() {
  923. schedule_type, _ := c.GetInt64("schedule_type")
  924. schedule_date, _ := c.GetInt64("schedule_date")
  925. patient_id, _ := c.GetInt64("patient_id")
  926. bed_id, _ := c.GetInt64("bed_id")
  927. //schedule_week, _ := c.GetInt64("schedule_week")
  928. mode_id, _ := c.GetInt64("mode_id")
  929. id, _ := c.GetInt64("id")
  930. org_id := c.GetMobileAdminUserInfo().Org.Id
  931. //查询该班次该床位是否已经存在患者
  932. schedule, _ := service.GetScheduleByClassType(schedule_type, schedule_date, bed_id, org_id)
  933. //查询该床位所属分区
  934. //numberlist, _ := service.GetPartionId(bed_id, org_id)
  935. //存在
  936. if schedule.ID > 0 {
  937. order, _ := service.GetDialysisOrder(schedule.ScheduleDate, schedule.PatientId, schedule.UserOrgId)
  938. if order.ID > 0 {
  939. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSchedule)
  940. return
  941. }
  942. //调换位置
  943. sch := models.Schedule{
  944. PatientId: schedule.PatientId,
  945. ModeId: schedule.ModeId,
  946. }
  947. var DialysisMachineName string
  948. so, _ := service.GetDialysisSolutionTwo(org_id, sch.PatientId, sch.ModeId)
  949. filedRecordOne, _ := service.FindFiledBy(org_id, "透析器")
  950. filedRecordTwo, _ := service.FindFiledBy(org_id, "灌流器")
  951. filedRecordThree, _ := service.FindFiledBy(org_id, "透析器/灌流器")
  952. if filedRecordOne.IsShow == 1 {
  953. DialysisMachineName = so.DialysisDialyszers
  954. }
  955. if filedRecordThree.IsShow == 1 {
  956. if len(DialysisMachineName) > 0 {
  957. DialysisMachineName = DialysisMachineName + "*" + so.DialyzerPerfusionApparatus
  958. } else {
  959. DialysisMachineName = so.DialyzerPerfusionApparatus
  960. }
  961. }
  962. if filedRecordTwo.IsShow == 1 {
  963. if len(DialysisMachineName) > 0 {
  964. DialysisMachineName = DialysisMachineName + "*" + so.DialysisIrrigation
  965. } else {
  966. DialysisMachineName = so.DialysisIrrigation
  967. }
  968. }
  969. sch.DialysisMachineName = DialysisMachineName
  970. schedu := models.Schedule{
  971. PatientId: patient_id,
  972. ModeId: mode_id,
  973. }
  974. var DialysisMachineName1 string
  975. so1, _ := service.GetDialysisSolutionTwo(org_id, schedu.PatientId, schedu.ModeId)
  976. filedRecordOne1, _ := service.FindFiledBy(org_id, "透析器")
  977. filedRecordTwo1, _ := service.FindFiledBy(org_id, "灌流器")
  978. filedRecordThree1, _ := service.FindFiledBy(org_id, "透析器/灌流器")
  979. if filedRecordOne1.IsShow == 1 {
  980. DialysisMachineName1 = so1.DialysisDialyszers
  981. }
  982. if filedRecordThree1.IsShow == 1 {
  983. if len(DialysisMachineName1) > 0 {
  984. DialysisMachineName1 = DialysisMachineName1 + "*" + so1.DialyzerPerfusionApparatus
  985. } else {
  986. DialysisMachineName1 = so1.DialyzerPerfusionApparatus
  987. }
  988. }
  989. if filedRecordTwo1.IsShow == 1 {
  990. if len(DialysisMachineName1) > 0 {
  991. DialysisMachineName1 = DialysisMachineName1 + "*" + so1.DialysisIrrigation
  992. } else {
  993. DialysisMachineName1 = so1.DialysisIrrigation
  994. }
  995. }
  996. schedu.DialysisMachineName = DialysisMachineName1
  997. err := service.UpdateScheduleById(schedule.ID, schedu, id, sch)
  998. if err == nil {
  999. c.ServeSuccessJSON(map[string]interface{}{
  1000. "msg": "ok",
  1001. })
  1002. } else {
  1003. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1004. return
  1005. }
  1006. } else {
  1007. xtSchedule := models.Schedule{
  1008. ScheduleDate: schedule_date,
  1009. ScheduleType: schedule_type,
  1010. PatientId: patient_id,
  1011. UserOrgId: org_id,
  1012. }
  1013. err := service.ChangeScheduleClass(xtSchedule)
  1014. if err == nil {
  1015. c.ServeSuccessJSON(map[string]interface{}{
  1016. "msg": "ok",
  1017. })
  1018. } else {
  1019. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1020. return
  1021. }
  1022. }
  1023. }
  1024. func (c *StaffScheduleApiController) ChangeScheduleBed() {
  1025. schedule_type, _ := c.GetInt64("schedule_type")
  1026. schedule_date, _ := c.GetInt64("schedule_date")
  1027. patient_id, _ := c.GetInt64("patient_id")
  1028. bed_id, _ := c.GetInt64("bed_id")
  1029. schedule_week, _ := c.GetInt64("schedule_week")
  1030. mode_id, _ := c.GetInt64("mode_id")
  1031. id, _ := c.GetInt64("id")
  1032. org_id := c.GetMobileAdminUserInfo().Org.Id
  1033. temp_schedule, _ := service.GetScheduleByClassTypeTwo(schedule_type, schedule_date, patient_id, org_id)
  1034. id = temp_schedule.ID
  1035. //查询该班次该床位是否已经存在患者
  1036. schedule, _ := service.GetScheduleByClassType(schedule_type, schedule_date, bed_id, org_id)
  1037. //查询该床位所属分区
  1038. numberlist, _ := service.GetPartionId(bed_id, org_id)
  1039. //存在
  1040. if schedule.ID > 0 {
  1041. order, _ := service.GetDialysisOrder(schedule.ScheduleDate, schedule.PatientId, schedule.UserOrgId)
  1042. if order.ID > 0 {
  1043. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSchedule)
  1044. return
  1045. }
  1046. //调换位置
  1047. sch := models.Schedule{
  1048. PatientId: schedule.PatientId,
  1049. ModeId: schedule.ModeId,
  1050. DialysisMachineName: schedule.DialysisMachineName,
  1051. }
  1052. var DialysisMachineName string
  1053. so, _ := service.GetDialysisSolutionTwo(org_id, sch.PatientId, sch.ModeId)
  1054. filedRecordOne, _ := service.FindFiledBy(org_id, "透析器")
  1055. filedRecordTwo, _ := service.FindFiledBy(org_id, "灌流器")
  1056. filedRecordThree, _ := service.FindFiledBy(org_id, "透析器/灌流器")
  1057. if filedRecordOne.IsShow == 1 {
  1058. DialysisMachineName = so.DialysisDialyszers
  1059. }
  1060. if filedRecordThree.IsShow == 1 {
  1061. if len(DialysisMachineName) > 0 {
  1062. DialysisMachineName = DialysisMachineName + "-" + so.DialyzerPerfusionApparatus
  1063. } else {
  1064. DialysisMachineName = so.DialyzerPerfusionApparatus
  1065. }
  1066. }
  1067. if filedRecordTwo.IsShow == 1 {
  1068. if len(DialysisMachineName) > 0 {
  1069. DialysisMachineName = DialysisMachineName + "-" + so.DialysisIrrigation
  1070. } else {
  1071. DialysisMachineName = so.DialysisIrrigation
  1072. }
  1073. }
  1074. sch.DialysisMachineName = DialysisMachineName
  1075. schedu := models.Schedule{
  1076. PatientId: patient_id,
  1077. ModeId: mode_id,
  1078. DialysisMachineName: schedule.DialysisMachineName,
  1079. }
  1080. var DialysisMachineName1 string
  1081. so1, _ := service.GetDialysisSolutionTwo(org_id, schedu.PatientId, schedu.ModeId)
  1082. filedRecordOne1, _ := service.FindFiledBy(org_id, "透析器")
  1083. filedRecordTwo1, _ := service.FindFiledBy(org_id, "灌流器")
  1084. filedRecordThree1, _ := service.FindFiledBy(org_id, "透析器/灌流器")
  1085. if filedRecordOne1.IsShow == 1 {
  1086. DialysisMachineName1 = so1.DialysisDialyszers
  1087. }
  1088. if filedRecordThree1.IsShow == 1 {
  1089. if len(DialysisMachineName1) > 0 {
  1090. DialysisMachineName1 = DialysisMachineName1 + "-" + so1.DialyzerPerfusionApparatus
  1091. } else {
  1092. DialysisMachineName1 = so1.DialyzerPerfusionApparatus
  1093. }
  1094. }
  1095. if filedRecordTwo1.IsShow == 1 {
  1096. if len(DialysisMachineName1) > 0 {
  1097. DialysisMachineName1 = DialysisMachineName1 + "-" + so1.DialysisIrrigation
  1098. } else {
  1099. DialysisMachineName1 = so1.DialysisIrrigation
  1100. }
  1101. }
  1102. schedu.DialysisMachineName = DialysisMachineName1
  1103. err := service.UpdateScheduleById(schedule.ID, schedu, id, sch)
  1104. //记录日志
  1105. byterequest, _ := json.Marshal(schedule)
  1106. scheduleLog := models.XtScheduleLog{
  1107. UserOrgId: org_id,
  1108. RecordDate: schedule.ScheduleDate,
  1109. Status: 1,
  1110. PatientId: schedule.PatientId,
  1111. Ctime: time.Now().Unix(),
  1112. Mtime: 0,
  1113. ErrLog: string(byterequest),
  1114. Source: "手机端修改调班",
  1115. Module: 4,
  1116. AdminUserId: c.GetMobileAdminUserInfo().AdminUser.Id,
  1117. }
  1118. service.UpdateRepeatSchStatus(org_id, schedule_date)
  1119. service.CreateScheduleLog(scheduleLog)
  1120. if err == nil {
  1121. c.ServeSuccessJSON(map[string]interface{}{
  1122. "msg": "ok",
  1123. })
  1124. } else {
  1125. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1126. return
  1127. }
  1128. } else {
  1129. var str string
  1130. //查找该机构用的是什么透析器
  1131. filedConfig, _ := service.GetFiledConfig(org_id)
  1132. if filedConfig.ID > 0 {
  1133. solutionType, _ := service.GetLastDialysisSolutionType(org_id, patient_id, mode_id)
  1134. str = solutionType.DialyzerPerfusionApparatus
  1135. } else {
  1136. solutionType, _ := service.GetLastDialysisSolutionType(org_id, patient_id, mode_id)
  1137. str = solutionType.DialysisDialyszers + "/" + solutionType.DialysisIrrigation
  1138. }
  1139. xtSchedule := models.Schedule{
  1140. UserOrgId: org_id,
  1141. PartitionId: numberlist.ZoneId,
  1142. BedId: bed_id,
  1143. PatientId: patient_id,
  1144. ScheduleDate: schedule_date,
  1145. ScheduleType: schedule_type,
  1146. ScheduleWeek: schedule_week,
  1147. ModeId: mode_id,
  1148. Status: 1,
  1149. CreatedTime: time.Now().Unix(),
  1150. UpdatedTime: 0,
  1151. IsExport: 20000,
  1152. DialysisMachineName: str,
  1153. }
  1154. var err error
  1155. err = service.CreateSchedule(&xtSchedule, id)
  1156. service.UpdateRepeatSchStatus(org_id, schedule_date)
  1157. //记录日志
  1158. byterequest, _ := json.Marshal(schedule)
  1159. scheduleLog := models.XtScheduleLog{
  1160. UserOrgId: org_id,
  1161. RecordDate: schedule.ScheduleDate,
  1162. Status: 1,
  1163. PatientId: schedule.PatientId,
  1164. Ctime: time.Now().Unix(),
  1165. Mtime: 0,
  1166. ErrLog: string(byterequest),
  1167. Source: "手机端新建调班",
  1168. Module: 1,
  1169. AdminUserId: c.GetMobileAdminUserInfo().AdminUser.Id,
  1170. }
  1171. service.CreateScheduleLog(scheduleLog)
  1172. if err == nil {
  1173. c.ServeSuccessJSON(map[string]interface{}{
  1174. "msg": "ok",
  1175. })
  1176. return
  1177. } else {
  1178. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1179. return
  1180. }
  1181. }
  1182. }
  1183. func (c *StaffScheduleApiController) UpdateMobileSchedule() {
  1184. id_one, _ := c.GetInt64("id_one")
  1185. id_two, _ := c.GetInt64("id_two")
  1186. schedule_date, _ := c.GetInt64("schedule_date")
  1187. //timeLayout := "2006-01-02"
  1188. //loc, _ := time.LoadLocation("Local")
  1189. //startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", schedule_date+" 00:00:00", loc)
  1190. mode_id, _ := c.GetInt64("mode_id")
  1191. bed_id, _ := c.GetInt64("bed_id")
  1192. zone_id, _ := c.GetInt64("zone_id")
  1193. schedule_type, _ := c.GetInt64("schedule_type")
  1194. orgId := c.GetMobileAdminUserInfo().Org.Id
  1195. schedule, _ := service.GetSchedulePatientIdByPatient(id_one, schedule_date, orgId)
  1196. if schedule.ID > 0 {
  1197. service.UpdateMobileSchedule(id_two, mode_id, bed_id, zone_id, schedule_type, schedule.ID)
  1198. }
  1199. c.ServeSuccessJSON(map[string]interface{}{
  1200. "msg": "ok",
  1201. })
  1202. return
  1203. }