schedule_template_api_controller.go 77KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "strconv"
  6. "strings"
  7. "time"
  8. "XT_New/enums"
  9. "XT_New/models"
  10. "XT_New/service"
  11. "github.com/astaxie/beego"
  12. )
  13. func PatientScheduleTemplateAPIControllerRegistRouters() {
  14. beego.Router("/api/schtemp/p/initdata", &PatientScheduleTemplateAPIController{}, "get:InitData")
  15. beego.Router("/api/schtemp/p/setmode", &PatientScheduleTemplateAPIController{}, "post:SetMode")
  16. beego.Router("/api/schtemp/p/update_sch", &PatientScheduleTemplateAPIController{}, "post:UpdateSchedules")
  17. beego.Router("/api/patients/list", &PatientScheduleTemplateAPIController{}, "get:GetPatientList")
  18. beego.Router("/api/schedule/update_schtemplate", &PatientScheduleTemplateAPIController{}, "post:UpdateSchedulesTemplate")
  19. beego.Router("/api/schtemplate_device/get", &ScheduleApiController{}, "Get:GetTemplateDevicesNumbers")
  20. beego.Router("/api/schtemplate/exchange", &ScheduleApiController{}, "Get:ExchangeSchTemplate")
  21. beego.Router("/api/schtemplate/coversch", &ScheduleApiController{}, "Get:CoverSchTemplate")
  22. beego.Router("/api/schtemplate/change", &ScheduleApiController{}, "post:DeleteAndAddScheduleTemplateTwo")
  23. beego.Router("/api/schtemplate/save", &ScheduleApiController{}, "post:SaveSchTemplate")
  24. }
  25. func (c *ScheduleApiController) SaveSchTemplate() {
  26. templates, _ := service.GetOrgPatientScheduleTemplateIDs(c.GetAdminUserInfo().CurrentOrgId)
  27. mode, _ := service.GetPatientScheduleTempalate(c.GetAdminUserInfo().CurrentOrgId)
  28. t := time.Now()
  29. yearDay := t.YearDay()
  30. yearFirstDay := t.AddDate(0, 0, -yearDay+1)
  31. firstDayInWeek := int(yearFirstDay.Weekday())
  32. //今年第一周有几天
  33. firstWeekDays := 1
  34. if firstDayInWeek != 0 {
  35. firstWeekDays = 7 - firstDayInWeek + 1
  36. }
  37. var week int
  38. if yearDay <= firstWeekDays {
  39. week = 1
  40. } else {
  41. week = (yearDay-firstWeekDays)/7 + 2
  42. }
  43. var schedules []models.Schedule
  44. fmt.Println(week)
  45. if mode.Mode == 1 {
  46. for _, item := range templates {
  47. if item.Week > 0 {
  48. timeArr := WeekIntervalTime(0) //获取本周的周一到周日
  49. nextTimeArr := WeekIntervalTime(1) //获取下周的周一到周日
  50. nextnextTimeArr := WeekIntervalTime(2) //获取下下周的周一到周日
  51. t := time.Now()
  52. week_day, _ := strconv.Atoi(t.Weekday().String())
  53. if week_day == 0 {
  54. week_day = 7
  55. }
  56. items, _ := service.GetTemplateListByTemplateId(item.ID, item.OrgID)
  57. //处理本周,先判断当前属于周几
  58. for _, item := range items {
  59. var schedule models.Schedule
  60. if int(item.Weekday) > week_day {
  61. schedule.IsExport = 400000
  62. var DialysisMachineName string
  63. so, _ := service.GetDialysisSolutionTwo(item.OrgID, item.PatientID, item.TreatMode)
  64. filedRecordOne, _ := service.FindFiledBy(item.OrgID, "透析器")
  65. filedRecordTwo, _ := service.FindFiledBy(item.OrgID, "灌流器")
  66. filedRecordThree, _ := service.FindFiledBy(item.OrgID, "透析器/灌流器")
  67. if filedRecordOne.IsShow == 1 {
  68. DialysisMachineName = so.DialysisDialyszers
  69. }
  70. if filedRecordThree.IsShow == 1 {
  71. if len(DialysisMachineName) > 0 {
  72. DialysisMachineName = DialysisMachineName + "*" + so.DialyzerPerfusionApparatus
  73. } else {
  74. DialysisMachineName = so.DialyzerPerfusionApparatus
  75. }
  76. }
  77. if filedRecordTwo.IsShow == 1 {
  78. if len(DialysisMachineName) > 0 {
  79. DialysisMachineName = DialysisMachineName + "*" + so.DialysisIrrigation
  80. } else {
  81. DialysisMachineName = so.DialysisIrrigation
  82. }
  83. }
  84. schedule.DialysisMachineName = DialysisMachineName
  85. schedule.ScheduleType = item.TimeType
  86. schedule.ModeId = item.TreatMode
  87. schedule.ScheduleWeek = item.Weekday
  88. schedule.BedId = item.DeviceNumberID
  89. formatTime, _ := time.Parse("2006-01-02", timeArr[int(item.Weekday)])
  90. schedule.ScheduleDate = formatTime.Unix()
  91. schedule.UserOrgId = item.OrgID
  92. schedule.Status = 1
  93. schedule.CreatedTime = time.Now().Unix()
  94. schedule.UpdatedTime = time.Now().Unix()
  95. device, _ := service.GetDeviceByID(item.OrgID, item.DeviceNumberID)
  96. schedule.PartitionId = device.DeviceZoneID
  97. schedules = append(schedules, schedule)
  98. }
  99. }
  100. //处理下周
  101. for _, item := range items {
  102. var schedule models.Schedule
  103. schedule.IsExport = 400000
  104. var DialysisMachineName string
  105. so, _ := service.GetDialysisSolutionTwo(item.OrgID, item.PatientID, item.TreatMode)
  106. filedRecordOne, _ := service.FindFiledBy(item.OrgID, "透析器")
  107. filedRecordTwo, _ := service.FindFiledBy(item.OrgID, "灌流器")
  108. filedRecordThree, _ := service.FindFiledBy(item.OrgID, "透析器/灌流器")
  109. if filedRecordOne.IsShow == 1 {
  110. DialysisMachineName = so.DialysisDialyszers
  111. }
  112. if filedRecordThree.IsShow == 1 {
  113. if len(DialysisMachineName) > 0 {
  114. DialysisMachineName = DialysisMachineName + "*" + so.DialyzerPerfusionApparatus
  115. } else {
  116. DialysisMachineName = so.DialyzerPerfusionApparatus
  117. }
  118. }
  119. if filedRecordTwo.IsShow == 1 {
  120. if len(DialysisMachineName) > 0 {
  121. DialysisMachineName = DialysisMachineName + "*" + so.DialysisIrrigation
  122. } else {
  123. DialysisMachineName = so.DialysisIrrigation
  124. }
  125. }
  126. schedule.DialysisMachineName = DialysisMachineName
  127. schedule.ScheduleType = item.TimeType
  128. schedule.ModeId = item.TreatMode
  129. schedule.ScheduleWeek = item.Weekday
  130. schedule.BedId = item.DeviceNumberID
  131. formatTime, _ := time.Parse("2006-01-02", nextTimeArr[int(item.Weekday)])
  132. schedule.ScheduleDate = formatTime.Unix()
  133. schedule.UserOrgId = item.OrgID
  134. schedule.Status = 1
  135. schedule.CreatedTime = time.Now().Unix()
  136. schedule.UpdatedTime = time.Now().Unix()
  137. device, _ := service.GetDeviceByID(item.OrgID, item.DeviceNumberID)
  138. schedule.PartitionId = device.DeviceZoneID
  139. schedules = append(schedules, schedule)
  140. }
  141. //处理下下周,先判断当前属于周几
  142. for _, item := range items {
  143. var schedule models.Schedule
  144. schedule.IsExport = 400000
  145. var DialysisMachineName string
  146. so, _ := service.GetDialysisSolutionTwo(item.OrgID, item.PatientID, item.TreatMode)
  147. filedRecordOne, _ := service.FindFiledBy(item.OrgID, "透析器")
  148. filedRecordTwo, _ := service.FindFiledBy(item.OrgID, "灌流器")
  149. filedRecordThree, _ := service.FindFiledBy(item.OrgID, "透析器/灌流器")
  150. if filedRecordOne.IsShow == 1 {
  151. DialysisMachineName = so.DialysisDialyszers
  152. }
  153. if filedRecordThree.IsShow == 1 {
  154. if len(DialysisMachineName) > 0 {
  155. DialysisMachineName = DialysisMachineName + "*" + so.DialyzerPerfusionApparatus
  156. } else {
  157. DialysisMachineName = so.DialyzerPerfusionApparatus
  158. }
  159. }
  160. if filedRecordTwo.IsShow == 1 {
  161. if len(DialysisMachineName) > 0 {
  162. DialysisMachineName = DialysisMachineName + "*" + so.DialysisIrrigation
  163. } else {
  164. DialysisMachineName = so.DialysisIrrigation
  165. }
  166. }
  167. schedule.DialysisMachineName = DialysisMachineName
  168. schedule.ScheduleType = item.TimeType
  169. schedule.ModeId = item.TreatMode
  170. schedule.ScheduleWeek = item.Weekday
  171. schedule.BedId = item.DeviceNumberID
  172. formatTime, _ := time.Parse("2006-01-02", nextnextTimeArr[int(item.Weekday)])
  173. schedule.ScheduleDate = formatTime.Unix()
  174. schedule.UserOrgId = item.OrgID
  175. schedule.Status = 1
  176. schedule.CreatedTime = time.Now().Unix()
  177. schedule.UpdatedTime = time.Now().Unix()
  178. device, _ := service.GetDeviceByID(item.OrgID, item.DeviceNumberID)
  179. schedule.PartitionId = device.DeviceZoneID
  180. schedules = append(schedules, schedule)
  181. }
  182. }
  183. }
  184. } else if mode.Mode == 2 {
  185. for _, item := range templates {
  186. if item.Week > 0 {
  187. switch item.Week - week {
  188. case -1: //当前模板是上周的模板
  189. ////根据模板类型,来判断需要修改哪几周数据,模板类型:单周模板,双周模板,三周模板,四周模板
  190. ////如果是单周模板:则修改本周除了当天未来的数据,下周,下下周数据
  191. ////如果是双周模板:则修改下周数据
  192. ////如果是三周模板:则修改下下周数据
  193. ////如果是四周模板:则不用修改数据
  194. //nextTimeArr := WeekIntervalTime(1) //获取下周的周一到周日
  195. //t := time.Now()
  196. //week_day,_ := strconv.Atoi(t.Weekday().String())
  197. //if week_day == 0{
  198. // week_day = 7
  199. //}
  200. //items, _ := service.GetTemplateListByTemplateId(item.ID,item.OrgID)
  201. //var schedules []models.Schedule
  202. ////处理下周
  203. //for _,item := range items{
  204. // var schedule models.Schedule
  205. // schedule.IsExport = 400000
  206. // var DialysisMachineName string
  207. // so, _ := service.GetDialysisSolutionTwo(item.OrgID, item.PatientID, item.TreatMode)
  208. // filedRecordOne, _ := service.FindFiledBy(item.OrgID, "透析器")
  209. // filedRecordTwo, _ := service.FindFiledBy(item.OrgID, "灌流器")
  210. // filedRecordThree, _ := service.FindFiledBy(item.OrgID, "透析器/灌流器")
  211. // if filedRecordOne.IsShow == 1 {
  212. // DialysisMachineName = so.DialysisDialyszers
  213. // }
  214. // if filedRecordThree.IsShow == 1 {
  215. // if len(DialysisMachineName) > 0 {
  216. // DialysisMachineName = DialysisMachineName + "*" + so.DialyzerPerfusionApparatus
  217. // } else {
  218. // DialysisMachineName = so.DialyzerPerfusionApparatus
  219. // }
  220. // }
  221. // if filedRecordTwo.IsShow == 1 {
  222. // if len(DialysisMachineName) > 0 {
  223. // DialysisMachineName = DialysisMachineName + "*" + so.DialysisIrrigation
  224. // } else {
  225. // DialysisMachineName = so.DialysisIrrigation
  226. // }
  227. // }
  228. // schedule.DialysisMachineName = DialysisMachineName
  229. // schedule.ScheduleType = item.TimeType
  230. // schedule.ModeId = item.TreatMode
  231. // schedule.ScheduleWeek = item.Weekday
  232. // schedule.BedId = item.DeviceNumberID
  233. // formatTime,_:=time.Parse("2006-01-02", nextTimeArr[int(item.Weekday)])
  234. // schedule.ScheduleDate =formatTime.Unix()
  235. // schedule.UserOrgId = item.OrgID
  236. // schedule.Status = 1
  237. // schedule.CreatedTime = time.Now().Unix()
  238. // schedule.UpdatedTime = time.Now().Unix()
  239. // device,_ := service.GetDeviceByID(item.OrgID,item.DeviceNumberID)
  240. // schedule.PartitionId = device.DeviceZoneID
  241. // schedules = append(schedules,schedule)
  242. //}
  243. break
  244. case 0:
  245. //当前修改的模板是本周的模板
  246. //根据模板类型,来判断需要修改哪几周数据,模板类型:单周模板,双周模板,三周模板,四周模板
  247. //如果是单周模板:则修改本周除了当天未来的数据,下周,下下周数据
  248. //如果是双周模板:则修改下下周数据
  249. //如果是三周模板:则修改本周除了当天未来的数据
  250. //如果是四周模板:则修改本周除了当天未来的数据
  251. //TimeArr :=WeekIntervalTime(0)
  252. t := time.Now()
  253. week_day, _ := strconv.Atoi(t.Weekday().String())
  254. if week_day == 0 {
  255. week_day = 7
  256. }
  257. timeArr := WeekIntervalTime(0) //获取本周的周一到周日
  258. items_two, _ := service.GetTemplateListByTemplateId(item.ID, item.OrgID)
  259. //处理本周,先判断当前属于周几
  260. for _, item := range items_two {
  261. var schedule models.Schedule
  262. if int(item.Weekday) > week_day {
  263. schedule.IsExport = 400000
  264. var DialysisMachineName string
  265. so, _ := service.GetDialysisSolutionTwo(item.OrgID, item.PatientID, item.TreatMode)
  266. filedRecordOne, _ := service.FindFiledBy(item.OrgID, "透析器")
  267. filedRecordTwo, _ := service.FindFiledBy(item.OrgID, "灌流器")
  268. filedRecordThree, _ := service.FindFiledBy(item.OrgID, "透析器/灌流器")
  269. if filedRecordOne.IsShow == 1 {
  270. DialysisMachineName = so.DialysisDialyszers
  271. }
  272. if filedRecordThree.IsShow == 1 {
  273. if len(DialysisMachineName) > 0 {
  274. DialysisMachineName = DialysisMachineName + "*" + so.DialyzerPerfusionApparatus
  275. } else {
  276. DialysisMachineName = so.DialyzerPerfusionApparatus
  277. }
  278. }
  279. if filedRecordTwo.IsShow == 1 {
  280. if len(DialysisMachineName) > 0 {
  281. DialysisMachineName = DialysisMachineName + "*" + so.DialysisIrrigation
  282. } else {
  283. DialysisMachineName = so.DialysisIrrigation
  284. }
  285. }
  286. schedule.DialysisMachineName = DialysisMachineName
  287. schedule.ScheduleType = item.TimeType
  288. schedule.ModeId = item.TreatMode
  289. schedule.ScheduleWeek = item.Weekday
  290. schedule.BedId = item.DeviceNumberID
  291. formatTime, _ := time.Parse("2006-01-02", timeArr[int(item.Weekday)])
  292. schedule.ScheduleDate = formatTime.Unix()
  293. schedule.UserOrgId = item.OrgID
  294. schedule.Status = 1
  295. schedule.CreatedTime = time.Now().Unix()
  296. schedule.UpdatedTime = time.Now().Unix()
  297. device, _ := service.GetDeviceByID(item.OrgID, item.DeviceNumberID)
  298. schedule.PartitionId = device.DeviceZoneID
  299. schedules = append(schedules, schedule)
  300. }
  301. }
  302. nextnextTimeArr := WeekIntervalTime(2) //获取下下周的周一到周日
  303. items, _ := service.GetTemplateListByTemplateId(item.ID, item.OrgID)
  304. //处理下下周
  305. for _, item := range items {
  306. var schedule models.Schedule
  307. schedule.IsExport = 400000
  308. var DialysisMachineName string
  309. so, _ := service.GetDialysisSolutionTwo(item.OrgID, item.PatientID, item.TreatMode)
  310. filedRecordOne, _ := service.FindFiledBy(item.OrgID, "透析器")
  311. filedRecordTwo, _ := service.FindFiledBy(item.OrgID, "灌流器")
  312. filedRecordThree, _ := service.FindFiledBy(item.OrgID, "透析器/灌流器")
  313. if filedRecordOne.IsShow == 1 {
  314. DialysisMachineName = so.DialysisDialyszers
  315. }
  316. if filedRecordThree.IsShow == 1 {
  317. if len(DialysisMachineName) > 0 {
  318. DialysisMachineName = DialysisMachineName + "*" + so.DialyzerPerfusionApparatus
  319. } else {
  320. DialysisMachineName = so.DialyzerPerfusionApparatus
  321. }
  322. }
  323. if filedRecordTwo.IsShow == 1 {
  324. if len(DialysisMachineName) > 0 {
  325. DialysisMachineName = DialysisMachineName + "*" + so.DialysisIrrigation
  326. } else {
  327. DialysisMachineName = so.DialysisIrrigation
  328. }
  329. }
  330. schedule.DialysisMachineName = DialysisMachineName
  331. schedule.ScheduleType = item.TimeType
  332. schedule.ModeId = item.TreatMode
  333. schedule.ScheduleWeek = item.Weekday
  334. schedule.BedId = item.DeviceNumberID
  335. formatTime, _ := time.Parse("2006-01-02", nextnextTimeArr[int(item.Weekday)])
  336. schedule.ScheduleDate = formatTime.Unix()
  337. schedule.UserOrgId = item.OrgID
  338. schedule.Status = 1
  339. schedule.CreatedTime = time.Now().Unix()
  340. schedule.UpdatedTime = time.Now().Unix()
  341. device, _ := service.GetDeviceByID(item.OrgID, item.DeviceNumberID)
  342. schedule.PartitionId = device.DeviceZoneID
  343. schedules = append(schedules, schedule)
  344. }
  345. break
  346. case 1:
  347. //当前修改的模板是本周的模板
  348. //根据模板类型,来判断需要修改哪几周数据,模板类型:单周模板,双周模板,三周模板,四周模板
  349. //如果是单周模板:则修改本周除了当天未来的数据,下周,下下周数据
  350. //如果是双周模板:则修改下下周数据
  351. //如果是三周模板:则修改本周除了当天未来的数据
  352. //如果是四周模板:则修改本周除了当天未来的数据
  353. //TimeArr :=WeekIntervalTime(0)
  354. nextTimeArr := WeekIntervalTime(1) //获取下下周的周一到周日
  355. t := time.Now()
  356. week_day, _ := strconv.Atoi(t.Weekday().String())
  357. if week_day == 0 {
  358. week_day = 7
  359. }
  360. items, _ := service.GetTemplateListByTemplateId(item.ID, item.OrgID)
  361. //处理下下周
  362. for _, item := range items {
  363. var schedule models.Schedule
  364. schedule.IsExport = 400000
  365. var DialysisMachineName string
  366. so, _ := service.GetDialysisSolutionTwo(item.OrgID, item.PatientID, item.TreatMode)
  367. filedRecordOne, _ := service.FindFiledBy(item.OrgID, "透析器")
  368. filedRecordTwo, _ := service.FindFiledBy(item.OrgID, "灌流器")
  369. filedRecordThree, _ := service.FindFiledBy(item.OrgID, "透析器/灌流器")
  370. if filedRecordOne.IsShow == 1 {
  371. DialysisMachineName = so.DialysisDialyszers
  372. }
  373. if filedRecordThree.IsShow == 1 {
  374. if len(DialysisMachineName) > 0 {
  375. DialysisMachineName = DialysisMachineName + "*" + so.DialyzerPerfusionApparatus
  376. } else {
  377. DialysisMachineName = so.DialyzerPerfusionApparatus
  378. }
  379. }
  380. if filedRecordTwo.IsShow == 1 {
  381. if len(DialysisMachineName) > 0 {
  382. DialysisMachineName = DialysisMachineName + "*" + so.DialysisIrrigation
  383. } else {
  384. DialysisMachineName = so.DialysisIrrigation
  385. }
  386. }
  387. schedule.DialysisMachineName = DialysisMachineName
  388. schedule.ScheduleType = item.TimeType
  389. schedule.ModeId = item.TreatMode
  390. schedule.ScheduleWeek = item.Weekday
  391. schedule.BedId = item.DeviceNumberID
  392. formatTime, _ := time.Parse("2006-01-02", nextTimeArr[int(item.Weekday)])
  393. schedule.ScheduleDate = formatTime.Unix()
  394. schedule.UserOrgId = item.OrgID
  395. schedule.Status = 1
  396. schedule.CreatedTime = time.Now().Unix()
  397. schedule.UpdatedTime = time.Now().Unix()
  398. device, _ := service.GetDeviceByID(item.OrgID, item.DeviceNumberID)
  399. schedule.PartitionId = device.DeviceZoneID
  400. schedules = append(schedules, schedule)
  401. }
  402. break
  403. case 2:
  404. //当前修改的模板是下下周的模板
  405. //根据模板类型,来判断需要修改哪几周数据,模板类型:单周模板,双周模板,三周模板,四周模板
  406. //如果是单周模板:则修改本周除了当天未来的数据,下周,下下周数据
  407. //如果是双周模板:则修改本周数据,下下周数据
  408. //如果是三周模板:则修改下下周的数据
  409. //如果是四周模板:则修改本周除了当天未来的数据
  410. //nextTwoTimeArr :=WeekIntervalTime(2)
  411. timeArr := WeekIntervalTime(0) //获取本周的周一到周日
  412. t := time.Now()
  413. week_day, _ := strconv.Atoi(t.Weekday().String())
  414. if week_day == 0 {
  415. week_day = 7
  416. }
  417. items, _ := service.GetTemplateListByTemplateId(item.ID, item.OrgID)
  418. var schedules []models.Schedule
  419. //处理本周,先判断当前属于周几
  420. for _, item := range items {
  421. var schedule models.Schedule
  422. if int(item.Weekday) > week_day {
  423. schedule.IsExport = 400000
  424. var DialysisMachineName string
  425. so, _ := service.GetDialysisSolutionTwo(item.OrgID, item.PatientID, item.TreatMode)
  426. filedRecordOne, _ := service.FindFiledBy(item.OrgID, "透析器")
  427. filedRecordTwo, _ := service.FindFiledBy(item.OrgID, "灌流器")
  428. filedRecordThree, _ := service.FindFiledBy(item.OrgID, "透析器/灌流器")
  429. if filedRecordOne.IsShow == 1 {
  430. DialysisMachineName = so.DialysisDialyszers
  431. }
  432. if filedRecordThree.IsShow == 1 {
  433. if len(DialysisMachineName) > 0 {
  434. DialysisMachineName = DialysisMachineName + "*" + so.DialyzerPerfusionApparatus
  435. } else {
  436. DialysisMachineName = so.DialyzerPerfusionApparatus
  437. }
  438. }
  439. if filedRecordTwo.IsShow == 1 {
  440. if len(DialysisMachineName) > 0 {
  441. DialysisMachineName = DialysisMachineName + "*" + so.DialysisIrrigation
  442. } else {
  443. DialysisMachineName = so.DialysisIrrigation
  444. }
  445. }
  446. schedule.DialysisMachineName = DialysisMachineName
  447. schedule.ScheduleType = item.TimeType
  448. schedule.ModeId = item.TreatMode
  449. schedule.ScheduleWeek = item.Weekday
  450. schedule.BedId = item.DeviceNumberID
  451. formatTime, _ := time.Parse("2006-01-02", timeArr[int(item.Weekday)])
  452. schedule.ScheduleDate = formatTime.Unix()
  453. schedule.UserOrgId = item.OrgID
  454. schedule.Status = 1
  455. schedule.CreatedTime = time.Now().Unix()
  456. schedule.UpdatedTime = time.Now().Unix()
  457. device, _ := service.GetDeviceByID(item.OrgID, item.DeviceNumberID)
  458. schedule.PartitionId = device.DeviceZoneID
  459. schedules = append(schedules, schedule)
  460. }
  461. }
  462. nextnextTimeArr := WeekIntervalTime(2) //获取下下周的周一到周日
  463. items_two, _ := service.GetTemplateListByTemplateId(item.ID, item.OrgID)
  464. //处理下下周
  465. for _, item := range items_two {
  466. var schedule models.Schedule
  467. schedule.IsExport = 400000
  468. var DialysisMachineName string
  469. so, _ := service.GetDialysisSolutionTwo(item.OrgID, item.PatientID, item.TreatMode)
  470. filedRecordOne, _ := service.FindFiledBy(item.OrgID, "透析器")
  471. filedRecordTwo, _ := service.FindFiledBy(item.OrgID, "灌流器")
  472. filedRecordThree, _ := service.FindFiledBy(item.OrgID, "透析器/灌流器")
  473. if filedRecordOne.IsShow == 1 {
  474. DialysisMachineName = so.DialysisDialyszers
  475. }
  476. if filedRecordThree.IsShow == 1 {
  477. if len(DialysisMachineName) > 0 {
  478. DialysisMachineName = DialysisMachineName + "*" + so.DialyzerPerfusionApparatus
  479. } else {
  480. DialysisMachineName = so.DialyzerPerfusionApparatus
  481. }
  482. }
  483. if filedRecordTwo.IsShow == 1 {
  484. if len(DialysisMachineName) > 0 {
  485. DialysisMachineName = DialysisMachineName + "*" + so.DialysisIrrigation
  486. } else {
  487. DialysisMachineName = so.DialysisIrrigation
  488. }
  489. }
  490. schedule.DialysisMachineName = DialysisMachineName
  491. schedule.ScheduleType = item.TimeType
  492. schedule.ModeId = item.TreatMode
  493. schedule.ScheduleWeek = item.Weekday
  494. schedule.BedId = item.DeviceNumberID
  495. formatTime, _ := time.Parse("2006-01-02", nextnextTimeArr[int(item.Weekday)])
  496. schedule.ScheduleDate = formatTime.Unix()
  497. schedule.UserOrgId = item.OrgID
  498. schedule.Status = 1
  499. schedule.CreatedTime = time.Now().Unix()
  500. schedule.UpdatedTime = time.Now().Unix()
  501. device, _ := service.GetDeviceByID(item.OrgID, item.DeviceNumberID)
  502. schedule.PartitionId = device.DeviceZoneID
  503. schedules = append(schedules, schedule)
  504. }
  505. break
  506. }
  507. }
  508. }
  509. } else if mode.Mode == 3 {
  510. for _, item := range templates {
  511. if item.Week > 0 {
  512. switch item.Week - week {
  513. //case -1:
  514. // //当前模板是上周的模板
  515. // //根据模板类型,来判断需要修改哪几周数据,模板类型:单周模板,双周模板,三周模板,四周模板
  516. // //如果是单周模板:则修改本周除了当天未来的数据,下周,下下周数据
  517. // //如果是双周模板:则修改下周数据
  518. // //如果是三周模板:则修改下下周数据
  519. // //如果是四周模板:则不用修改数据
  520. // //TimeArr :=WeekIntervalTime(0)
  521. // nextnextTimeArr := WeekIntervalTime(2) //获取下下周的周一到周日
  522. // t := time.Now()
  523. // week_day,_ := strconv.Atoi(t.Weekday().String())
  524. // if week_day == 0{
  525. // week_day = 7
  526. // }
  527. // items, _ := service.GetTemplateListByTemplateId(item.ID,item.OrgID)
  528. // var schedules []models.Schedule
  529. // //处理下周
  530. // for _,item := range items{
  531. // var schedule models.Schedule
  532. // schedule.IsExport = 400000
  533. // var DialysisMachineName string
  534. // so, _ := service.GetDialysisSolutionTwo(item.OrgID, item.PatientID, item.TreatMode)
  535. // filedRecordOne, _ := service.FindFiledBy(item.OrgID, "透析器")
  536. // filedRecordTwo, _ := service.FindFiledBy(item.OrgID, "灌流器")
  537. // filedRecordThree, _ := service.FindFiledBy(item.OrgID, "透析器/灌流器")
  538. // if filedRecordOne.IsShow == 1 {
  539. // DialysisMachineName = so.DialysisDialyszers
  540. // }
  541. // if filedRecordThree.IsShow == 1 {
  542. // if len(DialysisMachineName) > 0 {
  543. // DialysisMachineName = DialysisMachineName + "*" + so.DialyzerPerfusionApparatus
  544. // } else {
  545. // DialysisMachineName = so.DialyzerPerfusionApparatus
  546. // }
  547. // }
  548. // if filedRecordTwo.IsShow == 1 {
  549. // if len(DialysisMachineName) > 0 {
  550. // DialysisMachineName = DialysisMachineName + "*" + so.DialysisIrrigation
  551. // } else {
  552. // DialysisMachineName = so.DialysisIrrigation
  553. // }
  554. // }
  555. // schedule.DialysisMachineName = DialysisMachineName
  556. // schedule.ScheduleType = item.TimeType
  557. // schedule.ModeId = item.TreatMode
  558. // schedule.ScheduleWeek = item.Weekday
  559. // schedule.BedId = item.DeviceNumberID
  560. // formatTime,_:=time.Parse("2006-01-02", nextnextTimeArr[int(item.Weekday)])
  561. // schedule.ScheduleDate =formatTime.Unix()
  562. // schedule.UserOrgId = item.OrgID
  563. // schedule.Status = 1
  564. // schedule.CreatedTime = time.Now().Unix()
  565. // schedule.UpdatedTime = time.Now().Unix()
  566. // device,_ := service.GetDeviceByID(item.OrgID,item.DeviceNumberID)
  567. // schedule.PartitionId = device.DeviceZoneID
  568. // schedules = append(schedules,schedule)
  569. // }
  570. //
  571. // break
  572. case 0:
  573. timeArr := WeekIntervalTime(0) //获取本周的周一到周日
  574. t := time.Now()
  575. week_day, _ := strconv.Atoi(t.Weekday().String())
  576. if week_day == 0 {
  577. week_day = 7
  578. }
  579. items, _ := service.GetTemplateListByTemplateId(item.ID, item.OrgID)
  580. var schedules []models.Schedule
  581. //处理本周,先判断当前属于周几
  582. for _, item := range items {
  583. var schedule models.Schedule
  584. if int(item.Weekday) > week_day {
  585. schedule.IsExport = 400000
  586. var DialysisMachineName string
  587. so, _ := service.GetDialysisSolutionTwo(item.OrgID, item.PatientID, item.TreatMode)
  588. filedRecordOne, _ := service.FindFiledBy(item.OrgID, "透析器")
  589. filedRecordTwo, _ := service.FindFiledBy(item.OrgID, "灌流器")
  590. filedRecordThree, _ := service.FindFiledBy(item.OrgID, "透析器/灌流器")
  591. if filedRecordOne.IsShow == 1 {
  592. DialysisMachineName = so.DialysisDialyszers
  593. }
  594. if filedRecordThree.IsShow == 1 {
  595. if len(DialysisMachineName) > 0 {
  596. DialysisMachineName = DialysisMachineName + "*" + so.DialyzerPerfusionApparatus
  597. } else {
  598. DialysisMachineName = so.DialyzerPerfusionApparatus
  599. }
  600. }
  601. if filedRecordTwo.IsShow == 1 {
  602. if len(DialysisMachineName) > 0 {
  603. DialysisMachineName = DialysisMachineName + "*" + so.DialysisIrrigation
  604. } else {
  605. DialysisMachineName = so.DialysisIrrigation
  606. }
  607. }
  608. schedule.DialysisMachineName = DialysisMachineName
  609. schedule.ScheduleType = item.TimeType
  610. schedule.ModeId = item.TreatMode
  611. schedule.ScheduleWeek = item.Weekday
  612. schedule.BedId = item.DeviceNumberID
  613. formatTime, _ := time.Parse("2006-01-02", timeArr[int(item.Weekday)])
  614. schedule.ScheduleDate = formatTime.Unix()
  615. schedule.UserOrgId = item.OrgID
  616. schedule.Status = 1
  617. schedule.CreatedTime = time.Now().Unix()
  618. schedule.UpdatedTime = time.Now().Unix()
  619. device, _ := service.GetDeviceByID(item.OrgID, item.DeviceNumberID)
  620. schedule.PartitionId = device.DeviceZoneID
  621. schedules = append(schedules, schedule)
  622. }
  623. }
  624. break
  625. case 1:
  626. nexttimeArr := WeekIntervalTime(1) //获取本周的周一到周日
  627. items, _ := service.GetTemplateListByTemplateId(item.ID, item.OrgID)
  628. var schedules []models.Schedule
  629. //处理下周
  630. for _, item := range items {
  631. var schedule models.Schedule
  632. schedule.IsExport = 400000
  633. var DialysisMachineName string
  634. so, _ := service.GetDialysisSolutionTwo(item.OrgID, item.PatientID, item.TreatMode)
  635. filedRecordOne, _ := service.FindFiledBy(item.OrgID, "透析器")
  636. filedRecordTwo, _ := service.FindFiledBy(item.OrgID, "灌流器")
  637. filedRecordThree, _ := service.FindFiledBy(item.OrgID, "透析器/灌流器")
  638. if filedRecordOne.IsShow == 1 {
  639. DialysisMachineName = so.DialysisDialyszers
  640. }
  641. if filedRecordThree.IsShow == 1 {
  642. if len(DialysisMachineName) > 0 {
  643. DialysisMachineName = DialysisMachineName + "*" + so.DialyzerPerfusionApparatus
  644. } else {
  645. DialysisMachineName = so.DialyzerPerfusionApparatus
  646. }
  647. }
  648. if filedRecordTwo.IsShow == 1 {
  649. if len(DialysisMachineName) > 0 {
  650. DialysisMachineName = DialysisMachineName + "*" + so.DialysisIrrigation
  651. } else {
  652. DialysisMachineName = so.DialysisIrrigation
  653. }
  654. }
  655. schedule.DialysisMachineName = DialysisMachineName
  656. schedule.ScheduleType = item.TimeType
  657. schedule.ModeId = item.TreatMode
  658. schedule.ScheduleWeek = item.Weekday
  659. schedule.BedId = item.DeviceNumberID
  660. formatTime, _ := time.Parse("2006-01-02", nexttimeArr[int(item.Weekday)])
  661. schedule.ScheduleDate = formatTime.Unix()
  662. schedule.UserOrgId = item.OrgID
  663. schedule.Status = 1
  664. schedule.CreatedTime = time.Now().Unix()
  665. schedule.UpdatedTime = time.Now().Unix()
  666. device, _ := service.GetDeviceByID(item.OrgID, item.DeviceNumberID)
  667. schedule.PartitionId = device.DeviceZoneID
  668. schedules = append(schedules, schedule)
  669. }
  670. break
  671. case 2:
  672. //当前修改的模板是下下周的模板
  673. //根据模板类型,来判断需要修改哪几周数据,模板类型:单周模板,双周模板,三周模板,四周模板
  674. //如果是单周模板:则修改本周除了当天未来的数据,下周,下下周数据
  675. //如果是双周模板:则修改本周数据,下下周数据
  676. //如果是三周模板:则修改下下周的数据
  677. //如果是四周模板:则修改本周除了当天未来的数据
  678. //nextTwoTimeArr :=WeekIntervalTime(2)
  679. nextnexttimeArr := WeekIntervalTime(2) //获取本周的周一到周日
  680. t := time.Now()
  681. week_day, _ := strconv.Atoi(t.Weekday().String())
  682. if week_day == 0 {
  683. week_day = 7
  684. }
  685. items, _ := service.GetTemplateListByTemplateId(item.ID, item.OrgID)
  686. var schedules []models.Schedule
  687. //处理下下周
  688. for _, item := range items {
  689. var schedule models.Schedule
  690. schedule.IsExport = 400000
  691. var DialysisMachineName string
  692. so, _ := service.GetDialysisSolutionTwo(item.OrgID, item.PatientID, item.TreatMode)
  693. filedRecordOne, _ := service.FindFiledBy(item.OrgID, "透析器")
  694. filedRecordTwo, _ := service.FindFiledBy(item.OrgID, "灌流器")
  695. filedRecordThree, _ := service.FindFiledBy(item.OrgID, "透析器/灌流器")
  696. if filedRecordOne.IsShow == 1 {
  697. DialysisMachineName = so.DialysisDialyszers
  698. }
  699. if filedRecordThree.IsShow == 1 {
  700. if len(DialysisMachineName) > 0 {
  701. DialysisMachineName = DialysisMachineName + "*" + so.DialyzerPerfusionApparatus
  702. } else {
  703. DialysisMachineName = so.DialyzerPerfusionApparatus
  704. }
  705. }
  706. if filedRecordTwo.IsShow == 1 {
  707. if len(DialysisMachineName) > 0 {
  708. DialysisMachineName = DialysisMachineName + "*" + so.DialysisIrrigation
  709. } else {
  710. DialysisMachineName = so.DialysisIrrigation
  711. }
  712. }
  713. schedule.DialysisMachineName = DialysisMachineName
  714. schedule.ScheduleType = item.TimeType
  715. schedule.ModeId = item.TreatMode
  716. schedule.ScheduleWeek = item.Weekday
  717. schedule.BedId = item.DeviceNumberID
  718. formatTime, _ := time.Parse("2006-01-02", nextnexttimeArr[int(item.Weekday)])
  719. schedule.ScheduleDate = formatTime.Unix()
  720. schedule.UserOrgId = item.OrgID
  721. schedule.Status = 1
  722. schedule.CreatedTime = time.Now().Unix()
  723. schedule.UpdatedTime = time.Now().Unix()
  724. device, _ := service.GetDeviceByID(item.OrgID, item.DeviceNumberID)
  725. schedule.PartitionId = device.DeviceZoneID
  726. schedules = append(schedules, schedule)
  727. }
  728. break
  729. }
  730. }
  731. }
  732. } else if mode.Mode == 4 {
  733. for _, item := range templates {
  734. if item.Week > 0 {
  735. switch item.Week - week {
  736. case 0:
  737. timeArr := WeekIntervalTime(0) //获取本周的周一到周日
  738. t := time.Now()
  739. week_day, _ := strconv.Atoi(t.Weekday().String())
  740. if week_day == 0 {
  741. week_day = 7
  742. }
  743. items, _ := service.GetTemplateListByTemplateId(item.ID, item.OrgID)
  744. var schedules []models.Schedule
  745. //处理本周,先判断当前属于周几
  746. for _, item := range items {
  747. var schedule models.Schedule
  748. if int(item.Weekday) > week_day {
  749. schedule.IsExport = 400000
  750. var DialysisMachineName string
  751. so, _ := service.GetDialysisSolutionTwo(item.OrgID, item.PatientID, item.TreatMode)
  752. filedRecordOne, _ := service.FindFiledBy(item.OrgID, "透析器")
  753. filedRecordTwo, _ := service.FindFiledBy(item.OrgID, "灌流器")
  754. filedRecordThree, _ := service.FindFiledBy(item.OrgID, "透析器/灌流器")
  755. if filedRecordOne.IsShow == 1 {
  756. DialysisMachineName = so.DialysisDialyszers
  757. }
  758. if filedRecordThree.IsShow == 1 {
  759. if len(DialysisMachineName) > 0 {
  760. DialysisMachineName = DialysisMachineName + "*" + so.DialyzerPerfusionApparatus
  761. } else {
  762. DialysisMachineName = so.DialyzerPerfusionApparatus
  763. }
  764. }
  765. if filedRecordTwo.IsShow == 1 {
  766. if len(DialysisMachineName) > 0 {
  767. DialysisMachineName = DialysisMachineName + "*" + so.DialysisIrrigation
  768. } else {
  769. DialysisMachineName = so.DialysisIrrigation
  770. }
  771. }
  772. schedule.DialysisMachineName = DialysisMachineName
  773. schedule.ScheduleType = item.TimeType
  774. schedule.ModeId = item.TreatMode
  775. schedule.ScheduleWeek = item.Weekday
  776. schedule.BedId = item.DeviceNumberID
  777. formatTime, _ := time.Parse("2006-01-02", timeArr[int(item.Weekday)])
  778. schedule.ScheduleDate = formatTime.Unix()
  779. schedule.UserOrgId = item.OrgID
  780. schedule.Status = 1
  781. schedule.CreatedTime = time.Now().Unix()
  782. schedule.UpdatedTime = time.Now().Unix()
  783. device, _ := service.GetDeviceByID(item.OrgID, item.DeviceNumberID)
  784. schedule.PartitionId = device.DeviceZoneID
  785. schedules = append(schedules, schedule)
  786. }
  787. }
  788. break
  789. case 1:
  790. nexttimeArr := WeekIntervalTime(1) //获取本周的周一到周日
  791. items, _ := service.GetTemplateListByTemplateId(item.ID, item.OrgID)
  792. var schedules []models.Schedule
  793. //处理下周,先判断当前属于周几
  794. for _, item := range items {
  795. var schedule models.Schedule
  796. schedule.IsExport = 400000
  797. var DialysisMachineName string
  798. so, _ := service.GetDialysisSolutionTwo(item.OrgID, item.PatientID, item.TreatMode)
  799. filedRecordOne, _ := service.FindFiledBy(item.OrgID, "透析器")
  800. filedRecordTwo, _ := service.FindFiledBy(item.OrgID, "灌流器")
  801. filedRecordThree, _ := service.FindFiledBy(item.OrgID, "透析器/灌流器")
  802. if filedRecordOne.IsShow == 1 {
  803. DialysisMachineName = so.DialysisDialyszers
  804. }
  805. if filedRecordThree.IsShow == 1 {
  806. if len(DialysisMachineName) > 0 {
  807. DialysisMachineName = DialysisMachineName + "*" + so.DialyzerPerfusionApparatus
  808. } else {
  809. DialysisMachineName = so.DialyzerPerfusionApparatus
  810. }
  811. }
  812. if filedRecordTwo.IsShow == 1 {
  813. if len(DialysisMachineName) > 0 {
  814. DialysisMachineName = DialysisMachineName + "*" + so.DialysisIrrigation
  815. } else {
  816. DialysisMachineName = so.DialysisIrrigation
  817. }
  818. }
  819. schedule.DialysisMachineName = DialysisMachineName
  820. schedule.ScheduleType = item.TimeType
  821. schedule.ModeId = item.TreatMode
  822. schedule.ScheduleWeek = item.Weekday
  823. schedule.BedId = item.DeviceNumberID
  824. formatTime, _ := time.Parse("2006-01-02", nexttimeArr[int(item.Weekday)])
  825. schedule.ScheduleDate = formatTime.Unix()
  826. schedule.UserOrgId = item.OrgID
  827. schedule.Status = 1
  828. schedule.CreatedTime = time.Now().Unix()
  829. schedule.UpdatedTime = time.Now().Unix()
  830. device, _ := service.GetDeviceByID(item.OrgID, item.DeviceNumberID)
  831. schedule.PartitionId = device.DeviceZoneID
  832. schedules = append(schedules, schedule)
  833. }
  834. break
  835. case 2:
  836. nextnexttimeArr := WeekIntervalTime(2) //获取本周的周一到周日
  837. items, _ := service.GetTemplateListByTemplateId(item.ID, item.OrgID)
  838. var schedules []models.Schedule
  839. //处理下下周,先判断当前属于周几
  840. for _, item := range items {
  841. var schedule models.Schedule
  842. schedule.IsExport = 400000
  843. var DialysisMachineName string
  844. so, _ := service.GetDialysisSolutionTwo(item.OrgID, item.PatientID, item.TreatMode)
  845. filedRecordOne, _ := service.FindFiledBy(item.OrgID, "透析器")
  846. filedRecordTwo, _ := service.FindFiledBy(item.OrgID, "灌流器")
  847. filedRecordThree, _ := service.FindFiledBy(item.OrgID, "透析器/灌流器")
  848. if filedRecordOne.IsShow == 1 {
  849. DialysisMachineName = so.DialysisDialyszers
  850. }
  851. if filedRecordThree.IsShow == 1 {
  852. if len(DialysisMachineName) > 0 {
  853. DialysisMachineName = DialysisMachineName + "*" + so.DialyzerPerfusionApparatus
  854. } else {
  855. DialysisMachineName = so.DialyzerPerfusionApparatus
  856. }
  857. }
  858. if filedRecordTwo.IsShow == 1 {
  859. if len(DialysisMachineName) > 0 {
  860. DialysisMachineName = DialysisMachineName + "*" + so.DialysisIrrigation
  861. } else {
  862. DialysisMachineName = so.DialysisIrrigation
  863. }
  864. }
  865. schedule.DialysisMachineName = DialysisMachineName
  866. schedule.ScheduleType = item.TimeType
  867. schedule.ModeId = item.TreatMode
  868. schedule.ScheduleWeek = item.Weekday
  869. schedule.BedId = item.DeviceNumberID
  870. formatTime, _ := time.Parse("2006-01-02", nextnexttimeArr[int(item.Weekday)])
  871. schedule.ScheduleDate = formatTime.Unix()
  872. schedule.UserOrgId = item.OrgID
  873. schedule.Status = 1
  874. schedule.CreatedTime = time.Now().Unix()
  875. schedule.UpdatedTime = time.Now().Unix()
  876. device, _ := service.GetDeviceByID(item.OrgID, item.DeviceNumberID)
  877. schedule.PartitionId = device.DeviceZoneID
  878. schedules = append(schedules, schedule)
  879. }
  880. break
  881. }
  882. }
  883. }
  884. }
  885. //清除今天以后的排班数据病并同步数据
  886. err := service.ClearAndCreateSyncSch(c.GetAdminUserInfo().CurrentOrgId, time.Now().Unix(), schedules)
  887. if err == nil {
  888. c.ServeSuccessJSON(map[string]interface{}{
  889. "msg": "同步成功",
  890. })
  891. } else {
  892. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSyncWrong)
  893. return
  894. }
  895. }
  896. func (c *ScheduleApiController) CoverSchTemplate() {
  897. templateID, _ := c.GetInt64("template_id")
  898. week_type_one, _ := c.GetInt64("week_type_one")
  899. time_type_one, _ := c.GetInt64("time_type_one")
  900. device_id_one, _ := c.GetInt64("device_id_one")
  901. patient_id_one, _ := c.GetInt64("patient_id_one")
  902. week_type_two, _ := c.GetInt64("week_type_two")
  903. time_type_two, _ := c.GetInt64("time_type_two")
  904. device_id_two, _ := c.GetInt64("device_id_two")
  905. patient_id_two, _ := c.GetInt64("patient_id_two")
  906. sch, _ := service.GetScheduleTemplateForDeviceNumberTwo(c.GetAdminUserInfo().CurrentOrgId, device_id_one, templateID, week_type_one, time_type_one, patient_id_one)
  907. sch_two, _ := service.GetScheduleTemplateForDeviceNumberTwo(c.GetAdminUserInfo().CurrentOrgId, device_id_two, templateID, week_type_two, time_type_two, patient_id_two)
  908. if sch.ID == 0 {
  909. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist)
  910. return
  911. }
  912. if sch_two.ID == 0 {
  913. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist)
  914. return
  915. }
  916. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  917. if sch.Weekday != sch_two.Weekday && sch.PatientID != sch_two.PatientID {
  918. count, _ := service.GetScheduleTemplateCountByDate(c.GetAdminUserInfo().CurrentOrgId, sch_two.Weekday, sch.PatientID, sch.TemplateID)
  919. if count > 0 {
  920. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  921. return
  922. }
  923. }
  924. var new_sch models.PatientScheduleTemplateItem
  925. new_sch = sch
  926. new_sch.DeviceNumberID = sch_two.DeviceNumberID
  927. new_sch.Weekday = sch_two.Weekday
  928. new_sch.TimeType = sch_two.TimeType
  929. new_sch.ID = 0
  930. //删除原来的排班并生成新的排班
  931. err := service.SaveSchTemplateTwo(sch, sch_two, new_sch)
  932. if err == nil {
  933. templates, getTemplateItemsErr := service.GetOrgPatientScheduleTemplateItems(c.GetAdminUserInfo().CurrentOrgId)
  934. if getTemplateItemsErr != nil {
  935. c.ErrorLog("获取排班模板排班失败:%v", getTemplateItemsErr)
  936. }
  937. c.ServeSuccessJSON(map[string]interface{}{
  938. "items": templates,
  939. "msg": "覆盖成功",
  940. })
  941. } else {
  942. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  943. return
  944. }
  945. }
  946. func (c *ScheduleApiController) ExchangeSchTemplate() {
  947. templateID, _ := c.GetInt64("template_id")
  948. week_type_one, _ := c.GetInt64("week_type_one")
  949. time_type_one, _ := c.GetInt64("time_type_one")
  950. device_id_one, _ := c.GetInt64("device_id_one")
  951. patient_id_one, _ := c.GetInt64("patient_id_one")
  952. week_type_two, _ := c.GetInt64("week_type_two")
  953. time_type_two, _ := c.GetInt64("time_type_two")
  954. device_id_two, _ := c.GetInt64("device_id_two")
  955. patient_id_two, _ := c.GetInt64("patient_id_two")
  956. sch, _ := service.GetScheduleTemplateForDeviceNumberTwo(c.GetAdminUserInfo().CurrentOrgId, device_id_one, templateID, week_type_one, time_type_one, patient_id_one)
  957. sch_two, _ := service.GetScheduleTemplateForDeviceNumberTwo(c.GetAdminUserInfo().CurrentOrgId, device_id_two, templateID, week_type_two, time_type_two, patient_id_two)
  958. if sch.ID == 0 {
  959. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist)
  960. return
  961. }
  962. if sch_two.ID == 0 {
  963. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist)
  964. return
  965. }
  966. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  967. if sch.Weekday != sch_two.Weekday && sch.PatientID != sch_two.PatientID {
  968. count, _ := service.GetScheduleTemplateCountByDate(c.GetAdminUserInfo().CurrentOrgId, sch_two.Weekday, sch.PatientID, sch.TemplateID)
  969. if count > 0 {
  970. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  971. return
  972. }
  973. count1, _ := service.GetScheduleTemplateCountByDate(c.GetAdminUserInfo().CurrentOrgId, sch.Weekday, sch_two.PatientID, sch_two.TemplateID)
  974. if count1 > 0 {
  975. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  976. return
  977. }
  978. }
  979. err := service.UpdateScheduleTemplateThree(sch, sch_two)
  980. if err == nil {
  981. templates, getTemplateItemsErr := service.GetOrgPatientScheduleTemplateItems(c.GetAdminUserInfo().CurrentOrgId)
  982. if getTemplateItemsErr != nil {
  983. c.ErrorLog("获取排班模板排班失败:%v", getTemplateItemsErr)
  984. }
  985. c.ServeSuccessJSON(map[string]interface{}{
  986. "items": templates,
  987. "msg": "交换成功",
  988. })
  989. } else {
  990. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  991. return
  992. }
  993. }
  994. func (c *ScheduleApiController) DeleteAndAddScheduleTemplateTwo() {
  995. templateID, _ := c.GetInt64("template_id")
  996. week_type_one, _ := c.GetInt64("week_type_one")
  997. time_type_one, _ := c.GetInt64("time_type_one")
  998. device_id_one, _ := c.GetInt64("device_id_one")
  999. patient_id_one, _ := c.GetInt64("patient_id_one")
  1000. week_type_two, _ := c.GetInt8("week_type_two")
  1001. time_type_two, _ := c.GetInt8("time_type_two")
  1002. device_id_two, _ := c.GetInt64("device_id_two")
  1003. patient_id_two, _ := c.GetInt64("patient_id_two")
  1004. mode_id, _ := c.GetInt64("mode_id")
  1005. sch, _ := service.GetScheduleTemplateForDeviceNumberTwo(c.GetAdminUserInfo().CurrentOrgId, device_id_one, templateID, week_type_one, time_type_one, patient_id_one)
  1006. if sch.ID == 0 {
  1007. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist)
  1008. return
  1009. }
  1010. // 先删除后新增
  1011. sch.Status = 0
  1012. //service.SaveSchTemplate(sch)
  1013. item := models.PatientScheduleTemplateItem{
  1014. DeviceNumberID: device_id_two,
  1015. PatientID: patient_id_two,
  1016. TreatMode: mode_id,
  1017. Weekday: week_type_two,
  1018. TimeType: time_type_two,
  1019. Status: 1,
  1020. OrgID: c.GetAdminUserInfo().CurrentOrgId,
  1021. TemplateID: templateID,
  1022. CreateTime: time.Now().Unix(),
  1023. ModifyTime: 0,
  1024. IsExport: 40000,
  1025. }
  1026. err := service.SaveSchTemplate(sch, item)
  1027. if err == nil {
  1028. templates, getTemplateItemsErr := service.GetOrgPatientScheduleTemplateItems(c.GetAdminUserInfo().CurrentOrgId)
  1029. if getTemplateItemsErr != nil {
  1030. c.ErrorLog("获取排班模板排班失败:%v", getTemplateItemsErr)
  1031. }
  1032. c.ServeSuccessJSON(map[string]interface{}{
  1033. "items": templates,
  1034. })
  1035. } else {
  1036. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1037. return
  1038. }
  1039. }
  1040. func (c *ScheduleApiController) GetTemplateDevicesNumbers() {
  1041. sch_type, _ := c.GetInt("sch_type", 0)
  1042. zone_id, _ := c.GetInt64("zone_id", 0)
  1043. patient_id, _ := c.GetInt64("patient_id", 0)
  1044. template_id, _ := c.GetInt64("template_id", 0)
  1045. weekday, _ := c.GetInt64("weekday")
  1046. deviceNumbers, getDeviceNumbersErr := service.GetAllAvaildTemplateDeviceNumbersByZone(c.GetAdminUserInfo().CurrentOrgId, weekday, sch_type, zone_id, patient_id, template_id)
  1047. if getDeviceNumbersErr != nil {
  1048. c.ErrorLog("获取所有床位失败:%v", getDeviceNumbersErr)
  1049. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1050. return
  1051. }
  1052. c.ServeSuccessJSON(map[string]interface{}{
  1053. "devices": deviceNumbers,
  1054. })
  1055. }
  1056. // type TestCtr struct {
  1057. // BaseAPIController
  1058. // }
  1059. // func (this *TestCtr) Test() {
  1060. // now := time.Now().AddDate(0, 0, 7)
  1061. // weekday := int(now.Weekday())
  1062. // if weekday == 0 {
  1063. // weekday = 7
  1064. // }
  1065. // monday := now.AddDate(0, 0, 1-weekday)
  1066. // sunday := now.AddDate(0, 0, 7-weekday)
  1067. // // this.TraceLog("%v", weekday)
  1068. // this.ServeSuccessJSON(map[string]interface{}{
  1069. // "weekday": weekday,
  1070. // "monday": monday.Format("2006-01-02"),
  1071. // "sunday": sunday.Format("2006-01-02"),
  1072. // })
  1073. // }
  1074. // ------- 患者排班模板 --------
  1075. type PatientScheduleTemplateAPIController struct {
  1076. BaseAuthAPIController
  1077. }
  1078. // /api/schtemp/p/initdata [get]
  1079. func (this *PatientScheduleTemplateAPIController) InitData() {
  1080. adminUserInfo := this.GetAdminUserInfo()
  1081. patitionIdStr := this.GetString("patitionid")
  1082. var ids []string
  1083. if len(patitionIdStr) > 0 {
  1084. ids = strings.Split(patitionIdStr, ",")
  1085. }
  1086. mode, getModeErr := service.GetOrgPatientScheduleTemplateMode(adminUserInfo.CurrentOrgId)
  1087. if getModeErr != nil {
  1088. this.ErrorLog("获取排班模板启用模式失败:%v", getModeErr)
  1089. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1090. return
  1091. }
  1092. now := time.Now()
  1093. if mode == nil {
  1094. mode = &models.PatientScheduleTemplateMode{
  1095. OrgID: adminUserInfo.CurrentOrgId,
  1096. Mode: 0,
  1097. ExecuteTimes: 0,
  1098. Status: 1,
  1099. CreateTime: now.Unix(),
  1100. ModifyTime: now.Unix(),
  1101. }
  1102. createModeErr := service.SavePatientScheduleTemplateMode(mode)
  1103. if createModeErr != nil {
  1104. this.ErrorLog("创建排班模板启用模式失败:%v", createModeErr)
  1105. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1106. return
  1107. }
  1108. }
  1109. deviceNumbers, getDeviceNumbersErr := service.GetScheduleValidDeviceNumbers(adminUserInfo.CurrentOrgId, ids)
  1110. if getDeviceNumbersErr != nil {
  1111. this.ErrorLog("获取床位号失败:%v", getDeviceNumbersErr)
  1112. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1113. return
  1114. }
  1115. templates, getTemplatesErr := service.GetOrgPatientScheduleTemplateItems(adminUserInfo.CurrentOrgId)
  1116. if getTemplatesErr != nil {
  1117. this.ErrorLog("获取排班模板及其排班列表失败:%v", getTemplatesErr)
  1118. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1119. return
  1120. }
  1121. if len(templates) == 0 {
  1122. firstTemp, secondTemp, thirdTemp, fourTemp, createTempErr := service.CreateTwoPatientScheduleTemplates(adminUserInfo.CurrentOrgId)
  1123. if createTempErr != nil {
  1124. this.ErrorLog("创建4个排班模板失败:%v", createTempErr)
  1125. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1126. return
  1127. }
  1128. templates = append(templates, firstTemp, secondTemp, thirdTemp, fourTemp)
  1129. } else if len(templates) == 1 {
  1130. temp, thirdTemp, fourTemp, createTempErr := service.CreatePatientScheduleTemplate(adminUserInfo.CurrentOrgId)
  1131. if createTempErr != nil {
  1132. this.ErrorLog("创建3个排班模板失败:%v", createTempErr)
  1133. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1134. return
  1135. }
  1136. templates = append(templates, temp, thirdTemp, fourTemp)
  1137. } else if len(templates) == 2 {
  1138. thirdTemp, fourTemp, createTempErr := service.CreatePatientScheduleTemplateTwo(adminUserInfo.CurrentOrgId)
  1139. if createTempErr != nil {
  1140. this.ErrorLog("创建2个排班模板失败:%v", createTempErr)
  1141. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1142. return
  1143. }
  1144. templates = append(templates, thirdTemp, fourTemp)
  1145. } else if len(templates) == 3 {
  1146. temp, createTempErr := service.CreatePatientScheduleTemplateThree(adminUserInfo.CurrentOrgId)
  1147. if createTempErr != nil {
  1148. this.ErrorLog("创建1个排班模板失败:%v", createTempErr)
  1149. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1150. return
  1151. }
  1152. templates = append(templates, temp)
  1153. }
  1154. patients, getPatientsErr := service.PatientScheduleTemplateGetAllValidPatient(adminUserInfo.CurrentOrgId)
  1155. if getPatientsErr != nil {
  1156. this.ErrorLog("获取患者列表失败失败:%v", getPatientsErr)
  1157. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1158. return
  1159. }
  1160. // 获取本周的排班
  1161. //monday, sunday := utils.GetMondayAndSundayOfWeekDate(&now)
  1162. //schedules, getScheduleErr := service.GetWeekSchedule(adminUserInfo.CurrentOrgId, monday.Unix(), sunday.Unix())
  1163. //if getScheduleErr != nil {
  1164. // this.ErrorLog("获取本周排班失败:%v", getScheduleErr)
  1165. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1166. // return
  1167. //}
  1168. this.ServeSuccessJSON(map[string]interface{}{
  1169. "template_mode": mode,
  1170. "device_numbers": deviceNumbers,
  1171. "templates": templates,
  1172. "patients": patients,
  1173. //"schedules": schedules,
  1174. })
  1175. }
  1176. // /api/schtemp/p/setmode [post]
  1177. // @param mode:int 0.不启用模板 1.单周模板 2.双周模板 3.三周模版 4.四周模版
  1178. func (this *PatientScheduleTemplateAPIController) SetMode() {
  1179. mode, _ := this.GetInt8("mode")
  1180. week_time, _ := this.GetInt8("week_time")
  1181. if mode != 1 && mode != 2 && mode != 0 && mode != 3 && mode != 4 {
  1182. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1183. return
  1184. }
  1185. if mode > 0 {
  1186. if week_time == 0 {
  1187. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1188. return
  1189. }
  1190. }
  1191. adminUserInfo := this.GetAdminUserInfo()
  1192. templateMode, getTemplateModeErr := service.GetOrgPatientScheduleTemplateMode(adminUserInfo.CurrentOrgId)
  1193. if getTemplateModeErr != nil {
  1194. this.ErrorLog("获取排班模板启用模式失败:%v", getTemplateModeErr)
  1195. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1196. return
  1197. } else if templateMode == nil {
  1198. this.ErrorLog("获取不到排班模板启用模式")
  1199. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1200. return
  1201. }
  1202. templateMode.Week = int64(week_time)
  1203. templateMode.OriginalWeek = int64(week_time)
  1204. if mode != templateMode.Mode {
  1205. if templateMode.Mode == 0 { // 0 -> 1 或 0 -> 2 则直接清除下四周的排班
  1206. templateMode.Mode = mode
  1207. templateMode.ExecuteTimes = 0
  1208. templateMode.ModifyTime = time.Now().Unix()
  1209. updateErr := service.SavePatientScheduleTemplateModeAndClearNextTwoWeekSchedules(templateMode)
  1210. if updateErr != nil {
  1211. this.ErrorLog("更新排班模板启用方式(0 -> 1 或 0 -> 2)时失败:%v", updateErr)
  1212. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1213. return
  1214. }
  1215. } else if mode == 0 { // 1 -> 0 或 2 -> 0 则不处理排班,但清除所有模板item
  1216. templateMode.Mode = mode
  1217. templateMode.ExecuteTimes = 0
  1218. templateMode.ModifyTime = time.Now().Unix()
  1219. updateErr := service.SavePatientScheduleTemplateModeAndClearAllTemplateItems(templateMode)
  1220. if updateErr != nil {
  1221. this.ErrorLog("更新排班模板启用方式(1 -> 0 或 2 -> 0)时失败:%v", updateErr)
  1222. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1223. return
  1224. }
  1225. } else if templateMode.Mode == 1 && mode == 2 { // 1 -> 2 清除第二周排班
  1226. templateMode.Mode = mode
  1227. templateMode.ExecuteTimes = 0
  1228. templateMode.ModifyTime = time.Now().Unix()
  1229. updateErr := service.SavePatientScheduleTemplateModeAndClearNextTwoWeekSchedules(templateMode)
  1230. if updateErr != nil {
  1231. this.ErrorLog("更新排班模板启用方式(1 -> 2)时失败:%v", updateErr)
  1232. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1233. return
  1234. }
  1235. } else if templateMode.Mode == 1 && mode == 3 {
  1236. templateMode.Mode = mode
  1237. templateMode.ExecuteTimes = 0
  1238. templateMode.ModifyTime = time.Now().Unix()
  1239. updateErr := service.SaveTemplateMode(templateMode)
  1240. if updateErr != nil {
  1241. this.ErrorLog("更新排班模板启用方式(1 -> 3)时失败:%v", updateErr)
  1242. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1243. return
  1244. }
  1245. } else if templateMode.Mode == 1 && mode == 4 {
  1246. templateMode.Mode = mode
  1247. templateMode.ExecuteTimes = 0
  1248. templateMode.ModifyTime = time.Now().Unix()
  1249. updateErr := service.SaveTemplateMode(templateMode)
  1250. if updateErr != nil {
  1251. this.ErrorLog("更新排班模板启用方式(1 -> 4)时失败:%v", updateErr)
  1252. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1253. return
  1254. }
  1255. } else if templateMode.Mode == 2 && mode == 1 { // 2 -> 1 清除第二周模板item,清除第二周排班
  1256. templateIDs, getTemplateIDsErr := service.GetOrgPatientScheduleTemplateIDs(adminUserInfo.CurrentOrgId)
  1257. if getTemplateIDsErr != nil {
  1258. this.ErrorLog("获取排班模板失败:%v", getTemplateIDsErr)
  1259. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1260. return
  1261. }
  1262. firstWeekItems, getFirstWeekItemsErr := service.GetOrgPatientScheduleTemplateItemsWithoutPatientByTemplateID(adminUserInfo.CurrentOrgId, templateIDs[0].ID)
  1263. if getFirstWeekItemsErr != nil {
  1264. this.ErrorLog("获取排班模板排班失败:%v", getFirstWeekItemsErr)
  1265. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1266. return
  1267. }
  1268. templateMode.Mode = mode
  1269. templateMode.ExecuteTimes = 0
  1270. templateMode.ModifyTime = time.Now().Unix()
  1271. updateErr := service.SavePatientScheduleTemplateMode2To1(templateMode, templateIDs[1].ID, firstWeekItems)
  1272. if updateErr != nil {
  1273. this.ErrorLog("更新排班模板启用方式(1 -> 2)时失败:%v", updateErr)
  1274. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1275. return
  1276. }
  1277. } else if templateMode.Mode == 2 && mode == 3 { //
  1278. templateMode.Mode = mode
  1279. templateMode.ExecuteTimes = 0
  1280. templateMode.ModifyTime = time.Now().Unix()
  1281. updateErr := service.SaveTemplateMode(templateMode)
  1282. if updateErr != nil {
  1283. this.ErrorLog("更新排班模板启用方式(1 -> 4)时失败:%v", updateErr)
  1284. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1285. return
  1286. }
  1287. } else if templateMode.Mode == 2 && mode == 4 { //
  1288. templateMode.Mode = mode
  1289. templateMode.ExecuteTimes = 0
  1290. templateMode.ModifyTime = time.Now().Unix()
  1291. updateErr := service.SaveTemplateMode(templateMode)
  1292. if updateErr != nil {
  1293. this.ErrorLog("更新排班模板启用方式(1 -> 4)时失败:%v", updateErr)
  1294. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1295. return
  1296. }
  1297. } else if templateMode.Mode == 3 && mode == 1 { // 3 -> 1 清除第三,二周模板item,清除第三,二周排班
  1298. templateIDs, getTemplateIDsErr := service.GetOrgPatientScheduleTemplateIDs(adminUserInfo.CurrentOrgId)
  1299. if getTemplateIDsErr != nil {
  1300. this.ErrorLog("获取排班模板失败:%v", getTemplateIDsErr)
  1301. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1302. return
  1303. }
  1304. templateMode.Mode = mode
  1305. templateMode.ExecuteTimes = 0
  1306. templateMode.ModifyTime = time.Now().Unix()
  1307. updateErr := service.SavePatientScheduleTemplateMode3To1(templateMode, templateIDs[1].ID, templateIDs[2].ID)
  1308. if updateErr != nil {
  1309. this.ErrorLog("更新排班模板启用方式(1 -> 3)时失败:%v", updateErr)
  1310. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1311. return
  1312. }
  1313. } else if templateMode.Mode == 3 && mode == 2 { // 3 -> 1 清除第三周模板item,清除第三周排班,将第一周的排班重复到第二周
  1314. templateIDs, getTemplateIDsErr := service.GetOrgPatientScheduleTemplateIDs(adminUserInfo.CurrentOrgId)
  1315. if getTemplateIDsErr != nil {
  1316. this.ErrorLog("获取排班模板失败:%v", getTemplateIDsErr)
  1317. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1318. return
  1319. }
  1320. templateMode.Mode = mode
  1321. templateMode.ExecuteTimes = 0
  1322. templateMode.ModifyTime = time.Now().Unix()
  1323. updateErr := service.SavePatientScheduleTemplateMode3To2(templateMode, templateIDs[2].ID)
  1324. if updateErr != nil {
  1325. this.ErrorLog("更新排班模板启用方式(2 -> 3)时失败:%v", updateErr)
  1326. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1327. return
  1328. }
  1329. } else if templateMode.Mode == 3 && mode == 4 { // 2 -> 1 清除第二周模板item,清除第二周排班
  1330. templateMode.Mode = mode
  1331. templateMode.ExecuteTimes = 0
  1332. templateMode.ModifyTime = time.Now().Unix()
  1333. updateErr := service.SaveTemplateMode(templateMode)
  1334. if updateErr != nil {
  1335. this.ErrorLog("更新排班模板启用方式(1 -> 4)时失败:%v", updateErr)
  1336. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1337. return
  1338. }
  1339. } else if templateMode.Mode == 4 && mode == 1 { // 4 -> 1 清除第三周模板item,清除第三周排班,将第一周的排班重复到第二周
  1340. templateIDs, getTemplateIDsErr := service.GetOrgPatientScheduleTemplateIDs(adminUserInfo.CurrentOrgId)
  1341. if getTemplateIDsErr != nil {
  1342. this.ErrorLog("获取排班模板失败:%v", getTemplateIDsErr)
  1343. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1344. return
  1345. }
  1346. templateMode.Mode = mode
  1347. templateMode.ExecuteTimes = 0
  1348. templateMode.ModifyTime = time.Now().Unix()
  1349. updateErr := service.SavePatientScheduleTemplateMode4To1(templateMode, templateIDs[1].ID, templateIDs[2].ID, templateIDs[3].ID)
  1350. if updateErr != nil {
  1351. this.ErrorLog("更新排班模板启用方式(1 -> 4)时失败:%v", updateErr)
  1352. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1353. return
  1354. }
  1355. } else if templateMode.Mode == 4 && mode == 2 { // 4 -> 2
  1356. templateIDs, getTemplateIDsErr := service.GetOrgPatientScheduleTemplateIDs(adminUserInfo.CurrentOrgId)
  1357. if getTemplateIDsErr != nil {
  1358. this.ErrorLog("获取排班模板失败:%v", getTemplateIDsErr)
  1359. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1360. return
  1361. }
  1362. templateMode.Mode = mode
  1363. templateMode.ExecuteTimes = 0
  1364. templateMode.ModifyTime = time.Now().Unix()
  1365. updateErr := service.SavePatientScheduleTemplateMode4To2(templateMode, templateIDs[2].ID, templateIDs[3].ID)
  1366. if updateErr != nil {
  1367. this.ErrorLog("更新排班模板启用方式(2 -> 4)时失败:%v", updateErr)
  1368. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1369. return
  1370. }
  1371. } else if templateMode.Mode == 4 && mode == 3 { // 4 -> 3
  1372. templateIDs, getTemplateIDsErr := service.GetOrgPatientScheduleTemplateIDs(adminUserInfo.CurrentOrgId)
  1373. if getTemplateIDsErr != nil {
  1374. this.ErrorLog("获取排班模板失败:%v", getTemplateIDsErr)
  1375. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1376. return
  1377. }
  1378. templateMode.Mode = mode
  1379. templateMode.ExecuteTimes = 0
  1380. templateMode.ModifyTime = time.Now().Unix()
  1381. updateErr := service.SavePatientScheduleTemplateMode4To3(templateMode, templateIDs[3].ID)
  1382. if updateErr != nil {
  1383. this.ErrorLog("更新排班模板启用方式(3 -> 4)时失败:%v", updateErr)
  1384. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1385. return
  1386. }
  1387. }
  1388. templates, _ := service.GetOrgPatientScheduleTemplateIDs(adminUserInfo.CurrentOrgId)
  1389. //处理第几周数问题
  1390. if mode == 0 {
  1391. service.UpdateTemplateItemWeek(templates[0].OrgID, templates[0].ID, 0)
  1392. service.UpdateTemplateItemWeek(templates[1].OrgID, templates[1].ID, 0)
  1393. service.UpdateTemplateItemWeek(templates[2].OrgID, templates[2].ID, 0)
  1394. service.UpdateTemplateItemWeek(templates[3].OrgID, templates[3].ID, 0)
  1395. } else if mode == 1 {
  1396. service.UpdateTemplateItemWeek(templates[0].OrgID, templates[0].ID, week_time)
  1397. service.UpdateTemplateItemWeek(templates[1].OrgID, templates[1].ID, 0)
  1398. service.UpdateTemplateItemWeek(templates[2].OrgID, templates[2].ID, 0)
  1399. service.UpdateTemplateItemWeek(templates[3].OrgID, templates[3].ID, 0)
  1400. } else if mode == 2 {
  1401. service.UpdateTemplateItemWeek(templates[0].OrgID, templates[0].ID, week_time)
  1402. service.UpdateTemplateItemWeek(templates[1].OrgID, templates[1].ID, week_time+1)
  1403. service.UpdateTemplateItemWeek(templates[2].OrgID, templates[2].ID, 0)
  1404. service.UpdateTemplateItemWeek(templates[3].OrgID, templates[3].ID, 0)
  1405. } else if mode == 3 {
  1406. service.UpdateTemplateItemWeek(templates[0].OrgID, templates[0].ID, week_time)
  1407. service.UpdateTemplateItemWeek(templates[1].OrgID, templates[1].ID, week_time+1)
  1408. service.UpdateTemplateItemWeek(templates[2].OrgID, templates[2].ID, week_time+2)
  1409. service.UpdateTemplateItemWeek(templates[3].OrgID, templates[3].ID, 0)
  1410. } else if mode == 4 {
  1411. service.UpdateTemplateItemWeek(templates[0].OrgID, templates[0].ID, week_time)
  1412. service.UpdateTemplateItemWeek(templates[1].OrgID, templates[1].ID, week_time+1)
  1413. service.UpdateTemplateItemWeek(templates[2].OrgID, templates[2].ID, week_time+2)
  1414. service.UpdateTemplateItemWeek(templates[3].OrgID, templates[3].ID, week_time+3)
  1415. }
  1416. } else {
  1417. fmt.Println("~~~~~~~~")
  1418. service.UpdateTemplateItemModeWeek(adminUserInfo.CurrentOrgId, templateMode.ID, templateMode.OriginalWeek)
  1419. }
  1420. this.ServeSuccessJSON(nil)
  1421. }
  1422. // /api/schtemp/p/update_sch [post]
  1423. // @param template_id:int
  1424. // @param add_schs:array'json ([ {device_number_id, patient_id, mode(treat_mode), weekday, time_type} ])
  1425. // @param del_schs:array'json ([ {device_number_id, weekday, time_type} ])
  1426. // @param change_schs:array'json ([ {device_number_id, patient_id, mode(treat_mode), weekday, time_type} ])
  1427. func (this *PatientScheduleTemplateAPIController) UpdateSchedules() {
  1428. templateID, _ := this.GetInt64("template_id")
  1429. addSchedulesJSON := this.GetString("add_schs")
  1430. delSchedulesJSON := this.GetString("del_schs")
  1431. changeSchedulesJSON := this.GetString("change_schs")
  1432. var addSchedules []*ParamModelSchedule
  1433. var delSchedules []*ParamModelSchedule
  1434. var changeSchedules []*ParamModelSchedule
  1435. parseErr := json.Unmarshal([]byte(addSchedulesJSON), &addSchedules)
  1436. if parseErr != nil {
  1437. this.ErrorLog("解析增加排班的数组参数失败:%v", parseErr)
  1438. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1439. return
  1440. }
  1441. parseErr = json.Unmarshal([]byte(delSchedulesJSON), &delSchedules)
  1442. if parseErr != nil {
  1443. this.ErrorLog("解析删除排班的数组参数失败:%v", parseErr)
  1444. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1445. return
  1446. }
  1447. parseErr = json.Unmarshal([]byte(changeSchedulesJSON), &changeSchedules)
  1448. if parseErr != nil {
  1449. this.ErrorLog("解析修改排班的数组参数失败:%v", parseErr)
  1450. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1451. return
  1452. }
  1453. adminUserInfo := this.GetAdminUserInfo()
  1454. templateIDs, getTemplateIDsErr := service.GetOrgPatientScheduleTemplateIDs(adminUserInfo.CurrentOrgId)
  1455. if getTemplateIDsErr != nil {
  1456. this.ErrorLog("获取排班模板失败:%v", getTemplateIDsErr)
  1457. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1458. return
  1459. } else {
  1460. isTemplateIDExist := false
  1461. for _, templateIDObject := range templateIDs {
  1462. if templateIDObject.ID == templateID {
  1463. isTemplateIDExist = true
  1464. break
  1465. }
  1466. }
  1467. if isTemplateIDExist == false {
  1468. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleTemplateNotExist)
  1469. return
  1470. }
  1471. }
  1472. addTemplateItems := make([]*models.PatientScheduleTemplateItem, 0, len(addSchedules))
  1473. delTemplateItems := make([]*models.PatientScheduleTemplateItem, 0, len(delSchedules))
  1474. changeTemplateItems := make([]*models.PatientScheduleTemplateItem, 0, len(changeSchedules))
  1475. for _, sch := range addSchedules {
  1476. if sch.DeviceNumberID <= 0 || sch.PatientID <= 0 || sch.Weekday < 1 || sch.Weekday > 7 || sch.TimeType < 1 || sch.TimeType > 3 {
  1477. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1478. return
  1479. }
  1480. addTemplateItems = append(addTemplateItems, &models.PatientScheduleTemplateItem{
  1481. DeviceNumberID: sch.DeviceNumberID,
  1482. PatientID: sch.PatientID,
  1483. TreatMode: sch.Mode,
  1484. Weekday: sch.Weekday,
  1485. TimeType: sch.TimeType,
  1486. })
  1487. }
  1488. for _, sch := range delSchedules {
  1489. if sch.DeviceNumberID <= 0 || sch.Weekday < 1 || sch.Weekday > 7 || sch.TimeType < 1 || sch.TimeType > 3 {
  1490. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1491. return
  1492. }
  1493. delTemplateItems = append(delTemplateItems, &models.PatientScheduleTemplateItem{
  1494. DeviceNumberID: sch.DeviceNumberID,
  1495. Weekday: sch.Weekday,
  1496. TimeType: sch.TimeType,
  1497. })
  1498. }
  1499. for _, sch := range changeSchedules {
  1500. if sch.DeviceNumberID <= 0 || sch.PatientID <= 0 || sch.Weekday < 1 || sch.Weekday > 7 || sch.TimeType < 1 || sch.TimeType > 3 {
  1501. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1502. return
  1503. }
  1504. changeTemplateItems = append(changeTemplateItems, &models.PatientScheduleTemplateItem{
  1505. DeviceNumberID: sch.DeviceNumberID,
  1506. PatientID: sch.PatientID,
  1507. TreatMode: sch.Mode,
  1508. Weekday: sch.Weekday,
  1509. TimeType: sch.TimeType,
  1510. })
  1511. }
  1512. templateMode, getTemplateModeErr := service.GetOrgPatientScheduleTemplateMode(adminUserInfo.CurrentOrgId)
  1513. if getTemplateModeErr != nil {
  1514. this.ErrorLog("获取排班模板启用模式失败:%v", getTemplateModeErr)
  1515. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1516. return
  1517. } else if templateMode == nil {
  1518. this.ErrorLog("获取不到排班模板启用模式")
  1519. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1520. return
  1521. }
  1522. //shouldUpdateNextWeekSchedules := false
  1523. //shouldUpdateNextSecondWeekSchedules := false
  1524. //shouldUpdateNextThirdWeekSchedules := false
  1525. //shouldUpdateNextFourWeekSchedules := false
  1526. //
  1527. if templateMode.Mode == 0 {
  1528. this.ErrorLog("当前未开启排班模板,所以更新模板的操作将被无视")
  1529. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1530. return
  1531. }
  1532. //判断当前用的是模版几
  1533. //templateIDIndex := 1
  1534. //for index, templateIDObject := range templateIDs {
  1535. // if templateIDObject.ID == templateID {
  1536. // //templateIDIndex = index + 1
  1537. // }
  1538. //}
  1539. //if templateMode.Mode == 1 {
  1540. // if templateIDIndex == 1 {
  1541. // shouldUpdateNextWeekSchedules = true
  1542. // shouldUpdateNextSecondWeekSchedules = true
  1543. // } else {
  1544. // this.ErrorLog("当前开启的是单周模板,所以不会更新第二个模板")
  1545. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1546. // return
  1547. // }
  1548. //
  1549. //} else if templateMode.Mode == 2 { // mode == 2 => 开启双周模板时,只需更新一周排班
  1550. // if templateIDIndex == 1 {
  1551. // if templateMode.ExecuteTimes%2 == 0 {
  1552. // shouldUpdateNextWeekSchedules = true
  1553. // shouldUpdateNextSecondWeekSchedules = false
  1554. // } else {
  1555. // shouldUpdateNextWeekSchedules = false
  1556. // shouldUpdateNextSecondWeekSchedules = true
  1557. // }
  1558. //
  1559. // } else {
  1560. // if templateMode.ExecuteTimes%2 == 0 {
  1561. // shouldUpdateNextWeekSchedules = false
  1562. // shouldUpdateNextSecondWeekSchedules = true
  1563. // } else {
  1564. // shouldUpdateNextWeekSchedules = true
  1565. // shouldUpdateNextSecondWeekSchedules = false
  1566. // }
  1567. //
  1568. // }
  1569. //} else if templateMode.Mode == 3 { // mode == 2 => 开启双周模板时,只需更新一周排班
  1570. // if templateIDIndex == 1 { //当前修改的是第一个模版
  1571. // if templateMode.ExecuteTimes%3 == 0 {
  1572. // shouldUpdateNextWeekSchedules = true
  1573. // shouldUpdateNextSecondWeekSchedules = false
  1574. // shouldUpdateNextThirdWeekSchedules = false
  1575. // } else if templateMode.ExecuteTimes%3 == 1 {
  1576. // shouldUpdateNextWeekSchedules = false
  1577. // shouldUpdateNextSecondWeekSchedules = true
  1578. // shouldUpdateNextThirdWeekSchedules = false
  1579. // } else {
  1580. // shouldUpdateNextWeekSchedules = false
  1581. // shouldUpdateNextSecondWeekSchedules = false
  1582. // shouldUpdateNextThirdWeekSchedules = true
  1583. // }
  1584. // } else if templateIDIndex == 2 {
  1585. // if templateMode.ExecuteTimes%2 == 0 {
  1586. // shouldUpdateNextWeekSchedules = false
  1587. // shouldUpdateNextSecondWeekSchedules = true
  1588. // } else {
  1589. // shouldUpdateNextWeekSchedules = true
  1590. // shouldUpdateNextSecondWeekSchedules = false
  1591. // }
  1592. //
  1593. // } else {
  1594. //
  1595. // }
  1596. //}
  1597. updateErr := service.UpdateScheduleTemplate(adminUserInfo.CurrentOrgId, templateID, addTemplateItems, delTemplateItems, changeTemplateItems, false, false)
  1598. if updateErr != nil {
  1599. this.ErrorLog("更新排班模板排班失败:%v", updateErr)
  1600. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1601. return
  1602. }
  1603. templates, getTemplateItemsErr := service.GetOrgPatientScheduleTemplateItems(adminUserInfo.CurrentOrgId)
  1604. if getTemplateItemsErr != nil {
  1605. this.ErrorLog("获取排班模板排班失败:%v", getTemplateItemsErr)
  1606. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1607. return
  1608. }
  1609. this.ServeSuccessJSON(map[string]interface{}{
  1610. "items": templates,
  1611. })
  1612. }
  1613. func WeekIntervalTime(week int) []string {
  1614. now := time.Now()
  1615. offset := int(time.Monday - now.Weekday())
  1616. //周日做特殊判断 因为time.Monday = 0
  1617. if offset > 0 {
  1618. offset = -6
  1619. }
  1620. var timeArr []string
  1621. year, month, day := now.Date()
  1622. thisWeek := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1623. startTime := thisWeek.AddDate(0, 0, offset+7*week).Format("2006-01-02") + " 00:00:00"
  1624. twoTime := thisWeek.AddDate(0, 0, offset+1+7*week).Format("2006-01-02") + " 00:00:00"
  1625. threeTime := thisWeek.AddDate(0, 0, offset+2+7*week).Format("2006-01-02") + " 00:00:00"
  1626. fourTime := thisWeek.AddDate(0, 0, offset+3+7*week).Format("2006-01-02") + " 00:00:00"
  1627. fiveTime := thisWeek.AddDate(0, 0, offset+4+7*week).Format("2006-01-02") + " 00:00:00"
  1628. SixTime := thisWeek.AddDate(0, 0, offset+5+7*week).Format("2006-01-02") + " 00:00:00"
  1629. endTime := thisWeek.AddDate(0, 0, offset+6+7*week).Format("2006-01-02") + " 00:00:00"
  1630. timeArr = append(timeArr, startTime)
  1631. timeArr = append(timeArr, twoTime)
  1632. timeArr = append(timeArr, threeTime)
  1633. timeArr = append(timeArr, fourTime)
  1634. timeArr = append(timeArr, fiveTime)
  1635. timeArr = append(timeArr, SixTime)
  1636. timeArr = append(timeArr, endTime)
  1637. return timeArr
  1638. }
  1639. type ParamModelSchedule struct {
  1640. DeviceNumberID int64 `json:"device_number_id"`
  1641. PatientID int64 `json:"patient_id"`
  1642. Mode int64 `json:"mode"`
  1643. Weekday int8 `json:"weekday"`
  1644. TimeType int8 `json:"time_type"`
  1645. }
  1646. func (this *PatientScheduleTemplateAPIController) GetPatientList() {
  1647. patients, err := service.GetSchTemplatePatientList(this.GetAdminUserInfo().CurrentOrgId)
  1648. if err != nil {
  1649. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1650. }
  1651. this.ServeSuccessJSON(map[string]interface{}{
  1652. "list": patients,
  1653. })
  1654. }
  1655. type ParamModelEditSchedule struct {
  1656. ID int64 `json:"sch_id"`
  1657. DeviceNumberID int64 `json:"jihao_id"`
  1658. PatientID int64 `json:"patient_id"`
  1659. Mode int64 `json:"mode_id"`
  1660. Weekday int64 `json:"schedule_week"`
  1661. TimeType int64 `json:"time_type"`
  1662. TemplateID int64 `json:"t_id"`
  1663. Title string `json:"title"`
  1664. }
  1665. func (this *PatientScheduleTemplateAPIController) UpdateSchedulesTemplate() {
  1666. addOrEditSchedulesJSON := this.GetString("edit_schs")
  1667. delSchedulesJSON := this.GetString("del_schs")
  1668. fmt.Println(addOrEditSchedulesJSON)
  1669. var addOrEditSchedules []*ParamModelEditSchedule
  1670. var delSchedules []*ParamModelEditSchedule
  1671. parseErr := json.Unmarshal([]byte(addOrEditSchedulesJSON), &addOrEditSchedules)
  1672. json.Unmarshal([]byte(delSchedulesJSON), &delSchedules)
  1673. fmt.Println(parseErr)
  1674. if parseErr != nil {
  1675. this.ErrorLog("解析增加编辑排班的数组参数失败:%v", parseErr)
  1676. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1677. return
  1678. }
  1679. //if parseDelErr != nil {
  1680. // this.ErrorLog("解析删除排班的数组参数失败:%v", parseErr)
  1681. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1682. // return
  1683. //}
  1684. for _, item := range delSchedules {
  1685. src_template, _ := service.GetScheduleTemplateItem(item.ID)
  1686. src_template.Status = 0
  1687. service.SaveSchTemplateItem(src_template)
  1688. }
  1689. for _, item := range addOrEditSchedules {
  1690. if item.ID > 0 { //已经存在的数据
  1691. src_template, _ := service.GetScheduleTemplateItem(item.ID)
  1692. src_template.DeviceNumberID = item.DeviceNumberID
  1693. src_template.TimeType = int8(item.TimeType)
  1694. src_template.TreatMode = item.Mode
  1695. schItem, _ := service.GetScheduleTemplateThree(this.GetAdminUserInfo().CurrentOrgId, src_template.DeviceNumberID, src_template.TemplateID, int64(src_template.Weekday), int64(src_template.TimeType), src_template.PatientID)
  1696. if schItem.ID > 0 {
  1697. json := make(map[string]interface{})
  1698. json["msg"] = item.Title + "周" + strconv.FormatInt(item.Weekday, 10) + "的床位已经有人排班无法保存,可能存在重复排班"
  1699. json["state"] = 0
  1700. this.Data["json"] = json
  1701. this.ServeJSON()
  1702. break
  1703. }
  1704. service.SaveSchTemplateItem(src_template)
  1705. } else {
  1706. schItemTwo, _ := service.GetScheduleTemplateTwo(this.GetAdminUserInfo().CurrentOrgId, item.TemplateID, item.Weekday, item.PatientID)
  1707. fmt.Println("222222")
  1708. if schItemTwo.ID > 0 { //当天存在排班,存在则为修改
  1709. fmt.Println("333333333")
  1710. src_template, _ := service.GetScheduleTemplateItem(schItemTwo.ID)
  1711. src_template.DeviceNumberID = item.DeviceNumberID
  1712. src_template.TimeType = int8(item.TimeType)
  1713. src_template.TreatMode = item.Mode
  1714. service.SaveSchTemplateItem(src_template)
  1715. } else {
  1716. schItem, _ := service.GetScheduleTemplateOne(this.GetAdminUserInfo().CurrentOrgId, item.DeviceNumberID, item.TemplateID, item.Weekday, item.TimeType)
  1717. if schItem.ID == 0 { //床位未被占用
  1718. var template models.PatientScheduleTemplateItem
  1719. template.TreatMode = item.Mode
  1720. template.TemplateID = int64(item.TemplateID)
  1721. template.TimeType = int8(item.TimeType)
  1722. template.DeviceNumberID = item.DeviceNumberID
  1723. template.CreateTime = time.Now().Unix()
  1724. template.ModifyTime = time.Now().Unix()
  1725. template.OrgID = this.GetAdminUserInfo().CurrentOrgId
  1726. template.PatientID = item.PatientID
  1727. template.Weekday = int8(item.Weekday)
  1728. template.Status = 1
  1729. service.SaveSchTemplateItem(template)
  1730. } else { //床位被占用 1.被自己占用,2。被别人占用
  1731. if schItem.PatientID != 0 && schItem.PatientID == item.PatientID { //当天该患者已经存在排班则设为修改操作
  1732. src_template, _ := service.GetScheduleTemplateItem(schItem.ID)
  1733. src_template.DeviceNumberID = item.DeviceNumberID
  1734. src_template.TimeType = int8(item.TimeType)
  1735. src_template.TreatMode = item.Mode
  1736. service.SaveSchTemplateItem(src_template)
  1737. } else if schItem.PatientID != 0 && schItem.PatientID != item.PatientID { //当天该床位被其他人占用,则无法保存
  1738. //fmt.Println("7777777")
  1739. json := make(map[string]interface{})
  1740. json["msg"] = item.Title + "周" + strconv.FormatInt(item.Weekday, 10) + "的床位已经有人排班,无法保存"
  1741. json["state"] = 0
  1742. this.Data["json"] = json
  1743. this.ServeJSON()
  1744. break
  1745. }
  1746. }
  1747. }
  1748. }
  1749. }
  1750. templates, _ := service.GetOrgPatientScheduleTemplateItems(this.GetAdminUserInfo().CurrentOrgId)
  1751. this.ServeSuccessJSON(map[string]interface{}{
  1752. "items": templates,
  1753. })
  1754. }
  1755. //func (c *ScheduleApiController) DeleteScheduleTemplateTwo() {
  1756. // id, _ := c.GetInt64("id", 0)
  1757. // if id <= 0 {
  1758. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1759. // return
  1760. // }
  1761. //
  1762. // adminINfo := c.GetAdminUserInfo()
  1763. //
  1764. // schedule, _ := service.GetSc(adminINfo.CurrentOrgId, id)
  1765. // timeNow := time.Now().Format("2006-01-02")
  1766. // timeTemplate := "2006-01-02"
  1767. //
  1768. // tm := time.Unix(int64(schedule.ScheduleDate), 0)
  1769. // timeStr := tm.Format(timeTemplate)
  1770. // if timeNow > timeStr {
  1771. //
  1772. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleBeforeNow)
  1773. // return
  1774. // }
  1775. // if schedule == nil {
  1776. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist)
  1777. // return
  1778. // }
  1779. //
  1780. // order, err := service.GetOneDialysisOrder(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
  1781. // if err != nil {
  1782. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1783. // return
  1784. // }
  1785. //
  1786. // if order != nil {
  1787. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDelScheduleFailByDialysisTwo)
  1788. // return
  1789. // }
  1790. //
  1791. // schedule.Status = 0
  1792. // schedule.UpdatedTime = time.Now().Unix()
  1793. // err = service.UpdateSchedule(schedule)
  1794. // redis := service.RedisClient()
  1795. //
  1796. // //处方
  1797. // keyOne := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":prescriptions_list_all"
  1798. // redis.Set(keyOne, "", time.Second)
  1799. //
  1800. // //医嘱
  1801. // keyTwo := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":advice_list_all"
  1802. // redis.Set(keyTwo, "", time.Second)
  1803. //
  1804. // keySix := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_befores_list_all"
  1805. // redis.Set(keySix, "", time.Second)
  1806. // keyThree := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_after_dislysis_list_all"
  1807. // redis.Set(keyThree, "", time.Second)
  1808. //
  1809. // keyFour := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":monitor_record_list_all"
  1810. // redis.Set(keyFour, "", time.Second)
  1811. //
  1812. // keyFive := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":treatment_summarys_list_all"
  1813. // redis.Set(keyFive, "", time.Second)
  1814. //
  1815. // keySeven := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":dialysis_orders_list_all"
  1816. // redis.Set(keySeven, "", time.Second)
  1817. // fmt.Println(err)
  1818. // defer redis.Close()
  1819. // if err != nil {
  1820. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteScheduleFail)
  1821. // return
  1822. // }
  1823. //
  1824. // c.ServeSuccessJSON(map[string]interface{}{
  1825. // "msg": "ok",
  1826. // "schedule": &schedule,
  1827. // })
  1828. //}