mobile_dialysis_service.go 529KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891
  1. package service
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "strconv"
  6. "time"
  7. "XT_New/models"
  8. "github.com/jinzhu/gorm"
  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. FirstLetter string `gorm:"column:first_letter" json:"first_letter" form:"first_letter"`
  172. }
  173. func (MSchedualPatientVMList) TableName() string {
  174. return "xt_patients"
  175. }
  176. type MSchedualPatientVM struct {
  177. ID int64 `gorm:"column:id" json:"id" form:"id"`
  178. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  179. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  180. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  181. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  182. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
  183. AdmissionNumber string `gorm:"column:admission_number" json:"admission_number" form:"admission_number"`
  184. Source int64 `gorm:"column:source" json:"source" form:"source"`
  185. Lapseto int64 `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
  186. PartitionId int64 `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
  187. BedId int64 `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
  188. Name string `gorm:"column:name" json:"name" form:"name"`
  189. Alias string `gorm:"column:alias" json:"alias" form:"alias"`
  190. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  191. Nation string `gorm:"column:nation" json:"nation" form:"nation"`
  192. NativePlace string `gorm:"column:native_place" json:"native_place" form:"native_place"`
  193. MaritalStatus int64 `gorm:"column:marital_status" json:"marital_status" form:"marital_status"`
  194. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  195. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  196. ReimbursementWayId int64 `gorm:"column:reimbursement_way_id" json:"reimbursement_way_id" form:"reimbursement_way_id"`
  197. HealthCareType int64 `gorm:"column:health_care_type" json:"health_care_type" form:"health_care_type"`
  198. HealthCareNo string `gorm:"column:health_care_no" json:"health_care_no" form:"health_care_no"`
  199. HealthCareDueDate int64 `gorm:"column:health_care_due_date" json:"health_care_due_date" form:"health_care_due_date"`
  200. Height int64 `gorm:"column:height" json:"height" form:"height"`
  201. BloodType int64 `gorm:"column:blood_type" json:"blood_type" form:"blood_type"`
  202. Rh int64 `gorm:"column:rh" json:"rh" form:"rh"`
  203. HealthCareDueAlertDate int64 `gorm:"column:health_care_due_alert_date" json:"health_care_due_alert_date" form:"health_care_due_alert_date"`
  204. EducationLevel int64 `gorm:"column:education_level" json:"education_level" form:"education_level"`
  205. Profession int64 `gorm:"column:profession" json:"profession" form:"profession"`
  206. Phone string `gorm:"column:phone" json:"phone" form:"phone"`
  207. HomeTelephone string `gorm:"column:home_telephone" json:"home_telephone" form:"home_telephone"`
  208. RelativePhone string `gorm:"column:relative_phone" json:"relative_phone" form:"relative_phone"`
  209. RelativeRelations string `gorm:"column:relative_relations" json:"relative_relations" form:"relative_relations"`
  210. HomeAddress string `gorm:"column:home_address" json:"home_address" form:"home_address"`
  211. WorkUnit string `gorm:"column:work_unit" json:"work_unit" form:"work_unit"`
  212. UnitAddress string `gorm:"column:unit_address" json:"unit_address" form:"unit_address"`
  213. Children int64 `gorm:"column:children" json:"children" form:"children"`
  214. ReceivingDate int64 `gorm:"column:receiving_date" json:"receiving_date" form:"receiving_date"`
  215. IsHospitalFirstDialysis int64 `gorm:"column:is_hospital_first_dialysis" json:"is_hospital_first_dialysis" form:"is_hospital_first_dialysis"`
  216. FirstDialysisDate int64 `gorm:"column:first_dialysis_date" json:"first_dialysis_date" form:"first_dialysis_date"`
  217. FirstDialysisHospital string `gorm:"column:first_dialysis_hospital" json:"first_dialysis_hospital" form:"first_dialysis_hospital"`
  218. InductionPeriod int64 `gorm:"column:induction_period" json:"induction_period" form:"induction_period"`
  219. InitialDialysis int64 `gorm:"column:initial_dialysis" json:"initial_dialysis" form:"initial_dialysis"`
  220. TotalDialysis int64 `gorm:"column:total_dialysis" json:"total_dialysis" form:"total_dialysis"`
  221. AttendingDoctorId int64 `gorm:"column:attending_doctor_id" json:"attending_doctor_id" form:"attending_doctor_id"`
  222. HeadNurseId int64 `gorm:"column:head_nurse_id" json:"head_nurse_id" form:"head_nurse_id"`
  223. Evaluate string `gorm:"column:evaluate" json:"evaluate" form:"evaluate"`
  224. Diagnose string `gorm:"column:diagnose" json:"diagnose" form:"diagnose"`
  225. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  226. RegistrarsId int64 `gorm:"column:registrars_id" json:"registrars_id" form:"registrars_id"`
  227. Registrars string `gorm:"column:registrars" json:"registrars" form:"registrars"`
  228. QrCode string `gorm:"column:qr_code" json:"qr_code" form:"qr_code"`
  229. BindingState int64 `gorm:"column:binding_state" json:"binding_state" form:"binding_state"`
  230. PatientComplains string `gorm:"column:patient_complains" json:"patient_complains"` // 主诉
  231. PresentHistory string `gorm:"column:present_history" json:"present_history"` // 现病史
  232. PastHistory string `gorm:"column:past_history" json:"past_history"` // 既往史
  233. Temperature float64 `gorm:"column:temperature" json:"temperature"` // 体格检查-体温
  234. Pulse int64 `gorm:"column:pulse" json:"pulse"` // 体格检查-脉搏
  235. Respiratory int64 `gorm:"column:respiratory" json:"respiratory"` // 体格检查-呼吸频率
  236. SBP int64 `gorm:"column:sbp" json:"sbp"` // 体格检查-收缩压
  237. DBP int64 `gorm:"column:dbp" json:"dbp"` // 体格检查-舒张压
  238. Status int64 `gorm:"column:status" json:"status" form:"status"`
  239. Age int64 `gorm:"column:age" json:"age"`
  240. IsOpenRemind int64 `gorm:"column:is_open_remind" json:"is_open_remind"`
  241. DialysisAge int64 `gorm:"column:dialysis_age" json:"dialysis_age" form:"dialysis_age"`
  242. ExpenseKind int64 `gorm:"column:expense_kind" json:"expense_kind" form:"expense_kind"`
  243. TellPhone string `gorm:"column:tell_phone" json:"tell_phone" form:"tell_phone"`
  244. FirstTreatmentDate int64 `gorm:"column:first_treatment_date" json:"first_treatment_date" form:"first_treatment_date"`
  245. ContactName string `gorm:"column:contact_name" json:"contact_name" form:"contact_name"`
  246. UserSysBeforeCount int64 `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
  247. FirstLetter string `gorm:"column:first_letter" json:"first_letter" form:"first_letter"`
  248. }
  249. func (MSchedualPatientVM) TableName() string {
  250. return "xt_patients"
  251. }
  252. type MDialysisOrderVM struct {
  253. ID int64 `gorm:"column:id" json:"id"`
  254. DialysisDate int64 `gorm:"column:dialysis_date" json:"dialysis_date"`
  255. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  256. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  257. Stage int64 `gorm:"column:stage" json:"stage"`
  258. BedID int64 `gorm:"column:bed_id" json:"bed_id"`
  259. StartNurse int64 `gorm:"column:start_nurse" json:"start_nurse"`
  260. FinishNurse int64 `gorm:"column:finish_nurse" json:"finish_nurse"`
  261. Status int64 `gorm:"column:status" json:"status"`
  262. PunctureNurse int64 `gorm:"column:puncture_nurse" json:"puncture_nurse"`
  263. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedID" json:"device_number"`
  264. MonitoringRecords []*models.MonitoringRecord `gorm:"ForeignKey:DialysisOrderId" json:"monitoring_records"`
  265. Creator int64 `gorm:"column:creator" json:"creator"`
  266. Modifier int64 `gorm:"column:modifier" json:"modifier"`
  267. FinishCreator int64 `gorm:"column:finish_creator" json:"finish_creator"`
  268. FinishModifier int64 `gorm:"column:finish_modifier" json:"finish_modifier"`
  269. SchedualType int64 `gorm:"column:schedual_type" json:"schedual_type"`
  270. WashpipeNurse int64 `gorm:"column:washpipe_nurse" json:"washpipe_nurse" form:"washpipe_nurse"`
  271. DialysisIrrigation string `gorm:"column:dialysis_irrigation" json:"dialysis_irrigation" form:"dialysis_irrigation"`
  272. DialysisDialyszers string `gorm:"column:dialysis_dialyszers" json:"dialysis_dialyszers" form:"dialysis_dialyszers"`
  273. }
  274. func (MDialysisOrderVM) TableName() string {
  275. return "xt_dialysis_order"
  276. }
  277. type MDialysisOrderVMList struct {
  278. ID int64 `gorm:"column:id" json:"id"`
  279. DialysisDate int64 `gorm:"column:dialysis_date" json:"dialysis_date"`
  280. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  281. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  282. // PrescriptionId int64 `gorm:"column:prescription_id" json:"prescription_id"`
  283. Stage int64 `gorm:"column:stage" json:"stage"`
  284. // Remark string `gorm:"column:remark" json:"remark"`
  285. BedID int64 `gorm:"column:bed_id" json:"bed_id"`
  286. StartNurse int64 `gorm:"column:start_nurse" json:"start_nurse"`
  287. Status int64 `gorm:"column:status" json:"status"`
  288. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedID" json:"device_number"`
  289. Creator int64 `gorm:"column:creator" json:"creator"`
  290. WashpipeNurse int64 `gorm:"column:washpipe_nurse" json:"washpipe_nurse" form:"washpipe_nurse"`
  291. NucleinDate int64 `gorm:"column:nuclein_date" json:"nuclein_date" form:"nuclein_date"`
  292. DialysisIrrigation string `gorm:"column:dialysis_irrigation" json:"dialysis_irrigation" form:"dialysis_irrigation"`
  293. DialysisDialyszers string `gorm:"column:dialysis_dialyszers" json:"dialysis_dialyszers" form:"dialysis_dialyszers"`
  294. ScheduleRemark string `gorm:"column:schedule_remark" json:"schedule_remark" form:"schedule_remark"`
  295. }
  296. func (MDialysisOrderVMList) TableName() string {
  297. return "xt_dialysis_order"
  298. }
  299. type VMDoctorAdvice struct {
  300. ID int64 `gorm:"column:id" json:"id" form:"id"`
  301. GroupNo int64 `gorm:"column:groupno" json:"groupno" form:"groupno"`
  302. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  303. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  304. AdviceDate int64 `gorm:"column:advice_date" json:"advice_date" form:"advice_date"`
  305. Status int64 `gorm:"column:status" json:"status" form:"status"`
  306. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
  307. RecordDate int64 `gorm:"column:record_date" json:"record_date"`
  308. CheckTime int64 `gorm:"column:check_time" json:"check_time" form:"check_time"`
  309. CheckState int64 `gorm:"column:check_state" json:"check_state" form:"check_state"`
  310. ParentId int64 `gorm:"column:parent_id" json:"parent_id" form:"parent_id"`
  311. }
  312. func (VMDoctorAdvice) TableName() string {
  313. return "xt_doctor_advice"
  314. }
  315. type VMHisDoctorAdviceInfo struct {
  316. ID int64 `gorm:"column:id" json:"id" form:"id"`
  317. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  318. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  319. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  320. ExecutionTime int64 `gorm:"column:execution_time" json:"execution_time" form:"execution_time"`
  321. ExecutionStaff int64 `gorm:"column:execution_staff" json:"execution_staff" form:"execution_staff"`
  322. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
  323. IsMedicine int64 `gorm:"column:is_medicine" json:"is_medicine" form:"is_medicine"`
  324. ExecutionFrequencyId int64 `gorm:"column:execution_frequency_id" json:"execution_frequency_id" form:"execution_frequency_id"`
  325. IsSelfDrug int64 `gorm:"column:is_self_drug" json:"is_self_drug" form:"is_self_drug"`
  326. }
  327. func (VMHisDoctorAdviceInfo) TableName() string {
  328. return "his_doctor_advice_info"
  329. }
  330. type VMAssessmentAfterDislysis struct {
  331. ID int64 `gorm:"column:id" json:"id"`
  332. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  333. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  334. AssessmentDate int64 `gorm:"column:assessment_date" json:"assessment_date"`
  335. WeightAfter float64 `gorm:"column:weight_after" json:"weight_after"`
  336. Status int64 `gorm:"column:status" json:"status"`
  337. }
  338. func (VMAssessmentAfterDislysis) TableName() string {
  339. return "xt_assessment_after_dislysis"
  340. }
  341. type NewDeviceInformation struct {
  342. ID int64 `gorm:"column:id" json:"id" form:"id"`
  343. Date int64 `gorm:"column:date" json:"date" form:"date"`
  344. Class int64 `gorm:"column:class" json:"class" form:"class"`
  345. Zone int64 `gorm:"column:zone" json:"zone" form:"zone"`
  346. BedNumber int64 `gorm:"column:bed_number" json:"bed_number" form:"bed_number"`
  347. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  348. Status int64 `gorm:"column:status" json:"status" form:"status"`
  349. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  350. EquimentId int64 `gorm:"column:equiment_id" json:"equiment_id" form:"equiment_id"`
  351. Bed string `gorm:"column:bed" json:"bed" form:"bed"`
  352. Stime int64 `gorm:"column:stime" json:"stime" form:"stime"`
  353. }
  354. func (NewDeviceInformation) TableName() string {
  355. return "xt_device_information"
  356. }
  357. // 获取透析记录
  358. func MobileGetDialysisRecord(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  359. var record models.DialysisOrder
  360. err := readDb.Model(&models.DialysisOrder{}).Where("user_org_id = ? AND patient_id = ? AND dialysis_date = ?", orgID, patientID, recordDate).First(&record).Error
  361. if err != nil {
  362. if err == gorm.ErrRecordNotFound {
  363. return nil, nil
  364. } else {
  365. return nil, err
  366. }
  367. }
  368. return &record, nil
  369. }
  370. // 用户基本信息
  371. func MobileGetPatientDetail(orgID int64, patientID int64) (*MPatient, error) {
  372. var patient MPatient
  373. //err := readDb.Model(&MPatient{}).Where("status = 1 AND user_org_id = ? AND id = ?", orgID, patientID).First(&patient).Error
  374. //if err != nil {
  375. // if err == gorm.ErrRecordNotFound {
  376. // return nil, nil
  377. // } else {
  378. // return nil, err
  379. // }
  380. //}
  381. //return &patient, nil
  382. redis := RedisClient()
  383. defer redis.Close()
  384. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":patient_info"
  385. patient_info_str, _ := redis.Get(key).Result()
  386. if len(patient_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  387. err = readDb.Model(&patient).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
  388. if err != nil {
  389. if err == gorm.ErrRecordNotFound {
  390. return &patient, nil
  391. } else {
  392. return &patient, err
  393. }
  394. } else {
  395. if patient.ID > 0 {
  396. //缓存数据
  397. patient_info_json, err := json.Marshal(&patient)
  398. if err == nil {
  399. redis.Set(key, patient_info_json, time.Second*60*60*18)
  400. }
  401. }
  402. return &patient, nil
  403. }
  404. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  405. json.Unmarshal([]byte(patient_info_str), &patient)
  406. return &patient, nil
  407. }
  408. }
  409. func MobileGetSchedualDetailOne(orgID int64, patientID int64, schedualDate int64) (*MDialysisScheduleVM, error) {
  410. var vm MDialysisScheduleVM
  411. err := readDb.
  412. Table("xt_schedule").
  413. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  414. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  415. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  416. First(&vm).Error
  417. return &vm, err
  418. }
  419. // 用户排班信息
  420. func MobileGetSchedualDetailSix(orgID int64, patientID int64, schedualDate int64) (*MDialysisScheduleVM, error) {
  421. var vm MDialysisScheduleVM
  422. err := readDb.
  423. Table("xt_schedule").
  424. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  425. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  426. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  427. First(&vm).Error
  428. if err != nil {
  429. if err == gorm.ErrRecordNotFound {
  430. return nil, nil
  431. } else {
  432. return nil, err
  433. }
  434. }
  435. return &vm, err
  436. }
  437. // 用户排班信息
  438. func MobileGetSchedualDetail(orgID int64, patientID int64, schedualDate int64) (*MDialysisScheduleVM, error) {
  439. redis := RedisClient()
  440. defer redis.Close()
  441. var vm MDialysisScheduleVM
  442. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(schedualDate, 10) + ":schedual_detail"
  443. redis.Set(key, "", time.Second)
  444. schedual_detail_str, _ := redis.Get(key).Result()
  445. if len(schedual_detail_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  446. err := readDb.
  447. Table("xt_schedule").
  448. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  449. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  450. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  451. First(&vm).Error
  452. if err != nil {
  453. if err == gorm.ErrRecordNotFound {
  454. return nil, nil
  455. } else {
  456. return nil, err
  457. }
  458. } else {
  459. if vm.ID > 0 {
  460. //缓存数据
  461. schedual_detail_str, err := json.Marshal(vm)
  462. if err == nil {
  463. redis.Set(key, schedual_detail_str, time.Second*60*60*18)
  464. }
  465. } else {
  466. redis.Set(key, "null", time.Second*60*60*18)
  467. }
  468. return &vm, nil
  469. }
  470. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  471. if schedual_detail_str == "null" {
  472. return &vm, nil
  473. }
  474. json.Unmarshal([]byte(schedual_detail_str), &vm)
  475. return &vm, nil
  476. }
  477. }
  478. // 用户排班信息
  479. func MobileGetPatientSchedual(orgID int64, patientID int64, schedualDate int64) (*models.Schedule, error) {
  480. var schedule models.Schedule
  481. err := readDb.
  482. Table("xt_schedule").
  483. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  484. First(&schedule).Error
  485. if err != nil {
  486. if err == gorm.ErrRecordNotFound {
  487. return nil, nil
  488. } else {
  489. return nil, err
  490. }
  491. }
  492. return &schedule, nil
  493. }
  494. type MPatient struct {
  495. ID int64 `gorm:"column:id" json:"id" form:"id"`
  496. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  497. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  498. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  499. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  500. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
  501. AdmissionNumber string `gorm:"column:admission_number" json:"admission_number" form:"admission_number"`
  502. Source int64 `gorm:"column:source" json:"source" form:"source"`
  503. Lapseto int64 `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
  504. PartitionId int64 `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
  505. BedId int64 `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
  506. Name string `gorm:"column:name" json:"name" form:"name"`
  507. Alias string `gorm:"column:alias" json:"alias" form:"alias"`
  508. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  509. Nation string `gorm:"column:nation" json:"nation" form:"nation"`
  510. NativePlace string `gorm:"column:native_place" json:"native_place" form:"native_place"`
  511. MaritalStatus int64 `gorm:"column:marital_status" json:"marital_status" form:"marital_status"`
  512. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  513. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  514. ReimbursementWayId int64 `gorm:"column:reimbursement_way_id" json:"reimbursement_way_id" form:"reimbursement_way_id"`
  515. HealthCareType int64 `gorm:"column:health_care_type" json:"health_care_type" form:"health_care_type"`
  516. HealthCareNo string `gorm:"column:health_care_no" json:"health_care_no" form:"health_care_no"`
  517. HealthCareDueDate int64 `gorm:"column:health_care_due_date" json:"health_care_due_date" form:"health_care_due_date"`
  518. Height int64 `gorm:"column:height" json:"height" form:"height"`
  519. BloodType int64 `gorm:"column:blood_type" json:"blood_type" form:"blood_type"`
  520. Rh int64 `gorm:"column:rh" json:"rh" form:"rh"`
  521. HealthCareDueAlertDate int64 `gorm:"column:health_care_due_alert_date" json:"health_care_due_alert_date" form:"health_care_due_alert_date"`
  522. EducationLevel int64 `gorm:"column:education_level" json:"education_level" form:"education_level"`
  523. Profession int64 `gorm:"column:profession" json:"profession" form:"profession"`
  524. Phone string `gorm:"column:phone" json:"phone" form:"phone"`
  525. HomeTelephone string `gorm:"column:home_telephone" json:"home_telephone" form:"home_telephone"`
  526. RelativePhone string `gorm:"column:relative_phone" json:"relative_phone" form:"relative_phone"`
  527. RelativeRelations string `gorm:"column:relative_relations" json:"relative_relations" form:"relative_relations"`
  528. HomeAddress string `gorm:"column:home_address" json:"home_address" form:"home_address"`
  529. WorkUnit string `gorm:"column:work_unit" json:"work_unit" form:"work_unit"`
  530. UnitAddress string `gorm:"column:unit_address" json:"unit_address" form:"unit_address"`
  531. Children int64 `gorm:"column:children" json:"children" form:"children"`
  532. ReceivingDate int64 `gorm:"column:receiving_date" json:"receiving_date" form:"receiving_date"`
  533. IsHospitalFirstDialysis int64 `gorm:"column:is_hospital_first_dialysis" json:"is_hospital_first_dialysis" form:"is_hospital_first_dialysis"`
  534. FirstDialysisDate int64 `gorm:"column:first_dialysis_date" json:"first_dialysis_date" form:"first_dialysis_date"`
  535. FirstDialysisHospital string `gorm:"column:first_dialysis_hospital" json:"first_dialysis_hospital" form:"first_dialysis_hospital"`
  536. InductionPeriod int64 `gorm:"column:induction_period" json:"induction_period" form:"induction_period"`
  537. InitialDialysis int64 `gorm:"column:initial_dialysis" json:"initial_dialysis" form:"initial_dialysis"`
  538. TotalDialysis int64 `gorm:"column:total_dialysis" json:"total_dialysis" form:"total_dialysis"`
  539. AttendingDoctorId int64 `gorm:"column:attending_doctor_id" json:"attending_doctor_id" form:"attending_doctor_id"`
  540. HeadNurseId int64 `gorm:"column:head_nurse_id" json:"head_nurse_id" form:"head_nurse_id"`
  541. Evaluate string `gorm:"column:evaluate" json:"evaluate" form:"evaluate"`
  542. Diagnose string `gorm:"column:diagnose" json:"diagnose" form:"diagnose"`
  543. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  544. RegistrarsId int64 `gorm:"column:registrars_id" json:"registrars_id" form:"registrars_id"`
  545. Registrars string `gorm:"column:registrars" json:"registrars" form:"registrars"`
  546. QrCode string `gorm:"column:qr_code" json:"qr_code" form:"qr_code"`
  547. BindingState int64 `gorm:"column:binding_state" json:"binding_state" form:"binding_state"`
  548. PatientComplains string `gorm:"column:patient_complains" json:"patient_complains"` // 主诉
  549. PresentHistory string `gorm:"column:present_history" json:"present_history"` // 现病史
  550. PastHistory string `gorm:"column:past_history" json:"past_history"` // 既往史
  551. Temperature float64 `gorm:"column:temperature" json:"temperature"` // 体格检查-体温
  552. Pulse int64 `gorm:"column:pulse" json:"pulse"` // 体格检查-脉搏
  553. Respiratory int64 `gorm:"column:respiratory" json:"respiratory"` // 体格检查-呼吸频率
  554. SBP int64 `gorm:"column:sbp" json:"sbp"` // 体格检查-收缩压
  555. DBP int64 `gorm:"column:dbp" json:"dbp"` // 体格检查-舒张压
  556. Status int64 `gorm:"column:status" json:"status" form:"status"`
  557. Age int64 `gorm:"column:age" json:"age"`
  558. IsOpenRemind int64 `gorm:"column:is_open_remind" json:"is_open_remind"`
  559. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  560. DialysisAge int64 `gorm:"column:dialysis_age" json:"dialysis_age" form:"dialysis_age"`
  561. ExpenseKind int64 `gorm:"column:expense_kind" json:"expense_kind" form:"expense_kind"`
  562. TellPhone string `gorm:"column:tell_phone" json:"tell_phone" form:"tell_phone"`
  563. FirstTreatmentDate int64 `gorm:"column:first_treatment_date" json:"first_treatment_date" form:"first_treatment_date"`
  564. ContactName string `gorm:"column:contact_name" json:"contact_name" form:"contact_name"`
  565. UserSysBeforeCount int64 `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
  566. }
  567. func (MPatient) TableName() string {
  568. return "xt_patients"
  569. }
  570. // 接诊评估
  571. func MobileGetReceiverTreatmentAccessRecord(orgID int64, patientID int64, recordDate int64) (*models.ReceiveTreatmentAsses, error) {
  572. var record models.ReceiveTreatmentAsses
  573. redis := RedisClient()
  574. defer redis.Close()
  575. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":receive_treatment_asses"
  576. receive_treatment_asses_str, _ := redis.Get(key).Result()
  577. if len(receive_treatment_asses_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  578. err = readDb.Model(&models.ReceiveTreatmentAsses{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  579. if err != nil {
  580. if err == gorm.ErrRecordNotFound {
  581. if record.ID <= 0 {
  582. redis.Set(key, "", time.Second*60*60*18)
  583. }
  584. return nil, nil
  585. } else {
  586. return nil, err
  587. }
  588. } else {
  589. if record.ID > 0 {
  590. //缓存数据
  591. receive_treatment_asses_str, err := json.Marshal(record)
  592. if err == nil {
  593. redis.Set(key, receive_treatment_asses_str, time.Second*60*60*18)
  594. }
  595. } else {
  596. redis.Set(key, "null", time.Second*60*60*18)
  597. }
  598. return &record, nil
  599. }
  600. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  601. if receive_treatment_asses_str == "null" {
  602. return &record, nil
  603. }
  604. json.Unmarshal([]byte(receive_treatment_asses_str), &record)
  605. return &record, nil
  606. }
  607. }
  608. // 透前评估
  609. func MobileGetPredialysisEvaluationOne(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
  610. var record models.PredialysisEvaluation
  611. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  612. if err != nil {
  613. if err == gorm.ErrRecordNotFound {
  614. return nil, nil
  615. } else {
  616. return nil, err
  617. }
  618. }
  619. return &record, nil
  620. }
  621. func MobileGetPredialysisEvaluationTwo(orgID int64, patientID int64, recordDate int64) (models.PredialysisEvaluation, error) {
  622. var record models.PredialysisEvaluation
  623. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  624. return record, err
  625. }
  626. // 透前评估
  627. func MobileGetPredialysisEvaluation(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
  628. var record models.PredialysisEvaluation
  629. redis := RedisClient()
  630. defer redis.Close()
  631. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":assessment_before_dislysis"
  632. assessment_before_dislysis_str, _ := redis.Get(key).Result()
  633. redis.Set(key, "", time.Second)
  634. if len(assessment_before_dislysis_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  635. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  636. if err != nil {
  637. if err == gorm.ErrRecordNotFound {
  638. if record.ID <= 0 {
  639. redis.Set(key, "", time.Second*60*60*18)
  640. }
  641. return nil, nil
  642. } else {
  643. return nil, err
  644. }
  645. } else {
  646. if record.ID > 0 {
  647. //缓存数据
  648. assessment_before_dislysis_str, err := json.Marshal(record)
  649. if err == nil {
  650. redis.Set(key, assessment_before_dislysis_str, time.Second*60*60*18)
  651. }
  652. } else {
  653. redis.Set(key, "null", time.Second*60*60*18)
  654. }
  655. return &record, nil
  656. }
  657. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  658. if assessment_before_dislysis_str == "null" {
  659. return &record, nil
  660. } else {
  661. json.Unmarshal([]byte(assessment_before_dislysis_str), &record)
  662. return &record, nil
  663. }
  664. }
  665. }
  666. // 获取 maxDate 之前一次的透前评估记录
  667. func MobileGetLastTimePredialysisEvaluationOne(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
  668. var record models.PredialysisEvaluation
  669. 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
  670. if err != nil {
  671. if err == gorm.ErrRecordNotFound {
  672. return nil, nil
  673. } else {
  674. return nil, err
  675. }
  676. }
  677. return &record, nil
  678. }
  679. // 获取 maxDate 之前一次的透前评估记录
  680. func MobileGetLastTimePredialysisEvaluation(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
  681. var record models.PredialysisEvaluation
  682. redis := RedisClient()
  683. defer redis.Close()
  684. // cur_date := time.Now().Format("2006-01-02")
  685. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(maxDate, 10) + ":assessment_before_dislysis_last"
  686. assessment_before_dislysis_last_str, _ := redis.Get(key).Result()
  687. if len(assessment_before_dislysis_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  688. 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
  689. if err != nil {
  690. if err == gorm.ErrRecordNotFound {
  691. if record.ID <= 0 {
  692. redis.Set(key, "", time.Second*60*60*18)
  693. }
  694. return nil, nil
  695. } else {
  696. return nil, err
  697. }
  698. } else {
  699. if record.ID > 0 {
  700. //缓存数据
  701. assessment_before_dislysis_last_str, err := json.Marshal(record)
  702. if err == nil {
  703. redis.Set(key, assessment_before_dislysis_last_str, time.Second*60*60*4)
  704. }
  705. } else {
  706. redis.Set(key, "null", time.Second*60*60*18)
  707. }
  708. return &record, nil
  709. }
  710. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  711. if assessment_before_dislysis_last_str == "null" {
  712. return &record, nil
  713. } else {
  714. json.Unmarshal([]byte(assessment_before_dislysis_last_str), &record)
  715. return &record, nil
  716. }
  717. }
  718. }
  719. // 临时医嘱
  720. func MobileGetDoctorAdvices(orgID int64, patientID int64, recordDate int64) ([]*models.DoctorAdvice, error) {
  721. var records []*models.DoctorAdvice
  722. // err := readDb.Model(&models.DoctorAdvice{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).Find(&records).Error
  723. err := readDb.
  724. Model(&models.DoctorAdvice{}).
  725. Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? and (advice_type = 2 or advice_type = 3)", patientID, orgID, recordDate).
  726. 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").
  727. Order("start_time asc, groupno desc, advice_order desc, id").
  728. Scan(&records).Error
  729. if err != nil {
  730. return nil, err
  731. }
  732. return records, nil
  733. }
  734. func MobileGetDoctorAdvicesByGroups(orgID int64, patientID int64, recordDate int64) ([]*models.DoctorAdvice, error) {
  735. var records []*models.DoctorAdvice
  736. redis := RedisClient()
  737. defer redis.Close()
  738. // cur_date := time.Now().Format("2006-01-02")
  739. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":doctor_advices"
  740. //fmt.Println("key23233232323323wi", key)
  741. redis.Set(key, "", time.Second)
  742. doctor_advices_str, _ := redis.Get(key).Result()
  743. if len(doctor_advices_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  744. err := readDb.Model(&models.DoctorAdvice{}).
  745. Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? and (advice_type = 2 || advice_type = 3)", patientID, orgID, recordDate).
  746. 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").
  747. Order("start_time asc, groupno desc, advice_order desc, id asc").
  748. Scan(&records).Error
  749. if err != nil {
  750. if err == gorm.ErrRecordNotFound {
  751. if len(records) <= 0 {
  752. redis.Set(key, "", time.Second*60*60*18)
  753. }
  754. return nil, nil
  755. } else {
  756. return nil, err
  757. }
  758. } else {
  759. if len(records) > 0 {
  760. //缓存数据
  761. doctor_advices_str, err := json.Marshal(records)
  762. if err == nil {
  763. redis.Set(key, doctor_advices_str, time.Second*60*60*18)
  764. return records, nil
  765. }
  766. } else {
  767. redis.Set(key, "null", time.Second*60*60*18)
  768. return records, nil
  769. }
  770. return records, nil
  771. }
  772. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  773. if doctor_advices_str == "null" {
  774. return records, nil
  775. } else {
  776. json.Unmarshal([]byte(doctor_advices_str), &records)
  777. return records, nil
  778. }
  779. }
  780. }
  781. // 透析记录
  782. func MobileGetSchedualDialysisRecordTen(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  783. var record models.DialysisOrder
  784. 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
  785. if err != nil {
  786. if err == gorm.ErrRecordNotFound {
  787. return nil, nil
  788. } else {
  789. return nil, err
  790. }
  791. }
  792. return &record, nil
  793. }
  794. //func MobileGetSchedualDialysisRecord(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  795. // var record models.DialysisOrder
  796. //
  797. // 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
  798. //
  799. //
  800. // return &record,err
  801. //}
  802. // 透析记录
  803. func MobileGetSchedualDialysisRecord(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  804. var record models.DialysisOrder
  805. redis := RedisClient()
  806. defer redis.Close()
  807. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":dialysis_order"
  808. dialysis_order_str, _ := redis.Get(key).Result()
  809. if len(dialysis_order_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  810. 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
  811. if err != nil {
  812. if err == gorm.ErrRecordNotFound {
  813. return nil, nil
  814. } else {
  815. return nil, err
  816. }
  817. } else {
  818. if record.ID > 0 {
  819. //缓存数据
  820. dialysis_order_str, err := json.Marshal(record)
  821. if err == nil {
  822. redis.Set(key, dialysis_order_str, time.Second*60*60*18)
  823. }
  824. } else {
  825. redis.Set(key, "null", time.Second*60*60*18)
  826. }
  827. return &record, nil
  828. }
  829. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  830. if dialysis_order_str == "null" {
  831. 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
  832. return &record, nil
  833. } else {
  834. json.Unmarshal([]byte(dialysis_order_str), &record)
  835. return &record, nil
  836. }
  837. }
  838. }
  839. // 双人核对
  840. func MobileGetDoubleCheck(orgID int64, patientID int64, recordDate int64) (*models.DoubleCheck, error) {
  841. var record models.DoubleCheck
  842. redis := RedisClient()
  843. defer redis.Close()
  844. // cur_date := time.Now().Format("2006-01-02")
  845. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":double_check"
  846. double_check_str, _ := redis.Get(key).Result()
  847. if len(double_check_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  848. err := readDb.Model(&models.DoubleCheck{}).Where("patient_id = ? and user_org_id = ? and status = 1 and check_date = ?", patientID, orgID, recordDate).First(&record).Error
  849. if err != nil {
  850. if err == gorm.ErrRecordNotFound {
  851. if record.ID <= 0 {
  852. redis.Set(key, "null", time.Second*60*60*18)
  853. }
  854. return nil, nil
  855. } else {
  856. return nil, err
  857. }
  858. } else {
  859. if record.ID > 0 {
  860. //缓存数据
  861. double_check_str, err := json.Marshal(record)
  862. if err == nil {
  863. redis.Set(key, double_check_str, time.Second*60*60*18)
  864. }
  865. } else {
  866. redis.Set(key, "null", time.Second*60*60*18)
  867. }
  868. return &record, nil
  869. }
  870. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  871. if double_check_str == "null" {
  872. return &record, nil
  873. } else {
  874. json.Unmarshal([]byte(double_check_str), &record)
  875. return &record, nil
  876. }
  877. }
  878. }
  879. // 透析监测记录
  880. func MobileGetMonitorRecords(orgID int64, patientID int64, recordDate int64) ([]*models.MonitoringRecord, error) {
  881. var records []*models.MonitoringRecord
  882. redis := RedisClient()
  883. defer redis.Close()
  884. // cur_date := time.Now().Format("2006-01-02")
  885. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":monitor_records"
  886. redis.Set(key, "", time.Second)
  887. monitor_records_str, _ := redis.Get(key).Result()
  888. if len(monitor_records_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  889. 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
  890. if err != nil {
  891. if err == gorm.ErrRecordNotFound {
  892. //if len(records) <= 0 {
  893. // redis.Set(key, "null", time.Second*60*60*18)
  894. //}
  895. return nil, nil
  896. } else {
  897. return nil, err
  898. }
  899. } else {
  900. if len(records) > 0 {
  901. //缓存数据
  902. monitor_records_str, err := json.Marshal(records)
  903. if err == nil {
  904. redis.Set(key, monitor_records_str, time.Second*60*60*18)
  905. }
  906. } else {
  907. redis.Set(key, "null", time.Second*60*60*18)
  908. }
  909. return records, nil
  910. }
  911. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  912. if monitor_records_str == "null" {
  913. return records, nil
  914. } else {
  915. json.Unmarshal([]byte(monitor_records_str), &records)
  916. return records, nil
  917. }
  918. }
  919. }
  920. func MobileGetMonitorRecordFirst(orgID int64, patientID int64, recordDate int64) (*models.MonitoringRecord, error) {
  921. var records models.MonitoringRecord
  922. 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
  923. if err != nil {
  924. return nil, err
  925. }
  926. return &records, nil
  927. }
  928. func MobileGetLastMonitorRecordOne(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  929. var record models.MonitoringRecord
  930. 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
  931. if err != nil {
  932. if err == gorm.ErrRecordNotFound {
  933. return nil, nil
  934. } else {
  935. return nil, err
  936. }
  937. }
  938. return &record, nil
  939. }
  940. func MobileGetLastMonitorRecord(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  941. var record models.MonitoringRecord
  942. redis := RedisClient()
  943. defer redis.Close()
  944. // cur_date := time.Now().Format("2006-01-02")
  945. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(beforeDate, 10) + ":monitor_record_last"
  946. monitor_record_last_str, _ := redis.Get(key).Result()
  947. if len(monitor_record_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  948. 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
  949. if err != nil {
  950. if err == gorm.ErrRecordNotFound {
  951. if record.ID <= 0 {
  952. redis.Set(key, "null", time.Second*60*60*18)
  953. }
  954. return nil, nil
  955. } else {
  956. return nil, err
  957. }
  958. } else {
  959. if record.ID > 0 {
  960. //缓存数据
  961. monitor_record_last_str, err := json.Marshal(record)
  962. if err == nil {
  963. redis.Set(key, monitor_record_last_str, time.Second*60*60*18)
  964. }
  965. } else {
  966. redis.Set(key, "null", time.Second*60*60*18)
  967. }
  968. return &record, nil
  969. }
  970. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  971. if monitor_record_last_str == "null" {
  972. return &record, nil
  973. } else {
  974. json.Unmarshal([]byte(monitor_record_last_str), &record)
  975. return &record, nil
  976. }
  977. }
  978. }
  979. func MobileGetAssessmentAfterDislysisOne(orgID int64, patientID int64, recordDate int64) (*models.AssessmentAfterDislysis, error) {
  980. var record models.AssessmentAfterDislysis
  981. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  982. if err != nil {
  983. if err == gorm.ErrRecordNotFound {
  984. return nil, nil
  985. } else {
  986. return nil, err
  987. }
  988. }
  989. return &record, nil
  990. }
  991. // 透后评估
  992. func MobileGetAssessmentAfterDislysis(orgID int64, patientID int64, recordDate int64) (*models.AssessmentAfterDislysis, error) {
  993. var record models.AssessmentAfterDislysis
  994. redis := RedisClient()
  995. defer redis.Close()
  996. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":assessment_after_dislysis"
  997. redis.Set(key, "", time.Second)
  998. assessment_after_dislysis_str, _ := redis.Get(key).Result()
  999. if len(assessment_after_dislysis_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1000. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  1001. if err != nil {
  1002. if err == gorm.ErrRecordNotFound {
  1003. if record.ID <= 0 {
  1004. redis.Set(key, "null", time.Second*60*60*18)
  1005. }
  1006. return nil, nil
  1007. } else {
  1008. return nil, err
  1009. }
  1010. } else {
  1011. if record.ID > 0 {
  1012. //缓存数据
  1013. assessment_after_dislysis_str, err := json.Marshal(record)
  1014. if err == nil {
  1015. redis.Set(key, assessment_after_dislysis_str, time.Second*60*60*18)
  1016. }
  1017. } else {
  1018. redis.Set(key, "null", time.Second*60*60*18)
  1019. }
  1020. return &record, nil
  1021. }
  1022. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1023. if assessment_after_dislysis_str == "null" {
  1024. return &record, nil
  1025. } else {
  1026. json.Unmarshal([]byte(assessment_after_dislysis_str), &record)
  1027. return &record, nil
  1028. }
  1029. }
  1030. }
  1031. // 获取 maxDate 之前一次的透后评估记录
  1032. func MobileGetLastTimeAssessmentAfterDislysis(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  1033. var record models.AssessmentAfterDislysis
  1034. redis := RedisClient()
  1035. defer redis.Close()
  1036. // cur_date := time.Now().Format("2006-01-02")
  1037. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(maxDate, 10) + ":assessment_after_dislysis_last"
  1038. redis.Set(key, "", time.Second)
  1039. assessment_after_dislysis_last_str, _ := redis.Get(key).Result()
  1040. if len(assessment_after_dislysis_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1041. 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
  1042. if err != nil {
  1043. if err == gorm.ErrRecordNotFound {
  1044. if record.ID <= 0 {
  1045. redis.Set(key, "null", time.Second*60*60*18)
  1046. }
  1047. return nil, nil
  1048. } else {
  1049. return nil, err
  1050. }
  1051. } else {
  1052. if record.ID > 0 {
  1053. //缓存数据
  1054. assessment_after_dislysis_last_str, err := json.Marshal(record)
  1055. if err == nil {
  1056. redis.Set(key, assessment_after_dislysis_last_str, time.Second*60*60*18)
  1057. }
  1058. } else {
  1059. redis.Set(key, "null", time.Second*60*60*18)
  1060. }
  1061. return &record, nil
  1062. }
  1063. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1064. if assessment_after_dislysis_last_str == "null" {
  1065. return &record, nil
  1066. } else {
  1067. json.Unmarshal([]byte(assessment_after_dislysis_last_str), &record)
  1068. return &record, nil
  1069. }
  1070. }
  1071. }
  1072. func MobileGetLastTimeAssessmentAfterDislysisOne(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  1073. var record models.AssessmentAfterDislysis
  1074. 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
  1075. if err != nil {
  1076. if err == gorm.ErrRecordNotFound {
  1077. return nil, nil
  1078. } else {
  1079. return nil, err
  1080. }
  1081. }
  1082. return &record, nil
  1083. }
  1084. func MobileGetLast(orgID int64, patientID int64, maxDate int64) (models.AssessmentAfterDislysis, error) {
  1085. dislysis := models.AssessmentAfterDislysis{}
  1086. 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
  1087. return dislysis, err
  1088. }
  1089. // 治疗小结
  1090. func MobileGetTreatmentSummary(orgID int64, patientID int64, recordDate int64) (*models.TreatmentSummary, error) {
  1091. var record models.TreatmentSummary
  1092. redis := RedisClient()
  1093. defer redis.Close()
  1094. // cur_date := time.Now().Format("2006-01-02")
  1095. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":treatment_summary"
  1096. treatment_summary_str, _ := redis.Get(key).Result()
  1097. if len(treatment_summary_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1098. err := readDb.Model(&models.TreatmentSummary{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  1099. if err != nil {
  1100. if err == gorm.ErrRecordNotFound {
  1101. if record.ID <= 0 {
  1102. redis.Set(key, "null", time.Second*60*60*18)
  1103. }
  1104. return nil, nil
  1105. } else {
  1106. return nil, err
  1107. }
  1108. } else {
  1109. if record.ID > 0 {
  1110. //缓存数据
  1111. treatment_summary_str, err := json.Marshal(record)
  1112. if err == nil {
  1113. redis.Set(key, treatment_summary_str, time.Second*60*60*18)
  1114. }
  1115. } else {
  1116. redis.Set(key, "null", time.Second*60*60*18)
  1117. }
  1118. return &record, nil
  1119. }
  1120. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1121. if treatment_summary_str == "null" {
  1122. return &record, nil
  1123. } else {
  1124. json.Unmarshal([]byte(treatment_summary_str), &record)
  1125. return &record, nil
  1126. }
  1127. }
  1128. }
  1129. // 透析处方
  1130. func MobileGetDialysisPrescribe(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  1131. var record models.DialysisPrescription
  1132. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).Find(&record).Error
  1133. if err != nil {
  1134. if err == gorm.ErrRecordNotFound {
  1135. return nil, nil
  1136. } else {
  1137. return nil, err
  1138. }
  1139. }
  1140. return &record, nil
  1141. }
  1142. func MobileGetDialysisSchedual(orgID int64, patientID int64, scheduleDate int64) (*models.XtSchedule, error) {
  1143. var schedule models.XtSchedule
  1144. err := readDb.Model(&models.XtSchedule{}).Where("patient_id = ? and user_org_id = ? and status = 1 and schedule_date = ?", patientID, orgID, scheduleDate).First(&schedule).Error
  1145. if err != nil {
  1146. if err == gorm.ErrRecordNotFound {
  1147. return nil, nil
  1148. } else {
  1149. return nil, err
  1150. }
  1151. }
  1152. return &schedule, nil
  1153. }
  1154. // 透析方案
  1155. func MobileGetDialysisSolution(orgID int64, patientID int64) (*models.DialysisSolution, error) {
  1156. var record models.DialysisSolution
  1157. err := readDb.Model(&models.DialysisSolution{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  1158. if err != nil {
  1159. if err == gorm.ErrRecordNotFound {
  1160. return nil, nil
  1161. } else {
  1162. return nil, err
  1163. }
  1164. }
  1165. return &record, nil
  1166. }
  1167. func MobileGetPatientById(orgID int64, patientID int64) (*models.Patients, error) {
  1168. var patient models.Patients
  1169. err := readDb.Model(&models.Patients{}).Where("id = ? and user_org_id = ? and status = 1", patientID, orgID).First(&patient).Error
  1170. if err != nil {
  1171. if err == gorm.ErrRecordNotFound {
  1172. return nil, nil
  1173. } else {
  1174. return nil, err
  1175. }
  1176. }
  1177. return &patient, nil
  1178. }
  1179. func DisableMonitor(orgID int64, patientID int64, recordID int64, admin_user_id int64) error {
  1180. fmt.Println()
  1181. tx := writeDb.Begin()
  1182. updateTime := time.Now().Unix()
  1183. 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
  1184. if err != nil {
  1185. tx.Rollback()
  1186. return err
  1187. }
  1188. tx.Commit()
  1189. return nil
  1190. }
  1191. func GetMonitorById(id int64, orgId int64) (models.MonitoringRecord, error) {
  1192. record := models.MonitoringRecord{}
  1193. err := XTReadDB().Where("id = ? and user_org_id =?", id, orgId).Find(&record).Error
  1194. return record, err
  1195. }
  1196. func GetMonitor(orgID int64, patientID int64, id int64) (*models.MonitoringRecord, error) {
  1197. var monitor models.MonitoringRecord
  1198. var err error
  1199. err = readDb.Model(&models.MonitoringRecord{}).Where("id = ? AND user_org_id = ? AND patient_id = ? AND status = 1 ", id, orgID, patientID).Find(&monitor).Error
  1200. if err == gorm.ErrRecordNotFound {
  1201. return nil, nil
  1202. }
  1203. if err != nil {
  1204. return nil, err
  1205. }
  1206. return &monitor, nil
  1207. }
  1208. type MScheduleDoctorAdviceVM struct {
  1209. ID int64 `gorm:"column:id" json:"id"`
  1210. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  1211. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  1212. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  1213. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1214. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  1215. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  1216. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  1217. Status int64 `gorm:"column:status" json:"status"`
  1218. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  1219. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  1220. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  1221. DoctorAdvices []*MDoctorAdviceVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  1222. Prescription *models.DialysisPrescriptionTwenty `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  1223. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  1224. }
  1225. func (MScheduleDoctorAdviceVM) TableName() string {
  1226. return "xt_schedule"
  1227. }
  1228. type MScheduleDoctorAdviceVMOne struct {
  1229. ID int64 `gorm:"column:id" json:"id"`
  1230. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  1231. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  1232. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  1233. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1234. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  1235. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  1236. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  1237. Status int64 `gorm:"column:status" json:"status"`
  1238. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  1239. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  1240. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  1241. DoctorAdvices []*MDoctorAdviceVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  1242. Prescription *models.DialysisPrescriptionTwenty `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  1243. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  1244. }
  1245. func (MScheduleDoctorAdviceVMOne) TableName() string {
  1246. return "xt_schedule"
  1247. }
  1248. type MDoctorAdviceVM struct {
  1249. ID int64 `gorm:"column:id" json:"id"`
  1250. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  1251. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1252. AdviceType int64 `gorm:"column:advice_type" json:"advice_type"`
  1253. AdviceDate int64 `gorm:"column:advice_date" json:"advice_date"`
  1254. StartTime int64 `gorm:"column:start_time" json:"start_time"`
  1255. AdviceName string `gorm:"column:advice_name" json:"advice_name"`
  1256. AdviceDesc string `gorm:"column:advice_desc" json:"advice_desc"`
  1257. ReminderDate int64 `gorm:"column:reminder_date" json:"reminder_date"`
  1258. SingleDose float64 `gorm:"column:single_dose" json:"single_dose"`
  1259. SingleDoseUnit string `gorm:"column:single_dose_unit" json:"single_dose_unit"`
  1260. PrescribingNumber float64 `gorm:"column:prescribing_number" json:"prescribing_number"`
  1261. PrescribingNumberUnit string `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit"`
  1262. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way"`
  1263. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency"`
  1264. AdviceDoctor int64 `gorm:"column:advice_doctor" json:"advice_doctor"`
  1265. Status int64 `gorm:"column:status" json:"status"`
  1266. CreatedTime int64 `gorm:"column:created_time" json:"created_time"`
  1267. UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time"`
  1268. AdviceAffirm string `gorm:"column:advice_affirm" json:"advice_affirm"`
  1269. Remark string `gorm:"column:remark" json:"remark"`
  1270. StopTime int64 `gorm:"column:stop_time" json:"stop_time"`
  1271. StopReason string `gorm:"column:stop_reason" json:"stop_reason"`
  1272. StopDoctor int64 `gorm:"column:stop_doctor" json:"stop_doctor"`
  1273. StopState int64 `gorm:"column:stop_state" json:"stop_state"`
  1274. ParentId int64 `gorm:"column:parent_id" json:"parent_id"`
  1275. ExecutionTime int64 `gorm:"column:execution_time" json:"execution_time"`
  1276. ExecutionStaff int64 `gorm:"column:execution_staff" json:"execution_staff"`
  1277. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state"`
  1278. Checker int64 `gorm:"column:checker" json:"checker"`
  1279. RecordDate int64 `gorm:"column:record_date" json:"record_date"`
  1280. DialysisOrderId int64 `gorm:"column:dialysis_order_id" json:"dialysis_order_id"`
  1281. CheckTime int64 `gorm:"column:check_time" json:"check_time"`
  1282. CheckState int64 `gorm:"column:check_state" json:"check_state"`
  1283. DrugSpec float64 `gorm:"column:drug_spec" json:"drug_spec"`
  1284. DrugSpecUnit string `gorm:"column:drug_spec_unit" json:"drug_spec_unit"`
  1285. Groupno int64 `gorm:"column:groupno" json:"groupno"`
  1286. RemindType int64 `gorm:"column:remind_type" json:"remind_type"`
  1287. FrequencyType int64 `gorm:"column:frequency_type" json:"frequency_type"`
  1288. DayCount int64 `gorm:"column:day_count" json:"day_count"`
  1289. WeekDay string `gorm:"column:week_day" json:"week_day"`
  1290. TemplateId string `gorm:"column:template_id" json:"template_id"`
  1291. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1292. IsMedicine int64 `gorm:"column:is_medicine" json:"is_medicine" form:"is_medicine"`
  1293. IsSettle int64 `gorm:"column:is_settle" json:"is_settle" form:"is_settle"`
  1294. }
  1295. func (MDoctorAdviceVM) TableName() string {
  1296. return "xt_doctor_advice"
  1297. }
  1298. func MobileGetScheduleDoctorAdvices(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string) ([]*MScheduleDoctorAdviceVM, error) {
  1299. var vms []*MScheduleDoctorAdviceVM
  1300. adviceWhere := ""
  1301. adviceCondition := []interface{}{}
  1302. if adviceType == 0 {
  1303. if patientType == 0 {
  1304. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  1305. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1306. } else if patientType == 1 {
  1307. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  1308. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1309. } else if patientType == 2 {
  1310. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  1311. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1312. }
  1313. } else if adviceType == 1 {
  1314. if patientType == 0 {
  1315. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  1316. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1317. } else if patientType == 1 {
  1318. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  1319. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1320. } else if patientType == 2 {
  1321. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  1322. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1323. }
  1324. } else if adviceType == 3 {
  1325. if patientType == 0 {
  1326. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  1327. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1328. } else if patientType == 1 {
  1329. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  1330. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1331. } else if patientType == 2 {
  1332. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  1333. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1334. }
  1335. } else if adviceType == 2 && len(deliverWay) > 0 {
  1336. if patientType == 0 {
  1337. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  1338. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1339. } else if patientType == 1 {
  1340. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  1341. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  1342. } else if patientType == 2 {
  1343. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  1344. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1345. }
  1346. } else if adviceType == 2 && len(deliverWay) <= 0 {
  1347. if patientType == 0 {
  1348. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  1349. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1350. } else if patientType == 1 {
  1351. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND (advice_doctor = ? or execution_staff = ?)"
  1352. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, adminUserId)
  1353. } else if patientType == 2 {
  1354. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  1355. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1356. }
  1357. }
  1358. db := readDb.
  1359. Table("xt_schedule").
  1360. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1361. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1362. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1363. }).
  1364. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1365. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1366. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1367. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  1368. Preload("DoctorAdvices", adviceCondition...).
  1369. Where("status = 1 AND user_org_id = ?", orgID)
  1370. if scheduleDate != 0 {
  1371. db = db.Where("schedule_date = ?", scheduleDate)
  1372. }
  1373. err := db.Find(&vms).Error
  1374. return vms, err
  1375. }
  1376. func MobileGetScheduleDoctorAdvicesTwo(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string) ([]*MScheduleDoctorAdviceVMOne, error) {
  1377. var vms []*MScheduleDoctorAdviceVMOne
  1378. adviceWhere := ""
  1379. adviceCondition := []interface{}{}
  1380. if adviceType == 0 {
  1381. if patientType == 0 {
  1382. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  1383. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1384. } else if patientType == 1 {
  1385. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  1386. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1387. } else if patientType == 2 {
  1388. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  1389. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1390. } else if patientType == 3 {
  1391. 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"
  1392. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1393. } else if patientType == 4 {
  1394. 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)"
  1395. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1396. }
  1397. } else if adviceType == 1 {
  1398. if patientType == 0 {
  1399. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  1400. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1401. } else if patientType == 1 {
  1402. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  1403. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1404. } else if patientType == 2 {
  1405. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  1406. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1407. } else if patientType == 3 {
  1408. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = 1"
  1409. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1410. } else if patientType == 4 {
  1411. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and (is_settle = 0 or is_settle = 2)"
  1412. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1413. }
  1414. } else if adviceType == 3 {
  1415. if patientType == 0 {
  1416. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  1417. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1418. } else if patientType == 1 {
  1419. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  1420. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1421. } else if patientType == 2 {
  1422. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  1423. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1424. } else if patientType == 3 {
  1425. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 and is_settle = 1"
  1426. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1427. } else if patientType == 4 {
  1428. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 and (is_settle = 0 or is_settle = 2)"
  1429. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1430. }
  1431. } else if adviceType == 2 && len(deliverWay) > 0 {
  1432. if patientType == 0 {
  1433. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  1434. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1435. } else if patientType == 1 {
  1436. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  1437. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  1438. } else if patientType == 2 {
  1439. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  1440. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1441. } else if patientType == 3 {
  1442. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 and delivery_way = ? and is_settle = 1"
  1443. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1444. } else if patientType == 4 {
  1445. 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)"
  1446. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1447. }
  1448. } else if adviceType == 2 && len(deliverWay) <= 0 {
  1449. if patientType == 0 {
  1450. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  1451. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1452. } else if patientType == 1 {
  1453. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND (advice_doctor = ? or execution_staff = ?)"
  1454. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, adminUserId)
  1455. } else if patientType == 2 {
  1456. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  1457. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1458. } else if patientType == 3 {
  1459. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 and is_settle = 1"
  1460. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1461. } else if patientType == 4 {
  1462. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 and (is_settle = 0 or is_settle = 2)"
  1463. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1464. }
  1465. }
  1466. db := readDb.
  1467. Table("xt_schedule").
  1468. //Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1469. //Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1470. // return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1471. //}).
  1472. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1473. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1474. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1475. Preload("DoctorAdvices", adviceCondition...).
  1476. Where("status = 1 AND user_org_id = ?", orgID)
  1477. if scheduleDate != 0 {
  1478. db = db.Where("schedule_date = ?", scheduleDate)
  1479. }
  1480. err := db.Find(&vms).Error
  1481. return vms, err
  1482. }
  1483. func GetHisDoctorAdvices(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleDoctorAdviceVM, error) {
  1484. var vms []*HisMScheduleDoctorAdviceVM
  1485. if len(deliverWay) > 0 {
  1486. if patientType == 0 {
  1487. db := readDb.
  1488. Table("xt_schedule").
  1489. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  1490. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1491. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1492. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1493. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1494. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1495. }).
  1496. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1497. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1498. Where("status = 1 AND user_org_id = ?", orgID)
  1499. if scheduleDate != 0 {
  1500. db = db.Where("schedule_date = ?", scheduleDate)
  1501. }
  1502. err = db.Find(&vms).Error
  1503. }
  1504. if patientType > 0 {
  1505. db := readDb.
  1506. Table("xt_schedule").
  1507. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1508. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1509. 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).
  1510. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1511. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1512. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1513. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1514. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1515. }).Where("status = 1 AND user_org_id = ?", orgID)
  1516. if scheduleDate != 0 {
  1517. db = db.Where("schedule_date = ?", scheduleDate)
  1518. }
  1519. err = db.Find(&vms).Error
  1520. }
  1521. } else {
  1522. if patientType == 0 {
  1523. db := readDb.
  1524. Table("xt_schedule").
  1525. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? ", orgID, scheduleDate).
  1526. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1527. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1528. return db.Where("status = 1 AND user_org_id = ? and dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1529. }).
  1530. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1531. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1532. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1533. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1534. Where("status = 1 AND user_org_id = ?", orgID)
  1535. if scheduleDate != 0 {
  1536. db = db.Where("schedule_date = ?", scheduleDate)
  1537. }
  1538. err = db.Find(&vms).Error
  1539. }
  1540. if patientType > 0 {
  1541. db := readDb.
  1542. Table("xt_schedule").
  1543. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1544. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1545. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1546. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1547. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1548. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1549. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1550. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1551. Where("status = 1 AND user_org_id = ?", orgID)
  1552. if scheduleDate != 0 {
  1553. db = db.Where("schedule_date = ?", scheduleDate)
  1554. }
  1555. err = db.Find(&vms).Error
  1556. }
  1557. }
  1558. return vms, err
  1559. }
  1560. func GetHisDoctorAdvicesTwo(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleDoctorAdviceVMOne, error) {
  1561. var vms []*HisMScheduleDoctorAdviceVMOne
  1562. if len(deliverWay) > 0 {
  1563. if patientType == 0 {
  1564. db := readDb.
  1565. Table("xt_schedule").
  1566. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  1567. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1568. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1569. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1570. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1571. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1572. }).
  1573. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1574. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1575. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1576. Where("status = 1 AND user_org_id = ?", orgID)
  1577. if scheduleDate != 0 {
  1578. db = db.Where("schedule_date = ?", scheduleDate)
  1579. }
  1580. err = db.Find(&vms).Error
  1581. }
  1582. if patientType > 0 {
  1583. if patientType == 1 {
  1584. db := readDb.
  1585. Table("xt_schedule").
  1586. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1587. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1588. 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).
  1589. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1590. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1591. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1592. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1593. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1594. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1595. Where("status = 1 AND user_org_id = ?", orgID)
  1596. if scheduleDate != 0 {
  1597. db = db.Where("schedule_date = ?", scheduleDate)
  1598. }
  1599. err = db.Find(&vms).Error
  1600. }
  1601. if patientType == 2 {
  1602. db := readDb.
  1603. Table("xt_schedule").
  1604. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1605. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1606. 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).
  1607. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1608. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1609. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1610. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1611. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1612. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Where("status = 1 AND user_org_id = ?", orgID)
  1613. if scheduleDate != 0 {
  1614. db = db.Where("schedule_date = ?", scheduleDate)
  1615. }
  1616. err = db.Find(&vms).Error
  1617. }
  1618. if patientType == 3 {
  1619. db := readDb.
  1620. Table("xt_schedule").
  1621. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1622. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1623. 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).
  1624. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1625. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1626. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1627. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1628. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1629. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Where("status = 1 AND user_org_id = ?", orgID)
  1630. if scheduleDate != 0 {
  1631. db = db.Where("schedule_date = ?", scheduleDate)
  1632. }
  1633. err = db.Find(&vms).Error
  1634. }
  1635. if patientType == 4 {
  1636. db := readDb.
  1637. Table("xt_schedule").
  1638. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1639. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1640. 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).
  1641. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1642. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1643. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1644. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1645. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1646. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Where("status = 1 AND user_org_id = ?", orgID)
  1647. if scheduleDate != 0 {
  1648. db = db.Where("schedule_date = ?", scheduleDate)
  1649. }
  1650. err = db.Find(&vms).Error
  1651. }
  1652. }
  1653. } else {
  1654. if patientType == 0 {
  1655. db := readDb.
  1656. Table("xt_schedule").
  1657. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? ", orgID, scheduleDate).
  1658. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1659. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1660. return db.Where("status = 1 AND user_org_id = ? and dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1661. }).
  1662. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1663. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1664. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1665. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1666. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1667. Where("status = 1 AND user_org_id = ?", orgID)
  1668. if scheduleDate != 0 {
  1669. db = db.Where("schedule_date = ?", scheduleDate)
  1670. }
  1671. err = db.Find(&vms).Error
  1672. }
  1673. if patientType > 0 {
  1674. if patientType == 1 {
  1675. db := readDb.
  1676. Table("xt_schedule").
  1677. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1678. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1679. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1680. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1681. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1682. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1683. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1684. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1685. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1686. Where("status = 1 AND user_org_id = ?", orgID)
  1687. if scheduleDate != 0 {
  1688. db = db.Where("schedule_date = ?", scheduleDate)
  1689. }
  1690. err = db.Find(&vms).Error
  1691. }
  1692. if patientType == 2 {
  1693. db := readDb.
  1694. Table("xt_schedule").
  1695. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1696. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1697. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1698. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1699. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1700. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1701. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1702. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1703. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1704. Where("status = 1 AND user_org_id = ?", orgID)
  1705. if scheduleDate != 0 {
  1706. db = db.Where("schedule_date = ?", scheduleDate)
  1707. }
  1708. err = db.Find(&vms).Error
  1709. }
  1710. if patientType == 3 {
  1711. db := readDb.
  1712. Table("xt_schedule").
  1713. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1714. 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).
  1715. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1716. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1717. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1718. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1719. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1720. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1721. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1722. Where("status = 1 AND user_org_id = ?", orgID)
  1723. if scheduleDate != 0 {
  1724. db = db.Where("schedule_date = ?", scheduleDate)
  1725. }
  1726. err = db.Find(&vms).Error
  1727. }
  1728. if patientType == 4 {
  1729. db := readDb.
  1730. Table("xt_schedule").
  1731. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1732. 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).
  1733. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1734. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1735. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1736. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1737. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1738. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1739. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1740. Where("status = 1 AND user_org_id = ?", orgID)
  1741. if scheduleDate != 0 {
  1742. db = db.Where("schedule_date = ?", scheduleDate)
  1743. }
  1744. err = db.Find(&vms).Error
  1745. }
  1746. }
  1747. }
  1748. return vms, err
  1749. }
  1750. func GetMobileHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleProjectVM, error) {
  1751. var vms []*HisMScheduleProjectVM
  1752. //if patientType == 0 {
  1753. // db := readDb.
  1754. // Table("xt_schedule").
  1755. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1756. // Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1757. // return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1758. // }).
  1759. // Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1760. // Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1761. // Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1762. // Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1763. // return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1764. // }).
  1765. // Where("status = 1 AND user_org_id = ?", orgID)
  1766. // if scheduleDate != 0 {
  1767. // db = db.Where("schedule_date = ?", scheduleDate)
  1768. // }
  1769. // err = db.Find(&vms).Error
  1770. //}
  1771. //if patientType > 0 {
  1772. // db := readDb.
  1773. // Table("xt_schedule").
  1774. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1775. // Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1776. // return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1777. // }).
  1778. // Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1779. // Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1780. // Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1781. // Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1782. // Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1783. // return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1784. // }).
  1785. // Where("status = 1 AND user_org_id = ?", orgID)
  1786. // if scheduleDate != 0 {
  1787. // db = db.Where("schedule_date = ?", scheduleDate)
  1788. // }
  1789. // err = db.Find(&vms).Error
  1790. //}
  1791. db := readDb.Table("xt_schedule").Where("status = 1")
  1792. if orgID > 0 {
  1793. db = db.Where("user_org_id = ?", orgID)
  1794. }
  1795. if scheduleDate > 0 {
  1796. db = db.Where("schedule_date =?", scheduleDate)
  1797. }
  1798. err = db.Find(&vms).Error
  1799. if patientType == 0 {
  1800. db := readDb.
  1801. Table("xt_schedule").
  1802. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1803. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1804. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1805. }).
  1806. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1807. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1808. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1809. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1810. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1811. }).
  1812. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  1813. 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")
  1814. }).
  1815. Where("status = 1 AND user_org_id = ?", orgID)
  1816. if scheduleDate != 0 {
  1817. db = db.Where("schedule_date = ?", scheduleDate)
  1818. }
  1819. err = db.Find(&vms).Error
  1820. }
  1821. if patientType > 0 {
  1822. db := readDb.
  1823. Table("xt_schedule").
  1824. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1825. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1826. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1827. }).
  1828. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1829. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1830. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1831. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1832. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1833. }).
  1834. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  1835. 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")
  1836. }).
  1837. Where("status = 1 AND user_org_id = ?", orgID)
  1838. if scheduleDate != 0 {
  1839. db = db.Where("schedule_date = ?", scheduleDate)
  1840. }
  1841. err = db.Find(&vms).Error
  1842. }
  1843. return vms, err
  1844. }
  1845. func MobileCreateDialysisOrder(orgID int64, patientID int64, order *models.DialysisOrder) error {
  1846. now := time.Now()
  1847. tx := writeDb.Begin()
  1848. if createOrderErr := tx.Model(&models.DialysisOrder{}).Create(order).Error; createOrderErr != nil {
  1849. tx.Rollback()
  1850. return createOrderErr
  1851. }
  1852. // 更新透析记录 ID
  1853. // 透析处方
  1854. 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 {
  1855. tx.Rollback()
  1856. return err
  1857. }
  1858. // 接诊评估
  1859. 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 {
  1860. tx.Rollback()
  1861. return err
  1862. }
  1863. // 透前评估
  1864. 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 {
  1865. tx.Rollback()
  1866. return err
  1867. }
  1868. // 临时医嘱
  1869. 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 {
  1870. tx.Rollback()
  1871. return err
  1872. }
  1873. // 双人核对
  1874. 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 {
  1875. tx.Rollback()
  1876. return err
  1877. }
  1878. // 透后评估
  1879. 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 {
  1880. tx.Rollback()
  1881. return err
  1882. }
  1883. // 治疗小结
  1884. 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 {
  1885. tx.Rollback()
  1886. return err
  1887. }
  1888. // 透析监测
  1889. 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 {
  1890. tx.Rollback()
  1891. return err
  1892. }
  1893. tx.Commit()
  1894. return nil
  1895. }
  1896. type MobileUrgentSchedulePatientVM struct {
  1897. ID int64 `gorm:"column:id" json:"id"`
  1898. Name string `gorm:"column:name" json:"name"`
  1899. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no"`
  1900. }
  1901. func (MobileUrgentSchedulePatientVM) TableName() string {
  1902. return "xt_patients"
  1903. }
  1904. type MobileUrgentScheduleTreatmentModeVM struct {
  1905. ID int64 `gorm:"column:id" json:"id"`
  1906. Name string `gorm:"column:name" json:"name"`
  1907. }
  1908. func (MobileUrgentScheduleTreatmentModeVM) TableName() string {
  1909. return "xt_treatment_mode"
  1910. }
  1911. func MobileGetAllPatientsForUrgentSchedule(orgID int64, record_date int64) ([]*MobileUrgentSchedulePatientVM, error) {
  1912. var vms []*MobileUrgentSchedulePatientVM = make([]*MobileUrgentSchedulePatientVM, 0)
  1913. 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()
  1914. defer rows.Close()
  1915. if err != nil {
  1916. return nil, err
  1917. }
  1918. for rows.Next() {
  1919. var vm MobileUrgentSchedulePatientVM
  1920. readDb.ScanRows(rows, &vm)
  1921. vms = append(vms, &vm)
  1922. }
  1923. return vms, nil
  1924. }
  1925. func MobileGetAllTrearmentModesForUrgentSchedule() ([]*MobileUrgentScheduleTreatmentModeVM, error) {
  1926. var modes []*MobileUrgentScheduleTreatmentModeVM
  1927. err := readDb.Model(&MobileUrgentScheduleTreatmentModeVM{}).Where("status = 1").Find(&modes).Error
  1928. if err != nil {
  1929. return nil, err
  1930. }
  1931. return modes, nil
  1932. }
  1933. type MobileUrgentScheduleScheduleListVM struct {
  1934. ID int64 `gorm:"column:id" json:"id"`
  1935. // ZoneID int64 `gorm:"column:partition_id" json:"zone_id"`
  1936. DeviceNumberID int64 `gorm:"column:bed_id" json:"bed_id"`
  1937. PatientID int64 `gorm:"column:patient_id" json:"patient_id"`
  1938. ScheduleType int `gorm:"column:schedule_type" json:"schedule_type"`
  1939. DeviceNumber *models.DeviceNumber `gorm:"ForeignKey:DeviceNumberID" json:"device_number"`
  1940. // DeviceZone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"device_zone"`
  1941. }
  1942. func (MobileUrgentScheduleScheduleListVM) TableName() string {
  1943. return "xt_schedule"
  1944. }
  1945. func MobileGetSchedulesForUrgentSchedule(orgID int64, scheduleDate int64, schedule_type int) (schedules []*MobileUrgentScheduleScheduleListVM, err error) {
  1946. db := readDb.
  1947. Model(&MobileUrgentScheduleScheduleListVM{}).
  1948. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1949. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND schedule_type = ? ", orgID, scheduleDate, schedule_type)
  1950. err = db.Find(&schedules).Error
  1951. if err != nil {
  1952. return nil, err
  1953. }
  1954. return schedules, nil
  1955. }
  1956. func MobileGetOtherSchedulesForUrgentSchedule(orgID int64, scheduleDate int64, schedule_type int) ([]*MobileUrgentScheduleScheduleListVM, error) {
  1957. var vms []*MobileUrgentScheduleScheduleListVM = make([]*MobileUrgentScheduleScheduleListVM, 0)
  1958. 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()
  1959. defer rows.Close()
  1960. if err != nil {
  1961. return nil, err
  1962. }
  1963. for rows.Next() {
  1964. var vm MobileUrgentScheduleScheduleListVM
  1965. readDb.ScanRows(rows, &vm)
  1966. vms = append(vms, &vm)
  1967. }
  1968. return vms, nil
  1969. }
  1970. type MobileUrgentScheduleDeviceNumberVM struct {
  1971. ID int64 `gorm:"column:id" json:"id"`
  1972. Number string `gorm:"column:number" json:"number"`
  1973. ZoneID int64 `gorm:"column:zone_id" json:"zone_id"`
  1974. Zone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"zone"`
  1975. }
  1976. func (MobileUrgentScheduleDeviceNumberVM) TableName() string {
  1977. return "xt_device_number"
  1978. }
  1979. func MobileGetAllDeviceNumbersForUrgentSchedule(orgID int64, record_date int64, schedule_type int) ([]*DeviceNumberViewModel, error) {
  1980. var vms []*DeviceNumberViewModel = make([]*DeviceNumberViewModel, 0)
  1981. 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()
  1982. defer rows.Close()
  1983. if err != nil {
  1984. return nil, err
  1985. }
  1986. for rows.Next() {
  1987. var vm DeviceNumberViewModel
  1988. readDb.ScanRows(rows, &vm)
  1989. vms = append(vms, &vm)
  1990. }
  1991. return vms, nil
  1992. //var deviceNumbers []*MobileUrgentScheduleDeviceNumberVM
  1993. //db := readDb.
  1994. // Model(&MobileUrgentScheduleDeviceNumberVM{}).
  1995. // Preload("Zone", "status = 1 AND org_id = ?", orgID).
  1996. // Where("status = 1 AND org_id = ?", orgID)
  1997. //err := db.Order("zone_id asc").Find(&deviceNumbers).Error
  1998. //if err != nil {
  1999. // return nil, err
  2000. //}
  2001. //return deviceNumbers, nil
  2002. }
  2003. func GetValidScheduleMonitorRecordCount() (int64, error) {
  2004. var total int64
  2005. err := readDb.Model(&models.MonitoringRecord{}).Where("status = 1 AND operate_time = 0 AND monitoring_date <> 0").Count(&total).Error
  2006. return total, err
  2007. }
  2008. func GetTop1000ValidScheduleMonitorRecord() ([]*models.MonitoringRecord, error) {
  2009. var monitors []*models.MonitoringRecord
  2010. err := readDb.Model(&models.MonitoringRecord{}).Where("status = 1 AND operate_time = 0 AND monitoring_date <> 0").Order("id asc").Limit(100).Find(&monitors).Error
  2011. if err != nil {
  2012. return nil, err
  2013. }
  2014. return monitors, nil
  2015. }
  2016. func BatchUpdateMonitors(monitors []*models.MonitoringRecord) error {
  2017. tx := writeDb.Begin()
  2018. for index := 0; index < len(monitors); index++ {
  2019. tx.Save(monitors[index])
  2020. }
  2021. return tx.Commit().Error
  2022. }
  2023. func ModifyStartDialysisOrder(order *models.DialysisOrder) error {
  2024. tx := writeDb.Begin()
  2025. updateTime := time.Now().Unix()
  2026. 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, "blood_flow_volume": order.BloodFlowVolume, "blood_drawing": order.BloodDrawing}).Error
  2027. if err != nil {
  2028. tx.Rollback()
  2029. return err
  2030. }
  2031. tx.Commit()
  2032. return err
  2033. }
  2034. func ModifyFinishDialysisOrder(order *models.DialysisOrder) error {
  2035. tx := writeDb.Begin()
  2036. updateTime := time.Now().Unix()
  2037. 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, "condenser": order.Condenser}).Error
  2038. if err != nil {
  2039. tx.Rollback()
  2040. return err
  2041. }
  2042. tx.Commit()
  2043. return err
  2044. }
  2045. func MobileGetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  2046. var record models.SgjPatientDryweight
  2047. err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  2048. if err != nil {
  2049. if err == gorm.ErrRecordNotFound {
  2050. return nil, nil
  2051. } else {
  2052. return nil, err
  2053. }
  2054. }
  2055. return &record, nil
  2056. }
  2057. //func MobileGetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  2058. // var record models.SgjPatientDryweight
  2059. // redis := RedisClient()
  2060. // defer redis.Close()
  2061. //
  2062. // key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":last_dry_weight"
  2063. // last_dry_weight_str, _ := redis.Get(key).Result()
  2064. //
  2065. // if len(last_dry_weight_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2066. // err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  2067. // if err != nil {
  2068. // if err == gorm.ErrRecordNotFound {
  2069. // if record.ID <= 0 {
  2070. // redis.Set(key, "null", time.Second*60*60*18)
  2071. // }
  2072. // return nil, nil
  2073. // } else {
  2074. // return nil, err
  2075. // }
  2076. // } else {
  2077. // if record.ID > 0 {
  2078. // //缓存数据
  2079. // last_dry_weight_str, err := json.Marshal(record)
  2080. // if err == nil {
  2081. // redis.Set(key, last_dry_weight_str, time.Second*60*60*18)
  2082. // return nil, err
  2083. // }
  2084. // } else {
  2085. // redis.Set(key, "null", time.Second*60*60*18)
  2086. // return nil, err
  2087. // }
  2088. // return &record, nil
  2089. // }
  2090. // } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2091. // if last_dry_weight_str == "null" {
  2092. // return &record, nil
  2093. // } else {
  2094. // json.Unmarshal([]byte(last_dry_weight_str), &record)
  2095. // return &record, nil
  2096. // }
  2097. //
  2098. // }
  2099. //}
  2100. // 透析方案
  2101. func MobileGetDialysisSolutionByModeIdSix(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  2102. var record models.DialysisSolution
  2103. err := readDb.Model(&models.DialysisSolution{}).Where("patient_id = ? and user_org_id = ? and status = 1 AND mode_id = ? and solution_status =1", patientID, orgID, mode_id).Last(&record).Error
  2104. if err != nil {
  2105. if err == gorm.ErrRecordNotFound {
  2106. return nil, nil
  2107. } else {
  2108. return nil, err
  2109. }
  2110. }
  2111. return &record, nil
  2112. }
  2113. // 透析方案
  2114. func MobileGetDialysisSolutionByModeIdSevenTwety(orgID int64, patientID int64, mode_id int64) (models.DialysisSolution, error) {
  2115. var record models.DialysisSolution
  2116. err = readDb.Model(&models.DialysisSolution{}).Where("patient_id = ? and user_org_id = ? and status = 1 AND mode_id = ? and solution_status =1", patientID, orgID, mode_id).Last(&record).Error
  2117. return record, nil
  2118. }
  2119. // 透析方案
  2120. func MobileGetDialysisSolutionByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  2121. var record models.DialysisSolution
  2122. redis := RedisClient()
  2123. defer redis.Close()
  2124. // cur_date := time.Now().Format("2006-01-02")
  2125. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2126. dialysis_solution_str, _ := redis.Get(key).Result()
  2127. if len(dialysis_solution_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2128. err := readDb.Model(&models.DialysisSolution{}).Where("patient_id = ? and user_org_id = ? and status = 1 AND mode_id = ? and solution_status=1", patientID, orgID, mode_id).Last(&record).Error
  2129. if err != nil {
  2130. if err == gorm.ErrRecordNotFound {
  2131. if record.ID <= 0 {
  2132. redis.Set(key, "null", time.Second*60*60*18)
  2133. }
  2134. return nil, nil
  2135. } else {
  2136. return nil, err
  2137. }
  2138. } else {
  2139. if record.ID > 0 {
  2140. //缓存数据
  2141. dialysis_solution_str, err := json.Marshal(record)
  2142. if err == nil {
  2143. redis.Set(key, dialysis_solution_str, time.Second*60*60*18)
  2144. }
  2145. } else {
  2146. redis.Set(key, "null", time.Second*60*60*18)
  2147. }
  2148. return &record, nil
  2149. }
  2150. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2151. if dialysis_solution_str == "null" {
  2152. return &record, nil
  2153. } else {
  2154. json.Unmarshal([]byte(dialysis_solution_str), &record)
  2155. return &record, nil
  2156. }
  2157. }
  2158. }
  2159. // 透析处方
  2160. func MobileGetDialysisPrescribeByModeId(orgID int64, patientID int64, recordDate int64, mode_id int64) (*models.DialysisPrescription, error) {
  2161. var record models.DialysisPrescription
  2162. redis := RedisClient()
  2163. defer redis.Close()
  2164. // cur_date := time.Now().Format("2006-01-02")
  2165. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2166. redis.Set(key, "", time.Second)
  2167. dialysis_prescribe_str, _ := redis.Get(key).Result()
  2168. if len(dialysis_prescribe_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2169. 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
  2170. if err != nil {
  2171. if err == gorm.ErrRecordNotFound {
  2172. if record.ID <= 0 {
  2173. redis.Set(key, "null", time.Second*60*60*18)
  2174. }
  2175. return nil, nil
  2176. } else {
  2177. return nil, err
  2178. }
  2179. } else {
  2180. if record.ID > 0 {
  2181. //缓存数据
  2182. dialysis_prescribe_str, err := json.Marshal(record)
  2183. if err == nil {
  2184. redis.Set(key, dialysis_prescribe_str, time.Second*60*60*18)
  2185. }
  2186. } else {
  2187. redis.Set(key, "null", time.Second*60*60*18)
  2188. }
  2189. return &record, nil
  2190. }
  2191. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2192. if dialysis_prescribe_str == "null" {
  2193. return &record, nil
  2194. } else {
  2195. json.Unmarshal([]byte(dialysis_prescribe_str), &record)
  2196. return &record, nil
  2197. }
  2198. }
  2199. }
  2200. func MobileGetDialysisPrescribeByModeIdSix(orgID int64, patientID int64, recordDate int64, mode_id int64) (*models.DialysisPrescription, error) {
  2201. var record models.DialysisPrescription
  2202. 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
  2203. if err != nil {
  2204. if err == gorm.ErrRecordNotFound {
  2205. return nil, nil
  2206. } else {
  2207. return nil, err
  2208. }
  2209. }
  2210. return &record, nil
  2211. }
  2212. func MobileGetDialysisPrescribeByModeIdOne(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  2213. var record models.DialysisPrescription
  2214. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  2215. if err != nil {
  2216. if err == gorm.ErrRecordNotFound {
  2217. return nil, nil
  2218. } else {
  2219. return nil, err
  2220. }
  2221. }
  2222. return &record, nil
  2223. }
  2224. //func MobileGetDialysisPrescribeByModeIdOne(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  2225. // var record models.DialysisPrescription
  2226. // redis := RedisClient()
  2227. // defer redis.Close()
  2228. //
  2229. // // cur_date := time.Now().Format("2006-01-02")
  2230. // key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":dialysis_prescribe_by_mode"
  2231. // dialysis_prescribe_by_mode_str, _ := redis.Get(key).Result()
  2232. //
  2233. // if len(dialysis_prescribe_by_mode_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2234. // err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  2235. // if err != nil {
  2236. // if err == gorm.ErrRecordNotFound {
  2237. // if record.ID <= 0 {
  2238. // redis.Set(key, "null", time.Second*60*60*18)
  2239. // }
  2240. // return nil, nil
  2241. // } else {
  2242. // return nil, err
  2243. // }
  2244. // } else {
  2245. //
  2246. // if record.ID > 0 {
  2247. // //缓存数据
  2248. // dialysis_prescribe_by_mode_str, err := json.Marshal(record)
  2249. //
  2250. // if err == nil {
  2251. // redis.Set(key, dialysis_prescribe_by_mode_str, time.Second*60*60*18)
  2252. // return nil, err
  2253. // }
  2254. // } else {
  2255. // redis.Set(key, "null", time.Second*60*60*18)
  2256. // return nil, err
  2257. // }
  2258. // return &record, nil
  2259. // }
  2260. // } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2261. // if dialysis_prescribe_by_mode_str == "null" {
  2262. // json.Unmarshal([]byte(dialysis_prescribe_by_mode_str), &record)
  2263. // return &record, nil
  2264. // } else {
  2265. // json.Unmarshal([]byte(dialysis_prescribe_by_mode_str), &record)
  2266. // return &record, nil
  2267. // }
  2268. //
  2269. // }
  2270. //}
  2271. func MobileGetLastDialysisPrescribe(orgID int64, patientID int64) (*models.DialysisPrescription, error) {
  2272. var record models.DialysisPrescription
  2273. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 ", patientID, orgID).Last(&record).Error
  2274. if err != nil {
  2275. if err == gorm.ErrRecordNotFound {
  2276. return nil, nil
  2277. } else {
  2278. return nil, err
  2279. }
  2280. }
  2281. return &record, nil
  2282. }
  2283. func MobileGetLastDialysisPrescribeByModeIdSix(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2284. var record models.DialysisPrescription
  2285. 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
  2286. //if err != nil {
  2287. // if err == gorm.ErrRecordNotFound {
  2288. // return nil, nil
  2289. // } else {
  2290. // return nil, err
  2291. // }
  2292. //}
  2293. return &record, err
  2294. }
  2295. func MobileGetLastDialysisPrescribeByModeIdTen(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2296. var record models.DialysisPrescription
  2297. 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
  2298. if err != nil {
  2299. if err == gorm.ErrRecordNotFound {
  2300. return nil, nil
  2301. } else {
  2302. return nil, err
  2303. }
  2304. }
  2305. return &record, err
  2306. }
  2307. func MobileGetLastDialysisPrescribeByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2308. var record models.DialysisPrescription
  2309. redis := RedisClient()
  2310. defer redis.Close()
  2311. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  2312. dialysis_prescribe_by_mode_id, _ := redis.Get(key).Result()
  2313. if len(dialysis_prescribe_by_mode_id) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2314. 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
  2315. if err != nil {
  2316. if err == gorm.ErrRecordNotFound {
  2317. if record.ID <= 0 {
  2318. redis.Set(key, "null", time.Second*60*60*18)
  2319. }
  2320. return nil, nil
  2321. } else {
  2322. return nil, err
  2323. }
  2324. } else {
  2325. if record.ID > 0 {
  2326. //缓存数据
  2327. dialysis_prescribe_by_mode_str, err := json.Marshal(record)
  2328. if err == nil {
  2329. redis.Set(key, dialysis_prescribe_by_mode_str, time.Second*60*60*18)
  2330. return nil, err
  2331. }
  2332. } else {
  2333. redis.Set(key, "null", time.Second*60*60*18)
  2334. return nil, err
  2335. }
  2336. return &record, nil
  2337. }
  2338. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2339. if dialysis_prescribe_by_mode_id == "null" {
  2340. return &record, nil
  2341. } else {
  2342. json.Unmarshal([]byte(dialysis_prescribe_by_mode_id), &record)
  2343. return &record, nil
  2344. }
  2345. }
  2346. }
  2347. func MobileGetLastDialysisPrescribeByModeIdOne(orgID int64, patientID int64, mode_id int64) (models.DialysisPrescription, error) {
  2348. var record models.DialysisPrescription
  2349. 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
  2350. return record, err
  2351. }
  2352. func GetAllAvaildDeviceNumbers(orgID int64, record_date int64, schedule_type int) ([]*DeviceNumberViewModel, error) {
  2353. var vms []*DeviceNumberViewModel = make([]*DeviceNumberViewModel, 0)
  2354. 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()
  2355. defer rows.Close()
  2356. if err != nil {
  2357. return nil, err
  2358. }
  2359. for rows.Next() {
  2360. var vm DeviceNumberViewModel
  2361. readDb.ScanRows(rows, &vm)
  2362. vms = append(vms, &vm)
  2363. }
  2364. return vms, nil
  2365. }
  2366. // 获取 maxDate 之前一次的透前评估记录
  2367. func GetLastTimePredialysisEvaluation(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
  2368. var record models.PredialysisEvaluation
  2369. 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
  2370. if err != nil {
  2371. if err == gorm.ErrRecordNotFound {
  2372. return nil, nil
  2373. } else {
  2374. return nil, err
  2375. }
  2376. }
  2377. return &record, nil
  2378. }
  2379. func GetLastTimeOrder(orgID int64, patientID int64, maxDate int64) (*models.DialysisOrder, error) {
  2380. var record models.DialysisOrder
  2381. 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
  2382. if err != nil {
  2383. if err == gorm.ErrRecordNotFound {
  2384. return nil, nil
  2385. } else {
  2386. return nil, err
  2387. }
  2388. }
  2389. return &record, nil
  2390. }
  2391. func GetLastMonitorRecord(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  2392. var record models.MonitoringRecord
  2393. 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
  2394. if err != nil {
  2395. if err == gorm.ErrRecordNotFound {
  2396. return nil, nil
  2397. } else {
  2398. return nil, err
  2399. }
  2400. }
  2401. return &record, nil
  2402. }
  2403. // 获取 maxDate 之前一次的透后评估记录
  2404. func GetLastTimeAssessmentAfterDislysis(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  2405. var record models.AssessmentAfterDislysis
  2406. 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
  2407. if err != nil {
  2408. if err == gorm.ErrRecordNotFound {
  2409. return nil, nil
  2410. } else {
  2411. return nil, err
  2412. }
  2413. }
  2414. return &record, nil
  2415. }
  2416. // 透析处方
  2417. func GetDialysisPrescribe(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  2418. var record models.DialysisPrescription
  2419. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  2420. if err != nil {
  2421. if err == gorm.ErrRecordNotFound {
  2422. return nil, nil
  2423. } else {
  2424. return nil, err
  2425. }
  2426. }
  2427. return &record, nil
  2428. }
  2429. // 透析方案
  2430. func GetDialysisSolution(orgID int64, patientID int64, mode_id int64) (models.DialysisSolution, error) {
  2431. var record models.DialysisSolution
  2432. 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
  2433. return record, err
  2434. }
  2435. func GetDialysisSolutionOne(orgID int64, mode_id int64) (*models.DialysisSolution, error) {
  2436. var record models.DialysisSolution
  2437. err := readDb.Model(&models.DialysisSolution{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2438. if err != nil {
  2439. if err == gorm.ErrRecordNotFound {
  2440. return nil, nil
  2441. } else {
  2442. return nil, err
  2443. }
  2444. }
  2445. return &record, nil
  2446. }
  2447. func GetLastDialysisPrescribeByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2448. var record models.DialysisPrescription
  2449. 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
  2450. if err != nil {
  2451. if err == gorm.ErrRecordNotFound {
  2452. return nil, nil
  2453. } else {
  2454. return nil, err
  2455. }
  2456. }
  2457. return &record, nil
  2458. }
  2459. func GetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  2460. var record models.SgjPatientDryweight
  2461. err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  2462. if err != nil {
  2463. if err == gorm.ErrRecordNotFound {
  2464. return nil, nil
  2465. } else {
  2466. return nil, err
  2467. }
  2468. }
  2469. return &record, nil
  2470. }
  2471. func MobileGetSystemDialysisPrescribeByModeIdSix(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2472. var record models.SystemPrescription
  2473. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).First(&record).Error
  2474. if err != nil {
  2475. if err == gorm.ErrRecordNotFound {
  2476. return nil, nil
  2477. } else {
  2478. return nil, err
  2479. }
  2480. }
  2481. return &record, nil
  2482. }
  2483. func MobileGetSystemDialysisPrescribeByModeId(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2484. var record models.SystemPrescription
  2485. redis := RedisClient()
  2486. defer redis.Close()
  2487. // cur_date := time.Now().Format("2006-01-02")
  2488. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  2489. system_dialysis_prescribe_str, _ := redis.Get(key).Result()
  2490. if len(system_dialysis_prescribe_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2491. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2492. if err != nil {
  2493. if err == gorm.ErrRecordNotFound {
  2494. if record.ID <= 0 {
  2495. redis.Set(key, "null", time.Second*60*60*18)
  2496. }
  2497. return nil, nil
  2498. } else {
  2499. return nil, err
  2500. }
  2501. } else {
  2502. if record.ID > 0 {
  2503. //缓存数据
  2504. system_dialysis_prescribe_str, err := json.Marshal(record)
  2505. if err == nil {
  2506. redis.Set(key, system_dialysis_prescribe_str, time.Second*60*60*18)
  2507. }
  2508. } else {
  2509. redis.Set(key, "null", time.Second*60*60*18)
  2510. }
  2511. return &record, nil
  2512. }
  2513. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2514. if system_dialysis_prescribe_str == "null" {
  2515. return &record, nil
  2516. } else {
  2517. json.Unmarshal([]byte(system_dialysis_prescribe_str), &record)
  2518. return &record, nil
  2519. }
  2520. }
  2521. }
  2522. func MobileGetSystemDialysisPrescribeByModeIdOne(orgID int64, mode_id int64) (models.SystemPrescription, error) {
  2523. var record models.SystemPrescription
  2524. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2525. return record, err
  2526. }
  2527. func GetSystemDialysisPrescribeByModeId(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2528. var record models.SystemPrescription
  2529. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2530. if err != nil {
  2531. if err == gorm.ErrRecordNotFound {
  2532. return nil, nil
  2533. } else {
  2534. return nil, err
  2535. }
  2536. }
  2537. return &record, nil
  2538. }
  2539. func GetDialysisOrderCount(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2540. 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
  2541. return
  2542. }
  2543. func GetDialysisOrderCountOne(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2544. 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
  2545. return
  2546. }
  2547. func GetDialysisOrderCountTwo(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2548. err = readDb.Model(&models.DialysisOrder{}).Where("dialysis_date>=1704038400 and dialysis_date <= ? AND status = 1 AND stage = 2 AND user_org_id = ? AND patient_id = ?", recordDate, orgID, patient_id).Count(&count).Error
  2549. return
  2550. }
  2551. func GetFirstDateOfMonth(d time.Time) time.Time {
  2552. d = d.AddDate(0, 0, -d.Day()+1)
  2553. return GetZeroTime(d)
  2554. }
  2555. func GetZeroTime(d time.Time) time.Time {
  2556. return time.Date(d.Year(), d.Month(), d.Day(), 0, 0, 0, 0, d.Location())
  2557. }
  2558. func GetDialysisCountByPatientId(startime int64, endtime int64, patientid int64, orgid int64) (order []*models.BloodDialysisOrderCount, err error) {
  2559. db := XTReadDB().Table("xt_dialysis_order as o")
  2560. 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
  2561. return order, err
  2562. }
  2563. func FindConsumablesByDate(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error) {
  2564. 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
  2565. return
  2566. }
  2567. func FindConsumablesByDateTwo(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error) {
  2568. 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
  2569. return
  2570. }
  2571. func FindConsumablesByDateThree(orgID int64, patient_id int64, recordDate int64) (consumables []*models.BloodAutomaticReduceDetail, err error) {
  2572. 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
  2573. return
  2574. }
  2575. //func FindLastConsumables(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error){
  2576. // 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
  2577. // return
  2578. //}
  2579. //
  2580. func GetLastTimeConsumables(orgID int64, patientID int64, maxDate int64) (prepare []*models.DialysisBeforePrepare, err error) {
  2581. 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
  2582. return
  2583. }
  2584. type GoodsType struct {
  2585. ID int64 `gorm:"column:id" json:"id"`
  2586. TypeName string `gorm:"column:type_name" json:"type_name"`
  2587. Remark string `gorm:"column:remark" json:"remark"`
  2588. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2589. Status int64 `gorm:"column:status" json:"status"`
  2590. Type int64 `gorm:"column:type" json:"type"`
  2591. }
  2592. func (GoodsType) TableName() string {
  2593. return "xt_goods_type"
  2594. }
  2595. type VMGoodInfo struct {
  2596. ID int64 `gorm:"column:id" json:"id"`
  2597. SpecificationName string `gorm:"column:specification_name" json:"specification_name"`
  2598. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2599. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2600. GoodName string `gorm:"column:good_name" json:"good_name" form:"good_name"`
  2601. GoodUnit int64 `gorm:"column:good_unit" json:"good_unit" form:"good_unit"`
  2602. Total float64 `gorm:"column:total" json:"total" form:"total"`
  2603. PackingUnit string `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
  2604. MedicalInsuranceNumber string `gorm:"column:medical_insurance_number" json:"medical_insurance_number" form:"medical_insurance_number"`
  2605. }
  2606. func (VMGoodInfo) TableName() string {
  2607. return "xt_good_information"
  2608. }
  2609. type AutomaticReduceDetail struct {
  2610. ID int64 `gorm:"column:id" json:"id"`
  2611. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2612. Status int64 `gorm:"column:status" json:"status"`
  2613. RecordTime int64 `gorm:"column:record_time" json:"record_time"`
  2614. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2615. GoodId int64 `gorm:"column:good_id" json:"good_id"`
  2616. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2617. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"info"`
  2618. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"type"`
  2619. Count int64 `gorm:"column:count" json:"count"`
  2620. }
  2621. func (AutomaticReduceDetail) TableName() string {
  2622. return "xt_automatic_reduce_detail"
  2623. }
  2624. type DialysisBeforePrepare struct {
  2625. ID int64 `gorm:"column:id" json:"id" form:"id"`
  2626. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  2627. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  2628. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  2629. GoodId int64 `gorm:"column:good_id" json:"good_id" form:"good_id"`
  2630. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id" form:"good_type_id"`
  2631. Count int64 `gorm:"column:count" json:"count" form:"count"`
  2632. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  2633. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  2634. Creater int64 `gorm:"column:creater" json:"creater" form:"creater"`
  2635. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  2636. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"info"`
  2637. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"type"`
  2638. }
  2639. func (DialysisBeforePrepare) TableName() string {
  2640. return "dialysis_before_prepare"
  2641. }
  2642. type MDialysisGoodsVM struct {
  2643. ID int64 `gorm:"column:id" json:"id"`
  2644. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2645. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2646. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2647. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2648. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2649. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2650. ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week"`
  2651. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2652. Status int64 `gorm:"column:status" json:"status"`
  2653. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2654. SchedualPatient *MSchedualPatientVMList `gorm:"ForeignKey:PatientId" json:"patient"`
  2655. AutomaticReduceDetail []*AutomaticReduceDetail `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"good_user"`
  2656. LastAutomaticReduceDetail []*AutomaticReduceDetail `gorm:"-" json:"last_good_user"`
  2657. DialysisBeforePrepare []*DialysisBeforePrepare `gorm:"ForeignKey:PatientId,ScheduleDate;AssociationForeignKey:PatientId,RecordDate" json:"good_user_detail"`
  2658. LastDialysisBeforePrepare []*DialysisBeforePrepare `gorm:"-" json:"last_good_user_detail"`
  2659. Project []*models.HisPrescriptionProject `gorm:"-" json:"project"`
  2660. //WarehouseOutInfo []*models.WarehouseOutInfoSeven `gorm:"ForeignKey:PatientId,ScheduleDate;AssociationForeignKey:PatientId,SysRecordTime" json:"ware_house_out_info"`
  2661. DialysisPrescription models.DialysisPrescriptionListSix `gorm:"ForeignKey:PatientId,ModeId;AssociationForeignKey:PatientId,ModeId" json:"prescription"`
  2662. }
  2663. func (MDialysisGoodsVM) TableName() string {
  2664. return "xt_schedule"
  2665. }
  2666. type VMWarehouseOutInfo struct {
  2667. ID int64 `gorm:"column:id" json:"id"`
  2668. WarehouseOutId int64 `gorm:"column:warehouse_out_id" json:"warehouse_out_id"`
  2669. GoodId int64 `gorm:"column:good_id" json:"good_id"`
  2670. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2671. Count int64 `gorm:"column:count" json:"count"`
  2672. Price float64 `gorm:"column:price" json:"price"`
  2673. TotalPrice float64 `gorm:"column:total_price" json:"total_price"`
  2674. Status int64 `gorm:"column:status" json:"status"`
  2675. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2676. WarehouseOutOrderNumber string `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number"`
  2677. GoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"good_info"`
  2678. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"good_type"`
  2679. IsSys int64 `gorm:"column:is_sys" json:"is_sys"`
  2680. SysRecordTime int64 `gorm:"column:sys_record_time" json:"sys_record_time"`
  2681. Mtime int64 `gorm:"column:mtime" json:"mtime"`
  2682. Ctime int64 `gorm:"column:ctime" json:"ctime"`
  2683. }
  2684. func (VMWarehouseOutInfo) TableName() string {
  2685. return "xt_warehouse_out_info"
  2686. }
  2687. type DialysisGoodsDate struct {
  2688. RecordDate int64
  2689. }
  2690. type DialysisGoodsDetailDate struct {
  2691. RecordTime int64
  2692. }
  2693. 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) {
  2694. var vms []*MDialysisGoodsVM
  2695. var total int64
  2696. db := readDb.
  2697. Table("xt_schedule as sch").
  2698. Preload("DialysisPrescription", "status=1 and user_org_id =? and solution_status = 1", orgID).
  2699. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  2700. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2701. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2702. Preload("DialysisBeforePrepare", func(db *gorm.DB) *gorm.DB {
  2703. 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)
  2704. }).
  2705. Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
  2706. 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")
  2707. }).Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
  2708. if scheduleDate != 0 {
  2709. db = db.Where("schedule_date = ?", scheduleDate)
  2710. }
  2711. if schedule_type != 0 {
  2712. db = db.Where("schedule_type = ?", schedule_type)
  2713. }
  2714. if partition_id != 0 {
  2715. db = db.Where("partition_id = ?", partition_id)
  2716. }
  2717. if patient_id != 0 {
  2718. db = db.Where("patient_id = ?", patient_id)
  2719. }
  2720. err := db.Find(&vms).Error
  2721. return vms, err, total
  2722. }
  2723. func GetLastDialysisGoods(patient_id int64, orgID int64, record_time int64) (goodUser []*AutomaticReduceDetail, err error) {
  2724. var Id []*DialysisGoodsDetailDate
  2725. 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
  2726. if len(Id) > 0 {
  2727. 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
  2728. }
  2729. return
  2730. }
  2731. func GetLastDialysisBeforePrepare(patient_id int64, orgID int64, record_time int64) (goodUser []*DialysisBeforePrepare, err error) {
  2732. var Id []*DialysisGoodsDate
  2733. 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
  2734. if len(Id) > 0 {
  2735. 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
  2736. }
  2737. return
  2738. }
  2739. func GetAllWarehouseOutSumList(patient_id int64, orgID int64, record_time int64) (info []*models.WarehouseOutInfoSeven, err error) {
  2740. err = XTReadDB().Where("patient_id = ? and org_id = ? and sys_record_time = ? and status = 1", patient_id, orgID, record_time).Find(&info).Error
  2741. return info, err
  2742. }
  2743. func MobileGetGoodsStatistics(orgID int64, start_time int64, end_time int64) (list []*models.StockInfo, err error) {
  2744. db := readDb.Model(&models.StockInfo{})
  2745. db = db.Where("xt_good_information.org_id = ? AND xt_good_information.status = 1", orgID)
  2746. 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")
  2747. db = db.Preload("QueryWarehouseOutInfo", func(db *gorm.DB) *gorm.DB {
  2748. 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)
  2749. })
  2750. db = db.Preload("GoodsType", "org_id = ? AND status = 1", orgID)
  2751. err = db.Order("ctime desc").Find(&list).Error
  2752. return
  2753. }
  2754. 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) {
  2755. var vms []*MDialysisGoodsVM
  2756. var total int64
  2757. db := readDb.
  2758. Model(&models.Schedule{}).
  2759. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  2760. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2761. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2762. Preload("DialysisBeforePrepare", func(db *gorm.DB) *gorm.DB {
  2763. 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)
  2764. }).Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
  2765. 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)
  2766. }).Where("xt_schedule.status = 1 AND xt_schedule.user_org_id = ?", orgID)
  2767. if scheduleDate != 0 {
  2768. db = db.Where("schedule_date = ?", scheduleDate)
  2769. }
  2770. if patient_id != 0 {
  2771. db = db.Where("patient_id = ?", patient_id)
  2772. }
  2773. if len(keywords) != 0 {
  2774. keywords = "%" + keywords + "%"
  2775. 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)
  2776. if schedule_type != 0 {
  2777. db = db.Where("schedule_type = ?", schedule_type)
  2778. }
  2779. if partition_id != 0 {
  2780. db = db.Where("partition_id = ?", partition_id)
  2781. }
  2782. if good_type == 1 {
  2783. db = db.Where("patient_id in(?)", ids)
  2784. }
  2785. if good_type == 2 {
  2786. if len(ids) > 0 {
  2787. db = db.Where("patient_id not in(?)", ids)
  2788. }
  2789. }
  2790. } else {
  2791. if schedule_type != 0 {
  2792. db = db.Where("schedule_type = ?", schedule_type)
  2793. }
  2794. if partition_id != 0 {
  2795. db = db.Where("partition_id = ?", partition_id)
  2796. }
  2797. if good_type == 1 {
  2798. db = db.Where("patient_id in(?)", ids)
  2799. }
  2800. if good_type == 2 {
  2801. if len(ids) > 0 {
  2802. db = db.Where("patient_id not in(?)", ids)
  2803. }
  2804. }
  2805. db = db.Count(&total)
  2806. offset := (page - 1) * limit
  2807. db = db.Offset(offset).Limit(limit)
  2808. }
  2809. err := db.Find(&vms).Error
  2810. return vms, err, total
  2811. }
  2812. func GetLastDialysisGoodsTwo(patient_id int64, orgID int64, record_time int64) (goodUser []*AutomaticReduceDetail, err error) {
  2813. var Id []*DialysisGoodsDetailDate
  2814. 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
  2815. if len(Id) > 0 {
  2816. 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
  2817. }
  2818. return
  2819. }
  2820. func GetLastDialysisBeforePrepareTwo(patient_id int64, orgID int64, record_time int64) (goodUser []*DialysisBeforePrepare, err error) {
  2821. var Id []*DialysisGoodsDate
  2822. 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
  2823. if len(Id) > 0 {
  2824. 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
  2825. }
  2826. return
  2827. }
  2828. func GetAssessmentBefor(orgid int64, patientid int64, recorddate int64) (*models.PredialysisEvaluation, error) {
  2829. evaluation := models.PredialysisEvaluation{}
  2830. err := XTReadDB().Model(&evaluation).Where("user_org_id = ? and patient_id = ? and assessment_date = ? and status = 1", orgid, patientid, recorddate).Find(&evaluation).Error
  2831. if err == gorm.ErrRecordNotFound {
  2832. return nil, err
  2833. }
  2834. if err != nil {
  2835. return nil, err
  2836. }
  2837. return &evaluation, nil
  2838. }
  2839. func GetAssessmentBeforThrity(orgid int64, patientid int64, recorddate int64) (models.PredialysisEvaluation, error) {
  2840. evaluation := models.PredialysisEvaluation{}
  2841. err := XTReadDB().Model(&evaluation).Where("user_org_id = ? and patient_id = ? and assessment_date = ? and status = 1", orgid, patientid, recorddate).Find(&evaluation).Error
  2842. return evaluation, err
  2843. }
  2844. func GetAssessmentBeforFourty(orgid int64, patientid int64, recorddate int64) (models.XtAssessmentBeforeDislysis, error) {
  2845. evaluation := models.XtAssessmentBeforeDislysis{}
  2846. err := XTReadDB().Model(&evaluation).Where("user_org_id = ? and patient_id = ? and assessment_date = ? and status = 1", orgid, patientid, recorddate).Find(&evaluation).Error
  2847. return evaluation, err
  2848. }
  2849. func GetAllHisDoctorAdvice(orgid int64, patientid int64, recorddate int64) (his []*models.HisDoctorAdviceInfo, err error) {
  2850. redis := RedisClient()
  2851. defer redis.Close()
  2852. key := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patientid, 10) + ":" + strconv.FormatInt(recorddate, 10) + ":his_doctor_advice"
  2853. his_doctor_advice_str, _ := redis.Get(key).Result()
  2854. redis.Set(key, "", time.Second)
  2855. if len(his_doctor_advice_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2856. 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
  2857. if err != nil {
  2858. if err == gorm.ErrRecordNotFound {
  2859. if len(his) <= 0 {
  2860. redis.Set(key, "null", time.Second*60*60*18)
  2861. }
  2862. return his, nil
  2863. } else {
  2864. return his, err
  2865. }
  2866. } else {
  2867. if len(his) > 0 {
  2868. //缓存数据
  2869. his_doctor_advice_str, err := json.Marshal(his)
  2870. if err == nil {
  2871. redis.Set(key, his_doctor_advice_str, time.Second*60*60*18)
  2872. }
  2873. } else {
  2874. redis.Set(key, "null", time.Second*60*60*18)
  2875. }
  2876. return his, nil
  2877. }
  2878. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2879. json.Unmarshal([]byte(his_doctor_advice_str), &his)
  2880. return his, nil
  2881. }
  2882. }
  2883. func GetLastDialysisPrescriptionByPatientId(orgid int64, patientid int64, recorddate int64) (*models.DialysisPrescription, error) {
  2884. prescription := models.DialysisPrescription{}
  2885. err := readDb.Model(&models.DialysisPrescription{}).Where("user_org_id = ? and patient_id = ? and record_date = ? and status = 1", orgid, patientid, recorddate).Find(&prescription).Error
  2886. if err == gorm.ErrRecordNotFound {
  2887. return nil, err
  2888. }
  2889. if err != nil {
  2890. return nil, err
  2891. }
  2892. return &prescription, nil
  2893. }
  2894. func GetLastDialysisPrescriptionByPatientIdTwo(orgid int64, patientid int64, recorddate int64) (models.DialysisPrescription, error) {
  2895. prescription := models.DialysisPrescription{}
  2896. err := readDb.Model(&models.DialysisPrescription{}).Where("user_org_id = ? and patient_id = ? and record_date = ? and status = 1", orgid, patientid, recorddate).Find(&prescription).Error
  2897. return prescription, err
  2898. }
  2899. type HisMScheduleDoctorAdviceVM struct {
  2900. ID int64 `gorm:"column:id" json:"id"`
  2901. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2902. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2903. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2904. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2905. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2906. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2907. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2908. Status int64 `gorm:"column:status" json:"status"`
  2909. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  2910. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  2911. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2912. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  2913. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  2914. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  2915. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  2916. }
  2917. func (HisMScheduleDoctorAdviceVM) TableName() string {
  2918. return "xt_schedule"
  2919. }
  2920. type HisMScheduleDoctorAdviceVMOne struct {
  2921. ID int64 `gorm:"column:id" json:"id"`
  2922. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2923. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2924. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2925. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2926. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2927. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2928. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2929. Status int64 `gorm:"column:status" json:"status"`
  2930. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  2931. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  2932. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2933. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  2934. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  2935. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  2936. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  2937. }
  2938. func (HisMScheduleDoctorAdviceVMOne) TableName() string {
  2939. return "xt_schedule"
  2940. }
  2941. type HisMScheduleProjectVM struct {
  2942. ID int64 `gorm:"column:id" json:"id"`
  2943. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2944. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2945. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2946. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2947. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2948. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2949. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2950. Status int64 `gorm:"column:status" json:"status"`
  2951. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  2952. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  2953. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2954. Prescription *models.DialysisPrescriptionTwenty `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  2955. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  2956. HisPrescriptionTeamProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"team_project"`
  2957. }
  2958. func (HisMScheduleProjectVM) TableName() string {
  2959. return "xt_schedule"
  2960. }
  2961. func GetHisDoctorConfig(orgid int64) (models.XtHisConfig, error) {
  2962. config := models.XtHisConfig{}
  2963. err := XTReadDB().Model(&config).Where("user_org_id = ? and status =1", orgid).Find(&config).Error
  2964. return config, err
  2965. }
  2966. func GetHisDoctorPatientById(orgid int64, patientid int64, recordtime int64) (advice []*models.HisDoctorAdviceInfo, err error) {
  2967. db := XTReadDB().Table("his_doctor_advice_info as x").Where("x.status = 1")
  2968. if orgid > 0 {
  2969. db = db.Where("x.user_org_id = ?", orgid)
  2970. }
  2971. if patientid > 0 {
  2972. db = db.Where("x.patient_id =?", patientid)
  2973. }
  2974. if recordtime > 0 {
  2975. db = db.Where("x.advice_date = ?", recordtime)
  2976. }
  2977. 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
  2978. return advice, err
  2979. }
  2980. func GetDoctorAdviceCount(startime int64, endtime int64, deliveway string, orgid int64) (advice []*models.BloodDoctorAdvice, err error) {
  2981. db := XTReadDB().Table("xt_doctor_advice as x").Where("x.status = 1 and x.advice_type =2")
  2982. if startime > 0 {
  2983. db = db.Where("x.advice_date >= ?", startime)
  2984. }
  2985. if endtime > 0 {
  2986. db = db.Where("x.advice_date<=?", endtime)
  2987. }
  2988. if orgid > 0 {
  2989. db = db.Where("x.user_org_id = ?", orgid)
  2990. }
  2991. if len(deliveway) > 0 {
  2992. db = db.Where("x.delivery_way = ?", deliveway)
  2993. }
  2994. 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
  2995. return advice, err
  2996. }
  2997. func GetHisDoctorAdviceCount(startime int64, endtime int64, deliveway string, orgid int64) (advice []*models.BloodDoctorAdvice, err error) {
  2998. db := XTReadDB().Table("his_doctor_advice_info as x").Where("x.status = 1 and x.advice_type =2")
  2999. if startime > 0 {
  3000. db = db.Where("x.advice_date >= ?", startime)
  3001. }
  3002. if endtime > 0 {
  3003. db = db.Where("x.advice_date<=?", endtime)
  3004. }
  3005. if orgid > 0 {
  3006. db = db.Where("x.user_org_id = ?", orgid)
  3007. }
  3008. if len(deliveway) > 0 {
  3009. db = db.Where("x.delivery_way = ?", deliveway)
  3010. }
  3011. 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
  3012. return advice, err
  3013. }
  3014. 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) {
  3015. var vms []*MScheduleDoctorAdviceVM
  3016. adviceWhere := ""
  3017. adviceCondition := []interface{}{}
  3018. if adviceType == 0 {
  3019. if patientType == 0 {
  3020. if patient_id > 0 {
  3021. if execution_state > 0 {
  3022. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  3023. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3024. } else {
  3025. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
  3026. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3027. }
  3028. } else {
  3029. if execution_state > 0 {
  3030. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ?"
  3031. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3032. } else {
  3033. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  3034. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3035. }
  3036. }
  3037. } else if patientType == 1 {
  3038. if patient_id > 0 {
  3039. if execution_state > 0 {
  3040. 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= ?"
  3041. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3042. } else {
  3043. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
  3044. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3045. }
  3046. } else {
  3047. if execution_state > 0 {
  3048. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  3049. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3050. } else {
  3051. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  3052. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3053. }
  3054. }
  3055. } else if patientType == 2 {
  3056. if patient_id > 0 {
  3057. if execution_state > 0 {
  3058. 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 = ?"
  3059. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3060. } else {
  3061. 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 = ?)"
  3062. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3063. }
  3064. } else {
  3065. if execution_state > 0 {
  3066. 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 = ?"
  3067. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3068. } else {
  3069. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  3070. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3071. }
  3072. }
  3073. }
  3074. } else if adviceType == 1 {
  3075. if patientType == 0 {
  3076. if patient_id > 0 {
  3077. if execution_state > 0 {
  3078. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ?"
  3079. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3080. } else {
  3081. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
  3082. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3083. }
  3084. } else {
  3085. if execution_state > 0 {
  3086. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ?"
  3087. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3088. } else {
  3089. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  3090. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3091. }
  3092. }
  3093. } else if patientType == 1 {
  3094. if patient_id > 0 {
  3095. if execution_state > 0 {
  3096. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  3097. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3098. } else {
  3099. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
  3100. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3101. }
  3102. } else {
  3103. if execution_state > 0 {
  3104. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?"
  3105. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3106. } else {
  3107. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  3108. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3109. }
  3110. }
  3111. } else if patientType == 2 {
  3112. if patient_id > 0 {
  3113. if execution_state > 0 {
  3114. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  3115. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3116. } else {
  3117. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
  3118. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3119. }
  3120. } else {
  3121. if execution_state > 0 {
  3122. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ?"
  3123. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3124. } else {
  3125. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  3126. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3127. }
  3128. }
  3129. }
  3130. } else if adviceType == 3 {
  3131. if patientType == 0 {
  3132. if patient_id > 0 {
  3133. if execution_state > 0 {
  3134. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ?"
  3135. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3136. } else {
  3137. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? "
  3138. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3139. }
  3140. } else {
  3141. if execution_state > 0 {
  3142. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? "
  3143. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3144. } else {
  3145. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  3146. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3147. }
  3148. }
  3149. } else if patientType == 1 {
  3150. if patient_id > 0 {
  3151. if execution_state > 0 {
  3152. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  3153. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3154. } else {
  3155. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
  3156. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3157. }
  3158. } else {
  3159. if execution_state > 0 {
  3160. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? "
  3161. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3162. } else {
  3163. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  3164. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3165. }
  3166. }
  3167. } else if patientType == 2 {
  3168. if patient_id > 0 {
  3169. if execution_state > 0 {
  3170. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  3171. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3172. } else {
  3173. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ?"
  3174. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3175. }
  3176. } else {
  3177. if execution_state > 0 {
  3178. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ?"
  3179. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3180. } else {
  3181. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  3182. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3183. }
  3184. }
  3185. }
  3186. } else if adviceType == 2 && len(deliverWay) > 0 {
  3187. if patientType == 0 {
  3188. if patient_id > 0 {
  3189. if execution_state > 0 {
  3190. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  3191. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  3192. } else {
  3193. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ?"
  3194. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  3195. }
  3196. } else {
  3197. if execution_state > 0 {
  3198. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ?"
  3199. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  3200. } else {
  3201. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  3202. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  3203. }
  3204. }
  3205. } else if patientType == 1 {
  3206. if patient_id > 0 {
  3207. if execution_state > 0 {
  3208. 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 = ?"
  3209. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state)
  3210. } else {
  3211. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ?"
  3212. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
  3213. }
  3214. } else {
  3215. if execution_state > 0 {
  3216. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ?"
  3217. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state)
  3218. } else {
  3219. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  3220. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  3221. }
  3222. }
  3223. } else if patientType == 2 {
  3224. if patient_id > 0 {
  3225. if execution_state > 0 {
  3226. 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 = ?"
  3227. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  3228. } else {
  3229. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ?"
  3230. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  3231. }
  3232. } else {
  3233. if execution_state > 0 {
  3234. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ?"
  3235. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  3236. } else {
  3237. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  3238. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  3239. }
  3240. }
  3241. }
  3242. } else if adviceType == 2 && len(deliverWay) <= 0 {
  3243. if patientType == 0 {
  3244. if patient_id > 0 {
  3245. if execution_state > 0 {
  3246. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ?"
  3247. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3248. } else {
  3249. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ?"
  3250. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3251. }
  3252. } else {
  3253. if execution_state > 0 {
  3254. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?"
  3255. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3256. } else {
  3257. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  3258. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3259. }
  3260. }
  3261. } else if patientType == 1 {
  3262. if patient_id > 0 {
  3263. if execution_state > 0 {
  3264. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  3265. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3266. } else {
  3267. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ?"
  3268. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3269. }
  3270. } else {
  3271. if execution_state > 0 {
  3272. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ?"
  3273. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3274. } else {
  3275. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?"
  3276. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3277. }
  3278. }
  3279. } else if patientType == 2 {
  3280. if patient_id > 0 {
  3281. if execution_state > 0 {
  3282. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  3283. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3284. } else {
  3285. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ?"
  3286. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3287. }
  3288. } else {
  3289. if execution_state > 0 {
  3290. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ?"
  3291. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3292. } else {
  3293. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  3294. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3295. }
  3296. }
  3297. }
  3298. }
  3299. db := readDb.Table("xt_schedule")
  3300. if scheduleType > 0 {
  3301. db = db.Where("schedule_type = ?", scheduleType)
  3302. }
  3303. if partitonType > 0 {
  3304. db = db.Where("partition_id = ?", partitonType)
  3305. }
  3306. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3307. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3308. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3309. }).
  3310. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3311. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3312. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3313. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3314. Preload("DoctorAdvices", adviceCondition...).
  3315. Where("status = 1 AND user_org_id = ?", orgID)
  3316. if scheduleDate != 0 {
  3317. db = db.Where("schedule_date = ?", scheduleDate)
  3318. }
  3319. err := db.Find(&vms).Error
  3320. return vms, err
  3321. }
  3322. func GetHisDoctorAdvicesOne(orgID int64, scheduleDate int64, deliverWay string, scheduleType int64, partitionType int64, patient_id int64, execution_state int64, cost_type int64) ([]*HisMScheduleDoctorAdviceVM, error) {
  3323. var vms []*HisMScheduleDoctorAdviceVM
  3324. if len(deliverWay) > 0 {
  3325. db := readDb.Table("xt_schedule")
  3326. if scheduleType > 0 {
  3327. db = db.Where("schedule_type = ?", scheduleType)
  3328. }
  3329. if partitionType > 0 {
  3330. db = db.Where("partition_id = ?", partitionType)
  3331. }
  3332. if patient_id > 0 {
  3333. if execution_state > 0 {
  3334. if cost_type > 0 {
  3335. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3336. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3337. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3338. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3339. 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).
  3340. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3341. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3342. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3343. Where("status = 1 AND user_org_id = ?", orgID)
  3344. if scheduleDate != 0 {
  3345. db = db.Where("schedule_date = ?", scheduleDate)
  3346. }
  3347. err = db.Find(&vms).Error
  3348. } else {
  3349. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3350. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3351. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3352. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3353. 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).
  3354. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3355. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3356. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3357. Where("status = 1 AND user_org_id = ?", orgID)
  3358. if scheduleDate != 0 {
  3359. db = db.Where("schedule_date = ?", scheduleDate)
  3360. }
  3361. err = db.Find(&vms).Error
  3362. }
  3363. } else {
  3364. if cost_type > 0 {
  3365. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3366. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3367. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3368. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3369. 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).
  3370. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3371. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3372. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3373. Where("status = 1 AND user_org_id = ?", orgID)
  3374. if scheduleDate != 0 {
  3375. db = db.Where("schedule_date = ?", scheduleDate)
  3376. }
  3377. err = db.Find(&vms).Error
  3378. } else {
  3379. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3380. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3381. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3382. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3383. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ?", orgID, scheduleDate, deliverWay, patient_id).
  3384. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3385. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3386. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3387. Where("status = 1 AND user_org_id = ?", orgID)
  3388. if scheduleDate != 0 {
  3389. db = db.Where("schedule_date = ?", scheduleDate)
  3390. }
  3391. err = db.Find(&vms).Error
  3392. }
  3393. }
  3394. } else {
  3395. if execution_state > 0 {
  3396. if cost_type > 0 {
  3397. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3398. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3399. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3400. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3401. 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).
  3402. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3403. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3404. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3405. Where("status = 1 AND user_org_id = ?", orgID)
  3406. if scheduleDate != 0 {
  3407. db = db.Where("schedule_date = ?", scheduleDate)
  3408. }
  3409. err = db.Find(&vms).Error
  3410. } else {
  3411. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3412. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3413. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3414. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3415. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_state = ?", orgID, scheduleDate, deliverWay, execution_state).
  3416. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3417. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3418. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3419. Where("status = 1 AND user_org_id = ?", orgID)
  3420. if scheduleDate != 0 {
  3421. db = db.Where("schedule_date = ?", scheduleDate)
  3422. }
  3423. err = db.Find(&vms).Error
  3424. }
  3425. } else {
  3426. if cost_type > 0 {
  3427. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3428. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3429. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3430. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3431. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and is_settle = ?", orgID, scheduleDate, deliverWay, cost_type).
  3432. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3433. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3434. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3435. Where("status = 1 AND user_org_id = ?", orgID)
  3436. if scheduleDate != 0 {
  3437. db = db.Where("schedule_date = ?", scheduleDate)
  3438. }
  3439. err = db.Find(&vms).Error
  3440. } else {
  3441. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3442. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3443. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3444. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3445. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  3446. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3447. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3448. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3449. Where("status = 1 AND user_org_id = ?", orgID)
  3450. if scheduleDate != 0 {
  3451. db = db.Where("schedule_date = ?", scheduleDate)
  3452. }
  3453. err = db.Find(&vms).Error
  3454. }
  3455. }
  3456. }
  3457. } else {
  3458. db := readDb.Table("xt_schedule")
  3459. if scheduleType > 0 {
  3460. db = db.Where("schedule_type = ?", scheduleType)
  3461. }
  3462. if partitionType > 0 {
  3463. db = db.Where("partition_id = ?", partitionType)
  3464. }
  3465. if patient_id > 0 {
  3466. if execution_state > 0 {
  3467. if cost_type > 0 {
  3468. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3469. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3470. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3471. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3472. 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).
  3473. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3474. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3475. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3476. Where("status = 1 AND user_org_id = ?", orgID)
  3477. if scheduleDate != 0 {
  3478. db = db.Where("schedule_date = ?", scheduleDate)
  3479. }
  3480. err = db.Find(&vms).Error
  3481. } else {
  3482. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3483. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3484. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3485. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3486. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and execution_state = ?", orgID, scheduleDate, patient_id, execution_state).
  3487. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3488. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3489. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3490. Where("status = 1 AND user_org_id = ?", orgID)
  3491. if scheduleDate != 0 {
  3492. db = db.Where("schedule_date = ?", scheduleDate)
  3493. }
  3494. err = db.Find(&vms).Error
  3495. }
  3496. } else {
  3497. if cost_type > 0 {
  3498. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3499. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3500. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3501. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3502. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and is_settle = ?", orgID, scheduleDate, patient_id, cost_type).
  3503. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3504. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3505. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3506. Where("status = 1 AND user_org_id = ?", orgID)
  3507. if scheduleDate != 0 {
  3508. db = db.Where("schedule_date = ?", scheduleDate)
  3509. }
  3510. err = db.Find(&vms).Error
  3511. } else {
  3512. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3513. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3514. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3515. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3516. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3517. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3518. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3519. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3520. Where("status = 1 AND user_org_id = ?", orgID)
  3521. if scheduleDate != 0 {
  3522. db = db.Where("schedule_date = ?", scheduleDate)
  3523. }
  3524. err = db.Find(&vms).Error
  3525. }
  3526. }
  3527. } else {
  3528. if execution_state > 0 {
  3529. if cost_type > 0 {
  3530. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3531. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3532. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3533. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3534. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ? and is_settle = ?", orgID, scheduleDate, execution_state, cost_type).
  3535. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3536. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3537. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3538. Where("status = 1 AND user_org_id = ?", orgID)
  3539. if scheduleDate != 0 {
  3540. db = db.Where("schedule_date = ?", scheduleDate)
  3541. }
  3542. err = db.Find(&vms).Error
  3543. } else {
  3544. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3545. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3546. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3547. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3548. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ?", orgID, scheduleDate, execution_state).
  3549. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3550. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3551. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3552. Where("status = 1 AND user_org_id = ?", orgID)
  3553. if scheduleDate != 0 {
  3554. db = db.Where("schedule_date = ?", scheduleDate)
  3555. }
  3556. err = db.Find(&vms).Error
  3557. }
  3558. } else {
  3559. if cost_type > 0 {
  3560. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3561. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3562. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3563. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3564. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and is_settle = ?", orgID, scheduleDate, cost_type).
  3565. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3566. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3567. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3568. Where("status = 1 AND user_org_id = ?", orgID)
  3569. if scheduleDate != 0 {
  3570. db = db.Where("schedule_date = ?", scheduleDate)
  3571. }
  3572. err = db.Find(&vms).Error
  3573. } else {
  3574. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3575. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3576. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3577. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3578. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ?", orgID, scheduleDate).
  3579. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3580. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3581. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3582. Where("status = 1 AND user_org_id = ?", orgID)
  3583. if scheduleDate != 0 {
  3584. db = db.Where("schedule_date = ?", scheduleDate)
  3585. }
  3586. err = db.Find(&vms).Error
  3587. }
  3588. }
  3589. }
  3590. }
  3591. return vms, err
  3592. }
  3593. func BatchDeleteMonitor(ids []string) (err error) {
  3594. if len(ids) == 1 {
  3595. err = XTWriteDB().Model(&models.MonitoringRecord{}).Where("id=?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3596. } else {
  3597. err = XTWriteDB().Model(models.MonitoringRecord{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3598. }
  3599. return
  3600. }
  3601. func GetPatientDialysisRecordList(patientid int64, startime int64, endtime int64) (order []*models.XtDialysisOrders, err error) {
  3602. db := XTReadDB().Table("xt_dialysis_order as x").Where("x.status = 1")
  3603. //table := XTReadDB().Table("xt_schedule as s")
  3604. //fmt.Println(table)
  3605. if patientid > 0 {
  3606. db = db.Where("x.patient_id = ?", patientid)
  3607. }
  3608. if startime > 0 {
  3609. db = db.Where("x.dialysis_date>=?", startime)
  3610. }
  3611. if endtime > 0 {
  3612. db = db.Where("x.dialysis_date <= ?", endtime)
  3613. }
  3614. err = db.Select("x.id,x.dialysis_date,x.schedual_type,s.mode_id").Where("s.status=1").Joins("left join xt_schedule as s on x.patient_id = s.patient_id and x.dialysis_date = s.schedule_date ").Group("x.id").Scan(&order).Error
  3615. return order, err
  3616. }
  3617. func GetPatientDialysisRecordListOne(patientid int64, startime int64, endtime int64) (order []*models.XtScheduleSixTy, err error) {
  3618. db := XTReadDB().Table("xt_schedule as x").Where("x.status = 1")
  3619. //table := XTReadDB().Table("xt_schedule as s")
  3620. //fmt.Println(table)
  3621. if patientid > 0 {
  3622. db = db.Where("x.patient_id = ?", patientid)
  3623. }
  3624. if startime > 0 {
  3625. db = db.Where("x.schedule_date>=?", startime)
  3626. }
  3627. if endtime > 0 {
  3628. db = db.Where("x.schedule_date <= ?", endtime)
  3629. }
  3630. err = db.Select("x.id,x.schedule_date,x.schedule_type,x.mode_id").Find(&order).Error
  3631. return order, err
  3632. }
  3633. func BatchDeleteAdvice(ids []string) (err error) {
  3634. if len(ids) == 1 {
  3635. err = XTWriteDB().Model(&models.DoctorAdvice{}).Where("id=?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3636. } else {
  3637. err = XTWriteDB().Model(models.DoctorAdvice{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3638. }
  3639. return
  3640. }
  3641. func BatchDeleteHisAdvice(ids []string) (err error) {
  3642. if len(ids) == 1 {
  3643. err = XTWriteDB().Model(&models.HisDoctorAdviceInfo{}).Where("id = ?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3644. } else {
  3645. err = XTWriteDB().Model(models.HisDoctorAdviceInfo{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3646. }
  3647. return
  3648. }
  3649. func UpdateAutoReduceDetail(good_id int64, count int64, record_time int64, patient_id int64) (models.AutomaticReduceDetail, error) {
  3650. detail := models.AutomaticReduceDetail{}
  3651. 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
  3652. return detail, err
  3653. }
  3654. func DeleteAutoReduceDetail(good_id int64, record_time int64, patient_id int64) error {
  3655. detail := models.AutomaticReduceDetail{}
  3656. 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
  3657. return err
  3658. }
  3659. func DeleteDialysisBeforOne(good_id int64, record_time int64, patient_id int64) error {
  3660. detail := models.DialysisBeforePrepare{}
  3661. 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
  3662. return err
  3663. }
  3664. func BatchAdviceCheck(ids []string, creator int64) error {
  3665. advice := models.XtDoctorAdvice{}
  3666. 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
  3667. return err
  3668. }
  3669. func BatchHisAdviceCheck(ids []string, creator int64) error {
  3670. advice := models.HisDoctorAdviceInfo{}
  3671. 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
  3672. return err
  3673. }
  3674. func BatchAdviceExecution(ids []string, creator int64, execution_state int64) error {
  3675. advice := models.XtDoctorAdvice{}
  3676. 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
  3677. return err
  3678. }
  3679. func BatchHisAdviceExecution(ids []string, creator int64, execution_state int64) error {
  3680. advice := models.HisDoctorAdviceInfo{}
  3681. 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
  3682. return err
  3683. }
  3684. func GetAdviceExecutionById(ids []string) (doctor []*models.XtDoctorAdvice, err error) {
  3685. err = XTReadDB().Model(&doctor).Where("id IN(?) AND status = 1", ids).Find(&doctor).Error
  3686. return doctor, err
  3687. }
  3688. func GetHisAdviceExecutionById(ids []string) (doctor []*models.HisDoctorAdviceInfo, err error) {
  3689. err = XTReadDB().Model(&doctor).Where("id IN(?) AND status = 1", ids).Find(&doctor).Error
  3690. return doctor, err
  3691. }
  3692. func GetHisProjectConfig(orgid int64) (models.XtHisProjectConfig, error) {
  3693. config := models.XtHisProjectConfig{}
  3694. err := XTReadDB().Model(&config).Where("user_org_id = ? and status =1", orgid).Find(&config).Error
  3695. return config, err
  3696. }
  3697. func GetHisPrescriptionProject(org_id int64, patient_id int64, record_date int64) (project []*models.HisPrescriptionProject, err error) {
  3698. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("GoodInfo", func(db *gorm.DB) *gorm.DB {
  3699. return db.Preload("GoodsType", "status = 1").Where("status = 1 and is_warehouse = 1")
  3700. }).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
  3701. return
  3702. }
  3703. func GetPCHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64, patient_id int64, execution_state int64) ([]*HisMScheduleProjectVM, error) {
  3704. var vms []*HisMScheduleProjectVM
  3705. if patientType == 0 {
  3706. if patient_id > 0 {
  3707. if execution_state == 1 {
  3708. db := readDb.
  3709. Table("xt_schedule").
  3710. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3711. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3712. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3713. }).
  3714. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3715. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3716. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3717. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3718. 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")
  3719. }).
  3720. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3721. 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")
  3722. }).Where("status = 1 AND user_org_id = ?", orgID)
  3723. if scheduleDate != 0 {
  3724. db = db.Where("schedule_date = ?", scheduleDate)
  3725. }
  3726. err = db.Find(&vms).Error
  3727. } else if execution_state == 2 {
  3728. db := readDb.
  3729. Table("xt_schedule").
  3730. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3731. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3732. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3733. }).
  3734. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3735. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3736. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3737. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3738. 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")
  3739. }).
  3740. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3741. 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")
  3742. }).Where("status = 1 AND user_org_id = ?", orgID)
  3743. if scheduleDate != 0 {
  3744. db = db.Where("schedule_date = ?", scheduleDate)
  3745. }
  3746. err = db.Find(&vms).Error
  3747. } else if execution_state == 0 {
  3748. db := readDb.
  3749. Table("xt_schedule").
  3750. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3751. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3752. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3753. }).
  3754. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3755. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3756. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3757. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3758. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3759. }).
  3760. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3761. 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")
  3762. }).Where("status = 1 AND user_org_id = ?", orgID)
  3763. if scheduleDate != 0 {
  3764. db = db.Where("schedule_date = ?", scheduleDate)
  3765. }
  3766. err = db.Find(&vms).Error
  3767. }
  3768. } else {
  3769. if patient_id > 0 {
  3770. if execution_state == 1 {
  3771. db := readDb.
  3772. Table("xt_schedule").
  3773. Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
  3774. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3775. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3776. }).
  3777. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3778. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3779. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3780. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3781. 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")
  3782. }).
  3783. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3784. 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")
  3785. }).Where("status = 1 AND user_org_id = ?", orgID)
  3786. if scheduleDate != 0 {
  3787. db = db.Where("schedule_date = ?", scheduleDate)
  3788. }
  3789. err = db.Find(&vms).Error
  3790. } else if execution_state == 2 {
  3791. db := readDb.
  3792. Table("xt_schedule").
  3793. Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
  3794. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3795. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3796. }).
  3797. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3798. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3799. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3800. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3801. 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")
  3802. }).
  3803. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3804. 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")
  3805. }).Where("status = 1 AND user_org_id = ?", orgID)
  3806. if scheduleDate != 0 {
  3807. db = db.Where("schedule_date = ?", scheduleDate)
  3808. }
  3809. err = db.Find(&vms).Error
  3810. } else if execution_state == 0 {
  3811. db := readDb.
  3812. Table("xt_schedule").
  3813. Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
  3814. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3815. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3816. }).
  3817. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3818. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3819. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3820. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3821. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3822. }).
  3823. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3824. 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")
  3825. }).Where("status = 1 AND user_org_id = ?", orgID)
  3826. if scheduleDate != 0 {
  3827. db = db.Where("schedule_date = ?", scheduleDate)
  3828. }
  3829. err = db.Find(&vms).Error
  3830. }
  3831. } else {
  3832. if execution_state == 1 {
  3833. db := readDb.
  3834. Table("xt_schedule").
  3835. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3836. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3837. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3838. }).
  3839. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3840. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3841. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3842. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3843. 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")
  3844. }).
  3845. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3846. 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")
  3847. }).Where("status = 1 AND user_org_id = ?", orgID)
  3848. if scheduleDate != 0 {
  3849. db = db.Where("schedule_date = ?", scheduleDate)
  3850. }
  3851. err = db.Find(&vms).Error
  3852. } else if execution_state == 2 {
  3853. fmt.Println("j氯332n323232n323ℹ️33232323232")
  3854. db := readDb.
  3855. Table("xt_schedule").
  3856. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3857. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3858. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3859. }).
  3860. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3861. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3862. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3863. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3864. 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")
  3865. }).
  3866. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3867. 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")
  3868. }).Where("status = 1 AND user_org_id = ?", orgID)
  3869. if scheduleDate != 0 {
  3870. db = db.Where("schedule_date = ?", scheduleDate)
  3871. }
  3872. err = db.Find(&vms).Error
  3873. } else if execution_state == 0 {
  3874. db := readDb.
  3875. Table("xt_schedule").
  3876. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3877. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3878. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3879. }).
  3880. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3881. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3882. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3883. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3884. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3885. }).
  3886. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3887. 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")
  3888. }).Where("status = 1 AND user_org_id = ?", orgID)
  3889. if scheduleDate != 0 {
  3890. db = db.Where("schedule_date = ?", scheduleDate)
  3891. }
  3892. err = db.Find(&vms).Error
  3893. }
  3894. }
  3895. }
  3896. }
  3897. if patientType > 0 {
  3898. if execution_state == 1 {
  3899. db := readDb.
  3900. Table("xt_schedule").
  3901. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3902. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3903. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3904. }).
  3905. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3906. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3907. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3908. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  3909. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3910. 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")
  3911. }).
  3912. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3913. 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")
  3914. }).Where("status = 1 AND user_org_id = ?", orgID)
  3915. if scheduleDate != 0 {
  3916. db = db.Where("schedule_date = ?", scheduleDate)
  3917. }
  3918. err = db.Find(&vms).Error
  3919. } else if execution_state == 2 {
  3920. db := readDb.
  3921. Table("xt_schedule").
  3922. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3923. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3924. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3925. }).
  3926. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3927. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3928. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3929. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  3930. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3931. 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")
  3932. }).
  3933. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3934. 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")
  3935. }).Where("status = 1 AND user_org_id = ?", orgID)
  3936. if scheduleDate != 0 {
  3937. db = db.Where("schedule_date = ?", scheduleDate)
  3938. }
  3939. err = db.Find(&vms).Error
  3940. } else if execution_state == 0 {
  3941. db := readDb.
  3942. Table("xt_schedule").
  3943. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3944. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3945. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3946. }).
  3947. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3948. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3949. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3950. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  3951. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3952. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3953. }).
  3954. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3955. 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")
  3956. }).Where("status = 1 AND user_org_id = ?", orgID)
  3957. if scheduleDate != 0 {
  3958. db = db.Where("schedule_date = ?", scheduleDate)
  3959. }
  3960. err = db.Find(&vms).Error
  3961. }
  3962. }
  3963. return vms, err
  3964. }
  3965. func UpdateStockGoods(good_id int64, record_time int64, patient_id int64, count int64) error {
  3966. prepare := models.DialysisBeforePrepare{}
  3967. var err error
  3968. if count > 0 {
  3969. 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
  3970. }
  3971. if count <= 0 {
  3972. 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
  3973. }
  3974. return err
  3975. }
  3976. func UPdateAutoStockGoods(good_id int64, record_time int64, patient_id int64, count int64) error {
  3977. detail := models.AutomaticReduceDetail{}
  3978. 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
  3979. return err
  3980. }
  3981. func MobileGetDialysisSolutionByModeIdSeven(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  3982. var record models.DialysisSolution
  3983. 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
  3984. if err != nil {
  3985. if err == gorm.ErrRecordNotFound {
  3986. return nil, nil
  3987. } else {
  3988. return nil, err
  3989. }
  3990. }
  3991. return &record, nil
  3992. }
  3993. func MobileGetLastDialysisPrescribeByModeIdSeven(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  3994. var record models.DialysisPrescription
  3995. 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
  3996. if err != nil {
  3997. if err == gorm.ErrRecordNotFound {
  3998. return nil, nil
  3999. } else {
  4000. return nil, err
  4001. }
  4002. }
  4003. return &record, nil
  4004. }
  4005. func MobileGetLastDialysisPrescription(patientID int64, orgID int64) (models.DialysisPrescriptionThrity, error) {
  4006. prescription := models.DialysisPrescriptionThrity{}
  4007. err := readDb.Model(&prescription).Where("patient_id = ? and user_org_id = ? and status = 1 and remark<>''", patientID, orgID).Last(&prescription).Error
  4008. return prescription, err
  4009. }
  4010. func MobileGetSystemDialysisPrescribeByModeIdSeven(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  4011. var record models.SystemPrescription
  4012. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).First(&record).Error
  4013. if err != nil {
  4014. if err == gorm.ErrRecordNotFound {
  4015. return nil, nil
  4016. } else {
  4017. return nil, err
  4018. }
  4019. }
  4020. return &record, nil
  4021. }
  4022. // 透前评估
  4023. func MobileGetPredialysisEvaluationSeven(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
  4024. var record models.PredialysisEvaluation
  4025. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  4026. if err != nil {
  4027. if err == gorm.ErrRecordNotFound {
  4028. return nil, nil
  4029. } else {
  4030. return nil, err
  4031. }
  4032. }
  4033. return &record, nil
  4034. }
  4035. //
  4036. //func MobileGetDialysisGoodsSix(orgID int64, scheduleDate int64) (prepare []*models.DialysisBeforePrepare, err error) {
  4037. //
  4038. // 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
  4039. // return prepare, err
  4040. //}
  4041. func GetMobileAutoReduce(orgID int64, scheduleDate int64) (auto []*models.AutomaticReduceDetail, err error) {
  4042. err = readDb.Where("org_id = ? and status = 1 and record_time = ?", orgID, scheduleDate).Find(&auto).Error
  4043. return auto, err
  4044. }
  4045. func GetRoleList(orgid int64, admin_user_id int64) (models.SgjUserAdminRole, error) {
  4046. role := models.SgjUserAdminRole{}
  4047. err = readUserDb.Where("org_id = ? and admin_user_id = ? and status =1 ", orgid, admin_user_id).Find(&role).Error
  4048. return role, err
  4049. }
  4050. func GetDialysisGood(orgID int64, scheduleDate int64) (auto []*models.AutomaticReduceDetail, err error) {
  4051. err = readDb.Where("org_id = ? and status = 1 and record_time >= ?", orgID, scheduleDate).Group("patient_id").Find(&auto).Error
  4052. return auto, err
  4053. }
  4054. func GetGoodWarehouseOutInfo(orgId int64, patient_id int64, sys_record_time int64) (outifno []*models.WarehouseOutInfoSeven, err error) {
  4055. err = readDb.Where("org_id = ? and patient_id = ? and sys_record_time = ? and status = 1", orgId, patient_id, sys_record_time).Find(&outifno).Error
  4056. return outifno, err
  4057. }
  4058. func GetLastDilysisOrder(orgid int64, patient_id int64, dialysis_date int64) (models.DialysisOrder, error) {
  4059. order := models.DialysisOrder{}
  4060. err = XTReadDB().Where("user_org_id = ? and patient_id = ? and dialysis_date < ? and status= 1", orgid, patient_id, dialysis_date).Last(&order).Error
  4061. return order, err
  4062. }
  4063. func GetFistMonitor(orgid int64, patient_id int64, dialysis_date int64) (models.MonitoringRecord, error) {
  4064. record := models.MonitoringRecord{}
  4065. err := XTReadDB().Where("org_id = ? and patient_id = ? and monitoring_date = ? and status = 1", orgid, patient_id, dialysis_date).Find(&record).Error
  4066. return record, err
  4067. }
  4068. func GetFistMonitorSix(orgid int64, patient_id int64, dialysis_date int64) (record []*models.MonitoringRecord, err error) {
  4069. err = XTReadDB().Where("user_org_id = ? and patient_id = ? and monitoring_date = ? and status = 1", orgid, patient_id, dialysis_date).Find(&record).Error
  4070. return record, err
  4071. }
  4072. 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, keyword string) ([]*MScheduleDoctorAdviceVM, error) {
  4073. var vms []*MScheduleDoctorAdviceVM
  4074. keyword = "%" + keyword + "%"
  4075. adviceWhere := ""
  4076. adviceCondition := []interface{}{}
  4077. if adviceType == 0 {
  4078. if patientType == 0 {
  4079. if patient_id > 0 {
  4080. if execution_state > 0 {
  4081. if cost_type > 0 {
  4082. if len(execution_frequency) > 0 {
  4083. if len(keyword) > 0 {
  4084. 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 = ? and advice_name like ?"
  4085. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4086. } else {
  4087. 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 = ?"
  4088. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4089. }
  4090. } else {
  4091. if len(keyword) > 0 {
  4092. 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 advice_name like ?"
  4093. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  4094. } else {
  4095. 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 = ?"
  4096. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4097. }
  4098. }
  4099. } else {
  4100. if len(execution_frequency) > 0 {
  4101. if len(keyword) > 0 {
  4102. 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 = ? and advice_name like ?"
  4103. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  4104. } else {
  4105. 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 = ?"
  4106. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4107. }
  4108. } else {
  4109. if len(keyword) > 0 {
  4110. 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 advice_name like ?"
  4111. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  4112. } else {
  4113. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  4114. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4115. }
  4116. }
  4117. }
  4118. } else {
  4119. if cost_type > 0 {
  4120. if len(execution_frequency) > 0 {
  4121. 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 = ?"
  4122. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4123. } else {
  4124. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and is_settle = ?"
  4125. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4126. }
  4127. } else {
  4128. if len(execution_frequency) > 0 {
  4129. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_frequency = ?"
  4130. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4131. } else {
  4132. if len(keyword) > 0 {
  4133. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and advice_name like ?"
  4134. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  4135. } else {
  4136. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
  4137. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4138. }
  4139. }
  4140. }
  4141. }
  4142. } else {
  4143. if execution_state > 0 {
  4144. if cost_type > 0 {
  4145. if len(execution_frequency) > 0 {
  4146. if len(keyword) > 0 {
  4147. 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 = ? and advice_name like ?"
  4148. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  4149. } else {
  4150. 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 = ?"
  4151. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4152. }
  4153. } else {
  4154. if len(keyword) > 0 {
  4155. 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 advice_name like ?"
  4156. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  4157. } else {
  4158. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and is_settle = ?"
  4159. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4160. }
  4161. }
  4162. } else {
  4163. if len(execution_frequency) > 0 {
  4164. if len(keyword) > 0 {
  4165. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and execution_frequency = ? and advice_name like ?"
  4166. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  4167. } else {
  4168. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and execution_frequency = ?"
  4169. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4170. }
  4171. } else {
  4172. if len(keyword) > 0 {
  4173. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and advice_name like ?"
  4174. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  4175. } else {
  4176. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ?"
  4177. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4178. }
  4179. }
  4180. }
  4181. } else {
  4182. if cost_type > 0 {
  4183. if len(execution_frequency) > 0 {
  4184. if len(keyword) > 0 {
  4185. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ? and execution_frequency = ? and advice_name like ?"
  4186. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  4187. } else {
  4188. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ? and execution_frequency = ?"
  4189. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  4190. }
  4191. } else {
  4192. if len(keyword) > 0 {
  4193. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ? and advice_name like ?"
  4194. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  4195. } else {
  4196. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ?"
  4197. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4198. }
  4199. }
  4200. } else {
  4201. if len(execution_frequency) > 0 {
  4202. if len(keyword) > 0 {
  4203. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_frequency = ? and advice_name like ?"
  4204. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  4205. } else {
  4206. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_frequency = ?"
  4207. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  4208. }
  4209. } else {
  4210. if len(keyword) > 0 {
  4211. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and advice_name like ?"
  4212. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  4213. } else {
  4214. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  4215. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4216. }
  4217. }
  4218. }
  4219. }
  4220. }
  4221. } else if patientType == 1 {
  4222. if patient_id > 0 {
  4223. if execution_state > 0 {
  4224. if cost_type > 0 {
  4225. if len(execution_frequency) > 0 {
  4226. if len(keyword) > 0 {
  4227. 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 = ? and advice_name like ?"
  4228. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4229. } else {
  4230. 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 = ?"
  4231. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  4232. }
  4233. } else {
  4234. if len(keyword) > 0 {
  4235. 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 advice_name like ?"
  4236. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, keyword)
  4237. } else {
  4238. 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 = ?"
  4239. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  4240. }
  4241. }
  4242. } else {
  4243. if len(execution_frequency) > 0 {
  4244. if len(keyword) > 0 {
  4245. 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 = ? and advice_name like ?"
  4246. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  4247. } else {
  4248. 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 = ?"
  4249. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  4250. }
  4251. } else {
  4252. if len(keyword) > 0 {
  4253. 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 advice_name like ?"
  4254. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, keyword)
  4255. } else {
  4256. 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= ?"
  4257. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  4258. }
  4259. }
  4260. }
  4261. } else {
  4262. if cost_type > 0 {
  4263. if len(execution_frequency) > 0 {
  4264. if len(keyword) > 0 {
  4265. 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 = ? and advice_name like ?"
  4266. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  4267. } else {
  4268. 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 = ?"
  4269. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  4270. }
  4271. } else {
  4272. if len(keyword) > 0 {
  4273. 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 advice_name like ?"
  4274. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, keyword)
  4275. } else {
  4276. 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=?"
  4277. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  4278. }
  4279. }
  4280. } else {
  4281. if len(execution_frequency) > 0 {
  4282. if len(keyword) > 0 {
  4283. 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 = ? and advice_name like ?"
  4284. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency, keyword)
  4285. } else {
  4286. 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 = ?"
  4287. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  4288. }
  4289. } else {
  4290. if len(keyword) > 0 {
  4291. 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 advice_name like ?"
  4292. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, keyword)
  4293. } else {
  4294. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
  4295. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  4296. }
  4297. }
  4298. }
  4299. }
  4300. } else {
  4301. if execution_state > 0 {
  4302. if cost_type > 0 {
  4303. if len(execution_frequency) > 0 {
  4304. if len(keyword) > 0 {
  4305. 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 = ? and advice_name like ?"
  4306. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  4307. } else {
  4308. 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 = ?"
  4309. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  4310. }
  4311. } else {
  4312. if len(keyword) > 0 {
  4313. 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 advice_name like ?"
  4314. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, keyword)
  4315. } else {
  4316. 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=?"
  4317. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  4318. }
  4319. }
  4320. } else {
  4321. if len(execution_frequency) > 0 {
  4322. if len(keyword) > 0 {
  4323. 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 = ? and advice_name like ?"
  4324. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency, keyword)
  4325. } else {
  4326. 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 = ?"
  4327. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  4328. }
  4329. } else {
  4330. if len(keyword) > 0 {
  4331. 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 advice_name like ?"
  4332. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, keyword)
  4333. } else {
  4334. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  4335. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  4336. }
  4337. }
  4338. }
  4339. } else {
  4340. if cost_type > 0 {
  4341. if len(execution_frequency) > 0 {
  4342. if len(keyword) > 0 {
  4343. 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 = ? and advice_name like ?"
  4344. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency, keyword)
  4345. } else {
  4346. 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 = ?"
  4347. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  4348. }
  4349. } else {
  4350. if len(keyword) > 0 {
  4351. 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 advice_name like ?"
  4352. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, keyword)
  4353. } else {
  4354. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and is_settle=?"
  4355. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  4356. }
  4357. }
  4358. } else {
  4359. if len(execution_frequency) > 0 {
  4360. if len(keyword) > 0 {
  4361. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_frequency = ? and advice_name like ?"
  4362. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency, keyword)
  4363. } else {
  4364. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_frequency = ?"
  4365. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  4366. }
  4367. } else {
  4368. if len(keyword) > 0 {
  4369. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and advice_name like ?"
  4370. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, keyword)
  4371. } else {
  4372. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  4373. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  4374. }
  4375. }
  4376. }
  4377. }
  4378. }
  4379. } else if patientType == 2 {
  4380. if patient_id > 0 {
  4381. if execution_state > 0 {
  4382. if cost_type > 0 {
  4383. if len(execution_frequency) > 0 {
  4384. if len(keyword) > 0 {
  4385. 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 = ? and advice_name like ?"
  4386. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4387. } else {
  4388. 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 = ?"
  4389. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4390. }
  4391. } else {
  4392. if len(keyword) > 0 {
  4393. 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 advice_name like ?"
  4394. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  4395. } else {
  4396. 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=?"
  4397. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4398. }
  4399. }
  4400. } else {
  4401. if len(execution_frequency) > 0 {
  4402. if len(keyword) > 0 {
  4403. 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 = ? and advice_name like ?"
  4404. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  4405. } else {
  4406. 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 = ?"
  4407. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4408. }
  4409. } else {
  4410. if len(keyword) > 0 {
  4411. 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 advice_name like ?"
  4412. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  4413. } else {
  4414. 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 = ?"
  4415. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4416. }
  4417. }
  4418. }
  4419. } else {
  4420. if cost_type > 0 {
  4421. if len(execution_frequency) > 0 {
  4422. if len(keyword) > 0 {
  4423. 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 = ? and advice_name like ?"
  4424. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  4425. } else {
  4426. 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 = ?"
  4427. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4428. }
  4429. } else {
  4430. if len(keyword) > 0 {
  4431. 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 advice_name like ?"
  4432. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  4433. } else {
  4434. 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=?"
  4435. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4436. }
  4437. }
  4438. } else {
  4439. if len(execution_frequency) > 0 {
  4440. if len(keyword) > 0 {
  4441. 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 = ? and advice_name like ?"
  4442. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  4443. } else {
  4444. 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 = ?"
  4445. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4446. }
  4447. } else {
  4448. if len(keyword) > 0 {
  4449. 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 advice_name like ?"
  4450. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  4451. } else {
  4452. 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 = ?)"
  4453. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4454. }
  4455. }
  4456. }
  4457. }
  4458. } else {
  4459. if execution_state > 0 {
  4460. if cost_type > 0 {
  4461. if len(execution_frequency) > 0 {
  4462. if len(keyword) > 0 {
  4463. 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 = ? and advice_name like ?"
  4464. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  4465. } else {
  4466. 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 = ?"
  4467. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4468. }
  4469. } else {
  4470. if len(keyword) > 0 {
  4471. 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 advice_name like ?"
  4472. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  4473. } else {
  4474. 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=?"
  4475. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4476. }
  4477. }
  4478. } else {
  4479. if len(execution_frequency) > 0 {
  4480. if len(keyword) > 0 {
  4481. 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 = ? and advice_name like ?"
  4482. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  4483. } else {
  4484. 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 = ?"
  4485. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4486. }
  4487. } else {
  4488. if len(keyword) > 0 {
  4489. 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 advice_name like ?"
  4490. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  4491. } else {
  4492. 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 = ?"
  4493. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4494. }
  4495. }
  4496. }
  4497. } else {
  4498. if cost_type > 0 {
  4499. if len(execution_frequency) > 0 {
  4500. if len(keyword) > 0 {
  4501. 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 = ? and advice_name like ?"
  4502. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  4503. } else {
  4504. 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 = ?"
  4505. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  4506. }
  4507. } else {
  4508. if len(keyword) > 0 {
  4509. 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 advice_name like ?"
  4510. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  4511. } else {
  4512. 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 = ?"
  4513. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4514. }
  4515. }
  4516. } else {
  4517. if len(execution_frequency) > 0 {
  4518. if len(keyword) > 0 {
  4519. 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 = ? and advice_name like ?"
  4520. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  4521. } else {
  4522. 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 = ?"
  4523. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  4524. }
  4525. } else {
  4526. if len(keyword) > 0 {
  4527. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1) and advice_name like ?"
  4528. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  4529. } else {
  4530. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  4531. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4532. }
  4533. }
  4534. }
  4535. }
  4536. }
  4537. }
  4538. } else if adviceType == 1 {
  4539. if patientType == 0 {
  4540. if patient_id > 0 {
  4541. if execution_state > 0 {
  4542. if cost_type > 0 {
  4543. if len(execution_frequency) > 0 {
  4544. if len(keyword) > 0 {
  4545. 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 = ? and advice_name like ?"
  4546. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4547. } else {
  4548. 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 = ?"
  4549. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4550. }
  4551. } else {
  4552. if len(keyword) > 0 {
  4553. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  4554. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  4555. } else {
  4556. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  4557. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4558. }
  4559. }
  4560. } else {
  4561. if len(execution_frequency) > 0 {
  4562. if len(keyword) > 0 {
  4563. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  4564. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  4565. } else {
  4566. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  4567. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4568. }
  4569. } else {
  4570. if len(keyword) > 0 {
  4571. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  4572. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  4573. } else {
  4574. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ?"
  4575. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4576. }
  4577. }
  4578. }
  4579. } else {
  4580. if cost_type > 0 {
  4581. if len(execution_frequency) > 0 {
  4582. if len(keyword) > 0 {
  4583. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  4584. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  4585. } else {
  4586. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  4587. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4588. }
  4589. } else {
  4590. if len(keyword) > 0 {
  4591. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? and advice_name like ? "
  4592. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  4593. } else {
  4594. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? "
  4595. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4596. }
  4597. }
  4598. } else {
  4599. if len(execution_frequency) > 0 {
  4600. if len(keyword) > 0 {
  4601. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and advice_name like ?"
  4602. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  4603. } else {
  4604. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
  4605. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4606. }
  4607. }
  4608. }
  4609. }
  4610. } else {
  4611. if execution_state > 0 {
  4612. if cost_type > 0 {
  4613. if len(execution_frequency) > 0 {
  4614. if len(keyword) > 0 {
  4615. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  4616. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  4617. } else {
  4618. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  4619. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4620. }
  4621. } else {
  4622. if len(keyword) > 0 {
  4623. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  4624. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  4625. } else {
  4626. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ?"
  4627. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4628. }
  4629. }
  4630. } else {
  4631. if len(execution_frequency) > 0 {
  4632. if len(keyword) > 0 {
  4633. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  4634. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  4635. } else {
  4636. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and execution_frequency = ?"
  4637. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4638. }
  4639. } else {
  4640. if len(keyword) > 0 {
  4641. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and advice_name like ?"
  4642. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  4643. } else {
  4644. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ?"
  4645. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4646. }
  4647. }
  4648. }
  4649. } else {
  4650. if cost_type > 0 {
  4651. if len(keyword) > 0 {
  4652. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = ? and advice_name like ?"
  4653. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  4654. } else {
  4655. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = ? "
  4656. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4657. }
  4658. } else {
  4659. if len(keyword) > 0 {
  4660. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and advice_name like ?"
  4661. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  4662. } else {
  4663. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  4664. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4665. }
  4666. }
  4667. }
  4668. }
  4669. } else if patientType == 1 {
  4670. if patient_id > 0 {
  4671. if execution_state > 0 {
  4672. if cost_type > 0 {
  4673. if len(execution_frequency) > 0 {
  4674. if len(keyword) > 0 {
  4675. 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 = ? and advice_name like ?"
  4676. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4677. } else {
  4678. 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 = ?"
  4679. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  4680. }
  4681. } else {
  4682. if len(keyword) > 0 {
  4683. 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 advice_name like ?"
  4684. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, keyword)
  4685. } else {
  4686. 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 = ?"
  4687. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  4688. }
  4689. }
  4690. } else {
  4691. if len(execution_frequency) > 0 {
  4692. if len(keyword) > 0 {
  4693. 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 = ? and advice_name like ?"
  4694. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  4695. } else {
  4696. 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 = ?"
  4697. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  4698. }
  4699. } else {
  4700. if len(keyword) > 0 {
  4701. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  4702. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, keyword)
  4703. } else {
  4704. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  4705. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  4706. }
  4707. }
  4708. }
  4709. } else {
  4710. if cost_type > 0 {
  4711. if len(execution_frequency) > 0 {
  4712. if len(keyword) > 0 {
  4713. 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 = ? and advice_name like ?"
  4714. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  4715. } else {
  4716. 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 = ?"
  4717. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  4718. }
  4719. } else {
  4720. if len(keyword) > 0 {
  4721. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  4722. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, keyword)
  4723. } else {
  4724. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  4725. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  4726. }
  4727. }
  4728. } else {
  4729. if len(execution_frequency) > 0 {
  4730. if len(keyword) > 0 {
  4731. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  4732. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency, keyword)
  4733. } else {
  4734. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  4735. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  4736. }
  4737. } else {
  4738. if len(keyword) > 0 {
  4739. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and advice_name like ?"
  4740. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, keyword)
  4741. } else {
  4742. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
  4743. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  4744. }
  4745. }
  4746. }
  4747. }
  4748. } else {
  4749. if execution_state > 0 {
  4750. if cost_type > 0 {
  4751. if len(execution_frequency) > 0 {
  4752. if len(keyword) > 0 {
  4753. 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 = ? and advice_name like ?"
  4754. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  4755. } else {
  4756. 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 = ?"
  4757. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  4758. }
  4759. } else {
  4760. if len(keyword) > 0 {
  4761. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=? and is_settle = ? and advice_name like ?"
  4762. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, keyword)
  4763. } else {
  4764. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=? and is_settle = ?"
  4765. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  4766. }
  4767. }
  4768. } else {
  4769. if len(execution_frequency) > 0 {
  4770. if len(keyword) > 0 {
  4771. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?and execution_frequency = ? and advice_name like ?"
  4772. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency, keyword)
  4773. } else {
  4774. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?and execution_frequency = ?"
  4775. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  4776. }
  4777. } else {
  4778. if len(keyword) > 0 {
  4779. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=? and advice_name like ?"
  4780. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, keyword)
  4781. } else {
  4782. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?"
  4783. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  4784. }
  4785. }
  4786. }
  4787. } else {
  4788. if cost_type > 0 {
  4789. if len(execution_frequency) > 0 {
  4790. if len(keyword) > 0 {
  4791. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  4792. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency, keyword)
  4793. } else {
  4794. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  4795. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  4796. }
  4797. } else {
  4798. if len(keyword) > 0 {
  4799. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? and advice_name like ?"
  4800. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, keyword)
  4801. } else {
  4802. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? "
  4803. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  4804. }
  4805. }
  4806. } else {
  4807. if len(execution_frequency) > 0 {
  4808. if len(keyword) > 0 {
  4809. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_frequency = ? and advice_name like ?"
  4810. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency, keyword)
  4811. } else {
  4812. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_frequency = ?"
  4813. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  4814. }
  4815. } else {
  4816. if len(keyword) > 0 {
  4817. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and advice_name like ?"
  4818. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, keyword)
  4819. } else {
  4820. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  4821. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  4822. }
  4823. }
  4824. }
  4825. }
  4826. }
  4827. } else if patientType == 2 {
  4828. if patient_id > 0 {
  4829. if execution_state > 0 {
  4830. if cost_type > 0 {
  4831. if len(execution_frequency) > 0 {
  4832. if len(keyword) > 0 {
  4833. 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 = ? and advice_name like ?"
  4834. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4835. } else {
  4836. 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 = ?"
  4837. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4838. }
  4839. } else {
  4840. if len(keyword) > 0 {
  4841. 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 advice_name like ?"
  4842. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  4843. } else {
  4844. 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 = ?"
  4845. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4846. }
  4847. }
  4848. } else {
  4849. if len(execution_frequency) > 0 {
  4850. if len(keyword) > 0 {
  4851. 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 = ? and advice_name like ?"
  4852. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  4853. } else {
  4854. 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 = ?"
  4855. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4856. }
  4857. } else {
  4858. if len(keyword) > 0 {
  4859. 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 advice_name like ?"
  4860. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  4861. } else {
  4862. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  4863. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4864. }
  4865. }
  4866. }
  4867. } else {
  4868. if cost_type > 0 {
  4869. if len(execution_frequency) > 0 {
  4870. if len(keyword) > 0 {
  4871. 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 = ? and advice_name like ?"
  4872. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  4873. } else {
  4874. 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 = ?"
  4875. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4876. }
  4877. } else {
  4878. if len(keyword) > 0 {
  4879. 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 advice_name like ?"
  4880. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  4881. } else {
  4882. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  4883. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4884. }
  4885. }
  4886. } else {
  4887. if len(execution_frequency) > 0 {
  4888. if len(keyword) > 0 {
  4889. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_frequency = ? and advice_name like ?"
  4890. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  4891. } else {
  4892. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_frequency = ?"
  4893. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4894. }
  4895. } else {
  4896. if len(keyword) > 0 {
  4897. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and advice_name like ?"
  4898. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  4899. } else {
  4900. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
  4901. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4902. }
  4903. }
  4904. }
  4905. }
  4906. } else {
  4907. if execution_state > 0 {
  4908. if cost_type > 0 {
  4909. if len(execution_frequency) > 0 {
  4910. if len(keyword) > 0 {
  4911. 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 = ? and advice_name like ?"
  4912. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  4913. } else {
  4914. 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 = ?"
  4915. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4916. }
  4917. } else {
  4918. if len(keyword) > 0 {
  4919. 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 advice_name like ?"
  4920. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  4921. } else {
  4922. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  4923. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4924. }
  4925. }
  4926. } else {
  4927. if len(execution_frequency) > 0 {
  4928. if len(keyword) > 0 {
  4929. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and execution_frequency = ? and advice_name like ?"
  4930. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  4931. } else {
  4932. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and execution_frequency = ?"
  4933. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4934. }
  4935. } else {
  4936. if len(keyword) > 0 {
  4937. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and advice_name like ?"
  4938. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  4939. } else {
  4940. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ?"
  4941. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4942. }
  4943. }
  4944. }
  4945. } else {
  4946. if cost_type > 0 {
  4947. if len(execution_frequency) > 0 {
  4948. if len(keyword) > 0 {
  4949. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ? and execution_frequency = ? and advice_name like ?"
  4950. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  4951. } else {
  4952. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  4953. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  4954. }
  4955. } else {
  4956. if len(keyword) > 0 {
  4957. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ? and advice_name like ?"
  4958. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  4959. } else {
  4960. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ?"
  4961. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4962. }
  4963. }
  4964. } else {
  4965. if len(execution_frequency) > 0 {
  4966. if len(keyword) > 0 {
  4967. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_frequency = ? and advice_name like ?"
  4968. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  4969. } else {
  4970. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_frequency = ?"
  4971. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  4972. }
  4973. } else {
  4974. if len(keyword) > 0 {
  4975. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and advice_name like ?"
  4976. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  4977. } else {
  4978. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  4979. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4980. }
  4981. }
  4982. }
  4983. }
  4984. }
  4985. }
  4986. } else if adviceType == 3 {
  4987. if patientType == 0 {
  4988. if patient_id > 0 {
  4989. if execution_state > 0 {
  4990. if cost_type > 0 {
  4991. if len(execution_frequency) > 0 {
  4992. if len(keyword) > 0 {
  4993. 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 =? and advice_name like ?"
  4994. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4995. } else {
  4996. 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 =?"
  4997. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4998. }
  4999. } else {
  5000. if len(keyword) > 0 {
  5001. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5002. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  5003. } else {
  5004. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  5005. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5006. }
  5007. }
  5008. } else {
  5009. if len(execution_frequency) > 0 {
  5010. if len(keyword) > 0 {
  5011. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency =? and advice_name like ?"
  5012. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  5013. } else {
  5014. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency =?"
  5015. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  5016. }
  5017. } else {
  5018. if len(keyword) > 0 {
  5019. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  5020. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  5021. } else {
  5022. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ?"
  5023. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5024. }
  5025. }
  5026. }
  5027. } else {
  5028. if cost_type > 0 {
  5029. if len(execution_frequency) > 0 {
  5030. if len(keyword) > 0 {
  5031. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency =? and advice_name like ?"
  5032. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  5033. } else {
  5034. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency =?"
  5035. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  5036. }
  5037. } else {
  5038. if len(keyword) > 0 {
  5039. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  5040. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  5041. } else {
  5042. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? "
  5043. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5044. }
  5045. }
  5046. } else {
  5047. if len(execution_frequency) > 0 {
  5048. if len(keyword) > 0 {
  5049. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_frequency =? and advice_name like ?"
  5050. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  5051. } else {
  5052. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_frequency =?"
  5053. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  5054. }
  5055. } else {
  5056. if len(keyword) > 0 {
  5057. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and advice_name like ?"
  5058. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  5059. } else {
  5060. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? "
  5061. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5062. }
  5063. }
  5064. }
  5065. }
  5066. } else {
  5067. if execution_state > 0 {
  5068. if cost_type > 0 {
  5069. if len(execution_frequency) > 0 {
  5070. if len(keyword) > 0 {
  5071. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ? and execution_frequency =? and advice_name like ?"
  5072. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  5073. } else {
  5074. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ? and execution_frequency =?"
  5075. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  5076. }
  5077. } else {
  5078. if len(keyword) > 0 {
  5079. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ? and advice_name like ?"
  5080. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  5081. } else {
  5082. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ?"
  5083. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5084. }
  5085. }
  5086. } else {
  5087. if len(execution_frequency) > 0 {
  5088. if len(keyword) > 0 {
  5089. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and execution_frequency =? and advice_name like ?"
  5090. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  5091. } else {
  5092. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and execution_frequency =?"
  5093. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  5094. }
  5095. } else {
  5096. if len(keyword) > 0 {
  5097. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and advice_name like ?"
  5098. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  5099. } else {
  5100. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? "
  5101. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5102. }
  5103. }
  5104. }
  5105. } else {
  5106. if cost_type > 0 {
  5107. if len(execution_frequency) > 0 {
  5108. if len(keyword) > 0 {
  5109. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? and execution_frequency =? and advice_name like ?"
  5110. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  5111. } else {
  5112. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? and execution_frequency =?"
  5113. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  5114. }
  5115. } else {
  5116. if len(keyword) > 0 {
  5117. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? and advice_name like ?"
  5118. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  5119. } else {
  5120. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? "
  5121. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5122. }
  5123. }
  5124. } else {
  5125. if len(execution_frequency) > 0 {
  5126. if len(keyword) > 0 {
  5127. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_frequency =? and advice_name like ?"
  5128. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  5129. } else {
  5130. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_frequency =?"
  5131. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  5132. }
  5133. } else {
  5134. if len(keyword) > 0 {
  5135. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and advice_name like ?"
  5136. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  5137. } else {
  5138. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  5139. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5140. }
  5141. }
  5142. }
  5143. }
  5144. }
  5145. } else if patientType == 1 {
  5146. if patient_id > 0 {
  5147. if execution_state > 0 {
  5148. if cost_type > 0 {
  5149. if len(execution_frequency) > 0 {
  5150. if len(keyword) > 0 {
  5151. 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 = ? and advice_name like ?"
  5152. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5153. } else {
  5154. 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 = ?"
  5155. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  5156. }
  5157. } else {
  5158. if len(keyword) > 0 {
  5159. 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 advice_name like ?"
  5160. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, keyword)
  5161. } else {
  5162. 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 = ?"
  5163. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  5164. }
  5165. }
  5166. } else {
  5167. if len(execution_frequency) > 0 {
  5168. if len(keyword) > 0 {
  5169. 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 = ? and advice_name like ?"
  5170. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  5171. } else {
  5172. 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 = ?"
  5173. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  5174. }
  5175. } else {
  5176. if len(keyword) > 0 {
  5177. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  5178. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, keyword)
  5179. } else {
  5180. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  5181. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  5182. }
  5183. }
  5184. }
  5185. } else {
  5186. if cost_type > 0 {
  5187. if len(execution_frequency) > 0 {
  5188. if len(keyword) > 0 {
  5189. 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 = ? and advice_name like ?"
  5190. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  5191. } else {
  5192. 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 = ?"
  5193. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  5194. }
  5195. } else {
  5196. if len(keyword) > 0 {
  5197. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  5198. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, keyword)
  5199. } else {
  5200. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  5201. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  5202. }
  5203. }
  5204. } else {
  5205. if len(execution_frequency) > 0 {
  5206. if len(keyword) > 0 {
  5207. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  5208. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency, keyword)
  5209. } else {
  5210. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  5211. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  5212. }
  5213. } else {
  5214. if len(keyword) > 0 {
  5215. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and advice_name like ?"
  5216. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, keyword)
  5217. } else {
  5218. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
  5219. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  5220. }
  5221. }
  5222. }
  5223. }
  5224. } else {
  5225. if execution_state > 0 {
  5226. if cost_type > 0 {
  5227. if len(execution_frequency) > 0 {
  5228. if len(keyword) > 0 {
  5229. 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 = ? and advice_name like ?"
  5230. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  5231. } else {
  5232. 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 = ?"
  5233. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  5234. }
  5235. } else {
  5236. if len(keyword) > 0 {
  5237. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? and is_settle = ? and advice_name like ?"
  5238. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, keyword)
  5239. } else {
  5240. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? and is_settle = ?"
  5241. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  5242. }
  5243. }
  5244. } else {
  5245. if len(execution_frequency) > 0 {
  5246. if len(keyword) > 0 {
  5247. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =?and execution_frequency = ? and avice_name like ? "
  5248. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency, keyword)
  5249. } else {
  5250. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =?and execution_frequency = ? "
  5251. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  5252. }
  5253. } else {
  5254. if len(keyword) > 0 {
  5255. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? and advice_name like ?"
  5256. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, keyword)
  5257. } else {
  5258. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? "
  5259. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  5260. }
  5261. }
  5262. }
  5263. } else {
  5264. if cost_type > 0 {
  5265. if len(execution_frequency) > 0 {
  5266. if len(keyword) > 0 {
  5267. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5268. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency, keyword)
  5269. } else {
  5270. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  5271. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  5272. }
  5273. } else {
  5274. if len(keyword) > 0 {
  5275. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ? and advice_name like ?"
  5276. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, keyword)
  5277. } else {
  5278. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ?"
  5279. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  5280. }
  5281. }
  5282. } else {
  5283. if len(execution_frequency) > 0 {
  5284. if len(keyword) > 0 {
  5285. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_frequency = ? and advice_name like ?"
  5286. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency, keyword)
  5287. } else {
  5288. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_frequency = ?"
  5289. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  5290. }
  5291. } else {
  5292. if len(keyword) > 0 {
  5293. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and advice_name like ?"
  5294. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, keyword)
  5295. } else {
  5296. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  5297. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  5298. }
  5299. }
  5300. }
  5301. }
  5302. }
  5303. } else if patientType == 2 {
  5304. if patient_id > 0 {
  5305. if execution_state > 0 {
  5306. if cost_type > 0 {
  5307. if len(execution_frequency) > 0 {
  5308. if len(keyword) > 0 {
  5309. 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 = ? and advice_name like ?"
  5310. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5311. } else {
  5312. 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 = ?"
  5313. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  5314. }
  5315. } else {
  5316. if len(keyword) > 0 {
  5317. 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 advice_name like ?"
  5318. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  5319. } else {
  5320. 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 = ?"
  5321. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5322. }
  5323. }
  5324. } else {
  5325. if len(execution_frequency) > 0 {
  5326. if len(keyword) > 0 {
  5327. 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 = ? and advice_name like ?"
  5328. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  5329. } else {
  5330. 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 = ?"
  5331. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  5332. }
  5333. } else {
  5334. if len(keyword) > 0 {
  5335. 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 advice_name like ?"
  5336. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  5337. } else {
  5338. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  5339. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5340. }
  5341. }
  5342. }
  5343. } else {
  5344. if cost_type > 0 {
  5345. if len(execution_frequency) > 0 {
  5346. if len(keyword) > 0 {
  5347. 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 = ? and advice_name like ?"
  5348. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  5349. } else {
  5350. 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 = ?"
  5351. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  5352. }
  5353. } else {
  5354. if len(keyword) > 0 {
  5355. 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 advice_name like ?"
  5356. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  5357. } else {
  5358. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  5359. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5360. }
  5361. }
  5362. } else {
  5363. if len(execution_frequency) > 0 {
  5364. if len(keyword) > 0 {
  5365. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_frequency = ? and advice_name like ?"
  5366. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  5367. } else {
  5368. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_frequency = ?"
  5369. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  5370. }
  5371. } else {
  5372. if len(keyword) > 0 {
  5373. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and advice_name like ?"
  5374. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  5375. } else {
  5376. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ?"
  5377. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5378. }
  5379. }
  5380. }
  5381. }
  5382. } else {
  5383. if execution_state > 0 {
  5384. if cost_type > 0 {
  5385. if len(execution_frequency) > 0 {
  5386. if len(keyword) > 0 {
  5387. 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 = ? and advice_name like ?"
  5388. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  5389. } else {
  5390. 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 = ?"
  5391. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  5392. }
  5393. } else {
  5394. if len(keyword) > 0 {
  5395. 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 advice_name like ?"
  5396. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  5397. } else {
  5398. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and is_settle = ?"
  5399. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5400. }
  5401. }
  5402. } else {
  5403. if len(execution_frequency) > 0 {
  5404. if len(keyword) > 0 {
  5405. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and execution_frequency = ? and advice_name like ?"
  5406. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  5407. } else {
  5408. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and execution_frequency = ?"
  5409. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  5410. }
  5411. } else {
  5412. if len(keyword) > 0 {
  5413. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and advice_name like ?"
  5414. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  5415. } else {
  5416. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ?"
  5417. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5418. }
  5419. }
  5420. }
  5421. } else {
  5422. if cost_type > 0 {
  5423. if len(execution_frequency) > 0 {
  5424. if len(keyword) > 0 {
  5425. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5426. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  5427. } else {
  5428. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  5429. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  5430. }
  5431. } else {
  5432. if len(keyword) > 0 {
  5433. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ? and advice_name like ?"
  5434. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  5435. } else {
  5436. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ?"
  5437. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5438. }
  5439. }
  5440. } else {
  5441. if len(execution_frequency) > 0 {
  5442. if len(keyword) > 0 {
  5443. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_frequency = ? and advice_name like ?"
  5444. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  5445. } else {
  5446. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_frequency = ?"
  5447. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  5448. }
  5449. } else {
  5450. if len(keyword) > 0 {
  5451. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and advice_name like ?"
  5452. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  5453. } else {
  5454. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  5455. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5456. }
  5457. }
  5458. }
  5459. }
  5460. }
  5461. }
  5462. } else if adviceType == 2 && len(deliverWay) > 0 {
  5463. if patientType == 0 {
  5464. if patient_id > 0 {
  5465. if execution_state > 0 {
  5466. if cost_type > 0 {
  5467. if len(execution_frequency) > 0 {
  5468. if len(keyword) > 0 {
  5469. 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 = ? and advice_name like ?"
  5470. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5471. } else {
  5472. 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 = ?"
  5473. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency)
  5474. }
  5475. } else {
  5476. if len(keyword) > 0 {
  5477. 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 advice_name like ?"
  5478. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, keyword)
  5479. } else {
  5480. 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 = ?"
  5481. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  5482. }
  5483. }
  5484. } else {
  5485. if len(execution_frequency) > 0 {
  5486. if len(keyword) > 0 {
  5487. 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 = ? and advice_name like ?"
  5488. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency, keyword)
  5489. } else {
  5490. 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 = ?"
  5491. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency)
  5492. }
  5493. } else {
  5494. if len(keyword) > 0 {
  5495. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  5496. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, keyword)
  5497. } else {
  5498. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  5499. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  5500. }
  5501. }
  5502. }
  5503. } else {
  5504. if cost_type > 0 {
  5505. if len(execution_frequency) > 0 {
  5506. if len(keyword) > 0 {
  5507. 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 = ? and advice_name like ?"
  5508. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency, keyword)
  5509. } else {
  5510. 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 = ?"
  5511. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency)
  5512. }
  5513. } else {
  5514. if len(keyword) > 0 {
  5515. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  5516. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, keyword)
  5517. } else {
  5518. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and is_settle = ?"
  5519. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  5520. }
  5521. }
  5522. } else {
  5523. if len(execution_frequency) > 0 {
  5524. if len(keyword) > 0 {
  5525. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  5526. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency, keyword)
  5527. } else {
  5528. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_frequency = ?"
  5529. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency)
  5530. }
  5531. } else {
  5532. if len(keyword) > 0 {
  5533. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and advice_name like ?"
  5534. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, keyword)
  5535. } else {
  5536. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ?"
  5537. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  5538. }
  5539. }
  5540. }
  5541. }
  5542. } else {
  5543. if execution_state > 0 {
  5544. if cost_type > 0 {
  5545. if len(execution_frequency) > 0 {
  5546. if len(keyword) > 0 {
  5547. 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 = ? and advice_name like ?"
  5548. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency, keyword)
  5549. } else {
  5550. 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 = ?"
  5551. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency)
  5552. }
  5553. } else {
  5554. if len(keyword) > 0 {
  5555. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5556. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, keyword)
  5557. } else {
  5558. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and is_settle = ?"
  5559. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  5560. }
  5561. }
  5562. } else {
  5563. if len(execution_frequency) > 0 {
  5564. if len(keyword) > 0 {
  5565. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5566. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency, keyword)
  5567. } else {
  5568. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and execution_frequency = ?"
  5569. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency)
  5570. }
  5571. } else {
  5572. if len(keyword) > 0 {
  5573. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and advice_name like ?"
  5574. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, keyword)
  5575. } else {
  5576. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ?"
  5577. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  5578. }
  5579. }
  5580. }
  5581. } else {
  5582. if cost_type > 0 {
  5583. if len(execution_frequency) > 0 {
  5584. if len(keyword) > 0 {
  5585. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5586. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, execution_frequency, keyword)
  5587. } else {
  5588. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and is_settle = ? and execution_frequency = ?"
  5589. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, execution_frequency)
  5590. }
  5591. } else {
  5592. if len(keyword) > 0 {
  5593. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and is_settle = ? and advice_name like ?"
  5594. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, keyword)
  5595. } else {
  5596. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and is_settle = ?"
  5597. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  5598. }
  5599. }
  5600. } else {
  5601. if len(execution_frequency) > 0 {
  5602. if len(keyword) > 0 {
  5603. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_frequency = ? and advice_name like ?"
  5604. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_frequency, keyword)
  5605. } else {
  5606. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_frequency = ?"
  5607. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_frequency)
  5608. }
  5609. } else {
  5610. if len(keyword) > 0 {
  5611. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and advice_name like ?"
  5612. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, keyword)
  5613. } else {
  5614. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  5615. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  5616. }
  5617. }
  5618. }
  5619. }
  5620. }
  5621. } else if patientType == 1 {
  5622. if patient_id > 0 {
  5623. if execution_state > 0 {
  5624. if cost_type > 0 {
  5625. if len(execution_frequency) > 0 {
  5626. if len(keyword) > 0 {
  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 = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5628. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5629. } else {
  5630. 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 = ?"
  5631. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type, execution_frequency)
  5632. }
  5633. } else {
  5634. if len(keyword) > 0 {
  5635. 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 advice_name like ?"
  5636. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type, keyword)
  5637. } else {
  5638. 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 = ?"
  5639. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type)
  5640. }
  5641. }
  5642. } else {
  5643. if len(execution_frequency) > 0 {
  5644. if len(keyword) > 0 {
  5645. 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 = ? and advice_name like ?"
  5646. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, execution_frequency, keyword)
  5647. } else {
  5648. 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 = ?"
  5649. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, execution_frequency)
  5650. }
  5651. } else {
  5652. if len(keyword) > 0 {
  5653. 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 advice_name like ?"
  5654. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, keyword)
  5655. } else {
  5656. 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 = ?"
  5657. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state)
  5658. }
  5659. }
  5660. }
  5661. } else {
  5662. if cost_type > 0 {
  5663. if len(execution_frequency) > 0 {
  5664. if len(keyword) > 0 {
  5665. 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 = ? and advice_name like ?"
  5666. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type, execution_frequency, keyword)
  5667. } else {
  5668. 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 = ?"
  5669. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type, execution_frequency)
  5670. }
  5671. } else {
  5672. if len(keyword) > 0 {
  5673. 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 advice_name like ?"
  5674. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type, keyword)
  5675. } else {
  5676. 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 = ?"
  5677. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type)
  5678. }
  5679. }
  5680. } else {
  5681. if len(execution_frequency) > 0 {
  5682. if len(keyword) > 0 {
  5683. 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 = ? and advice_name like ?"
  5684. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_frequency, keyword)
  5685. } else {
  5686. 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 = ?"
  5687. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_frequency)
  5688. }
  5689. } else {
  5690. if len(keyword) > 0 {
  5691. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and avice_name like ?"
  5692. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, keyword)
  5693. } else {
  5694. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ?"
  5695. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
  5696. }
  5697. }
  5698. }
  5699. }
  5700. } else {
  5701. if execution_state > 0 {
  5702. if cost_type > 0 {
  5703. if len(execution_frequency) > 0 {
  5704. if len(keyword) > 0 {
  5705. 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 = ? and advice_name like ?"
  5706. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type, execution_frequency, keyword)
  5707. } else {
  5708. 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 = ?"
  5709. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type, execution_frequency)
  5710. }
  5711. } else {
  5712. if len(keyword) > 0 {
  5713. 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 advice_name like ?"
  5714. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type, keyword)
  5715. } else {
  5716. 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 = ?"
  5717. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type)
  5718. }
  5719. }
  5720. } else {
  5721. if len(execution_frequency) > 0 {
  5722. if len(keyword) > 0 {
  5723. 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 = ? and advice_name like ?"
  5724. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, execution_frequency, keyword)
  5725. } else {
  5726. 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 = ?"
  5727. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, execution_frequency)
  5728. }
  5729. } else {
  5730. if len(keyword) > 0 {
  5731. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ? and advice_name like ?"
  5732. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, keyword)
  5733. } else {
  5734. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ?"
  5735. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state)
  5736. }
  5737. }
  5738. }
  5739. } else {
  5740. if cost_type > 0 {
  5741. if len(execution_frequency) > 0 {
  5742. if len(keyword) > 0 {
  5743. 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 = ? and advice_name like ?"
  5744. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type, execution_frequency, keyword)
  5745. } else {
  5746. 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 = ?"
  5747. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type, execution_frequency)
  5748. }
  5749. } else {
  5750. if len(keyword) > 0 {
  5751. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and is_settle = ? and advice_name like ?"
  5752. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type, keyword)
  5753. } else {
  5754. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and is_settle = ?"
  5755. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type)
  5756. }
  5757. }
  5758. } else {
  5759. if len(execution_frequency) > 0 {
  5760. if len(keyword) > 0 {
  5761. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_frequency = ? and advic_name like ?"
  5762. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_frequency, keyword)
  5763. } else {
  5764. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_frequency = ?"
  5765. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_frequency)
  5766. }
  5767. } else {
  5768. if len(keyword) > 0 {
  5769. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and advice_name like ?"
  5770. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, keyword)
  5771. } else {
  5772. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  5773. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  5774. }
  5775. }
  5776. }
  5777. }
  5778. }
  5779. } else if patientType == 2 {
  5780. if patient_id > 0 {
  5781. if execution_state > 0 {
  5782. if cost_type > 0 {
  5783. if len(execution_frequency) > 0 {
  5784. if len(keyword) > 0 {
  5785. 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 = ? and advice_name like ?"
  5786. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5787. } else {
  5788. 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 = ?"
  5789. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency)
  5790. }
  5791. } else {
  5792. if len(keyword) > 0 {
  5793. 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 advice_name like ?"
  5794. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, keyword)
  5795. } else {
  5796. 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 = ?"
  5797. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  5798. }
  5799. }
  5800. } else {
  5801. if len(execution_frequency) > 0 {
  5802. if len(keyword) > 0 {
  5803. 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 = ? and advice_name like ?"
  5804. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency, keyword)
  5805. } else {
  5806. 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 = ?"
  5807. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency)
  5808. }
  5809. } else {
  5810. if len(keyword) > 0 {
  5811. 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 advice_name like ?"
  5812. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, keyword)
  5813. } else {
  5814. 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 = ?"
  5815. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  5816. }
  5817. }
  5818. }
  5819. } else {
  5820. if cost_type > 0 {
  5821. if len(execution_frequency) > 0 {
  5822. if len(keyword) > 0 {
  5823. 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 = ? and advice_name like ?"
  5824. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency, keyword)
  5825. } else {
  5826. 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 = ?"
  5827. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency)
  5828. }
  5829. } else {
  5830. if len(keyword) > 0 {
  5831. 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 advice_name like ?"
  5832. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, keyword)
  5833. } else {
  5834. 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 = ?"
  5835. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  5836. }
  5837. }
  5838. } else {
  5839. if len(execution_frequency) > 0 {
  5840. if len(keyword) > 0 {
  5841. 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 = ? and advice_name like ?"
  5842. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency, keyword)
  5843. } else {
  5844. 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 = ?"
  5845. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency)
  5846. }
  5847. } else {
  5848. if len(keyword) > 0 {
  5849. 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 advice_name like ?"
  5850. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, keyword)
  5851. } else {
  5852. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ?"
  5853. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  5854. }
  5855. }
  5856. }
  5857. }
  5858. } else {
  5859. if execution_state > 0 {
  5860. if cost_type > 0 {
  5861. if len(execution_frequency) > 0 {
  5862. if len(keyword) > 0 {
  5863. 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 = ? and advice_name like ?"
  5864. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency, keyword)
  5865. } else {
  5866. 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 = ?"
  5867. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency)
  5868. }
  5869. } else {
  5870. if len(keyword) > 0 {
  5871. 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 advice_name like ?"
  5872. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, keyword)
  5873. } else {
  5874. 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 = ?"
  5875. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  5876. }
  5877. }
  5878. } else {
  5879. if len(execution_frequency) > 0 {
  5880. if len(keyword) > 0 {
  5881. 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 = ? and advice_name like ?"
  5882. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency, keyword)
  5883. } else {
  5884. 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 = ?"
  5885. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency)
  5886. }
  5887. } else {
  5888. if len(keyword) > 0 {
  5889. 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 advice_name like ?"
  5890. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, keyword)
  5891. } else {
  5892. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ?"
  5893. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  5894. }
  5895. }
  5896. }
  5897. } else {
  5898. if cost_type > 0 {
  5899. if len(execution_frequency) > 0 {
  5900. if len(keyword) > 0 {
  5901. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and is_settle = ? and advice_name like ?"
  5902. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, keyword)
  5903. } else {
  5904. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and is_settle = ?"
  5905. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  5906. }
  5907. } else {
  5908. if len(keyword) > 0 {
  5909. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and is_settle = ? and advice_name like ?"
  5910. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, keyword)
  5911. } else {
  5912. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and is_settle = ?"
  5913. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  5914. }
  5915. }
  5916. } else {
  5917. if len(keyword) > 0 {
  5918. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and advice_name like ?"
  5919. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, keyword)
  5920. } else {
  5921. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  5922. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  5923. }
  5924. }
  5925. }
  5926. }
  5927. }
  5928. } else if adviceType == 2 && len(deliverWay) <= 0 {
  5929. if patientType == 0 {
  5930. if patient_id > 0 {
  5931. if execution_state > 0 {
  5932. if cost_type > 0 {
  5933. if len(execution_frequency) > 0 {
  5934. if len(keyword) > 0 {
  5935. 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 = ? and advice_name like ?"
  5936. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5937. } else {
  5938. 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 = ?"
  5939. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  5940. }
  5941. } else {
  5942. if len(keyword) > 0 {
  5943. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5944. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  5945. } else {
  5946. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  5947. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5948. }
  5949. }
  5950. } else {
  5951. if len(execution_frequency) > 0 {
  5952. if len(keyword) > 0 {
  5953. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5954. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  5955. } else {
  5956. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  5957. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  5958. }
  5959. } else {
  5960. if len(keyword) > 0 {
  5961. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  5962. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  5963. } else {
  5964. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ?"
  5965. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5966. }
  5967. }
  5968. }
  5969. } else {
  5970. if cost_type > 0 {
  5971. if len(execution_frequency) > 0 {
  5972. if len(keyword) > 0 {
  5973. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5974. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  5975. } else {
  5976. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  5977. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  5978. }
  5979. } else {
  5980. if len(keyword) > 0 {
  5981. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  5982. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  5983. } else {
  5984. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and is_settle = ?"
  5985. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5986. }
  5987. }
  5988. } else {
  5989. if len(execution_frequency) > 0 {
  5990. if len(keyword) > 0 {
  5991. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  5992. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  5993. } else {
  5994. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_frequency = ?"
  5995. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  5996. }
  5997. } else {
  5998. if len(keyword) > 0 {
  5999. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and advice_name like ?"
  6000. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  6001. } else {
  6002. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ?"
  6003. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6004. }
  6005. }
  6006. }
  6007. }
  6008. } else {
  6009. if execution_state > 0 {
  6010. if cost_type > 0 {
  6011. if len(execution_frequency) > 0 {
  6012. if len(keyword) > 0 {
  6013. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6014. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  6015. } else {
  6016. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  6017. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  6018. }
  6019. } else {
  6020. if len(keyword) > 0 {
  6021. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  6022. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  6023. } else {
  6024. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ? and is_settle = ?"
  6025. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6026. }
  6027. }
  6028. } else {
  6029. if len(execution_frequency) > 0 {
  6030. if len(keyword) > 0 {
  6031. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?and execution_frequency = ? and advice_name like ?"
  6032. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  6033. } else {
  6034. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?and execution_frequency = ?"
  6035. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  6036. }
  6037. } else {
  6038. if len(keyword) > 0 {
  6039. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ? and advice_name like ?"
  6040. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  6041. } else {
  6042. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?"
  6043. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6044. }
  6045. }
  6046. }
  6047. } else {
  6048. if cost_type > 0 {
  6049. if len(execution_frequency) > 0 {
  6050. if len(keyword) > 0 {
  6051. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6052. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  6053. } else {
  6054. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and is_settle = ? and execution_frequency = ?"
  6055. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  6056. }
  6057. }
  6058. } else {
  6059. if len(execution_frequency) > 0 {
  6060. if len(keyword) > 0 {
  6061. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_frequency = ? and advice_name like ?"
  6062. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  6063. } else {
  6064. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_frequency = ?"
  6065. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  6066. }
  6067. } else {
  6068. if len(keyword) > 0 {
  6069. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and advice_name like ?"
  6070. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  6071. } else {
  6072. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  6073. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6074. }
  6075. }
  6076. }
  6077. }
  6078. }
  6079. } else if patientType == 1 {
  6080. if patient_id > 0 {
  6081. if execution_state > 0 {
  6082. if cost_type > 0 {
  6083. if len(execution_frequency) > 0 {
  6084. if len(keyword) > 0 {
  6085. 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 = ? and advice_name like ?"
  6086. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  6087. } else {
  6088. 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 = ?"
  6089. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  6090. }
  6091. } else {
  6092. if len(keyword) > 0 {
  6093. 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 advice_name like ?"
  6094. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, keyword)
  6095. } else {
  6096. 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 = ?"
  6097. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  6098. }
  6099. }
  6100. } else {
  6101. if len(execution_frequency) > 0 {
  6102. if len(keyword) > 0 {
  6103. 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 = ? and advice_name like ?"
  6104. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  6105. } else {
  6106. 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 = ?"
  6107. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  6108. }
  6109. } else {
  6110. if len(keyword) > 0 {
  6111. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  6112. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, keyword)
  6113. } else {
  6114. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  6115. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  6116. }
  6117. }
  6118. }
  6119. } else {
  6120. if cost_type > 0 {
  6121. if len(execution_frequency) > 0 {
  6122. if len(keyword) > 0 {
  6123. 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 = ? and advice_name like ?"
  6124. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  6125. } else {
  6126. 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 = ?"
  6127. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  6128. }
  6129. } else {
  6130. if len(keyword) > 0 {
  6131. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  6132. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, keyword)
  6133. } else {
  6134. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  6135. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  6136. }
  6137. }
  6138. } else {
  6139. if len(execution_frequency) > 0 {
  6140. if len(keyword) > 0 {
  6141. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  6142. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency, keyword)
  6143. } else {
  6144. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  6145. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  6146. }
  6147. } else {
  6148. if len(keyword) > 0 {
  6149. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and advice_name like ?"
  6150. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, keyword)
  6151. } else {
  6152. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ?"
  6153. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  6154. }
  6155. }
  6156. }
  6157. }
  6158. } else {
  6159. if execution_state > 0 {
  6160. if cost_type > 0 {
  6161. if len(execution_frequency) > 0 {
  6162. if len(keyword) > 0 {
  6163. 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 = ? and advice_name like ?"
  6164. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  6165. } else {
  6166. 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 = ?"
  6167. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  6168. }
  6169. } else {
  6170. if len(keyword) > 0 {
  6171. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  6172. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, keyword)
  6173. } else {
  6174. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ? and is_settle = ?"
  6175. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  6176. }
  6177. }
  6178. } else {
  6179. if len(execution_frequency) > 0 {
  6180. if len(keyword) > 0 {
  6181. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  6182. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency, keyword)
  6183. } else {
  6184. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ? and execution_frequency = ?"
  6185. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  6186. }
  6187. } else {
  6188. if len(keyword) > 0 {
  6189. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ? and advice_name like ?"
  6190. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, keyword)
  6191. } else {
  6192. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ?"
  6193. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  6194. }
  6195. }
  6196. }
  6197. } else {
  6198. if cost_type > 0 {
  6199. if len(execution_frequency) > 0 {
  6200. if len(keyword) > 0 {
  6201. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6202. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency, keyword)
  6203. } else {
  6204. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  6205. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  6206. }
  6207. } else {
  6208. if len(keyword) > 0 {
  6209. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and is_settle = ? and advice_name like ?"
  6210. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, keyword)
  6211. } else {
  6212. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and is_settle = ?"
  6213. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  6214. }
  6215. }
  6216. } else {
  6217. if len(execution_frequency) > 0 {
  6218. if len(keyword) > 0 {
  6219. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_frequency = ? and advice_name like ?"
  6220. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency, keyword)
  6221. } else {
  6222. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_frequency = ?"
  6223. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  6224. }
  6225. } else {
  6226. if len(keyword) > 0 {
  6227. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and advice_name like ?"
  6228. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, keyword)
  6229. } else {
  6230. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?"
  6231. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  6232. }
  6233. }
  6234. }
  6235. }
  6236. }
  6237. } else if patientType == 2 {
  6238. if patient_id > 0 {
  6239. if execution_state > 0 {
  6240. if cost_type > 0 {
  6241. if len(execution_frequency) > 0 {
  6242. if len(keyword) > 0 {
  6243. 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=? and advice_name like ?"
  6244. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  6245. } else {
  6246. 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=?"
  6247. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  6248. }
  6249. } else {
  6250. if len(keyword) > 0 {
  6251. 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 advice_name like ?"
  6252. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  6253. } else {
  6254. 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 = ?"
  6255. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6256. }
  6257. }
  6258. } else {
  6259. if len(execution_frequency) > 0 {
  6260. if len(keyword) > 0 {
  6261. 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=? and advice_name like ?"
  6262. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  6263. } else {
  6264. 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=?"
  6265. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  6266. }
  6267. } else {
  6268. if len(keyword) > 0 {
  6269. 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 advice_name like ?"
  6270. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  6271. } else {
  6272. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  6273. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6274. }
  6275. }
  6276. }
  6277. } else {
  6278. if cost_type > 0 {
  6279. if len(execution_frequency) > 0 {
  6280. if len(keyword) > 0 {
  6281. 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=? and advice_name like ?"
  6282. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  6283. } else {
  6284. 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=?"
  6285. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  6286. }
  6287. } else {
  6288. if len(keyword) > 0 {
  6289. 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 advice_name like ?"
  6290. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  6291. } else {
  6292. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  6293. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6294. }
  6295. }
  6296. } else {
  6297. if len(execution_frequency) > 0 {
  6298. if len(keyword) > 0 {
  6299. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_frequency=? and advice_name like ?"
  6300. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  6301. } else {
  6302. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_frequency=?"
  6303. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  6304. }
  6305. } else {
  6306. if len(keyword) > 0 {
  6307. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and advice_name like ?"
  6308. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  6309. } else {
  6310. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ?"
  6311. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6312. }
  6313. }
  6314. }
  6315. }
  6316. } else {
  6317. if execution_state > 0 {
  6318. if cost_type > 0 {
  6319. if len(execution_frequency) > 0 {
  6320. if len(keyword) > 0 {
  6321. 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 = ? and advice_name like ?"
  6322. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  6323. } else {
  6324. 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 = ?"
  6325. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  6326. }
  6327. } else {
  6328. if len(keyword) > 0 {
  6329. 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 advice_name like ?"
  6330. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  6331. } else {
  6332. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  6333. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6334. }
  6335. }
  6336. } else {
  6337. if len(execution_frequency) > 0 {
  6338. if len(keyword) > 0 {
  6339. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ? and execution_frequency = ? and advice_name like ?"
  6340. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  6341. } else {
  6342. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ? and execution_frequency = ? "
  6343. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  6344. }
  6345. } else {
  6346. if len(keyword) > 0 {
  6347. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ? and advice_name like ?"
  6348. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  6349. } else {
  6350. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ?"
  6351. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6352. }
  6353. }
  6354. }
  6355. } else {
  6356. if cost_type > 0 {
  6357. if len(execution_frequency) > 0 {
  6358. if len(keyword) > 0 {
  6359. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6360. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  6361. } else {
  6362. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  6363. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  6364. }
  6365. } else {
  6366. if len(keyword) > 0 {
  6367. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and is_settle = ? and advice_name like ?"
  6368. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  6369. } else {
  6370. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and is_settle = ?"
  6371. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6372. }
  6373. }
  6374. } else {
  6375. if len(execution_frequency) > 0 {
  6376. if len(keyword) > 0 {
  6377. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_frequency = ? and advice_name like ?"
  6378. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  6379. } else {
  6380. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_frequency = ?"
  6381. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  6382. }
  6383. } else {
  6384. if len(keyword) > 0 {
  6385. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and advice_name like ?"
  6386. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  6387. } else {
  6388. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  6389. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6390. }
  6391. }
  6392. }
  6393. }
  6394. }
  6395. }
  6396. }
  6397. db := readDb.Table("xt_schedule")
  6398. if scheduleType > 0 {
  6399. db = db.Where("schedule_type = ?", scheduleType)
  6400. }
  6401. if partitonType > 0 {
  6402. db = db.Where("partition_id = ?", partitonType)
  6403. }
  6404. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6405. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6406. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6407. }).
  6408. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6409. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6410. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6411. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6412. Preload("DoctorAdvices", adviceCondition...).
  6413. Where("status = 1 AND user_org_id = ?", orgID)
  6414. if scheduleDate != 0 {
  6415. db = db.Where("schedule_date = ?", scheduleDate)
  6416. }
  6417. err := db.Find(&vms).Error
  6418. return vms, err
  6419. }
  6420. 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) {
  6421. var vms []*MScheduleDoctorAdviceVM
  6422. adviceWhere := ""
  6423. adviceCondition := []interface{}{}
  6424. if adviceType == 0 {
  6425. if patientType == 0 {
  6426. if patient_id > 0 {
  6427. if execution_state > 0 {
  6428. if cost_type > 0 {
  6429. 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 = ?"
  6430. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6431. } else {
  6432. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  6433. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6434. }
  6435. } else {
  6436. if cost_type > 0 {
  6437. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and is_settle = ?"
  6438. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6439. } else {
  6440. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
  6441. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6442. }
  6443. }
  6444. } else {
  6445. if execution_state > 0 {
  6446. if cost_type > 0 {
  6447. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and is_settle = ?"
  6448. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6449. } else {
  6450. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ?"
  6451. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6452. }
  6453. } else {
  6454. if cost_type > 0 {
  6455. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ?"
  6456. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6457. } else {
  6458. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  6459. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6460. }
  6461. }
  6462. }
  6463. } else if patientType == 1 {
  6464. if patient_id > 0 {
  6465. if execution_state > 0 {
  6466. if cost_type > 0 {
  6467. 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 = ?"
  6468. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  6469. } else {
  6470. 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= ?"
  6471. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  6472. }
  6473. } else {
  6474. if cost_type > 0 {
  6475. 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=?"
  6476. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  6477. } else {
  6478. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
  6479. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  6480. }
  6481. }
  6482. } else {
  6483. if execution_state > 0 {
  6484. if cost_type > 0 {
  6485. 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=?"
  6486. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  6487. } else {
  6488. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  6489. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  6490. }
  6491. } else {
  6492. if cost_type > 0 {
  6493. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and is_settle=?"
  6494. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  6495. } else {
  6496. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  6497. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  6498. }
  6499. }
  6500. }
  6501. } else if patientType == 2 {
  6502. if patient_id > 0 {
  6503. if execution_state > 0 {
  6504. if cost_type > 0 {
  6505. 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=?"
  6506. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6507. } else {
  6508. 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 = ?"
  6509. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6510. }
  6511. } else {
  6512. if cost_type > 0 {
  6513. 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=?"
  6514. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6515. } else {
  6516. 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 = ?)"
  6517. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6518. }
  6519. }
  6520. } else {
  6521. if execution_state > 0 {
  6522. if cost_type > 0 {
  6523. 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=?"
  6524. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6525. } else {
  6526. 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 = ?"
  6527. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6528. }
  6529. } else {
  6530. if cost_type > 0 {
  6531. 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 = ?"
  6532. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6533. } else {
  6534. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  6535. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6536. }
  6537. }
  6538. }
  6539. }
  6540. } else if adviceType == 1 {
  6541. if patientType == 0 {
  6542. if patient_id > 0 {
  6543. if execution_state > 0 {
  6544. if cost_type > 0 {
  6545. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  6546. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6547. } else {
  6548. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ?"
  6549. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6550. }
  6551. } else {
  6552. if cost_type > 0 {
  6553. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? "
  6554. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6555. } else {
  6556. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
  6557. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6558. }
  6559. }
  6560. } else {
  6561. if execution_state > 0 {
  6562. if cost_type > 0 {
  6563. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ?"
  6564. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6565. } else {
  6566. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ?"
  6567. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6568. }
  6569. } else {
  6570. if cost_type > 0 {
  6571. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = ? "
  6572. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6573. } else {
  6574. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  6575. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6576. }
  6577. }
  6578. }
  6579. } else if patientType == 1 {
  6580. if patient_id > 0 {
  6581. if execution_state > 0 {
  6582. if cost_type > 0 {
  6583. 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 = ?"
  6584. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  6585. } else {
  6586. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  6587. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  6588. }
  6589. } else {
  6590. if cost_type > 0 {
  6591. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  6592. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  6593. } else {
  6594. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
  6595. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  6596. }
  6597. }
  6598. } else {
  6599. if execution_state > 0 {
  6600. if cost_type > 0 {
  6601. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=? and is_settle = ?"
  6602. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  6603. } else {
  6604. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?"
  6605. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  6606. }
  6607. } else {
  6608. if cost_type > 0 {
  6609. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? "
  6610. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  6611. } else {
  6612. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  6613. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  6614. }
  6615. }
  6616. }
  6617. } else if patientType == 2 {
  6618. if patient_id > 0 {
  6619. if execution_state > 0 {
  6620. if cost_type > 0 {
  6621. 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 = ?"
  6622. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6623. } else {
  6624. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  6625. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6626. }
  6627. } else {
  6628. if cost_type > 0 {
  6629. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  6630. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6631. } else {
  6632. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
  6633. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6634. }
  6635. }
  6636. } else {
  6637. if execution_state > 0 {
  6638. if cost_type > 0 {
  6639. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  6640. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6641. } else {
  6642. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ?"
  6643. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6644. }
  6645. } else {
  6646. if cost_type > 0 {
  6647. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ?"
  6648. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6649. } else {
  6650. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  6651. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6652. }
  6653. }
  6654. }
  6655. }
  6656. } else if adviceType == 3 {
  6657. if patientType == 0 {
  6658. if patient_id > 0 {
  6659. if execution_state > 0 {
  6660. if cost_type > 0 {
  6661. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  6662. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6663. } else {
  6664. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ?"
  6665. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6666. }
  6667. } else {
  6668. if cost_type > 0 {
  6669. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? "
  6670. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6671. } else {
  6672. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? "
  6673. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6674. }
  6675. }
  6676. } else {
  6677. if execution_state > 0 {
  6678. if cost_type > 0 {
  6679. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ?"
  6680. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6681. } else {
  6682. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? "
  6683. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6684. }
  6685. } else {
  6686. if cost_type > 0 {
  6687. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? "
  6688. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6689. } else {
  6690. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  6691. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6692. }
  6693. }
  6694. }
  6695. } else if patientType == 1 {
  6696. if patient_id > 0 {
  6697. if execution_state > 0 {
  6698. if cost_type > 0 {
  6699. 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 = ?"
  6700. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  6701. } else {
  6702. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  6703. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  6704. }
  6705. } else {
  6706. if cost_type > 0 {
  6707. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  6708. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  6709. } else {
  6710. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
  6711. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  6712. }
  6713. }
  6714. } else {
  6715. if execution_state > 0 {
  6716. if cost_type > 0 {
  6717. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? and is_settle = ?"
  6718. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  6719. } else {
  6720. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? "
  6721. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  6722. }
  6723. } else {
  6724. if cost_type > 0 {
  6725. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ?"
  6726. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  6727. } else {
  6728. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  6729. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  6730. }
  6731. }
  6732. }
  6733. } else if patientType == 2 {
  6734. if patient_id > 0 {
  6735. if execution_state > 0 {
  6736. if cost_type > 0 {
  6737. 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 = ?"
  6738. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6739. } else {
  6740. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  6741. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6742. }
  6743. } else {
  6744. if cost_type > 0 {
  6745. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  6746. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6747. } else {
  6748. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ?"
  6749. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6750. }
  6751. }
  6752. } else {
  6753. if execution_state > 0 {
  6754. if cost_type > 0 {
  6755. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and is_settle = ?"
  6756. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6757. } else {
  6758. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ?"
  6759. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6760. }
  6761. } else {
  6762. if cost_type > 0 {
  6763. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ?"
  6764. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6765. } else {
  6766. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  6767. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6768. }
  6769. }
  6770. }
  6771. }
  6772. } else if adviceType == 2 && len(deliverWay) > 0 {
  6773. if patientType == 0 {
  6774. if patient_id > 0 {
  6775. if execution_state > 0 {
  6776. if cost_type > 0 {
  6777. 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 = ?"
  6778. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  6779. } else {
  6780. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  6781. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  6782. }
  6783. } else {
  6784. if cost_type > 0 {
  6785. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and is_settle = ?"
  6786. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  6787. } else {
  6788. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ?"
  6789. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  6790. }
  6791. }
  6792. } else {
  6793. if execution_state > 0 {
  6794. if cost_type > 0 {
  6795. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and is_settle = ?"
  6796. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  6797. } else {
  6798. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ?"
  6799. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  6800. }
  6801. } else {
  6802. if cost_type > 0 {
  6803. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and is_settle = ?"
  6804. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  6805. } else {
  6806. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  6807. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  6808. }
  6809. }
  6810. }
  6811. } else if patientType == 1 {
  6812. if patient_id > 0 {
  6813. if execution_state > 0 {
  6814. if cost_type > 0 {
  6815. 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 = ?"
  6816. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type)
  6817. } else {
  6818. 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 = ?"
  6819. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state)
  6820. }
  6821. } else {
  6822. if cost_type > 0 {
  6823. 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 = ?"
  6824. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type)
  6825. } else {
  6826. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ?"
  6827. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
  6828. }
  6829. }
  6830. } else {
  6831. if execution_state > 0 {
  6832. if cost_type > 0 {
  6833. 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 = ?"
  6834. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type)
  6835. } else {
  6836. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ?"
  6837. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state)
  6838. }
  6839. } else {
  6840. if cost_type > 0 {
  6841. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and is_settle = ?"
  6842. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type)
  6843. } else {
  6844. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  6845. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  6846. }
  6847. }
  6848. }
  6849. } else if patientType == 2 {
  6850. if patient_id > 0 {
  6851. if execution_state > 0 {
  6852. if cost_type > 0 {
  6853. 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 = ?"
  6854. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  6855. } else {
  6856. 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 = ?"
  6857. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  6858. }
  6859. } else {
  6860. if cost_type > 0 {
  6861. 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 = ?"
  6862. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  6863. } else {
  6864. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ?"
  6865. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  6866. }
  6867. }
  6868. } else {
  6869. if execution_state > 0 {
  6870. if cost_type > 0 {
  6871. 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 = ?"
  6872. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  6873. } else {
  6874. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ?"
  6875. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  6876. }
  6877. } else {
  6878. if cost_type > 0 {
  6879. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and is_settle = ?"
  6880. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  6881. } else {
  6882. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  6883. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  6884. }
  6885. }
  6886. }
  6887. }
  6888. } else if adviceType == 2 && len(deliverWay) <= 0 {
  6889. if patientType == 0 {
  6890. if patient_id > 0 {
  6891. if execution_state > 0 {
  6892. if cost_type > 0 {
  6893. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  6894. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6895. } else {
  6896. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ?"
  6897. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6898. }
  6899. } else {
  6900. if cost_type > 0 {
  6901. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and is_settle = ?"
  6902. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6903. } else {
  6904. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ?"
  6905. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6906. }
  6907. }
  6908. } else {
  6909. if execution_state > 0 {
  6910. if cost_type > 0 {
  6911. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ? and is_settle = ?"
  6912. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6913. } else {
  6914. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?"
  6915. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6916. }
  6917. } else {
  6918. if cost_type > 0 {
  6919. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and is_settle = ?"
  6920. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6921. } else {
  6922. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  6923. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6924. }
  6925. }
  6926. }
  6927. } else if patientType == 1 {
  6928. if patient_id > 0 {
  6929. if execution_state > 0 {
  6930. if cost_type > 0 {
  6931. 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 = ?"
  6932. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  6933. } else {
  6934. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  6935. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  6936. }
  6937. } else {
  6938. if cost_type > 0 {
  6939. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  6940. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  6941. } else {
  6942. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ?"
  6943. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  6944. }
  6945. }
  6946. } else {
  6947. if execution_state > 0 {
  6948. if cost_type > 0 {
  6949. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ? and is_settle = ?"
  6950. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  6951. } else {
  6952. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ?"
  6953. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  6954. }
  6955. } else {
  6956. if cost_type > 0 {
  6957. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and is_settle = ?"
  6958. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  6959. } else {
  6960. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?"
  6961. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  6962. }
  6963. }
  6964. }
  6965. } else if patientType == 2 {
  6966. if patient_id > 0 {
  6967. if execution_state > 0 {
  6968. if cost_type > 0 {
  6969. 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 = ?"
  6970. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6971. } else {
  6972. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  6973. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6974. }
  6975. } else {
  6976. if cost_type > 0 {
  6977. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  6978. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6979. } else {
  6980. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ?"
  6981. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6982. }
  6983. }
  6984. } else {
  6985. if execution_state > 0 {
  6986. if cost_type > 0 {
  6987. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  6988. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6989. } else {
  6990. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ?"
  6991. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6992. }
  6993. } else {
  6994. if cost_type > 0 {
  6995. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and is_settle = ?"
  6996. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6997. } else {
  6998. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  6999. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  7000. }
  7001. }
  7002. }
  7003. }
  7004. }
  7005. db := readDb.Table("xt_schedule")
  7006. if scheduleType > 0 {
  7007. db = db.Where("schedule_type = ?", scheduleType)
  7008. }
  7009. if partitonType > 0 {
  7010. db = db.Where("partition_id = ?", partitonType)
  7011. }
  7012. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7013. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7014. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7015. }).
  7016. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7017. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7018. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7019. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7020. Preload("DoctorAdvices", adviceCondition...).
  7021. Where("status = 1 AND user_org_id = ?", orgID)
  7022. if scheduleDate != 0 {
  7023. db = db.Where("schedule_date = ?", scheduleDate)
  7024. }
  7025. err := db.Find(&vms).Error
  7026. return vms, err
  7027. }
  7028. func GetLastPatientOrder(id int64) (models.XtDialysisOrder, error) {
  7029. order := models.XtDialysisOrder{}
  7030. err := XTReadDB().Where("id = ? and status = 1", id).Find(&order).Error
  7031. return order, err
  7032. }
  7033. func UpdateMobilePatient(org_id int64, patient_id int64, schedule_remark string) error {
  7034. order := models.XtPatients{}
  7035. 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
  7036. 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
  7037. return err
  7038. }
  7039. func GetDialysisTotalCount(org_id int64, patient_id int64) (models.BloodDialysisOrderCount, error) {
  7040. order := models.BloodDialysisOrderCount{}
  7041. db := XTReadDB().Table("xt_dialysis_order as o")
  7042. 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
  7043. return order, err
  7044. }
  7045. func GetDialysisTotalCountOne(org_id int64, patient_id int64) (models.BloodDialysisOrderCount, error) {
  7046. order := models.BloodDialysisOrderCount{}
  7047. db := XTReadDB().Table("xt_dialysis_order as o")
  7048. 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>=1704038400 and x.schedule_date = o.dialysis_date and x.status = 1 ", org_id, patient_id).Scan(&order).Error
  7049. return order, err
  7050. }
  7051. func UpdateDialysisOrder(patient_id int64, dialysis_date int64, user_org_id int64, dialysis_total int64) (models.DialysisOrder, error) {
  7052. order := models.DialysisOrder{}
  7053. 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
  7054. return order, err
  7055. }
  7056. func UpdateDeviceInformation(patientid int64, dialysis_date int64) error {
  7057. information := models.DeviceInformation{}
  7058. err := UserWriteDB().Model(&information).Where("patient_id = ? and date = ? and status = 1", patientid, dialysis_date).Update(map[string]interface{}{"status": 0}).Error
  7059. return err
  7060. }
  7061. func MobileGetDoubleCheckSix(orgID int64, patientID int64, recordDate int64) (models.DoubleCheck, error) {
  7062. var record models.DoubleCheck
  7063. err := readDb.Where("patient_id = ? and user_org_id = ? and status = 1 and check_date = ?", patientID, orgID, recordDate).First(&record).Error
  7064. return record, err
  7065. }
  7066. func GetFirstMonitor(patient_id int64, monit_date int64) (models.MonitoringRecord, error) {
  7067. record := models.MonitoringRecord{}
  7068. err := XTReadDB().Where("patient_id = ? and monitoring_date = ? and status=1", patient_id, monit_date).First(&record).Error
  7069. return record, err
  7070. }
  7071. func UpdateFirstMonitor(id int64, catheter_operation string) (models.MonitoringRecord, error) {
  7072. record := models.MonitoringRecord{}
  7073. err := XTWriteDB().Model(&record).Where("id = ? and status= 1", id).Updates(map[string]interface{}{"dispose": catheter_operation}).Error
  7074. return record, err
  7075. }
  7076. 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) {
  7077. var vms []*HisMScheduleDoctorAdviceVM
  7078. if len(deliverWay) > 0 {
  7079. db := readDb.Table("xt_schedule")
  7080. if scheduleType > 0 {
  7081. db = db.Where("schedule_type = ?", scheduleType)
  7082. }
  7083. if partitionType > 0 {
  7084. db = db.Where("partition_id = ?", partitionType)
  7085. }
  7086. if patient_id > 0 {
  7087. if execution_state > 0 {
  7088. if cost_type > 0 {
  7089. if len(execution_frequency) > 0 {
  7090. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7091. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7092. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7093. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7094. 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).
  7095. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7096. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7097. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7098. Where("status = 1 AND user_org_id = ?", orgID)
  7099. if scheduleDate != 0 {
  7100. db = db.Where("schedule_date = ?", scheduleDate)
  7101. }
  7102. err = db.Find(&vms).Error
  7103. } else {
  7104. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7105. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7106. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7107. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7108. 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).
  7109. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7110. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7111. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7112. Where("status = 1 AND user_org_id = ?", orgID)
  7113. if scheduleDate != 0 {
  7114. db = db.Where("schedule_date = ?", scheduleDate)
  7115. }
  7116. err = db.Find(&vms).Error
  7117. }
  7118. } else {
  7119. if len(execution_frequency) > 0 {
  7120. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7121. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7122. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7123. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7124. 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).
  7125. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7126. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7127. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7128. Where("status = 1 AND user_org_id = ?", orgID)
  7129. if scheduleDate != 0 {
  7130. db = db.Where("schedule_date = ?", scheduleDate)
  7131. }
  7132. err = db.Find(&vms).Error
  7133. } else {
  7134. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7135. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7136. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7137. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7138. 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).
  7139. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7140. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7141. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7142. Where("status = 1 AND user_org_id = ?", orgID)
  7143. if scheduleDate != 0 {
  7144. db = db.Where("schedule_date = ?", scheduleDate)
  7145. }
  7146. err = db.Find(&vms).Error
  7147. }
  7148. }
  7149. } else {
  7150. if cost_type > 0 {
  7151. if len(execution_frequency) > 0 {
  7152. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7153. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7154. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7155. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7156. 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).
  7157. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7158. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7159. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7160. Where("status = 1 AND user_org_id = ?", orgID)
  7161. if scheduleDate != 0 {
  7162. db = db.Where("schedule_date = ?", scheduleDate)
  7163. }
  7164. err = db.Find(&vms).Error
  7165. } else {
  7166. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7167. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7168. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7169. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7170. 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).
  7171. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7172. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7173. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7174. Where("status = 1 AND user_org_id = ?", orgID)
  7175. if scheduleDate != 0 {
  7176. db = db.Where("schedule_date = ?", scheduleDate)
  7177. }
  7178. err = db.Find(&vms).Error
  7179. }
  7180. } else {
  7181. if len(execution_frequency) > 0 {
  7182. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7183. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7184. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7185. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7186. 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).
  7187. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7188. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7189. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7190. Where("status = 1 AND user_org_id = ?", orgID)
  7191. if scheduleDate != 0 {
  7192. db = db.Where("schedule_date = ?", scheduleDate)
  7193. }
  7194. err = db.Find(&vms).Error
  7195. } else {
  7196. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7197. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7198. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7199. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7200. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ?", orgID, scheduleDate, deliverWay, patient_id).
  7201. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7202. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7203. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7204. Where("status = 1 AND user_org_id = ?", orgID)
  7205. if scheduleDate != 0 {
  7206. db = db.Where("schedule_date = ?", scheduleDate)
  7207. }
  7208. err = db.Find(&vms).Error
  7209. }
  7210. }
  7211. }
  7212. } else {
  7213. if execution_state > 0 {
  7214. if cost_type > 0 {
  7215. if len(execution_frequency) > 0 {
  7216. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7217. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7218. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7219. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7220. 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).
  7221. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7222. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7223. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7224. Where("status = 1 AND user_org_id = ?", orgID)
  7225. if scheduleDate != 0 {
  7226. db = db.Where("schedule_date = ?", scheduleDate)
  7227. }
  7228. err = db.Find(&vms).Error
  7229. } else {
  7230. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7231. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7232. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7233. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7234. 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).
  7235. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7236. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7237. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7238. Where("status = 1 AND user_org_id = ?", orgID)
  7239. if scheduleDate != 0 {
  7240. db = db.Where("schedule_date = ?", scheduleDate)
  7241. }
  7242. err = db.Find(&vms).Error
  7243. }
  7244. } else {
  7245. if len(execution_frequency) > 0 {
  7246. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7247. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7248. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7249. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7250. 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).
  7251. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7252. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7253. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7254. Where("status = 1 AND user_org_id = ?", orgID)
  7255. if scheduleDate != 0 {
  7256. db = db.Where("schedule_date = ?", scheduleDate)
  7257. }
  7258. err = db.Find(&vms).Error
  7259. } else {
  7260. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7261. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7262. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7263. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7264. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_state = ?", orgID, scheduleDate, deliverWay, execution_state).
  7265. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7266. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7267. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7268. Where("status = 1 AND user_org_id = ?", orgID)
  7269. if scheduleDate != 0 {
  7270. db = db.Where("schedule_date = ?", scheduleDate)
  7271. }
  7272. err = db.Find(&vms).Error
  7273. }
  7274. }
  7275. } else {
  7276. if cost_type > 0 {
  7277. if len(execution_frequency) > 0 {
  7278. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7279. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7280. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7281. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7282. 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).
  7283. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7284. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7285. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7286. Where("status = 1 AND user_org_id = ?", orgID)
  7287. if scheduleDate != 0 {
  7288. db = db.Where("schedule_date = ?", scheduleDate)
  7289. }
  7290. err = db.Find(&vms).Error
  7291. } else {
  7292. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7293. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7294. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7295. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7296. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and is_settle = ?", orgID, scheduleDate, deliverWay, cost_type).
  7297. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7298. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7299. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7300. Where("status = 1 AND user_org_id = ?", orgID)
  7301. if scheduleDate != 0 {
  7302. db = db.Where("schedule_date = ?", scheduleDate)
  7303. }
  7304. err = db.Find(&vms).Error
  7305. }
  7306. } else {
  7307. if len(execution_frequency) > 0 {
  7308. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7309. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7310. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7311. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7312. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_frequency = ?", orgID, scheduleDate, deliverWay, execution_frequency).
  7313. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7314. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7315. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7316. Where("status = 1 AND user_org_id = ?", orgID)
  7317. if scheduleDate != 0 {
  7318. db = db.Where("schedule_date = ?", scheduleDate)
  7319. }
  7320. err = db.Find(&vms).Error
  7321. } else {
  7322. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7323. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7324. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7325. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7326. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  7327. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7328. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7329. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7330. Where("status = 1 AND user_org_id = ?", orgID)
  7331. if scheduleDate != 0 {
  7332. db = db.Where("schedule_date = ?", scheduleDate)
  7333. }
  7334. err = db.Find(&vms).Error
  7335. }
  7336. }
  7337. }
  7338. }
  7339. } else {
  7340. db := readDb.Table("xt_schedule")
  7341. if scheduleType > 0 {
  7342. db = db.Where("schedule_type = ?", scheduleType)
  7343. }
  7344. if partitionType > 0 {
  7345. db = db.Where("partition_id = ?", partitionType)
  7346. }
  7347. if patient_id > 0 {
  7348. if execution_state > 0 {
  7349. fmt.Println("execution_state---------------------", execution_state)
  7350. if cost_type > 0 {
  7351. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7352. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7353. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7354. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7355. 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).
  7356. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7357. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7358. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7359. Where("status = 1 AND user_org_id = ?", orgID)
  7360. if scheduleDate != 0 {
  7361. db = db.Where("schedule_date = ?", scheduleDate)
  7362. }
  7363. err = db.Find(&vms).Error
  7364. } else {
  7365. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7366. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7367. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7368. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7369. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and execution_state = ?", orgID, scheduleDate, patient_id, execution_state).
  7370. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7371. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7372. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7373. Where("status = 1 AND user_org_id = ?", orgID)
  7374. if scheduleDate != 0 {
  7375. db = db.Where("schedule_date = ?", scheduleDate)
  7376. }
  7377. err = db.Find(&vms).Error
  7378. }
  7379. } else {
  7380. if cost_type > 0 {
  7381. if len(execution_frequency) > 0 {
  7382. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7383. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7384. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7385. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7386. 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).
  7387. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7388. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7389. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7390. Where("status = 1 AND user_org_id = ?", orgID)
  7391. if scheduleDate != 0 {
  7392. db = db.Where("schedule_date = ?", scheduleDate)
  7393. }
  7394. err = db.Find(&vms).Error
  7395. } else {
  7396. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7397. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7398. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7399. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7400. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and is_settle = ?", orgID, scheduleDate, patient_id, cost_type).
  7401. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7402. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7403. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7404. Where("status = 1 AND user_org_id = ?", orgID)
  7405. if scheduleDate != 0 {
  7406. db = db.Where("schedule_date = ?", scheduleDate)
  7407. }
  7408. err = db.Find(&vms).Error
  7409. }
  7410. } else {
  7411. if len(execution_frequency) > 0 {
  7412. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7413. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7414. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7415. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7416. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and execution_frequency = ?", orgID, scheduleDate, patient_id, execution_frequency).
  7417. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7418. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7419. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7420. Where("status = 1 AND user_org_id = ?", orgID)
  7421. if scheduleDate != 0 {
  7422. db = db.Where("schedule_date = ?", scheduleDate)
  7423. }
  7424. err = db.Find(&vms).Error
  7425. } else {
  7426. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7427. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7428. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7429. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7430. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7431. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7432. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7433. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7434. Where("status = 1 AND user_org_id = ?", orgID)
  7435. if scheduleDate != 0 {
  7436. db = db.Where("schedule_date = ?", scheduleDate)
  7437. }
  7438. err = db.Find(&vms).Error
  7439. }
  7440. }
  7441. }
  7442. } else {
  7443. if execution_state > 0 {
  7444. if cost_type > 0 {
  7445. if len(execution_frequency) > 0 {
  7446. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7447. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7448. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7449. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7450. 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).
  7451. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7452. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7453. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7454. Where("status = 1 AND user_org_id = ?", orgID)
  7455. if scheduleDate != 0 {
  7456. db = db.Where("schedule_date = ?", scheduleDate)
  7457. }
  7458. err = db.Find(&vms).Error
  7459. } else {
  7460. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7461. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7462. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7463. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7464. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ? and is_settle = ?", orgID, scheduleDate, execution_state, cost_type).
  7465. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7466. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7467. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7468. Where("status = 1 AND user_org_id = ?", orgID)
  7469. if scheduleDate != 0 {
  7470. db = db.Where("schedule_date = ?", scheduleDate)
  7471. }
  7472. err = db.Find(&vms).Error
  7473. }
  7474. } else {
  7475. if len(execution_frequency) > 0 {
  7476. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7477. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7478. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7479. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7480. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ? and execution_frequency = ?", orgID, scheduleDate, execution_state, execution_frequency).
  7481. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7482. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7483. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7484. Where("status = 1 AND user_org_id = ?", orgID)
  7485. if scheduleDate != 0 {
  7486. db = db.Where("schedule_date = ?", scheduleDate)
  7487. }
  7488. err = db.Find(&vms).Error
  7489. } else {
  7490. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7491. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7492. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7493. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7494. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ?", orgID, scheduleDate, execution_state).
  7495. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7496. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7497. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7498. Where("status = 1 AND user_org_id = ?", orgID)
  7499. if scheduleDate != 0 {
  7500. db = db.Where("schedule_date = ?", scheduleDate)
  7501. }
  7502. err = db.Find(&vms).Error
  7503. }
  7504. }
  7505. } else {
  7506. if cost_type > 0 {
  7507. if len(execution_frequency) > 0 {
  7508. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7509. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7510. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7511. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7512. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and is_settle = ?", orgID, scheduleDate, cost_type).
  7513. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7514. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7515. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7516. Where("status = 1 AND user_org_id = ?", orgID)
  7517. if scheduleDate != 0 {
  7518. db = db.Where("schedule_date = ?", scheduleDate)
  7519. }
  7520. err = db.Find(&vms).Error
  7521. } else {
  7522. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7523. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7524. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7525. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7526. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and is_settle = ? and execution_frequency = ?", orgID, scheduleDate, cost_type, execution_frequency).
  7527. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7528. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7529. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7530. Where("status = 1 AND user_org_id = ?", orgID)
  7531. if scheduleDate != 0 {
  7532. db = db.Where("schedule_date = ?", scheduleDate)
  7533. }
  7534. err = db.Find(&vms).Error
  7535. }
  7536. } else {
  7537. if len(execution_frequency) > 0 {
  7538. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7539. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7540. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7541. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7542. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_frequency = ?", orgID, scheduleDate, execution_frequency).
  7543. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7544. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7545. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7546. Where("status = 1 AND user_org_id = ?", orgID)
  7547. if scheduleDate != 0 {
  7548. db = db.Where("schedule_date = ?", scheduleDate)
  7549. }
  7550. err = db.Find(&vms).Error
  7551. } else {
  7552. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7553. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7554. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7555. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7556. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ?", orgID, scheduleDate).
  7557. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7558. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7559. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7560. Where("status = 1 AND user_org_id = ?", orgID)
  7561. if scheduleDate != 0 {
  7562. db = db.Where("schedule_date = ?", scheduleDate)
  7563. }
  7564. err = db.Find(&vms).Error
  7565. }
  7566. }
  7567. }
  7568. }
  7569. }
  7570. return vms, err
  7571. }
  7572. func GetPatientDryWeight(org_id int64, patient_id int64) (weight []*models.SgjPatientDryweight, err error) {
  7573. err = XTReadDB().Where("user_org_id = ? and patient_id = ? and status =1", org_id, patient_id).Order("id desc").Limit(6).Find(&weight).Error
  7574. return weight, err
  7575. }
  7576. 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, keyword string) ([]*MScheduleDoctorAdviceVM, error) {
  7577. fmt.Println("deliverWay-----------------", deliverWay)
  7578. fmt.Println("execution_frequency------------------", execution_frequency)
  7579. fmt.Println("adviceType-----------------", adviceType)
  7580. fmt.Println("patientType----------------", patientType)
  7581. fmt.Println("patient_id----------------", patient_id)
  7582. fmt.Println("execution_state----------------", execution_state)
  7583. fmt.Println("cost_type---------------------", cost_type)
  7584. fmt.Println("execution_frequency", execution_frequency)
  7585. var vms []*MScheduleDoctorAdviceVM
  7586. adviceWhere := ""
  7587. keyword = "%" + keyword + "%"
  7588. adviceCondition := []interface{}{}
  7589. if adviceType == 1 {
  7590. if patientType == 0 {
  7591. if patient_id > 0 {
  7592. if execution_state > 0 {
  7593. if cost_type > 0 {
  7594. if len(execution_frequency) > 0 {
  7595. if len(keyword) > 0 {
  7596. if len(deliverWay) > 0 {
  7597. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and delivery_way = ? and advice_name like ?"
  7598. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency, deliverWay, keyword)
  7599. } else {
  7600. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  7601. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency, keyword)
  7602. }
  7603. } else {
  7604. if len(deliverWay) > 0 {
  7605. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and delivery_way =?"
  7606. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency, deliverWay)
  7607. } else {
  7608. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  7609. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency)
  7610. }
  7611. }
  7612. } else {
  7613. if len(keyword) > 0 {
  7614. if len(deliverWay) > 0 {
  7615. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ? and delivery_way =?"
  7616. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, keyword, deliverWay)
  7617. } else {
  7618. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  7619. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, keyword)
  7620. }
  7621. } else {
  7622. if len(deliverWay) > 0 {
  7623. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ? and delivery_way =?"
  7624. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, deliverWay)
  7625. } else {
  7626. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ?"
  7627. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type)
  7628. }
  7629. }
  7630. }
  7631. } else {
  7632. if len(execution_frequency) > 0 {
  7633. if len(keyword) > 0 {
  7634. if len(deliverWay) > 0 {
  7635. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  7636. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency, keyword, deliverWay)
  7637. } else {
  7638. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  7639. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency, keyword)
  7640. }
  7641. } else {
  7642. if len(deliverWay) > 0 {
  7643. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and execution_frequency = ? and delivery_way =?"
  7644. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency, deliverWay)
  7645. } else {
  7646. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and execution_frequency = ?"
  7647. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency)
  7648. }
  7649. }
  7650. } else {
  7651. if len(keyword) > 0 {
  7652. if len(deliverWay) > 0 {
  7653. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and advice_name like ? and delivery_way =?"
  7654. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, keyword, deliverWay)
  7655. } else {
  7656. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and advice_name like ?"
  7657. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, keyword)
  7658. }
  7659. } else {
  7660. if len(deliverWay) > 0 {
  7661. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and delivery_way =?"
  7662. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, deliverWay)
  7663. } else {
  7664. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ?"
  7665. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state)
  7666. }
  7667. }
  7668. }
  7669. }
  7670. } else {
  7671. if cost_type > 0 {
  7672. if len(execution_frequency) > 0 {
  7673. if len(keyword) > 0 {
  7674. if len(deliverWay) > 0 {
  7675. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  7676. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency, keyword, deliverWay)
  7677. } else {
  7678. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  7679. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency, keyword)
  7680. }
  7681. } else {
  7682. if len(deliverWay) > 0 {
  7683. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and execution_frequency = ? and delivery_way =?"
  7684. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency, deliverWay)
  7685. } else {
  7686. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and execution_frequency = ?"
  7687. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency)
  7688. }
  7689. }
  7690. } else {
  7691. if len(keyword) > 0 {
  7692. if len(deliverWay) > 0 {
  7693. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and advice_name like ? and delivery_way =?"
  7694. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, keyword, deliverWay)
  7695. } else {
  7696. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and advice_name like ?"
  7697. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, keyword)
  7698. }
  7699. } else {
  7700. if len(deliverWay) > 0 {
  7701. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and delivery_way =?"
  7702. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, deliverWay)
  7703. } else {
  7704. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? "
  7705. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type)
  7706. }
  7707. }
  7708. }
  7709. } else {
  7710. if len(execution_frequency) > 0 {
  7711. if len(keyword) > 0 {
  7712. if len(deliverWay) > 0 {
  7713. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  7714. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency, keyword, deliverWay)
  7715. } else {
  7716. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_frequency = ? and advice_name like ?"
  7717. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency, keyword)
  7718. }
  7719. } else {
  7720. if len(deliverWay) > 0 {
  7721. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_frequency = ? and delivery_way =?"
  7722. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency, deliverWay)
  7723. } else {
  7724. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_frequency = ?"
  7725. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency)
  7726. }
  7727. }
  7728. } else {
  7729. if len(keyword) > 0 {
  7730. if len(deliverWay) > 0 {
  7731. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and advice_name like ? and delivery_way =?"
  7732. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, keyword, deliverWay)
  7733. } else {
  7734. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and advice_name like ?"
  7735. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, keyword)
  7736. }
  7737. } else {
  7738. if len(deliverWay) > 0 {
  7739. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and delivery_way =?"
  7740. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, deliverWay)
  7741. } else {
  7742. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? "
  7743. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id)
  7744. }
  7745. }
  7746. }
  7747. }
  7748. }
  7749. } else {
  7750. if execution_state > 0 {
  7751. if cost_type > 0 {
  7752. if len(execution_frequency) > 0 {
  7753. if len(keyword) > 0 {
  7754. if len(deliverWay) > 0 {
  7755. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  7756. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency, keyword, deliverWay)
  7757. } else {
  7758. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  7759. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency, keyword)
  7760. }
  7761. } else {
  7762. if len(deliverWay) > 0 {
  7763. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and execution_frequency = ? and delivery_way =?"
  7764. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency, deliverWay)
  7765. } else {
  7766. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and execution_frequency = ?"
  7767. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency)
  7768. }
  7769. }
  7770. } else {
  7771. if len(keyword) > 0 {
  7772. if len(deliverWay) > 0 {
  7773. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and advice_name like ? and delivery_way =?"
  7774. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, keyword, deliverWay)
  7775. } else {
  7776. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and advice_name like ?"
  7777. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, keyword)
  7778. }
  7779. } else {
  7780. if len(deliverWay) > 0 {
  7781. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and delivery_way =?"
  7782. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, deliverWay)
  7783. } else {
  7784. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ?"
  7785. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type)
  7786. }
  7787. }
  7788. }
  7789. } else {
  7790. if len(execution_frequency) > 0 {
  7791. if len(keyword) > 0 {
  7792. if len(deliverWay) > 0 {
  7793. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  7794. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency, keyword, deliverWay)
  7795. } else {
  7796. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and execution_frequency = ? and advice_name like ?"
  7797. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency, keyword)
  7798. }
  7799. } else {
  7800. if len(deliverWay) > 0 {
  7801. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and execution_frequency = ? and delivery_way =?"
  7802. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency, deliverWay)
  7803. } else {
  7804. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and execution_frequency = ?"
  7805. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency)
  7806. }
  7807. }
  7808. } else {
  7809. if len(keyword) > 0 {
  7810. if len(deliverWay) > 0 {
  7811. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and advice_name like ? and delivery_way =?"
  7812. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, keyword, deliverWay)
  7813. } else {
  7814. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and advice_name like ?"
  7815. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, keyword)
  7816. }
  7817. } else {
  7818. if len(deliverWay) > 0 {
  7819. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and delivery_way =?"
  7820. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, deliverWay)
  7821. } else {
  7822. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ?"
  7823. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state)
  7824. }
  7825. }
  7826. }
  7827. }
  7828. } else {
  7829. if cost_type > 0 {
  7830. if len(keyword) > 0 {
  7831. if len(deliverWay) > 0 {
  7832. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and is_settle = ? and advice_name like ? and delivery_way =?"
  7833. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, keyword, deliverWay)
  7834. } else {
  7835. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and is_settle = ? and advice_name like ?"
  7836. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, keyword)
  7837. }
  7838. } else {
  7839. if len(deliverWay) > 0 {
  7840. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and is_settle = ? and delivery_way =?"
  7841. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, deliverWay)
  7842. } else {
  7843. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and is_settle = ? "
  7844. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type)
  7845. }
  7846. }
  7847. } else {
  7848. if len(keyword) > 0 {
  7849. if len(deliverWay) > 0 {
  7850. if len(execution_frequency) > 0 {
  7851. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and advice_name like ? and delivery_way =? and execution_frequency =? "
  7852. adviceCondition = append(adviceCondition, adviceWhere, orgID, keyword, deliverWay, execution_frequency)
  7853. } else {
  7854. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and advice_name like ? and delivery_way =?"
  7855. adviceCondition = append(adviceCondition, adviceWhere, orgID, keyword, deliverWay)
  7856. }
  7857. } else {
  7858. if len(execution_frequency) > 0 {
  7859. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and advice_name like ? and execution_frequency =?"
  7860. adviceCondition = append(adviceCondition, adviceWhere, orgID, keyword, execution_frequency)
  7861. } else {
  7862. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and advice_name like ?"
  7863. adviceCondition = append(adviceCondition, adviceWhere, orgID, keyword)
  7864. }
  7865. }
  7866. } else {
  7867. if len(deliverWay) > 0 {
  7868. if len(execution_frequency) > 0 {
  7869. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and delivery_way =? and execution_frequency =?"
  7870. adviceCondition = append(adviceCondition, adviceWhere, orgID, deliverWay, execution_frequency)
  7871. } else {
  7872. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and delivery_way =?"
  7873. adviceCondition = append(adviceCondition, adviceWhere, orgID, deliverWay)
  7874. }
  7875. } else {
  7876. if len(execution_frequency) > 0 {
  7877. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_frequency =?"
  7878. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_frequency)
  7879. } else {
  7880. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 "
  7881. adviceCondition = append(adviceCondition, adviceWhere, orgID)
  7882. }
  7883. }
  7884. }
  7885. }
  7886. }
  7887. }
  7888. } else if patientType == 1 {
  7889. if patient_id > 0 {
  7890. if execution_state > 0 {
  7891. if cost_type > 0 {
  7892. if len(execution_frequency) > 0 {
  7893. if len(keyword) > 0 {
  7894. if len(deliverWay) > 0 {
  7895. 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 = ? and advice_name like ? and delivery_way =?"
  7896. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword, deliverWay)
  7897. } else {
  7898. 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 = ? and advice_name like ?"
  7899. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  7900. }
  7901. } else {
  7902. if len(keyword) > 0 {
  7903. if len(deliverWay) > 0 {
  7904. 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 = ? and delivery_way =?"
  7905. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, execution_frequency, deliverWay)
  7906. }
  7907. } else {
  7908. if len(deliverWay) > 0 {
  7909. 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 = ? and delivery_way =?"
  7910. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, execution_frequency, deliverWay)
  7911. } else {
  7912. 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 = ?"
  7913. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  7914. }
  7915. }
  7916. }
  7917. } else {
  7918. if len(keyword) > 0 {
  7919. if len(deliverWay) > 0 {
  7920. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ? and delivery_way =?"
  7921. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, keyword, deliverWay)
  7922. } else {
  7923. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  7924. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, keyword)
  7925. }
  7926. } else {
  7927. if len(deliverWay) > 0 {
  7928. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and delivery_way =?"
  7929. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, deliverWay)
  7930. } else {
  7931. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  7932. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type)
  7933. }
  7934. }
  7935. }
  7936. } else {
  7937. if len(execution_frequency) > 0 {
  7938. if len(keyword) > 0 {
  7939. if len(deliverWay) > 0 {
  7940. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  7941. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, execution_frequency, keyword, deliverWay)
  7942. } else {
  7943. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  7944. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  7945. }
  7946. } else {
  7947. if len(deliverWay) > 0 {
  7948. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and delivery_way =?"
  7949. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, execution_frequency, deliverWay)
  7950. } else {
  7951. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  7952. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, execution_frequency)
  7953. }
  7954. }
  7955. } else {
  7956. if len(keyword) > 0 {
  7957. if len(deliverWay) > 0 {
  7958. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and advice_name like ? and delivery_way =?"
  7959. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, keyword, deliverWay)
  7960. } else {
  7961. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  7962. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, keyword)
  7963. }
  7964. } else {
  7965. if len(deliverWay) > 0 {
  7966. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and delivery_way =?"
  7967. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, deliverWay)
  7968. } else {
  7969. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  7970. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state)
  7971. }
  7972. }
  7973. }
  7974. }
  7975. } else {
  7976. if cost_type > 0 {
  7977. if len(execution_frequency) > 0 {
  7978. if len(keyword) > 0 {
  7979. if len(deliverWay) > 0 {
  7980. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ?and execution_frequency = ? and advice_name like ? and delivery_way =?"
  7981. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, execution_frequency, keyword, deliverWay)
  7982. } else {
  7983. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ?and execution_frequency = ? and advice_name like ?"
  7984. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  7985. }
  7986. } else {
  7987. if len(deliverWay) > 0 {
  7988. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ?and execution_frequency = ? and delivery_way =?"
  7989. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, execution_frequency, deliverWay)
  7990. } else {
  7991. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ?and execution_frequency = ?"
  7992. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, execution_frequency)
  7993. }
  7994. }
  7995. } else {
  7996. if len(keyword) > 0 {
  7997. if len(deliverWay) > 0 {
  7998. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ? and advice_name like ? and delivery_way =?"
  7999. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, keyword, deliverWay)
  8000. } else {
  8001. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  8002. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, keyword)
  8003. }
  8004. } else {
  8005. if len(deliverWay) > 0 {
  8006. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ? and delivery_way =? "
  8007. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, deliverWay)
  8008. } else {
  8009. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  8010. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type)
  8011. }
  8012. }
  8013. }
  8014. } else {
  8015. if len(execution_frequency) > 0 {
  8016. if len(keyword) > 0 {
  8017. if len(deliverWay) > 0 {
  8018. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_frequency = ? and advice_name like ? and delivery_way =? "
  8019. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_frequency, keyword, deliverWay)
  8020. } else {
  8021. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  8022. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_frequency, keyword)
  8023. }
  8024. } else {
  8025. if len(deliverWay) > 0 {
  8026. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_frequency = ? and delivery_way =? "
  8027. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_frequency, deliverWay)
  8028. } else {
  8029. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  8030. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_frequency)
  8031. }
  8032. }
  8033. } else {
  8034. if len(keyword) > 0 {
  8035. if len(deliverWay) > 0 {
  8036. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and advice_name like ? and delivery_way =?"
  8037. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, keyword, deliverWay)
  8038. } else {
  8039. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and advice_name like ?"
  8040. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, keyword)
  8041. }
  8042. } else {
  8043. if len(deliverWay) > 0 {
  8044. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and delivery_way =?"
  8045. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, deliverWay)
  8046. } else {
  8047. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ?"
  8048. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id)
  8049. }
  8050. }
  8051. }
  8052. }
  8053. }
  8054. } else {
  8055. if execution_state > 0 {
  8056. if cost_type > 0 {
  8057. if len(execution_frequency) > 0 {
  8058. if len(keyword) > 0 {
  8059. if len(deliverWay) > 0 {
  8060. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ?and execution_frequency = ? and advice_name like ? and delivery_way =?"
  8061. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, execution_frequency, keyword, deliverWay)
  8062. } else {
  8063. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ?and execution_frequency = ? and advice_name like ?"
  8064. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  8065. }
  8066. } else {
  8067. if len(deliverWay) > 0 {
  8068. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ?and execution_frequency = ? and delivery_way =?"
  8069. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, execution_frequency, deliverWay)
  8070. } else {
  8071. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ?and execution_frequency = ?"
  8072. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, execution_frequency)
  8073. }
  8074. }
  8075. } else {
  8076. if len(keyword) > 0 {
  8077. if len(deliverWay) > 0 {
  8078. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ? and advice_name like ? and delivery_way =?"
  8079. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, keyword, deliverWay)
  8080. } else {
  8081. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ? and advice_name like ?"
  8082. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, keyword)
  8083. }
  8084. } else {
  8085. if len(deliverWay) > 0 {
  8086. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ? and delivery_way =?"
  8087. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, deliverWay)
  8088. } else {
  8089. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ?"
  8090. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type)
  8091. }
  8092. }
  8093. }
  8094. } else {
  8095. if len(execution_frequency) > 0 {
  8096. if len(keyword) > 0 {
  8097. if len(deliverWay) > 0 {
  8098. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=?and execution_frequency = ? and advice_name like ? and delivery_way =?"
  8099. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, execution_frequency, keyword, deliverWay)
  8100. } else {
  8101. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=?and execution_frequency = ? and advice_name like ?"
  8102. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, execution_frequency, keyword)
  8103. }
  8104. } else {
  8105. if len(deliverWay) > 0 {
  8106. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=?and execution_frequency = ? and delivery_way =?"
  8107. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, execution_frequency, deliverWay)
  8108. } else {
  8109. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=?and execution_frequency = ?"
  8110. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, execution_frequency)
  8111. }
  8112. }
  8113. } else {
  8114. if len(keyword) > 0 {
  8115. if len(deliverWay) > 0 {
  8116. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and advice_name like ? and delivery_way =?"
  8117. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, keyword, deliverWay)
  8118. } else {
  8119. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and advice_name like ?"
  8120. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, keyword)
  8121. }
  8122. } else {
  8123. if len(deliverWay) > 0 {
  8124. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and delivery_way =?"
  8125. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, deliverWay)
  8126. } else {
  8127. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=?"
  8128. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state)
  8129. }
  8130. }
  8131. }
  8132. }
  8133. } else {
  8134. if cost_type > 0 {
  8135. if len(execution_frequency) > 0 {
  8136. if len(keyword) > 0 {
  8137. if len(deliverWay) > 0 {
  8138. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  8139. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, execution_frequency, keyword, deliverWay)
  8140. } else {
  8141. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  8142. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, execution_frequency, keyword)
  8143. }
  8144. } else {
  8145. if len(deliverWay) > 0 {
  8146. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and execution_frequency = ? and delivery_way =?"
  8147. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, execution_frequency, deliverWay)
  8148. } else {
  8149. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  8150. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, execution_frequency)
  8151. }
  8152. }
  8153. } else {
  8154. if len(keyword) > 0 {
  8155. if len(deliverWay) > 0 {
  8156. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and advice_name like ? and delivery_way =?"
  8157. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, keyword, deliverWay)
  8158. } else {
  8159. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and advice_name like ?"
  8160. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, keyword)
  8161. }
  8162. } else {
  8163. if len(deliverWay) > 0 {
  8164. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and delivery_way =?"
  8165. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, deliverWay)
  8166. } else {
  8167. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? "
  8168. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type)
  8169. }
  8170. }
  8171. }
  8172. } else {
  8173. if len(execution_frequency) > 0 {
  8174. if len(keyword) > 0 {
  8175. if len(deliverWay) > 0 {
  8176. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  8177. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_frequency, keyword, deliverWay)
  8178. } else {
  8179. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_frequency = ? and advice_name like ?"
  8180. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_frequency, keyword)
  8181. }
  8182. } else {
  8183. if len(deliverWay) > 0 {
  8184. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_frequency = ? and delivery_way =?"
  8185. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_frequency, deliverWay)
  8186. } else {
  8187. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_frequency = ?"
  8188. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_frequency)
  8189. }
  8190. }
  8191. } else {
  8192. if len(keyword) > 0 {
  8193. if len(deliverWay) > 0 {
  8194. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and advice_name like ? and delivery_way =?"
  8195. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, keyword, deliverWay)
  8196. } else {
  8197. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and advice_name like ?"
  8198. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, keyword)
  8199. }
  8200. } else {
  8201. if len(deliverWay) > 0 {
  8202. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and delivery_way =?"
  8203. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, deliverWay)
  8204. } else {
  8205. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? "
  8206. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId)
  8207. }
  8208. }
  8209. }
  8210. }
  8211. }
  8212. }
  8213. } else if patientType == 2 {
  8214. if patient_id > 0 {
  8215. if execution_state > 0 {
  8216. if cost_type > 0 {
  8217. if len(execution_frequency) > 0 {
  8218. if len(keyword) > 0 {
  8219. if len(deliverWay) > 0 {
  8220. 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 = ? and advice_name like ? and delivery_way =?"
  8221. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency, keyword, deliverWay)
  8222. } else {
  8223. 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 = ? and advice_name like ?"
  8224. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency, keyword)
  8225. }
  8226. } else {
  8227. if len(deliverWay) > 0 {
  8228. 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 = ? and delivery_way =?"
  8229. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency, deliverWay)
  8230. } else {
  8231. 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 = ?"
  8232. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency)
  8233. }
  8234. }
  8235. } else {
  8236. if len(keyword) > 0 {
  8237. if len(deliverWay) > 0 {
  8238. 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 advice_name like ? and delivery_way =?"
  8239. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, keyword, deliverWay)
  8240. } else {
  8241. 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 advice_name like ?"
  8242. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, keyword)
  8243. }
  8244. } else {
  8245. if len(deliverWay) > 0 {
  8246. 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 delivery_way =?"
  8247. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, deliverWay)
  8248. } else {
  8249. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ?"
  8250. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type)
  8251. }
  8252. }
  8253. }
  8254. } else {
  8255. if len(execution_frequency) > 0 {
  8256. if len(keyword) > 0 {
  8257. if len(deliverWay) > 0 {
  8258. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  8259. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency, keyword, deliverWay)
  8260. } else {
  8261. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  8262. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency, keyword)
  8263. }
  8264. } else {
  8265. if len(deliverWay) > 0 {
  8266. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and execution_frequency = ? and delivery_way =?"
  8267. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency, deliverWay)
  8268. } else {
  8269. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and execution_frequency = ?"
  8270. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency)
  8271. }
  8272. }
  8273. } else {
  8274. if len(keyword) > 0 {
  8275. if len(deliverWay) > 0 {
  8276. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and advice_name like ? and delivery_way =?"
  8277. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, keyword, deliverWay)
  8278. } else {
  8279. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and advice_name like ?"
  8280. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, keyword)
  8281. }
  8282. } else {
  8283. if len(deliverWay) > 0 {
  8284. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and delivery_way =?"
  8285. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, deliverWay)
  8286. } else {
  8287. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  8288. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state)
  8289. }
  8290. }
  8291. }
  8292. }
  8293. } else {
  8294. if cost_type > 0 {
  8295. if len(execution_frequency) > 0 {
  8296. if len(keyword) > 0 {
  8297. if len(deliverWay) > 0 {
  8298. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  8299. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency, keyword, deliverWay)
  8300. } else {
  8301. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  8302. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency, keyword)
  8303. }
  8304. } else {
  8305. if len(deliverWay) > 0 {
  8306. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and is_settle = ? and execution_frequency = ? and delivery_way =?"
  8307. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency, deliverWay)
  8308. } else {
  8309. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and is_settle = ? and execution_frequency = ?"
  8310. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency)
  8311. }
  8312. }
  8313. } else {
  8314. if len(keyword) > 0 {
  8315. if len(deliverWay) > 0 {
  8316. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and is_settle = ? and advice_name like ? and delivery_way =?"
  8317. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, keyword, deliverWay)
  8318. } else {
  8319. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and is_settle = ? and advice_name like ?"
  8320. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, keyword)
  8321. }
  8322. } else {
  8323. if len(deliverWay) > 0 {
  8324. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and is_settle = ? and delivery_way =?"
  8325. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, deliverWay)
  8326. } else {
  8327. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  8328. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type)
  8329. }
  8330. }
  8331. }
  8332. } else {
  8333. if len(execution_frequency) > 0 {
  8334. if len(keyword) > 0 {
  8335. if len(deliverWay) > 0 {
  8336. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  8337. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency, keyword, deliverWay)
  8338. } else {
  8339. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_frequency = ? and advice_name like ?"
  8340. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency, keyword)
  8341. }
  8342. } else {
  8343. if len(deliverWay) > 0 {
  8344. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_frequency = ? and delivery_way =?"
  8345. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency, deliverWay)
  8346. } else {
  8347. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_frequency = ?"
  8348. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency)
  8349. }
  8350. }
  8351. } else {
  8352. if len(keyword) > 0 {
  8353. if len(deliverWay) > 0 {
  8354. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and advice_name like ? and delivery_way =?"
  8355. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, keyword, deliverWay)
  8356. } else {
  8357. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and advice_name like ?"
  8358. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, keyword)
  8359. }
  8360. } else {
  8361. if len(deliverWay) > 0 {
  8362. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and delivery_way =?"
  8363. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, deliverWay)
  8364. } else {
  8365. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ?"
  8366. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id)
  8367. }
  8368. }
  8369. }
  8370. }
  8371. }
  8372. } else {
  8373. if execution_state > 0 {
  8374. if cost_type > 0 {
  8375. if len(execution_frequency) > 0 {
  8376. if len(keyword) > 0 {
  8377. if len(deliverWay) > 0 {
  8378. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  8379. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency, keyword, deliverWay)
  8380. } else {
  8381. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  8382. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency, keyword)
  8383. }
  8384. } else {
  8385. if len(deliverWay) > 0 {
  8386. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ? and execution_frequency = ? and delivery_way =?"
  8387. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency, deliverWay)
  8388. } else {
  8389. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ? and execution_frequency = ?"
  8390. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency)
  8391. }
  8392. }
  8393. } else {
  8394. if len(keyword) > 0 {
  8395. if len(deliverWay) > 0 {
  8396. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ? and advice_name like ? and delivery_way =?"
  8397. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, keyword, deliverWay)
  8398. } else {
  8399. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ? and advice_name like ?"
  8400. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, keyword)
  8401. }
  8402. } else {
  8403. if len(deliverWay) > 0 {
  8404. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ? and delivery_way =?"
  8405. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, deliverWay)
  8406. } else {
  8407. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  8408. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type)
  8409. }
  8410. }
  8411. }
  8412. } else {
  8413. if len(execution_frequency) > 0 {
  8414. if len(keyword) > 0 {
  8415. if len(deliverWay) > 0 {
  8416. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  8417. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency, keyword, deliverWay)
  8418. } else {
  8419. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ? and execution_frequency = ? and advice_name like ?"
  8420. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency, keyword)
  8421. }
  8422. } else {
  8423. if len(deliverWay) > 0 {
  8424. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ? and execution_frequency = ? and delivery_way =?"
  8425. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency, deliverWay)
  8426. } else {
  8427. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ? and execution_frequency = ?"
  8428. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency)
  8429. }
  8430. }
  8431. } else {
  8432. if len(keyword) > 0 {
  8433. if len(deliverWay) > 0 {
  8434. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ? and advice_name like ? and delivery_way =?"
  8435. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, keyword, deliverWay)
  8436. } else {
  8437. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ? and advice_name like ?"
  8438. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, keyword)
  8439. }
  8440. } else {
  8441. if len(deliverWay) > 0 {
  8442. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ? and delivery_way =?"
  8443. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, deliverWay)
  8444. } else {
  8445. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ?"
  8446. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state)
  8447. }
  8448. }
  8449. }
  8450. }
  8451. } else {
  8452. if cost_type > 0 {
  8453. if len(execution_frequency) > 0 {
  8454. if len(keyword) > 0 {
  8455. if len(deliverWay) > 0 {
  8456. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  8457. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, execution_frequency, keyword, deliverWay)
  8458. } else {
  8459. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ? and execution_frequency = ? and advice_name like ?"
  8460. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, execution_frequency, keyword)
  8461. }
  8462. } else {
  8463. if len(deliverWay) > 0 {
  8464. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ? and execution_frequency = ? and delivery_way =?"
  8465. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, execution_frequency, deliverWay)
  8466. } else {
  8467. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  8468. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, execution_frequency)
  8469. }
  8470. }
  8471. } else {
  8472. if len(keyword) > 0 {
  8473. if len(deliverWay) > 0 {
  8474. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ? and advice_name like ? and delivery_way =?"
  8475. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, keyword, deliverWay)
  8476. } else {
  8477. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ? and advice_name like ?"
  8478. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, keyword)
  8479. }
  8480. } else {
  8481. if len(deliverWay) > 0 {
  8482. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ? and delivery_way =?"
  8483. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, deliverWay)
  8484. } else {
  8485. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ?"
  8486. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type)
  8487. }
  8488. }
  8489. }
  8490. } else {
  8491. if len(execution_frequency) > 0 {
  8492. if len(keyword) > 0 {
  8493. if len(deliverWay) > 0 {
  8494. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_frequency = ? and advice_name like ? and delivery_way =?"
  8495. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_frequency, keyword, deliverWay)
  8496. } else {
  8497. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_frequency = ? and advice_name like ?"
  8498. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_frequency, keyword)
  8499. }
  8500. } else {
  8501. if len(deliverWay) > 0 {
  8502. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_frequency = ? and delivery_way =?"
  8503. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_frequency, deliverWay)
  8504. } else {
  8505. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_frequency = ?"
  8506. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_frequency)
  8507. }
  8508. }
  8509. } else {
  8510. if len(keyword) > 0 {
  8511. if len(deliverWay) > 0 {
  8512. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and advice_name like ? and delivery_way =?"
  8513. adviceCondition = append(adviceCondition, adviceWhere, orgID, keyword, deliverWay)
  8514. } else {
  8515. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and advice_name like ?"
  8516. adviceCondition = append(adviceCondition, adviceWhere, orgID, keyword)
  8517. }
  8518. } else {
  8519. if len(deliverWay) > 0 {
  8520. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and delivery_way =?"
  8521. adviceCondition = append(adviceCondition, adviceWhere, orgID, deliverWay)
  8522. } else {
  8523. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0"
  8524. adviceCondition = append(adviceCondition, adviceWhere, orgID)
  8525. }
  8526. }
  8527. }
  8528. }
  8529. }
  8530. }
  8531. }
  8532. }
  8533. db := readDb.Table("xt_schedule")
  8534. if scheduleType > 0 {
  8535. db = db.Where("schedule_type = ?", scheduleType)
  8536. }
  8537. if partitonType > 0 {
  8538. db = db.Where("partition_id = ?", partitonType)
  8539. }
  8540. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  8541. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  8542. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  8543. }).
  8544. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  8545. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  8546. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  8547. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  8548. Preload("DoctorAdvices", adviceCondition...).
  8549. Where("status = 1 AND user_org_id = ?", orgID)
  8550. if scheduleDate != 0 {
  8551. db = db.Where("schedule_date = ?", scheduleDate)
  8552. }
  8553. err := db.Find(&vms).Error
  8554. return vms, err
  8555. }
  8556. func GetLastAcceptTreatment(user_org_id int64, patient_id int64) (models.ReceiveTreatmentAsses, error) {
  8557. treatmentAsses := models.ReceiveTreatmentAsses{}
  8558. err := XTReadDB().Where("user_org_id = ? and patient_id = ? and status=1 and admission_number<>''", user_org_id, patient_id).Last(&treatmentAsses).Error
  8559. return treatmentAsses, err
  8560. }