schedule_api_controller.go 90KB

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