mobile_dialysis_service.go 540KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047
  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 = ? and status=1", 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. redis.Set(key, "", time.Second)
  948. if len(monitor_record_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  949. 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
  950. if err != nil {
  951. if err == gorm.ErrRecordNotFound {
  952. if record.ID <= 0 {
  953. redis.Set(key, "null", time.Second*60*60*18)
  954. }
  955. return nil, nil
  956. } else {
  957. return nil, err
  958. }
  959. } else {
  960. if record.ID > 0 {
  961. //缓存数据
  962. monitor_record_last_str, err := json.Marshal(record)
  963. if err == nil {
  964. redis.Set(key, monitor_record_last_str, time.Second*60*60*18)
  965. }
  966. } else {
  967. redis.Set(key, "null", time.Second*60*60*18)
  968. }
  969. return &record, nil
  970. }
  971. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  972. if monitor_record_last_str == "null" {
  973. return &record, nil
  974. } else {
  975. json.Unmarshal([]byte(monitor_record_last_str), &record)
  976. return &record, nil
  977. }
  978. }
  979. }
  980. func MobileGetAssessmentAfterDislysisOne(orgID int64, patientID int64, recordDate int64) (*models.AssessmentAfterDislysis, error) {
  981. var record models.AssessmentAfterDislysis
  982. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  983. if err != nil {
  984. if err == gorm.ErrRecordNotFound {
  985. return nil, nil
  986. } else {
  987. return nil, err
  988. }
  989. }
  990. return &record, nil
  991. }
  992. // 透后评估
  993. func MobileGetAssessmentAfterDislysis(orgID int64, patientID int64, recordDate int64) (*models.AssessmentAfterDislysis, error) {
  994. var record models.AssessmentAfterDislysis
  995. redis := RedisClient()
  996. defer redis.Close()
  997. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":assessment_after_dislysis"
  998. redis.Set(key, "", time.Second)
  999. assessment_after_dislysis_str, _ := redis.Get(key).Result()
  1000. if len(assessment_after_dislysis_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1001. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  1002. if err != nil {
  1003. if err == gorm.ErrRecordNotFound {
  1004. if record.ID <= 0 {
  1005. redis.Set(key, "null", time.Second*60*60*18)
  1006. }
  1007. return nil, nil
  1008. } else {
  1009. return nil, err
  1010. }
  1011. } else {
  1012. if record.ID > 0 {
  1013. //缓存数据
  1014. assessment_after_dislysis_str, err := json.Marshal(record)
  1015. if err == nil {
  1016. redis.Set(key, assessment_after_dislysis_str, time.Second*60*60*18)
  1017. }
  1018. } else {
  1019. redis.Set(key, "null", time.Second*60*60*18)
  1020. }
  1021. return &record, nil
  1022. }
  1023. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1024. if assessment_after_dislysis_str == "null" {
  1025. return &record, nil
  1026. } else {
  1027. json.Unmarshal([]byte(assessment_after_dislysis_str), &record)
  1028. return &record, nil
  1029. }
  1030. }
  1031. }
  1032. // 获取 maxDate 之前一次的透后评估记录
  1033. func MobileGetLastTimeAssessmentAfterDislysis(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  1034. var record models.AssessmentAfterDislysis
  1035. redis := RedisClient()
  1036. defer redis.Close()
  1037. // cur_date := time.Now().Format("2006-01-02")
  1038. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(maxDate, 10) + ":assessment_after_dislysis_last"
  1039. redis.Set(key, "", time.Second)
  1040. assessment_after_dislysis_last_str, _ := redis.Get(key).Result()
  1041. if len(assessment_after_dislysis_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1042. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where(" patient_id = ? and user_org_id = ? and status = 1 and assessment_date>=1725120000 and assessment_date < ?", patientID, orgID, maxDate).Order("assessment_date desc").First(&record).Error
  1043. if err != nil {
  1044. if err == gorm.ErrRecordNotFound {
  1045. if record.ID <= 0 {
  1046. redis.Set(key, "null", time.Second*60*60*18)
  1047. }
  1048. return nil, nil
  1049. } else {
  1050. return nil, err
  1051. }
  1052. } else {
  1053. if record.ID > 0 {
  1054. //缓存数据
  1055. assessment_after_dislysis_last_str, err := json.Marshal(record)
  1056. if err == nil {
  1057. redis.Set(key, assessment_after_dislysis_last_str, time.Second*60*60*18)
  1058. }
  1059. } else {
  1060. redis.Set(key, "null", time.Second*60*60*18)
  1061. }
  1062. return &record, nil
  1063. }
  1064. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1065. if assessment_after_dislysis_last_str == "null" {
  1066. return &record, nil
  1067. } else {
  1068. json.Unmarshal([]byte(assessment_after_dislysis_last_str), &record)
  1069. return &record, nil
  1070. }
  1071. }
  1072. }
  1073. func MobileGetLastTimeAssessmentAfterDislysisOne(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  1074. var record models.AssessmentAfterDislysis
  1075. 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
  1076. if err != nil {
  1077. if err == gorm.ErrRecordNotFound {
  1078. return nil, nil
  1079. } else {
  1080. return nil, err
  1081. }
  1082. }
  1083. return &record, nil
  1084. }
  1085. func MobileGetLastTimeAssessmentAfterDislysisTwo(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  1086. var record models.AssessmentAfterDislysis
  1087. 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
  1088. return &record, nil
  1089. }
  1090. func MobileGetLast(orgID int64, patientID int64, maxDate int64) (models.AssessmentAfterDislysis, error) {
  1091. dislysis := models.AssessmentAfterDislysis{}
  1092. 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
  1093. return dislysis, err
  1094. }
  1095. // 治疗小结
  1096. func MobileGetTreatmentSummary(orgID int64, patientID int64, recordDate int64) (*models.TreatmentSummary, error) {
  1097. var record models.TreatmentSummary
  1098. redis := RedisClient()
  1099. defer redis.Close()
  1100. // cur_date := time.Now().Format("2006-01-02")
  1101. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":treatment_summary"
  1102. treatment_summary_str, _ := redis.Get(key).Result()
  1103. if len(treatment_summary_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1104. err := readDb.Model(&models.TreatmentSummary{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  1105. if err != nil {
  1106. if err == gorm.ErrRecordNotFound {
  1107. if record.ID <= 0 {
  1108. redis.Set(key, "null", time.Second*60*60*18)
  1109. }
  1110. return nil, nil
  1111. } else {
  1112. return nil, err
  1113. }
  1114. } else {
  1115. if record.ID > 0 {
  1116. //缓存数据
  1117. treatment_summary_str, err := json.Marshal(record)
  1118. if err == nil {
  1119. redis.Set(key, treatment_summary_str, time.Second*60*60*18)
  1120. }
  1121. } else {
  1122. redis.Set(key, "null", time.Second*60*60*18)
  1123. }
  1124. return &record, nil
  1125. }
  1126. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1127. if treatment_summary_str == "null" {
  1128. return &record, nil
  1129. } else {
  1130. json.Unmarshal([]byte(treatment_summary_str), &record)
  1131. return &record, nil
  1132. }
  1133. }
  1134. }
  1135. // 透析处方
  1136. func MobileGetDialysisPrescribe(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  1137. var record models.DialysisPrescription
  1138. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).Find(&record).Error
  1139. if err != nil {
  1140. if err == gorm.ErrRecordNotFound {
  1141. return nil, nil
  1142. } else {
  1143. return nil, err
  1144. }
  1145. }
  1146. return &record, nil
  1147. }
  1148. func MobileGetDialysisPrescribeOne(orgID int64, patientID int64, recordDate int64) (models.DialysisPrescription, error) {
  1149. var record models.DialysisPrescription
  1150. err = readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).Find(&record).Error
  1151. return record, nil
  1152. }
  1153. func UpdateMobileGetDialysisPrescribe(id int64, dewater_amount float64) error {
  1154. err := XTWriteDB().Model(&models.DialysisPrescription{}).Where("id=? and status=1", id).Updates(map[string]interface{}{"target_ultrafiltration": dewater_amount, "prescription_water": dewater_amount}).Error
  1155. return err
  1156. }
  1157. func UpdateMobileGetDialysisPrescribeOne(id int64, dewater_amount float64) error {
  1158. err := XTWriteDB().Model(&models.DialysisPrescription{}).Where("id=? and status=1", id).Updates(map[string]interface{}{"target_ultrafiltration": dewater_amount}).Error
  1159. return err
  1160. }
  1161. func MobileGetDialysisSchedual(orgID int64, patientID int64, scheduleDate int64) (*models.XtSchedule, error) {
  1162. var schedule models.XtSchedule
  1163. err := readDb.Model(&models.XtSchedule{}).Where("patient_id = ? and user_org_id = ? and status = 1 and schedule_date = ?", patientID, orgID, scheduleDate).First(&schedule).Error
  1164. if err != nil {
  1165. if err == gorm.ErrRecordNotFound {
  1166. return nil, nil
  1167. } else {
  1168. return nil, err
  1169. }
  1170. }
  1171. return &schedule, nil
  1172. }
  1173. // 透析方案
  1174. func MobileGetDialysisSolution(orgID int64, patientID int64) (*models.DialysisSolution, error) {
  1175. var record models.DialysisSolution
  1176. err := readDb.Model(&models.DialysisSolution{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  1177. if err != nil {
  1178. if err == gorm.ErrRecordNotFound {
  1179. return nil, nil
  1180. } else {
  1181. return nil, err
  1182. }
  1183. }
  1184. return &record, nil
  1185. }
  1186. func MobileGetPatientById(orgID int64, patientID int64) (*models.Patients, error) {
  1187. var patient models.Patients
  1188. err := readDb.Model(&models.Patients{}).Where("id = ? and user_org_id = ? and status = 1", patientID, orgID).First(&patient).Error
  1189. if err != nil {
  1190. if err == gorm.ErrRecordNotFound {
  1191. return nil, nil
  1192. } else {
  1193. return nil, err
  1194. }
  1195. }
  1196. return &patient, nil
  1197. }
  1198. func DisableMonitor(orgID int64, patientID int64, recordID int64, admin_user_id int64) error {
  1199. fmt.Println()
  1200. tx := writeDb.Begin()
  1201. updateTime := time.Now().Unix()
  1202. 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
  1203. if err != nil {
  1204. tx.Rollback()
  1205. return err
  1206. }
  1207. tx.Commit()
  1208. return nil
  1209. }
  1210. func GetMonitorById(id int64, orgId int64) (models.MonitoringRecord, error) {
  1211. record := models.MonitoringRecord{}
  1212. err := XTReadDB().Where("id = ? and user_org_id =?", id, orgId).Find(&record).Error
  1213. return record, err
  1214. }
  1215. func GetMonitor(orgID int64, patientID int64, id int64) (*models.MonitoringRecord, error) {
  1216. var monitor models.MonitoringRecord
  1217. var err error
  1218. err = readDb.Model(&models.MonitoringRecord{}).Where("id = ? AND user_org_id = ? AND patient_id = ? AND status = 1 ", id, orgID, patientID).Find(&monitor).Error
  1219. if err == gorm.ErrRecordNotFound {
  1220. return nil, nil
  1221. }
  1222. if err != nil {
  1223. return nil, err
  1224. }
  1225. return &monitor, nil
  1226. }
  1227. type MScheduleDoctorAdviceVM struct {
  1228. ID int64 `gorm:"column:id" json:"id"`
  1229. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  1230. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  1231. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  1232. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1233. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  1234. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  1235. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  1236. Status int64 `gorm:"column:status" json:"status"`
  1237. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  1238. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  1239. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  1240. DoctorAdvices []*MDoctorAdviceVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  1241. Prescription *models.DialysisPrescriptionTwenty `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  1242. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  1243. }
  1244. func (MScheduleDoctorAdviceVM) TableName() string {
  1245. return "xt_schedule"
  1246. }
  1247. type MScheduleDoctorAdviceVMOne struct {
  1248. ID int64 `gorm:"column:id" json:"id"`
  1249. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  1250. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  1251. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  1252. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1253. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  1254. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  1255. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  1256. Status int64 `gorm:"column:status" json:"status"`
  1257. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  1258. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  1259. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  1260. DoctorAdvices []*MDoctorAdviceVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  1261. Prescription *models.DialysisPrescriptionTwenty `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  1262. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  1263. }
  1264. func (MScheduleDoctorAdviceVMOne) TableName() string {
  1265. return "xt_schedule"
  1266. }
  1267. type MDoctorAdviceVM struct {
  1268. ID int64 `gorm:"column:id" json:"id"`
  1269. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  1270. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1271. AdviceType int64 `gorm:"column:advice_type" json:"advice_type"`
  1272. AdviceDate int64 `gorm:"column:advice_date" json:"advice_date"`
  1273. StartTime int64 `gorm:"column:start_time" json:"start_time"`
  1274. AdviceName string `gorm:"column:advice_name" json:"advice_name"`
  1275. AdviceDesc string `gorm:"column:advice_desc" json:"advice_desc"`
  1276. ReminderDate int64 `gorm:"column:reminder_date" json:"reminder_date"`
  1277. SingleDose float64 `gorm:"column:single_dose" json:"single_dose"`
  1278. SingleDoseUnit string `gorm:"column:single_dose_unit" json:"single_dose_unit"`
  1279. PrescribingNumber float64 `gorm:"column:prescribing_number" json:"prescribing_number"`
  1280. PrescribingNumberUnit string `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit"`
  1281. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way"`
  1282. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency"`
  1283. AdviceDoctor int64 `gorm:"column:advice_doctor" json:"advice_doctor"`
  1284. Status int64 `gorm:"column:status" json:"status"`
  1285. CreatedTime int64 `gorm:"column:created_time" json:"created_time"`
  1286. UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time"`
  1287. AdviceAffirm string `gorm:"column:advice_affirm" json:"advice_affirm"`
  1288. Remark string `gorm:"column:remark" json:"remark"`
  1289. StopTime int64 `gorm:"column:stop_time" json:"stop_time"`
  1290. StopReason string `gorm:"column:stop_reason" json:"stop_reason"`
  1291. StopDoctor int64 `gorm:"column:stop_doctor" json:"stop_doctor"`
  1292. StopState int64 `gorm:"column:stop_state" json:"stop_state"`
  1293. ParentId int64 `gorm:"column:parent_id" json:"parent_id"`
  1294. ExecutionTime int64 `gorm:"column:execution_time" json:"execution_time"`
  1295. ExecutionStaff int64 `gorm:"column:execution_staff" json:"execution_staff"`
  1296. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state"`
  1297. Checker int64 `gorm:"column:checker" json:"checker"`
  1298. RecordDate int64 `gorm:"column:record_date" json:"record_date"`
  1299. DialysisOrderId int64 `gorm:"column:dialysis_order_id" json:"dialysis_order_id"`
  1300. CheckTime int64 `gorm:"column:check_time" json:"check_time"`
  1301. CheckState int64 `gorm:"column:check_state" json:"check_state"`
  1302. DrugSpec float64 `gorm:"column:drug_spec" json:"drug_spec"`
  1303. DrugSpecUnit string `gorm:"column:drug_spec_unit" json:"drug_spec_unit"`
  1304. Groupno int64 `gorm:"column:groupno" json:"groupno"`
  1305. RemindType int64 `gorm:"column:remind_type" json:"remind_type"`
  1306. FrequencyType int64 `gorm:"column:frequency_type" json:"frequency_type"`
  1307. DayCount int64 `gorm:"column:day_count" json:"day_count"`
  1308. WeekDay string `gorm:"column:week_day" json:"week_day"`
  1309. TemplateId string `gorm:"column:template_id" json:"template_id"`
  1310. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1311. IsMedicine int64 `gorm:"column:is_medicine" json:"is_medicine" form:"is_medicine"`
  1312. IsSettle int64 `gorm:"column:is_settle" json:"is_settle" form:"is_settle"`
  1313. }
  1314. func (MDoctorAdviceVM) TableName() string {
  1315. return "xt_doctor_advice"
  1316. }
  1317. func MobileGetScheduleDoctorAdvices(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string) ([]*MScheduleDoctorAdviceVM, error) {
  1318. var vms []*MScheduleDoctorAdviceVM
  1319. adviceWhere := ""
  1320. adviceCondition := []interface{}{}
  1321. if adviceType == 0 {
  1322. if patientType == 0 {
  1323. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  1324. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1325. } else if patientType == 1 {
  1326. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  1327. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1328. } else if patientType == 2 {
  1329. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  1330. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1331. }
  1332. } else if adviceType == 1 {
  1333. if patientType == 0 {
  1334. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  1335. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1336. } else if patientType == 1 {
  1337. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  1338. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1339. } else if patientType == 2 {
  1340. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  1341. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1342. }
  1343. } else if adviceType == 3 {
  1344. if patientType == 0 {
  1345. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  1346. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1347. } else if patientType == 1 {
  1348. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  1349. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1350. } else if patientType == 2 {
  1351. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  1352. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1353. }
  1354. } else if adviceType == 2 && len(deliverWay) > 0 {
  1355. if patientType == 0 {
  1356. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  1357. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1358. } else if patientType == 1 {
  1359. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  1360. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  1361. } else if patientType == 2 {
  1362. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  1363. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1364. }
  1365. } else if adviceType == 2 && len(deliverWay) <= 0 {
  1366. if patientType == 0 {
  1367. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  1368. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1369. } else if patientType == 1 {
  1370. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND (advice_doctor = ? or execution_staff = ?)"
  1371. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, adminUserId)
  1372. } else if patientType == 2 {
  1373. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  1374. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1375. }
  1376. }
  1377. db := readDb.
  1378. Table("xt_schedule").
  1379. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1380. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1381. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1382. }).
  1383. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1384. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1385. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1386. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  1387. Preload("DoctorAdvices", adviceCondition...).
  1388. Where("status = 1 AND user_org_id = ?", orgID)
  1389. if scheduleDate != 0 {
  1390. db = db.Where("schedule_date = ?", scheduleDate)
  1391. }
  1392. err := db.Find(&vms).Error
  1393. return vms, err
  1394. }
  1395. func MobileGetScheduleDoctorAdvicesTwo(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string) ([]*MScheduleDoctorAdviceVMOne, error) {
  1396. var vms []*MScheduleDoctorAdviceVMOne
  1397. adviceWhere := ""
  1398. adviceCondition := []interface{}{}
  1399. if adviceType == 0 {
  1400. if patientType == 0 {
  1401. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  1402. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1403. } else if patientType == 1 {
  1404. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  1405. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1406. } else if patientType == 2 {
  1407. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  1408. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1409. } else if patientType == 3 {
  1410. 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"
  1411. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1412. } else if patientType == 4 {
  1413. 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)"
  1414. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1415. }
  1416. } else if adviceType == 1 {
  1417. if patientType == 0 {
  1418. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  1419. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1420. } else if patientType == 1 {
  1421. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  1422. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1423. } else if patientType == 2 {
  1424. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  1425. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1426. } else if patientType == 3 {
  1427. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = 1"
  1428. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1429. } else if patientType == 4 {
  1430. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and (is_settle = 0 or is_settle = 2)"
  1431. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1432. }
  1433. } else if adviceType == 3 {
  1434. if patientType == 0 {
  1435. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  1436. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1437. } else if patientType == 1 {
  1438. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  1439. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1440. } else if patientType == 2 {
  1441. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  1442. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1443. } else if patientType == 3 {
  1444. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 and is_settle = 1"
  1445. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1446. } else if patientType == 4 {
  1447. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 and (is_settle = 0 or is_settle = 2)"
  1448. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1449. }
  1450. } else if adviceType == 2 && len(deliverWay) > 0 {
  1451. if patientType == 0 {
  1452. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  1453. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1454. } else if patientType == 1 {
  1455. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  1456. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  1457. } else if patientType == 2 {
  1458. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  1459. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1460. } else if patientType == 3 {
  1461. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 and delivery_way = ? and is_settle = 1"
  1462. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1463. } else if patientType == 4 {
  1464. 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)"
  1465. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1466. }
  1467. } else if adviceType == 2 && len(deliverWay) <= 0 {
  1468. if patientType == 0 {
  1469. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  1470. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1471. } else if patientType == 1 {
  1472. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND (advice_doctor = ? or execution_staff = ?)"
  1473. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, adminUserId)
  1474. } else if patientType == 2 {
  1475. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  1476. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1477. } else if patientType == 3 {
  1478. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 and is_settle = 1"
  1479. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1480. } else if patientType == 4 {
  1481. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 and (is_settle = 0 or is_settle = 2)"
  1482. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1483. }
  1484. }
  1485. db := readDb.
  1486. Table("xt_schedule").
  1487. //Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1488. //Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1489. // return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1490. //}).
  1491. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1492. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1493. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1494. Preload("DoctorAdvices", adviceCondition...).
  1495. Where("status = 1 AND user_org_id = ?", orgID)
  1496. if scheduleDate != 0 {
  1497. db = db.Where("schedule_date = ?", scheduleDate)
  1498. }
  1499. err := db.Find(&vms).Error
  1500. return vms, err
  1501. }
  1502. func GetHisDoctorAdvices(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleDoctorAdviceVM, error) {
  1503. var vms []*HisMScheduleDoctorAdviceVM
  1504. if len(deliverWay) > 0 {
  1505. if patientType == 0 {
  1506. db := readDb.
  1507. Table("xt_schedule").
  1508. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  1509. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1510. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1511. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1512. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1513. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1514. }).
  1515. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1516. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1517. Where("status = 1 AND user_org_id = ?", orgID)
  1518. if scheduleDate != 0 {
  1519. db = db.Where("schedule_date = ?", scheduleDate)
  1520. }
  1521. err = db.Find(&vms).Error
  1522. }
  1523. if patientType > 0 {
  1524. db := readDb.
  1525. Table("xt_schedule").
  1526. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1527. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1528. 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).
  1529. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1530. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1531. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1532. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1533. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND 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. } else {
  1541. if patientType == 0 {
  1542. db := readDb.
  1543. Table("xt_schedule").
  1544. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? ", orgID, scheduleDate).
  1545. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1546. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1547. return db.Where("status = 1 AND user_org_id = ? and dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1548. }).
  1549. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1550. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1551. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1552. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1553. Where("status = 1 AND user_org_id = ?", orgID)
  1554. if scheduleDate != 0 {
  1555. db = db.Where("schedule_date = ?", scheduleDate)
  1556. }
  1557. err = db.Find(&vms).Error
  1558. }
  1559. if patientType > 0 {
  1560. db := readDb.
  1561. Table("xt_schedule").
  1562. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1563. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1564. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1565. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1566. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1567. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1568. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1569. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1570. Where("status = 1 AND user_org_id = ?", orgID)
  1571. if scheduleDate != 0 {
  1572. db = db.Where("schedule_date = ?", scheduleDate)
  1573. }
  1574. err = db.Find(&vms).Error
  1575. }
  1576. }
  1577. return vms, err
  1578. }
  1579. func GetHisDoctorAdvicesTwo(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleDoctorAdviceVMOne, error) {
  1580. var vms []*HisMScheduleDoctorAdviceVMOne
  1581. if len(deliverWay) > 0 {
  1582. if patientType == 0 {
  1583. db := readDb.
  1584. Table("xt_schedule").
  1585. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  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("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1589. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1590. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1591. }).
  1592. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1593. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1594. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  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 > 0 {
  1602. if patientType == 1 {
  1603. db := readDb.
  1604. Table("xt_schedule").
  1605. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1606. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1607. 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).
  1608. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1609. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1610. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1611. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1612. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1613. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1614. Where("status = 1 AND user_org_id = ?", orgID)
  1615. if scheduleDate != 0 {
  1616. db = db.Where("schedule_date = ?", scheduleDate)
  1617. }
  1618. err = db.Find(&vms).Error
  1619. }
  1620. if patientType == 2 {
  1621. db := readDb.
  1622. Table("xt_schedule").
  1623. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1624. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1625. 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).
  1626. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1627. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1628. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1629. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1630. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1631. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Where("status = 1 AND user_org_id = ?", orgID)
  1632. if scheduleDate != 0 {
  1633. db = db.Where("schedule_date = ?", scheduleDate)
  1634. }
  1635. err = db.Find(&vms).Error
  1636. }
  1637. if patientType == 3 {
  1638. db := readDb.
  1639. Table("xt_schedule").
  1640. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1641. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1642. 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).
  1643. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1644. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1645. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1646. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1647. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1648. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Where("status = 1 AND user_org_id = ?", orgID)
  1649. if scheduleDate != 0 {
  1650. db = db.Where("schedule_date = ?", scheduleDate)
  1651. }
  1652. err = db.Find(&vms).Error
  1653. }
  1654. if patientType == 4 {
  1655. db := readDb.
  1656. Table("xt_schedule").
  1657. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1658. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1659. 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).
  1660. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1661. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1662. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1663. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1664. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1665. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Where("status = 1 AND user_org_id = ?", orgID)
  1666. if scheduleDate != 0 {
  1667. db = db.Where("schedule_date = ?", scheduleDate)
  1668. }
  1669. err = db.Find(&vms).Error
  1670. }
  1671. }
  1672. } else {
  1673. if patientType == 0 {
  1674. db := readDb.
  1675. Table("xt_schedule").
  1676. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? ", orgID, scheduleDate).
  1677. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1678. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1679. return db.Where("status = 1 AND user_org_id = ? and dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1680. }).
  1681. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1682. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1683. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1684. Preload("SchedualPatient", "status = 1 AND user_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 > 0 {
  1693. if patientType == 1 {
  1694. db := readDb.
  1695. Table("xt_schedule").
  1696. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1697. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1698. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1699. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1700. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1701. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1702. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1703. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1704. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1705. Where("status = 1 AND user_org_id = ?", orgID)
  1706. if scheduleDate != 0 {
  1707. db = db.Where("schedule_date = ?", scheduleDate)
  1708. }
  1709. err = db.Find(&vms).Error
  1710. }
  1711. if patientType == 2 {
  1712. db := readDb.
  1713. Table("xt_schedule").
  1714. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1715. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1716. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1717. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1718. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1719. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1720. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1721. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1722. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1723. Where("status = 1 AND user_org_id = ?", orgID)
  1724. if scheduleDate != 0 {
  1725. db = db.Where("schedule_date = ?", scheduleDate)
  1726. }
  1727. err = db.Find(&vms).Error
  1728. }
  1729. if patientType == 3 {
  1730. db := readDb.
  1731. Table("xt_schedule").
  1732. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1733. 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).
  1734. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1735. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1736. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1737. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1738. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1739. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1740. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1741. Where("status = 1 AND user_org_id = ?", orgID)
  1742. if scheduleDate != 0 {
  1743. db = db.Where("schedule_date = ?", scheduleDate)
  1744. }
  1745. err = db.Find(&vms).Error
  1746. }
  1747. if patientType == 4 {
  1748. db := readDb.
  1749. Table("xt_schedule").
  1750. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1751. 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).
  1752. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1753. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1754. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1755. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1756. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1757. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1758. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1759. Where("status = 1 AND user_org_id = ?", orgID)
  1760. if scheduleDate != 0 {
  1761. db = db.Where("schedule_date = ?", scheduleDate)
  1762. }
  1763. err = db.Find(&vms).Error
  1764. }
  1765. }
  1766. }
  1767. return vms, err
  1768. }
  1769. func GetMobileHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleProjectVM, error) {
  1770. var vms []*HisMScheduleProjectVM
  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("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1782. // return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1783. // }).
  1784. // Where("status = 1 AND user_org_id = ?", orgID)
  1785. // if scheduleDate != 0 {
  1786. // db = db.Where("schedule_date = ?", scheduleDate)
  1787. // }
  1788. // err = db.Find(&vms).Error
  1789. //}
  1790. //if patientType > 0 {
  1791. // db := readDb.
  1792. // Table("xt_schedule").
  1793. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1794. // Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1795. // return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1796. // }).
  1797. // Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1798. // Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1799. // Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1800. // Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1801. // Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1802. // return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1803. // }).
  1804. // Where("status = 1 AND user_org_id = ?", orgID)
  1805. // if scheduleDate != 0 {
  1806. // db = db.Where("schedule_date = ?", scheduleDate)
  1807. // }
  1808. // err = db.Find(&vms).Error
  1809. //}
  1810. db := readDb.Table("xt_schedule").Where("status = 1")
  1811. if orgID > 0 {
  1812. db = db.Where("user_org_id = ?", orgID)
  1813. }
  1814. if scheduleDate > 0 {
  1815. db = db.Where("schedule_date =?", scheduleDate)
  1816. }
  1817. err = db.Find(&vms).Error
  1818. if patientType == 0 {
  1819. db := readDb.
  1820. Table("xt_schedule").
  1821. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1822. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1823. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1824. }).
  1825. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1826. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1827. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1828. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1829. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1830. }).
  1831. Preload("HisPrescriptionTeamProject", 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("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  1833. }).
  1834. Where("status = 1 AND user_org_id = ?", orgID)
  1835. if scheduleDate != 0 {
  1836. db = db.Where("schedule_date = ?", scheduleDate)
  1837. }
  1838. err = db.Find(&vms).Error
  1839. }
  1840. if patientType > 0 {
  1841. db := readDb.
  1842. Table("xt_schedule").
  1843. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1844. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1845. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1846. }).
  1847. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1848. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1849. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1850. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1851. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1852. }).
  1853. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  1854. 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")
  1855. }).
  1856. Where("status = 1 AND user_org_id = ?", orgID)
  1857. if scheduleDate != 0 {
  1858. db = db.Where("schedule_date = ?", scheduleDate)
  1859. }
  1860. err = db.Find(&vms).Error
  1861. }
  1862. return vms, err
  1863. }
  1864. func MobileCreateDialysisOrder(orgID int64, patientID int64, order *models.DialysisOrder) error {
  1865. now := time.Now()
  1866. tx := writeDb.Begin()
  1867. if createOrderErr := tx.Model(&models.DialysisOrder{}).Create(order).Error; createOrderErr != nil {
  1868. tx.Rollback()
  1869. return createOrderErr
  1870. }
  1871. // 更新透析记录 ID
  1872. // 透析处方
  1873. 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 {
  1874. tx.Rollback()
  1875. return err
  1876. }
  1877. // 接诊评估
  1878. 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 {
  1879. tx.Rollback()
  1880. return err
  1881. }
  1882. // 透前评估
  1883. 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 {
  1884. tx.Rollback()
  1885. return err
  1886. }
  1887. // 临时医嘱
  1888. 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 {
  1889. tx.Rollback()
  1890. return err
  1891. }
  1892. // 双人核对
  1893. 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 {
  1894. tx.Rollback()
  1895. return err
  1896. }
  1897. // 透后评估
  1898. 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 {
  1899. tx.Rollback()
  1900. return err
  1901. }
  1902. // 治疗小结
  1903. 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 {
  1904. tx.Rollback()
  1905. return err
  1906. }
  1907. // 透析监测
  1908. 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 {
  1909. tx.Rollback()
  1910. return err
  1911. }
  1912. tx.Commit()
  1913. return nil
  1914. }
  1915. type MobileUrgentSchedulePatientVM struct {
  1916. ID int64 `gorm:"column:id" json:"id"`
  1917. Name string `gorm:"column:name" json:"name"`
  1918. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no"`
  1919. }
  1920. func (MobileUrgentSchedulePatientVM) TableName() string {
  1921. return "xt_patients"
  1922. }
  1923. type MobileUrgentScheduleTreatmentModeVM struct {
  1924. ID int64 `gorm:"column:id" json:"id"`
  1925. Name string `gorm:"column:name" json:"name"`
  1926. }
  1927. func (MobileUrgentScheduleTreatmentModeVM) TableName() string {
  1928. return "xt_treatment_mode"
  1929. }
  1930. func MobileGetAllPatientsForUrgentSchedule(orgID int64, record_date int64) ([]*MobileUrgentSchedulePatientVM, error) {
  1931. var vms []*MobileUrgentSchedulePatientVM = make([]*MobileUrgentSchedulePatientVM, 0)
  1932. 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()
  1933. defer rows.Close()
  1934. if err != nil {
  1935. return nil, err
  1936. }
  1937. for rows.Next() {
  1938. var vm MobileUrgentSchedulePatientVM
  1939. readDb.ScanRows(rows, &vm)
  1940. vms = append(vms, &vm)
  1941. }
  1942. return vms, nil
  1943. }
  1944. func MobileGetAllTrearmentModesForUrgentSchedule() ([]*MobileUrgentScheduleTreatmentModeVM, error) {
  1945. var modes []*MobileUrgentScheduleTreatmentModeVM
  1946. err := readDb.Model(&MobileUrgentScheduleTreatmentModeVM{}).Where("status = 1").Find(&modes).Error
  1947. if err != nil {
  1948. return nil, err
  1949. }
  1950. return modes, nil
  1951. }
  1952. type MobileUrgentScheduleScheduleListVM struct {
  1953. ID int64 `gorm:"column:id" json:"id"`
  1954. // ZoneID int64 `gorm:"column:partition_id" json:"zone_id"`
  1955. DeviceNumberID int64 `gorm:"column:bed_id" json:"bed_id"`
  1956. PatientID int64 `gorm:"column:patient_id" json:"patient_id"`
  1957. ScheduleType int `gorm:"column:schedule_type" json:"schedule_type"`
  1958. DeviceNumber *models.DeviceNumber `gorm:"ForeignKey:DeviceNumberID" json:"device_number"`
  1959. // DeviceZone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"device_zone"`
  1960. }
  1961. func (MobileUrgentScheduleScheduleListVM) TableName() string {
  1962. return "xt_schedule"
  1963. }
  1964. func MobileGetSchedulesForUrgentSchedule(orgID int64, scheduleDate int64, schedule_type int) (schedules []*MobileUrgentScheduleScheduleListVM, err error) {
  1965. db := readDb.
  1966. Model(&MobileUrgentScheduleScheduleListVM{}).
  1967. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1968. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND schedule_type = ? ", orgID, scheduleDate, schedule_type)
  1969. err = db.Find(&schedules).Error
  1970. if err != nil {
  1971. return nil, err
  1972. }
  1973. return schedules, nil
  1974. }
  1975. func MobileGetOtherSchedulesForUrgentSchedule(orgID int64, scheduleDate int64, schedule_type int) ([]*MobileUrgentScheduleScheduleListVM, error) {
  1976. var vms []*MobileUrgentScheduleScheduleListVM = make([]*MobileUrgentScheduleScheduleListVM, 0)
  1977. 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()
  1978. defer rows.Close()
  1979. if err != nil {
  1980. return nil, err
  1981. }
  1982. for rows.Next() {
  1983. var vm MobileUrgentScheduleScheduleListVM
  1984. readDb.ScanRows(rows, &vm)
  1985. vms = append(vms, &vm)
  1986. }
  1987. return vms, nil
  1988. }
  1989. type MobileUrgentScheduleDeviceNumberVM struct {
  1990. ID int64 `gorm:"column:id" json:"id"`
  1991. Number string `gorm:"column:number" json:"number"`
  1992. ZoneID int64 `gorm:"column:zone_id" json:"zone_id"`
  1993. Zone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"zone"`
  1994. }
  1995. func (MobileUrgentScheduleDeviceNumberVM) TableName() string {
  1996. return "xt_device_number"
  1997. }
  1998. func MobileGetAllDeviceNumbersForUrgentSchedule(orgID int64, record_date int64, schedule_type int) ([]*DeviceNumberViewModel, error) {
  1999. var vms []*DeviceNumberViewModel = make([]*DeviceNumberViewModel, 0)
  2000. 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()
  2001. defer rows.Close()
  2002. if err != nil {
  2003. return nil, err
  2004. }
  2005. for rows.Next() {
  2006. var vm DeviceNumberViewModel
  2007. readDb.ScanRows(rows, &vm)
  2008. vms = append(vms, &vm)
  2009. }
  2010. return vms, nil
  2011. //var deviceNumbers []*MobileUrgentScheduleDeviceNumberVM
  2012. //db := readDb.
  2013. // Model(&MobileUrgentScheduleDeviceNumberVM{}).
  2014. // Preload("Zone", "status = 1 AND org_id = ?", orgID).
  2015. // Where("status = 1 AND org_id = ?", orgID)
  2016. //err := db.Order("zone_id asc").Find(&deviceNumbers).Error
  2017. //if err != nil {
  2018. // return nil, err
  2019. //}
  2020. //return deviceNumbers, nil
  2021. }
  2022. func GetValidScheduleMonitorRecordCount() (int64, error) {
  2023. var total int64
  2024. err := readDb.Model(&models.MonitoringRecord{}).Where("status = 1 AND operate_time = 0 AND monitoring_date <> 0").Count(&total).Error
  2025. return total, err
  2026. }
  2027. func GetTop1000ValidScheduleMonitorRecord() ([]*models.MonitoringRecord, error) {
  2028. var monitors []*models.MonitoringRecord
  2029. err := readDb.Model(&models.MonitoringRecord{}).Where("status = 1 AND operate_time = 0 AND monitoring_date <> 0").Order("id asc").Limit(100).Find(&monitors).Error
  2030. if err != nil {
  2031. return nil, err
  2032. }
  2033. return monitors, nil
  2034. }
  2035. func BatchUpdateMonitors(monitors []*models.MonitoringRecord) error {
  2036. tx := writeDb.Begin()
  2037. for index := 0; index < len(monitors); index++ {
  2038. tx.Save(monitors[index])
  2039. }
  2040. return tx.Commit().Error
  2041. }
  2042. func ModifyStartDialysisOrder(order *models.DialysisOrder) error {
  2043. tx := writeDb.Begin()
  2044. updateTime := time.Now().Unix()
  2045. 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, "dialysis_strainer": order.DialysisStrainer}).Error
  2046. if err != nil {
  2047. tx.Rollback()
  2048. return err
  2049. }
  2050. tx.Commit()
  2051. return err
  2052. }
  2053. func UpdateScheduleByBedId(patient_id int64, schedule_date int64, bed_id int64, schedule_type int64, zone_id int64) error {
  2054. err := XTWriteDB().Model(&models.XtSchedule{}).Where("patient_id = ? and schedule_date = ? and status=1", patient_id, schedule_date).Updates(map[string]interface{}{"bed_id": bed_id, "schedule_type": schedule_type, "partition_id": zone_id}).Error
  2055. return err
  2056. }
  2057. func ModifyFinishDialysisOrder(order *models.DialysisOrder) error {
  2058. tx := writeDb.Begin()
  2059. updateTime := time.Now().Unix()
  2060. 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
  2061. if err != nil {
  2062. tx.Rollback()
  2063. return err
  2064. }
  2065. tx.Commit()
  2066. return err
  2067. }
  2068. func MobileGetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  2069. var record models.SgjPatientDryweight
  2070. err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  2071. if err != nil {
  2072. if err == gorm.ErrRecordNotFound {
  2073. return nil, nil
  2074. } else {
  2075. return nil, err
  2076. }
  2077. }
  2078. return &record, nil
  2079. }
  2080. //func MobileGetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  2081. // var record models.SgjPatientDryweight
  2082. // redis := RedisClient()
  2083. // defer redis.Close()
  2084. //
  2085. // key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":last_dry_weight"
  2086. // last_dry_weight_str, _ := redis.Get(key).Result()
  2087. //
  2088. // if len(last_dry_weight_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2089. // err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  2090. // if err != nil {
  2091. // if err == gorm.ErrRecordNotFound {
  2092. // if record.ID <= 0 {
  2093. // redis.Set(key, "null", time.Second*60*60*18)
  2094. // }
  2095. // return nil, nil
  2096. // } else {
  2097. // return nil, err
  2098. // }
  2099. // } else {
  2100. // if record.ID > 0 {
  2101. // //缓存数据
  2102. // last_dry_weight_str, err := json.Marshal(record)
  2103. // if err == nil {
  2104. // redis.Set(key, last_dry_weight_str, time.Second*60*60*18)
  2105. // return nil, err
  2106. // }
  2107. // } else {
  2108. // redis.Set(key, "null", time.Second*60*60*18)
  2109. // return nil, err
  2110. // }
  2111. // return &record, nil
  2112. // }
  2113. // } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2114. // if last_dry_weight_str == "null" {
  2115. // return &record, nil
  2116. // } else {
  2117. // json.Unmarshal([]byte(last_dry_weight_str), &record)
  2118. // return &record, nil
  2119. // }
  2120. //
  2121. // }
  2122. //}
  2123. // 透析方案
  2124. func MobileGetDialysisSolutionByModeIdSix(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  2125. var record models.DialysisSolution
  2126. 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
  2127. if err != nil {
  2128. if err == gorm.ErrRecordNotFound {
  2129. return nil, nil
  2130. } else {
  2131. return nil, err
  2132. }
  2133. }
  2134. return &record, nil
  2135. }
  2136. // 透析方案
  2137. func MobileGetDialysisSolutionByModeIdSevenTwety(orgID int64, patientID int64, mode_id int64) (models.DialysisSolution, error) {
  2138. var record models.DialysisSolution
  2139. 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
  2140. return record, nil
  2141. }
  2142. // 透析方案
  2143. func MobileGetDialysisSolutionByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  2144. var record models.DialysisSolution
  2145. redis := RedisClient()
  2146. defer redis.Close()
  2147. // cur_date := time.Now().Format("2006-01-02")
  2148. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2149. dialysis_solution_str, _ := redis.Get(key).Result()
  2150. redis.Set(key, "", time.Second*60)
  2151. if len(dialysis_solution_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2152. 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
  2153. if err != nil {
  2154. if err == gorm.ErrRecordNotFound {
  2155. if record.ID <= 0 {
  2156. redis.Set(key, "null", time.Second*60*60*18)
  2157. }
  2158. return nil, nil
  2159. } else {
  2160. return nil, err
  2161. }
  2162. } else {
  2163. if record.ID > 0 {
  2164. //缓存数据
  2165. dialysis_solution_str, err := json.Marshal(record)
  2166. if err == nil {
  2167. redis.Set(key, dialysis_solution_str, time.Second*60*60*18)
  2168. }
  2169. } else {
  2170. redis.Set(key, "null", time.Second*60*60*18)
  2171. }
  2172. return &record, nil
  2173. }
  2174. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2175. if dialysis_solution_str == "null" {
  2176. return &record, nil
  2177. } else {
  2178. json.Unmarshal([]byte(dialysis_solution_str), &record)
  2179. return &record, nil
  2180. }
  2181. }
  2182. }
  2183. // 透析处方
  2184. func MobileGetDialysisPrescribeByModeId(orgID int64, patientID int64, recordDate int64, mode_id int64) (*models.DialysisPrescription, error) {
  2185. var record models.DialysisPrescription
  2186. redis := RedisClient()
  2187. defer redis.Close()
  2188. // cur_date := time.Now().Format("2006-01-02")
  2189. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2190. redis.Set(key, "", time.Second)
  2191. dialysis_prescribe_str, _ := redis.Get(key).Result()
  2192. if len(dialysis_prescribe_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2193. 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
  2194. if err != nil {
  2195. if err == gorm.ErrRecordNotFound {
  2196. if record.ID <= 0 {
  2197. redis.Set(key, "null", time.Second*60*60*18)
  2198. }
  2199. return nil, nil
  2200. } else {
  2201. return nil, err
  2202. }
  2203. } else {
  2204. if record.ID > 0 {
  2205. //缓存数据
  2206. dialysis_prescribe_str, err := json.Marshal(record)
  2207. if err == nil {
  2208. redis.Set(key, dialysis_prescribe_str, time.Second*60*60*18)
  2209. }
  2210. } else {
  2211. redis.Set(key, "null", time.Second*60*60*18)
  2212. }
  2213. return &record, nil
  2214. }
  2215. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2216. if dialysis_prescribe_str == "null" {
  2217. return &record, nil
  2218. } else {
  2219. json.Unmarshal([]byte(dialysis_prescribe_str), &record)
  2220. return &record, nil
  2221. }
  2222. }
  2223. }
  2224. func MobileGetDialysisPrescribeByModeIdSix(orgID int64, patientID int64, recordDate int64, mode_id int64) (*models.DialysisPrescription, error) {
  2225. var record models.DialysisPrescription
  2226. 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
  2227. if err != nil {
  2228. if err == gorm.ErrRecordNotFound {
  2229. return nil, nil
  2230. } else {
  2231. return nil, err
  2232. }
  2233. }
  2234. return &record, nil
  2235. }
  2236. func MobileGetDialysisPrescribeByModeIdOne(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  2237. var record models.DialysisPrescription
  2238. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  2239. if err != nil {
  2240. if err == gorm.ErrRecordNotFound {
  2241. return nil, nil
  2242. } else {
  2243. return nil, err
  2244. }
  2245. }
  2246. return &record, nil
  2247. }
  2248. //func MobileGetDialysisPrescribeByModeIdOne(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  2249. // var record models.DialysisPrescription
  2250. // redis := RedisClient()
  2251. // defer redis.Close()
  2252. //
  2253. // // cur_date := time.Now().Format("2006-01-02")
  2254. // key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":dialysis_prescribe_by_mode"
  2255. // dialysis_prescribe_by_mode_str, _ := redis.Get(key).Result()
  2256. //
  2257. // if len(dialysis_prescribe_by_mode_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2258. // err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  2259. // if err != nil {
  2260. // if err == gorm.ErrRecordNotFound {
  2261. // if record.ID <= 0 {
  2262. // redis.Set(key, "null", time.Second*60*60*18)
  2263. // }
  2264. // return nil, nil
  2265. // } else {
  2266. // return nil, err
  2267. // }
  2268. // } else {
  2269. //
  2270. // if record.ID > 0 {
  2271. // //缓存数据
  2272. // dialysis_prescribe_by_mode_str, err := json.Marshal(record)
  2273. //
  2274. // if err == nil {
  2275. // redis.Set(key, dialysis_prescribe_by_mode_str, time.Second*60*60*18)
  2276. // return nil, err
  2277. // }
  2278. // } else {
  2279. // redis.Set(key, "null", time.Second*60*60*18)
  2280. // return nil, err
  2281. // }
  2282. // return &record, nil
  2283. // }
  2284. // } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2285. // if dialysis_prescribe_by_mode_str == "null" {
  2286. // json.Unmarshal([]byte(dialysis_prescribe_by_mode_str), &record)
  2287. // return &record, nil
  2288. // } else {
  2289. // json.Unmarshal([]byte(dialysis_prescribe_by_mode_str), &record)
  2290. // return &record, nil
  2291. // }
  2292. //
  2293. // }
  2294. //}
  2295. func MobileGetLastDialysisPrescribe(orgID int64, patientID 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 ", patientID, orgID).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, nil
  2306. }
  2307. func MobileGetLastDialysisPrescribeByModeIdSix(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2308. var record models.DialysisPrescription
  2309. 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
  2310. //if err != nil {
  2311. // if err == gorm.ErrRecordNotFound {
  2312. // return nil, nil
  2313. // } else {
  2314. // return nil, err
  2315. // }
  2316. //}
  2317. return &record, err
  2318. }
  2319. func MobileGetLastDialysisPrescribeByModeIdTen(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2320. var record models.DialysisPrescription
  2321. 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
  2322. if err != nil {
  2323. if err == gorm.ErrRecordNotFound {
  2324. return nil, nil
  2325. } else {
  2326. return nil, err
  2327. }
  2328. }
  2329. return &record, err
  2330. }
  2331. func MobileGetLastDialysisPrescribeByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2332. var record models.DialysisPrescription
  2333. redis := RedisClient()
  2334. defer redis.Close()
  2335. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  2336. dialysis_prescribe_by_mode_id, _ := redis.Get(key).Result()
  2337. if len(dialysis_prescribe_by_mode_id) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2338. 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
  2339. if err != nil {
  2340. if err == gorm.ErrRecordNotFound {
  2341. if record.ID <= 0 {
  2342. redis.Set(key, "null", time.Second*60*60*18)
  2343. }
  2344. return nil, nil
  2345. } else {
  2346. return nil, err
  2347. }
  2348. } else {
  2349. if record.ID > 0 {
  2350. //缓存数据
  2351. dialysis_prescribe_by_mode_str, err := json.Marshal(record)
  2352. if err == nil {
  2353. redis.Set(key, dialysis_prescribe_by_mode_str, time.Second*60*60*18)
  2354. return nil, err
  2355. }
  2356. } else {
  2357. redis.Set(key, "null", time.Second*60*60*18)
  2358. return nil, err
  2359. }
  2360. return &record, nil
  2361. }
  2362. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2363. if dialysis_prescribe_by_mode_id == "null" {
  2364. return &record, nil
  2365. } else {
  2366. json.Unmarshal([]byte(dialysis_prescribe_by_mode_id), &record)
  2367. return &record, nil
  2368. }
  2369. }
  2370. }
  2371. func MobileGetLastDialysisPrescribeByModeIdOne(orgID int64, patientID int64, mode_id int64) (models.DialysisPrescription, error) {
  2372. var record models.DialysisPrescription
  2373. 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
  2374. return record, err
  2375. }
  2376. func GetAllAvaildDeviceNumbers(orgID int64, record_date int64, schedule_type int) ([]*DeviceNumberViewModel, error) {
  2377. var vms []*DeviceNumberViewModel = make([]*DeviceNumberViewModel, 0)
  2378. 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()
  2379. defer rows.Close()
  2380. if err != nil {
  2381. return nil, err
  2382. }
  2383. for rows.Next() {
  2384. var vm DeviceNumberViewModel
  2385. readDb.ScanRows(rows, &vm)
  2386. vms = append(vms, &vm)
  2387. }
  2388. return vms, nil
  2389. }
  2390. // 获取 maxDate 之前一次的透前评估记录
  2391. func GetLastTimePredialysisEvaluation(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
  2392. var record models.PredialysisEvaluation
  2393. 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
  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. func GetLastTimeOrder(orgID int64, patientID int64, maxDate int64) (*models.DialysisOrder, error) {
  2404. var record models.DialysisOrder
  2405. 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
  2406. if err != nil {
  2407. if err == gorm.ErrRecordNotFound {
  2408. return nil, nil
  2409. } else {
  2410. return nil, err
  2411. }
  2412. }
  2413. return &record, nil
  2414. }
  2415. func GetLastMonitorRecord(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  2416. var record models.MonitoringRecord
  2417. 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
  2418. if err != nil {
  2419. if err == gorm.ErrRecordNotFound {
  2420. return nil, nil
  2421. } else {
  2422. return nil, err
  2423. }
  2424. }
  2425. return &record, nil
  2426. }
  2427. func GetLastMonitorRecordTwenty(orgID int64, patientID int64, beforeDate int64) (models.MonitoringRecord, error) {
  2428. var record models.MonitoringRecord
  2429. err = readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ? and ultrafiltration_volume_one!=''", patientID, orgID, beforeDate).Order("operate_time desc").First(&record).Error
  2430. return record, nil
  2431. }
  2432. func GetLastMonitorRecordTwentyOne(orgID int64, patientID int64, beforeDate int64) (models.MonitoringRecord, error) {
  2433. var record models.MonitoringRecord
  2434. err = readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ? and monitor_systolic_blood_pressure_one!=''", patientID, orgID, beforeDate).Order("operate_time desc").First(&record).Error
  2435. return record, nil
  2436. }
  2437. func GetLastMonitorRecordTwentyTwo(orgID int64, patientID int64, beforeDate int64) (models.MonitoringRecord, error) {
  2438. var record models.MonitoringRecord
  2439. err = readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ? and monitor_diastolic_blood_pressure_one!=''", patientID, orgID, beforeDate).Order("operate_time desc").First(&record).Error
  2440. return record, nil
  2441. }
  2442. func GetLastMonitorRecordTwentyThree(orgID int64, patientID int64, beforeDate int64) (models.MonitoringRecord, error) {
  2443. var record models.MonitoringRecord
  2444. err = readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ? and pulse_frequency_one!=''", patientID, orgID, beforeDate).Order("operate_time desc").First(&record).Error
  2445. return record, nil
  2446. }
  2447. func GetLastMonitorRecordTwentyFour(orgID int64, patientID int64, beforeDate int64) (models.MonitoringRecord, error) {
  2448. var record models.MonitoringRecord
  2449. err = readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ? and displacement_quantity_one!=''", patientID, orgID, beforeDate).Order("operate_time desc").First(&record).Error
  2450. return record, nil
  2451. }
  2452. // 获取 maxDate 之前一次的透后评估记录
  2453. func GetLastTimeAssessmentAfterDislysis(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  2454. var record models.AssessmentAfterDislysis
  2455. 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
  2456. if err != nil {
  2457. if err == gorm.ErrRecordNotFound {
  2458. return nil, nil
  2459. } else {
  2460. return nil, err
  2461. }
  2462. }
  2463. return &record, nil
  2464. }
  2465. // 透析处方
  2466. func GetDialysisPrescribe(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  2467. var record models.DialysisPrescription
  2468. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  2469. if err != nil {
  2470. if err == gorm.ErrRecordNotFound {
  2471. return nil, nil
  2472. } else {
  2473. return nil, err
  2474. }
  2475. }
  2476. return &record, nil
  2477. }
  2478. func GetDialysisPrescribeOne(orgID int64, patientID int64, recordDate int64) (models.DialysisPrescription, error) {
  2479. var record models.DialysisPrescription
  2480. err = readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  2481. return record, err
  2482. }
  2483. // 透析方案
  2484. func GetDialysisSolution(orgID int64, patientID int64, mode_id int64) (models.DialysisSolution, error) {
  2485. var record models.DialysisSolution
  2486. 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
  2487. return record, err
  2488. }
  2489. func GetDialysisSolutionOne(orgID int64, mode_id int64) (*models.DialysisSolution, error) {
  2490. var record models.DialysisSolution
  2491. err := readDb.Model(&models.DialysisSolution{}).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. return nil, nil
  2495. } else {
  2496. return nil, err
  2497. }
  2498. }
  2499. return &record, nil
  2500. }
  2501. func GetLastDialysisPrescribeByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2502. var record models.DialysisPrescription
  2503. 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
  2504. if err != nil {
  2505. if err == gorm.ErrRecordNotFound {
  2506. return nil, nil
  2507. } else {
  2508. return nil, err
  2509. }
  2510. }
  2511. return &record, nil
  2512. }
  2513. func GetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  2514. var record models.SgjPatientDryweight
  2515. err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  2516. if err != nil {
  2517. if err == gorm.ErrRecordNotFound {
  2518. return nil, nil
  2519. } else {
  2520. return nil, err
  2521. }
  2522. }
  2523. return &record, nil
  2524. }
  2525. func MobileGetSystemDialysisPrescribeByModeIdSix(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2526. var record models.SystemPrescription
  2527. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).First(&record).Error
  2528. if err != nil {
  2529. if err == gorm.ErrRecordNotFound {
  2530. return nil, nil
  2531. } else {
  2532. return nil, err
  2533. }
  2534. }
  2535. return &record, nil
  2536. }
  2537. func MobileGetSystemDialysisPrescribeByModeId(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2538. var record models.SystemPrescription
  2539. redis := RedisClient()
  2540. defer redis.Close()
  2541. // cur_date := time.Now().Format("2006-01-02")
  2542. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  2543. system_dialysis_prescribe_str, _ := redis.Get(key).Result()
  2544. if len(system_dialysis_prescribe_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2545. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2546. if err != nil {
  2547. if err == gorm.ErrRecordNotFound {
  2548. if record.ID <= 0 {
  2549. redis.Set(key, "null", time.Second*60*60*18)
  2550. }
  2551. return nil, nil
  2552. } else {
  2553. return nil, err
  2554. }
  2555. } else {
  2556. if record.ID > 0 {
  2557. //缓存数据
  2558. system_dialysis_prescribe_str, err := json.Marshal(record)
  2559. if err == nil {
  2560. redis.Set(key, system_dialysis_prescribe_str, time.Second*60*60*18)
  2561. }
  2562. } else {
  2563. redis.Set(key, "null", time.Second*60*60*18)
  2564. }
  2565. return &record, nil
  2566. }
  2567. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2568. if system_dialysis_prescribe_str == "null" {
  2569. return &record, nil
  2570. } else {
  2571. json.Unmarshal([]byte(system_dialysis_prescribe_str), &record)
  2572. return &record, nil
  2573. }
  2574. }
  2575. }
  2576. func MobileGetSystemDialysisPrescribeByModeIdOne(orgID int64, mode_id int64) (models.SystemPrescription, error) {
  2577. var record models.SystemPrescription
  2578. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2579. return record, err
  2580. }
  2581. func GetSystemDialysisPrescribeByModeId(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2582. var record models.SystemPrescription
  2583. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2584. if err != nil {
  2585. if err == gorm.ErrRecordNotFound {
  2586. return nil, nil
  2587. } else {
  2588. return nil, err
  2589. }
  2590. }
  2591. return &record, nil
  2592. }
  2593. func GetDialysisOrderCount(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2594. 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
  2595. return
  2596. }
  2597. func GetDialysisOrderCountOne(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2598. 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
  2599. return
  2600. }
  2601. func GetDialysisOrderCountTwo(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2602. 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
  2603. return
  2604. }
  2605. func GetFirstDateOfMonth(d time.Time) time.Time {
  2606. d = d.AddDate(0, 0, -d.Day()+1)
  2607. return GetZeroTime(d)
  2608. }
  2609. func GetZeroTime(d time.Time) time.Time {
  2610. return time.Date(d.Year(), d.Month(), d.Day(), 0, 0, 0, 0, d.Location())
  2611. }
  2612. func GetDialysisCountByPatientId(startime int64, endtime int64, patientid int64, orgid int64) (order []*models.BloodDialysisOrderCount, err error) {
  2613. db := XTReadDB().Table("xt_dialysis_order as o")
  2614. 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
  2615. return order, err
  2616. }
  2617. func FindConsumablesByDate(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error) {
  2618. 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
  2619. return
  2620. }
  2621. func FindConsumablesByDateTwo(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error) {
  2622. 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
  2623. return
  2624. }
  2625. func FindConsumablesByDateThree(orgID int64, patient_id int64, recordDate int64) (consumables []*models.BloodAutomaticReduceDetail, err error) {
  2626. 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
  2627. return
  2628. }
  2629. func FindHisPrescription(orgID int64, patient_id int64, recordDate int64) (project []*models.HisPrescriptionProject, err error) {
  2630. err = readDb.Model(&models.HisPrescriptionProject{}).Where("user_org_id = ? AND patient_id = ? AND record_date = ? AND status = 1 and type =3", orgID, patient_id, recordDate).Find(&project).Error
  2631. return
  2632. }
  2633. //func FindLastConsumables(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error){
  2634. // 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
  2635. // return
  2636. //}
  2637. //
  2638. func GetLastTimeConsumables(orgID int64, patientID int64, maxDate int64) (prepare []*models.DialysisBeforePrepare, err error) {
  2639. 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
  2640. return
  2641. }
  2642. type GoodsType struct {
  2643. ID int64 `gorm:"column:id" json:"id"`
  2644. TypeName string `gorm:"column:type_name" json:"type_name"`
  2645. Remark string `gorm:"column:remark" json:"remark"`
  2646. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2647. Status int64 `gorm:"column:status" json:"status"`
  2648. Type int64 `gorm:"column:type" json:"type"`
  2649. }
  2650. func (GoodsType) TableName() string {
  2651. return "xt_goods_type"
  2652. }
  2653. type VMGoodInfo struct {
  2654. ID int64 `gorm:"column:id" json:"id"`
  2655. SpecificationName string `gorm:"column:specification_name" json:"specification_name"`
  2656. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2657. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2658. GoodName string `gorm:"column:good_name" json:"good_name" form:"good_name"`
  2659. GoodUnit int64 `gorm:"column:good_unit" json:"good_unit" form:"good_unit"`
  2660. Total float64 `gorm:"column:total" json:"total" form:"total"`
  2661. PackingUnit string `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
  2662. MedicalInsuranceNumber string `gorm:"column:medical_insurance_number" json:"medical_insurance_number" form:"medical_insurance_number"`
  2663. }
  2664. func (VMGoodInfo) TableName() string {
  2665. return "xt_good_information"
  2666. }
  2667. type AutomaticReduceDetail struct {
  2668. ID int64 `gorm:"column:id" json:"id"`
  2669. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2670. Status int64 `gorm:"column:status" json:"status"`
  2671. RecordTime int64 `gorm:"column:record_time" json:"record_time"`
  2672. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2673. GoodId int64 `gorm:"column:good_id" json:"good_id"`
  2674. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2675. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"info"`
  2676. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"type"`
  2677. Count int64 `gorm:"column:count" json:"count"`
  2678. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  2679. }
  2680. func (AutomaticReduceDetail) TableName() string {
  2681. return "xt_automatic_reduce_detail"
  2682. }
  2683. type DialysisBeforePrepare struct {
  2684. ID int64 `gorm:"column:id" json:"id" form:"id"`
  2685. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  2686. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  2687. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  2688. GoodId int64 `gorm:"column:good_id" json:"good_id" form:"good_id"`
  2689. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id" form:"good_type_id"`
  2690. Count int64 `gorm:"column:count" json:"count" form:"count"`
  2691. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  2692. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  2693. Creater int64 `gorm:"column:creater" json:"creater" form:"creater"`
  2694. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  2695. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"info"`
  2696. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"type"`
  2697. }
  2698. func (DialysisBeforePrepare) TableName() string {
  2699. return "dialysis_before_prepare"
  2700. }
  2701. type MDialysisGoodsVM struct {
  2702. ID int64 `gorm:"column:id" json:"id"`
  2703. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2704. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2705. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2706. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2707. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2708. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2709. ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week"`
  2710. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2711. Status int64 `gorm:"column:status" json:"status"`
  2712. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2713. SchedualPatient *MSchedualPatientVMList `gorm:"ForeignKey:PatientId" json:"patient"`
  2714. AutomaticReduceDetail []*AutomaticReduceDetail `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"good_user"`
  2715. LastAutomaticReduceDetail []*AutomaticReduceDetail `gorm:"-" json:"last_good_user"`
  2716. DialysisBeforePrepare []*DialysisBeforePrepare `gorm:"ForeignKey:PatientId,ScheduleDate;AssociationForeignKey:PatientId,RecordDate" json:"good_user_detail"`
  2717. LastDialysisBeforePrepare []*DialysisBeforePrepare `gorm:"-" json:"last_good_user_detail"`
  2718. Project []*models.HisPrescriptionProject `gorm:"-" json:"project"`
  2719. //WarehouseOutInfo []*models.WarehouseOutInfoSeven `gorm:"ForeignKey:PatientId,ScheduleDate;AssociationForeignKey:PatientId,SysRecordTime" json:"ware_house_out_info"`
  2720. DialysisPrescription models.DialysisPrescriptionListSix `gorm:"ForeignKey:PatientId,ModeId;AssociationForeignKey:PatientId,ModeId" json:"prescription"`
  2721. }
  2722. func (MDialysisGoodsVM) TableName() string {
  2723. return "xt_schedule"
  2724. }
  2725. type VMWarehouseOutInfo struct {
  2726. ID int64 `gorm:"column:id" json:"id"`
  2727. WarehouseOutId int64 `gorm:"column:warehouse_out_id" json:"warehouse_out_id"`
  2728. GoodId int64 `gorm:"column:good_id" json:"good_id"`
  2729. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2730. Count int64 `gorm:"column:count" json:"count"`
  2731. Price float64 `gorm:"column:price" json:"price"`
  2732. TotalPrice float64 `gorm:"column:total_price" json:"total_price"`
  2733. Status int64 `gorm:"column:status" json:"status"`
  2734. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2735. WarehouseOutOrderNumber string `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number"`
  2736. GoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"good_info"`
  2737. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"good_type"`
  2738. IsSys int64 `gorm:"column:is_sys" json:"is_sys"`
  2739. SysRecordTime int64 `gorm:"column:sys_record_time" json:"sys_record_time"`
  2740. Mtime int64 `gorm:"column:mtime" json:"mtime"`
  2741. Ctime int64 `gorm:"column:ctime" json:"ctime"`
  2742. }
  2743. func (VMWarehouseOutInfo) TableName() string {
  2744. return "xt_warehouse_out_info"
  2745. }
  2746. type DialysisGoodsDate struct {
  2747. RecordDate int64
  2748. }
  2749. type DialysisGoodsDetailDate struct {
  2750. RecordTime int64
  2751. }
  2752. 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) {
  2753. var vms []*MDialysisGoodsVM
  2754. var total int64
  2755. db := readDb.
  2756. Table("xt_schedule as sch").
  2757. Preload("DialysisPrescription", "status=1 and user_org_id =? and solution_status = 1", orgID).
  2758. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  2759. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2760. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2761. Preload("DialysisBeforePrepare", func(db *gorm.DB) *gorm.DB {
  2762. 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)
  2763. }).
  2764. Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
  2765. 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")
  2766. }).Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
  2767. if scheduleDate != 0 {
  2768. db = db.Where("schedule_date = ?", scheduleDate)
  2769. }
  2770. if schedule_type != 0 {
  2771. db = db.Where("schedule_type = ?", schedule_type)
  2772. }
  2773. if partition_id != 0 {
  2774. db = db.Where("partition_id = ?", partition_id)
  2775. }
  2776. if patient_id != 0 {
  2777. db = db.Where("patient_id = ?", patient_id)
  2778. }
  2779. err := db.Find(&vms).Error
  2780. return vms, err, total
  2781. }
  2782. func GetLastDialysisGoods(patient_id int64, orgID int64, record_time int64) (goodUser []*AutomaticReduceDetail, err error) {
  2783. var Id []*DialysisGoodsDetailDate
  2784. 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
  2785. if len(Id) > 0 {
  2786. 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
  2787. }
  2788. return
  2789. }
  2790. func GetLastDialysisBeforePrepare(patient_id int64, orgID int64, record_time int64) (goodUser []*DialysisBeforePrepare, err error) {
  2791. var Id []*DialysisGoodsDate
  2792. 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
  2793. if len(Id) > 0 {
  2794. 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
  2795. }
  2796. return
  2797. }
  2798. func GetPatientAutoMatic(patient_id int64, orgID int64, record_time int64, good_id int64) (auto []*models.AutomaticReduceDetail, err error) {
  2799. err = XTReadDB().Where("patient_id = ? and org_id = ? and record_time = ? and good_id =? and status=1", patient_id, orgID, record_time, good_id).Find(&auto).Error
  2800. return auto, err
  2801. }
  2802. func GetAllWarehouseOutSumList(patient_id int64, orgID int64, record_time int64) (info []*models.WarehouseOutInfoSeven, err error) {
  2803. err = XTReadDB().Where("patient_id = ? and org_id = ? and sys_record_time = ? and status = 1", patient_id, orgID, record_time).Preload("GoodInfo", "status=1 and org_id = ?", orgID).Find(&info).Error
  2804. return info, err
  2805. }
  2806. func MobileGetGoodsStatistics(orgID int64, start_time int64, end_time int64) (list []*models.StockInfo, err error) {
  2807. db := readDb.Model(&models.StockInfo{})
  2808. db = db.Where("xt_good_information.org_id = ? AND xt_good_information.status = 1", orgID)
  2809. 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")
  2810. db = db.Preload("QueryWarehouseOutInfo", func(db *gorm.DB) *gorm.DB {
  2811. 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)
  2812. })
  2813. db = db.Preload("GoodsType", "org_id = ? AND status = 1", orgID)
  2814. err = db.Order("ctime desc").Find(&list).Error
  2815. return
  2816. }
  2817. 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) {
  2818. var vms []*MDialysisGoodsVM
  2819. var total int64
  2820. db := readDb.
  2821. Model(&models.Schedule{}).
  2822. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  2823. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2824. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2825. Preload("DialysisBeforePrepare", func(db *gorm.DB) *gorm.DB {
  2826. 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)
  2827. }).Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
  2828. 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)
  2829. }).Where("xt_schedule.status = 1 AND xt_schedule.user_org_id = ?", orgID)
  2830. if scheduleDate != 0 {
  2831. db = db.Where("schedule_date = ?", scheduleDate)
  2832. }
  2833. if patient_id != 0 {
  2834. db = db.Where("patient_id = ?", patient_id)
  2835. }
  2836. if len(keywords) != 0 {
  2837. keywords = "%" + keywords + "%"
  2838. 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)
  2839. if schedule_type != 0 {
  2840. db = db.Where("schedule_type = ?", schedule_type)
  2841. }
  2842. if partition_id != 0 {
  2843. db = db.Where("partition_id = ?", partition_id)
  2844. }
  2845. if good_type == 1 {
  2846. db = db.Where("patient_id in(?)", ids)
  2847. }
  2848. if good_type == 2 {
  2849. if len(ids) > 0 {
  2850. db = db.Where("patient_id not in(?)", ids)
  2851. }
  2852. }
  2853. } else {
  2854. if schedule_type != 0 {
  2855. db = db.Where("schedule_type = ?", schedule_type)
  2856. }
  2857. if partition_id != 0 {
  2858. db = db.Where("partition_id = ?", partition_id)
  2859. }
  2860. if good_type == 1 {
  2861. db = db.Where("patient_id in(?)", ids)
  2862. }
  2863. if good_type == 2 {
  2864. if len(ids) > 0 {
  2865. db = db.Where("patient_id not in(?)", ids)
  2866. }
  2867. }
  2868. db = db.Count(&total)
  2869. offset := (page - 1) * limit
  2870. db = db.Offset(offset).Limit(limit)
  2871. }
  2872. err := db.Find(&vms).Error
  2873. return vms, err, total
  2874. }
  2875. func GetLastDialysisGoodsTwo(patient_id int64, orgID int64, record_time int64) (goodUser []*AutomaticReduceDetail, err error) {
  2876. var Id []*DialysisGoodsDetailDate
  2877. 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
  2878. if len(Id) > 0 {
  2879. 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
  2880. }
  2881. return
  2882. }
  2883. func GetLastDialysisBeforePrepareTwo(patient_id int64, orgID int64, record_time int64) (goodUser []*DialysisBeforePrepare, err error) {
  2884. var Id []*DialysisGoodsDate
  2885. 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
  2886. if len(Id) > 0 {
  2887. 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
  2888. }
  2889. return
  2890. }
  2891. func GetAssessmentBefor(orgid int64, patientid int64, recorddate int64) (*models.PredialysisEvaluation, error) {
  2892. evaluation := models.PredialysisEvaluation{}
  2893. err := XTReadDB().Model(&evaluation).Where("user_org_id = ? and patient_id = ? and assessment_date = ? and status = 1", orgid, patientid, recorddate).Find(&evaluation).Error
  2894. if err == gorm.ErrRecordNotFound {
  2895. return nil, err
  2896. }
  2897. if err != nil {
  2898. return nil, err
  2899. }
  2900. return &evaluation, nil
  2901. }
  2902. func GetAssessmentBeforThrity(orgid int64, patientid int64, recorddate int64) (models.PredialysisEvaluation, error) {
  2903. evaluation := models.PredialysisEvaluation{}
  2904. err := XTReadDB().Model(&evaluation).Where("user_org_id = ? and patient_id = ? and assessment_date = ? and status = 1", orgid, patientid, recorddate).Find(&evaluation).Error
  2905. return evaluation, err
  2906. }
  2907. func GetAssessmentBeforFourty(orgid int64, patientid int64, recorddate int64) (models.XtAssessmentBeforeDislysis, error) {
  2908. evaluation := models.XtAssessmentBeforeDislysis{}
  2909. err := XTReadDB().Model(&evaluation).Where("user_org_id = ? and patient_id = ? and assessment_date = ? and status = 1", orgid, patientid, recorddate).Find(&evaluation).Error
  2910. return evaluation, err
  2911. }
  2912. func GetHisPrescriptionTemplateList(user_org_id int64, patient_id int64, mode_id int64) (models.HisPrescriptionTemplateSix, error) {
  2913. templateSix := models.HisPrescriptionTemplateSix{}
  2914. err := XTReadDB().Where("user_org_id = ? and patient_id = ? and mode = ? and status =1", user_org_id, patient_id, mode_id).Preload("HisPrescriptionInfoTemplateSix", func(db *gorm.DB) *gorm.DB {
  2915. return db.Where("status = 1 AND user_org_id = ? and type =2", user_org_id).Preload("HisPrescriptionProjectTemplateSeven", func(db *gorm.DB) *gorm.DB {
  2916. return db.Where("status = 1 AND user_org_id = ? and type =3", user_org_id).Preload("GoodInfo", "org_id = ? and status=1 ", user_org_id)
  2917. })
  2918. }).Find(&templateSix).Error
  2919. return templateSix, err
  2920. }
  2921. func GetAllHisDoctorAdvice(orgid int64, patientid int64, recorddate int64) (his []*models.HisDoctorAdviceInfo, err error) {
  2922. redis := RedisClient()
  2923. defer redis.Close()
  2924. key := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patientid, 10) + ":" + strconv.FormatInt(recorddate, 10) + ":his_doctor_advice"
  2925. his_doctor_advice_str, _ := redis.Get(key).Result()
  2926. redis.Set(key, "", time.Second)
  2927. if orgid != 10721 {
  2928. if len(his_doctor_advice_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2929. 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
  2930. if err != nil {
  2931. if err == gorm.ErrRecordNotFound {
  2932. if len(his) <= 0 {
  2933. redis.Set(key, "null", time.Second*60*60*18)
  2934. }
  2935. return his, nil
  2936. } else {
  2937. return his, err
  2938. }
  2939. } else {
  2940. if len(his) > 0 {
  2941. //缓存数据
  2942. his_doctor_advice_str, err := json.Marshal(his)
  2943. if err == nil {
  2944. redis.Set(key, his_doctor_advice_str, time.Second*60*60*18)
  2945. }
  2946. } else {
  2947. redis.Set(key, "null", time.Second*60*60*18)
  2948. }
  2949. return his, nil
  2950. }
  2951. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2952. json.Unmarshal([]byte(his_doctor_advice_str), &his)
  2953. return his, nil
  2954. }
  2955. }
  2956. if orgid == 10721 {
  2957. if len(his_doctor_advice_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2958. err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date = ? and execution_frequency!='上机前' and delivery_way!='口服' ", patientid, orgid, recorddate).Order("created_time asc").Find(&his).Error
  2959. if err != nil {
  2960. if err == gorm.ErrRecordNotFound {
  2961. if len(his) <= 0 {
  2962. redis.Set(key, "null", time.Second*60*60*18)
  2963. }
  2964. return his, nil
  2965. } else {
  2966. return his, err
  2967. }
  2968. } else {
  2969. if len(his) > 0 {
  2970. //缓存数据
  2971. his_doctor_advice_str, err := json.Marshal(his)
  2972. if err == nil {
  2973. redis.Set(key, his_doctor_advice_str, time.Second*60*60*18)
  2974. }
  2975. } else {
  2976. redis.Set(key, "null", time.Second*60*60*18)
  2977. }
  2978. return his, nil
  2979. }
  2980. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2981. json.Unmarshal([]byte(his_doctor_advice_str), &his)
  2982. return his, nil
  2983. }
  2984. }
  2985. return his, nil
  2986. }
  2987. func GetLastDialysisPrescriptionByPatientId(orgid int64, patientid int64, recorddate int64) (*models.DialysisPrescription, error) {
  2988. prescription := models.DialysisPrescription{}
  2989. err := readDb.Model(&models.DialysisPrescription{}).Where("user_org_id = ? and patient_id = ? and record_date = ? and status = 1", orgid, patientid, recorddate).Find(&prescription).Error
  2990. if err == gorm.ErrRecordNotFound {
  2991. return nil, err
  2992. }
  2993. if err != nil {
  2994. return nil, err
  2995. }
  2996. return &prescription, nil
  2997. }
  2998. func GetLastDialysisPrescriptionByPatientIdTwo(orgid int64, patientid int64, recorddate int64) (models.DialysisPrescription, error) {
  2999. prescription := models.DialysisPrescription{}
  3000. err := readDb.Model(&models.DialysisPrescription{}).Where("user_org_id = ? and patient_id = ? and record_date = ? and status = 1", orgid, patientid, recorddate).Find(&prescription).Error
  3001. return prescription, err
  3002. }
  3003. type HisMScheduleDoctorAdviceVM struct {
  3004. ID int64 `gorm:"column:id" json:"id"`
  3005. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  3006. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  3007. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  3008. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  3009. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  3010. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  3011. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  3012. Status int64 `gorm:"column:status" json:"status"`
  3013. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  3014. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  3015. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  3016. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  3017. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  3018. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  3019. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  3020. }
  3021. func (HisMScheduleDoctorAdviceVM) TableName() string {
  3022. return "xt_schedule"
  3023. }
  3024. type HisMScheduleDoctorAdviceVMOne struct {
  3025. ID int64 `gorm:"column:id" json:"id"`
  3026. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  3027. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  3028. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  3029. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  3030. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  3031. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  3032. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  3033. Status int64 `gorm:"column:status" json:"status"`
  3034. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  3035. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  3036. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  3037. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  3038. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  3039. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  3040. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  3041. }
  3042. func (HisMScheduleDoctorAdviceVMOne) TableName() string {
  3043. return "xt_schedule"
  3044. }
  3045. type HisMScheduleProjectVM struct {
  3046. ID int64 `gorm:"column:id" json:"id"`
  3047. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  3048. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  3049. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  3050. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  3051. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  3052. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  3053. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  3054. Status int64 `gorm:"column:status" json:"status"`
  3055. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  3056. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  3057. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  3058. Prescription *models.DialysisPrescriptionTwenty `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  3059. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  3060. HisPrescriptionTeamProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"team_project"`
  3061. }
  3062. func (HisMScheduleProjectVM) TableName() string {
  3063. return "xt_schedule"
  3064. }
  3065. func GetHisDoctorConfig(orgid int64) (models.XtHisConfig, error) {
  3066. config := models.XtHisConfig{}
  3067. err := XTReadDB().Model(&config).Where("user_org_id = ? and status =1", orgid).Find(&config).Error
  3068. return config, err
  3069. }
  3070. func GetHisDoctorPatientById(orgid int64, patientid int64, recordtime int64) (advice []*models.HisDoctorAdviceInfo, err error) {
  3071. db := XTReadDB().Table("his_doctor_advice_info as x").Where("x.status = 1")
  3072. if orgid > 0 {
  3073. db = db.Where("x.user_org_id = ?", orgid)
  3074. }
  3075. if patientid > 0 {
  3076. db = db.Where("x.patient_id =?", patientid)
  3077. }
  3078. if recordtime > 0 {
  3079. db = db.Where("x.advice_date = ?", recordtime)
  3080. }
  3081. 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
  3082. return advice, err
  3083. }
  3084. func GetDoctorAdviceCount(startime int64, endtime int64, deliveway string, orgid int64) (advice []*models.BloodDoctorAdvice, err error) {
  3085. db := XTReadDB().Table("xt_doctor_advice as x").Where("x.status = 1 and x.advice_type =2")
  3086. if startime > 0 {
  3087. db = db.Where("x.advice_date >= ?", startime)
  3088. }
  3089. if endtime > 0 {
  3090. db = db.Where("x.advice_date<=?", endtime)
  3091. }
  3092. if orgid > 0 {
  3093. db = db.Where("x.user_org_id = ?", orgid)
  3094. }
  3095. if len(deliveway) > 0 {
  3096. db = db.Where("x.delivery_way = ?", deliveway)
  3097. }
  3098. 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
  3099. return advice, err
  3100. }
  3101. func GetHisDoctorAdviceCount(startime int64, endtime int64, deliveway string, orgid int64) (advice []*models.BloodDoctorAdvice, err error) {
  3102. db := XTReadDB().Table("his_doctor_advice_info as x").Where("x.status = 1 and x.advice_type =2")
  3103. if startime > 0 {
  3104. db = db.Where("x.advice_date >= ?", startime)
  3105. }
  3106. if endtime > 0 {
  3107. db = db.Where("x.advice_date<=?", endtime)
  3108. }
  3109. if orgid > 0 {
  3110. db = db.Where("x.user_org_id = ?", orgid)
  3111. }
  3112. if len(deliveway) > 0 {
  3113. db = db.Where("x.delivery_way = ?", deliveway)
  3114. }
  3115. 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
  3116. return advice, err
  3117. }
  3118. 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) {
  3119. var vms []*MScheduleDoctorAdviceVM
  3120. adviceWhere := ""
  3121. adviceCondition := []interface{}{}
  3122. if adviceType == 0 {
  3123. if patientType == 0 {
  3124. if patient_id > 0 {
  3125. if execution_state > 0 {
  3126. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  3127. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3128. } else {
  3129. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
  3130. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3131. }
  3132. } else {
  3133. if execution_state > 0 {
  3134. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ?"
  3135. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3136. } else {
  3137. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  3138. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3139. }
  3140. }
  3141. } else if patientType == 1 {
  3142. if patient_id > 0 {
  3143. if execution_state > 0 {
  3144. 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= ?"
  3145. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3146. } else {
  3147. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
  3148. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3149. }
  3150. } else {
  3151. if execution_state > 0 {
  3152. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  3153. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3154. } else {
  3155. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  3156. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3157. }
  3158. }
  3159. } else if patientType == 2 {
  3160. if patient_id > 0 {
  3161. if execution_state > 0 {
  3162. 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 = ?"
  3163. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3164. } else {
  3165. 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 = ?)"
  3166. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3167. }
  3168. } else {
  3169. if execution_state > 0 {
  3170. 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 = ?"
  3171. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3172. } else {
  3173. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  3174. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3175. }
  3176. }
  3177. }
  3178. } else if adviceType == 1 {
  3179. if patientType == 0 {
  3180. if patient_id > 0 {
  3181. if execution_state > 0 {
  3182. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ?"
  3183. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3184. } else {
  3185. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
  3186. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3187. }
  3188. } else {
  3189. if execution_state > 0 {
  3190. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ?"
  3191. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3192. } else {
  3193. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  3194. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3195. }
  3196. }
  3197. } else if patientType == 1 {
  3198. if patient_id > 0 {
  3199. if execution_state > 0 {
  3200. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  3201. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3202. } else {
  3203. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
  3204. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3205. }
  3206. } else {
  3207. if execution_state > 0 {
  3208. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?"
  3209. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3210. } else {
  3211. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  3212. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3213. }
  3214. }
  3215. } else if patientType == 2 {
  3216. if patient_id > 0 {
  3217. if execution_state > 0 {
  3218. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  3219. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3220. } else {
  3221. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
  3222. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3223. }
  3224. } else {
  3225. if execution_state > 0 {
  3226. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ?"
  3227. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3228. } else {
  3229. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  3230. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3231. }
  3232. }
  3233. }
  3234. } else if adviceType == 3 {
  3235. if patientType == 0 {
  3236. if patient_id > 0 {
  3237. if execution_state > 0 {
  3238. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ?"
  3239. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3240. } else {
  3241. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? "
  3242. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3243. }
  3244. } else {
  3245. if execution_state > 0 {
  3246. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? "
  3247. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3248. } else {
  3249. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  3250. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3251. }
  3252. }
  3253. } else if patientType == 1 {
  3254. if patient_id > 0 {
  3255. if execution_state > 0 {
  3256. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  3257. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3258. } else {
  3259. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
  3260. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3261. }
  3262. } else {
  3263. if execution_state > 0 {
  3264. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? "
  3265. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3266. } else {
  3267. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  3268. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3269. }
  3270. }
  3271. } else if patientType == 2 {
  3272. if patient_id > 0 {
  3273. if execution_state > 0 {
  3274. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  3275. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3276. } else {
  3277. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ?"
  3278. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3279. }
  3280. } else {
  3281. if execution_state > 0 {
  3282. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ?"
  3283. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3284. } else {
  3285. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  3286. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3287. }
  3288. }
  3289. }
  3290. } else if adviceType == 2 && len(deliverWay) > 0 {
  3291. if patientType == 0 {
  3292. if patient_id > 0 {
  3293. if execution_state > 0 {
  3294. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  3295. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  3296. } else {
  3297. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ?"
  3298. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  3299. }
  3300. } else {
  3301. if execution_state > 0 {
  3302. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ?"
  3303. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  3304. } else {
  3305. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  3306. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  3307. }
  3308. }
  3309. } else if patientType == 1 {
  3310. if patient_id > 0 {
  3311. if execution_state > 0 {
  3312. 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 = ?"
  3313. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state)
  3314. } else {
  3315. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ?"
  3316. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
  3317. }
  3318. } else {
  3319. if execution_state > 0 {
  3320. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ?"
  3321. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state)
  3322. } else {
  3323. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  3324. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  3325. }
  3326. }
  3327. } else if patientType == 2 {
  3328. if patient_id > 0 {
  3329. if execution_state > 0 {
  3330. 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 = ?"
  3331. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  3332. } else {
  3333. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ?"
  3334. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  3335. }
  3336. } else {
  3337. if execution_state > 0 {
  3338. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ?"
  3339. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  3340. } else {
  3341. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  3342. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  3343. }
  3344. }
  3345. }
  3346. } else if adviceType == 2 && len(deliverWay) <= 0 {
  3347. if patientType == 0 {
  3348. if patient_id > 0 {
  3349. if execution_state > 0 {
  3350. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ?"
  3351. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3352. } else {
  3353. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ?"
  3354. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3355. }
  3356. } else {
  3357. if execution_state > 0 {
  3358. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?"
  3359. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3360. } else {
  3361. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  3362. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3363. }
  3364. }
  3365. } else if patientType == 1 {
  3366. if patient_id > 0 {
  3367. if execution_state > 0 {
  3368. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  3369. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3370. } else {
  3371. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ?"
  3372. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3373. }
  3374. } else {
  3375. if execution_state > 0 {
  3376. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ?"
  3377. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3378. } else {
  3379. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?"
  3380. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3381. }
  3382. }
  3383. } else if patientType == 2 {
  3384. if patient_id > 0 {
  3385. if execution_state > 0 {
  3386. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  3387. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3388. } else {
  3389. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ?"
  3390. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3391. }
  3392. } else {
  3393. if execution_state > 0 {
  3394. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ?"
  3395. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3396. } else {
  3397. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  3398. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3399. }
  3400. }
  3401. }
  3402. }
  3403. db := readDb.Table("xt_schedule")
  3404. if scheduleType > 0 {
  3405. db = db.Where("schedule_type = ?", scheduleType)
  3406. }
  3407. if partitonType > 0 {
  3408. db = db.Where("partition_id = ?", partitonType)
  3409. }
  3410. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3411. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3412. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3413. }).
  3414. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3415. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3416. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3417. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3418. Preload("DoctorAdvices", adviceCondition...).
  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. return vms, err
  3425. }
  3426. func GetHisDoctorAdvicesOne(orgID int64, scheduleDate int64, deliverWay string, scheduleType int64, partitionType int64, patient_id int64, execution_state int64, cost_type int64) ([]*HisMScheduleDoctorAdviceVM, error) {
  3427. var vms []*HisMScheduleDoctorAdviceVM
  3428. if len(deliverWay) > 0 {
  3429. db := readDb.Table("xt_schedule")
  3430. if scheduleType > 0 {
  3431. db = db.Where("schedule_type = ?", scheduleType)
  3432. }
  3433. if partitionType > 0 {
  3434. db = db.Where("partition_id = ?", partitionType)
  3435. }
  3436. if patient_id > 0 {
  3437. if execution_state > 0 {
  3438. if cost_type > 0 {
  3439. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3440. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3441. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3442. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3443. 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).
  3444. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3445. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3446. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3447. Where("status = 1 AND user_org_id = ?", orgID)
  3448. if scheduleDate != 0 {
  3449. db = db.Where("schedule_date = ?", scheduleDate)
  3450. }
  3451. err = db.Find(&vms).Error
  3452. } else {
  3453. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3454. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3455. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3456. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3457. 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).
  3458. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3459. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3460. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3461. Where("status = 1 AND user_org_id = ?", orgID)
  3462. if scheduleDate != 0 {
  3463. db = db.Where("schedule_date = ?", scheduleDate)
  3464. }
  3465. err = db.Find(&vms).Error
  3466. }
  3467. } else {
  3468. if cost_type > 0 {
  3469. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3470. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3471. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3472. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3473. 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).
  3474. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3475. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3476. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3477. Where("status = 1 AND user_org_id = ?", orgID)
  3478. if scheduleDate != 0 {
  3479. db = db.Where("schedule_date = ?", scheduleDate)
  3480. }
  3481. err = db.Find(&vms).Error
  3482. } else {
  3483. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3484. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3485. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3486. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3487. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ?", orgID, scheduleDate, deliverWay, patient_id).
  3488. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3489. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3490. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3491. Where("status = 1 AND user_org_id = ?", orgID)
  3492. if scheduleDate != 0 {
  3493. db = db.Where("schedule_date = ?", scheduleDate)
  3494. }
  3495. err = db.Find(&vms).Error
  3496. }
  3497. }
  3498. } else {
  3499. if execution_state > 0 {
  3500. if cost_type > 0 {
  3501. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3502. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3503. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3504. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3505. 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).
  3506. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3507. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3508. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3509. Where("status = 1 AND user_org_id = ?", orgID)
  3510. if scheduleDate != 0 {
  3511. db = db.Where("schedule_date = ?", scheduleDate)
  3512. }
  3513. err = db.Find(&vms).Error
  3514. } else {
  3515. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3516. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3517. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3518. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3519. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_state = ?", orgID, scheduleDate, deliverWay, execution_state).
  3520. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3521. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3522. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3523. Where("status = 1 AND user_org_id = ?", orgID)
  3524. if scheduleDate != 0 {
  3525. db = db.Where("schedule_date = ?", scheduleDate)
  3526. }
  3527. err = db.Find(&vms).Error
  3528. }
  3529. } else {
  3530. if cost_type > 0 {
  3531. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3532. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3533. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3534. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3535. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and is_settle = ?", orgID, scheduleDate, deliverWay, cost_type).
  3536. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3537. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3538. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3539. Where("status = 1 AND user_org_id = ?", orgID)
  3540. if scheduleDate != 0 {
  3541. db = db.Where("schedule_date = ?", scheduleDate)
  3542. }
  3543. err = db.Find(&vms).Error
  3544. } else {
  3545. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3546. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3547. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3548. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3549. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  3550. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3551. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3552. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3553. Where("status = 1 AND user_org_id = ?", orgID)
  3554. if scheduleDate != 0 {
  3555. db = db.Where("schedule_date = ?", scheduleDate)
  3556. }
  3557. err = db.Find(&vms).Error
  3558. }
  3559. }
  3560. }
  3561. } else {
  3562. db := readDb.Table("xt_schedule")
  3563. if scheduleType > 0 {
  3564. db = db.Where("schedule_type = ?", scheduleType)
  3565. }
  3566. if partitionType > 0 {
  3567. db = db.Where("partition_id = ?", partitionType)
  3568. }
  3569. if patient_id > 0 {
  3570. if execution_state > 0 {
  3571. if cost_type > 0 {
  3572. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3573. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3574. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3575. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3576. 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).
  3577. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3578. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3579. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3580. Where("status = 1 AND user_org_id = ?", orgID)
  3581. if scheduleDate != 0 {
  3582. db = db.Where("schedule_date = ?", scheduleDate)
  3583. }
  3584. err = db.Find(&vms).Error
  3585. } else {
  3586. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3587. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3588. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3589. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3590. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and execution_state = ?", orgID, scheduleDate, patient_id, execution_state).
  3591. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3592. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3593. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3594. Where("status = 1 AND user_org_id = ?", orgID)
  3595. if scheduleDate != 0 {
  3596. db = db.Where("schedule_date = ?", scheduleDate)
  3597. }
  3598. err = db.Find(&vms).Error
  3599. }
  3600. } else {
  3601. if cost_type > 0 {
  3602. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3603. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3604. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3605. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3606. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and is_settle = ?", orgID, scheduleDate, patient_id, cost_type).
  3607. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3608. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3609. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3610. Where("status = 1 AND user_org_id = ?", orgID)
  3611. if scheduleDate != 0 {
  3612. db = db.Where("schedule_date = ?", scheduleDate)
  3613. }
  3614. err = db.Find(&vms).Error
  3615. } else {
  3616. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3617. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3618. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3619. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3620. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3621. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3622. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3623. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3624. Where("status = 1 AND user_org_id = ?", orgID)
  3625. if scheduleDate != 0 {
  3626. db = db.Where("schedule_date = ?", scheduleDate)
  3627. }
  3628. err = db.Find(&vms).Error
  3629. }
  3630. }
  3631. } else {
  3632. if execution_state > 0 {
  3633. if cost_type > 0 {
  3634. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3635. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3636. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3637. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3638. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ? and is_settle = ?", orgID, scheduleDate, execution_state, cost_type).
  3639. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3640. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3641. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3642. Where("status = 1 AND user_org_id = ?", orgID)
  3643. if scheduleDate != 0 {
  3644. db = db.Where("schedule_date = ?", scheduleDate)
  3645. }
  3646. err = db.Find(&vms).Error
  3647. } else {
  3648. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3649. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3650. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3651. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3652. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ?", orgID, scheduleDate, execution_state).
  3653. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3654. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3655. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3656. Where("status = 1 AND user_org_id = ?", orgID)
  3657. if scheduleDate != 0 {
  3658. db = db.Where("schedule_date = ?", scheduleDate)
  3659. }
  3660. err = db.Find(&vms).Error
  3661. }
  3662. } else {
  3663. if cost_type > 0 {
  3664. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3665. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3666. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3667. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3668. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and is_settle = ?", orgID, scheduleDate, cost_type).
  3669. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3670. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3671. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3672. Where("status = 1 AND user_org_id = ?", orgID)
  3673. if scheduleDate != 0 {
  3674. db = db.Where("schedule_date = ?", scheduleDate)
  3675. }
  3676. err = db.Find(&vms).Error
  3677. } else {
  3678. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3679. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3680. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3681. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3682. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ?", orgID, scheduleDate).
  3683. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3684. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3685. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3686. Where("status = 1 AND user_org_id = ?", orgID)
  3687. if scheduleDate != 0 {
  3688. db = db.Where("schedule_date = ?", scheduleDate)
  3689. }
  3690. err = db.Find(&vms).Error
  3691. }
  3692. }
  3693. }
  3694. }
  3695. return vms, err
  3696. }
  3697. func BatchDeleteMonitor(ids []string) (err error) {
  3698. if len(ids) == 1 {
  3699. err = XTWriteDB().Model(&models.MonitoringRecord{}).Where("id=?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3700. } else {
  3701. err = XTWriteDB().Model(models.MonitoringRecord{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3702. }
  3703. return
  3704. }
  3705. func GetPatientDialysisRecordList(patientid int64, startime int64, endtime int64) (order []*models.XtDialysisOrders, err error) {
  3706. db := XTReadDB().Table("xt_dialysis_order as x").Where("x.status = 1")
  3707. //table := XTReadDB().Table("xt_schedule as s")
  3708. //fmt.Println(table)
  3709. if patientid > 0 {
  3710. db = db.Where("x.patient_id = ?", patientid)
  3711. }
  3712. if startime > 0 {
  3713. db = db.Where("x.dialysis_date>=?", startime)
  3714. }
  3715. if endtime > 0 {
  3716. db = db.Where("x.dialysis_date <= ?", endtime)
  3717. }
  3718. 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
  3719. return order, err
  3720. }
  3721. func GetPatientDialysisRecordListOne(patientid int64, startime int64, endtime int64) (order []*models.XtScheduleSixTy, err error) {
  3722. db := XTReadDB().Table("xt_schedule as x").Where("x.status = 1")
  3723. //table := XTReadDB().Table("xt_schedule as s")
  3724. //fmt.Println(table)
  3725. if patientid > 0 {
  3726. db = db.Where("x.patient_id = ?", patientid)
  3727. }
  3728. if startime > 0 {
  3729. db = db.Where("x.schedule_date>=?", startime)
  3730. }
  3731. if endtime > 0 {
  3732. db = db.Where("x.schedule_date <= ?", endtime)
  3733. }
  3734. err = db.Select("x.id,x.schedule_date,x.schedule_type,x.mode_id").Find(&order).Error
  3735. return order, err
  3736. }
  3737. func BatchDeleteAdvice(ids []string) (err error) {
  3738. if len(ids) == 1 {
  3739. err = XTWriteDB().Model(&models.DoctorAdvice{}).Where("id=?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3740. } else {
  3741. err = XTWriteDB().Model(models.DoctorAdvice{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3742. }
  3743. return
  3744. }
  3745. func BatchDeleteHisAdvice(ids []string) (err error) {
  3746. if len(ids) == 1 {
  3747. err = XTWriteDB().Model(&models.HisDoctorAdviceInfo{}).Where("id = ?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3748. } else {
  3749. err = XTWriteDB().Model(models.HisDoctorAdviceInfo{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3750. }
  3751. return
  3752. }
  3753. func UpdateAutoReduceDetail(good_id int64, count int64, record_time int64, patient_id int64) (models.AutomaticReduceDetail, error) {
  3754. detail := models.AutomaticReduceDetail{}
  3755. 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
  3756. return detail, err
  3757. }
  3758. func DeleteAutoReduceDetail(good_id int64, record_time int64, patient_id int64) error {
  3759. detail := models.AutomaticReduceDetail{}
  3760. 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
  3761. return err
  3762. }
  3763. func DeleteDialysisBeforOne(good_id int64, record_time int64, patient_id int64) error {
  3764. detail := models.DialysisBeforePrepare{}
  3765. 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
  3766. return err
  3767. }
  3768. func BatchAdviceCheck(ids []string, creator int64) error {
  3769. advice := models.XtDoctorAdvice{}
  3770. 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
  3771. return err
  3772. }
  3773. func BatchHisAdviceCheck(ids []string, creator int64) error {
  3774. advice := models.HisDoctorAdviceInfo{}
  3775. 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
  3776. return err
  3777. }
  3778. func BatchAdviceExecution(ids []string, creator int64, execution_state int64) error {
  3779. advice := models.XtDoctorAdvice{}
  3780. 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
  3781. return err
  3782. }
  3783. func BatchHisAdviceExecution(ids []string, creator int64, execution_state int64) error {
  3784. advice := models.HisDoctorAdviceInfo{}
  3785. 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
  3786. return err
  3787. }
  3788. func GetAdviceExecutionById(ids []string) (doctor []*models.XtDoctorAdvice, err error) {
  3789. err = XTReadDB().Model(&doctor).Where("id IN(?) AND status = 1", ids).Find(&doctor).Error
  3790. return doctor, err
  3791. }
  3792. func GetHisAdviceExecutionById(ids []string) (doctor []*models.HisDoctorAdviceInfo, err error) {
  3793. err = XTReadDB().Model(&doctor).Where("id IN(?) AND status = 1", ids).Find(&doctor).Error
  3794. return doctor, err
  3795. }
  3796. func GetHisProjectConfig(orgid int64) (models.XtHisProjectConfig, error) {
  3797. config := models.XtHisProjectConfig{}
  3798. err := XTReadDB().Model(&config).Where("user_org_id = ? and status =1", orgid).Find(&config).Error
  3799. return config, err
  3800. }
  3801. func GetHisPrescriptionProject(org_id int64, patient_id int64, record_date int64) (project []*models.HisPrescriptionProject, err error) {
  3802. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("GoodInfo", func(db *gorm.DB) *gorm.DB {
  3803. return db.Preload("GoodsType", "status = 1").Where("status = 1 and is_warehouse = 1")
  3804. }).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
  3805. return
  3806. }
  3807. func GetPCHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64, patient_id int64, execution_state int64) ([]*HisMScheduleProjectVM, error) {
  3808. var vms []*HisMScheduleProjectVM
  3809. if patientType == 0 {
  3810. if patient_id > 0 {
  3811. if execution_state == 1 {
  3812. db := readDb.
  3813. Table("xt_schedule").
  3814. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3815. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3816. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3817. }).
  3818. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3819. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3820. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3821. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3822. 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")
  3823. }).
  3824. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3825. 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")
  3826. }).Where("status = 1 AND user_org_id = ?", orgID)
  3827. if scheduleDate != 0 {
  3828. db = db.Where("schedule_date = ?", scheduleDate)
  3829. }
  3830. err = db.Find(&vms).Error
  3831. } else if execution_state == 2 {
  3832. db := readDb.
  3833. Table("xt_schedule").
  3834. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3835. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3836. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3837. }).
  3838. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3839. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3840. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3841. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3842. 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")
  3843. }).
  3844. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3845. 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")
  3846. }).Where("status = 1 AND user_org_id = ?", orgID)
  3847. if scheduleDate != 0 {
  3848. db = db.Where("schedule_date = ?", scheduleDate)
  3849. }
  3850. err = db.Find(&vms).Error
  3851. } else if execution_state == 0 {
  3852. db := readDb.
  3853. Table("xt_schedule").
  3854. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3855. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3856. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3857. }).
  3858. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3859. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3860. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3861. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3862. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3863. }).
  3864. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3865. 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")
  3866. }).Where("status = 1 AND user_org_id = ?", orgID)
  3867. if scheduleDate != 0 {
  3868. db = db.Where("schedule_date = ?", scheduleDate)
  3869. }
  3870. err = db.Find(&vms).Error
  3871. }
  3872. } else {
  3873. if patient_id > 0 {
  3874. if execution_state == 1 {
  3875. db := readDb.
  3876. Table("xt_schedule").
  3877. Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
  3878. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3879. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3880. }).
  3881. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3882. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3883. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3884. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3885. 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")
  3886. }).
  3887. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3888. 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")
  3889. }).Where("status = 1 AND user_org_id = ?", orgID)
  3890. if scheduleDate != 0 {
  3891. db = db.Where("schedule_date = ?", scheduleDate)
  3892. }
  3893. err = db.Find(&vms).Error
  3894. } else if execution_state == 2 {
  3895. db := readDb.
  3896. Table("xt_schedule").
  3897. Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
  3898. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3899. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3900. }).
  3901. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3902. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3903. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3904. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3905. 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")
  3906. }).
  3907. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3908. 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")
  3909. }).Where("status = 1 AND user_org_id = ?", orgID)
  3910. if scheduleDate != 0 {
  3911. db = db.Where("schedule_date = ?", scheduleDate)
  3912. }
  3913. err = db.Find(&vms).Error
  3914. } else if execution_state == 0 {
  3915. db := readDb.
  3916. Table("xt_schedule").
  3917. Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
  3918. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3919. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3920. }).
  3921. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3922. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3923. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3924. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3925. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3926. }).
  3927. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3928. 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")
  3929. }).Where("status = 1 AND user_org_id = ?", orgID)
  3930. if scheduleDate != 0 {
  3931. db = db.Where("schedule_date = ?", scheduleDate)
  3932. }
  3933. err = db.Find(&vms).Error
  3934. }
  3935. } else {
  3936. if execution_state == 1 {
  3937. db := readDb.
  3938. Table("xt_schedule").
  3939. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3940. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3941. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3942. }).
  3943. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3944. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3945. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3946. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3947. 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")
  3948. }).
  3949. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3950. 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")
  3951. }).Where("status = 1 AND user_org_id = ?", orgID)
  3952. if scheduleDate != 0 {
  3953. db = db.Where("schedule_date = ?", scheduleDate)
  3954. }
  3955. err = db.Find(&vms).Error
  3956. } else if execution_state == 2 {
  3957. fmt.Println("j氯332n323232n323ℹ️33232323232")
  3958. db := readDb.
  3959. Table("xt_schedule").
  3960. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3961. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3962. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3963. }).
  3964. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3965. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3966. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3967. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3968. 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")
  3969. }).
  3970. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3971. 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")
  3972. }).Where("status = 1 AND user_org_id = ?", orgID)
  3973. if scheduleDate != 0 {
  3974. db = db.Where("schedule_date = ?", scheduleDate)
  3975. }
  3976. err = db.Find(&vms).Error
  3977. } else if execution_state == 0 {
  3978. db := readDb.
  3979. Table("xt_schedule").
  3980. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3981. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3982. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3983. }).
  3984. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3985. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3986. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3987. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3988. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3989. }).
  3990. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3991. 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")
  3992. }).Where("status = 1 AND user_org_id = ?", orgID)
  3993. if scheduleDate != 0 {
  3994. db = db.Where("schedule_date = ?", scheduleDate)
  3995. }
  3996. err = db.Find(&vms).Error
  3997. }
  3998. }
  3999. }
  4000. }
  4001. if patientType > 0 {
  4002. if execution_state == 1 {
  4003. db := readDb.
  4004. Table("xt_schedule").
  4005. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  4006. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  4007. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  4008. }).
  4009. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  4010. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  4011. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  4012. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  4013. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  4014. 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")
  4015. }).
  4016. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  4017. 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")
  4018. }).Where("status = 1 AND user_org_id = ?", orgID)
  4019. if scheduleDate != 0 {
  4020. db = db.Where("schedule_date = ?", scheduleDate)
  4021. }
  4022. err = db.Find(&vms).Error
  4023. } else if execution_state == 2 {
  4024. db := readDb.
  4025. Table("xt_schedule").
  4026. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  4027. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  4028. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  4029. }).
  4030. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  4031. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  4032. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  4033. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  4034. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  4035. 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")
  4036. }).
  4037. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  4038. 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")
  4039. }).Where("status = 1 AND user_org_id = ?", orgID)
  4040. if scheduleDate != 0 {
  4041. db = db.Where("schedule_date = ?", scheduleDate)
  4042. }
  4043. err = db.Find(&vms).Error
  4044. } else if execution_state == 0 {
  4045. db := readDb.
  4046. Table("xt_schedule").
  4047. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  4048. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  4049. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  4050. }).
  4051. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  4052. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  4053. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  4054. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  4055. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  4056. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  4057. }).
  4058. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  4059. 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")
  4060. }).Where("status = 1 AND user_org_id = ?", orgID)
  4061. if scheduleDate != 0 {
  4062. db = db.Where("schedule_date = ?", scheduleDate)
  4063. }
  4064. err = db.Find(&vms).Error
  4065. }
  4066. }
  4067. return vms, err
  4068. }
  4069. func UpdateStockGoods(good_id int64, record_time int64, patient_id int64, count int64) error {
  4070. prepare := models.DialysisBeforePrepare{}
  4071. var err error
  4072. if count > 0 {
  4073. 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
  4074. }
  4075. if count <= 0 {
  4076. 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
  4077. }
  4078. return err
  4079. }
  4080. func UPdateAutoStockGoods(good_id int64, record_time int64, patient_id int64, count int64) error {
  4081. detail := models.AutomaticReduceDetail{}
  4082. 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
  4083. return err
  4084. }
  4085. func MobileGetDialysisSolutionByModeIdSeven(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  4086. var record models.DialysisSolution
  4087. 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
  4088. if err != nil {
  4089. if err == gorm.ErrRecordNotFound {
  4090. return nil, nil
  4091. } else {
  4092. return nil, err
  4093. }
  4094. }
  4095. return &record, nil
  4096. }
  4097. func MobileGetLastDialysisPrescribeByModeIdSeven(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  4098. var record models.DialysisPrescription
  4099. 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
  4100. if err != nil {
  4101. if err == gorm.ErrRecordNotFound {
  4102. return nil, nil
  4103. } else {
  4104. return nil, err
  4105. }
  4106. }
  4107. return &record, nil
  4108. }
  4109. func MobileGetLastDialysisPrescription(patientID int64, orgID int64) (models.DialysisPrescriptionThrity, error) {
  4110. prescription := models.DialysisPrescriptionThrity{}
  4111. err := readDb.Model(&prescription).Where("patient_id = ? and user_org_id = ? and status = 1 and remark<>''", patientID, orgID).Last(&prescription).Error
  4112. return prescription, err
  4113. }
  4114. func MobileGetSystemDialysisPrescribeByModeIdSeven(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  4115. var record models.SystemPrescription
  4116. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).First(&record).Error
  4117. if err != nil {
  4118. if err == gorm.ErrRecordNotFound {
  4119. return nil, nil
  4120. } else {
  4121. return nil, err
  4122. }
  4123. }
  4124. return &record, nil
  4125. }
  4126. // 透前评估
  4127. func MobileGetPredialysisEvaluationSeven(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
  4128. var record models.PredialysisEvaluation
  4129. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  4130. if err != nil {
  4131. if err == gorm.ErrRecordNotFound {
  4132. return nil, nil
  4133. } else {
  4134. return nil, err
  4135. }
  4136. }
  4137. return &record, nil
  4138. }
  4139. //
  4140. //func MobileGetDialysisGoodsSix(orgID int64, scheduleDate int64) (prepare []*models.DialysisBeforePrepare, err error) {
  4141. //
  4142. // 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
  4143. // return prepare, err
  4144. //}
  4145. func GetMobileAutoReduce(orgID int64, scheduleDate int64) (auto []*models.AutomaticReduceDetail, err error) {
  4146. err = readDb.Where("org_id = ? and status = 1 and record_time = ?", orgID, scheduleDate).Find(&auto).Error
  4147. return auto, err
  4148. }
  4149. func GetRoleList(orgid int64, admin_user_id int64) (models.SgjUserAdminRole, error) {
  4150. role := models.SgjUserAdminRole{}
  4151. err = readUserDb.Where("org_id = ? and admin_user_id = ? and status =1 ", orgid, admin_user_id).Find(&role).Error
  4152. return role, err
  4153. }
  4154. func GetDialysisGood(orgID int64, scheduleDate int64) (auto []*models.AutomaticReduceDetail, err error) {
  4155. err = readDb.Where("org_id = ? and status = 1 and record_time >= ?", orgID, scheduleDate).Group("patient_id").Find(&auto).Error
  4156. return auto, err
  4157. }
  4158. func GetGoodWarehouseOutInfo(orgId int64, patient_id int64, sys_record_time int64) (outifno []*models.WarehouseOutInfoSeven, err error) {
  4159. err = readDb.Where("org_id = ? and patient_id = ? and sys_record_time = ? and status = 1", orgId, patient_id, sys_record_time).Find(&outifno).Error
  4160. return outifno, err
  4161. }
  4162. func GetLastDilysisOrder(orgid int64, patient_id int64, dialysis_date int64) (models.DialysisOrder, error) {
  4163. order := models.DialysisOrder{}
  4164. err = XTReadDB().Where("user_org_id = ? and patient_id = ? and dialysis_date < ? and status= 1", orgid, patient_id, dialysis_date).Last(&order).Error
  4165. return order, err
  4166. }
  4167. func GetFistMonitor(orgid int64, patient_id int64, dialysis_date int64) (models.MonitoringRecord, error) {
  4168. record := models.MonitoringRecord{}
  4169. err := XTReadDB().Where("org_id = ? and patient_id = ? and monitoring_date = ? and status = 1", orgid, patient_id, dialysis_date).Find(&record).Error
  4170. return record, err
  4171. }
  4172. func GetFistMonitorSix(orgid int64, patient_id int64, dialysis_date int64) (record []*models.MonitoringRecord, err error) {
  4173. err = XTReadDB().Where("user_org_id = ? and patient_id = ? and monitoring_date = ? and status = 1", orgid, patient_id, dialysis_date).Find(&record).Error
  4174. return record, err
  4175. }
  4176. 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) {
  4177. var vms []*MScheduleDoctorAdviceVM
  4178. keyword = "%" + keyword + "%"
  4179. adviceWhere := ""
  4180. adviceCondition := []interface{}{}
  4181. if adviceType == 0 {
  4182. if patientType == 0 {
  4183. if patient_id > 0 {
  4184. if execution_state > 0 {
  4185. if cost_type > 0 {
  4186. if len(execution_frequency) > 0 {
  4187. if len(keyword) > 0 {
  4188. 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 ?"
  4189. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4190. } else {
  4191. 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 = ?"
  4192. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4193. }
  4194. } else {
  4195. if len(keyword) > 0 {
  4196. 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 ?"
  4197. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  4198. } else {
  4199. 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 = ?"
  4200. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4201. }
  4202. }
  4203. } else {
  4204. if len(execution_frequency) > 0 {
  4205. if len(keyword) > 0 {
  4206. 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 ?"
  4207. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  4208. } else {
  4209. 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 = ?"
  4210. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4211. }
  4212. } else {
  4213. if len(keyword) > 0 {
  4214. 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 ?"
  4215. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  4216. } else {
  4217. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  4218. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4219. }
  4220. }
  4221. }
  4222. } else {
  4223. if cost_type > 0 {
  4224. if len(execution_frequency) > 0 {
  4225. 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 = ?"
  4226. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4227. } else {
  4228. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and is_settle = ?"
  4229. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4230. }
  4231. } else {
  4232. if len(execution_frequency) > 0 {
  4233. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_frequency = ?"
  4234. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4235. } else {
  4236. if len(keyword) > 0 {
  4237. 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 ?"
  4238. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  4239. } else {
  4240. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
  4241. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4242. }
  4243. }
  4244. }
  4245. }
  4246. } else {
  4247. if execution_state > 0 {
  4248. if cost_type > 0 {
  4249. if len(execution_frequency) > 0 {
  4250. if len(keyword) > 0 {
  4251. 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 ?"
  4252. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  4253. } else {
  4254. 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 = ?"
  4255. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4256. }
  4257. } else {
  4258. if len(keyword) > 0 {
  4259. 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 ?"
  4260. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  4261. } else {
  4262. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and is_settle = ?"
  4263. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4264. }
  4265. }
  4266. } else {
  4267. if len(execution_frequency) > 0 {
  4268. if len(keyword) > 0 {
  4269. 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 ?"
  4270. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  4271. } else {
  4272. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and execution_frequency = ?"
  4273. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4274. }
  4275. } else {
  4276. if len(keyword) > 0 {
  4277. 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 ?"
  4278. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  4279. } else {
  4280. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ?"
  4281. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4282. }
  4283. }
  4284. }
  4285. } else {
  4286. if cost_type > 0 {
  4287. if len(execution_frequency) > 0 {
  4288. if len(keyword) > 0 {
  4289. 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 ?"
  4290. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  4291. } else {
  4292. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ? and execution_frequency = ?"
  4293. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  4294. }
  4295. } else {
  4296. if len(keyword) > 0 {
  4297. 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 ?"
  4298. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  4299. } else {
  4300. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ?"
  4301. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4302. }
  4303. }
  4304. } else {
  4305. if len(execution_frequency) > 0 {
  4306. if len(keyword) > 0 {
  4307. 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 ?"
  4308. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  4309. } else {
  4310. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_frequency = ?"
  4311. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  4312. }
  4313. } else {
  4314. if len(keyword) > 0 {
  4315. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and advice_name like ?"
  4316. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  4317. } else {
  4318. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  4319. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4320. }
  4321. }
  4322. }
  4323. }
  4324. }
  4325. } else if patientType == 1 {
  4326. if patient_id > 0 {
  4327. if execution_state > 0 {
  4328. if cost_type > 0 {
  4329. if len(execution_frequency) > 0 {
  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 patient_id = ? and execution_state= ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  4332. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency, 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 patient_id = ? and execution_state= ? and is_settle = ? and execution_frequency = ?"
  4335. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  4336. }
  4337. } else {
  4338. if len(keyword) > 0 {
  4339. 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 ?"
  4340. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, keyword)
  4341. } else {
  4342. 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 = ?"
  4343. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  4344. }
  4345. }
  4346. } else {
  4347. if len(execution_frequency) > 0 {
  4348. if len(keyword) > 0 {
  4349. 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 ?"
  4350. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  4351. } else {
  4352. 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 = ?"
  4353. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  4354. }
  4355. } else {
  4356. if len(keyword) > 0 {
  4357. 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 ?"
  4358. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, keyword)
  4359. } else {
  4360. 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= ?"
  4361. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  4362. }
  4363. }
  4364. }
  4365. } else {
  4366. if cost_type > 0 {
  4367. if len(execution_frequency) > 0 {
  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 patient_id = ? and is_settle=? and execution_frequency = ? and advice_name like ?"
  4370. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency, 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) and patient_id = ? and is_settle=? and execution_frequency = ?"
  4373. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  4374. }
  4375. } else {
  4376. if len(keyword) > 0 {
  4377. 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 ?"
  4378. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, keyword)
  4379. } else {
  4380. 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=?"
  4381. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  4382. }
  4383. }
  4384. } else {
  4385. if len(execution_frequency) > 0 {
  4386. if len(keyword) > 0 {
  4387. 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 ?"
  4388. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency, keyword)
  4389. } else {
  4390. 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 = ?"
  4391. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  4392. }
  4393. } else {
  4394. if len(keyword) > 0 {
  4395. 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 ?"
  4396. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, keyword)
  4397. } else {
  4398. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
  4399. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  4400. }
  4401. }
  4402. }
  4403. }
  4404. } else {
  4405. if execution_state > 0 {
  4406. if cost_type > 0 {
  4407. if len(execution_frequency) > 0 {
  4408. if len(keyword) > 0 {
  4409. 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 ?"
  4410. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  4411. } else {
  4412. 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 = ?"
  4413. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  4414. }
  4415. } else {
  4416. if len(keyword) > 0 {
  4417. 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 ?"
  4418. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, keyword)
  4419. } else {
  4420. 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=?"
  4421. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  4422. }
  4423. }
  4424. } else {
  4425. if len(execution_frequency) > 0 {
  4426. if len(keyword) > 0 {
  4427. 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 ?"
  4428. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency, keyword)
  4429. } else {
  4430. 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 = ?"
  4431. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  4432. }
  4433. } else {
  4434. if len(keyword) > 0 {
  4435. 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 ?"
  4436. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, keyword)
  4437. } else {
  4438. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  4439. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  4440. }
  4441. }
  4442. }
  4443. } else {
  4444. if cost_type > 0 {
  4445. if len(execution_frequency) > 0 {
  4446. if len(keyword) > 0 {
  4447. 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 ?"
  4448. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency, keyword)
  4449. } else {
  4450. 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 = ?"
  4451. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  4452. }
  4453. } else {
  4454. if len(keyword) > 0 {
  4455. 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 ?"
  4456. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, keyword)
  4457. } else {
  4458. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and is_settle=?"
  4459. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  4460. }
  4461. }
  4462. } else {
  4463. if len(execution_frequency) > 0 {
  4464. if len(keyword) > 0 {
  4465. 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 ?"
  4466. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency, keyword)
  4467. } else {
  4468. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_frequency = ?"
  4469. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  4470. }
  4471. } else {
  4472. if len(keyword) > 0 {
  4473. 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 ?"
  4474. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, keyword)
  4475. } else {
  4476. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  4477. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  4478. }
  4479. }
  4480. }
  4481. }
  4482. }
  4483. } else if patientType == 2 {
  4484. if patient_id > 0 {
  4485. if execution_state > 0 {
  4486. if cost_type > 0 {
  4487. if len(execution_frequency) > 0 {
  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 patient_id = ?) and execution_state = ? and is_settle=? and execution_frequency = ? and advice_name like ?"
  4490. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, 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 patient_id = ?) and execution_state = ? and is_settle=? and execution_frequency = ?"
  4493. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4494. }
  4495. } else {
  4496. if len(keyword) > 0 {
  4497. 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 ?"
  4498. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  4499. } else {
  4500. 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=?"
  4501. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4502. }
  4503. }
  4504. } else {
  4505. if len(execution_frequency) > 0 {
  4506. if len(keyword) > 0 {
  4507. 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 ?"
  4508. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  4509. } else {
  4510. 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 = ?"
  4511. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4512. }
  4513. } else {
  4514. if len(keyword) > 0 {
  4515. 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 ?"
  4516. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  4517. } else {
  4518. 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 = ?"
  4519. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4520. }
  4521. }
  4522. }
  4523. } else {
  4524. if cost_type > 0 {
  4525. if len(execution_frequency) > 0 {
  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 patient_id = ?) and is_settle=? and execution_frequency = ? and advice_name like ?"
  4528. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, 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 and patient_id = ?) and is_settle=? and execution_frequency = ?"
  4531. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4532. }
  4533. } else {
  4534. if len(keyword) > 0 {
  4535. 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 ?"
  4536. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  4537. } else {
  4538. 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=?"
  4539. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4540. }
  4541. }
  4542. } else {
  4543. if len(execution_frequency) > 0 {
  4544. if len(keyword) > 0 {
  4545. 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 ?"
  4546. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  4547. } else {
  4548. 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 = ?"
  4549. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4550. }
  4551. } else {
  4552. if len(keyword) > 0 {
  4553. 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 ?"
  4554. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  4555. } else {
  4556. 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 = ?)"
  4557. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4558. }
  4559. }
  4560. }
  4561. }
  4562. } else {
  4563. if execution_state > 0 {
  4564. if cost_type > 0 {
  4565. if len(execution_frequency) > 0 {
  4566. if len(keyword) > 0 {
  4567. 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 ?"
  4568. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  4569. } else {
  4570. 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 = ?"
  4571. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4572. }
  4573. } else {
  4574. if len(keyword) > 0 {
  4575. 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 ?"
  4576. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  4577. } else {
  4578. 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=?"
  4579. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4580. }
  4581. }
  4582. } else {
  4583. if len(execution_frequency) > 0 {
  4584. if len(keyword) > 0 {
  4585. 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 ?"
  4586. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  4587. } else {
  4588. 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 = ?"
  4589. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4590. }
  4591. } else {
  4592. if len(keyword) > 0 {
  4593. 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 ?"
  4594. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  4595. } else {
  4596. 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 = ?"
  4597. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4598. }
  4599. }
  4600. }
  4601. } else {
  4602. if cost_type > 0 {
  4603. if len(execution_frequency) > 0 {
  4604. if len(keyword) > 0 {
  4605. 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 ?"
  4606. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  4607. } else {
  4608. 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 = ?"
  4609. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  4610. }
  4611. } else {
  4612. if len(keyword) > 0 {
  4613. 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 ?"
  4614. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  4615. } else {
  4616. 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 = ?"
  4617. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4618. }
  4619. }
  4620. } else {
  4621. if len(execution_frequency) > 0 {
  4622. if len(keyword) > 0 {
  4623. 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 ?"
  4624. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  4625. } else {
  4626. 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 = ?"
  4627. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  4628. }
  4629. } else {
  4630. if len(keyword) > 0 {
  4631. 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 ?"
  4632. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  4633. } else {
  4634. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  4635. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4636. }
  4637. }
  4638. }
  4639. }
  4640. }
  4641. }
  4642. } else if adviceType == 1 {
  4643. if patientType == 0 {
  4644. if patient_id > 0 {
  4645. if execution_state > 0 {
  4646. if cost_type > 0 {
  4647. if len(execution_frequency) > 0 {
  4648. if len(keyword) > 0 {
  4649. 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 ?"
  4650. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4651. } else {
  4652. 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 = ?"
  4653. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4654. }
  4655. } else {
  4656. if len(keyword) > 0 {
  4657. 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 ?"
  4658. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  4659. } else {
  4660. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  4661. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4662. }
  4663. }
  4664. } else {
  4665. if len(execution_frequency) > 0 {
  4666. if len(keyword) > 0 {
  4667. 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 ?"
  4668. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  4669. } else {
  4670. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  4671. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4672. }
  4673. } else {
  4674. if len(keyword) > 0 {
  4675. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  4676. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  4677. } else {
  4678. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ?"
  4679. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4680. }
  4681. }
  4682. }
  4683. } else {
  4684. if cost_type > 0 {
  4685. if len(execution_frequency) > 0 {
  4686. if len(keyword) > 0 {
  4687. 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 ?"
  4688. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  4689. } else {
  4690. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  4691. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4692. }
  4693. } else {
  4694. if len(keyword) > 0 {
  4695. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? and advice_name like ? "
  4696. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  4697. } else {
  4698. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? "
  4699. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4700. }
  4701. }
  4702. } else {
  4703. if len(execution_frequency) > 0 {
  4704. if len(keyword) > 0 {
  4705. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and advice_name like ?"
  4706. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  4707. } else {
  4708. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
  4709. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4710. }
  4711. }
  4712. }
  4713. }
  4714. } else {
  4715. if execution_state > 0 {
  4716. if cost_type > 0 {
  4717. if len(execution_frequency) > 0 {
  4718. if len(keyword) > 0 {
  4719. 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 ?"
  4720. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  4721. } else {
  4722. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  4723. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4724. }
  4725. } else {
  4726. if len(keyword) > 0 {
  4727. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  4728. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  4729. } else {
  4730. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ?"
  4731. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4732. }
  4733. }
  4734. } else {
  4735. if len(execution_frequency) > 0 {
  4736. if len(keyword) > 0 {
  4737. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  4738. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  4739. } else {
  4740. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and execution_frequency = ?"
  4741. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4742. }
  4743. } else {
  4744. if len(keyword) > 0 {
  4745. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and advice_name like ?"
  4746. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  4747. } else {
  4748. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ?"
  4749. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4750. }
  4751. }
  4752. }
  4753. } else {
  4754. if cost_type > 0 {
  4755. if len(keyword) > 0 {
  4756. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = ? and advice_name like ?"
  4757. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  4758. } else {
  4759. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = ? "
  4760. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4761. }
  4762. } else {
  4763. if len(keyword) > 0 {
  4764. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and advice_name like ?"
  4765. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  4766. } else {
  4767. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  4768. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4769. }
  4770. }
  4771. }
  4772. }
  4773. } else if patientType == 1 {
  4774. if patient_id > 0 {
  4775. if execution_state > 0 {
  4776. if cost_type > 0 {
  4777. if len(execution_frequency) > 0 {
  4778. if len(keyword) > 0 {
  4779. 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 ?"
  4780. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4781. } else {
  4782. 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 = ?"
  4783. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  4784. }
  4785. } else {
  4786. if len(keyword) > 0 {
  4787. 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 ?"
  4788. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, keyword)
  4789. } else {
  4790. 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 = ?"
  4791. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  4792. }
  4793. }
  4794. } else {
  4795. if len(execution_frequency) > 0 {
  4796. if len(keyword) > 0 {
  4797. 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 ?"
  4798. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  4799. } else {
  4800. 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 = ?"
  4801. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  4802. }
  4803. } else {
  4804. if len(keyword) > 0 {
  4805. 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 ?"
  4806. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, keyword)
  4807. } else {
  4808. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  4809. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  4810. }
  4811. }
  4812. }
  4813. } else {
  4814. if cost_type > 0 {
  4815. if len(execution_frequency) > 0 {
  4816. if len(keyword) > 0 {
  4817. 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 ?"
  4818. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  4819. } else {
  4820. 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 = ?"
  4821. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  4822. }
  4823. } else {
  4824. if len(keyword) > 0 {
  4825. 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 ?"
  4826. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, keyword)
  4827. } else {
  4828. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  4829. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  4830. }
  4831. }
  4832. } else {
  4833. if len(execution_frequency) > 0 {
  4834. if len(keyword) > 0 {
  4835. 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 ?"
  4836. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency, keyword)
  4837. } else {
  4838. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  4839. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  4840. }
  4841. } else {
  4842. if len(keyword) > 0 {
  4843. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and advice_name like ?"
  4844. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, keyword)
  4845. } else {
  4846. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
  4847. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  4848. }
  4849. }
  4850. }
  4851. }
  4852. } else {
  4853. if execution_state > 0 {
  4854. if cost_type > 0 {
  4855. if len(execution_frequency) > 0 {
  4856. if len(keyword) > 0 {
  4857. 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 ?"
  4858. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  4859. } else {
  4860. 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 = ?"
  4861. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  4862. }
  4863. } else {
  4864. if len(keyword) > 0 {
  4865. 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 ?"
  4866. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, keyword)
  4867. } else {
  4868. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=? and is_settle = ?"
  4869. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  4870. }
  4871. }
  4872. } else {
  4873. if len(execution_frequency) > 0 {
  4874. if len(keyword) > 0 {
  4875. 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 ?"
  4876. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency, keyword)
  4877. } else {
  4878. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?and execution_frequency = ?"
  4879. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  4880. }
  4881. } else {
  4882. if len(keyword) > 0 {
  4883. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=? and advice_name like ?"
  4884. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, keyword)
  4885. } else {
  4886. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?"
  4887. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  4888. }
  4889. }
  4890. }
  4891. } else {
  4892. if cost_type > 0 {
  4893. if len(execution_frequency) > 0 {
  4894. if len(keyword) > 0 {
  4895. 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 ?"
  4896. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency, keyword)
  4897. } else {
  4898. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  4899. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  4900. }
  4901. } else {
  4902. if len(keyword) > 0 {
  4903. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? and advice_name like ?"
  4904. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, keyword)
  4905. } else {
  4906. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? "
  4907. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  4908. }
  4909. }
  4910. } else {
  4911. if len(execution_frequency) > 0 {
  4912. if len(keyword) > 0 {
  4913. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_frequency = ? and advice_name like ?"
  4914. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency, keyword)
  4915. } else {
  4916. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_frequency = ?"
  4917. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  4918. }
  4919. } else {
  4920. if len(keyword) > 0 {
  4921. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and advice_name like ?"
  4922. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, keyword)
  4923. } else {
  4924. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  4925. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  4926. }
  4927. }
  4928. }
  4929. }
  4930. }
  4931. } else if patientType == 2 {
  4932. if patient_id > 0 {
  4933. if execution_state > 0 {
  4934. if cost_type > 0 {
  4935. if len(execution_frequency) > 0 {
  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 patient_id = ? and execution_state = ? and is_settle = ?and execution_frequency = ? and advice_name like ?"
  4938. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4939. } else {
  4940. 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 = ?"
  4941. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4942. }
  4943. } else {
  4944. if len(keyword) > 0 {
  4945. 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 ?"
  4946. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  4947. } else {
  4948. 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 = ?"
  4949. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4950. }
  4951. }
  4952. } else {
  4953. if len(execution_frequency) > 0 {
  4954. if len(keyword) > 0 {
  4955. 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 ?"
  4956. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  4957. } else {
  4958. 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 = ?"
  4959. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4960. }
  4961. } else {
  4962. if len(keyword) > 0 {
  4963. 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 ?"
  4964. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  4965. } else {
  4966. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  4967. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4968. }
  4969. }
  4970. }
  4971. } else {
  4972. if cost_type > 0 {
  4973. if len(execution_frequency) > 0 {
  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 patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  4976. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  4977. } else {
  4978. 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 = ?"
  4979. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4980. }
  4981. } else {
  4982. if len(keyword) > 0 {
  4983. 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 ?"
  4984. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  4985. } else {
  4986. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  4987. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4988. }
  4989. }
  4990. } else {
  4991. if len(execution_frequency) > 0 {
  4992. if len(keyword) > 0 {
  4993. 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 ?"
  4994. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  4995. } else {
  4996. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_frequency = ?"
  4997. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4998. }
  4999. } else {
  5000. if len(keyword) > 0 {
  5001. 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 ?"
  5002. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  5003. } else {
  5004. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
  5005. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5006. }
  5007. }
  5008. }
  5009. }
  5010. } else {
  5011. if execution_state > 0 {
  5012. if cost_type > 0 {
  5013. if len(execution_frequency) > 0 {
  5014. if len(keyword) > 0 {
  5015. 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 ?"
  5016. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  5017. } else {
  5018. 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 = ?"
  5019. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  5020. }
  5021. } else {
  5022. if len(keyword) > 0 {
  5023. 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 ?"
  5024. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  5025. } else {
  5026. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  5027. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5028. }
  5029. }
  5030. } else {
  5031. if len(execution_frequency) > 0 {
  5032. if len(keyword) > 0 {
  5033. 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 ?"
  5034. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  5035. } else {
  5036. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and execution_frequency = ?"
  5037. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  5038. }
  5039. } else {
  5040. if len(keyword) > 0 {
  5041. 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 ?"
  5042. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  5043. } else {
  5044. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ?"
  5045. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5046. }
  5047. }
  5048. }
  5049. } else {
  5050. if cost_type > 0 {
  5051. if len(execution_frequency) > 0 {
  5052. if len(keyword) > 0 {
  5053. 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 ?"
  5054. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  5055. } else {
  5056. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  5057. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  5058. }
  5059. } else {
  5060. if len(keyword) > 0 {
  5061. 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 ?"
  5062. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  5063. } else {
  5064. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ?"
  5065. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5066. }
  5067. }
  5068. } else {
  5069. if len(execution_frequency) > 0 {
  5070. if len(keyword) > 0 {
  5071. 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 ?"
  5072. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  5073. } else {
  5074. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_frequency = ?"
  5075. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  5076. }
  5077. } else {
  5078. if len(keyword) > 0 {
  5079. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and advice_name like ?"
  5080. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  5081. } else {
  5082. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  5083. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5084. }
  5085. }
  5086. }
  5087. }
  5088. }
  5089. }
  5090. } else if adviceType == 3 {
  5091. if patientType == 0 {
  5092. if patient_id > 0 {
  5093. if execution_state > 0 {
  5094. if cost_type > 0 {
  5095. if len(execution_frequency) > 0 {
  5096. if len(keyword) > 0 {
  5097. 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 ?"
  5098. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5099. } else {
  5100. 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 =?"
  5101. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  5102. }
  5103. } else {
  5104. if len(keyword) > 0 {
  5105. 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 ?"
  5106. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  5107. } else {
  5108. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  5109. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5110. }
  5111. }
  5112. } else {
  5113. if len(execution_frequency) > 0 {
  5114. if len(keyword) > 0 {
  5115. 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 ?"
  5116. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  5117. } else {
  5118. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency =?"
  5119. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  5120. }
  5121. } else {
  5122. if len(keyword) > 0 {
  5123. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  5124. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  5125. } else {
  5126. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ?"
  5127. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5128. }
  5129. }
  5130. }
  5131. } else {
  5132. if cost_type > 0 {
  5133. if len(execution_frequency) > 0 {
  5134. if len(keyword) > 0 {
  5135. 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 ?"
  5136. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  5137. } else {
  5138. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency =?"
  5139. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  5140. }
  5141. } else {
  5142. if len(keyword) > 0 {
  5143. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  5144. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  5145. } else {
  5146. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? "
  5147. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5148. }
  5149. }
  5150. } else {
  5151. if len(execution_frequency) > 0 {
  5152. if len(keyword) > 0 {
  5153. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_frequency =? and advice_name like ?"
  5154. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  5155. } else {
  5156. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_frequency =?"
  5157. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  5158. }
  5159. } else {
  5160. if len(keyword) > 0 {
  5161. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and advice_name like ?"
  5162. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  5163. } else {
  5164. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? "
  5165. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5166. }
  5167. }
  5168. }
  5169. }
  5170. } else {
  5171. if execution_state > 0 {
  5172. if cost_type > 0 {
  5173. if len(execution_frequency) > 0 {
  5174. if len(keyword) > 0 {
  5175. 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 ?"
  5176. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  5177. } else {
  5178. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ? and execution_frequency =?"
  5179. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  5180. }
  5181. } else {
  5182. if len(keyword) > 0 {
  5183. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ? and advice_name like ?"
  5184. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  5185. } else {
  5186. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ?"
  5187. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5188. }
  5189. }
  5190. } else {
  5191. if len(execution_frequency) > 0 {
  5192. if len(keyword) > 0 {
  5193. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and execution_frequency =? and advice_name like ?"
  5194. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  5195. } else {
  5196. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and execution_frequency =?"
  5197. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  5198. }
  5199. } else {
  5200. if len(keyword) > 0 {
  5201. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and advice_name like ?"
  5202. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  5203. } else {
  5204. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? "
  5205. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5206. }
  5207. }
  5208. }
  5209. } else {
  5210. if cost_type > 0 {
  5211. if len(execution_frequency) > 0 {
  5212. if len(keyword) > 0 {
  5213. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? and execution_frequency =? and advice_name like ?"
  5214. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  5215. } else {
  5216. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? and execution_frequency =?"
  5217. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  5218. }
  5219. } else {
  5220. if len(keyword) > 0 {
  5221. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? and advice_name like ?"
  5222. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  5223. } else {
  5224. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? "
  5225. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5226. }
  5227. }
  5228. } else {
  5229. if len(execution_frequency) > 0 {
  5230. if len(keyword) > 0 {
  5231. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_frequency =? and advice_name like ?"
  5232. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  5233. } else {
  5234. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_frequency =?"
  5235. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  5236. }
  5237. } else {
  5238. if len(keyword) > 0 {
  5239. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and advice_name like ?"
  5240. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  5241. } else {
  5242. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  5243. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5244. }
  5245. }
  5246. }
  5247. }
  5248. }
  5249. } else if patientType == 1 {
  5250. if patient_id > 0 {
  5251. if execution_state > 0 {
  5252. if cost_type > 0 {
  5253. if len(execution_frequency) > 0 {
  5254. if len(keyword) > 0 {
  5255. 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 ?"
  5256. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5257. } else {
  5258. 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 = ?"
  5259. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  5260. }
  5261. } else {
  5262. if len(keyword) > 0 {
  5263. 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 ?"
  5264. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, keyword)
  5265. } else {
  5266. 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 = ?"
  5267. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  5268. }
  5269. }
  5270. } else {
  5271. if len(execution_frequency) > 0 {
  5272. if len(keyword) > 0 {
  5273. 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 ?"
  5274. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  5275. } else {
  5276. 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 = ?"
  5277. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  5278. }
  5279. } else {
  5280. if len(keyword) > 0 {
  5281. 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 ?"
  5282. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, keyword)
  5283. } else {
  5284. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  5285. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  5286. }
  5287. }
  5288. }
  5289. } else {
  5290. if cost_type > 0 {
  5291. if len(execution_frequency) > 0 {
  5292. if len(keyword) > 0 {
  5293. 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 ?"
  5294. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  5295. } else {
  5296. 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 = ?"
  5297. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  5298. }
  5299. } else {
  5300. if len(keyword) > 0 {
  5301. 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 ?"
  5302. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, keyword)
  5303. } else {
  5304. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  5305. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  5306. }
  5307. }
  5308. } else {
  5309. if len(execution_frequency) > 0 {
  5310. if len(keyword) > 0 {
  5311. 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 ?"
  5312. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency, keyword)
  5313. } else {
  5314. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  5315. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  5316. }
  5317. } else {
  5318. if len(keyword) > 0 {
  5319. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and advice_name like ?"
  5320. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, keyword)
  5321. } else {
  5322. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
  5323. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  5324. }
  5325. }
  5326. }
  5327. }
  5328. } else {
  5329. if execution_state > 0 {
  5330. if cost_type > 0 {
  5331. if len(execution_frequency) > 0 {
  5332. if len(keyword) > 0 {
  5333. 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 ?"
  5334. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  5335. } else {
  5336. 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 = ?"
  5337. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  5338. }
  5339. } else {
  5340. if len(keyword) > 0 {
  5341. 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 ?"
  5342. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, keyword)
  5343. } else {
  5344. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? and is_settle = ?"
  5345. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  5346. }
  5347. }
  5348. } else {
  5349. if len(execution_frequency) > 0 {
  5350. if len(keyword) > 0 {
  5351. 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 ? "
  5352. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency, keyword)
  5353. } else {
  5354. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =?and execution_frequency = ? "
  5355. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  5356. }
  5357. } else {
  5358. if len(keyword) > 0 {
  5359. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? and advice_name like ?"
  5360. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, keyword)
  5361. } else {
  5362. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? "
  5363. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  5364. }
  5365. }
  5366. }
  5367. } else {
  5368. if cost_type > 0 {
  5369. if len(execution_frequency) > 0 {
  5370. if len(keyword) > 0 {
  5371. 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 ?"
  5372. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency, keyword)
  5373. } else {
  5374. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  5375. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  5376. }
  5377. } else {
  5378. if len(keyword) > 0 {
  5379. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ? and advice_name like ?"
  5380. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, keyword)
  5381. } else {
  5382. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ?"
  5383. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  5384. }
  5385. }
  5386. } else {
  5387. if len(execution_frequency) > 0 {
  5388. if len(keyword) > 0 {
  5389. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_frequency = ? and advice_name like ?"
  5390. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency, keyword)
  5391. } else {
  5392. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_frequency = ?"
  5393. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  5394. }
  5395. } else {
  5396. if len(keyword) > 0 {
  5397. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and advice_name like ?"
  5398. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, keyword)
  5399. } else {
  5400. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  5401. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  5402. }
  5403. }
  5404. }
  5405. }
  5406. }
  5407. } else if patientType == 2 {
  5408. if patient_id > 0 {
  5409. if execution_state > 0 {
  5410. if cost_type > 0 {
  5411. if len(execution_frequency) > 0 {
  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 patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5414. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5415. } else {
  5416. 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 = ?"
  5417. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  5418. }
  5419. } else {
  5420. if len(keyword) > 0 {
  5421. 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 ?"
  5422. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  5423. } else {
  5424. 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 = ?"
  5425. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5426. }
  5427. }
  5428. } else {
  5429. if len(execution_frequency) > 0 {
  5430. if len(keyword) > 0 {
  5431. 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 ?"
  5432. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  5433. } else {
  5434. 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 = ?"
  5435. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  5436. }
  5437. } else {
  5438. if len(keyword) > 0 {
  5439. 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 ?"
  5440. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  5441. } else {
  5442. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  5443. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5444. }
  5445. }
  5446. }
  5447. } else {
  5448. if cost_type > 0 {
  5449. if len(execution_frequency) > 0 {
  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 patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5452. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  5453. } else {
  5454. 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 = ?"
  5455. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  5456. }
  5457. } else {
  5458. if len(keyword) > 0 {
  5459. 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 ?"
  5460. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  5461. } else {
  5462. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  5463. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5464. }
  5465. }
  5466. } else {
  5467. if len(execution_frequency) > 0 {
  5468. if len(keyword) > 0 {
  5469. 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 ?"
  5470. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  5471. } else {
  5472. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_frequency = ?"
  5473. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  5474. }
  5475. } else {
  5476. if len(keyword) > 0 {
  5477. 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 ?"
  5478. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  5479. } else {
  5480. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ?"
  5481. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5482. }
  5483. }
  5484. }
  5485. }
  5486. } else {
  5487. if execution_state > 0 {
  5488. if cost_type > 0 {
  5489. if len(execution_frequency) > 0 {
  5490. if len(keyword) > 0 {
  5491. 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 ?"
  5492. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  5493. } else {
  5494. 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 = ?"
  5495. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  5496. }
  5497. } else {
  5498. if len(keyword) > 0 {
  5499. 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 ?"
  5500. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  5501. } else {
  5502. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and is_settle = ?"
  5503. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5504. }
  5505. }
  5506. } else {
  5507. if len(execution_frequency) > 0 {
  5508. if len(keyword) > 0 {
  5509. 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 ?"
  5510. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  5511. } else {
  5512. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and execution_frequency = ?"
  5513. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  5514. }
  5515. } else {
  5516. if len(keyword) > 0 {
  5517. 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 ?"
  5518. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  5519. } else {
  5520. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ?"
  5521. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5522. }
  5523. }
  5524. }
  5525. } else {
  5526. if cost_type > 0 {
  5527. if len(execution_frequency) > 0 {
  5528. if len(keyword) > 0 {
  5529. 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 ?"
  5530. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  5531. } else {
  5532. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  5533. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  5534. }
  5535. } else {
  5536. if len(keyword) > 0 {
  5537. 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 ?"
  5538. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  5539. } else {
  5540. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ?"
  5541. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5542. }
  5543. }
  5544. } else {
  5545. if len(execution_frequency) > 0 {
  5546. if len(keyword) > 0 {
  5547. 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 ?"
  5548. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  5549. } else {
  5550. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_frequency = ?"
  5551. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  5552. }
  5553. } else {
  5554. if len(keyword) > 0 {
  5555. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and advice_name like ?"
  5556. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  5557. } else {
  5558. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  5559. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5560. }
  5561. }
  5562. }
  5563. }
  5564. }
  5565. }
  5566. } else if adviceType == 2 && len(deliverWay) > 0 {
  5567. if patientType == 0 {
  5568. if patient_id > 0 {
  5569. if execution_state > 0 {
  5570. if cost_type > 0 {
  5571. if len(execution_frequency) > 0 {
  5572. if len(keyword) > 0 {
  5573. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5574. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5575. } else {
  5576. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5577. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency)
  5578. }
  5579. } else {
  5580. if len(keyword) > 0 {
  5581. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5582. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, keyword)
  5583. } else {
  5584. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  5585. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  5586. }
  5587. }
  5588. } else {
  5589. if len(execution_frequency) > 0 {
  5590. if len(keyword) > 0 {
  5591. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5592. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency, keyword)
  5593. } else {
  5594. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  5595. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency)
  5596. }
  5597. } else {
  5598. if len(keyword) > 0 {
  5599. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  5600. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, keyword)
  5601. } else {
  5602. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  5603. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  5604. }
  5605. }
  5606. }
  5607. } else {
  5608. if cost_type > 0 {
  5609. if len(execution_frequency) > 0 {
  5610. if len(keyword) > 0 {
  5611. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5612. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency, keyword)
  5613. } else {
  5614. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  5615. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency)
  5616. }
  5617. } else {
  5618. if len(keyword) > 0 {
  5619. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  5620. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, keyword)
  5621. } else {
  5622. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and is_settle = ?"
  5623. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  5624. }
  5625. }
  5626. } else {
  5627. if len(execution_frequency) > 0 {
  5628. if len(keyword) > 0 {
  5629. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  5630. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency, keyword)
  5631. } else {
  5632. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and execution_frequency = ?"
  5633. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency)
  5634. }
  5635. } else {
  5636. if len(keyword) > 0 {
  5637. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and advice_name like ?"
  5638. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, keyword)
  5639. } else {
  5640. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ?"
  5641. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  5642. }
  5643. }
  5644. }
  5645. }
  5646. } else {
  5647. if execution_state > 0 {
  5648. if cost_type > 0 {
  5649. if len(execution_frequency) > 0 {
  5650. if len(keyword) > 0 {
  5651. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5652. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency, keyword)
  5653. } else {
  5654. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5655. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency)
  5656. }
  5657. } else {
  5658. if len(keyword) > 0 {
  5659. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5660. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, keyword)
  5661. } else {
  5662. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and execution_state = ? and is_settle = ?"
  5663. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  5664. }
  5665. }
  5666. } else {
  5667. if len(execution_frequency) > 0 {
  5668. if len(keyword) > 0 {
  5669. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5670. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency, keyword)
  5671. } else {
  5672. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and execution_state = ? and execution_frequency = ?"
  5673. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency)
  5674. }
  5675. } else {
  5676. if len(keyword) > 0 {
  5677. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and execution_state = ? and advice_name like ?"
  5678. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, keyword)
  5679. } else {
  5680. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and execution_state = ?"
  5681. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  5682. }
  5683. }
  5684. }
  5685. } else {
  5686. if cost_type > 0 {
  5687. if len(execution_frequency) > 0 {
  5688. if len(keyword) > 0 {
  5689. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5690. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, execution_frequency, keyword)
  5691. } else {
  5692. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and is_settle = ? and execution_frequency = ?"
  5693. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, execution_frequency)
  5694. }
  5695. } else {
  5696. if len(keyword) > 0 {
  5697. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3)2 AND record_date = ? and delivery_way = ? and is_settle = ? and advice_name like ?"
  5698. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, keyword)
  5699. } else {
  5700. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and is_settle = ?"
  5701. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  5702. }
  5703. }
  5704. } else {
  5705. if len(execution_frequency) > 0 {
  5706. if len(keyword) > 0 {
  5707. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and execution_frequency = ? and advice_name like ?"
  5708. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_frequency, keyword)
  5709. } else {
  5710. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and execution_frequency = ?"
  5711. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_frequency)
  5712. }
  5713. } else {
  5714. if len(keyword) > 0 {
  5715. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and advice_name like ?"
  5716. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, keyword)
  5717. } else {
  5718. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ?"
  5719. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  5720. }
  5721. }
  5722. }
  5723. }
  5724. }
  5725. } else if patientType == 1 {
  5726. if patient_id > 0 {
  5727. if execution_state > 0 {
  5728. if cost_type > 0 {
  5729. if len(execution_frequency) > 0 {
  5730. if len(keyword) > 0 {
  5731. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5732. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5733. } else {
  5734. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5735. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type, execution_frequency)
  5736. }
  5737. } else {
  5738. if len(keyword) > 0 {
  5739. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5740. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type, keyword)
  5741. } else {
  5742. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  5743. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type)
  5744. }
  5745. }
  5746. } else {
  5747. if len(execution_frequency) > 0 {
  5748. if len(keyword) > 0 {
  5749. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5750. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, execution_frequency, keyword)
  5751. } else {
  5752. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  5753. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, execution_frequency)
  5754. }
  5755. } else {
  5756. if len(keyword) > 0 {
  5757. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  5758. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, keyword)
  5759. } else {
  5760. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  5761. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state)
  5762. }
  5763. }
  5764. }
  5765. } else {
  5766. if cost_type > 0 {
  5767. if len(execution_frequency) > 0 {
  5768. if len(keyword) > 0 {
  5769. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5770. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type, execution_frequency, keyword)
  5771. } else {
  5772. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  5773. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type, execution_frequency)
  5774. }
  5775. } else {
  5776. if len(keyword) > 0 {
  5777. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  5778. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type, keyword)
  5779. } else {
  5780. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and is_settle = ?"
  5781. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type)
  5782. }
  5783. }
  5784. } else {
  5785. if len(execution_frequency) > 0 {
  5786. if len(keyword) > 0 {
  5787. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  5788. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_frequency, keyword)
  5789. } else {
  5790. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_frequency = ?"
  5791. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_frequency)
  5792. }
  5793. } else {
  5794. if len(keyword) > 0 {
  5795. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and avice_name like ?"
  5796. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, keyword)
  5797. } else {
  5798. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ?"
  5799. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
  5800. }
  5801. }
  5802. }
  5803. }
  5804. } else {
  5805. if execution_state > 0 {
  5806. if cost_type > 0 {
  5807. if len(execution_frequency) > 0 {
  5808. if len(keyword) > 0 {
  5809. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5810. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type, execution_frequency, keyword)
  5811. } else {
  5812. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5813. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type, execution_frequency)
  5814. }
  5815. } else {
  5816. if len(keyword) > 0 {
  5817. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5818. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type, keyword)
  5819. } else {
  5820. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and execution_state = ? and is_settle = ?"
  5821. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type)
  5822. }
  5823. }
  5824. } else {
  5825. if len(execution_frequency) > 0 {
  5826. if len(keyword) > 0 {
  5827. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5828. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, execution_frequency, keyword)
  5829. } else {
  5830. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and execution_state = ? and execution_frequency = ?"
  5831. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, execution_frequency)
  5832. }
  5833. } else {
  5834. if len(keyword) > 0 {
  5835. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and execution_state = ? and advice_name like ?"
  5836. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, keyword)
  5837. } else {
  5838. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and execution_state = ?"
  5839. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state)
  5840. }
  5841. }
  5842. }
  5843. } else {
  5844. if cost_type > 0 {
  5845. if len(execution_frequency) > 0 {
  5846. if len(keyword) > 0 {
  5847. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND(advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5848. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type, execution_frequency, keyword)
  5849. } else {
  5850. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and is_settle = ? and execution_frequency = ?"
  5851. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type, execution_frequency)
  5852. }
  5853. } else {
  5854. if len(keyword) > 0 {
  5855. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and is_settle = ? and advice_name like ?"
  5856. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type, keyword)
  5857. } else {
  5858. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and is_settle = ?"
  5859. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type)
  5860. }
  5861. }
  5862. } else {
  5863. if len(execution_frequency) > 0 {
  5864. if len(keyword) > 0 {
  5865. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and execution_frequency = ? and advic_name like ?"
  5866. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_frequency, keyword)
  5867. } else {
  5868. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and execution_frequency = ?"
  5869. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_frequency)
  5870. }
  5871. } else {
  5872. if len(keyword) > 0 {
  5873. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and advice_name like ?"
  5874. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, keyword)
  5875. } else {
  5876. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? "
  5877. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  5878. }
  5879. }
  5880. }
  5881. }
  5882. }
  5883. } else if patientType == 2 {
  5884. if patient_id > 0 {
  5885. if execution_state > 0 {
  5886. if cost_type > 0 {
  5887. if len(execution_frequency) > 0 {
  5888. if len(keyword) > 0 {
  5889. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5890. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5891. } else {
  5892. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5893. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency)
  5894. }
  5895. } else {
  5896. if len(keyword) > 0 {
  5897. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5898. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, keyword)
  5899. } else {
  5900. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3)2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  5901. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  5902. }
  5903. }
  5904. } else {
  5905. if len(execution_frequency) > 0 {
  5906. if len(keyword) > 0 {
  5907. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5908. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency, keyword)
  5909. } else {
  5910. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  5911. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency)
  5912. }
  5913. } else {
  5914. if len(keyword) > 0 {
  5915. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  5916. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, keyword)
  5917. } else {
  5918. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ?"
  5919. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  5920. }
  5921. }
  5922. }
  5923. } else {
  5924. if cost_type > 0 {
  5925. if len(execution_frequency) > 0 {
  5926. if len(keyword) > 0 {
  5927. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5928. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency, keyword)
  5929. } else {
  5930. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  5931. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency)
  5932. }
  5933. } else {
  5934. if len(keyword) > 0 {
  5935. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  5936. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, keyword)
  5937. } else {
  5938. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and is_settle = ?"
  5939. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  5940. }
  5941. }
  5942. } else {
  5943. if len(execution_frequency) > 0 {
  5944. if len(keyword) > 0 {
  5945. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  5946. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency, keyword)
  5947. } else {
  5948. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_frequency = ?"
  5949. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency)
  5950. }
  5951. } else {
  5952. if len(keyword) > 0 {
  5953. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and advice_name like ?"
  5954. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, keyword)
  5955. } else {
  5956. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ?"
  5957. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  5958. }
  5959. }
  5960. }
  5961. }
  5962. } else {
  5963. if execution_state > 0 {
  5964. if cost_type > 0 {
  5965. if len(execution_frequency) > 0 {
  5966. if len(keyword) > 0 {
  5967. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5968. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency, keyword)
  5969. } else {
  5970. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5971. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency)
  5972. }
  5973. } else {
  5974. if len(keyword) > 0 {
  5975. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5976. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, keyword)
  5977. } else {
  5978. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and execution_state = ? and is_settle = ?"
  5979. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  5980. }
  5981. }
  5982. } else {
  5983. if len(execution_frequency) > 0 {
  5984. if len(keyword) > 0 {
  5985. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5986. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency, keyword)
  5987. } else {
  5988. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and execution_state = ? and execution_frequency = ?"
  5989. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency)
  5990. }
  5991. } else {
  5992. if len(keyword) > 0 {
  5993. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and execution_state = ? and advice_name like ?"
  5994. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, keyword)
  5995. } else {
  5996. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and execution_state = ?"
  5997. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  5998. }
  5999. }
  6000. }
  6001. } else {
  6002. if cost_type > 0 {
  6003. if len(execution_frequency) > 0 {
  6004. if len(keyword) > 0 {
  6005. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and is_settle = ? and advice_name like ?"
  6006. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, keyword)
  6007. } else {
  6008. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and is_settle = ?"
  6009. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  6010. }
  6011. } else {
  6012. if len(keyword) > 0 {
  6013. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and is_settle = ? and advice_name like ?"
  6014. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, keyword)
  6015. } else {
  6016. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and is_settle = ?"
  6017. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  6018. }
  6019. }
  6020. } else {
  6021. if len(keyword) > 0 {
  6022. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and advice_name like ?"
  6023. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, keyword)
  6024. } else {
  6025. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ?"
  6026. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  6027. }
  6028. }
  6029. }
  6030. }
  6031. }
  6032. } else if adviceType == 2 && len(deliverWay) <= 0 {
  6033. if patientType == 0 {
  6034. if patient_id > 0 {
  6035. if execution_state > 0 {
  6036. if cost_type > 0 {
  6037. if len(execution_frequency) > 0 {
  6038. if len(keyword) > 0 {
  6039. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6040. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  6041. } else {
  6042. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  6043. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  6044. }
  6045. } else {
  6046. if len(keyword) > 0 {
  6047. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  6048. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  6049. } else {
  6050. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  6051. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6052. }
  6053. }
  6054. } else {
  6055. if len(execution_frequency) > 0 {
  6056. if len(keyword) > 0 {
  6057. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  6058. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  6059. } else {
  6060. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  6061. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  6062. }
  6063. } else {
  6064. if len(keyword) > 0 {
  6065. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  6066. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  6067. } else {
  6068. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and execution_state = ?"
  6069. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6070. }
  6071. }
  6072. }
  6073. } else {
  6074. if cost_type > 0 {
  6075. if len(execution_frequency) > 0 {
  6076. if len(keyword) > 0 {
  6077. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6078. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  6079. } else {
  6080. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  6081. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  6082. }
  6083. } else {
  6084. if len(keyword) > 0 {
  6085. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  6086. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  6087. } else {
  6088. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and is_settle = ?"
  6089. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6090. }
  6091. }
  6092. } else {
  6093. if len(execution_frequency) > 0 {
  6094. if len(keyword) > 0 {
  6095. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  6096. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  6097. } else {
  6098. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and execution_frequency = ?"
  6099. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  6100. }
  6101. } else {
  6102. if len(keyword) > 0 {
  6103. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and advice_name like ?"
  6104. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  6105. } else {
  6106. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ?"
  6107. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6108. }
  6109. }
  6110. }
  6111. }
  6112. } else {
  6113. if execution_state > 0 {
  6114. if cost_type > 0 {
  6115. if len(execution_frequency) > 0 {
  6116. if len(keyword) > 0 {
  6117. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6118. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  6119. } else {
  6120. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  6121. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  6122. }
  6123. } else {
  6124. if len(keyword) > 0 {
  6125. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  6126. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  6127. } else {
  6128. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and execution_state = ? and is_settle = ?"
  6129. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6130. }
  6131. }
  6132. } else {
  6133. if len(execution_frequency) > 0 {
  6134. if len(keyword) > 0 {
  6135. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and execution_state = ?and execution_frequency = ? and advice_name like ?"
  6136. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  6137. } else {
  6138. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and execution_state = ?and execution_frequency = ?"
  6139. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  6140. }
  6141. } else {
  6142. if len(keyword) > 0 {
  6143. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and execution_state = ? and advice_name like ?"
  6144. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  6145. } else {
  6146. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and execution_state = ?"
  6147. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6148. }
  6149. }
  6150. }
  6151. } else {
  6152. if cost_type > 0 {
  6153. if len(execution_frequency) > 0 {
  6154. if len(keyword) > 0 {
  6155. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6156. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  6157. } else {
  6158. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and is_settle = ? and execution_frequency = ?"
  6159. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  6160. }
  6161. }
  6162. } else {
  6163. if len(execution_frequency) > 0 {
  6164. if len(keyword) > 0 {
  6165. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and execution_frequency = ? and advice_name like ?"
  6166. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  6167. } else {
  6168. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and execution_frequency = ?"
  6169. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  6170. }
  6171. } else {
  6172. if len(keyword) > 0 {
  6173. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and advice_name like ?"
  6174. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  6175. } else {
  6176. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ?"
  6177. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6178. }
  6179. }
  6180. }
  6181. }
  6182. }
  6183. } else if patientType == 1 {
  6184. if patient_id > 0 {
  6185. if execution_state > 0 {
  6186. if cost_type > 0 {
  6187. if len(execution_frequency) > 0 {
  6188. if len(keyword) > 0 {
  6189. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6190. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  6191. } else {
  6192. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  6193. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  6194. }
  6195. } else {
  6196. if len(keyword) > 0 {
  6197. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  6198. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, keyword)
  6199. } else {
  6200. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  6201. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  6202. }
  6203. }
  6204. } else {
  6205. if len(execution_frequency) > 0 {
  6206. if len(keyword) > 0 {
  6207. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  6208. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  6209. } else {
  6210. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  6211. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  6212. }
  6213. } else {
  6214. if len(keyword) > 0 {
  6215. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  6216. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, keyword)
  6217. } else {
  6218. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  6219. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  6220. }
  6221. }
  6222. }
  6223. } else {
  6224. if cost_type > 0 {
  6225. if len(execution_frequency) > 0 {
  6226. if len(keyword) > 0 {
  6227. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3)2 AND advice_doctor = ? and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6228. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  6229. } else {
  6230. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  6231. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  6232. }
  6233. } else {
  6234. if len(keyword) > 0 {
  6235. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  6236. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, keyword)
  6237. } else {
  6238. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  6239. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  6240. }
  6241. }
  6242. } else {
  6243. if len(execution_frequency) > 0 {
  6244. if len(keyword) > 0 {
  6245. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  6246. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency, keyword)
  6247. } else {
  6248. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  6249. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  6250. }
  6251. } else {
  6252. if len(keyword) > 0 {
  6253. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and advice_name like ?"
  6254. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, keyword)
  6255. } else {
  6256. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ?"
  6257. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  6258. }
  6259. }
  6260. }
  6261. }
  6262. } else {
  6263. if execution_state > 0 {
  6264. if cost_type > 0 {
  6265. if len(execution_frequency) > 0 {
  6266. if len(keyword) > 0 {
  6267. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6268. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  6269. } else {
  6270. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  6271. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  6272. }
  6273. } else {
  6274. if len(keyword) > 0 {
  6275. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  6276. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, keyword)
  6277. } else {
  6278. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and execution_state = ? and is_settle = ?"
  6279. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  6280. }
  6281. }
  6282. } else {
  6283. if len(execution_frequency) > 0 {
  6284. if len(keyword) > 0 {
  6285. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  6286. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency, keyword)
  6287. } else {
  6288. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and execution_state = ? and execution_frequency = ?"
  6289. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  6290. }
  6291. } else {
  6292. if len(keyword) > 0 {
  6293. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and execution_state = ? and advice_name like ?"
  6294. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, keyword)
  6295. } else {
  6296. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and execution_state = ?"
  6297. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  6298. }
  6299. }
  6300. }
  6301. } else {
  6302. if cost_type > 0 {
  6303. if len(execution_frequency) > 0 {
  6304. if len(keyword) > 0 {
  6305. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6306. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency, keyword)
  6307. } else {
  6308. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  6309. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  6310. }
  6311. } else {
  6312. if len(keyword) > 0 {
  6313. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and is_settle = ? and advice_name like ?"
  6314. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, keyword)
  6315. } else {
  6316. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and is_settle = ?"
  6317. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  6318. }
  6319. }
  6320. } else {
  6321. if len(execution_frequency) > 0 {
  6322. if len(keyword) > 0 {
  6323. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and execution_frequency = ? and advice_name like ?"
  6324. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency, keyword)
  6325. } else {
  6326. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and execution_frequency = ?"
  6327. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  6328. }
  6329. } else {
  6330. if len(keyword) > 0 {
  6331. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and advice_name like ?"
  6332. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, keyword)
  6333. } else {
  6334. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ?"
  6335. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  6336. }
  6337. }
  6338. }
  6339. }
  6340. }
  6341. } else if patientType == 2 {
  6342. if patient_id > 0 {
  6343. if execution_state > 0 {
  6344. if cost_type > 0 {
  6345. if len(execution_frequency) > 0 {
  6346. if len(keyword) > 0 {
  6347. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency=? and advice_name like ?"
  6348. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  6349. } else {
  6350. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency=?"
  6351. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  6352. }
  6353. } else {
  6354. if len(keyword) > 0 {
  6355. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  6356. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  6357. } else {
  6358. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3)2 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ?"
  6359. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6360. }
  6361. }
  6362. } else {
  6363. if len(execution_frequency) > 0 {
  6364. if len(keyword) > 0 {
  6365. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and execution_state = ? and execution_frequency=? and advice_name like ?"
  6366. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  6367. } else {
  6368. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and execution_state = ? and execution_frequency=?"
  6369. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  6370. }
  6371. } else {
  6372. if len(keyword) > 0 {
  6373. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and execution_state = ? and advice_name like ?"
  6374. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  6375. } else {
  6376. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  6377. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6378. }
  6379. }
  6380. }
  6381. } else {
  6382. if cost_type > 0 {
  6383. if len(execution_frequency) > 0 {
  6384. if len(keyword) > 0 {
  6385. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and is_settle = ? and execution_frequency=? and advice_name like ?"
  6386. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  6387. } else {
  6388. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and is_settle = ? and execution_frequency=?"
  6389. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  6390. }
  6391. } else {
  6392. if len(keyword) > 0 {
  6393. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and is_settle = ? and advice_name like ?"
  6394. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  6395. } else {
  6396. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  6397. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6398. }
  6399. }
  6400. } else {
  6401. if len(execution_frequency) > 0 {
  6402. if len(keyword) > 0 {
  6403. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and execution_frequency=? and advice_name like ?"
  6404. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  6405. } else {
  6406. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and execution_frequency=?"
  6407. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  6408. }
  6409. } else {
  6410. if len(keyword) > 0 {
  6411. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and advice_name like ?"
  6412. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  6413. } else {
  6414. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ?"
  6415. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6416. }
  6417. }
  6418. }
  6419. }
  6420. } else {
  6421. if execution_state > 0 {
  6422. if cost_type > 0 {
  6423. if len(execution_frequency) > 0 {
  6424. if len(keyword) > 0 {
  6425. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6426. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  6427. } else {
  6428. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and execution_state = ? and is_settle = ? and execution_frequency = ?"
  6429. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  6430. }
  6431. } else {
  6432. if len(keyword) > 0 {
  6433. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and execution_state = ? and is_settle = ? and advice_name like ?"
  6434. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  6435. } else {
  6436. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  6437. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6438. }
  6439. }
  6440. } else {
  6441. if len(execution_frequency) > 0 {
  6442. if len(keyword) > 0 {
  6443. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and execution_state = ? and execution_frequency = ? and advice_name like ?"
  6444. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  6445. } else {
  6446. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and execution_state = ? and execution_frequency = ? "
  6447. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  6448. }
  6449. } else {
  6450. if len(keyword) > 0 {
  6451. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and execution_state = ? and advice_name like ?"
  6452. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  6453. } else {
  6454. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND a(advice_type = 2 or advice_type =3) AND execution_staff = 0 and execution_state = ?"
  6455. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6456. }
  6457. }
  6458. }
  6459. } else {
  6460. if cost_type > 0 {
  6461. if len(execution_frequency) > 0 {
  6462. if len(keyword) > 0 {
  6463. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6464. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  6465. } else {
  6466. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  6467. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  6468. }
  6469. } else {
  6470. if len(keyword) > 0 {
  6471. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and is_settle = ? and advice_name like ?"
  6472. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  6473. } else {
  6474. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and is_settle = ?"
  6475. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6476. }
  6477. }
  6478. } else {
  6479. if len(execution_frequency) > 0 {
  6480. if len(keyword) > 0 {
  6481. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and execution_frequency = ? and advice_name like ?"
  6482. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  6483. } else {
  6484. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and execution_frequency = ?"
  6485. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  6486. }
  6487. } else {
  6488. if len(keyword) > 0 {
  6489. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and advice_name like ?"
  6490. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  6491. } else {
  6492. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0"
  6493. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6494. }
  6495. }
  6496. }
  6497. }
  6498. }
  6499. }
  6500. }
  6501. db := readDb.Table("xt_schedule")
  6502. if scheduleType > 0 {
  6503. db = db.Where("schedule_type = ?", scheduleType)
  6504. }
  6505. if partitonType > 0 {
  6506. db = db.Where("partition_id = ?", partitonType)
  6507. }
  6508. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6509. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6510. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6511. }).
  6512. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6513. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6514. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6515. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6516. Preload("DoctorAdvices", adviceCondition...).
  6517. Where("status = 1 AND user_org_id = ?", orgID)
  6518. if scheduleDate != 0 {
  6519. db = db.Where("schedule_date = ?", scheduleDate)
  6520. }
  6521. err := db.Find(&vms).Error
  6522. return vms, err
  6523. }
  6524. 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) {
  6525. var vms []*MScheduleDoctorAdviceVM
  6526. adviceWhere := ""
  6527. adviceCondition := []interface{}{}
  6528. if adviceType == 0 {
  6529. if patientType == 0 {
  6530. if patient_id > 0 {
  6531. if execution_state > 0 {
  6532. if cost_type > 0 {
  6533. 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 = ?"
  6534. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6535. } else {
  6536. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  6537. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6538. }
  6539. } else {
  6540. if cost_type > 0 {
  6541. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and is_settle = ?"
  6542. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6543. } else {
  6544. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
  6545. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6546. }
  6547. }
  6548. } else {
  6549. if execution_state > 0 {
  6550. if cost_type > 0 {
  6551. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and is_settle = ?"
  6552. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6553. } else {
  6554. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ?"
  6555. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6556. }
  6557. } else {
  6558. if cost_type > 0 {
  6559. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ?"
  6560. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6561. } else {
  6562. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  6563. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6564. }
  6565. }
  6566. }
  6567. } else if patientType == 1 {
  6568. if patient_id > 0 {
  6569. if execution_state > 0 {
  6570. if cost_type > 0 {
  6571. 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 = ?"
  6572. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  6573. } else {
  6574. 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= ?"
  6575. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  6576. }
  6577. } else {
  6578. if cost_type > 0 {
  6579. 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=?"
  6580. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  6581. } else {
  6582. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
  6583. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  6584. }
  6585. }
  6586. } else {
  6587. if execution_state > 0 {
  6588. if cost_type > 0 {
  6589. 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=?"
  6590. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  6591. } else {
  6592. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  6593. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  6594. }
  6595. } else {
  6596. if cost_type > 0 {
  6597. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and is_settle=?"
  6598. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  6599. } else {
  6600. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  6601. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  6602. }
  6603. }
  6604. }
  6605. } else if patientType == 2 {
  6606. if patient_id > 0 {
  6607. if execution_state > 0 {
  6608. if cost_type > 0 {
  6609. 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=?"
  6610. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6611. } else {
  6612. 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 = ?"
  6613. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6614. }
  6615. } else {
  6616. if cost_type > 0 {
  6617. 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=?"
  6618. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6619. } else {
  6620. 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 = ?)"
  6621. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6622. }
  6623. }
  6624. } else {
  6625. if execution_state > 0 {
  6626. if cost_type > 0 {
  6627. 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=?"
  6628. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6629. } else {
  6630. 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 = ?"
  6631. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6632. }
  6633. } else {
  6634. if cost_type > 0 {
  6635. 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 = ?"
  6636. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6637. } else {
  6638. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  6639. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6640. }
  6641. }
  6642. }
  6643. }
  6644. } else if adviceType == 1 {
  6645. if patientType == 0 {
  6646. if patient_id > 0 {
  6647. if execution_state > 0 {
  6648. if cost_type > 0 {
  6649. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  6650. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6651. } else {
  6652. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ?"
  6653. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6654. }
  6655. } else {
  6656. if cost_type > 0 {
  6657. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? "
  6658. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6659. } else {
  6660. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
  6661. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6662. }
  6663. }
  6664. } else {
  6665. if execution_state > 0 {
  6666. if cost_type > 0 {
  6667. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ?"
  6668. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6669. } else {
  6670. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ?"
  6671. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6672. }
  6673. } else {
  6674. if cost_type > 0 {
  6675. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = ? "
  6676. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6677. } else {
  6678. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  6679. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6680. }
  6681. }
  6682. }
  6683. } else if patientType == 1 {
  6684. if patient_id > 0 {
  6685. if execution_state > 0 {
  6686. if cost_type > 0 {
  6687. 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 = ?"
  6688. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  6689. } else {
  6690. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  6691. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  6692. }
  6693. } else {
  6694. if cost_type > 0 {
  6695. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  6696. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  6697. } else {
  6698. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
  6699. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  6700. }
  6701. }
  6702. } else {
  6703. if execution_state > 0 {
  6704. if cost_type > 0 {
  6705. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=? and is_settle = ?"
  6706. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  6707. } else {
  6708. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?"
  6709. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  6710. }
  6711. } else {
  6712. if cost_type > 0 {
  6713. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? "
  6714. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  6715. } else {
  6716. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  6717. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  6718. }
  6719. }
  6720. }
  6721. } else if patientType == 2 {
  6722. if patient_id > 0 {
  6723. if execution_state > 0 {
  6724. if cost_type > 0 {
  6725. 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 = ?"
  6726. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6727. } else {
  6728. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  6729. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6730. }
  6731. } else {
  6732. if cost_type > 0 {
  6733. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  6734. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6735. } else {
  6736. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
  6737. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6738. }
  6739. }
  6740. } else {
  6741. if execution_state > 0 {
  6742. if cost_type > 0 {
  6743. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  6744. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6745. } else {
  6746. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ?"
  6747. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6748. }
  6749. } else {
  6750. if cost_type > 0 {
  6751. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ?"
  6752. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6753. } else {
  6754. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  6755. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6756. }
  6757. }
  6758. }
  6759. }
  6760. } else if adviceType == 3 {
  6761. if patientType == 0 {
  6762. if patient_id > 0 {
  6763. if execution_state > 0 {
  6764. if cost_type > 0 {
  6765. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  6766. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6767. } else {
  6768. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ?"
  6769. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6770. }
  6771. } else {
  6772. if cost_type > 0 {
  6773. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? "
  6774. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6775. } else {
  6776. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? "
  6777. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6778. }
  6779. }
  6780. } else {
  6781. if execution_state > 0 {
  6782. if cost_type > 0 {
  6783. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ?"
  6784. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6785. } else {
  6786. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? "
  6787. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6788. }
  6789. } else {
  6790. if cost_type > 0 {
  6791. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? "
  6792. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6793. } else {
  6794. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  6795. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6796. }
  6797. }
  6798. }
  6799. } else if patientType == 1 {
  6800. if patient_id > 0 {
  6801. if execution_state > 0 {
  6802. if cost_type > 0 {
  6803. 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 = ?"
  6804. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  6805. } else {
  6806. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  6807. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  6808. }
  6809. } else {
  6810. if cost_type > 0 {
  6811. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  6812. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  6813. } else {
  6814. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
  6815. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  6816. }
  6817. }
  6818. } else {
  6819. if execution_state > 0 {
  6820. if cost_type > 0 {
  6821. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? and is_settle = ?"
  6822. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  6823. } else {
  6824. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? "
  6825. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  6826. }
  6827. } else {
  6828. if cost_type > 0 {
  6829. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ?"
  6830. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  6831. } else {
  6832. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  6833. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  6834. }
  6835. }
  6836. }
  6837. } else if patientType == 2 {
  6838. if patient_id > 0 {
  6839. if execution_state > 0 {
  6840. if cost_type > 0 {
  6841. 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 = ?"
  6842. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6843. } else {
  6844. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  6845. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6846. }
  6847. } else {
  6848. if cost_type > 0 {
  6849. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  6850. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6851. } else {
  6852. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ?"
  6853. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6854. }
  6855. }
  6856. } else {
  6857. if execution_state > 0 {
  6858. if cost_type > 0 {
  6859. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and is_settle = ?"
  6860. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6861. } else {
  6862. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ?"
  6863. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6864. }
  6865. } else {
  6866. if cost_type > 0 {
  6867. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ?"
  6868. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6869. } else {
  6870. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  6871. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6872. }
  6873. }
  6874. }
  6875. }
  6876. } else if adviceType == 2 && len(deliverWay) > 0 {
  6877. if patientType == 0 {
  6878. if patient_id > 0 {
  6879. if execution_state > 0 {
  6880. if cost_type > 0 {
  6881. 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 = ?"
  6882. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  6883. } else {
  6884. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  6885. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  6886. }
  6887. } else {
  6888. if cost_type > 0 {
  6889. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and is_settle = ?"
  6890. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  6891. } else {
  6892. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ?"
  6893. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  6894. }
  6895. }
  6896. } else {
  6897. if execution_state > 0 {
  6898. if cost_type > 0 {
  6899. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and is_settle = ?"
  6900. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  6901. } else {
  6902. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ?"
  6903. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  6904. }
  6905. } else {
  6906. if cost_type > 0 {
  6907. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and is_settle = ?"
  6908. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  6909. } else {
  6910. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  6911. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  6912. }
  6913. }
  6914. }
  6915. } else if patientType == 1 {
  6916. if patient_id > 0 {
  6917. if execution_state > 0 {
  6918. if cost_type > 0 {
  6919. 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 = ?"
  6920. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type)
  6921. } else {
  6922. 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 = ?"
  6923. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state)
  6924. }
  6925. } else {
  6926. if cost_type > 0 {
  6927. 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 = ?"
  6928. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type)
  6929. } else {
  6930. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ?"
  6931. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
  6932. }
  6933. }
  6934. } else {
  6935. if execution_state > 0 {
  6936. if cost_type > 0 {
  6937. 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 = ?"
  6938. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type)
  6939. } else {
  6940. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ?"
  6941. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state)
  6942. }
  6943. } else {
  6944. if cost_type > 0 {
  6945. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and is_settle = ?"
  6946. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type)
  6947. } else {
  6948. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  6949. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  6950. }
  6951. }
  6952. }
  6953. } else if patientType == 2 {
  6954. if patient_id > 0 {
  6955. if execution_state > 0 {
  6956. if cost_type > 0 {
  6957. 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 = ?"
  6958. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  6959. } else {
  6960. 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 = ?"
  6961. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  6962. }
  6963. } else {
  6964. if cost_type > 0 {
  6965. 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 = ?"
  6966. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  6967. } else {
  6968. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ?"
  6969. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  6970. }
  6971. }
  6972. } else {
  6973. if execution_state > 0 {
  6974. if cost_type > 0 {
  6975. 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 = ?"
  6976. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  6977. } else {
  6978. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ?"
  6979. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  6980. }
  6981. } else {
  6982. if cost_type > 0 {
  6983. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and is_settle = ?"
  6984. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  6985. } else {
  6986. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  6987. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  6988. }
  6989. }
  6990. }
  6991. }
  6992. } else if adviceType == 2 && len(deliverWay) <= 0 {
  6993. if patientType == 0 {
  6994. if patient_id > 0 {
  6995. if execution_state > 0 {
  6996. if cost_type > 0 {
  6997. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  6998. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6999. } else {
  7000. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ?"
  7001. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  7002. }
  7003. } else {
  7004. if cost_type > 0 {
  7005. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and is_settle = ?"
  7006. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  7007. } else {
  7008. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ?"
  7009. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  7010. }
  7011. }
  7012. } else {
  7013. if execution_state > 0 {
  7014. if cost_type > 0 {
  7015. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ? and is_settle = ?"
  7016. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  7017. } else {
  7018. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?"
  7019. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  7020. }
  7021. } else {
  7022. if cost_type > 0 {
  7023. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and is_settle = ?"
  7024. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  7025. } else {
  7026. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  7027. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  7028. }
  7029. }
  7030. }
  7031. } else if patientType == 1 {
  7032. if patient_id > 0 {
  7033. if execution_state > 0 {
  7034. if cost_type > 0 {
  7035. 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 = ?"
  7036. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  7037. } else {
  7038. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  7039. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  7040. }
  7041. } else {
  7042. if cost_type > 0 {
  7043. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  7044. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  7045. } else {
  7046. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ?"
  7047. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  7048. }
  7049. }
  7050. } else {
  7051. if execution_state > 0 {
  7052. if cost_type > 0 {
  7053. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ? and is_settle = ?"
  7054. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  7055. } else {
  7056. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ?"
  7057. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  7058. }
  7059. } else {
  7060. if cost_type > 0 {
  7061. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and is_settle = ?"
  7062. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  7063. } else {
  7064. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?"
  7065. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  7066. }
  7067. }
  7068. }
  7069. } else if patientType == 2 {
  7070. if patient_id > 0 {
  7071. if execution_state > 0 {
  7072. if cost_type > 0 {
  7073. 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 = ?"
  7074. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  7075. } else {
  7076. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  7077. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  7078. }
  7079. } else {
  7080. if cost_type > 0 {
  7081. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  7082. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  7083. } else {
  7084. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ?"
  7085. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  7086. }
  7087. }
  7088. } else {
  7089. if execution_state > 0 {
  7090. if cost_type > 0 {
  7091. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  7092. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  7093. } else {
  7094. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ?"
  7095. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  7096. }
  7097. } else {
  7098. if cost_type > 0 {
  7099. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and is_settle = ?"
  7100. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  7101. } else {
  7102. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  7103. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  7104. }
  7105. }
  7106. }
  7107. }
  7108. }
  7109. db := readDb.Table("xt_schedule")
  7110. if scheduleType > 0 {
  7111. db = db.Where("schedule_type = ?", scheduleType)
  7112. }
  7113. if partitonType > 0 {
  7114. db = db.Where("partition_id = ?", partitonType)
  7115. }
  7116. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7117. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7118. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7119. }).
  7120. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7121. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7122. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7123. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7124. Preload("DoctorAdvices", adviceCondition...).
  7125. Where("status = 1 AND user_org_id = ?", orgID)
  7126. if scheduleDate != 0 {
  7127. db = db.Where("schedule_date = ?", scheduleDate)
  7128. }
  7129. err := db.Find(&vms).Error
  7130. return vms, err
  7131. }
  7132. func GetLastPatientOrder(id int64) (models.XtDialysisOrder, error) {
  7133. order := models.XtDialysisOrder{}
  7134. err := XTReadDB().Where("id = ? and status = 1", id).Find(&order).Error
  7135. return order, err
  7136. }
  7137. func UpdateMobilePatient(org_id int64, patient_id int64, schedule_remark string) error {
  7138. order := models.XtPatients{}
  7139. 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
  7140. 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
  7141. return err
  7142. }
  7143. func GetDialysisTotalCount(org_id int64, patient_id int64) (models.BloodDialysisOrderCount, error) {
  7144. order := models.BloodDialysisOrderCount{}
  7145. db := XTReadDB().Table("xt_dialysis_order as o")
  7146. 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
  7147. return order, err
  7148. }
  7149. func GetDialysisTotalCountOne(org_id int64, patient_id int64) (models.BloodDialysisOrderCount, error) {
  7150. order := models.BloodDialysisOrderCount{}
  7151. db := XTReadDB().Table("xt_dialysis_order as o")
  7152. 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
  7153. return order, err
  7154. }
  7155. func UpdateDialysisOrder(patient_id int64, dialysis_date int64, user_org_id int64, dialysis_total int64) (models.DialysisOrder, error) {
  7156. order := models.DialysisOrder{}
  7157. 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
  7158. return order, err
  7159. }
  7160. func UpdateDeviceInformation(patientid int64, dialysis_date int64) error {
  7161. information := models.DeviceInformation{}
  7162. err := UserWriteDB().Model(&information).Where("patient_id = ? and date = ? and status = 1", patientid, dialysis_date).Update(map[string]interface{}{"status": 0}).Error
  7163. return err
  7164. }
  7165. func MobileGetDoubleCheckSix(orgID int64, patientID int64, recordDate int64) (models.DoubleCheck, error) {
  7166. var record models.DoubleCheck
  7167. err := readDb.Where("patient_id = ? and user_org_id = ? and status = 1 and check_date = ?", patientID, orgID, recordDate).First(&record).Error
  7168. return record, err
  7169. }
  7170. func GetFirstMonitor(patient_id int64, monit_date int64) (models.MonitoringRecord, error) {
  7171. record := models.MonitoringRecord{}
  7172. err := XTReadDB().Where("patient_id = ? and monitoring_date = ? and status=1", patient_id, monit_date).First(&record).Error
  7173. return record, err
  7174. }
  7175. func GetFirstMonitorOne(patient_id int64, monit_date int64, org_id int64) (models.MonitoringRecord, error) {
  7176. record := models.MonitoringRecord{}
  7177. err := XTReadDB().Where("patient_id = ? and monitoring_date = ? and status=1 and user_org_id=?", patient_id, monit_date, org_id).First(&record).Error
  7178. return record, err
  7179. }
  7180. func GetLastMonitor(patient_id int64, monit_date int64, org_id int64) (models.MonitoringRecord, error) {
  7181. record := models.MonitoringRecord{}
  7182. err := XTReadDB().Where("patient_id = ? and monitoring_date = ? and status=1 and user_org_id = ?", patient_id, monit_date, org_id).Last(&record).Error
  7183. return record, err
  7184. }
  7185. func UpdateFirstMonitor(id int64, catheter_operation string) (models.MonitoringRecord, error) {
  7186. record := models.MonitoringRecord{}
  7187. err := XTWriteDB().Model(&record).Where("id = ? and status= 1", id).Updates(map[string]interface{}{"dispose": catheter_operation}).Error
  7188. return record, err
  7189. }
  7190. 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) {
  7191. var vms []*HisMScheduleDoctorAdviceVM
  7192. if len(deliverWay) > 0 {
  7193. db := readDb.Table("xt_schedule")
  7194. if scheduleType > 0 {
  7195. db = db.Where("schedule_type = ?", scheduleType)
  7196. }
  7197. if partitionType > 0 {
  7198. db = db.Where("partition_id = ?", partitionType)
  7199. }
  7200. if patient_id > 0 {
  7201. if execution_state > 0 {
  7202. if cost_type > 0 {
  7203. if len(execution_frequency) > 0 {
  7204. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7205. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7206. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7207. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7208. 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).
  7209. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7210. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7211. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7212. Where("status = 1 AND user_org_id = ?", orgID)
  7213. if scheduleDate != 0 {
  7214. db = db.Where("schedule_date = ?", scheduleDate)
  7215. }
  7216. err = db.Find(&vms).Error
  7217. } else {
  7218. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7219. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7220. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7221. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7222. 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).
  7223. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7224. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7225. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7226. Where("status = 1 AND user_org_id = ?", orgID)
  7227. if scheduleDate != 0 {
  7228. db = db.Where("schedule_date = ?", scheduleDate)
  7229. }
  7230. err = db.Find(&vms).Error
  7231. }
  7232. } else {
  7233. if len(execution_frequency) > 0 {
  7234. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7235. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7236. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7237. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7238. 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).
  7239. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7240. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7241. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7242. Where("status = 1 AND user_org_id = ?", orgID)
  7243. if scheduleDate != 0 {
  7244. db = db.Where("schedule_date = ?", scheduleDate)
  7245. }
  7246. err = db.Find(&vms).Error
  7247. } else {
  7248. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7249. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7250. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7251. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7252. 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).
  7253. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7254. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7255. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7256. Where("status = 1 AND user_org_id = ?", orgID)
  7257. if scheduleDate != 0 {
  7258. db = db.Where("schedule_date = ?", scheduleDate)
  7259. }
  7260. err = db.Find(&vms).Error
  7261. }
  7262. }
  7263. } else {
  7264. if cost_type > 0 {
  7265. if len(execution_frequency) > 0 {
  7266. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7267. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7268. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7269. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7270. 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).
  7271. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7272. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7273. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7274. Where("status = 1 AND user_org_id = ?", orgID)
  7275. if scheduleDate != 0 {
  7276. db = db.Where("schedule_date = ?", scheduleDate)
  7277. }
  7278. err = db.Find(&vms).Error
  7279. } else {
  7280. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7281. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7282. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7283. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7284. 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).
  7285. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7286. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7287. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7288. Where("status = 1 AND user_org_id = ?", orgID)
  7289. if scheduleDate != 0 {
  7290. db = db.Where("schedule_date = ?", scheduleDate)
  7291. }
  7292. err = db.Find(&vms).Error
  7293. }
  7294. } else {
  7295. if len(execution_frequency) > 0 {
  7296. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7297. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7298. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7299. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7300. 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).
  7301. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7302. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7303. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7304. Where("status = 1 AND user_org_id = ?", orgID)
  7305. if scheduleDate != 0 {
  7306. db = db.Where("schedule_date = ?", scheduleDate)
  7307. }
  7308. err = db.Find(&vms).Error
  7309. } else {
  7310. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7311. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7312. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7313. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7314. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ?", orgID, scheduleDate, deliverWay, patient_id).
  7315. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7316. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7317. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7318. Where("status = 1 AND user_org_id = ?", orgID)
  7319. if scheduleDate != 0 {
  7320. db = db.Where("schedule_date = ?", scheduleDate)
  7321. }
  7322. err = db.Find(&vms).Error
  7323. }
  7324. }
  7325. }
  7326. } else {
  7327. if execution_state > 0 {
  7328. if cost_type > 0 {
  7329. if len(execution_frequency) > 0 {
  7330. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7331. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7332. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7333. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7334. 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).
  7335. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7336. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7337. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7338. Where("status = 1 AND user_org_id = ?", orgID)
  7339. if scheduleDate != 0 {
  7340. db = db.Where("schedule_date = ?", scheduleDate)
  7341. }
  7342. err = db.Find(&vms).Error
  7343. } else {
  7344. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7345. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7346. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7347. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7348. 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).
  7349. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7350. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7351. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7352. Where("status = 1 AND user_org_id = ?", orgID)
  7353. if scheduleDate != 0 {
  7354. db = db.Where("schedule_date = ?", scheduleDate)
  7355. }
  7356. err = db.Find(&vms).Error
  7357. }
  7358. } else {
  7359. if len(execution_frequency) > 0 {
  7360. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7361. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7362. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7363. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7364. 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).
  7365. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7366. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7367. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7368. Where("status = 1 AND user_org_id = ?", orgID)
  7369. if scheduleDate != 0 {
  7370. db = db.Where("schedule_date = ?", scheduleDate)
  7371. }
  7372. err = db.Find(&vms).Error
  7373. } else {
  7374. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7375. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7376. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7377. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7378. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_state = ?", orgID, scheduleDate, deliverWay, execution_state).
  7379. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7380. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7381. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7382. Where("status = 1 AND user_org_id = ?", orgID)
  7383. if scheduleDate != 0 {
  7384. db = db.Where("schedule_date = ?", scheduleDate)
  7385. }
  7386. err = db.Find(&vms).Error
  7387. }
  7388. }
  7389. } else {
  7390. if cost_type > 0 {
  7391. if len(execution_frequency) > 0 {
  7392. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7393. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7394. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7395. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7396. 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).
  7397. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7398. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7399. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7400. Where("status = 1 AND user_org_id = ?", orgID)
  7401. if scheduleDate != 0 {
  7402. db = db.Where("schedule_date = ?", scheduleDate)
  7403. }
  7404. err = db.Find(&vms).Error
  7405. } else {
  7406. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7407. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7408. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7409. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7410. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and is_settle = ?", orgID, scheduleDate, deliverWay, cost_type).
  7411. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7412. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7413. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7414. Where("status = 1 AND user_org_id = ?", orgID)
  7415. if scheduleDate != 0 {
  7416. db = db.Where("schedule_date = ?", scheduleDate)
  7417. }
  7418. err = db.Find(&vms).Error
  7419. }
  7420. } else {
  7421. if len(execution_frequency) > 0 {
  7422. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7423. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7424. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7425. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7426. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_frequency = ?", orgID, scheduleDate, deliverWay, execution_frequency).
  7427. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7428. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7429. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7430. Where("status = 1 AND user_org_id = ?", orgID)
  7431. if scheduleDate != 0 {
  7432. db = db.Where("schedule_date = ?", scheduleDate)
  7433. }
  7434. err = db.Find(&vms).Error
  7435. } else {
  7436. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7437. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7438. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7439. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7440. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  7441. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7442. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7443. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7444. Where("status = 1 AND user_org_id = ?", orgID)
  7445. if scheduleDate != 0 {
  7446. db = db.Where("schedule_date = ?", scheduleDate)
  7447. }
  7448. err = db.Find(&vms).Error
  7449. }
  7450. }
  7451. }
  7452. }
  7453. } else {
  7454. db := readDb.Table("xt_schedule")
  7455. if scheduleType > 0 {
  7456. db = db.Where("schedule_type = ?", scheduleType)
  7457. }
  7458. if partitionType > 0 {
  7459. db = db.Where("partition_id = ?", partitionType)
  7460. }
  7461. if patient_id > 0 {
  7462. if execution_state > 0 {
  7463. fmt.Println("execution_state---------------------", execution_state)
  7464. if cost_type > 0 {
  7465. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7466. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7467. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7468. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7469. 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).
  7470. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7471. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7472. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7473. Where("status = 1 AND user_org_id = ?", orgID)
  7474. if scheduleDate != 0 {
  7475. db = db.Where("schedule_date = ?", scheduleDate)
  7476. }
  7477. err = db.Find(&vms).Error
  7478. } else {
  7479. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7480. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7481. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7482. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7483. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and execution_state = ?", orgID, scheduleDate, patient_id, execution_state).
  7484. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7485. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7486. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7487. Where("status = 1 AND user_org_id = ?", orgID)
  7488. if scheduleDate != 0 {
  7489. db = db.Where("schedule_date = ?", scheduleDate)
  7490. }
  7491. err = db.Find(&vms).Error
  7492. }
  7493. } else {
  7494. if cost_type > 0 {
  7495. if len(execution_frequency) > 0 {
  7496. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7497. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7498. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7499. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7500. 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).
  7501. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7502. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7503. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7504. Where("status = 1 AND user_org_id = ?", orgID)
  7505. if scheduleDate != 0 {
  7506. db = db.Where("schedule_date = ?", scheduleDate)
  7507. }
  7508. err = db.Find(&vms).Error
  7509. } else {
  7510. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7511. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7512. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7513. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7514. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and is_settle = ?", orgID, scheduleDate, patient_id, cost_type).
  7515. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7516. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7517. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7518. Where("status = 1 AND user_org_id = ?", orgID)
  7519. if scheduleDate != 0 {
  7520. db = db.Where("schedule_date = ?", scheduleDate)
  7521. }
  7522. err = db.Find(&vms).Error
  7523. }
  7524. } else {
  7525. if len(execution_frequency) > 0 {
  7526. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7527. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7528. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7529. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7530. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and execution_frequency = ?", orgID, scheduleDate, patient_id, execution_frequency).
  7531. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7532. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7533. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7534. Where("status = 1 AND user_org_id = ?", orgID)
  7535. if scheduleDate != 0 {
  7536. db = db.Where("schedule_date = ?", scheduleDate)
  7537. }
  7538. err = db.Find(&vms).Error
  7539. } else {
  7540. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7541. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7542. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7543. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7544. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7545. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7546. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7547. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7548. Where("status = 1 AND user_org_id = ?", orgID)
  7549. if scheduleDate != 0 {
  7550. db = db.Where("schedule_date = ?", scheduleDate)
  7551. }
  7552. err = db.Find(&vms).Error
  7553. }
  7554. }
  7555. }
  7556. } else {
  7557. if execution_state > 0 {
  7558. if cost_type > 0 {
  7559. if len(execution_frequency) > 0 {
  7560. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7561. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7562. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7563. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7564. 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).
  7565. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7566. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7567. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7568. Where("status = 1 AND user_org_id = ?", orgID)
  7569. if scheduleDate != 0 {
  7570. db = db.Where("schedule_date = ?", scheduleDate)
  7571. }
  7572. err = db.Find(&vms).Error
  7573. } else {
  7574. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7575. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7576. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7577. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7578. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ? and is_settle = ?", orgID, scheduleDate, execution_state, cost_type).
  7579. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7580. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7581. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7582. Where("status = 1 AND user_org_id = ?", orgID)
  7583. if scheduleDate != 0 {
  7584. db = db.Where("schedule_date = ?", scheduleDate)
  7585. }
  7586. err = db.Find(&vms).Error
  7587. }
  7588. } else {
  7589. if len(execution_frequency) > 0 {
  7590. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7591. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7592. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7593. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7594. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ? and execution_frequency = ?", orgID, scheduleDate, execution_state, execution_frequency).
  7595. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7596. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7597. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7598. Where("status = 1 AND user_org_id = ?", orgID)
  7599. if scheduleDate != 0 {
  7600. db = db.Where("schedule_date = ?", scheduleDate)
  7601. }
  7602. err = db.Find(&vms).Error
  7603. } else {
  7604. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7605. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7606. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7607. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7608. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ?", orgID, scheduleDate, execution_state).
  7609. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7610. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7611. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7612. Where("status = 1 AND user_org_id = ?", orgID)
  7613. if scheduleDate != 0 {
  7614. db = db.Where("schedule_date = ?", scheduleDate)
  7615. }
  7616. err = db.Find(&vms).Error
  7617. }
  7618. }
  7619. } else {
  7620. if cost_type > 0 {
  7621. if len(execution_frequency) > 0 {
  7622. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7623. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7624. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7625. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7626. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and is_settle = ?", orgID, scheduleDate, cost_type).
  7627. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7628. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7629. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7630. Where("status = 1 AND user_org_id = ?", orgID)
  7631. if scheduleDate != 0 {
  7632. db = db.Where("schedule_date = ?", scheduleDate)
  7633. }
  7634. err = db.Find(&vms).Error
  7635. } else {
  7636. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7637. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7638. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7639. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7640. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and is_settle = ? and execution_frequency = ?", orgID, scheduleDate, cost_type, execution_frequency).
  7641. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7642. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7643. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7644. Where("status = 1 AND user_org_id = ?", orgID)
  7645. if scheduleDate != 0 {
  7646. db = db.Where("schedule_date = ?", scheduleDate)
  7647. }
  7648. err = db.Find(&vms).Error
  7649. }
  7650. } else {
  7651. if len(execution_frequency) > 0 {
  7652. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7653. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7654. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7655. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7656. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_frequency = ?", orgID, scheduleDate, execution_frequency).
  7657. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7658. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7659. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7660. Where("status = 1 AND user_org_id = ?", orgID)
  7661. if scheduleDate != 0 {
  7662. db = db.Where("schedule_date = ?", scheduleDate)
  7663. }
  7664. err = db.Find(&vms).Error
  7665. } else {
  7666. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7667. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7668. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7669. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7670. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ?", orgID, scheduleDate).
  7671. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7672. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7673. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7674. Where("status = 1 AND user_org_id = ?", orgID)
  7675. if scheduleDate != 0 {
  7676. db = db.Where("schedule_date = ?", scheduleDate)
  7677. }
  7678. err = db.Find(&vms).Error
  7679. }
  7680. }
  7681. }
  7682. }
  7683. }
  7684. return vms, err
  7685. }
  7686. func GetPatientDryWeight(org_id int64, patient_id int64) (weight []*models.SgjPatientDryweight, err error) {
  7687. err = XTReadDB().Where("user_org_id = ? and patient_id = ? and status =1", org_id, patient_id).Order("id desc").Limit(6).Find(&weight).Error
  7688. return weight, err
  7689. }
  7690. 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) {
  7691. fmt.Println("deliverWay-----------------", deliverWay)
  7692. fmt.Println("execution_frequency------------------", execution_frequency)
  7693. fmt.Println("adviceType-----------------", adviceType)
  7694. fmt.Println("patientType----------------", patientType)
  7695. fmt.Println("patient_id----------------", patient_id)
  7696. fmt.Println("execution_state----------------", execution_state)
  7697. fmt.Println("cost_type---------------------", cost_type)
  7698. fmt.Println("execution_frequency", execution_frequency)
  7699. var vms []*MScheduleDoctorAdviceVM
  7700. adviceWhere := ""
  7701. keyword = "%" + keyword + "%"
  7702. adviceCondition := []interface{}{}
  7703. if adviceType == 1 {
  7704. if patientType == 0 {
  7705. if patient_id > 0 {
  7706. if execution_state > 0 {
  7707. if cost_type > 0 {
  7708. if len(execution_frequency) > 0 {
  7709. if len(keyword) > 0 {
  7710. if len(deliverWay) > 0 {
  7711. 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 ?"
  7712. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency, deliverWay, keyword)
  7713. } else {
  7714. 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 ?"
  7715. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency, keyword)
  7716. }
  7717. } else {
  7718. if len(deliverWay) > 0 {
  7719. 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 =?"
  7720. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency, deliverWay)
  7721. } else {
  7722. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  7723. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency)
  7724. }
  7725. }
  7726. } else {
  7727. if len(keyword) > 0 {
  7728. if len(deliverWay) > 0 {
  7729. 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 =?"
  7730. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, keyword, deliverWay)
  7731. } else {
  7732. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  7733. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, keyword)
  7734. }
  7735. } else {
  7736. if len(deliverWay) > 0 {
  7737. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ? and delivery_way =?"
  7738. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, deliverWay)
  7739. } else {
  7740. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ?"
  7741. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type)
  7742. }
  7743. }
  7744. }
  7745. } else {
  7746. if len(execution_frequency) > 0 {
  7747. if len(keyword) > 0 {
  7748. if len(deliverWay) > 0 {
  7749. 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 =?"
  7750. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency, keyword, deliverWay)
  7751. } else {
  7752. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  7753. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency, keyword)
  7754. }
  7755. } else {
  7756. if len(deliverWay) > 0 {
  7757. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and execution_frequency = ? and delivery_way =?"
  7758. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency, deliverWay)
  7759. } else {
  7760. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and execution_frequency = ?"
  7761. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency)
  7762. }
  7763. }
  7764. } else {
  7765. if len(keyword) > 0 {
  7766. if len(deliverWay) > 0 {
  7767. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and advice_name like ? and delivery_way =?"
  7768. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, keyword, deliverWay)
  7769. } else {
  7770. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and advice_name like ?"
  7771. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, keyword)
  7772. }
  7773. } else {
  7774. if len(deliverWay) > 0 {
  7775. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and delivery_way =?"
  7776. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, deliverWay)
  7777. } else {
  7778. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ?"
  7779. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state)
  7780. }
  7781. }
  7782. }
  7783. }
  7784. } else {
  7785. if cost_type > 0 {
  7786. if len(execution_frequency) > 0 {
  7787. if len(keyword) > 0 {
  7788. if len(deliverWay) > 0 {
  7789. 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 =?"
  7790. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency, keyword, deliverWay)
  7791. } else {
  7792. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  7793. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency, keyword)
  7794. }
  7795. } else {
  7796. if len(deliverWay) > 0 {
  7797. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and execution_frequency = ? and delivery_way =?"
  7798. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency, deliverWay)
  7799. } else {
  7800. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and execution_frequency = ?"
  7801. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency)
  7802. }
  7803. }
  7804. } else {
  7805. if len(keyword) > 0 {
  7806. if len(deliverWay) > 0 {
  7807. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and advice_name like ? and delivery_way =?"
  7808. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, keyword, deliverWay)
  7809. } else {
  7810. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and advice_name like ?"
  7811. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, keyword)
  7812. }
  7813. } else {
  7814. if len(deliverWay) > 0 {
  7815. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and delivery_way =?"
  7816. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, deliverWay)
  7817. } else {
  7818. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? "
  7819. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type)
  7820. }
  7821. }
  7822. }
  7823. } else {
  7824. if len(execution_frequency) > 0 {
  7825. if len(keyword) > 0 {
  7826. if len(deliverWay) > 0 {
  7827. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  7828. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency, keyword, deliverWay)
  7829. } else {
  7830. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_frequency = ? and advice_name like ?"
  7831. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency, keyword)
  7832. }
  7833. } else {
  7834. if len(deliverWay) > 0 {
  7835. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_frequency = ? and delivery_way =?"
  7836. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency, deliverWay)
  7837. } else {
  7838. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_frequency = ?"
  7839. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency)
  7840. }
  7841. }
  7842. } else {
  7843. if len(keyword) > 0 {
  7844. if len(deliverWay) > 0 {
  7845. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and advice_name like ? and delivery_way =?"
  7846. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, keyword, deliverWay)
  7847. } else {
  7848. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and advice_name like ?"
  7849. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, keyword)
  7850. }
  7851. } else {
  7852. if len(deliverWay) > 0 {
  7853. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and delivery_way =?"
  7854. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, deliverWay)
  7855. } else {
  7856. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? "
  7857. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id)
  7858. }
  7859. }
  7860. }
  7861. }
  7862. }
  7863. } else {
  7864. if execution_state > 0 {
  7865. if cost_type > 0 {
  7866. if len(execution_frequency) > 0 {
  7867. if len(keyword) > 0 {
  7868. if len(deliverWay) > 0 {
  7869. 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 =?"
  7870. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency, keyword, deliverWay)
  7871. } else {
  7872. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  7873. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency, keyword)
  7874. }
  7875. } else {
  7876. if len(deliverWay) > 0 {
  7877. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and execution_frequency = ? and delivery_way =?"
  7878. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency, deliverWay)
  7879. } else {
  7880. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and execution_frequency = ?"
  7881. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency)
  7882. }
  7883. }
  7884. } else {
  7885. if len(keyword) > 0 {
  7886. if len(deliverWay) > 0 {
  7887. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and advice_name like ? and delivery_way =?"
  7888. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, keyword, deliverWay)
  7889. } else {
  7890. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and advice_name like ?"
  7891. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, keyword)
  7892. }
  7893. } else {
  7894. if len(deliverWay) > 0 {
  7895. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and delivery_way =?"
  7896. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, deliverWay)
  7897. } else {
  7898. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ?"
  7899. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type)
  7900. }
  7901. }
  7902. }
  7903. } else {
  7904. if len(execution_frequency) > 0 {
  7905. if len(keyword) > 0 {
  7906. if len(deliverWay) > 0 {
  7907. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  7908. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency, keyword, deliverWay)
  7909. } else {
  7910. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and execution_frequency = ? and advice_name like ?"
  7911. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency, keyword)
  7912. }
  7913. } else {
  7914. if len(deliverWay) > 0 {
  7915. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and execution_frequency = ? and delivery_way =?"
  7916. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency, deliverWay)
  7917. } else {
  7918. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and execution_frequency = ?"
  7919. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency)
  7920. }
  7921. }
  7922. } else {
  7923. if len(keyword) > 0 {
  7924. if len(deliverWay) > 0 {
  7925. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and advice_name like ? and delivery_way =?"
  7926. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, keyword, deliverWay)
  7927. } else {
  7928. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and advice_name like ?"
  7929. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, keyword)
  7930. }
  7931. } else {
  7932. if len(deliverWay) > 0 {
  7933. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and delivery_way =?"
  7934. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, deliverWay)
  7935. } else {
  7936. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ?"
  7937. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state)
  7938. }
  7939. }
  7940. }
  7941. }
  7942. } else {
  7943. if cost_type > 0 {
  7944. if len(keyword) > 0 {
  7945. if len(deliverWay) > 0 {
  7946. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and is_settle = ? and advice_name like ? and delivery_way =?"
  7947. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, keyword, deliverWay)
  7948. } else {
  7949. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and is_settle = ? and advice_name like ?"
  7950. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, keyword)
  7951. }
  7952. } else {
  7953. if len(deliverWay) > 0 {
  7954. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and is_settle = ? and delivery_way =?"
  7955. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, deliverWay)
  7956. } else {
  7957. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and is_settle = ? "
  7958. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type)
  7959. }
  7960. }
  7961. } else {
  7962. if len(keyword) > 0 {
  7963. if len(deliverWay) > 0 {
  7964. if len(execution_frequency) > 0 {
  7965. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and advice_name like ? and delivery_way =? and execution_frequency =? "
  7966. adviceCondition = append(adviceCondition, adviceWhere, orgID, keyword, deliverWay, execution_frequency)
  7967. } else {
  7968. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and advice_name like ? and delivery_way =?"
  7969. adviceCondition = append(adviceCondition, adviceWhere, orgID, keyword, deliverWay)
  7970. }
  7971. } else {
  7972. if len(execution_frequency) > 0 {
  7973. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and advice_name like ? and execution_frequency =?"
  7974. adviceCondition = append(adviceCondition, adviceWhere, orgID, keyword, execution_frequency)
  7975. } else {
  7976. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and advice_name like ?"
  7977. adviceCondition = append(adviceCondition, adviceWhere, orgID, keyword)
  7978. }
  7979. }
  7980. } else {
  7981. if len(deliverWay) > 0 {
  7982. if len(execution_frequency) > 0 {
  7983. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and delivery_way =? and execution_frequency =?"
  7984. adviceCondition = append(adviceCondition, adviceWhere, orgID, deliverWay, execution_frequency)
  7985. } else {
  7986. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and delivery_way =?"
  7987. adviceCondition = append(adviceCondition, adviceWhere, orgID, deliverWay)
  7988. }
  7989. } else {
  7990. if len(execution_frequency) > 0 {
  7991. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_frequency =?"
  7992. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_frequency)
  7993. } else {
  7994. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 "
  7995. adviceCondition = append(adviceCondition, adviceWhere, orgID)
  7996. }
  7997. }
  7998. }
  7999. }
  8000. }
  8001. }
  8002. } else if patientType == 1 {
  8003. if patient_id > 0 {
  8004. if execution_state > 0 {
  8005. if cost_type > 0 {
  8006. if len(execution_frequency) > 0 {
  8007. if len(keyword) > 0 {
  8008. if len(deliverWay) > 0 {
  8009. 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 =?"
  8010. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword, deliverWay)
  8011. } else {
  8012. 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 ?"
  8013. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  8014. }
  8015. } else {
  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_state = ? and is_settle = ? and execution_frequency = ? and delivery_way =?"
  8019. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, execution_frequency, deliverWay)
  8020. }
  8021. } else {
  8022. if len(deliverWay) > 0 {
  8023. 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 =?"
  8024. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, execution_frequency, deliverWay)
  8025. } else {
  8026. 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 = ?"
  8027. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  8028. }
  8029. }
  8030. }
  8031. } else {
  8032. if len(keyword) > 0 {
  8033. if len(deliverWay) > 0 {
  8034. 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 =?"
  8035. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, keyword, deliverWay)
  8036. } else {
  8037. 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 ?"
  8038. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, keyword)
  8039. }
  8040. } else {
  8041. if len(deliverWay) > 0 {
  8042. 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 =?"
  8043. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, deliverWay)
  8044. } else {
  8045. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  8046. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type)
  8047. }
  8048. }
  8049. }
  8050. } else {
  8051. if len(execution_frequency) > 0 {
  8052. if len(keyword) > 0 {
  8053. if len(deliverWay) > 0 {
  8054. 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 =?"
  8055. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, execution_frequency, keyword, deliverWay)
  8056. } else {
  8057. 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 ?"
  8058. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  8059. }
  8060. } else {
  8061. if len(deliverWay) > 0 {
  8062. 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 =?"
  8063. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, execution_frequency, deliverWay)
  8064. } else {
  8065. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  8066. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, execution_frequency)
  8067. }
  8068. }
  8069. } else {
  8070. if len(keyword) > 0 {
  8071. if len(deliverWay) > 0 {
  8072. 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 =?"
  8073. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, keyword, deliverWay)
  8074. } else {
  8075. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  8076. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, keyword)
  8077. }
  8078. } else {
  8079. if len(deliverWay) > 0 {
  8080. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and delivery_way =?"
  8081. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, deliverWay)
  8082. } else {
  8083. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  8084. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state)
  8085. }
  8086. }
  8087. }
  8088. }
  8089. } else {
  8090. if cost_type > 0 {
  8091. if len(execution_frequency) > 0 {
  8092. if len(keyword) > 0 {
  8093. if len(deliverWay) > 0 {
  8094. 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 =?"
  8095. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, execution_frequency, keyword, deliverWay)
  8096. } else {
  8097. 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 ?"
  8098. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  8099. }
  8100. } else {
  8101. if len(deliverWay) > 0 {
  8102. 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 =?"
  8103. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, execution_frequency, deliverWay)
  8104. } else {
  8105. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ?and execution_frequency = ?"
  8106. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, execution_frequency)
  8107. }
  8108. }
  8109. } else {
  8110. if len(keyword) > 0 {
  8111. if len(deliverWay) > 0 {
  8112. 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 =?"
  8113. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, keyword, deliverWay)
  8114. } else {
  8115. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  8116. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, keyword)
  8117. }
  8118. } else {
  8119. if len(deliverWay) > 0 {
  8120. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ? and delivery_way =? "
  8121. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, deliverWay)
  8122. } else {
  8123. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  8124. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type)
  8125. }
  8126. }
  8127. }
  8128. } else {
  8129. if len(execution_frequency) > 0 {
  8130. if len(keyword) > 0 {
  8131. if len(deliverWay) > 0 {
  8132. 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 =? "
  8133. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_frequency, keyword, deliverWay)
  8134. } else {
  8135. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  8136. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_frequency, keyword)
  8137. }
  8138. } else {
  8139. if len(deliverWay) > 0 {
  8140. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_frequency = ? and delivery_way =? "
  8141. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_frequency, deliverWay)
  8142. } else {
  8143. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  8144. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_frequency)
  8145. }
  8146. }
  8147. } else {
  8148. if len(keyword) > 0 {
  8149. if len(deliverWay) > 0 {
  8150. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and advice_name like ? and delivery_way =?"
  8151. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, keyword, deliverWay)
  8152. } else {
  8153. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and advice_name like ?"
  8154. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, keyword)
  8155. }
  8156. } else {
  8157. if len(deliverWay) > 0 {
  8158. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and delivery_way =?"
  8159. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, deliverWay)
  8160. } else {
  8161. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ?"
  8162. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id)
  8163. }
  8164. }
  8165. }
  8166. }
  8167. }
  8168. } else {
  8169. if execution_state > 0 {
  8170. if cost_type > 0 {
  8171. if len(execution_frequency) > 0 {
  8172. if len(keyword) > 0 {
  8173. if len(deliverWay) > 0 {
  8174. 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 =?"
  8175. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, execution_frequency, keyword, deliverWay)
  8176. } else {
  8177. 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 ?"
  8178. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  8179. }
  8180. } else {
  8181. if len(deliverWay) > 0 {
  8182. 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 =?"
  8183. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, execution_frequency, deliverWay)
  8184. } else {
  8185. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ?and execution_frequency = ?"
  8186. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, execution_frequency)
  8187. }
  8188. }
  8189. } else {
  8190. if len(keyword) > 0 {
  8191. if len(deliverWay) > 0 {
  8192. 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 =?"
  8193. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, keyword, deliverWay)
  8194. } else {
  8195. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ? and advice_name like ?"
  8196. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, keyword)
  8197. }
  8198. } else {
  8199. if len(deliverWay) > 0 {
  8200. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ? and delivery_way =?"
  8201. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, deliverWay)
  8202. } else {
  8203. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ?"
  8204. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type)
  8205. }
  8206. }
  8207. }
  8208. } else {
  8209. if len(execution_frequency) > 0 {
  8210. if len(keyword) > 0 {
  8211. if len(deliverWay) > 0 {
  8212. 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 =?"
  8213. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, execution_frequency, keyword, deliverWay)
  8214. } else {
  8215. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=?and execution_frequency = ? and advice_name like ?"
  8216. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, execution_frequency, keyword)
  8217. }
  8218. } else {
  8219. if len(deliverWay) > 0 {
  8220. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=?and execution_frequency = ? and delivery_way =?"
  8221. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, execution_frequency, deliverWay)
  8222. } else {
  8223. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=?and execution_frequency = ?"
  8224. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, execution_frequency)
  8225. }
  8226. }
  8227. } else {
  8228. if len(keyword) > 0 {
  8229. if len(deliverWay) > 0 {
  8230. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and advice_name like ? and delivery_way =?"
  8231. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, keyword, deliverWay)
  8232. } else {
  8233. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and advice_name like ?"
  8234. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, keyword)
  8235. }
  8236. } else {
  8237. if len(deliverWay) > 0 {
  8238. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and delivery_way =?"
  8239. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, deliverWay)
  8240. } else {
  8241. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=?"
  8242. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state)
  8243. }
  8244. }
  8245. }
  8246. }
  8247. } else {
  8248. if cost_type > 0 {
  8249. if len(execution_frequency) > 0 {
  8250. if len(keyword) > 0 {
  8251. if len(deliverWay) > 0 {
  8252. 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 =?"
  8253. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, execution_frequency, keyword, deliverWay)
  8254. } else {
  8255. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  8256. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, execution_frequency, keyword)
  8257. }
  8258. } else {
  8259. if len(deliverWay) > 0 {
  8260. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and execution_frequency = ? and delivery_way =?"
  8261. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, execution_frequency, deliverWay)
  8262. } else {
  8263. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  8264. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, execution_frequency)
  8265. }
  8266. }
  8267. } else {
  8268. if len(keyword) > 0 {
  8269. if len(deliverWay) > 0 {
  8270. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and advice_name like ? and delivery_way =?"
  8271. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, keyword, deliverWay)
  8272. } else {
  8273. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and advice_name like ?"
  8274. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, keyword)
  8275. }
  8276. } else {
  8277. if len(deliverWay) > 0 {
  8278. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and delivery_way =?"
  8279. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, deliverWay)
  8280. } else {
  8281. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? "
  8282. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type)
  8283. }
  8284. }
  8285. }
  8286. } else {
  8287. if len(execution_frequency) > 0 {
  8288. if len(keyword) > 0 {
  8289. if len(deliverWay) > 0 {
  8290. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  8291. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_frequency, keyword, deliverWay)
  8292. } else {
  8293. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_frequency = ? and advice_name like ?"
  8294. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_frequency, keyword)
  8295. }
  8296. } else {
  8297. if len(deliverWay) > 0 {
  8298. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_frequency = ? and delivery_way =?"
  8299. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_frequency, deliverWay)
  8300. } else {
  8301. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_frequency = ?"
  8302. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_frequency)
  8303. }
  8304. }
  8305. } else {
  8306. if len(keyword) > 0 {
  8307. if len(deliverWay) > 0 {
  8308. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and advice_name like ? and delivery_way =?"
  8309. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, keyword, deliverWay)
  8310. } else {
  8311. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and advice_name like ?"
  8312. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, keyword)
  8313. }
  8314. } else {
  8315. if len(deliverWay) > 0 {
  8316. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and delivery_way =?"
  8317. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, deliverWay)
  8318. } else {
  8319. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? "
  8320. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId)
  8321. }
  8322. }
  8323. }
  8324. }
  8325. }
  8326. }
  8327. } else if patientType == 2 {
  8328. if patient_id > 0 {
  8329. if execution_state > 0 {
  8330. if cost_type > 0 {
  8331. if len(execution_frequency) > 0 {
  8332. if len(keyword) > 0 {
  8333. if len(deliverWay) > 0 {
  8334. 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 =?"
  8335. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency, keyword, deliverWay)
  8336. } else {
  8337. 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 ?"
  8338. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency, keyword)
  8339. }
  8340. } else {
  8341. if len(deliverWay) > 0 {
  8342. 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 =?"
  8343. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency, deliverWay)
  8344. } else {
  8345. 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 = ?"
  8346. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency)
  8347. }
  8348. }
  8349. } else {
  8350. if len(keyword) > 0 {
  8351. if len(deliverWay) > 0 {
  8352. 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 =?"
  8353. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, keyword, deliverWay)
  8354. } else {
  8355. 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 ?"
  8356. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, keyword)
  8357. }
  8358. } else {
  8359. if len(deliverWay) > 0 {
  8360. 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 =?"
  8361. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, deliverWay)
  8362. } else {
  8363. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ?"
  8364. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type)
  8365. }
  8366. }
  8367. }
  8368. } else {
  8369. if len(execution_frequency) > 0 {
  8370. if len(keyword) > 0 {
  8371. if len(deliverWay) > 0 {
  8372. 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 =?"
  8373. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency, keyword, deliverWay)
  8374. } else {
  8375. 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 ?"
  8376. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency, keyword)
  8377. }
  8378. } else {
  8379. if len(deliverWay) > 0 {
  8380. 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 =?"
  8381. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency, deliverWay)
  8382. } else {
  8383. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and execution_frequency = ?"
  8384. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency)
  8385. }
  8386. }
  8387. } else {
  8388. if len(keyword) > 0 {
  8389. if len(deliverWay) > 0 {
  8390. 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 =?"
  8391. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, keyword, deliverWay)
  8392. } else {
  8393. 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 ?"
  8394. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, keyword)
  8395. }
  8396. } else {
  8397. if len(deliverWay) > 0 {
  8398. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and delivery_way =?"
  8399. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, deliverWay)
  8400. } else {
  8401. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  8402. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state)
  8403. }
  8404. }
  8405. }
  8406. }
  8407. } else {
  8408. if cost_type > 0 {
  8409. if len(execution_frequency) > 0 {
  8410. if len(keyword) > 0 {
  8411. if len(deliverWay) > 0 {
  8412. 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 =?"
  8413. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency, keyword, deliverWay)
  8414. } else {
  8415. 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 ?"
  8416. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency, keyword)
  8417. }
  8418. } else {
  8419. if len(deliverWay) > 0 {
  8420. 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 =?"
  8421. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency, deliverWay)
  8422. } else {
  8423. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and is_settle = ? and execution_frequency = ?"
  8424. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency)
  8425. }
  8426. }
  8427. } else {
  8428. if len(keyword) > 0 {
  8429. if len(deliverWay) > 0 {
  8430. 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 =?"
  8431. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, keyword, deliverWay)
  8432. } else {
  8433. 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 ?"
  8434. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, keyword)
  8435. }
  8436. } else {
  8437. if len(deliverWay) > 0 {
  8438. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and is_settle = ? and delivery_way =?"
  8439. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, deliverWay)
  8440. } else {
  8441. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  8442. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type)
  8443. }
  8444. }
  8445. }
  8446. } else {
  8447. if len(execution_frequency) > 0 {
  8448. if len(keyword) > 0 {
  8449. if len(deliverWay) > 0 {
  8450. 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 =?"
  8451. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency, keyword, deliverWay)
  8452. } else {
  8453. 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 ?"
  8454. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency, keyword)
  8455. }
  8456. } else {
  8457. if len(deliverWay) > 0 {
  8458. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_frequency = ? and delivery_way =?"
  8459. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency, deliverWay)
  8460. } else {
  8461. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_frequency = ?"
  8462. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency)
  8463. }
  8464. }
  8465. } else {
  8466. if len(keyword) > 0 {
  8467. if len(deliverWay) > 0 {
  8468. 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 =?"
  8469. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, keyword, deliverWay)
  8470. } else {
  8471. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and advice_name like ?"
  8472. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, keyword)
  8473. }
  8474. } else {
  8475. if len(deliverWay) > 0 {
  8476. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and delivery_way =?"
  8477. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, deliverWay)
  8478. } else {
  8479. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ?"
  8480. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id)
  8481. }
  8482. }
  8483. }
  8484. }
  8485. }
  8486. } else {
  8487. if execution_state > 0 {
  8488. if cost_type > 0 {
  8489. if len(execution_frequency) > 0 {
  8490. if len(keyword) > 0 {
  8491. if len(deliverWay) > 0 {
  8492. 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 =?"
  8493. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency, keyword, deliverWay)
  8494. } else {
  8495. 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 ?"
  8496. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency, keyword)
  8497. }
  8498. } else {
  8499. if len(deliverWay) > 0 {
  8500. 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 =?"
  8501. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency, deliverWay)
  8502. } else {
  8503. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ? and execution_frequency = ?"
  8504. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency)
  8505. }
  8506. }
  8507. } else {
  8508. if len(keyword) > 0 {
  8509. if len(deliverWay) > 0 {
  8510. 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 =?"
  8511. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, keyword, deliverWay)
  8512. } else {
  8513. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ? and advice_name like ?"
  8514. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, keyword)
  8515. }
  8516. } else {
  8517. if len(deliverWay) > 0 {
  8518. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ? and delivery_way =?"
  8519. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, deliverWay)
  8520. } else {
  8521. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  8522. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type)
  8523. }
  8524. }
  8525. }
  8526. } else {
  8527. if len(execution_frequency) > 0 {
  8528. if len(keyword) > 0 {
  8529. if len(deliverWay) > 0 {
  8530. 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 =?"
  8531. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency, keyword, deliverWay)
  8532. } else {
  8533. 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 ?"
  8534. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency, keyword)
  8535. }
  8536. } else {
  8537. if len(deliverWay) > 0 {
  8538. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ? and execution_frequency = ? and delivery_way =?"
  8539. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency, deliverWay)
  8540. } else {
  8541. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ? and execution_frequency = ?"
  8542. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency)
  8543. }
  8544. }
  8545. } else {
  8546. if len(keyword) > 0 {
  8547. if len(deliverWay) > 0 {
  8548. 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 =?"
  8549. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, keyword, deliverWay)
  8550. } else {
  8551. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ? and advice_name like ?"
  8552. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, keyword)
  8553. }
  8554. } else {
  8555. if len(deliverWay) > 0 {
  8556. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ? and delivery_way =?"
  8557. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, deliverWay)
  8558. } else {
  8559. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ?"
  8560. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state)
  8561. }
  8562. }
  8563. }
  8564. }
  8565. } else {
  8566. if cost_type > 0 {
  8567. if len(execution_frequency) > 0 {
  8568. if len(keyword) > 0 {
  8569. if len(deliverWay) > 0 {
  8570. 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 =?"
  8571. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, execution_frequency, keyword, deliverWay)
  8572. } else {
  8573. 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 ?"
  8574. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, execution_frequency, keyword)
  8575. }
  8576. } else {
  8577. if len(deliverWay) > 0 {
  8578. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ? and execution_frequency = ? and delivery_way =?"
  8579. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, execution_frequency, deliverWay)
  8580. } else {
  8581. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  8582. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, execution_frequency)
  8583. }
  8584. }
  8585. } else {
  8586. if len(keyword) > 0 {
  8587. if len(deliverWay) > 0 {
  8588. 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 =?"
  8589. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, keyword, deliverWay)
  8590. } else {
  8591. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ? and advice_name like ?"
  8592. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, keyword)
  8593. }
  8594. } else {
  8595. if len(deliverWay) > 0 {
  8596. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ? and delivery_way =?"
  8597. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, deliverWay)
  8598. } else {
  8599. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ?"
  8600. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type)
  8601. }
  8602. }
  8603. }
  8604. } else {
  8605. if len(execution_frequency) > 0 {
  8606. if len(keyword) > 0 {
  8607. if len(deliverWay) > 0 {
  8608. 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 =?"
  8609. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_frequency, keyword, deliverWay)
  8610. } else {
  8611. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_frequency = ? and advice_name like ?"
  8612. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_frequency, keyword)
  8613. }
  8614. } else {
  8615. if len(deliverWay) > 0 {
  8616. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_frequency = ? and delivery_way =?"
  8617. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_frequency, deliverWay)
  8618. } else {
  8619. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_frequency = ?"
  8620. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_frequency)
  8621. }
  8622. }
  8623. } else {
  8624. if len(keyword) > 0 {
  8625. if len(deliverWay) > 0 {
  8626. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and advice_name like ? and delivery_way =?"
  8627. adviceCondition = append(adviceCondition, adviceWhere, orgID, keyword, deliverWay)
  8628. } else {
  8629. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and advice_name like ?"
  8630. adviceCondition = append(adviceCondition, adviceWhere, orgID, keyword)
  8631. }
  8632. } else {
  8633. if len(deliverWay) > 0 {
  8634. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and delivery_way =?"
  8635. adviceCondition = append(adviceCondition, adviceWhere, orgID, deliverWay)
  8636. } else {
  8637. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0"
  8638. adviceCondition = append(adviceCondition, adviceWhere, orgID)
  8639. }
  8640. }
  8641. }
  8642. }
  8643. }
  8644. }
  8645. }
  8646. }
  8647. db := readDb.Table("xt_schedule")
  8648. if scheduleType > 0 {
  8649. db = db.Where("schedule_type = ?", scheduleType)
  8650. }
  8651. if partitonType > 0 {
  8652. db = db.Where("partition_id = ?", partitonType)
  8653. }
  8654. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  8655. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  8656. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  8657. }).
  8658. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  8659. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  8660. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  8661. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  8662. Preload("DoctorAdvices", adviceCondition...).
  8663. Where("status = 1 AND user_org_id = ?", orgID)
  8664. if scheduleDate != 0 {
  8665. db = db.Where("schedule_date = ?", scheduleDate)
  8666. }
  8667. err := db.Find(&vms).Error
  8668. return vms, err
  8669. }
  8670. func GetLastAcceptTreatment(user_org_id int64, patient_id int64) (models.ReceiveTreatmentAsses, error) {
  8671. treatmentAsses := models.ReceiveTreatmentAsses{}
  8672. err := XTReadDB().Where("user_org_id = ? and patient_id = ? and status=1 and admission_number<>''", user_org_id, patient_id).Last(&treatmentAsses).Error
  8673. return treatmentAsses, err
  8674. }
  8675. func GetDrugIsShow(id int64, org_id int64) (models.XtBaseDrug, error) {
  8676. baseDrug := models.XtBaseDrug{}
  8677. err := XTReadDB().Where("id = ? and status =1 and org_id = ?", id, org_id).Find(&baseDrug).Error
  8678. return baseDrug, err
  8679. }