schedule_api_controller.go 90KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943
  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. start_time := dataBody["start_time"].(string)
  823. end_time := dataBody["end_time"].(string)
  824. delete_type := int64(dataBody["delete_type"].(float64))
  825. fmt.Println("delete_type", delete_type)
  826. timeLayout := "2006-01-02"
  827. loc, _ := time.LoadLocation("Local")
  828. theTimeStart, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  829. theTimeEnd, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  830. fmt.Println("theTimeStart23232322332322323", theTimeStart.Unix())
  831. fmt.Println("theTimeStart23232322332322323", theTimeEnd.Unix())
  832. if dataBody["failed_schedule"] != nil || reflect.TypeOf(dataBody["failed_schedule"]).String() == "[]interface {}" {
  833. tempSchedule := dataBody["failed_schedule"].([]interface{})
  834. failed_total = len(tempSchedule)
  835. }
  836. if dataBody["schedule"] != nil || reflect.TypeOf(dataBody["schedule"]).String() == "[]interface {}" {
  837. tempSchedule := dataBody["schedule"].([]interface{})
  838. total_schedule = tempSchedule
  839. for _, schMap := range tempSchedule {
  840. schMapM := schMap.(map[string]interface{})
  841. var sch models.Schedule
  842. if schMapM["name"] == nil || reflect.TypeOf(schMapM["name"]).String() != "string" {
  843. utils.ErrorLog("name")
  844. return
  845. }
  846. name, _ := schMapM["name"].(string)
  847. fmt.Println(name)
  848. if len(name) == 0 { //名字为空则生成一条导入错误日志
  849. err_log := models.ExportErrLog{
  850. LogType: 2,
  851. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  852. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名不能为空",
  853. Status: 1,
  854. CreateTime: time.Now().Unix(),
  855. UpdateTime: time.Now().Unix(),
  856. ExportTime: export_time,
  857. }
  858. service.CreateExportErrLog(&err_log)
  859. continue
  860. } else {
  861. var patient []*models.Patients
  862. for _, item := range patients {
  863. if strings.Replace(item.Name, " ", "", -1) == name {
  864. patient = append(patient, item)
  865. }
  866. }
  867. if len(patient) == 0 { //错误日志
  868. err_log := models.ExportErrLog{
  869. LogType: 2,
  870. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  871. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列,患者姓名为\"" + name + "\"在系统中不存在,请在系统中添加该患者",
  872. Status: 1,
  873. CreateTime: time.Now().Unix(),
  874. UpdateTime: time.Now().Unix(),
  875. ExportTime: export_time,
  876. }
  877. service.CreateExportErrLog(&err_log)
  878. continue
  879. } else if len(patient) == 1 { //
  880. sch.PatientId = patient[0].ID
  881. } else if len(patient) > 1 { //出现同名的情况
  882. err_log := models.ExportErrLog{
  883. LogType: 2,
  884. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  885. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列" + "患者姓名为" + name + "在当前机构中存在重名,无法确定到具体患者",
  886. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列,患者姓名为\"" + name + "\"在在当前机构中存在重名,无法确定到具体患者",
  887. Status: 1,
  888. CreateTime: time.Now().Unix(),
  889. UpdateTime: time.Now().Unix(),
  890. ExportTime: export_time,
  891. }
  892. service.CreateExportErrLog(&err_log)
  893. continue
  894. }
  895. }
  896. if schMapM["schedule_type"] == nil && reflect.TypeOf(schMapM["schedule_type"]).String() != "float64" {
  897. utils.ErrorLog("schedule_type")
  898. return
  899. }
  900. schedule_type := int64(schMapM["schedule_type"].(float64))
  901. if schedule_type <= 0 { //班次格式有误,插入日志
  902. log := models.ExportLog{
  903. LogType: 2,
  904. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  905. TotalNum: int64(len(total_schedule) + failed_total),
  906. FailNum: 1 + int64(failed_total),
  907. SuccessNum: int64(len(schedules)),
  908. CreateTime: time.Now().Unix(),
  909. UpdateTime: time.Now().Unix(),
  910. ExportTime: export_time,
  911. Status: 1,
  912. }
  913. service.CreateExportLog(&log)
  914. err_log := models.ExportErrLog{
  915. LogType: 2,
  916. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  917. ErrMsg: "第2行第" + schMapM["row"].(string) + "列的班次格式有误",
  918. Status: 1,
  919. CreateTime: time.Now().Unix(),
  920. UpdateTime: time.Now().Unix(),
  921. ExportTime: export_time,
  922. }
  923. service.CreateExportErrLog(&err_log)
  924. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  925. return
  926. } else {
  927. sch.ScheduleType = schedule_type
  928. }
  929. if schMapM["partition_name"] == nil || reflect.TypeOf(schMapM["partition_name"]).String() != "string" {
  930. utils.ErrorLog("partition_name")
  931. return
  932. }
  933. partition_name, _ := schMapM["partition_name"].(string)
  934. if len(partition_name) == 0 { //分区为空
  935. log := models.ExportLog{
  936. LogType: 2,
  937. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  938. TotalNum: int64(len(total_schedule) + failed_total),
  939. FailNum: 1 + int64(failed_total),
  940. SuccessNum: int64(len(schedules)),
  941. CreateTime: time.Now().Unix(),
  942. UpdateTime: time.Now().Unix(),
  943. ExportTime: export_time,
  944. Status: 1,
  945. }
  946. service.CreateExportLog(&log)
  947. err_log := models.ExportErrLog{
  948. LogType: 2,
  949. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  950. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  951. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第1列所属的分区格式有误",
  952. Status: 1,
  953. CreateTime: time.Now().Unix(),
  954. UpdateTime: time.Now().Unix(),
  955. ExportTime: export_time,
  956. }
  957. service.CreateExportErrLog(&err_log)
  958. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  959. return
  960. } else {
  961. zone, err := service.FindDeviceZoneByName(partition_name, this.GetAdminUserInfo().CurrentOrgId)
  962. if err == nil {
  963. sch.PartitionId = zone.ID
  964. } else if err == gorm.ErrRecordNotFound { //查不到数据,插入错误日志
  965. log := models.ExportLog{
  966. LogType: 2,
  967. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  968. TotalNum: int64(len(total_schedule) + failed_total),
  969. FailNum: 1 + int64(failed_total),
  970. SuccessNum: int64(len(schedules)),
  971. CreateTime: time.Now().Unix(),
  972. UpdateTime: time.Now().Unix(),
  973. ExportTime: export_time,
  974. Status: 1,
  975. }
  976. service.CreateExportLog(&log)
  977. err_log := models.ExportErrLog{
  978. LogType: 2,
  979. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  980. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  981. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第1列所属的分区格式有误",
  982. Status: 1,
  983. CreateTime: time.Now().Unix(),
  984. UpdateTime: time.Now().Unix(),
  985. ExportTime: export_time,
  986. }
  987. service.CreateExportErrLog(&err_log)
  988. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  989. return
  990. }
  991. }
  992. if schMapM["device_number_name"] == nil || reflect.TypeOf(schMapM["device_number_name"]).String() != "string" {
  993. utils.ErrorLog("device_number_name")
  994. return
  995. }
  996. device_number_name, _ := schMapM["device_number_name"].(string)
  997. if len(device_number_name) == 0 { //分区为空
  998. log := models.ExportLog{
  999. LogType: 2,
  1000. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1001. TotalNum: int64(len(total_schedule) + failed_total),
  1002. FailNum: 1 + int64(failed_total),
  1003. SuccessNum: int64(len(schedules)),
  1004. CreateTime: time.Now().Unix(),
  1005. UpdateTime: time.Now().Unix(),
  1006. ExportTime: export_time,
  1007. Status: 1,
  1008. }
  1009. service.CreateExportLog(&log)
  1010. err_log := models.ExportErrLog{
  1011. LogType: 2,
  1012. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1013. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  1014. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
  1015. Status: 1,
  1016. CreateTime: time.Now().Unix(),
  1017. UpdateTime: time.Now().Unix(),
  1018. ExportTime: export_time,
  1019. }
  1020. service.CreateExportErrLog(&err_log)
  1021. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1022. return
  1023. } else {
  1024. device, err := service.FindDeviceByName(device_number_name, this.GetAdminUserInfo().CurrentOrgId, sch.PartitionId)
  1025. if err == nil {
  1026. if len(device) == 0 { //没查到数据,插入错误日志
  1027. log := models.ExportLog{
  1028. LogType: 2,
  1029. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1030. TotalNum: int64(len(total_schedule) + failed_total),
  1031. FailNum: 1 + int64(failed_total),
  1032. SuccessNum: int64(len(schedules)),
  1033. CreateTime: time.Now().Unix(),
  1034. UpdateTime: time.Now().Unix(),
  1035. ExportTime: export_time,
  1036. Status: 1,
  1037. }
  1038. service.CreateExportLog(&log)
  1039. err_log := models.ExportErrLog{
  1040. LogType: 2,
  1041. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1042. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
  1043. Status: 1,
  1044. CreateTime: time.Now().Unix(),
  1045. UpdateTime: time.Now().Unix(),
  1046. ExportTime: export_time,
  1047. }
  1048. service.CreateExportErrLog(&err_log)
  1049. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1050. return
  1051. } else if len(device) == 1 {
  1052. sch.BedId = device[0].ID
  1053. } else if len(device) > 1 { //出现重名,插入错误日志
  1054. log := models.ExportLog{
  1055. LogType: 2,
  1056. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1057. TotalNum: int64(len(total_schedule) + failed_total),
  1058. FailNum: 1 + int64(failed_total),
  1059. SuccessNum: int64(len(schedules)),
  1060. CreateTime: time.Now().Unix(),
  1061. UpdateTime: time.Now().Unix(),
  1062. ExportTime: export_time,
  1063. Status: 1,
  1064. }
  1065. service.CreateExportLog(&log)
  1066. err_log := models.ExportErrLog{
  1067. LogType: 2,
  1068. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1069. ErrMsg: "出现两个床位号相同的床位",
  1070. Status: 1,
  1071. CreateTime: time.Now().Unix(),
  1072. UpdateTime: time.Now().Unix(),
  1073. ExportTime: export_time,
  1074. }
  1075. service.CreateExportErrLog(&err_log)
  1076. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1077. return
  1078. }
  1079. }
  1080. }
  1081. if schMapM["schedule_week"] == nil || reflect.TypeOf(schMapM["schedule_week"]).String() != "string" {
  1082. utils.ErrorLog("schedule_week")
  1083. return
  1084. }
  1085. schedule_week, _ := schMapM["schedule_week"].(string)
  1086. if len(schedule_week) == 0 { //周几为空则生成一条导入错误日志
  1087. log := models.ExportLog{
  1088. LogType: 2,
  1089. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1090. TotalNum: int64(len(total_schedule) + failed_total),
  1091. FailNum: 1 + int64(failed_total),
  1092. SuccessNum: int64(len(schedules)),
  1093. CreateTime: time.Now().Unix(),
  1094. UpdateTime: time.Now().Unix(),
  1095. ExportTime: export_time,
  1096. Status: 1,
  1097. }
  1098. service.CreateExportLog(&log)
  1099. err_log := models.ExportErrLog{
  1100. LogType: 2,
  1101. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1102. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  1103. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  1104. Status: 1,
  1105. CreateTime: time.Now().Unix(),
  1106. UpdateTime: time.Now().Unix(),
  1107. ExportTime: export_time,
  1108. }
  1109. service.CreateExportErrLog(&err_log)
  1110. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1111. return
  1112. } else if schedule_week == "0" { //周几不符合格式则生成一条导入错误日志
  1113. log := models.ExportLog{
  1114. LogType: 2,
  1115. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1116. TotalNum: int64(len(total_schedule) + failed_total),
  1117. FailNum: 1 + int64(failed_total),
  1118. SuccessNum: int64(len(schedules)),
  1119. CreateTime: time.Now().Unix(),
  1120. UpdateTime: time.Now().Unix(),
  1121. ExportTime: export_time,
  1122. Status: 1,
  1123. }
  1124. service.CreateExportLog(&log)
  1125. err_log := models.ExportErrLog{
  1126. LogType: 2,
  1127. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1128. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  1129. Status: 1,
  1130. CreateTime: time.Now().Unix(),
  1131. UpdateTime: time.Now().Unix(),
  1132. ExportTime: export_time,
  1133. }
  1134. service.CreateExportErrLog(&err_log)
  1135. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1136. return
  1137. } else {
  1138. schedule_week, _ := strconv.ParseInt(schedule_week, 10, 64)
  1139. sch.ScheduleWeek = schedule_week
  1140. }
  1141. if schMapM["schedule_date"] == nil || reflect.TypeOf(schMapM["schedule_date"]).String() != "string" {
  1142. utils.ErrorLog("schedule_date")
  1143. return
  1144. }
  1145. schedule_date, _ := schMapM["schedule_date"].(string)
  1146. if len(schedule_date) == 0 { //周几为空则生成一条导入错误日志
  1147. log := models.ExportLog{
  1148. LogType: 2,
  1149. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1150. TotalNum: int64(len(total_schedule) + failed_total),
  1151. FailNum: 1 + int64(failed_total),
  1152. SuccessNum: int64(len(schedules)),
  1153. CreateTime: time.Now().Unix(),
  1154. UpdateTime: time.Now().Unix(),
  1155. ExportTime: export_time,
  1156. Status: 1,
  1157. }
  1158. service.CreateExportLog(&log)
  1159. err_log := models.ExportErrLog{
  1160. LogType: 2,
  1161. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1162. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  1163. Status: 1,
  1164. CreateTime: time.Now().Unix(),
  1165. UpdateTime: time.Now().Unix(),
  1166. ExportTime: export_time,
  1167. }
  1168. service.CreateExportErrLog(&err_log)
  1169. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1170. return
  1171. } else if schedule_date == "0" { //周几不符合格式则生成一条导入错误日志
  1172. log := models.ExportLog{
  1173. LogType: 2,
  1174. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1175. TotalNum: int64(len(total_schedule) + failed_total),
  1176. FailNum: 1 + int64(failed_total),
  1177. SuccessNum: int64(len(schedules)),
  1178. CreateTime: time.Now().Unix(),
  1179. UpdateTime: time.Now().Unix(),
  1180. ExportTime: export_time,
  1181. Status: 1,
  1182. }
  1183. service.CreateExportLog(&log)
  1184. err_log := models.ExportErrLog{
  1185. LogType: 2,
  1186. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1187. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  1188. Status: 1,
  1189. CreateTime: time.Now().Unix(),
  1190. UpdateTime: time.Now().Unix(),
  1191. ExportTime: export_time,
  1192. }
  1193. service.CreateExportErrLog(&err_log)
  1194. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1195. return
  1196. } else {
  1197. date, _ := utils.ParseTimeStringToTime("2006-01-02", schedule_date)
  1198. sch.ScheduleDate = date.Unix()
  1199. }
  1200. sch.CreatedTime = time.Now().Unix()
  1201. sch.UpdatedTime = time.Now().Unix()
  1202. sch.ModeId = 1
  1203. sch.Status = 1
  1204. sch.UserOrgId = this.GetAdminUserInfo().CurrentOrgId
  1205. sch.IsExport = 1
  1206. schedules = append(schedules, &sch)
  1207. }
  1208. errLogs, _ := service.FindSchedualExportLog(this.GetAdminUserInfo().CurrentOrgId, export_time)
  1209. if len(schedules) > 0 {
  1210. schedule_date := time.Now().Format("2006-01-02")
  1211. date, _ := utils.ParseTimeStringToTime("2006-01-02", schedule_date)
  1212. clear_schedule_date := date.Unix() //根据日期去清除,该日期未来的排班数据
  1213. // err := service.UpdateScheduleStatus(clear_schedule_date, this.GetAdminUserInfo().CurrentOrgId)
  1214. if err == nil {
  1215. //清除该机构的排班
  1216. //if delete_type == 1 {
  1217. // service.ModeScheduleByTimeOne(theTimeStart.Unix(), theTimeEnd.Unix(), this.GetAdminUserInfo().CurrentOrgId)
  1218. //}
  1219. //if delete_type == 0 {
  1220. // service.ModeScheduleByTime(theTimeStart.Unix(), theTimeEnd.Unix(), this.GetAdminUserInfo().CurrentOrgId)
  1221. //}
  1222. for _, item := range schedules {
  1223. // fmt.Println("clear_schedule_date3232232332232332232323",clear_schedule_date)
  1224. if item.ScheduleDate > clear_schedule_date {
  1225. //删除当天的以后日期排班
  1226. // service.DeleteScheduleExist(item.ScheduleDate, item.UserOrgId)
  1227. //查找当天日期是否存在
  1228. _, errcode := service.GetTodayScheduleIsExistOne(item.PatientId, item.ScheduleDate, item.UserOrgId)
  1229. if errcode == gorm.ErrRecordNotFound {
  1230. //清除当天该床位已有的患者
  1231. service.ModeFyScheduleById(item.ScheduleDate, item.BedId, item.ScheduleType)
  1232. service.CreateSchedule(item)
  1233. } else if errcode == nil {
  1234. schedule := models.XtSchedule{
  1235. PartitionId: item.PartitionId,
  1236. BedId: item.BedId,
  1237. PatientId: item.PatientId,
  1238. ScheduleDate: item.ScheduleDate,
  1239. ScheduleType: item.ScheduleType,
  1240. ScheduleWeek: item.ScheduleWeek,
  1241. ModeId: item.ModeId,
  1242. Status: 1,
  1243. }
  1244. service.UpdateScheduleByOrgIdOne(item.PatientId, item.ScheduleDate, item.UserOrgId, &schedule)
  1245. }
  1246. }
  1247. }
  1248. log := models.ExportLog{
  1249. LogType: 2,
  1250. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1251. TotalNum: int64(len(total_schedule) + failed_total),
  1252. FailNum: int64(len(errLogs) + failed_total),
  1253. SuccessNum: int64(len(schedules)),
  1254. CreateTime: time.Now().Unix(),
  1255. UpdateTime: time.Now().Unix(),
  1256. ExportTime: export_time,
  1257. Status: 1,
  1258. }
  1259. service.CreateExportLog(&log)
  1260. if failed_total > 0 {
  1261. err_log := models.ExportErrLog{
  1262. LogType: 2,
  1263. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1264. ErrMsg: "当前日期(" + time.Now().Format("2006-01-02") + " " + GetWeekString(time.Now().Weekday().String()) +
  1265. ")及以前的排班数据" + strconv.FormatInt(int64(failed_total), 10) + "条,不执行导入",
  1266. Status: 1,
  1267. CreateTime: time.Now().Unix(),
  1268. UpdateTime: time.Now().Unix(),
  1269. ExportTime: export_time,
  1270. }
  1271. service.CreateExportErrLog(&err_log)
  1272. }
  1273. this.ServeSuccessJSON(map[string]interface{}{
  1274. "msg": "导入成功",
  1275. "total_num": len(total_schedule) + failed_total,
  1276. "success_num": len(schedules),
  1277. "fail_num": int64(len(errLogs)),
  1278. })
  1279. } else {
  1280. log := models.ExportLog{
  1281. LogType: 2,
  1282. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1283. TotalNum: int64(len(total_schedule) + failed_total),
  1284. FailNum: int64(len(errLogs) + failed_total),
  1285. SuccessNum: int64(len(schedules)),
  1286. CreateTime: time.Now().Unix(),
  1287. UpdateTime: time.Now().Unix(),
  1288. ExportTime: export_time,
  1289. Status: 1,
  1290. }
  1291. service.CreateExportLog(&log)
  1292. if failed_total > 0 {
  1293. err_log := models.ExportErrLog{
  1294. LogType: 2,
  1295. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1296. ErrMsg: "当前日期(" + time.Now().Format("2006-01-02") + " " + GetWeekString(time.Now().Weekday().String()) +
  1297. ")及以前的排班数据" + strconv.FormatInt(int64(failed_total), 10) + "条,不执行导入",
  1298. Status: 1,
  1299. CreateTime: time.Now().Unix(),
  1300. UpdateTime: time.Now().Unix(),
  1301. ExportTime: export_time,
  1302. }
  1303. service.CreateExportErrLog(&err_log)
  1304. }
  1305. this.ServeSuccessJSON(map[string]interface{}{
  1306. "msg": "导入成功",
  1307. "total_num": len(total_schedule),
  1308. "success_num": len(schedules),
  1309. "fail_num": int64(len(errLogs)),
  1310. })
  1311. }
  1312. } else {
  1313. log := models.ExportLog{
  1314. LogType: 2,
  1315. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1316. TotalNum: int64(len(total_schedule) + failed_total),
  1317. FailNum: int64(len(errLogs) + failed_total),
  1318. SuccessNum: int64(len(schedules)),
  1319. CreateTime: time.Now().Unix(),
  1320. UpdateTime: time.Now().Unix(),
  1321. ExportTime: export_time,
  1322. Status: 1,
  1323. }
  1324. service.CreateExportLog(&log)
  1325. if failed_total > 0 {
  1326. err_log := models.ExportErrLog{
  1327. LogType: 2,
  1328. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1329. ErrMsg: "当前日期(" + time.Now().Format("2006-01-02") + " " + GetWeekString(time.Now().Weekday().String()) +
  1330. ")及以前的排班数据" + strconv.FormatInt(int64(failed_total), 10) + "条,不执行导入",
  1331. Status: 1,
  1332. CreateTime: time.Now().Unix(),
  1333. UpdateTime: time.Now().Unix(),
  1334. ExportTime: export_time,
  1335. }
  1336. service.CreateExportErrLog(&err_log)
  1337. }
  1338. this.ServeSuccessJSON(map[string]interface{}{
  1339. "msg": "导入成功",
  1340. "total_num": len(total_schedule),
  1341. "success_num": len(schedules),
  1342. "fail_num": int64(len(errLogs)),
  1343. })
  1344. }
  1345. }
  1346. }
  1347. func (this *ScheduleApiController) ExportScheduleTemplate() {
  1348. dataBody := make(map[string]interface{}, 0)
  1349. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1350. if err != nil {
  1351. utils.ErrorLog(err.Error())
  1352. return
  1353. }
  1354. utils.ErrorLog("%v", dataBody)
  1355. export_time := time.Now().Unix()
  1356. var schedules []*models.PatientScheduleTemplateItem
  1357. var total_schedule []interface{}
  1358. patients, _, _ := service.GetAllPatientList(this.GetAdminUserInfo().CurrentOrgId)
  1359. if dataBody["schedule"] != nil || reflect.TypeOf(dataBody["schedule"]).String() == "[]interface {}" {
  1360. tempSchedule := dataBody["schedule"].([]interface{})
  1361. total_schedule = tempSchedule
  1362. for _, schMap := range tempSchedule {
  1363. schMapM := schMap.(map[string]interface{})
  1364. var sch models.PatientScheduleTemplateItem
  1365. if schMapM["name"] == nil || reflect.TypeOf(schMapM["name"]).String() != "string" {
  1366. utils.ErrorLog("name")
  1367. return
  1368. }
  1369. name, _ := schMapM["name"].(string)
  1370. fmt.Println(name)
  1371. if len(name) == 0 { //名字为空则生成一条导入错误日志
  1372. err_log := models.ExportErrLog{
  1373. LogType: 3,
  1374. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1375. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名不能为空",
  1376. Status: 1,
  1377. CreateTime: time.Now().Unix(),
  1378. UpdateTime: time.Now().Unix(),
  1379. ExportTime: export_time,
  1380. }
  1381. service.CreateExportErrLog(&err_log)
  1382. continue
  1383. } else {
  1384. var patient []*models.Patients
  1385. for _, item := range patients {
  1386. if strings.Replace(item.Name, " ", "", -1) == name {
  1387. patient = append(patient, item)
  1388. }
  1389. }
  1390. if len(patient) == 0 { //错误日志
  1391. err_log := models.ExportErrLog{
  1392. LogType: 3,
  1393. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1394. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名在系统中不存在,请在系统中添加该病人",
  1395. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列患者姓名为\"" + name + "\"在系统中不存在,请在系统中添加该患者",
  1396. Status: 1,
  1397. CreateTime: time.Now().Unix(),
  1398. UpdateTime: time.Now().Unix(),
  1399. ExportTime: export_time,
  1400. }
  1401. service.CreateExportErrLog(&err_log)
  1402. continue
  1403. } else if len(patient) == 1 { //
  1404. sch.PatientID = patient[0].ID
  1405. } else if len(patient) > 1 { //出现同名的情况
  1406. err_log := models.ExportErrLog{
  1407. LogType: 3,
  1408. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1409. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列" + "患者姓名为" + name + "在当前机构中存在重名,无法确定到具体患者",
  1410. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列患者姓名为\"" + name + "\"在当前机构中存在重名,无法确定到具体患者",
  1411. Status: 1,
  1412. CreateTime: time.Now().Unix(),
  1413. UpdateTime: time.Now().Unix(),
  1414. ExportTime: export_time,
  1415. }
  1416. service.CreateExportErrLog(&err_log)
  1417. continue
  1418. }
  1419. }
  1420. if schMapM["schedule_type"] == nil && reflect.TypeOf(schMapM["schedule_type"]).String() != "float64" {
  1421. utils.ErrorLog("schedule_type")
  1422. return
  1423. }
  1424. schedule_type := int64(schMapM["schedule_type"].(float64))
  1425. if schedule_type <= 0 { //班次格式有误,插入日志
  1426. log := models.ExportLog{
  1427. LogType: 3,
  1428. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1429. TotalNum: int64(len(total_schedule)),
  1430. FailNum: 1,
  1431. SuccessNum: int64(len(schedules)),
  1432. CreateTime: time.Now().Unix(),
  1433. UpdateTime: time.Now().Unix(),
  1434. ExportTime: export_time,
  1435. Status: 1,
  1436. }
  1437. service.CreateExportLog(&log)
  1438. err_log := models.ExportErrLog{
  1439. LogType: 3,
  1440. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1441. ErrMsg: "第2行第" + schMapM["row"].(string) + "列的班次格式有误",
  1442. Status: 1,
  1443. CreateTime: time.Now().Unix(),
  1444. UpdateTime: time.Now().Unix(),
  1445. ExportTime: export_time,
  1446. }
  1447. service.CreateExportErrLog(&err_log)
  1448. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1449. return
  1450. } else {
  1451. sch.TimeType = int8(schedule_type)
  1452. }
  1453. if schMapM["template_id"] == nil && reflect.TypeOf(schMapM["template_id"]).String() != "float64" {
  1454. utils.ErrorLog("template_id")
  1455. return
  1456. }
  1457. template_id := int64(schMapM["template_id"].(float64))
  1458. sch.TemplateID = template_id
  1459. if schMapM["device_number_name"] == nil || reflect.TypeOf(schMapM["device_number_name"]).String() != "string" {
  1460. utils.ErrorLog("device_number_name")
  1461. return
  1462. }
  1463. partition_name, _ := schMapM["partition_name"].(string)
  1464. zone, _ := service.FindDeviceZoneByName(partition_name, this.GetAdminUserInfo().CurrentOrgId)
  1465. device_number_name, _ := schMapM["device_number_name"].(string)
  1466. if len(device_number_name) == 0 { //分区为空
  1467. log := models.ExportLog{
  1468. LogType: 3,
  1469. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1470. TotalNum: int64(len(total_schedule)),
  1471. FailNum: 1,
  1472. SuccessNum: int64(len(schedules)),
  1473. CreateTime: time.Now().Unix(),
  1474. UpdateTime: time.Now().Unix(),
  1475. ExportTime: export_time,
  1476. Status: 1,
  1477. }
  1478. service.CreateExportLog(&log)
  1479. err_log := models.ExportErrLog{
  1480. LogType: 3,
  1481. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1482. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  1483. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
  1484. Status: 1,
  1485. CreateTime: time.Now().Unix(),
  1486. UpdateTime: time.Now().Unix(),
  1487. ExportTime: export_time,
  1488. }
  1489. service.CreateExportErrLog(&err_log)
  1490. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1491. return
  1492. } else {
  1493. device, err := service.FindDeviceByNameTwo(device_number_name, this.GetAdminUserInfo().CurrentOrgId, zone.ID)
  1494. if err == nil {
  1495. if len(device) == 0 { //没查到数据,插入错误日志
  1496. log := models.ExportLog{
  1497. LogType: 3,
  1498. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1499. TotalNum: int64(len(total_schedule)),
  1500. FailNum: 1,
  1501. SuccessNum: int64(len(schedules)),
  1502. CreateTime: time.Now().Unix(),
  1503. UpdateTime: time.Now().Unix(),
  1504. ExportTime: export_time,
  1505. Status: 1,
  1506. }
  1507. service.CreateExportLog(&log)
  1508. err_log := models.ExportErrLog{
  1509. LogType: 3,
  1510. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1511. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
  1512. Status: 1,
  1513. CreateTime: time.Now().Unix(),
  1514. UpdateTime: time.Now().Unix(),
  1515. ExportTime: export_time,
  1516. }
  1517. service.CreateExportErrLog(&err_log)
  1518. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1519. return
  1520. } else if len(device) == 1 {
  1521. sch.DeviceNumberID = device[0].ID
  1522. } else if len(device) > 1 { //出现重名,插入错误日志
  1523. log := models.ExportLog{
  1524. LogType: 3,
  1525. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1526. TotalNum: int64(len(total_schedule)),
  1527. FailNum: 1,
  1528. SuccessNum: int64(len(schedules)),
  1529. CreateTime: time.Now().Unix(),
  1530. UpdateTime: time.Now().Unix(),
  1531. ExportTime: export_time,
  1532. Status: 1,
  1533. }
  1534. service.CreateExportLog(&log)
  1535. err_log := models.ExportErrLog{
  1536. LogType: 3,
  1537. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1538. ErrMsg: "出现两个床位号相同的床位",
  1539. Status: 1,
  1540. CreateTime: time.Now().Unix(),
  1541. UpdateTime: time.Now().Unix(),
  1542. ExportTime: export_time,
  1543. }
  1544. service.CreateExportErrLog(&err_log)
  1545. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1546. return
  1547. }
  1548. }
  1549. }
  1550. if schMapM["schedule_week"] == nil || reflect.TypeOf(schMapM["schedule_week"]).String() != "string" {
  1551. utils.ErrorLog("schedule_week")
  1552. return
  1553. }
  1554. schedule_week, _ := schMapM["schedule_week"].(string)
  1555. if len(schedule_week) == 0 { //周几为空则生成一条导入错误日志
  1556. log := models.ExportLog{
  1557. LogType: 3,
  1558. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1559. TotalNum: int64(len(total_schedule)),
  1560. FailNum: 1,
  1561. SuccessNum: int64(len(schedules)),
  1562. CreateTime: time.Now().Unix(),
  1563. UpdateTime: time.Now().Unix(),
  1564. ExportTime: export_time,
  1565. Status: 1,
  1566. }
  1567. service.CreateExportLog(&log)
  1568. err_log := models.ExportErrLog{
  1569. LogType: 3,
  1570. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1571. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  1572. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  1573. Status: 1,
  1574. CreateTime: time.Now().Unix(),
  1575. UpdateTime: time.Now().Unix(),
  1576. ExportTime: export_time,
  1577. }
  1578. service.CreateExportErrLog(&err_log)
  1579. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1580. return
  1581. } else if schedule_week == "0" { //周几不符合格式则生成一条导入错误日志
  1582. log := models.ExportLog{
  1583. LogType: 3,
  1584. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1585. TotalNum: int64(len(total_schedule)),
  1586. FailNum: 1,
  1587. SuccessNum: int64(len(schedules)),
  1588. CreateTime: time.Now().Unix(),
  1589. UpdateTime: time.Now().Unix(),
  1590. ExportTime: export_time,
  1591. Status: 1,
  1592. }
  1593. service.CreateExportLog(&log)
  1594. err_log := models.ExportErrLog{
  1595. LogType: 3,
  1596. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1597. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  1598. Status: 1,
  1599. CreateTime: time.Now().Unix(),
  1600. UpdateTime: time.Now().Unix(),
  1601. ExportTime: export_time,
  1602. }
  1603. service.CreateExportErrLog(&err_log)
  1604. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1605. return
  1606. } else {
  1607. schedule_week, _ := strconv.ParseInt(schedule_week, 10, 64)
  1608. sch.Weekday = int8(schedule_week)
  1609. }
  1610. sch.CreateTime = time.Now().Unix()
  1611. sch.ModifyTime = time.Now().Unix()
  1612. sch.TreatMode = 1
  1613. sch.Status = 1
  1614. sch.OrgID = this.GetAdminUserInfo().CurrentOrgId
  1615. sch.IsExport = 1
  1616. schedules = append(schedules, &sch)
  1617. }
  1618. errLogs, _ := service.FindSchedualTemplateExportLog(this.GetAdminUserInfo().CurrentOrgId, export_time)
  1619. if len(schedules) > 0 {
  1620. err := service.UpdateScheduleTemplateStatus(this.GetAdminUserInfo().CurrentOrgId)
  1621. if err == nil {
  1622. for _, item := range schedules {
  1623. service.CreateScheduleTemplate(item)
  1624. }
  1625. log := models.ExportLog{
  1626. LogType: 3,
  1627. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1628. TotalNum: int64(len(total_schedule)),
  1629. FailNum: int64(len(errLogs)),
  1630. SuccessNum: int64(len(schedules)),
  1631. CreateTime: time.Now().Unix(),
  1632. UpdateTime: time.Now().Unix(),
  1633. ExportTime: export_time,
  1634. Status: 1,
  1635. }
  1636. service.CreateExportLog(&log)
  1637. this.ServeSuccessJSON(map[string]interface{}{
  1638. "msg": "导入成功",
  1639. "total_num": len(total_schedule),
  1640. "success_num": len(schedules),
  1641. "fail_num": int64(len(errLogs)),
  1642. })
  1643. } else {
  1644. log := models.ExportLog{
  1645. LogType: 3,
  1646. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1647. TotalNum: int64(len(total_schedule)),
  1648. FailNum: int64(len(errLogs)),
  1649. SuccessNum: int64(len(schedules)),
  1650. CreateTime: time.Now().Unix(),
  1651. UpdateTime: time.Now().Unix(),
  1652. ExportTime: export_time,
  1653. Status: 1,
  1654. }
  1655. service.CreateExportLog(&log)
  1656. this.ServeSuccessJSON(map[string]interface{}{
  1657. "msg": "导入成功",
  1658. "total_num": len(total_schedule),
  1659. "success_num": len(schedules),
  1660. "fail_num": int64(len(errLogs)),
  1661. })
  1662. }
  1663. } else {
  1664. log := models.ExportLog{
  1665. LogType: 3,
  1666. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1667. TotalNum: int64(len(total_schedule)),
  1668. FailNum: int64(len(errLogs)),
  1669. SuccessNum: int64(len(schedules)),
  1670. CreateTime: time.Now().Unix(),
  1671. UpdateTime: time.Now().Unix(),
  1672. ExportTime: export_time,
  1673. Status: 1,
  1674. }
  1675. service.CreateExportLog(&log)
  1676. this.ServeSuccessJSON(map[string]interface{}{
  1677. "msg": "导入成功",
  1678. "total_num": len(total_schedule),
  1679. "success_num": len(schedules),
  1680. "fail_num": int64(len(errLogs)),
  1681. })
  1682. }
  1683. }
  1684. }
  1685. func (c *ScheduleApiController) GetInitExcelInitDate() {
  1686. thisTime := time.Now()
  1687. thisTime1 := time.Now()
  1688. thisTime2 := time.Now()
  1689. thisTime1 = thisTime1.AddDate(0, 0, 7)
  1690. thisTime2 = thisTime2.AddDate(0, 0, 14)
  1691. weekDay := int(thisTime.Weekday())
  1692. if weekDay == 0 {
  1693. weekDay = 7
  1694. }
  1695. weekEnd := 7 - weekDay
  1696. weekStart := weekEnd - 6
  1697. days := make([]string, 0)
  1698. for index := weekStart; index <= weekEnd; index++ {
  1699. theDay := thisTime.AddDate(0, 0, index)
  1700. days = append(days, theDay.Format("2006-01-02"))
  1701. }
  1702. weekDay1 := int(thisTime1.Weekday())
  1703. if weekDay1 == 0 {
  1704. weekDay1 = 7
  1705. }
  1706. weekEnd1 := 7 - weekDay1
  1707. weekStart1 := weekEnd1 - 6
  1708. for index := weekStart1; index <= weekEnd1; index++ {
  1709. theDay := thisTime1.AddDate(0, 0, index)
  1710. days = append(days, theDay.Format("2006-01-02"))
  1711. }
  1712. weekDay2 := int(thisTime2.Weekday())
  1713. if weekDay2 == 0 {
  1714. weekDay2 = 7
  1715. }
  1716. weekEnd2 := 7 - weekDay2
  1717. weekStart2 := weekEnd2 - 6
  1718. for index := weekStart2; index <= weekEnd2; index++ {
  1719. theDay := thisTime2.AddDate(0, 0, index)
  1720. days = append(days, theDay.Format("2006-01-02"))
  1721. }
  1722. c.ServeSuccessJSON(map[string]interface{}{
  1723. "days": days,
  1724. })
  1725. return
  1726. }
  1727. func GetWeekString(week string) string {
  1728. var weekStr string
  1729. switch week {
  1730. case "Sunday":
  1731. weekStr = "周日"
  1732. break
  1733. case "Monday":
  1734. weekStr = "周一"
  1735. break
  1736. case "Tuesday":
  1737. weekStr = "周二"
  1738. break
  1739. case "Wednesday":
  1740. weekStr = "周三"
  1741. break
  1742. case "Thursday":
  1743. weekStr = "周四"
  1744. break
  1745. case "Friday":
  1746. weekStr = "周五"
  1747. break
  1748. case "Saturday":
  1749. weekStr = "周六"
  1750. break
  1751. default:
  1752. weekStr = ""
  1753. break
  1754. }
  1755. return weekStr
  1756. }
  1757. func (c *ScheduleApiController) SearchTemplateSchedulePatients() {
  1758. template_id, _ := c.GetInt64("template_id", 0)
  1759. keywords := c.GetString("keywords")
  1760. adminInfo := c.GetAdminUserInfo()
  1761. scheduleItems, _ := service.GetTemplateSchedualPatientsByKeywords(keywords, adminInfo.CurrentOrgId, template_id)
  1762. c.ServeSuccessJSON(map[string]interface{}{
  1763. "schdules": scheduleItems,
  1764. })
  1765. }
  1766. func (c *ScheduleApiController) CancelScheduleTemplate() {
  1767. item_id, _ := c.GetInt64("id")
  1768. adminInfo := c.GetAdminUserInfo()
  1769. err := service.UpdateNewScheduleTemplateStatus(item_id, adminInfo.CurrentOrgId)
  1770. if err == nil {
  1771. c.ServeSuccessJSON(map[string]interface{}{
  1772. "msg": "取消成功",
  1773. })
  1774. return
  1775. } else {
  1776. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1777. return
  1778. }
  1779. }
  1780. func (this *ScheduleApiController) GetNextWeekDaySchedule() {
  1781. week_type, _ := this.GetInt64("week_type", -1)
  1782. week_time, _ := this.GetInt64("week_time")
  1783. //start_time, _ := this.GetInt64("start_time")
  1784. //end_time, _ := this.GetInt64("end_time")
  1785. record_date := this.GetString("record_date")
  1786. zons := this.GetString("zone")
  1787. zone := strings.Split(zons, ",")
  1788. start_time := this.GetString("start_time")
  1789. end_time := this.GetString("end_time")
  1790. timeLayout := "2006-01-02"
  1791. loc, _ := time.LoadLocation("Local")
  1792. theTimeStart, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1793. theTimeEnd, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  1794. adminUserInfo := this.GetAdminUserInfo()
  1795. var theStartTIme int64
  1796. if len(record_date) > 0 {
  1797. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1798. if err != nil {
  1799. utils.ErrorLog(err.Error())
  1800. }
  1801. theStartTIme = theTime.Unix()
  1802. }
  1803. schedule, err := service.GetNextWeekDaySchedule(week_type, week_time, theTimeStart.Unix(), theTimeEnd.Unix(), adminUserInfo.CurrentOrgId, zone, theStartTIme)
  1804. if err != nil {
  1805. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1806. return
  1807. }
  1808. this.ServeSuccessJSON(map[string]interface{}{
  1809. "schedule": schedule,
  1810. })
  1811. }
  1812. func (this *ScheduleApiController) GetThreeWeekList() {
  1813. start_time := this.GetString("start_time")
  1814. end_time := this.GetString("end_time")
  1815. partition_id, _ := this.GetInt64("partition_id")
  1816. schedule_type, _ := this.GetInt64("schedule_type")
  1817. fmt.Println(partition_id, schedule_type)
  1818. timeLayout := "2006-01-02"
  1819. loc, _ := time.LoadLocation("Local")
  1820. var theStartTIme int64
  1821. if len(start_time) > 0 {
  1822. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1823. if err != nil {
  1824. utils.ErrorLog(err.Error())
  1825. }
  1826. theStartTIme = theTime.Unix()
  1827. }
  1828. var theEndtTIme int64
  1829. if len(end_time) > 0 {
  1830. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  1831. if err != nil {
  1832. utils.ErrorLog(err.Error())
  1833. }
  1834. theEndtTIme = theTime.Unix()
  1835. }
  1836. adminUserInfo := this.GetAdminUserInfo()
  1837. orgId := adminUserInfo.CurrentOrgId
  1838. partitions, _ := service.GetSchedulePartitionPanel(orgId)
  1839. list, err := service.GetThreeWeekList(theStartTIme, theEndtTIme, orgId, schedule_type, partition_id)
  1840. if err != nil {
  1841. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1842. return
  1843. }
  1844. this.ServeSuccessJSON(map[string]interface{}{
  1845. "list": list,
  1846. "partitions": partitions,
  1847. })
  1848. }
  1849. func (this *ScheduleApiController) GetAllZones() {
  1850. adminUserInfo := this.GetAdminUserInfo()
  1851. orgId := adminUserInfo.CurrentOrgId
  1852. zones, err := service.GetAllZoneOne(orgId)
  1853. if err != nil {
  1854. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1855. return
  1856. }
  1857. this.ServeSuccessJSON(map[string]interface{}{
  1858. "zones": zones,
  1859. })
  1860. }
  1861. func (this *ScheduleApiController) GetCopyPatientSchedules() {
  1862. adminUserInfo := this.GetAdminUserInfo()
  1863. orgId := adminUserInfo.CurrentOrgId
  1864. start_time, _ := this.GetInt64("start_time")
  1865. fmt.Println("start_time", start_time)
  1866. end_time, _ := this.GetInt64("end_time")
  1867. fmt.Println("end_time", end_time)
  1868. copy_startime, _ := this.GetInt64("copy_startime")
  1869. fmt.Println("copy_startime", copy_startime)
  1870. copy_endtime, _ := this.GetInt64("copy_endtime")
  1871. //获取本周患者排班
  1872. schedules, _ := service.GetWeekSchedules(orgId, start_time, end_time)
  1873. //先清除复制周的排班
  1874. errcode := service.UpdatePatientSchedule(orgId, copy_startime, copy_endtime)
  1875. fmt.Println(errcode)
  1876. for _, item := range schedules {
  1877. //fmt.Println(item.StartTime+604800)
  1878. //礼拜1
  1879. if item.ScheduleWeek == 1 {
  1880. item.ScheduleDate = copy_startime
  1881. }
  1882. if item.ScheduleWeek == 2 {
  1883. item.ScheduleDate = copy_startime + 86400
  1884. }
  1885. if item.ScheduleWeek == 3 {
  1886. item.ScheduleDate = copy_startime + 172800
  1887. }
  1888. if item.ScheduleWeek == 4 {
  1889. item.ScheduleDate = copy_startime + 259200
  1890. }
  1891. if item.ScheduleWeek == 5 {
  1892. item.ScheduleDate = copy_startime + 345600
  1893. }
  1894. if item.ScheduleWeek == 6 {
  1895. item.ScheduleDate = copy_startime + 432000
  1896. }
  1897. //礼拜天
  1898. if item.ScheduleWeek == 7 {
  1899. item.ScheduleDate = copy_endtime
  1900. }
  1901. schedule := models.XtSchedule{
  1902. UserOrgId: item.UserOrgId,
  1903. PartitionId: item.PartitionId,
  1904. BedId: item.BedId,
  1905. PatientId: item.PatientId,
  1906. ScheduleDate: item.ScheduleDate,
  1907. ScheduleType: item.ScheduleType,
  1908. ScheduleWeek: item.ScheduleWeek,
  1909. ModeId: item.ModeId,
  1910. Status: 1,
  1911. CreatedTime: time.Now().Unix(),
  1912. }
  1913. err := service.AddPatientSchedule(&schedule)
  1914. if err != nil {
  1915. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1916. return
  1917. }
  1918. this.ServeSuccessJSON(map[string]interface{}{
  1919. "schedule": schedule,
  1920. })
  1921. }
  1922. //查询复制中的排班日期是否存在
  1923. //_, errcode := service.GetLastWeekSchedule(orgId, copy_startime, copy_endtime)
  1924. //
  1925. //if errcode == gorm.ErrRecordNotFound {
  1926. // //如果没有直接新增
  1927. //
  1928. // for _, item := range schedules {
  1929. // //fmt.Println(item.StartTime+604800)
  1930. // //礼拜1
  1931. // if item.ScheduleWeek == 1 {
  1932. // item.ScheduleDate = copy_startime
  1933. // }
  1934. // if item.ScheduleWeek == 2 {
  1935. // item.ScheduleDate = copy_startime + 86400
  1936. // }
  1937. // if item.ScheduleWeek == 3 {
  1938. // item.ScheduleDate = copy_startime + 172800
  1939. // }
  1940. // if item.ScheduleWeek == 4 {
  1941. // item.ScheduleDate = copy_startime + 259200
  1942. // }
  1943. // if item.ScheduleWeek == 5 {
  1944. // item.ScheduleDate = copy_startime + 345600
  1945. // }
  1946. //
  1947. // if item.ScheduleWeek == 6 {
  1948. // item.ScheduleDate = copy_startime + 432000
  1949. // }
  1950. // //礼拜天
  1951. // if item.ScheduleWeek == 0 {
  1952. // item.ScheduleDate = copy_endtime
  1953. // }
  1954. // schedule := models.XtSchedule{
  1955. // UserOrgId: item.UserOrgId,
  1956. // PartitionId: item.PartitionId,
  1957. // BedId: item.BedId,
  1958. // PatientId: item.PatientId,
  1959. // ScheduleDate: item.ScheduleDate,
  1960. // ScheduleType: item.ScheduleType,
  1961. // ScheduleWeek: item.ScheduleWeek,
  1962. // ModeId: item.ModeId,
  1963. // Status: 1,
  1964. // CreatedTime: time.Now().Unix(),
  1965. // }
  1966. //
  1967. // err := service.AddPatientSchedule(&schedule)
  1968. // if err != nil {
  1969. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1970. // return
  1971. // }
  1972. // this.ServeSuccessJSON(map[string]interface{}{
  1973. // "schedule": schedule,
  1974. // })
  1975. // }
  1976. //} else if errcode == nil {
  1977. //
  1978. // //先清除复制周的排班
  1979. // errcode := service.UpdatePatientSchedule(orgId, copy_startime, copy_endtime)
  1980. // fmt.Println(errcode)
  1981. // for _, item := range schedules {
  1982. // //fmt.Println(item.StartTime+604800)
  1983. // //礼拜1
  1984. // if item.ScheduleWeek == 1 {
  1985. // item.ScheduleDate = copy_startime
  1986. // }
  1987. // if item.ScheduleWeek == 2 {
  1988. // item.ScheduleDate = copy_startime + 86400
  1989. // }
  1990. // if item.ScheduleWeek == 3 {
  1991. // item.ScheduleDate = copy_startime + 172800
  1992. // }
  1993. // if item.ScheduleWeek == 4 {
  1994. // item.ScheduleDate = copy_startime + 259200
  1995. // }
  1996. // if item.ScheduleWeek == 5 {
  1997. // item.ScheduleDate = copy_startime + 345600
  1998. // }
  1999. //
  2000. // if item.ScheduleWeek == 6 {
  2001. // item.ScheduleDate = copy_startime + 432000
  2002. // }
  2003. // //礼拜天
  2004. // if item.ScheduleWeek == 0 {
  2005. // item.ScheduleDate = copy_endtime
  2006. // }
  2007. // schedule := models.XtSchedule{
  2008. // UserOrgId: item.UserOrgId,
  2009. // PartitionId: item.PartitionId,
  2010. // BedId: item.BedId,
  2011. // PatientId: item.PatientId,
  2012. // ScheduleDate: item.ScheduleDate,
  2013. // ScheduleType: item.ScheduleType,
  2014. // ScheduleWeek: item.ScheduleWeek,
  2015. // ModeId: item.ModeId,
  2016. // Status: 1,
  2017. // CreatedTime: time.Now().Unix(),
  2018. // }
  2019. //
  2020. // err := service.AddPatientSchedule(&schedule)
  2021. // if err != nil {
  2022. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2023. // return
  2024. // }
  2025. // this.ServeSuccessJSON(map[string]interface{}{
  2026. // "schedule": schedule,
  2027. // })
  2028. // }
  2029. //}
  2030. }
  2031. func (this *ScheduleApiController) SaveRemindPrint() {
  2032. id, _ := this.GetInt64("id")
  2033. anticoagulants, _ := this.GetInt64("anticoagulant")
  2034. anticoagulant_zongliang, _ := this.GetInt64("anticoagulant_zongliang")
  2035. classes, _ := this.GetInt64("classes")
  2036. dialyzers, _ := this.GetInt64("dialyzers")
  2037. doctor_advice, _ := this.GetInt64("doctor_advice")
  2038. mode, _ := this.GetInt64("mode")
  2039. name, _ := this.GetInt64("name")
  2040. number, _ := this.GetInt64("number")
  2041. perfusion_apparatus, _ := this.GetInt64("perfusion_apparatus")
  2042. prescription_status, _ := this.GetInt64("prescription_status")
  2043. week, _ := this.GetInt64("week")
  2044. zone, _ := this.GetInt64("zone")
  2045. adminUserInfo := this.GetAdminUserInfo()
  2046. orgId := adminUserInfo.CurrentOrgId
  2047. setting := models.XtRemindPrintSetting{
  2048. Anticoagulant: anticoagulants,
  2049. Classes: classes,
  2050. AnticoagulantZongliang: anticoagulant_zongliang,
  2051. Dialyzers: dialyzers,
  2052. DoctorAdvice: doctor_advice,
  2053. Mode: mode,
  2054. Name: name,
  2055. Number: number,
  2056. PerfusionApparatus: perfusion_apparatus,
  2057. PrescriptionStatus: prescription_status,
  2058. Week: week,
  2059. Zone: zone,
  2060. UserOrgId: orgId,
  2061. Status: 1,
  2062. Ctime: time.Now().Unix(),
  2063. }
  2064. _, errcode := service.GetSettingById(id)
  2065. if errcode == gorm.ErrRecordNotFound {
  2066. err := service.CreateSetting(&setting)
  2067. if err != nil {
  2068. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2069. return
  2070. }
  2071. this.ServeSuccessJSON(map[string]interface{}{
  2072. "setting": setting,
  2073. })
  2074. } else if errcode == nil {
  2075. err := service.UpdatedRemindPrint(&setting, id)
  2076. if err != nil {
  2077. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2078. return
  2079. }
  2080. this.ServeSuccessJSON(map[string]interface{}{
  2081. "setting": setting,
  2082. })
  2083. }
  2084. }
  2085. func (this *ScheduleApiController) GetRemindPrintList() {
  2086. adminUserInfo := this.GetAdminUserInfo()
  2087. orgId := adminUserInfo.CurrentOrgId
  2088. list, err := service.GetRemindPrintList(orgId)
  2089. if err != nil {
  2090. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2091. return
  2092. }
  2093. this.ServeSuccessJSON(map[string]interface{}{
  2094. "list": list,
  2095. })
  2096. }
  2097. func (this *ScheduleApiController) GetBloodScheduleList() {
  2098. week_type, _ := this.GetInt64("week_type", -1)
  2099. week_time, _ := this.GetInt64("week_time")
  2100. zones := this.GetString("zone")
  2101. zone := strings.Split(zones, ",")
  2102. thisTime := time.Now()
  2103. weekDay := int(thisTime.Weekday())
  2104. if weekDay == 0 {
  2105. weekDay = 7
  2106. }
  2107. weekEnd := 7 - weekDay
  2108. weekStart := weekEnd - 6
  2109. weekTitle := make([]string, 0)
  2110. days := make([]string, 0)
  2111. for index := weekStart; index <= weekEnd; index++ {
  2112. theDay := thisTime.AddDate(0, 0, index)
  2113. indexYear, indexMonthTime, indexDay := theDay.Date()
  2114. indexMonth := int(indexMonthTime)
  2115. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  2116. weekTitle = append(weekTitle, indexWeek)
  2117. days = append(days, theDay.Format("2006-01-02"))
  2118. }
  2119. fmt.Println(days)
  2120. var targetDayStr string
  2121. var startTime string
  2122. switch week_type {
  2123. case 0:
  2124. startTime = days[0]
  2125. targetDayStr = days[6]
  2126. break
  2127. case 1:
  2128. targetDayStr = days[0]
  2129. break
  2130. case 2:
  2131. targetDayStr = days[1]
  2132. break
  2133. case 3:
  2134. targetDayStr = days[2]
  2135. break
  2136. case 4:
  2137. targetDayStr = days[3]
  2138. break
  2139. case 5:
  2140. targetDayStr = days[4]
  2141. break
  2142. case 6:
  2143. targetDayStr = days[5]
  2144. break
  2145. case 7:
  2146. targetDayStr = days[6]
  2147. break
  2148. }
  2149. targetDay, parseErr := utils.ParseTimeStringToTime("2006-01-02", targetDayStr)
  2150. if parseErr != nil {
  2151. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2152. return
  2153. }
  2154. orgId := this.GetAdminUserInfo().CurrentOrgId
  2155. if week_type > 0 {
  2156. list, err := service.GetWeekDayScheduleByIdThee(orgId, targetDay.Unix(), week_time, zone)
  2157. if err != nil {
  2158. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2159. return
  2160. }
  2161. this.ServeSuccessJSON(map[string]interface{}{
  2162. "list": list,
  2163. "day": targetDayStr,
  2164. })
  2165. }
  2166. if week_type == 0 {
  2167. startDate, _ := utils.ParseTimeStringToTime("2006-01-02", startTime)
  2168. list, err := service.GetWeekDayScheduleByIdTwo(orgId, targetDay.Unix(), week_time, startDate.Unix(), zone)
  2169. if err != nil {
  2170. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2171. return
  2172. }
  2173. this.ServeSuccessJSON(map[string]interface{}{
  2174. "list": list,
  2175. "day": targetDayStr,
  2176. })
  2177. }
  2178. }
  2179. func (this *ScheduleApiController) GetPrintList() {
  2180. adminUserInfo := this.GetAdminUserInfo()
  2181. orgId := adminUserInfo.CurrentOrgId
  2182. list, err := service.GetRemindPrintList(orgId)
  2183. if err != nil {
  2184. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2185. return
  2186. }
  2187. this.ServeSuccessJSON(map[string]interface{}{
  2188. "list": list,
  2189. })
  2190. }
  2191. func (this *ScheduleApiController) GetAllZoneList() {
  2192. adminUserInfo := this.GetAdminUserInfo()
  2193. orgId := adminUserInfo.CurrentOrgId
  2194. zoneList, err := service.GetAllZoneOne(orgId)
  2195. if err != nil {
  2196. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2197. return
  2198. }
  2199. this.ServeSuccessJSON(map[string]interface{}{
  2200. "zoneList": zoneList,
  2201. })
  2202. }
  2203. func (this *ScheduleApiController) GetPatientScheduleCount() {
  2204. patitionIdStr := this.GetString("partition_id")
  2205. week, _ := this.GetInt64("weekTime", 0) //1:last, 2:this 3:next 4 nextTwo
  2206. ids := strings.Split(patitionIdStr, ",")
  2207. adminUserInfo := this.GetAdminUserInfo()
  2208. orgId := adminUserInfo.CurrentOrgId
  2209. thisTime := time.Now()
  2210. weekDay := int(thisTime.Weekday())
  2211. if week < 1 || week > 4 {
  2212. week = 2
  2213. }
  2214. if week == 1 {
  2215. thisTime = thisTime.AddDate(0, 0, -7)
  2216. } else if week == 3 {
  2217. thisTime = thisTime.AddDate(0, 0, 7)
  2218. } else if week == 4 {
  2219. thisTime = thisTime.AddDate(0, 0, 14)
  2220. }
  2221. if weekDay == 0 {
  2222. weekDay = 7
  2223. }
  2224. weekEnd := 7 - weekDay
  2225. weekStart := weekEnd - 6
  2226. weekTitle := make([]string, 0)
  2227. days := make([]string, 0)
  2228. for index := weekStart; index <= weekEnd; index++ {
  2229. theDay := thisTime.AddDate(0, 0, index)
  2230. indexYear, indexMonthTime, indexDay := theDay.Date()
  2231. indexMonth := int(indexMonthTime)
  2232. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  2233. weekTitle = append(weekTitle, indexWeek)
  2234. days = append(days, theDay.Format("2006-01-02"))
  2235. }
  2236. weekStartDay := thisTime.AddDate(0, 0, weekStart)
  2237. weekEndDay := thisTime.AddDate(0, 0, weekEnd)
  2238. weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
  2239. weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
  2240. timeLayout := "2006-01-02 15:04:05"
  2241. loc, _ := time.LoadLocation("Local")
  2242. theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
  2243. theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
  2244. weekStartPoint := theStarTime.Unix()
  2245. weekEndPoint := theEndTime.Unix()
  2246. fmt.Println("startTime222222222222222", weekStartPoint)
  2247. fmt.Println("endtime33333333333333", weekEndPoint)
  2248. list, err := service.GetPatientScheduleCount(orgId, weekStartPoint, weekEndPoint, ids)
  2249. _, total, _ := service.GetTotalBedNumber(orgId, ids)
  2250. if err != nil {
  2251. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2252. return
  2253. }
  2254. this.ServeSuccessJSON(map[string]interface{}{
  2255. "list": list,
  2256. "total": total,
  2257. })
  2258. }
  2259. func (c *ScheduleApiController) GetWeekPanelsOne() {
  2260. data, _ := c.GetInt64("data", 1)
  2261. patitionIdStr := c.GetString("patitionid")
  2262. ids := strings.Split(patitionIdStr, ",")
  2263. adminInfo := c.GetAdminUserInfo()
  2264. thisTime := time.Now()
  2265. year, monthTime, day := thisTime.Date()
  2266. month := int(monthTime)
  2267. _, theWeek := thisTime.ISOWeek()
  2268. weekDay := int(thisTime.Weekday())
  2269. if weekDay == 0 {
  2270. weekDay = 7
  2271. }
  2272. weekEnd := 7 - weekDay
  2273. weekStart := weekEnd - 6
  2274. weekDays := make([]string, 0)
  2275. for index := weekStart; index <= weekEnd; index++ {
  2276. theDay := thisTime.AddDate(0, 0, index)
  2277. indexYear, indexMonthTime, indexDay := theDay.Date()
  2278. indexMonth := int(indexMonthTime)
  2279. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  2280. weekDays = append(weekDays, indexWeek)
  2281. }
  2282. returnData := map[string]interface{}{
  2283. "year": year,
  2284. "month": month,
  2285. "day": day,
  2286. "theWeek": theWeek,
  2287. "weekDay": weekDay,
  2288. "weekDays": weekDays,
  2289. }
  2290. if data == 1 {
  2291. partitions, _ := service.GetSchedulePartitionPanelTwo(adminInfo.CurrentOrgId, ids)
  2292. returnData["partitions"] = partitions
  2293. }
  2294. c.ServeSuccessJSON(returnData)
  2295. return
  2296. }
  2297. func (c *ScheduleApiController) GetScheduleOne() {
  2298. week, _ := c.GetInt64("weekTime", 0) //1:last, 2:this 3:next 4 nextTwo
  2299. patitionIdStr := c.GetString("patitionid")
  2300. ids := strings.Split(patitionIdStr, ",")
  2301. fmt.Println("patitonStr", ids)
  2302. schedule_type, _ := c.GetInt64("schedule_type")
  2303. adminInfo := c.GetAdminUserInfo()
  2304. thisTime := time.Now()
  2305. today := thisTime.Format("2006-01-02")
  2306. if week < 1 || week > 4 {
  2307. week = 2
  2308. }
  2309. if week == 1 {
  2310. thisTime = thisTime.AddDate(0, 0, -7)
  2311. } else if week == 3 {
  2312. thisTime = thisTime.AddDate(0, 0, 7)
  2313. } else if week == 4 {
  2314. thisTime = thisTime.AddDate(0, 0, 14)
  2315. }
  2316. weekDay := int(thisTime.Weekday())
  2317. if weekDay == 0 {
  2318. weekDay = 7
  2319. }
  2320. weekEnd := 7 - weekDay
  2321. weekStart := weekEnd - 6
  2322. weekTitle := make([]string, 0)
  2323. days := make([]string, 0)
  2324. for index := weekStart; index <= weekEnd; index++ {
  2325. theDay := thisTime.AddDate(0, 0, index)
  2326. indexYear, indexMonthTime, indexDay := theDay.Date()
  2327. indexMonth := int(indexMonthTime)
  2328. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  2329. weekTitle = append(weekTitle, indexWeek)
  2330. days = append(days, theDay.Format("2006-01-02"))
  2331. }
  2332. weekStartDay := thisTime.AddDate(0, 0, weekStart)
  2333. weekEndDay := thisTime.AddDate(0, 0, weekEnd)
  2334. weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
  2335. weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
  2336. timeLayout := "2006-01-02 15:04:05"
  2337. loc, _ := time.LoadLocation("Local")
  2338. theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
  2339. theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
  2340. weekStartPoint := theStarTime.Unix()
  2341. weekEndPoint := theEndTime.Unix()
  2342. schdules, _ := service.GetWeekScheduleTwo(adminInfo.CurrentOrgId, weekStartPoint, weekEndPoint, ids, schedule_type)
  2343. c.ServeSuccessJSON(map[string]interface{}{
  2344. "days": days,
  2345. "weekTitle": weekTitle,
  2346. "schdules": schdules,
  2347. "today": today,
  2348. })
  2349. return
  2350. }
  2351. func (c *ScheduleApiController) SaveScheduleTemplate() {
  2352. template_id, _ := c.GetInt64("template_id")
  2353. orgId := c.GetAdminUserInfo().CurrentOrgId
  2354. template := models.ScheduleTemplate{
  2355. TemplateId: template_id,
  2356. UserOrgId: orgId,
  2357. Status: 1,
  2358. Ctime: time.Now().Unix(),
  2359. }
  2360. _, errcodes := service.GetScheudleTemplateById(orgId)
  2361. if errcodes == gorm.ErrRecordNotFound {
  2362. service.CreateXtscheduleTemplate(&template)
  2363. } else if errcodes == nil {
  2364. service.UpdateXtScheduleTemplate(&template, orgId)
  2365. }
  2366. c.ServeSuccessJSON(map[string]interface{}{
  2367. "template": template,
  2368. })
  2369. return
  2370. }
  2371. func (c *ScheduleApiController) GetScheduleTemplate() {
  2372. adminUserInfo := c.GetAdminUserInfo()
  2373. orgId := adminUserInfo.CurrentOrgId
  2374. template, _ := service.GetScheduleTemplate(orgId)
  2375. c.ServeSuccessJSON(map[string]interface{}{
  2376. "template": template,
  2377. })
  2378. return
  2379. }
  2380. func (c *ScheduleApiController) ChangeFuncPrint() {
  2381. adminUserInfo := c.GetAdminUserInfo()
  2382. orgId := adminUserInfo.CurrentOrgId
  2383. is_open, _ := c.GetInt64("is_open")
  2384. dataPrint := models.XtDataPrint{
  2385. UserOrgId: orgId,
  2386. IsOpen: is_open,
  2387. Status: 1,
  2388. Ctime: time.Now().Unix(),
  2389. }
  2390. _, errcode := service.GetDataPrintByOrgId(orgId)
  2391. fmt.Println("errcode222234444555556t66", errcode)
  2392. if errcode == gorm.ErrRecordNotFound {
  2393. service.CreateDataPrint(&dataPrint)
  2394. c.ServeSuccessJSON(map[string]interface{}{
  2395. "dataPrint": dataPrint,
  2396. })
  2397. return
  2398. } else if errcode == nil {
  2399. service.UpdteDataPrint(orgId, &dataPrint)
  2400. c.ServeSuccessJSON(map[string]interface{}{
  2401. "dataPrint": dataPrint,
  2402. })
  2403. return
  2404. }
  2405. }
  2406. func (c *ScheduleApiController) GetDataPrint() {
  2407. adminUserInfo := c.GetAdminUserInfo()
  2408. orgId := adminUserInfo.CurrentOrgId
  2409. dataPrint, _ := service.GetDataPrint(orgId)
  2410. c.ServeSuccessJSON(map[string]interface{}{
  2411. "dataPrint": dataPrint,
  2412. })
  2413. return
  2414. }
  2415. func (c *ScheduleApiController) GetNextWeekPanels() {
  2416. start_time, _ := c.GetInt64("start_time")
  2417. fmt.Println("start_time", start_time)
  2418. end_time, _ := c.GetInt64("end_time")
  2419. fmt.Println("end_time", end_time)
  2420. orgId := c.GetAdminUserInfo().CurrentOrgId
  2421. schedule, _ := service.GetNextWeekPanels(start_time, end_time, orgId)
  2422. c.ServeSuccessJSON(map[string]interface{}{
  2423. "schedule": schedule,
  2424. })
  2425. }
  2426. func (c *ScheduleApiController) SynchroSchedule() {
  2427. template_id, _ := c.GetInt64("template_id")
  2428. copy_startime, _ := c.GetInt64("copy_startime")
  2429. copy_endtime, _ := c.GetInt64("copy_endtime")
  2430. orgId := c.GetAdminUserInfo().CurrentOrgId
  2431. //根据模板ID获取模板数据
  2432. list, _ := service.GetTemplateListByTemplateId(template_id, orgId)
  2433. recordDateStr := time.Now().Format("2006-01-02")
  2434. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2435. nowtime := recordDate.Unix()
  2436. fmt.Println("今日时间", nowtime)
  2437. fmt.Println("后期日期", copy_startime)
  2438. var tuesday int64
  2439. var wednesday int64
  2440. var thursday int64
  2441. var friday int64
  2442. var saturday int64
  2443. //如果选择的开始日期大于当前日期
  2444. if copy_startime > nowtime {
  2445. //清空该时间段的所有排班数据
  2446. service.DeletePatientSchedule(copy_startime, copy_endtime, orgId)
  2447. tuesday = copy_startime + 86400
  2448. wednesday = copy_startime + 172800
  2449. thursday = copy_startime + 259200
  2450. friday = copy_startime + 345600
  2451. saturday = copy_startime + 432000
  2452. for _, item := range list {
  2453. if item.Weekday == 1 {
  2454. item.ScheduleDate = copy_startime
  2455. }
  2456. if item.Weekday == 2 {
  2457. item.ScheduleDate = tuesday
  2458. }
  2459. if item.Weekday == 3 {
  2460. item.ScheduleDate = wednesday
  2461. }
  2462. if item.Weekday == 4 {
  2463. item.ScheduleDate = thursday
  2464. }
  2465. if item.Weekday == 5 {
  2466. item.ScheduleDate = friday
  2467. }
  2468. if item.Weekday == 6 {
  2469. item.ScheduleDate = saturday
  2470. }
  2471. if item.Weekday == 7 {
  2472. item.ScheduleDate = copy_endtime
  2473. }
  2474. //根据床位号获取区号
  2475. number, _ := service.GetBedNumberById(item.DeviceNumberID, orgId)
  2476. item.ZoneId = number.ZoneID
  2477. }
  2478. for _, item := range list {
  2479. schedule := models.XtSchedule{
  2480. UserOrgId: orgId,
  2481. PartitionId: item.ZoneId,
  2482. BedId: item.DeviceNumberID,
  2483. PatientId: item.PatientID,
  2484. ScheduleDate: item.ScheduleDate,
  2485. ScheduleType: item.TimeType,
  2486. ScheduleWeek: item.Weekday,
  2487. ModeId: item.TreatMode,
  2488. Status: 1,
  2489. CreatedTime: time.Now().Unix(),
  2490. UpdatedTime: 0,
  2491. }
  2492. service.CreatePatientSchedule(&schedule)
  2493. }
  2494. }
  2495. //如果选择的日期小于当前日期,只同步今日以后的数据
  2496. if copy_startime <= nowtime {
  2497. //清空今日以后的数据
  2498. service.DeletePatientScheduleToday(nowtime, copy_endtime, orgId)
  2499. var tuesday int64
  2500. var wednesday int64
  2501. var thursday int64
  2502. var friday int64
  2503. var saturday int64
  2504. tuesday = copy_startime + 86400
  2505. wednesday = copy_startime + 172800
  2506. thursday = copy_startime + 259200
  2507. friday = copy_startime + 345600
  2508. saturday = copy_startime + 432000
  2509. for _, item := range list {
  2510. if item.Weekday == 1 {
  2511. item.ScheduleDate = copy_startime
  2512. }
  2513. if item.Weekday == 2 {
  2514. item.ScheduleDate = tuesday
  2515. }
  2516. if item.Weekday == 3 {
  2517. item.ScheduleDate = wednesday
  2518. }
  2519. if item.Weekday == 4 {
  2520. item.ScheduleDate = thursday
  2521. }
  2522. if item.Weekday == 5 {
  2523. item.ScheduleDate = friday
  2524. }
  2525. if item.Weekday == 6 {
  2526. item.ScheduleDate = saturday
  2527. }
  2528. if item.Weekday == 7 {
  2529. item.ScheduleDate = copy_endtime
  2530. }
  2531. //根据床位号获取区号
  2532. number, _ := service.GetBedNumberById(item.DeviceNumberID, orgId)
  2533. item.ZoneId = number.ZoneID
  2534. }
  2535. for _, item := range list {
  2536. // 同步今日以后的数据
  2537. if item.ScheduleDate > nowtime {
  2538. schedule := models.XtSchedule{
  2539. UserOrgId: orgId,
  2540. PartitionId: item.ZoneId,
  2541. BedId: item.DeviceNumberID,
  2542. PatientId: item.PatientID,
  2543. ScheduleDate: item.ScheduleDate,
  2544. ScheduleType: item.TimeType,
  2545. ScheduleWeek: item.Weekday,
  2546. ModeId: item.TreatMode,
  2547. Status: 1,
  2548. CreatedTime: time.Now().Unix(),
  2549. UpdatedTime: 0,
  2550. }
  2551. service.CreatePatientSchedule(&schedule)
  2552. }
  2553. }
  2554. }
  2555. returnData := make(map[string]interface{}, 0)
  2556. returnData["list"] = list
  2557. c.ServeSuccessJSON(returnData)
  2558. return
  2559. }
  2560. func (c *ScheduleApiController) GetPatientScheduleTempalate() {
  2561. orgId := c.GetAdminUserInfo().CurrentOrgId
  2562. tempalate, _ := service.GetPatientScheduleTempalate(orgId)
  2563. c.ServeSuccessJSON(map[string]interface{}{
  2564. "schedule": tempalate,
  2565. })
  2566. }