mobile_dialysis_service.go 393KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572
  1. package service
  2. import (
  3. "XT_New/models"
  4. "encoding/json"
  5. "fmt"
  6. "github.com/jinzhu/gorm"
  7. "strconv"
  8. "time"
  9. )
  10. // func GetSchedualPatients(orgID int64) ([]*MDialysisScheduleVM, error) {
  11. // var vms []*MDialysisScheduleVM
  12. // err := readDb.
  13. // Table("xt_schedule as sch").
  14. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  15. // Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  16. // Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
  17. // Preload("TreatmentMode", "status = 1").
  18. // Preload("DialysisOrder", "status = 1 AND user_org_id = ?", orgID).
  19. // Preload("DialysisOrder.MonitoringRecords", "status = 1 AND user_org_id = ?", orgID).
  20. // Where("sch.status = 1 AND sch.user_org_id = ? AND schedule_date = 1536768000", orgID).
  21. // Find(&vms).
  22. // Error
  23. // return vms, err
  24. // }
  25. func MobileGetDialysisScheduals(orgID int64, scheduleDate int64, scheduleType int64) ([]*MDialysisScheduleVMForList, error) {
  26. var vms []*MDialysisScheduleVMForList
  27. db := readDb.
  28. Table("xt_schedule as sch").
  29. Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
  30. if scheduleDate != 0 {
  31. db = db.Where("schedule_date = ?", scheduleDate)
  32. }
  33. if scheduleType != 0 {
  34. db = db.Where("schedule_type = ?", scheduleType)
  35. }
  36. err := db.Find(&vms).Error
  37. //err := db.Preload("DialysisLastOrder", func(db *gorm.DB) *gorm.DB {
  38. // return db.Order("dialysis_date desc").Where(" status = 1 AND user_org_id = ? and dialysis_date>=1672502400 && dialysis_date < ?", orgID, scheduleDate)
  39. //}).Preload("DialysisSolution", "status = 1 and user_org_id = ? and solution_status = 1", orgID).Find(&vms).Error
  40. return vms, err
  41. }
  42. func GetMonitDialysisOrder(user_org_id int64, patient_id int64, scheduleDate int64) (*models.MDialysisOrderForList, error) {
  43. order := models.MDialysisOrderForList{}
  44. err := XTReadDB().Where("user_org_id = ? and status =1 and patient_id = ?", user_org_id, patient_id).Order("id desc").Last(&order).Error
  45. return &order, err
  46. }
  47. func GetMonitDialysisSolution(user_org_id int64, patient_id int64, mode_id int64) (*models.DialysisSolution, error) {
  48. solution := models.DialysisSolution{}
  49. err := XTReadDB().Where("user_org_id = ? and patient_id =? and solution_status = 1 and mode_id = ?", user_org_id, patient_id, mode_id).Find(&solution).Error
  50. return &solution, err
  51. }
  52. func MobileGetWaitingScheduals(orgID int64, scheduleDate int64) ([]*MDialysisScheduleVM, error) {
  53. var vms []*MDialysisScheduleVM
  54. db := readDb.
  55. Table("xt_schedule as sch").
  56. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  57. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  58. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  59. // Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
  60. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  61. Preload("AssessmentBeforeDislysis", "status = 1 AND user_org_id = ? AND assessment_date = ? ", orgID, scheduleDate).
  62. Preload("DialysisOrder", "status = 1 AND user_org_id = ?", orgID).
  63. Preload("Advices", "status = 1 AND user_org_id = ? AND advice_type = 2 ", orgID).
  64. Preload("TreatmentMode", "status = 1").
  65. Preload("TreatmentSummary", "status = 1 AND user_org_id = ?", orgID).
  66. Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
  67. if scheduleDate != 0 {
  68. db = db.Where("schedule_date = ?", scheduleDate)
  69. }
  70. err := db.Find(&vms).Error
  71. return vms, err
  72. }
  73. type VMTreatmentSummary struct {
  74. ID int64 `gorm:"column:id" json:"id"`
  75. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  76. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  77. AssessmentDate int64 `gorm:"column:assessment_date" json:"assessment_date"`
  78. DialysisSummary string `gorm:"column:dialysis_summary" json:"dialysis_summary" form:"dialysis_summary"`
  79. }
  80. func (VMTreatmentSummary) TableName() string {
  81. return "xt_treatment_summary"
  82. }
  83. type AssessmentAfterDislysis struct {
  84. ID int64 `gorm:"column:id" json:"id"`
  85. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  86. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  87. AssessmentDate int64 `gorm:"column:assessment_date" json:"assessment_date"`
  88. WeightAfter float64 `gorm:"column:weight_after" json:"weight_after"`
  89. Status int64 `gorm:"column:status" json:"status"`
  90. }
  91. func (AssessmentAfterDislysis) TableName() string {
  92. return "xt_assessment_after_dislysis"
  93. }
  94. type MDialysisScheduleVM struct {
  95. ID int64 `gorm:"column:id" json:"id"`
  96. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  97. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  98. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  99. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  100. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  101. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  102. ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week"`
  103. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  104. Status int64 `gorm:"column:status" json:"status"`
  105. SchedualPatient *MSchedualPatientVMList `gorm:"ForeignKey:PatientId" json:"patient"`
  106. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  107. DialysisOrder *MDialysisOrderVMList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  108. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  109. AssessmentBeforeDislysis *models.PredialysisEvaluationList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_before_dislysis"`
  110. AssessmentAfterDislysis *AssessmentAfterDislysis `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_after_dislysis"`
  111. HisAdvices []*VMHisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"his_doctor_advice"`
  112. Advices []*VMDoctorAdvice `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  113. TreatmentSummary *VMTreatmentSummary `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"treatment_summary"`
  114. NewDeviceInformation *NewDeviceInformation `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"device_information"`
  115. }
  116. func (MDialysisScheduleVM) TableName() string {
  117. return "xt_schedule"
  118. }
  119. type MDialysisScheduleVMForList struct {
  120. ID int64 `gorm:"column:id" json:"id"`
  121. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  122. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  123. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  124. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  125. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  126. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  127. ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week"`
  128. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  129. Status int64 `gorm:"column:status" json:"status"`
  130. SchedualPatient *models.MSchedualPatientList `gorm:"ForeignKey:PatientId" json:"patient"`
  131. DeviceNumber *models.MDeviceNumberForList `gorm:"ForeignKey:BedId" json:"device_number"`
  132. DialysisOrder *models.MDialysisOrderForList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  133. DialysisLastOrder *models.MDialysisOrderForList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"last_order"`
  134. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  135. AssessmentBeforeDislysis *models.PredialysisEvaluationList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_before_dislysis"`
  136. AssessmentAfterDislysis *models.VMAssessmentAfterDislysis `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_after_dislysis"`
  137. HisAdvices []VMHisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"his_doctor_advice"`
  138. Advices []models.VMDoctorAdviceForList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  139. TreatmentSummary *models.VMTreatmentSummaryForList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"treatment_summary"`
  140. DialysisSolution *models.DialysisSolution `gorm:"ForeignKey:PatientId,ModeId;AssociationForeignKey:PatientId,ModeId" json:"dialysis_solution"`
  141. DoubleCheck *models.DoubleCheck `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dobule_check"`
  142. NewDeviceInformation *NewDeviceInformation `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"device_information"`
  143. //VMMonitoringRecord []models.VMMonitoringRecord `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"monitor_record"`
  144. }
  145. func (MDialysisScheduleVMForList) TableName() string {
  146. return "xt_schedule"
  147. }
  148. type MDeviceNumberVM struct {
  149. models.DeviceNumber
  150. Zone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"zone"`
  151. }
  152. func (MDeviceNumberVM) TableName() string {
  153. return "xt_device_number"
  154. }
  155. type MSchedualPatientVMList struct {
  156. ID int64 `gorm:"column:id" json:"id" form:"id"`
  157. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  158. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  159. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  160. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
  161. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  162. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  163. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  164. Age int64 `gorm:"column:age" json:"age"`
  165. Name string `gorm:"column:name" json:"name" form:"name"`
  166. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  167. UserSysBeforeCount int64 `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
  168. TrobleShoot int64 `gorm:"column:troble_shoot" json:"troble_shoot" form:"troble_shoot"`
  169. SchRemark string `gorm:"column:sch_remark" json:"sch_remark" form:"sch_remark"`
  170. ScheduleRemark string `gorm:"column:schedule_remark" json:"schedule_remark" form:"schedule_remark"`
  171. }
  172. func (MSchedualPatientVMList) TableName() string {
  173. return "xt_patients"
  174. }
  175. type MSchedualPatientVM struct {
  176. ID int64 `gorm:"column:id" json:"id" form:"id"`
  177. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  178. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  179. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  180. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  181. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
  182. AdmissionNumber string `gorm:"column:admission_number" json:"admission_number" form:"admission_number"`
  183. Source int64 `gorm:"column:source" json:"source" form:"source"`
  184. Lapseto int64 `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
  185. PartitionId int64 `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
  186. BedId int64 `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
  187. Name string `gorm:"column:name" json:"name" form:"name"`
  188. Alias string `gorm:"column:alias" json:"alias" form:"alias"`
  189. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  190. Nation string `gorm:"column:nation" json:"nation" form:"nation"`
  191. NativePlace string `gorm:"column:native_place" json:"native_place" form:"native_place"`
  192. MaritalStatus int64 `gorm:"column:marital_status" json:"marital_status" form:"marital_status"`
  193. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  194. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  195. ReimbursementWayId int64 `gorm:"column:reimbursement_way_id" json:"reimbursement_way_id" form:"reimbursement_way_id"`
  196. HealthCareType int64 `gorm:"column:health_care_type" json:"health_care_type" form:"health_care_type"`
  197. HealthCareNo string `gorm:"column:health_care_no" json:"health_care_no" form:"health_care_no"`
  198. HealthCareDueDate int64 `gorm:"column:health_care_due_date" json:"health_care_due_date" form:"health_care_due_date"`
  199. Height int64 `gorm:"column:height" json:"height" form:"height"`
  200. BloodType int64 `gorm:"column:blood_type" json:"blood_type" form:"blood_type"`
  201. Rh int64 `gorm:"column:rh" json:"rh" form:"rh"`
  202. HealthCareDueAlertDate int64 `gorm:"column:health_care_due_alert_date" json:"health_care_due_alert_date" form:"health_care_due_alert_date"`
  203. EducationLevel int64 `gorm:"column:education_level" json:"education_level" form:"education_level"`
  204. Profession int64 `gorm:"column:profession" json:"profession" form:"profession"`
  205. Phone string `gorm:"column:phone" json:"phone" form:"phone"`
  206. HomeTelephone string `gorm:"column:home_telephone" json:"home_telephone" form:"home_telephone"`
  207. RelativePhone string `gorm:"column:relative_phone" json:"relative_phone" form:"relative_phone"`
  208. RelativeRelations string `gorm:"column:relative_relations" json:"relative_relations" form:"relative_relations"`
  209. HomeAddress string `gorm:"column:home_address" json:"home_address" form:"home_address"`
  210. WorkUnit string `gorm:"column:work_unit" json:"work_unit" form:"work_unit"`
  211. UnitAddress string `gorm:"column:unit_address" json:"unit_address" form:"unit_address"`
  212. Children int64 `gorm:"column:children" json:"children" form:"children"`
  213. ReceivingDate int64 `gorm:"column:receiving_date" json:"receiving_date" form:"receiving_date"`
  214. IsHospitalFirstDialysis int64 `gorm:"column:is_hospital_first_dialysis" json:"is_hospital_first_dialysis" form:"is_hospital_first_dialysis"`
  215. FirstDialysisDate int64 `gorm:"column:first_dialysis_date" json:"first_dialysis_date" form:"first_dialysis_date"`
  216. FirstDialysisHospital string `gorm:"column:first_dialysis_hospital" json:"first_dialysis_hospital" form:"first_dialysis_hospital"`
  217. InductionPeriod int64 `gorm:"column:induction_period" json:"induction_period" form:"induction_period"`
  218. InitialDialysis int64 `gorm:"column:initial_dialysis" json:"initial_dialysis" form:"initial_dialysis"`
  219. TotalDialysis int64 `gorm:"column:total_dialysis" json:"total_dialysis" form:"total_dialysis"`
  220. AttendingDoctorId int64 `gorm:"column:attending_doctor_id" json:"attending_doctor_id" form:"attending_doctor_id"`
  221. HeadNurseId int64 `gorm:"column:head_nurse_id" json:"head_nurse_id" form:"head_nurse_id"`
  222. Evaluate string `gorm:"column:evaluate" json:"evaluate" form:"evaluate"`
  223. Diagnose string `gorm:"column:diagnose" json:"diagnose" form:"diagnose"`
  224. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  225. RegistrarsId int64 `gorm:"column:registrars_id" json:"registrars_id" form:"registrars_id"`
  226. Registrars string `gorm:"column:registrars" json:"registrars" form:"registrars"`
  227. QrCode string `gorm:"column:qr_code" json:"qr_code" form:"qr_code"`
  228. BindingState int64 `gorm:"column:binding_state" json:"binding_state" form:"binding_state"`
  229. PatientComplains string `gorm:"column:patient_complains" json:"patient_complains"` // 主诉
  230. PresentHistory string `gorm:"column:present_history" json:"present_history"` // 现病史
  231. PastHistory string `gorm:"column:past_history" json:"past_history"` // 既往史
  232. Temperature float64 `gorm:"column:temperature" json:"temperature"` // 体格检查-体温
  233. Pulse int64 `gorm:"column:pulse" json:"pulse"` // 体格检查-脉搏
  234. Respiratory int64 `gorm:"column:respiratory" json:"respiratory"` // 体格检查-呼吸频率
  235. SBP int64 `gorm:"column:sbp" json:"sbp"` // 体格检查-收缩压
  236. DBP int64 `gorm:"column:dbp" json:"dbp"` // 体格检查-舒张压
  237. Status int64 `gorm:"column:status" json:"status" form:"status"`
  238. Age int64 `gorm:"column:age" json:"age"`
  239. IsOpenRemind int64 `gorm:"column:is_open_remind" json:"is_open_remind"`
  240. DialysisAge int64 `gorm:"column:dialysis_age" json:"dialysis_age" form:"dialysis_age"`
  241. ExpenseKind int64 `gorm:"column:expense_kind" json:"expense_kind" form:"expense_kind"`
  242. TellPhone string `gorm:"column:tell_phone" json:"tell_phone" form:"tell_phone"`
  243. FirstTreatmentDate int64 `gorm:"column:first_treatment_date" json:"first_treatment_date" form:"first_treatment_date"`
  244. ContactName string `gorm:"column:contact_name" json:"contact_name" form:"contact_name"`
  245. UserSysBeforeCount int64 `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
  246. }
  247. func (MSchedualPatientVM) TableName() string {
  248. return "xt_patients"
  249. }
  250. type MDialysisOrderVM struct {
  251. ID int64 `gorm:"column:id" json:"id"`
  252. DialysisDate int64 `gorm:"column:dialysis_date" json:"dialysis_date"`
  253. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  254. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  255. Stage int64 `gorm:"column:stage" json:"stage"`
  256. BedID int64 `gorm:"column:bed_id" json:"bed_id"`
  257. StartNurse int64 `gorm:"column:start_nurse" json:"start_nurse"`
  258. FinishNurse int64 `gorm:"column:finish_nurse" json:"finish_nurse"`
  259. Status int64 `gorm:"column:status" json:"status"`
  260. PunctureNurse int64 `gorm:"column:puncture_nurse" json:"puncture_nurse"`
  261. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedID" json:"device_number"`
  262. MonitoringRecords []*models.MonitoringRecord `gorm:"ForeignKey:DialysisOrderId" json:"monitoring_records"`
  263. Creator int64 `gorm:"column:creator" json:"creator"`
  264. Modifier int64 `gorm:"column:modifier" json:"modifier"`
  265. FinishCreator int64 `gorm:"column:finish_creator" json:"finish_creator"`
  266. FinishModifier int64 `gorm:"column:finish_modifier" json:"finish_modifier"`
  267. SchedualType int64 `gorm:"column:schedual_type" json:"schedual_type"`
  268. WashpipeNurse int64 `gorm:"column:washpipe_nurse" json:"washpipe_nurse" form:"washpipe_nurse"`
  269. DialysisIrrigation string `gorm:"column:dialysis_irrigation" json:"dialysis_irrigation" form:"dialysis_irrigation"`
  270. DialysisDialyszers string `gorm:"column:dialysis_dialyszers" json:"dialysis_dialyszers" form:"dialysis_dialyszers"`
  271. }
  272. func (MDialysisOrderVM) TableName() string {
  273. return "xt_dialysis_order"
  274. }
  275. type MDialysisOrderVMList struct {
  276. ID int64 `gorm:"column:id" json:"id"`
  277. DialysisDate int64 `gorm:"column:dialysis_date" json:"dialysis_date"`
  278. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  279. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  280. // PrescriptionId int64 `gorm:"column:prescription_id" json:"prescription_id"`
  281. Stage int64 `gorm:"column:stage" json:"stage"`
  282. // Remark string `gorm:"column:remark" json:"remark"`
  283. BedID int64 `gorm:"column:bed_id" json:"bed_id"`
  284. StartNurse int64 `gorm:"column:start_nurse" json:"start_nurse"`
  285. Status int64 `gorm:"column:status" json:"status"`
  286. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedID" json:"device_number"`
  287. Creator int64 `gorm:"column:creator" json:"creator"`
  288. WashpipeNurse int64 `gorm:"column:washpipe_nurse" json:"washpipe_nurse" form:"washpipe_nurse"`
  289. NucleinDate int64 `gorm:"column:nuclein_date" json:"nuclein_date" form:"nuclein_date"`
  290. DialysisIrrigation string `gorm:"column:dialysis_irrigation" json:"dialysis_irrigation" form:"dialysis_irrigation"`
  291. DialysisDialyszers string `gorm:"column:dialysis_dialyszers" json:"dialysis_dialyszers" form:"dialysis_dialyszers"`
  292. ScheduleRemark string `gorm:"column:schedule_remark" json:"schedule_remark" form:"schedule_remark"`
  293. }
  294. func (MDialysisOrderVMList) TableName() string {
  295. return "xt_dialysis_order"
  296. }
  297. type VMDoctorAdvice struct {
  298. ID int64 `gorm:"column:id" json:"id" form:"id"`
  299. GroupNo int64 `gorm:"column:groupno" json:"groupno" form:"groupno"`
  300. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  301. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  302. AdviceDate int64 `gorm:"column:advice_date" json:"advice_date" form:"advice_date"`
  303. Status int64 `gorm:"column:status" json:"status" form:"status"`
  304. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
  305. RecordDate int64 `gorm:"column:record_date" json:"record_date"`
  306. CheckTime int64 `gorm:"column:check_time" json:"check_time" form:"check_time"`
  307. CheckState int64 `gorm:"column:check_state" json:"check_state" form:"check_state"`
  308. ParentId int64 `gorm:"column:parent_id" json:"parent_id" form:"parent_id"`
  309. }
  310. func (VMDoctorAdvice) TableName() string {
  311. return "xt_doctor_advice"
  312. }
  313. type VMHisDoctorAdviceInfo struct {
  314. ID int64 `gorm:"column:id" json:"id" form:"id"`
  315. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  316. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  317. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  318. ExecutionTime int64 `gorm:"column:execution_time" json:"execution_time" form:"execution_time"`
  319. ExecutionStaff int64 `gorm:"column:execution_staff" json:"execution_staff" form:"execution_staff"`
  320. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
  321. IsMedicine int64 `gorm:"column:is_medicine" json:"is_medicine" form:"is_medicine"`
  322. ExecutionFrequencyId int64 `gorm:"column:execution_frequency_id" json:"execution_frequency_id" form:"execution_frequency_id"`
  323. }
  324. func (VMHisDoctorAdviceInfo) TableName() string {
  325. return "his_doctor_advice_info"
  326. }
  327. type VMAssessmentAfterDislysis struct {
  328. ID int64 `gorm:"column:id" json:"id"`
  329. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  330. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  331. AssessmentDate int64 `gorm:"column:assessment_date" json:"assessment_date"`
  332. WeightAfter float64 `gorm:"column:weight_after" json:"weight_after"`
  333. Status int64 `gorm:"column:status" json:"status"`
  334. }
  335. func (VMAssessmentAfterDislysis) TableName() string {
  336. return "xt_assessment_after_dislysis"
  337. }
  338. type NewDeviceInformation struct {
  339. ID int64 `gorm:"column:id" json:"id" form:"id"`
  340. Date int64 `gorm:"column:date" json:"date" form:"date"`
  341. Class int64 `gorm:"column:class" json:"class" form:"class"`
  342. Zone int64 `gorm:"column:zone" json:"zone" form:"zone"`
  343. BedNumber int64 `gorm:"column:bed_number" json:"bed_number" form:"bed_number"`
  344. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  345. Status int64 `gorm:"column:status" json:"status" form:"status"`
  346. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  347. EquimentId int64 `gorm:"column:equiment_id" json:"equiment_id" form:"equiment_id"`
  348. Bed string `gorm:"column:bed" json:"bed" form:"bed"`
  349. Stime int64 `gorm:"column:stime" json:"stime" form:"stime"`
  350. }
  351. func (NewDeviceInformation) TableName() string {
  352. return "xt_device_information"
  353. }
  354. // 获取透析记录
  355. func MobileGetDialysisRecord(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  356. var record models.DialysisOrder
  357. err := readDb.Model(&models.DialysisOrder{}).Where("user_org_id = ? AND patient_id = ? AND dialysis_date = ?", orgID, patientID, recordDate).First(&record).Error
  358. if err != nil {
  359. if err == gorm.ErrRecordNotFound {
  360. return nil, nil
  361. } else {
  362. return nil, err
  363. }
  364. }
  365. return &record, nil
  366. }
  367. // 用户基本信息
  368. func MobileGetPatientDetail(orgID int64, patientID int64) (*MPatient, error) {
  369. var patient MPatient
  370. //err := readDb.Model(&MPatient{}).Where("status = 1 AND user_org_id = ? AND id = ?", orgID, patientID).First(&patient).Error
  371. //if err != nil {
  372. // if err == gorm.ErrRecordNotFound {
  373. // return nil, nil
  374. // } else {
  375. // return nil, err
  376. // }
  377. //}
  378. //return &patient, nil
  379. redis := RedisClient()
  380. defer redis.Close()
  381. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":patient_info"
  382. patient_info_str, _ := redis.Get(key).Result()
  383. if len(patient_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  384. err = readDb.Model(&patient).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
  385. if err != nil {
  386. if err == gorm.ErrRecordNotFound {
  387. return &patient, nil
  388. } else {
  389. return &patient, err
  390. }
  391. } else {
  392. if patient.ID > 0 {
  393. //缓存数据
  394. patient_info_json, err := json.Marshal(&patient)
  395. if err == nil {
  396. redis.Set(key, patient_info_json, time.Second*60*60*18)
  397. }
  398. }
  399. return &patient, nil
  400. }
  401. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  402. json.Unmarshal([]byte(patient_info_str), &patient)
  403. return &patient, nil
  404. }
  405. }
  406. func MobileGetSchedualDetailOne(orgID int64, patientID int64, schedualDate int64) (*MDialysisScheduleVM, error) {
  407. var vm MDialysisScheduleVM
  408. err := readDb.
  409. Table("xt_schedule").
  410. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  411. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  412. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  413. First(&vm).Error
  414. return &vm, err
  415. }
  416. // 用户排班信息
  417. func MobileGetSchedualDetailSix(orgID int64, patientID int64, schedualDate int64) (*MDialysisScheduleVM, error) {
  418. var vm MDialysisScheduleVM
  419. err := readDb.
  420. Table("xt_schedule").
  421. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  422. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  423. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  424. First(&vm).Error
  425. if err != nil {
  426. if err == gorm.ErrRecordNotFound {
  427. return nil, nil
  428. } else {
  429. return nil, err
  430. }
  431. }
  432. return &vm, err
  433. }
  434. // 用户排班信息
  435. func MobileGetSchedualDetail(orgID int64, patientID int64, schedualDate int64) (*MDialysisScheduleVM, error) {
  436. redis := RedisClient()
  437. defer redis.Close()
  438. var vm MDialysisScheduleVM
  439. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(schedualDate, 10) + ":schedual_detail"
  440. redis.Set(key, "", time.Second)
  441. schedual_detail_str, _ := redis.Get(key).Result()
  442. if len(schedual_detail_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  443. err := readDb.
  444. Table("xt_schedule").
  445. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  446. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  447. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  448. First(&vm).Error
  449. if err != nil {
  450. if err == gorm.ErrRecordNotFound {
  451. return nil, nil
  452. } else {
  453. return nil, err
  454. }
  455. } else {
  456. if vm.ID > 0 {
  457. //缓存数据
  458. schedual_detail_str, err := json.Marshal(vm)
  459. if err == nil {
  460. redis.Set(key, schedual_detail_str, time.Second*60*60*18)
  461. }
  462. } else {
  463. redis.Set(key, "null", time.Second*60*60*18)
  464. }
  465. return &vm, nil
  466. }
  467. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  468. if schedual_detail_str == "null" {
  469. return &vm, nil
  470. }
  471. json.Unmarshal([]byte(schedual_detail_str), &vm)
  472. return &vm, nil
  473. }
  474. }
  475. // 用户排班信息
  476. func MobileGetPatientSchedual(orgID int64, patientID int64, schedualDate int64) (*models.Schedule, error) {
  477. var schedule models.Schedule
  478. err := readDb.
  479. Table("xt_schedule").
  480. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  481. First(&schedule).Error
  482. if err != nil {
  483. if err == gorm.ErrRecordNotFound {
  484. return nil, nil
  485. } else {
  486. return nil, err
  487. }
  488. }
  489. return &schedule, nil
  490. }
  491. type MPatient struct {
  492. ID int64 `gorm:"column:id" json:"id" form:"id"`
  493. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  494. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  495. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  496. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  497. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
  498. AdmissionNumber string `gorm:"column:admission_number" json:"admission_number" form:"admission_number"`
  499. Source int64 `gorm:"column:source" json:"source" form:"source"`
  500. Lapseto int64 `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
  501. PartitionId int64 `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
  502. BedId int64 `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
  503. Name string `gorm:"column:name" json:"name" form:"name"`
  504. Alias string `gorm:"column:alias" json:"alias" form:"alias"`
  505. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  506. Nation string `gorm:"column:nation" json:"nation" form:"nation"`
  507. NativePlace string `gorm:"column:native_place" json:"native_place" form:"native_place"`
  508. MaritalStatus int64 `gorm:"column:marital_status" json:"marital_status" form:"marital_status"`
  509. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  510. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  511. ReimbursementWayId int64 `gorm:"column:reimbursement_way_id" json:"reimbursement_way_id" form:"reimbursement_way_id"`
  512. HealthCareType int64 `gorm:"column:health_care_type" json:"health_care_type" form:"health_care_type"`
  513. HealthCareNo string `gorm:"column:health_care_no" json:"health_care_no" form:"health_care_no"`
  514. HealthCareDueDate int64 `gorm:"column:health_care_due_date" json:"health_care_due_date" form:"health_care_due_date"`
  515. Height int64 `gorm:"column:height" json:"height" form:"height"`
  516. BloodType int64 `gorm:"column:blood_type" json:"blood_type" form:"blood_type"`
  517. Rh int64 `gorm:"column:rh" json:"rh" form:"rh"`
  518. HealthCareDueAlertDate int64 `gorm:"column:health_care_due_alert_date" json:"health_care_due_alert_date" form:"health_care_due_alert_date"`
  519. EducationLevel int64 `gorm:"column:education_level" json:"education_level" form:"education_level"`
  520. Profession int64 `gorm:"column:profession" json:"profession" form:"profession"`
  521. Phone string `gorm:"column:phone" json:"phone" form:"phone"`
  522. HomeTelephone string `gorm:"column:home_telephone" json:"home_telephone" form:"home_telephone"`
  523. RelativePhone string `gorm:"column:relative_phone" json:"relative_phone" form:"relative_phone"`
  524. RelativeRelations string `gorm:"column:relative_relations" json:"relative_relations" form:"relative_relations"`
  525. HomeAddress string `gorm:"column:home_address" json:"home_address" form:"home_address"`
  526. WorkUnit string `gorm:"column:work_unit" json:"work_unit" form:"work_unit"`
  527. UnitAddress string `gorm:"column:unit_address" json:"unit_address" form:"unit_address"`
  528. Children int64 `gorm:"column:children" json:"children" form:"children"`
  529. ReceivingDate int64 `gorm:"column:receiving_date" json:"receiving_date" form:"receiving_date"`
  530. IsHospitalFirstDialysis int64 `gorm:"column:is_hospital_first_dialysis" json:"is_hospital_first_dialysis" form:"is_hospital_first_dialysis"`
  531. FirstDialysisDate int64 `gorm:"column:first_dialysis_date" json:"first_dialysis_date" form:"first_dialysis_date"`
  532. FirstDialysisHospital string `gorm:"column:first_dialysis_hospital" json:"first_dialysis_hospital" form:"first_dialysis_hospital"`
  533. InductionPeriod int64 `gorm:"column:induction_period" json:"induction_period" form:"induction_period"`
  534. InitialDialysis int64 `gorm:"column:initial_dialysis" json:"initial_dialysis" form:"initial_dialysis"`
  535. TotalDialysis int64 `gorm:"column:total_dialysis" json:"total_dialysis" form:"total_dialysis"`
  536. AttendingDoctorId int64 `gorm:"column:attending_doctor_id" json:"attending_doctor_id" form:"attending_doctor_id"`
  537. HeadNurseId int64 `gorm:"column:head_nurse_id" json:"head_nurse_id" form:"head_nurse_id"`
  538. Evaluate string `gorm:"column:evaluate" json:"evaluate" form:"evaluate"`
  539. Diagnose string `gorm:"column:diagnose" json:"diagnose" form:"diagnose"`
  540. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  541. RegistrarsId int64 `gorm:"column:registrars_id" json:"registrars_id" form:"registrars_id"`
  542. Registrars string `gorm:"column:registrars" json:"registrars" form:"registrars"`
  543. QrCode string `gorm:"column:qr_code" json:"qr_code" form:"qr_code"`
  544. BindingState int64 `gorm:"column:binding_state" json:"binding_state" form:"binding_state"`
  545. PatientComplains string `gorm:"column:patient_complains" json:"patient_complains"` // 主诉
  546. PresentHistory string `gorm:"column:present_history" json:"present_history"` // 现病史
  547. PastHistory string `gorm:"column:past_history" json:"past_history"` // 既往史
  548. Temperature float64 `gorm:"column:temperature" json:"temperature"` // 体格检查-体温
  549. Pulse int64 `gorm:"column:pulse" json:"pulse"` // 体格检查-脉搏
  550. Respiratory int64 `gorm:"column:respiratory" json:"respiratory"` // 体格检查-呼吸频率
  551. SBP int64 `gorm:"column:sbp" json:"sbp"` // 体格检查-收缩压
  552. DBP int64 `gorm:"column:dbp" json:"dbp"` // 体格检查-舒张压
  553. Status int64 `gorm:"column:status" json:"status" form:"status"`
  554. Age int64 `gorm:"column:age" json:"age"`
  555. IsOpenRemind int64 `gorm:"column:is_open_remind" json:"is_open_remind"`
  556. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  557. DialysisAge int64 `gorm:"column:dialysis_age" json:"dialysis_age" form:"dialysis_age"`
  558. ExpenseKind int64 `gorm:"column:expense_kind" json:"expense_kind" form:"expense_kind"`
  559. TellPhone string `gorm:"column:tell_phone" json:"tell_phone" form:"tell_phone"`
  560. FirstTreatmentDate int64 `gorm:"column:first_treatment_date" json:"first_treatment_date" form:"first_treatment_date"`
  561. ContactName string `gorm:"column:contact_name" json:"contact_name" form:"contact_name"`
  562. UserSysBeforeCount int64 `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
  563. }
  564. func (MPatient) TableName() string {
  565. return "xt_patients"
  566. }
  567. // 接诊评估
  568. func MobileGetReceiverTreatmentAccessRecord(orgID int64, patientID int64, recordDate int64) (*models.ReceiveTreatmentAsses, error) {
  569. var record models.ReceiveTreatmentAsses
  570. redis := RedisClient()
  571. defer redis.Close()
  572. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":receive_treatment_asses"
  573. receive_treatment_asses_str, _ := redis.Get(key).Result()
  574. if len(receive_treatment_asses_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  575. err = readDb.Model(&models.ReceiveTreatmentAsses{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  576. if err != nil {
  577. if err == gorm.ErrRecordNotFound {
  578. if record.ID <= 0 {
  579. redis.Set(key, "", time.Second*60*60*18)
  580. }
  581. return nil, nil
  582. } else {
  583. return nil, err
  584. }
  585. } else {
  586. if record.ID > 0 {
  587. //缓存数据
  588. receive_treatment_asses_str, err := json.Marshal(record)
  589. if err == nil {
  590. redis.Set(key, receive_treatment_asses_str, time.Second*60*60*18)
  591. }
  592. } else {
  593. redis.Set(key, "null", time.Second*60*60*18)
  594. }
  595. return &record, nil
  596. }
  597. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  598. if receive_treatment_asses_str == "null" {
  599. return &record, nil
  600. }
  601. json.Unmarshal([]byte(receive_treatment_asses_str), &record)
  602. return &record, nil
  603. }
  604. }
  605. // 透前评估
  606. func MobileGetPredialysisEvaluationOne(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
  607. var record models.PredialysisEvaluation
  608. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  609. if err != nil {
  610. if err == gorm.ErrRecordNotFound {
  611. return nil, nil
  612. } else {
  613. return nil, err
  614. }
  615. }
  616. return &record, nil
  617. }
  618. func MobileGetPredialysisEvaluationTwo(orgID int64, patientID int64, recordDate int64) (models.PredialysisEvaluation, error) {
  619. var record models.PredialysisEvaluation
  620. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  621. return record, err
  622. }
  623. // 透前评估
  624. func MobileGetPredialysisEvaluation(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
  625. var record models.PredialysisEvaluation
  626. redis := RedisClient()
  627. defer redis.Close()
  628. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":assessment_before_dislysis"
  629. assessment_before_dislysis_str, _ := redis.Get(key).Result()
  630. redis.Set(key, "", time.Second)
  631. if len(assessment_before_dislysis_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  632. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  633. if err != nil {
  634. if err == gorm.ErrRecordNotFound {
  635. if record.ID <= 0 {
  636. redis.Set(key, "", time.Second*60*60*18)
  637. }
  638. return nil, nil
  639. } else {
  640. return nil, err
  641. }
  642. } else {
  643. if record.ID > 0 {
  644. //缓存数据
  645. assessment_before_dislysis_str, err := json.Marshal(record)
  646. if err == nil {
  647. redis.Set(key, assessment_before_dislysis_str, time.Second*60*60*18)
  648. }
  649. } else {
  650. redis.Set(key, "null", time.Second*60*60*18)
  651. }
  652. return &record, nil
  653. }
  654. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  655. if assessment_before_dislysis_str == "null" {
  656. return &record, nil
  657. } else {
  658. json.Unmarshal([]byte(assessment_before_dislysis_str), &record)
  659. return &record, nil
  660. }
  661. }
  662. }
  663. // 获取 maxDate 之前一次的透前评估记录
  664. func MobileGetLastTimePredialysisEvaluationOne(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
  665. var record models.PredialysisEvaluation
  666. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date < ?", patientID, orgID, maxDate).Order("assessment_date desc").First(&record).Error
  667. if err != nil {
  668. if err == gorm.ErrRecordNotFound {
  669. return nil, nil
  670. } else {
  671. return nil, err
  672. }
  673. }
  674. return &record, nil
  675. }
  676. // 获取 maxDate 之前一次的透前评估记录
  677. func MobileGetLastTimePredialysisEvaluation(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
  678. var record models.PredialysisEvaluation
  679. redis := RedisClient()
  680. defer redis.Close()
  681. // cur_date := time.Now().Format("2006-01-02")
  682. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(maxDate, 10) + ":assessment_before_dislysis_last"
  683. assessment_before_dislysis_last_str, _ := redis.Get(key).Result()
  684. if len(assessment_before_dislysis_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  685. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date < ?", patientID, orgID, maxDate).Order("assessment_date desc").First(&record).Error
  686. if err != nil {
  687. if err == gorm.ErrRecordNotFound {
  688. if record.ID <= 0 {
  689. redis.Set(key, "", time.Second*60*60*18)
  690. }
  691. return nil, nil
  692. } else {
  693. return nil, err
  694. }
  695. } else {
  696. if record.ID > 0 {
  697. //缓存数据
  698. assessment_before_dislysis_last_str, err := json.Marshal(record)
  699. if err == nil {
  700. redis.Set(key, assessment_before_dislysis_last_str, time.Second*60*60*4)
  701. }
  702. } else {
  703. redis.Set(key, "null", time.Second*60*60*18)
  704. }
  705. return &record, nil
  706. }
  707. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  708. if assessment_before_dislysis_last_str == "null" {
  709. return &record, nil
  710. } else {
  711. json.Unmarshal([]byte(assessment_before_dislysis_last_str), &record)
  712. return &record, nil
  713. }
  714. }
  715. }
  716. // 临时医嘱
  717. func MobileGetDoctorAdvices(orgID int64, patientID int64, recordDate int64) ([]*models.DoctorAdvice, error) {
  718. var records []*models.DoctorAdvice
  719. // err := readDb.Model(&models.DoctorAdvice{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).Find(&records).Error
  720. err := readDb.
  721. Model(&models.DoctorAdvice{}).
  722. Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? and (advice_type = 2 or advice_type = 3)", patientID, orgID, recordDate).
  723. Select("id,user_org_id,patient_id,advice_type,advice_date,record_date,start_time,advice_name,advice_desc,reminder_date, drug_spec, drug_spec_unit,single_dose,single_dose_unit,prescribing_number,prescribing_number_unit,delivery_way,execution_frequency,advice_doctor,status,created_time,updated_time,advice_affirm,remark,stop_time,stop_reason,stop_doctor,stop_state,parent_id,execution_time,execution_staff,execution_state,checker, check_state, check_time,way,drug_id,drug_name_id,IF(parent_id>0, parent_id, id) as advice_order,groupno,is_medicine").
  724. Order("start_time asc, groupno desc, advice_order desc, id").
  725. Scan(&records).Error
  726. if err != nil {
  727. return nil, err
  728. }
  729. return records, nil
  730. }
  731. func MobileGetDoctorAdvicesByGroups(orgID int64, patientID int64, recordDate int64) ([]*models.DoctorAdvice, error) {
  732. var records []*models.DoctorAdvice
  733. redis := RedisClient()
  734. defer redis.Close()
  735. // cur_date := time.Now().Format("2006-01-02")
  736. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":doctor_advices"
  737. //fmt.Println("key23233232323323wi", key)
  738. redis.Set(key, "", time.Second)
  739. doctor_advices_str, _ := redis.Get(key).Result()
  740. if len(doctor_advices_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  741. err := readDb.Model(&models.DoctorAdvice{}).
  742. Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? and (advice_type = 2 || advice_type = 3)", patientID, orgID, recordDate).
  743. Select("id, user_org_id, patient_id, advice_type, advice_date, record_date, start_time, advice_name,advice_desc, reminder_date, drug_spec, drug_spec_unit, single_dose, single_dose_unit, prescribing_number, prescribing_number_unit, delivery_way, execution_frequency, advice_doctor, status, created_time,updated_time, advice_affirm, remark, stop_time, stop_reason, stop_doctor, stop_state, parent_id, execution_time, execution_staff, execution_state, checker, check_state, check_time, groupno,way,drug_id,is_medicine,drug_name_id, IF(parent_id > 0, parent_id, id) as advice_order").
  744. Order("start_time asc, groupno desc, advice_order desc, id asc").
  745. Scan(&records).Error
  746. if err != nil {
  747. if err == gorm.ErrRecordNotFound {
  748. if len(records) <= 0 {
  749. redis.Set(key, "", time.Second*60*60*18)
  750. }
  751. return nil, nil
  752. } else {
  753. return nil, err
  754. }
  755. } else {
  756. if len(records) > 0 {
  757. //缓存数据
  758. doctor_advices_str, err := json.Marshal(records)
  759. if err == nil {
  760. redis.Set(key, doctor_advices_str, time.Second*60*60*18)
  761. return records, nil
  762. }
  763. } else {
  764. redis.Set(key, "null", time.Second*60*60*18)
  765. return records, nil
  766. }
  767. return records, nil
  768. }
  769. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  770. if doctor_advices_str == "null" {
  771. return records, nil
  772. } else {
  773. json.Unmarshal([]byte(doctor_advices_str), &records)
  774. return records, nil
  775. }
  776. }
  777. }
  778. // 透析记录
  779. func MobileGetSchedualDialysisRecordTen(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  780. var record models.DialysisOrder
  781. err := readDb.Model(&models.DialysisOrder{}).Preload("DeviceNumber", "org_id = ?", orgID).Where("user_org_id = ? AND patient_id = ? AND dialysis_date = ?", orgID, patientID, recordDate).First(&record).Error
  782. if err != nil {
  783. if err == gorm.ErrRecordNotFound {
  784. return nil, nil
  785. } else {
  786. return nil, err
  787. }
  788. }
  789. return &record, nil
  790. }
  791. //func MobileGetSchedualDialysisRecord(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  792. // var record models.DialysisOrder
  793. //
  794. // err := readDb.Model(&models.DialysisOrder{}).Preload("DeviceNumber", "org_id = ? AND status = 1", orgID).Where("user_org_id = ? AND patient_id = ? AND dialysis_date = ?", orgID, patientID, recordDate).First(&record).Error
  795. //
  796. //
  797. // return &record,err
  798. //}
  799. // 透析记录
  800. func MobileGetSchedualDialysisRecord(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  801. var record models.DialysisOrder
  802. redis := RedisClient()
  803. defer redis.Close()
  804. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":dialysis_order"
  805. dialysis_order_str, _ := redis.Get(key).Result()
  806. if len(dialysis_order_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  807. err := readDb.Model(&models.DialysisOrder{}).Preload("DeviceNumber", "org_id = ? AND status = 1", orgID).Where("user_org_id = ? AND patient_id = ? AND dialysis_date = ?", orgID, patientID, recordDate).First(&record).Error
  808. if err != nil {
  809. if err == gorm.ErrRecordNotFound {
  810. return nil, nil
  811. } else {
  812. return nil, err
  813. }
  814. } else {
  815. if record.ID > 0 {
  816. //缓存数据
  817. dialysis_order_str, err := json.Marshal(record)
  818. if err == nil {
  819. redis.Set(key, dialysis_order_str, time.Second*60*60*18)
  820. }
  821. } else {
  822. redis.Set(key, "null", time.Second*60*60*18)
  823. }
  824. return &record, nil
  825. }
  826. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  827. if dialysis_order_str == "null" {
  828. err = readDb.Model(&models.DialysisOrder{}).Preload("DeviceNumber", "org_id = ? AND status = 1", orgID).Where("user_org_id = ? AND patient_id = ? AND dialysis_date = ?", orgID, patientID, recordDate).First(&record).Error
  829. return &record, nil
  830. } else {
  831. json.Unmarshal([]byte(dialysis_order_str), &record)
  832. return &record, nil
  833. }
  834. }
  835. }
  836. // 双人核对
  837. func MobileGetDoubleCheck(orgID int64, patientID int64, recordDate int64) (*models.DoubleCheck, error) {
  838. var record models.DoubleCheck
  839. redis := RedisClient()
  840. defer redis.Close()
  841. // cur_date := time.Now().Format("2006-01-02")
  842. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":double_check"
  843. double_check_str, _ := redis.Get(key).Result()
  844. if len(double_check_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  845. err := readDb.Model(&models.DoubleCheck{}).Where("patient_id = ? and user_org_id = ? and status = 1 and check_date = ?", patientID, orgID, recordDate).First(&record).Error
  846. if err != nil {
  847. if err == gorm.ErrRecordNotFound {
  848. if record.ID <= 0 {
  849. redis.Set(key, "null", time.Second*60*60*18)
  850. }
  851. return nil, nil
  852. } else {
  853. return nil, err
  854. }
  855. } else {
  856. if record.ID > 0 {
  857. //缓存数据
  858. double_check_str, err := json.Marshal(record)
  859. if err == nil {
  860. redis.Set(key, double_check_str, time.Second*60*60*18)
  861. }
  862. } else {
  863. redis.Set(key, "null", time.Second*60*60*18)
  864. }
  865. return &record, nil
  866. }
  867. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  868. if double_check_str == "null" {
  869. return &record, nil
  870. } else {
  871. json.Unmarshal([]byte(double_check_str), &record)
  872. return &record, nil
  873. }
  874. }
  875. }
  876. // 透析监测记录
  877. func MobileGetMonitorRecords(orgID int64, patientID int64, recordDate int64) ([]*models.MonitoringRecord, error) {
  878. var records []*models.MonitoringRecord
  879. redis := RedisClient()
  880. defer redis.Close()
  881. // cur_date := time.Now().Format("2006-01-02")
  882. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":monitor_records"
  883. redis.Set(key, "", time.Second)
  884. monitor_records_str, _ := redis.Get(key).Result()
  885. if len(monitor_records_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  886. err := readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ?", patientID, orgID, recordDate).Order("operate_time asc").Find(&records).Error
  887. if err != nil {
  888. if err == gorm.ErrRecordNotFound {
  889. //if len(records) <= 0 {
  890. // redis.Set(key, "null", time.Second*60*60*18)
  891. //}
  892. return nil, nil
  893. } else {
  894. return nil, err
  895. }
  896. } else {
  897. if len(records) > 0 {
  898. //缓存数据
  899. monitor_records_str, err := json.Marshal(records)
  900. if err == nil {
  901. redis.Set(key, monitor_records_str, time.Second*60*60*18)
  902. }
  903. } else {
  904. redis.Set(key, "null", time.Second*60*60*18)
  905. }
  906. return records, nil
  907. }
  908. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  909. if monitor_records_str == "null" {
  910. return records, nil
  911. } else {
  912. json.Unmarshal([]byte(monitor_records_str), &records)
  913. return records, nil
  914. }
  915. }
  916. }
  917. func MobileGetMonitorRecordFirst(orgID int64, patientID int64, recordDate int64) (*models.MonitoringRecord, error) {
  918. var records models.MonitoringRecord
  919. err := readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ?", patientID, orgID, recordDate).Order("operate_time asc").First(&records).Error
  920. if err != nil {
  921. return nil, err
  922. }
  923. return &records, nil
  924. }
  925. func MobileGetLastMonitorRecordOne(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  926. var record models.MonitoringRecord
  927. err := readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ?", patientID, orgID, beforeDate).Order("operate_time desc").First(&record).Error
  928. if err != nil {
  929. if err == gorm.ErrRecordNotFound {
  930. return nil, nil
  931. } else {
  932. return nil, err
  933. }
  934. }
  935. return &record, nil
  936. }
  937. func MobileGetLastMonitorRecord(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  938. var record models.MonitoringRecord
  939. redis := RedisClient()
  940. defer redis.Close()
  941. // cur_date := time.Now().Format("2006-01-02")
  942. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(beforeDate, 10) + ":monitor_record_last"
  943. monitor_record_last_str, _ := redis.Get(key).Result()
  944. if len(monitor_record_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  945. err := readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ?", patientID, orgID, beforeDate).Order("operate_time desc").First(&record).Error
  946. if err != nil {
  947. if err == gorm.ErrRecordNotFound {
  948. if record.ID <= 0 {
  949. redis.Set(key, "null", time.Second*60*60*18)
  950. }
  951. return nil, nil
  952. } else {
  953. return nil, err
  954. }
  955. } else {
  956. if record.ID > 0 {
  957. //缓存数据
  958. monitor_record_last_str, err := json.Marshal(record)
  959. if err == nil {
  960. redis.Set(key, monitor_record_last_str, time.Second*60*60*18)
  961. }
  962. } else {
  963. redis.Set(key, "null", time.Second*60*60*18)
  964. }
  965. return &record, nil
  966. }
  967. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  968. if monitor_record_last_str == "null" {
  969. return &record, nil
  970. } else {
  971. json.Unmarshal([]byte(monitor_record_last_str), &record)
  972. return &record, nil
  973. }
  974. }
  975. }
  976. func MobileGetAssessmentAfterDislysisOne(orgID int64, patientID int64, recordDate int64) (*models.AssessmentAfterDislysis, error) {
  977. var record models.AssessmentAfterDislysis
  978. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  979. if err != nil {
  980. if err == gorm.ErrRecordNotFound {
  981. return nil, nil
  982. } else {
  983. return nil, err
  984. }
  985. }
  986. return &record, nil
  987. }
  988. // 透后评估
  989. func MobileGetAssessmentAfterDislysis(orgID int64, patientID int64, recordDate int64) (*models.AssessmentAfterDislysis, error) {
  990. var record models.AssessmentAfterDislysis
  991. redis := RedisClient()
  992. defer redis.Close()
  993. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":assessment_after_dislysis"
  994. redis.Set(key, "", time.Second)
  995. assessment_after_dislysis_str, _ := redis.Get(key).Result()
  996. if len(assessment_after_dislysis_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  997. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  998. if err != nil {
  999. if err == gorm.ErrRecordNotFound {
  1000. if record.ID <= 0 {
  1001. redis.Set(key, "null", time.Second*60*60*18)
  1002. }
  1003. return nil, nil
  1004. } else {
  1005. return nil, err
  1006. }
  1007. } else {
  1008. if record.ID > 0 {
  1009. //缓存数据
  1010. assessment_after_dislysis_str, err := json.Marshal(record)
  1011. if err == nil {
  1012. redis.Set(key, assessment_after_dislysis_str, time.Second*60*60*18)
  1013. }
  1014. } else {
  1015. redis.Set(key, "null", time.Second*60*60*18)
  1016. }
  1017. return &record, nil
  1018. }
  1019. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1020. if assessment_after_dislysis_str == "null" {
  1021. return &record, nil
  1022. } else {
  1023. json.Unmarshal([]byte(assessment_after_dislysis_str), &record)
  1024. return &record, nil
  1025. }
  1026. }
  1027. }
  1028. // 获取 maxDate 之前一次的透后评估记录
  1029. func MobileGetLastTimeAssessmentAfterDislysis(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  1030. var record models.AssessmentAfterDislysis
  1031. redis := RedisClient()
  1032. defer redis.Close()
  1033. // cur_date := time.Now().Format("2006-01-02")
  1034. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(maxDate, 10) + ":assessment_after_dislysis_last"
  1035. assessment_after_dislysis_last_str, _ := redis.Get(key).Result()
  1036. if len(assessment_after_dislysis_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1037. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date < ?", patientID, orgID, maxDate).Order("assessment_date desc").First(&record).Error
  1038. if err != nil {
  1039. if err == gorm.ErrRecordNotFound {
  1040. if record.ID <= 0 {
  1041. redis.Set(key, "null", time.Second*60*60*18)
  1042. }
  1043. return nil, nil
  1044. } else {
  1045. return nil, err
  1046. }
  1047. } else {
  1048. if record.ID > 0 {
  1049. //缓存数据
  1050. assessment_after_dislysis_last_str, err := json.Marshal(record)
  1051. if err == nil {
  1052. redis.Set(key, assessment_after_dislysis_last_str, time.Second*60*60*18)
  1053. }
  1054. } else {
  1055. redis.Set(key, "null", time.Second*60*60*18)
  1056. }
  1057. return &record, nil
  1058. }
  1059. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1060. if assessment_after_dislysis_last_str == "null" {
  1061. return &record, nil
  1062. } else {
  1063. json.Unmarshal([]byte(assessment_after_dislysis_last_str), &record)
  1064. return &record, nil
  1065. }
  1066. }
  1067. }
  1068. func MobileGetLastTimeAssessmentAfterDislysisOne(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  1069. var record models.AssessmentAfterDislysis
  1070. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date < ?", patientID, orgID, maxDate).Order("assessment_date desc").First(&record).Error
  1071. if err != nil {
  1072. if err == gorm.ErrRecordNotFound {
  1073. return nil, nil
  1074. } else {
  1075. return nil, err
  1076. }
  1077. }
  1078. return &record, nil
  1079. }
  1080. func MobileGetLast(orgID int64, patientID int64, maxDate int64) (models.AssessmentAfterDislysis, error) {
  1081. dislysis := models.AssessmentAfterDislysis{}
  1082. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date < ?", patientID, orgID, maxDate).Order("assessment_date desc").First(&dislysis).Error
  1083. return dislysis, err
  1084. }
  1085. // 治疗小结
  1086. func MobileGetTreatmentSummary(orgID int64, patientID int64, recordDate int64) (*models.TreatmentSummary, error) {
  1087. var record models.TreatmentSummary
  1088. redis := RedisClient()
  1089. defer redis.Close()
  1090. // cur_date := time.Now().Format("2006-01-02")
  1091. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":treatment_summary"
  1092. treatment_summary_str, _ := redis.Get(key).Result()
  1093. if len(treatment_summary_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1094. err := readDb.Model(&models.TreatmentSummary{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  1095. if err != nil {
  1096. if err == gorm.ErrRecordNotFound {
  1097. if record.ID <= 0 {
  1098. redis.Set(key, "null", time.Second*60*60*18)
  1099. }
  1100. return nil, nil
  1101. } else {
  1102. return nil, err
  1103. }
  1104. } else {
  1105. if record.ID > 0 {
  1106. //缓存数据
  1107. treatment_summary_str, err := json.Marshal(record)
  1108. if err == nil {
  1109. redis.Set(key, treatment_summary_str, time.Second*60*60*18)
  1110. }
  1111. } else {
  1112. redis.Set(key, "null", time.Second*60*60*18)
  1113. }
  1114. return &record, nil
  1115. }
  1116. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1117. if treatment_summary_str == "null" {
  1118. return &record, nil
  1119. } else {
  1120. json.Unmarshal([]byte(treatment_summary_str), &record)
  1121. return &record, nil
  1122. }
  1123. }
  1124. }
  1125. // 透析处方
  1126. func MobileGetDialysisPrescribe(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  1127. var record models.DialysisPrescription
  1128. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).Find(&record).Error
  1129. if err != nil {
  1130. if err == gorm.ErrRecordNotFound {
  1131. return nil, nil
  1132. } else {
  1133. return nil, err
  1134. }
  1135. }
  1136. return &record, nil
  1137. }
  1138. func MobileGetDialysisSchedual(orgID int64, patientID int64, scheduleDate int64) (*models.XtSchedule, error) {
  1139. var schedule models.XtSchedule
  1140. err := readDb.Model(&models.XtSchedule{}).Where("patient_id = ? and user_org_id = ? and status = 1 and schedule_date = ?", patientID, orgID, scheduleDate).First(&schedule).Error
  1141. if err != nil {
  1142. if err == gorm.ErrRecordNotFound {
  1143. return nil, nil
  1144. } else {
  1145. return nil, err
  1146. }
  1147. }
  1148. return &schedule, nil
  1149. }
  1150. // 透析方案
  1151. func MobileGetDialysisSolution(orgID int64, patientID int64) (*models.DialysisSolution, error) {
  1152. var record models.DialysisSolution
  1153. err := readDb.Model(&models.DialysisSolution{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  1154. if err != nil {
  1155. if err == gorm.ErrRecordNotFound {
  1156. return nil, nil
  1157. } else {
  1158. return nil, err
  1159. }
  1160. }
  1161. return &record, nil
  1162. }
  1163. func MobileGetPatientById(orgID int64, patientID int64) (*models.Patients, error) {
  1164. var patient models.Patients
  1165. err := readDb.Model(&models.Patients{}).Where("id = ? and user_org_id = ? and status = 1", patientID, orgID).First(&patient).Error
  1166. if err != nil {
  1167. if err == gorm.ErrRecordNotFound {
  1168. return nil, nil
  1169. } else {
  1170. return nil, err
  1171. }
  1172. }
  1173. return &patient, nil
  1174. }
  1175. func DisableMonitor(orgID int64, patientID int64, recordID int64, admin_user_id int64) error {
  1176. fmt.Println()
  1177. tx := writeDb.Begin()
  1178. updateTime := time.Now().Unix()
  1179. err := tx.Model(&models.MonitoringRecord{}).Where("user_org_id = ? AND patient_id = ? AND id = ? AND status = 1 ", orgID, patientID, recordID).Updates(map[string]interface{}{"status": 0, "updated_time": updateTime, "modify": admin_user_id}).Error
  1180. if err != nil {
  1181. tx.Rollback()
  1182. return err
  1183. }
  1184. tx.Commit()
  1185. return nil
  1186. }
  1187. func GetMonitor(orgID int64, patientID int64, id int64) (*models.MonitoringRecord, error) {
  1188. var monitor models.MonitoringRecord
  1189. var err error
  1190. err = readDb.Model(&models.MonitoringRecord{}).Where("id = ? AND user_org_id = ? AND patient_id = ? AND status = 1 ", id, orgID, patientID).Find(&monitor).Error
  1191. if err == gorm.ErrRecordNotFound {
  1192. return nil, nil
  1193. }
  1194. if err != nil {
  1195. return nil, err
  1196. }
  1197. return &monitor, nil
  1198. }
  1199. type MScheduleDoctorAdviceVM struct {
  1200. ID int64 `gorm:"column:id" json:"id"`
  1201. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  1202. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  1203. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  1204. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1205. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  1206. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  1207. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  1208. Status int64 `gorm:"column:status" json:"status"`
  1209. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  1210. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  1211. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  1212. DoctorAdvices []*MDoctorAdviceVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  1213. Prescription *models.DialysisPrescriptionTwenty `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  1214. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  1215. }
  1216. func (MScheduleDoctorAdviceVM) TableName() string {
  1217. return "xt_schedule"
  1218. }
  1219. type MScheduleDoctorAdviceVMOne struct {
  1220. ID int64 `gorm:"column:id" json:"id"`
  1221. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  1222. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  1223. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  1224. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1225. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  1226. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  1227. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  1228. Status int64 `gorm:"column:status" json:"status"`
  1229. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  1230. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  1231. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  1232. DoctorAdvices []*MDoctorAdviceVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  1233. Prescription *models.DialysisPrescriptionTwenty `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  1234. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  1235. }
  1236. func (MScheduleDoctorAdviceVMOne) TableName() string {
  1237. return "xt_schedule"
  1238. }
  1239. type MDoctorAdviceVM struct {
  1240. ID int64 `gorm:"column:id" json:"id"`
  1241. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  1242. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1243. AdviceType int64 `gorm:"column:advice_type" json:"advice_type"`
  1244. AdviceDate int64 `gorm:"column:advice_date" json:"advice_date"`
  1245. StartTime int64 `gorm:"column:start_time" json:"start_time"`
  1246. AdviceName string `gorm:"column:advice_name" json:"advice_name"`
  1247. AdviceDesc string `gorm:"column:advice_desc" json:"advice_desc"`
  1248. ReminderDate int64 `gorm:"column:reminder_date" json:"reminder_date"`
  1249. SingleDose float64 `gorm:"column:single_dose" json:"single_dose"`
  1250. SingleDoseUnit string `gorm:"column:single_dose_unit" json:"single_dose_unit"`
  1251. PrescribingNumber float64 `gorm:"column:prescribing_number" json:"prescribing_number"`
  1252. PrescribingNumberUnit string `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit"`
  1253. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way"`
  1254. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency"`
  1255. AdviceDoctor int64 `gorm:"column:advice_doctor" json:"advice_doctor"`
  1256. Status int64 `gorm:"column:status" json:"status"`
  1257. CreatedTime int64 `gorm:"column:created_time" json:"created_time"`
  1258. UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time"`
  1259. AdviceAffirm string `gorm:"column:advice_affirm" json:"advice_affirm"`
  1260. Remark string `gorm:"column:remark" json:"remark"`
  1261. StopTime int64 `gorm:"column:stop_time" json:"stop_time"`
  1262. StopReason string `gorm:"column:stop_reason" json:"stop_reason"`
  1263. StopDoctor int64 `gorm:"column:stop_doctor" json:"stop_doctor"`
  1264. StopState int64 `gorm:"column:stop_state" json:"stop_state"`
  1265. ParentId int64 `gorm:"column:parent_id" json:"parent_id"`
  1266. ExecutionTime int64 `gorm:"column:execution_time" json:"execution_time"`
  1267. ExecutionStaff int64 `gorm:"column:execution_staff" json:"execution_staff"`
  1268. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state"`
  1269. Checker int64 `gorm:"column:checker" json:"checker"`
  1270. RecordDate int64 `gorm:"column:record_date" json:"record_date"`
  1271. DialysisOrderId int64 `gorm:"column:dialysis_order_id" json:"dialysis_order_id"`
  1272. CheckTime int64 `gorm:"column:check_time" json:"check_time"`
  1273. CheckState int64 `gorm:"column:check_state" json:"check_state"`
  1274. DrugSpec float64 `gorm:"column:drug_spec" json:"drug_spec"`
  1275. DrugSpecUnit string `gorm:"column:drug_spec_unit" json:"drug_spec_unit"`
  1276. Groupno int64 `gorm:"column:groupno" json:"groupno"`
  1277. RemindType int64 `gorm:"column:remind_type" json:"remind_type"`
  1278. FrequencyType int64 `gorm:"column:frequency_type" json:"frequency_type"`
  1279. DayCount int64 `gorm:"column:day_count" json:"day_count"`
  1280. WeekDay string `gorm:"column:week_day" json:"week_day"`
  1281. TemplateId string `gorm:"column:template_id" json:"template_id"`
  1282. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1283. IsMedicine int64 `gorm:"column:is_medicine" json:"is_medicine" form:"is_medicine"`
  1284. IsSettle int64 `gorm:"column:is_settle" json:"is_settle" form:"is_settle"`
  1285. }
  1286. func (MDoctorAdviceVM) TableName() string {
  1287. return "xt_doctor_advice"
  1288. }
  1289. func MobileGetScheduleDoctorAdvices(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string) ([]*MScheduleDoctorAdviceVM, error) {
  1290. var vms []*MScheduleDoctorAdviceVM
  1291. adviceWhere := ""
  1292. adviceCondition := []interface{}{}
  1293. if adviceType == 0 {
  1294. if patientType == 0 {
  1295. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  1296. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1297. } else if patientType == 1 {
  1298. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  1299. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1300. } else if patientType == 2 {
  1301. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  1302. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1303. }
  1304. } else if adviceType == 1 {
  1305. if patientType == 0 {
  1306. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  1307. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1308. } else if patientType == 1 {
  1309. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  1310. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1311. } else if patientType == 2 {
  1312. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  1313. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1314. }
  1315. } else if adviceType == 3 {
  1316. if patientType == 0 {
  1317. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  1318. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1319. } else if patientType == 1 {
  1320. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  1321. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1322. } else if patientType == 2 {
  1323. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  1324. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1325. }
  1326. } else if adviceType == 2 && len(deliverWay) > 0 {
  1327. if patientType == 0 {
  1328. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  1329. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1330. } else if patientType == 1 {
  1331. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  1332. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  1333. } else if patientType == 2 {
  1334. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  1335. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1336. }
  1337. } else if adviceType == 2 && len(deliverWay) <= 0 {
  1338. if patientType == 0 {
  1339. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  1340. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1341. } else if patientType == 1 {
  1342. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND (advice_doctor = ? or execution_staff = ?)"
  1343. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, adminUserId)
  1344. } else if patientType == 2 {
  1345. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  1346. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1347. }
  1348. }
  1349. db := readDb.
  1350. Table("xt_schedule").
  1351. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1352. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1353. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1354. }).
  1355. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1356. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1357. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1358. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  1359. Preload("DoctorAdvices", adviceCondition...).
  1360. Where("status = 1 AND user_org_id = ?", orgID)
  1361. if scheduleDate != 0 {
  1362. db = db.Where("schedule_date = ?", scheduleDate)
  1363. }
  1364. err := db.Find(&vms).Error
  1365. return vms, err
  1366. }
  1367. func MobileGetScheduleDoctorAdvicesTwo(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string) ([]*MScheduleDoctorAdviceVMOne, error) {
  1368. var vms []*MScheduleDoctorAdviceVMOne
  1369. adviceWhere := ""
  1370. adviceCondition := []interface{}{}
  1371. if adviceType == 0 {
  1372. if patientType == 0 {
  1373. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  1374. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1375. } else if patientType == 1 {
  1376. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  1377. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1378. } else if patientType == 2 {
  1379. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  1380. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1381. } else if patientType == 3 {
  1382. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1) and is_settle = 1"
  1383. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1384. } else if patientType == 4 {
  1385. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1) and (is_settle = 0 or is_settle = 2)"
  1386. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1387. }
  1388. } else if adviceType == 1 {
  1389. if patientType == 0 {
  1390. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  1391. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1392. } else if patientType == 1 {
  1393. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  1394. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1395. } else if patientType == 2 {
  1396. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  1397. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1398. } else if patientType == 3 {
  1399. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = 1"
  1400. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1401. } else if patientType == 4 {
  1402. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and (is_settle = 0 or is_settle = 2)"
  1403. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1404. }
  1405. } else if adviceType == 3 {
  1406. if patientType == 0 {
  1407. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  1408. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1409. } else if patientType == 1 {
  1410. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  1411. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1412. } else if patientType == 2 {
  1413. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  1414. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1415. } else if patientType == 3 {
  1416. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 and is_settle = 1"
  1417. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1418. } else if patientType == 4 {
  1419. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 and (is_settle = 0 or is_settle = 2)"
  1420. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1421. }
  1422. } else if adviceType == 2 && len(deliverWay) > 0 {
  1423. if patientType == 0 {
  1424. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  1425. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1426. } else if patientType == 1 {
  1427. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  1428. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  1429. } else if patientType == 2 {
  1430. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  1431. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1432. } else if patientType == 3 {
  1433. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 and delivery_way = ? and is_settle = 1"
  1434. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1435. } else if patientType == 4 {
  1436. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 and delivery_way = ? and (is_settle = 0 or is_settle =2)"
  1437. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1438. }
  1439. } else if adviceType == 2 && len(deliverWay) <= 0 {
  1440. if patientType == 0 {
  1441. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  1442. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1443. } else if patientType == 1 {
  1444. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND (advice_doctor = ? or execution_staff = ?)"
  1445. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, adminUserId)
  1446. } else if patientType == 2 {
  1447. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  1448. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1449. } else if patientType == 3 {
  1450. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 and is_settle = 1"
  1451. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1452. } else if patientType == 4 {
  1453. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 and (is_settle = 0 or is_settle = 2)"
  1454. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1455. }
  1456. }
  1457. db := readDb.
  1458. Table("xt_schedule").
  1459. //Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1460. //Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1461. // return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1462. //}).
  1463. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1464. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1465. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1466. Preload("DoctorAdvices", adviceCondition...).
  1467. Where("status = 1 AND user_org_id = ?", orgID)
  1468. if scheduleDate != 0 {
  1469. db = db.Where("schedule_date = ?", scheduleDate)
  1470. }
  1471. err := db.Find(&vms).Error
  1472. return vms, err
  1473. }
  1474. func GetHisDoctorAdvices(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleDoctorAdviceVM, error) {
  1475. var vms []*HisMScheduleDoctorAdviceVM
  1476. if len(deliverWay) > 0 {
  1477. if patientType == 0 {
  1478. db := readDb.
  1479. Table("xt_schedule").
  1480. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  1481. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1482. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1483. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1484. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1485. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1486. }).
  1487. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1488. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1489. Where("status = 1 AND user_org_id = ?", orgID)
  1490. if scheduleDate != 0 {
  1491. db = db.Where("schedule_date = ?", scheduleDate)
  1492. }
  1493. err = db.Find(&vms).Error
  1494. }
  1495. if patientType > 0 {
  1496. db := readDb.
  1497. Table("xt_schedule").
  1498. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1499. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1500. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, deliverWay, adminUserId, adminUserId).
  1501. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1502. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1503. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1504. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1505. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1506. }).Where("status = 1 AND user_org_id = ?", orgID)
  1507. if scheduleDate != 0 {
  1508. db = db.Where("schedule_date = ?", scheduleDate)
  1509. }
  1510. err = db.Find(&vms).Error
  1511. }
  1512. } else {
  1513. if patientType == 0 {
  1514. db := readDb.
  1515. Table("xt_schedule").
  1516. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? ", orgID, scheduleDate).
  1517. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1518. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1519. return db.Where("status = 1 AND user_org_id = ? and dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1520. }).
  1521. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1522. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1523. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1524. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1525. Where("status = 1 AND user_org_id = ?", orgID)
  1526. if scheduleDate != 0 {
  1527. db = db.Where("schedule_date = ?", scheduleDate)
  1528. }
  1529. err = db.Find(&vms).Error
  1530. }
  1531. if patientType > 0 {
  1532. db := readDb.
  1533. Table("xt_schedule").
  1534. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1535. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1536. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1537. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1538. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1539. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1540. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1541. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1542. Where("status = 1 AND user_org_id = ?", orgID)
  1543. if scheduleDate != 0 {
  1544. db = db.Where("schedule_date = ?", scheduleDate)
  1545. }
  1546. err = db.Find(&vms).Error
  1547. }
  1548. }
  1549. return vms, err
  1550. }
  1551. func GetHisDoctorAdvicesTwo(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleDoctorAdviceVMOne, error) {
  1552. var vms []*HisMScheduleDoctorAdviceVMOne
  1553. if len(deliverWay) > 0 {
  1554. if patientType == 0 {
  1555. db := readDb.
  1556. Table("xt_schedule").
  1557. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  1558. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1559. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1560. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1561. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1562. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1563. }).
  1564. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1565. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1566. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1567. Where("status = 1 AND user_org_id = ?", orgID)
  1568. if scheduleDate != 0 {
  1569. db = db.Where("schedule_date = ?", scheduleDate)
  1570. }
  1571. err = db.Find(&vms).Error
  1572. }
  1573. if patientType > 0 {
  1574. if patientType == 1 {
  1575. db := readDb.
  1576. Table("xt_schedule").
  1577. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1578. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1579. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, deliverWay, adminUserId, adminUserId).
  1580. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1581. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1582. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1583. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1584. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1585. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1586. Where("status = 1 AND user_org_id = ?", orgID)
  1587. if scheduleDate != 0 {
  1588. db = db.Where("schedule_date = ?", scheduleDate)
  1589. }
  1590. err = db.Find(&vms).Error
  1591. }
  1592. if patientType == 2 {
  1593. db := readDb.
  1594. Table("xt_schedule").
  1595. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1596. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1597. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and (advice_doctor = ? or execution_staff = ?)", orgID, scheduleDate, deliverWay, adminUserId, adminUserId).
  1598. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1599. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1600. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1601. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1602. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1603. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Where("status = 1 AND user_org_id = ?", orgID)
  1604. if scheduleDate != 0 {
  1605. db = db.Where("schedule_date = ?", scheduleDate)
  1606. }
  1607. err = db.Find(&vms).Error
  1608. }
  1609. if patientType == 3 {
  1610. db := readDb.
  1611. Table("xt_schedule").
  1612. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1613. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1614. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and (advice_doctor = ? or execution_staff = ?) and is_settle = 1", orgID, scheduleDate, deliverWay, adminUserId, adminUserId).
  1615. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1616. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1617. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1618. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1619. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1620. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Where("status = 1 AND user_org_id = ?", orgID)
  1621. if scheduleDate != 0 {
  1622. db = db.Where("schedule_date = ?", scheduleDate)
  1623. }
  1624. err = db.Find(&vms).Error
  1625. }
  1626. if patientType == 4 {
  1627. db := readDb.
  1628. Table("xt_schedule").
  1629. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1630. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1631. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and (advice_doctor = ? or execution_staff = ?) and (is_settle = 0 or is_settle = 2)", orgID, scheduleDate, deliverWay, adminUserId, adminUserId).
  1632. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1633. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1634. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1635. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1636. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1637. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Where("status = 1 AND user_org_id = ?", orgID)
  1638. if scheduleDate != 0 {
  1639. db = db.Where("schedule_date = ?", scheduleDate)
  1640. }
  1641. err = db.Find(&vms).Error
  1642. }
  1643. }
  1644. } else {
  1645. if patientType == 0 {
  1646. db := readDb.
  1647. Table("xt_schedule").
  1648. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? ", orgID, scheduleDate).
  1649. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1650. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1651. return db.Where("status = 1 AND user_org_id = ? and dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1652. }).
  1653. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1654. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1655. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1656. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1657. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1658. Where("status = 1 AND user_org_id = ?", orgID)
  1659. if scheduleDate != 0 {
  1660. db = db.Where("schedule_date = ?", scheduleDate)
  1661. }
  1662. err = db.Find(&vms).Error
  1663. }
  1664. if patientType > 0 {
  1665. if patientType == 1 {
  1666. db := readDb.
  1667. Table("xt_schedule").
  1668. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1669. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1670. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1671. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1672. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1673. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1674. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1675. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1676. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1677. Where("status = 1 AND user_org_id = ?", orgID)
  1678. if scheduleDate != 0 {
  1679. db = db.Where("schedule_date = ?", scheduleDate)
  1680. }
  1681. err = db.Find(&vms).Error
  1682. }
  1683. if patientType == 2 {
  1684. db := readDb.
  1685. Table("xt_schedule").
  1686. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1687. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1688. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1689. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1690. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1691. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1692. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1693. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1694. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1695. Where("status = 1 AND user_org_id = ?", orgID)
  1696. if scheduleDate != 0 {
  1697. db = db.Where("schedule_date = ?", scheduleDate)
  1698. }
  1699. err = db.Find(&vms).Error
  1700. }
  1701. if patientType == 3 {
  1702. db := readDb.
  1703. Table("xt_schedule").
  1704. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1705. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) and is_settle = 1", orgID, scheduleDate, adminUserId, adminUserId).
  1706. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1707. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1708. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1709. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1710. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1711. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1712. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1713. Where("status = 1 AND user_org_id = ?", orgID)
  1714. if scheduleDate != 0 {
  1715. db = db.Where("schedule_date = ?", scheduleDate)
  1716. }
  1717. err = db.Find(&vms).Error
  1718. }
  1719. if patientType == 4 {
  1720. db := readDb.
  1721. Table("xt_schedule").
  1722. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1723. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) and (is_settle = 0 or is_settle =2) ", orgID, scheduleDate, adminUserId, adminUserId).
  1724. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1725. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1726. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1727. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1728. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1729. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1730. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1731. Where("status = 1 AND user_org_id = ?", orgID)
  1732. if scheduleDate != 0 {
  1733. db = db.Where("schedule_date = ?", scheduleDate)
  1734. }
  1735. err = db.Find(&vms).Error
  1736. }
  1737. }
  1738. }
  1739. return vms, err
  1740. }
  1741. func GetMobileHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleProjectVM, error) {
  1742. var vms []*HisMScheduleProjectVM
  1743. //if patientType == 0 {
  1744. // db := readDb.
  1745. // Table("xt_schedule").
  1746. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1747. // Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1748. // return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1749. // }).
  1750. // Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1751. // Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1752. // Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1753. // Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1754. // return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1755. // }).
  1756. // Where("status = 1 AND user_org_id = ?", orgID)
  1757. // if scheduleDate != 0 {
  1758. // db = db.Where("schedule_date = ?", scheduleDate)
  1759. // }
  1760. // err = db.Find(&vms).Error
  1761. //}
  1762. //if patientType > 0 {
  1763. // db := readDb.
  1764. // Table("xt_schedule").
  1765. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1766. // Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1767. // return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1768. // }).
  1769. // Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1770. // Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1771. // Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1772. // Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1773. // Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1774. // return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1775. // }).
  1776. // Where("status = 1 AND user_org_id = ?", orgID)
  1777. // if scheduleDate != 0 {
  1778. // db = db.Where("schedule_date = ?", scheduleDate)
  1779. // }
  1780. // err = db.Find(&vms).Error
  1781. //}
  1782. db := readDb.Table("xt_schedule").Where("status = 1")
  1783. if orgID > 0 {
  1784. db = db.Where("user_org_id = ?", orgID)
  1785. }
  1786. if scheduleDate > 0 {
  1787. db = db.Where("schedule_date =?", scheduleDate)
  1788. }
  1789. err = db.Find(&vms).Error
  1790. if patientType == 0 {
  1791. db := readDb.
  1792. Table("xt_schedule").
  1793. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1794. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1795. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1796. }).
  1797. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1798. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1799. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1800. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1801. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1802. }).
  1803. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  1804. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  1805. }).
  1806. Where("status = 1 AND user_org_id = ?", orgID)
  1807. if scheduleDate != 0 {
  1808. db = db.Where("schedule_date = ?", scheduleDate)
  1809. }
  1810. err = db.Find(&vms).Error
  1811. }
  1812. if patientType > 0 {
  1813. db := readDb.
  1814. Table("xt_schedule").
  1815. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1816. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1817. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1818. }).
  1819. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1820. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1821. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1822. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1823. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1824. }).
  1825. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  1826. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  1827. }).
  1828. Where("status = 1 AND user_org_id = ?", orgID)
  1829. if scheduleDate != 0 {
  1830. db = db.Where("schedule_date = ?", scheduleDate)
  1831. }
  1832. err = db.Find(&vms).Error
  1833. }
  1834. return vms, err
  1835. }
  1836. func MobileCreateDialysisOrder(orgID int64, patientID int64, order *models.DialysisOrder) error {
  1837. now := time.Now()
  1838. tx := writeDb.Begin()
  1839. if createOrderErr := tx.Model(&models.DialysisOrder{}).Create(order).Error; createOrderErr != nil {
  1840. tx.Rollback()
  1841. return createOrderErr
  1842. }
  1843. // 更新透析记录 ID
  1844. // 透析处方
  1845. if err := tx.Model(&models.DialysisPrescription{}).Where("user_org_id = ? AND patient_id = ? AND record_date = ? AND status = 1", orgID, patientID, order.DialysisDate).Updates(map[string]interface{}{"record_id": order.ID, "updated_time": now.Unix()}).Error; err != nil {
  1846. tx.Rollback()
  1847. return err
  1848. }
  1849. // 接诊评估
  1850. if err := tx.Model(&models.ReceiveTreatmentAsses{}).Where("user_org_id = ? AND patient_id = ? AND record_date = ? AND status = 1", orgID, patientID, order.DialysisDate).Updates(map[string]interface{}{"record_id": order.ID, "update_time": now.Unix()}).Error; err != nil {
  1851. tx.Rollback()
  1852. return err
  1853. }
  1854. // 透前评估
  1855. if err := tx.Model(&models.PredialysisEvaluation{}).Where("user_org_id = ? AND patient_id = ? AND assessment_date = ? AND status = 1", orgID, patientID, order.DialysisDate).Updates(map[string]interface{}{"dialysis_order_id": order.ID, "updated_time": now.Unix()}).Error; err != nil {
  1856. tx.Rollback()
  1857. return err
  1858. }
  1859. // 临时医嘱
  1860. if err := tx.Model(&models.DoctorAdvice{}).Where("user_org_id = ? AND patient_id = ? AND record_date = ? AND status = 1 AND advice_type = 2", orgID, patientID, order.DialysisDate).Updates(map[string]interface{}{"dialysis_order_id": order.ID, "updated_time": now.Unix()}).Error; err != nil {
  1861. tx.Rollback()
  1862. return err
  1863. }
  1864. // 双人核对
  1865. if err := tx.Model(&models.DoubleCheck{}).Where("user_org_id = ? AND patient_id = ? AND check_date = ? AND status = 1", orgID, patientID, order.DialysisDate).Updates(map[string]interface{}{"dialysis_order_id": order.ID, "updated_time": now.Unix()}).Error; err != nil {
  1866. tx.Rollback()
  1867. return err
  1868. }
  1869. // 透后评估
  1870. if err := tx.Model(&models.AssessmentAfterDislysis{}).Where("user_org_id = ? AND patient_id = ? AND assessment_date = ? AND status = 1", orgID, patientID, order.DialysisDate).Updates(map[string]interface{}{"dialysis_order_id": order.ID, "updated_time": now.Unix()}).Error; err != nil {
  1871. tx.Rollback()
  1872. return err
  1873. }
  1874. // 治疗小结
  1875. if err := tx.Model(&models.TreatmentSummary{}).Where("user_org_id = ? AND patient_id = ? AND assessment_date = ? AND status = 1", orgID, patientID, order.DialysisDate).Updates(map[string]interface{}{"dialysis_order_id": order.ID, "updated_time": now.Unix()}).Error; err != nil {
  1876. tx.Rollback()
  1877. return err
  1878. }
  1879. // 透析监测
  1880. if err := tx.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id=? and status=1 and monitoring_date = ?", patientID, orgID, order.DialysisDate).Update(map[string]interface{}{"dialysis_order_id": order.ID, "updated_time": now.Unix()}).Error; err != nil {
  1881. tx.Rollback()
  1882. return err
  1883. }
  1884. tx.Commit()
  1885. return nil
  1886. }
  1887. type MobileUrgentSchedulePatientVM struct {
  1888. ID int64 `gorm:"column:id" json:"id"`
  1889. Name string `gorm:"column:name" json:"name"`
  1890. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no"`
  1891. }
  1892. func (MobileUrgentSchedulePatientVM) TableName() string {
  1893. return "xt_patients"
  1894. }
  1895. type MobileUrgentScheduleTreatmentModeVM struct {
  1896. ID int64 `gorm:"column:id" json:"id"`
  1897. Name string `gorm:"column:name" json:"name"`
  1898. }
  1899. func (MobileUrgentScheduleTreatmentModeVM) TableName() string {
  1900. return "xt_treatment_mode"
  1901. }
  1902. func MobileGetAllPatientsForUrgentSchedule(orgID int64, record_date int64) ([]*MobileUrgentSchedulePatientVM, error) {
  1903. var vms []*MobileUrgentSchedulePatientVM = make([]*MobileUrgentSchedulePatientVM, 0)
  1904. rows, err := readDb.Raw("SELECT p.* FROM xt_patients as p WHERE (p.user_org_id = ? AND p.status = 1 AND p.lapseto = 1) AND NOT EXISTS (Select * FROM `xt_dialysis_order` as d Where d.`dialysis_date` = ? AND d.`status` = 1 AND d.`patient_id` = p.id AND d.user_org_id = p.user_org_id )", orgID, record_date).Rows()
  1905. defer rows.Close()
  1906. if err != nil {
  1907. return nil, err
  1908. }
  1909. for rows.Next() {
  1910. var vm MobileUrgentSchedulePatientVM
  1911. readDb.ScanRows(rows, &vm)
  1912. vms = append(vms, &vm)
  1913. }
  1914. return vms, nil
  1915. }
  1916. func MobileGetAllTrearmentModesForUrgentSchedule() ([]*MobileUrgentScheduleTreatmentModeVM, error) {
  1917. var modes []*MobileUrgentScheduleTreatmentModeVM
  1918. err := readDb.Model(&MobileUrgentScheduleTreatmentModeVM{}).Where("status = 1").Find(&modes).Error
  1919. if err != nil {
  1920. return nil, err
  1921. }
  1922. return modes, nil
  1923. }
  1924. type MobileUrgentScheduleScheduleListVM struct {
  1925. ID int64 `gorm:"column:id" json:"id"`
  1926. // ZoneID int64 `gorm:"column:partition_id" json:"zone_id"`
  1927. DeviceNumberID int64 `gorm:"column:bed_id" json:"bed_id"`
  1928. PatientID int64 `gorm:"column:patient_id" json:"patient_id"`
  1929. ScheduleType int `gorm:"column:schedule_type" json:"schedule_type"`
  1930. DeviceNumber *models.DeviceNumber `gorm:"ForeignKey:DeviceNumberID" json:"device_number"`
  1931. // DeviceZone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"device_zone"`
  1932. }
  1933. func (MobileUrgentScheduleScheduleListVM) TableName() string {
  1934. return "xt_schedule"
  1935. }
  1936. func MobileGetSchedulesForUrgentSchedule(orgID int64, scheduleDate int64, schedule_type int) (schedules []*MobileUrgentScheduleScheduleListVM, err error) {
  1937. db := readDb.
  1938. Model(&MobileUrgentScheduleScheduleListVM{}).
  1939. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1940. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND schedule_type = ? ", orgID, scheduleDate, schedule_type)
  1941. err = db.Find(&schedules).Error
  1942. if err != nil {
  1943. return nil, err
  1944. }
  1945. return schedules, nil
  1946. }
  1947. func MobileGetOtherSchedulesForUrgentSchedule(orgID int64, scheduleDate int64, schedule_type int) ([]*MobileUrgentScheduleScheduleListVM, error) {
  1948. var vms []*MobileUrgentScheduleScheduleListVM = make([]*MobileUrgentScheduleScheduleListVM, 0)
  1949. rows, err := readDb.Raw("SELECT * FROM xt_schedule as s WHERE s.user_org_id = ? AND s.status = 1 AND s.schedule_date = ? ", orgID, scheduleDate).Rows()
  1950. defer rows.Close()
  1951. if err != nil {
  1952. return nil, err
  1953. }
  1954. for rows.Next() {
  1955. var vm MobileUrgentScheduleScheduleListVM
  1956. readDb.ScanRows(rows, &vm)
  1957. vms = append(vms, &vm)
  1958. }
  1959. return vms, nil
  1960. }
  1961. type MobileUrgentScheduleDeviceNumberVM struct {
  1962. ID int64 `gorm:"column:id" json:"id"`
  1963. Number string `gorm:"column:number" json:"number"`
  1964. ZoneID int64 `gorm:"column:zone_id" json:"zone_id"`
  1965. Zone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"zone"`
  1966. }
  1967. func (MobileUrgentScheduleDeviceNumberVM) TableName() string {
  1968. return "xt_device_number"
  1969. }
  1970. func MobileGetAllDeviceNumbersForUrgentSchedule(orgID int64, record_date int64, schedule_type int) ([]*DeviceNumberViewModel, error) {
  1971. var vms []*DeviceNumberViewModel = make([]*DeviceNumberViewModel, 0)
  1972. rows, err := readDb.Raw("SELECT n.*, z.name as zone_name, g.name as group_name FROM xt_device_number as n join xt_device_zone as z on z.id = n.zone_id join xt_device_group as g on g.id = n.group_id WHERE (n.org_id = ? AND n.status = 1) AND NOT EXISTS (Select * FROM xt_schedule as s Where s.`schedule_date` = ? AND s.user_org_id = n.org_id AND s.`bed_id` = n.id AND s.`schedule_type` = ? AND s.status = 1 )", orgID, record_date, schedule_type).Rows()
  1973. defer rows.Close()
  1974. if err != nil {
  1975. return nil, err
  1976. }
  1977. for rows.Next() {
  1978. var vm DeviceNumberViewModel
  1979. readDb.ScanRows(rows, &vm)
  1980. vms = append(vms, &vm)
  1981. }
  1982. return vms, nil
  1983. //var deviceNumbers []*MobileUrgentScheduleDeviceNumberVM
  1984. //db := readDb.
  1985. // Model(&MobileUrgentScheduleDeviceNumberVM{}).
  1986. // Preload("Zone", "status = 1 AND org_id = ?", orgID).
  1987. // Where("status = 1 AND org_id = ?", orgID)
  1988. //err := db.Order("zone_id asc").Find(&deviceNumbers).Error
  1989. //if err != nil {
  1990. // return nil, err
  1991. //}
  1992. //return deviceNumbers, nil
  1993. }
  1994. func GetValidScheduleMonitorRecordCount() (int64, error) {
  1995. var total int64
  1996. err := readDb.Model(&models.MonitoringRecord{}).Where("status = 1 AND operate_time = 0 AND monitoring_date <> 0").Count(&total).Error
  1997. return total, err
  1998. }
  1999. func GetTop1000ValidScheduleMonitorRecord() ([]*models.MonitoringRecord, error) {
  2000. var monitors []*models.MonitoringRecord
  2001. err := readDb.Model(&models.MonitoringRecord{}).Where("status = 1 AND operate_time = 0 AND monitoring_date <> 0").Order("id asc").Limit(100).Find(&monitors).Error
  2002. if err != nil {
  2003. return nil, err
  2004. }
  2005. return monitors, nil
  2006. }
  2007. func BatchUpdateMonitors(monitors []*models.MonitoringRecord) error {
  2008. tx := writeDb.Begin()
  2009. for index := 0; index < len(monitors); index++ {
  2010. tx.Save(monitors[index])
  2011. }
  2012. return tx.Commit().Error
  2013. }
  2014. func ModifyStartDialysisOrder(order *models.DialysisOrder) error {
  2015. tx := writeDb.Begin()
  2016. updateTime := time.Now().Unix()
  2017. err := tx.Model(&models.DialysisOrder{}).Where("user_org_id = ? AND id = ? AND status = 1 ", order.UserOrgId, order.ID).Updates(map[string]interface{}{"start_nurse": order.StartNurse, "updated_time": updateTime, "bed_id": order.BedID, "puncture_nurse": order.PunctureNurse, "start_time": order.StartTime, "modifier": order.Modifier, "schedual_type": order.SchedualType, "washpipe_nurse": order.WashpipeNurse, "change_nurse": order.ChangeNurse, "difficult_puncture_nurse": order.DifficultPunctureNurse, "new_fistula_nurse": order.NewFistulaNurse, "quality_nurse_id": order.QualityNurseId, "puncture_needle": order.PunctureNeedle, "puncture_way": order.PunctureWay, "dialysis_dialyszers": order.DialysisDialyszers, "dialysis_irrigation": order.DialysisIrrigation, "blood_access_id": order.BloodAccessId, "nuclein_date": order.NucleinDate, "schedule_remark": order.ScheduleRemark, "order_remark": order.OrderRemark, "catheter_operation": order.CatheterOperation}).Error
  2018. if err != nil {
  2019. tx.Rollback()
  2020. return err
  2021. }
  2022. tx.Commit()
  2023. return err
  2024. }
  2025. func ModifyFinishDialysisOrder(order *models.DialysisOrder) error {
  2026. tx := writeDb.Begin()
  2027. updateTime := time.Now().Unix()
  2028. err := tx.Model(&models.DialysisOrder{}).Where("user_org_id = ? AND id = ? AND status = 1 ", order.UserOrgId, order.ID).Updates(map[string]interface{}{"finish_nurse": order.FinishNurse, "updated_time": updateTime, "end_time": order.EndTime, "finish_modifier": order.FinishModifier, "puncture_point_haematoma": order.PuncturePointHaematoma, "blood_access_internal_fistula": order.BloodAccessInternalFistula, "catheter": order.Catheter, "cruor": order.Cruor, "mission": order.Mission}).Error
  2029. if err != nil {
  2030. tx.Rollback()
  2031. return err
  2032. }
  2033. tx.Commit()
  2034. return err
  2035. }
  2036. func MobileGetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  2037. var record models.SgjPatientDryweight
  2038. err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  2039. if err != nil {
  2040. if err == gorm.ErrRecordNotFound {
  2041. return nil, nil
  2042. } else {
  2043. return nil, err
  2044. }
  2045. }
  2046. return &record, nil
  2047. }
  2048. //func MobileGetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  2049. // var record models.SgjPatientDryweight
  2050. // redis := RedisClient()
  2051. // defer redis.Close()
  2052. //
  2053. // key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":last_dry_weight"
  2054. // last_dry_weight_str, _ := redis.Get(key).Result()
  2055. //
  2056. // if len(last_dry_weight_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2057. // err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  2058. // if err != nil {
  2059. // if err == gorm.ErrRecordNotFound {
  2060. // if record.ID <= 0 {
  2061. // redis.Set(key, "null", time.Second*60*60*18)
  2062. // }
  2063. // return nil, nil
  2064. // } else {
  2065. // return nil, err
  2066. // }
  2067. // } else {
  2068. // if record.ID > 0 {
  2069. // //缓存数据
  2070. // last_dry_weight_str, err := json.Marshal(record)
  2071. // if err == nil {
  2072. // redis.Set(key, last_dry_weight_str, time.Second*60*60*18)
  2073. // return nil, err
  2074. // }
  2075. // } else {
  2076. // redis.Set(key, "null", time.Second*60*60*18)
  2077. // return nil, err
  2078. // }
  2079. // return &record, nil
  2080. // }
  2081. // } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2082. // if last_dry_weight_str == "null" {
  2083. // return &record, nil
  2084. // } else {
  2085. // json.Unmarshal([]byte(last_dry_weight_str), &record)
  2086. // return &record, nil
  2087. // }
  2088. //
  2089. // }
  2090. //}
  2091. // 透析方案
  2092. func MobileGetDialysisSolutionByModeIdSix(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  2093. var record models.DialysisSolution
  2094. err := readDb.Model(&models.DialysisSolution{}).Where("patient_id = ? and user_org_id = ? and status = 1 AND mode_id = ?", patientID, orgID, mode_id).Last(&record).Error
  2095. if err != nil {
  2096. if err == gorm.ErrRecordNotFound {
  2097. return nil, nil
  2098. } else {
  2099. return nil, err
  2100. }
  2101. }
  2102. return &record, nil
  2103. }
  2104. // 透析方案
  2105. func MobileGetDialysisSolutionByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  2106. var record models.DialysisSolution
  2107. redis := RedisClient()
  2108. defer redis.Close()
  2109. // cur_date := time.Now().Format("2006-01-02")
  2110. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2111. dialysis_solution_str, _ := redis.Get(key).Result()
  2112. if len(dialysis_solution_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2113. err := readDb.Model(&models.DialysisSolution{}).Where("patient_id = ? and user_org_id = ? and status = 1 AND mode_id = ?", patientID, orgID, mode_id).Last(&record).Error
  2114. if err != nil {
  2115. if err == gorm.ErrRecordNotFound {
  2116. if record.ID <= 0 {
  2117. redis.Set(key, "null", time.Second*60*60*18)
  2118. }
  2119. return nil, nil
  2120. } else {
  2121. return nil, err
  2122. }
  2123. } else {
  2124. if record.ID > 0 {
  2125. //缓存数据
  2126. dialysis_solution_str, err := json.Marshal(record)
  2127. if err == nil {
  2128. redis.Set(key, dialysis_solution_str, time.Second*60*60*18)
  2129. }
  2130. } else {
  2131. redis.Set(key, "null", time.Second*60*60*18)
  2132. }
  2133. return &record, nil
  2134. }
  2135. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2136. if dialysis_solution_str == "null" {
  2137. return &record, nil
  2138. } else {
  2139. json.Unmarshal([]byte(dialysis_solution_str), &record)
  2140. return &record, nil
  2141. }
  2142. }
  2143. }
  2144. // 透析处方
  2145. func MobileGetDialysisPrescribeByModeId(orgID int64, patientID int64, recordDate int64, mode_id int64) (*models.DialysisPrescription, error) {
  2146. var record models.DialysisPrescription
  2147. redis := RedisClient()
  2148. defer redis.Close()
  2149. // cur_date := time.Now().Format("2006-01-02")
  2150. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2151. redis.Set(key, "", time.Second)
  2152. dialysis_prescribe_str, _ := redis.Get(key).Result()
  2153. if len(dialysis_prescribe_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2154. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? AND mode_id = ?", patientID, orgID, recordDate, mode_id).First(&record).Error
  2155. if err != nil {
  2156. if err == gorm.ErrRecordNotFound {
  2157. if record.ID <= 0 {
  2158. redis.Set(key, "null", time.Second*60*60*18)
  2159. }
  2160. return nil, nil
  2161. } else {
  2162. return nil, err
  2163. }
  2164. } else {
  2165. if record.ID > 0 {
  2166. //缓存数据
  2167. dialysis_prescribe_str, err := json.Marshal(record)
  2168. if err == nil {
  2169. redis.Set(key, dialysis_prescribe_str, time.Second*60*60*18)
  2170. }
  2171. } else {
  2172. redis.Set(key, "null", time.Second*60*60*18)
  2173. }
  2174. return &record, nil
  2175. }
  2176. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2177. if dialysis_prescribe_str == "null" {
  2178. return &record, nil
  2179. } else {
  2180. json.Unmarshal([]byte(dialysis_prescribe_str), &record)
  2181. return &record, nil
  2182. }
  2183. }
  2184. }
  2185. func MobileGetDialysisPrescribeByModeIdSix(orgID int64, patientID int64, recordDate int64, mode_id int64) (*models.DialysisPrescription, error) {
  2186. var record models.DialysisPrescription
  2187. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? AND mode_id = ?", patientID, orgID, recordDate, mode_id).First(&record).Error
  2188. if err != nil {
  2189. if err == gorm.ErrRecordNotFound {
  2190. return nil, nil
  2191. } else {
  2192. return nil, err
  2193. }
  2194. }
  2195. return &record, nil
  2196. }
  2197. func MobileGetDialysisPrescribeByModeIdOne(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  2198. var record models.DialysisPrescription
  2199. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  2200. if err != nil {
  2201. if err == gorm.ErrRecordNotFound {
  2202. return nil, nil
  2203. } else {
  2204. return nil, err
  2205. }
  2206. }
  2207. return &record, nil
  2208. }
  2209. //func MobileGetDialysisPrescribeByModeIdOne(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  2210. // var record models.DialysisPrescription
  2211. // redis := RedisClient()
  2212. // defer redis.Close()
  2213. //
  2214. // // cur_date := time.Now().Format("2006-01-02")
  2215. // key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":dialysis_prescribe_by_mode"
  2216. // dialysis_prescribe_by_mode_str, _ := redis.Get(key).Result()
  2217. //
  2218. // if len(dialysis_prescribe_by_mode_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2219. // err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  2220. // if err != nil {
  2221. // if err == gorm.ErrRecordNotFound {
  2222. // if record.ID <= 0 {
  2223. // redis.Set(key, "null", time.Second*60*60*18)
  2224. // }
  2225. // return nil, nil
  2226. // } else {
  2227. // return nil, err
  2228. // }
  2229. // } else {
  2230. //
  2231. // if record.ID > 0 {
  2232. // //缓存数据
  2233. // dialysis_prescribe_by_mode_str, err := json.Marshal(record)
  2234. //
  2235. // if err == nil {
  2236. // redis.Set(key, dialysis_prescribe_by_mode_str, time.Second*60*60*18)
  2237. // return nil, err
  2238. // }
  2239. // } else {
  2240. // redis.Set(key, "null", time.Second*60*60*18)
  2241. // return nil, err
  2242. // }
  2243. // return &record, nil
  2244. // }
  2245. // } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2246. // if dialysis_prescribe_by_mode_str == "null" {
  2247. // json.Unmarshal([]byte(dialysis_prescribe_by_mode_str), &record)
  2248. // return &record, nil
  2249. // } else {
  2250. // json.Unmarshal([]byte(dialysis_prescribe_by_mode_str), &record)
  2251. // return &record, nil
  2252. // }
  2253. //
  2254. // }
  2255. //}
  2256. func MobileGetLastDialysisPrescribe(orgID int64, patientID int64) (*models.DialysisPrescription, error) {
  2257. var record models.DialysisPrescription
  2258. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 ", patientID, orgID).Last(&record).Error
  2259. if err != nil {
  2260. if err == gorm.ErrRecordNotFound {
  2261. return nil, nil
  2262. } else {
  2263. return nil, err
  2264. }
  2265. }
  2266. return &record, nil
  2267. }
  2268. func MobileGetLastDialysisPrescribeByModeIdSix(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2269. var record models.DialysisPrescription
  2270. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 AND mode_id = ?", patientID, orgID, mode_id).Last(&record).Error
  2271. //if err != nil {
  2272. // if err == gorm.ErrRecordNotFound {
  2273. // return nil, nil
  2274. // } else {
  2275. // return nil, err
  2276. // }
  2277. //}
  2278. return &record, err
  2279. }
  2280. func MobileGetLastDialysisPrescribeByModeIdTen(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2281. var record models.DialysisPrescription
  2282. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 AND mode_id = ?", patientID, orgID, mode_id).Last(&record).Error
  2283. if err != nil {
  2284. if err == gorm.ErrRecordNotFound {
  2285. return nil, nil
  2286. } else {
  2287. return nil, err
  2288. }
  2289. }
  2290. return &record, err
  2291. }
  2292. func MobileGetLastDialysisPrescribeByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2293. var record models.DialysisPrescription
  2294. redis := RedisClient()
  2295. defer redis.Close()
  2296. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  2297. dialysis_prescribe_by_mode_id, _ := redis.Get(key).Result()
  2298. if len(dialysis_prescribe_by_mode_id) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2299. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and mode_id = ?", patientID, orgID, mode_id).Last(&record).Error
  2300. if err != nil {
  2301. if err == gorm.ErrRecordNotFound {
  2302. if record.ID <= 0 {
  2303. redis.Set(key, "null", time.Second*60*60*18)
  2304. }
  2305. return nil, nil
  2306. } else {
  2307. return nil, err
  2308. }
  2309. } else {
  2310. if record.ID > 0 {
  2311. //缓存数据
  2312. dialysis_prescribe_by_mode_str, err := json.Marshal(record)
  2313. if err == nil {
  2314. redis.Set(key, dialysis_prescribe_by_mode_str, time.Second*60*60*18)
  2315. return nil, err
  2316. }
  2317. } else {
  2318. redis.Set(key, "null", time.Second*60*60*18)
  2319. return nil, err
  2320. }
  2321. return &record, nil
  2322. }
  2323. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2324. if dialysis_prescribe_by_mode_id == "null" {
  2325. return &record, nil
  2326. } else {
  2327. json.Unmarshal([]byte(dialysis_prescribe_by_mode_id), &record)
  2328. return &record, nil
  2329. }
  2330. }
  2331. }
  2332. func MobileGetLastDialysisPrescribeByModeIdOne(orgID int64, patientID int64, mode_id int64) (models.DialysisPrescription, error) {
  2333. var record models.DialysisPrescription
  2334. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and mode_id = ?", patientID, orgID, mode_id).Last(&record).Error
  2335. return record, err
  2336. }
  2337. func GetAllAvaildDeviceNumbers(orgID int64, record_date int64, schedule_type int) ([]*DeviceNumberViewModel, error) {
  2338. var vms []*DeviceNumberViewModel = make([]*DeviceNumberViewModel, 0)
  2339. rows, err := readDb.Raw("SELECT n.*, z.name as zone_name, g.name as group_name FROM xt_device_number as n join xt_device_zone as z on z.id = n.zone_id join xt_device_group as g on g.id = n.group_id WHERE (n.org_id = ? AND n.status = 1) AND NOT EXISTS (Select * FROM xt_schedule as s Where s.`schedule_date` = ? AND s.user_org_id = n.org_id AND s.`bed_id` = n.id AND s.`schedule_type` = ? AND s.status = 1 )", orgID, record_date, schedule_type).Rows()
  2340. defer rows.Close()
  2341. if err != nil {
  2342. return nil, err
  2343. }
  2344. for rows.Next() {
  2345. var vm DeviceNumberViewModel
  2346. readDb.ScanRows(rows, &vm)
  2347. vms = append(vms, &vm)
  2348. }
  2349. return vms, nil
  2350. }
  2351. // 获取 maxDate 之前一次的透前评估记录
  2352. func GetLastTimePredialysisEvaluation(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
  2353. var record models.PredialysisEvaluation
  2354. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date < ?", patientID, orgID, maxDate).Order("assessment_date desc").First(&record).Error
  2355. if err != nil {
  2356. if err == gorm.ErrRecordNotFound {
  2357. return nil, nil
  2358. } else {
  2359. return nil, err
  2360. }
  2361. }
  2362. return &record, nil
  2363. }
  2364. func GetLastTimeOrder(orgID int64, patientID int64, maxDate int64) (*models.DialysisOrder, error) {
  2365. var record models.DialysisOrder
  2366. err := readDb.Model(&models.DialysisOrder{}).Where("patient_id = ? and user_org_id = ? and status = 1 and dialysis_date < ?", patientID, orgID, maxDate).Order("dialysis_date desc").First(&record).Error
  2367. if err != nil {
  2368. if err == gorm.ErrRecordNotFound {
  2369. return nil, nil
  2370. } else {
  2371. return nil, err
  2372. }
  2373. }
  2374. return &record, nil
  2375. }
  2376. func GetLastMonitorRecord(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  2377. var record models.MonitoringRecord
  2378. err := readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ?", patientID, orgID, beforeDate).Order("operate_time desc").First(&record).Error
  2379. if err != nil {
  2380. if err == gorm.ErrRecordNotFound {
  2381. return nil, nil
  2382. } else {
  2383. return nil, err
  2384. }
  2385. }
  2386. return &record, nil
  2387. }
  2388. // 获取 maxDate 之前一次的透后评估记录
  2389. func GetLastTimeAssessmentAfterDislysis(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  2390. var record models.AssessmentAfterDislysis
  2391. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date < ?", patientID, orgID, maxDate).Order("assessment_date desc").First(&record).Error
  2392. if err != nil {
  2393. if err == gorm.ErrRecordNotFound {
  2394. return nil, nil
  2395. } else {
  2396. return nil, err
  2397. }
  2398. }
  2399. return &record, nil
  2400. }
  2401. // 透析处方
  2402. func GetDialysisPrescribe(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  2403. var record models.DialysisPrescription
  2404. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  2405. if err != nil {
  2406. if err == gorm.ErrRecordNotFound {
  2407. return nil, nil
  2408. } else {
  2409. return nil, err
  2410. }
  2411. }
  2412. return &record, nil
  2413. }
  2414. // 透析方案
  2415. func GetDialysisSolution(orgID int64, patientID int64, mode_id int64) (models.DialysisSolution, error) {
  2416. var record models.DialysisSolution
  2417. err := readDb.Model(&models.DialysisSolution{}).Where("patient_id = ? and user_org_id = ? and status = 1 AND mode_id = ?", patientID, orgID, mode_id).Last(&record).Error
  2418. return record, err
  2419. }
  2420. func GetDialysisSolutionOne(orgID int64, mode_id int64) (*models.DialysisSolution, error) {
  2421. var record models.DialysisSolution
  2422. err := readDb.Model(&models.DialysisSolution{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2423. if err != nil {
  2424. if err == gorm.ErrRecordNotFound {
  2425. return nil, nil
  2426. } else {
  2427. return nil, err
  2428. }
  2429. }
  2430. return &record, nil
  2431. }
  2432. func GetLastDialysisPrescribeByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2433. var record models.DialysisPrescription
  2434. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 AND mode_id = ?", patientID, orgID, mode_id).Last(&record).Error
  2435. if err != nil {
  2436. if err == gorm.ErrRecordNotFound {
  2437. return nil, nil
  2438. } else {
  2439. return nil, err
  2440. }
  2441. }
  2442. return &record, nil
  2443. }
  2444. func GetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  2445. var record models.SgjPatientDryweight
  2446. err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  2447. if err != nil {
  2448. if err == gorm.ErrRecordNotFound {
  2449. return nil, nil
  2450. } else {
  2451. return nil, err
  2452. }
  2453. }
  2454. return &record, nil
  2455. }
  2456. func MobileGetSystemDialysisPrescribeByModeIdSix(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2457. var record models.SystemPrescription
  2458. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).First(&record).Error
  2459. if err != nil {
  2460. if err == gorm.ErrRecordNotFound {
  2461. return nil, nil
  2462. } else {
  2463. return nil, err
  2464. }
  2465. }
  2466. return &record, nil
  2467. }
  2468. func MobileGetSystemDialysisPrescribeByModeId(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2469. var record models.SystemPrescription
  2470. redis := RedisClient()
  2471. defer redis.Close()
  2472. // cur_date := time.Now().Format("2006-01-02")
  2473. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  2474. system_dialysis_prescribe_str, _ := redis.Get(key).Result()
  2475. if len(system_dialysis_prescribe_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2476. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2477. if err != nil {
  2478. if err == gorm.ErrRecordNotFound {
  2479. if record.ID <= 0 {
  2480. redis.Set(key, "null", time.Second*60*60*18)
  2481. }
  2482. return nil, nil
  2483. } else {
  2484. return nil, err
  2485. }
  2486. } else {
  2487. if record.ID > 0 {
  2488. //缓存数据
  2489. system_dialysis_prescribe_str, err := json.Marshal(record)
  2490. if err == nil {
  2491. redis.Set(key, system_dialysis_prescribe_str, time.Second*60*60*18)
  2492. }
  2493. } else {
  2494. redis.Set(key, "null", time.Second*60*60*18)
  2495. }
  2496. return &record, nil
  2497. }
  2498. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2499. if system_dialysis_prescribe_str == "null" {
  2500. return &record, nil
  2501. } else {
  2502. json.Unmarshal([]byte(system_dialysis_prescribe_str), &record)
  2503. return &record, nil
  2504. }
  2505. }
  2506. }
  2507. func MobileGetSystemDialysisPrescribeByModeIdOne(orgID int64, mode_id int64) (models.SystemPrescription, error) {
  2508. var record models.SystemPrescription
  2509. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2510. return record, err
  2511. }
  2512. func GetSystemDialysisPrescribeByModeId(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2513. var record models.SystemPrescription
  2514. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2515. if err != nil {
  2516. if err == gorm.ErrRecordNotFound {
  2517. return nil, nil
  2518. } else {
  2519. return nil, err
  2520. }
  2521. }
  2522. return &record, nil
  2523. }
  2524. func GetDialysisOrderCount(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2525. err = readDb.Model(&models.DialysisOrder{}).Where("dialysis_date <= ? AND status = 1 AND stage = 2 AND user_org_id = ? AND patient_id = ?", recordDate, orgID, patient_id).Count(&count).Error
  2526. return
  2527. }
  2528. func GetDialysisOrderCountOne(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2529. err = readDb.Model(&models.DialysisOrder{}).Where("dialysis_date>=1640966400 and dialysis_date <= ? AND status = 1 AND stage = 2 AND user_org_id = ? AND patient_id = ?", recordDate, orgID, patient_id).Count(&count).Error
  2530. return
  2531. }
  2532. func GetDialysisOrderCountTwo(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2533. err = readDb.Model(&models.DialysisOrder{}).Where("dialysis_date>=1672502400 and dialysis_date <= ? AND status = 1 AND stage = 2 AND user_org_id = ? AND patient_id = ?", recordDate, orgID, patient_id).Count(&count).Error
  2534. return
  2535. }
  2536. func GetFirstDateOfMonth(d time.Time) time.Time {
  2537. d = d.AddDate(0, 0, -d.Day()+1)
  2538. return GetZeroTime(d)
  2539. }
  2540. func GetZeroTime(d time.Time) time.Time {
  2541. return time.Date(d.Year(), d.Month(), d.Day(), 0, 0, 0, 0, d.Location())
  2542. }
  2543. func GetDialysisCountByPatientId(startime int64, endtime int64, patientid int64, orgid int64) (order []*models.BloodDialysisOrderCount, err error) {
  2544. db := XTReadDB().Table("xt_dialysis_order as o")
  2545. err = db.Raw("select count(o.id) as count,o.patient_id from xt_dialysis_order as o left join xt_schedule AS x ON x.patient_id = o.patient_id where o.status = 1 and o.dialysis_date>=? and o.dialysis_date<=? and o.user_org_id = ? and x.schedule_date = o.dialysis_date and x.status = 1 and o.patient_id = ?", startime, endtime, orgid, patientid).Scan(&order).Group("o.patient_id").Error
  2546. return order, err
  2547. }
  2548. func FindConsumablesByDate(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error) {
  2549. err = readDb.Model(&models.DialysisBeforePrepare{}).Where("user_org_id = ? AND patient_id = ? AND record_date = ? AND status = 1 AND count<>0", orgID, patient_id, recordDate).Find(&consumables).Error
  2550. return
  2551. }
  2552. func FindConsumablesByDateTwo(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error) {
  2553. err = readDb.Model(&models.DialysisBeforePrepare{}).Where("user_org_id = ? AND patient_id = ? AND record_date = ? AND status = 1 AND count > 0", orgID, patient_id, recordDate).Find(&consumables).Error
  2554. return
  2555. }
  2556. func FindConsumablesByDateThree(orgID int64, patient_id int64, recordDate int64) (consumables []*models.BloodAutomaticReduceDetail, err error) {
  2557. err = readDb.Model(&models.BloodAutomaticReduceDetail{}).Where("org_id = ? AND patient_id = ? AND record_time = ? AND status = 1 AND count > 0", orgID, patient_id, recordDate).Find(&consumables).Error
  2558. return
  2559. }
  2560. //func FindLastConsumables(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error){
  2561. // err = readDb.Model(&models.DialysisBeforePrepare{}).Where("user_org_id = ? AND patient_id = ? AND record_date = ? AND status = 1", orgID, patient_id,recordDate).Find(&consumables).Error
  2562. // return
  2563. //}
  2564. //
  2565. func GetLastTimeConsumables(orgID int64, patientID int64, maxDate int64) (prepare []*models.DialysisBeforePrepare, err error) {
  2566. err = readDb.Model(&models.DialysisBeforePrepare{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date < ?", patientID, orgID, maxDate).Order("record_date desc").Find(&prepare).Error
  2567. return
  2568. }
  2569. type GoodsType struct {
  2570. ID int64 `gorm:"column:id" json:"id"`
  2571. TypeName string `gorm:"column:type_name" json:"type_name"`
  2572. Remark string `gorm:"column:remark" json:"remark"`
  2573. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2574. Status int64 `gorm:"column:status" json:"status"`
  2575. Type int64 `gorm:"column:type" json:"type"`
  2576. }
  2577. func (GoodsType) TableName() string {
  2578. return "xt_goods_type"
  2579. }
  2580. type VMGoodInfo struct {
  2581. ID int64 `gorm:"column:id" json:"id"`
  2582. SpecificationName string `gorm:"column:specification_name" json:"specification_name"`
  2583. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2584. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2585. GoodName string `gorm:"column:good_name" json:"good_name" form:"good_name"`
  2586. GoodUnit int64 `gorm:"column:good_unit" json:"good_unit" form:"good_unit"`
  2587. Total float64 `gorm:"column:total" json:"total" form:"total"`
  2588. PackingUnit string `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
  2589. MedicalInsuranceNumber string `gorm:"column:medical_insurance_number" json:"medical_insurance_number" form:"medical_insurance_number"`
  2590. }
  2591. func (VMGoodInfo) TableName() string {
  2592. return "xt_good_information"
  2593. }
  2594. type AutomaticReduceDetail struct {
  2595. ID int64 `gorm:"column:id" json:"id"`
  2596. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2597. Status int64 `gorm:"column:status" json:"status"`
  2598. RecordTime int64 `gorm:"column:record_time" json:"record_time"`
  2599. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2600. GoodId int64 `gorm:"column:good_id" json:"good_id"`
  2601. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2602. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"info"`
  2603. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"type"`
  2604. Count int64 `gorm:"column:count" json:"count"`
  2605. }
  2606. func (AutomaticReduceDetail) TableName() string {
  2607. return "xt_automatic_reduce_detail"
  2608. }
  2609. type DialysisBeforePrepare struct {
  2610. ID int64 `gorm:"column:id" json:"id" form:"id"`
  2611. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  2612. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  2613. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  2614. GoodId int64 `gorm:"column:good_id" json:"good_id" form:"good_id"`
  2615. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id" form:"good_type_id"`
  2616. Count int64 `gorm:"column:count" json:"count" form:"count"`
  2617. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  2618. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  2619. Creater int64 `gorm:"column:creater" json:"creater" form:"creater"`
  2620. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  2621. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"info"`
  2622. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"type"`
  2623. }
  2624. func (DialysisBeforePrepare) TableName() string {
  2625. return "dialysis_before_prepare"
  2626. }
  2627. type MDialysisGoodsVM struct {
  2628. ID int64 `gorm:"column:id" json:"id"`
  2629. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2630. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2631. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2632. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2633. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2634. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2635. ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week"`
  2636. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2637. Status int64 `gorm:"column:status" json:"status"`
  2638. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2639. SchedualPatient *MSchedualPatientVMList `gorm:"ForeignKey:PatientId" json:"patient"`
  2640. AutomaticReduceDetail []*AutomaticReduceDetail `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"good_user"`
  2641. LastAutomaticReduceDetail []*AutomaticReduceDetail `gorm:"-" json:"last_good_user"`
  2642. DialysisBeforePrepare []*DialysisBeforePrepare `gorm:"ForeignKey:PatientId,ScheduleDate;AssociationForeignKey:PatientId,RecordDate" json:"good_user_detail"`
  2643. LastDialysisBeforePrepare []*DialysisBeforePrepare `gorm:"-" json:"last_good_user_detail"`
  2644. Project []*models.HisPrescriptionProject `gorm:"-" json:"project"`
  2645. //WarehouseOutInfo []*models.WarehouseOutInfoSeven `gorm:"ForeignKey:PatientId,ScheduleDate;AssociationForeignKey:PatientId,SysRecordTime" json:"ware_house_out_info"`
  2646. }
  2647. func (MDialysisGoodsVM) TableName() string {
  2648. return "xt_schedule"
  2649. }
  2650. type VMWarehouseOutInfo struct {
  2651. ID int64 `gorm:"column:id" json:"id"`
  2652. WarehouseOutId int64 `gorm:"column:warehouse_out_id" json:"warehouse_out_id"`
  2653. GoodId int64 `gorm:"column:good_id" json:"good_id"`
  2654. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2655. Count int64 `gorm:"column:count" json:"count"`
  2656. Price float64 `gorm:"column:price" json:"price"`
  2657. TotalPrice float64 `gorm:"column:total_price" json:"total_price"`
  2658. Status int64 `gorm:"column:status" json:"status"`
  2659. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2660. WarehouseOutOrderNumber string `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number"`
  2661. GoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"good_info"`
  2662. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"good_type"`
  2663. IsSys int64 `gorm:"column:is_sys" json:"is_sys"`
  2664. SysRecordTime int64 `gorm:"column:sys_record_time" json:"sys_record_time"`
  2665. Mtime int64 `gorm:"column:mtime" json:"mtime"`
  2666. Ctime int64 `gorm:"column:ctime" json:"ctime"`
  2667. }
  2668. func (VMWarehouseOutInfo) TableName() string {
  2669. return "xt_warehouse_out_info"
  2670. }
  2671. type DialysisGoodsDate struct {
  2672. RecordDate int64
  2673. }
  2674. type DialysisGoodsDetailDate struct {
  2675. RecordTime int64
  2676. }
  2677. func MobileGetDialysisGoods(orgID int64, scheduleDate int64, schedule_type int64, partition_id int64, page int, limit int, patient_id int64, keywords string, end_time int64) ([]*MDialysisGoodsVM, error, int64) {
  2678. var vms []*MDialysisGoodsVM
  2679. var total int64
  2680. db := readDb.
  2681. Table("xt_schedule as sch").
  2682. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  2683. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2684. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2685. Preload("DialysisBeforePrepare", func(db *gorm.DB) *gorm.DB {
  2686. return db.Preload("VMGoodInfo", "status = 1 AND org_id = ? and find_in_set('停用',good_status) = 0", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0) ", orgID).Where("status = 1 AND user_org_id = ? AND record_date = ? AND count > 0 ", orgID, scheduleDate)
  2687. }).
  2688. Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
  2689. return db.Preload("VMGoodInfo", "status = 1 AND org_id = ? and find_in_set('停用',good_status) = 0", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0) ", orgID).Where("status = 1 AND org_id = ? AND count > 0 AND record_time >= ? AND record_time <= ? ", orgID, scheduleDate, end_time).Group("patient_id,good_id")
  2690. }).Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
  2691. if scheduleDate != 0 {
  2692. db = db.Where("schedule_date = ?", scheduleDate)
  2693. }
  2694. if schedule_type != 0 {
  2695. db = db.Where("schedule_type = ?", schedule_type)
  2696. }
  2697. if partition_id != 0 {
  2698. db = db.Where("partition_id = ?", partition_id)
  2699. }
  2700. if patient_id != 0 {
  2701. db = db.Where("patient_id = ?", patient_id)
  2702. }
  2703. err := db.Find(&vms).Error
  2704. return vms, err, total
  2705. }
  2706. func GetLastDialysisGoods(patient_id int64, orgID int64, record_time int64) (goodUser []*AutomaticReduceDetail, err error) {
  2707. var Id []*DialysisGoodsDetailDate
  2708. err = readDb.Model(&AutomaticReduceDetail{}).Where("patient_id = ? AND org_id = ? AND status=1 AND record_time < ? AND count > 0", patient_id, orgID, record_time).Select("record_time").Group("record_time").Order("record_time asc").Scan(&Id).Error
  2709. if len(Id) > 0 {
  2710. err = readDb.Model(&AutomaticReduceDetail{}).Where("patient_id = ? AND org_id = ? AND status=1 AND record_time = ? AND count > 0", patient_id, orgID, Id[len(Id)-1].RecordTime).Preload("VMGoodInfo", "status = 1 AND org_id = ? and find_in_set('停用',good_status) = 0", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0) ", orgID).Find(&goodUser).Error
  2711. }
  2712. return
  2713. }
  2714. func GetLastDialysisBeforePrepare(patient_id int64, orgID int64, record_time int64) (goodUser []*DialysisBeforePrepare, err error) {
  2715. var Id []*DialysisGoodsDate
  2716. err = readDb.Model(&models.DialysisBeforePrepare{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date < ? AND count > 0", patient_id, orgID, record_time).Select("record_date").Group("record_date").Order("record_date asc").Scan(&Id).Error
  2717. if len(Id) > 0 {
  2718. err = readDb.Model(&models.DialysisBeforePrepare{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date = ? AND count > 0", patient_id, orgID, Id[len(Id)-1].RecordDate).Preload("VMGoodInfo", "status = 1 AND org_id = ? and find_in_set('停用',good_status) = 0", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0) ", orgID).Find(&goodUser).Error
  2719. }
  2720. return
  2721. }
  2722. func GetAllWarehouseOutSumList(patient_id int64, orgID int64, record_time int64) (info []*models.WarehouseOutInfoSeven, err error) {
  2723. err = XTReadDB().Where("patient_id = ? and org_id = ? and sys_record_time = ? and status = 1", patient_id, orgID, record_time).Find(&info).Error
  2724. return info, err
  2725. }
  2726. func MobileGetGoodsStatistics(orgID int64, start_time int64, end_time int64) (list []*models.StockInfo, err error) {
  2727. db := readDb.Model(&models.StockInfo{})
  2728. db = db.Where("xt_good_information.org_id = ? AND xt_good_information.status = 1", orgID)
  2729. db = db.Joins("JOIN xt_warehouse_out_info AS info ON info.good_id=xt_good_information.id AND info.status = 1 AND info.org_id = ?", orgID).Group("xt_good_information.id")
  2730. db = db.Preload("QueryWarehouseOutInfo", func(db *gorm.DB) *gorm.DB {
  2731. return db.Where("xt_warehouse_out_info.org_id = ? AND xt_warehouse_out_info.status = 1 AND xt_warehouse_out_info.sys_record_time >= ? AND xt_warehouse_out_info.sys_record_time <= ?", orgID, start_time, end_time)
  2732. })
  2733. db = db.Preload("GoodsType", "org_id = ? AND status = 1", orgID)
  2734. err = db.Order("ctime desc").Find(&list).Error
  2735. return
  2736. }
  2737. func PCGetDialysisGoods(orgID int64, scheduleDate int64, schedule_type int64, partition_id int64, page int, limit int, patient_id int64, keywords string, end_time int64, good_type int64, ids []int64) ([]*MDialysisGoodsVM, error, int64) {
  2738. var vms []*MDialysisGoodsVM
  2739. var total int64
  2740. db := readDb.
  2741. Model(&models.Schedule{}).
  2742. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  2743. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2744. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2745. Preload("DialysisBeforePrepare", func(db *gorm.DB) *gorm.DB {
  2746. return db.Preload("VMGoodInfo", "status = 1 AND org_id = ? ", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0) ", orgID).Where("status = 1 AND user_org_id = ? AND record_date = ? AND count > 0 ", orgID, scheduleDate)
  2747. }).Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
  2748. return db.Preload("VMGoodInfo", "status = 1 AND org_id = ? ", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0) ", orgID).Where("status = 1 AND org_id = ? AND record_time >= ? AND record_time <=? AND count > 0", orgID, scheduleDate, end_time)
  2749. }).Where("xt_schedule.status = 1 AND xt_schedule.user_org_id = ?", orgID)
  2750. if scheduleDate != 0 {
  2751. db = db.Where("schedule_date = ?", scheduleDate)
  2752. }
  2753. if patient_id != 0 {
  2754. db = db.Where("patient_id = ?", patient_id)
  2755. }
  2756. if len(keywords) != 0 {
  2757. keywords = "%" + keywords + "%"
  2758. db = db.Joins("JOIN xt_patients AS patient ON patient.id=xt_schedule.patient_id AND patient.status = 1 AND patient.user_org_id = ? AND patient.name Like ?", orgID, keywords)
  2759. if schedule_type != 0 {
  2760. db = db.Where("schedule_type = ?", schedule_type)
  2761. }
  2762. if partition_id != 0 {
  2763. db = db.Where("partition_id = ?", partition_id)
  2764. }
  2765. if good_type == 1 {
  2766. db = db.Where("patient_id in(?)", ids)
  2767. }
  2768. if good_type == 2 {
  2769. if len(ids) > 0 {
  2770. db = db.Where("patient_id not in(?)", ids)
  2771. }
  2772. }
  2773. } else {
  2774. if schedule_type != 0 {
  2775. db = db.Where("schedule_type = ?", schedule_type)
  2776. }
  2777. if partition_id != 0 {
  2778. db = db.Where("partition_id = ?", partition_id)
  2779. }
  2780. if good_type == 1 {
  2781. db = db.Where("patient_id in(?)", ids)
  2782. }
  2783. if good_type == 2 {
  2784. if len(ids) > 0 {
  2785. db = db.Where("patient_id not in(?)", ids)
  2786. }
  2787. }
  2788. db = db.Count(&total)
  2789. offset := (page - 1) * limit
  2790. db = db.Offset(offset).Limit(limit)
  2791. }
  2792. err := db.Find(&vms).Error
  2793. return vms, err, total
  2794. }
  2795. func GetLastDialysisGoodsTwo(patient_id int64, orgID int64, record_time int64) (goodUser []*AutomaticReduceDetail, err error) {
  2796. var Id []*DialysisGoodsDetailDate
  2797. err = readDb.Model(&AutomaticReduceDetail{}).Where("patient_id = ? AND org_id = ? AND status=1 AND record_time < ? AND count > 0", patient_id, orgID, record_time).Select("record_time").Group("record_time").Order("record_time asc").Scan(&Id).Error
  2798. if len(Id) > 0 {
  2799. err = readDb.Model(&AutomaticReduceDetail{}).Where("patient_id = ? AND org_id = ? AND status=1 AND record_time = ? AND count > 0", patient_id, orgID, Id[len(Id)-1].RecordTime).Preload("VMGoodInfo", "status = 1 AND org_id = ? ", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0) ", orgID).Find(&goodUser).Error
  2800. }
  2801. return
  2802. }
  2803. func GetLastDialysisBeforePrepareTwo(patient_id int64, orgID int64, record_time int64) (goodUser []*DialysisBeforePrepare, err error) {
  2804. var Id []*DialysisGoodsDate
  2805. err = readDb.Model(&models.DialysisBeforePrepare{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date < ? AND count > 0", patient_id, orgID, record_time).Select("record_date").Group("record_date").Order("record_date asc").Scan(&Id).Error
  2806. if len(Id) > 0 {
  2807. err = readDb.Model(&models.DialysisBeforePrepare{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date = ? AND count > 0", patient_id, orgID, Id[len(Id)-1].RecordDate).Preload("VMGoodInfo", "status = 1 AND org_id = ? ", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0) ", orgID).Find(&goodUser).Error
  2808. }
  2809. return
  2810. }
  2811. func GetAssessmentBefor(orgid int64, patientid int64, recorddate int64) (*models.PredialysisEvaluation, error) {
  2812. evaluation := models.PredialysisEvaluation{}
  2813. err := XTReadDB().Model(&evaluation).Where("user_org_id = ? and patient_id = ? and assessment_date = ? and status = 1", orgid, patientid, recorddate).Find(&evaluation).Error
  2814. if err == gorm.ErrRecordNotFound {
  2815. return nil, err
  2816. }
  2817. if err != nil {
  2818. return nil, err
  2819. }
  2820. return &evaluation, nil
  2821. }
  2822. func GetAssessmentBeforThrity(orgid int64, patientid int64, recorddate int64) (models.PredialysisEvaluation, error) {
  2823. evaluation := models.PredialysisEvaluation{}
  2824. err := XTReadDB().Model(&evaluation).Where("user_org_id = ? and patient_id = ? and assessment_date = ? and status = 1", orgid, patientid, recorddate).Find(&evaluation).Error
  2825. return evaluation, err
  2826. }
  2827. func GetAllHisDoctorAdvice(orgid int64, patientid int64, recorddate int64) (his []*models.HisDoctorAdviceInfo, err error) {
  2828. redis := RedisClient()
  2829. defer redis.Close()
  2830. key := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patientid, 10) + ":" + strconv.FormatInt(recorddate, 10) + ":his_doctor_advice"
  2831. his_doctor_advice_str, _ := redis.Get(key).Result()
  2832. redis.Set(key, "", time.Second)
  2833. if len(his_doctor_advice_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2834. err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date = ?", patientid, orgid, recorddate).Order("created_time asc").Find(&his).Error
  2835. if err != nil {
  2836. if err == gorm.ErrRecordNotFound {
  2837. if len(his) <= 0 {
  2838. redis.Set(key, "null", time.Second*60*60*18)
  2839. }
  2840. return his, nil
  2841. } else {
  2842. return his, err
  2843. }
  2844. } else {
  2845. if len(his) > 0 {
  2846. //缓存数据
  2847. his_doctor_advice_str, err := json.Marshal(his)
  2848. if err == nil {
  2849. redis.Set(key, his_doctor_advice_str, time.Second*60*60*18)
  2850. }
  2851. } else {
  2852. redis.Set(key, "null", time.Second*60*60*18)
  2853. }
  2854. return his, nil
  2855. }
  2856. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2857. json.Unmarshal([]byte(his_doctor_advice_str), &his)
  2858. return his, nil
  2859. }
  2860. }
  2861. func GetLastDialysisPrescriptionByPatientId(orgid int64, patientid int64, recorddate int64) (*models.DialysisPrescription, error) {
  2862. prescription := models.DialysisPrescription{}
  2863. err := readDb.Model(&models.DialysisPrescription{}).Where("user_org_id = ? and patient_id = ? and record_date = ? and status = 1", orgid, patientid, recorddate).Find(&prescription).Error
  2864. if err == gorm.ErrRecordNotFound {
  2865. return nil, err
  2866. }
  2867. if err != nil {
  2868. return nil, err
  2869. }
  2870. return &prescription, nil
  2871. }
  2872. func GetLastDialysisPrescriptionByPatientIdTwo(orgid int64, patientid int64, recorddate int64) (models.DialysisPrescription, error) {
  2873. prescription := models.DialysisPrescription{}
  2874. err := readDb.Model(&models.DialysisPrescription{}).Where("user_org_id = ? and patient_id = ? and record_date = ? and status = 1", orgid, patientid, recorddate).Find(&prescription).Error
  2875. return prescription, err
  2876. }
  2877. type HisMScheduleDoctorAdviceVM struct {
  2878. ID int64 `gorm:"column:id" json:"id"`
  2879. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2880. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2881. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2882. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2883. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2884. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2885. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2886. Status int64 `gorm:"column:status" json:"status"`
  2887. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  2888. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  2889. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2890. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  2891. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  2892. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  2893. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  2894. }
  2895. func (HisMScheduleDoctorAdviceVM) TableName() string {
  2896. return "xt_schedule"
  2897. }
  2898. type HisMScheduleDoctorAdviceVMOne struct {
  2899. ID int64 `gorm:"column:id" json:"id"`
  2900. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2901. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2902. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2903. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2904. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2905. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2906. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2907. Status int64 `gorm:"column:status" json:"status"`
  2908. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  2909. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  2910. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2911. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  2912. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  2913. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  2914. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  2915. }
  2916. func (HisMScheduleDoctorAdviceVMOne) TableName() string {
  2917. return "xt_schedule"
  2918. }
  2919. type HisMScheduleProjectVM struct {
  2920. ID int64 `gorm:"column:id" json:"id"`
  2921. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2922. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2923. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2924. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2925. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2926. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2927. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2928. Status int64 `gorm:"column:status" json:"status"`
  2929. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  2930. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  2931. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2932. Prescription *models.DialysisPrescriptionTwenty `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  2933. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  2934. HisPrescriptionTeamProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"team_project"`
  2935. }
  2936. func (HisMScheduleProjectVM) TableName() string {
  2937. return "xt_schedule"
  2938. }
  2939. func GetHisDoctorConfig(orgid int64) (models.XtHisConfig, error) {
  2940. config := models.XtHisConfig{}
  2941. err := XTReadDB().Model(&config).Where("user_org_id = ? and status =1", orgid).Find(&config).Error
  2942. return config, err
  2943. }
  2944. func GetHisDoctorPatientById(orgid int64, patientid int64, recordtime int64) (advice []*models.HisDoctorAdviceInfo, err error) {
  2945. db := XTReadDB().Table("his_doctor_advice_info as x").Where("x.status = 1")
  2946. if orgid > 0 {
  2947. db = db.Where("x.user_org_id = ?", orgid)
  2948. }
  2949. if patientid > 0 {
  2950. db = db.Where("x.patient_id =?", patientid)
  2951. }
  2952. if recordtime > 0 {
  2953. db = db.Where("x.advice_date = ?", recordtime)
  2954. }
  2955. err = db.Select("x.id,x.user_org_id,x.patient_id,x.his_patient_id,x.advice_type,x.advice_date,x.start_time,x.advice_name,x.advice_desc,x.reminder_date,x.single_dose,x.single_dose_unit,x.single_dose_unit,x.prescribing_number_unit,x.prescribing_number,x.delivery_way,x.execution_frequency,x.advice_doctor,x.status,x.advice_affirm,x.remark,x.stop_time,x.stop_reason,x.stop_doctor,x.stop_state,x.parent_id,x.execution_time,x.execution_staff,x.checker,x.record_date,x.dialysis_order_id,x.check_time,x.check_state,x.drug_spec,x.drug_spec_unit,x.groupno,x.remind_type,x.frequency_type,x.day_count,x.week_day,x.template_id,x.modifier,x.drug_id,x.price,x.prescription_id,x.med_list_codg,x.feedetl_sn,x.day").Find(&advice).Error
  2956. return advice, err
  2957. }
  2958. func GetDoctorAdviceCount(startime int64, endtime int64, deliveway string, orgid int64) (advice []*models.BloodDoctorAdvice, err error) {
  2959. db := XTReadDB().Table("xt_doctor_advice as x").Where("x.status = 1 and x.advice_type =2")
  2960. if startime > 0 {
  2961. db = db.Where("x.advice_date >= ?", startime)
  2962. }
  2963. if endtime > 0 {
  2964. db = db.Where("x.advice_date<=?", endtime)
  2965. }
  2966. if orgid > 0 {
  2967. db = db.Where("x.user_org_id = ?", orgid)
  2968. }
  2969. if len(deliveway) > 0 {
  2970. db = db.Where("x.delivery_way = ?", deliveway)
  2971. }
  2972. err = db.Select("x.advice_name,x.advice_desc,x.delivery_way,count(x.id) as total").Group("x.advice_name,x.advice_desc").Scan(&advice).Error
  2973. return advice, err
  2974. }
  2975. func GetHisDoctorAdviceCount(startime int64, endtime int64, deliveway string, orgid int64) (advice []*models.BloodDoctorAdvice, err error) {
  2976. db := XTReadDB().Table("his_doctor_advice_info as x").Where("x.status = 1 and x.advice_type =2")
  2977. if startime > 0 {
  2978. db = db.Where("x.advice_date >= ?", startime)
  2979. }
  2980. if endtime > 0 {
  2981. db = db.Where("x.advice_date<=?", endtime)
  2982. }
  2983. if orgid > 0 {
  2984. db = db.Where("x.user_org_id = ?", orgid)
  2985. }
  2986. if len(deliveway) > 0 {
  2987. db = db.Where("x.delivery_way = ?", deliveway)
  2988. }
  2989. err = db.Select("x.advice_name,x.advice_desc,x.delivery_way,count(x.id) as total").Group("x.advice_name,x.advice_desc").Scan(&advice).Error
  2990. return advice, err
  2991. }
  2992. func MobileGetScheduleDoctorAdvicesSix(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string, scheduleType int64, partitonType int64, patient_id int64, execution_state int64) ([]*MScheduleDoctorAdviceVM, error) {
  2993. var vms []*MScheduleDoctorAdviceVM
  2994. adviceWhere := ""
  2995. adviceCondition := []interface{}{}
  2996. if adviceType == 0 {
  2997. if patientType == 0 {
  2998. if patient_id > 0 {
  2999. if execution_state > 0 {
  3000. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  3001. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3002. } else {
  3003. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
  3004. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3005. }
  3006. } else {
  3007. if execution_state > 0 {
  3008. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ?"
  3009. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3010. } else {
  3011. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  3012. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3013. }
  3014. }
  3015. } else if patientType == 1 {
  3016. if patient_id > 0 {
  3017. if execution_state > 0 {
  3018. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  3019. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3020. } else {
  3021. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
  3022. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3023. }
  3024. } else {
  3025. if execution_state > 0 {
  3026. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  3027. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3028. } else {
  3029. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  3030. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3031. }
  3032. }
  3033. } else if patientType == 2 {
  3034. if patient_id > 0 {
  3035. if execution_state > 0 {
  3036. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?) and execution_state = ?"
  3037. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3038. } else {
  3039. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?)"
  3040. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3041. }
  3042. } else {
  3043. if execution_state > 0 {
  3044. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  3045. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3046. } else {
  3047. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  3048. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3049. }
  3050. }
  3051. }
  3052. } else if adviceType == 1 {
  3053. if patientType == 0 {
  3054. if patient_id > 0 {
  3055. if execution_state > 0 {
  3056. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ?"
  3057. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3058. } else {
  3059. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
  3060. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3061. }
  3062. } else {
  3063. if execution_state > 0 {
  3064. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ?"
  3065. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3066. } else {
  3067. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  3068. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3069. }
  3070. }
  3071. } else if patientType == 1 {
  3072. if patient_id > 0 {
  3073. if execution_state > 0 {
  3074. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  3075. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3076. } else {
  3077. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
  3078. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3079. }
  3080. } else {
  3081. if execution_state > 0 {
  3082. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?"
  3083. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3084. } else {
  3085. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  3086. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3087. }
  3088. }
  3089. } else if patientType == 2 {
  3090. if patient_id > 0 {
  3091. if execution_state > 0 {
  3092. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  3093. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3094. } else {
  3095. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
  3096. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3097. }
  3098. } else {
  3099. if execution_state > 0 {
  3100. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ?"
  3101. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3102. } else {
  3103. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  3104. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3105. }
  3106. }
  3107. }
  3108. } else if adviceType == 3 {
  3109. if patientType == 0 {
  3110. if patient_id > 0 {
  3111. if execution_state > 0 {
  3112. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ?"
  3113. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3114. } else {
  3115. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? "
  3116. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3117. }
  3118. } else {
  3119. if execution_state > 0 {
  3120. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? "
  3121. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3122. } else {
  3123. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  3124. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3125. }
  3126. }
  3127. } else if patientType == 1 {
  3128. if patient_id > 0 {
  3129. if execution_state > 0 {
  3130. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  3131. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3132. } else {
  3133. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
  3134. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3135. }
  3136. } else {
  3137. if execution_state > 0 {
  3138. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? "
  3139. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3140. } else {
  3141. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  3142. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3143. }
  3144. }
  3145. } else if patientType == 2 {
  3146. if patient_id > 0 {
  3147. if execution_state > 0 {
  3148. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  3149. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3150. } else {
  3151. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ?"
  3152. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3153. }
  3154. } else {
  3155. if execution_state > 0 {
  3156. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ?"
  3157. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3158. } else {
  3159. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  3160. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3161. }
  3162. }
  3163. }
  3164. } else if adviceType == 2 && len(deliverWay) > 0 {
  3165. if patientType == 0 {
  3166. if patient_id > 0 {
  3167. if execution_state > 0 {
  3168. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  3169. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  3170. } else {
  3171. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ?"
  3172. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  3173. }
  3174. } else {
  3175. if execution_state > 0 {
  3176. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ?"
  3177. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  3178. } else {
  3179. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  3180. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  3181. }
  3182. }
  3183. } else if patientType == 1 {
  3184. if patient_id > 0 {
  3185. if execution_state > 0 {
  3186. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  3187. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state)
  3188. } else {
  3189. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ?"
  3190. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
  3191. }
  3192. } else {
  3193. if execution_state > 0 {
  3194. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ?"
  3195. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state)
  3196. } else {
  3197. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  3198. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  3199. }
  3200. }
  3201. } else if patientType == 2 {
  3202. if patient_id > 0 {
  3203. if execution_state > 0 {
  3204. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ?"
  3205. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  3206. } else {
  3207. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ?"
  3208. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  3209. }
  3210. } else {
  3211. if execution_state > 0 {
  3212. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ?"
  3213. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  3214. } else {
  3215. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  3216. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  3217. }
  3218. }
  3219. }
  3220. } else if adviceType == 2 && len(deliverWay) <= 0 {
  3221. if patientType == 0 {
  3222. if patient_id > 0 {
  3223. if execution_state > 0 {
  3224. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ?"
  3225. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3226. } else {
  3227. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ?"
  3228. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3229. }
  3230. } else {
  3231. if execution_state > 0 {
  3232. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?"
  3233. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3234. } else {
  3235. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  3236. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3237. }
  3238. }
  3239. } else if patientType == 1 {
  3240. if patient_id > 0 {
  3241. if execution_state > 0 {
  3242. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  3243. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3244. } else {
  3245. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ?"
  3246. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3247. }
  3248. } else {
  3249. if execution_state > 0 {
  3250. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ?"
  3251. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3252. } else {
  3253. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?"
  3254. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3255. }
  3256. }
  3257. } else if patientType == 2 {
  3258. if patient_id > 0 {
  3259. if execution_state > 0 {
  3260. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  3261. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3262. } else {
  3263. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ?"
  3264. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3265. }
  3266. } else {
  3267. if execution_state > 0 {
  3268. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ?"
  3269. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3270. } else {
  3271. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  3272. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3273. }
  3274. }
  3275. }
  3276. }
  3277. db := readDb.Table("xt_schedule")
  3278. if scheduleType > 0 {
  3279. db = db.Where("schedule_type = ?", scheduleType)
  3280. }
  3281. if partitonType > 0 {
  3282. db = db.Where("partition_id = ?", partitonType)
  3283. }
  3284. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3285. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3286. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3287. }).
  3288. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3289. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3290. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3291. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3292. Preload("DoctorAdvices", adviceCondition...).
  3293. Where("status = 1 AND user_org_id = ?", orgID)
  3294. if scheduleDate != 0 {
  3295. db = db.Where("schedule_date = ?", scheduleDate)
  3296. }
  3297. err := db.Find(&vms).Error
  3298. return vms, err
  3299. }
  3300. func GetHisDoctorAdvicesOne(orgID int64, scheduleDate int64, deliverWay string, scheduleType int64, partitionType int64, patient_id int64, execution_state int64, cost_type int64) ([]*HisMScheduleDoctorAdviceVM, error) {
  3301. var vms []*HisMScheduleDoctorAdviceVM
  3302. if len(deliverWay) > 0 {
  3303. db := readDb.Table("xt_schedule")
  3304. if scheduleType > 0 {
  3305. db = db.Where("schedule_type = ?", scheduleType)
  3306. }
  3307. if partitionType > 0 {
  3308. db = db.Where("partition_id = ?", partitionType)
  3309. }
  3310. if patient_id > 0 {
  3311. if execution_state > 0 {
  3312. if cost_type > 0 {
  3313. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3314. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3315. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3316. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3317. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle", orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type).
  3318. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3319. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3320. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3321. Where("status = 1 AND user_org_id = ?", orgID)
  3322. if scheduleDate != 0 {
  3323. db = db.Where("schedule_date = ?", scheduleDate)
  3324. }
  3325. err = db.Find(&vms).Error
  3326. } else {
  3327. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3328. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3329. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3330. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3331. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ? and execution_state = ?", orgID, scheduleDate, deliverWay, patient_id, execution_state).
  3332. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3333. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3334. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3335. Where("status = 1 AND user_org_id = ?", orgID)
  3336. if scheduleDate != 0 {
  3337. db = db.Where("schedule_date = ?", scheduleDate)
  3338. }
  3339. err = db.Find(&vms).Error
  3340. }
  3341. } else {
  3342. if cost_type > 0 {
  3343. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3344. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3345. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3346. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3347. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ? and is_settle", orgID, scheduleDate, deliverWay, patient_id, cost_type).
  3348. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3349. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3350. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3351. Where("status = 1 AND user_org_id = ?", orgID)
  3352. if scheduleDate != 0 {
  3353. db = db.Where("schedule_date = ?", scheduleDate)
  3354. }
  3355. err = db.Find(&vms).Error
  3356. } else {
  3357. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3358. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3359. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3360. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3361. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ?", orgID, scheduleDate, deliverWay, patient_id).
  3362. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3363. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3364. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3365. Where("status = 1 AND user_org_id = ?", orgID)
  3366. if scheduleDate != 0 {
  3367. db = db.Where("schedule_date = ?", scheduleDate)
  3368. }
  3369. err = db.Find(&vms).Error
  3370. }
  3371. }
  3372. } else {
  3373. if execution_state > 0 {
  3374. if cost_type > 0 {
  3375. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3376. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3377. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3378. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3379. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_state = ? and is_settle = ?", orgID, scheduleDate, deliverWay, execution_state, cost_type).
  3380. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3381. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3382. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3383. Where("status = 1 AND user_org_id = ?", orgID)
  3384. if scheduleDate != 0 {
  3385. db = db.Where("schedule_date = ?", scheduleDate)
  3386. }
  3387. err = db.Find(&vms).Error
  3388. } else {
  3389. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3390. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3391. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3392. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3393. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_state = ?", orgID, scheduleDate, deliverWay, execution_state).
  3394. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3395. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3396. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3397. Where("status = 1 AND user_org_id = ?", orgID)
  3398. if scheduleDate != 0 {
  3399. db = db.Where("schedule_date = ?", scheduleDate)
  3400. }
  3401. err = db.Find(&vms).Error
  3402. }
  3403. } else {
  3404. if cost_type > 0 {
  3405. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3406. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3407. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3408. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3409. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and is_settle = ?", orgID, scheduleDate, deliverWay, cost_type).
  3410. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3411. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3412. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3413. Where("status = 1 AND user_org_id = ?", orgID)
  3414. if scheduleDate != 0 {
  3415. db = db.Where("schedule_date = ?", scheduleDate)
  3416. }
  3417. err = db.Find(&vms).Error
  3418. } else {
  3419. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3420. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3421. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3422. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3423. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  3424. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3425. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3426. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3427. Where("status = 1 AND user_org_id = ?", orgID)
  3428. if scheduleDate != 0 {
  3429. db = db.Where("schedule_date = ?", scheduleDate)
  3430. }
  3431. err = db.Find(&vms).Error
  3432. }
  3433. }
  3434. }
  3435. } else {
  3436. db := readDb.Table("xt_schedule")
  3437. if scheduleType > 0 {
  3438. db = db.Where("schedule_type = ?", scheduleType)
  3439. }
  3440. if partitionType > 0 {
  3441. db = db.Where("partition_id = ?", partitionType)
  3442. }
  3443. if patient_id > 0 {
  3444. if execution_state > 0 {
  3445. if cost_type > 0 {
  3446. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3447. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3448. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3449. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3450. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and execution_state = ? and is_settle = ?", orgID, scheduleDate, patient_id, execution_state, cost_type).
  3451. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3452. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3453. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3454. Where("status = 1 AND user_org_id = ?", orgID)
  3455. if scheduleDate != 0 {
  3456. db = db.Where("schedule_date = ?", scheduleDate)
  3457. }
  3458. err = db.Find(&vms).Error
  3459. } else {
  3460. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3461. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3462. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3463. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3464. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and execution_state = ?", orgID, scheduleDate, patient_id, execution_state).
  3465. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3466. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3467. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3468. Where("status = 1 AND user_org_id = ?", orgID)
  3469. if scheduleDate != 0 {
  3470. db = db.Where("schedule_date = ?", scheduleDate)
  3471. }
  3472. err = db.Find(&vms).Error
  3473. }
  3474. } else {
  3475. if cost_type > 0 {
  3476. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3477. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3478. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3479. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3480. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and is_settle = ?", orgID, scheduleDate, patient_id, cost_type).
  3481. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3482. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3483. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3484. Where("status = 1 AND user_org_id = ?", orgID)
  3485. if scheduleDate != 0 {
  3486. db = db.Where("schedule_date = ?", scheduleDate)
  3487. }
  3488. err = db.Find(&vms).Error
  3489. } else {
  3490. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3491. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3492. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3493. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3494. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3495. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3496. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3497. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3498. Where("status = 1 AND user_org_id = ?", orgID)
  3499. if scheduleDate != 0 {
  3500. db = db.Where("schedule_date = ?", scheduleDate)
  3501. }
  3502. err = db.Find(&vms).Error
  3503. }
  3504. }
  3505. } else {
  3506. if execution_state > 0 {
  3507. if cost_type > 0 {
  3508. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3509. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3510. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3511. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3512. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ? and is_settle = ?", orgID, scheduleDate, execution_state, cost_type).
  3513. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3514. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3515. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3516. Where("status = 1 AND user_org_id = ?", orgID)
  3517. if scheduleDate != 0 {
  3518. db = db.Where("schedule_date = ?", scheduleDate)
  3519. }
  3520. err = db.Find(&vms).Error
  3521. } else {
  3522. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3523. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3524. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3525. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3526. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ?", orgID, scheduleDate, execution_state).
  3527. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3528. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3529. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3530. Where("status = 1 AND user_org_id = ?", orgID)
  3531. if scheduleDate != 0 {
  3532. db = db.Where("schedule_date = ?", scheduleDate)
  3533. }
  3534. err = db.Find(&vms).Error
  3535. }
  3536. } else {
  3537. if cost_type > 0 {
  3538. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3539. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3540. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3541. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3542. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and is_settle = ?", orgID, scheduleDate, cost_type).
  3543. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3544. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3545. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3546. Where("status = 1 AND user_org_id = ?", orgID)
  3547. if scheduleDate != 0 {
  3548. db = db.Where("schedule_date = ?", scheduleDate)
  3549. }
  3550. err = db.Find(&vms).Error
  3551. } else {
  3552. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3553. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3554. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3555. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3556. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ?", orgID, scheduleDate).
  3557. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3558. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3559. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3560. Where("status = 1 AND user_org_id = ?", orgID)
  3561. if scheduleDate != 0 {
  3562. db = db.Where("schedule_date = ?", scheduleDate)
  3563. }
  3564. err = db.Find(&vms).Error
  3565. }
  3566. }
  3567. }
  3568. }
  3569. return vms, err
  3570. }
  3571. func BatchDeleteMonitor(ids []string) (err error) {
  3572. if len(ids) == 1 {
  3573. err = XTWriteDB().Model(&models.MonitoringRecord{}).Where("id=?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3574. } else {
  3575. err = XTWriteDB().Model(models.MonitoringRecord{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3576. }
  3577. return
  3578. }
  3579. func GetPatientDialysisRecordList(patientid int64, startime int64, endtime int64) (order []*models.XtDialysisOrders, err error) {
  3580. db := XTReadDB().Table("xt_dialysis_order as x").Where("x.status = 1")
  3581. //table := XTReadDB().Table("xt_schedule as s")
  3582. //fmt.Println(table)
  3583. if patientid > 0 {
  3584. db = db.Where("x.patient_id = ?", patientid)
  3585. }
  3586. if startime > 0 {
  3587. db = db.Where("x.dialysis_date>=?", startime)
  3588. }
  3589. if endtime > 0 {
  3590. db = db.Where("x.dialysis_date <= ?", endtime)
  3591. }
  3592. err = db.Select("x.id,x.dialysis_date,x.schedual_type,s.mode_id").Joins("left join xt_schedule as s on x.patient_id = s.patient_id and x.dialysis_date = s.schedule_date ").Scan(&order).Error
  3593. return order, err
  3594. }
  3595. func BatchDeleteAdvice(ids []string) (err error) {
  3596. if len(ids) == 1 {
  3597. err = XTWriteDB().Model(&models.DoctorAdvice{}).Where("id=?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3598. } else {
  3599. err = XTWriteDB().Model(models.DoctorAdvice{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3600. }
  3601. return
  3602. }
  3603. func BatchDeleteHisAdvice(ids []string) (err error) {
  3604. if len(ids) == 1 {
  3605. err = XTWriteDB().Model(&models.HisDoctorAdviceInfo{}).Where("id = ?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3606. } else {
  3607. err = XTWriteDB().Model(models.HisDoctorAdviceInfo{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3608. }
  3609. return
  3610. }
  3611. func UpdateAutoReduceDetail(good_id int64, count int64, record_time int64, patient_id int64) (models.AutomaticReduceDetail, error) {
  3612. detail := models.AutomaticReduceDetail{}
  3613. err := XTWriteDB().Model(&detail).Where("good_id = ? and status = 1 and record_time = ? and patient_id = ?", good_id, record_time, patient_id).Updates(map[string]interface{}{"count": count}).Error
  3614. return detail, err
  3615. }
  3616. func DeleteAutoReduceDetail(good_id int64, record_time int64, patient_id int64) error {
  3617. detail := models.AutomaticReduceDetail{}
  3618. err := XTWriteDB().Model(&detail).Where("good_id = ? and status = 1 and record_time = ? and patient_id = ?", good_id, record_time, patient_id).Updates(map[string]interface{}{"status": 0}).Error
  3619. return err
  3620. }
  3621. func DeleteDialysisBeforOne(good_id int64, record_time int64, patient_id int64) error {
  3622. detail := models.DialysisBeforePrepare{}
  3623. err := XTWriteDB().Model(&detail).Where("good_id = ? and status = 1 and record_date = ? and patient_id = ?", good_id, record_time, patient_id).Updates(map[string]interface{}{"status": 0}).Error
  3624. return err
  3625. }
  3626. func BatchAdviceCheck(ids []string, creator int64) error {
  3627. advice := models.XtDoctorAdvice{}
  3628. err := XTWriteDB().Model(&advice).Where("id IN(?) and status = 1", ids).Updates(map[string]interface{}{"check_state": 1, "checker": creator, "check_time": time.Now().Unix()}).Error
  3629. return err
  3630. }
  3631. func BatchHisAdviceCheck(ids []string, creator int64) error {
  3632. advice := models.HisDoctorAdviceInfo{}
  3633. err := XTWriteDB().Model(&advice).Where("id IN(?) and status = 1", ids).Updates(map[string]interface{}{"check_state": 1, "checker": creator, "check_time": time.Now().Unix()}).Error
  3634. return err
  3635. }
  3636. func BatchAdviceExecution(ids []string, creator int64, execution_state int64) error {
  3637. advice := models.XtDoctorAdvice{}
  3638. err := XTWriteDB().Model(&advice).Where("id IN(?) and status = 1", ids).Updates(map[string]interface{}{"execution_state": 1, "execution_staff": creator, "execution_time": execution_state}).Error
  3639. return err
  3640. }
  3641. func BatchHisAdviceExecution(ids []string, creator int64, execution_state int64) error {
  3642. advice := models.HisDoctorAdviceInfo{}
  3643. err := XTWriteDB().Model(&advice).Where("id IN(?) and status = 1", ids).Updates(map[string]interface{}{"execution_state": 1, "execution_staff": creator, "execution_time": execution_state}).Error
  3644. return err
  3645. }
  3646. func GetAdviceExecutionById(ids []string) (doctor []*models.XtDoctorAdvice, err error) {
  3647. err = XTReadDB().Model(&doctor).Where("id IN(?) AND status = 1", ids).Find(&doctor).Error
  3648. return doctor, err
  3649. }
  3650. func GetHisAdviceExecutionById(ids []string) (doctor []*models.HisDoctorAdviceInfo, err error) {
  3651. err = XTReadDB().Model(&doctor).Where("id IN(?) AND status = 1", ids).Find(&doctor).Error
  3652. return doctor, err
  3653. }
  3654. func GetHisProjectConfig(orgid int64) (models.XtHisProjectConfig, error) {
  3655. config := models.XtHisProjectConfig{}
  3656. err := XTReadDB().Model(&config).Where("user_org_id = ? and status =1", orgid).Find(&config).Error
  3657. return config, err
  3658. }
  3659. func GetHisPrescriptionProject(org_id int64, patient_id int64, record_date int64) (project []*models.HisPrescriptionProject, err error) {
  3660. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("GoodInfo", func(db *gorm.DB) *gorm.DB {
  3661. return db.Preload("GoodsType", "status = 1").Where("status = 1 and is_warehouse = 1")
  3662. }).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND type = 3", org_id, record_date, patient_id).Find(&project).Error
  3663. return
  3664. }
  3665. func GetPCHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64, patient_id int64, execution_state int64) ([]*HisMScheduleProjectVM, error) {
  3666. var vms []*HisMScheduleProjectVM
  3667. if patientType == 0 {
  3668. if patient_id > 0 {
  3669. if execution_state == 1 {
  3670. db := readDb.
  3671. Table("xt_schedule").
  3672. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3673. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3674. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3675. }).
  3676. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3677. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3678. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3679. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3680. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0 and execution_state = ?", orgID, scheduleDate, execution_state).Preload("HisProject").Preload("GoodInfo", "status=1")
  3681. }).
  3682. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3683. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0 and execution_state = ?", orgID, scheduleDate, execution_state).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  3684. }).Where("status = 1 AND user_org_id = ?", orgID)
  3685. if scheduleDate != 0 {
  3686. db = db.Where("schedule_date = ?", scheduleDate)
  3687. }
  3688. err = db.Find(&vms).Error
  3689. } else if execution_state == 2 {
  3690. db := readDb.
  3691. Table("xt_schedule").
  3692. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3693. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3694. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3695. }).
  3696. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3697. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3698. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3699. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3700. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0 and execution_state = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3701. }).
  3702. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3703. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0 and execution_state = 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  3704. }).Where("status = 1 AND user_org_id = ?", orgID)
  3705. if scheduleDate != 0 {
  3706. db = db.Where("schedule_date = ?", scheduleDate)
  3707. }
  3708. err = db.Find(&vms).Error
  3709. } else if execution_state == 0 {
  3710. db := readDb.
  3711. Table("xt_schedule").
  3712. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3713. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3714. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3715. }).
  3716. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3717. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3718. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3719. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3720. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3721. }).
  3722. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3723. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  3724. }).Where("status = 1 AND user_org_id = ?", orgID)
  3725. if scheduleDate != 0 {
  3726. db = db.Where("schedule_date = ?", scheduleDate)
  3727. }
  3728. err = db.Find(&vms).Error
  3729. }
  3730. } else {
  3731. if patient_id > 0 {
  3732. if execution_state == 1 {
  3733. db := readDb.
  3734. Table("xt_schedule").
  3735. Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
  3736. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3737. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3738. }).
  3739. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3740. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3741. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3742. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3743. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0 and execution_state = ?", orgID, scheduleDate, execution_state).Preload("HisProject").Preload("GoodInfo", "status=1")
  3744. }).
  3745. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3746. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0 and execution_state = ?", orgID, scheduleDate, execution_state).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  3747. }).Where("status = 1 AND user_org_id = ?", orgID)
  3748. if scheduleDate != 0 {
  3749. db = db.Where("schedule_date = ?", scheduleDate)
  3750. }
  3751. err = db.Find(&vms).Error
  3752. } else if execution_state == 2 {
  3753. db := readDb.
  3754. Table("xt_schedule").
  3755. Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
  3756. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3757. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3758. }).
  3759. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3760. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3761. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3762. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3763. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0 and execution_state = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3764. }).
  3765. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3766. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0 and execution_state = 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  3767. }).Where("status = 1 AND user_org_id = ?", orgID)
  3768. if scheduleDate != 0 {
  3769. db = db.Where("schedule_date = ?", scheduleDate)
  3770. }
  3771. err = db.Find(&vms).Error
  3772. } else if execution_state == 0 {
  3773. db := readDb.
  3774. Table("xt_schedule").
  3775. Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
  3776. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3777. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3778. }).
  3779. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3780. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3781. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3782. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3783. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3784. }).
  3785. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3786. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  3787. }).Where("status = 1 AND user_org_id = ?", orgID)
  3788. if scheduleDate != 0 {
  3789. db = db.Where("schedule_date = ?", scheduleDate)
  3790. }
  3791. err = db.Find(&vms).Error
  3792. }
  3793. } else {
  3794. if execution_state == 1 {
  3795. db := readDb.
  3796. Table("xt_schedule").
  3797. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3798. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3799. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3800. }).
  3801. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3802. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3803. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3804. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3805. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0 and execution_state = ?", orgID, scheduleDate, execution_state).Preload("HisProject").Preload("GoodInfo", "status=1")
  3806. }).
  3807. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3808. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0 and execution_state = ?", orgID, scheduleDate, execution_state).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  3809. }).Where("status = 1 AND user_org_id = ?", orgID)
  3810. if scheduleDate != 0 {
  3811. db = db.Where("schedule_date = ?", scheduleDate)
  3812. }
  3813. err = db.Find(&vms).Error
  3814. } else if execution_state == 2 {
  3815. fmt.Println("j氯332n323232n323ℹ️33232323232")
  3816. db := readDb.
  3817. Table("xt_schedule").
  3818. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3819. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3820. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3821. }).
  3822. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3823. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3824. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3825. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3826. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0 and execution_state =0 ", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3827. }).
  3828. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3829. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0 and execution_state =0 ", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  3830. }).Where("status = 1 AND user_org_id = ?", orgID)
  3831. if scheduleDate != 0 {
  3832. db = db.Where("schedule_date = ?", scheduleDate)
  3833. }
  3834. err = db.Find(&vms).Error
  3835. } else if execution_state == 0 {
  3836. db := readDb.
  3837. Table("xt_schedule").
  3838. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3839. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3840. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3841. }).
  3842. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3843. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3844. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3845. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3846. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3847. }).
  3848. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3849. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  3850. }).Where("status = 1 AND user_org_id = ?", orgID)
  3851. if scheduleDate != 0 {
  3852. db = db.Where("schedule_date = ?", scheduleDate)
  3853. }
  3854. err = db.Find(&vms).Error
  3855. }
  3856. }
  3857. }
  3858. }
  3859. if patientType > 0 {
  3860. if execution_state == 1 {
  3861. db := readDb.
  3862. Table("xt_schedule").
  3863. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3864. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3865. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3866. }).
  3867. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3868. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3869. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3870. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  3871. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3872. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0 and execution_state = 1", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3873. }).
  3874. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3875. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  3876. }).Where("status = 1 AND user_org_id = ?", orgID)
  3877. if scheduleDate != 0 {
  3878. db = db.Where("schedule_date = ?", scheduleDate)
  3879. }
  3880. err = db.Find(&vms).Error
  3881. } else if execution_state == 2 {
  3882. db := readDb.
  3883. Table("xt_schedule").
  3884. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3885. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3886. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3887. }).
  3888. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3889. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3890. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3891. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  3892. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3893. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0 and execution_state = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3894. }).
  3895. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3896. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  3897. }).Where("status = 1 AND user_org_id = ?", orgID)
  3898. if scheduleDate != 0 {
  3899. db = db.Where("schedule_date = ?", scheduleDate)
  3900. }
  3901. err = db.Find(&vms).Error
  3902. } else if execution_state == 0 {
  3903. db := readDb.
  3904. Table("xt_schedule").
  3905. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3906. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3907. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3908. }).
  3909. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3910. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3911. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3912. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  3913. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3914. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3915. }).
  3916. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3917. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  3918. }).Where("status = 1 AND user_org_id = ?", orgID)
  3919. if scheduleDate != 0 {
  3920. db = db.Where("schedule_date = ?", scheduleDate)
  3921. }
  3922. err = db.Find(&vms).Error
  3923. }
  3924. }
  3925. return vms, err
  3926. }
  3927. func UpdateStockGoods(good_id int64, record_time int64, patient_id int64, count int64) error {
  3928. prepare := models.DialysisBeforePrepare{}
  3929. var err error
  3930. if count > 0 {
  3931. err = XTWriteDB().Model(&prepare).Where("good_id= ? and record_date = ? and patient_id = ? and count <> 0 and status = 1", good_id, record_time, patient_id).Updates(map[string]interface{}{"count": count}).Error
  3932. }
  3933. if count <= 0 {
  3934. err = XTWriteDB().Model(&prepare).Where("good_id= ? and record_date = ? and patient_id = ? and count <> 0 and status = 1", good_id, record_time, patient_id).Updates(map[string]interface{}{"count": count, "status": 0}).Error
  3935. }
  3936. return err
  3937. }
  3938. func UPdateAutoStockGoods(good_id int64, record_time int64, patient_id int64, count int64) error {
  3939. detail := models.AutomaticReduceDetail{}
  3940. err := XTWriteDB().Model(&detail).Where("good_id = ? and record_time = ? and patient_id = ? and count <> 0 and status = 1", good_id, record_time, patient_id).Updates(map[string]interface{}{"count": count}).Error
  3941. return err
  3942. }
  3943. func MobileGetDialysisSolutionByModeIdSeven(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  3944. var record models.DialysisSolution
  3945. err := readDb.Model(&models.DialysisSolution{}).Where("patient_id = ? and user_org_id = ? and status = 1 AND mode_id = ?", patientID, orgID, mode_id).Last(&record).Error
  3946. if err != nil {
  3947. if err == gorm.ErrRecordNotFound {
  3948. return nil, nil
  3949. } else {
  3950. return nil, err
  3951. }
  3952. }
  3953. return &record, nil
  3954. }
  3955. func MobileGetLastDialysisPrescribeByModeIdSeven(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  3956. var record models.DialysisPrescription
  3957. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 AND mode_id = ?", patientID, orgID, mode_id).Last(&record).Error
  3958. if err != nil {
  3959. if err == gorm.ErrRecordNotFound {
  3960. return nil, nil
  3961. } else {
  3962. return nil, err
  3963. }
  3964. }
  3965. return &record, nil
  3966. }
  3967. func MobileGetLastDialysisPrescription(patientID int64, orgID int64) (models.DialysisPrescriptionThrity, error) {
  3968. prescription := models.DialysisPrescriptionThrity{}
  3969. err := readDb.Model(&prescription).Where("patient_id = ? and user_org_id = ? and status = 1 and remark<>''", patientID, orgID).Last(&prescription).Error
  3970. return prescription, err
  3971. }
  3972. func MobileGetSystemDialysisPrescribeByModeIdSeven(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  3973. var record models.SystemPrescription
  3974. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).First(&record).Error
  3975. if err != nil {
  3976. if err == gorm.ErrRecordNotFound {
  3977. return nil, nil
  3978. } else {
  3979. return nil, err
  3980. }
  3981. }
  3982. return &record, nil
  3983. }
  3984. // 透前评估
  3985. func MobileGetPredialysisEvaluationSeven(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
  3986. var record models.PredialysisEvaluation
  3987. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  3988. if err != nil {
  3989. if err == gorm.ErrRecordNotFound {
  3990. return nil, nil
  3991. } else {
  3992. return nil, err
  3993. }
  3994. }
  3995. return &record, nil
  3996. }
  3997. //
  3998. //func MobileGetDialysisGoodsSix(orgID int64, scheduleDate int64) (prepare []*models.DialysisBeforePrepare, err error) {
  3999. //
  4000. // err = readDb.Where("user_org_id = ? AND status=1 AND record_date = ? AND count > 0", orgID, scheduleDate).Select("patient_id,good_id,record_date").Find(&prepare).Error
  4001. // return prepare, err
  4002. //}
  4003. func GetMobileAutoReduce(orgID int64, scheduleDate int64) (auto []*models.AutomaticReduceDetail, err error) {
  4004. err = readDb.Where("org_id = ? and status = 1 and record_time = ?", orgID, scheduleDate).Find(&auto).Error
  4005. return auto, err
  4006. }
  4007. func GetRoleList(orgid int64, admin_user_id int64) (models.SgjUserAdminRole, error) {
  4008. role := models.SgjUserAdminRole{}
  4009. err = readUserDb.Where("org_id = ? and admin_user_id = ? and status =1 ", orgid, admin_user_id).Find(&role).Error
  4010. return role, err
  4011. }
  4012. func GetDialysisGood(orgID int64, scheduleDate int64) (auto []*models.AutomaticReduceDetail, err error) {
  4013. err = readDb.Where("org_id = ? and status = 1 and record_time >= ?", orgID, scheduleDate).Group("patient_id").Find(&auto).Error
  4014. return auto, err
  4015. }
  4016. func GetGoodWarehouseOutInfo(orgId int64, patient_id int64, sys_record_time int64) (outifno []*models.WarehouseOutInfoSeven, err error) {
  4017. err = readDb.Where("org_id = ? and patient_id = ? and sys_record_time = ? and status = 1", orgId, patient_id, sys_record_time).Find(&outifno).Error
  4018. return outifno, err
  4019. }
  4020. func GetLastDilysisOrder(orgid int64, patient_id int64, dialysis_date int64) (models.DialysisOrder, error) {
  4021. order := models.DialysisOrder{}
  4022. err = XTReadDB().Where("user_org_id = ? and patient_id = ? and dialysis_date < ? and status= 1", orgid, patient_id, dialysis_date).Last(&order).Error
  4023. return order, err
  4024. }
  4025. func GetFistMonitor(orgid int64, patient_id int64, dialysis_date int64) (models.MonitoringRecord, error) {
  4026. record := models.MonitoringRecord{}
  4027. err := XTReadDB().Where("org_id = ? and patient_id = ? and monitoring_date = ? and status = 1", orgid, patient_id, dialysis_date).Find(&record).Error
  4028. return record, err
  4029. }
  4030. func GetFistMonitorSix(orgid int64, patient_id int64, dialysis_date int64) (record []*models.MonitoringRecord, err error) {
  4031. err = XTReadDB().Where("user_org_id = ? and patient_id = ? and monitoring_date = ? and status = 1", orgid, patient_id, dialysis_date).Find(&record).Error
  4032. return record, err
  4033. }
  4034. func MobileGetScheduleDoctorAdvicesOne(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string, scheduleType int64, partitonType int64, patient_id int64, execution_state int64, cost_type int64, execution_frequency string) ([]*MScheduleDoctorAdviceVM, error) {
  4035. var vms []*MScheduleDoctorAdviceVM
  4036. adviceWhere := ""
  4037. adviceCondition := []interface{}{}
  4038. if adviceType == 0 {
  4039. if patientType == 0 {
  4040. if patient_id > 0 {
  4041. if execution_state > 0 {
  4042. if cost_type > 0 {
  4043. if len(execution_frequency) > 0 {
  4044. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ? and is_settle = ? and execution_frequency = ?"
  4045. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4046. } else {
  4047. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ? and is_settle = ?"
  4048. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4049. }
  4050. } else {
  4051. if len(execution_frequency) > 0 {
  4052. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ? and execution_frequency = ?"
  4053. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4054. } else {
  4055. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  4056. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4057. }
  4058. }
  4059. } else {
  4060. if cost_type > 0 {
  4061. if len(execution_frequency) > 0 {
  4062. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and is_settle = ? and execution_frequency = ?"
  4063. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4064. } else {
  4065. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and is_settle = ?"
  4066. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4067. }
  4068. } else {
  4069. if len(execution_frequency) > 0 {
  4070. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_frequency = ?"
  4071. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4072. } else {
  4073. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
  4074. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4075. }
  4076. }
  4077. }
  4078. } else {
  4079. if execution_state > 0 {
  4080. if cost_type > 0 {
  4081. if len(execution_frequency) > 0 {
  4082. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and is_settle = ? and execution_frequency = ?"
  4083. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4084. } else {
  4085. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and is_settle = ?"
  4086. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4087. }
  4088. } else {
  4089. if len(execution_frequency) > 0 {
  4090. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and execution_frequency = ?"
  4091. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4092. } else {
  4093. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ?"
  4094. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4095. }
  4096. }
  4097. } else {
  4098. if cost_type > 0 {
  4099. if len(execution_frequency) > 0 {
  4100. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ? and execution_frequency = ?"
  4101. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  4102. } else {
  4103. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ?"
  4104. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4105. }
  4106. } else {
  4107. if len(execution_frequency) > 0 {
  4108. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_frequency = ?"
  4109. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  4110. } else {
  4111. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  4112. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4113. }
  4114. }
  4115. }
  4116. }
  4117. } else if patientType == 1 {
  4118. if patient_id > 0 {
  4119. if execution_state > 0 {
  4120. if cost_type > 0 {
  4121. if len(execution_frequency) > 0 {
  4122. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ? and is_settle = ? and execution_frequency = ?"
  4123. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  4124. } else {
  4125. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ? and is_settle = ?"
  4126. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  4127. }
  4128. } else {
  4129. if len(execution_frequency) > 0 {
  4130. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ? and execution_frequency = ?"
  4131. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  4132. } else {
  4133. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  4134. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  4135. }
  4136. }
  4137. } else {
  4138. if cost_type > 0 {
  4139. if len(execution_frequency) > 0 {
  4140. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ? and is_settle=? and execution_frequency = ?"
  4141. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  4142. } else {
  4143. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ? and is_settle=?"
  4144. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  4145. }
  4146. } else {
  4147. if len(execution_frequency) > 0 {
  4148. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_frequency = ?"
  4149. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  4150. } else {
  4151. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
  4152. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  4153. }
  4154. }
  4155. }
  4156. } else {
  4157. if execution_state > 0 {
  4158. if cost_type > 0 {
  4159. if len(execution_frequency) > 0 {
  4160. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ? and is_settle=? and execution_frequency = ?"
  4161. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  4162. } else {
  4163. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ? and is_settle=?"
  4164. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  4165. }
  4166. } else {
  4167. if len(execution_frequency) > 0 {
  4168. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ? and execution_frequency = ?"
  4169. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  4170. } else {
  4171. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  4172. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  4173. }
  4174. }
  4175. } else {
  4176. if cost_type > 0 {
  4177. if len(execution_frequency) > 0 {
  4178. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and is_settle=? and execution_frequency = ?"
  4179. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  4180. } else {
  4181. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and is_settle=?"
  4182. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  4183. }
  4184. } else {
  4185. if len(execution_frequency) > 0 {
  4186. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_frequency = ?"
  4187. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  4188. } else {
  4189. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  4190. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  4191. }
  4192. }
  4193. }
  4194. }
  4195. } else if patientType == 2 {
  4196. if patient_id > 0 {
  4197. if execution_state > 0 {
  4198. if cost_type > 0 {
  4199. if len(execution_frequency) > 0 {
  4200. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?) and execution_state = ? and is_settle=? and execution_frequency = ?"
  4201. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4202. } else {
  4203. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?) and execution_state = ? and is_settle=?"
  4204. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4205. }
  4206. } else {
  4207. if len(execution_frequency) > 0 {
  4208. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?) and execution_state = ?and execution_frequency = ?"
  4209. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4210. } else {
  4211. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?) and execution_state = ?"
  4212. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4213. }
  4214. }
  4215. } else {
  4216. if cost_type > 0 {
  4217. if len(execution_frequency) > 0 {
  4218. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?) and is_settle=? and execution_frequency = ?"
  4219. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4220. } else {
  4221. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?) and is_settle=?"
  4222. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4223. }
  4224. } else {
  4225. if len(execution_frequency) > 0 {
  4226. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?)and execution_frequency = ?"
  4227. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4228. } else {
  4229. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?)"
  4230. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4231. }
  4232. }
  4233. }
  4234. } else {
  4235. if execution_state > 0 {
  4236. if cost_type > 0 {
  4237. if len(execution_frequency) > 0 {
  4238. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1) and execution_state = ? and is_settle=? and execution_frequency = ?"
  4239. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4240. } else {
  4241. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1) and execution_state = ? and is_settle=?"
  4242. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4243. }
  4244. } else {
  4245. if len(execution_frequency) > 0 {
  4246. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1) and execution_state = ? and execution_frequency = ?"
  4247. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4248. } else {
  4249. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  4250. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4251. }
  4252. }
  4253. } else {
  4254. if cost_type > 0 {
  4255. if len(execution_frequency) > 0 {
  4256. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1) and is_settle = ? and execution_frequency = ?"
  4257. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  4258. } else {
  4259. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1) and is_settle = ?"
  4260. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4261. }
  4262. } else {
  4263. if len(execution_frequency) > 0 {
  4264. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1) and execution_frequency = ?"
  4265. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  4266. } else {
  4267. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  4268. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4269. }
  4270. }
  4271. }
  4272. }
  4273. }
  4274. } else if adviceType == 1 {
  4275. if patientType == 0 {
  4276. if patient_id > 0 {
  4277. if execution_state > 0 {
  4278. if cost_type > 0 {
  4279. if len(execution_frequency) > 0 {
  4280. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  4281. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4282. } else {
  4283. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  4284. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4285. }
  4286. } else {
  4287. if len(execution_frequency) > 0 {
  4288. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  4289. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4290. } else {
  4291. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ?"
  4292. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4293. }
  4294. }
  4295. } else {
  4296. if cost_type > 0 {
  4297. if len(execution_frequency) > 0 {
  4298. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  4299. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4300. } else {
  4301. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? "
  4302. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4303. }
  4304. } else {
  4305. if len(execution_frequency) > 0 {
  4306. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_frequency = ?"
  4307. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4308. } else {
  4309. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
  4310. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4311. }
  4312. }
  4313. }
  4314. } else {
  4315. if execution_state > 0 {
  4316. if cost_type > 0 {
  4317. if len(execution_frequency) > 0 {
  4318. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  4319. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4320. } else {
  4321. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ?"
  4322. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4323. }
  4324. } else {
  4325. if len(execution_frequency) > 0 {
  4326. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and execution_frequency = ?"
  4327. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4328. } else {
  4329. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ?"
  4330. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4331. }
  4332. }
  4333. } else {
  4334. if cost_type > 0 {
  4335. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = ? "
  4336. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4337. } else {
  4338. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  4339. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4340. }
  4341. }
  4342. }
  4343. } else if patientType == 1 {
  4344. if patient_id > 0 {
  4345. if execution_state > 0 {
  4346. if cost_type > 0 {
  4347. if len(execution_frequency) > 0 {
  4348. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  4349. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  4350. } else {
  4351. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  4352. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  4353. }
  4354. } else {
  4355. if len(execution_frequency) > 0 {
  4356. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  4357. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  4358. } else {
  4359. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  4360. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  4361. }
  4362. }
  4363. } else {
  4364. if cost_type > 0 {
  4365. if len(execution_frequency) > 0 {
  4366. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and is_settle = ?and execution_frequency = ?"
  4367. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  4368. } else {
  4369. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  4370. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  4371. }
  4372. } else {
  4373. if len(execution_frequency) > 0 {
  4374. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  4375. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  4376. } else {
  4377. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
  4378. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  4379. }
  4380. }
  4381. }
  4382. } else {
  4383. if execution_state > 0 {
  4384. if cost_type > 0 {
  4385. if len(execution_frequency) > 0 {
  4386. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=? and is_settle = ?and execution_frequency = ?"
  4387. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  4388. } else {
  4389. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=? and is_settle = ?"
  4390. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  4391. }
  4392. } else {
  4393. if len(execution_frequency) > 0 {
  4394. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?and execution_frequency = ?"
  4395. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  4396. } else {
  4397. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?"
  4398. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  4399. }
  4400. }
  4401. } else {
  4402. if cost_type > 0 {
  4403. if len(execution_frequency) > 0 {
  4404. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  4405. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  4406. } else {
  4407. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? "
  4408. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  4409. }
  4410. } else {
  4411. if len(execution_frequency) > 0 {
  4412. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_frequency = ?"
  4413. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  4414. } else {
  4415. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  4416. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  4417. }
  4418. }
  4419. }
  4420. }
  4421. } else if patientType == 2 {
  4422. if patient_id > 0 {
  4423. if execution_state > 0 {
  4424. if cost_type > 0 {
  4425. if len(execution_frequency) > 0 {
  4426. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ?and execution_frequency = ?"
  4427. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4428. } else {
  4429. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ?"
  4430. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4431. }
  4432. } else {
  4433. if len(execution_frequency) > 0 {
  4434. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ? and execution_frequency = ?"
  4435. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4436. } else {
  4437. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  4438. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4439. }
  4440. }
  4441. } else {
  4442. if cost_type > 0 {
  4443. if len(execution_frequency) > 0 {
  4444. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and is_settle = ? and execution_frequency = ?"
  4445. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4446. } else {
  4447. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  4448. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4449. }
  4450. } else {
  4451. if len(execution_frequency) > 0 {
  4452. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_frequency = ?"
  4453. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4454. } else {
  4455. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
  4456. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4457. }
  4458. }
  4459. }
  4460. } else {
  4461. if execution_state > 0 {
  4462. if cost_type > 0 {
  4463. if len(execution_frequency) > 0 {
  4464. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and is_settle = ? and execution_frequency = ?"
  4465. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4466. } else {
  4467. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  4468. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4469. }
  4470. } else {
  4471. if len(execution_frequency) > 0 {
  4472. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and execution_frequency = ?"
  4473. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4474. } else {
  4475. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ?"
  4476. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4477. }
  4478. }
  4479. } else {
  4480. if cost_type > 0 {
  4481. if len(execution_frequency) > 0 {
  4482. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  4483. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  4484. } else {
  4485. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ?"
  4486. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4487. }
  4488. } else {
  4489. if len(execution_frequency) > 0 {
  4490. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_frequency = ?"
  4491. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  4492. } else {
  4493. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  4494. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4495. }
  4496. }
  4497. }
  4498. }
  4499. }
  4500. } else if adviceType == 3 {
  4501. if patientType == 0 {
  4502. if patient_id > 0 {
  4503. if execution_state > 0 {
  4504. if cost_type > 0 {
  4505. if len(execution_frequency) > 0 {
  4506. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency =?"
  4507. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4508. } else {
  4509. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  4510. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4511. }
  4512. } else {
  4513. if len(execution_frequency) > 0 {
  4514. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency =?"
  4515. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4516. } else {
  4517. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ?"
  4518. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4519. }
  4520. }
  4521. } else {
  4522. if cost_type > 0 {
  4523. if len(execution_frequency) > 0 {
  4524. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency =?"
  4525. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4526. } else {
  4527. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? "
  4528. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4529. }
  4530. } else {
  4531. if len(execution_frequency) > 0 {
  4532. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_frequency =?"
  4533. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4534. } else {
  4535. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? "
  4536. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4537. }
  4538. }
  4539. }
  4540. } else {
  4541. if execution_state > 0 {
  4542. if cost_type > 0 {
  4543. if len(execution_frequency) > 0 {
  4544. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ? and execution_frequency =?"
  4545. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4546. } else {
  4547. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ?"
  4548. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4549. }
  4550. } else {
  4551. if len(execution_frequency) > 0 {
  4552. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and execution_frequency =?"
  4553. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4554. } else {
  4555. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? "
  4556. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4557. }
  4558. }
  4559. } else {
  4560. if cost_type > 0 {
  4561. if len(execution_frequency) > 0 {
  4562. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? and execution_frequency =?"
  4563. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  4564. } else {
  4565. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? "
  4566. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4567. }
  4568. } else {
  4569. if len(execution_frequency) > 0 {
  4570. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_frequency =?"
  4571. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  4572. } else {
  4573. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  4574. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4575. }
  4576. }
  4577. }
  4578. }
  4579. } else if patientType == 1 {
  4580. if patient_id > 0 {
  4581. if execution_state > 0 {
  4582. if cost_type > 0 {
  4583. if len(execution_frequency) > 0 {
  4584. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  4585. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  4586. } else {
  4587. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  4588. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  4589. }
  4590. } else {
  4591. if len(execution_frequency) > 0 {
  4592. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  4593. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  4594. } else {
  4595. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  4596. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  4597. }
  4598. }
  4599. } else {
  4600. if cost_type > 0 {
  4601. if len(execution_frequency) > 0 {
  4602. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  4603. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  4604. } else {
  4605. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  4606. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  4607. }
  4608. } else {
  4609. if len(execution_frequency) > 0 {
  4610. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  4611. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  4612. } else {
  4613. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
  4614. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  4615. }
  4616. }
  4617. }
  4618. } else {
  4619. if execution_state > 0 {
  4620. if cost_type > 0 {
  4621. if len(execution_frequency) > 0 {
  4622. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? and is_settle = ? and execution_frequency = ?"
  4623. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  4624. } else {
  4625. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? and is_settle = ?"
  4626. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  4627. }
  4628. } else {
  4629. if len(execution_frequency) > 0 {
  4630. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =?and execution_frequency = ? "
  4631. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  4632. } else {
  4633. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? "
  4634. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  4635. }
  4636. }
  4637. } else {
  4638. if cost_type > 0 {
  4639. if len(execution_frequency) > 0 {
  4640. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  4641. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  4642. } else {
  4643. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ?"
  4644. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  4645. }
  4646. } else {
  4647. if len(execution_frequency) > 0 {
  4648. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_frequency = ?"
  4649. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  4650. } else {
  4651. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  4652. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  4653. }
  4654. }
  4655. }
  4656. }
  4657. } else if patientType == 2 {
  4658. if patient_id > 0 {
  4659. if execution_state > 0 {
  4660. if cost_type > 0 {
  4661. if len(execution_frequency) > 0 {
  4662. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  4663. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4664. } else {
  4665. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ?"
  4666. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4667. }
  4668. } else {
  4669. if len(execution_frequency) > 0 {
  4670. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ? and execution_frequency = ?"
  4671. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4672. } else {
  4673. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  4674. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4675. }
  4676. }
  4677. } else {
  4678. if cost_type > 0 {
  4679. if len(execution_frequency) > 0 {
  4680. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and is_settle = ? and execution_frequency = ?"
  4681. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4682. } else {
  4683. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  4684. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4685. }
  4686. } else {
  4687. if len(execution_frequency) > 0 {
  4688. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_frequency = ?"
  4689. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4690. } else {
  4691. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ?"
  4692. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4693. }
  4694. }
  4695. }
  4696. } else {
  4697. if execution_state > 0 {
  4698. if cost_type > 0 {
  4699. if len(execution_frequency) > 0 {
  4700. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and is_settle = ? and execution_frequency = ?"
  4701. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4702. } else {
  4703. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and is_settle = ?"
  4704. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4705. }
  4706. } else {
  4707. if len(execution_frequency) > 0 {
  4708. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and execution_frequency = ?"
  4709. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4710. } else {
  4711. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ?"
  4712. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4713. }
  4714. }
  4715. } else {
  4716. if cost_type > 0 {
  4717. if len(execution_frequency) > 0 {
  4718. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  4719. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  4720. } else {
  4721. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ?"
  4722. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4723. }
  4724. } else {
  4725. if len(execution_frequency) > 0 {
  4726. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_frequency = ?"
  4727. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  4728. } else {
  4729. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  4730. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4731. }
  4732. }
  4733. }
  4734. }
  4735. }
  4736. } else if adviceType == 2 && len(deliverWay) > 0 {
  4737. if patientType == 0 {
  4738. if patient_id > 0 {
  4739. if execution_state > 0 {
  4740. if cost_type > 0 {
  4741. if len(execution_frequency) > 0 {
  4742. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  4743. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency)
  4744. } else {
  4745. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  4746. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  4747. }
  4748. } else {
  4749. if len(execution_frequency) > 0 {
  4750. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  4751. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency)
  4752. } else {
  4753. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  4754. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  4755. }
  4756. }
  4757. } else {
  4758. if cost_type > 0 {
  4759. if len(execution_frequency) > 0 {
  4760. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  4761. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency)
  4762. } else {
  4763. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and is_settle = ?"
  4764. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  4765. }
  4766. } else {
  4767. if len(execution_frequency) > 0 {
  4768. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_frequency = ?"
  4769. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency)
  4770. } else {
  4771. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ?"
  4772. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  4773. }
  4774. }
  4775. }
  4776. } else {
  4777. if execution_state > 0 {
  4778. if cost_type > 0 {
  4779. if len(execution_frequency) > 0 {
  4780. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  4781. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency)
  4782. } else {
  4783. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and is_settle = ?"
  4784. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  4785. }
  4786. } else {
  4787. if len(execution_frequency) > 0 {
  4788. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and execution_frequency = ?"
  4789. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency)
  4790. } else {
  4791. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ?"
  4792. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  4793. }
  4794. }
  4795. } else {
  4796. if cost_type > 0 {
  4797. if len(execution_frequency) > 0 {
  4798. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and is_settle = ? and execution_frequency = ?"
  4799. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, execution_frequency)
  4800. } else {
  4801. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and is_settle = ?"
  4802. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  4803. }
  4804. } else {
  4805. if len(execution_frequency) > 0 {
  4806. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_frequency = ?"
  4807. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_frequency)
  4808. } else {
  4809. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  4810. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  4811. }
  4812. }
  4813. }
  4814. }
  4815. } else if patientType == 1 {
  4816. if patient_id > 0 {
  4817. if execution_state > 0 {
  4818. if cost_type > 0 {
  4819. if len(execution_frequency) > 0 {
  4820. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  4821. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type, execution_frequency)
  4822. } else {
  4823. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  4824. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type)
  4825. }
  4826. } else {
  4827. if len(execution_frequency) > 0 {
  4828. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  4829. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, execution_frequency)
  4830. } else {
  4831. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  4832. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state)
  4833. }
  4834. }
  4835. } else {
  4836. if cost_type > 0 {
  4837. if len(execution_frequency) > 0 {
  4838. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  4839. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type, execution_frequency)
  4840. } else {
  4841. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and is_settle = ?"
  4842. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type)
  4843. }
  4844. } else {
  4845. if len(execution_frequency) > 0 {
  4846. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_frequency = ?"
  4847. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_frequency)
  4848. } else {
  4849. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ?"
  4850. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
  4851. }
  4852. }
  4853. }
  4854. } else {
  4855. if execution_state > 0 {
  4856. if cost_type > 0 {
  4857. if len(execution_frequency) > 0 {
  4858. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  4859. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type, execution_frequency)
  4860. } else {
  4861. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ? and is_settle = ?"
  4862. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type)
  4863. }
  4864. } else {
  4865. if len(execution_frequency) > 0 {
  4866. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ? and execution_frequency = ?"
  4867. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, execution_frequency)
  4868. } else {
  4869. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ?"
  4870. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state)
  4871. }
  4872. }
  4873. } else {
  4874. if cost_type > 0 {
  4875. if len(execution_frequency) > 0 {
  4876. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and is_settle = ? and execution_frequency = ?"
  4877. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type, execution_frequency)
  4878. } else {
  4879. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and is_settle = ?"
  4880. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type)
  4881. }
  4882. } else {
  4883. if len(execution_frequency) > 0 {
  4884. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_frequency = ?"
  4885. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_frequency)
  4886. } else {
  4887. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  4888. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  4889. }
  4890. }
  4891. }
  4892. }
  4893. } else if patientType == 2 {
  4894. if patient_id > 0 {
  4895. if execution_state > 0 {
  4896. if cost_type > 0 {
  4897. if len(execution_frequency) > 0 {
  4898. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  4899. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency)
  4900. } else {
  4901. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  4902. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  4903. }
  4904. } else {
  4905. if len(execution_frequency) > 0 {
  4906. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  4907. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency)
  4908. } else {
  4909. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ?"
  4910. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  4911. }
  4912. }
  4913. } else {
  4914. if cost_type > 0 {
  4915. if len(execution_frequency) > 0 {
  4916. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  4917. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency)
  4918. } else {
  4919. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and is_settle = ?"
  4920. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  4921. }
  4922. } else {
  4923. if len(execution_frequency) > 0 {
  4924. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_frequency = ?"
  4925. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency)
  4926. } else {
  4927. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ?"
  4928. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  4929. }
  4930. }
  4931. }
  4932. } else {
  4933. if execution_state > 0 {
  4934. if cost_type > 0 {
  4935. if len(execution_frequency) > 0 {
  4936. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  4937. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency)
  4938. } else {
  4939. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ? and is_settle = ?"
  4940. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  4941. }
  4942. } else {
  4943. if len(execution_frequency) > 0 {
  4944. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ? and execution_frequency = ?"
  4945. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency)
  4946. } else {
  4947. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ?"
  4948. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  4949. }
  4950. }
  4951. } else {
  4952. if cost_type > 0 {
  4953. if len(execution_frequency) > 0 {
  4954. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and is_settle = ?"
  4955. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  4956. } else {
  4957. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and is_settle = ?"
  4958. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  4959. }
  4960. } else {
  4961. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  4962. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  4963. }
  4964. }
  4965. }
  4966. }
  4967. } else if adviceType == 2 && len(deliverWay) <= 0 {
  4968. fmt.Println("寄哪里233223322323233232", patientType)
  4969. fmt.Println("patient_id", patient_id)
  4970. fmt.Println("execution_state000000", execution_state)
  4971. fmt.Println("cost_type", cost_type)
  4972. fmt.Println("len23323232", len(execution_frequency))
  4973. if patientType == 0 {
  4974. if patient_id > 0 {
  4975. if execution_state > 0 {
  4976. if cost_type > 0 {
  4977. if len(execution_frequency) > 0 {
  4978. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  4979. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4980. } else {
  4981. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  4982. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4983. }
  4984. } else {
  4985. if len(execution_frequency) > 0 {
  4986. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  4987. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4988. } else {
  4989. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ?"
  4990. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4991. }
  4992. }
  4993. } else {
  4994. if cost_type > 0 {
  4995. if len(execution_frequency) > 0 {
  4996. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  4997. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4998. } else {
  4999. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and is_settle = ?"
  5000. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5001. }
  5002. } else {
  5003. if len(execution_frequency) > 0 {
  5004. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_frequency = ?"
  5005. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  5006. } else {
  5007. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ?"
  5008. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5009. }
  5010. }
  5011. }
  5012. } else {
  5013. if execution_state > 0 {
  5014. if cost_type > 0 {
  5015. if len(execution_frequency) > 0 {
  5016. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5017. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  5018. } else {
  5019. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ? and is_settle = ?"
  5020. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5021. }
  5022. } else {
  5023. if len(execution_frequency) > 0 {
  5024. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?and execution_frequency = ?"
  5025. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  5026. } else {
  5027. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?"
  5028. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5029. }
  5030. }
  5031. } else {
  5032. if cost_type > 0 {
  5033. if len(execution_frequency) > 0 {
  5034. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and is_settle = ? and execution_frequency = ?"
  5035. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  5036. }
  5037. } else {
  5038. if len(execution_frequency) > 0 {
  5039. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_frequency = ?"
  5040. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  5041. } else {
  5042. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  5043. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5044. }
  5045. }
  5046. }
  5047. }
  5048. } else if patientType == 1 {
  5049. if patient_id > 0 {
  5050. if execution_state > 0 {
  5051. if cost_type > 0 {
  5052. if len(execution_frequency) > 0 {
  5053. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5054. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  5055. } else {
  5056. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  5057. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  5058. }
  5059. } else {
  5060. if len(execution_frequency) > 0 {
  5061. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  5062. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  5063. } else {
  5064. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  5065. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  5066. }
  5067. }
  5068. } else {
  5069. if cost_type > 0 {
  5070. if len(execution_frequency) > 0 {
  5071. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  5072. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  5073. } else {
  5074. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  5075. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  5076. }
  5077. } else {
  5078. if len(execution_frequency) > 0 {
  5079. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  5080. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  5081. } else {
  5082. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ?"
  5083. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  5084. }
  5085. }
  5086. }
  5087. } else {
  5088. if execution_state > 0 {
  5089. if cost_type > 0 {
  5090. if len(execution_frequency) > 0 {
  5091. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5092. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  5093. } else {
  5094. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ? and is_settle = ?"
  5095. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  5096. }
  5097. } else {
  5098. if len(execution_frequency) > 0 {
  5099. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ? and execution_frequency = ?"
  5100. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  5101. } else {
  5102. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ?"
  5103. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  5104. }
  5105. }
  5106. } else {
  5107. if cost_type > 0 {
  5108. if len(execution_frequency) > 0 {
  5109. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  5110. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  5111. } else {
  5112. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and is_settle = ?"
  5113. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  5114. }
  5115. } else {
  5116. if len(execution_frequency) > 0 {
  5117. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_frequency = ?"
  5118. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  5119. } else {
  5120. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?"
  5121. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  5122. }
  5123. }
  5124. }
  5125. }
  5126. } else if patientType == 2 {
  5127. if patient_id > 0 {
  5128. if execution_state > 0 {
  5129. if cost_type > 0 {
  5130. if len(execution_frequency) > 0 {
  5131. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency=?"
  5132. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  5133. } else {
  5134. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ?"
  5135. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5136. }
  5137. } else {
  5138. if len(execution_frequency) > 0 {
  5139. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ? and execution_frequency=?"
  5140. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  5141. } else {
  5142. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  5143. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5144. }
  5145. }
  5146. } else {
  5147. if cost_type > 0 {
  5148. if len(execution_frequency) > 0 {
  5149. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and is_settle = ? and execution_frequency=?"
  5150. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  5151. } else {
  5152. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  5153. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5154. }
  5155. } else {
  5156. if len(execution_frequency) > 0 {
  5157. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_frequency=?"
  5158. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  5159. } else {
  5160. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ?"
  5161. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5162. }
  5163. }
  5164. }
  5165. } else {
  5166. if execution_state > 0 {
  5167. if cost_type > 0 {
  5168. if len(execution_frequency) > 0 {
  5169. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5170. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  5171. } else {
  5172. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  5173. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5174. }
  5175. } else {
  5176. if len(execution_frequency) > 0 {
  5177. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ? and execution_frequency = ?"
  5178. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  5179. } else {
  5180. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ?"
  5181. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5182. }
  5183. }
  5184. } else {
  5185. if cost_type > 0 {
  5186. if len(execution_frequency) > 0 {
  5187. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  5188. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  5189. } else {
  5190. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and is_settle = ?"
  5191. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5192. }
  5193. } else {
  5194. if len(execution_frequency) > 0 {
  5195. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_frequency = ?"
  5196. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  5197. } else {
  5198. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  5199. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5200. }
  5201. }
  5202. }
  5203. }
  5204. }
  5205. }
  5206. db := readDb.Table("xt_schedule")
  5207. if scheduleType > 0 {
  5208. db = db.Where("schedule_type = ?", scheduleType)
  5209. }
  5210. if partitonType > 0 {
  5211. db = db.Where("partition_id = ?", partitonType)
  5212. }
  5213. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  5214. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  5215. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  5216. }).
  5217. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  5218. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  5219. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  5220. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  5221. Preload("DoctorAdvices", adviceCondition...).
  5222. Where("status = 1 AND user_org_id = ?", orgID)
  5223. if scheduleDate != 0 {
  5224. db = db.Where("schedule_date = ?", scheduleDate)
  5225. }
  5226. err := db.Find(&vms).Error
  5227. return vms, err
  5228. }
  5229. func MobileGetScheduleDoctorAdvicesSevenList(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string, scheduleType int64, partitonType int64, patient_id int64, execution_state int64, cost_type int64) ([]*MScheduleDoctorAdviceVM, error) {
  5230. var vms []*MScheduleDoctorAdviceVM
  5231. adviceWhere := ""
  5232. adviceCondition := []interface{}{}
  5233. if adviceType == 0 {
  5234. if patientType == 0 {
  5235. if patient_id > 0 {
  5236. if execution_state > 0 {
  5237. if cost_type > 0 {
  5238. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ? and is_settle = ?"
  5239. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5240. } else {
  5241. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  5242. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5243. }
  5244. } else {
  5245. if cost_type > 0 {
  5246. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and is_settle = ?"
  5247. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5248. } else {
  5249. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
  5250. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5251. }
  5252. }
  5253. } else {
  5254. if execution_state > 0 {
  5255. if cost_type > 0 {
  5256. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and is_settle = ?"
  5257. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5258. } else {
  5259. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ?"
  5260. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5261. }
  5262. } else {
  5263. if cost_type > 0 {
  5264. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ?"
  5265. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5266. } else {
  5267. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  5268. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5269. }
  5270. }
  5271. }
  5272. } else if patientType == 1 {
  5273. if patient_id > 0 {
  5274. if execution_state > 0 {
  5275. if cost_type > 0 {
  5276. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ? and is_settle = ?"
  5277. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  5278. } else {
  5279. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  5280. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  5281. }
  5282. } else {
  5283. if cost_type > 0 {
  5284. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ? and is_settle=?"
  5285. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  5286. } else {
  5287. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
  5288. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  5289. }
  5290. }
  5291. } else {
  5292. if execution_state > 0 {
  5293. if cost_type > 0 {
  5294. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ? and is_settle=?"
  5295. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  5296. } else {
  5297. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  5298. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  5299. }
  5300. } else {
  5301. if cost_type > 0 {
  5302. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and is_settle=?"
  5303. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  5304. } else {
  5305. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  5306. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  5307. }
  5308. }
  5309. }
  5310. } else if patientType == 2 {
  5311. if patient_id > 0 {
  5312. if execution_state > 0 {
  5313. if cost_type > 0 {
  5314. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?) and execution_state = ? and is_settle=?"
  5315. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5316. } else {
  5317. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?) and execution_state = ?"
  5318. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5319. }
  5320. } else {
  5321. if cost_type > 0 {
  5322. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?) and is_settle=?"
  5323. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5324. } else {
  5325. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?)"
  5326. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5327. }
  5328. }
  5329. } else {
  5330. if execution_state > 0 {
  5331. if cost_type > 0 {
  5332. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1) and execution_state = ? and is_settle=?"
  5333. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5334. } else {
  5335. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  5336. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5337. }
  5338. } else {
  5339. if cost_type > 0 {
  5340. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1) and is_settle = ?"
  5341. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5342. } else {
  5343. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  5344. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5345. }
  5346. }
  5347. }
  5348. }
  5349. } else if adviceType == 1 {
  5350. if patientType == 0 {
  5351. if patient_id > 0 {
  5352. if execution_state > 0 {
  5353. if cost_type > 0 {
  5354. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  5355. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5356. } else {
  5357. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ?"
  5358. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5359. }
  5360. } else {
  5361. if cost_type > 0 {
  5362. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? "
  5363. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5364. } else {
  5365. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
  5366. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5367. }
  5368. }
  5369. } else {
  5370. if execution_state > 0 {
  5371. if cost_type > 0 {
  5372. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ?"
  5373. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5374. } else {
  5375. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ?"
  5376. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5377. }
  5378. } else {
  5379. if cost_type > 0 {
  5380. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = ? "
  5381. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5382. } else {
  5383. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  5384. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5385. }
  5386. }
  5387. }
  5388. } else if patientType == 1 {
  5389. if patient_id > 0 {
  5390. if execution_state > 0 {
  5391. if cost_type > 0 {
  5392. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  5393. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  5394. } else {
  5395. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  5396. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  5397. }
  5398. } else {
  5399. if cost_type > 0 {
  5400. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  5401. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  5402. } else {
  5403. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
  5404. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  5405. }
  5406. }
  5407. } else {
  5408. if execution_state > 0 {
  5409. if cost_type > 0 {
  5410. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=? and is_settle = ?"
  5411. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  5412. } else {
  5413. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?"
  5414. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  5415. }
  5416. } else {
  5417. if cost_type > 0 {
  5418. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? "
  5419. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  5420. } else {
  5421. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  5422. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  5423. }
  5424. }
  5425. }
  5426. } else if patientType == 2 {
  5427. if patient_id > 0 {
  5428. if execution_state > 0 {
  5429. if cost_type > 0 {
  5430. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ?"
  5431. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5432. } else {
  5433. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  5434. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5435. }
  5436. } else {
  5437. if cost_type > 0 {
  5438. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  5439. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5440. } else {
  5441. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
  5442. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5443. }
  5444. }
  5445. } else {
  5446. if execution_state > 0 {
  5447. if cost_type > 0 {
  5448. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  5449. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5450. } else {
  5451. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ?"
  5452. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5453. }
  5454. } else {
  5455. if cost_type > 0 {
  5456. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ?"
  5457. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5458. } else {
  5459. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  5460. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5461. }
  5462. }
  5463. }
  5464. }
  5465. } else if adviceType == 3 {
  5466. if patientType == 0 {
  5467. if patient_id > 0 {
  5468. if execution_state > 0 {
  5469. if cost_type > 0 {
  5470. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  5471. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5472. } else {
  5473. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ?"
  5474. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5475. }
  5476. } else {
  5477. if cost_type > 0 {
  5478. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? "
  5479. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5480. } else {
  5481. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? "
  5482. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5483. }
  5484. }
  5485. } else {
  5486. if execution_state > 0 {
  5487. if cost_type > 0 {
  5488. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ?"
  5489. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5490. } else {
  5491. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? "
  5492. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5493. }
  5494. } else {
  5495. if cost_type > 0 {
  5496. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? "
  5497. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5498. } else {
  5499. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  5500. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5501. }
  5502. }
  5503. }
  5504. } else if patientType == 1 {
  5505. if patient_id > 0 {
  5506. if execution_state > 0 {
  5507. if cost_type > 0 {
  5508. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  5509. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  5510. } else {
  5511. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  5512. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  5513. }
  5514. } else {
  5515. if cost_type > 0 {
  5516. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  5517. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  5518. } else {
  5519. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
  5520. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  5521. }
  5522. }
  5523. } else {
  5524. if execution_state > 0 {
  5525. if cost_type > 0 {
  5526. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? and is_settle = ?"
  5527. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  5528. } else {
  5529. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? "
  5530. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  5531. }
  5532. } else {
  5533. if cost_type > 0 {
  5534. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ?"
  5535. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  5536. } else {
  5537. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  5538. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  5539. }
  5540. }
  5541. }
  5542. } else if patientType == 2 {
  5543. if patient_id > 0 {
  5544. if execution_state > 0 {
  5545. if cost_type > 0 {
  5546. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ?"
  5547. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5548. } else {
  5549. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  5550. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5551. }
  5552. } else {
  5553. if cost_type > 0 {
  5554. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  5555. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5556. } else {
  5557. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ?"
  5558. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5559. }
  5560. }
  5561. } else {
  5562. if execution_state > 0 {
  5563. if cost_type > 0 {
  5564. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and is_settle = ?"
  5565. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5566. } else {
  5567. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ?"
  5568. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5569. }
  5570. } else {
  5571. if cost_type > 0 {
  5572. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ?"
  5573. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5574. } else {
  5575. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  5576. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5577. }
  5578. }
  5579. }
  5580. }
  5581. } else if adviceType == 2 && len(deliverWay) > 0 {
  5582. if patientType == 0 {
  5583. if patient_id > 0 {
  5584. if execution_state > 0 {
  5585. if cost_type > 0 {
  5586. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  5587. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  5588. } else {
  5589. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  5590. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  5591. }
  5592. } else {
  5593. if cost_type > 0 {
  5594. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and is_settle = ?"
  5595. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  5596. } else {
  5597. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ?"
  5598. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  5599. }
  5600. }
  5601. } else {
  5602. if execution_state > 0 {
  5603. if cost_type > 0 {
  5604. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and is_settle = ?"
  5605. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  5606. } else {
  5607. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ?"
  5608. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  5609. }
  5610. } else {
  5611. if cost_type > 0 {
  5612. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and is_settle = ?"
  5613. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  5614. } else {
  5615. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  5616. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  5617. }
  5618. }
  5619. }
  5620. } else if patientType == 1 {
  5621. if patient_id > 0 {
  5622. if execution_state > 0 {
  5623. if cost_type > 0 {
  5624. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  5625. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type)
  5626. } else {
  5627. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  5628. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state)
  5629. }
  5630. } else {
  5631. if cost_type > 0 {
  5632. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and is_settle = ?"
  5633. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type)
  5634. } else {
  5635. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ?"
  5636. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
  5637. }
  5638. }
  5639. } else {
  5640. if execution_state > 0 {
  5641. if cost_type > 0 {
  5642. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ? and is_settle = ?"
  5643. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type)
  5644. } else {
  5645. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ?"
  5646. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state)
  5647. }
  5648. } else {
  5649. if cost_type > 0 {
  5650. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and is_settle = ?"
  5651. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type)
  5652. } else {
  5653. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  5654. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  5655. }
  5656. }
  5657. }
  5658. } else if patientType == 2 {
  5659. if patient_id > 0 {
  5660. if execution_state > 0 {
  5661. if cost_type > 0 {
  5662. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  5663. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  5664. } else {
  5665. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ?"
  5666. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  5667. }
  5668. } else {
  5669. if cost_type > 0 {
  5670. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and is_settle = ?"
  5671. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  5672. } else {
  5673. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ?"
  5674. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  5675. }
  5676. }
  5677. } else {
  5678. if execution_state > 0 {
  5679. if cost_type > 0 {
  5680. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ? and is_settle = ?"
  5681. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  5682. } else {
  5683. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ?"
  5684. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  5685. }
  5686. } else {
  5687. if cost_type > 0 {
  5688. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and is_settle = ?"
  5689. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  5690. } else {
  5691. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  5692. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  5693. }
  5694. }
  5695. }
  5696. }
  5697. } else if adviceType == 2 && len(deliverWay) <= 0 {
  5698. if patientType == 0 {
  5699. if patient_id > 0 {
  5700. if execution_state > 0 {
  5701. if cost_type > 0 {
  5702. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  5703. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5704. } else {
  5705. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ?"
  5706. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5707. }
  5708. } else {
  5709. if cost_type > 0 {
  5710. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and is_settle = ?"
  5711. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5712. } else {
  5713. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ?"
  5714. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5715. }
  5716. }
  5717. } else {
  5718. if execution_state > 0 {
  5719. if cost_type > 0 {
  5720. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ? and is_settle = ?"
  5721. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5722. } else {
  5723. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?"
  5724. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5725. }
  5726. } else {
  5727. if cost_type > 0 {
  5728. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and is_settle = ?"
  5729. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5730. } else {
  5731. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  5732. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5733. }
  5734. }
  5735. }
  5736. } else if patientType == 1 {
  5737. if patient_id > 0 {
  5738. if execution_state > 0 {
  5739. if cost_type > 0 {
  5740. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  5741. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  5742. } else {
  5743. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  5744. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  5745. }
  5746. } else {
  5747. if cost_type > 0 {
  5748. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  5749. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  5750. } else {
  5751. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ?"
  5752. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  5753. }
  5754. }
  5755. } else {
  5756. if execution_state > 0 {
  5757. if cost_type > 0 {
  5758. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ? and is_settle = ?"
  5759. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  5760. } else {
  5761. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ?"
  5762. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  5763. }
  5764. } else {
  5765. if cost_type > 0 {
  5766. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and is_settle = ?"
  5767. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  5768. } else {
  5769. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?"
  5770. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  5771. }
  5772. }
  5773. }
  5774. } else if patientType == 2 {
  5775. if patient_id > 0 {
  5776. if execution_state > 0 {
  5777. if cost_type > 0 {
  5778. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ?"
  5779. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5780. } else {
  5781. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  5782. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5783. }
  5784. } else {
  5785. if cost_type > 0 {
  5786. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  5787. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5788. } else {
  5789. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ?"
  5790. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5791. }
  5792. }
  5793. } else {
  5794. if execution_state > 0 {
  5795. if cost_type > 0 {
  5796. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  5797. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5798. } else {
  5799. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ?"
  5800. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5801. }
  5802. } else {
  5803. if cost_type > 0 {
  5804. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and is_settle = ?"
  5805. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5806. } else {
  5807. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  5808. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5809. }
  5810. }
  5811. }
  5812. }
  5813. }
  5814. db := readDb.Table("xt_schedule")
  5815. if scheduleType > 0 {
  5816. db = db.Where("schedule_type = ?", scheduleType)
  5817. }
  5818. if partitonType > 0 {
  5819. db = db.Where("partition_id = ?", partitonType)
  5820. }
  5821. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  5822. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  5823. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  5824. }).
  5825. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  5826. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  5827. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  5828. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  5829. Preload("DoctorAdvices", adviceCondition...).
  5830. Where("status = 1 AND user_org_id = ?", orgID)
  5831. if scheduleDate != 0 {
  5832. db = db.Where("schedule_date = ?", scheduleDate)
  5833. }
  5834. err := db.Find(&vms).Error
  5835. return vms, err
  5836. }
  5837. func GetLastPatientOrder(id int64) (models.XtDialysisOrder, error) {
  5838. order := models.XtDialysisOrder{}
  5839. err := XTReadDB().Where("id = ? and status = 1", id).Find(&order).Error
  5840. return order, err
  5841. }
  5842. func UpdateMobilePatient(org_id int64, patient_id int64, schedule_remark string) error {
  5843. order := models.XtPatients{}
  5844. err := XTWriteDB().Model(&order).Where("user_org_id = ? and id = ? and status = 1", org_id, patient_id).Updates(map[string]interface{}{"schedule_remark": schedule_remark}).Error
  5845. err = XTWriteDB().Model(models.XtPatientsNew{}).Where("user_org_id = ? and id = ? and status = 1", org_id, patient_id).Updates(map[string]interface{}{"schedule_remark": schedule_remark}).Error
  5846. return err
  5847. }
  5848. func GetDialysisTotalCount(org_id int64, patient_id int64) (models.BloodDialysisOrderCount, error) {
  5849. order := models.BloodDialysisOrderCount{}
  5850. db := XTReadDB().Table("xt_dialysis_order as o")
  5851. err = db.Raw("select count(o.id) as count,o.patient_id from xt_dialysis_order as o left join xt_schedule as x on x.patient_id = o.patient_id where o.status =1 and o.user_org_id = ? and o.patient_id = ? and x.schedule_date = o.dialysis_date and x.status = 1 ", org_id, patient_id).Scan(&order).Error
  5852. return order, err
  5853. }
  5854. func GetDialysisTotalCountOne(org_id int64, patient_id int64) (models.BloodDialysisOrderCount, error) {
  5855. order := models.BloodDialysisOrderCount{}
  5856. db := XTReadDB().Table("xt_dialysis_order as o")
  5857. err = db.Raw("select count(o.id) as count,o.patient_id from xt_dialysis_order as o left join xt_schedule as x on x.patient_id = o.patient_id where o.status =1 and o.user_org_id = ? and o.patient_id = ? and o.dialysis_date>=1672502400 and x.schedule_date = o.dialysis_date and x.status = 1 ", org_id, patient_id).Scan(&order).Error
  5858. return order, err
  5859. }
  5860. func UpdateDialysisOrder(patient_id int64, dialysis_date int64, user_org_id int64, dialysis_total int64) (models.DialysisOrder, error) {
  5861. order := models.DialysisOrder{}
  5862. err := XTWriteDB().Model(&order).Where("patient_id = ? and dialysis_date = ? and user_org_id = ? and status = 1", patient_id, dialysis_date, user_org_id).Updates(map[string]interface{}{"dialysis_total": dialysis_total}).Error
  5863. return order, err
  5864. }
  5865. func UpdateDeviceInformation(patientid int64, dialysis_date int64) error {
  5866. information := models.DeviceInformation{}
  5867. err := UserWriteDB().Model(&information).Where("patient_id = ? and date = ? and status = 1", patientid, dialysis_date).Update(map[string]interface{}{"status": 0}).Error
  5868. return err
  5869. }
  5870. func MobileGetDoubleCheckSix(orgID int64, patientID int64, recordDate int64) (models.DoubleCheck, error) {
  5871. var record models.DoubleCheck
  5872. err := readDb.Where("patient_id = ? and user_org_id = ? and status = 1 and check_date = ?", patientID, orgID, recordDate).First(&record).Error
  5873. return record, err
  5874. }
  5875. func GetFirstMonitor(patient_id int64, monit_date int64) (models.MonitoringRecord, error) {
  5876. record := models.MonitoringRecord{}
  5877. err := XTReadDB().Where("patient_id = ? and monitoring_date = ? and status=1", patient_id, monit_date).First(&record).Error
  5878. return record, err
  5879. }
  5880. func UpdateFirstMonitor(id int64, catheter_operation string) (models.MonitoringRecord, error) {
  5881. record := models.MonitoringRecord{}
  5882. err := XTWriteDB().Model(&record).Where("id = ? and status= 1", id).Updates(map[string]interface{}{"dispose": catheter_operation}).Error
  5883. return record, err
  5884. }
  5885. func GetHisDoctorAdvicesTwentyOne(orgID int64, scheduleDate int64, deliverWay string, scheduleType int64, partitionType int64, patient_id int64, execution_state int64, cost_type int64, execution_frequency string) ([]*HisMScheduleDoctorAdviceVM, error) {
  5886. var vms []*HisMScheduleDoctorAdviceVM
  5887. if len(deliverWay) > 0 {
  5888. db := readDb.Table("xt_schedule")
  5889. if scheduleType > 0 {
  5890. db = db.Where("schedule_type = ?", scheduleType)
  5891. }
  5892. if partitionType > 0 {
  5893. db = db.Where("partition_id = ?", partitionType)
  5894. }
  5895. if patient_id > 0 {
  5896. if execution_state > 0 {
  5897. if cost_type > 0 {
  5898. if len(execution_frequency) > 0 {
  5899. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  5900. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  5901. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  5902. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  5903. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle and execution_frequency = ?", orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency).
  5904. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  5905. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  5906. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  5907. Where("status = 1 AND user_org_id = ?", orgID)
  5908. if scheduleDate != 0 {
  5909. db = db.Where("schedule_date = ?", scheduleDate)
  5910. }
  5911. err = db.Find(&vms).Error
  5912. } else {
  5913. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  5914. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  5915. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  5916. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  5917. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle", orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type).
  5918. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  5919. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  5920. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  5921. Where("status = 1 AND user_org_id = ?", orgID)
  5922. if scheduleDate != 0 {
  5923. db = db.Where("schedule_date = ?", scheduleDate)
  5924. }
  5925. err = db.Find(&vms).Error
  5926. }
  5927. } else {
  5928. if len(execution_frequency) > 0 {
  5929. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  5930. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  5931. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  5932. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  5933. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and execution_frequency = ?", orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency).
  5934. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  5935. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  5936. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  5937. Where("status = 1 AND user_org_id = ?", orgID)
  5938. if scheduleDate != 0 {
  5939. db = db.Where("schedule_date = ?", scheduleDate)
  5940. }
  5941. err = db.Find(&vms).Error
  5942. } else {
  5943. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  5944. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  5945. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  5946. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  5947. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ? and execution_state = ?", orgID, scheduleDate, deliverWay, patient_id, execution_state).
  5948. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  5949. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  5950. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  5951. Where("status = 1 AND user_org_id = ?", orgID)
  5952. if scheduleDate != 0 {
  5953. db = db.Where("schedule_date = ?", scheduleDate)
  5954. }
  5955. err = db.Find(&vms).Error
  5956. }
  5957. }
  5958. } else {
  5959. if cost_type > 0 {
  5960. if len(execution_frequency) > 0 {
  5961. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  5962. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  5963. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  5964. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  5965. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ? and is_settle = ? and execution_frequency =?", orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency).
  5966. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  5967. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  5968. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  5969. Where("status = 1 AND user_org_id = ?", orgID)
  5970. if scheduleDate != 0 {
  5971. db = db.Where("schedule_date = ?", scheduleDate)
  5972. }
  5973. err = db.Find(&vms).Error
  5974. } else {
  5975. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  5976. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  5977. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  5978. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  5979. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ? and is_settle", orgID, scheduleDate, deliverWay, patient_id, cost_type).
  5980. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  5981. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  5982. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  5983. Where("status = 1 AND user_org_id = ?", orgID)
  5984. if scheduleDate != 0 {
  5985. db = db.Where("schedule_date = ?", scheduleDate)
  5986. }
  5987. err = db.Find(&vms).Error
  5988. }
  5989. } else {
  5990. if len(execution_frequency) > 0 {
  5991. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  5992. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  5993. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  5994. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  5995. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ? and execution_frequency = ?", orgID, scheduleDate, deliverWay, patient_id, execution_frequency).
  5996. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  5997. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  5998. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  5999. Where("status = 1 AND user_org_id = ?", orgID)
  6000. if scheduleDate != 0 {
  6001. db = db.Where("schedule_date = ?", scheduleDate)
  6002. }
  6003. err = db.Find(&vms).Error
  6004. } else {
  6005. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  6006. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6007. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6008. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  6009. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ?", orgID, scheduleDate, deliverWay, patient_id).
  6010. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6011. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6012. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6013. Where("status = 1 AND user_org_id = ?", orgID)
  6014. if scheduleDate != 0 {
  6015. db = db.Where("schedule_date = ?", scheduleDate)
  6016. }
  6017. err = db.Find(&vms).Error
  6018. }
  6019. }
  6020. }
  6021. } else {
  6022. if execution_state > 0 {
  6023. if cost_type > 0 {
  6024. if len(execution_frequency) > 0 {
  6025. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6026. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6027. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6028. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6029. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_state = ? and is_settle = ? and execution_frequency= ?", orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency).
  6030. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6031. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6032. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6033. Where("status = 1 AND user_org_id = ?", orgID)
  6034. if scheduleDate != 0 {
  6035. db = db.Where("schedule_date = ?", scheduleDate)
  6036. }
  6037. err = db.Find(&vms).Error
  6038. } else {
  6039. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6040. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6041. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6042. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6043. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_state = ? and is_settle = ?", orgID, scheduleDate, deliverWay, execution_state, cost_type).
  6044. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6045. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6046. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6047. Where("status = 1 AND user_org_id = ?", orgID)
  6048. if scheduleDate != 0 {
  6049. db = db.Where("schedule_date = ?", scheduleDate)
  6050. }
  6051. err = db.Find(&vms).Error
  6052. }
  6053. } else {
  6054. if len(execution_frequency) > 0 {
  6055. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6056. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6057. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6058. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6059. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_state = ? and execution_frequency =?", orgID, scheduleDate, deliverWay, execution_state, execution_frequency).
  6060. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6061. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6062. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6063. Where("status = 1 AND user_org_id = ?", orgID)
  6064. if scheduleDate != 0 {
  6065. db = db.Where("schedule_date = ?", scheduleDate)
  6066. }
  6067. err = db.Find(&vms).Error
  6068. } else {
  6069. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6070. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6071. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6072. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6073. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_state = ?", orgID, scheduleDate, deliverWay, execution_state).
  6074. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6075. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6076. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6077. Where("status = 1 AND user_org_id = ?", orgID)
  6078. if scheduleDate != 0 {
  6079. db = db.Where("schedule_date = ?", scheduleDate)
  6080. }
  6081. err = db.Find(&vms).Error
  6082. }
  6083. }
  6084. } else {
  6085. if cost_type > 0 {
  6086. if len(execution_frequency) > 0 {
  6087. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6088. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6089. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6090. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6091. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and is_settle = ? and execution_frequency = ?", orgID, scheduleDate, deliverWay, cost_type, execution_frequency).
  6092. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6093. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6094. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6095. Where("status = 1 AND user_org_id = ?", orgID)
  6096. if scheduleDate != 0 {
  6097. db = db.Where("schedule_date = ?", scheduleDate)
  6098. }
  6099. err = db.Find(&vms).Error
  6100. } else {
  6101. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6102. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6103. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6104. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6105. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and is_settle = ?", orgID, scheduleDate, deliverWay, cost_type).
  6106. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6107. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6108. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6109. Where("status = 1 AND user_org_id = ?", orgID)
  6110. if scheduleDate != 0 {
  6111. db = db.Where("schedule_date = ?", scheduleDate)
  6112. }
  6113. err = db.Find(&vms).Error
  6114. }
  6115. } else {
  6116. if len(execution_frequency) > 0 {
  6117. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6118. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6119. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6120. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6121. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_frequency = ?", orgID, scheduleDate, deliverWay, execution_frequency).
  6122. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6123. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6124. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6125. Where("status = 1 AND user_org_id = ?", orgID)
  6126. if scheduleDate != 0 {
  6127. db = db.Where("schedule_date = ?", scheduleDate)
  6128. }
  6129. err = db.Find(&vms).Error
  6130. } else {
  6131. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6132. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6133. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6134. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6135. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  6136. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6137. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6138. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6139. Where("status = 1 AND user_org_id = ?", orgID)
  6140. if scheduleDate != 0 {
  6141. db = db.Where("schedule_date = ?", scheduleDate)
  6142. }
  6143. err = db.Find(&vms).Error
  6144. }
  6145. }
  6146. }
  6147. }
  6148. } else {
  6149. db := readDb.Table("xt_schedule")
  6150. if scheduleType > 0 {
  6151. db = db.Where("schedule_type = ?", scheduleType)
  6152. }
  6153. if partitionType > 0 {
  6154. db = db.Where("partition_id = ?", partitionType)
  6155. }
  6156. if patient_id > 0 {
  6157. if execution_state > 0 {
  6158. if cost_type > 0 {
  6159. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  6160. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6161. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6162. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  6163. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and execution_state = ? and is_settle = ?", orgID, scheduleDate, patient_id, execution_state, cost_type).
  6164. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6165. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6166. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6167. Where("status = 1 AND user_org_id = ?", orgID)
  6168. if scheduleDate != 0 {
  6169. db = db.Where("schedule_date = ?", scheduleDate)
  6170. }
  6171. err = db.Find(&vms).Error
  6172. } else {
  6173. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  6174. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6175. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6176. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  6177. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and execution_state = ?", orgID, scheduleDate, patient_id, execution_state).
  6178. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6179. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6180. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6181. Where("status = 1 AND user_org_id = ?", orgID)
  6182. if scheduleDate != 0 {
  6183. db = db.Where("schedule_date = ?", scheduleDate)
  6184. }
  6185. err = db.Find(&vms).Error
  6186. }
  6187. } else {
  6188. if cost_type > 0 {
  6189. if len(execution_frequency) > 0 {
  6190. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  6191. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6192. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6193. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  6194. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and is_settle = ? and execution_frequency = ?", orgID, scheduleDate, patient_id, cost_type, execution_frequency).
  6195. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6196. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6197. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6198. Where("status = 1 AND user_org_id = ?", orgID)
  6199. if scheduleDate != 0 {
  6200. db = db.Where("schedule_date = ?", scheduleDate)
  6201. }
  6202. err = db.Find(&vms).Error
  6203. } else {
  6204. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  6205. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6206. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6207. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  6208. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and is_settle = ?", orgID, scheduleDate, patient_id, cost_type).
  6209. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6210. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6211. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6212. Where("status = 1 AND user_org_id = ?", orgID)
  6213. if scheduleDate != 0 {
  6214. db = db.Where("schedule_date = ?", scheduleDate)
  6215. }
  6216. err = db.Find(&vms).Error
  6217. }
  6218. } else {
  6219. if len(execution_frequency) > 0 {
  6220. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  6221. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6222. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6223. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  6224. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and execution_frequency = ?", orgID, scheduleDate, patient_id, execution_frequency).
  6225. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6226. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6227. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6228. Where("status = 1 AND user_org_id = ?", orgID)
  6229. if scheduleDate != 0 {
  6230. db = db.Where("schedule_date = ?", scheduleDate)
  6231. }
  6232. err = db.Find(&vms).Error
  6233. } else {
  6234. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  6235. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6236. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6237. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  6238. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  6239. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6240. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6241. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6242. Where("status = 1 AND user_org_id = ?", orgID)
  6243. if scheduleDate != 0 {
  6244. db = db.Where("schedule_date = ?", scheduleDate)
  6245. }
  6246. err = db.Find(&vms).Error
  6247. }
  6248. }
  6249. }
  6250. } else {
  6251. if execution_state > 0 {
  6252. if cost_type > 0 {
  6253. if len(execution_frequency) > 0 {
  6254. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6255. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6256. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6257. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6258. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ? and is_settle = ? and execution_frequency = ?", orgID, scheduleDate, execution_state, cost_type, execution_frequency).
  6259. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6260. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6261. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6262. Where("status = 1 AND user_org_id = ?", orgID)
  6263. if scheduleDate != 0 {
  6264. db = db.Where("schedule_date = ?", scheduleDate)
  6265. }
  6266. err = db.Find(&vms).Error
  6267. } else {
  6268. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6269. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6270. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6271. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6272. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ? and is_settle = ?", orgID, scheduleDate, execution_state, cost_type).
  6273. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6274. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6275. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6276. Where("status = 1 AND user_org_id = ?", orgID)
  6277. if scheduleDate != 0 {
  6278. db = db.Where("schedule_date = ?", scheduleDate)
  6279. }
  6280. err = db.Find(&vms).Error
  6281. }
  6282. } else {
  6283. if len(execution_frequency) > 0 {
  6284. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6285. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6286. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6287. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6288. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ? and execution_frequency = ?", orgID, scheduleDate, execution_state, execution_frequency).
  6289. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6290. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6291. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6292. Where("status = 1 AND user_org_id = ?", orgID)
  6293. if scheduleDate != 0 {
  6294. db = db.Where("schedule_date = ?", scheduleDate)
  6295. }
  6296. err = db.Find(&vms).Error
  6297. } else {
  6298. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6299. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6300. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6301. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6302. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ?", orgID, scheduleDate, execution_state).
  6303. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6304. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6305. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6306. Where("status = 1 AND user_org_id = ?", orgID)
  6307. if scheduleDate != 0 {
  6308. db = db.Where("schedule_date = ?", scheduleDate)
  6309. }
  6310. err = db.Find(&vms).Error
  6311. }
  6312. }
  6313. } else {
  6314. if cost_type > 0 {
  6315. if len(execution_frequency) > 0 {
  6316. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6317. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6318. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6319. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6320. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and is_settle = ?", orgID, scheduleDate, cost_type).
  6321. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6322. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6323. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6324. Where("status = 1 AND user_org_id = ?", orgID)
  6325. if scheduleDate != 0 {
  6326. db = db.Where("schedule_date = ?", scheduleDate)
  6327. }
  6328. err = db.Find(&vms).Error
  6329. } else {
  6330. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6331. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6332. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6333. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6334. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and is_settle = ? and execution_frequency = ?", orgID, scheduleDate, cost_type, execution_frequency).
  6335. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6336. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6337. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6338. Where("status = 1 AND user_org_id = ?", orgID)
  6339. if scheduleDate != 0 {
  6340. db = db.Where("schedule_date = ?", scheduleDate)
  6341. }
  6342. err = db.Find(&vms).Error
  6343. }
  6344. } else {
  6345. if len(execution_frequency) > 0 {
  6346. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6347. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6348. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6349. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6350. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_frequency = ?", orgID, scheduleDate, execution_frequency).
  6351. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6352. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6353. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6354. Where("status = 1 AND user_org_id = ?", orgID)
  6355. if scheduleDate != 0 {
  6356. db = db.Where("schedule_date = ?", scheduleDate)
  6357. }
  6358. err = db.Find(&vms).Error
  6359. } else {
  6360. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6361. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6362. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6363. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6364. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ?", orgID, scheduleDate).
  6365. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6366. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6367. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6368. Where("status = 1 AND user_org_id = ?", orgID)
  6369. if scheduleDate != 0 {
  6370. db = db.Where("schedule_date = ?", scheduleDate)
  6371. }
  6372. err = db.Find(&vms).Error
  6373. }
  6374. }
  6375. }
  6376. }
  6377. }
  6378. return vms, err
  6379. }
  6380. func GetPatientDryWeight(org_id int64, patient_id int64) (weight []*models.SgjPatientDryweight, err error) {
  6381. err = XTReadDB().Where("user_org_id = ? and patient_id = ? and status =1", org_id, patient_id).Order("id desc").Limit(6).Find(&weight).Error
  6382. return weight, err
  6383. }
  6384. func MobileGetLongScheduleDoctorAdvices(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string, scheduleType int64, partitonType int64, patient_id int64, execution_state int64, cost_type int64, execution_frequency string) ([]*MScheduleDoctorAdviceVM, error) {
  6385. var vms []*MScheduleDoctorAdviceVM
  6386. adviceWhere := ""
  6387. adviceCondition := []interface{}{}
  6388. if adviceType == 1 {
  6389. if patientType == 0 {
  6390. if patient_id > 0 {
  6391. if execution_state > 0 {
  6392. if cost_type > 0 {
  6393. if len(execution_frequency) > 0 {
  6394. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  6395. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency)
  6396. } else {
  6397. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ?"
  6398. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type)
  6399. }
  6400. } else {
  6401. if len(execution_frequency) > 0 {
  6402. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and execution_frequency = ?"
  6403. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency)
  6404. } else {
  6405. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ?"
  6406. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state)
  6407. }
  6408. }
  6409. } else {
  6410. if cost_type > 0 {
  6411. if len(execution_frequency) > 0 {
  6412. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and execution_frequency = ?"
  6413. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency)
  6414. } else {
  6415. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? "
  6416. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type)
  6417. }
  6418. } else {
  6419. if len(execution_frequency) > 0 {
  6420. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_frequency = ?"
  6421. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency)
  6422. } else {
  6423. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? "
  6424. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id)
  6425. }
  6426. }
  6427. }
  6428. } else {
  6429. if execution_state > 0 {
  6430. if cost_type > 0 {
  6431. if len(execution_frequency) > 0 {
  6432. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and execution_frequency = ?"
  6433. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency)
  6434. } else {
  6435. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ?"
  6436. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type)
  6437. }
  6438. } else {
  6439. if len(execution_frequency) > 0 {
  6440. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and execution_frequency = ?"
  6441. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency)
  6442. } else {
  6443. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ?"
  6444. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state)
  6445. }
  6446. }
  6447. } else {
  6448. if cost_type > 0 {
  6449. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and is_settle = ? "
  6450. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type)
  6451. } else {
  6452. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 "
  6453. adviceCondition = append(adviceCondition, adviceWhere, orgID)
  6454. }
  6455. }
  6456. }
  6457. } else if patientType == 1 {
  6458. if patient_id > 0 {
  6459. if execution_state > 0 {
  6460. if cost_type > 0 {
  6461. if len(execution_frequency) > 0 {
  6462. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  6463. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  6464. } else {
  6465. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  6466. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type)
  6467. }
  6468. } else {
  6469. if len(execution_frequency) > 0 {
  6470. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  6471. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, execution_frequency)
  6472. } else {
  6473. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  6474. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state)
  6475. }
  6476. }
  6477. } else {
  6478. if cost_type > 0 {
  6479. if len(execution_frequency) > 0 {
  6480. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ?and execution_frequency = ?"
  6481. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, execution_frequency)
  6482. } else {
  6483. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  6484. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type)
  6485. }
  6486. } else {
  6487. if len(execution_frequency) > 0 {
  6488. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  6489. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_frequency)
  6490. } else {
  6491. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ?"
  6492. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id)
  6493. }
  6494. }
  6495. }
  6496. } else {
  6497. if execution_state > 0 {
  6498. if cost_type > 0 {
  6499. if len(execution_frequency) > 0 {
  6500. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ?and execution_frequency = ?"
  6501. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, execution_frequency)
  6502. } else {
  6503. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ?"
  6504. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type)
  6505. }
  6506. } else {
  6507. if len(execution_frequency) > 0 {
  6508. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=?and execution_frequency = ?"
  6509. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, execution_frequency)
  6510. } else {
  6511. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=?"
  6512. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state)
  6513. }
  6514. }
  6515. } else {
  6516. if cost_type > 0 {
  6517. if len(execution_frequency) > 0 {
  6518. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  6519. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, execution_frequency)
  6520. } else {
  6521. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? "
  6522. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type)
  6523. }
  6524. } else {
  6525. if len(execution_frequency) > 0 {
  6526. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_frequency = ?"
  6527. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_frequency)
  6528. } else {
  6529. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? "
  6530. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId)
  6531. }
  6532. }
  6533. }
  6534. }
  6535. } else if patientType == 2 {
  6536. if patient_id > 0 {
  6537. if execution_state > 0 {
  6538. if cost_type > 0 {
  6539. if len(execution_frequency) > 0 {
  6540. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ?and execution_frequency = ?"
  6541. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency)
  6542. } else {
  6543. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ?"
  6544. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type)
  6545. }
  6546. } else {
  6547. if len(execution_frequency) > 0 {
  6548. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and execution_frequency = ?"
  6549. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency)
  6550. } else {
  6551. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  6552. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state)
  6553. }
  6554. }
  6555. } else {
  6556. if cost_type > 0 {
  6557. if len(execution_frequency) > 0 {
  6558. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and is_settle = ? and execution_frequency = ?"
  6559. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency)
  6560. } else {
  6561. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  6562. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type)
  6563. }
  6564. } else {
  6565. if len(execution_frequency) > 0 {
  6566. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_frequency = ?"
  6567. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency)
  6568. } else {
  6569. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ?"
  6570. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id)
  6571. }
  6572. }
  6573. }
  6574. } else {
  6575. if execution_state > 0 {
  6576. if cost_type > 0 {
  6577. if len(execution_frequency) > 0 {
  6578. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ? and execution_frequency = ?"
  6579. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency)
  6580. } else {
  6581. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  6582. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type)
  6583. }
  6584. } else {
  6585. if len(execution_frequency) > 0 {
  6586. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ? and execution_frequency = ?"
  6587. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency)
  6588. } else {
  6589. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ?"
  6590. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state)
  6591. }
  6592. }
  6593. } else {
  6594. if cost_type > 0 {
  6595. if len(execution_frequency) > 0 {
  6596. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  6597. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, execution_frequency)
  6598. } else {
  6599. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ?"
  6600. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type)
  6601. }
  6602. } else {
  6603. if len(execution_frequency) > 0 {
  6604. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_frequency = ?"
  6605. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_frequency)
  6606. } else {
  6607. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0"
  6608. adviceCondition = append(adviceCondition, adviceWhere, orgID)
  6609. }
  6610. }
  6611. }
  6612. }
  6613. }
  6614. }
  6615. db := readDb.Table("xt_schedule")
  6616. if scheduleType > 0 {
  6617. db = db.Where("schedule_type = ?", scheduleType)
  6618. }
  6619. if partitonType > 0 {
  6620. db = db.Where("partition_id = ?", partitonType)
  6621. }
  6622. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6623. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6624. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6625. }).
  6626. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6627. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6628. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6629. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6630. Preload("DoctorAdvices", adviceCondition...).
  6631. Where("status = 1 AND user_org_id = ?", orgID)
  6632. if scheduleDate != 0 {
  6633. db = db.Where("schedule_date = ?", scheduleDate)
  6634. }
  6635. err := db.Find(&vms).Error
  6636. return vms, err
  6637. }