schedule_api_controller.go 146KB

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