schedule_api_controller.go 142KB

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