schedule_api_controller.go 141KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467
  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/getnextscheduleweekdayone", &ScheduleApiController{}, "Get:GetNextWeekDayScheduleOne")
  37. beego.Router("/api/schedule/getthreeweeklist", &ScheduleApiController{}, "Get:GetThreeWeekList")
  38. beego.Router("/api/schedule/getallzones", &ScheduleApiController{}, "Get:GetAllZones")
  39. beego.Router("/api/schedule/copypatientschedules", &ScheduleApiController{}, "Get:GetCopyPatientSchedules")
  40. beego.Router("/api/schedule/saveremindprint", &ScheduleApiController{}, "Get:SaveRemindPrint")
  41. beego.Router("/api/schedule/getremindprintlist", &ScheduleApiController{}, "Get:GetRemindPrintList")
  42. beego.Router("/api/schedule/getbloodschedulelist", &ScheduleApiController{}, "Get:GetBloodScheduleList")
  43. beego.Router("/api/schedule/getprintlist", &ScheduleApiController{}, "Get:GetPrintList")
  44. beego.Router("/api/schedule/getallzonelist", &ScheduleApiController{}, "Get:GetAllZoneList")
  45. beego.Router("/api/schedule/getpatientschedulecount", &ScheduleApiController{}, "Get:GetPatientScheduleCount")
  46. beego.Router("/api/schedule/weekpanelone", &ScheduleApiController{}, "Get:GetWeekPanelsOne")
  47. beego.Router("/api/schedule/schedulesone", &ScheduleApiController{}, "Get:GetScheduleOne")
  48. beego.Router("/api/schedule/scheduletwo", &ScheduleApiController{}, "Get:GetScheduleTwo")
  49. beego.Router("/api/schedule/postscheduletemplate", &ScheduleApiController{}, "Get:SaveScheduleTemplate")
  50. beego.Router("/api/schedule/getscheduletemplate", &ScheduleApiController{}, "Get:GetScheduleTemplate")
  51. beego.Router("/api/order/changefuncprint", &ScheduleApiController{}, "Get:ChangeFuncPrint")
  52. beego.Router("/api/order/getdataprint", &ScheduleApiController{}, "Get:GetDataPrint")
  53. beego.Router("/api/schedule/getnextweekpanels", &ScheduleApiController{}, "Get:GetNextWeekPanels")
  54. beego.Router("/api/schedule/synchroschedule", &ScheduleApiController{}, "Get:SynchroSchedule")
  55. beego.Router("/api/schedule/getpatientscheduletemplate", &ScheduleApiController{}, "Get:GetPatientScheduleTempalate")
  56. beego.Router("/api/schedule/getsolutionschedule", &ScheduleApiController{}, "Get:GetSolutionSchedule")
  57. beego.Router("/api/schedule/smartpatientsch", &ScheduleApiController{}, "Get:GetPatient")
  58. beego.Router("/api/schedule/smartpatientschtemplate", &ScheduleApiController{}, "Get:GetPatientSchTemplate")
  59. beego.Router("/api/patient/smartpatientsch", &ScheduleApiController{}, "Get:GetPatientSmartSch")
  60. beego.Router("/api/patient/smartpatientschtemplate", &ScheduleApiController{}, "Get:GetPatientSmartSchTemplate")
  61. beego.Router("/api/device/get", &ScheduleApiController{}, "Get:GetDevicesNumbers")
  62. beego.Router("/api/smartsch/batch", &ScheduleApiController{}, "Post:BatchPostSmartSch")
  63. beego.Router("/api/smartsch/get", &ScheduleApiController{}, "Get:GetSmartSch")
  64. beego.Router("/api/sch/exchange", &ScheduleApiController{}, "Get:ExchangeSch")
  65. beego.Router("/api/sch/coversch", &ScheduleApiController{}, "Get:CoverSch")
  66. }
  67. func (c *ScheduleApiController) CoverSch() {
  68. id_one, _ := c.GetInt64("id_one")
  69. id_two, _ := c.GetInt64("id_two")
  70. sch, _ := service.GetSchedule(c.GetAdminUserInfo().CurrentOrgId, id_one)
  71. sch_two, _ := service.GetSchedule(c.GetAdminUserInfo().CurrentOrgId, id_two)
  72. order, _ := service.GetDialysisOrder(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  73. if order.ID > 0 {
  74. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderOne)
  75. return
  76. }
  77. order2, _ := service.GetDialysisOrder(sch_two.ScheduleDate, sch_two.PatientId, sch_two.UserOrgId)
  78. if order2.ID > 0 {
  79. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  80. return
  81. }
  82. var new_sch *models.Schedule
  83. new_sch = sch
  84. new_sch.BedId = sch_two.BedId
  85. new_sch.ScheduleDate = sch_two.ScheduleDate
  86. new_sch.ScheduleWeek = sch_two.ScheduleWeek
  87. new_sch.PartitionId = sch_two.PartitionId
  88. new_sch.ScheduleType = sch_two.ScheduleType
  89. new_sch.ID = 0
  90. sch_two.Status = 0
  91. sch.Status = 0
  92. //删除原来的排班
  93. service.SaveSchTwo(sch_two)
  94. service.SaveSchTwo(sch)
  95. //生成新的排班
  96. service.SaveSchTwo(new_sch)
  97. //service.UpdateScheduleThree(sch,sch_two)
  98. c.ServeSuccessJSON(map[string]interface{}{
  99. "msg": "覆盖成功",
  100. })
  101. }
  102. func (c *ScheduleApiController) ExchangeSch() {
  103. id_one, _ := c.GetInt64("id_one")
  104. id_two, _ := c.GetInt64("id_two")
  105. sch, _ := service.GetSchedule(c.GetAdminUserInfo().CurrentOrgId, id_one)
  106. sch_two, _ := service.GetSchedule(c.GetAdminUserInfo().CurrentOrgId, id_two)
  107. order, _ := service.GetDialysisOrder(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  108. if order.ID > 0 {
  109. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderOne)
  110. return
  111. }
  112. order2, _ := service.GetDialysisOrder(sch_two.ScheduleDate, sch_two.PatientId, sch_two.UserOrgId)
  113. if order2.ID > 0 {
  114. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  115. return
  116. }
  117. service.UpdateScheduleThree(sch, sch_two)
  118. c.ServeSuccessJSON(map[string]interface{}{
  119. "msg": "替换成功",
  120. })
  121. }
  122. func (c *ScheduleApiController) BatchPostSmartSch() {
  123. patient_id, _ := c.GetInt64("patient_id")
  124. adminInfo := c.GetAdminUserInfo()
  125. patientInfo, _ := service.FindPatientById(adminInfo.CurrentOrgId, patient_id)
  126. if patientInfo.ID == 0 {
  127. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  128. return
  129. }
  130. dataBody := make(map[string]interface{}, 0)
  131. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  132. if err != nil {
  133. utils.ErrorLog(err.Error())
  134. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  135. return
  136. }
  137. //数据校验
  138. if dataBody["smart_schs"] != nil && reflect.TypeOf(dataBody["smart_schs"]).String() == "[]interface {}" {
  139. schs, _ := dataBody["smart_schs"].([]interface{})
  140. if len(schs) > 0 {
  141. for _, item := range schs {
  142. items := item.(map[string]interface{})
  143. if items["sch_id"] == nil || reflect.TypeOf(items["sch_id"]).String() != "float64" {
  144. utils.ErrorLog("id")
  145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  146. return
  147. }
  148. var schedule models.Schedule
  149. //var oldSchedule *models.Schedule
  150. sch_id := int64(items["sch_id"].(float64))
  151. if sch_id > 0 { //修改排班信息
  152. schedule, _ = service.GetScheduleTwo(adminInfo.CurrentOrgId, sch_id)
  153. fmt.Println("2222222")
  154. if items["mode_id"] == nil || reflect.TypeOf(items["mode_id"]).String() != "float64" {
  155. utils.ErrorLog("mode_id")
  156. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  157. return
  158. }
  159. modeId := int64(items["mode_id"].(float64))
  160. if modeId < 1 {
  161. utils.ErrorLog("modeId < 1")
  162. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  163. return
  164. }
  165. schedule.ModeId = modeId
  166. order, err := service.GetOneDialysisOrder(adminInfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
  167. if err != nil {
  168. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  169. return
  170. }
  171. if order != nil {
  172. week_type, _ := items["week_type"].(string)
  173. week_name, _ := items["week_name"].(string)
  174. switch week_type {
  175. case "1":
  176. json := make(map[string]interface{})
  177. json["msg"] = "本周" + week_name + "的床位已经有人上机,无法保存"
  178. json["state"] = 0
  179. c.Data["json"] = json
  180. c.ServeJSON()
  181. break
  182. case "2":
  183. json := make(map[string]interface{})
  184. json["msg"] = "下周" + week_name + "的床位已经有人上机,无法保存"
  185. json["state"] = 0
  186. c.Data["json"] = json
  187. c.ServeJSON()
  188. break
  189. case "3":
  190. json := make(map[string]interface{})
  191. json["msg"] = "下周" + week_name + "的床位已经有人上机,无法保存"
  192. json["state"] = 0
  193. c.Data["json"] = json
  194. c.ServeJSON()
  195. break
  196. }
  197. return
  198. }
  199. if order != nil {
  200. week_type, _ := items["week_type"].(string)
  201. week_name, _ := items["week_name"].(string)
  202. switch week_type {
  203. case "1":
  204. json := make(map[string]interface{})
  205. json["msg"] = "本周" + week_name + "的床位已经有人上机,无法保存"
  206. json["state"] = 0
  207. c.Data["json"] = json
  208. c.ServeJSON()
  209. break
  210. case "2":
  211. json := make(map[string]interface{})
  212. json["msg"] = "下周" + week_name + "的床位已经有人上机,无法保存"
  213. json["state"] = 0
  214. c.Data["json"] = json
  215. c.ServeJSON()
  216. break
  217. case "3":
  218. json := make(map[string]interface{})
  219. json["msg"] = "下周" + week_name + "的床位已经有人上机,无法保存"
  220. json["state"] = 0
  221. c.Data["json"] = json
  222. c.ServeJSON()
  223. break
  224. }
  225. return
  226. }
  227. if items["schedule_type"] == nil || reflect.TypeOf(items["schedule_type"]).String() != "float64" {
  228. utils.ErrorLog("schedule_type")
  229. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  230. return
  231. }
  232. scheduleType := int64(items["schedule_type"].(float64))
  233. if scheduleType < 1 || scheduleType > 3 {
  234. utils.ErrorLog("scheduleType < 3")
  235. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  236. return
  237. }
  238. schedule.ScheduleType = scheduleType
  239. if items["bed_id"] == nil || reflect.TypeOf(items["bed_id"]).String() != "float64" {
  240. utils.ErrorLog("bed_id")
  241. fmt.Println("~~~~~~333333333")
  242. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  243. return
  244. }
  245. bedId := int64(items["bed_id"].(float64))
  246. if bedId < 1 {
  247. utils.ErrorLog("bedId < 1")
  248. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  249. return
  250. }
  251. schedule.BedId = bedId
  252. if items["zone_id"] == nil || reflect.TypeOf(items["zone_id"]).String() != "float64" {
  253. utils.ErrorLog("zone_id")
  254. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  255. return
  256. }
  257. partitionId := int64(items["zone_id"].(float64))
  258. if partitionId < 1 {
  259. utils.ErrorLog("partitionId < 1")
  260. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  261. return
  262. }
  263. schedule.PartitionId = partitionId
  264. bed, _ := service.GetDeviceNumberByID(adminInfo.CurrentOrgId, schedule.BedId)
  265. if bed == nil {
  266. week_type, _ := items["week_type"].(string)
  267. week_name, _ := items["week_name"].(string)
  268. switch week_type {
  269. case "1":
  270. json := make(map[string]interface{})
  271. json["msg"] = "本周" + week_name + "的机号不存在,无法保存"
  272. json["state"] = 0
  273. c.Data["json"] = json
  274. c.ServeJSON()
  275. break
  276. case "2":
  277. json := make(map[string]interface{})
  278. json["msg"] = "下周" + week_name + "的机号不存在,无法保存"
  279. json["state"] = 0
  280. c.Data["json"] = json
  281. c.ServeJSON()
  282. break
  283. case "3":
  284. json := make(map[string]interface{})
  285. json["msg"] = "下周" + week_name + "的机号不存在,无法保存"
  286. json["state"] = 0
  287. c.Data["json"] = json
  288. c.ServeJSON()
  289. break
  290. }
  291. return
  292. }
  293. if bed.ZoneID != schedule.PartitionId {
  294. week_type, _ := items["week_type"].(string)
  295. week_name, _ := items["week_name"].(string)
  296. switch week_type {
  297. case "1":
  298. json := make(map[string]interface{})
  299. json["msg"] = "本周" + week_name + "所选机号不在选择分区中,无法保存"
  300. json["state"] = 0
  301. c.Data["json"] = json
  302. c.ServeJSON()
  303. break
  304. case "2":
  305. json := make(map[string]interface{})
  306. json["msg"] = "下周" + week_name + "所选机号不在选择分区中,无法保存"
  307. json["state"] = 0
  308. c.Data["json"] = json
  309. c.ServeJSON()
  310. break
  311. case "3":
  312. json := make(map[string]interface{})
  313. json["msg"] = "下周" + week_name + "所选机号不在选择分区中,无法保存"
  314. json["state"] = 0
  315. c.Data["json"] = json
  316. c.ServeJSON()
  317. break
  318. }
  319. return
  320. }
  321. startTime := schedule.ScheduleDate
  322. endTime := startTime + 86399
  323. //一天只有排班一次
  324. daySchedule, err := service.GetDaySchedule(adminInfo.CurrentOrgId, startTime, endTime, schedule.PatientId)
  325. if daySchedule.ID > 0 && daySchedule.ID != schedule.ID {
  326. week_type, _ := items["week_type"].(string)
  327. week_name, _ := items["week_name"].(string)
  328. switch week_type {
  329. case "1":
  330. json := make(map[string]interface{})
  331. json["msg"] = "本周" + week_name + "已有排班,同一天不可有两次排班,无法保存"
  332. json["state"] = 0
  333. c.Data["json"] = json
  334. c.ServeJSON()
  335. break
  336. case "2":
  337. json := make(map[string]interface{})
  338. json["msg"] = "下周" + week_name + "已有排班,同一天不可有两次排班,无法保存"
  339. json["state"] = 0
  340. c.Data["json"] = json
  341. c.ServeJSON()
  342. break
  343. case "3":
  344. json := make(map[string]interface{})
  345. json["msg"] = "下下周" + week_name + "已有排班,同一天不可有两次排班,无法保存"
  346. json["state"] = 0
  347. c.Data["json"] = json
  348. c.ServeJSON()
  349. break
  350. }
  351. return
  352. }
  353. //同天同位置只能排一个
  354. pointSchedule, err := service.GetPointSchedule(adminInfo.CurrentOrgId, schedule.ScheduleDate, schedule.ScheduleWeek, schedule.ScheduleType, schedule.BedId)
  355. if err != nil {
  356. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  357. return
  358. }
  359. if pointSchedule.ID > 0 && pointSchedule.PatientId != patient_id {
  360. week_type, _ := items["week_type"].(string)
  361. week_name, _ := items["week_name"].(string)
  362. switch week_type {
  363. case "1":
  364. json := make(map[string]interface{})
  365. json["msg"] = "本周" + week_name + "所先位置排班已经存在,无法保存"
  366. json["state"] = 0
  367. c.Data["json"] = json
  368. c.ServeJSON()
  369. break
  370. case "2":
  371. json := make(map[string]interface{})
  372. json["msg"] = "下周" + week_name + "所先位置排班已经存在,无法保存"
  373. json["state"] = 0
  374. c.Data["json"] = json
  375. c.ServeJSON()
  376. break
  377. case "3":
  378. json := make(map[string]interface{})
  379. json["msg"] = "下下周" + week_name + "所先位置排班已经存在,无法保存"
  380. json["state"] = 0
  381. c.Data["json"] = json
  382. c.ServeJSON()
  383. break
  384. }
  385. return
  386. }
  387. } else { //新的排班信息
  388. fmt.Println("111111111")
  389. if items["schedule_date"] == nil || reflect.TypeOf(items["schedule_date"]).String() != "string" {
  390. fmt.Println("33333333")
  391. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  392. return
  393. }
  394. scheduleDate, _ := items["schedule_date"].(string)
  395. if len(scheduleDate) == 0 {
  396. utils.ErrorLog("len(schedule_date) == 0")
  397. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  398. return
  399. }
  400. timeLayout := "2006-01-02"
  401. loc, _ := time.LoadLocation("Local")
  402. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", scheduleDate+" 00:00:00", loc)
  403. if err != nil {
  404. utils.ErrorLog(err.Error())
  405. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  406. return
  407. }
  408. schedule.ScheduleDate = theTime.Unix()
  409. //existSch,_ := service.GetScheduleByDate(c.GetAdminUserInfo().CurrentOrgId,schedule.ScheduleDate,patient_id)
  410. //
  411. //if existSch.ID > 0{
  412. // fmt.Println("555555555")
  413. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  414. // return
  415. //
  416. //}
  417. timeNow := time.Now().Format("2006-01-02")
  418. if timeNow > scheduleDate {
  419. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleBeforeNow)
  420. return
  421. }
  422. scheduleType := int64(items["schedule_type"].(float64))
  423. if scheduleType < 1 || scheduleType > 3 {
  424. utils.ErrorLog("scheduleType < 3")
  425. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  426. return
  427. }
  428. schedule.ScheduleType = scheduleType
  429. if items["bed_id"] == nil || reflect.TypeOf(items["bed_id"]).String() != "float64" {
  430. fmt.Println("~~~~~~22222")
  431. utils.ErrorLog("bed_id")
  432. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  433. return
  434. }
  435. bedId := int64(items["bed_id"].(float64))
  436. if bedId < 1 {
  437. utils.ErrorLog("bedId < 1")
  438. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  439. return
  440. }
  441. schedule.BedId = bedId
  442. if items["zone_id"] == nil || reflect.TypeOf(items["zone_id"]).String() != "float64" {
  443. utils.ErrorLog("zone_id")
  444. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  445. return
  446. }
  447. partitionId := int64(items["zone_id"].(float64))
  448. if partitionId < 1 {
  449. utils.ErrorLog("zone_id < 1")
  450. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  451. return
  452. }
  453. schedule.PartitionId = partitionId
  454. if items["schedule_week"] == nil || reflect.TypeOf(items["schedule_week"]).String() != "float64" {
  455. utils.ErrorLog("schedule_week")
  456. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  457. return
  458. }
  459. scheduleWeek := int64(items["schedule_week"].(float64))
  460. if scheduleWeek < 1 || scheduleWeek > 7 {
  461. utils.ErrorLog("scheduleWeek < 1")
  462. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  463. return
  464. }
  465. schedule.ScheduleWeek = scheduleWeek
  466. if items["mode_id"] == nil || reflect.TypeOf(items["mode_id"]).String() != "float64" {
  467. utils.ErrorLog("mode_id")
  468. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  469. return
  470. }
  471. modeId := int64(items["mode_id"].(float64))
  472. if modeId < 1 && modeId > 14 {
  473. utils.ErrorLog("modeId < 1")
  474. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  475. return
  476. }
  477. //校验当天改床位是否有排班,如果有排班则不能替换排班
  478. sch, _ := service.GetScheduleByZoneAndBed(adminInfo.CurrentOrgId, partitionId, bedId, schedule.ScheduleDate, schedule.ScheduleType)
  479. fmt.Println(sch.PatientId)
  480. fmt.Println(schedule.PatientId)
  481. if sch.ID > 0 && sch.PatientId != patient_id {
  482. week_type, _ := items["week_type"].(string)
  483. week_name, _ := items["week_name"].(string)
  484. switch week_type {
  485. case "1":
  486. json := make(map[string]interface{})
  487. json["msg"] = "本周" + week_name + "该床位已经有人排班,无法保存"
  488. json["state"] = 0
  489. c.Data["json"] = json
  490. c.ServeJSON()
  491. break
  492. case "2":
  493. json := make(map[string]interface{})
  494. json["msg"] = "下周" + week_name + "该床位已经有人排班,无法保存"
  495. json["state"] = 0
  496. c.Data["json"] = json
  497. c.ServeJSON()
  498. break
  499. case "3":
  500. json := make(map[string]interface{})
  501. json["msg"] = "下下周" + week_name + "该床位已经有人排班,无法保存"
  502. json["state"] = 0
  503. c.Data["json"] = json
  504. c.ServeJSON()
  505. break
  506. }
  507. return
  508. }
  509. //daySchedule, err := service.GetDaySchedule(adminInfo.CurrentOrgId, theTime.Unix(), theTime.Unix(), patient_id)
  510. //if daySchedule.ID > 0 && daySchedule.ID != schedule.ID {
  511. // week_type, _ := items["week_type"].(string)
  512. // week_name, _ := items["week_name"].(string)
  513. //
  514. // switch week_type {
  515. // case "1":
  516. // json := make(map[string]interface{})
  517. // json["msg"] = "本周" + week_name + "该床位已经有人排班,无法保存"
  518. // json["state"] = 0
  519. // c.Data["json"] = json
  520. // c.ServeJSON()
  521. // break
  522. // case "2":
  523. // json := make(map[string]interface{})
  524. // json["msg"] = "下周" + week_name + "当天该患者已经排班,无法保存"
  525. // json["state"] = 0
  526. // c.Data["json"] = json
  527. // c.ServeJSON()
  528. // break
  529. // case "3":
  530. // json := make(map[string]interface{})
  531. // json["msg"] = "下下周" + week_name + "当天该患者已经排班,无法保存"
  532. // json["state"] = 0
  533. // c.Data["json"] = json
  534. // c.ServeJSON()
  535. // break
  536. // }
  537. //
  538. // return
  539. //
  540. //
  541. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleAgainOneDay)
  542. // return
  543. //}
  544. //
  545. }
  546. }
  547. }
  548. }
  549. ////删除数据
  550. if dataBody["del_schs"] != nil && reflect.TypeOf(dataBody["del_schs"]).String() == "[]interface {}" {
  551. schs, _ := dataBody["del_schs"].([]interface{})
  552. if len(schs) > 0 {
  553. for _, item := range schs {
  554. items := item.(map[string]interface{})
  555. if items["sch_id"] == nil || reflect.TypeOf(items["sch_id"]).String() != "float64" {
  556. utils.ErrorLog("id")
  557. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  558. return
  559. }
  560. var schedule models.Schedule
  561. sch_id := int64(items["sch_id"].(float64))
  562. if sch_id > 0 { //修改排班信息
  563. schedule, _ = service.GetScheduleTwo(adminInfo.CurrentOrgId, sch_id)
  564. schedule.Status = 0
  565. service.SaveSch(schedule)
  566. }
  567. HandleRedis(adminInfo.CurrentOrgId, schedule.ScheduleDate)
  568. }
  569. }
  570. }
  571. ////修改或保存数据
  572. if dataBody["smart_schs"] != nil && reflect.TypeOf(dataBody["smart_schs"]).String() == "[]interface {}" {
  573. schs, _ := dataBody["smart_schs"].([]interface{})
  574. if len(schs) > 0 {
  575. for _, item := range schs {
  576. items := item.(map[string]interface{})
  577. if items["sch_id"] == nil || reflect.TypeOf(items["sch_id"]).String() != "float64" {
  578. utils.ErrorLog("id")
  579. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  580. return
  581. }
  582. var schedule models.Schedule
  583. //var oldSchedule *models.Schedule
  584. sch_id := int64(items["sch_id"].(float64))
  585. if sch_id > 0 { //修改排班信息
  586. fmt.Println("!!!!!!!")
  587. schedule, _ = service.GetScheduleTwo(adminInfo.CurrentOrgId, sch_id)
  588. if items["mode_id"] == nil || reflect.TypeOf(items["mode_id"]).String() != "float64" {
  589. fmt.Println(reflect.TypeOf(items["mode_id"]))
  590. utils.ErrorLog("mode_id")
  591. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  592. return
  593. }
  594. modeId := int64(items["mode_id"].(float64))
  595. if modeId < 1 {
  596. utils.ErrorLog("modeId < 1")
  597. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  598. return
  599. }
  600. schedule.ModeId = modeId
  601. order, err := service.GetOneDialysisOrder(adminInfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
  602. if err != nil {
  603. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  604. return
  605. }
  606. if order != nil {
  607. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeMode)
  608. return
  609. }
  610. if order != nil {
  611. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeDeviceNumber)
  612. return
  613. }
  614. if items["schedule_type"] == nil || reflect.TypeOf(items["schedule_type"]).String() != "float64" {
  615. utils.ErrorLog("schedule_type")
  616. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  617. return
  618. }
  619. scheduleType := int64(items["schedule_type"].(float64))
  620. if scheduleType < 1 || scheduleType > 3 {
  621. utils.ErrorLog("scheduleType < 3")
  622. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  623. return
  624. }
  625. schedule.ScheduleType = scheduleType
  626. if items["bed_id"] == nil || reflect.TypeOf(items["bed_id"]).String() != "float64" {
  627. utils.ErrorLog("bed_id")
  628. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  629. return
  630. }
  631. bedId := int64(items["bed_id"].(float64))
  632. if bedId < 1 {
  633. utils.ErrorLog("bedId < 1")
  634. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  635. return
  636. }
  637. schedule.BedId = bedId
  638. if items["zone_id"] == nil || reflect.TypeOf(items["zone_id"]).String() != "float64" {
  639. utils.ErrorLog("zone_id")
  640. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  641. return
  642. }
  643. partitionId := int64(items["zone_id"].(float64))
  644. if partitionId < 1 {
  645. utils.ErrorLog("partitionId < 1")
  646. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  647. return
  648. }
  649. schedule.PartitionId = partitionId
  650. bed, _ := service.GetDeviceNumberByID(adminInfo.CurrentOrgId, schedule.BedId)
  651. if bed == nil {
  652. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotExist)
  653. return
  654. }
  655. if bed.ZoneID != schedule.PartitionId {
  656. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotTheZone)
  657. return
  658. }
  659. startTime := schedule.ScheduleDate
  660. endTime := startTime + 86399
  661. //一天只有排班一次
  662. daySchedule, err := service.GetDaySchedule(adminInfo.CurrentOrgId, startTime, endTime, schedule.PatientId)
  663. if daySchedule.ID > 0 && daySchedule.ID != schedule.ID {
  664. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleAgainOneDay)
  665. return
  666. }
  667. //同天同位置只能排一个
  668. pointSchedule, err := service.GetPointSchedule(adminInfo.CurrentOrgId, schedule.ScheduleDate, schedule.ScheduleWeek, schedule.ScheduleType, schedule.BedId)
  669. if err != nil {
  670. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  671. return
  672. }
  673. if pointSchedule.ID > 0 && pointSchedule.PatientId != patient_id {
  674. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePointScheduleExist)
  675. return
  676. }
  677. var DialysisMachineName string
  678. so, _ := service.GetDialysisSolutionTwo(adminInfo.CurrentOrgId, schedule.PatientId, schedule.ModeId)
  679. filedRecordOne, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "透析器")
  680. filedRecordTwo, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "灌流器")
  681. filedRecordThree, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "透析器/灌流器")
  682. if filedRecordOne.IsShow == 1 {
  683. DialysisMachineName = so.DialysisDialyszers
  684. }
  685. if filedRecordThree.IsShow == 1 {
  686. if len(DialysisMachineName) > 0 {
  687. DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
  688. } else {
  689. DialysisMachineName = so.DialyzerPerfusionApparatus
  690. }
  691. }
  692. if filedRecordTwo.IsShow == 1 {
  693. if len(DialysisMachineName) > 0 {
  694. DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
  695. } else {
  696. DialysisMachineName = so.DialysisIrrigation
  697. }
  698. }
  699. schedule.DialysisMachineName = DialysisMachineName
  700. schedule.IsExport = 3000
  701. service.SaveSch(schedule)
  702. } else { //新的排班信息
  703. if items["schedule_date"] == nil || reflect.TypeOf(items["schedule_date"]).String() != "string" {
  704. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  705. return
  706. }
  707. scheduleDate, _ := items["schedule_date"].(string)
  708. if len(scheduleDate) == 0 {
  709. utils.ErrorLog("len(schedule_date) == 0")
  710. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  711. return
  712. }
  713. timeLayout := "2006-01-02"
  714. loc, _ := time.LoadLocation("Local")
  715. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", scheduleDate+" 00:00:00", loc)
  716. if err != nil {
  717. utils.ErrorLog(err.Error())
  718. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  719. return
  720. }
  721. schedule.ScheduleDate = theTime.Unix()
  722. timeNow := time.Now().Format("2006-01-02")
  723. if timeNow > scheduleDate {
  724. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleBeforeNow)
  725. return
  726. }
  727. scheduleType := int64(items["schedule_type"].(float64))
  728. if scheduleType < 1 || scheduleType > 3 {
  729. utils.ErrorLog("scheduleType < 3")
  730. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  731. return
  732. }
  733. schedule.ScheduleType = scheduleType
  734. if items["bed_id"] == nil || reflect.TypeOf(items["bed_id"]).String() != "float64" {
  735. utils.ErrorLog("bed_id")
  736. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  737. return
  738. }
  739. bedId := int64(items["bed_id"].(float64))
  740. if bedId < 1 {
  741. utils.ErrorLog("bedId < 1")
  742. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  743. return
  744. }
  745. schedule.BedId = bedId
  746. if items["zone_id"] == nil || reflect.TypeOf(items["zone_id"]).String() != "float64" {
  747. utils.ErrorLog("zone_id")
  748. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  749. return
  750. }
  751. partitionId := int64(items["zone_id"].(float64))
  752. if partitionId < 1 {
  753. utils.ErrorLog("zone_id < 1")
  754. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  755. return
  756. }
  757. schedule.PartitionId = partitionId
  758. if items["schedule_week"] == nil || reflect.TypeOf(items["schedule_week"]).String() != "float64" {
  759. utils.ErrorLog("schedule_week")
  760. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  761. return
  762. }
  763. scheduleWeek := int64(items["schedule_week"].(float64))
  764. if scheduleWeek < 1 || scheduleWeek > 7 {
  765. utils.ErrorLog("scheduleWeek < 1")
  766. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  767. return
  768. }
  769. schedule.ScheduleWeek = scheduleWeek
  770. if items["mode_id"] == nil || reflect.TypeOf(items["mode_id"]).String() != "float64" {
  771. fmt.Println(reflect.TypeOf(items["mode_id"]))
  772. utils.ErrorLog("mode_id")
  773. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  774. return
  775. }
  776. modeId := int64(items["mode_id"].(float64))
  777. if modeId < 1 && modeId > 14 {
  778. utils.ErrorLog("modeId < 1")
  779. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  780. return
  781. }
  782. //校验当天改床位是否有排班,如果有排班则不能替换排班
  783. sch, _ := service.GetScheduleByZoneAndBed(adminInfo.CurrentOrgId, partitionId, bedId, schedule.ScheduleDate, schedule.ScheduleType)
  784. if sch.ID > 0 && sch.PatientId != patient_id {
  785. c.ServeFailJSONWithSGJErrorCode(enums.ErrorSchedualcRepeatBed)
  786. return
  787. }
  788. var DialysisMachineName string
  789. so, _ := service.GetDialysisSolutionTwo(adminInfo.CurrentOrgId, schedule.PatientId, schedule.ModeId)
  790. filedRecordOne, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "透析器")
  791. filedRecordTwo, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "灌流器")
  792. filedRecordThree, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "透析器/灌流器")
  793. if filedRecordOne.IsShow == 1 {
  794. DialysisMachineName = so.DialysisDialyszers
  795. }
  796. if filedRecordThree.IsShow == 1 {
  797. if len(schedule.DialysisMachineName) > 0 {
  798. DialysisMachineName = DialysisMachineName + "," + so.DialyzerPerfusionApparatus
  799. } else {
  800. DialysisMachineName = so.DialyzerPerfusionApparatus
  801. }
  802. }
  803. if filedRecordTwo.IsShow == 1 {
  804. if len(DialysisMachineName) > 0 {
  805. DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
  806. } else {
  807. DialysisMachineName = so.DialysisIrrigation
  808. }
  809. }
  810. schedule.DialysisMachineName = DialysisMachineName
  811. //判断当前保存的患者是否已经有排班
  812. existSchedule, _ := service.GetScheduleByDate(adminInfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
  813. if existSchedule.ID > 0 {
  814. existSchedule.ModeId = modeId
  815. existSchedule.BedId = schedule.BedId
  816. existSchedule.PartitionId = schedule.PartitionId
  817. existSchedule.ScheduleType = schedule.ScheduleType
  818. existSchedule.DialysisMachineName = schedule.DialysisMachineName
  819. existSchedule.IsExport = 3001
  820. service.SaveSmartSch(existSchedule)
  821. } else {
  822. schedule.ModeId = modeId
  823. schedule.PatientId = patient_id
  824. schedule.CreatedTime = time.Now().Unix()
  825. schedule.UpdatedTime = time.Now().Unix()
  826. schedule.Status = 1
  827. schedule.UserOrgId = adminInfo.CurrentOrgId
  828. var DialysisMachineName string
  829. so, _ := service.GetDialysisSolutionTwo(adminInfo.CurrentOrgId, schedule.PatientId, schedule.ModeId)
  830. filedRecordOne, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "透析器")
  831. filedRecordTwo, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "灌流器")
  832. filedRecordThree, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "透析器/灌流器")
  833. if filedRecordOne.IsShow == 1 {
  834. DialysisMachineName = so.DialysisDialyszers
  835. }
  836. if filedRecordThree.IsShow == 1 {
  837. if len(DialysisMachineName) > 0 {
  838. DialysisMachineName = DialysisMachineName + "," + so.DialyzerPerfusionApparatus
  839. } else {
  840. DialysisMachineName = so.DialyzerPerfusionApparatus
  841. }
  842. }
  843. if filedRecordTwo.IsShow == 1 {
  844. if len(DialysisMachineName) > 0 {
  845. DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
  846. } else {
  847. DialysisMachineName = so.DialysisIrrigation
  848. }
  849. }
  850. schedule.DialysisMachineName = DialysisMachineName
  851. //schedule.DialysisMachineName = schedule.DialysisMachineName
  852. daySchedule, _ := service.GetDaySchedule(adminInfo.CurrentOrgId, theTime.Unix(), theTime.Unix(), patient_id)
  853. if daySchedule.ID > 0 {
  854. daySchedule.ModeId = schedule.ModeId
  855. daySchedule.ScheduleType = schedule.ScheduleType
  856. daySchedule.PartitionId = schedule.PartitionId
  857. daySchedule.BedId = schedule.BedId
  858. daySchedule.DialysisMachineName = schedule.DialysisMachineName
  859. existSchedule.IsExport = 3002
  860. service.SaveSch(daySchedule)
  861. } else {
  862. existSchedule.IsExport = 3003
  863. service.CreateSchedule(&schedule)
  864. }
  865. }
  866. }
  867. c.ServeSuccessJSON(map[string]interface{}{
  868. "msg": "保存成功",
  869. })
  870. HandleRedis(adminInfo.CurrentOrgId, schedule.ScheduleDate)
  871. }
  872. }
  873. }
  874. }
  875. func HandleRedis(org_id int64, sch_date int64) {
  876. redis := service.RedisClient()
  877. //处方
  878. keyOne := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(sch_date, 10) + ":prescriptions_list_all"
  879. redis.Set(keyOne, "", time.Second)
  880. //医嘱
  881. keyTwo := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(sch_date, 10) + ":advice_list_all"
  882. redis.Set(keyTwo, "", time.Second)
  883. keySix := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(sch_date, 10) + ":assessment_befores_list_all"
  884. redis.Set(keySix, "", time.Second)
  885. keyThree := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(sch_date, 10) + ":assessment_after_dislysis_list_all"
  886. redis.Set(keyThree, "", time.Second)
  887. keyFour := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(sch_date, 10) + ":monitor_record_list_all"
  888. redis.Set(keyFour, "", time.Second)
  889. keyFive := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(sch_date, 10) + ":treatment_summarys_list_all"
  890. redis.Set(keyFive, "", time.Second)
  891. keySeven := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(sch_date, 10) + ":dialysis_orders_list_all"
  892. redis.Set(keySeven, "", time.Second)
  893. defer redis.Close()
  894. }
  895. func (c *ScheduleApiController) GetSmartSch() {
  896. patient_id, _ := c.GetInt64("patient_id")
  897. fmt.Println("~~~~~~")
  898. fmt.Println(patient_id)
  899. fmt.Println("~~~~~~")
  900. adminUserInfo := c.GetAdminUserInfo()
  901. sch, err := service.GetSmartSchPatientByPatientID(adminUserInfo.CurrentOrgId, patient_id)
  902. if err != nil {
  903. utils.ErrorLog(err.Error())
  904. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  905. return
  906. }
  907. c.ServeSuccessJSON(map[string]interface{}{
  908. "sch": sch,
  909. })
  910. }
  911. func (c *ScheduleApiController) GetPatient() {
  912. keyWord := c.GetString("keyword")
  913. adminUserInfo := c.GetAdminUserInfo()
  914. patient, err := service.GetSmartSchPatientByKeyWord(adminUserInfo.CurrentOrgId, keyWord)
  915. if err != nil {
  916. utils.ErrorLog(err.Error())
  917. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  918. return
  919. }
  920. c.ServeSuccessJSON(map[string]interface{}{
  921. "patient": patient,
  922. })
  923. }
  924. func (c *ScheduleApiController) GetPatientSchTemplate() {
  925. //patient_id, _ := c.GetInt64("patient_id",0)
  926. keyWord := c.GetString("keyword")
  927. adminUserInfo := c.GetAdminUserInfo()
  928. patient, err := service.GetSmartSchTemplatePatientByKeyWord(adminUserInfo.CurrentOrgId, keyWord)
  929. if err != nil {
  930. utils.ErrorLog(err.Error())
  931. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  932. return
  933. }
  934. c.ServeSuccessJSON(map[string]interface{}{
  935. "patient": patient,
  936. })
  937. }
  938. func (c *ScheduleApiController) GetPatientSmartSch() {
  939. patient_id, _ := c.GetInt64("patient_id", 0)
  940. adminUserInfo := c.GetAdminUserInfo()
  941. schs, err := service.GetSmartSchPatientByID(adminUserInfo.CurrentOrgId, patient_id)
  942. if err != nil {
  943. utils.ErrorLog(err.Error())
  944. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  945. return
  946. }
  947. c.ServeSuccessJSON(map[string]interface{}{
  948. "schedules": schs,
  949. })
  950. }
  951. func (c *ScheduleApiController) GetPatientSmartSchTemplate() {
  952. patient_id, _ := c.GetInt64("patient_id", 0)
  953. adminUserInfo := c.GetAdminUserInfo()
  954. mode, _ := service.GetOrgPatientScheduleTemplateModeTwo(adminUserInfo.CurrentOrgId)
  955. if mode.ID > 0 {
  956. if mode.Mode == 0 {
  957. //schs, _ := service.GetSmartSchTemplatePatientByID(adminUserInfo.CurrentOrgId, patient_id)
  958. c.ServeSuccessJSON(map[string]interface{}{
  959. "status": 0,
  960. })
  961. } else if mode.Mode == 1 {
  962. schs, _ := service.GetSmartSchTemplatePatientByID(adminUserInfo.CurrentOrgId, patient_id, 1)
  963. c.ServeSuccessJSON(map[string]interface{}{
  964. "status": 0,
  965. "schedules_template": schs,
  966. })
  967. } else if mode.Mode == 2 {
  968. schs, _ := service.GetSmartSchTemplatePatientByID(adminUserInfo.CurrentOrgId, patient_id, 2)
  969. c.ServeSuccessJSON(map[string]interface{}{
  970. "status": 1,
  971. "schedules_template": schs,
  972. })
  973. } else if mode.Mode == 3 {
  974. schs, _ := service.GetSmartSchTemplatePatientByID(adminUserInfo.CurrentOrgId, patient_id, 3)
  975. c.ServeSuccessJSON(map[string]interface{}{
  976. "status": 1,
  977. "schedules_template": schs,
  978. })
  979. } else if mode.Mode == 4 {
  980. schs, _ := service.GetSmartSchTemplatePatientByID(adminUserInfo.CurrentOrgId, patient_id, 4)
  981. c.ServeSuccessJSON(map[string]interface{}{
  982. "status": 1,
  983. "schedules_template": schs,
  984. })
  985. }
  986. } else {
  987. c.ServeSuccessJSON(map[string]interface{}{
  988. "status": 0,
  989. })
  990. }
  991. }
  992. func (c *ScheduleApiController) GetDevicesNumbers() {
  993. sch_type, _ := c.GetInt("sch_type", 0)
  994. zone_id, _ := c.GetInt64("zone_id", 0)
  995. patient_id, _ := c.GetInt64("patient_id", 0)
  996. schedule_date := c.GetString("schedule_date")
  997. timeLayout := "2006-01-02"
  998. loc, _ := time.LoadLocation("Local")
  999. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", schedule_date+" 00:00:00", loc)
  1000. if err != nil {
  1001. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1002. return
  1003. }
  1004. recordDateTime := theTime.Unix()
  1005. deviceNumbers, getDeviceNumbersErr := service.GetAllAvaildDeviceNumbersByZone(c.GetAdminUserInfo().CurrentOrgId, recordDateTime, sch_type, zone_id, patient_id)
  1006. if getDeviceNumbersErr != nil {
  1007. c.ErrorLog("获取所有床位失败:%v", getDeviceNumbersErr)
  1008. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1009. return
  1010. }
  1011. c.ServeSuccessJSON(map[string]interface{}{
  1012. "devices": deviceNumbers,
  1013. })
  1014. }
  1015. func (c *ScheduleApiController) GetWeekPanels() {
  1016. data, _ := c.GetInt64("data", 1)
  1017. patitionIdStr := c.GetString("patitionid")
  1018. var ids []string
  1019. if len(patitionIdStr) > 0 {
  1020. ids = strings.Split(patitionIdStr, ",")
  1021. }
  1022. adminInfo := c.GetAdminUserInfo()
  1023. thisTime := time.Now()
  1024. year, monthTime, day := thisTime.Date()
  1025. month := int(monthTime)
  1026. _, theWeek := thisTime.ISOWeek()
  1027. lastWeek := thisTime.AddDate(0, 0, -7)
  1028. nextWeek := thisTime.AddDate(0, 0, 7)
  1029. nextSecWeek := thisTime.AddDate(0, 0, 14)
  1030. _, theLastWeek := lastWeek.ISOWeek()
  1031. _, theNextWeek := nextWeek.ISOWeek()
  1032. _, theNextSecWeek := nextSecWeek.ISOWeek()
  1033. weekDay := int(thisTime.Weekday())
  1034. if weekDay == 0 {
  1035. weekDay = 7
  1036. }
  1037. weekEnd := 7 - weekDay
  1038. weekStart := weekEnd - 6
  1039. weekDays := make([]string, 0)
  1040. for index := weekStart; index <= weekEnd; index++ {
  1041. theDay := thisTime.AddDate(0, 0, index)
  1042. indexYear, indexMonthTime, indexDay := theDay.Date()
  1043. indexMonth := int(indexMonthTime)
  1044. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  1045. weekDays = append(weekDays, indexWeek)
  1046. }
  1047. returnData := map[string]interface{}{
  1048. "year": year,
  1049. "month": month,
  1050. "day": day,
  1051. "theWeek": theWeek,
  1052. "theNextWeek": theNextWeek,
  1053. "theNextSecWeek": theNextSecWeek,
  1054. "theLastWeek": theLastWeek,
  1055. "weekDay": weekDay,
  1056. "weekDays": weekDays,
  1057. }
  1058. if data == 1 {
  1059. fmt.Println(ids)
  1060. partitions, _ := service.GetSchedulePartitionPanelOne(adminInfo.CurrentOrgId, ids)
  1061. fmt.Println("````~~")
  1062. fmt.Println(partitions)
  1063. returnData["partitions"] = partitions
  1064. }
  1065. c.ServeSuccessJSON(returnData)
  1066. return
  1067. }
  1068. func (c *ScheduleApiController) GetSchedules() {
  1069. week, _ := c.GetInt64("weekTime", 0) //1:last, 2:this 3:next 4 nextTwo
  1070. partition_id, _ := c.GetInt64("partition_id")
  1071. schedule_type, _ := c.GetInt64("schedule_type")
  1072. adminInfo := c.GetAdminUserInfo()
  1073. thisTime := time.Now()
  1074. today := thisTime.Format("2006-01-02")
  1075. if week < 1 || week > 4 {
  1076. week = 2
  1077. }
  1078. if week == 1 {
  1079. thisTime = thisTime.AddDate(0, 0, -7)
  1080. } else if week == 3 {
  1081. thisTime = thisTime.AddDate(0, 0, 7)
  1082. } else if week == 4 {
  1083. thisTime = thisTime.AddDate(0, 0, 14)
  1084. }
  1085. weekDay := int(thisTime.Weekday())
  1086. if weekDay == 0 {
  1087. weekDay = 7
  1088. }
  1089. weekEnd := 7 - weekDay
  1090. weekStart := weekEnd - 6
  1091. weekTitle := make([]string, 0)
  1092. days := make([]string, 0)
  1093. for index := weekStart; index <= weekEnd; index++ {
  1094. theDay := thisTime.AddDate(0, 0, index)
  1095. indexYear, indexMonthTime, indexDay := theDay.Date()
  1096. indexMonth := int(indexMonthTime)
  1097. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  1098. weekTitle = append(weekTitle, indexWeek)
  1099. days = append(days, theDay.Format("2006-01-02"))
  1100. }
  1101. weekStartDay := thisTime.AddDate(0, 0, weekStart)
  1102. weekEndDay := thisTime.AddDate(0, 0, weekEnd)
  1103. weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
  1104. weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
  1105. timeLayout := "2006-01-02 15:04:05"
  1106. loc, _ := time.LoadLocation("Local")
  1107. theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
  1108. theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
  1109. weekStartPoint := theStarTime.Unix()
  1110. weekEndPoint := theEndTime.Unix()
  1111. schdules, _ := service.GetWeekScheduleOne(adminInfo.CurrentOrgId, weekStartPoint, weekEndPoint, partition_id, schedule_type)
  1112. c.ServeSuccessJSON(map[string]interface{}{
  1113. "days": days,
  1114. "weekTitle": weekTitle,
  1115. "schdules": schdules,
  1116. "today": today,
  1117. })
  1118. return
  1119. }
  1120. func (c *ScheduleApiController) GetPatients() {
  1121. keywords := c.GetString("keywords", "")
  1122. schedule, _ := c.GetInt64("schedule", 0) //1已2未
  1123. contagion, _ := c.GetInt64("contagion", 0)
  1124. adminInfo := c.GetAdminUserInfo()
  1125. thisTime := time.Now()
  1126. weekDay := int(thisTime.Weekday())
  1127. if weekDay == 0 {
  1128. weekDay = 7
  1129. }
  1130. thisWeekEnd := 7 - weekDay
  1131. weekStartPoint := thisWeekEnd - 6
  1132. weekStartDay := thisTime.AddDate(0, 0, weekStartPoint)
  1133. weekEndPoint := thisWeekEnd + 7
  1134. weekEndDay := thisTime.AddDate(0, 0, weekEndPoint)
  1135. fmt.Println(weekStartPoint, weekStartDay, weekEndPoint, weekEndDay)
  1136. weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
  1137. weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
  1138. fmt.Println(weekStartTime, weekEndTime)
  1139. timeLayout := "2006-01-02 15:04:05"
  1140. loc, _ := time.LoadLocation("Local")
  1141. theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
  1142. theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
  1143. weekStart := theStarTime.Unix()
  1144. weekEnd := theEndTime.Unix()
  1145. patients, _ := service.GetPatientWithScheduleAndSolution(adminInfo.CurrentOrgId, keywords, weekStart, weekEnd, schedule, contagion)
  1146. fmt.Println("patinets23233232323232232322323wode", patients)
  1147. c.ServeSuccessJSON(map[string]interface{}{
  1148. "patients": patients,
  1149. })
  1150. return
  1151. }
  1152. func (c *ScheduleApiController) CreateSchedule() {
  1153. patientID, _ := c.GetInt64("patient_id", 0)
  1154. if patientID <= 0 {
  1155. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1156. return
  1157. }
  1158. adminUserInfo := c.GetAdminUserInfo()
  1159. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patientID)
  1160. if patientInfo.ID == 0 {
  1161. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1162. return
  1163. }
  1164. var schedule models.Schedule
  1165. dataBody := make(map[string]interface{}, 0)
  1166. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1167. if err != nil {
  1168. utils.ErrorLog(err.Error())
  1169. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1170. return
  1171. }
  1172. if dataBody["schedule_date"] == nil || reflect.TypeOf(dataBody["schedule_date"]).String() != "string" {
  1173. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1174. return
  1175. }
  1176. scheduleDate, _ := dataBody["schedule_date"].(string)
  1177. if len(scheduleDate) == 0 {
  1178. utils.ErrorLog("len(schedule_date) == 0")
  1179. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1180. return
  1181. }
  1182. timeLayout := "2006-01-02"
  1183. loc, _ := time.LoadLocation("Local")
  1184. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", scheduleDate+" 00:00:00", loc)
  1185. if err != nil {
  1186. utils.ErrorLog(err.Error())
  1187. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1188. return
  1189. }
  1190. schedule.ScheduleDate = theTime.Unix()
  1191. timeNow := time.Now().Format("2006-01-02")
  1192. if timeNow > scheduleDate {
  1193. utils.ErrorLog(timeNow)
  1194. utils.ErrorLog(scheduleDate)
  1195. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleBeforeNow)
  1196. return
  1197. }
  1198. if dataBody["schedule_type"] == nil || reflect.TypeOf(dataBody["schedule_type"]).String() != "float64" {
  1199. utils.ErrorLog("schedule_type")
  1200. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1201. return
  1202. }
  1203. scheduleType := int64(dataBody["schedule_type"].(float64))
  1204. if scheduleType < 1 || scheduleType > 3 {
  1205. utils.ErrorLog("scheduleType < 3")
  1206. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1207. return
  1208. }
  1209. schedule.ScheduleType = scheduleType
  1210. if dataBody["bed_id"] == nil || reflect.TypeOf(dataBody["bed_id"]).String() != "float64" {
  1211. utils.ErrorLog("bed_id")
  1212. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1213. return
  1214. }
  1215. bedId := int64(dataBody["bed_id"].(float64))
  1216. if bedId < 1 {
  1217. utils.ErrorLog("bedId < 1")
  1218. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1219. return
  1220. }
  1221. schedule.BedId = bedId
  1222. if dataBody["partition_id"] == nil || reflect.TypeOf(dataBody["partition_id"]).String() != "float64" {
  1223. utils.ErrorLog("partition_id")
  1224. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1225. return
  1226. }
  1227. partitionId := int64(dataBody["partition_id"].(float64))
  1228. if partitionId < 1 {
  1229. utils.ErrorLog("partitionId < 1")
  1230. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1231. return
  1232. }
  1233. schedule.PartitionId = partitionId
  1234. if dataBody["schedule_week"] == nil || reflect.TypeOf(dataBody["schedule_week"]).String() != "float64" {
  1235. utils.ErrorLog("schedule_week")
  1236. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1237. return
  1238. }
  1239. scheduleWeek := int64(dataBody["schedule_week"].(float64))
  1240. if scheduleWeek < 1 || scheduleWeek > 7 {
  1241. utils.ErrorLog("scheduleWeek < 1")
  1242. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1243. return
  1244. }
  1245. schedule.ScheduleWeek = scheduleWeek
  1246. if dataBody["mode_id"] == nil || reflect.TypeOf(dataBody["mode_id"]).String() != "float64" {
  1247. utils.ErrorLog("mode_id")
  1248. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1249. return
  1250. }
  1251. modeId := int64(dataBody["mode_id"].(float64))
  1252. if modeId < 1 && modeId > 14 {
  1253. utils.ErrorLog("modeId < 1")
  1254. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1255. return
  1256. }
  1257. schedule.ModeId = modeId
  1258. schedule.PatientId = patientID
  1259. schedule.CreatedTime = time.Now().Unix()
  1260. schedule.UpdatedTime = time.Now().Unix()
  1261. schedule.Status = 1
  1262. schedule.UserOrgId = adminUserInfo.CurrentOrgId
  1263. schedule.IsExport = 5
  1264. var DialysisMachineName string
  1265. so, _ := service.GetDialysisSolutionTwo(adminUserInfo.CurrentOrgId, schedule.PatientId, schedule.ModeId)
  1266. filedRecordOne, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "透析器")
  1267. filedRecordTwo, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "灌流器")
  1268. filedRecordThree, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "透析器/灌流器")
  1269. if filedRecordOne.IsShow == 1 {
  1270. DialysisMachineName = so.DialysisDialyszers
  1271. }
  1272. if filedRecordThree.IsShow == 1 {
  1273. if len(DialysisMachineName) > 0 {
  1274. DialysisMachineName = DialysisMachineName + "," + so.DialyzerPerfusionApparatus
  1275. } else {
  1276. DialysisMachineName = so.DialyzerPerfusionApparatus
  1277. }
  1278. }
  1279. if filedRecordTwo.IsShow == 1 {
  1280. if len(DialysisMachineName) > 0 {
  1281. DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
  1282. } else {
  1283. DialysisMachineName = so.DialysisIrrigation
  1284. }
  1285. }
  1286. schedule.DialysisMachineName = DialysisMachineName
  1287. bed, _ := service.GetDeviceNumberByID(adminUserInfo.CurrentOrgId, schedule.BedId)
  1288. if bed == nil {
  1289. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotExist)
  1290. return
  1291. }
  1292. if bed.ZoneID != schedule.PartitionId {
  1293. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotTheZone)
  1294. return
  1295. }
  1296. scheduleDateStart := scheduleDate + " 00:00:00"
  1297. scheduleDateEnd := scheduleDate + " 23:59:59"
  1298. timeLayout = "2006-01-02 15:04:05"
  1299. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  1300. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  1301. startTime := theStartTime.Unix()
  1302. endTime := theEndTime.Unix()
  1303. //一天只有排班一次
  1304. daySchedule, err := service.GetDaySchedule(adminUserInfo.CurrentOrgId, startTime, endTime, patientID)
  1305. if daySchedule.ID > 0 {
  1306. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleAgainOneDay)
  1307. return
  1308. }
  1309. //同天同位置只能排一个
  1310. pointSchedule, err := service.GetPointSchedule(adminUserInfo.CurrentOrgId, schedule.ScheduleDate, schedule.ScheduleWeek, schedule.ScheduleType, schedule.BedId)
  1311. if err != nil {
  1312. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1313. return
  1314. }
  1315. if pointSchedule.ID > 0 {
  1316. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePointScheduleExist)
  1317. return
  1318. }
  1319. redis := service.RedisClient()
  1320. schedule.IsExport = 1000
  1321. err = service.CreateSchedule(&schedule)
  1322. key := "scheduals_" + scheduleDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1323. redis.Set(key, "", time.Second)
  1324. //处方
  1325. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":prescriptions_list_all"
  1326. redis.Set(keyOne, "", time.Second)
  1327. //医嘱
  1328. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":advice_list_all"
  1329. redis.Set(keyTwo, "", time.Second)
  1330. keySix := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_befores_list_all"
  1331. redis.Set(keySix, "", time.Second)
  1332. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_after_dislysis_list_all"
  1333. redis.Set(keyThree, "", time.Second)
  1334. keyFour := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":monitor_record_list_all"
  1335. redis.Set(keyFour, "", time.Second)
  1336. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":treatment_summarys_list_all"
  1337. redis.Set(keyFive, "", time.Second)
  1338. keySeven := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":dialysis_orders_list_all"
  1339. redis.Set(keySeven, "", time.Second)
  1340. fmt.Println(err)
  1341. defer redis.Close()
  1342. if err != nil {
  1343. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateScheduleFail)
  1344. return
  1345. }
  1346. schedule.Patient = patientInfo.Name
  1347. c.ServeSuccessJSON(map[string]interface{}{
  1348. "msg": "ok",
  1349. "schedule": schedule,
  1350. })
  1351. return
  1352. }
  1353. func (c *ScheduleApiController) DeleteSchedule() {
  1354. id, _ := c.GetInt64("id", 0)
  1355. if id <= 0 {
  1356. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1357. return
  1358. }
  1359. adminINfo := c.GetAdminUserInfo()
  1360. schedule, _ := service.GetSchedule(adminINfo.CurrentOrgId, id)
  1361. timeNow := time.Now().Format("2006-01-02")
  1362. timeTemplate := "2006-01-02"
  1363. tm := time.Unix(int64(schedule.ScheduleDate), 0)
  1364. timeStr := tm.Format(timeTemplate)
  1365. if timeNow > timeStr {
  1366. utils.ErrorLog(timeNow)
  1367. utils.ErrorLog(timeStr)
  1368. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleBeforeNow)
  1369. return
  1370. }
  1371. if schedule == nil {
  1372. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist)
  1373. return
  1374. }
  1375. order, err := service.GetOneDialysisOrder(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
  1376. if err != nil {
  1377. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1378. return
  1379. }
  1380. if order != nil {
  1381. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDelScheduleFailByDialysis)
  1382. return
  1383. }
  1384. schedule.Status = 0
  1385. schedule.UpdatedTime = time.Now().Unix()
  1386. err = service.UpdateSchedule(schedule)
  1387. redis := service.RedisClient()
  1388. //处方
  1389. keyOne := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":prescriptions_list_all"
  1390. redis.Set(keyOne, "", time.Second)
  1391. //医嘱
  1392. keyTwo := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":advice_list_all"
  1393. redis.Set(keyTwo, "", time.Second)
  1394. keySix := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_befores_list_all"
  1395. redis.Set(keySix, "", time.Second)
  1396. keyThree := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_after_dislysis_list_all"
  1397. redis.Set(keyThree, "", time.Second)
  1398. keyFour := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":monitor_record_list_all"
  1399. redis.Set(keyFour, "", time.Second)
  1400. keyFive := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":treatment_summarys_list_all"
  1401. redis.Set(keyFive, "", time.Second)
  1402. keySeven := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":dialysis_orders_list_all"
  1403. redis.Set(keySeven, "", time.Second)
  1404. fmt.Println(err)
  1405. defer redis.Close()
  1406. if err != nil {
  1407. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteScheduleFail)
  1408. return
  1409. }
  1410. c.ServeSuccessJSON(map[string]interface{}{
  1411. "msg": "ok",
  1412. "schedule": &schedule,
  1413. })
  1414. }
  1415. func (c *ScheduleApiController) ChangeSchedule() {
  1416. id, _ := c.GetInt64("id", 0)
  1417. if id <= 0 {
  1418. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1419. return
  1420. }
  1421. adminINfo := c.GetAdminUserInfo()
  1422. schedule, _ := service.GetSchedule(adminINfo.CurrentOrgId, id)
  1423. if schedule == nil {
  1424. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist)
  1425. return
  1426. }
  1427. dataBody := make(map[string]interface{}, 0)
  1428. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1429. if err != nil {
  1430. utils.ErrorLog(err.Error())
  1431. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1432. return
  1433. }
  1434. if dataBody["change_action"] == nil || reflect.TypeOf(dataBody["change_action"]).String() != "string" {
  1435. utils.ErrorLog("change_action")
  1436. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1437. return
  1438. }
  1439. changeAction := dataBody["change_action"].(string)
  1440. if changeAction == "change_mode" {
  1441. if dataBody["mode_id"] == nil || reflect.TypeOf(dataBody["mode_id"]).String() != "float64" {
  1442. utils.ErrorLog("mode_id")
  1443. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrongForSchMode)
  1444. return
  1445. }
  1446. modeId := int64(dataBody["mode_id"].(float64))
  1447. if modeId < 1 {
  1448. utils.ErrorLog("modeId < 1")
  1449. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrongForSchMode)
  1450. return
  1451. }
  1452. schedule.ModeId = modeId
  1453. so, _ := service.GetDialysisSolutionTwo(adminINfo.CurrentOrgId, schedule.PatientId, schedule.ModeId)
  1454. filedRecordOne, _ := service.FindFiledBy(adminINfo.CurrentOrgId, "透析器")
  1455. filedRecordTwo, _ := service.FindFiledBy(adminINfo.CurrentOrgId, "灌流器")
  1456. filedRecordThree, _ := service.FindFiledBy(adminINfo.CurrentOrgId, "透析器/灌流器")
  1457. var DialysisMachineName string
  1458. if filedRecordOne.IsShow == 1 {
  1459. DialysisMachineName = so.DialysisDialyszers
  1460. fmt.Println("1111")
  1461. fmt.Println(DialysisMachineName)
  1462. }
  1463. if filedRecordThree.IsShow == 1 {
  1464. if len(schedule.DialysisMachineName) > 0 {
  1465. DialysisMachineName = DialysisMachineName + "," + so.DialyzerPerfusionApparatus
  1466. fmt.Println("22222")
  1467. fmt.Println(DialysisMachineName)
  1468. } else {
  1469. DialysisMachineName = so.DialyzerPerfusionApparatus
  1470. fmt.Println("333333")
  1471. fmt.Println(DialysisMachineName)
  1472. }
  1473. }
  1474. if filedRecordTwo.IsShow == 1 {
  1475. if len(DialysisMachineName) > 0 {
  1476. DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
  1477. fmt.Println("55555555")
  1478. fmt.Println(DialysisMachineName)
  1479. } else {
  1480. DialysisMachineName = so.DialysisIrrigation
  1481. fmt.Println("66666666")
  1482. fmt.Println(DialysisMachineName)
  1483. }
  1484. }
  1485. schedule.DialysisMachineName = DialysisMachineName
  1486. order, err := service.GetOneDialysisOrder(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
  1487. if err != nil {
  1488. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1489. return
  1490. }
  1491. if order != nil {
  1492. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeMode)
  1493. return
  1494. }
  1495. } else if changeAction == "change_device" {
  1496. order, err := service.GetOneDialysisOrder(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
  1497. if err != nil {
  1498. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1499. return
  1500. }
  1501. if order != nil {
  1502. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeDeviceNumber)
  1503. return
  1504. }
  1505. if dataBody["schedule_type"] == nil || reflect.TypeOf(dataBody["schedule_type"]).String() != "float64" {
  1506. utils.ErrorLog("schedule_type")
  1507. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1508. return
  1509. }
  1510. scheduleType := int64(dataBody["schedule_type"].(float64))
  1511. if scheduleType < 1 || scheduleType > 3 {
  1512. utils.ErrorLog("scheduleType < 3")
  1513. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1514. return
  1515. }
  1516. schedule.ScheduleType = scheduleType
  1517. if dataBody["bed_id"] == nil || reflect.TypeOf(dataBody["bed_id"]).String() != "float64" {
  1518. utils.ErrorLog("bed_id")
  1519. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1520. return
  1521. }
  1522. bedId := int64(dataBody["bed_id"].(float64))
  1523. if bedId < 1 {
  1524. utils.ErrorLog("bedId < 1")
  1525. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1526. return
  1527. }
  1528. schedule.BedId = bedId
  1529. if dataBody["partition_id"] == nil || reflect.TypeOf(dataBody["partition_id"]).String() != "float64" {
  1530. utils.ErrorLog("partition_id")
  1531. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1532. return
  1533. }
  1534. partitionId := int64(dataBody["partition_id"].(float64))
  1535. if partitionId < 1 {
  1536. utils.ErrorLog("partitionId < 1")
  1537. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1538. return
  1539. }
  1540. schedule.PartitionId = partitionId
  1541. bed, _ := service.GetDeviceNumberByID(adminINfo.CurrentOrgId, schedule.BedId)
  1542. if bed == nil {
  1543. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotExist)
  1544. return
  1545. }
  1546. if bed.ZoneID != schedule.PartitionId {
  1547. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotTheZone)
  1548. return
  1549. }
  1550. startTime := schedule.ScheduleDate
  1551. endTime := startTime + 86399
  1552. //一天只有排班一次
  1553. daySchedule, err := service.GetDaySchedule(adminINfo.CurrentOrgId, startTime, endTime, schedule.PatientId)
  1554. if daySchedule.ID > 0 && daySchedule.ID != schedule.ID {
  1555. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleAgainOneDay)
  1556. return
  1557. }
  1558. //同天同位置只能排一个
  1559. pointSchedule, err := service.GetPointSchedule(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.ScheduleWeek, schedule.ScheduleType, schedule.BedId)
  1560. if err != nil {
  1561. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1562. return
  1563. }
  1564. if pointSchedule.ID > 0 {
  1565. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePointScheduleExist)
  1566. return
  1567. }
  1568. } else {
  1569. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1570. return
  1571. }
  1572. schedule.UpdatedTime = time.Now().Unix()
  1573. err = service.UpdateSchedule(schedule)
  1574. prescription := models.DialysisPrescription{
  1575. ModeId: schedule.ModeId,
  1576. }
  1577. _, errcode := service.GetDialysisPrescribe(schedule.UserOrgId, schedule.PatientId, schedule.ScheduleDate)
  1578. if errcode == gorm.ErrRecordNotFound {
  1579. if err != nil {
  1580. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeScheduleFail)
  1581. return
  1582. }
  1583. c.ServeSuccessJSON(map[string]interface{}{
  1584. "msg": "ok",
  1585. "schedule": &schedule,
  1586. })
  1587. } else if errcode == nil {
  1588. err = service.UpdatedDialysisPrescription(&prescription, schedule.ScheduleDate, schedule.PatientId, schedule.UserOrgId)
  1589. if err != nil {
  1590. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeScheduleFail)
  1591. return
  1592. }
  1593. c.ServeSuccessJSON(map[string]interface{}{
  1594. "msg": "ok",
  1595. "schedule": &schedule,
  1596. })
  1597. }
  1598. }
  1599. // /api/schedule/print/initdata [get]
  1600. // @param date:string yyyy-MM-dd 要打印的那一周中的任一天
  1601. func (this *ScheduleApiController) PrintInitData() {
  1602. dateStr := this.GetString("date")
  1603. //week_type, _ := this.GetInt64("type", 0)
  1604. var date *time.Time
  1605. if len(dateStr) == 0 {
  1606. now := time.Now()
  1607. date = &now
  1608. } else {
  1609. var parseErr error
  1610. date, parseErr = utils.ParseTimeStringToTime("2006-01-02", dateStr)
  1611. if parseErr != nil {
  1612. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1613. return
  1614. }
  1615. }
  1616. adminUserInfo := this.GetAdminUserInfo()
  1617. // 获取本周的排班
  1618. var monday time.Time
  1619. var sunday time.Time
  1620. //switch week_type {
  1621. //case 1:
  1622. monday, sunday = utils.GetMondayAndSundayOfWeekDate(date)
  1623. // break
  1624. //case 2:
  1625. // monday, sunday = utils.GetMondayAndSundayOfNextWeekDate(date)
  1626. //
  1627. // break
  1628. //case 3:
  1629. // monday, sunday = utils.GetMondayAndSundayOfNextNextWeekDate(date)
  1630. // break
  1631. //}
  1632. schedules, getScheduleErr := service.GetPrinitWeekSchedules(adminUserInfo.CurrentOrgId, monday.Unix(), sunday.Unix())
  1633. total, getScheduleErr := service.GetPrinitWeekTotal(adminUserInfo.CurrentOrgId, monday.Unix(), sunday.Unix())
  1634. if getScheduleErr != nil {
  1635. this.ErrorLog("获取周排班失败:%v", getScheduleErr)
  1636. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1637. return
  1638. }
  1639. thisTime := date
  1640. weekDay := int(thisTime.Weekday())
  1641. if weekDay == 0 {
  1642. weekDay = 7
  1643. }
  1644. weekEnd := 7 - weekDay
  1645. weekStart := weekEnd - 6
  1646. days := make([]string, 0)
  1647. for index := weekStart; index <= weekEnd; index++ {
  1648. theDay := thisTime.AddDate(0, 0, index)
  1649. days = append(days, theDay.Format("2006-01-02"))
  1650. }
  1651. this.ServeSuccessJSON(map[string]interface{}{
  1652. "total": total,
  1653. "schedules": schedules,
  1654. "monday": monday.Unix(),
  1655. "days": days,
  1656. })
  1657. }
  1658. func (this *ScheduleApiController) UrgentScheduleData() {
  1659. schedule_type, _ := this.GetInt("type", 0)
  1660. schedule_date := this.GetString("date")
  1661. var date *time.Time
  1662. if len(schedule_date) == 0 {
  1663. now := time.Now()
  1664. date = &now
  1665. } else {
  1666. var parseErr error
  1667. date, parseErr = utils.ParseTimeStringToTime("2006-01-02", schedule_date)
  1668. if parseErr != nil {
  1669. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1670. return
  1671. }
  1672. }
  1673. adminUserInfo := this.GetAdminUserInfo()
  1674. deviceNumbers, getDeviceNumbersErr := service.MobileGetAllDeviceNumbersForUrgentSchedule(adminUserInfo.CurrentOrgId, date.Unix(), schedule_type)
  1675. if getDeviceNumbersErr != nil {
  1676. this.ErrorLog("获取所有床位失败:%v", getDeviceNumbersErr)
  1677. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1678. return
  1679. }
  1680. // today := utils.ZeroHourTimeOfDay(time.Now())
  1681. schedules, getSchedulesErr := service.MobileGetOtherSchedulesForUrgentSchedule(adminUserInfo.CurrentOrgId, date.Unix(), schedule_type)
  1682. if getSchedulesErr != nil {
  1683. this.ErrorLog("获取所有排班失败:%v", getSchedulesErr)
  1684. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1685. return
  1686. }
  1687. this.ServeSuccessJSON(map[string]interface{}{
  1688. "device_numbers": deviceNumbers,
  1689. "schedules": schedules,
  1690. })
  1691. }
  1692. func (this *ScheduleApiController) SearchSchedulePatients() {
  1693. keywords := this.GetString("keywords")
  1694. week_type, _ := this.GetInt64("week_type", 0)
  1695. start_sch := this.GetString("start_sch")
  1696. end_sch := this.GetString("end_sch")
  1697. thisTime1 := time.Now()
  1698. thisTime2 := time.Now()
  1699. thisTime1 = thisTime1.AddDate(0, 0, 7)
  1700. thisTime2 = thisTime2.AddDate(0, 0, 14)
  1701. var start_time string
  1702. var end_time string
  1703. switch week_type {
  1704. case 1:
  1705. timeLayout := "2006-01-02"
  1706. loc, _ := time.LoadLocation("Local")
  1707. var startSchTime int64
  1708. if len(start_sch) > 0 {
  1709. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_sch+" 00:00:00", loc)
  1710. startSchTime = theTime.Unix()
  1711. }
  1712. var endSchTime int64
  1713. if len(end_sch) > 0 {
  1714. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_sch+" 00:00:00", loc)
  1715. endSchTime = theTime.Unix()
  1716. }
  1717. adminUserInfo := this.GetAdminUserInfo()
  1718. list, _ := service.GetSchedualPatientsByKeywords(keywords, adminUserInfo.CurrentOrgId, startSchTime, endSchTime)
  1719. this.ServeSuccessJSON(map[string]interface{}{
  1720. "schdules": list,
  1721. })
  1722. break
  1723. case 2:
  1724. days := make([]string, 0)
  1725. weekDay1 := int(thisTime1.Weekday())
  1726. if weekDay1 == 0 {
  1727. weekDay1 = 7
  1728. }
  1729. weekEnd1 := 7 - weekDay1
  1730. weekStart1 := weekEnd1 - 6
  1731. for index := weekStart1; index <= weekEnd1; index++ {
  1732. fmt.Println(index)
  1733. theDay := thisTime1.AddDate(0, 0, index)
  1734. days = append(days, theDay.Format("2006-01-02"))
  1735. }
  1736. fmt.Println(days)
  1737. start_time = days[0]
  1738. end_time = days[len(days)-1]
  1739. timeLayout := "2006-01-02"
  1740. loc, _ := time.LoadLocation("Local")
  1741. var theStartTime int64
  1742. if len(start_time) > 0 {
  1743. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1744. theStartTime = theTime.Unix()
  1745. }
  1746. var theEndtTime int64
  1747. if len(end_time) > 0 {
  1748. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1749. theEndtTime = theTime.Unix()
  1750. }
  1751. adminUserInfo := this.GetAdminUserInfo()
  1752. list, _ := service.GetSchedualPatientsByKeywordsAndWeek(keywords, adminUserInfo.CurrentOrgId, theStartTime, theEndtTime)
  1753. this.ServeSuccessJSON(map[string]interface{}{
  1754. "schdules": list,
  1755. })
  1756. break
  1757. case 3:
  1758. days := make([]string, 0)
  1759. weekDay2 := int(thisTime2.Weekday())
  1760. if weekDay2 == 0 {
  1761. weekDay2 = 7
  1762. }
  1763. weekEnd2 := 7 - weekDay2
  1764. weekStart2 := weekEnd2 - 6
  1765. for index := weekStart2; index <= weekEnd2; index++ {
  1766. theDay := thisTime2.AddDate(0, 0, index)
  1767. days = append(days, theDay.Format("2006-01-02"))
  1768. }
  1769. start_time = days[0]
  1770. end_time = days[len(days)-1]
  1771. timeLayout := "2006-01-02"
  1772. loc, _ := time.LoadLocation("Local")
  1773. var theStartTime int64
  1774. if len(start_time) > 0 {
  1775. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1776. theStartTime = theTime.Unix()
  1777. }
  1778. var theEndtTime int64
  1779. if len(end_time) > 0 {
  1780. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1781. theEndtTime = theTime.Unix()
  1782. }
  1783. adminUserInfo := this.GetAdminUserInfo()
  1784. list, _ := service.GetSchedualPatientsByKeywordsAndWeek(keywords, adminUserInfo.CurrentOrgId, theStartTime, theEndtTime)
  1785. this.ServeSuccessJSON(map[string]interface{}{
  1786. "schdules": list,
  1787. })
  1788. break
  1789. }
  1790. }
  1791. func (this *ScheduleApiController) GetWeekDaySchedule() {
  1792. week_type, _ := this.GetInt64("week_type", -1)
  1793. week_time, _ := this.GetInt64("week_time")
  1794. thisTime := time.Now()
  1795. weekDay := int(thisTime.Weekday())
  1796. if weekDay == 0 {
  1797. weekDay = 7
  1798. }
  1799. weekEnd := 7 - weekDay
  1800. weekStart := weekEnd - 6
  1801. weekTitle := make([]string, 0)
  1802. days := make([]string, 0)
  1803. for index := weekStart; index <= weekEnd; index++ {
  1804. theDay := thisTime.AddDate(0, 0, index)
  1805. indexYear, indexMonthTime, indexDay := theDay.Date()
  1806. indexMonth := int(indexMonthTime)
  1807. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  1808. weekTitle = append(weekTitle, indexWeek)
  1809. days = append(days, theDay.Format("2006-01-02"))
  1810. }
  1811. fmt.Println(days)
  1812. var targetDayStr string
  1813. var startTime string
  1814. var endTime string
  1815. switch week_type {
  1816. case 0:
  1817. {
  1818. startTime = days[0]
  1819. endTime = days[6]
  1820. }
  1821. case 1:
  1822. targetDayStr = days[0]
  1823. break
  1824. case 2:
  1825. targetDayStr = days[1]
  1826. break
  1827. case 3:
  1828. targetDayStr = days[2]
  1829. break
  1830. case 4:
  1831. targetDayStr = days[3]
  1832. break
  1833. case 5:
  1834. targetDayStr = days[4]
  1835. break
  1836. case 6:
  1837. targetDayStr = days[5]
  1838. break
  1839. case 7:
  1840. targetDayStr = days[6]
  1841. break
  1842. }
  1843. targetDay, parseErr := utils.ParseTimeStringToTime("2006-01-02", targetDayStr)
  1844. startDay, _ := utils.ParseTimeStringToTime("2006-01-02", startTime)
  1845. endDay, _ := utils.ParseTimeStringToTime("2006-01-02", endTime)
  1846. fmt.Println(startDay, endDay)
  1847. if parseErr != nil {
  1848. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1849. return
  1850. }
  1851. orgId := this.GetAdminUserInfo().CurrentOrgId
  1852. list, _ := service.GetWeekDayScheduleTwo(orgId, targetDay.Unix(), targetDay, week_time)
  1853. this.ServeSuccessJSON(map[string]interface{}{
  1854. "schdules": list,
  1855. "day": targetDayStr,
  1856. })
  1857. }
  1858. func Struct2Map(obj interface{}) map[string]interface{} {
  1859. t := reflect.TypeOf(obj)
  1860. v := reflect.ValueOf(obj)
  1861. var data = make(map[string]interface{})
  1862. for i := 0; i < t.NumField(); i++ {
  1863. data[t.Field(i).Name] = v.Field(i).Interface()
  1864. }
  1865. return data
  1866. }
  1867. func (this *ScheduleApiController) ExportSchedule() {
  1868. dataBody := make(map[string]interface{}, 0)
  1869. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1870. if err != nil {
  1871. utils.ErrorLog(err.Error())
  1872. return
  1873. }
  1874. utils.ErrorLog("%v", dataBody)
  1875. export_time := time.Now().Unix()
  1876. var schedules []*models.Schedule
  1877. var failed_total int
  1878. var total_schedule []interface{}
  1879. var patients []*models.Patients
  1880. patients, _, _ = service.GetAllPatientList(this.GetAdminUserInfo().CurrentOrgId)
  1881. start_time := dataBody["start_time"].(string)
  1882. end_time := dataBody["end_time"].(string)
  1883. delete_type := int64(dataBody["delete_type"].(float64))
  1884. fmt.Println("delete_type", delete_type)
  1885. timeLayout := "2006-01-02"
  1886. loc, _ := time.LoadLocation("Local")
  1887. theTimeStart, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1888. theTimeEnd, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  1889. fmt.Println("theTimeStart23232322332322323", theTimeStart.Unix())
  1890. fmt.Println("theTimeStart23232322332322323", theTimeEnd.Unix())
  1891. if dataBody["failed_schedule"] != nil || reflect.TypeOf(dataBody["failed_schedule"]).String() == "[]interface {}" {
  1892. tempSchedule := dataBody["failed_schedule"].([]interface{})
  1893. failed_total = len(tempSchedule)
  1894. }
  1895. if dataBody["schedule"] != nil || reflect.TypeOf(dataBody["schedule"]).String() == "[]interface {}" {
  1896. tempSchedule := dataBody["schedule"].([]interface{})
  1897. total_schedule = tempSchedule
  1898. for _, schMap := range tempSchedule {
  1899. schMapM := schMap.(map[string]interface{})
  1900. var sch models.Schedule
  1901. if schMapM["name"] == nil || reflect.TypeOf(schMapM["name"]).String() != "string" {
  1902. utils.ErrorLog("name")
  1903. return
  1904. }
  1905. name, _ := schMapM["name"].(string)
  1906. fmt.Println(name)
  1907. if len(name) == 0 { //名字为空则生成一条导入错误日志
  1908. err_log := models.ExportErrLog{
  1909. LogType: 2,
  1910. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1911. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名不能为空",
  1912. Status: 1,
  1913. CreateTime: time.Now().Unix(),
  1914. UpdateTime: time.Now().Unix(),
  1915. ExportTime: export_time,
  1916. }
  1917. service.CreateExportErrLog(&err_log)
  1918. continue
  1919. } else {
  1920. var patient []*models.Patients
  1921. for _, item := range patients {
  1922. if strings.Replace(item.Name, " ", "", -1) == name {
  1923. patient = append(patient, item)
  1924. }
  1925. }
  1926. if len(patient) == 0 { //错误日志
  1927. err_log := models.ExportErrLog{
  1928. LogType: 2,
  1929. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1930. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列,患者姓名为\"" + name + "\"在系统中不存在,请在系统中添加该患者",
  1931. Status: 1,
  1932. CreateTime: time.Now().Unix(),
  1933. UpdateTime: time.Now().Unix(),
  1934. ExportTime: export_time,
  1935. }
  1936. service.CreateExportErrLog(&err_log)
  1937. continue
  1938. } else if len(patient) == 1 { //
  1939. sch.PatientId = patient[0].ID
  1940. } else if len(patient) > 1 { //出现同名的情况
  1941. err_log := models.ExportErrLog{
  1942. LogType: 2,
  1943. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1944. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列" + "患者姓名为" + name + "在当前机构中存在重名,无法确定到具体患者",
  1945. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列,患者姓名为\"" + name + "\"在在当前机构中存在重名,无法确定到具体患者",
  1946. Status: 1,
  1947. CreateTime: time.Now().Unix(),
  1948. UpdateTime: time.Now().Unix(),
  1949. ExportTime: export_time,
  1950. }
  1951. service.CreateExportErrLog(&err_log)
  1952. continue
  1953. }
  1954. }
  1955. if schMapM["schedule_type"] == nil && reflect.TypeOf(schMapM["schedule_type"]).String() != "float64" {
  1956. utils.ErrorLog("schedule_type")
  1957. return
  1958. }
  1959. schedule_type := int64(schMapM["schedule_type"].(float64))
  1960. if schedule_type <= 0 { //班次格式有误,插入日志
  1961. log := models.ExportLog{
  1962. LogType: 2,
  1963. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1964. TotalNum: int64(len(total_schedule) + failed_total),
  1965. FailNum: 1 + int64(failed_total),
  1966. SuccessNum: int64(len(schedules)),
  1967. CreateTime: time.Now().Unix(),
  1968. UpdateTime: time.Now().Unix(),
  1969. ExportTime: export_time,
  1970. Status: 1,
  1971. }
  1972. service.CreateExportLog(&log)
  1973. err_log := models.ExportErrLog{
  1974. LogType: 2,
  1975. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1976. ErrMsg: "第2行第" + schMapM["row"].(string) + "列的班次格式有误",
  1977. Status: 1,
  1978. CreateTime: time.Now().Unix(),
  1979. UpdateTime: time.Now().Unix(),
  1980. ExportTime: export_time,
  1981. }
  1982. service.CreateExportErrLog(&err_log)
  1983. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1984. return
  1985. } else {
  1986. sch.ScheduleType = schedule_type
  1987. }
  1988. if schMapM["partition_name"] == nil || reflect.TypeOf(schMapM["partition_name"]).String() != "string" {
  1989. utils.ErrorLog("partition_name")
  1990. return
  1991. }
  1992. partition_name, _ := schMapM["partition_name"].(string)
  1993. if len(partition_name) == 0 { //分区为空
  1994. log := models.ExportLog{
  1995. LogType: 2,
  1996. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1997. TotalNum: int64(len(total_schedule) + failed_total),
  1998. FailNum: 1 + int64(failed_total),
  1999. SuccessNum: int64(len(schedules)),
  2000. CreateTime: time.Now().Unix(),
  2001. UpdateTime: time.Now().Unix(),
  2002. ExportTime: export_time,
  2003. Status: 1,
  2004. }
  2005. service.CreateExportLog(&log)
  2006. err_log := models.ExportErrLog{
  2007. LogType: 2,
  2008. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2009. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  2010. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第1列所属的分区格式有误",
  2011. Status: 1,
  2012. CreateTime: time.Now().Unix(),
  2013. UpdateTime: time.Now().Unix(),
  2014. ExportTime: export_time,
  2015. }
  2016. service.CreateExportErrLog(&err_log)
  2017. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2018. return
  2019. } else {
  2020. zone, err := service.FindDeviceZoneByName(partition_name, this.GetAdminUserInfo().CurrentOrgId)
  2021. if err == nil {
  2022. sch.PartitionId = zone.ID
  2023. } else if err == gorm.ErrRecordNotFound { //查不到数据,插入错误日志
  2024. log := models.ExportLog{
  2025. LogType: 2,
  2026. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2027. TotalNum: int64(len(total_schedule) + failed_total),
  2028. FailNum: 1 + int64(failed_total),
  2029. SuccessNum: int64(len(schedules)),
  2030. CreateTime: time.Now().Unix(),
  2031. UpdateTime: time.Now().Unix(),
  2032. ExportTime: export_time,
  2033. Status: 1,
  2034. }
  2035. service.CreateExportLog(&log)
  2036. err_log := models.ExportErrLog{
  2037. LogType: 2,
  2038. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2039. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  2040. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第1列所属的分区格式有误",
  2041. Status: 1,
  2042. CreateTime: time.Now().Unix(),
  2043. UpdateTime: time.Now().Unix(),
  2044. ExportTime: export_time,
  2045. }
  2046. service.CreateExportErrLog(&err_log)
  2047. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2048. return
  2049. }
  2050. }
  2051. if schMapM["device_number_name"] == nil || reflect.TypeOf(schMapM["device_number_name"]).String() != "string" {
  2052. utils.ErrorLog("device_number_name")
  2053. return
  2054. }
  2055. device_number_name, _ := schMapM["device_number_name"].(string)
  2056. if len(device_number_name) == 0 { //分区为空
  2057. log := models.ExportLog{
  2058. LogType: 2,
  2059. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2060. TotalNum: int64(len(total_schedule) + failed_total),
  2061. FailNum: 1 + int64(failed_total),
  2062. SuccessNum: int64(len(schedules)),
  2063. CreateTime: time.Now().Unix(),
  2064. UpdateTime: time.Now().Unix(),
  2065. ExportTime: export_time,
  2066. Status: 1,
  2067. }
  2068. service.CreateExportLog(&log)
  2069. err_log := models.ExportErrLog{
  2070. LogType: 2,
  2071. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2072. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  2073. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
  2074. Status: 1,
  2075. CreateTime: time.Now().Unix(),
  2076. UpdateTime: time.Now().Unix(),
  2077. ExportTime: export_time,
  2078. }
  2079. service.CreateExportErrLog(&err_log)
  2080. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2081. return
  2082. } else {
  2083. device, err := service.FindDeviceByName(device_number_name, this.GetAdminUserInfo().CurrentOrgId, sch.PartitionId)
  2084. if err == nil {
  2085. if len(device) == 0 { //没查到数据,插入错误日志
  2086. log := models.ExportLog{
  2087. LogType: 2,
  2088. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2089. TotalNum: int64(len(total_schedule) + failed_total),
  2090. FailNum: 1 + int64(failed_total),
  2091. SuccessNum: int64(len(schedules)),
  2092. CreateTime: time.Now().Unix(),
  2093. UpdateTime: time.Now().Unix(),
  2094. ExportTime: export_time,
  2095. Status: 1,
  2096. }
  2097. service.CreateExportLog(&log)
  2098. err_log := models.ExportErrLog{
  2099. LogType: 2,
  2100. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2101. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
  2102. Status: 1,
  2103. CreateTime: time.Now().Unix(),
  2104. UpdateTime: time.Now().Unix(),
  2105. ExportTime: export_time,
  2106. }
  2107. service.CreateExportErrLog(&err_log)
  2108. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2109. return
  2110. } else if len(device) == 1 {
  2111. sch.BedId = device[0].ID
  2112. } else if len(device) > 1 { //出现重名,插入错误日志
  2113. log := models.ExportLog{
  2114. LogType: 2,
  2115. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2116. TotalNum: int64(len(total_schedule) + failed_total),
  2117. FailNum: 1 + int64(failed_total),
  2118. SuccessNum: int64(len(schedules)),
  2119. CreateTime: time.Now().Unix(),
  2120. UpdateTime: time.Now().Unix(),
  2121. ExportTime: export_time,
  2122. Status: 1,
  2123. }
  2124. service.CreateExportLog(&log)
  2125. err_log := models.ExportErrLog{
  2126. LogType: 2,
  2127. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2128. ErrMsg: "出现两个床位号相同的床位",
  2129. Status: 1,
  2130. CreateTime: time.Now().Unix(),
  2131. UpdateTime: time.Now().Unix(),
  2132. ExportTime: export_time,
  2133. }
  2134. service.CreateExportErrLog(&err_log)
  2135. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2136. return
  2137. }
  2138. }
  2139. }
  2140. if schMapM["schedule_week"] == nil || reflect.TypeOf(schMapM["schedule_week"]).String() != "string" {
  2141. utils.ErrorLog("schedule_week")
  2142. return
  2143. }
  2144. schedule_week, _ := schMapM["schedule_week"].(string)
  2145. if len(schedule_week) == 0 { //周几为空则生成一条导入错误日志
  2146. log := models.ExportLog{
  2147. LogType: 2,
  2148. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2149. TotalNum: int64(len(total_schedule) + failed_total),
  2150. FailNum: 1 + int64(failed_total),
  2151. SuccessNum: int64(len(schedules)),
  2152. CreateTime: time.Now().Unix(),
  2153. UpdateTime: time.Now().Unix(),
  2154. ExportTime: export_time,
  2155. Status: 1,
  2156. }
  2157. service.CreateExportLog(&log)
  2158. err_log := models.ExportErrLog{
  2159. LogType: 2,
  2160. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2161. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  2162. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  2163. Status: 1,
  2164. CreateTime: time.Now().Unix(),
  2165. UpdateTime: time.Now().Unix(),
  2166. ExportTime: export_time,
  2167. }
  2168. service.CreateExportErrLog(&err_log)
  2169. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2170. return
  2171. } else if schedule_week == "0" { //周几不符合格式则生成一条导入错误日志
  2172. log := models.ExportLog{
  2173. LogType: 2,
  2174. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2175. TotalNum: int64(len(total_schedule) + failed_total),
  2176. FailNum: 1 + int64(failed_total),
  2177. SuccessNum: int64(len(schedules)),
  2178. CreateTime: time.Now().Unix(),
  2179. UpdateTime: time.Now().Unix(),
  2180. ExportTime: export_time,
  2181. Status: 1,
  2182. }
  2183. service.CreateExportLog(&log)
  2184. err_log := models.ExportErrLog{
  2185. LogType: 2,
  2186. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2187. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  2188. Status: 1,
  2189. CreateTime: time.Now().Unix(),
  2190. UpdateTime: time.Now().Unix(),
  2191. ExportTime: export_time,
  2192. }
  2193. service.CreateExportErrLog(&err_log)
  2194. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2195. return
  2196. } else {
  2197. schedule_week, _ := strconv.ParseInt(schedule_week, 10, 64)
  2198. sch.ScheduleWeek = schedule_week
  2199. }
  2200. if schMapM["schedule_date"] == nil || reflect.TypeOf(schMapM["schedule_date"]).String() != "string" {
  2201. utils.ErrorLog("schedule_date")
  2202. return
  2203. }
  2204. schedule_date, _ := schMapM["schedule_date"].(string)
  2205. if len(schedule_date) == 0 { //周几为空则生成一条导入错误日志
  2206. log := models.ExportLog{
  2207. LogType: 2,
  2208. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2209. TotalNum: int64(len(total_schedule) + failed_total),
  2210. FailNum: 1 + int64(failed_total),
  2211. SuccessNum: int64(len(schedules)),
  2212. CreateTime: time.Now().Unix(),
  2213. UpdateTime: time.Now().Unix(),
  2214. ExportTime: export_time,
  2215. Status: 1,
  2216. }
  2217. service.CreateExportLog(&log)
  2218. err_log := models.ExportErrLog{
  2219. LogType: 2,
  2220. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2221. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  2222. Status: 1,
  2223. CreateTime: time.Now().Unix(),
  2224. UpdateTime: time.Now().Unix(),
  2225. ExportTime: export_time,
  2226. }
  2227. service.CreateExportErrLog(&err_log)
  2228. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2229. return
  2230. } else if schedule_date == "0" { //周几不符合格式则生成一条导入错误日志
  2231. log := models.ExportLog{
  2232. LogType: 2,
  2233. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2234. TotalNum: int64(len(total_schedule) + failed_total),
  2235. FailNum: 1 + int64(failed_total),
  2236. SuccessNum: int64(len(schedules)),
  2237. CreateTime: time.Now().Unix(),
  2238. UpdateTime: time.Now().Unix(),
  2239. ExportTime: export_time,
  2240. Status: 1,
  2241. }
  2242. service.CreateExportLog(&log)
  2243. err_log := models.ExportErrLog{
  2244. LogType: 2,
  2245. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2246. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  2247. Status: 1,
  2248. CreateTime: time.Now().Unix(),
  2249. UpdateTime: time.Now().Unix(),
  2250. ExportTime: export_time,
  2251. }
  2252. service.CreateExportErrLog(&err_log)
  2253. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2254. return
  2255. } else {
  2256. date, _ := utils.ParseTimeStringToTime("2006-01-02", schedule_date)
  2257. sch.ScheduleDate = date.Unix()
  2258. }
  2259. sch.CreatedTime = time.Now().Unix()
  2260. sch.UpdatedTime = time.Now().Unix()
  2261. sch.ModeId = 1
  2262. sch.Status = 1
  2263. sch.UserOrgId = this.GetAdminUserInfo().CurrentOrgId
  2264. sch.IsExport = 1
  2265. var DialysisMachineName string
  2266. so, _ := service.GetDialysisSolutionTwo(sch.UserOrgId, sch.PatientId, sch.ModeId)
  2267. filedRecordOne, _ := service.FindFiledBy(sch.UserOrgId, "透析器")
  2268. filedRecordTwo, _ := service.FindFiledBy(sch.UserOrgId, "灌流器")
  2269. filedRecordThree, _ := service.FindFiledBy(sch.UserOrgId, "透析器/灌流器")
  2270. if filedRecordOne.IsShow == 1 {
  2271. DialysisMachineName = so.DialysisDialyszers
  2272. }
  2273. if filedRecordThree.IsShow == 1 {
  2274. if len(DialysisMachineName) > 0 {
  2275. DialysisMachineName = DialysisMachineName + "," + so.DialyzerPerfusionApparatus
  2276. } else {
  2277. DialysisMachineName = so.DialyzerPerfusionApparatus
  2278. }
  2279. }
  2280. if filedRecordTwo.IsShow == 1 {
  2281. if len(DialysisMachineName) > 0 {
  2282. DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
  2283. } else {
  2284. DialysisMachineName = so.DialysisIrrigation
  2285. }
  2286. }
  2287. sch.DialysisMachineName = DialysisMachineName
  2288. schedules = append(schedules, &sch)
  2289. }
  2290. errLogs, _ := service.FindSchedualExportLog(this.GetAdminUserInfo().CurrentOrgId, export_time)
  2291. if len(schedules) > 0 {
  2292. schedule_date := time.Now().Format("2006-01-02")
  2293. date, _ := utils.ParseTimeStringToTime("2006-01-02", schedule_date)
  2294. clear_schedule_date := date.Unix() //根据日期去清除,该日期未来的排班数据
  2295. service.UpdateScheduleByExport(this.GetAdminUserInfo().CurrentOrgId, clear_schedule_date)
  2296. if err == nil {
  2297. for _, item := range schedules {
  2298. if item.ScheduleDate > clear_schedule_date {
  2299. //查询该患者是否转出获取死亡
  2300. fmt.Println("11111323242423")
  2301. //查找当天日期是否存在
  2302. _, errcode := service.GetTodayScheduleIsExistOne(item.PatientId, item.ScheduleDate, item.UserOrgId)
  2303. if errcode == gorm.ErrRecordNotFound {
  2304. //查询该床位是否有患者
  2305. fmt.Println("errcodes")
  2306. sch, errcodes := service.GetPatientByBed(item.ScheduleDate, item.BedId, item.ScheduleType, item.UserOrgId)
  2307. fmt.Println("errcodes")
  2308. fmt.Println(errcodes)
  2309. fmt.Println(sch)
  2310. if errcodes == gorm.ErrRecordNotFound {
  2311. fmt.Println("1111111")
  2312. service.CreateSchedule(item)
  2313. } else if errcodes == nil {
  2314. fmt.Println("1111222222222")
  2315. //清除当天该床位已有的患者
  2316. service.ModeFyScheduleById(sch.ScheduleDate, sch.BedId, sch.ScheduleType, sch.UserOrgId)
  2317. service.CreateSchedule(item)
  2318. }
  2319. } else if errcode == nil {
  2320. schedule := models.XtSchedule{
  2321. PartitionId: item.PartitionId,
  2322. BedId: item.BedId,
  2323. PatientId: item.PatientId,
  2324. ScheduleDate: item.ScheduleDate,
  2325. ScheduleType: item.ScheduleType,
  2326. ScheduleWeek: item.ScheduleWeek,
  2327. ModeId: 1,
  2328. Status: 1,
  2329. DialysisMachineName: item.DialysisMachineName,
  2330. }
  2331. fmt.Println("1111222222223333333333333333332")
  2332. service.UpdateScheduleByOrgIdOne(item.PatientId, item.ScheduleDate, item.UserOrgId, &schedule)
  2333. }
  2334. }
  2335. }
  2336. log := models.ExportLog{
  2337. LogType: 2,
  2338. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2339. TotalNum: int64(len(total_schedule) + failed_total),
  2340. FailNum: int64(len(errLogs) + failed_total),
  2341. SuccessNum: int64(len(schedules)),
  2342. CreateTime: time.Now().Unix(),
  2343. UpdateTime: time.Now().Unix(),
  2344. ExportTime: export_time,
  2345. Status: 1,
  2346. }
  2347. service.CreateExportLog(&log)
  2348. if failed_total > 0 {
  2349. err_log := models.ExportErrLog{
  2350. LogType: 2,
  2351. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2352. ErrMsg: "当前日期(" + time.Now().Format("2006-01-02") + " " + GetWeekString(time.Now().Weekday().String()) +
  2353. ")及以前的排班数据" + strconv.FormatInt(int64(failed_total), 10) + "条,不执行导入",
  2354. Status: 1,
  2355. CreateTime: time.Now().Unix(),
  2356. UpdateTime: time.Now().Unix(),
  2357. ExportTime: export_time,
  2358. }
  2359. service.CreateExportErrLog(&err_log)
  2360. }
  2361. this.ServeSuccessJSON(map[string]interface{}{
  2362. "msg": "导入成功",
  2363. "total_num": len(total_schedule) + failed_total,
  2364. "success_num": len(schedules),
  2365. "fail_num": int64(len(errLogs)),
  2366. })
  2367. } else {
  2368. log := models.ExportLog{
  2369. LogType: 2,
  2370. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2371. TotalNum: int64(len(total_schedule) + failed_total),
  2372. FailNum: int64(len(errLogs) + failed_total),
  2373. SuccessNum: int64(len(schedules)),
  2374. CreateTime: time.Now().Unix(),
  2375. UpdateTime: time.Now().Unix(),
  2376. ExportTime: export_time,
  2377. Status: 1,
  2378. }
  2379. service.CreateExportLog(&log)
  2380. if failed_total > 0 {
  2381. err_log := models.ExportErrLog{
  2382. LogType: 2,
  2383. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2384. ErrMsg: "当前日期(" + time.Now().Format("2006-01-02") + " " + GetWeekString(time.Now().Weekday().String()) +
  2385. ")及以前的排班数据" + strconv.FormatInt(int64(failed_total), 10) + "条,不执行导入",
  2386. Status: 1,
  2387. CreateTime: time.Now().Unix(),
  2388. UpdateTime: time.Now().Unix(),
  2389. ExportTime: export_time,
  2390. }
  2391. service.CreateExportErrLog(&err_log)
  2392. }
  2393. this.ServeSuccessJSON(map[string]interface{}{
  2394. "msg": "导入成功",
  2395. "total_num": len(total_schedule),
  2396. "success_num": len(schedules),
  2397. "fail_num": int64(len(errLogs)),
  2398. })
  2399. }
  2400. } else {
  2401. log := models.ExportLog{
  2402. LogType: 2,
  2403. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2404. TotalNum: int64(len(total_schedule) + failed_total),
  2405. FailNum: int64(len(errLogs) + failed_total),
  2406. SuccessNum: int64(len(schedules)),
  2407. CreateTime: time.Now().Unix(),
  2408. UpdateTime: time.Now().Unix(),
  2409. ExportTime: export_time,
  2410. Status: 1,
  2411. }
  2412. service.CreateExportLog(&log)
  2413. if failed_total > 0 {
  2414. err_log := models.ExportErrLog{
  2415. LogType: 2,
  2416. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2417. ErrMsg: "当前日期(" + time.Now().Format("2006-01-02") + " " + GetWeekString(time.Now().Weekday().String()) +
  2418. ")及以前的排班数据" + strconv.FormatInt(int64(failed_total), 10) + "条,不执行导入",
  2419. Status: 1,
  2420. CreateTime: time.Now().Unix(),
  2421. UpdateTime: time.Now().Unix(),
  2422. ExportTime: export_time,
  2423. }
  2424. service.CreateExportErrLog(&err_log)
  2425. }
  2426. this.ServeSuccessJSON(map[string]interface{}{
  2427. "msg": "导入成功",
  2428. "total_num": len(total_schedule),
  2429. "success_num": len(schedules),
  2430. "fail_num": int64(len(errLogs)),
  2431. })
  2432. }
  2433. }
  2434. }
  2435. func (this *ScheduleApiController) ExportScheduleTemplate() {
  2436. dataBody := make(map[string]interface{}, 0)
  2437. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  2438. if err != nil {
  2439. utils.ErrorLog(err.Error())
  2440. return
  2441. }
  2442. utils.ErrorLog("%v", dataBody)
  2443. export_time := time.Now().Unix()
  2444. var schedules []*models.PatientScheduleTemplateItem
  2445. var total_schedule []interface{}
  2446. patients, _, _ := service.GetAllPatientList(this.GetAdminUserInfo().CurrentOrgId)
  2447. if dataBody["schedule"] != nil || reflect.TypeOf(dataBody["schedule"]).String() == "[]interface {}" {
  2448. tempSchedule := dataBody["schedule"].([]interface{})
  2449. total_schedule = tempSchedule
  2450. for _, schMap := range tempSchedule {
  2451. schMapM := schMap.(map[string]interface{})
  2452. var sch models.PatientScheduleTemplateItem
  2453. if schMapM["name"] == nil || reflect.TypeOf(schMapM["name"]).String() != "string" {
  2454. utils.ErrorLog("name")
  2455. return
  2456. }
  2457. name, _ := schMapM["name"].(string)
  2458. fmt.Println(name)
  2459. if len(name) == 0 { //名字为空则生成一条导入错误日志
  2460. err_log := models.ExportErrLog{
  2461. LogType: 3,
  2462. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2463. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名不能为空",
  2464. Status: 1,
  2465. CreateTime: time.Now().Unix(),
  2466. UpdateTime: time.Now().Unix(),
  2467. ExportTime: export_time,
  2468. }
  2469. service.CreateExportErrLog(&err_log)
  2470. continue
  2471. } else {
  2472. var patient []*models.Patients
  2473. for _, item := range patients {
  2474. if strings.Replace(item.Name, " ", "", -1) == name {
  2475. patient = append(patient, item)
  2476. }
  2477. }
  2478. if len(patient) == 0 { //错误日志
  2479. err_log := models.ExportErrLog{
  2480. LogType: 3,
  2481. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2482. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名在系统中不存在,请在系统中添加该病人",
  2483. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列患者姓名为\"" + name + "\"在系统中不存在,请在系统中添加该患者",
  2484. Status: 1,
  2485. CreateTime: time.Now().Unix(),
  2486. UpdateTime: time.Now().Unix(),
  2487. ExportTime: export_time,
  2488. }
  2489. service.CreateExportErrLog(&err_log)
  2490. continue
  2491. } else if len(patient) == 1 { //
  2492. sch.PatientID = patient[0].ID
  2493. } else if len(patient) > 1 { //出现同名的情况
  2494. err_log := models.ExportErrLog{
  2495. LogType: 3,
  2496. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2497. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列" + "患者姓名为" + name + "在当前机构中存在重名,无法确定到具体患者",
  2498. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列患者姓名为\"" + name + "\"在当前机构中存在重名,无法确定到具体患者",
  2499. Status: 1,
  2500. CreateTime: time.Now().Unix(),
  2501. UpdateTime: time.Now().Unix(),
  2502. ExportTime: export_time,
  2503. }
  2504. service.CreateExportErrLog(&err_log)
  2505. continue
  2506. }
  2507. }
  2508. if schMapM["schedule_type"] == nil && reflect.TypeOf(schMapM["schedule_type"]).String() != "float64" {
  2509. utils.ErrorLog("schedule_type")
  2510. return
  2511. }
  2512. schedule_type := int64(schMapM["schedule_type"].(float64))
  2513. if schedule_type <= 0 { //班次格式有误,插入日志
  2514. log := models.ExportLog{
  2515. LogType: 3,
  2516. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2517. TotalNum: int64(len(total_schedule)),
  2518. FailNum: 1,
  2519. SuccessNum: int64(len(schedules)),
  2520. CreateTime: time.Now().Unix(),
  2521. UpdateTime: time.Now().Unix(),
  2522. ExportTime: export_time,
  2523. Status: 1,
  2524. }
  2525. service.CreateExportLog(&log)
  2526. err_log := models.ExportErrLog{
  2527. LogType: 3,
  2528. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2529. ErrMsg: "第2行第" + schMapM["row"].(string) + "列的班次格式有误",
  2530. Status: 1,
  2531. CreateTime: time.Now().Unix(),
  2532. UpdateTime: time.Now().Unix(),
  2533. ExportTime: export_time,
  2534. }
  2535. service.CreateExportErrLog(&err_log)
  2536. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2537. return
  2538. } else {
  2539. sch.TimeType = int8(schedule_type)
  2540. }
  2541. if schMapM["template_id"] == nil && reflect.TypeOf(schMapM["template_id"]).String() != "float64" {
  2542. utils.ErrorLog("template_id")
  2543. return
  2544. }
  2545. template_id := int64(schMapM["template_id"].(float64))
  2546. sch.TemplateID = template_id
  2547. if schMapM["device_number_name"] == nil || reflect.TypeOf(schMapM["device_number_name"]).String() != "string" {
  2548. utils.ErrorLog("device_number_name")
  2549. return
  2550. }
  2551. partition_name, _ := schMapM["partition_name"].(string)
  2552. zone, _ := service.FindDeviceZoneByName(partition_name, this.GetAdminUserInfo().CurrentOrgId)
  2553. device_number_name, _ := schMapM["device_number_name"].(string)
  2554. if len(device_number_name) == 0 { //分区为空
  2555. log := models.ExportLog{
  2556. LogType: 3,
  2557. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2558. TotalNum: int64(len(total_schedule)),
  2559. FailNum: 1,
  2560. SuccessNum: int64(len(schedules)),
  2561. CreateTime: time.Now().Unix(),
  2562. UpdateTime: time.Now().Unix(),
  2563. ExportTime: export_time,
  2564. Status: 1,
  2565. }
  2566. service.CreateExportLog(&log)
  2567. err_log := models.ExportErrLog{
  2568. LogType: 3,
  2569. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2570. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  2571. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
  2572. Status: 1,
  2573. CreateTime: time.Now().Unix(),
  2574. UpdateTime: time.Now().Unix(),
  2575. ExportTime: export_time,
  2576. }
  2577. service.CreateExportErrLog(&err_log)
  2578. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2579. return
  2580. } else {
  2581. device, err := service.FindDeviceByNameTwo(device_number_name, this.GetAdminUserInfo().CurrentOrgId, zone.ID)
  2582. if err == nil {
  2583. if len(device) == 0 { //没查到数据,插入错误日志
  2584. log := models.ExportLog{
  2585. LogType: 3,
  2586. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2587. TotalNum: int64(len(total_schedule)),
  2588. FailNum: 1,
  2589. SuccessNum: int64(len(schedules)),
  2590. CreateTime: time.Now().Unix(),
  2591. UpdateTime: time.Now().Unix(),
  2592. ExportTime: export_time,
  2593. Status: 1,
  2594. }
  2595. service.CreateExportLog(&log)
  2596. err_log := models.ExportErrLog{
  2597. LogType: 3,
  2598. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2599. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
  2600. Status: 1,
  2601. CreateTime: time.Now().Unix(),
  2602. UpdateTime: time.Now().Unix(),
  2603. ExportTime: export_time,
  2604. }
  2605. service.CreateExportErrLog(&err_log)
  2606. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2607. return
  2608. } else if len(device) == 1 {
  2609. sch.DeviceNumberID = device[0].ID
  2610. } else if len(device) > 1 { //出现重名,插入错误日志
  2611. log := models.ExportLog{
  2612. LogType: 3,
  2613. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2614. TotalNum: int64(len(total_schedule)),
  2615. FailNum: 1,
  2616. SuccessNum: int64(len(schedules)),
  2617. CreateTime: time.Now().Unix(),
  2618. UpdateTime: time.Now().Unix(),
  2619. ExportTime: export_time,
  2620. Status: 1,
  2621. }
  2622. service.CreateExportLog(&log)
  2623. err_log := models.ExportErrLog{
  2624. LogType: 3,
  2625. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2626. ErrMsg: "出现两个床位号相同的床位",
  2627. Status: 1,
  2628. CreateTime: time.Now().Unix(),
  2629. UpdateTime: time.Now().Unix(),
  2630. ExportTime: export_time,
  2631. }
  2632. service.CreateExportErrLog(&err_log)
  2633. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2634. return
  2635. }
  2636. }
  2637. }
  2638. if schMapM["schedule_week"] == nil || reflect.TypeOf(schMapM["schedule_week"]).String() != "string" {
  2639. utils.ErrorLog("schedule_week")
  2640. return
  2641. }
  2642. schedule_week, _ := schMapM["schedule_week"].(string)
  2643. if len(schedule_week) == 0 { //周几为空则生成一条导入错误日志
  2644. log := models.ExportLog{
  2645. LogType: 3,
  2646. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2647. TotalNum: int64(len(total_schedule)),
  2648. FailNum: 1,
  2649. SuccessNum: int64(len(schedules)),
  2650. CreateTime: time.Now().Unix(),
  2651. UpdateTime: time.Now().Unix(),
  2652. ExportTime: export_time,
  2653. Status: 1,
  2654. }
  2655. service.CreateExportLog(&log)
  2656. err_log := models.ExportErrLog{
  2657. LogType: 3,
  2658. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2659. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  2660. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  2661. Status: 1,
  2662. CreateTime: time.Now().Unix(),
  2663. UpdateTime: time.Now().Unix(),
  2664. ExportTime: export_time,
  2665. }
  2666. service.CreateExportErrLog(&err_log)
  2667. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2668. return
  2669. } else if schedule_week == "0" { //周几不符合格式则生成一条导入错误日志
  2670. log := models.ExportLog{
  2671. LogType: 3,
  2672. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2673. TotalNum: int64(len(total_schedule)),
  2674. FailNum: 1,
  2675. SuccessNum: int64(len(schedules)),
  2676. CreateTime: time.Now().Unix(),
  2677. UpdateTime: time.Now().Unix(),
  2678. ExportTime: export_time,
  2679. Status: 1,
  2680. }
  2681. service.CreateExportLog(&log)
  2682. err_log := models.ExportErrLog{
  2683. LogType: 3,
  2684. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2685. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  2686. Status: 1,
  2687. CreateTime: time.Now().Unix(),
  2688. UpdateTime: time.Now().Unix(),
  2689. ExportTime: export_time,
  2690. }
  2691. service.CreateExportErrLog(&err_log)
  2692. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2693. return
  2694. } else {
  2695. schedule_week, _ := strconv.ParseInt(schedule_week, 10, 64)
  2696. sch.Weekday = int8(schedule_week)
  2697. }
  2698. treat_mode, _ := schMapM["treat_mode"].(string)
  2699. treat_mode_int, _ := strconv.ParseInt(treat_mode, 10, 64)
  2700. sch.CreateTime = time.Now().Unix()
  2701. sch.ModifyTime = time.Now().Unix()
  2702. sch.TreatMode = treat_mode_int
  2703. sch.Status = 1
  2704. sch.OrgID = this.GetAdminUserInfo().CurrentOrgId
  2705. sch.IsExport = 1
  2706. schedules = append(schedules, &sch)
  2707. }
  2708. errLogs, _ := service.FindSchedualTemplateExportLog(this.GetAdminUserInfo().CurrentOrgId, export_time)
  2709. //for _, item := range schedules {
  2710. //
  2711. //}
  2712. if len(schedules) > 0 {
  2713. err := service.UpdateScheduleTemplateStatus(this.GetAdminUserInfo().CurrentOrgId)
  2714. if err == nil {
  2715. for _, item := range schedules {
  2716. //判斷某個模板下,當天是否有排版,沒有的話就新增
  2717. total := service.ExportScheduleTemplate(item)
  2718. if total == 0 {
  2719. service.CreateScheduleTemplate(item)
  2720. }
  2721. }
  2722. ////查询已经转出或者死亡的患者
  2723. //patientList, _ := service.GetDeathPatient(this.GetAdminUserInfo().CurrentOrgId)
  2724. //for _, it := range patientList {
  2725. // timeStr := time.Now().Format("2006-01-02")
  2726. // timeLayout := "2006-01-02 15:04:05"
  2727. // timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  2728. // timenow := timeStringToTime.Unix()
  2729. // service.UpdateScheduleByDeathTime(it.ID, timenow)
  2730. // service.UpdateScheduleItemByPatientId(it.ID)
  2731. //}
  2732. log := models.ExportLog{
  2733. LogType: 3,
  2734. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2735. TotalNum: int64(len(total_schedule)),
  2736. FailNum: int64(len(errLogs)),
  2737. SuccessNum: int64(len(schedules)),
  2738. CreateTime: time.Now().Unix(),
  2739. UpdateTime: time.Now().Unix(),
  2740. ExportTime: export_time,
  2741. Status: 1,
  2742. }
  2743. service.CreateExportLog(&log)
  2744. this.ServeSuccessJSON(map[string]interface{}{
  2745. "msg": "导入成功",
  2746. "total_num": len(total_schedule),
  2747. "success_num": len(schedules),
  2748. "fail_num": int64(len(errLogs)),
  2749. })
  2750. } else {
  2751. log := models.ExportLog{
  2752. LogType: 3,
  2753. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2754. TotalNum: int64(len(total_schedule)),
  2755. FailNum: int64(len(errLogs)),
  2756. SuccessNum: int64(len(schedules)),
  2757. CreateTime: time.Now().Unix(),
  2758. UpdateTime: time.Now().Unix(),
  2759. ExportTime: export_time,
  2760. Status: 1,
  2761. }
  2762. service.CreateExportLog(&log)
  2763. this.ServeSuccessJSON(map[string]interface{}{
  2764. "msg": "导入成功",
  2765. "total_num": len(total_schedule),
  2766. "success_num": len(schedules),
  2767. "fail_num": int64(len(errLogs)),
  2768. })
  2769. }
  2770. } else {
  2771. log := models.ExportLog{
  2772. LogType: 3,
  2773. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2774. TotalNum: int64(len(total_schedule)),
  2775. FailNum: int64(len(errLogs)),
  2776. SuccessNum: int64(len(schedules)),
  2777. CreateTime: time.Now().Unix(),
  2778. UpdateTime: time.Now().Unix(),
  2779. ExportTime: export_time,
  2780. Status: 1,
  2781. }
  2782. service.CreateExportLog(&log)
  2783. this.ServeSuccessJSON(map[string]interface{}{
  2784. "msg": "导入成功",
  2785. "total_num": len(total_schedule),
  2786. "success_num": len(schedules),
  2787. "fail_num": int64(len(errLogs)),
  2788. })
  2789. }
  2790. }
  2791. }
  2792. func (c *ScheduleApiController) GetInitExcelInitDate() {
  2793. thisTime := time.Now()
  2794. thisTime1 := time.Now()
  2795. thisTime2 := time.Now()
  2796. thisTime3 := time.Now()
  2797. thisTime4 := time.Now()
  2798. thisTime1 = thisTime1.AddDate(0, 0, 7)
  2799. thisTime2 = thisTime2.AddDate(0, 0, 14)
  2800. thisTime3 = thisTime3.AddDate(0, 0, 21)
  2801. thisTime4 = thisTime4.AddDate(0, 0, 28)
  2802. weekDay := int(thisTime.Weekday())
  2803. if weekDay == 0 {
  2804. weekDay = 7
  2805. }
  2806. weekEnd := 7 - weekDay
  2807. weekStart := weekEnd - 6
  2808. days := make([]string, 0)
  2809. for index := weekStart; index <= weekEnd; index++ {
  2810. theDay := thisTime.AddDate(0, 0, index)
  2811. days = append(days, theDay.Format("2006-01-02"))
  2812. }
  2813. weekDay1 := int(thisTime1.Weekday())
  2814. if weekDay1 == 0 {
  2815. weekDay1 = 7
  2816. }
  2817. weekEnd1 := 7 - weekDay1
  2818. weekStart1 := weekEnd1 - 6
  2819. for index := weekStart1; index <= weekEnd1; index++ {
  2820. theDay := thisTime1.AddDate(0, 0, index)
  2821. days = append(days, theDay.Format("2006-01-02"))
  2822. }
  2823. weekDay2 := int(thisTime2.Weekday())
  2824. if weekDay2 == 0 {
  2825. weekDay2 = 7
  2826. }
  2827. weekEnd2 := 7 - weekDay2
  2828. weekStart2 := weekEnd2 - 6
  2829. for index := weekStart2; index <= weekEnd2; index++ {
  2830. theDay := thisTime2.AddDate(0, 0, index)
  2831. days = append(days, theDay.Format("2006-01-02"))
  2832. }
  2833. weekDay3 := int(thisTime3.Weekday())
  2834. if weekDay3 == 0 {
  2835. weekDay3 = 7
  2836. }
  2837. weekEnd3 := 7 - weekDay3
  2838. weekStart3 := weekEnd3 - 6
  2839. for index := weekStart3; index <= weekEnd3; index++ {
  2840. theDay := thisTime3.AddDate(0, 0, index)
  2841. days = append(days, theDay.Format("2006-01-02"))
  2842. }
  2843. weekDay4 := int(thisTime4.Weekday())
  2844. if weekDay4 == 0 {
  2845. weekDay4 = 7
  2846. }
  2847. weekEnd4 := 7 - weekDay4
  2848. weekStart4 := weekEnd4 - 6
  2849. for index := weekStart4; index <= weekEnd4; index++ {
  2850. theDay := thisTime4.AddDate(0, 0, index)
  2851. days = append(days, theDay.Format("2006-01-02"))
  2852. }
  2853. c.ServeSuccessJSON(map[string]interface{}{
  2854. "days": days,
  2855. })
  2856. return
  2857. }
  2858. func GetWeekString(week string) string {
  2859. var weekStr string
  2860. switch week {
  2861. case "Sunday":
  2862. weekStr = "周日"
  2863. break
  2864. case "Monday":
  2865. weekStr = "周一"
  2866. break
  2867. case "Tuesday":
  2868. weekStr = "周二"
  2869. break
  2870. case "Wednesday":
  2871. weekStr = "周三"
  2872. break
  2873. case "Thursday":
  2874. weekStr = "周四"
  2875. break
  2876. case "Friday":
  2877. weekStr = "周五"
  2878. break
  2879. case "Saturday":
  2880. weekStr = "周六"
  2881. break
  2882. default:
  2883. weekStr = ""
  2884. break
  2885. }
  2886. return weekStr
  2887. }
  2888. func (c *ScheduleApiController) SearchTemplateSchedulePatients() {
  2889. template_id, _ := c.GetInt64("template_id", 0)
  2890. keywords := c.GetString("keywords")
  2891. adminInfo := c.GetAdminUserInfo()
  2892. scheduleItems, _ := service.GetTemplateSchedualPatientsByKeywords(keywords, adminInfo.CurrentOrgId, template_id)
  2893. c.ServeSuccessJSON(map[string]interface{}{
  2894. "schdules": scheduleItems,
  2895. })
  2896. }
  2897. func (c *ScheduleApiController) CancelScheduleTemplate() {
  2898. item_id, _ := c.GetInt64("id")
  2899. adminInfo := c.GetAdminUserInfo()
  2900. err := service.UpdateNewScheduleTemplateStatus(item_id, adminInfo.CurrentOrgId)
  2901. if err == nil {
  2902. c.ServeSuccessJSON(map[string]interface{}{
  2903. "msg": "取消成功",
  2904. })
  2905. return
  2906. } else {
  2907. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2908. return
  2909. }
  2910. }
  2911. func (this *ScheduleApiController) GetNextWeekDayScheduleOne() {
  2912. week_type, _ := this.GetInt64("week_type", -1)
  2913. week_time, _ := this.GetInt64("week_time")
  2914. record_date := this.GetString("record_date")
  2915. zons := this.GetString("zone")
  2916. zone := strings.Split(zons, ",")
  2917. start_time, _ := this.GetInt64("start_time")
  2918. end_time, _ := this.GetInt64("end_time")
  2919. timeLayout := "2006-01-02"
  2920. loc, _ := time.LoadLocation("Local")
  2921. //theTimeStart, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2922. //theTimeEnd, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  2923. adminUserInfo := this.GetAdminUserInfo()
  2924. var theStartTIme int64
  2925. if len(record_date) > 0 {
  2926. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2927. if err != nil {
  2928. utils.ErrorLog(err.Error())
  2929. }
  2930. theStartTIme = theTime.Unix()
  2931. }
  2932. schedule, err := service.GetNextWeekDaySchedule(week_type, week_time, start_time, end_time, adminUserInfo.CurrentOrgId, zone, theStartTIme)
  2933. for _, item := range schedule {
  2934. order, _ := service.GetLastDialysisOrder(adminUserInfo.CurrentOrgId, item.PatientId, theStartTIme)
  2935. item.XtDialysisOrderSix = order
  2936. if adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 9675 || adminUserInfo.CurrentOrgId == 10340 {
  2937. dialysisprescription, _ := service.GetLastDialysisSolution(adminUserInfo.CurrentOrgId, item.PatientId, item.ModeId, item.ScheduleDate)
  2938. item.DialysisPrescription = dialysisprescription
  2939. }
  2940. }
  2941. if err != nil {
  2942. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2943. return
  2944. }
  2945. this.ServeSuccessJSON(map[string]interface{}{
  2946. "schedule": schedule,
  2947. })
  2948. }
  2949. func (this *ScheduleApiController) GetNextWeekDaySchedule() {
  2950. week_type, _ := this.GetInt64("week_type", -1)
  2951. week_time, _ := this.GetInt64("week_time")
  2952. record_date := this.GetString("record_date")
  2953. zons := this.GetString("zone")
  2954. zone := strings.Split(zons, ",")
  2955. start_time := this.GetString("start_time")
  2956. end_time := this.GetString("end_time")
  2957. timeLayout := "2006-01-02"
  2958. loc, _ := time.LoadLocation("Local")
  2959. theTimeStart, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2960. theTimeEnd, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  2961. adminUserInfo := this.GetAdminUserInfo()
  2962. var theStartTIme int64
  2963. if len(record_date) > 0 {
  2964. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2965. if err != nil {
  2966. utils.ErrorLog(err.Error())
  2967. }
  2968. theStartTIme = theTime.Unix()
  2969. }
  2970. schedule, err := service.GetNextWeekDaySchedule(week_type, week_time, theTimeStart.Unix(), theTimeEnd.Unix(), adminUserInfo.CurrentOrgId, zone, theStartTIme)
  2971. if err != nil {
  2972. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2973. return
  2974. }
  2975. this.ServeSuccessJSON(map[string]interface{}{
  2976. "schedule": schedule,
  2977. })
  2978. }
  2979. func (this *ScheduleApiController) GetThreeWeekList() {
  2980. start_time := this.GetString("start_time")
  2981. end_time := this.GetString("end_time")
  2982. partition_id, _ := this.GetInt64("partition_id")
  2983. schedule_type, _ := this.GetInt64("schedule_type")
  2984. fmt.Println(partition_id, schedule_type)
  2985. timeLayout := "2006-01-02"
  2986. loc, _ := time.LoadLocation("Local")
  2987. var theStartTIme int64
  2988. if len(start_time) > 0 {
  2989. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2990. if err != nil {
  2991. utils.ErrorLog(err.Error())
  2992. }
  2993. theStartTIme = theTime.Unix()
  2994. }
  2995. var theEndtTIme int64
  2996. if len(end_time) > 0 {
  2997. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  2998. if err != nil {
  2999. utils.ErrorLog(err.Error())
  3000. }
  3001. theEndtTIme = theTime.Unix()
  3002. }
  3003. adminUserInfo := this.GetAdminUserInfo()
  3004. orgId := adminUserInfo.CurrentOrgId
  3005. partitions, _ := service.GetSchedulePartitionPanel(orgId)
  3006. list, err := service.GetThreeWeekList(theStartTIme, theEndtTIme, orgId, schedule_type, partition_id)
  3007. if err != nil {
  3008. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3009. return
  3010. }
  3011. this.ServeSuccessJSON(map[string]interface{}{
  3012. "list": list,
  3013. "partitions": partitions,
  3014. })
  3015. }
  3016. func (this *ScheduleApiController) GetAllZones() {
  3017. adminUserInfo := this.GetAdminUserInfo()
  3018. orgId := adminUserInfo.CurrentOrgId
  3019. zones, err := service.GetAllZoneOne(orgId)
  3020. if err != nil {
  3021. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3022. return
  3023. }
  3024. this.ServeSuccessJSON(map[string]interface{}{
  3025. "zones": zones,
  3026. })
  3027. }
  3028. func (this *ScheduleApiController) GetCopyPatientSchedules() {
  3029. adminUserInfo := this.GetAdminUserInfo()
  3030. orgId := adminUserInfo.CurrentOrgId
  3031. start_time, _ := this.GetInt64("start_time")
  3032. fmt.Println("start_time", start_time)
  3033. end_time, _ := this.GetInt64("end_time")
  3034. fmt.Println("end_time", end_time)
  3035. copy_startime, _ := this.GetInt64("copy_startime")
  3036. fmt.Println("copy_startime", copy_startime)
  3037. copy_endtime, _ := this.GetInt64("copy_endtime")
  3038. //获取本周患者排班
  3039. schedules, _ := service.GetWeekSchedules(orgId, start_time, end_time)
  3040. //先清除复制周的排班
  3041. errcode := service.UpdatePatientSchedule(orgId, copy_startime, copy_endtime)
  3042. fmt.Println(errcode)
  3043. var err error
  3044. for _, item := range schedules {
  3045. //fmt.Println(item.StartTime+604800)
  3046. //礼拜1
  3047. if item.ScheduleWeek == 1 {
  3048. item.ScheduleDate = copy_startime
  3049. }
  3050. if item.ScheduleWeek == 2 {
  3051. item.ScheduleDate = copy_startime + 86400
  3052. }
  3053. if item.ScheduleWeek == 3 {
  3054. item.ScheduleDate = copy_startime + 172800
  3055. }
  3056. if item.ScheduleWeek == 4 {
  3057. item.ScheduleDate = copy_startime + 259200
  3058. }
  3059. if item.ScheduleWeek == 5 {
  3060. item.ScheduleDate = copy_startime + 345600
  3061. }
  3062. if item.ScheduleWeek == 6 {
  3063. item.ScheduleDate = copy_startime + 432000
  3064. }
  3065. //礼拜天
  3066. if item.ScheduleWeek == 7 {
  3067. item.ScheduleDate = copy_endtime
  3068. }
  3069. schedule := models.XtSchedule{
  3070. UserOrgId: item.UserOrgId,
  3071. PartitionId: item.PartitionId,
  3072. BedId: item.BedId,
  3073. PatientId: item.PatientId,
  3074. ScheduleDate: item.ScheduleDate,
  3075. ScheduleType: item.ScheduleType,
  3076. ScheduleWeek: item.ScheduleWeek,
  3077. ModeId: item.ModeId,
  3078. Status: 1,
  3079. CreatedTime: time.Now().Unix(),
  3080. }
  3081. var DialysisMachineName string
  3082. so, _ := service.GetDialysisSolutionTwo(adminUserInfo.CurrentOrgId, schedule.PatientId, schedule.ModeId)
  3083. filedRecordOne, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "透析器")
  3084. filedRecordTwo, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "灌流器")
  3085. filedRecordThree, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "透析器/灌流器")
  3086. if filedRecordOne.IsShow == 1 {
  3087. DialysisMachineName = so.DialysisDialyszers
  3088. }
  3089. if filedRecordThree.IsShow == 1 {
  3090. if len(DialysisMachineName) > 0 {
  3091. DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
  3092. } else {
  3093. DialysisMachineName = so.DialyzerPerfusionApparatus
  3094. }
  3095. }
  3096. if filedRecordTwo.IsShow == 1 {
  3097. if len(DialysisMachineName) > 0 {
  3098. DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
  3099. } else {
  3100. DialysisMachineName = so.DialysisIrrigation
  3101. }
  3102. }
  3103. schedule.DialysisMachineName = DialysisMachineName
  3104. schedule.IsExport = 4000
  3105. err = service.AddPatientSchedule(&schedule)
  3106. }
  3107. patientList, _ := service.GetDeathPatient(this.GetAdminUserInfo().CurrentOrgId)
  3108. timeStr := time.Now().Format("2006-01-02")
  3109. timeLayout := "2006-01-02 15:04:05"
  3110. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  3111. timenow := timeStringToTime.Unix()
  3112. for _, it := range patientList {
  3113. service.UpdateScheduleByDeathTime(it.ID, timenow)
  3114. service.UpdateScheduleItemByPatientId(it.ID)
  3115. }
  3116. if err != nil {
  3117. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3118. return
  3119. }
  3120. this.ServeSuccessJSON(map[string]interface{}{
  3121. "msg": "msg",
  3122. })
  3123. return
  3124. //查询复制中的排班日期是否存在
  3125. //_, errcode := service.GetLastWeekSchedule(orgId, copy_startime, copy_endtime)
  3126. //
  3127. //if errcode == gorm.ErrRecordNotFound {
  3128. // //如果没有直接新增
  3129. //
  3130. // for _, item := range schedules {
  3131. // //fmt.Println(item.StartTime+604800)
  3132. // //礼拜1
  3133. // if item.ScheduleWeek == 1 {
  3134. // item.ScheduleDate = copy_startime
  3135. // }
  3136. // if item.ScheduleWeek == 2 {
  3137. // item.ScheduleDate = copy_startime + 86400
  3138. // }
  3139. // if item.ScheduleWeek == 3 {
  3140. // item.ScheduleDate = copy_startime + 172800
  3141. // }
  3142. // if item.ScheduleWeek == 4 {
  3143. // item.ScheduleDate = copy_startime + 259200
  3144. // }
  3145. // if item.ScheduleWeek == 5 {
  3146. // item.ScheduleDate = copy_startime + 345600
  3147. // }
  3148. //
  3149. // if item.ScheduleWeek == 6 {
  3150. // item.ScheduleDate = copy_startime + 432000
  3151. // }
  3152. // //礼拜天
  3153. // if item.ScheduleWeek == 0 {
  3154. // item.ScheduleDate = copy_endtime
  3155. // }
  3156. // schedule := models.XtSchedule{
  3157. // UserOrgId: item.UserOrgId,
  3158. // PartitionId: item.PartitionId,
  3159. // BedId: item.BedId,
  3160. // PatientId: item.PatientId,
  3161. // ScheduleDate: item.ScheduleDate,
  3162. // ScheduleType: item.ScheduleType,
  3163. // ScheduleWeek: item.ScheduleWeek,
  3164. // ModeId: item.ModeId,
  3165. // Status: 1,
  3166. // CreatedTime: time.Now().Unix(),
  3167. // }
  3168. //
  3169. // err := service.AddPatientSchedule(&schedule)
  3170. // if err != nil {
  3171. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3172. // return
  3173. // }
  3174. // this.ServeSuccessJSON(map[string]interface{}{
  3175. // "schedule": schedule,
  3176. // })
  3177. // }
  3178. //} else if errcode == nil {
  3179. //
  3180. // //先清除复制周的排班
  3181. // errcode := service.UpdatePatientSchedule(orgId, copy_startime, copy_endtime)
  3182. // fmt.Println(errcode)
  3183. // for _, item := range schedules {
  3184. // //fmt.Println(item.StartTime+604800)
  3185. // //礼拜1
  3186. // if item.ScheduleWeek == 1 {
  3187. // item.ScheduleDate = copy_startime
  3188. // }
  3189. // if item.ScheduleWeek == 2 {
  3190. // item.ScheduleDate = copy_startime + 86400
  3191. // }
  3192. // if item.ScheduleWeek == 3 {
  3193. // item.ScheduleDate = copy_startime + 172800
  3194. // }
  3195. // if item.ScheduleWeek == 4 {
  3196. // item.ScheduleDate = copy_startime + 259200
  3197. // }
  3198. // if item.ScheduleWeek == 5 {
  3199. // item.ScheduleDate = copy_startime + 345600
  3200. // }
  3201. //
  3202. // if item.ScheduleWeek == 6 {
  3203. // item.ScheduleDate = copy_startime + 432000
  3204. // }
  3205. // //礼拜天
  3206. // if item.ScheduleWeek == 0 {
  3207. // item.ScheduleDate = copy_endtime
  3208. // }
  3209. // schedule := models.XtSchedule{
  3210. // UserOrgId: item.UserOrgId,
  3211. // PartitionId: item.PartitionId,
  3212. // BedId: item.BedId,
  3213. // PatientId: item.PatientId,
  3214. // ScheduleDate: item.ScheduleDate,
  3215. // ScheduleType: item.ScheduleType,
  3216. // ScheduleWeek: item.ScheduleWeek,
  3217. // ModeId: item.ModeId,
  3218. // Status: 1,
  3219. // CreatedTime: time.Now().Unix(),
  3220. // }
  3221. //
  3222. // err := service.AddPatientSchedule(&schedule)
  3223. // if err != nil {
  3224. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3225. // return
  3226. // }
  3227. // this.ServeSuccessJSON(map[string]interface{}{
  3228. // "schedule": schedule,
  3229. // })
  3230. // }
  3231. //}
  3232. }
  3233. func (this *ScheduleApiController) SaveRemindPrint() {
  3234. id, _ := this.GetInt64("id")
  3235. anticoagulants, _ := this.GetInt64("anticoagulant")
  3236. anticoagulant_zongliang, _ := this.GetInt64("anticoagulant_zongliang")
  3237. classes, _ := this.GetInt64("classes")
  3238. dialyzers, _ := this.GetInt64("dialyzers")
  3239. doctor_advice, _ := this.GetInt64("doctor_advice")
  3240. mode, _ := this.GetInt64("mode")
  3241. name, _ := this.GetInt64("name")
  3242. number, _ := this.GetInt64("number")
  3243. perfusion_apparatus, _ := this.GetInt64("perfusion_apparatus")
  3244. prescription_status, _ := this.GetInt64("prescription_status")
  3245. week, _ := this.GetInt64("week")
  3246. zone, _ := this.GetInt64("zone")
  3247. adminUserInfo := this.GetAdminUserInfo()
  3248. orgId := adminUserInfo.CurrentOrgId
  3249. setting := models.XtRemindPrintSetting{
  3250. Anticoagulant: anticoagulants,
  3251. Classes: classes,
  3252. AnticoagulantZongliang: anticoagulant_zongliang,
  3253. Dialyzers: dialyzers,
  3254. DoctorAdvice: doctor_advice,
  3255. Mode: mode,
  3256. Name: name,
  3257. Number: number,
  3258. PerfusionApparatus: perfusion_apparatus,
  3259. PrescriptionStatus: prescription_status,
  3260. Week: week,
  3261. Zone: zone,
  3262. UserOrgId: orgId,
  3263. Status: 1,
  3264. Ctime: time.Now().Unix(),
  3265. }
  3266. _, errcode := service.GetSettingById(id)
  3267. if errcode == gorm.ErrRecordNotFound {
  3268. err := service.CreateSetting(&setting)
  3269. if err != nil {
  3270. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3271. return
  3272. }
  3273. this.ServeSuccessJSON(map[string]interface{}{
  3274. "setting": setting,
  3275. })
  3276. } else if errcode == nil {
  3277. err := service.UpdatedRemindPrint(&setting, id)
  3278. if err != nil {
  3279. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3280. return
  3281. }
  3282. this.ServeSuccessJSON(map[string]interface{}{
  3283. "setting": setting,
  3284. })
  3285. }
  3286. }
  3287. func (this *ScheduleApiController) GetRemindPrintList() {
  3288. adminUserInfo := this.GetAdminUserInfo()
  3289. orgId := adminUserInfo.CurrentOrgId
  3290. list, err := service.GetRemindPrintList(orgId)
  3291. if err != nil {
  3292. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3293. return
  3294. }
  3295. this.ServeSuccessJSON(map[string]interface{}{
  3296. "list": list,
  3297. })
  3298. }
  3299. func (this *ScheduleApiController) GetBloodScheduleList() {
  3300. week_type, _ := this.GetInt64("week_type", -1)
  3301. week_time, _ := this.GetInt64("week_time")
  3302. zones := this.GetString("zone")
  3303. zone := strings.Split(zones, ",")
  3304. thisTime := time.Now()
  3305. weekDay := int(thisTime.Weekday())
  3306. if weekDay == 0 {
  3307. weekDay = 7
  3308. }
  3309. weekEnd := 7 - weekDay
  3310. weekStart := weekEnd - 6
  3311. weekTitle := make([]string, 0)
  3312. days := make([]string, 0)
  3313. for index := weekStart; index <= weekEnd; index++ {
  3314. theDay := thisTime.AddDate(0, 0, index)
  3315. indexYear, indexMonthTime, indexDay := theDay.Date()
  3316. indexMonth := int(indexMonthTime)
  3317. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  3318. weekTitle = append(weekTitle, indexWeek)
  3319. days = append(days, theDay.Format("2006-01-02"))
  3320. }
  3321. fmt.Println(days)
  3322. var targetDayStr string
  3323. var startTime string
  3324. switch week_type {
  3325. case 0:
  3326. startTime = days[0]
  3327. targetDayStr = days[6]
  3328. break
  3329. case 1:
  3330. targetDayStr = days[0]
  3331. break
  3332. case 2:
  3333. targetDayStr = days[1]
  3334. break
  3335. case 3:
  3336. targetDayStr = days[2]
  3337. break
  3338. case 4:
  3339. targetDayStr = days[3]
  3340. break
  3341. case 5:
  3342. targetDayStr = days[4]
  3343. break
  3344. case 6:
  3345. targetDayStr = days[5]
  3346. break
  3347. case 7:
  3348. targetDayStr = days[6]
  3349. break
  3350. }
  3351. targetDay, parseErr := utils.ParseTimeStringToTime("2006-01-02", targetDayStr)
  3352. if parseErr != nil {
  3353. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3354. return
  3355. }
  3356. orgId := this.GetAdminUserInfo().CurrentOrgId
  3357. if week_type > 0 {
  3358. list, err := service.GetWeekDayScheduleByIdThee(orgId, targetDay.Unix(), week_time, zone)
  3359. for _, item := range list {
  3360. order, _ := service.GetLastDialysisOrder(orgId, item.PatientId, targetDay.Unix())
  3361. item.XtDialysisOrderSix = order
  3362. if orgId == 9671 || orgId == 9675 || orgId == 10340 {
  3363. solution, _ := service.GetLastDialysisSolution(orgId, item.PatientId, item.ModeId, item.ScheduleDate)
  3364. item.DialysisPrescription = solution
  3365. }
  3366. }
  3367. if err != nil {
  3368. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3369. return
  3370. }
  3371. this.ServeSuccessJSON(map[string]interface{}{
  3372. "list": list,
  3373. "day": targetDayStr,
  3374. })
  3375. }
  3376. if week_type == 0 {
  3377. startDate, _ := utils.ParseTimeStringToTime("2006-01-02", startTime)
  3378. list, err := service.GetWeekDayScheduleByIdTwo(orgId, targetDay.Unix(), week_time, startDate.Unix(), zone)
  3379. for _, item := range list {
  3380. order, _ := service.GetLastDialysisOrder(orgId, item.PatientId, targetDay.Unix())
  3381. item.XtDialysisOrderSix = order
  3382. if orgId == 9671 || orgId == 9675 || orgId == 10340 {
  3383. solution, _ := service.GetLastDialysisSolution(orgId, item.PatientId, item.ModeId, item.ScheduleDate)
  3384. item.DialysisPrescription = solution
  3385. }
  3386. }
  3387. if err != nil {
  3388. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3389. return
  3390. }
  3391. this.ServeSuccessJSON(map[string]interface{}{
  3392. "list": list,
  3393. "day": targetDayStr,
  3394. })
  3395. }
  3396. }
  3397. func (this *ScheduleApiController) GetPrintList() {
  3398. adminUserInfo := this.GetAdminUserInfo()
  3399. orgId := adminUserInfo.CurrentOrgId
  3400. list, err := service.GetRemindPrintList(orgId)
  3401. if err != nil {
  3402. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3403. return
  3404. }
  3405. this.ServeSuccessJSON(map[string]interface{}{
  3406. "list": list,
  3407. })
  3408. }
  3409. func (this *ScheduleApiController) GetAllZoneList() {
  3410. adminUserInfo := this.GetAdminUserInfo()
  3411. orgId := adminUserInfo.CurrentOrgId
  3412. zoneList, err := service.GetAllZoneOne(orgId)
  3413. if err != nil {
  3414. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3415. return
  3416. }
  3417. this.ServeSuccessJSON(map[string]interface{}{
  3418. "zoneList": zoneList,
  3419. })
  3420. }
  3421. func (this *ScheduleApiController) GetPatientScheduleCount() {
  3422. patitionIdStr := this.GetString("partition_id")
  3423. week, _ := this.GetInt64("weekTime", 0) //1:last, 2:this 3:next 4 nextTwo
  3424. ids := strings.Split(patitionIdStr, ",")
  3425. adminUserInfo := this.GetAdminUserInfo()
  3426. orgId := adminUserInfo.CurrentOrgId
  3427. thisTime := time.Now()
  3428. weekDay := int(thisTime.Weekday())
  3429. if week < 1 || week > 4 {
  3430. week = 2
  3431. }
  3432. if week == 1 {
  3433. thisTime = thisTime.AddDate(0, 0, -7)
  3434. } else if week == 3 {
  3435. thisTime = thisTime.AddDate(0, 0, 7)
  3436. } else if week == 4 {
  3437. thisTime = thisTime.AddDate(0, 0, 14)
  3438. }
  3439. if weekDay == 0 {
  3440. weekDay = 7
  3441. }
  3442. weekEnd := 7 - weekDay
  3443. weekStart := weekEnd - 6
  3444. weekTitle := make([]string, 0)
  3445. days := make([]string, 0)
  3446. for index := weekStart; index <= weekEnd; index++ {
  3447. theDay := thisTime.AddDate(0, 0, index)
  3448. indexYear, indexMonthTime, indexDay := theDay.Date()
  3449. indexMonth := int(indexMonthTime)
  3450. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  3451. weekTitle = append(weekTitle, indexWeek)
  3452. days = append(days, theDay.Format("2006-01-02"))
  3453. }
  3454. weekStartDay := thisTime.AddDate(0, 0, weekStart)
  3455. weekEndDay := thisTime.AddDate(0, 0, weekEnd)
  3456. weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
  3457. weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
  3458. timeLayout := "2006-01-02 15:04:05"
  3459. loc, _ := time.LoadLocation("Local")
  3460. theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
  3461. theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
  3462. weekStartPoint := theStarTime.Unix()
  3463. weekEndPoint := theEndTime.Unix()
  3464. list, err := service.GetPatientScheduleCount(orgId, weekStartPoint, weekEndPoint, ids)
  3465. _, total, _ := service.GetTotalBedNumber(orgId, ids)
  3466. if err != nil {
  3467. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3468. return
  3469. }
  3470. this.ServeSuccessJSON(map[string]interface{}{
  3471. "list": list,
  3472. "total": total,
  3473. })
  3474. }
  3475. func (c *ScheduleApiController) GetWeekPanelsOne() {
  3476. data, _ := c.GetInt64("data", 1)
  3477. patitionIdStr := c.GetString("patitionid")
  3478. ids := strings.Split(patitionIdStr, ",")
  3479. adminInfo := c.GetAdminUserInfo()
  3480. thisTime := time.Now()
  3481. year, monthTime, day := thisTime.Date()
  3482. month := int(monthTime)
  3483. _, theWeek := thisTime.ISOWeek()
  3484. weekDay := int(thisTime.Weekday())
  3485. if weekDay == 0 {
  3486. weekDay = 7
  3487. }
  3488. weekEnd := 7 - weekDay
  3489. weekStart := weekEnd - 6
  3490. weekDays := make([]string, 0)
  3491. for index := weekStart; index <= weekEnd; index++ {
  3492. theDay := thisTime.AddDate(0, 0, index)
  3493. indexYear, indexMonthTime, indexDay := theDay.Date()
  3494. indexMonth := int(indexMonthTime)
  3495. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  3496. weekDays = append(weekDays, indexWeek)
  3497. }
  3498. returnData := map[string]interface{}{
  3499. "year": year,
  3500. "month": month,
  3501. "day": day,
  3502. "theWeek": theWeek,
  3503. "weekDay": weekDay,
  3504. "weekDays": weekDays,
  3505. }
  3506. if data == 1 {
  3507. partitions, _ := service.GetSchedulePartitionPanelTwo(adminInfo.CurrentOrgId, ids)
  3508. returnData["partitions"] = partitions
  3509. }
  3510. c.ServeSuccessJSON(returnData)
  3511. return
  3512. }
  3513. func (c *ScheduleApiController) GetScheduleOne() {
  3514. week, _ := c.GetInt64("weekTime", 0) //1:last, 2:this 3:next 4 nextTwo
  3515. patitionIdStr := c.GetString("patitionid")
  3516. ids := strings.Split(patitionIdStr, ",")
  3517. fmt.Println("patitonStr", ids)
  3518. schedule_type, _ := c.GetInt64("schedule_type")
  3519. adminInfo := c.GetAdminUserInfo()
  3520. thisTime := time.Now()
  3521. today := thisTime.Format("2006-01-02")
  3522. if week < 1 || week > 4 {
  3523. week = 2
  3524. }
  3525. if week == 1 {
  3526. thisTime = thisTime.AddDate(0, 0, -7)
  3527. } else if week == 3 {
  3528. thisTime = thisTime.AddDate(0, 0, 7)
  3529. } else if week == 4 {
  3530. thisTime = thisTime.AddDate(0, 0, 14)
  3531. }
  3532. weekDay := int(thisTime.Weekday())
  3533. if weekDay == 0 {
  3534. weekDay = 7
  3535. }
  3536. weekEnd := 7 - weekDay
  3537. weekStart := weekEnd - 6
  3538. weekTitle := make([]string, 0)
  3539. days := make([]string, 0)
  3540. for index := weekStart; index <= weekEnd; index++ {
  3541. theDay := thisTime.AddDate(0, 0, index)
  3542. indexYear, indexMonthTime, indexDay := theDay.Date()
  3543. indexMonth := int(indexMonthTime)
  3544. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  3545. weekTitle = append(weekTitle, indexWeek)
  3546. days = append(days, theDay.Format("2006-01-02"))
  3547. }
  3548. weekStartDay := thisTime.AddDate(0, 0, weekStart)
  3549. weekEndDay := thisTime.AddDate(0, 0, weekEnd)
  3550. weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
  3551. weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
  3552. timeLayout := "2006-01-02 15:04:05"
  3553. loc, _ := time.LoadLocation("Local")
  3554. theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
  3555. theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
  3556. weekStartPoint := theStarTime.Unix()
  3557. weekEndPoint := theEndTime.Unix()
  3558. schdules, _ := service.GetWeekScheduleTwo(adminInfo.CurrentOrgId, weekStartPoint, weekEndPoint, ids, schedule_type)
  3559. c.ServeSuccessJSON(map[string]interface{}{
  3560. "days": days,
  3561. "weekTitle": weekTitle,
  3562. "schdules": schdules,
  3563. "today": today,
  3564. })
  3565. return
  3566. }
  3567. func (c *ScheduleApiController) GetScheduleTwo() {
  3568. week, _ := c.GetInt64("weekTime", 0) //1:last, 2:this 3:next 4 nextTwo
  3569. patitionIdStr := c.GetString("patitionid")
  3570. ids := strings.Split(patitionIdStr, ",")
  3571. schedule_type, _ := c.GetInt64("schedule_type")
  3572. adminInfo := c.GetAdminUserInfo()
  3573. weekDateStr := c.GetString("week_date")
  3574. WeekDayIds := strings.Split(weekDateStr, ",")
  3575. thisTime := time.Now()
  3576. today := thisTime.Format("2006-01-02")
  3577. if week < 1 || week > 4 {
  3578. week = 2
  3579. }
  3580. if week == 1 {
  3581. thisTime = thisTime.AddDate(0, 0, -7)
  3582. } else if week == 3 {
  3583. thisTime = thisTime.AddDate(0, 0, 7)
  3584. } else if week == 4 {
  3585. thisTime = thisTime.AddDate(0, 0, 14)
  3586. }
  3587. weekDay := int(thisTime.Weekday())
  3588. if weekDay == 0 {
  3589. weekDay = 7
  3590. }
  3591. weekEnd := 7 - weekDay
  3592. weekStart := weekEnd - 6
  3593. weekTitle := make([]string, 0)
  3594. days := make([]string, 0)
  3595. for index := weekStart; index <= weekEnd; index++ {
  3596. theDay := thisTime.AddDate(0, 0, index)
  3597. indexYear, indexMonthTime, indexDay := theDay.Date()
  3598. indexMonth := int(indexMonthTime)
  3599. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  3600. weekTitle = append(weekTitle, indexWeek)
  3601. days = append(days, theDay.Format("2006-01-02"))
  3602. }
  3603. weekStartDay := thisTime.AddDate(0, 0, weekStart)
  3604. weekEndDay := thisTime.AddDate(0, 0, weekEnd)
  3605. weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
  3606. weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
  3607. timeLayout := "2006-01-02 15:04:05"
  3608. loc, _ := time.LoadLocation("Local")
  3609. theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
  3610. theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
  3611. weekStartPoint := theStarTime.Unix()
  3612. weekEndPoint := theEndTime.Unix()
  3613. schdules, _ := service.GetWeekScheduleThree(adminInfo.CurrentOrgId, weekStartPoint, weekEndPoint, ids, schedule_type, WeekDayIds)
  3614. c.ServeSuccessJSON(map[string]interface{}{
  3615. "days": days,
  3616. "weekTitle": weekTitle,
  3617. "schdules": schdules,
  3618. "today": today,
  3619. })
  3620. return
  3621. }
  3622. func (c *ScheduleApiController) SaveScheduleTemplate() {
  3623. template_id, _ := c.GetInt64("template_id")
  3624. orgId := c.GetAdminUserInfo().CurrentOrgId
  3625. template := models.ScheduleTemplate{
  3626. TemplateId: template_id,
  3627. UserOrgId: orgId,
  3628. Status: 1,
  3629. Ctime: time.Now().Unix(),
  3630. }
  3631. _, errcodes := service.GetScheudleTemplateById(orgId)
  3632. if errcodes == gorm.ErrRecordNotFound {
  3633. service.CreateXtscheduleTemplate(&template)
  3634. } else if errcodes == nil {
  3635. service.UpdateXtScheduleTemplate(&template, orgId)
  3636. }
  3637. c.ServeSuccessJSON(map[string]interface{}{
  3638. "template": template,
  3639. })
  3640. return
  3641. }
  3642. func (c *ScheduleApiController) GetScheduleTemplate() {
  3643. adminUserInfo := c.GetAdminUserInfo()
  3644. orgId := adminUserInfo.CurrentOrgId
  3645. template, _ := service.GetScheduleTemplate(orgId)
  3646. c.ServeSuccessJSON(map[string]interface{}{
  3647. "template": template,
  3648. })
  3649. return
  3650. }
  3651. func (c *ScheduleApiController) ChangeFuncPrint() {
  3652. adminUserInfo := c.GetAdminUserInfo()
  3653. orgId := adminUserInfo.CurrentOrgId
  3654. is_open, _ := c.GetInt64("is_open")
  3655. dataPrint := models.XtDataPrint{
  3656. UserOrgId: orgId,
  3657. IsOpen: is_open,
  3658. Status: 1,
  3659. Ctime: time.Now().Unix(),
  3660. }
  3661. _, errcode := service.GetDataPrintByOrgId(orgId)
  3662. if errcode == gorm.ErrRecordNotFound {
  3663. service.CreateDataPrint(&dataPrint)
  3664. c.ServeSuccessJSON(map[string]interface{}{
  3665. "dataPrint": dataPrint,
  3666. })
  3667. return
  3668. } else if errcode == nil {
  3669. service.UpdteDataPrint(orgId, &dataPrint)
  3670. c.ServeSuccessJSON(map[string]interface{}{
  3671. "dataPrint": dataPrint,
  3672. })
  3673. return
  3674. }
  3675. }
  3676. func (c *ScheduleApiController) GetDataPrint() {
  3677. adminUserInfo := c.GetAdminUserInfo()
  3678. orgId := adminUserInfo.CurrentOrgId
  3679. dataPrint, _ := service.GetDataPrint(orgId)
  3680. c.ServeSuccessJSON(map[string]interface{}{
  3681. "dataPrint": dataPrint,
  3682. })
  3683. return
  3684. }
  3685. func (c *ScheduleApiController) GetNextWeekPanels() {
  3686. start_time, _ := c.GetInt64("start_time")
  3687. fmt.Println("start_time", start_time)
  3688. end_time, _ := c.GetInt64("end_time")
  3689. fmt.Println("end_time", end_time)
  3690. orgId := c.GetAdminUserInfo().CurrentOrgId
  3691. schedule, _ := service.GetNextWeekPanels(start_time, end_time, orgId)
  3692. c.ServeSuccessJSON(map[string]interface{}{
  3693. "schedule": schedule,
  3694. })
  3695. }
  3696. func (c *ScheduleApiController) SynchroSchedule() {
  3697. template_id, _ := c.GetInt64("template_id")
  3698. copy_startime, _ := c.GetInt64("copy_startime")
  3699. copy_endtime, _ := c.GetInt64("copy_endtime")
  3700. orgId := c.GetAdminUserInfo().CurrentOrgId
  3701. //根据模板ID获取模板数据
  3702. list, _ := service.GetTemplateListByTemplateId(template_id, orgId)
  3703. fmt.Println(len(list))
  3704. //数据去重操作
  3705. list = RemoveRepeatedScheduleTemplate(list)
  3706. recordDateStr := time.Now().Format("2006-01-02")
  3707. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3708. nowtime := recordDate.Unix()
  3709. fmt.Println("今日时间", nowtime)
  3710. fmt.Println("后期日期", copy_startime)
  3711. var tuesday int64
  3712. var wednesday int64
  3713. var thursday int64
  3714. var friday int64
  3715. var saturday int64
  3716. //
  3717. //如果选择的开始日期大于当前日期
  3718. if copy_startime > nowtime {
  3719. //清空该时间段的所有排班数据
  3720. service.DeletePatientSchedule(copy_startime, copy_endtime, orgId)
  3721. tuesday = copy_startime + 86400
  3722. wednesday = copy_startime + 172800
  3723. thursday = copy_startime + 259200
  3724. friday = copy_startime + 345600
  3725. saturday = copy_startime + 432000
  3726. for _, item := range list {
  3727. if item.Weekday == 1 {
  3728. item.ScheduleDate = copy_startime
  3729. }
  3730. if item.Weekday == 2 {
  3731. item.ScheduleDate = tuesday
  3732. }
  3733. if item.Weekday == 3 {
  3734. item.ScheduleDate = wednesday
  3735. }
  3736. if item.Weekday == 4 {
  3737. item.ScheduleDate = thursday
  3738. }
  3739. if item.Weekday == 5 {
  3740. item.ScheduleDate = friday
  3741. }
  3742. if item.Weekday == 6 {
  3743. item.ScheduleDate = saturday
  3744. }
  3745. if item.Weekday == 7 {
  3746. item.ScheduleDate = copy_endtime
  3747. }
  3748. //根据床位号获取区号
  3749. number, _ := service.GetBedNumberById(item.DeviceNumberID, orgId)
  3750. item.ZoneId = number.ZoneID
  3751. }
  3752. for _, item := range list {
  3753. schedule := models.XtSchedule{
  3754. UserOrgId: orgId,
  3755. PartitionId: item.ZoneId,
  3756. BedId: item.DeviceNumberID,
  3757. PatientId: item.PatientID,
  3758. ScheduleDate: item.ScheduleDate,
  3759. ScheduleType: item.TimeType,
  3760. ScheduleWeek: item.Weekday,
  3761. ModeId: item.TreatMode,
  3762. Status: 1,
  3763. CreatedTime: time.Now().Unix(),
  3764. UpdatedTime: 0,
  3765. IsExport: 2000,
  3766. }
  3767. var DialysisMachineName string
  3768. so, _ := service.GetDialysisSolutionTwo(c.GetAdminUserInfo().CurrentOrgId, schedule.PatientId, schedule.ModeId)
  3769. filedRecordOne, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "透析器")
  3770. filedRecordTwo, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "灌流器")
  3771. filedRecordThree, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "透析器/灌流器")
  3772. if filedRecordOne.IsShow == 1 {
  3773. DialysisMachineName = so.DialysisDialyszers
  3774. }
  3775. if filedRecordThree.IsShow == 1 {
  3776. if len(DialysisMachineName) > 0 {
  3777. DialysisMachineName = DialysisMachineName + "," + so.DialyzerPerfusionApparatus
  3778. } else {
  3779. DialysisMachineName = so.DialyzerPerfusionApparatus
  3780. }
  3781. }
  3782. if filedRecordTwo.IsShow == 1 {
  3783. if len(DialysisMachineName) > 0 {
  3784. DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
  3785. } else {
  3786. DialysisMachineName = so.DialysisIrrigation
  3787. }
  3788. }
  3789. schedule.DialysisMachineName = DialysisMachineName
  3790. service.CreatePatientSchedule(&schedule)
  3791. }
  3792. }
  3793. //如果选择的日期小于当前日期,只同步今日以后的数据
  3794. if copy_startime <= nowtime {
  3795. //清空今日以后的数据
  3796. service.DeletePatientScheduleToday(nowtime, copy_endtime, orgId)
  3797. var tuesday int64
  3798. var wednesday int64
  3799. var thursday int64
  3800. var friday int64
  3801. var saturday int64
  3802. tuesday = copy_startime + 86400
  3803. wednesday = copy_startime + 172800
  3804. thursday = copy_startime + 259200
  3805. friday = copy_startime + 345600
  3806. saturday = copy_startime + 432000
  3807. for _, item := range list {
  3808. if item.Weekday == 1 {
  3809. item.ScheduleDate = copy_startime
  3810. }
  3811. if item.Weekday == 2 {
  3812. item.ScheduleDate = tuesday
  3813. }
  3814. if item.Weekday == 3 {
  3815. item.ScheduleDate = wednesday
  3816. }
  3817. if item.Weekday == 4 {
  3818. item.ScheduleDate = thursday
  3819. }
  3820. if item.Weekday == 5 {
  3821. item.ScheduleDate = friday
  3822. }
  3823. if item.Weekday == 6 {
  3824. item.ScheduleDate = saturday
  3825. }
  3826. if item.Weekday == 7 {
  3827. item.ScheduleDate = copy_endtime
  3828. }
  3829. //根据床位号获取区号
  3830. number, _ := service.GetBedNumberById(item.DeviceNumberID, orgId)
  3831. item.ZoneId = number.ZoneID
  3832. }
  3833. for _, item := range list {
  3834. // 同步今日以后的数据
  3835. if item.ScheduleDate > nowtime {
  3836. schedule := models.XtSchedule{
  3837. UserOrgId: orgId,
  3838. PartitionId: item.ZoneId,
  3839. BedId: item.DeviceNumberID,
  3840. PatientId: item.PatientID,
  3841. ScheduleDate: item.ScheduleDate,
  3842. ScheduleType: item.TimeType,
  3843. ScheduleWeek: item.Weekday,
  3844. ModeId: item.TreatMode,
  3845. Status: 1,
  3846. CreatedTime: time.Now().Unix(),
  3847. UpdatedTime: 0,
  3848. }
  3849. var DialysisMachineName string
  3850. so, _ := service.GetDialysisSolutionTwo(c.GetAdminUserInfo().CurrentOrgId, schedule.PatientId, schedule.ModeId)
  3851. filedRecordOne, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "透析器")
  3852. filedRecordTwo, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "灌流器")
  3853. filedRecordThree, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "透析器/灌流器")
  3854. if filedRecordOne.IsShow == 1 {
  3855. DialysisMachineName = so.DialysisDialyszers
  3856. }
  3857. if filedRecordThree.IsShow == 1 {
  3858. if len(DialysisMachineName) > 0 {
  3859. DialysisMachineName = DialysisMachineName + "," + so.DialyzerPerfusionApparatus
  3860. } else {
  3861. DialysisMachineName = so.DialyzerPerfusionApparatus
  3862. }
  3863. }
  3864. if filedRecordTwo.IsShow == 1 {
  3865. if len(schedule.DialysisMachineName) > 0 {
  3866. DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
  3867. } else {
  3868. DialysisMachineName = so.DialysisIrrigation
  3869. }
  3870. }
  3871. schedule.DialysisMachineName = DialysisMachineName
  3872. service.CreatePatientSchedule(&schedule)
  3873. }
  3874. }
  3875. }
  3876. returnData := make(map[string]interface{}, 0)
  3877. returnData["list"] = list
  3878. c.ServeSuccessJSON(returnData)
  3879. return
  3880. }
  3881. func (c *ScheduleApiController) GetPatientScheduleTempalate() {
  3882. orgId := c.GetAdminUserInfo().CurrentOrgId
  3883. tempalate, _ := service.GetPatientScheduleTempalate(orgId)
  3884. c.ServeSuccessJSON(map[string]interface{}{
  3885. "schedule": tempalate,
  3886. })
  3887. }
  3888. func (c *ScheduleApiController) GetSolutionSchedule() {
  3889. orgId := c.GetAdminUserInfo().CurrentOrgId
  3890. solution, _ := service.GetSolutionSchedule(orgId)
  3891. c.ServeSuccessJSON(map[string]interface{}{
  3892. "solution": solution,
  3893. })
  3894. return
  3895. }
  3896. func RemoveRepeatedScheduleTemplate(arr []*models.VmPatientScheduleTemplateItem) (newArr []*models.VmPatientScheduleTemplateItem) {
  3897. newArr = make([]*models.VmPatientScheduleTemplateItem, 0)
  3898. for i := 0; i < len(arr); i++ {
  3899. repeat := false
  3900. for j := i + 1; j < len(arr); j++ {
  3901. if arr[i].TemplateID == arr[j].TemplateID && arr[i].PatientID == arr[j].PatientID && arr[i].Weekday == arr[j].Weekday {
  3902. repeat = true
  3903. break
  3904. }
  3905. }
  3906. if !repeat {
  3907. newArr = append(newArr, arr[i])
  3908. }
  3909. }
  3910. return
  3911. }