schedule_api_controller.go 88KB

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