schedule_api_controller.go 90KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/jinzhu/gorm"
  10. "reflect"
  11. "strconv"
  12. "strings"
  13. "time"
  14. "github.com/astaxie/beego"
  15. )
  16. type ScheduleApiController struct {
  17. BaseAuthAPIController
  18. }
  19. func ScheduleApiRegistRouters() {
  20. beego.Router("/api/schedule/weekpanel", &ScheduleApiController{}, "Get:GetWeekPanels")
  21. beego.Router("/api/schedule/schedules", &ScheduleApiController{}, "Get:GetSchedules")
  22. beego.Router("/api/excel_date/init", &ScheduleApiController{}, "Get:GetInitExcelInitDate")
  23. beego.Router("/api/schedule/patients", &ScheduleApiController{}, "Get:GetPatients")
  24. beego.Router("/api/schedule/create", &ScheduleApiController{}, "Post:CreateSchedule")
  25. beego.Router("/api/schedule/delete", &ScheduleApiController{}, "Delete:DeleteSchedule")
  26. beego.Router("/api/schedule/change", &ScheduleApiController{}, "Put:ChangeSchedule")
  27. beego.Router("/api/schedule/urgentinit", &ScheduleApiController{}, "Get:UrgentScheduleData")
  28. beego.Router("/api/schedule/print/initdata", &ScheduleApiController{}, "get:PrintInitData")
  29. beego.Router("/api/schedule/search", &ScheduleApiController{}, "get:SearchSchedulePatients")
  30. beego.Router("/api/schedule/week", &ScheduleApiController{}, "get:GetWeekDaySchedule")
  31. beego.Router("/api/schedule/export", &ScheduleApiController{}, "post:ExportSchedule")
  32. beego.Router("/api/schedule_template/export", &ScheduleApiController{}, "post:ExportScheduleTemplate")
  33. beego.Router("/api/schedule_template/search", &ScheduleApiController{}, "get:SearchTemplateSchedulePatients")
  34. beego.Router("/api/schedule_template/cancel", &ScheduleApiController{}, "post:CancelScheduleTemplate")
  35. beego.Router("/api/schedule/getnextscheduleweekday", &ScheduleApiController{}, "Get:GetNextWeekDaySchedule")
  36. beego.Router("/api/schedule/getthreeweeklist", &ScheduleApiController{}, "Get:GetThreeWeekList")
  37. beego.Router("/api/schedule/getallzones", &ScheduleApiController{}, "Get:GetAllZones")
  38. beego.Router("/api/schedule/copypatientschedules", &ScheduleApiController{}, "Get:GetCopyPatientSchedules")
  39. beego.Router("/api/schedule/saveremindprint", &ScheduleApiController{}, "Get:SaveRemindPrint")
  40. beego.Router("/api/schedule/getremindprintlist", &ScheduleApiController{}, "Get:GetRemindPrintList")
  41. beego.Router("/api/schedule/getbloodschedulelist", &ScheduleApiController{}, "Get:GetBloodScheduleList")
  42. beego.Router("/api/schedule/getprintlist", &ScheduleApiController{}, "Get:GetPrintList")
  43. beego.Router("/api/schedule/getallzonelist", &ScheduleApiController{}, "Get:GetAllZoneList")
  44. beego.Router("/api/schedule/getpatientschedulecount", &ScheduleApiController{}, "Get:GetPatientScheduleCount")
  45. beego.Router("/api/schedule/weekpanelone", &ScheduleApiController{}, "Get:GetWeekPanelsOne")
  46. beego.Router("/api/schedule/schedulesone", &ScheduleApiController{}, "Get:GetScheduleOne")
  47. beego.Router("/api/schedule/postscheduletemplate", &ScheduleApiController{}, "Get:SaveScheduleTemplate")
  48. beego.Router("/api/schedule/getscheduletemplate", &ScheduleApiController{}, "Get:GetScheduleTemplate")
  49. beego.Router("/api/order/changefuncprint", &ScheduleApiController{}, "Get:ChangeFuncPrint")
  50. beego.Router("/api/order/getdataprint", &ScheduleApiController{}, "Get:GetDataPrint")
  51. beego.Router("/api/schedule/getnextweekpanels", &ScheduleApiController{}, "Get:GetNextWeekPanels")
  52. beego.Router("/api/schedule/synchroschedule", &ScheduleApiController{}, "Get:SynchroSchedule")
  53. beego.Router("/api/schedule/getpatientscheduletemplate", &ScheduleApiController{}, "Get:GetPatientScheduleTempalate")
  54. beego.Router("/api/schedule/getsolutionschedule", &ScheduleApiController{}, "Get:GetSolutionSchedule")
  55. }
  56. func (c *ScheduleApiController) GetWeekPanels() {
  57. data, _ := c.GetInt64("data", 1)
  58. patitionId, _ := c.GetInt64("patitionid")
  59. adminInfo := c.GetAdminUserInfo()
  60. thisTime := time.Now()
  61. year, monthTime, day := thisTime.Date()
  62. month := int(monthTime)
  63. _, theWeek := thisTime.ISOWeek()
  64. weekDay := int(thisTime.Weekday())
  65. if weekDay == 0 {
  66. weekDay = 7
  67. }
  68. weekEnd := 7 - weekDay
  69. weekStart := weekEnd - 6
  70. weekDays := make([]string, 0)
  71. for index := weekStart; index <= weekEnd; index++ {
  72. theDay := thisTime.AddDate(0, 0, index)
  73. indexYear, indexMonthTime, indexDay := theDay.Date()
  74. indexMonth := int(indexMonthTime)
  75. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  76. weekDays = append(weekDays, indexWeek)
  77. }
  78. returnData := map[string]interface{}{
  79. "year": year,
  80. "month": month,
  81. "day": day,
  82. "theWeek": theWeek,
  83. "weekDay": weekDay,
  84. "weekDays": weekDays,
  85. }
  86. if data == 1 {
  87. partitions, _ := service.GetSchedulePartitionPanelOne(adminInfo.CurrentOrgId, patitionId)
  88. returnData["partitions"] = partitions
  89. }
  90. c.ServeSuccessJSON(returnData)
  91. return
  92. }
  93. func (c *ScheduleApiController) GetSchedules() {
  94. week, _ := c.GetInt64("weekTime", 0) //1:last, 2:this 3:next 4 nextTwo
  95. partition_id, _ := c.GetInt64("partition_id")
  96. schedule_type, _ := c.GetInt64("schedule_type")
  97. adminInfo := c.GetAdminUserInfo()
  98. thisTime := time.Now()
  99. today := thisTime.Format("2006-01-02")
  100. if week < 1 || week > 4 {
  101. week = 2
  102. }
  103. if week == 1 {
  104. thisTime = thisTime.AddDate(0, 0, -7)
  105. } else if week == 3 {
  106. thisTime = thisTime.AddDate(0, 0, 7)
  107. } else if week == 4 {
  108. thisTime = thisTime.AddDate(0, 0, 14)
  109. }
  110. weekDay := int(thisTime.Weekday())
  111. if weekDay == 0 {
  112. weekDay = 7
  113. }
  114. weekEnd := 7 - weekDay
  115. weekStart := weekEnd - 6
  116. weekTitle := make([]string, 0)
  117. days := make([]string, 0)
  118. for index := weekStart; index <= weekEnd; index++ {
  119. theDay := thisTime.AddDate(0, 0, index)
  120. indexYear, indexMonthTime, indexDay := theDay.Date()
  121. indexMonth := int(indexMonthTime)
  122. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  123. weekTitle = append(weekTitle, indexWeek)
  124. days = append(days, theDay.Format("2006-01-02"))
  125. }
  126. weekStartDay := thisTime.AddDate(0, 0, weekStart)
  127. weekEndDay := thisTime.AddDate(0, 0, weekEnd)
  128. weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
  129. weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
  130. timeLayout := "2006-01-02 15:04:05"
  131. loc, _ := time.LoadLocation("Local")
  132. theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
  133. theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
  134. weekStartPoint := theStarTime.Unix()
  135. weekEndPoint := theEndTime.Unix()
  136. schdules, _ := service.GetWeekScheduleOne(adminInfo.CurrentOrgId, weekStartPoint, weekEndPoint, partition_id, schedule_type)
  137. c.ServeSuccessJSON(map[string]interface{}{
  138. "days": days,
  139. "weekTitle": weekTitle,
  140. "schdules": schdules,
  141. "today": today,
  142. })
  143. return
  144. }
  145. func (c *ScheduleApiController) GetPatients() {
  146. keywords := c.GetString("keywords", "")
  147. schedule, _ := c.GetInt64("schedule", 0) //1已2未
  148. contagion, _ := c.GetInt64("contagion", 0)
  149. adminInfo := c.GetAdminUserInfo()
  150. thisTime := time.Now()
  151. weekDay := int(thisTime.Weekday())
  152. if weekDay == 0 {
  153. weekDay = 7
  154. }
  155. thisWeekEnd := 7 - weekDay
  156. weekStartPoint := thisWeekEnd - 6
  157. weekStartDay := thisTime.AddDate(0, 0, weekStartPoint)
  158. weekEndPoint := thisWeekEnd + 7
  159. weekEndDay := thisTime.AddDate(0, 0, weekEndPoint)
  160. fmt.Println(weekStartPoint, weekStartDay, weekEndPoint, weekEndDay)
  161. weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
  162. weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
  163. fmt.Println(weekStartTime, weekEndTime)
  164. timeLayout := "2006-01-02 15:04:05"
  165. loc, _ := time.LoadLocation("Local")
  166. theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
  167. theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
  168. weekStart := theStarTime.Unix()
  169. weekEnd := theEndTime.Unix()
  170. patients, _ := service.GetPatientWithScheduleAndSolution(adminInfo.CurrentOrgId, keywords, weekStart, weekEnd, schedule, contagion)
  171. c.ServeSuccessJSON(map[string]interface{}{
  172. "patients": patients,
  173. })
  174. return
  175. }
  176. func (c *ScheduleApiController) CreateSchedule() {
  177. patientID, _ := c.GetInt64("patient_id", 0)
  178. if patientID <= 0 {
  179. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  180. return
  181. }
  182. adminUserInfo := c.GetAdminUserInfo()
  183. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patientID)
  184. if patientInfo.ID == 0 {
  185. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  186. return
  187. }
  188. var schedule models.Schedule
  189. dataBody := make(map[string]interface{}, 0)
  190. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  191. if err != nil {
  192. utils.ErrorLog(err.Error())
  193. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  194. return
  195. }
  196. if dataBody["schedule_date"] == nil || reflect.TypeOf(dataBody["schedule_date"]).String() != "string" {
  197. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  198. return
  199. }
  200. scheduleDate, _ := dataBody["schedule_date"].(string)
  201. if len(scheduleDate) == 0 {
  202. utils.ErrorLog("len(schedule_date) == 0")
  203. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  204. return
  205. }
  206. timeLayout := "2006-01-02"
  207. loc, _ := time.LoadLocation("Local")
  208. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", scheduleDate+" 00:00:00", loc)
  209. if err != nil {
  210. utils.ErrorLog(err.Error())
  211. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  212. return
  213. }
  214. schedule.ScheduleDate = theTime.Unix()
  215. timeNow := time.Now().Format("2006-01-02")
  216. if timeNow > scheduleDate {
  217. utils.ErrorLog(timeNow)
  218. utils.ErrorLog(scheduleDate)
  219. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleBeforeNow)
  220. return
  221. }
  222. if dataBody["schedule_type"] == nil || reflect.TypeOf(dataBody["schedule_type"]).String() != "float64" {
  223. utils.ErrorLog("schedule_type")
  224. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  225. return
  226. }
  227. scheduleType := int64(dataBody["schedule_type"].(float64))
  228. if scheduleType < 1 || scheduleType > 3 {
  229. utils.ErrorLog("scheduleType < 3")
  230. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  231. return
  232. }
  233. schedule.ScheduleType = scheduleType
  234. if dataBody["bed_id"] == nil || reflect.TypeOf(dataBody["bed_id"]).String() != "float64" {
  235. utils.ErrorLog("bed_id")
  236. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  237. return
  238. }
  239. bedId := int64(dataBody["bed_id"].(float64))
  240. if bedId < 1 {
  241. utils.ErrorLog("bedId < 1")
  242. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  243. return
  244. }
  245. schedule.BedId = bedId
  246. if dataBody["partition_id"] == nil || reflect.TypeOf(dataBody["partition_id"]).String() != "float64" {
  247. utils.ErrorLog("partition_id")
  248. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  249. return
  250. }
  251. partitionId := int64(dataBody["partition_id"].(float64))
  252. if partitionId < 1 {
  253. utils.ErrorLog("partitionId < 1")
  254. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  255. return
  256. }
  257. schedule.PartitionId = partitionId
  258. if dataBody["schedule_week"] == nil || reflect.TypeOf(dataBody["schedule_week"]).String() != "float64" {
  259. utils.ErrorLog("schedule_week")
  260. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  261. return
  262. }
  263. scheduleWeek := int64(dataBody["schedule_week"].(float64))
  264. if scheduleWeek < 1 || scheduleWeek > 7 {
  265. utils.ErrorLog("scheduleWeek < 1")
  266. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  267. return
  268. }
  269. schedule.ScheduleWeek = scheduleWeek
  270. if dataBody["mode_id"] == nil || reflect.TypeOf(dataBody["mode_id"]).String() != "float64" {
  271. utils.ErrorLog("mode_id")
  272. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  273. return
  274. }
  275. modeId := int64(dataBody["mode_id"].(float64))
  276. if modeId < 1 && modeId > 14 {
  277. utils.ErrorLog("modeId < 1")
  278. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  279. return
  280. }
  281. schedule.ModeId = modeId
  282. schedule.PatientId = patientID
  283. schedule.CreatedTime = time.Now().Unix()
  284. schedule.UpdatedTime = time.Now().Unix()
  285. schedule.Status = 1
  286. schedule.UserOrgId = adminUserInfo.CurrentOrgId
  287. bed, _ := service.GetDeviceNumberByID(adminUserInfo.CurrentOrgId, schedule.BedId)
  288. if bed == nil {
  289. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotExist)
  290. return
  291. }
  292. if bed.ZoneID != schedule.PartitionId {
  293. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotTheZone)
  294. return
  295. }
  296. scheduleDateStart := scheduleDate + " 00:00:00"
  297. scheduleDateEnd := scheduleDate + " 23:59:59"
  298. timeLayout = "2006-01-02 15:04:05"
  299. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  300. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  301. startTime := theStartTime.Unix()
  302. endTime := theEndTime.Unix()
  303. //一天只有排班一次
  304. daySchedule, err := service.GetDaySchedule(adminUserInfo.CurrentOrgId, startTime, endTime, patientID)
  305. if daySchedule.ID > 0 {
  306. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleAgainOneDay)
  307. return
  308. }
  309. //同天同位置只能排一个
  310. pointSchedule, err := service.GetPointSchedule(adminUserInfo.CurrentOrgId, schedule.ScheduleDate, schedule.ScheduleWeek, schedule.ScheduleType, schedule.BedId)
  311. if err != nil {
  312. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  313. return
  314. }
  315. if pointSchedule.ID > 0 {
  316. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePointScheduleExist)
  317. return
  318. }
  319. redis := service.RedisClient()
  320. err = service.CreateSchedule(&schedule)
  321. key := "scheduals_" + scheduleDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  322. redis.Set(key, "", time.Second)
  323. //处方
  324. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":prescriptions_list_all"
  325. redis.Set(keyOne, "", time.Second)
  326. //医嘱
  327. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":advice_list_all"
  328. redis.Set(keyTwo, "", time.Second)
  329. keySix := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_befores_list_all"
  330. redis.Set(keySix, "", time.Second)
  331. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_after_dislysis_list_all"
  332. redis.Set(keyThree, "", time.Second)
  333. keyFour := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":monitor_record_list_all"
  334. redis.Set(keyFour, "", time.Second)
  335. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":treatment_summarys_list_all"
  336. redis.Set(keyFive, "", time.Second)
  337. keySeven := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":dialysis_orders_list_all"
  338. redis.Set(keySeven, "", time.Second)
  339. fmt.Println(err)
  340. defer redis.Close()
  341. if err != nil {
  342. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateScheduleFail)
  343. return
  344. }
  345. schedule.Patient = patientInfo.Name
  346. c.ServeSuccessJSON(map[string]interface{}{
  347. "msg": "ok",
  348. "schedule": schedule,
  349. })
  350. return
  351. }
  352. func (c *ScheduleApiController) DeleteSchedule() {
  353. id, _ := c.GetInt64("id", 0)
  354. if id <= 0 {
  355. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  356. return
  357. }
  358. adminINfo := c.GetAdminUserInfo()
  359. schedule, _ := service.GetSchedule(adminINfo.CurrentOrgId, id)
  360. if schedule == nil {
  361. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist)
  362. return
  363. }
  364. order, err := service.GetOneDialysisOrder(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
  365. if err != nil {
  366. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  367. return
  368. }
  369. if order != nil {
  370. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDelScheduleFailByDialysis)
  371. return
  372. }
  373. schedule.Status = 0
  374. schedule.UpdatedTime = time.Now().Unix()
  375. err = service.UpdateSchedule(schedule)
  376. redis := service.RedisClient()
  377. //处方
  378. keyOne := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":prescriptions_list_all"
  379. redis.Set(keyOne, "", time.Second)
  380. //医嘱
  381. keyTwo := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":advice_list_all"
  382. redis.Set(keyTwo, "", time.Second)
  383. keySix := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_befores_list_all"
  384. redis.Set(keySix, "", time.Second)
  385. keyThree := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_after_dislysis_list_all"
  386. redis.Set(keyThree, "", time.Second)
  387. keyFour := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":monitor_record_list_all"
  388. redis.Set(keyFour, "", time.Second)
  389. keyFive := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":treatment_summarys_list_all"
  390. redis.Set(keyFive, "", time.Second)
  391. keySeven := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":dialysis_orders_list_all"
  392. redis.Set(keySeven, "", time.Second)
  393. fmt.Println(err)
  394. defer redis.Close()
  395. if err != nil {
  396. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteScheduleFail)
  397. return
  398. }
  399. c.ServeSuccessJSON(map[string]interface{}{
  400. "msg": "ok",
  401. "schedule": &schedule,
  402. })
  403. }
  404. func (c *ScheduleApiController) ChangeSchedule() {
  405. id, _ := c.GetInt64("id", 0)
  406. if id <= 0 {
  407. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  408. return
  409. }
  410. adminINfo := c.GetAdminUserInfo()
  411. schedule, _ := service.GetSchedule(adminINfo.CurrentOrgId, id)
  412. if schedule == nil {
  413. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist)
  414. return
  415. }
  416. dataBody := make(map[string]interface{}, 0)
  417. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  418. if err != nil {
  419. utils.ErrorLog(err.Error())
  420. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  421. return
  422. }
  423. if dataBody["change_action"] == nil || reflect.TypeOf(dataBody["change_action"]).String() != "string" {
  424. utils.ErrorLog("change_action")
  425. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  426. return
  427. }
  428. changeAction := dataBody["change_action"].(string)
  429. if changeAction == "change_mode" {
  430. if dataBody["mode_id"] == nil || reflect.TypeOf(dataBody["mode_id"]).String() != "float64" {
  431. utils.ErrorLog("mode_id")
  432. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  433. return
  434. }
  435. modeId := int64(dataBody["mode_id"].(float64))
  436. if modeId < 1 {
  437. utils.ErrorLog("modeId < 1")
  438. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  439. return
  440. }
  441. schedule.ModeId = modeId
  442. order, err := service.GetOneDialysisOrder(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
  443. if err != nil {
  444. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  445. return
  446. }
  447. if order != nil {
  448. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeMode)
  449. return
  450. }
  451. } else if changeAction == "change_device" {
  452. order, err := service.GetOneDialysisOrder(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
  453. if err != nil {
  454. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  455. return
  456. }
  457. if order != nil {
  458. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeDeviceNumber)
  459. return
  460. }
  461. if dataBody["schedule_type"] == nil || reflect.TypeOf(dataBody["schedule_type"]).String() != "float64" {
  462. utils.ErrorLog("schedule_type")
  463. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  464. return
  465. }
  466. scheduleType := int64(dataBody["schedule_type"].(float64))
  467. if scheduleType < 1 || scheduleType > 3 {
  468. utils.ErrorLog("scheduleType < 3")
  469. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  470. return
  471. }
  472. schedule.ScheduleType = scheduleType
  473. if dataBody["bed_id"] == nil || reflect.TypeOf(dataBody["bed_id"]).String() != "float64" {
  474. utils.ErrorLog("bed_id")
  475. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  476. return
  477. }
  478. bedId := int64(dataBody["bed_id"].(float64))
  479. if bedId < 1 {
  480. utils.ErrorLog("bedId < 1")
  481. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  482. return
  483. }
  484. schedule.BedId = bedId
  485. if dataBody["partition_id"] == nil || reflect.TypeOf(dataBody["partition_id"]).String() != "float64" {
  486. utils.ErrorLog("partition_id")
  487. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  488. return
  489. }
  490. partitionId := int64(dataBody["partition_id"].(float64))
  491. if partitionId < 1 {
  492. utils.ErrorLog("partitionId < 1")
  493. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  494. return
  495. }
  496. schedule.PartitionId = partitionId
  497. bed, _ := service.GetDeviceNumberByID(adminINfo.CurrentOrgId, schedule.BedId)
  498. if bed == nil {
  499. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotExist)
  500. return
  501. }
  502. if bed.ZoneID != schedule.PartitionId {
  503. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotTheZone)
  504. return
  505. }
  506. startTime := schedule.ScheduleDate
  507. endTime := startTime + 86399
  508. //一天只有排班一次
  509. daySchedule, err := service.GetDaySchedule(adminINfo.CurrentOrgId, startTime, endTime, schedule.PatientId)
  510. if daySchedule.ID > 0 && daySchedule.ID != schedule.ID {
  511. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleAgainOneDay)
  512. return
  513. }
  514. //同天同位置只能排一个
  515. pointSchedule, err := service.GetPointSchedule(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.ScheduleWeek, schedule.ScheduleType, schedule.BedId)
  516. if err != nil {
  517. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  518. return
  519. }
  520. if pointSchedule.ID > 0 {
  521. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePointScheduleExist)
  522. return
  523. }
  524. } else {
  525. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  526. return
  527. }
  528. schedule.UpdatedTime = time.Now().Unix()
  529. err = service.UpdateSchedule(schedule)
  530. prescription := models.DialysisPrescription{
  531. ModeId: schedule.ModeId,
  532. }
  533. _, errcode := service.GetDialysisPrescribe(schedule.UserOrgId, schedule.PatientId, schedule.ScheduleDate)
  534. if errcode == gorm.ErrRecordNotFound {
  535. if err != nil {
  536. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeScheduleFail)
  537. return
  538. }
  539. c.ServeSuccessJSON(map[string]interface{}{
  540. "msg": "ok",
  541. "schedule": &schedule,
  542. })
  543. } else if errcode == nil {
  544. err = service.UpdatedDialysisPrescription(&prescription, schedule.ScheduleDate, schedule.PatientId, schedule.UserOrgId)
  545. if err != nil {
  546. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeScheduleFail)
  547. return
  548. }
  549. c.ServeSuccessJSON(map[string]interface{}{
  550. "msg": "ok",
  551. "schedule": &schedule,
  552. })
  553. }
  554. }
  555. // /api/schedule/print/initdata [get]
  556. // @param date:string yyyy-MM-dd 要打印的那一周中的任一天
  557. func (this *ScheduleApiController) PrintInitData() {
  558. dateStr := this.GetString("date")
  559. //week_type, _ := this.GetInt64("type", 0)
  560. var date *time.Time
  561. if len(dateStr) == 0 {
  562. now := time.Now()
  563. date = &now
  564. } else {
  565. var parseErr error
  566. date, parseErr = utils.ParseTimeStringToTime("2006-01-02", dateStr)
  567. if parseErr != nil {
  568. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  569. return
  570. }
  571. }
  572. adminUserInfo := this.GetAdminUserInfo()
  573. // 获取本周的排班
  574. var monday time.Time
  575. var sunday time.Time
  576. //switch week_type {
  577. //case 1:
  578. monday, sunday = utils.GetMondayAndSundayOfWeekDate(date)
  579. // break
  580. //case 2:
  581. // monday, sunday = utils.GetMondayAndSundayOfNextWeekDate(date)
  582. //
  583. // break
  584. //case 3:
  585. // monday, sunday = utils.GetMondayAndSundayOfNextNextWeekDate(date)
  586. // break
  587. //}
  588. schedules, getScheduleErr := service.GetPrinitWeekSchedules(adminUserInfo.CurrentOrgId, monday.Unix(), sunday.Unix())
  589. total, getScheduleErr := service.GetPrinitWeekTotal(adminUserInfo.CurrentOrgId, monday.Unix(), sunday.Unix())
  590. if getScheduleErr != nil {
  591. this.ErrorLog("获取周排班失败:%v", getScheduleErr)
  592. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  593. return
  594. }
  595. thisTime := date
  596. weekDay := int(thisTime.Weekday())
  597. if weekDay == 0 {
  598. weekDay = 7
  599. }
  600. weekEnd := 7 - weekDay
  601. weekStart := weekEnd - 6
  602. days := make([]string, 0)
  603. for index := weekStart; index <= weekEnd; index++ {
  604. theDay := thisTime.AddDate(0, 0, index)
  605. days = append(days, theDay.Format("2006-01-02"))
  606. }
  607. this.ServeSuccessJSON(map[string]interface{}{
  608. "total": total,
  609. "schedules": schedules,
  610. "monday": monday.Unix(),
  611. "days": days,
  612. })
  613. }
  614. func (this *ScheduleApiController) UrgentScheduleData() {
  615. schedule_type, _ := this.GetInt("type", 0)
  616. schedule_date := this.GetString("date")
  617. var date *time.Time
  618. if len(schedule_date) == 0 {
  619. now := time.Now()
  620. date = &now
  621. } else {
  622. var parseErr error
  623. date, parseErr = utils.ParseTimeStringToTime("2006-01-02", schedule_date)
  624. if parseErr != nil {
  625. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  626. return
  627. }
  628. }
  629. adminUserInfo := this.GetAdminUserInfo()
  630. deviceNumbers, getDeviceNumbersErr := service.MobileGetAllDeviceNumbersForUrgentSchedule(adminUserInfo.CurrentOrgId, date.Unix(), schedule_type)
  631. if getDeviceNumbersErr != nil {
  632. this.ErrorLog("获取所有床位失败:%v", getDeviceNumbersErr)
  633. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  634. return
  635. }
  636. // today := utils.ZeroHourTimeOfDay(time.Now())
  637. schedules, getSchedulesErr := service.MobileGetOtherSchedulesForUrgentSchedule(adminUserInfo.CurrentOrgId, date.Unix(), schedule_type)
  638. if getSchedulesErr != nil {
  639. this.ErrorLog("获取所有排班失败:%v", getSchedulesErr)
  640. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  641. return
  642. }
  643. this.ServeSuccessJSON(map[string]interface{}{
  644. "device_numbers": deviceNumbers,
  645. "schedules": schedules,
  646. })
  647. }
  648. func (this *ScheduleApiController) SearchSchedulePatients() {
  649. keywords := this.GetString("keywords")
  650. week_type, _ := this.GetInt64("week_type", 0)
  651. thisTime1 := time.Now()
  652. thisTime2 := time.Now()
  653. thisTime1 = thisTime1.AddDate(0, 0, 7)
  654. thisTime2 = thisTime2.AddDate(0, 0, 14)
  655. var start_time string
  656. var end_time string
  657. switch week_type {
  658. case 1:
  659. adminUserInfo := this.GetAdminUserInfo()
  660. list, _ := service.GetSchedualPatientsByKeywords(keywords, adminUserInfo.CurrentOrgId)
  661. this.ServeSuccessJSON(map[string]interface{}{
  662. "schdules": list,
  663. })
  664. break
  665. case 2:
  666. days := make([]string, 0)
  667. weekDay1 := int(thisTime1.Weekday())
  668. if weekDay1 == 0 {
  669. weekDay1 = 7
  670. }
  671. weekEnd1 := 7 - weekDay1
  672. weekStart1 := weekEnd1 - 6
  673. for index := weekStart1; index <= weekEnd1; index++ {
  674. fmt.Println(index)
  675. theDay := thisTime1.AddDate(0, 0, index)
  676. days = append(days, theDay.Format("2006-01-02"))
  677. }
  678. fmt.Println(days)
  679. start_time = days[0]
  680. end_time = days[len(days)-1]
  681. timeLayout := "2006-01-02"
  682. loc, _ := time.LoadLocation("Local")
  683. var theStartTime int64
  684. if len(start_time) > 0 {
  685. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  686. theStartTime = theTime.Unix()
  687. }
  688. var theEndtTime int64
  689. if len(end_time) > 0 {
  690. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  691. theEndtTime = theTime.Unix()
  692. }
  693. adminUserInfo := this.GetAdminUserInfo()
  694. list, _ := service.GetSchedualPatientsByKeywordsAndWeek(keywords, adminUserInfo.CurrentOrgId, theStartTime, theEndtTime)
  695. this.ServeSuccessJSON(map[string]interface{}{
  696. "schdules": list,
  697. })
  698. break
  699. case 3:
  700. days := make([]string, 0)
  701. weekDay2 := int(thisTime2.Weekday())
  702. if weekDay2 == 0 {
  703. weekDay2 = 7
  704. }
  705. weekEnd2 := 7 - weekDay2
  706. weekStart2 := weekEnd2 - 6
  707. for index := weekStart2; index <= weekEnd2; index++ {
  708. theDay := thisTime2.AddDate(0, 0, index)
  709. days = append(days, theDay.Format("2006-01-02"))
  710. }
  711. start_time = days[0]
  712. end_time = days[len(days)-1]
  713. timeLayout := "2006-01-02"
  714. loc, _ := time.LoadLocation("Local")
  715. var theStartTime int64
  716. if len(start_time) > 0 {
  717. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  718. theStartTime = theTime.Unix()
  719. }
  720. var theEndtTime int64
  721. if len(end_time) > 0 {
  722. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  723. theEndtTime = theTime.Unix()
  724. }
  725. adminUserInfo := this.GetAdminUserInfo()
  726. list, _ := service.GetSchedualPatientsByKeywordsAndWeek(keywords, adminUserInfo.CurrentOrgId, theStartTime, theEndtTime)
  727. this.ServeSuccessJSON(map[string]interface{}{
  728. "schdules": list,
  729. })
  730. break
  731. }
  732. }
  733. func (this *ScheduleApiController) GetWeekDaySchedule() {
  734. week_type, _ := this.GetInt64("week_type", -1)
  735. week_time, _ := this.GetInt64("week_time")
  736. thisTime := time.Now()
  737. weekDay := int(thisTime.Weekday())
  738. if weekDay == 0 {
  739. weekDay = 7
  740. }
  741. weekEnd := 7 - weekDay
  742. weekStart := weekEnd - 6
  743. weekTitle := make([]string, 0)
  744. days := make([]string, 0)
  745. for index := weekStart; index <= weekEnd; index++ {
  746. theDay := thisTime.AddDate(0, 0, index)
  747. indexYear, indexMonthTime, indexDay := theDay.Date()
  748. indexMonth := int(indexMonthTime)
  749. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  750. weekTitle = append(weekTitle, indexWeek)
  751. days = append(days, theDay.Format("2006-01-02"))
  752. }
  753. fmt.Println(days)
  754. var targetDayStr string
  755. var startTime string
  756. var endTime string
  757. switch week_type {
  758. case 0:
  759. {
  760. startTime = days[0]
  761. endTime = days[6]
  762. }
  763. case 1:
  764. targetDayStr = days[0]
  765. break
  766. case 2:
  767. targetDayStr = days[1]
  768. break
  769. case 3:
  770. targetDayStr = days[2]
  771. break
  772. case 4:
  773. targetDayStr = days[3]
  774. break
  775. case 5:
  776. targetDayStr = days[4]
  777. break
  778. case 6:
  779. targetDayStr = days[5]
  780. break
  781. case 7:
  782. targetDayStr = days[6]
  783. break
  784. }
  785. targetDay, parseErr := utils.ParseTimeStringToTime("2006-01-02", targetDayStr)
  786. startDay, _ := utils.ParseTimeStringToTime("2006-01-02", startTime)
  787. endDay, _ := utils.ParseTimeStringToTime("2006-01-02", endTime)
  788. fmt.Println(startDay, endDay)
  789. if parseErr != nil {
  790. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  791. return
  792. }
  793. orgId := this.GetAdminUserInfo().CurrentOrgId
  794. list, _ := service.GetWeekDayScheduleTwo(orgId, targetDay.Unix(), targetDay, week_time)
  795. this.ServeSuccessJSON(map[string]interface{}{
  796. "schdules": list,
  797. "day": targetDayStr,
  798. })
  799. }
  800. func Struct2Map(obj interface{}) map[string]interface{} {
  801. t := reflect.TypeOf(obj)
  802. v := reflect.ValueOf(obj)
  803. var data = make(map[string]interface{})
  804. for i := 0; i < t.NumField(); i++ {
  805. data[t.Field(i).Name] = v.Field(i).Interface()
  806. }
  807. return data
  808. }
  809. func (this *ScheduleApiController) ExportSchedule() {
  810. dataBody := make(map[string]interface{}, 0)
  811. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  812. if err != nil {
  813. utils.ErrorLog(err.Error())
  814. return
  815. }
  816. utils.ErrorLog("%v", dataBody)
  817. export_time := time.Now().Unix()
  818. var schedules []*models.Schedule
  819. var failed_total int
  820. var total_schedule []interface{}
  821. var patients []*models.Patients
  822. patients, _, _ = service.GetAllPatientList(this.GetAdminUserInfo().CurrentOrgId)
  823. start_time := dataBody["start_time"].(string)
  824. end_time := dataBody["end_time"].(string)
  825. delete_type := int64(dataBody["delete_type"].(float64))
  826. fmt.Println("delete_type", delete_type)
  827. timeLayout := "2006-01-02"
  828. loc, _ := time.LoadLocation("Local")
  829. theTimeStart, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  830. theTimeEnd, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  831. fmt.Println("theTimeStart23232322332322323", theTimeStart.Unix())
  832. fmt.Println("theTimeStart23232322332322323", theTimeEnd.Unix())
  833. if dataBody["failed_schedule"] != nil || reflect.TypeOf(dataBody["failed_schedule"]).String() == "[]interface {}" {
  834. tempSchedule := dataBody["failed_schedule"].([]interface{})
  835. failed_total = len(tempSchedule)
  836. }
  837. if dataBody["schedule"] != nil || reflect.TypeOf(dataBody["schedule"]).String() == "[]interface {}" {
  838. tempSchedule := dataBody["schedule"].([]interface{})
  839. total_schedule = tempSchedule
  840. for _, schMap := range tempSchedule {
  841. schMapM := schMap.(map[string]interface{})
  842. var sch models.Schedule
  843. if schMapM["name"] == nil || reflect.TypeOf(schMapM["name"]).String() != "string" {
  844. utils.ErrorLog("name")
  845. return
  846. }
  847. name, _ := schMapM["name"].(string)
  848. fmt.Println(name)
  849. if len(name) == 0 { //名字为空则生成一条导入错误日志
  850. err_log := models.ExportErrLog{
  851. LogType: 2,
  852. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  853. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名不能为空",
  854. Status: 1,
  855. CreateTime: time.Now().Unix(),
  856. UpdateTime: time.Now().Unix(),
  857. ExportTime: export_time,
  858. }
  859. service.CreateExportErrLog(&err_log)
  860. continue
  861. } else {
  862. var patient []*models.Patients
  863. for _, item := range patients {
  864. if strings.Replace(item.Name, " ", "", -1) == name {
  865. patient = append(patient, item)
  866. }
  867. }
  868. if len(patient) == 0 { //错误日志
  869. err_log := models.ExportErrLog{
  870. LogType: 2,
  871. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  872. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列,患者姓名为\"" + name + "\"在系统中不存在,请在系统中添加该患者",
  873. Status: 1,
  874. CreateTime: time.Now().Unix(),
  875. UpdateTime: time.Now().Unix(),
  876. ExportTime: export_time,
  877. }
  878. service.CreateExportErrLog(&err_log)
  879. continue
  880. } else if len(patient) == 1 { //
  881. sch.PatientId = patient[0].ID
  882. } else if len(patient) > 1 { //出现同名的情况
  883. err_log := models.ExportErrLog{
  884. LogType: 2,
  885. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  886. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列" + "患者姓名为" + name + "在当前机构中存在重名,无法确定到具体患者",
  887. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列,患者姓名为\"" + name + "\"在在当前机构中存在重名,无法确定到具体患者",
  888. Status: 1,
  889. CreateTime: time.Now().Unix(),
  890. UpdateTime: time.Now().Unix(),
  891. ExportTime: export_time,
  892. }
  893. service.CreateExportErrLog(&err_log)
  894. continue
  895. }
  896. }
  897. if schMapM["schedule_type"] == nil && reflect.TypeOf(schMapM["schedule_type"]).String() != "float64" {
  898. utils.ErrorLog("schedule_type")
  899. return
  900. }
  901. schedule_type := int64(schMapM["schedule_type"].(float64))
  902. if schedule_type <= 0 { //班次格式有误,插入日志
  903. log := models.ExportLog{
  904. LogType: 2,
  905. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  906. TotalNum: int64(len(total_schedule) + failed_total),
  907. FailNum: 1 + int64(failed_total),
  908. SuccessNum: int64(len(schedules)),
  909. CreateTime: time.Now().Unix(),
  910. UpdateTime: time.Now().Unix(),
  911. ExportTime: export_time,
  912. Status: 1,
  913. }
  914. service.CreateExportLog(&log)
  915. err_log := models.ExportErrLog{
  916. LogType: 2,
  917. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  918. ErrMsg: "第2行第" + schMapM["row"].(string) + "列的班次格式有误",
  919. Status: 1,
  920. CreateTime: time.Now().Unix(),
  921. UpdateTime: time.Now().Unix(),
  922. ExportTime: export_time,
  923. }
  924. service.CreateExportErrLog(&err_log)
  925. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  926. return
  927. } else {
  928. sch.ScheduleType = schedule_type
  929. }
  930. if schMapM["partition_name"] == nil || reflect.TypeOf(schMapM["partition_name"]).String() != "string" {
  931. utils.ErrorLog("partition_name")
  932. return
  933. }
  934. partition_name, _ := schMapM["partition_name"].(string)
  935. if len(partition_name) == 0 { //分区为空
  936. log := models.ExportLog{
  937. LogType: 2,
  938. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  939. TotalNum: int64(len(total_schedule) + failed_total),
  940. FailNum: 1 + int64(failed_total),
  941. SuccessNum: int64(len(schedules)),
  942. CreateTime: time.Now().Unix(),
  943. UpdateTime: time.Now().Unix(),
  944. ExportTime: export_time,
  945. Status: 1,
  946. }
  947. service.CreateExportLog(&log)
  948. err_log := models.ExportErrLog{
  949. LogType: 2,
  950. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  951. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  952. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第1列所属的分区格式有误",
  953. Status: 1,
  954. CreateTime: time.Now().Unix(),
  955. UpdateTime: time.Now().Unix(),
  956. ExportTime: export_time,
  957. }
  958. service.CreateExportErrLog(&err_log)
  959. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  960. return
  961. } else {
  962. zone, err := service.FindDeviceZoneByName(partition_name, this.GetAdminUserInfo().CurrentOrgId)
  963. if err == nil {
  964. sch.PartitionId = zone.ID
  965. } else if err == gorm.ErrRecordNotFound { //查不到数据,插入错误日志
  966. log := models.ExportLog{
  967. LogType: 2,
  968. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  969. TotalNum: int64(len(total_schedule) + failed_total),
  970. FailNum: 1 + int64(failed_total),
  971. SuccessNum: int64(len(schedules)),
  972. CreateTime: time.Now().Unix(),
  973. UpdateTime: time.Now().Unix(),
  974. ExportTime: export_time,
  975. Status: 1,
  976. }
  977. service.CreateExportLog(&log)
  978. err_log := models.ExportErrLog{
  979. LogType: 2,
  980. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  981. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  982. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第1列所属的分区格式有误",
  983. Status: 1,
  984. CreateTime: time.Now().Unix(),
  985. UpdateTime: time.Now().Unix(),
  986. ExportTime: export_time,
  987. }
  988. service.CreateExportErrLog(&err_log)
  989. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  990. return
  991. }
  992. }
  993. if schMapM["device_number_name"] == nil || reflect.TypeOf(schMapM["device_number_name"]).String() != "string" {
  994. utils.ErrorLog("device_number_name")
  995. return
  996. }
  997. device_number_name, _ := schMapM["device_number_name"].(string)
  998. if len(device_number_name) == 0 { //分区为空
  999. log := models.ExportLog{
  1000. LogType: 2,
  1001. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1002. TotalNum: int64(len(total_schedule) + failed_total),
  1003. FailNum: 1 + int64(failed_total),
  1004. SuccessNum: int64(len(schedules)),
  1005. CreateTime: time.Now().Unix(),
  1006. UpdateTime: time.Now().Unix(),
  1007. ExportTime: export_time,
  1008. Status: 1,
  1009. }
  1010. service.CreateExportLog(&log)
  1011. err_log := models.ExportErrLog{
  1012. LogType: 2,
  1013. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1014. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  1015. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
  1016. Status: 1,
  1017. CreateTime: time.Now().Unix(),
  1018. UpdateTime: time.Now().Unix(),
  1019. ExportTime: export_time,
  1020. }
  1021. service.CreateExportErrLog(&err_log)
  1022. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1023. return
  1024. } else {
  1025. device, err := service.FindDeviceByName(device_number_name, this.GetAdminUserInfo().CurrentOrgId, sch.PartitionId)
  1026. if err == nil {
  1027. if len(device) == 0 { //没查到数据,插入错误日志
  1028. log := models.ExportLog{
  1029. LogType: 2,
  1030. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1031. TotalNum: int64(len(total_schedule) + failed_total),
  1032. FailNum: 1 + int64(failed_total),
  1033. SuccessNum: int64(len(schedules)),
  1034. CreateTime: time.Now().Unix(),
  1035. UpdateTime: time.Now().Unix(),
  1036. ExportTime: export_time,
  1037. Status: 1,
  1038. }
  1039. service.CreateExportLog(&log)
  1040. err_log := models.ExportErrLog{
  1041. LogType: 2,
  1042. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1043. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
  1044. Status: 1,
  1045. CreateTime: time.Now().Unix(),
  1046. UpdateTime: time.Now().Unix(),
  1047. ExportTime: export_time,
  1048. }
  1049. service.CreateExportErrLog(&err_log)
  1050. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1051. return
  1052. } else if len(device) == 1 {
  1053. sch.BedId = device[0].ID
  1054. } else if len(device) > 1 { //出现重名,插入错误日志
  1055. log := models.ExportLog{
  1056. LogType: 2,
  1057. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1058. TotalNum: int64(len(total_schedule) + failed_total),
  1059. FailNum: 1 + int64(failed_total),
  1060. SuccessNum: int64(len(schedules)),
  1061. CreateTime: time.Now().Unix(),
  1062. UpdateTime: time.Now().Unix(),
  1063. ExportTime: export_time,
  1064. Status: 1,
  1065. }
  1066. service.CreateExportLog(&log)
  1067. err_log := models.ExportErrLog{
  1068. LogType: 2,
  1069. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1070. ErrMsg: "出现两个床位号相同的床位",
  1071. Status: 1,
  1072. CreateTime: time.Now().Unix(),
  1073. UpdateTime: time.Now().Unix(),
  1074. ExportTime: export_time,
  1075. }
  1076. service.CreateExportErrLog(&err_log)
  1077. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1078. return
  1079. }
  1080. }
  1081. }
  1082. if schMapM["schedule_week"] == nil || reflect.TypeOf(schMapM["schedule_week"]).String() != "string" {
  1083. utils.ErrorLog("schedule_week")
  1084. return
  1085. }
  1086. schedule_week, _ := schMapM["schedule_week"].(string)
  1087. if len(schedule_week) == 0 { //周几为空则生成一条导入错误日志
  1088. log := models.ExportLog{
  1089. LogType: 2,
  1090. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1091. TotalNum: int64(len(total_schedule) + failed_total),
  1092. FailNum: 1 + int64(failed_total),
  1093. SuccessNum: int64(len(schedules)),
  1094. CreateTime: time.Now().Unix(),
  1095. UpdateTime: time.Now().Unix(),
  1096. ExportTime: export_time,
  1097. Status: 1,
  1098. }
  1099. service.CreateExportLog(&log)
  1100. err_log := models.ExportErrLog{
  1101. LogType: 2,
  1102. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1103. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  1104. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  1105. Status: 1,
  1106. CreateTime: time.Now().Unix(),
  1107. UpdateTime: time.Now().Unix(),
  1108. ExportTime: export_time,
  1109. }
  1110. service.CreateExportErrLog(&err_log)
  1111. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1112. return
  1113. } else if schedule_week == "0" { //周几不符合格式则生成一条导入错误日志
  1114. log := models.ExportLog{
  1115. LogType: 2,
  1116. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1117. TotalNum: int64(len(total_schedule) + failed_total),
  1118. FailNum: 1 + int64(failed_total),
  1119. SuccessNum: int64(len(schedules)),
  1120. CreateTime: time.Now().Unix(),
  1121. UpdateTime: time.Now().Unix(),
  1122. ExportTime: export_time,
  1123. Status: 1,
  1124. }
  1125. service.CreateExportLog(&log)
  1126. err_log := models.ExportErrLog{
  1127. LogType: 2,
  1128. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1129. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  1130. Status: 1,
  1131. CreateTime: time.Now().Unix(),
  1132. UpdateTime: time.Now().Unix(),
  1133. ExportTime: export_time,
  1134. }
  1135. service.CreateExportErrLog(&err_log)
  1136. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1137. return
  1138. } else {
  1139. schedule_week, _ := strconv.ParseInt(schedule_week, 10, 64)
  1140. sch.ScheduleWeek = schedule_week
  1141. }
  1142. if schMapM["schedule_date"] == nil || reflect.TypeOf(schMapM["schedule_date"]).String() != "string" {
  1143. utils.ErrorLog("schedule_date")
  1144. return
  1145. }
  1146. schedule_date, _ := schMapM["schedule_date"].(string)
  1147. if len(schedule_date) == 0 { //周几为空则生成一条导入错误日志
  1148. log := models.ExportLog{
  1149. LogType: 2,
  1150. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1151. TotalNum: int64(len(total_schedule) + failed_total),
  1152. FailNum: 1 + int64(failed_total),
  1153. SuccessNum: int64(len(schedules)),
  1154. CreateTime: time.Now().Unix(),
  1155. UpdateTime: time.Now().Unix(),
  1156. ExportTime: export_time,
  1157. Status: 1,
  1158. }
  1159. service.CreateExportLog(&log)
  1160. err_log := models.ExportErrLog{
  1161. LogType: 2,
  1162. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1163. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  1164. Status: 1,
  1165. CreateTime: time.Now().Unix(),
  1166. UpdateTime: time.Now().Unix(),
  1167. ExportTime: export_time,
  1168. }
  1169. service.CreateExportErrLog(&err_log)
  1170. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1171. return
  1172. } else if schedule_date == "0" { //周几不符合格式则生成一条导入错误日志
  1173. log := models.ExportLog{
  1174. LogType: 2,
  1175. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1176. TotalNum: int64(len(total_schedule) + failed_total),
  1177. FailNum: 1 + int64(failed_total),
  1178. SuccessNum: int64(len(schedules)),
  1179. CreateTime: time.Now().Unix(),
  1180. UpdateTime: time.Now().Unix(),
  1181. ExportTime: export_time,
  1182. Status: 1,
  1183. }
  1184. service.CreateExportLog(&log)
  1185. err_log := models.ExportErrLog{
  1186. LogType: 2,
  1187. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1188. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  1189. Status: 1,
  1190. CreateTime: time.Now().Unix(),
  1191. UpdateTime: time.Now().Unix(),
  1192. ExportTime: export_time,
  1193. }
  1194. service.CreateExportErrLog(&err_log)
  1195. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1196. return
  1197. } else {
  1198. date, _ := utils.ParseTimeStringToTime("2006-01-02", schedule_date)
  1199. sch.ScheduleDate = date.Unix()
  1200. }
  1201. sch.CreatedTime = time.Now().Unix()
  1202. sch.UpdatedTime = time.Now().Unix()
  1203. sch.ModeId = 1
  1204. sch.Status = 1
  1205. sch.UserOrgId = this.GetAdminUserInfo().CurrentOrgId
  1206. sch.IsExport = 1
  1207. schedules = append(schedules, &sch)
  1208. }
  1209. errLogs, _ := service.FindSchedualExportLog(this.GetAdminUserInfo().CurrentOrgId, export_time)
  1210. if len(schedules) > 0 {
  1211. schedule_date := time.Now().Format("2006-01-02")
  1212. date, _ := utils.ParseTimeStringToTime("2006-01-02", schedule_date)
  1213. clear_schedule_date := date.Unix() //根据日期去清除,该日期未来的排班数据
  1214. // err := service.UpdateScheduleStatus(clear_schedule_date, this.GetAdminUserInfo().CurrentOrgId)
  1215. if err == nil {
  1216. //清除该机构的排班
  1217. //if delete_type == 1 {
  1218. // service.ModeScheduleByTimeOne(theTimeStart.Unix(), theTimeEnd.Unix(), this.GetAdminUserInfo().CurrentOrgId)
  1219. //}
  1220. //if delete_type == 0 {
  1221. // service.ModeScheduleByTime(theTimeStart.Unix(), theTimeEnd.Unix(), this.GetAdminUserInfo().CurrentOrgId)
  1222. //}
  1223. for _, item := range schedules {
  1224. // fmt.Println("clear_schedule_date3232232332232332232323",clear_schedule_date)
  1225. if item.ScheduleDate > clear_schedule_date {
  1226. //删除当天的以后日期排班
  1227. // service.DeleteScheduleExist(item.ScheduleDate, item.UserOrgId)
  1228. //查找当天日期是否存在
  1229. _, errcode := service.GetTodayScheduleIsExistOne(item.PatientId, item.ScheduleDate, item.UserOrgId)
  1230. if errcode == gorm.ErrRecordNotFound {
  1231. //清除当天该床位已有的患者
  1232. service.ModeFyScheduleById(item.ScheduleDate, item.BedId, item.ScheduleType)
  1233. service.CreateSchedule(item)
  1234. } else if errcode == nil {
  1235. schedule := models.XtSchedule{
  1236. PartitionId: item.PartitionId,
  1237. BedId: item.BedId,
  1238. PatientId: item.PatientId,
  1239. ScheduleDate: item.ScheduleDate,
  1240. ScheduleType: item.ScheduleType,
  1241. ScheduleWeek: item.ScheduleWeek,
  1242. ModeId: item.ModeId,
  1243. Status: 1,
  1244. }
  1245. service.UpdateScheduleByOrgIdOne(item.PatientId, item.ScheduleDate, item.UserOrgId, &schedule)
  1246. }
  1247. }
  1248. }
  1249. log := models.ExportLog{
  1250. LogType: 2,
  1251. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1252. TotalNum: int64(len(total_schedule) + failed_total),
  1253. FailNum: int64(len(errLogs) + failed_total),
  1254. SuccessNum: int64(len(schedules)),
  1255. CreateTime: time.Now().Unix(),
  1256. UpdateTime: time.Now().Unix(),
  1257. ExportTime: export_time,
  1258. Status: 1,
  1259. }
  1260. service.CreateExportLog(&log)
  1261. if failed_total > 0 {
  1262. err_log := models.ExportErrLog{
  1263. LogType: 2,
  1264. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1265. ErrMsg: "当前日期(" + time.Now().Format("2006-01-02") + " " + GetWeekString(time.Now().Weekday().String()) +
  1266. ")及以前的排班数据" + strconv.FormatInt(int64(failed_total), 10) + "条,不执行导入",
  1267. Status: 1,
  1268. CreateTime: time.Now().Unix(),
  1269. UpdateTime: time.Now().Unix(),
  1270. ExportTime: export_time,
  1271. }
  1272. service.CreateExportErrLog(&err_log)
  1273. }
  1274. this.ServeSuccessJSON(map[string]interface{}{
  1275. "msg": "导入成功",
  1276. "total_num": len(total_schedule) + failed_total,
  1277. "success_num": len(schedules),
  1278. "fail_num": int64(len(errLogs)),
  1279. })
  1280. } else {
  1281. log := models.ExportLog{
  1282. LogType: 2,
  1283. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1284. TotalNum: int64(len(total_schedule) + failed_total),
  1285. FailNum: int64(len(errLogs) + failed_total),
  1286. SuccessNum: int64(len(schedules)),
  1287. CreateTime: time.Now().Unix(),
  1288. UpdateTime: time.Now().Unix(),
  1289. ExportTime: export_time,
  1290. Status: 1,
  1291. }
  1292. service.CreateExportLog(&log)
  1293. if failed_total > 0 {
  1294. err_log := models.ExportErrLog{
  1295. LogType: 2,
  1296. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1297. ErrMsg: "当前日期(" + time.Now().Format("2006-01-02") + " " + GetWeekString(time.Now().Weekday().String()) +
  1298. ")及以前的排班数据" + strconv.FormatInt(int64(failed_total), 10) + "条,不执行导入",
  1299. Status: 1,
  1300. CreateTime: time.Now().Unix(),
  1301. UpdateTime: time.Now().Unix(),
  1302. ExportTime: export_time,
  1303. }
  1304. service.CreateExportErrLog(&err_log)
  1305. }
  1306. this.ServeSuccessJSON(map[string]interface{}{
  1307. "msg": "导入成功",
  1308. "total_num": len(total_schedule),
  1309. "success_num": len(schedules),
  1310. "fail_num": int64(len(errLogs)),
  1311. })
  1312. }
  1313. } else {
  1314. log := models.ExportLog{
  1315. LogType: 2,
  1316. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1317. TotalNum: int64(len(total_schedule) + failed_total),
  1318. FailNum: int64(len(errLogs) + failed_total),
  1319. SuccessNum: int64(len(schedules)),
  1320. CreateTime: time.Now().Unix(),
  1321. UpdateTime: time.Now().Unix(),
  1322. ExportTime: export_time,
  1323. Status: 1,
  1324. }
  1325. service.CreateExportLog(&log)
  1326. if failed_total > 0 {
  1327. err_log := models.ExportErrLog{
  1328. LogType: 2,
  1329. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1330. ErrMsg: "当前日期(" + time.Now().Format("2006-01-02") + " " + GetWeekString(time.Now().Weekday().String()) +
  1331. ")及以前的排班数据" + strconv.FormatInt(int64(failed_total), 10) + "条,不执行导入",
  1332. Status: 1,
  1333. CreateTime: time.Now().Unix(),
  1334. UpdateTime: time.Now().Unix(),
  1335. ExportTime: export_time,
  1336. }
  1337. service.CreateExportErrLog(&err_log)
  1338. }
  1339. this.ServeSuccessJSON(map[string]interface{}{
  1340. "msg": "导入成功",
  1341. "total_num": len(total_schedule),
  1342. "success_num": len(schedules),
  1343. "fail_num": int64(len(errLogs)),
  1344. })
  1345. }
  1346. }
  1347. }
  1348. func (this *ScheduleApiController) ExportScheduleTemplate() {
  1349. dataBody := make(map[string]interface{}, 0)
  1350. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1351. if err != nil {
  1352. utils.ErrorLog(err.Error())
  1353. return
  1354. }
  1355. utils.ErrorLog("%v", dataBody)
  1356. export_time := time.Now().Unix()
  1357. var schedules []*models.PatientScheduleTemplateItem
  1358. var total_schedule []interface{}
  1359. patients, _, _ := service.GetAllPatientList(this.GetAdminUserInfo().CurrentOrgId)
  1360. if dataBody["schedule"] != nil || reflect.TypeOf(dataBody["schedule"]).String() == "[]interface {}" {
  1361. tempSchedule := dataBody["schedule"].([]interface{})
  1362. total_schedule = tempSchedule
  1363. for _, schMap := range tempSchedule {
  1364. schMapM := schMap.(map[string]interface{})
  1365. var sch models.PatientScheduleTemplateItem
  1366. if schMapM["name"] == nil || reflect.TypeOf(schMapM["name"]).String() != "string" {
  1367. utils.ErrorLog("name")
  1368. return
  1369. }
  1370. name, _ := schMapM["name"].(string)
  1371. fmt.Println(name)
  1372. if len(name) == 0 { //名字为空则生成一条导入错误日志
  1373. err_log := models.ExportErrLog{
  1374. LogType: 3,
  1375. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1376. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名不能为空",
  1377. Status: 1,
  1378. CreateTime: time.Now().Unix(),
  1379. UpdateTime: time.Now().Unix(),
  1380. ExportTime: export_time,
  1381. }
  1382. service.CreateExportErrLog(&err_log)
  1383. continue
  1384. } else {
  1385. var patient []*models.Patients
  1386. for _, item := range patients {
  1387. if strings.Replace(item.Name, " ", "", -1) == name {
  1388. patient = append(patient, item)
  1389. }
  1390. }
  1391. if len(patient) == 0 { //错误日志
  1392. err_log := models.ExportErrLog{
  1393. LogType: 3,
  1394. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1395. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名在系统中不存在,请在系统中添加该病人",
  1396. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列患者姓名为\"" + name + "\"在系统中不存在,请在系统中添加该患者",
  1397. Status: 1,
  1398. CreateTime: time.Now().Unix(),
  1399. UpdateTime: time.Now().Unix(),
  1400. ExportTime: export_time,
  1401. }
  1402. service.CreateExportErrLog(&err_log)
  1403. continue
  1404. } else if len(patient) == 1 { //
  1405. sch.PatientID = patient[0].ID
  1406. } else if len(patient) > 1 { //出现同名的情况
  1407. err_log := models.ExportErrLog{
  1408. LogType: 3,
  1409. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1410. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列" + "患者姓名为" + name + "在当前机构中存在重名,无法确定到具体患者",
  1411. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列患者姓名为\"" + name + "\"在当前机构中存在重名,无法确定到具体患者",
  1412. Status: 1,
  1413. CreateTime: time.Now().Unix(),
  1414. UpdateTime: time.Now().Unix(),
  1415. ExportTime: export_time,
  1416. }
  1417. service.CreateExportErrLog(&err_log)
  1418. continue
  1419. }
  1420. }
  1421. if schMapM["schedule_type"] == nil && reflect.TypeOf(schMapM["schedule_type"]).String() != "float64" {
  1422. utils.ErrorLog("schedule_type")
  1423. return
  1424. }
  1425. schedule_type := int64(schMapM["schedule_type"].(float64))
  1426. if schedule_type <= 0 { //班次格式有误,插入日志
  1427. log := models.ExportLog{
  1428. LogType: 3,
  1429. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1430. TotalNum: int64(len(total_schedule)),
  1431. FailNum: 1,
  1432. SuccessNum: int64(len(schedules)),
  1433. CreateTime: time.Now().Unix(),
  1434. UpdateTime: time.Now().Unix(),
  1435. ExportTime: export_time,
  1436. Status: 1,
  1437. }
  1438. service.CreateExportLog(&log)
  1439. err_log := models.ExportErrLog{
  1440. LogType: 3,
  1441. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1442. ErrMsg: "第2行第" + schMapM["row"].(string) + "列的班次格式有误",
  1443. Status: 1,
  1444. CreateTime: time.Now().Unix(),
  1445. UpdateTime: time.Now().Unix(),
  1446. ExportTime: export_time,
  1447. }
  1448. service.CreateExportErrLog(&err_log)
  1449. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1450. return
  1451. } else {
  1452. sch.TimeType = int8(schedule_type)
  1453. }
  1454. if schMapM["template_id"] == nil && reflect.TypeOf(schMapM["template_id"]).String() != "float64" {
  1455. utils.ErrorLog("template_id")
  1456. return
  1457. }
  1458. template_id := int64(schMapM["template_id"].(float64))
  1459. sch.TemplateID = template_id
  1460. if schMapM["device_number_name"] == nil || reflect.TypeOf(schMapM["device_number_name"]).String() != "string" {
  1461. utils.ErrorLog("device_number_name")
  1462. return
  1463. }
  1464. partition_name, _ := schMapM["partition_name"].(string)
  1465. zone, _ := service.FindDeviceZoneByName(partition_name, this.GetAdminUserInfo().CurrentOrgId)
  1466. device_number_name, _ := schMapM["device_number_name"].(string)
  1467. if len(device_number_name) == 0 { //分区为空
  1468. log := models.ExportLog{
  1469. LogType: 3,
  1470. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1471. TotalNum: int64(len(total_schedule)),
  1472. FailNum: 1,
  1473. SuccessNum: int64(len(schedules)),
  1474. CreateTime: time.Now().Unix(),
  1475. UpdateTime: time.Now().Unix(),
  1476. ExportTime: export_time,
  1477. Status: 1,
  1478. }
  1479. service.CreateExportLog(&log)
  1480. err_log := models.ExportErrLog{
  1481. LogType: 3,
  1482. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1483. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  1484. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
  1485. Status: 1,
  1486. CreateTime: time.Now().Unix(),
  1487. UpdateTime: time.Now().Unix(),
  1488. ExportTime: export_time,
  1489. }
  1490. service.CreateExportErrLog(&err_log)
  1491. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1492. return
  1493. } else {
  1494. device, err := service.FindDeviceByNameTwo(device_number_name, this.GetAdminUserInfo().CurrentOrgId, zone.ID)
  1495. if err == nil {
  1496. if len(device) == 0 { //没查到数据,插入错误日志
  1497. log := models.ExportLog{
  1498. LogType: 3,
  1499. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1500. TotalNum: int64(len(total_schedule)),
  1501. FailNum: 1,
  1502. SuccessNum: int64(len(schedules)),
  1503. CreateTime: time.Now().Unix(),
  1504. UpdateTime: time.Now().Unix(),
  1505. ExportTime: export_time,
  1506. Status: 1,
  1507. }
  1508. service.CreateExportLog(&log)
  1509. err_log := models.ExportErrLog{
  1510. LogType: 3,
  1511. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1512. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
  1513. Status: 1,
  1514. CreateTime: time.Now().Unix(),
  1515. UpdateTime: time.Now().Unix(),
  1516. ExportTime: export_time,
  1517. }
  1518. service.CreateExportErrLog(&err_log)
  1519. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1520. return
  1521. } else if len(device) == 1 {
  1522. sch.DeviceNumberID = device[0].ID
  1523. } else if len(device) > 1 { //出现重名,插入错误日志
  1524. log := models.ExportLog{
  1525. LogType: 3,
  1526. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1527. TotalNum: int64(len(total_schedule)),
  1528. FailNum: 1,
  1529. SuccessNum: int64(len(schedules)),
  1530. CreateTime: time.Now().Unix(),
  1531. UpdateTime: time.Now().Unix(),
  1532. ExportTime: export_time,
  1533. Status: 1,
  1534. }
  1535. service.CreateExportLog(&log)
  1536. err_log := models.ExportErrLog{
  1537. LogType: 3,
  1538. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1539. ErrMsg: "出现两个床位号相同的床位",
  1540. Status: 1,
  1541. CreateTime: time.Now().Unix(),
  1542. UpdateTime: time.Now().Unix(),
  1543. ExportTime: export_time,
  1544. }
  1545. service.CreateExportErrLog(&err_log)
  1546. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1547. return
  1548. }
  1549. }
  1550. }
  1551. if schMapM["schedule_week"] == nil || reflect.TypeOf(schMapM["schedule_week"]).String() != "string" {
  1552. utils.ErrorLog("schedule_week")
  1553. return
  1554. }
  1555. schedule_week, _ := schMapM["schedule_week"].(string)
  1556. if len(schedule_week) == 0 { //周几为空则生成一条导入错误日志
  1557. log := models.ExportLog{
  1558. LogType: 3,
  1559. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1560. TotalNum: int64(len(total_schedule)),
  1561. FailNum: 1,
  1562. SuccessNum: int64(len(schedules)),
  1563. CreateTime: time.Now().Unix(),
  1564. UpdateTime: time.Now().Unix(),
  1565. ExportTime: export_time,
  1566. Status: 1,
  1567. }
  1568. service.CreateExportLog(&log)
  1569. err_log := models.ExportErrLog{
  1570. LogType: 3,
  1571. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1572. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  1573. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  1574. Status: 1,
  1575. CreateTime: time.Now().Unix(),
  1576. UpdateTime: time.Now().Unix(),
  1577. ExportTime: export_time,
  1578. }
  1579. service.CreateExportErrLog(&err_log)
  1580. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1581. return
  1582. } else if schedule_week == "0" { //周几不符合格式则生成一条导入错误日志
  1583. log := models.ExportLog{
  1584. LogType: 3,
  1585. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1586. TotalNum: int64(len(total_schedule)),
  1587. FailNum: 1,
  1588. SuccessNum: int64(len(schedules)),
  1589. CreateTime: time.Now().Unix(),
  1590. UpdateTime: time.Now().Unix(),
  1591. ExportTime: export_time,
  1592. Status: 1,
  1593. }
  1594. service.CreateExportLog(&log)
  1595. err_log := models.ExportErrLog{
  1596. LogType: 3,
  1597. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1598. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  1599. Status: 1,
  1600. CreateTime: time.Now().Unix(),
  1601. UpdateTime: time.Now().Unix(),
  1602. ExportTime: export_time,
  1603. }
  1604. service.CreateExportErrLog(&err_log)
  1605. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1606. return
  1607. } else {
  1608. schedule_week, _ := strconv.ParseInt(schedule_week, 10, 64)
  1609. sch.Weekday = int8(schedule_week)
  1610. }
  1611. sch.CreateTime = time.Now().Unix()
  1612. sch.ModifyTime = time.Now().Unix()
  1613. sch.TreatMode = 1
  1614. sch.Status = 1
  1615. sch.OrgID = this.GetAdminUserInfo().CurrentOrgId
  1616. sch.IsExport = 1
  1617. schedules = append(schedules, &sch)
  1618. }
  1619. errLogs, _ := service.FindSchedualTemplateExportLog(this.GetAdminUserInfo().CurrentOrgId, export_time)
  1620. if len(schedules) > 0 {
  1621. err := service.UpdateScheduleTemplateStatus(this.GetAdminUserInfo().CurrentOrgId)
  1622. if err == nil {
  1623. for _, item := range schedules {
  1624. service.CreateScheduleTemplate(item)
  1625. }
  1626. log := models.ExportLog{
  1627. LogType: 3,
  1628. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1629. TotalNum: int64(len(total_schedule)),
  1630. FailNum: int64(len(errLogs)),
  1631. SuccessNum: int64(len(schedules)),
  1632. CreateTime: time.Now().Unix(),
  1633. UpdateTime: time.Now().Unix(),
  1634. ExportTime: export_time,
  1635. Status: 1,
  1636. }
  1637. service.CreateExportLog(&log)
  1638. this.ServeSuccessJSON(map[string]interface{}{
  1639. "msg": "导入成功",
  1640. "total_num": len(total_schedule),
  1641. "success_num": len(schedules),
  1642. "fail_num": int64(len(errLogs)),
  1643. })
  1644. } else {
  1645. log := models.ExportLog{
  1646. LogType: 3,
  1647. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1648. TotalNum: int64(len(total_schedule)),
  1649. FailNum: int64(len(errLogs)),
  1650. SuccessNum: int64(len(schedules)),
  1651. CreateTime: time.Now().Unix(),
  1652. UpdateTime: time.Now().Unix(),
  1653. ExportTime: export_time,
  1654. Status: 1,
  1655. }
  1656. service.CreateExportLog(&log)
  1657. this.ServeSuccessJSON(map[string]interface{}{
  1658. "msg": "导入成功",
  1659. "total_num": len(total_schedule),
  1660. "success_num": len(schedules),
  1661. "fail_num": int64(len(errLogs)),
  1662. })
  1663. }
  1664. } else {
  1665. log := models.ExportLog{
  1666. LogType: 3,
  1667. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1668. TotalNum: int64(len(total_schedule)),
  1669. FailNum: int64(len(errLogs)),
  1670. SuccessNum: int64(len(schedules)),
  1671. CreateTime: time.Now().Unix(),
  1672. UpdateTime: time.Now().Unix(),
  1673. ExportTime: export_time,
  1674. Status: 1,
  1675. }
  1676. service.CreateExportLog(&log)
  1677. this.ServeSuccessJSON(map[string]interface{}{
  1678. "msg": "导入成功",
  1679. "total_num": len(total_schedule),
  1680. "success_num": len(schedules),
  1681. "fail_num": int64(len(errLogs)),
  1682. })
  1683. }
  1684. }
  1685. }
  1686. func (c *ScheduleApiController) GetInitExcelInitDate() {
  1687. thisTime := time.Now()
  1688. thisTime1 := time.Now()
  1689. thisTime2 := time.Now()
  1690. thisTime1 = thisTime1.AddDate(0, 0, 7)
  1691. thisTime2 = thisTime2.AddDate(0, 0, 14)
  1692. weekDay := int(thisTime.Weekday())
  1693. if weekDay == 0 {
  1694. weekDay = 7
  1695. }
  1696. weekEnd := 7 - weekDay
  1697. weekStart := weekEnd - 6
  1698. days := make([]string, 0)
  1699. for index := weekStart; index <= weekEnd; index++ {
  1700. theDay := thisTime.AddDate(0, 0, index)
  1701. days = append(days, theDay.Format("2006-01-02"))
  1702. }
  1703. weekDay1 := int(thisTime1.Weekday())
  1704. if weekDay1 == 0 {
  1705. weekDay1 = 7
  1706. }
  1707. weekEnd1 := 7 - weekDay1
  1708. weekStart1 := weekEnd1 - 6
  1709. for index := weekStart1; index <= weekEnd1; index++ {
  1710. theDay := thisTime1.AddDate(0, 0, index)
  1711. days = append(days, theDay.Format("2006-01-02"))
  1712. }
  1713. weekDay2 := int(thisTime2.Weekday())
  1714. if weekDay2 == 0 {
  1715. weekDay2 = 7
  1716. }
  1717. weekEnd2 := 7 - weekDay2
  1718. weekStart2 := weekEnd2 - 6
  1719. for index := weekStart2; index <= weekEnd2; index++ {
  1720. theDay := thisTime2.AddDate(0, 0, index)
  1721. days = append(days, theDay.Format("2006-01-02"))
  1722. }
  1723. c.ServeSuccessJSON(map[string]interface{}{
  1724. "days": days,
  1725. })
  1726. return
  1727. }
  1728. func GetWeekString(week string) string {
  1729. var weekStr string
  1730. switch week {
  1731. case "Sunday":
  1732. weekStr = "周日"
  1733. break
  1734. case "Monday":
  1735. weekStr = "周一"
  1736. break
  1737. case "Tuesday":
  1738. weekStr = "周二"
  1739. break
  1740. case "Wednesday":
  1741. weekStr = "周三"
  1742. break
  1743. case "Thursday":
  1744. weekStr = "周四"
  1745. break
  1746. case "Friday":
  1747. weekStr = "周五"
  1748. break
  1749. case "Saturday":
  1750. weekStr = "周六"
  1751. break
  1752. default:
  1753. weekStr = ""
  1754. break
  1755. }
  1756. return weekStr
  1757. }
  1758. func (c *ScheduleApiController) SearchTemplateSchedulePatients() {
  1759. template_id, _ := c.GetInt64("template_id", 0)
  1760. keywords := c.GetString("keywords")
  1761. adminInfo := c.GetAdminUserInfo()
  1762. scheduleItems, _ := service.GetTemplateSchedualPatientsByKeywords(keywords, adminInfo.CurrentOrgId, template_id)
  1763. c.ServeSuccessJSON(map[string]interface{}{
  1764. "schdules": scheduleItems,
  1765. })
  1766. }
  1767. func (c *ScheduleApiController) CancelScheduleTemplate() {
  1768. item_id, _ := c.GetInt64("id")
  1769. adminInfo := c.GetAdminUserInfo()
  1770. err := service.UpdateNewScheduleTemplateStatus(item_id, adminInfo.CurrentOrgId)
  1771. if err == nil {
  1772. c.ServeSuccessJSON(map[string]interface{}{
  1773. "msg": "取消成功",
  1774. })
  1775. return
  1776. } else {
  1777. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1778. return
  1779. }
  1780. }
  1781. func (this *ScheduleApiController) GetNextWeekDaySchedule() {
  1782. week_type, _ := this.GetInt64("week_type", -1)
  1783. week_time, _ := this.GetInt64("week_time")
  1784. //start_time, _ := this.GetInt64("start_time")
  1785. //end_time, _ := this.GetInt64("end_time")
  1786. record_date := this.GetString("record_date")
  1787. zons := this.GetString("zone")
  1788. zone := strings.Split(zons, ",")
  1789. start_time := this.GetString("start_time")
  1790. end_time := this.GetString("end_time")
  1791. timeLayout := "2006-01-02"
  1792. loc, _ := time.LoadLocation("Local")
  1793. theTimeStart, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1794. theTimeEnd, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  1795. adminUserInfo := this.GetAdminUserInfo()
  1796. var theStartTIme int64
  1797. if len(record_date) > 0 {
  1798. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1799. if err != nil {
  1800. utils.ErrorLog(err.Error())
  1801. }
  1802. theStartTIme = theTime.Unix()
  1803. }
  1804. schedule, err := service.GetNextWeekDaySchedule(week_type, week_time, theTimeStart.Unix(), theTimeEnd.Unix(), adminUserInfo.CurrentOrgId, zone, theStartTIme)
  1805. if err != nil {
  1806. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1807. return
  1808. }
  1809. this.ServeSuccessJSON(map[string]interface{}{
  1810. "schedule": schedule,
  1811. })
  1812. }
  1813. func (this *ScheduleApiController) GetThreeWeekList() {
  1814. start_time := this.GetString("start_time")
  1815. end_time := this.GetString("end_time")
  1816. partition_id, _ := this.GetInt64("partition_id")
  1817. schedule_type, _ := this.GetInt64("schedule_type")
  1818. fmt.Println(partition_id, schedule_type)
  1819. timeLayout := "2006-01-02"
  1820. loc, _ := time.LoadLocation("Local")
  1821. var theStartTIme int64
  1822. if len(start_time) > 0 {
  1823. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1824. if err != nil {
  1825. utils.ErrorLog(err.Error())
  1826. }
  1827. theStartTIme = theTime.Unix()
  1828. }
  1829. var theEndtTIme int64
  1830. if len(end_time) > 0 {
  1831. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  1832. if err != nil {
  1833. utils.ErrorLog(err.Error())
  1834. }
  1835. theEndtTIme = theTime.Unix()
  1836. }
  1837. adminUserInfo := this.GetAdminUserInfo()
  1838. orgId := adminUserInfo.CurrentOrgId
  1839. partitions, _ := service.GetSchedulePartitionPanel(orgId)
  1840. list, err := service.GetThreeWeekList(theStartTIme, theEndtTIme, orgId, schedule_type, partition_id)
  1841. if err != nil {
  1842. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1843. return
  1844. }
  1845. this.ServeSuccessJSON(map[string]interface{}{
  1846. "list": list,
  1847. "partitions": partitions,
  1848. })
  1849. }
  1850. func (this *ScheduleApiController) GetAllZones() {
  1851. adminUserInfo := this.GetAdminUserInfo()
  1852. orgId := adminUserInfo.CurrentOrgId
  1853. zones, err := service.GetAllZoneOne(orgId)
  1854. if err != nil {
  1855. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1856. return
  1857. }
  1858. this.ServeSuccessJSON(map[string]interface{}{
  1859. "zones": zones,
  1860. })
  1861. }
  1862. func (this *ScheduleApiController) GetCopyPatientSchedules() {
  1863. adminUserInfo := this.GetAdminUserInfo()
  1864. orgId := adminUserInfo.CurrentOrgId
  1865. start_time, _ := this.GetInt64("start_time")
  1866. fmt.Println("start_time", start_time)
  1867. end_time, _ := this.GetInt64("end_time")
  1868. fmt.Println("end_time", end_time)
  1869. copy_startime, _ := this.GetInt64("copy_startime")
  1870. fmt.Println("copy_startime", copy_startime)
  1871. copy_endtime, _ := this.GetInt64("copy_endtime")
  1872. //获取本周患者排班
  1873. schedules, _ := service.GetWeekSchedules(orgId, start_time, end_time)
  1874. //先清除复制周的排班
  1875. errcode := service.UpdatePatientSchedule(orgId, copy_startime, copy_endtime)
  1876. fmt.Println(errcode)
  1877. for _, item := range schedules {
  1878. //fmt.Println(item.StartTime+604800)
  1879. //礼拜1
  1880. if item.ScheduleWeek == 1 {
  1881. item.ScheduleDate = copy_startime
  1882. }
  1883. if item.ScheduleWeek == 2 {
  1884. item.ScheduleDate = copy_startime + 86400
  1885. }
  1886. if item.ScheduleWeek == 3 {
  1887. item.ScheduleDate = copy_startime + 172800
  1888. }
  1889. if item.ScheduleWeek == 4 {
  1890. item.ScheduleDate = copy_startime + 259200
  1891. }
  1892. if item.ScheduleWeek == 5 {
  1893. item.ScheduleDate = copy_startime + 345600
  1894. }
  1895. if item.ScheduleWeek == 6 {
  1896. item.ScheduleDate = copy_startime + 432000
  1897. }
  1898. //礼拜天
  1899. if item.ScheduleWeek == 7 {
  1900. item.ScheduleDate = copy_endtime
  1901. }
  1902. schedule := models.XtSchedule{
  1903. UserOrgId: item.UserOrgId,
  1904. PartitionId: item.PartitionId,
  1905. BedId: item.BedId,
  1906. PatientId: item.PatientId,
  1907. ScheduleDate: item.ScheduleDate,
  1908. ScheduleType: item.ScheduleType,
  1909. ScheduleWeek: item.ScheduleWeek,
  1910. ModeId: item.ModeId,
  1911. Status: 1,
  1912. CreatedTime: time.Now().Unix(),
  1913. }
  1914. err := service.AddPatientSchedule(&schedule)
  1915. if err != nil {
  1916. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1917. return
  1918. }
  1919. this.ServeSuccessJSON(map[string]interface{}{
  1920. "schedule": schedule,
  1921. })
  1922. }
  1923. //查询复制中的排班日期是否存在
  1924. //_, errcode := service.GetLastWeekSchedule(orgId, copy_startime, copy_endtime)
  1925. //
  1926. //if errcode == gorm.ErrRecordNotFound {
  1927. // //如果没有直接新增
  1928. //
  1929. // for _, item := range schedules {
  1930. // //fmt.Println(item.StartTime+604800)
  1931. // //礼拜1
  1932. // if item.ScheduleWeek == 1 {
  1933. // item.ScheduleDate = copy_startime
  1934. // }
  1935. // if item.ScheduleWeek == 2 {
  1936. // item.ScheduleDate = copy_startime + 86400
  1937. // }
  1938. // if item.ScheduleWeek == 3 {
  1939. // item.ScheduleDate = copy_startime + 172800
  1940. // }
  1941. // if item.ScheduleWeek == 4 {
  1942. // item.ScheduleDate = copy_startime + 259200
  1943. // }
  1944. // if item.ScheduleWeek == 5 {
  1945. // item.ScheduleDate = copy_startime + 345600
  1946. // }
  1947. //
  1948. // if item.ScheduleWeek == 6 {
  1949. // item.ScheduleDate = copy_startime + 432000
  1950. // }
  1951. // //礼拜天
  1952. // if item.ScheduleWeek == 0 {
  1953. // item.ScheduleDate = copy_endtime
  1954. // }
  1955. // schedule := models.XtSchedule{
  1956. // UserOrgId: item.UserOrgId,
  1957. // PartitionId: item.PartitionId,
  1958. // BedId: item.BedId,
  1959. // PatientId: item.PatientId,
  1960. // ScheduleDate: item.ScheduleDate,
  1961. // ScheduleType: item.ScheduleType,
  1962. // ScheduleWeek: item.ScheduleWeek,
  1963. // ModeId: item.ModeId,
  1964. // Status: 1,
  1965. // CreatedTime: time.Now().Unix(),
  1966. // }
  1967. //
  1968. // err := service.AddPatientSchedule(&schedule)
  1969. // if err != nil {
  1970. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1971. // return
  1972. // }
  1973. // this.ServeSuccessJSON(map[string]interface{}{
  1974. // "schedule": schedule,
  1975. // })
  1976. // }
  1977. //} else if errcode == nil {
  1978. //
  1979. // //先清除复制周的排班
  1980. // errcode := service.UpdatePatientSchedule(orgId, copy_startime, copy_endtime)
  1981. // fmt.Println(errcode)
  1982. // for _, item := range schedules {
  1983. // //fmt.Println(item.StartTime+604800)
  1984. // //礼拜1
  1985. // if item.ScheduleWeek == 1 {
  1986. // item.ScheduleDate = copy_startime
  1987. // }
  1988. // if item.ScheduleWeek == 2 {
  1989. // item.ScheduleDate = copy_startime + 86400
  1990. // }
  1991. // if item.ScheduleWeek == 3 {
  1992. // item.ScheduleDate = copy_startime + 172800
  1993. // }
  1994. // if item.ScheduleWeek == 4 {
  1995. // item.ScheduleDate = copy_startime + 259200
  1996. // }
  1997. // if item.ScheduleWeek == 5 {
  1998. // item.ScheduleDate = copy_startime + 345600
  1999. // }
  2000. //
  2001. // if item.ScheduleWeek == 6 {
  2002. // item.ScheduleDate = copy_startime + 432000
  2003. // }
  2004. // //礼拜天
  2005. // if item.ScheduleWeek == 0 {
  2006. // item.ScheduleDate = copy_endtime
  2007. // }
  2008. // schedule := models.XtSchedule{
  2009. // UserOrgId: item.UserOrgId,
  2010. // PartitionId: item.PartitionId,
  2011. // BedId: item.BedId,
  2012. // PatientId: item.PatientId,
  2013. // ScheduleDate: item.ScheduleDate,
  2014. // ScheduleType: item.ScheduleType,
  2015. // ScheduleWeek: item.ScheduleWeek,
  2016. // ModeId: item.ModeId,
  2017. // Status: 1,
  2018. // CreatedTime: time.Now().Unix(),
  2019. // }
  2020. //
  2021. // err := service.AddPatientSchedule(&schedule)
  2022. // if err != nil {
  2023. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2024. // return
  2025. // }
  2026. // this.ServeSuccessJSON(map[string]interface{}{
  2027. // "schedule": schedule,
  2028. // })
  2029. // }
  2030. //}
  2031. }
  2032. func (this *ScheduleApiController) SaveRemindPrint() {
  2033. id, _ := this.GetInt64("id")
  2034. anticoagulants, _ := this.GetInt64("anticoagulant")
  2035. anticoagulant_zongliang, _ := this.GetInt64("anticoagulant_zongliang")
  2036. classes, _ := this.GetInt64("classes")
  2037. dialyzers, _ := this.GetInt64("dialyzers")
  2038. doctor_advice, _ := this.GetInt64("doctor_advice")
  2039. mode, _ := this.GetInt64("mode")
  2040. name, _ := this.GetInt64("name")
  2041. number, _ := this.GetInt64("number")
  2042. perfusion_apparatus, _ := this.GetInt64("perfusion_apparatus")
  2043. prescription_status, _ := this.GetInt64("prescription_status")
  2044. week, _ := this.GetInt64("week")
  2045. zone, _ := this.GetInt64("zone")
  2046. adminUserInfo := this.GetAdminUserInfo()
  2047. orgId := adminUserInfo.CurrentOrgId
  2048. setting := models.XtRemindPrintSetting{
  2049. Anticoagulant: anticoagulants,
  2050. Classes: classes,
  2051. AnticoagulantZongliang: anticoagulant_zongliang,
  2052. Dialyzers: dialyzers,
  2053. DoctorAdvice: doctor_advice,
  2054. Mode: mode,
  2055. Name: name,
  2056. Number: number,
  2057. PerfusionApparatus: perfusion_apparatus,
  2058. PrescriptionStatus: prescription_status,
  2059. Week: week,
  2060. Zone: zone,
  2061. UserOrgId: orgId,
  2062. Status: 1,
  2063. Ctime: time.Now().Unix(),
  2064. }
  2065. _, errcode := service.GetSettingById(id)
  2066. if errcode == gorm.ErrRecordNotFound {
  2067. err := service.CreateSetting(&setting)
  2068. if err != nil {
  2069. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2070. return
  2071. }
  2072. this.ServeSuccessJSON(map[string]interface{}{
  2073. "setting": setting,
  2074. })
  2075. } else if errcode == nil {
  2076. err := service.UpdatedRemindPrint(&setting, id)
  2077. if err != nil {
  2078. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2079. return
  2080. }
  2081. this.ServeSuccessJSON(map[string]interface{}{
  2082. "setting": setting,
  2083. })
  2084. }
  2085. }
  2086. func (this *ScheduleApiController) GetRemindPrintList() {
  2087. adminUserInfo := this.GetAdminUserInfo()
  2088. orgId := adminUserInfo.CurrentOrgId
  2089. list, err := service.GetRemindPrintList(orgId)
  2090. if err != nil {
  2091. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2092. return
  2093. }
  2094. this.ServeSuccessJSON(map[string]interface{}{
  2095. "list": list,
  2096. })
  2097. }
  2098. func (this *ScheduleApiController) GetBloodScheduleList() {
  2099. week_type, _ := this.GetInt64("week_type", -1)
  2100. week_time, _ := this.GetInt64("week_time")
  2101. zones := this.GetString("zone")
  2102. zone := strings.Split(zones, ",")
  2103. thisTime := time.Now()
  2104. weekDay := int(thisTime.Weekday())
  2105. if weekDay == 0 {
  2106. weekDay = 7
  2107. }
  2108. weekEnd := 7 - weekDay
  2109. weekStart := weekEnd - 6
  2110. weekTitle := make([]string, 0)
  2111. days := make([]string, 0)
  2112. for index := weekStart; index <= weekEnd; index++ {
  2113. theDay := thisTime.AddDate(0, 0, index)
  2114. indexYear, indexMonthTime, indexDay := theDay.Date()
  2115. indexMonth := int(indexMonthTime)
  2116. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  2117. weekTitle = append(weekTitle, indexWeek)
  2118. days = append(days, theDay.Format("2006-01-02"))
  2119. }
  2120. fmt.Println(days)
  2121. var targetDayStr string
  2122. var startTime string
  2123. switch week_type {
  2124. case 0:
  2125. startTime = days[0]
  2126. targetDayStr = days[6]
  2127. break
  2128. case 1:
  2129. targetDayStr = days[0]
  2130. break
  2131. case 2:
  2132. targetDayStr = days[1]
  2133. break
  2134. case 3:
  2135. targetDayStr = days[2]
  2136. break
  2137. case 4:
  2138. targetDayStr = days[3]
  2139. break
  2140. case 5:
  2141. targetDayStr = days[4]
  2142. break
  2143. case 6:
  2144. targetDayStr = days[5]
  2145. break
  2146. case 7:
  2147. targetDayStr = days[6]
  2148. break
  2149. }
  2150. targetDay, parseErr := utils.ParseTimeStringToTime("2006-01-02", targetDayStr)
  2151. if parseErr != nil {
  2152. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2153. return
  2154. }
  2155. orgId := this.GetAdminUserInfo().CurrentOrgId
  2156. if week_type > 0 {
  2157. list, err := service.GetWeekDayScheduleByIdThee(orgId, targetDay.Unix(), week_time, zone)
  2158. if err != nil {
  2159. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2160. return
  2161. }
  2162. this.ServeSuccessJSON(map[string]interface{}{
  2163. "list": list,
  2164. "day": targetDayStr,
  2165. })
  2166. }
  2167. if week_type == 0 {
  2168. startDate, _ := utils.ParseTimeStringToTime("2006-01-02", startTime)
  2169. list, err := service.GetWeekDayScheduleByIdTwo(orgId, targetDay.Unix(), week_time, startDate.Unix(), zone)
  2170. if err != nil {
  2171. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2172. return
  2173. }
  2174. this.ServeSuccessJSON(map[string]interface{}{
  2175. "list": list,
  2176. "day": targetDayStr,
  2177. })
  2178. }
  2179. }
  2180. func (this *ScheduleApiController) GetPrintList() {
  2181. adminUserInfo := this.GetAdminUserInfo()
  2182. orgId := adminUserInfo.CurrentOrgId
  2183. list, err := service.GetRemindPrintList(orgId)
  2184. if err != nil {
  2185. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2186. return
  2187. }
  2188. this.ServeSuccessJSON(map[string]interface{}{
  2189. "list": list,
  2190. })
  2191. }
  2192. func (this *ScheduleApiController) GetAllZoneList() {
  2193. adminUserInfo := this.GetAdminUserInfo()
  2194. orgId := adminUserInfo.CurrentOrgId
  2195. zoneList, err := service.GetAllZoneOne(orgId)
  2196. if err != nil {
  2197. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2198. return
  2199. }
  2200. this.ServeSuccessJSON(map[string]interface{}{
  2201. "zoneList": zoneList,
  2202. })
  2203. }
  2204. func (this *ScheduleApiController) GetPatientScheduleCount() {
  2205. patitionIdStr := this.GetString("partition_id")
  2206. week, _ := this.GetInt64("weekTime", 0) //1:last, 2:this 3:next 4 nextTwo
  2207. ids := strings.Split(patitionIdStr, ",")
  2208. adminUserInfo := this.GetAdminUserInfo()
  2209. orgId := adminUserInfo.CurrentOrgId
  2210. thisTime := time.Now()
  2211. weekDay := int(thisTime.Weekday())
  2212. if week < 1 || week > 4 {
  2213. week = 2
  2214. }
  2215. if week == 1 {
  2216. thisTime = thisTime.AddDate(0, 0, -7)
  2217. } else if week == 3 {
  2218. thisTime = thisTime.AddDate(0, 0, 7)
  2219. } else if week == 4 {
  2220. thisTime = thisTime.AddDate(0, 0, 14)
  2221. }
  2222. if weekDay == 0 {
  2223. weekDay = 7
  2224. }
  2225. weekEnd := 7 - weekDay
  2226. weekStart := weekEnd - 6
  2227. weekTitle := make([]string, 0)
  2228. days := make([]string, 0)
  2229. for index := weekStart; index <= weekEnd; index++ {
  2230. theDay := thisTime.AddDate(0, 0, index)
  2231. indexYear, indexMonthTime, indexDay := theDay.Date()
  2232. indexMonth := int(indexMonthTime)
  2233. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  2234. weekTitle = append(weekTitle, indexWeek)
  2235. days = append(days, theDay.Format("2006-01-02"))
  2236. }
  2237. weekStartDay := thisTime.AddDate(0, 0, weekStart)
  2238. weekEndDay := thisTime.AddDate(0, 0, weekEnd)
  2239. weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
  2240. weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
  2241. timeLayout := "2006-01-02 15:04:05"
  2242. loc, _ := time.LoadLocation("Local")
  2243. theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
  2244. theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
  2245. weekStartPoint := theStarTime.Unix()
  2246. weekEndPoint := theEndTime.Unix()
  2247. fmt.Println("startTime222222222222222", weekStartPoint)
  2248. fmt.Println("endtime33333333333333", weekEndPoint)
  2249. list, err := service.GetPatientScheduleCount(orgId, weekStartPoint, weekEndPoint, ids)
  2250. _, total, _ := service.GetTotalBedNumber(orgId, ids)
  2251. if err != nil {
  2252. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2253. return
  2254. }
  2255. this.ServeSuccessJSON(map[string]interface{}{
  2256. "list": list,
  2257. "total": total,
  2258. })
  2259. }
  2260. func (c *ScheduleApiController) GetWeekPanelsOne() {
  2261. data, _ := c.GetInt64("data", 1)
  2262. patitionIdStr := c.GetString("patitionid")
  2263. ids := strings.Split(patitionIdStr, ",")
  2264. adminInfo := c.GetAdminUserInfo()
  2265. thisTime := time.Now()
  2266. year, monthTime, day := thisTime.Date()
  2267. month := int(monthTime)
  2268. _, theWeek := thisTime.ISOWeek()
  2269. weekDay := int(thisTime.Weekday())
  2270. if weekDay == 0 {
  2271. weekDay = 7
  2272. }
  2273. weekEnd := 7 - weekDay
  2274. weekStart := weekEnd - 6
  2275. weekDays := make([]string, 0)
  2276. for index := weekStart; index <= weekEnd; index++ {
  2277. theDay := thisTime.AddDate(0, 0, index)
  2278. indexYear, indexMonthTime, indexDay := theDay.Date()
  2279. indexMonth := int(indexMonthTime)
  2280. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  2281. weekDays = append(weekDays, indexWeek)
  2282. }
  2283. returnData := map[string]interface{}{
  2284. "year": year,
  2285. "month": month,
  2286. "day": day,
  2287. "theWeek": theWeek,
  2288. "weekDay": weekDay,
  2289. "weekDays": weekDays,
  2290. }
  2291. if data == 1 {
  2292. partitions, _ := service.GetSchedulePartitionPanelTwo(adminInfo.CurrentOrgId, ids)
  2293. returnData["partitions"] = partitions
  2294. }
  2295. c.ServeSuccessJSON(returnData)
  2296. return
  2297. }
  2298. func (c *ScheduleApiController) GetScheduleOne() {
  2299. week, _ := c.GetInt64("weekTime", 0) //1:last, 2:this 3:next 4 nextTwo
  2300. patitionIdStr := c.GetString("patitionid")
  2301. ids := strings.Split(patitionIdStr, ",")
  2302. fmt.Println("patitonStr", ids)
  2303. schedule_type, _ := c.GetInt64("schedule_type")
  2304. adminInfo := c.GetAdminUserInfo()
  2305. thisTime := time.Now()
  2306. today := thisTime.Format("2006-01-02")
  2307. if week < 1 || week > 4 {
  2308. week = 2
  2309. }
  2310. if week == 1 {
  2311. thisTime = thisTime.AddDate(0, 0, -7)
  2312. } else if week == 3 {
  2313. thisTime = thisTime.AddDate(0, 0, 7)
  2314. } else if week == 4 {
  2315. thisTime = thisTime.AddDate(0, 0, 14)
  2316. }
  2317. weekDay := int(thisTime.Weekday())
  2318. if weekDay == 0 {
  2319. weekDay = 7
  2320. }
  2321. weekEnd := 7 - weekDay
  2322. weekStart := weekEnd - 6
  2323. weekTitle := make([]string, 0)
  2324. days := make([]string, 0)
  2325. for index := weekStart; index <= weekEnd; index++ {
  2326. theDay := thisTime.AddDate(0, 0, index)
  2327. indexYear, indexMonthTime, indexDay := theDay.Date()
  2328. indexMonth := int(indexMonthTime)
  2329. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  2330. weekTitle = append(weekTitle, indexWeek)
  2331. days = append(days, theDay.Format("2006-01-02"))
  2332. }
  2333. weekStartDay := thisTime.AddDate(0, 0, weekStart)
  2334. weekEndDay := thisTime.AddDate(0, 0, weekEnd)
  2335. weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
  2336. weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
  2337. timeLayout := "2006-01-02 15:04:05"
  2338. loc, _ := time.LoadLocation("Local")
  2339. theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
  2340. theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
  2341. weekStartPoint := theStarTime.Unix()
  2342. weekEndPoint := theEndTime.Unix()
  2343. schdules, _ := service.GetWeekScheduleTwo(adminInfo.CurrentOrgId, weekStartPoint, weekEndPoint, ids, schedule_type)
  2344. c.ServeSuccessJSON(map[string]interface{}{
  2345. "days": days,
  2346. "weekTitle": weekTitle,
  2347. "schdules": schdules,
  2348. "today": today,
  2349. })
  2350. return
  2351. }
  2352. func (c *ScheduleApiController) SaveScheduleTemplate() {
  2353. template_id, _ := c.GetInt64("template_id")
  2354. orgId := c.GetAdminUserInfo().CurrentOrgId
  2355. template := models.ScheduleTemplate{
  2356. TemplateId: template_id,
  2357. UserOrgId: orgId,
  2358. Status: 1,
  2359. Ctime: time.Now().Unix(),
  2360. }
  2361. _, errcodes := service.GetScheudleTemplateById(orgId)
  2362. if errcodes == gorm.ErrRecordNotFound {
  2363. service.CreateXtscheduleTemplate(&template)
  2364. } else if errcodes == nil {
  2365. service.UpdateXtScheduleTemplate(&template, orgId)
  2366. }
  2367. c.ServeSuccessJSON(map[string]interface{}{
  2368. "template": template,
  2369. })
  2370. return
  2371. }
  2372. func (c *ScheduleApiController) GetScheduleTemplate() {
  2373. adminUserInfo := c.GetAdminUserInfo()
  2374. orgId := adminUserInfo.CurrentOrgId
  2375. template, _ := service.GetScheduleTemplate(orgId)
  2376. c.ServeSuccessJSON(map[string]interface{}{
  2377. "template": template,
  2378. })
  2379. return
  2380. }
  2381. func (c *ScheduleApiController) ChangeFuncPrint() {
  2382. adminUserInfo := c.GetAdminUserInfo()
  2383. orgId := adminUserInfo.CurrentOrgId
  2384. is_open, _ := c.GetInt64("is_open")
  2385. dataPrint := models.XtDataPrint{
  2386. UserOrgId: orgId,
  2387. IsOpen: is_open,
  2388. Status: 1,
  2389. Ctime: time.Now().Unix(),
  2390. }
  2391. _, errcode := service.GetDataPrintByOrgId(orgId)
  2392. fmt.Println("errcode222234444555556t66", errcode)
  2393. if errcode == gorm.ErrRecordNotFound {
  2394. service.CreateDataPrint(&dataPrint)
  2395. c.ServeSuccessJSON(map[string]interface{}{
  2396. "dataPrint": dataPrint,
  2397. })
  2398. return
  2399. } else if errcode == nil {
  2400. service.UpdteDataPrint(orgId, &dataPrint)
  2401. c.ServeSuccessJSON(map[string]interface{}{
  2402. "dataPrint": dataPrint,
  2403. })
  2404. return
  2405. }
  2406. }
  2407. func (c *ScheduleApiController) GetDataPrint() {
  2408. adminUserInfo := c.GetAdminUserInfo()
  2409. orgId := adminUserInfo.CurrentOrgId
  2410. dataPrint, _ := service.GetDataPrint(orgId)
  2411. c.ServeSuccessJSON(map[string]interface{}{
  2412. "dataPrint": dataPrint,
  2413. })
  2414. return
  2415. }
  2416. func (c *ScheduleApiController) GetNextWeekPanels() {
  2417. start_time, _ := c.GetInt64("start_time")
  2418. fmt.Println("start_time", start_time)
  2419. end_time, _ := c.GetInt64("end_time")
  2420. fmt.Println("end_time", end_time)
  2421. orgId := c.GetAdminUserInfo().CurrentOrgId
  2422. schedule, _ := service.GetNextWeekPanels(start_time, end_time, orgId)
  2423. c.ServeSuccessJSON(map[string]interface{}{
  2424. "schedule": schedule,
  2425. })
  2426. }
  2427. func (c *ScheduleApiController) SynchroSchedule() {
  2428. template_id, _ := c.GetInt64("template_id")
  2429. copy_startime, _ := c.GetInt64("copy_startime")
  2430. copy_endtime, _ := c.GetInt64("copy_endtime")
  2431. orgId := c.GetAdminUserInfo().CurrentOrgId
  2432. //根据模板ID获取模板数据
  2433. list, _ := service.GetTemplateListByTemplateId(template_id, orgId)
  2434. recordDateStr := time.Now().Format("2006-01-02")
  2435. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2436. nowtime := recordDate.Unix()
  2437. fmt.Println("今日时间", nowtime)
  2438. fmt.Println("后期日期", copy_startime)
  2439. var tuesday int64
  2440. var wednesday int64
  2441. var thursday int64
  2442. var friday int64
  2443. var saturday int64
  2444. //如果选择的开始日期大于当前日期
  2445. if copy_startime > nowtime {
  2446. //清空该时间段的所有排班数据
  2447. service.DeletePatientSchedule(copy_startime, copy_endtime, orgId)
  2448. tuesday = copy_startime + 86400
  2449. wednesday = copy_startime + 172800
  2450. thursday = copy_startime + 259200
  2451. friday = copy_startime + 345600
  2452. saturday = copy_startime + 432000
  2453. for _, item := range list {
  2454. if item.Weekday == 1 {
  2455. item.ScheduleDate = copy_startime
  2456. }
  2457. if item.Weekday == 2 {
  2458. item.ScheduleDate = tuesday
  2459. }
  2460. if item.Weekday == 3 {
  2461. item.ScheduleDate = wednesday
  2462. }
  2463. if item.Weekday == 4 {
  2464. item.ScheduleDate = thursday
  2465. }
  2466. if item.Weekday == 5 {
  2467. item.ScheduleDate = friday
  2468. }
  2469. if item.Weekday == 6 {
  2470. item.ScheduleDate = saturday
  2471. }
  2472. if item.Weekday == 7 {
  2473. item.ScheduleDate = copy_endtime
  2474. }
  2475. //根据床位号获取区号
  2476. number, _ := service.GetBedNumberById(item.DeviceNumberID, orgId)
  2477. item.ZoneId = number.ZoneID
  2478. }
  2479. for _, item := range list {
  2480. schedule := models.XtSchedule{
  2481. UserOrgId: orgId,
  2482. PartitionId: item.ZoneId,
  2483. BedId: item.DeviceNumberID,
  2484. PatientId: item.PatientID,
  2485. ScheduleDate: item.ScheduleDate,
  2486. ScheduleType: item.TimeType,
  2487. ScheduleWeek: item.Weekday,
  2488. ModeId: item.TreatMode,
  2489. Status: 1,
  2490. CreatedTime: time.Now().Unix(),
  2491. UpdatedTime: 0,
  2492. }
  2493. service.CreatePatientSchedule(&schedule)
  2494. }
  2495. }
  2496. //如果选择的日期小于当前日期,只同步今日以后的数据
  2497. if copy_startime <= nowtime {
  2498. //清空今日以后的数据
  2499. service.DeletePatientScheduleToday(nowtime, copy_endtime, orgId)
  2500. var tuesday int64
  2501. var wednesday int64
  2502. var thursday int64
  2503. var friday int64
  2504. var saturday int64
  2505. tuesday = copy_startime + 86400
  2506. wednesday = copy_startime + 172800
  2507. thursday = copy_startime + 259200
  2508. friday = copy_startime + 345600
  2509. saturday = copy_startime + 432000
  2510. for _, item := range list {
  2511. if item.Weekday == 1 {
  2512. item.ScheduleDate = copy_startime
  2513. }
  2514. if item.Weekday == 2 {
  2515. item.ScheduleDate = tuesday
  2516. }
  2517. if item.Weekday == 3 {
  2518. item.ScheduleDate = wednesday
  2519. }
  2520. if item.Weekday == 4 {
  2521. item.ScheduleDate = thursday
  2522. }
  2523. if item.Weekday == 5 {
  2524. item.ScheduleDate = friday
  2525. }
  2526. if item.Weekday == 6 {
  2527. item.ScheduleDate = saturday
  2528. }
  2529. if item.Weekday == 7 {
  2530. item.ScheduleDate = copy_endtime
  2531. }
  2532. //根据床位号获取区号
  2533. number, _ := service.GetBedNumberById(item.DeviceNumberID, orgId)
  2534. item.ZoneId = number.ZoneID
  2535. }
  2536. for _, item := range list {
  2537. // 同步今日以后的数据
  2538. if item.ScheduleDate > nowtime {
  2539. schedule := models.XtSchedule{
  2540. UserOrgId: orgId,
  2541. PartitionId: item.ZoneId,
  2542. BedId: item.DeviceNumberID,
  2543. PatientId: item.PatientID,
  2544. ScheduleDate: item.ScheduleDate,
  2545. ScheduleType: item.TimeType,
  2546. ScheduleWeek: item.Weekday,
  2547. ModeId: item.TreatMode,
  2548. Status: 1,
  2549. CreatedTime: time.Now().Unix(),
  2550. UpdatedTime: 0,
  2551. }
  2552. service.CreatePatientSchedule(&schedule)
  2553. }
  2554. }
  2555. }
  2556. returnData := make(map[string]interface{}, 0)
  2557. returnData["list"] = list
  2558. c.ServeSuccessJSON(returnData)
  2559. return
  2560. }
  2561. func (c *ScheduleApiController) GetPatientScheduleTempalate() {
  2562. orgId := c.GetAdminUserInfo().CurrentOrgId
  2563. tempalate, _ := service.GetPatientScheduleTempalate(orgId)
  2564. c.ServeSuccessJSON(map[string]interface{}{
  2565. "schedule": tempalate,
  2566. })
  2567. }
  2568. func (c *ScheduleApiController) GetSolutionSchedule() {
  2569. orgId := c.GetAdminUserInfo().CurrentOrgId
  2570. solution, _ := service.GetSolutionSchedule(orgId)
  2571. fmt.Println("solution33232323223233233323232332323232", solution)
  2572. c.ServeSuccessJSON(map[string]interface{}{
  2573. "solution": solution,
  2574. })
  2575. return
  2576. }