schedule_template_api_controller.go 77KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "encoding/json"
  7. "fmt"
  8. "strconv"
  9. "strings"
  10. "time"
  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. fmt.Println("deviceNumbers233323232332232323223233223323232323", deviceNumbers)
  1111. if getDeviceNumbersErr != nil {
  1112. this.ErrorLog("获取床位号失败:%v", getDeviceNumbersErr)
  1113. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1114. return
  1115. }
  1116. templates, getTemplatesErr := service.GetOrgPatientScheduleTemplateItems(adminUserInfo.CurrentOrgId)
  1117. if getTemplatesErr != nil {
  1118. this.ErrorLog("获取排班模板及其排班列表失败:%v", getTemplatesErr)
  1119. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1120. return
  1121. }
  1122. if len(templates) == 0 {
  1123. firstTemp, secondTemp, thirdTemp, fourTemp, createTempErr := service.CreateTwoPatientScheduleTemplates(adminUserInfo.CurrentOrgId)
  1124. if createTempErr != nil {
  1125. this.ErrorLog("创建4个排班模板失败:%v", createTempErr)
  1126. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1127. return
  1128. }
  1129. templates = append(templates, firstTemp, secondTemp, thirdTemp, fourTemp)
  1130. } else if len(templates) == 1 {
  1131. temp, thirdTemp, fourTemp, createTempErr := service.CreatePatientScheduleTemplate(adminUserInfo.CurrentOrgId)
  1132. if createTempErr != nil {
  1133. this.ErrorLog("创建3个排班模板失败:%v", createTempErr)
  1134. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1135. return
  1136. }
  1137. templates = append(templates, temp, thirdTemp, fourTemp)
  1138. } else if len(templates) == 2 {
  1139. thirdTemp, fourTemp, createTempErr := service.CreatePatientScheduleTemplateTwo(adminUserInfo.CurrentOrgId)
  1140. if createTempErr != nil {
  1141. this.ErrorLog("创建2个排班模板失败:%v", createTempErr)
  1142. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1143. return
  1144. }
  1145. templates = append(templates, thirdTemp, fourTemp)
  1146. } else if len(templates) == 3 {
  1147. temp, createTempErr := service.CreatePatientScheduleTemplateThree(adminUserInfo.CurrentOrgId)
  1148. if createTempErr != nil {
  1149. this.ErrorLog("创建1个排班模板失败:%v", createTempErr)
  1150. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1151. return
  1152. }
  1153. templates = append(templates, temp)
  1154. }
  1155. patients, getPatientsErr := service.PatientScheduleTemplateGetAllValidPatient(adminUserInfo.CurrentOrgId)
  1156. if getPatientsErr != nil {
  1157. this.ErrorLog("获取患者列表失败失败:%v", getPatientsErr)
  1158. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1159. return
  1160. }
  1161. // 获取本周的排班
  1162. //monday, sunday := utils.GetMondayAndSundayOfWeekDate(&now)
  1163. //schedules, getScheduleErr := service.GetWeekSchedule(adminUserInfo.CurrentOrgId, monday.Unix(), sunday.Unix())
  1164. //if getScheduleErr != nil {
  1165. // this.ErrorLog("获取本周排班失败:%v", getScheduleErr)
  1166. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1167. // return
  1168. //}
  1169. this.ServeSuccessJSON(map[string]interface{}{
  1170. "template_mode": mode,
  1171. "device_numbers": deviceNumbers,
  1172. "templates": templates,
  1173. "patients": patients,
  1174. //"schedules": schedules,
  1175. })
  1176. }
  1177. // /api/schtemp/p/setmode [post]
  1178. // @param mode:int 0.不启用模板 1.单周模板 2.双周模板 3.三周模版 4.四周模版
  1179. func (this *PatientScheduleTemplateAPIController) SetMode() {
  1180. mode, _ := this.GetInt8("mode")
  1181. week_time, _ := this.GetInt8("week_time")
  1182. if mode != 1 && mode != 2 && mode != 0 && mode != 3 && mode != 4 {
  1183. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1184. return
  1185. }
  1186. if mode > 0 {
  1187. if week_time == 0 {
  1188. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1189. return
  1190. }
  1191. }
  1192. adminUserInfo := this.GetAdminUserInfo()
  1193. templateMode, getTemplateModeErr := service.GetOrgPatientScheduleTemplateMode(adminUserInfo.CurrentOrgId)
  1194. if getTemplateModeErr != nil {
  1195. this.ErrorLog("获取排班模板启用模式失败:%v", getTemplateModeErr)
  1196. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1197. return
  1198. } else if templateMode == nil {
  1199. this.ErrorLog("获取不到排班模板启用模式")
  1200. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1201. return
  1202. }
  1203. templateMode.Week = int64(week_time)
  1204. templateMode.OriginalWeek = int64(week_time)
  1205. if mode != templateMode.Mode {
  1206. if templateMode.Mode == 0 { // 0 -> 1 或 0 -> 2 则直接清除下四周的排班
  1207. templateMode.Mode = mode
  1208. templateMode.ExecuteTimes = 0
  1209. templateMode.ModifyTime = time.Now().Unix()
  1210. updateErr := service.SavePatientScheduleTemplateModeAndClearNextTwoWeekSchedules(templateMode)
  1211. if updateErr != nil {
  1212. this.ErrorLog("更新排班模板启用方式(0 -> 1 或 0 -> 2)时失败:%v", updateErr)
  1213. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1214. return
  1215. }
  1216. } else if mode == 0 { // 1 -> 0 或 2 -> 0 则不处理排班,但清除所有模板item
  1217. templateMode.Mode = mode
  1218. templateMode.ExecuteTimes = 0
  1219. templateMode.ModifyTime = time.Now().Unix()
  1220. updateErr := service.SavePatientScheduleTemplateModeAndClearAllTemplateItems(templateMode)
  1221. if updateErr != nil {
  1222. this.ErrorLog("更新排班模板启用方式(1 -> 0 或 2 -> 0)时失败:%v", updateErr)
  1223. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1224. return
  1225. }
  1226. } else if templateMode.Mode == 1 && mode == 2 { // 1 -> 2 清除第二周排班
  1227. templateMode.Mode = mode
  1228. templateMode.ExecuteTimes = 0
  1229. templateMode.ModifyTime = time.Now().Unix()
  1230. updateErr := service.SavePatientScheduleTemplateModeAndClearNextTwoWeekSchedules(templateMode)
  1231. if updateErr != nil {
  1232. this.ErrorLog("更新排班模板启用方式(1 -> 2)时失败:%v", updateErr)
  1233. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1234. return
  1235. }
  1236. } else if templateMode.Mode == 1 && mode == 3 {
  1237. templateMode.Mode = mode
  1238. templateMode.ExecuteTimes = 0
  1239. templateMode.ModifyTime = time.Now().Unix()
  1240. updateErr := service.SaveTemplateMode(templateMode)
  1241. if updateErr != nil {
  1242. this.ErrorLog("更新排班模板启用方式(1 -> 3)时失败:%v", updateErr)
  1243. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1244. return
  1245. }
  1246. } else if templateMode.Mode == 1 && mode == 4 {
  1247. templateMode.Mode = mode
  1248. templateMode.ExecuteTimes = 0
  1249. templateMode.ModifyTime = time.Now().Unix()
  1250. updateErr := service.SaveTemplateMode(templateMode)
  1251. if updateErr != nil {
  1252. this.ErrorLog("更新排班模板启用方式(1 -> 4)时失败:%v", updateErr)
  1253. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1254. return
  1255. }
  1256. } else if templateMode.Mode == 2 && mode == 1 { // 2 -> 1 清除第二周模板item,清除第二周排班
  1257. templateIDs, getTemplateIDsErr := service.GetOrgPatientScheduleTemplateIDs(adminUserInfo.CurrentOrgId)
  1258. if getTemplateIDsErr != nil {
  1259. this.ErrorLog("获取排班模板失败:%v", getTemplateIDsErr)
  1260. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1261. return
  1262. }
  1263. firstWeekItems, getFirstWeekItemsErr := service.GetOrgPatientScheduleTemplateItemsWithoutPatientByTemplateID(adminUserInfo.CurrentOrgId, templateIDs[0].ID)
  1264. if getFirstWeekItemsErr != nil {
  1265. this.ErrorLog("获取排班模板排班失败:%v", getFirstWeekItemsErr)
  1266. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1267. return
  1268. }
  1269. templateMode.Mode = mode
  1270. templateMode.ExecuteTimes = 0
  1271. templateMode.ModifyTime = time.Now().Unix()
  1272. updateErr := service.SavePatientScheduleTemplateMode2To1(templateMode, templateIDs[1].ID, firstWeekItems)
  1273. if updateErr != nil {
  1274. this.ErrorLog("更新排班模板启用方式(1 -> 2)时失败:%v", updateErr)
  1275. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1276. return
  1277. }
  1278. } else if templateMode.Mode == 2 && mode == 3 { //
  1279. templateMode.Mode = mode
  1280. templateMode.ExecuteTimes = 0
  1281. templateMode.ModifyTime = time.Now().Unix()
  1282. updateErr := service.SaveTemplateMode(templateMode)
  1283. if updateErr != nil {
  1284. this.ErrorLog("更新排班模板启用方式(1 -> 4)时失败:%v", updateErr)
  1285. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1286. return
  1287. }
  1288. } else if templateMode.Mode == 2 && mode == 4 { //
  1289. templateMode.Mode = mode
  1290. templateMode.ExecuteTimes = 0
  1291. templateMode.ModifyTime = time.Now().Unix()
  1292. updateErr := service.SaveTemplateMode(templateMode)
  1293. if updateErr != nil {
  1294. this.ErrorLog("更新排班模板启用方式(1 -> 4)时失败:%v", updateErr)
  1295. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1296. return
  1297. }
  1298. } else if templateMode.Mode == 3 && mode == 1 { // 3 -> 1 清除第三,二周模板item,清除第三,二周排班
  1299. templateIDs, getTemplateIDsErr := service.GetOrgPatientScheduleTemplateIDs(adminUserInfo.CurrentOrgId)
  1300. if getTemplateIDsErr != nil {
  1301. this.ErrorLog("获取排班模板失败:%v", getTemplateIDsErr)
  1302. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1303. return
  1304. }
  1305. templateMode.Mode = mode
  1306. templateMode.ExecuteTimes = 0
  1307. templateMode.ModifyTime = time.Now().Unix()
  1308. updateErr := service.SavePatientScheduleTemplateMode3To1(templateMode, templateIDs[1].ID, templateIDs[2].ID)
  1309. if updateErr != nil {
  1310. this.ErrorLog("更新排班模板启用方式(1 -> 3)时失败:%v", updateErr)
  1311. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1312. return
  1313. }
  1314. } else if templateMode.Mode == 3 && mode == 2 { // 3 -> 1 清除第三周模板item,清除第三周排班,将第一周的排班重复到第二周
  1315. templateIDs, getTemplateIDsErr := service.GetOrgPatientScheduleTemplateIDs(adminUserInfo.CurrentOrgId)
  1316. if getTemplateIDsErr != nil {
  1317. this.ErrorLog("获取排班模板失败:%v", getTemplateIDsErr)
  1318. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1319. return
  1320. }
  1321. templateMode.Mode = mode
  1322. templateMode.ExecuteTimes = 0
  1323. templateMode.ModifyTime = time.Now().Unix()
  1324. updateErr := service.SavePatientScheduleTemplateMode3To2(templateMode, templateIDs[2].ID)
  1325. if updateErr != nil {
  1326. this.ErrorLog("更新排班模板启用方式(2 -> 3)时失败:%v", updateErr)
  1327. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1328. return
  1329. }
  1330. } else if templateMode.Mode == 3 && mode == 4 { // 2 -> 1 清除第二周模板item,清除第二周排班
  1331. templateMode.Mode = mode
  1332. templateMode.ExecuteTimes = 0
  1333. templateMode.ModifyTime = time.Now().Unix()
  1334. updateErr := service.SaveTemplateMode(templateMode)
  1335. if updateErr != nil {
  1336. this.ErrorLog("更新排班模板启用方式(1 -> 4)时失败:%v", updateErr)
  1337. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1338. return
  1339. }
  1340. } else if templateMode.Mode == 4 && mode == 1 { // 4 -> 1 清除第三周模板item,清除第三周排班,将第一周的排班重复到第二周
  1341. templateIDs, getTemplateIDsErr := service.GetOrgPatientScheduleTemplateIDs(adminUserInfo.CurrentOrgId)
  1342. if getTemplateIDsErr != nil {
  1343. this.ErrorLog("获取排班模板失败:%v", getTemplateIDsErr)
  1344. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1345. return
  1346. }
  1347. templateMode.Mode = mode
  1348. templateMode.ExecuteTimes = 0
  1349. templateMode.ModifyTime = time.Now().Unix()
  1350. updateErr := service.SavePatientScheduleTemplateMode4To1(templateMode, templateIDs[1].ID, templateIDs[2].ID, templateIDs[3].ID)
  1351. if updateErr != nil {
  1352. this.ErrorLog("更新排班模板启用方式(1 -> 4)时失败:%v", updateErr)
  1353. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1354. return
  1355. }
  1356. } else if templateMode.Mode == 4 && mode == 2 { // 4 -> 2
  1357. templateIDs, getTemplateIDsErr := service.GetOrgPatientScheduleTemplateIDs(adminUserInfo.CurrentOrgId)
  1358. if getTemplateIDsErr != nil {
  1359. this.ErrorLog("获取排班模板失败:%v", getTemplateIDsErr)
  1360. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1361. return
  1362. }
  1363. templateMode.Mode = mode
  1364. templateMode.ExecuteTimes = 0
  1365. templateMode.ModifyTime = time.Now().Unix()
  1366. updateErr := service.SavePatientScheduleTemplateMode4To2(templateMode, templateIDs[2].ID, templateIDs[3].ID)
  1367. if updateErr != nil {
  1368. this.ErrorLog("更新排班模板启用方式(2 -> 4)时失败:%v", updateErr)
  1369. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1370. return
  1371. }
  1372. } else if templateMode.Mode == 4 && mode == 3 { // 4 -> 3
  1373. templateIDs, getTemplateIDsErr := service.GetOrgPatientScheduleTemplateIDs(adminUserInfo.CurrentOrgId)
  1374. if getTemplateIDsErr != nil {
  1375. this.ErrorLog("获取排班模板失败:%v", getTemplateIDsErr)
  1376. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1377. return
  1378. }
  1379. templateMode.Mode = mode
  1380. templateMode.ExecuteTimes = 0
  1381. templateMode.ModifyTime = time.Now().Unix()
  1382. updateErr := service.SavePatientScheduleTemplateMode4To3(templateMode, templateIDs[3].ID)
  1383. if updateErr != nil {
  1384. this.ErrorLog("更新排班模板启用方式(3 -> 4)时失败:%v", updateErr)
  1385. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1386. return
  1387. }
  1388. }
  1389. templates, _ := service.GetOrgPatientScheduleTemplateIDs(adminUserInfo.CurrentOrgId)
  1390. //处理第几周数问题
  1391. if mode == 0 {
  1392. service.UpdateTemplateItemWeek(templates[0].OrgID, templates[0].ID, 0)
  1393. service.UpdateTemplateItemWeek(templates[1].OrgID, templates[1].ID, 0)
  1394. service.UpdateTemplateItemWeek(templates[2].OrgID, templates[2].ID, 0)
  1395. service.UpdateTemplateItemWeek(templates[3].OrgID, templates[3].ID, 0)
  1396. } else if mode == 1 {
  1397. service.UpdateTemplateItemWeek(templates[0].OrgID, templates[0].ID, week_time)
  1398. service.UpdateTemplateItemWeek(templates[1].OrgID, templates[1].ID, 0)
  1399. service.UpdateTemplateItemWeek(templates[2].OrgID, templates[2].ID, 0)
  1400. service.UpdateTemplateItemWeek(templates[3].OrgID, templates[3].ID, 0)
  1401. } else if mode == 2 {
  1402. service.UpdateTemplateItemWeek(templates[0].OrgID, templates[0].ID, week_time)
  1403. service.UpdateTemplateItemWeek(templates[1].OrgID, templates[1].ID, week_time+1)
  1404. service.UpdateTemplateItemWeek(templates[2].OrgID, templates[2].ID, 0)
  1405. service.UpdateTemplateItemWeek(templates[3].OrgID, templates[3].ID, 0)
  1406. } else if mode == 3 {
  1407. service.UpdateTemplateItemWeek(templates[0].OrgID, templates[0].ID, week_time)
  1408. service.UpdateTemplateItemWeek(templates[1].OrgID, templates[1].ID, week_time+1)
  1409. service.UpdateTemplateItemWeek(templates[2].OrgID, templates[2].ID, week_time+2)
  1410. service.UpdateTemplateItemWeek(templates[3].OrgID, templates[3].ID, 0)
  1411. } else if mode == 4 {
  1412. service.UpdateTemplateItemWeek(templates[0].OrgID, templates[0].ID, week_time)
  1413. service.UpdateTemplateItemWeek(templates[1].OrgID, templates[1].ID, week_time+1)
  1414. service.UpdateTemplateItemWeek(templates[2].OrgID, templates[2].ID, week_time+2)
  1415. service.UpdateTemplateItemWeek(templates[3].OrgID, templates[3].ID, week_time+3)
  1416. }
  1417. } else {
  1418. fmt.Println("~~~~~~~~")
  1419. service.UpdateTemplateItemModeWeek(adminUserInfo.CurrentOrgId, templateMode.ID, templateMode.OriginalWeek)
  1420. }
  1421. this.ServeSuccessJSON(nil)
  1422. }
  1423. // /api/schtemp/p/update_sch [post]
  1424. // @param template_id:int
  1425. // @param add_schs:array'json ([ {device_number_id, patient_id, mode(treat_mode), weekday, time_type} ])
  1426. // @param del_schs:array'json ([ {device_number_id, weekday, time_type} ])
  1427. // @param change_schs:array'json ([ {device_number_id, patient_id, mode(treat_mode), weekday, time_type} ])
  1428. func (this *PatientScheduleTemplateAPIController) UpdateSchedules() {
  1429. templateID, _ := this.GetInt64("template_id")
  1430. addSchedulesJSON := this.GetString("add_schs")
  1431. delSchedulesJSON := this.GetString("del_schs")
  1432. changeSchedulesJSON := this.GetString("change_schs")
  1433. var addSchedules []*ParamModelSchedule
  1434. var delSchedules []*ParamModelSchedule
  1435. var changeSchedules []*ParamModelSchedule
  1436. parseErr := json.Unmarshal([]byte(addSchedulesJSON), &addSchedules)
  1437. if parseErr != nil {
  1438. this.ErrorLog("解析增加排班的数组参数失败:%v", parseErr)
  1439. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1440. return
  1441. }
  1442. parseErr = json.Unmarshal([]byte(delSchedulesJSON), &delSchedules)
  1443. if parseErr != nil {
  1444. this.ErrorLog("解析删除排班的数组参数失败:%v", parseErr)
  1445. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1446. return
  1447. }
  1448. parseErr = json.Unmarshal([]byte(changeSchedulesJSON), &changeSchedules)
  1449. if parseErr != nil {
  1450. this.ErrorLog("解析修改排班的数组参数失败:%v", parseErr)
  1451. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1452. return
  1453. }
  1454. adminUserInfo := this.GetAdminUserInfo()
  1455. templateIDs, getTemplateIDsErr := service.GetOrgPatientScheduleTemplateIDs(adminUserInfo.CurrentOrgId)
  1456. if getTemplateIDsErr != nil {
  1457. this.ErrorLog("获取排班模板失败:%v", getTemplateIDsErr)
  1458. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1459. return
  1460. } else {
  1461. isTemplateIDExist := false
  1462. for _, templateIDObject := range templateIDs {
  1463. if templateIDObject.ID == templateID {
  1464. isTemplateIDExist = true
  1465. break
  1466. }
  1467. }
  1468. if isTemplateIDExist == false {
  1469. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleTemplateNotExist)
  1470. return
  1471. }
  1472. }
  1473. addTemplateItems := make([]*models.PatientScheduleTemplateItem, 0, len(addSchedules))
  1474. delTemplateItems := make([]*models.PatientScheduleTemplateItem, 0, len(delSchedules))
  1475. changeTemplateItems := make([]*models.PatientScheduleTemplateItem, 0, len(changeSchedules))
  1476. for _, sch := range addSchedules {
  1477. if sch.DeviceNumberID <= 0 || sch.PatientID <= 0 || sch.Weekday < 1 || sch.Weekday > 7 || sch.TimeType < 1 || sch.TimeType > 3 {
  1478. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1479. return
  1480. }
  1481. addTemplateItems = append(addTemplateItems, &models.PatientScheduleTemplateItem{
  1482. DeviceNumberID: sch.DeviceNumberID,
  1483. PatientID: sch.PatientID,
  1484. TreatMode: sch.Mode,
  1485. Weekday: sch.Weekday,
  1486. TimeType: sch.TimeType,
  1487. })
  1488. }
  1489. for _, sch := range delSchedules {
  1490. if sch.DeviceNumberID <= 0 || sch.Weekday < 1 || sch.Weekday > 7 || sch.TimeType < 1 || sch.TimeType > 3 {
  1491. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1492. return
  1493. }
  1494. delTemplateItems = append(delTemplateItems, &models.PatientScheduleTemplateItem{
  1495. DeviceNumberID: sch.DeviceNumberID,
  1496. Weekday: sch.Weekday,
  1497. TimeType: sch.TimeType,
  1498. })
  1499. }
  1500. for _, sch := range changeSchedules {
  1501. if sch.DeviceNumberID <= 0 || sch.PatientID <= 0 || sch.Weekday < 1 || sch.Weekday > 7 || sch.TimeType < 1 || sch.TimeType > 3 {
  1502. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1503. return
  1504. }
  1505. changeTemplateItems = append(changeTemplateItems, &models.PatientScheduleTemplateItem{
  1506. DeviceNumberID: sch.DeviceNumberID,
  1507. PatientID: sch.PatientID,
  1508. TreatMode: sch.Mode,
  1509. Weekday: sch.Weekday,
  1510. TimeType: sch.TimeType,
  1511. })
  1512. }
  1513. templateMode, getTemplateModeErr := service.GetOrgPatientScheduleTemplateMode(adminUserInfo.CurrentOrgId)
  1514. if getTemplateModeErr != nil {
  1515. this.ErrorLog("获取排班模板启用模式失败:%v", getTemplateModeErr)
  1516. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1517. return
  1518. } else if templateMode == nil {
  1519. this.ErrorLog("获取不到排班模板启用模式")
  1520. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1521. return
  1522. }
  1523. //shouldUpdateNextWeekSchedules := false
  1524. //shouldUpdateNextSecondWeekSchedules := false
  1525. //shouldUpdateNextThirdWeekSchedules := false
  1526. //shouldUpdateNextFourWeekSchedules := false
  1527. //
  1528. if templateMode.Mode == 0 {
  1529. this.ErrorLog("当前未开启排班模板,所以更新模板的操作将被无视")
  1530. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1531. return
  1532. }
  1533. //判断当前用的是模版几
  1534. //templateIDIndex := 1
  1535. //for index, templateIDObject := range templateIDs {
  1536. // if templateIDObject.ID == templateID {
  1537. // //templateIDIndex = index + 1
  1538. // }
  1539. //}
  1540. //if templateMode.Mode == 1 {
  1541. // if templateIDIndex == 1 {
  1542. // shouldUpdateNextWeekSchedules = true
  1543. // shouldUpdateNextSecondWeekSchedules = true
  1544. // } else {
  1545. // this.ErrorLog("当前开启的是单周模板,所以不会更新第二个模板")
  1546. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1547. // return
  1548. // }
  1549. //
  1550. //} else if templateMode.Mode == 2 { // mode == 2 => 开启双周模板时,只需更新一周排班
  1551. // if templateIDIndex == 1 {
  1552. // if templateMode.ExecuteTimes%2 == 0 {
  1553. // shouldUpdateNextWeekSchedules = true
  1554. // shouldUpdateNextSecondWeekSchedules = false
  1555. // } else {
  1556. // shouldUpdateNextWeekSchedules = false
  1557. // shouldUpdateNextSecondWeekSchedules = true
  1558. // }
  1559. //
  1560. // } else {
  1561. // if templateMode.ExecuteTimes%2 == 0 {
  1562. // shouldUpdateNextWeekSchedules = false
  1563. // shouldUpdateNextSecondWeekSchedules = true
  1564. // } else {
  1565. // shouldUpdateNextWeekSchedules = true
  1566. // shouldUpdateNextSecondWeekSchedules = false
  1567. // }
  1568. //
  1569. // }
  1570. //} else if templateMode.Mode == 3 { // mode == 2 => 开启双周模板时,只需更新一周排班
  1571. // if templateIDIndex == 1 { //当前修改的是第一个模版
  1572. // if templateMode.ExecuteTimes%3 == 0 {
  1573. // shouldUpdateNextWeekSchedules = true
  1574. // shouldUpdateNextSecondWeekSchedules = false
  1575. // shouldUpdateNextThirdWeekSchedules = false
  1576. // } else if templateMode.ExecuteTimes%3 == 1 {
  1577. // shouldUpdateNextWeekSchedules = false
  1578. // shouldUpdateNextSecondWeekSchedules = true
  1579. // shouldUpdateNextThirdWeekSchedules = false
  1580. // } else {
  1581. // shouldUpdateNextWeekSchedules = false
  1582. // shouldUpdateNextSecondWeekSchedules = false
  1583. // shouldUpdateNextThirdWeekSchedules = true
  1584. // }
  1585. // } else if templateIDIndex == 2 {
  1586. // if templateMode.ExecuteTimes%2 == 0 {
  1587. // shouldUpdateNextWeekSchedules = false
  1588. // shouldUpdateNextSecondWeekSchedules = true
  1589. // } else {
  1590. // shouldUpdateNextWeekSchedules = true
  1591. // shouldUpdateNextSecondWeekSchedules = false
  1592. // }
  1593. //
  1594. // } else {
  1595. //
  1596. // }
  1597. //}
  1598. updateErr := service.UpdateScheduleTemplate(adminUserInfo.CurrentOrgId, templateID, addTemplateItems, delTemplateItems, changeTemplateItems, false, false)
  1599. if updateErr != nil {
  1600. this.ErrorLog("更新排班模板排班失败:%v", updateErr)
  1601. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1602. return
  1603. }
  1604. templates, getTemplateItemsErr := service.GetOrgPatientScheduleTemplateItems(adminUserInfo.CurrentOrgId)
  1605. if getTemplateItemsErr != nil {
  1606. this.ErrorLog("获取排班模板排班失败:%v", getTemplateItemsErr)
  1607. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1608. return
  1609. }
  1610. this.ServeSuccessJSON(map[string]interface{}{
  1611. "items": templates,
  1612. })
  1613. }
  1614. func WeekIntervalTime(week int) []string {
  1615. now := time.Now()
  1616. offset := int(time.Monday - now.Weekday())
  1617. //周日做特殊判断 因为time.Monday = 0
  1618. if offset > 0 {
  1619. offset = -6
  1620. }
  1621. var timeArr []string
  1622. year, month, day := now.Date()
  1623. thisWeek := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1624. startTime := thisWeek.AddDate(0, 0, offset+7*week).Format("2006-01-02") + " 00:00:00"
  1625. twoTime := thisWeek.AddDate(0, 0, offset+1+7*week).Format("2006-01-02") + " 00:00:00"
  1626. threeTime := thisWeek.AddDate(0, 0, offset+2+7*week).Format("2006-01-02") + " 00:00:00"
  1627. fourTime := thisWeek.AddDate(0, 0, offset+3+7*week).Format("2006-01-02") + " 00:00:00"
  1628. fiveTime := thisWeek.AddDate(0, 0, offset+4+7*week).Format("2006-01-02") + " 00:00:00"
  1629. SixTime := thisWeek.AddDate(0, 0, offset+5+7*week).Format("2006-01-02") + " 00:00:00"
  1630. endTime := thisWeek.AddDate(0, 0, offset+6+7*week).Format("2006-01-02") + " 00:00:00"
  1631. timeArr = append(timeArr, startTime)
  1632. timeArr = append(timeArr, twoTime)
  1633. timeArr = append(timeArr, threeTime)
  1634. timeArr = append(timeArr, fourTime)
  1635. timeArr = append(timeArr, fiveTime)
  1636. timeArr = append(timeArr, SixTime)
  1637. timeArr = append(timeArr, endTime)
  1638. return timeArr
  1639. }
  1640. type ParamModelSchedule struct {
  1641. DeviceNumberID int64 `json:"device_number_id"`
  1642. PatientID int64 `json:"patient_id"`
  1643. Mode int64 `json:"mode"`
  1644. Weekday int8 `json:"weekday"`
  1645. TimeType int8 `json:"time_type"`
  1646. }
  1647. func (this *PatientScheduleTemplateAPIController) GetPatientList() {
  1648. patients, err := service.GetSchTemplatePatientList(this.GetAdminUserInfo().CurrentOrgId)
  1649. if err != nil {
  1650. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1651. }
  1652. this.ServeSuccessJSON(map[string]interface{}{
  1653. "list": patients,
  1654. })
  1655. }
  1656. type ParamModelEditSchedule struct {
  1657. ID int64 `json:"sch_id"`
  1658. DeviceNumberID int64 `json:"jihao_id"`
  1659. PatientID int64 `json:"patient_id"`
  1660. Mode int64 `json:"mode_id"`
  1661. Weekday int64 `json:"schedule_week"`
  1662. TimeType int64 `json:"time_type"`
  1663. TemplateID int64 `json:"t_id"`
  1664. Title string `json:"title"`
  1665. }
  1666. func (this *PatientScheduleTemplateAPIController) UpdateSchedulesTemplate() {
  1667. addOrEditSchedulesJSON := this.GetString("edit_schs")
  1668. delSchedulesJSON := this.GetString("del_schs")
  1669. fmt.Println(addOrEditSchedulesJSON)
  1670. var addOrEditSchedules []*ParamModelEditSchedule
  1671. var delSchedules []*ParamModelEditSchedule
  1672. parseErr := json.Unmarshal([]byte(addOrEditSchedulesJSON), &addOrEditSchedules)
  1673. json.Unmarshal([]byte(delSchedulesJSON), &delSchedules)
  1674. fmt.Println(parseErr)
  1675. if parseErr != nil {
  1676. this.ErrorLog("解析增加编辑排班的数组参数失败:%v", parseErr)
  1677. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1678. return
  1679. }
  1680. //if parseDelErr != nil {
  1681. // this.ErrorLog("解析删除排班的数组参数失败:%v", parseErr)
  1682. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1683. // return
  1684. //}
  1685. for _, item := range delSchedules {
  1686. src_template, _ := service.GetScheduleTemplateItem(item.ID)
  1687. src_template.Status = 0
  1688. service.SaveSchTemplateItem(src_template)
  1689. }
  1690. for _, item := range addOrEditSchedules {
  1691. if item.ID > 0 { //已经存在的数据
  1692. src_template, _ := service.GetScheduleTemplateItem(item.ID)
  1693. src_template.DeviceNumberID = item.DeviceNumberID
  1694. src_template.TimeType = int8(item.TimeType)
  1695. src_template.TreatMode = item.Mode
  1696. schItem, _ := service.GetScheduleTemplateThree(this.GetAdminUserInfo().CurrentOrgId, src_template.DeviceNumberID, src_template.TemplateID, int64(src_template.Weekday), int64(src_template.TimeType), src_template.PatientID)
  1697. if schItem.ID > 0 {
  1698. json := make(map[string]interface{})
  1699. json["msg"] = item.Title + "周" + strconv.FormatInt(item.Weekday, 10) + "的床位已经有人排班无法保存,可能存在重复排班"
  1700. json["state"] = 0
  1701. this.Data["json"] = json
  1702. this.ServeJSON()
  1703. break
  1704. }
  1705. service.SaveSchTemplateItem(src_template)
  1706. } else {
  1707. schItemTwo, _ := service.GetScheduleTemplateTwo(this.GetAdminUserInfo().CurrentOrgId, item.TemplateID, item.Weekday, item.PatientID)
  1708. fmt.Println("222222")
  1709. if schItemTwo.ID > 0 { //当天存在排班,存在则为修改
  1710. fmt.Println("333333333")
  1711. src_template, _ := service.GetScheduleTemplateItem(schItemTwo.ID)
  1712. src_template.DeviceNumberID = item.DeviceNumberID
  1713. src_template.TimeType = int8(item.TimeType)
  1714. src_template.TreatMode = item.Mode
  1715. service.SaveSchTemplateItem(src_template)
  1716. } else {
  1717. schItem, _ := service.GetScheduleTemplateOne(this.GetAdminUserInfo().CurrentOrgId, item.DeviceNumberID, item.TemplateID, item.Weekday, item.TimeType)
  1718. if schItem.ID == 0 { //床位未被占用
  1719. var template models.PatientScheduleTemplateItem
  1720. template.TreatMode = item.Mode
  1721. template.TemplateID = int64(item.TemplateID)
  1722. template.TimeType = int8(item.TimeType)
  1723. template.DeviceNumberID = item.DeviceNumberID
  1724. template.CreateTime = time.Now().Unix()
  1725. template.ModifyTime = time.Now().Unix()
  1726. template.OrgID = this.GetAdminUserInfo().CurrentOrgId
  1727. template.PatientID = item.PatientID
  1728. template.Weekday = int8(item.Weekday)
  1729. template.Status = 1
  1730. service.SaveSchTemplateItem(template)
  1731. } else { //床位被占用 1.被自己占用,2。被别人占用
  1732. if schItem.PatientID != 0 && schItem.PatientID == item.PatientID { //当天该患者已经存在排班则设为修改操作
  1733. src_template, _ := service.GetScheduleTemplateItem(schItem.ID)
  1734. src_template.DeviceNumberID = item.DeviceNumberID
  1735. src_template.TimeType = int8(item.TimeType)
  1736. src_template.TreatMode = item.Mode
  1737. service.SaveSchTemplateItem(src_template)
  1738. } else if schItem.PatientID != 0 && schItem.PatientID != item.PatientID { //当天该床位被其他人占用,则无法保存
  1739. //fmt.Println("7777777")
  1740. json := make(map[string]interface{})
  1741. json["msg"] = item.Title + "周" + strconv.FormatInt(item.Weekday, 10) + "的床位已经有人排班,无法保存"
  1742. json["state"] = 0
  1743. this.Data["json"] = json
  1744. this.ServeJSON()
  1745. break
  1746. }
  1747. }
  1748. }
  1749. }
  1750. }
  1751. templates, _ := service.GetOrgPatientScheduleTemplateItems(this.GetAdminUserInfo().CurrentOrgId)
  1752. this.ServeSuccessJSON(map[string]interface{}{
  1753. "items": templates,
  1754. })
  1755. }
  1756. //func (c *ScheduleApiController) DeleteScheduleTemplateTwo() {
  1757. // id, _ := c.GetInt64("id", 0)
  1758. // if id <= 0 {
  1759. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1760. // return
  1761. // }
  1762. //
  1763. // adminINfo := c.GetAdminUserInfo()
  1764. //
  1765. // schedule, _ := service.GetSc(adminINfo.CurrentOrgId, id)
  1766. // timeNow := time.Now().Format("2006-01-02")
  1767. // timeTemplate := "2006-01-02"
  1768. //
  1769. // tm := time.Unix(int64(schedule.ScheduleDate), 0)
  1770. // timeStr := tm.Format(timeTemplate)
  1771. // if timeNow > timeStr {
  1772. //
  1773. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleBeforeNow)
  1774. // return
  1775. // }
  1776. // if schedule == nil {
  1777. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist)
  1778. // return
  1779. // }
  1780. //
  1781. // order, err := service.GetOneDialysisOrder(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
  1782. // if err != nil {
  1783. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1784. // return
  1785. // }
  1786. //
  1787. // if order != nil {
  1788. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDelScheduleFailByDialysisTwo)
  1789. // return
  1790. // }
  1791. //
  1792. // schedule.Status = 0
  1793. // schedule.UpdatedTime = time.Now().Unix()
  1794. // err = service.UpdateSchedule(schedule)
  1795. // redis := service.RedisClient()
  1796. //
  1797. // //处方
  1798. // keyOne := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":prescriptions_list_all"
  1799. // redis.Set(keyOne, "", time.Second)
  1800. //
  1801. // //医嘱
  1802. // keyTwo := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":advice_list_all"
  1803. // redis.Set(keyTwo, "", time.Second)
  1804. //
  1805. // keySix := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_befores_list_all"
  1806. // redis.Set(keySix, "", time.Second)
  1807. // keyThree := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_after_dislysis_list_all"
  1808. // redis.Set(keyThree, "", time.Second)
  1809. //
  1810. // keyFour := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":monitor_record_list_all"
  1811. // redis.Set(keyFour, "", time.Second)
  1812. //
  1813. // keyFive := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":treatment_summarys_list_all"
  1814. // redis.Set(keyFive, "", time.Second)
  1815. //
  1816. // keySeven := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":dialysis_orders_list_all"
  1817. // redis.Set(keySeven, "", time.Second)
  1818. // fmt.Println(err)
  1819. // defer redis.Close()
  1820. // if err != nil {
  1821. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteScheduleFail)
  1822. // return
  1823. // }
  1824. //
  1825. // c.ServeSuccessJSON(map[string]interface{}{
  1826. // "msg": "ok",
  1827. // "schedule": &schedule,
  1828. // })
  1829. //}