mobile_dialysis_service.go 541KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062
  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. DialysisSolution *models.DialysisSolution `gorm:"ForeignKey:PatientId,ModeId;AssociationForeignKey:PatientId,ModeId" json:"dialysis_solution"`
  116. }
  117. func (MDialysisScheduleVM) TableName() string {
  118. return "xt_schedule"
  119. }
  120. type MDialysisScheduleVMForList struct {
  121. ID int64 `gorm:"column:id" json:"id"`
  122. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  123. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  124. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  125. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  126. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  127. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  128. ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week"`
  129. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  130. Status int64 `gorm:"column:status" json:"status"`
  131. SchedualPatient *models.MSchedualPatientList `gorm:"ForeignKey:PatientId" json:"patient"`
  132. DeviceNumber *models.MDeviceNumberForList `gorm:"ForeignKey:BedId" json:"device_number"`
  133. DialysisOrder *models.MDialysisOrderForList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  134. DialysisLastOrder *models.MDialysisOrderForList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"last_order"`
  135. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  136. AssessmentBeforeDislysis *models.PredialysisEvaluationList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_before_dislysis"`
  137. AssessmentAfterDislysis *models.VMAssessmentAfterDislysis `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_after_dislysis"`
  138. HisAdvices []VMHisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"his_doctor_advice"`
  139. Advices []models.VMDoctorAdviceForList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  140. TreatmentSummary *models.VMTreatmentSummaryForList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"treatment_summary"`
  141. DialysisSolution *models.DialysisSolution `gorm:"ForeignKey:PatientId,ModeId;AssociationForeignKey:PatientId,ModeId" json:"dialysis_solution"`
  142. DoubleCheck *models.DoubleCheck `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dobule_check"`
  143. NewDeviceInformation *NewDeviceInformation `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"device_information"`
  144. //VMMonitoringRecord []models.VMMonitoringRecord `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"monitor_record"`
  145. }
  146. func (MDialysisScheduleVMForList) TableName() string {
  147. return "xt_schedule"
  148. }
  149. type MDeviceNumberVM struct {
  150. models.DeviceNumber
  151. Zone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"zone"`
  152. }
  153. func (MDeviceNumberVM) TableName() string {
  154. return "xt_device_number"
  155. }
  156. type MSchedualPatientVMList struct {
  157. ID int64 `gorm:"column:id" json:"id" form:"id"`
  158. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  159. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  160. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  161. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
  162. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  163. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  164. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  165. Age int64 `gorm:"column:age" json:"age"`
  166. Name string `gorm:"column:name" json:"name" form:"name"`
  167. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  168. UserSysBeforeCount int64 `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
  169. TrobleShoot int64 `gorm:"column:troble_shoot" json:"troble_shoot" form:"troble_shoot"`
  170. SchRemark string `gorm:"column:sch_remark" json:"sch_remark" form:"sch_remark"`
  171. ScheduleRemark string `gorm:"column:schedule_remark" json:"schedule_remark" form:"schedule_remark"`
  172. FirstLetter string `gorm:"column:first_letter" json:"first_letter" form:"first_letter"`
  173. }
  174. func (MSchedualPatientVMList) TableName() string {
  175. return "xt_patients"
  176. }
  177. type MSchedualPatientVM struct {
  178. ID int64 `gorm:"column:id" json:"id" form:"id"`
  179. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  180. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  181. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  182. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  183. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
  184. AdmissionNumber string `gorm:"column:admission_number" json:"admission_number" form:"admission_number"`
  185. Source int64 `gorm:"column:source" json:"source" form:"source"`
  186. Lapseto int64 `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
  187. PartitionId int64 `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
  188. BedId int64 `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
  189. Name string `gorm:"column:name" json:"name" form:"name"`
  190. Alias string `gorm:"column:alias" json:"alias" form:"alias"`
  191. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  192. Nation string `gorm:"column:nation" json:"nation" form:"nation"`
  193. NativePlace string `gorm:"column:native_place" json:"native_place" form:"native_place"`
  194. MaritalStatus int64 `gorm:"column:marital_status" json:"marital_status" form:"marital_status"`
  195. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  196. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  197. ReimbursementWayId int64 `gorm:"column:reimbursement_way_id" json:"reimbursement_way_id" form:"reimbursement_way_id"`
  198. HealthCareType int64 `gorm:"column:health_care_type" json:"health_care_type" form:"health_care_type"`
  199. HealthCareNo string `gorm:"column:health_care_no" json:"health_care_no" form:"health_care_no"`
  200. HealthCareDueDate int64 `gorm:"column:health_care_due_date" json:"health_care_due_date" form:"health_care_due_date"`
  201. Height int64 `gorm:"column:height" json:"height" form:"height"`
  202. BloodType int64 `gorm:"column:blood_type" json:"blood_type" form:"blood_type"`
  203. Rh int64 `gorm:"column:rh" json:"rh" form:"rh"`
  204. HealthCareDueAlertDate int64 `gorm:"column:health_care_due_alert_date" json:"health_care_due_alert_date" form:"health_care_due_alert_date"`
  205. EducationLevel int64 `gorm:"column:education_level" json:"education_level" form:"education_level"`
  206. Profession int64 `gorm:"column:profession" json:"profession" form:"profession"`
  207. Phone string `gorm:"column:phone" json:"phone" form:"phone"`
  208. HomeTelephone string `gorm:"column:home_telephone" json:"home_telephone" form:"home_telephone"`
  209. RelativePhone string `gorm:"column:relative_phone" json:"relative_phone" form:"relative_phone"`
  210. RelativeRelations string `gorm:"column:relative_relations" json:"relative_relations" form:"relative_relations"`
  211. HomeAddress string `gorm:"column:home_address" json:"home_address" form:"home_address"`
  212. WorkUnit string `gorm:"column:work_unit" json:"work_unit" form:"work_unit"`
  213. UnitAddress string `gorm:"column:unit_address" json:"unit_address" form:"unit_address"`
  214. Children int64 `gorm:"column:children" json:"children" form:"children"`
  215. ReceivingDate int64 `gorm:"column:receiving_date" json:"receiving_date" form:"receiving_date"`
  216. IsHospitalFirstDialysis int64 `gorm:"column:is_hospital_first_dialysis" json:"is_hospital_first_dialysis" form:"is_hospital_first_dialysis"`
  217. FirstDialysisDate int64 `gorm:"column:first_dialysis_date" json:"first_dialysis_date" form:"first_dialysis_date"`
  218. FirstDialysisHospital string `gorm:"column:first_dialysis_hospital" json:"first_dialysis_hospital" form:"first_dialysis_hospital"`
  219. InductionPeriod int64 `gorm:"column:induction_period" json:"induction_period" form:"induction_period"`
  220. InitialDialysis int64 `gorm:"column:initial_dialysis" json:"initial_dialysis" form:"initial_dialysis"`
  221. TotalDialysis int64 `gorm:"column:total_dialysis" json:"total_dialysis" form:"total_dialysis"`
  222. AttendingDoctorId int64 `gorm:"column:attending_doctor_id" json:"attending_doctor_id" form:"attending_doctor_id"`
  223. HeadNurseId int64 `gorm:"column:head_nurse_id" json:"head_nurse_id" form:"head_nurse_id"`
  224. Evaluate string `gorm:"column:evaluate" json:"evaluate" form:"evaluate"`
  225. Diagnose string `gorm:"column:diagnose" json:"diagnose" form:"diagnose"`
  226. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  227. RegistrarsId int64 `gorm:"column:registrars_id" json:"registrars_id" form:"registrars_id"`
  228. Registrars string `gorm:"column:registrars" json:"registrars" form:"registrars"`
  229. QrCode string `gorm:"column:qr_code" json:"qr_code" form:"qr_code"`
  230. BindingState int64 `gorm:"column:binding_state" json:"binding_state" form:"binding_state"`
  231. PatientComplains string `gorm:"column:patient_complains" json:"patient_complains"` // 主诉
  232. PresentHistory string `gorm:"column:present_history" json:"present_history"` // 现病史
  233. PastHistory string `gorm:"column:past_history" json:"past_history"` // 既往史
  234. Temperature float64 `gorm:"column:temperature" json:"temperature"` // 体格检查-体温
  235. Pulse int64 `gorm:"column:pulse" json:"pulse"` // 体格检查-脉搏
  236. Respiratory int64 `gorm:"column:respiratory" json:"respiratory"` // 体格检查-呼吸频率
  237. SBP int64 `gorm:"column:sbp" json:"sbp"` // 体格检查-收缩压
  238. DBP int64 `gorm:"column:dbp" json:"dbp"` // 体格检查-舒张压
  239. Status int64 `gorm:"column:status" json:"status" form:"status"`
  240. Age int64 `gorm:"column:age" json:"age"`
  241. IsOpenRemind int64 `gorm:"column:is_open_remind" json:"is_open_remind"`
  242. DialysisAge int64 `gorm:"column:dialysis_age" json:"dialysis_age" form:"dialysis_age"`
  243. ExpenseKind int64 `gorm:"column:expense_kind" json:"expense_kind" form:"expense_kind"`
  244. TellPhone string `gorm:"column:tell_phone" json:"tell_phone" form:"tell_phone"`
  245. FirstTreatmentDate int64 `gorm:"column:first_treatment_date" json:"first_treatment_date" form:"first_treatment_date"`
  246. ContactName string `gorm:"column:contact_name" json:"contact_name" form:"contact_name"`
  247. UserSysBeforeCount int64 `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
  248. FirstLetter string `gorm:"column:first_letter" json:"first_letter" form:"first_letter"`
  249. }
  250. func (MSchedualPatientVM) TableName() string {
  251. return "xt_patients"
  252. }
  253. type MDialysisOrderVM struct {
  254. ID int64 `gorm:"column:id" json:"id"`
  255. DialysisDate int64 `gorm:"column:dialysis_date" json:"dialysis_date"`
  256. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  257. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  258. Stage int64 `gorm:"column:stage" json:"stage"`
  259. BedID int64 `gorm:"column:bed_id" json:"bed_id"`
  260. StartNurse int64 `gorm:"column:start_nurse" json:"start_nurse"`
  261. FinishNurse int64 `gorm:"column:finish_nurse" json:"finish_nurse"`
  262. Status int64 `gorm:"column:status" json:"status"`
  263. PunctureNurse int64 `gorm:"column:puncture_nurse" json:"puncture_nurse"`
  264. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedID" json:"device_number"`
  265. MonitoringRecords []*models.MonitoringRecord `gorm:"ForeignKey:DialysisOrderId" json:"monitoring_records"`
  266. Creator int64 `gorm:"column:creator" json:"creator"`
  267. Modifier int64 `gorm:"column:modifier" json:"modifier"`
  268. FinishCreator int64 `gorm:"column:finish_creator" json:"finish_creator"`
  269. FinishModifier int64 `gorm:"column:finish_modifier" json:"finish_modifier"`
  270. SchedualType int64 `gorm:"column:schedual_type" json:"schedual_type"`
  271. WashpipeNurse int64 `gorm:"column:washpipe_nurse" json:"washpipe_nurse" form:"washpipe_nurse"`
  272. DialysisIrrigation string `gorm:"column:dialysis_irrigation" json:"dialysis_irrigation" form:"dialysis_irrigation"`
  273. DialysisDialyszers string `gorm:"column:dialysis_dialyszers" json:"dialysis_dialyszers" form:"dialysis_dialyszers"`
  274. }
  275. func (MDialysisOrderVM) TableName() string {
  276. return "xt_dialysis_order"
  277. }
  278. type MDialysisOrderVMList struct {
  279. ID int64 `gorm:"column:id" json:"id"`
  280. DialysisDate int64 `gorm:"column:dialysis_date" json:"dialysis_date"`
  281. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  282. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  283. // PrescriptionId int64 `gorm:"column:prescription_id" json:"prescription_id"`
  284. Stage int64 `gorm:"column:stage" json:"stage"`
  285. // Remark string `gorm:"column:remark" json:"remark"`
  286. BedID int64 `gorm:"column:bed_id" json:"bed_id"`
  287. StartNurse int64 `gorm:"column:start_nurse" json:"start_nurse"`
  288. Status int64 `gorm:"column:status" json:"status"`
  289. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedID" json:"device_number"`
  290. Creator int64 `gorm:"column:creator" json:"creator"`
  291. WashpipeNurse int64 `gorm:"column:washpipe_nurse" json:"washpipe_nurse" form:"washpipe_nurse"`
  292. NucleinDate int64 `gorm:"column:nuclein_date" json:"nuclein_date" form:"nuclein_date"`
  293. DialysisIrrigation string `gorm:"column:dialysis_irrigation" json:"dialysis_irrigation" form:"dialysis_irrigation"`
  294. DialysisDialyszers string `gorm:"column:dialysis_dialyszers" json:"dialysis_dialyszers" form:"dialysis_dialyszers"`
  295. ScheduleRemark string `gorm:"column:schedule_remark" json:"schedule_remark" form:"schedule_remark"`
  296. }
  297. func (MDialysisOrderVMList) TableName() string {
  298. return "xt_dialysis_order"
  299. }
  300. type VMDoctorAdvice struct {
  301. ID int64 `gorm:"column:id" json:"id" form:"id"`
  302. GroupNo int64 `gorm:"column:groupno" json:"groupno" form:"groupno"`
  303. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  304. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  305. AdviceDate int64 `gorm:"column:advice_date" json:"advice_date" form:"advice_date"`
  306. Status int64 `gorm:"column:status" json:"status" form:"status"`
  307. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
  308. RecordDate int64 `gorm:"column:record_date" json:"record_date"`
  309. CheckTime int64 `gorm:"column:check_time" json:"check_time" form:"check_time"`
  310. CheckState int64 `gorm:"column:check_state" json:"check_state" form:"check_state"`
  311. ParentId int64 `gorm:"column:parent_id" json:"parent_id" form:"parent_id"`
  312. }
  313. func (VMDoctorAdvice) TableName() string {
  314. return "xt_doctor_advice"
  315. }
  316. type VMHisDoctorAdviceInfo struct {
  317. ID int64 `gorm:"column:id" json:"id" form:"id"`
  318. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  319. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  320. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  321. ExecutionTime int64 `gorm:"column:execution_time" json:"execution_time" form:"execution_time"`
  322. ExecutionStaff int64 `gorm:"column:execution_staff" json:"execution_staff" form:"execution_staff"`
  323. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
  324. IsMedicine int64 `gorm:"column:is_medicine" json:"is_medicine" form:"is_medicine"`
  325. ExecutionFrequencyId int64 `gorm:"column:execution_frequency_id" json:"execution_frequency_id" form:"execution_frequency_id"`
  326. IsSelfDrug int64 `gorm:"column:is_self_drug" json:"is_self_drug" form:"is_self_drug"`
  327. }
  328. func (VMHisDoctorAdviceInfo) TableName() string {
  329. return "his_doctor_advice_info"
  330. }
  331. type VMAssessmentAfterDislysis struct {
  332. ID int64 `gorm:"column:id" json:"id"`
  333. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  334. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  335. AssessmentDate int64 `gorm:"column:assessment_date" json:"assessment_date"`
  336. WeightAfter float64 `gorm:"column:weight_after" json:"weight_after"`
  337. Status int64 `gorm:"column:status" json:"status"`
  338. }
  339. func (VMAssessmentAfterDislysis) TableName() string {
  340. return "xt_assessment_after_dislysis"
  341. }
  342. type NewDeviceInformation struct {
  343. ID int64 `gorm:"column:id" json:"id" form:"id"`
  344. Date int64 `gorm:"column:date" json:"date" form:"date"`
  345. Class int64 `gorm:"column:class" json:"class" form:"class"`
  346. Zone int64 `gorm:"column:zone" json:"zone" form:"zone"`
  347. BedNumber int64 `gorm:"column:bed_number" json:"bed_number" form:"bed_number"`
  348. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  349. Status int64 `gorm:"column:status" json:"status" form:"status"`
  350. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  351. EquimentId int64 `gorm:"column:equiment_id" json:"equiment_id" form:"equiment_id"`
  352. Bed string `gorm:"column:bed" json:"bed" form:"bed"`
  353. Stime int64 `gorm:"column:stime" json:"stime" form:"stime"`
  354. }
  355. func (NewDeviceInformation) TableName() string {
  356. return "xt_device_information"
  357. }
  358. // 获取透析记录
  359. func MobileGetDialysisRecord(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  360. var record models.DialysisOrder
  361. err := readDb.Model(&models.DialysisOrder{}).Where("user_org_id = ? AND patient_id = ? AND dialysis_date = ?", orgID, patientID, recordDate).First(&record).Error
  362. if err != nil {
  363. if err == gorm.ErrRecordNotFound {
  364. return nil, nil
  365. } else {
  366. return nil, err
  367. }
  368. }
  369. return &record, nil
  370. }
  371. // 用户基本信息
  372. func MobileGetPatientDetail(orgID int64, patientID int64) (*MPatient, error) {
  373. var patient MPatient
  374. //err := readDb.Model(&MPatient{}).Where("status = 1 AND user_org_id = ? AND id = ?", orgID, patientID).First(&patient).Error
  375. //if err != nil {
  376. // if err == gorm.ErrRecordNotFound {
  377. // return nil, nil
  378. // } else {
  379. // return nil, err
  380. // }
  381. //}
  382. //return &patient, nil
  383. redis := RedisClient()
  384. defer redis.Close()
  385. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":patient_info"
  386. patient_info_str, _ := redis.Get(key).Result()
  387. if len(patient_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  388. err = readDb.Model(&patient).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
  389. if err != nil {
  390. if err == gorm.ErrRecordNotFound {
  391. return &patient, nil
  392. } else {
  393. return &patient, err
  394. }
  395. } else {
  396. if patient.ID > 0 {
  397. //缓存数据
  398. patient_info_json, err := json.Marshal(&patient)
  399. if err == nil {
  400. redis.Set(key, patient_info_json, time.Second*60*60*18)
  401. }
  402. }
  403. return &patient, nil
  404. }
  405. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  406. json.Unmarshal([]byte(patient_info_str), &patient)
  407. return &patient, nil
  408. }
  409. }
  410. func MobileGetSchedualDetailOne(orgID int64, patientID int64, schedualDate int64) (*MDialysisScheduleVM, error) {
  411. var vm MDialysisScheduleVM
  412. err := readDb.
  413. Table("xt_schedule").
  414. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  415. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  416. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  417. First(&vm).Error
  418. return &vm, err
  419. }
  420. // 用户排班信息
  421. func MobileGetSchedualDetailSix(orgID int64, patientID int64, schedualDate int64) (*MDialysisScheduleVM, error) {
  422. var vm MDialysisScheduleVM
  423. err := readDb.
  424. Table("xt_schedule").
  425. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  426. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  427. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  428. First(&vm).Error
  429. if err != nil {
  430. if err == gorm.ErrRecordNotFound {
  431. return nil, nil
  432. } else {
  433. return nil, err
  434. }
  435. }
  436. return &vm, err
  437. }
  438. // 用户排班信息
  439. func MobileGetSchedualDetail(orgID int64, patientID int64, schedualDate int64) (*MDialysisScheduleVM, error) {
  440. redis := RedisClient()
  441. defer redis.Close()
  442. var vm MDialysisScheduleVM
  443. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(schedualDate, 10) + ":schedual_detail"
  444. redis.Set(key, "", time.Second)
  445. schedual_detail_str, _ := redis.Get(key).Result()
  446. if len(schedual_detail_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  447. err := readDb.
  448. Table("xt_schedule").
  449. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  450. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  451. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  452. First(&vm).Error
  453. if err != nil {
  454. if err == gorm.ErrRecordNotFound {
  455. return nil, nil
  456. } else {
  457. return nil, err
  458. }
  459. } else {
  460. if vm.ID > 0 {
  461. //缓存数据
  462. schedual_detail_str, err := json.Marshal(vm)
  463. if err == nil {
  464. redis.Set(key, schedual_detail_str, time.Second*60*60*18)
  465. }
  466. } else {
  467. redis.Set(key, "null", time.Second*60*60*18)
  468. }
  469. return &vm, nil
  470. }
  471. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  472. if schedual_detail_str == "null" {
  473. return &vm, nil
  474. }
  475. json.Unmarshal([]byte(schedual_detail_str), &vm)
  476. return &vm, nil
  477. }
  478. }
  479. // 用户排班信息
  480. func MobileGetPatientSchedual(orgID int64, patientID int64, schedualDate int64) (*models.Schedule, error) {
  481. var schedule models.Schedule
  482. err := readDb.
  483. Table("xt_schedule").
  484. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  485. First(&schedule).Error
  486. if err != nil {
  487. if err == gorm.ErrRecordNotFound {
  488. return nil, nil
  489. } else {
  490. return nil, err
  491. }
  492. }
  493. return &schedule, nil
  494. }
  495. type MPatient struct {
  496. ID int64 `gorm:"column:id" json:"id" form:"id"`
  497. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  498. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  499. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  500. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  501. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
  502. AdmissionNumber string `gorm:"column:admission_number" json:"admission_number" form:"admission_number"`
  503. Source int64 `gorm:"column:source" json:"source" form:"source"`
  504. Lapseto int64 `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
  505. PartitionId int64 `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
  506. BedId int64 `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
  507. Name string `gorm:"column:name" json:"name" form:"name"`
  508. Alias string `gorm:"column:alias" json:"alias" form:"alias"`
  509. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  510. Nation string `gorm:"column:nation" json:"nation" form:"nation"`
  511. NativePlace string `gorm:"column:native_place" json:"native_place" form:"native_place"`
  512. MaritalStatus int64 `gorm:"column:marital_status" json:"marital_status" form:"marital_status"`
  513. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  514. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  515. ReimbursementWayId int64 `gorm:"column:reimbursement_way_id" json:"reimbursement_way_id" form:"reimbursement_way_id"`
  516. HealthCareType int64 `gorm:"column:health_care_type" json:"health_care_type" form:"health_care_type"`
  517. HealthCareNo string `gorm:"column:health_care_no" json:"health_care_no" form:"health_care_no"`
  518. HealthCareDueDate int64 `gorm:"column:health_care_due_date" json:"health_care_due_date" form:"health_care_due_date"`
  519. Height int64 `gorm:"column:height" json:"height" form:"height"`
  520. BloodType int64 `gorm:"column:blood_type" json:"blood_type" form:"blood_type"`
  521. Rh int64 `gorm:"column:rh" json:"rh" form:"rh"`
  522. HealthCareDueAlertDate int64 `gorm:"column:health_care_due_alert_date" json:"health_care_due_alert_date" form:"health_care_due_alert_date"`
  523. EducationLevel int64 `gorm:"column:education_level" json:"education_level" form:"education_level"`
  524. Profession int64 `gorm:"column:profession" json:"profession" form:"profession"`
  525. Phone string `gorm:"column:phone" json:"phone" form:"phone"`
  526. HomeTelephone string `gorm:"column:home_telephone" json:"home_telephone" form:"home_telephone"`
  527. RelativePhone string `gorm:"column:relative_phone" json:"relative_phone" form:"relative_phone"`
  528. RelativeRelations string `gorm:"column:relative_relations" json:"relative_relations" form:"relative_relations"`
  529. HomeAddress string `gorm:"column:home_address" json:"home_address" form:"home_address"`
  530. WorkUnit string `gorm:"column:work_unit" json:"work_unit" form:"work_unit"`
  531. UnitAddress string `gorm:"column:unit_address" json:"unit_address" form:"unit_address"`
  532. Children int64 `gorm:"column:children" json:"children" form:"children"`
  533. ReceivingDate int64 `gorm:"column:receiving_date" json:"receiving_date" form:"receiving_date"`
  534. IsHospitalFirstDialysis int64 `gorm:"column:is_hospital_first_dialysis" json:"is_hospital_first_dialysis" form:"is_hospital_first_dialysis"`
  535. FirstDialysisDate int64 `gorm:"column:first_dialysis_date" json:"first_dialysis_date" form:"first_dialysis_date"`
  536. FirstDialysisHospital string `gorm:"column:first_dialysis_hospital" json:"first_dialysis_hospital" form:"first_dialysis_hospital"`
  537. InductionPeriod int64 `gorm:"column:induction_period" json:"induction_period" form:"induction_period"`
  538. InitialDialysis int64 `gorm:"column:initial_dialysis" json:"initial_dialysis" form:"initial_dialysis"`
  539. TotalDialysis int64 `gorm:"column:total_dialysis" json:"total_dialysis" form:"total_dialysis"`
  540. AttendingDoctorId int64 `gorm:"column:attending_doctor_id" json:"attending_doctor_id" form:"attending_doctor_id"`
  541. HeadNurseId int64 `gorm:"column:head_nurse_id" json:"head_nurse_id" form:"head_nurse_id"`
  542. Evaluate string `gorm:"column:evaluate" json:"evaluate" form:"evaluate"`
  543. Diagnose string `gorm:"column:diagnose" json:"diagnose" form:"diagnose"`
  544. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  545. RegistrarsId int64 `gorm:"column:registrars_id" json:"registrars_id" form:"registrars_id"`
  546. Registrars string `gorm:"column:registrars" json:"registrars" form:"registrars"`
  547. QrCode string `gorm:"column:qr_code" json:"qr_code" form:"qr_code"`
  548. BindingState int64 `gorm:"column:binding_state" json:"binding_state" form:"binding_state"`
  549. PatientComplains string `gorm:"column:patient_complains" json:"patient_complains"` // 主诉
  550. PresentHistory string `gorm:"column:present_history" json:"present_history"` // 现病史
  551. PastHistory string `gorm:"column:past_history" json:"past_history"` // 既往史
  552. Temperature float64 `gorm:"column:temperature" json:"temperature"` // 体格检查-体温
  553. Pulse int64 `gorm:"column:pulse" json:"pulse"` // 体格检查-脉搏
  554. Respiratory int64 `gorm:"column:respiratory" json:"respiratory"` // 体格检查-呼吸频率
  555. SBP int64 `gorm:"column:sbp" json:"sbp"` // 体格检查-收缩压
  556. DBP int64 `gorm:"column:dbp" json:"dbp"` // 体格检查-舒张压
  557. Status int64 `gorm:"column:status" json:"status" form:"status"`
  558. Age int64 `gorm:"column:age" json:"age"`
  559. IsOpenRemind int64 `gorm:"column:is_open_remind" json:"is_open_remind"`
  560. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  561. DialysisAge int64 `gorm:"column:dialysis_age" json:"dialysis_age" form:"dialysis_age"`
  562. ExpenseKind int64 `gorm:"column:expense_kind" json:"expense_kind" form:"expense_kind"`
  563. TellPhone string `gorm:"column:tell_phone" json:"tell_phone" form:"tell_phone"`
  564. FirstTreatmentDate int64 `gorm:"column:first_treatment_date" json:"first_treatment_date" form:"first_treatment_date"`
  565. ContactName string `gorm:"column:contact_name" json:"contact_name" form:"contact_name"`
  566. UserSysBeforeCount int64 `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
  567. }
  568. func (MPatient) TableName() string {
  569. return "xt_patients"
  570. }
  571. // 接诊评估
  572. func MobileGetReceiverTreatmentAccessRecord(orgID int64, patientID int64, recordDate int64) (*models.ReceiveTreatmentAsses, error) {
  573. var record models.ReceiveTreatmentAsses
  574. redis := RedisClient()
  575. defer redis.Close()
  576. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":receive_treatment_asses"
  577. receive_treatment_asses_str, _ := redis.Get(key).Result()
  578. if len(receive_treatment_asses_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  579. err = readDb.Model(&models.ReceiveTreatmentAsses{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  580. if err != nil {
  581. if err == gorm.ErrRecordNotFound {
  582. if record.ID <= 0 {
  583. redis.Set(key, "", time.Second*60*60*18)
  584. }
  585. return nil, nil
  586. } else {
  587. return nil, err
  588. }
  589. } else {
  590. if record.ID > 0 {
  591. //缓存数据
  592. receive_treatment_asses_str, err := json.Marshal(record)
  593. if err == nil {
  594. redis.Set(key, receive_treatment_asses_str, time.Second*60*60*18)
  595. }
  596. } else {
  597. redis.Set(key, "null", time.Second*60*60*18)
  598. }
  599. return &record, nil
  600. }
  601. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  602. if receive_treatment_asses_str == "null" {
  603. return &record, nil
  604. }
  605. json.Unmarshal([]byte(receive_treatment_asses_str), &record)
  606. return &record, nil
  607. }
  608. }
  609. // 透前评估
  610. func MobileGetPredialysisEvaluationOne(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
  611. var record models.PredialysisEvaluation
  612. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  613. if err != nil {
  614. if err == gorm.ErrRecordNotFound {
  615. return nil, nil
  616. } else {
  617. return nil, err
  618. }
  619. }
  620. return &record, nil
  621. }
  622. func MobileGetPredialysisEvaluationTwo(orgID int64, patientID int64, recordDate int64) (models.PredialysisEvaluation, error) {
  623. var record models.PredialysisEvaluation
  624. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  625. return record, err
  626. }
  627. // 透前评估
  628. func MobileGetPredialysisEvaluation(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
  629. var record models.PredialysisEvaluation
  630. redis := RedisClient()
  631. defer redis.Close()
  632. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":assessment_before_dislysis"
  633. assessment_before_dislysis_str, _ := redis.Get(key).Result()
  634. redis.Set(key, "", time.Second)
  635. if len(assessment_before_dislysis_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  636. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  637. if err != nil {
  638. if err == gorm.ErrRecordNotFound {
  639. if record.ID <= 0 {
  640. redis.Set(key, "", time.Second*60*60*18)
  641. }
  642. return nil, nil
  643. } else {
  644. return nil, err
  645. }
  646. } else {
  647. if record.ID > 0 {
  648. //缓存数据
  649. assessment_before_dislysis_str, err := json.Marshal(record)
  650. if err == nil {
  651. redis.Set(key, assessment_before_dislysis_str, time.Second*60*60*18)
  652. }
  653. } else {
  654. redis.Set(key, "null", time.Second*60*60*18)
  655. }
  656. return &record, nil
  657. }
  658. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  659. if assessment_before_dislysis_str == "null" {
  660. return &record, nil
  661. } else {
  662. json.Unmarshal([]byte(assessment_before_dislysis_str), &record)
  663. return &record, nil
  664. }
  665. }
  666. }
  667. // 获取 maxDate 之前一次的透前评估记录
  668. func MobileGetLastTimePredialysisEvaluationOne(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
  669. var record models.PredialysisEvaluation
  670. 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
  671. if err != nil {
  672. if err == gorm.ErrRecordNotFound {
  673. return nil, nil
  674. } else {
  675. return nil, err
  676. }
  677. }
  678. return &record, nil
  679. }
  680. // 获取 maxDate 之前一次的透前评估记录
  681. func MobileGetLastTimePredialysisEvaluation(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
  682. var record models.PredialysisEvaluation
  683. redis := RedisClient()
  684. defer redis.Close()
  685. // cur_date := time.Now().Format("2006-01-02")
  686. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(maxDate, 10) + ":assessment_before_dislysis_last"
  687. assessment_before_dislysis_last_str, _ := redis.Get(key).Result()
  688. if len(assessment_before_dislysis_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  689. 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
  690. if err != nil {
  691. if err == gorm.ErrRecordNotFound {
  692. if record.ID <= 0 {
  693. redis.Set(key, "", time.Second*60*60*18)
  694. }
  695. return nil, nil
  696. } else {
  697. return nil, err
  698. }
  699. } else {
  700. if record.ID > 0 {
  701. //缓存数据
  702. assessment_before_dislysis_last_str, err := json.Marshal(record)
  703. if err == nil {
  704. redis.Set(key, assessment_before_dislysis_last_str, time.Second*60*60*4)
  705. }
  706. } else {
  707. redis.Set(key, "null", time.Second*60*60*18)
  708. }
  709. return &record, nil
  710. }
  711. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  712. if assessment_before_dislysis_last_str == "null" {
  713. return &record, nil
  714. } else {
  715. json.Unmarshal([]byte(assessment_before_dislysis_last_str), &record)
  716. return &record, nil
  717. }
  718. }
  719. }
  720. // 临时医嘱
  721. func MobileGetDoctorAdvices(orgID int64, patientID int64, recordDate int64) ([]*models.DoctorAdvice, error) {
  722. var records []*models.DoctorAdvice
  723. // err := readDb.Model(&models.DoctorAdvice{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).Find(&records).Error
  724. err := readDb.
  725. Model(&models.DoctorAdvice{}).
  726. Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? and (advice_type = 2 or advice_type = 3)", patientID, orgID, recordDate).
  727. 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").
  728. Order("start_time asc, groupno desc, advice_order desc, id").
  729. Scan(&records).Error
  730. if err != nil {
  731. return nil, err
  732. }
  733. return records, nil
  734. }
  735. func MobileGetDoctorAdvicesByGroups(orgID int64, patientID int64, recordDate int64) ([]*models.DoctorAdvice, error) {
  736. var records []*models.DoctorAdvice
  737. redis := RedisClient()
  738. defer redis.Close()
  739. // cur_date := time.Now().Format("2006-01-02")
  740. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":doctor_advices"
  741. //fmt.Println("key23233232323323wi", key)
  742. redis.Set(key, "", time.Second)
  743. doctor_advices_str, _ := redis.Get(key).Result()
  744. if len(doctor_advices_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  745. err := readDb.Model(&models.DoctorAdvice{}).
  746. Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? and (advice_type = 2 || advice_type = 3)", patientID, orgID, recordDate).
  747. 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").
  748. Order("start_time asc, groupno desc, advice_order desc, id asc").
  749. Scan(&records).Error
  750. if err != nil {
  751. if err == gorm.ErrRecordNotFound {
  752. if len(records) <= 0 {
  753. redis.Set(key, "", time.Second*60*60*18)
  754. }
  755. return nil, nil
  756. } else {
  757. return nil, err
  758. }
  759. } else {
  760. if len(records) > 0 {
  761. //缓存数据
  762. doctor_advices_str, err := json.Marshal(records)
  763. if err == nil {
  764. redis.Set(key, doctor_advices_str, time.Second*60*60*18)
  765. return records, nil
  766. }
  767. } else {
  768. redis.Set(key, "null", time.Second*60*60*18)
  769. return records, nil
  770. }
  771. return records, nil
  772. }
  773. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  774. if doctor_advices_str == "null" {
  775. return records, nil
  776. } else {
  777. json.Unmarshal([]byte(doctor_advices_str), &records)
  778. return records, nil
  779. }
  780. }
  781. }
  782. // 透析记录
  783. func MobileGetSchedualDialysisRecordTen(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  784. var record models.DialysisOrder
  785. 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
  786. if err != nil {
  787. if err == gorm.ErrRecordNotFound {
  788. return nil, nil
  789. } else {
  790. return nil, err
  791. }
  792. }
  793. return &record, nil
  794. }
  795. //func MobileGetSchedualDialysisRecord(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  796. // var record models.DialysisOrder
  797. //
  798. // 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
  799. //
  800. //
  801. // return &record,err
  802. //}
  803. // 透析记录
  804. func MobileGetSchedualDialysisRecord(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  805. var record models.DialysisOrder
  806. redis := RedisClient()
  807. defer redis.Close()
  808. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":dialysis_order"
  809. dialysis_order_str, _ := redis.Get(key).Result()
  810. if len(dialysis_order_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  811. 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
  812. if err != nil {
  813. if err == gorm.ErrRecordNotFound {
  814. return nil, nil
  815. } else {
  816. return nil, err
  817. }
  818. } else {
  819. if record.ID > 0 {
  820. //缓存数据
  821. dialysis_order_str, err := json.Marshal(record)
  822. if err == nil {
  823. redis.Set(key, dialysis_order_str, time.Second*60*60*18)
  824. }
  825. } else {
  826. redis.Set(key, "null", time.Second*60*60*18)
  827. }
  828. return &record, nil
  829. }
  830. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  831. if dialysis_order_str == "null" {
  832. 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
  833. return &record, nil
  834. } else {
  835. json.Unmarshal([]byte(dialysis_order_str), &record)
  836. return &record, nil
  837. }
  838. }
  839. }
  840. // 双人核对
  841. func MobileGetDoubleCheck(orgID int64, patientID int64, recordDate int64) (*models.DoubleCheck, error) {
  842. var record models.DoubleCheck
  843. redis := RedisClient()
  844. defer redis.Close()
  845. // cur_date := time.Now().Format("2006-01-02")
  846. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":double_check"
  847. double_check_str, _ := redis.Get(key).Result()
  848. if len(double_check_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  849. err := readDb.Model(&models.DoubleCheck{}).Where("patient_id = ? and user_org_id = ? and status = 1 and check_date = ?", patientID, orgID, recordDate).First(&record).Error
  850. if err != nil {
  851. if err == gorm.ErrRecordNotFound {
  852. if record.ID <= 0 {
  853. redis.Set(key, "null", time.Second*60*60*18)
  854. }
  855. return nil, nil
  856. } else {
  857. return nil, err
  858. }
  859. } else {
  860. if record.ID > 0 {
  861. //缓存数据
  862. double_check_str, err := json.Marshal(record)
  863. if err == nil {
  864. redis.Set(key, double_check_str, time.Second*60*60*18)
  865. }
  866. } else {
  867. redis.Set(key, "null", time.Second*60*60*18)
  868. }
  869. return &record, nil
  870. }
  871. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  872. if double_check_str == "null" {
  873. return &record, nil
  874. } else {
  875. json.Unmarshal([]byte(double_check_str), &record)
  876. return &record, nil
  877. }
  878. }
  879. }
  880. // 透析监测记录
  881. func MobileGetMonitorRecords(orgID int64, patientID int64, recordDate int64) ([]*models.MonitoringRecord, error) {
  882. var records []*models.MonitoringRecord
  883. redis := RedisClient()
  884. defer redis.Close()
  885. // cur_date := time.Now().Format("2006-01-02")
  886. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":monitor_records"
  887. redis.Set(key, "", time.Second)
  888. monitor_records_str, _ := redis.Get(key).Result()
  889. if len(monitor_records_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  890. 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
  891. if err != nil {
  892. if err == gorm.ErrRecordNotFound {
  893. //if len(records) <= 0 {
  894. // redis.Set(key, "null", time.Second*60*60*18)
  895. //}
  896. return nil, nil
  897. } else {
  898. return nil, err
  899. }
  900. } else {
  901. if len(records) > 0 {
  902. //缓存数据
  903. monitor_records_str, err := json.Marshal(records)
  904. if err == nil {
  905. redis.Set(key, monitor_records_str, time.Second*60*60*18)
  906. }
  907. } else {
  908. redis.Set(key, "null", time.Second*60*60*18)
  909. }
  910. return records, nil
  911. }
  912. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  913. if monitor_records_str == "null" {
  914. return records, nil
  915. } else {
  916. json.Unmarshal([]byte(monitor_records_str), &records)
  917. return records, nil
  918. }
  919. }
  920. }
  921. func MobileGetMonitorRecordFirst(orgID int64, patientID int64, recordDate int64) (*models.MonitoringRecord, error) {
  922. var records models.MonitoringRecord
  923. 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
  924. if err != nil {
  925. return nil, err
  926. }
  927. return &records, nil
  928. }
  929. func MobileGetLastMonitorRecordOne(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  930. var record models.MonitoringRecord
  931. 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
  932. if err != nil {
  933. if err == gorm.ErrRecordNotFound {
  934. return nil, nil
  935. } else {
  936. return nil, err
  937. }
  938. }
  939. return &record, nil
  940. }
  941. func MobileGetLastMonitorRecord(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  942. var record models.MonitoringRecord
  943. redis := RedisClient()
  944. defer redis.Close()
  945. // cur_date := time.Now().Format("2006-01-02")
  946. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(beforeDate, 10) + ":monitor_record_last"
  947. monitor_record_last_str, _ := redis.Get(key).Result()
  948. redis.Set(key, "", time.Second)
  949. if len(monitor_record_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  950. 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
  951. if err != nil {
  952. if err == gorm.ErrRecordNotFound {
  953. if record.ID <= 0 {
  954. redis.Set(key, "null", time.Second*60*60*18)
  955. }
  956. return nil, nil
  957. } else {
  958. return nil, err
  959. }
  960. } else {
  961. if record.ID > 0 {
  962. //缓存数据
  963. monitor_record_last_str, err := json.Marshal(record)
  964. if err == nil {
  965. redis.Set(key, monitor_record_last_str, time.Second*60*60*18)
  966. }
  967. } else {
  968. redis.Set(key, "null", time.Second*60*60*18)
  969. }
  970. return &record, nil
  971. }
  972. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  973. if monitor_record_last_str == "null" {
  974. return &record, nil
  975. } else {
  976. json.Unmarshal([]byte(monitor_record_last_str), &record)
  977. return &record, nil
  978. }
  979. }
  980. }
  981. func MobileGetAssessmentAfterDislysisOne(orgID int64, patientID int64, recordDate int64) (*models.AssessmentAfterDislysis, error) {
  982. var record models.AssessmentAfterDislysis
  983. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  984. if err != nil {
  985. if err == gorm.ErrRecordNotFound {
  986. return nil, nil
  987. } else {
  988. return nil, err
  989. }
  990. }
  991. return &record, nil
  992. }
  993. // 透后评估
  994. func MobileGetAssessmentAfterDislysis(orgID int64, patientID int64, recordDate int64) (*models.AssessmentAfterDislysis, error) {
  995. var record models.AssessmentAfterDislysis
  996. redis := RedisClient()
  997. defer redis.Close()
  998. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":assessment_after_dislysis"
  999. redis.Set(key, "", time.Second)
  1000. assessment_after_dislysis_str, _ := redis.Get(key).Result()
  1001. if len(assessment_after_dislysis_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1002. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  1003. if err != nil {
  1004. if err == gorm.ErrRecordNotFound {
  1005. if record.ID <= 0 {
  1006. redis.Set(key, "null", time.Second*60*60*18)
  1007. }
  1008. return nil, nil
  1009. } else {
  1010. return nil, err
  1011. }
  1012. } else {
  1013. if record.ID > 0 {
  1014. //缓存数据
  1015. assessment_after_dislysis_str, err := json.Marshal(record)
  1016. if err == nil {
  1017. redis.Set(key, assessment_after_dislysis_str, time.Second*60*60*18)
  1018. }
  1019. } else {
  1020. redis.Set(key, "null", time.Second*60*60*18)
  1021. }
  1022. return &record, nil
  1023. }
  1024. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1025. if assessment_after_dislysis_str == "null" {
  1026. return &record, nil
  1027. } else {
  1028. json.Unmarshal([]byte(assessment_after_dislysis_str), &record)
  1029. return &record, nil
  1030. }
  1031. }
  1032. }
  1033. // 获取 maxDate 之前一次的透后评估记录
  1034. func MobileGetLastTimeAssessmentAfterDislysis(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  1035. var record models.AssessmentAfterDislysis
  1036. redis := RedisClient()
  1037. defer redis.Close()
  1038. // cur_date := time.Now().Format("2006-01-02")
  1039. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(maxDate, 10) + ":assessment_after_dislysis_last"
  1040. redis.Set(key, "", time.Second)
  1041. assessment_after_dislysis_last_str, _ := redis.Get(key).Result()
  1042. if len(assessment_after_dislysis_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1043. 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
  1044. if err != nil {
  1045. if err == gorm.ErrRecordNotFound {
  1046. if record.ID <= 0 {
  1047. redis.Set(key, "null", time.Second*60*60*18)
  1048. }
  1049. return nil, nil
  1050. } else {
  1051. return nil, err
  1052. }
  1053. } else {
  1054. if record.ID > 0 {
  1055. //缓存数据
  1056. assessment_after_dislysis_last_str, err := json.Marshal(record)
  1057. if err == nil {
  1058. redis.Set(key, assessment_after_dislysis_last_str, time.Second*60*60*18)
  1059. }
  1060. } else {
  1061. redis.Set(key, "null", time.Second*60*60*18)
  1062. }
  1063. return &record, nil
  1064. }
  1065. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1066. if assessment_after_dislysis_last_str == "null" {
  1067. return &record, nil
  1068. } else {
  1069. json.Unmarshal([]byte(assessment_after_dislysis_last_str), &record)
  1070. return &record, nil
  1071. }
  1072. }
  1073. }
  1074. func MobileGetLastTimeAssessmentAfterDislysisOne(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  1075. var record models.AssessmentAfterDislysis
  1076. 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
  1077. if err != nil {
  1078. if err == gorm.ErrRecordNotFound {
  1079. return nil, nil
  1080. } else {
  1081. return nil, err
  1082. }
  1083. }
  1084. return &record, nil
  1085. }
  1086. func MobileGetLastTimeAssessmentAfterDislysisTwo(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  1087. var record models.AssessmentAfterDislysis
  1088. 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
  1089. return &record, nil
  1090. }
  1091. func MobileGetLast(orgID int64, patientID int64, maxDate int64) (models.AssessmentAfterDislysis, error) {
  1092. dislysis := models.AssessmentAfterDislysis{}
  1093. 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
  1094. return dislysis, err
  1095. }
  1096. // 治疗小结
  1097. func MobileGetTreatmentSummary(orgID int64, patientID int64, recordDate int64) (*models.TreatmentSummary, error) {
  1098. var record models.TreatmentSummary
  1099. redis := RedisClient()
  1100. defer redis.Close()
  1101. // cur_date := time.Now().Format("2006-01-02")
  1102. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":treatment_summary"
  1103. treatment_summary_str, _ := redis.Get(key).Result()
  1104. if len(treatment_summary_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1105. err := readDb.Model(&models.TreatmentSummary{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  1106. if err != nil {
  1107. if err == gorm.ErrRecordNotFound {
  1108. if record.ID <= 0 {
  1109. redis.Set(key, "null", time.Second*60*60*18)
  1110. }
  1111. return nil, nil
  1112. } else {
  1113. return nil, err
  1114. }
  1115. } else {
  1116. if record.ID > 0 {
  1117. //缓存数据
  1118. treatment_summary_str, err := json.Marshal(record)
  1119. if err == nil {
  1120. redis.Set(key, treatment_summary_str, time.Second*60*60*18)
  1121. }
  1122. } else {
  1123. redis.Set(key, "null", time.Second*60*60*18)
  1124. }
  1125. return &record, nil
  1126. }
  1127. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1128. if treatment_summary_str == "null" {
  1129. return &record, nil
  1130. } else {
  1131. json.Unmarshal([]byte(treatment_summary_str), &record)
  1132. return &record, nil
  1133. }
  1134. }
  1135. }
  1136. // 透析处方
  1137. func MobileGetDialysisPrescribe(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  1138. var record models.DialysisPrescription
  1139. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).Find(&record).Error
  1140. if err != nil {
  1141. if err == gorm.ErrRecordNotFound {
  1142. return nil, nil
  1143. } else {
  1144. return nil, err
  1145. }
  1146. }
  1147. return &record, nil
  1148. }
  1149. func MobileGetDialysisPrescribeOne(orgID int64, patientID int64, recordDate int64) (models.DialysisPrescription, error) {
  1150. var record models.DialysisPrescription
  1151. err = readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).Find(&record).Error
  1152. return record, nil
  1153. }
  1154. func UpdateMobileGetDialysisPrescribe(id int64, dewater_amount float64) error {
  1155. err := XTWriteDB().Model(&models.DialysisPrescription{}).Where("id=? and status=1", id).Updates(map[string]interface{}{"target_ultrafiltration": dewater_amount, "prescription_water": dewater_amount}).Error
  1156. return err
  1157. }
  1158. func UpdateMobileGetDialysisPrescribeOne(id int64, dewater_amount float64) error {
  1159. err := XTWriteDB().Model(&models.DialysisPrescription{}).Where("id=? and status=1", id).Updates(map[string]interface{}{"target_ultrafiltration": dewater_amount}).Error
  1160. return err
  1161. }
  1162. func MobileGetDialysisSchedual(orgID int64, patientID int64, scheduleDate int64) (*models.XtSchedule, error) {
  1163. var schedule models.XtSchedule
  1164. err := readDb.Model(&models.XtSchedule{}).Where("patient_id = ? and user_org_id = ? and status = 1 and schedule_date = ?", patientID, orgID, scheduleDate).First(&schedule).Error
  1165. if err != nil {
  1166. if err == gorm.ErrRecordNotFound {
  1167. return nil, nil
  1168. } else {
  1169. return nil, err
  1170. }
  1171. }
  1172. return &schedule, nil
  1173. }
  1174. // 透析方案
  1175. func MobileGetDialysisSolution(orgID int64, patientID int64) (*models.DialysisSolution, error) {
  1176. var record models.DialysisSolution
  1177. err := readDb.Model(&models.DialysisSolution{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  1178. if err != nil {
  1179. if err == gorm.ErrRecordNotFound {
  1180. return nil, nil
  1181. } else {
  1182. return nil, err
  1183. }
  1184. }
  1185. return &record, nil
  1186. }
  1187. func MobileGetPatientById(orgID int64, patientID int64) (*models.Patients, error) {
  1188. var patient models.Patients
  1189. err := readDb.Model(&models.Patients{}).Where("id = ? and user_org_id = ? and status = 1", patientID, orgID).First(&patient).Error
  1190. if err != nil {
  1191. if err == gorm.ErrRecordNotFound {
  1192. return nil, nil
  1193. } else {
  1194. return nil, err
  1195. }
  1196. }
  1197. return &patient, nil
  1198. }
  1199. func DisableMonitor(orgID int64, patientID int64, recordID int64, admin_user_id int64) error {
  1200. fmt.Println()
  1201. tx := writeDb.Begin()
  1202. updateTime := time.Now().Unix()
  1203. 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
  1204. if err != nil {
  1205. tx.Rollback()
  1206. return err
  1207. }
  1208. tx.Commit()
  1209. return nil
  1210. }
  1211. func GetMonitorById(id int64, orgId int64) (models.MonitoringRecord, error) {
  1212. record := models.MonitoringRecord{}
  1213. err := XTReadDB().Where("id = ? and user_org_id =?", id, orgId).Find(&record).Error
  1214. return record, err
  1215. }
  1216. func GetMonitor(orgID int64, patientID int64, id int64) (*models.MonitoringRecord, error) {
  1217. var monitor models.MonitoringRecord
  1218. var err error
  1219. err = readDb.Model(&models.MonitoringRecord{}).Where("id = ? AND user_org_id = ? AND patient_id = ? AND status = 1 ", id, orgID, patientID).Find(&monitor).Error
  1220. if err == gorm.ErrRecordNotFound {
  1221. return nil, nil
  1222. }
  1223. if err != nil {
  1224. return nil, err
  1225. }
  1226. return &monitor, nil
  1227. }
  1228. type MScheduleDoctorAdviceVM struct {
  1229. ID int64 `gorm:"column:id" json:"id"`
  1230. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  1231. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  1232. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  1233. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1234. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  1235. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  1236. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  1237. Status int64 `gorm:"column:status" json:"status"`
  1238. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  1239. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  1240. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  1241. DoctorAdvices []*MDoctorAdviceVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  1242. Prescription *models.DialysisPrescriptionTwenty `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  1243. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  1244. }
  1245. func (MScheduleDoctorAdviceVM) TableName() string {
  1246. return "xt_schedule"
  1247. }
  1248. type MScheduleDoctorAdviceVMOne struct {
  1249. ID int64 `gorm:"column:id" json:"id"`
  1250. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  1251. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  1252. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  1253. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1254. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  1255. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  1256. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  1257. Status int64 `gorm:"column:status" json:"status"`
  1258. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  1259. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  1260. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  1261. DoctorAdvices []*MDoctorAdviceVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  1262. Prescription *models.DialysisPrescriptionTwenty `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  1263. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  1264. }
  1265. func (MScheduleDoctorAdviceVMOne) TableName() string {
  1266. return "xt_schedule"
  1267. }
  1268. type MDoctorAdviceVM struct {
  1269. ID int64 `gorm:"column:id" json:"id"`
  1270. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  1271. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1272. AdviceType int64 `gorm:"column:advice_type" json:"advice_type"`
  1273. AdviceDate int64 `gorm:"column:advice_date" json:"advice_date"`
  1274. StartTime int64 `gorm:"column:start_time" json:"start_time"`
  1275. AdviceName string `gorm:"column:advice_name" json:"advice_name"`
  1276. AdviceDesc string `gorm:"column:advice_desc" json:"advice_desc"`
  1277. ReminderDate int64 `gorm:"column:reminder_date" json:"reminder_date"`
  1278. SingleDose float64 `gorm:"column:single_dose" json:"single_dose"`
  1279. SingleDoseUnit string `gorm:"column:single_dose_unit" json:"single_dose_unit"`
  1280. PrescribingNumber float64 `gorm:"column:prescribing_number" json:"prescribing_number"`
  1281. PrescribingNumberUnit string `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit"`
  1282. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way"`
  1283. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency"`
  1284. AdviceDoctor int64 `gorm:"column:advice_doctor" json:"advice_doctor"`
  1285. Status int64 `gorm:"column:status" json:"status"`
  1286. CreatedTime int64 `gorm:"column:created_time" json:"created_time"`
  1287. UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time"`
  1288. AdviceAffirm string `gorm:"column:advice_affirm" json:"advice_affirm"`
  1289. Remark string `gorm:"column:remark" json:"remark"`
  1290. StopTime int64 `gorm:"column:stop_time" json:"stop_time"`
  1291. StopReason string `gorm:"column:stop_reason" json:"stop_reason"`
  1292. StopDoctor int64 `gorm:"column:stop_doctor" json:"stop_doctor"`
  1293. StopState int64 `gorm:"column:stop_state" json:"stop_state"`
  1294. ParentId int64 `gorm:"column:parent_id" json:"parent_id"`
  1295. ExecutionTime int64 `gorm:"column:execution_time" json:"execution_time"`
  1296. ExecutionStaff int64 `gorm:"column:execution_staff" json:"execution_staff"`
  1297. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state"`
  1298. Checker int64 `gorm:"column:checker" json:"checker"`
  1299. RecordDate int64 `gorm:"column:record_date" json:"record_date"`
  1300. DialysisOrderId int64 `gorm:"column:dialysis_order_id" json:"dialysis_order_id"`
  1301. CheckTime int64 `gorm:"column:check_time" json:"check_time"`
  1302. CheckState int64 `gorm:"column:check_state" json:"check_state"`
  1303. DrugSpec float64 `gorm:"column:drug_spec" json:"drug_spec"`
  1304. DrugSpecUnit string `gorm:"column:drug_spec_unit" json:"drug_spec_unit"`
  1305. Groupno int64 `gorm:"column:groupno" json:"groupno"`
  1306. RemindType int64 `gorm:"column:remind_type" json:"remind_type"`
  1307. FrequencyType int64 `gorm:"column:frequency_type" json:"frequency_type"`
  1308. DayCount int64 `gorm:"column:day_count" json:"day_count"`
  1309. WeekDay string `gorm:"column:week_day" json:"week_day"`
  1310. TemplateId string `gorm:"column:template_id" json:"template_id"`
  1311. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1312. IsMedicine int64 `gorm:"column:is_medicine" json:"is_medicine" form:"is_medicine"`
  1313. IsSettle int64 `gorm:"column:is_settle" json:"is_settle" form:"is_settle"`
  1314. }
  1315. func (MDoctorAdviceVM) TableName() string {
  1316. return "xt_doctor_advice"
  1317. }
  1318. func MobileGetScheduleDoctorAdvices(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string) ([]*MScheduleDoctorAdviceVM, error) {
  1319. var vms []*MScheduleDoctorAdviceVM
  1320. adviceWhere := ""
  1321. adviceCondition := []interface{}{}
  1322. if adviceType == 0 {
  1323. if patientType == 0 {
  1324. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  1325. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1326. } else if patientType == 1 {
  1327. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  1328. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1329. } else if patientType == 2 {
  1330. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  1331. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1332. }
  1333. } else if adviceType == 1 {
  1334. if patientType == 0 {
  1335. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  1336. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1337. } else if patientType == 1 {
  1338. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  1339. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1340. } else if patientType == 2 {
  1341. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  1342. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1343. }
  1344. } else if adviceType == 3 {
  1345. if patientType == 0 {
  1346. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  1347. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1348. } else if patientType == 1 {
  1349. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  1350. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1351. } else if patientType == 2 {
  1352. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  1353. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1354. }
  1355. } else if adviceType == 2 && len(deliverWay) > 0 {
  1356. if patientType == 0 {
  1357. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  1358. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1359. } else if patientType == 1 {
  1360. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  1361. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  1362. } else if patientType == 2 {
  1363. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  1364. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1365. }
  1366. } else if adviceType == 2 && len(deliverWay) <= 0 {
  1367. if patientType == 0 {
  1368. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  1369. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1370. } else if patientType == 1 {
  1371. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND (advice_doctor = ? or execution_staff = ?)"
  1372. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, adminUserId)
  1373. } else if patientType == 2 {
  1374. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  1375. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1376. }
  1377. }
  1378. db := readDb.
  1379. Table("xt_schedule").
  1380. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1381. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1382. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1383. }).
  1384. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1385. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1386. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1387. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  1388. Preload("DoctorAdvices", adviceCondition...).
  1389. Where("status = 1 AND user_org_id = ?", orgID)
  1390. if scheduleDate != 0 {
  1391. db = db.Where("schedule_date = ?", scheduleDate)
  1392. }
  1393. err := db.Find(&vms).Error
  1394. return vms, err
  1395. }
  1396. func MobileGetScheduleDoctorAdvicesTwo(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string) ([]*MScheduleDoctorAdviceVMOne, error) {
  1397. var vms []*MScheduleDoctorAdviceVMOne
  1398. adviceWhere := ""
  1399. adviceCondition := []interface{}{}
  1400. if adviceType == 0 {
  1401. if patientType == 0 {
  1402. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  1403. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1404. } else if patientType == 1 {
  1405. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  1406. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1407. } else if patientType == 2 {
  1408. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  1409. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1410. } else if patientType == 3 {
  1411. 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"
  1412. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1413. } else if patientType == 4 {
  1414. 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)"
  1415. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1416. }
  1417. } else if adviceType == 1 {
  1418. if patientType == 0 {
  1419. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  1420. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1421. } else if patientType == 1 {
  1422. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  1423. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1424. } else if patientType == 2 {
  1425. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  1426. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1427. } else if patientType == 3 {
  1428. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = 1"
  1429. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1430. } else if patientType == 4 {
  1431. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and (is_settle = 0 or is_settle = 2)"
  1432. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1433. }
  1434. } else if adviceType == 3 {
  1435. if patientType == 0 {
  1436. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  1437. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1438. } else if patientType == 1 {
  1439. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  1440. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1441. } else if patientType == 2 {
  1442. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  1443. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1444. } else if patientType == 3 {
  1445. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 and is_settle = 1"
  1446. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1447. } else if patientType == 4 {
  1448. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 and (is_settle = 0 or is_settle = 2)"
  1449. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1450. }
  1451. } else if adviceType == 2 && len(deliverWay) > 0 {
  1452. if patientType == 0 {
  1453. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  1454. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1455. } else if patientType == 1 {
  1456. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  1457. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  1458. } else if patientType == 2 {
  1459. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  1460. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1461. } else if patientType == 3 {
  1462. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 and delivery_way = ? and is_settle = 1"
  1463. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1464. } else if patientType == 4 {
  1465. 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)"
  1466. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1467. }
  1468. } else if adviceType == 2 && len(deliverWay) <= 0 {
  1469. if patientType == 0 {
  1470. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  1471. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1472. } else if patientType == 1 {
  1473. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND (advice_doctor = ? or execution_staff = ?)"
  1474. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, adminUserId)
  1475. } else if patientType == 2 {
  1476. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  1477. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1478. } else if patientType == 3 {
  1479. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 and is_settle = 1"
  1480. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1481. } else if patientType == 4 {
  1482. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 and (is_settle = 0 or is_settle = 2)"
  1483. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1484. }
  1485. }
  1486. db := readDb.
  1487. Table("xt_schedule").
  1488. //Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1489. //Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1490. // return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1491. //}).
  1492. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1493. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1494. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1495. Preload("DoctorAdvices", adviceCondition...).
  1496. Where("status = 1 AND user_org_id = ?", orgID)
  1497. if scheduleDate != 0 {
  1498. db = db.Where("schedule_date = ?", scheduleDate)
  1499. }
  1500. err := db.Find(&vms).Error
  1501. return vms, err
  1502. }
  1503. func GetHisDoctorAdvices(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleDoctorAdviceVM, error) {
  1504. var vms []*HisMScheduleDoctorAdviceVM
  1505. if len(deliverWay) > 0 {
  1506. if patientType == 0 {
  1507. db := readDb.
  1508. Table("xt_schedule").
  1509. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  1510. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1511. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1512. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1513. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1514. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1515. }).
  1516. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1517. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1518. Where("status = 1 AND user_org_id = ?", orgID)
  1519. if scheduleDate != 0 {
  1520. db = db.Where("schedule_date = ?", scheduleDate)
  1521. }
  1522. err = db.Find(&vms).Error
  1523. }
  1524. if patientType > 0 {
  1525. db := readDb.
  1526. Table("xt_schedule").
  1527. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1528. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1529. 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).
  1530. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1531. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1532. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1533. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1534. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1535. }).Where("status = 1 AND user_org_id = ?", orgID)
  1536. if scheduleDate != 0 {
  1537. db = db.Where("schedule_date = ?", scheduleDate)
  1538. }
  1539. err = db.Find(&vms).Error
  1540. }
  1541. } else {
  1542. if patientType == 0 {
  1543. db := readDb.
  1544. Table("xt_schedule").
  1545. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? ", orgID, scheduleDate).
  1546. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1547. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1548. return db.Where("status = 1 AND user_org_id = ? and dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1549. }).
  1550. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1551. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1552. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1553. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1554. Where("status = 1 AND user_org_id = ?", orgID)
  1555. if scheduleDate != 0 {
  1556. db = db.Where("schedule_date = ?", scheduleDate)
  1557. }
  1558. err = db.Find(&vms).Error
  1559. }
  1560. if patientType > 0 {
  1561. db := readDb.
  1562. Table("xt_schedule").
  1563. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1564. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1565. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1566. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1567. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1568. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1569. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1570. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1571. Where("status = 1 AND user_org_id = ?", orgID)
  1572. if scheduleDate != 0 {
  1573. db = db.Where("schedule_date = ?", scheduleDate)
  1574. }
  1575. err = db.Find(&vms).Error
  1576. }
  1577. }
  1578. return vms, err
  1579. }
  1580. func GetHisDoctorAdvicesTwo(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleDoctorAdviceVMOne, error) {
  1581. var vms []*HisMScheduleDoctorAdviceVMOne
  1582. if len(deliverWay) > 0 {
  1583. if patientType == 0 {
  1584. db := readDb.
  1585. Table("xt_schedule").
  1586. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  1587. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1588. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1589. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1590. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1591. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1592. }).
  1593. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1594. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1595. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1596. Where("status = 1 AND user_org_id = ?", orgID)
  1597. if scheduleDate != 0 {
  1598. db = db.Where("schedule_date = ?", scheduleDate)
  1599. }
  1600. err = db.Find(&vms).Error
  1601. }
  1602. if patientType > 0 {
  1603. if patientType == 1 {
  1604. db := readDb.
  1605. Table("xt_schedule").
  1606. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1607. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1608. 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).
  1609. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1610. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1611. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1612. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1613. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1614. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1615. Where("status = 1 AND user_org_id = ?", orgID)
  1616. if scheduleDate != 0 {
  1617. db = db.Where("schedule_date = ?", scheduleDate)
  1618. }
  1619. err = db.Find(&vms).Error
  1620. }
  1621. if patientType == 2 {
  1622. db := readDb.
  1623. Table("xt_schedule").
  1624. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1625. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1626. 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).
  1627. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1628. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1629. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1630. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1631. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1632. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Where("status = 1 AND user_org_id = ?", orgID)
  1633. if scheduleDate != 0 {
  1634. db = db.Where("schedule_date = ?", scheduleDate)
  1635. }
  1636. err = db.Find(&vms).Error
  1637. }
  1638. if patientType == 3 {
  1639. db := readDb.
  1640. Table("xt_schedule").
  1641. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1642. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1643. 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).
  1644. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1645. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1646. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1647. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1648. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1649. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Where("status = 1 AND user_org_id = ?", orgID)
  1650. if scheduleDate != 0 {
  1651. db = db.Where("schedule_date = ?", scheduleDate)
  1652. }
  1653. err = db.Find(&vms).Error
  1654. }
  1655. if patientType == 4 {
  1656. db := readDb.
  1657. Table("xt_schedule").
  1658. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1659. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1660. 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).
  1661. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1662. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1663. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1664. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1665. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1666. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Where("status = 1 AND user_org_id = ?", orgID)
  1667. if scheduleDate != 0 {
  1668. db = db.Where("schedule_date = ?", scheduleDate)
  1669. }
  1670. err = db.Find(&vms).Error
  1671. }
  1672. }
  1673. } else {
  1674. if patientType == 0 {
  1675. db := readDb.
  1676. Table("xt_schedule").
  1677. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? ", orgID, scheduleDate).
  1678. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1679. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1680. return db.Where("status = 1 AND user_org_id = ? and dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1681. }).
  1682. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1683. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1684. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1685. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1686. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1687. Where("status = 1 AND user_org_id = ?", orgID)
  1688. if scheduleDate != 0 {
  1689. db = db.Where("schedule_date = ?", scheduleDate)
  1690. }
  1691. err = db.Find(&vms).Error
  1692. }
  1693. if patientType > 0 {
  1694. if patientType == 1 {
  1695. db := readDb.
  1696. Table("xt_schedule").
  1697. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1698. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1699. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1700. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1701. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1702. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1703. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1704. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1705. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1706. Where("status = 1 AND user_org_id = ?", orgID)
  1707. if scheduleDate != 0 {
  1708. db = db.Where("schedule_date = ?", scheduleDate)
  1709. }
  1710. err = db.Find(&vms).Error
  1711. }
  1712. if patientType == 2 {
  1713. db := readDb.
  1714. Table("xt_schedule").
  1715. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1716. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1717. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1718. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1719. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1720. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1721. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1722. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1723. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1724. Where("status = 1 AND user_org_id = ?", orgID)
  1725. if scheduleDate != 0 {
  1726. db = db.Where("schedule_date = ?", scheduleDate)
  1727. }
  1728. err = db.Find(&vms).Error
  1729. }
  1730. if patientType == 3 {
  1731. db := readDb.
  1732. Table("xt_schedule").
  1733. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1734. 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).
  1735. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1736. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1737. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1738. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1739. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1740. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1741. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1742. Where("status = 1 AND user_org_id = ?", orgID)
  1743. if scheduleDate != 0 {
  1744. db = db.Where("schedule_date = ?", scheduleDate)
  1745. }
  1746. err = db.Find(&vms).Error
  1747. }
  1748. if patientType == 4 {
  1749. db := readDb.
  1750. Table("xt_schedule").
  1751. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1752. 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).
  1753. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1754. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1755. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1756. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1757. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1758. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1759. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1760. Where("status = 1 AND user_org_id = ?", orgID)
  1761. if scheduleDate != 0 {
  1762. db = db.Where("schedule_date = ?", scheduleDate)
  1763. }
  1764. err = db.Find(&vms).Error
  1765. }
  1766. }
  1767. }
  1768. return vms, err
  1769. }
  1770. func GetMobileHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleProjectVM, error) {
  1771. var vms []*HisMScheduleProjectVM
  1772. //if patientType == 0 {
  1773. // db := readDb.
  1774. // Table("xt_schedule").
  1775. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1776. // Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1777. // return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1778. // }).
  1779. // Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1780. // Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1781. // Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1782. // Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1783. // return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1784. // }).
  1785. // Where("status = 1 AND user_org_id = ?", orgID)
  1786. // if scheduleDate != 0 {
  1787. // db = db.Where("schedule_date = ?", scheduleDate)
  1788. // }
  1789. // err = db.Find(&vms).Error
  1790. //}
  1791. //if patientType > 0 {
  1792. // db := readDb.
  1793. // Table("xt_schedule").
  1794. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1795. // Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1796. // return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1797. // }).
  1798. // Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1799. // Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1800. // Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1801. // Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1802. // Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1803. // return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1804. // }).
  1805. // Where("status = 1 AND user_org_id = ?", orgID)
  1806. // if scheduleDate != 0 {
  1807. // db = db.Where("schedule_date = ?", scheduleDate)
  1808. // }
  1809. // err = db.Find(&vms).Error
  1810. //}
  1811. db := readDb.Table("xt_schedule").Where("status = 1")
  1812. if orgID > 0 {
  1813. db = db.Where("user_org_id = ?", orgID)
  1814. }
  1815. if scheduleDate > 0 {
  1816. db = db.Where("schedule_date =?", scheduleDate)
  1817. }
  1818. err = db.Find(&vms).Error
  1819. if patientType == 0 {
  1820. db := readDb.
  1821. Table("xt_schedule").
  1822. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1823. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1824. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1825. }).
  1826. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1827. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1828. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1829. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1830. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1831. }).
  1832. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  1833. 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")
  1834. }).
  1835. Where("status = 1 AND user_org_id = ?", orgID)
  1836. if scheduleDate != 0 {
  1837. db = db.Where("schedule_date = ?", scheduleDate)
  1838. }
  1839. err = db.Find(&vms).Error
  1840. }
  1841. if patientType > 0 {
  1842. db := readDb.
  1843. Table("xt_schedule").
  1844. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1845. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1846. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1847. }).
  1848. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1849. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1850. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1851. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1852. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1853. }).
  1854. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  1855. 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")
  1856. }).
  1857. Where("status = 1 AND user_org_id = ?", orgID)
  1858. if scheduleDate != 0 {
  1859. db = db.Where("schedule_date = ?", scheduleDate)
  1860. }
  1861. err = db.Find(&vms).Error
  1862. }
  1863. return vms, err
  1864. }
  1865. func MobileCreateDialysisOrder(orgID int64, patientID int64, order *models.DialysisOrder) error {
  1866. now := time.Now()
  1867. tx := writeDb.Begin()
  1868. if createOrderErr := tx.Model(&models.DialysisOrder{}).Create(order).Error; createOrderErr != nil {
  1869. tx.Rollback()
  1870. return createOrderErr
  1871. }
  1872. // 更新透析记录 ID
  1873. // 透析处方
  1874. 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 {
  1875. tx.Rollback()
  1876. return err
  1877. }
  1878. // 接诊评估
  1879. 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 {
  1880. tx.Rollback()
  1881. return err
  1882. }
  1883. // 透前评估
  1884. 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 {
  1885. tx.Rollback()
  1886. return err
  1887. }
  1888. // 临时医嘱
  1889. 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 {
  1890. tx.Rollback()
  1891. return err
  1892. }
  1893. // 双人核对
  1894. 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 {
  1895. tx.Rollback()
  1896. return err
  1897. }
  1898. // 透后评估
  1899. 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 {
  1900. tx.Rollback()
  1901. return err
  1902. }
  1903. // 治疗小结
  1904. 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 {
  1905. tx.Rollback()
  1906. return err
  1907. }
  1908. // 透析监测
  1909. 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 {
  1910. tx.Rollback()
  1911. return err
  1912. }
  1913. tx.Commit()
  1914. return nil
  1915. }
  1916. type MobileUrgentSchedulePatientVM struct {
  1917. ID int64 `gorm:"column:id" json:"id"`
  1918. Name string `gorm:"column:name" json:"name"`
  1919. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no"`
  1920. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  1921. }
  1922. func (MobileUrgentSchedulePatientVM) TableName() string {
  1923. return "xt_patients"
  1924. }
  1925. type MobileUrgentScheduleTreatmentModeVM struct {
  1926. ID int64 `gorm:"column:id" json:"id"`
  1927. Name string `gorm:"column:name" json:"name"`
  1928. }
  1929. func (MobileUrgentScheduleTreatmentModeVM) TableName() string {
  1930. return "xt_treatment_mode"
  1931. }
  1932. func MobileGetAllPatientsForUrgentSchedule(orgID int64, record_date int64) ([]*MobileUrgentSchedulePatientVM, error) {
  1933. var vms []*MobileUrgentSchedulePatientVM = make([]*MobileUrgentSchedulePatientVM, 0)
  1934. 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 p.patient_type =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()
  1935. defer rows.Close()
  1936. if err != nil {
  1937. return nil, err
  1938. }
  1939. for rows.Next() {
  1940. var vm MobileUrgentSchedulePatientVM
  1941. readDb.ScanRows(rows, &vm)
  1942. vms = append(vms, &vm)
  1943. }
  1944. return vms, nil
  1945. }
  1946. func MobileGetAllTrearmentModesForUrgentSchedule() ([]*MobileUrgentScheduleTreatmentModeVM, error) {
  1947. var modes []*MobileUrgentScheduleTreatmentModeVM
  1948. err := readDb.Model(&MobileUrgentScheduleTreatmentModeVM{}).Where("status = 1").Find(&modes).Error
  1949. if err != nil {
  1950. return nil, err
  1951. }
  1952. return modes, nil
  1953. }
  1954. type MobileUrgentScheduleScheduleListVM struct {
  1955. ID int64 `gorm:"column:id" json:"id"`
  1956. // ZoneID int64 `gorm:"column:partition_id" json:"zone_id"`
  1957. DeviceNumberID int64 `gorm:"column:bed_id" json:"bed_id"`
  1958. PatientID int64 `gorm:"column:patient_id" json:"patient_id"`
  1959. ScheduleType int `gorm:"column:schedule_type" json:"schedule_type"`
  1960. DeviceNumber *models.DeviceNumber `gorm:"ForeignKey:DeviceNumberID" json:"device_number"`
  1961. // DeviceZone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"device_zone"`
  1962. }
  1963. func (MobileUrgentScheduleScheduleListVM) TableName() string {
  1964. return "xt_schedule"
  1965. }
  1966. func MobileGetSchedulesForUrgentSchedule(orgID int64, scheduleDate int64, schedule_type int) (schedules []*MobileUrgentScheduleScheduleListVM, err error) {
  1967. db := readDb.
  1968. Model(&MobileUrgentScheduleScheduleListVM{}).
  1969. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1970. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND schedule_type = ? ", orgID, scheduleDate, schedule_type)
  1971. err = db.Find(&schedules).Error
  1972. if err != nil {
  1973. return nil, err
  1974. }
  1975. return schedules, nil
  1976. }
  1977. func MobileGetOtherSchedulesForUrgentSchedule(orgID int64, scheduleDate int64, schedule_type int) ([]*MobileUrgentScheduleScheduleListVM, error) {
  1978. var vms []*MobileUrgentScheduleScheduleListVM = make([]*MobileUrgentScheduleScheduleListVM, 0)
  1979. 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()
  1980. defer rows.Close()
  1981. if err != nil {
  1982. return nil, err
  1983. }
  1984. for rows.Next() {
  1985. var vm MobileUrgentScheduleScheduleListVM
  1986. readDb.ScanRows(rows, &vm)
  1987. vms = append(vms, &vm)
  1988. }
  1989. return vms, nil
  1990. }
  1991. type MobileUrgentScheduleDeviceNumberVM struct {
  1992. ID int64 `gorm:"column:id" json:"id"`
  1993. Number string `gorm:"column:number" json:"number"`
  1994. ZoneID int64 `gorm:"column:zone_id" json:"zone_id"`
  1995. Zone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"zone"`
  1996. }
  1997. func (MobileUrgentScheduleDeviceNumberVM) TableName() string {
  1998. return "xt_device_number"
  1999. }
  2000. func MobileGetAllDeviceNumbersForUrgentSchedule(orgID int64, record_date int64, schedule_type int) ([]*DeviceNumberViewModel, error) {
  2001. var vms []*DeviceNumberViewModel = make([]*DeviceNumberViewModel, 0)
  2002. 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()
  2003. defer rows.Close()
  2004. if err != nil {
  2005. return nil, err
  2006. }
  2007. for rows.Next() {
  2008. var vm DeviceNumberViewModel
  2009. readDb.ScanRows(rows, &vm)
  2010. vms = append(vms, &vm)
  2011. }
  2012. return vms, nil
  2013. //var deviceNumbers []*MobileUrgentScheduleDeviceNumberVM
  2014. //db := readDb.
  2015. // Model(&MobileUrgentScheduleDeviceNumberVM{}).
  2016. // Preload("Zone", "status = 1 AND org_id = ?", orgID).
  2017. // Where("status = 1 AND org_id = ?", orgID)
  2018. //err := db.Order("zone_id asc").Find(&deviceNumbers).Error
  2019. //if err != nil {
  2020. // return nil, err
  2021. //}
  2022. //return deviceNumbers, nil
  2023. }
  2024. func GetValidScheduleMonitorRecordCount() (int64, error) {
  2025. var total int64
  2026. err := readDb.Model(&models.MonitoringRecord{}).Where("status = 1 AND operate_time = 0 AND monitoring_date <> 0").Count(&total).Error
  2027. return total, err
  2028. }
  2029. func GetTop1000ValidScheduleMonitorRecord() ([]*models.MonitoringRecord, error) {
  2030. var monitors []*models.MonitoringRecord
  2031. err := readDb.Model(&models.MonitoringRecord{}).Where("status = 1 AND operate_time = 0 AND monitoring_date <> 0").Order("id asc").Limit(100).Find(&monitors).Error
  2032. if err != nil {
  2033. return nil, err
  2034. }
  2035. return monitors, nil
  2036. }
  2037. func BatchUpdateMonitors(monitors []*models.MonitoringRecord) error {
  2038. tx := writeDb.Begin()
  2039. for index := 0; index < len(monitors); index++ {
  2040. tx.Save(monitors[index])
  2041. }
  2042. return tx.Commit().Error
  2043. }
  2044. func ModifyStartDialysisOrder(order *models.DialysisOrder) error {
  2045. tx := writeDb.Begin()
  2046. updateTime := time.Now().Unix()
  2047. 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
  2048. if err != nil {
  2049. tx.Rollback()
  2050. return err
  2051. }
  2052. tx.Commit()
  2053. return err
  2054. }
  2055. func UpdateScheduleByBedId(patient_id int64, schedule_date int64, bed_id int64, schedule_type int64, zone_id int64) error {
  2056. 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
  2057. return err
  2058. }
  2059. func ModifyFinishDialysisOrder(order *models.DialysisOrder) error {
  2060. tx := writeDb.Begin()
  2061. updateTime := time.Now().Unix()
  2062. 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
  2063. if err != nil {
  2064. tx.Rollback()
  2065. return err
  2066. }
  2067. tx.Commit()
  2068. return err
  2069. }
  2070. func MobileGetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  2071. var record models.SgjPatientDryweight
  2072. err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  2073. if err != nil {
  2074. if err == gorm.ErrRecordNotFound {
  2075. return nil, nil
  2076. } else {
  2077. return nil, err
  2078. }
  2079. }
  2080. return &record, nil
  2081. }
  2082. //func MobileGetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  2083. // var record models.SgjPatientDryweight
  2084. // redis := RedisClient()
  2085. // defer redis.Close()
  2086. //
  2087. // key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":last_dry_weight"
  2088. // last_dry_weight_str, _ := redis.Get(key).Result()
  2089. //
  2090. // if len(last_dry_weight_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2091. // err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  2092. // if err != nil {
  2093. // if err == gorm.ErrRecordNotFound {
  2094. // if record.ID <= 0 {
  2095. // redis.Set(key, "null", time.Second*60*60*18)
  2096. // }
  2097. // return nil, nil
  2098. // } else {
  2099. // return nil, err
  2100. // }
  2101. // } else {
  2102. // if record.ID > 0 {
  2103. // //缓存数据
  2104. // last_dry_weight_str, err := json.Marshal(record)
  2105. // if err == nil {
  2106. // redis.Set(key, last_dry_weight_str, time.Second*60*60*18)
  2107. // return nil, err
  2108. // }
  2109. // } else {
  2110. // redis.Set(key, "null", time.Second*60*60*18)
  2111. // return nil, err
  2112. // }
  2113. // return &record, nil
  2114. // }
  2115. // } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2116. // if last_dry_weight_str == "null" {
  2117. // return &record, nil
  2118. // } else {
  2119. // json.Unmarshal([]byte(last_dry_weight_str), &record)
  2120. // return &record, nil
  2121. // }
  2122. //
  2123. // }
  2124. //}
  2125. // 透析方案
  2126. func MobileGetDialysisSolutionByModeIdSix(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  2127. var record models.DialysisSolution
  2128. err := readDb.Model(&models.DialysisSolution{}).Where("patient_id = ? and user_org_id = ? and status = 1 AND mode_id = ? and solution_status =1", patientID, orgID, mode_id).Last(&record).Error
  2129. if err != nil {
  2130. if err == gorm.ErrRecordNotFound {
  2131. return nil, nil
  2132. } else {
  2133. return nil, err
  2134. }
  2135. }
  2136. return &record, nil
  2137. }
  2138. // 透析方案
  2139. func MobileGetDialysisSolutionByModeIdSevenTwety(orgID int64, patientID int64, mode_id int64) (models.DialysisSolution, error) {
  2140. var record models.DialysisSolution
  2141. 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
  2142. return record, nil
  2143. }
  2144. // 透析方案
  2145. func MobileGetDialysisSolutionByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  2146. var record models.DialysisSolution
  2147. redis := RedisClient()
  2148. defer redis.Close()
  2149. // cur_date := time.Now().Format("2006-01-02")
  2150. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2151. dialysis_solution_str, _ := redis.Get(key).Result()
  2152. redis.Set(key, "", time.Second*60)
  2153. if len(dialysis_solution_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2154. 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
  2155. if err != nil {
  2156. if err == gorm.ErrRecordNotFound {
  2157. if record.ID <= 0 {
  2158. redis.Set(key, "null", time.Second*60*60*18)
  2159. }
  2160. return nil, nil
  2161. } else {
  2162. return nil, err
  2163. }
  2164. } else {
  2165. if record.ID > 0 {
  2166. //缓存数据
  2167. dialysis_solution_str, err := json.Marshal(record)
  2168. if err == nil {
  2169. redis.Set(key, dialysis_solution_str, time.Second*60*60*18)
  2170. }
  2171. } else {
  2172. redis.Set(key, "null", time.Second*60*60*18)
  2173. }
  2174. return &record, nil
  2175. }
  2176. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2177. if dialysis_solution_str == "null" {
  2178. return &record, nil
  2179. } else {
  2180. json.Unmarshal([]byte(dialysis_solution_str), &record)
  2181. return &record, nil
  2182. }
  2183. }
  2184. }
  2185. // 透析处方
  2186. func MobileGetDialysisPrescribeByModeId(orgID int64, patientID int64, recordDate int64, mode_id int64) (*models.DialysisPrescription, error) {
  2187. var record models.DialysisPrescription
  2188. redis := RedisClient()
  2189. defer redis.Close()
  2190. // cur_date := time.Now().Format("2006-01-02")
  2191. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2192. redis.Set(key, "", time.Second)
  2193. dialysis_prescribe_str, _ := redis.Get(key).Result()
  2194. if len(dialysis_prescribe_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2195. 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
  2196. if err != nil {
  2197. if err == gorm.ErrRecordNotFound {
  2198. if record.ID <= 0 {
  2199. redis.Set(key, "null", time.Second*60*60*18)
  2200. }
  2201. return nil, nil
  2202. } else {
  2203. return nil, err
  2204. }
  2205. } else {
  2206. if record.ID > 0 {
  2207. //缓存数据
  2208. dialysis_prescribe_str, err := json.Marshal(record)
  2209. if err == nil {
  2210. redis.Set(key, dialysis_prescribe_str, time.Second*60*60*18)
  2211. }
  2212. } else {
  2213. redis.Set(key, "null", time.Second*60*60*18)
  2214. }
  2215. return &record, nil
  2216. }
  2217. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2218. if dialysis_prescribe_str == "null" {
  2219. return &record, nil
  2220. } else {
  2221. json.Unmarshal([]byte(dialysis_prescribe_str), &record)
  2222. return &record, nil
  2223. }
  2224. }
  2225. }
  2226. func MobileGetDialysisPrescribeByModeIdSix(orgID int64, patientID int64, recordDate int64, mode_id int64) (*models.DialysisPrescription, error) {
  2227. var record models.DialysisPrescription
  2228. 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
  2229. if err != nil {
  2230. if err == gorm.ErrRecordNotFound {
  2231. return nil, nil
  2232. } else {
  2233. return nil, err
  2234. }
  2235. }
  2236. return &record, nil
  2237. }
  2238. func MobileGetDialysisPrescribeByModeIdOne(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  2239. var record models.DialysisPrescription
  2240. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  2241. if err != nil {
  2242. if err == gorm.ErrRecordNotFound {
  2243. return nil, nil
  2244. } else {
  2245. return nil, err
  2246. }
  2247. }
  2248. return &record, nil
  2249. }
  2250. //func MobileGetDialysisPrescribeByModeIdOne(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  2251. // var record models.DialysisPrescription
  2252. // redis := RedisClient()
  2253. // defer redis.Close()
  2254. //
  2255. // // cur_date := time.Now().Format("2006-01-02")
  2256. // key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":dialysis_prescribe_by_mode"
  2257. // dialysis_prescribe_by_mode_str, _ := redis.Get(key).Result()
  2258. //
  2259. // if len(dialysis_prescribe_by_mode_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2260. // err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  2261. // if err != nil {
  2262. // if err == gorm.ErrRecordNotFound {
  2263. // if record.ID <= 0 {
  2264. // redis.Set(key, "null", time.Second*60*60*18)
  2265. // }
  2266. // return nil, nil
  2267. // } else {
  2268. // return nil, err
  2269. // }
  2270. // } else {
  2271. //
  2272. // if record.ID > 0 {
  2273. // //缓存数据
  2274. // dialysis_prescribe_by_mode_str, err := json.Marshal(record)
  2275. //
  2276. // if err == nil {
  2277. // redis.Set(key, dialysis_prescribe_by_mode_str, time.Second*60*60*18)
  2278. // return nil, err
  2279. // }
  2280. // } else {
  2281. // redis.Set(key, "null", time.Second*60*60*18)
  2282. // return nil, err
  2283. // }
  2284. // return &record, nil
  2285. // }
  2286. // } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2287. // if dialysis_prescribe_by_mode_str == "null" {
  2288. // json.Unmarshal([]byte(dialysis_prescribe_by_mode_str), &record)
  2289. // return &record, nil
  2290. // } else {
  2291. // json.Unmarshal([]byte(dialysis_prescribe_by_mode_str), &record)
  2292. // return &record, nil
  2293. // }
  2294. //
  2295. // }
  2296. //}
  2297. func MobileGetLastDialysisPrescribe(orgID int64, patientID int64) (*models.DialysisPrescription, error) {
  2298. var record models.DialysisPrescription
  2299. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 ", patientID, orgID).Last(&record).Error
  2300. if err != nil {
  2301. if err == gorm.ErrRecordNotFound {
  2302. return nil, nil
  2303. } else {
  2304. return nil, err
  2305. }
  2306. }
  2307. return &record, nil
  2308. }
  2309. func MobileGetLastDialysisPrescribeByModeIdSix(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2310. var record models.DialysisPrescription
  2311. 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
  2312. //if err != nil {
  2313. // if err == gorm.ErrRecordNotFound {
  2314. // return nil, nil
  2315. // } else {
  2316. // return nil, err
  2317. // }
  2318. //}
  2319. return &record, err
  2320. }
  2321. func MobileGetLastDialysisPrescribeByModeIdTen(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2322. var record models.DialysisPrescription
  2323. 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
  2324. if err != nil {
  2325. if err == gorm.ErrRecordNotFound {
  2326. return nil, nil
  2327. } else {
  2328. return nil, err
  2329. }
  2330. }
  2331. return &record, err
  2332. }
  2333. func MobileGetLastDialysisPrescribeByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2334. var record models.DialysisPrescription
  2335. redis := RedisClient()
  2336. defer redis.Close()
  2337. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  2338. dialysis_prescribe_by_mode_id, _ := redis.Get(key).Result()
  2339. if len(dialysis_prescribe_by_mode_id) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2340. 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
  2341. if err != nil {
  2342. if err == gorm.ErrRecordNotFound {
  2343. if record.ID <= 0 {
  2344. redis.Set(key, "null", time.Second*60*60*18)
  2345. }
  2346. return nil, nil
  2347. } else {
  2348. return nil, err
  2349. }
  2350. } else {
  2351. if record.ID > 0 {
  2352. //缓存数据
  2353. dialysis_prescribe_by_mode_str, err := json.Marshal(record)
  2354. if err == nil {
  2355. redis.Set(key, dialysis_prescribe_by_mode_str, time.Second*60*60*18)
  2356. return nil, err
  2357. }
  2358. } else {
  2359. redis.Set(key, "null", time.Second*60*60*18)
  2360. return nil, err
  2361. }
  2362. return &record, nil
  2363. }
  2364. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2365. if dialysis_prescribe_by_mode_id == "null" {
  2366. return &record, nil
  2367. } else {
  2368. json.Unmarshal([]byte(dialysis_prescribe_by_mode_id), &record)
  2369. return &record, nil
  2370. }
  2371. }
  2372. }
  2373. func MobileGetLastDialysisPrescribeByModeIdOne(orgID int64, patientID int64, mode_id int64) (models.DialysisPrescription, error) {
  2374. var record models.DialysisPrescription
  2375. 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
  2376. return record, err
  2377. }
  2378. func GetAllAvaildDeviceNumbers(orgID int64, record_date int64, schedule_type int) ([]*DeviceNumberViewModel, error) {
  2379. var vms []*DeviceNumberViewModel = make([]*DeviceNumberViewModel, 0)
  2380. 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()
  2381. defer rows.Close()
  2382. if err != nil {
  2383. return nil, err
  2384. }
  2385. for rows.Next() {
  2386. var vm DeviceNumberViewModel
  2387. readDb.ScanRows(rows, &vm)
  2388. vms = append(vms, &vm)
  2389. }
  2390. return vms, nil
  2391. }
  2392. // 获取 maxDate 之前一次的透前评估记录
  2393. func GetLastTimePredialysisEvaluation(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
  2394. var record models.PredialysisEvaluation
  2395. 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
  2396. if err != nil {
  2397. if err == gorm.ErrRecordNotFound {
  2398. return nil, nil
  2399. } else {
  2400. return nil, err
  2401. }
  2402. }
  2403. return &record, nil
  2404. }
  2405. func GetLastTimeOrder(orgID int64, patientID int64, maxDate int64) (*models.DialysisOrder, error) {
  2406. var record models.DialysisOrder
  2407. 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
  2408. if err != nil {
  2409. if err == gorm.ErrRecordNotFound {
  2410. return nil, nil
  2411. } else {
  2412. return nil, err
  2413. }
  2414. }
  2415. return &record, nil
  2416. }
  2417. func GetLastMonitorRecord(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  2418. var record models.MonitoringRecord
  2419. 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
  2420. if err != nil {
  2421. if err == gorm.ErrRecordNotFound {
  2422. return nil, nil
  2423. } else {
  2424. return nil, err
  2425. }
  2426. }
  2427. return &record, nil
  2428. }
  2429. func GetLastMonitorRecordTwenty(orgID int64, patientID int64, beforeDate int64) (models.MonitoringRecord, error) {
  2430. var record models.MonitoringRecord
  2431. 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
  2432. return record, nil
  2433. }
  2434. func GetLastMonitorRecordTwentyOne(orgID int64, patientID int64, beforeDate int64) (models.MonitoringRecord, error) {
  2435. var record models.MonitoringRecord
  2436. 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
  2437. return record, nil
  2438. }
  2439. func GetLastMonitorRecordTwentyTwo(orgID int64, patientID int64, beforeDate int64) (models.MonitoringRecord, error) {
  2440. var record models.MonitoringRecord
  2441. 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
  2442. return record, nil
  2443. }
  2444. func GetLastMonitorRecordTwentyThree(orgID int64, patientID int64, beforeDate int64) (models.MonitoringRecord, error) {
  2445. var record models.MonitoringRecord
  2446. 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
  2447. return record, nil
  2448. }
  2449. func GetLastMonitorRecordTwentyFour(orgID int64, patientID int64, beforeDate int64) (models.MonitoringRecord, error) {
  2450. var record models.MonitoringRecord
  2451. 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
  2452. return record, nil
  2453. }
  2454. // 获取 maxDate 之前一次的透后评估记录
  2455. func GetLastTimeAssessmentAfterDislysis(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  2456. var record models.AssessmentAfterDislysis
  2457. 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
  2458. if err != nil {
  2459. if err == gorm.ErrRecordNotFound {
  2460. return nil, nil
  2461. } else {
  2462. return nil, err
  2463. }
  2464. }
  2465. return &record, nil
  2466. }
  2467. // 透析处方
  2468. func GetDialysisPrescribe(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  2469. var record models.DialysisPrescription
  2470. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  2471. if err != nil {
  2472. if err == gorm.ErrRecordNotFound {
  2473. return nil, nil
  2474. } else {
  2475. return nil, err
  2476. }
  2477. }
  2478. return &record, nil
  2479. }
  2480. func GetDialysisPrescribeOne(orgID int64, patientID int64, recordDate int64) (models.DialysisPrescription, error) {
  2481. var record models.DialysisPrescription
  2482. err = readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  2483. return record, err
  2484. }
  2485. // 透析方案
  2486. func GetDialysisSolution(orgID int64, patientID int64, mode_id int64) (models.DialysisSolution, error) {
  2487. var record models.DialysisSolution
  2488. 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
  2489. return record, err
  2490. }
  2491. func GetDialysisSolutionOne(orgID int64, mode_id int64) (*models.DialysisSolution, error) {
  2492. var record models.DialysisSolution
  2493. err := readDb.Model(&models.DialysisSolution{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2494. if err != nil {
  2495. if err == gorm.ErrRecordNotFound {
  2496. return nil, nil
  2497. } else {
  2498. return nil, err
  2499. }
  2500. }
  2501. return &record, nil
  2502. }
  2503. func GetLastDialysisPrescribeByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2504. var record models.DialysisPrescription
  2505. 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
  2506. if err != nil {
  2507. if err == gorm.ErrRecordNotFound {
  2508. return nil, nil
  2509. } else {
  2510. return nil, err
  2511. }
  2512. }
  2513. return &record, nil
  2514. }
  2515. func GetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  2516. var record models.SgjPatientDryweight
  2517. err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  2518. if err != nil {
  2519. if err == gorm.ErrRecordNotFound {
  2520. return nil, nil
  2521. } else {
  2522. return nil, err
  2523. }
  2524. }
  2525. return &record, nil
  2526. }
  2527. func MobileGetSystemDialysisPrescribeByModeIdSix(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2528. var record models.SystemPrescription
  2529. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).First(&record).Error
  2530. if err != nil {
  2531. if err == gorm.ErrRecordNotFound {
  2532. return nil, nil
  2533. } else {
  2534. return nil, err
  2535. }
  2536. }
  2537. return &record, nil
  2538. }
  2539. func MobileGetSystemDialysisPrescribeByModeId(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2540. var record models.SystemPrescription
  2541. redis := RedisClient()
  2542. defer redis.Close()
  2543. // cur_date := time.Now().Format("2006-01-02")
  2544. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  2545. system_dialysis_prescribe_str, _ := redis.Get(key).Result()
  2546. if len(system_dialysis_prescribe_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2547. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2548. if err != nil {
  2549. if err == gorm.ErrRecordNotFound {
  2550. if record.ID <= 0 {
  2551. redis.Set(key, "null", time.Second*60*60*18)
  2552. }
  2553. return nil, nil
  2554. } else {
  2555. return nil, err
  2556. }
  2557. } else {
  2558. if record.ID > 0 {
  2559. //缓存数据
  2560. system_dialysis_prescribe_str, err := json.Marshal(record)
  2561. if err == nil {
  2562. redis.Set(key, system_dialysis_prescribe_str, time.Second*60*60*18)
  2563. }
  2564. } else {
  2565. redis.Set(key, "null", time.Second*60*60*18)
  2566. }
  2567. return &record, nil
  2568. }
  2569. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2570. if system_dialysis_prescribe_str == "null" {
  2571. return &record, nil
  2572. } else {
  2573. json.Unmarshal([]byte(system_dialysis_prescribe_str), &record)
  2574. return &record, nil
  2575. }
  2576. }
  2577. }
  2578. func MobileGetSystemDialysisPrescribeByModeIdOne(orgID int64, mode_id int64) (models.SystemPrescription, error) {
  2579. var record models.SystemPrescription
  2580. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2581. return record, err
  2582. }
  2583. func GetSystemDialysisPrescribeByModeId(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2584. var record models.SystemPrescription
  2585. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2586. if err != nil {
  2587. if err == gorm.ErrRecordNotFound {
  2588. return nil, nil
  2589. } else {
  2590. return nil, err
  2591. }
  2592. }
  2593. return &record, nil
  2594. }
  2595. func GetDialysisOrderCount(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2596. 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
  2597. return
  2598. }
  2599. func GetDialysisOrderCountOne(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2600. 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
  2601. return
  2602. }
  2603. func GetDialysisOrderCountTwo(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2604. err = readDb.Model(&models.DialysisOrder{}).Where("dialysis_date>=1735660800 and dialysis_date <= ? AND status = 1 AND stage = 2 AND user_org_id = ? AND patient_id = ?", recordDate, orgID, patient_id).Count(&count).Error
  2605. return
  2606. }
  2607. func GetFirstDateOfMonth(d time.Time) time.Time {
  2608. d = d.AddDate(0, 0, -d.Day()+1)
  2609. return GetZeroTime(d)
  2610. }
  2611. func GetZeroTime(d time.Time) time.Time {
  2612. return time.Date(d.Year(), d.Month(), d.Day(), 0, 0, 0, 0, d.Location())
  2613. }
  2614. func GetDialysisCountByPatientId(startime int64, endtime int64, patientid int64, orgid int64) (order []*models.BloodDialysisOrderCount, err error) {
  2615. db := XTReadDB().Table("xt_dialysis_order as o")
  2616. 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
  2617. return order, err
  2618. }
  2619. func FindConsumablesByDate(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error) {
  2620. 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
  2621. return
  2622. }
  2623. func FindConsumablesByDateTwo(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error) {
  2624. 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
  2625. return
  2626. }
  2627. func FindConsumablesByDateThree(orgID int64, patient_id int64, recordDate int64) (consumables []*models.BloodAutomaticReduceDetail, err error) {
  2628. 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
  2629. return
  2630. }
  2631. func FindHisPrescription(orgID int64, patient_id int64, recordDate int64) (project []*models.HisPrescriptionProject, err error) {
  2632. 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
  2633. return
  2634. }
  2635. //func FindLastConsumables(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error){
  2636. // 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
  2637. // return
  2638. //}
  2639. //
  2640. func GetLastTimeConsumables(orgID int64, patientID int64, maxDate int64) (prepare []*models.DialysisBeforePrepare, err error) {
  2641. 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
  2642. return
  2643. }
  2644. type GoodsType struct {
  2645. ID int64 `gorm:"column:id" json:"id"`
  2646. TypeName string `gorm:"column:type_name" json:"type_name"`
  2647. Remark string `gorm:"column:remark" json:"remark"`
  2648. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2649. Status int64 `gorm:"column:status" json:"status"`
  2650. Type int64 `gorm:"column:type" json:"type"`
  2651. }
  2652. func (GoodsType) TableName() string {
  2653. return "xt_goods_type"
  2654. }
  2655. type VMGoodInfo struct {
  2656. ID int64 `gorm:"column:id" json:"id"`
  2657. SpecificationName string `gorm:"column:specification_name" json:"specification_name"`
  2658. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2659. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2660. GoodName string `gorm:"column:good_name" json:"good_name" form:"good_name"`
  2661. GoodUnit int64 `gorm:"column:good_unit" json:"good_unit" form:"good_unit"`
  2662. Total float64 `gorm:"column:total" json:"total" form:"total"`
  2663. PackingUnit string `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
  2664. MedicalInsuranceNumber string `gorm:"column:medical_insurance_number" json:"medical_insurance_number" form:"medical_insurance_number"`
  2665. }
  2666. func (VMGoodInfo) TableName() string {
  2667. return "xt_good_information"
  2668. }
  2669. type AutomaticReduceDetail struct {
  2670. ID int64 `gorm:"column:id" json:"id"`
  2671. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2672. Status int64 `gorm:"column:status" json:"status"`
  2673. RecordTime int64 `gorm:"column:record_time" json:"record_time"`
  2674. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2675. GoodId int64 `gorm:"column:good_id" json:"good_id"`
  2676. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2677. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"info"`
  2678. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"type"`
  2679. Count int64 `gorm:"column:count" json:"count"`
  2680. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  2681. }
  2682. func (AutomaticReduceDetail) TableName() string {
  2683. return "xt_automatic_reduce_detail"
  2684. }
  2685. type DialysisBeforePrepare struct {
  2686. ID int64 `gorm:"column:id" json:"id" form:"id"`
  2687. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  2688. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  2689. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  2690. GoodId int64 `gorm:"column:good_id" json:"good_id" form:"good_id"`
  2691. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id" form:"good_type_id"`
  2692. Count int64 `gorm:"column:count" json:"count" form:"count"`
  2693. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  2694. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  2695. Creater int64 `gorm:"column:creater" json:"creater" form:"creater"`
  2696. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  2697. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"info"`
  2698. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"type"`
  2699. }
  2700. func (DialysisBeforePrepare) TableName() string {
  2701. return "dialysis_before_prepare"
  2702. }
  2703. type MDialysisGoodsVM struct {
  2704. ID int64 `gorm:"column:id" json:"id"`
  2705. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2706. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2707. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2708. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2709. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2710. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2711. ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week"`
  2712. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2713. Status int64 `gorm:"column:status" json:"status"`
  2714. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2715. SchedualPatient *MSchedualPatientVMList `gorm:"ForeignKey:PatientId" json:"patient"`
  2716. AutomaticReduceDetail []*AutomaticReduceDetail `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"good_user"`
  2717. LastAutomaticReduceDetail []*AutomaticReduceDetail `gorm:"-" json:"last_good_user"`
  2718. DialysisBeforePrepare []*DialysisBeforePrepare `gorm:"ForeignKey:PatientId,ScheduleDate;AssociationForeignKey:PatientId,RecordDate" json:"good_user_detail"`
  2719. LastDialysisBeforePrepare []*DialysisBeforePrepare `gorm:"-" json:"last_good_user_detail"`
  2720. Project []*models.HisPrescriptionProject `gorm:"-" json:"project"`
  2721. //WarehouseOutInfo []*models.WarehouseOutInfoSeven `gorm:"ForeignKey:PatientId,ScheduleDate;AssociationForeignKey:PatientId,SysRecordTime" json:"ware_house_out_info"`
  2722. DialysisPrescription models.DialysisPrescriptionListSix `gorm:"ForeignKey:PatientId,ModeId;AssociationForeignKey:PatientId,ModeId" json:"prescription"`
  2723. }
  2724. func (MDialysisGoodsVM) TableName() string {
  2725. return "xt_schedule"
  2726. }
  2727. type VMWarehouseOutInfo struct {
  2728. ID int64 `gorm:"column:id" json:"id"`
  2729. WarehouseOutId int64 `gorm:"column:warehouse_out_id" json:"warehouse_out_id"`
  2730. GoodId int64 `gorm:"column:good_id" json:"good_id"`
  2731. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2732. Count int64 `gorm:"column:count" json:"count"`
  2733. Price float64 `gorm:"column:price" json:"price"`
  2734. TotalPrice float64 `gorm:"column:total_price" json:"total_price"`
  2735. Status int64 `gorm:"column:status" json:"status"`
  2736. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2737. WarehouseOutOrderNumber string `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number"`
  2738. GoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"good_info"`
  2739. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"good_type"`
  2740. IsSys int64 `gorm:"column:is_sys" json:"is_sys"`
  2741. SysRecordTime int64 `gorm:"column:sys_record_time" json:"sys_record_time"`
  2742. Mtime int64 `gorm:"column:mtime" json:"mtime"`
  2743. Ctime int64 `gorm:"column:ctime" json:"ctime"`
  2744. }
  2745. func (VMWarehouseOutInfo) TableName() string {
  2746. return "xt_warehouse_out_info"
  2747. }
  2748. type DialysisGoodsDate struct {
  2749. RecordDate int64
  2750. }
  2751. type DialysisGoodsDetailDate struct {
  2752. RecordTime int64
  2753. }
  2754. 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) {
  2755. var vms []*MDialysisGoodsVM
  2756. var total int64
  2757. db := readDb.
  2758. Table("xt_schedule as sch").
  2759. Preload("DialysisPrescription", "status=1 and user_org_id =? and solution_status = 1", orgID).
  2760. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  2761. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2762. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2763. Preload("DialysisBeforePrepare", func(db *gorm.DB) *gorm.DB {
  2764. 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)
  2765. }).
  2766. Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
  2767. 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")
  2768. }).Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
  2769. if scheduleDate != 0 {
  2770. db = db.Where("schedule_date = ?", scheduleDate)
  2771. }
  2772. if schedule_type != 0 {
  2773. db = db.Where("schedule_type = ?", schedule_type)
  2774. }
  2775. if partition_id != 0 {
  2776. db = db.Where("partition_id = ?", partition_id)
  2777. }
  2778. if patient_id != 0 {
  2779. db = db.Where("patient_id = ?", patient_id)
  2780. }
  2781. err := db.Find(&vms).Error
  2782. return vms, err, total
  2783. }
  2784. func GetLastDialysisGoods(patient_id int64, orgID int64, record_time int64) (goodUser []*AutomaticReduceDetail, err error) {
  2785. var Id []*DialysisGoodsDetailDate
  2786. 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
  2787. if len(Id) > 0 {
  2788. 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
  2789. }
  2790. return
  2791. }
  2792. func GetLastDialysisBeforePrepare(patient_id int64, orgID int64, record_time int64) (goodUser []*DialysisBeforePrepare, err error) {
  2793. var Id []*DialysisGoodsDate
  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, record_time).Select("record_date").Group("record_date").Order("record_date asc").Scan(&Id).Error
  2795. if len(Id) > 0 {
  2796. 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
  2797. }
  2798. return
  2799. }
  2800. func GetPatientAutoMatic(patient_id int64, orgID int64, record_time int64, good_id int64) (auto []*models.AutomaticReduceDetail, err error) {
  2801. 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
  2802. return auto, err
  2803. }
  2804. func GetAllWarehouseOutSumList(patient_id int64, orgID int64, record_time int64) (info []*models.WarehouseOutInfoSeven, err error) {
  2805. 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
  2806. return info, err
  2807. }
  2808. func MobileGetGoodsStatistics(orgID int64, start_time int64, end_time int64) (list []*models.StockInfo, err error) {
  2809. db := readDb.Model(&models.StockInfo{})
  2810. db = db.Where("xt_good_information.org_id = ? AND xt_good_information.status = 1", orgID)
  2811. 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")
  2812. db = db.Preload("QueryWarehouseOutInfo", func(db *gorm.DB) *gorm.DB {
  2813. 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)
  2814. })
  2815. db = db.Preload("GoodsType", "org_id = ? AND status = 1", orgID)
  2816. err = db.Order("ctime desc").Find(&list).Error
  2817. return
  2818. }
  2819. 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) {
  2820. var vms []*MDialysisGoodsVM
  2821. var total int64
  2822. db := readDb.
  2823. Model(&models.Schedule{}).
  2824. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  2825. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2826. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2827. Preload("DialysisBeforePrepare", 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 user_org_id = ? AND record_date = ? AND count > 0 ", orgID, scheduleDate)
  2829. }).Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
  2830. 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)
  2831. }).Where("xt_schedule.status = 1 AND xt_schedule.user_org_id = ?", orgID)
  2832. if scheduleDate != 0 {
  2833. db = db.Where("schedule_date = ?", scheduleDate)
  2834. }
  2835. if patient_id != 0 {
  2836. db = db.Where("patient_id = ?", patient_id)
  2837. }
  2838. if len(keywords) != 0 {
  2839. keywords = "%" + keywords + "%"
  2840. 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)
  2841. if schedule_type != 0 {
  2842. db = db.Where("schedule_type = ?", schedule_type)
  2843. }
  2844. if partition_id != 0 {
  2845. db = db.Where("partition_id = ?", partition_id)
  2846. }
  2847. if good_type == 1 {
  2848. db = db.Where("patient_id in(?)", ids)
  2849. }
  2850. if good_type == 2 {
  2851. if len(ids) > 0 {
  2852. db = db.Where("patient_id not in(?)", ids)
  2853. }
  2854. }
  2855. } else {
  2856. if schedule_type != 0 {
  2857. db = db.Where("schedule_type = ?", schedule_type)
  2858. }
  2859. if partition_id != 0 {
  2860. db = db.Where("partition_id = ?", partition_id)
  2861. }
  2862. if good_type == 1 {
  2863. db = db.Where("patient_id in(?)", ids)
  2864. }
  2865. if good_type == 2 {
  2866. if len(ids) > 0 {
  2867. db = db.Where("patient_id not in(?)", ids)
  2868. }
  2869. }
  2870. db = db.Count(&total)
  2871. offset := (page - 1) * limit
  2872. db = db.Offset(offset).Limit(limit)
  2873. }
  2874. err := db.Find(&vms).Error
  2875. return vms, err, total
  2876. }
  2877. func GetLastDialysisGoodsTwo(patient_id int64, orgID int64, record_time int64) (goodUser []*AutomaticReduceDetail, err error) {
  2878. var Id []*DialysisGoodsDetailDate
  2879. 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
  2880. if len(Id) > 0 {
  2881. 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
  2882. }
  2883. return
  2884. }
  2885. func GetLastDialysisBeforePrepareTwo(patient_id int64, orgID int64, record_time int64) (goodUser []*DialysisBeforePrepare, err error) {
  2886. var Id []*DialysisGoodsDate
  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, record_time).Select("record_date").Group("record_date").Order("record_date asc").Scan(&Id).Error
  2888. if len(Id) > 0 {
  2889. 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
  2890. }
  2891. return
  2892. }
  2893. func GetAssessmentBefor(orgid int64, patientid int64, recorddate int64) (*models.PredialysisEvaluation, error) {
  2894. evaluation := models.PredialysisEvaluation{}
  2895. err := XTReadDB().Model(&evaluation).Where("user_org_id = ? and patient_id = ? and assessment_date = ? and status = 1", orgid, patientid, recorddate).Find(&evaluation).Error
  2896. if err == gorm.ErrRecordNotFound {
  2897. return nil, err
  2898. }
  2899. if err != nil {
  2900. return nil, err
  2901. }
  2902. return &evaluation, nil
  2903. }
  2904. func GetAssessmentBeforThrity(orgid int64, patientid int64, recorddate int64) (models.PredialysisEvaluation, error) {
  2905. evaluation := models.PredialysisEvaluation{}
  2906. err := XTReadDB().Model(&evaluation).Where("user_org_id = ? and patient_id = ? and assessment_date = ? and status = 1", orgid, patientid, recorddate).Find(&evaluation).Error
  2907. return evaluation, err
  2908. }
  2909. func GetAssessmentBeforFourty(orgid int64, patientid int64, recorddate int64) (models.XtAssessmentBeforeDislysis, error) {
  2910. evaluation := models.XtAssessmentBeforeDislysis{}
  2911. err := XTReadDB().Model(&evaluation).Where("user_org_id = ? and patient_id = ? and assessment_date = ? and status = 1", orgid, patientid, recorddate).Find(&evaluation).Error
  2912. return evaluation, err
  2913. }
  2914. func GetHisPrescriptionTemplateList(user_org_id int64, patient_id int64, mode_id int64) (models.HisPrescriptionTemplateSix, error) {
  2915. templateSix := models.HisPrescriptionTemplateSix{}
  2916. 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 {
  2917. return db.Where("status = 1 AND user_org_id = ? and type =2", user_org_id).Preload("HisPrescriptionProjectTemplateSeven", func(db *gorm.DB) *gorm.DB {
  2918. 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)
  2919. })
  2920. }).Find(&templateSix).Error
  2921. return templateSix, err
  2922. }
  2923. func GetAllHisDoctorAdvice(orgid int64, patientid int64, recorddate int64) (his []*models.HisDoctorAdviceInfo, err error) {
  2924. redis := RedisClient()
  2925. defer redis.Close()
  2926. key := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patientid, 10) + ":" + strconv.FormatInt(recorddate, 10) + ":his_doctor_advice"
  2927. his_doctor_advice_str, _ := redis.Get(key).Result()
  2928. redis.Set(key, "", time.Second)
  2929. if orgid != 10721 {
  2930. if len(his_doctor_advice_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2931. 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
  2932. if err != nil {
  2933. if err == gorm.ErrRecordNotFound {
  2934. if len(his) <= 0 {
  2935. redis.Set(key, "null", time.Second*60*60*18)
  2936. }
  2937. return his, nil
  2938. } else {
  2939. return his, err
  2940. }
  2941. } else {
  2942. if len(his) > 0 {
  2943. //缓存数据
  2944. his_doctor_advice_str, err := json.Marshal(his)
  2945. if err == nil {
  2946. redis.Set(key, his_doctor_advice_str, time.Second*60*60*18)
  2947. }
  2948. } else {
  2949. redis.Set(key, "null", time.Second*60*60*18)
  2950. }
  2951. return his, nil
  2952. }
  2953. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2954. json.Unmarshal([]byte(his_doctor_advice_str), &his)
  2955. return his, nil
  2956. }
  2957. }
  2958. if orgid == 10721 {
  2959. if len(his_doctor_advice_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2960. var keyword = "胰岛素"
  2961. keyword = "%" + keyword + "%"
  2962. err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date = ? and execution_frequency!='上机前' and delivery_way!='口服' and advice_name not like ?", patientid, orgid, recorddate, keyword).Order("created_time asc").Find(&his).Error
  2963. if err != nil {
  2964. if err == gorm.ErrRecordNotFound {
  2965. if len(his) <= 0 {
  2966. redis.Set(key, "null", time.Second*60*60*18)
  2967. }
  2968. return his, nil
  2969. } else {
  2970. return his, err
  2971. }
  2972. } else {
  2973. if len(his) > 0 {
  2974. //缓存数据
  2975. his_doctor_advice_str, err := json.Marshal(his)
  2976. if err == nil {
  2977. redis.Set(key, his_doctor_advice_str, time.Second*60*60*18)
  2978. }
  2979. } else {
  2980. redis.Set(key, "null", time.Second*60*60*18)
  2981. }
  2982. return his, nil
  2983. }
  2984. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2985. json.Unmarshal([]byte(his_doctor_advice_str), &his)
  2986. return his, nil
  2987. }
  2988. }
  2989. return his, nil
  2990. }
  2991. func GetLastDialysisPrescriptionByPatientId(orgid int64, patientid int64, recorddate int64) (*models.DialysisPrescription, error) {
  2992. prescription := models.DialysisPrescription{}
  2993. err := readDb.Model(&models.DialysisPrescription{}).Where("user_org_id = ? and patient_id = ? and record_date = ? and status = 1", orgid, patientid, recorddate).Find(&prescription).Error
  2994. if err == gorm.ErrRecordNotFound {
  2995. return nil, err
  2996. }
  2997. if err != nil {
  2998. return nil, err
  2999. }
  3000. return &prescription, nil
  3001. }
  3002. func GetLastDialysisPrescriptionByPatientIdTwo(orgid int64, patientid int64, recorddate int64) (models.DialysisPrescription, error) {
  3003. prescription := models.DialysisPrescription{}
  3004. err := readDb.Model(&models.DialysisPrescription{}).Where("user_org_id = ? and patient_id = ? and record_date = ? and status = 1", orgid, patientid, recorddate).Find(&prescription).Error
  3005. return prescription, err
  3006. }
  3007. type HisMScheduleDoctorAdviceVM struct {
  3008. ID int64 `gorm:"column:id" json:"id"`
  3009. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  3010. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  3011. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  3012. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  3013. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  3014. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  3015. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  3016. Status int64 `gorm:"column:status" json:"status"`
  3017. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  3018. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  3019. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  3020. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  3021. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  3022. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  3023. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  3024. }
  3025. func (HisMScheduleDoctorAdviceVM) TableName() string {
  3026. return "xt_schedule"
  3027. }
  3028. type HisMScheduleDoctorAdviceVMOne struct {
  3029. ID int64 `gorm:"column:id" json:"id"`
  3030. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  3031. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  3032. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  3033. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  3034. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  3035. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  3036. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  3037. Status int64 `gorm:"column:status" json:"status"`
  3038. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  3039. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  3040. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  3041. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  3042. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  3043. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  3044. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  3045. }
  3046. func (HisMScheduleDoctorAdviceVMOne) TableName() string {
  3047. return "xt_schedule"
  3048. }
  3049. type HisMScheduleProjectVM struct {
  3050. ID int64 `gorm:"column:id" json:"id"`
  3051. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  3052. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  3053. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  3054. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  3055. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  3056. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  3057. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  3058. Status int64 `gorm:"column:status" json:"status"`
  3059. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  3060. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  3061. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  3062. Prescription *models.DialysisPrescriptionTwenty `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  3063. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  3064. HisPrescriptionTeamProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"team_project"`
  3065. }
  3066. func (HisMScheduleProjectVM) TableName() string {
  3067. return "xt_schedule"
  3068. }
  3069. func GetHisDoctorConfig(orgid int64) (models.XtHisConfig, error) {
  3070. config := models.XtHisConfig{}
  3071. err := XTReadDB().Model(&config).Where("user_org_id = ? and status =1", orgid).Find(&config).Error
  3072. return config, err
  3073. }
  3074. func GetHisDoctorPatientById(orgid int64, patientid int64, recordtime int64) (advice []*models.HisDoctorAdviceInfo, err error) {
  3075. db := XTReadDB().Table("his_doctor_advice_info as x").Where("x.status = 1")
  3076. if orgid > 0 {
  3077. db = db.Where("x.user_org_id = ?", orgid)
  3078. }
  3079. if patientid > 0 {
  3080. db = db.Where("x.patient_id =?", patientid)
  3081. }
  3082. if recordtime > 0 {
  3083. db = db.Where("x.advice_date = ?", recordtime)
  3084. }
  3085. 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
  3086. return advice, err
  3087. }
  3088. func GetDoctorAdviceCount(startime int64, endtime int64, deliveway string, orgid int64) (advice []*models.BloodDoctorAdvice, err error) {
  3089. db := XTReadDB().Table("xt_doctor_advice as x").Where("x.status = 1 and x.advice_type =2")
  3090. if startime > 0 {
  3091. db = db.Where("x.advice_date >= ?", startime)
  3092. }
  3093. if endtime > 0 {
  3094. db = db.Where("x.advice_date<=?", endtime)
  3095. }
  3096. if orgid > 0 {
  3097. db = db.Where("x.user_org_id = ?", orgid)
  3098. }
  3099. if len(deliveway) > 0 {
  3100. db = db.Where("x.delivery_way = ?", deliveway)
  3101. }
  3102. 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
  3103. return advice, err
  3104. }
  3105. func GetHisDoctorAdviceCount(startime int64, endtime int64, deliveway string, orgid int64) (advice []*models.BloodDoctorAdvice, err error) {
  3106. db := XTReadDB().Table("his_doctor_advice_info as x").Where("x.status = 1 and x.advice_type =2")
  3107. if startime > 0 {
  3108. db = db.Where("x.advice_date >= ?", startime)
  3109. }
  3110. if endtime > 0 {
  3111. db = db.Where("x.advice_date<=?", endtime)
  3112. }
  3113. if orgid > 0 {
  3114. db = db.Where("x.user_org_id = ?", orgid)
  3115. }
  3116. if len(deliveway) > 0 {
  3117. db = db.Where("x.delivery_way = ?", deliveway)
  3118. }
  3119. 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
  3120. return advice, err
  3121. }
  3122. 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) {
  3123. var vms []*MScheduleDoctorAdviceVM
  3124. adviceWhere := ""
  3125. adviceCondition := []interface{}{}
  3126. if adviceType == 0 {
  3127. if patientType == 0 {
  3128. if patient_id > 0 {
  3129. if execution_state > 0 {
  3130. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  3131. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3132. } else {
  3133. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
  3134. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3135. }
  3136. } else {
  3137. if execution_state > 0 {
  3138. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ?"
  3139. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3140. } else {
  3141. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  3142. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3143. }
  3144. }
  3145. } else if patientType == 1 {
  3146. if patient_id > 0 {
  3147. if execution_state > 0 {
  3148. 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= ?"
  3149. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3150. } else {
  3151. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
  3152. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3153. }
  3154. } else {
  3155. if execution_state > 0 {
  3156. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  3157. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3158. } else {
  3159. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  3160. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3161. }
  3162. }
  3163. } else if patientType == 2 {
  3164. if patient_id > 0 {
  3165. if execution_state > 0 {
  3166. 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 = ?"
  3167. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3168. } else {
  3169. 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 = ?)"
  3170. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3171. }
  3172. } else {
  3173. if execution_state > 0 {
  3174. 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 = ?"
  3175. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3176. } else {
  3177. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  3178. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3179. }
  3180. }
  3181. }
  3182. } else if adviceType == 1 {
  3183. if patientType == 0 {
  3184. if patient_id > 0 {
  3185. if execution_state > 0 {
  3186. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ?"
  3187. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3188. } else {
  3189. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
  3190. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3191. }
  3192. } else {
  3193. if execution_state > 0 {
  3194. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ?"
  3195. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3196. } else {
  3197. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  3198. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3199. }
  3200. }
  3201. } else if patientType == 1 {
  3202. if patient_id > 0 {
  3203. if execution_state > 0 {
  3204. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  3205. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3206. } else {
  3207. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
  3208. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3209. }
  3210. } else {
  3211. if execution_state > 0 {
  3212. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?"
  3213. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3214. } else {
  3215. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  3216. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3217. }
  3218. }
  3219. } else if patientType == 2 {
  3220. if patient_id > 0 {
  3221. if execution_state > 0 {
  3222. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  3223. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3224. } else {
  3225. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
  3226. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3227. }
  3228. } else {
  3229. if execution_state > 0 {
  3230. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ?"
  3231. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3232. } else {
  3233. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  3234. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3235. }
  3236. }
  3237. }
  3238. } else if adviceType == 3 {
  3239. if patientType == 0 {
  3240. if patient_id > 0 {
  3241. if execution_state > 0 {
  3242. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ?"
  3243. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3244. } else {
  3245. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? "
  3246. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3247. }
  3248. } else {
  3249. if execution_state > 0 {
  3250. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? "
  3251. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3252. } else {
  3253. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  3254. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3255. }
  3256. }
  3257. } else if patientType == 1 {
  3258. if patient_id > 0 {
  3259. if execution_state > 0 {
  3260. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  3261. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3262. } else {
  3263. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
  3264. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3265. }
  3266. } else {
  3267. if execution_state > 0 {
  3268. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? "
  3269. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3270. } else {
  3271. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  3272. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3273. }
  3274. }
  3275. } else if patientType == 2 {
  3276. if patient_id > 0 {
  3277. if execution_state > 0 {
  3278. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  3279. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3280. } else {
  3281. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ?"
  3282. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3283. }
  3284. } else {
  3285. if execution_state > 0 {
  3286. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ?"
  3287. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3288. } else {
  3289. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  3290. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3291. }
  3292. }
  3293. }
  3294. } else if adviceType == 2 && len(deliverWay) > 0 {
  3295. if patientType == 0 {
  3296. if patient_id > 0 {
  3297. if execution_state > 0 {
  3298. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  3299. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  3300. } else {
  3301. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ?"
  3302. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  3303. }
  3304. } else {
  3305. if execution_state > 0 {
  3306. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ?"
  3307. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  3308. } else {
  3309. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  3310. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  3311. }
  3312. }
  3313. } else if patientType == 1 {
  3314. if patient_id > 0 {
  3315. if execution_state > 0 {
  3316. 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 = ?"
  3317. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state)
  3318. } else {
  3319. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ?"
  3320. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
  3321. }
  3322. } else {
  3323. if execution_state > 0 {
  3324. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ?"
  3325. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state)
  3326. } else {
  3327. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  3328. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  3329. }
  3330. }
  3331. } else if patientType == 2 {
  3332. if patient_id > 0 {
  3333. if execution_state > 0 {
  3334. 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 = ?"
  3335. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  3336. } else {
  3337. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ?"
  3338. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  3339. }
  3340. } else {
  3341. if execution_state > 0 {
  3342. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ?"
  3343. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  3344. } else {
  3345. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  3346. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  3347. }
  3348. }
  3349. }
  3350. } else if adviceType == 2 && len(deliverWay) <= 0 {
  3351. if patientType == 0 {
  3352. if patient_id > 0 {
  3353. if execution_state > 0 {
  3354. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ?"
  3355. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3356. } else {
  3357. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ?"
  3358. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3359. }
  3360. } else {
  3361. if execution_state > 0 {
  3362. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?"
  3363. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3364. } else {
  3365. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  3366. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3367. }
  3368. }
  3369. } else if patientType == 1 {
  3370. if patient_id > 0 {
  3371. if execution_state > 0 {
  3372. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  3373. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3374. } else {
  3375. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ?"
  3376. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3377. }
  3378. } else {
  3379. if execution_state > 0 {
  3380. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ?"
  3381. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3382. } else {
  3383. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?"
  3384. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3385. }
  3386. }
  3387. } else if patientType == 2 {
  3388. if patient_id > 0 {
  3389. if execution_state > 0 {
  3390. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  3391. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3392. } else {
  3393. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ?"
  3394. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3395. }
  3396. } else {
  3397. if execution_state > 0 {
  3398. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ?"
  3399. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3400. } else {
  3401. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  3402. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3403. }
  3404. }
  3405. }
  3406. }
  3407. db := readDb.Table("xt_schedule")
  3408. if scheduleType > 0 {
  3409. db = db.Where("schedule_type = ?", scheduleType)
  3410. }
  3411. if partitonType > 0 {
  3412. db = db.Where("partition_id = ?", partitonType)
  3413. }
  3414. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3415. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3416. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3417. }).
  3418. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3419. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3420. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3421. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3422. Preload("DoctorAdvices", adviceCondition...).
  3423. Where("status = 1 AND user_org_id = ?", orgID)
  3424. if scheduleDate != 0 {
  3425. db = db.Where("schedule_date = ?", scheduleDate)
  3426. }
  3427. err := db.Find(&vms).Error
  3428. return vms, err
  3429. }
  3430. func GetHisDoctorAdvicesOne(orgID int64, scheduleDate int64, deliverWay string, scheduleType int64, partitionType int64, patient_id int64, execution_state int64, cost_type int64) ([]*HisMScheduleDoctorAdviceVM, error) {
  3431. var vms []*HisMScheduleDoctorAdviceVM
  3432. if len(deliverWay) > 0 {
  3433. db := readDb.Table("xt_schedule")
  3434. if scheduleType > 0 {
  3435. db = db.Where("schedule_type = ?", scheduleType)
  3436. }
  3437. if partitionType > 0 {
  3438. db = db.Where("partition_id = ?", partitionType)
  3439. }
  3440. if patient_id > 0 {
  3441. if execution_state > 0 {
  3442. if cost_type > 0 {
  3443. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3444. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3445. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3446. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3447. 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).
  3448. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3449. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3450. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3451. Where("status = 1 AND user_org_id = ?", orgID)
  3452. if scheduleDate != 0 {
  3453. db = db.Where("schedule_date = ?", scheduleDate)
  3454. }
  3455. err = db.Find(&vms).Error
  3456. } else {
  3457. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3458. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3459. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3460. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3461. 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).
  3462. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3463. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3464. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3465. Where("status = 1 AND user_org_id = ?", orgID)
  3466. if scheduleDate != 0 {
  3467. db = db.Where("schedule_date = ?", scheduleDate)
  3468. }
  3469. err = db.Find(&vms).Error
  3470. }
  3471. } else {
  3472. if cost_type > 0 {
  3473. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3474. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3475. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3476. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3477. 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).
  3478. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3479. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3480. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3481. Where("status = 1 AND user_org_id = ?", orgID)
  3482. if scheduleDate != 0 {
  3483. db = db.Where("schedule_date = ?", scheduleDate)
  3484. }
  3485. err = db.Find(&vms).Error
  3486. } else {
  3487. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3488. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3489. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3490. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3491. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ?", orgID, scheduleDate, deliverWay, patient_id).
  3492. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3493. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3494. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3495. Where("status = 1 AND user_org_id = ?", orgID)
  3496. if scheduleDate != 0 {
  3497. db = db.Where("schedule_date = ?", scheduleDate)
  3498. }
  3499. err = db.Find(&vms).Error
  3500. }
  3501. }
  3502. } else {
  3503. if execution_state > 0 {
  3504. if cost_type > 0 {
  3505. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3506. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3507. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3508. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3509. 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).
  3510. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3511. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3512. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3513. Where("status = 1 AND user_org_id = ?", orgID)
  3514. if scheduleDate != 0 {
  3515. db = db.Where("schedule_date = ?", scheduleDate)
  3516. }
  3517. err = db.Find(&vms).Error
  3518. } else {
  3519. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3520. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3521. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3522. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3523. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_state = ?", orgID, scheduleDate, deliverWay, execution_state).
  3524. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3525. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3526. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3527. Where("status = 1 AND user_org_id = ?", orgID)
  3528. if scheduleDate != 0 {
  3529. db = db.Where("schedule_date = ?", scheduleDate)
  3530. }
  3531. err = db.Find(&vms).Error
  3532. }
  3533. } else {
  3534. if cost_type > 0 {
  3535. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3536. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3537. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3538. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3539. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and is_settle = ?", orgID, scheduleDate, deliverWay, cost_type).
  3540. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3541. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3542. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3543. Where("status = 1 AND user_org_id = ?", orgID)
  3544. if scheduleDate != 0 {
  3545. db = db.Where("schedule_date = ?", scheduleDate)
  3546. }
  3547. err = db.Find(&vms).Error
  3548. } else {
  3549. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3550. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3551. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3552. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3553. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  3554. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3555. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3556. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3557. Where("status = 1 AND user_org_id = ?", orgID)
  3558. if scheduleDate != 0 {
  3559. db = db.Where("schedule_date = ?", scheduleDate)
  3560. }
  3561. err = db.Find(&vms).Error
  3562. }
  3563. }
  3564. }
  3565. } else {
  3566. db := readDb.Table("xt_schedule")
  3567. if scheduleType > 0 {
  3568. db = db.Where("schedule_type = ?", scheduleType)
  3569. }
  3570. if partitionType > 0 {
  3571. db = db.Where("partition_id = ?", partitionType)
  3572. }
  3573. if patient_id > 0 {
  3574. if execution_state > 0 {
  3575. if cost_type > 0 {
  3576. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3577. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3578. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3579. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3580. 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).
  3581. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3582. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3583. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3584. Where("status = 1 AND user_org_id = ?", orgID)
  3585. if scheduleDate != 0 {
  3586. db = db.Where("schedule_date = ?", scheduleDate)
  3587. }
  3588. err = db.Find(&vms).Error
  3589. } else {
  3590. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3591. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3592. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3593. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3594. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and execution_state = ?", orgID, scheduleDate, patient_id, execution_state).
  3595. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3596. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3597. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3598. Where("status = 1 AND user_org_id = ?", orgID)
  3599. if scheduleDate != 0 {
  3600. db = db.Where("schedule_date = ?", scheduleDate)
  3601. }
  3602. err = db.Find(&vms).Error
  3603. }
  3604. } else {
  3605. if cost_type > 0 {
  3606. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3607. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3608. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3609. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3610. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and is_settle = ?", orgID, scheduleDate, patient_id, cost_type).
  3611. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3612. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3613. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3614. Where("status = 1 AND user_org_id = ?", orgID)
  3615. if scheduleDate != 0 {
  3616. db = db.Where("schedule_date = ?", scheduleDate)
  3617. }
  3618. err = db.Find(&vms).Error
  3619. } else {
  3620. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3621. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3622. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3623. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3624. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3625. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3626. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3627. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3628. Where("status = 1 AND user_org_id = ?", orgID)
  3629. if scheduleDate != 0 {
  3630. db = db.Where("schedule_date = ?", scheduleDate)
  3631. }
  3632. err = db.Find(&vms).Error
  3633. }
  3634. }
  3635. } else {
  3636. if execution_state > 0 {
  3637. if cost_type > 0 {
  3638. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3639. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3640. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3641. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3642. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ? and is_settle = ?", orgID, scheduleDate, execution_state, cost_type).
  3643. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3644. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3645. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3646. Where("status = 1 AND user_org_id = ?", orgID)
  3647. if scheduleDate != 0 {
  3648. db = db.Where("schedule_date = ?", scheduleDate)
  3649. }
  3650. err = db.Find(&vms).Error
  3651. } else {
  3652. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3653. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3654. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3655. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3656. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ?", orgID, scheduleDate, execution_state).
  3657. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3658. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3659. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3660. Where("status = 1 AND user_org_id = ?", orgID)
  3661. if scheduleDate != 0 {
  3662. db = db.Where("schedule_date = ?", scheduleDate)
  3663. }
  3664. err = db.Find(&vms).Error
  3665. }
  3666. } else {
  3667. if cost_type > 0 {
  3668. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3669. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3670. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3671. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3672. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and is_settle = ?", orgID, scheduleDate, cost_type).
  3673. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3674. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3675. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3676. Where("status = 1 AND user_org_id = ?", orgID)
  3677. if scheduleDate != 0 {
  3678. db = db.Where("schedule_date = ?", scheduleDate)
  3679. }
  3680. err = db.Find(&vms).Error
  3681. } else {
  3682. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3683. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3684. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3685. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3686. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ?", orgID, scheduleDate).
  3687. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3688. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3689. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3690. Where("status = 1 AND user_org_id = ?", orgID)
  3691. if scheduleDate != 0 {
  3692. db = db.Where("schedule_date = ?", scheduleDate)
  3693. }
  3694. err = db.Find(&vms).Error
  3695. }
  3696. }
  3697. }
  3698. }
  3699. return vms, err
  3700. }
  3701. func BatchDeleteMonitor(ids []string) (err error) {
  3702. if len(ids) == 1 {
  3703. err = XTWriteDB().Model(&models.MonitoringRecord{}).Where("id=?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3704. } else {
  3705. err = XTWriteDB().Model(models.MonitoringRecord{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3706. }
  3707. return
  3708. }
  3709. func GetPatientDialysisRecordList(patientid int64, startime int64, endtime int64) (order []*models.XtDialysisOrders, err error) {
  3710. db := XTReadDB().Table("xt_dialysis_order as x").Where("x.status = 1")
  3711. //table := XTReadDB().Table("xt_schedule as s")
  3712. //fmt.Println(table)
  3713. if patientid > 0 {
  3714. db = db.Where("x.patient_id = ?", patientid)
  3715. }
  3716. if startime > 0 {
  3717. db = db.Where("x.dialysis_date>=?", startime)
  3718. }
  3719. if endtime > 0 {
  3720. db = db.Where("x.dialysis_date <= ?", endtime)
  3721. }
  3722. 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
  3723. return order, err
  3724. }
  3725. func GetPatientDialysisRecordListOne(patientid int64, startime int64, endtime int64) (order []*models.XtScheduleSixTy, err error) {
  3726. db := XTReadDB().Table("xt_schedule as x").Where("x.status = 1")
  3727. //table := XTReadDB().Table("xt_schedule as s")
  3728. //fmt.Println(table)
  3729. if patientid > 0 {
  3730. db = db.Where("x.patient_id = ?", patientid)
  3731. }
  3732. if startime > 0 {
  3733. db = db.Where("x.schedule_date>=?", startime)
  3734. }
  3735. if endtime > 0 {
  3736. db = db.Where("x.schedule_date <= ?", endtime)
  3737. }
  3738. err = db.Select("x.id,x.schedule_date,x.schedule_type,x.mode_id").Find(&order).Error
  3739. return order, err
  3740. }
  3741. func BatchDeleteAdvice(ids []string) (err error) {
  3742. if len(ids) == 1 {
  3743. err = XTWriteDB().Model(&models.DoctorAdvice{}).Where("id=?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3744. } else {
  3745. err = XTWriteDB().Model(models.DoctorAdvice{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3746. }
  3747. return
  3748. }
  3749. func BatchDeleteHisAdvice(ids []string) (err error) {
  3750. if len(ids) == 1 {
  3751. err = XTWriteDB().Model(&models.HisDoctorAdviceInfo{}).Where("id = ?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3752. } else {
  3753. err = XTWriteDB().Model(models.HisDoctorAdviceInfo{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3754. }
  3755. return
  3756. }
  3757. func UpdateAutoReduceDetail(good_id int64, count int64, record_time int64, patient_id int64) (models.AutomaticReduceDetail, error) {
  3758. detail := models.AutomaticReduceDetail{}
  3759. 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
  3760. return detail, err
  3761. }
  3762. func DeleteAutoReduceDetail(good_id int64, record_time int64, patient_id int64) error {
  3763. detail := models.AutomaticReduceDetail{}
  3764. 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
  3765. return err
  3766. }
  3767. func DeleteDialysisBeforOne(good_id int64, record_time int64, patient_id int64) error {
  3768. detail := models.DialysisBeforePrepare{}
  3769. 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
  3770. return err
  3771. }
  3772. func BatchAdviceCheck(ids []string, creator int64) error {
  3773. advice := models.XtDoctorAdvice{}
  3774. 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
  3775. return err
  3776. }
  3777. func BatchHisAdviceCheck(ids []string, creator int64) error {
  3778. advice := models.HisDoctorAdviceInfo{}
  3779. 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
  3780. return err
  3781. }
  3782. func BatchAdviceExecution(ids []string, creator int64, execution_state int64) error {
  3783. advice := models.XtDoctorAdvice{}
  3784. 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
  3785. return err
  3786. }
  3787. func BatchHisAdviceExecution(ids []string, creator int64, execution_state int64) error {
  3788. advice := models.HisDoctorAdviceInfo{}
  3789. 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
  3790. return err
  3791. }
  3792. func GetAdviceExecutionById(ids []string) (doctor []*models.XtDoctorAdvice, err error) {
  3793. err = XTReadDB().Model(&doctor).Where("id IN(?) AND status = 1", ids).Find(&doctor).Error
  3794. return doctor, err
  3795. }
  3796. func GetHisAdviceExecutionById(ids []string) (doctor []*models.HisDoctorAdviceInfo, err error) {
  3797. err = XTReadDB().Model(&doctor).Where("id IN(?) AND status = 1", ids).Find(&doctor).Error
  3798. return doctor, err
  3799. }
  3800. func GetHisProjectConfig(orgid int64) (models.XtHisProjectConfig, error) {
  3801. config := models.XtHisProjectConfig{}
  3802. err := XTReadDB().Model(&config).Where("user_org_id = ? and status =1", orgid).Find(&config).Error
  3803. return config, err
  3804. }
  3805. func GetHisPrescriptionProject(org_id int64, patient_id int64, record_date int64) (project []*models.HisPrescriptionProject, err error) {
  3806. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("GoodInfo", func(db *gorm.DB) *gorm.DB {
  3807. return db.Preload("GoodsType", "status = 1").Where("status = 1 and is_warehouse = 1")
  3808. }).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
  3809. return
  3810. }
  3811. func GetPCHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64, patient_id int64, execution_state int64) ([]*HisMScheduleProjectVM, error) {
  3812. var vms []*HisMScheduleProjectVM
  3813. if patientType == 0 {
  3814. if patient_id > 0 {
  3815. if execution_state == 1 {
  3816. db := readDb.
  3817. Table("xt_schedule").
  3818. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3819. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3820. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3821. }).
  3822. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3823. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3824. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3825. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3826. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0 and execution_state = ?", orgID, scheduleDate, execution_state).Preload("HisProject").Preload("GoodInfo", "status=1")
  3827. }).
  3828. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3829. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0 and execution_state = ?", orgID, scheduleDate, execution_state).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  3830. }).Where("status = 1 AND user_org_id = ?", orgID)
  3831. if scheduleDate != 0 {
  3832. db = db.Where("schedule_date = ?", scheduleDate)
  3833. }
  3834. err = db.Find(&vms).Error
  3835. } else if execution_state == 2 {
  3836. db := readDb.
  3837. Table("xt_schedule").
  3838. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3839. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3840. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3841. }).
  3842. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3843. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3844. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3845. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3846. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0 and execution_state = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3847. }).
  3848. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3849. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0 and execution_state = 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  3850. }).Where("status = 1 AND user_org_id = ?", orgID)
  3851. if scheduleDate != 0 {
  3852. db = db.Where("schedule_date = ?", scheduleDate)
  3853. }
  3854. err = db.Find(&vms).Error
  3855. } else if execution_state == 0 {
  3856. db := readDb.
  3857. Table("xt_schedule").
  3858. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3859. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3860. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3861. }).
  3862. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3863. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3864. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3865. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3866. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3867. }).
  3868. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3869. 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")
  3870. }).Where("status = 1 AND user_org_id = ?", orgID)
  3871. if scheduleDate != 0 {
  3872. db = db.Where("schedule_date = ?", scheduleDate)
  3873. }
  3874. err = db.Find(&vms).Error
  3875. }
  3876. } else {
  3877. if patient_id > 0 {
  3878. if execution_state == 1 {
  3879. db := readDb.
  3880. Table("xt_schedule").
  3881. Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
  3882. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3883. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3884. }).
  3885. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3886. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3887. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3888. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3889. 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")
  3890. }).
  3891. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3892. 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")
  3893. }).Where("status = 1 AND user_org_id = ?", orgID)
  3894. if scheduleDate != 0 {
  3895. db = db.Where("schedule_date = ?", scheduleDate)
  3896. }
  3897. err = db.Find(&vms).Error
  3898. } else if execution_state == 2 {
  3899. db := readDb.
  3900. Table("xt_schedule").
  3901. Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
  3902. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3903. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3904. }).
  3905. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3906. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3907. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3908. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3909. 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")
  3910. }).
  3911. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3912. 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")
  3913. }).Where("status = 1 AND user_org_id = ?", orgID)
  3914. if scheduleDate != 0 {
  3915. db = db.Where("schedule_date = ?", scheduleDate)
  3916. }
  3917. err = db.Find(&vms).Error
  3918. } else if execution_state == 0 {
  3919. db := readDb.
  3920. Table("xt_schedule").
  3921. Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
  3922. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3923. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3924. }).
  3925. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3926. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3927. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3928. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3929. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3930. }).
  3931. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3932. 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")
  3933. }).Where("status = 1 AND user_org_id = ?", orgID)
  3934. if scheduleDate != 0 {
  3935. db = db.Where("schedule_date = ?", scheduleDate)
  3936. }
  3937. err = db.Find(&vms).Error
  3938. }
  3939. } else {
  3940. if execution_state == 1 {
  3941. db := readDb.
  3942. Table("xt_schedule").
  3943. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3944. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3945. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3946. }).
  3947. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3948. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3949. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3950. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3951. 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")
  3952. }).
  3953. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3954. 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")
  3955. }).Where("status = 1 AND user_org_id = ?", orgID)
  3956. if scheduleDate != 0 {
  3957. db = db.Where("schedule_date = ?", scheduleDate)
  3958. }
  3959. err = db.Find(&vms).Error
  3960. } else if execution_state == 2 {
  3961. fmt.Println("j氯332n323232n323ℹ️33232323232")
  3962. db := readDb.
  3963. Table("xt_schedule").
  3964. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3965. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3966. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3967. }).
  3968. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3969. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3970. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3971. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3972. 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")
  3973. }).
  3974. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3975. 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")
  3976. }).Where("status = 1 AND user_org_id = ?", orgID)
  3977. if scheduleDate != 0 {
  3978. db = db.Where("schedule_date = ?", scheduleDate)
  3979. }
  3980. err = db.Find(&vms).Error
  3981. } else if execution_state == 0 {
  3982. db := readDb.
  3983. Table("xt_schedule").
  3984. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3985. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3986. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3987. }).
  3988. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3989. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3990. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3991. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3992. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3993. }).
  3994. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3995. 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")
  3996. }).Where("status = 1 AND user_org_id = ?", orgID)
  3997. if scheduleDate != 0 {
  3998. db = db.Where("schedule_date = ?", scheduleDate)
  3999. }
  4000. err = db.Find(&vms).Error
  4001. }
  4002. }
  4003. }
  4004. }
  4005. if patientType > 0 {
  4006. if execution_state == 1 {
  4007. db := readDb.
  4008. Table("xt_schedule").
  4009. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  4010. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  4011. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  4012. }).
  4013. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  4014. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  4015. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  4016. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  4017. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  4018. 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")
  4019. }).
  4020. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  4021. 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")
  4022. }).Where("status = 1 AND user_org_id = ?", orgID)
  4023. if scheduleDate != 0 {
  4024. db = db.Where("schedule_date = ?", scheduleDate)
  4025. }
  4026. err = db.Find(&vms).Error
  4027. } else if execution_state == 2 {
  4028. db := readDb.
  4029. Table("xt_schedule").
  4030. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  4031. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  4032. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  4033. }).
  4034. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  4035. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  4036. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  4037. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  4038. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  4039. 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")
  4040. }).
  4041. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  4042. 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")
  4043. }).Where("status = 1 AND user_org_id = ?", orgID)
  4044. if scheduleDate != 0 {
  4045. db = db.Where("schedule_date = ?", scheduleDate)
  4046. }
  4047. err = db.Find(&vms).Error
  4048. } else if execution_state == 0 {
  4049. db := readDb.
  4050. Table("xt_schedule").
  4051. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  4052. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  4053. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  4054. }).
  4055. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  4056. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  4057. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  4058. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  4059. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  4060. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  4061. }).
  4062. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  4063. 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")
  4064. }).Where("status = 1 AND user_org_id = ?", orgID)
  4065. if scheduleDate != 0 {
  4066. db = db.Where("schedule_date = ?", scheduleDate)
  4067. }
  4068. err = db.Find(&vms).Error
  4069. }
  4070. }
  4071. return vms, err
  4072. }
  4073. func UpdateStockGoods(good_id int64, record_time int64, patient_id int64, count int64) error {
  4074. prepare := models.DialysisBeforePrepare{}
  4075. var err error
  4076. if count > 0 {
  4077. 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
  4078. }
  4079. if count <= 0 {
  4080. 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
  4081. }
  4082. return err
  4083. }
  4084. func UPdateAutoStockGoods(good_id int64, record_time int64, patient_id int64, count int64) error {
  4085. detail := models.AutomaticReduceDetail{}
  4086. 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
  4087. return err
  4088. }
  4089. func MobileGetDialysisSolutionByModeIdSeven(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  4090. var record models.DialysisSolution
  4091. 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
  4092. if err != nil {
  4093. if err == gorm.ErrRecordNotFound {
  4094. return nil, nil
  4095. } else {
  4096. return nil, err
  4097. }
  4098. }
  4099. return &record, nil
  4100. }
  4101. func MobileGetLastDialysisPrescribeByModeIdSeven(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  4102. var record models.DialysisPrescription
  4103. 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
  4104. if err != nil {
  4105. if err == gorm.ErrRecordNotFound {
  4106. return nil, nil
  4107. } else {
  4108. return nil, err
  4109. }
  4110. }
  4111. return &record, nil
  4112. }
  4113. func MobileGetLastDialysisPrescription(patientID int64, orgID int64) (models.DialysisPrescriptionThrity, error) {
  4114. prescription := models.DialysisPrescriptionThrity{}
  4115. err := readDb.Model(&prescription).Where("patient_id = ? and user_org_id = ? and status = 1 and remark<>''", patientID, orgID).Last(&prescription).Error
  4116. return prescription, err
  4117. }
  4118. func MobileGetSystemDialysisPrescribeByModeIdSeven(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  4119. var record models.SystemPrescription
  4120. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).First(&record).Error
  4121. if err != nil {
  4122. if err == gorm.ErrRecordNotFound {
  4123. return nil, nil
  4124. } else {
  4125. return nil, err
  4126. }
  4127. }
  4128. return &record, nil
  4129. }
  4130. // 透前评估
  4131. func MobileGetPredialysisEvaluationSeven(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
  4132. var record models.PredialysisEvaluation
  4133. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  4134. if err != nil {
  4135. if err == gorm.ErrRecordNotFound {
  4136. return nil, nil
  4137. } else {
  4138. return nil, err
  4139. }
  4140. }
  4141. return &record, nil
  4142. }
  4143. //
  4144. //func MobileGetDialysisGoodsSix(orgID int64, scheduleDate int64) (prepare []*models.DialysisBeforePrepare, err error) {
  4145. //
  4146. // 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
  4147. // return prepare, err
  4148. //}
  4149. func GetMobileAutoReduce(orgID int64, scheduleDate int64) (auto []*models.AutomaticReduceDetail, err error) {
  4150. err = readDb.Where("org_id = ? and status = 1 and record_time = ?", orgID, scheduleDate).Find(&auto).Error
  4151. return auto, err
  4152. }
  4153. func GetRoleList(orgid int64, admin_user_id int64) (models.SgjUserAdminRole, error) {
  4154. role := models.SgjUserAdminRole{}
  4155. err = readUserDb.Where("org_id = ? and admin_user_id = ? and status =1 ", orgid, admin_user_id).Find(&role).Error
  4156. return role, err
  4157. }
  4158. func GetDialysisGood(orgID int64, scheduleDate int64) (auto []*models.AutomaticReduceDetail, err error) {
  4159. err = readDb.Where("org_id = ? and status = 1 and record_time >= ?", orgID, scheduleDate).Group("patient_id").Find(&auto).Error
  4160. return auto, err
  4161. }
  4162. func GetGoodWarehouseOutInfo(orgId int64, patient_id int64, sys_record_time int64) (outifno []*models.WarehouseOutInfoSeven, err error) {
  4163. err = readDb.Where("org_id = ? and patient_id = ? and sys_record_time = ? and status = 1", orgId, patient_id, sys_record_time).Find(&outifno).Error
  4164. return outifno, err
  4165. }
  4166. func GetLastDilysisOrder(orgid int64, patient_id int64, dialysis_date int64) (models.DialysisOrder, error) {
  4167. order := models.DialysisOrder{}
  4168. err = XTReadDB().Where("user_org_id = ? and patient_id = ? and dialysis_date < ? and status= 1", orgid, patient_id, dialysis_date).Last(&order).Error
  4169. return order, err
  4170. }
  4171. func GetFistMonitor(orgid int64, patient_id int64, dialysis_date int64) (models.MonitoringRecord, error) {
  4172. record := models.MonitoringRecord{}
  4173. err := XTReadDB().Where("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 GetFistMonitorSix(orgid int64, patient_id int64, dialysis_date int64) (record []*models.MonitoringRecord, err error) {
  4177. err = XTReadDB().Where("user_org_id = ? and patient_id = ? and monitoring_date = ? and status = 1", orgid, patient_id, dialysis_date).Find(&record).Error
  4178. return record, err
  4179. }
  4180. 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) {
  4181. var vms []*MScheduleDoctorAdviceVM
  4182. keyword = "%" + keyword + "%"
  4183. adviceWhere := ""
  4184. adviceCondition := []interface{}{}
  4185. if adviceType == 0 {
  4186. if patientType == 0 {
  4187. if patient_id > 0 {
  4188. if execution_state > 0 {
  4189. if cost_type > 0 {
  4190. if len(execution_frequency) > 0 {
  4191. if len(keyword) > 0 {
  4192. 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 ?"
  4193. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4194. } else {
  4195. 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 = ?"
  4196. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4197. }
  4198. } else {
  4199. if len(keyword) > 0 {
  4200. 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 ?"
  4201. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  4202. } else {
  4203. 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 = ?"
  4204. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4205. }
  4206. }
  4207. } else {
  4208. if len(execution_frequency) > 0 {
  4209. if len(keyword) > 0 {
  4210. 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 ?"
  4211. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  4212. } else {
  4213. 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 = ?"
  4214. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4215. }
  4216. } else {
  4217. if len(keyword) > 0 {
  4218. 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 ?"
  4219. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  4220. } else {
  4221. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  4222. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4223. }
  4224. }
  4225. }
  4226. } else {
  4227. if cost_type > 0 {
  4228. if len(execution_frequency) > 0 {
  4229. 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 = ?"
  4230. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4231. } else {
  4232. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and is_settle = ?"
  4233. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4234. }
  4235. } else {
  4236. if len(execution_frequency) > 0 {
  4237. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_frequency = ?"
  4238. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4239. } else {
  4240. if len(keyword) > 0 {
  4241. 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 ?"
  4242. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  4243. } else {
  4244. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
  4245. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4246. }
  4247. }
  4248. }
  4249. }
  4250. } else {
  4251. if execution_state > 0 {
  4252. if cost_type > 0 {
  4253. if len(execution_frequency) > 0 {
  4254. if len(keyword) > 0 {
  4255. 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 ?"
  4256. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  4257. } else {
  4258. 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 = ?"
  4259. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4260. }
  4261. } else {
  4262. if len(keyword) > 0 {
  4263. 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 ?"
  4264. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  4265. } else {
  4266. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and is_settle = ?"
  4267. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4268. }
  4269. }
  4270. } else {
  4271. if len(execution_frequency) > 0 {
  4272. if len(keyword) > 0 {
  4273. 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 ?"
  4274. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  4275. } else {
  4276. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and execution_frequency = ?"
  4277. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4278. }
  4279. } else {
  4280. if len(keyword) > 0 {
  4281. 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 ?"
  4282. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  4283. } else {
  4284. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ?"
  4285. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4286. }
  4287. }
  4288. }
  4289. } else {
  4290. if cost_type > 0 {
  4291. if len(execution_frequency) > 0 {
  4292. if len(keyword) > 0 {
  4293. 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 ?"
  4294. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  4295. } else {
  4296. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ? and execution_frequency = ?"
  4297. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  4298. }
  4299. } else {
  4300. if len(keyword) > 0 {
  4301. 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 ?"
  4302. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  4303. } else {
  4304. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ?"
  4305. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4306. }
  4307. }
  4308. } else {
  4309. if len(execution_frequency) > 0 {
  4310. if len(keyword) > 0 {
  4311. 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 ?"
  4312. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  4313. } else {
  4314. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_frequency = ?"
  4315. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  4316. }
  4317. } else {
  4318. if len(keyword) > 0 {
  4319. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and advice_name like ?"
  4320. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  4321. } else {
  4322. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  4323. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4324. }
  4325. }
  4326. }
  4327. }
  4328. }
  4329. } else if patientType == 1 {
  4330. if patient_id > 0 {
  4331. if execution_state > 0 {
  4332. if cost_type > 0 {
  4333. if len(execution_frequency) > 0 {
  4334. if len(keyword) > 0 {
  4335. 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 ?"
  4336. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4337. } else {
  4338. 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 = ?"
  4339. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  4340. }
  4341. } else {
  4342. if len(keyword) > 0 {
  4343. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ? and is_settle = ? and advice_name like ?"
  4344. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, keyword)
  4345. } else {
  4346. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ? and is_settle = ?"
  4347. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  4348. }
  4349. }
  4350. } else {
  4351. if len(execution_frequency) > 0 {
  4352. if len(keyword) > 0 {
  4353. 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 ?"
  4354. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  4355. } else {
  4356. 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 = ?"
  4357. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  4358. }
  4359. } else {
  4360. if len(keyword) > 0 {
  4361. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ? and advice_name like ?"
  4362. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, keyword)
  4363. } else {
  4364. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  4365. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  4366. }
  4367. }
  4368. }
  4369. } else {
  4370. if cost_type > 0 {
  4371. if len(execution_frequency) > 0 {
  4372. if len(keyword) > 0 {
  4373. 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 ?"
  4374. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  4375. } else {
  4376. 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 = ?"
  4377. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  4378. }
  4379. } else {
  4380. if len(keyword) > 0 {
  4381. 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 ?"
  4382. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, keyword)
  4383. } else {
  4384. 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=?"
  4385. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  4386. }
  4387. }
  4388. } else {
  4389. if len(execution_frequency) > 0 {
  4390. if len(keyword) > 0 {
  4391. 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 ?"
  4392. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency, keyword)
  4393. } else {
  4394. 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 = ?"
  4395. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  4396. }
  4397. } else {
  4398. if len(keyword) > 0 {
  4399. 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 ?"
  4400. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, keyword)
  4401. } else {
  4402. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
  4403. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  4404. }
  4405. }
  4406. }
  4407. }
  4408. } else {
  4409. if execution_state > 0 {
  4410. if cost_type > 0 {
  4411. if len(execution_frequency) > 0 {
  4412. if len(keyword) > 0 {
  4413. 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 ?"
  4414. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  4415. } else {
  4416. 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 = ?"
  4417. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  4418. }
  4419. } else {
  4420. if len(keyword) > 0 {
  4421. 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 ?"
  4422. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, keyword)
  4423. } else {
  4424. 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=?"
  4425. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  4426. }
  4427. }
  4428. } else {
  4429. if len(execution_frequency) > 0 {
  4430. if len(keyword) > 0 {
  4431. 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 ?"
  4432. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency, keyword)
  4433. } else {
  4434. 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 = ?"
  4435. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  4436. }
  4437. } else {
  4438. if len(keyword) > 0 {
  4439. 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 ?"
  4440. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, keyword)
  4441. } else {
  4442. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  4443. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  4444. }
  4445. }
  4446. }
  4447. } else {
  4448. if cost_type > 0 {
  4449. if len(execution_frequency) > 0 {
  4450. if len(keyword) > 0 {
  4451. 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 ?"
  4452. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency, keyword)
  4453. } else {
  4454. 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 = ?"
  4455. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  4456. }
  4457. } else {
  4458. if len(keyword) > 0 {
  4459. 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 ?"
  4460. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, keyword)
  4461. } else {
  4462. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and is_settle=?"
  4463. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  4464. }
  4465. }
  4466. } else {
  4467. if len(execution_frequency) > 0 {
  4468. if len(keyword) > 0 {
  4469. 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 ?"
  4470. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency, keyword)
  4471. } else {
  4472. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_frequency = ?"
  4473. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  4474. }
  4475. } else {
  4476. if len(keyword) > 0 {
  4477. 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 ?"
  4478. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, keyword)
  4479. } else {
  4480. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  4481. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  4482. }
  4483. }
  4484. }
  4485. }
  4486. }
  4487. } else if patientType == 2 {
  4488. if patient_id > 0 {
  4489. if execution_state > 0 {
  4490. if cost_type > 0 {
  4491. if len(execution_frequency) > 0 {
  4492. if len(keyword) > 0 {
  4493. 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 ?"
  4494. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4495. } else {
  4496. 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 = ?"
  4497. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4498. }
  4499. } else {
  4500. if len(keyword) > 0 {
  4501. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?) and execution_state = ? and is_settle=? and advice_name like ?"
  4502. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  4503. } else {
  4504. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?) and execution_state = ? and is_settle=?"
  4505. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4506. }
  4507. }
  4508. } else {
  4509. if len(execution_frequency) > 0 {
  4510. if len(keyword) > 0 {
  4511. 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 ?"
  4512. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  4513. } else {
  4514. 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 = ?"
  4515. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4516. }
  4517. } else {
  4518. if len(keyword) > 0 {
  4519. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?) and execution_state = ? and advice_name like ?"
  4520. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  4521. } else {
  4522. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?) and execution_state = ?"
  4523. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4524. }
  4525. }
  4526. }
  4527. } else {
  4528. if cost_type > 0 {
  4529. if len(execution_frequency) > 0 {
  4530. if len(keyword) > 0 {
  4531. 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 ?"
  4532. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  4533. } else {
  4534. 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 = ?"
  4535. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4536. }
  4537. } else {
  4538. if len(keyword) > 0 {
  4539. 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 ?"
  4540. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  4541. } else {
  4542. 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=?"
  4543. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4544. }
  4545. }
  4546. } else {
  4547. if len(execution_frequency) > 0 {
  4548. if len(keyword) > 0 {
  4549. 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 ?"
  4550. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  4551. } else {
  4552. 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 = ?"
  4553. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4554. }
  4555. } else {
  4556. if len(keyword) > 0 {
  4557. 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 ?"
  4558. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  4559. } else {
  4560. 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 = ?)"
  4561. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4562. }
  4563. }
  4564. }
  4565. }
  4566. } else {
  4567. if execution_state > 0 {
  4568. if cost_type > 0 {
  4569. if len(execution_frequency) > 0 {
  4570. if len(keyword) > 0 {
  4571. 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 ?"
  4572. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  4573. } else {
  4574. 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 = ?"
  4575. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4576. }
  4577. } else {
  4578. if len(keyword) > 0 {
  4579. 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 ?"
  4580. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  4581. } else {
  4582. 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=?"
  4583. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4584. }
  4585. }
  4586. } else {
  4587. if len(execution_frequency) > 0 {
  4588. if len(keyword) > 0 {
  4589. 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 ?"
  4590. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  4591. } else {
  4592. 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 = ?"
  4593. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4594. }
  4595. } else {
  4596. if len(keyword) > 0 {
  4597. 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 ?"
  4598. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  4599. } else {
  4600. 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 = ?"
  4601. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4602. }
  4603. }
  4604. }
  4605. } else {
  4606. if cost_type > 0 {
  4607. if len(execution_frequency) > 0 {
  4608. if len(keyword) > 0 {
  4609. 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 ?"
  4610. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  4611. } else {
  4612. 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 = ?"
  4613. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  4614. }
  4615. } else {
  4616. if len(keyword) > 0 {
  4617. 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 ?"
  4618. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  4619. } else {
  4620. 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 = ?"
  4621. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4622. }
  4623. }
  4624. } else {
  4625. if len(execution_frequency) > 0 {
  4626. if len(keyword) > 0 {
  4627. 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 ?"
  4628. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  4629. } else {
  4630. 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 = ?"
  4631. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  4632. }
  4633. } else {
  4634. if len(keyword) > 0 {
  4635. 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 ?"
  4636. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  4637. } else {
  4638. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  4639. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4640. }
  4641. }
  4642. }
  4643. }
  4644. }
  4645. }
  4646. } else if adviceType == 1 {
  4647. if patientType == 0 {
  4648. if patient_id > 0 {
  4649. if execution_state > 0 {
  4650. if cost_type > 0 {
  4651. if len(execution_frequency) > 0 {
  4652. if len(keyword) > 0 {
  4653. 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 ?"
  4654. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4655. } else {
  4656. 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 = ?"
  4657. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4658. }
  4659. } else {
  4660. if len(keyword) > 0 {
  4661. 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 ?"
  4662. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  4663. } else {
  4664. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  4665. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4666. }
  4667. }
  4668. } else {
  4669. if len(execution_frequency) > 0 {
  4670. if len(keyword) > 0 {
  4671. 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 ?"
  4672. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  4673. } else {
  4674. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  4675. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4676. }
  4677. } else {
  4678. if len(keyword) > 0 {
  4679. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  4680. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  4681. } else {
  4682. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ?"
  4683. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4684. }
  4685. }
  4686. }
  4687. } else {
  4688. if cost_type > 0 {
  4689. if len(execution_frequency) > 0 {
  4690. if len(keyword) > 0 {
  4691. 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 ?"
  4692. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  4693. } else {
  4694. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  4695. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4696. }
  4697. } else {
  4698. if len(keyword) > 0 {
  4699. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? and advice_name like ? "
  4700. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  4701. } else {
  4702. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? "
  4703. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4704. }
  4705. }
  4706. } else {
  4707. if len(execution_frequency) > 0 {
  4708. if len(keyword) > 0 {
  4709. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and advice_name like ?"
  4710. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  4711. } else {
  4712. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
  4713. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4714. }
  4715. }
  4716. }
  4717. }
  4718. } else {
  4719. if execution_state > 0 {
  4720. if cost_type > 0 {
  4721. if len(execution_frequency) > 0 {
  4722. if len(keyword) > 0 {
  4723. 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 ?"
  4724. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  4725. } else {
  4726. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  4727. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4728. }
  4729. } else {
  4730. if len(keyword) > 0 {
  4731. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  4732. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  4733. } else {
  4734. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ?"
  4735. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4736. }
  4737. }
  4738. } else {
  4739. if len(execution_frequency) > 0 {
  4740. if len(keyword) > 0 {
  4741. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  4742. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  4743. } else {
  4744. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and execution_frequency = ?"
  4745. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4746. }
  4747. } else {
  4748. if len(keyword) > 0 {
  4749. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and advice_name like ?"
  4750. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  4751. } else {
  4752. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ?"
  4753. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4754. }
  4755. }
  4756. }
  4757. } else {
  4758. if cost_type > 0 {
  4759. if len(keyword) > 0 {
  4760. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = ? and advice_name like ?"
  4761. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  4762. } else {
  4763. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = ? "
  4764. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4765. }
  4766. } else {
  4767. if len(keyword) > 0 {
  4768. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and advice_name like ?"
  4769. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  4770. } else {
  4771. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  4772. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4773. }
  4774. }
  4775. }
  4776. }
  4777. } else if patientType == 1 {
  4778. if patient_id > 0 {
  4779. if execution_state > 0 {
  4780. if cost_type > 0 {
  4781. if len(execution_frequency) > 0 {
  4782. if len(keyword) > 0 {
  4783. 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 ?"
  4784. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4785. } else {
  4786. 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 = ?"
  4787. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  4788. }
  4789. } else {
  4790. if len(keyword) > 0 {
  4791. 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 ?"
  4792. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, keyword)
  4793. } else {
  4794. 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 = ?"
  4795. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  4796. }
  4797. }
  4798. } else {
  4799. if len(execution_frequency) > 0 {
  4800. if len(keyword) > 0 {
  4801. 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 ?"
  4802. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  4803. } else {
  4804. 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 = ?"
  4805. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  4806. }
  4807. } else {
  4808. if len(keyword) > 0 {
  4809. 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 ?"
  4810. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, keyword)
  4811. } else {
  4812. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  4813. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  4814. }
  4815. }
  4816. }
  4817. } else {
  4818. if cost_type > 0 {
  4819. if len(execution_frequency) > 0 {
  4820. if len(keyword) > 0 {
  4821. 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 ?"
  4822. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  4823. } else {
  4824. 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 = ?"
  4825. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  4826. }
  4827. } else {
  4828. if len(keyword) > 0 {
  4829. 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 ?"
  4830. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, keyword)
  4831. } else {
  4832. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  4833. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  4834. }
  4835. }
  4836. } else {
  4837. if len(execution_frequency) > 0 {
  4838. if len(keyword) > 0 {
  4839. 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 ?"
  4840. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency, keyword)
  4841. } else {
  4842. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  4843. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  4844. }
  4845. } else {
  4846. if len(keyword) > 0 {
  4847. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and advice_name like ?"
  4848. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, keyword)
  4849. } else {
  4850. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
  4851. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  4852. }
  4853. }
  4854. }
  4855. }
  4856. } else {
  4857. if execution_state > 0 {
  4858. if cost_type > 0 {
  4859. if len(execution_frequency) > 0 {
  4860. if len(keyword) > 0 {
  4861. 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 ?"
  4862. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  4863. } else {
  4864. 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 = ?"
  4865. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  4866. }
  4867. } else {
  4868. if len(keyword) > 0 {
  4869. 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 ?"
  4870. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, keyword)
  4871. } else {
  4872. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=? and is_settle = ?"
  4873. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  4874. }
  4875. }
  4876. } else {
  4877. if len(execution_frequency) > 0 {
  4878. if len(keyword) > 0 {
  4879. 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 ?"
  4880. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency, keyword)
  4881. } else {
  4882. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?and execution_frequency = ?"
  4883. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  4884. }
  4885. } else {
  4886. if len(keyword) > 0 {
  4887. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=? and advice_name like ?"
  4888. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, keyword)
  4889. } else {
  4890. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?"
  4891. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  4892. }
  4893. }
  4894. }
  4895. } else {
  4896. if cost_type > 0 {
  4897. if len(execution_frequency) > 0 {
  4898. if len(keyword) > 0 {
  4899. 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 ?"
  4900. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency, keyword)
  4901. } else {
  4902. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  4903. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  4904. }
  4905. } else {
  4906. if len(keyword) > 0 {
  4907. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? and advice_name like ?"
  4908. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, keyword)
  4909. } else {
  4910. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? "
  4911. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  4912. }
  4913. }
  4914. } else {
  4915. if len(execution_frequency) > 0 {
  4916. if len(keyword) > 0 {
  4917. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_frequency = ? and advice_name like ?"
  4918. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency, keyword)
  4919. } else {
  4920. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_frequency = ?"
  4921. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  4922. }
  4923. } else {
  4924. if len(keyword) > 0 {
  4925. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and advice_name like ?"
  4926. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, keyword)
  4927. } else {
  4928. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  4929. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  4930. }
  4931. }
  4932. }
  4933. }
  4934. }
  4935. } else if patientType == 2 {
  4936. if patient_id > 0 {
  4937. if execution_state > 0 {
  4938. if cost_type > 0 {
  4939. if len(execution_frequency) > 0 {
  4940. if len(keyword) > 0 {
  4941. 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 ?"
  4942. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4943. } else {
  4944. 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 = ?"
  4945. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4946. }
  4947. } else {
  4948. if len(keyword) > 0 {
  4949. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  4950. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  4951. } else {
  4952. 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 = ?"
  4953. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4954. }
  4955. }
  4956. } else {
  4957. if len(execution_frequency) > 0 {
  4958. if len(keyword) > 0 {
  4959. 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 ?"
  4960. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  4961. } else {
  4962. 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 = ?"
  4963. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4964. }
  4965. } else {
  4966. if len(keyword) > 0 {
  4967. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ? and advice_name like ?"
  4968. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  4969. } else {
  4970. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  4971. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4972. }
  4973. }
  4974. }
  4975. } else {
  4976. if cost_type > 0 {
  4977. if len(execution_frequency) > 0 {
  4978. if len(keyword) > 0 {
  4979. 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 ?"
  4980. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  4981. } else {
  4982. 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 = ?"
  4983. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4984. }
  4985. } else {
  4986. if len(keyword) > 0 {
  4987. 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 ?"
  4988. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  4989. } else {
  4990. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  4991. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4992. }
  4993. }
  4994. } else {
  4995. if len(execution_frequency) > 0 {
  4996. if len(keyword) > 0 {
  4997. 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 ?"
  4998. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  4999. } else {
  5000. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_frequency = ?"
  5001. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  5002. }
  5003. } else {
  5004. if len(keyword) > 0 {
  5005. 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 ?"
  5006. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  5007. } else {
  5008. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
  5009. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5010. }
  5011. }
  5012. }
  5013. }
  5014. } else {
  5015. if execution_state > 0 {
  5016. if cost_type > 0 {
  5017. if len(execution_frequency) > 0 {
  5018. if len(keyword) > 0 {
  5019. 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 ?"
  5020. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  5021. } else {
  5022. 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 = ?"
  5023. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  5024. }
  5025. } else {
  5026. if len(keyword) > 0 {
  5027. 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 ?"
  5028. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  5029. } else {
  5030. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  5031. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5032. }
  5033. }
  5034. } else {
  5035. if len(execution_frequency) > 0 {
  5036. if len(keyword) > 0 {
  5037. 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 ?"
  5038. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  5039. } else {
  5040. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and execution_frequency = ?"
  5041. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  5042. }
  5043. } else {
  5044. if len(keyword) > 0 {
  5045. 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 ?"
  5046. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  5047. } else {
  5048. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ?"
  5049. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5050. }
  5051. }
  5052. }
  5053. } else {
  5054. if cost_type > 0 {
  5055. if len(execution_frequency) > 0 {
  5056. if len(keyword) > 0 {
  5057. 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 ?"
  5058. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  5059. } else {
  5060. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  5061. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  5062. }
  5063. } else {
  5064. if len(keyword) > 0 {
  5065. 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 ?"
  5066. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  5067. } else {
  5068. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ?"
  5069. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5070. }
  5071. }
  5072. } else {
  5073. if len(execution_frequency) > 0 {
  5074. if len(keyword) > 0 {
  5075. 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 ?"
  5076. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  5077. } else {
  5078. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_frequency = ?"
  5079. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  5080. }
  5081. } else {
  5082. if len(keyword) > 0 {
  5083. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and advice_name like ?"
  5084. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  5085. } else {
  5086. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  5087. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5088. }
  5089. }
  5090. }
  5091. }
  5092. }
  5093. }
  5094. } else if adviceType == 3 {
  5095. if patientType == 0 {
  5096. if patient_id > 0 {
  5097. if execution_state > 0 {
  5098. if cost_type > 0 {
  5099. if len(execution_frequency) > 0 {
  5100. if len(keyword) > 0 {
  5101. 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 ?"
  5102. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5103. } else {
  5104. 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 =?"
  5105. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  5106. }
  5107. } else {
  5108. if len(keyword) > 0 {
  5109. 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 ?"
  5110. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  5111. } else {
  5112. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  5113. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5114. }
  5115. }
  5116. } else {
  5117. if len(execution_frequency) > 0 {
  5118. if len(keyword) > 0 {
  5119. 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 ?"
  5120. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  5121. } else {
  5122. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency =?"
  5123. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  5124. }
  5125. } else {
  5126. if len(keyword) > 0 {
  5127. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  5128. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  5129. } else {
  5130. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ?"
  5131. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5132. }
  5133. }
  5134. }
  5135. } else {
  5136. if cost_type > 0 {
  5137. if len(execution_frequency) > 0 {
  5138. if len(keyword) > 0 {
  5139. 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 ?"
  5140. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  5141. } else {
  5142. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency =?"
  5143. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  5144. }
  5145. } else {
  5146. if len(keyword) > 0 {
  5147. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  5148. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  5149. } else {
  5150. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? "
  5151. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5152. }
  5153. }
  5154. } else {
  5155. if len(execution_frequency) > 0 {
  5156. if len(keyword) > 0 {
  5157. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_frequency =? and advice_name like ?"
  5158. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  5159. } else {
  5160. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_frequency =?"
  5161. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  5162. }
  5163. } else {
  5164. if len(keyword) > 0 {
  5165. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and advice_name like ?"
  5166. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  5167. } else {
  5168. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? "
  5169. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5170. }
  5171. }
  5172. }
  5173. }
  5174. } else {
  5175. if execution_state > 0 {
  5176. if cost_type > 0 {
  5177. if len(execution_frequency) > 0 {
  5178. if len(keyword) > 0 {
  5179. 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 ?"
  5180. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  5181. } else {
  5182. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ? and execution_frequency =?"
  5183. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  5184. }
  5185. } else {
  5186. if len(keyword) > 0 {
  5187. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ? and advice_name like ?"
  5188. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  5189. } else {
  5190. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ?"
  5191. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5192. }
  5193. }
  5194. } else {
  5195. if len(execution_frequency) > 0 {
  5196. if len(keyword) > 0 {
  5197. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and execution_frequency =? and advice_name like ?"
  5198. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  5199. } else {
  5200. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and execution_frequency =?"
  5201. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  5202. }
  5203. } else {
  5204. if len(keyword) > 0 {
  5205. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and advice_name like ?"
  5206. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  5207. } else {
  5208. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? "
  5209. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5210. }
  5211. }
  5212. }
  5213. } else {
  5214. if cost_type > 0 {
  5215. if len(execution_frequency) > 0 {
  5216. if len(keyword) > 0 {
  5217. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? and execution_frequency =? and advice_name like ?"
  5218. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  5219. } else {
  5220. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? and execution_frequency =?"
  5221. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  5222. }
  5223. } else {
  5224. if len(keyword) > 0 {
  5225. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? and advice_name like ?"
  5226. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  5227. } else {
  5228. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? "
  5229. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5230. }
  5231. }
  5232. } else {
  5233. if len(execution_frequency) > 0 {
  5234. if len(keyword) > 0 {
  5235. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_frequency =? and advice_name like ?"
  5236. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  5237. } else {
  5238. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_frequency =?"
  5239. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  5240. }
  5241. } else {
  5242. if len(keyword) > 0 {
  5243. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and advice_name like ?"
  5244. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  5245. } else {
  5246. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  5247. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5248. }
  5249. }
  5250. }
  5251. }
  5252. }
  5253. } else if patientType == 1 {
  5254. if patient_id > 0 {
  5255. if execution_state > 0 {
  5256. if cost_type > 0 {
  5257. if len(execution_frequency) > 0 {
  5258. if len(keyword) > 0 {
  5259. 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 ?"
  5260. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5261. } else {
  5262. 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 = ?"
  5263. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  5264. }
  5265. } else {
  5266. if len(keyword) > 0 {
  5267. 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 ?"
  5268. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, keyword)
  5269. } else {
  5270. 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 = ?"
  5271. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  5272. }
  5273. }
  5274. } else {
  5275. if len(execution_frequency) > 0 {
  5276. if len(keyword) > 0 {
  5277. 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 ?"
  5278. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  5279. } else {
  5280. 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 = ?"
  5281. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  5282. }
  5283. } else {
  5284. if len(keyword) > 0 {
  5285. 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 ?"
  5286. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, keyword)
  5287. } else {
  5288. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  5289. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  5290. }
  5291. }
  5292. }
  5293. } else {
  5294. if cost_type > 0 {
  5295. if len(execution_frequency) > 0 {
  5296. if len(keyword) > 0 {
  5297. 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 ?"
  5298. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  5299. } else {
  5300. 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 = ?"
  5301. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  5302. }
  5303. } else {
  5304. if len(keyword) > 0 {
  5305. 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 ?"
  5306. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, keyword)
  5307. } else {
  5308. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  5309. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  5310. }
  5311. }
  5312. } else {
  5313. if len(execution_frequency) > 0 {
  5314. if len(keyword) > 0 {
  5315. 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 ?"
  5316. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency, keyword)
  5317. } else {
  5318. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  5319. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  5320. }
  5321. } else {
  5322. if len(keyword) > 0 {
  5323. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and advice_name like ?"
  5324. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, keyword)
  5325. } else {
  5326. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
  5327. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  5328. }
  5329. }
  5330. }
  5331. }
  5332. } else {
  5333. if execution_state > 0 {
  5334. if cost_type > 0 {
  5335. if len(execution_frequency) > 0 {
  5336. if len(keyword) > 0 {
  5337. 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 ?"
  5338. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  5339. } else {
  5340. 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 = ?"
  5341. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  5342. }
  5343. } else {
  5344. if len(keyword) > 0 {
  5345. 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 ?"
  5346. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, keyword)
  5347. } else {
  5348. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? and is_settle = ?"
  5349. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  5350. }
  5351. }
  5352. } else {
  5353. if len(execution_frequency) > 0 {
  5354. if len(keyword) > 0 {
  5355. 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 ? "
  5356. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency, keyword)
  5357. } else {
  5358. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =?and execution_frequency = ? "
  5359. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  5360. }
  5361. } else {
  5362. if len(keyword) > 0 {
  5363. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? and advice_name like ?"
  5364. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, keyword)
  5365. } else {
  5366. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? "
  5367. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  5368. }
  5369. }
  5370. }
  5371. } else {
  5372. if cost_type > 0 {
  5373. if len(execution_frequency) > 0 {
  5374. if len(keyword) > 0 {
  5375. 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 ?"
  5376. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency, keyword)
  5377. } else {
  5378. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  5379. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  5380. }
  5381. } else {
  5382. if len(keyword) > 0 {
  5383. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ? and advice_name like ?"
  5384. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, keyword)
  5385. } else {
  5386. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ?"
  5387. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  5388. }
  5389. }
  5390. } else {
  5391. if len(execution_frequency) > 0 {
  5392. if len(keyword) > 0 {
  5393. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_frequency = ? and advice_name like ?"
  5394. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency, keyword)
  5395. } else {
  5396. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_frequency = ?"
  5397. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  5398. }
  5399. } else {
  5400. if len(keyword) > 0 {
  5401. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and advice_name like ?"
  5402. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, keyword)
  5403. } else {
  5404. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  5405. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  5406. }
  5407. }
  5408. }
  5409. }
  5410. }
  5411. } else if patientType == 2 {
  5412. if patient_id > 0 {
  5413. if execution_state > 0 {
  5414. if cost_type > 0 {
  5415. if len(execution_frequency) > 0 {
  5416. if len(keyword) > 0 {
  5417. 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 ?"
  5418. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5419. } else {
  5420. 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 = ?"
  5421. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  5422. }
  5423. } else {
  5424. if len(keyword) > 0 {
  5425. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5426. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  5427. } else {
  5428. 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 = ?"
  5429. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5430. }
  5431. }
  5432. } else {
  5433. if len(execution_frequency) > 0 {
  5434. if len(keyword) > 0 {
  5435. 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 ?"
  5436. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  5437. } else {
  5438. 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 = ?"
  5439. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  5440. }
  5441. } else {
  5442. if len(keyword) > 0 {
  5443. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ? and advice_name like ?"
  5444. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  5445. } else {
  5446. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  5447. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5448. }
  5449. }
  5450. }
  5451. } else {
  5452. if cost_type > 0 {
  5453. if len(execution_frequency) > 0 {
  5454. if len(keyword) > 0 {
  5455. 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 ?"
  5456. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  5457. } else {
  5458. 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 = ?"
  5459. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  5460. }
  5461. } else {
  5462. if len(keyword) > 0 {
  5463. 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 ?"
  5464. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  5465. } else {
  5466. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  5467. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5468. }
  5469. }
  5470. } else {
  5471. if len(execution_frequency) > 0 {
  5472. if len(keyword) > 0 {
  5473. 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 ?"
  5474. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  5475. } else {
  5476. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_frequency = ?"
  5477. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  5478. }
  5479. } else {
  5480. if len(keyword) > 0 {
  5481. 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 ?"
  5482. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  5483. } else {
  5484. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ?"
  5485. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5486. }
  5487. }
  5488. }
  5489. }
  5490. } else {
  5491. if execution_state > 0 {
  5492. if cost_type > 0 {
  5493. if len(execution_frequency) > 0 {
  5494. if len(keyword) > 0 {
  5495. 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 ?"
  5496. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  5497. } else {
  5498. 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 = ?"
  5499. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  5500. }
  5501. } else {
  5502. if len(keyword) > 0 {
  5503. 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 ?"
  5504. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  5505. } else {
  5506. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and is_settle = ?"
  5507. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5508. }
  5509. }
  5510. } else {
  5511. if len(execution_frequency) > 0 {
  5512. if len(keyword) > 0 {
  5513. 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 ?"
  5514. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  5515. } else {
  5516. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and execution_frequency = ?"
  5517. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  5518. }
  5519. } else {
  5520. if len(keyword) > 0 {
  5521. 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 ?"
  5522. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  5523. } else {
  5524. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ?"
  5525. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5526. }
  5527. }
  5528. }
  5529. } else {
  5530. if cost_type > 0 {
  5531. if len(execution_frequency) > 0 {
  5532. if len(keyword) > 0 {
  5533. 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 ?"
  5534. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  5535. } else {
  5536. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  5537. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  5538. }
  5539. } else {
  5540. if len(keyword) > 0 {
  5541. 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 ?"
  5542. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  5543. } else {
  5544. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ?"
  5545. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5546. }
  5547. }
  5548. } else {
  5549. if len(execution_frequency) > 0 {
  5550. if len(keyword) > 0 {
  5551. 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 ?"
  5552. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  5553. } else {
  5554. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_frequency = ?"
  5555. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  5556. }
  5557. } else {
  5558. if len(keyword) > 0 {
  5559. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and advice_name like ?"
  5560. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  5561. } else {
  5562. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  5563. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5564. }
  5565. }
  5566. }
  5567. }
  5568. }
  5569. }
  5570. } else if adviceType == 2 && len(deliverWay) > 0 {
  5571. if patientType == 0 {
  5572. if patient_id > 0 {
  5573. if execution_state > 0 {
  5574. if cost_type > 0 {
  5575. if len(execution_frequency) > 0 {
  5576. if len(keyword) > 0 {
  5577. 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 ?"
  5578. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5579. } else {
  5580. 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 = ?"
  5581. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency)
  5582. }
  5583. } else {
  5584. if len(keyword) > 0 {
  5585. 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 ?"
  5586. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, keyword)
  5587. } else {
  5588. 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 = ?"
  5589. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  5590. }
  5591. }
  5592. } else {
  5593. if len(execution_frequency) > 0 {
  5594. if len(keyword) > 0 {
  5595. 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 ?"
  5596. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency, keyword)
  5597. } else {
  5598. 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 = ?"
  5599. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency)
  5600. }
  5601. } else {
  5602. if len(keyword) > 0 {
  5603. 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 ?"
  5604. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, keyword)
  5605. } else {
  5606. 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 = ?"
  5607. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  5608. }
  5609. }
  5610. }
  5611. } else {
  5612. if cost_type > 0 {
  5613. if len(execution_frequency) > 0 {
  5614. if len(keyword) > 0 {
  5615. 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 ?"
  5616. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency, keyword)
  5617. } else {
  5618. 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 = ?"
  5619. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency)
  5620. }
  5621. } else {
  5622. if len(keyword) > 0 {
  5623. 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 ?"
  5624. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, keyword)
  5625. } else {
  5626. 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 = ?"
  5627. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  5628. }
  5629. }
  5630. } else {
  5631. if len(execution_frequency) > 0 {
  5632. if len(keyword) > 0 {
  5633. 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 ?"
  5634. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency, keyword)
  5635. } else {
  5636. 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 = ?"
  5637. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency)
  5638. }
  5639. } else {
  5640. if len(keyword) > 0 {
  5641. 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 ?"
  5642. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, keyword)
  5643. } else {
  5644. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ?"
  5645. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  5646. }
  5647. }
  5648. }
  5649. }
  5650. } else {
  5651. if execution_state > 0 {
  5652. if cost_type > 0 {
  5653. if len(execution_frequency) > 0 {
  5654. if len(keyword) > 0 {
  5655. 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 ?"
  5656. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency, keyword)
  5657. } else {
  5658. 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 = ?"
  5659. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency)
  5660. }
  5661. } else {
  5662. if len(keyword) > 0 {
  5663. 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 ?"
  5664. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, keyword)
  5665. } else {
  5666. 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 = ?"
  5667. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  5668. }
  5669. }
  5670. } else {
  5671. if len(execution_frequency) > 0 {
  5672. if len(keyword) > 0 {
  5673. 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 ?"
  5674. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency, keyword)
  5675. } else {
  5676. 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 = ?"
  5677. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency)
  5678. }
  5679. } else {
  5680. if len(keyword) > 0 {
  5681. 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 ?"
  5682. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, keyword)
  5683. } else {
  5684. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and execution_state = ?"
  5685. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  5686. }
  5687. }
  5688. }
  5689. } else {
  5690. if cost_type > 0 {
  5691. if len(execution_frequency) > 0 {
  5692. if len(keyword) > 0 {
  5693. 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 ?"
  5694. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, execution_frequency, keyword)
  5695. } else {
  5696. 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 = ?"
  5697. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, execution_frequency)
  5698. }
  5699. } else {
  5700. if len(keyword) > 0 {
  5701. 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 ?"
  5702. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, keyword)
  5703. } else {
  5704. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and is_settle = ?"
  5705. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  5706. }
  5707. }
  5708. } else {
  5709. if len(execution_frequency) > 0 {
  5710. if len(keyword) > 0 {
  5711. 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 ?"
  5712. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_frequency, keyword)
  5713. } else {
  5714. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and execution_frequency = ?"
  5715. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_frequency)
  5716. }
  5717. } else {
  5718. if len(keyword) > 0 {
  5719. 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 ?"
  5720. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, keyword)
  5721. } else {
  5722. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ?"
  5723. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  5724. }
  5725. }
  5726. }
  5727. }
  5728. }
  5729. } else if patientType == 1 {
  5730. if patient_id > 0 {
  5731. if execution_state > 0 {
  5732. if cost_type > 0 {
  5733. if len(execution_frequency) > 0 {
  5734. if len(keyword) > 0 {
  5735. 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 ?"
  5736. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5737. } else {
  5738. 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 = ?"
  5739. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type, execution_frequency)
  5740. }
  5741. } else {
  5742. if len(keyword) > 0 {
  5743. 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 ?"
  5744. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type, keyword)
  5745. } else {
  5746. 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 = ?"
  5747. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type)
  5748. }
  5749. }
  5750. } else {
  5751. if len(execution_frequency) > 0 {
  5752. if len(keyword) > 0 {
  5753. 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 ?"
  5754. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, execution_frequency, keyword)
  5755. } else {
  5756. 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 = ?"
  5757. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, execution_frequency)
  5758. }
  5759. } else {
  5760. if len(keyword) > 0 {
  5761. 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 ?"
  5762. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, keyword)
  5763. } else {
  5764. 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 = ?"
  5765. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state)
  5766. }
  5767. }
  5768. }
  5769. } else {
  5770. if cost_type > 0 {
  5771. if len(execution_frequency) > 0 {
  5772. if len(keyword) > 0 {
  5773. 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 ?"
  5774. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type, execution_frequency, keyword)
  5775. } else {
  5776. 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 = ?"
  5777. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type, execution_frequency)
  5778. }
  5779. } else {
  5780. if len(keyword) > 0 {
  5781. 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 ?"
  5782. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type, keyword)
  5783. } else {
  5784. 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 = ?"
  5785. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type)
  5786. }
  5787. }
  5788. } else {
  5789. if len(execution_frequency) > 0 {
  5790. if len(keyword) > 0 {
  5791. 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 ?"
  5792. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_frequency, keyword)
  5793. } else {
  5794. 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 = ?"
  5795. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_frequency)
  5796. }
  5797. } else {
  5798. if len(keyword) > 0 {
  5799. 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 ?"
  5800. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, keyword)
  5801. } else {
  5802. 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 = ?"
  5803. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
  5804. }
  5805. }
  5806. }
  5807. }
  5808. } else {
  5809. if execution_state > 0 {
  5810. if cost_type > 0 {
  5811. if len(execution_frequency) > 0 {
  5812. if len(keyword) > 0 {
  5813. 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 ?"
  5814. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type, execution_frequency, keyword)
  5815. } else {
  5816. 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 = ?"
  5817. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type, execution_frequency)
  5818. }
  5819. } else {
  5820. if len(keyword) > 0 {
  5821. 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 ?"
  5822. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type, keyword)
  5823. } else {
  5824. 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 = ?"
  5825. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type)
  5826. }
  5827. }
  5828. } else {
  5829. if len(execution_frequency) > 0 {
  5830. if len(keyword) > 0 {
  5831. 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 ?"
  5832. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, execution_frequency, keyword)
  5833. } else {
  5834. 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 = ?"
  5835. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, execution_frequency)
  5836. }
  5837. } else {
  5838. if len(keyword) > 0 {
  5839. 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 ?"
  5840. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, keyword)
  5841. } else {
  5842. 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 = ?"
  5843. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state)
  5844. }
  5845. }
  5846. }
  5847. } else {
  5848. if cost_type > 0 {
  5849. if len(execution_frequency) > 0 {
  5850. if len(keyword) > 0 {
  5851. 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 ?"
  5852. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type, execution_frequency, keyword)
  5853. } else {
  5854. 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 = ?"
  5855. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type, execution_frequency)
  5856. }
  5857. } else {
  5858. if len(keyword) > 0 {
  5859. 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 ?"
  5860. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type, keyword)
  5861. } else {
  5862. 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 = ?"
  5863. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type)
  5864. }
  5865. }
  5866. } else {
  5867. if len(execution_frequency) > 0 {
  5868. if len(keyword) > 0 {
  5869. 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 ?"
  5870. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_frequency, keyword)
  5871. } else {
  5872. 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 = ?"
  5873. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_frequency)
  5874. }
  5875. } else {
  5876. if len(keyword) > 0 {
  5877. 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 ?"
  5878. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, keyword)
  5879. } else {
  5880. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? "
  5881. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  5882. }
  5883. }
  5884. }
  5885. }
  5886. }
  5887. } else if patientType == 2 {
  5888. if patient_id > 0 {
  5889. if execution_state > 0 {
  5890. if cost_type > 0 {
  5891. if len(execution_frequency) > 0 {
  5892. if len(keyword) > 0 {
  5893. 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 ?"
  5894. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5895. } else {
  5896. 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 = ?"
  5897. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency)
  5898. }
  5899. } else {
  5900. if len(keyword) > 0 {
  5901. 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 ?"
  5902. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, keyword)
  5903. } else {
  5904. 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 = ?"
  5905. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  5906. }
  5907. }
  5908. } else {
  5909. if len(execution_frequency) > 0 {
  5910. if len(keyword) > 0 {
  5911. 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 ?"
  5912. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency, keyword)
  5913. } else {
  5914. 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 = ?"
  5915. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency)
  5916. }
  5917. } else {
  5918. if len(keyword) > 0 {
  5919. 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 ?"
  5920. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, keyword)
  5921. } else {
  5922. 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 = ?"
  5923. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  5924. }
  5925. }
  5926. }
  5927. } else {
  5928. if cost_type > 0 {
  5929. if len(execution_frequency) > 0 {
  5930. if len(keyword) > 0 {
  5931. 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 ?"
  5932. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency, keyword)
  5933. } else {
  5934. 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 = ?"
  5935. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency)
  5936. }
  5937. } else {
  5938. if len(keyword) > 0 {
  5939. 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 ?"
  5940. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, keyword)
  5941. } else {
  5942. 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 = ?"
  5943. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  5944. }
  5945. }
  5946. } else {
  5947. if len(execution_frequency) > 0 {
  5948. if len(keyword) > 0 {
  5949. 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 ?"
  5950. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency, keyword)
  5951. } else {
  5952. 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 = ?"
  5953. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency)
  5954. }
  5955. } else {
  5956. if len(keyword) > 0 {
  5957. 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 ?"
  5958. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, keyword)
  5959. } else {
  5960. 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 = ?"
  5961. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  5962. }
  5963. }
  5964. }
  5965. }
  5966. } else {
  5967. if execution_state > 0 {
  5968. if cost_type > 0 {
  5969. if len(execution_frequency) > 0 {
  5970. if len(keyword) > 0 {
  5971. 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 ?"
  5972. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency, keyword)
  5973. } else {
  5974. 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 = ?"
  5975. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency)
  5976. }
  5977. } else {
  5978. if len(keyword) > 0 {
  5979. 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 ?"
  5980. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, keyword)
  5981. } else {
  5982. 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 = ?"
  5983. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  5984. }
  5985. }
  5986. } else {
  5987. if len(execution_frequency) > 0 {
  5988. if len(keyword) > 0 {
  5989. 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 ?"
  5990. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency, keyword)
  5991. } else {
  5992. 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 = ?"
  5993. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency)
  5994. }
  5995. } else {
  5996. if len(keyword) > 0 {
  5997. 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 ?"
  5998. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, keyword)
  5999. } else {
  6000. 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 = ?"
  6001. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  6002. }
  6003. }
  6004. }
  6005. } else {
  6006. if cost_type > 0 {
  6007. if len(execution_frequency) > 0 {
  6008. if len(keyword) > 0 {
  6009. 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 ?"
  6010. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, keyword)
  6011. } else {
  6012. 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 = ?"
  6013. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  6014. }
  6015. } else {
  6016. if len(keyword) > 0 {
  6017. 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 ?"
  6018. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, keyword)
  6019. } else {
  6020. 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 = ?"
  6021. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  6022. }
  6023. }
  6024. } else {
  6025. if len(keyword) > 0 {
  6026. 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 ?"
  6027. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, keyword)
  6028. } else {
  6029. 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 = ?"
  6030. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  6031. }
  6032. }
  6033. }
  6034. }
  6035. }
  6036. } else if adviceType == 2 && len(deliverWay) <= 0 {
  6037. if patientType == 0 {
  6038. if patient_id > 0 {
  6039. if execution_state > 0 {
  6040. if cost_type > 0 {
  6041. if len(execution_frequency) > 0 {
  6042. if len(keyword) > 0 {
  6043. 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 ?"
  6044. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  6045. } else {
  6046. 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 = ?"
  6047. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  6048. }
  6049. } else {
  6050. if len(keyword) > 0 {
  6051. 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 ?"
  6052. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  6053. } else {
  6054. 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 = ?"
  6055. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6056. }
  6057. }
  6058. } else {
  6059. if len(execution_frequency) > 0 {
  6060. if len(keyword) > 0 {
  6061. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  6062. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  6063. } else {
  6064. 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 = ?"
  6065. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  6066. }
  6067. } else {
  6068. if len(keyword) > 0 {
  6069. 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 ?"
  6070. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  6071. } else {
  6072. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and execution_state = ?"
  6073. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6074. }
  6075. }
  6076. }
  6077. } else {
  6078. if cost_type > 0 {
  6079. if len(execution_frequency) > 0 {
  6080. if len(keyword) > 0 {
  6081. 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 ?"
  6082. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  6083. } else {
  6084. 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 = ?"
  6085. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  6086. }
  6087. } else {
  6088. if len(keyword) > 0 {
  6089. 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 ?"
  6090. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  6091. } else {
  6092. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and is_settle = ?"
  6093. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6094. }
  6095. }
  6096. } else {
  6097. if len(execution_frequency) > 0 {
  6098. if len(keyword) > 0 {
  6099. 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 ?"
  6100. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  6101. } else {
  6102. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and execution_frequency = ?"
  6103. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  6104. }
  6105. } else {
  6106. if len(keyword) > 0 {
  6107. 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 ?"
  6108. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  6109. } else {
  6110. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ?"
  6111. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6112. }
  6113. }
  6114. }
  6115. }
  6116. } else {
  6117. if execution_state > 0 {
  6118. if cost_type > 0 {
  6119. if len(execution_frequency) > 0 {
  6120. if len(keyword) > 0 {
  6121. 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 ?"
  6122. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  6123. } else {
  6124. 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 = ?"
  6125. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  6126. }
  6127. } else {
  6128. if len(keyword) > 0 {
  6129. 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 ?"
  6130. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  6131. } else {
  6132. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and execution_state = ? and is_settle = ?"
  6133. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6134. }
  6135. }
  6136. } else {
  6137. if len(execution_frequency) > 0 {
  6138. if len(keyword) > 0 {
  6139. 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 ?"
  6140. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  6141. } else {
  6142. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and execution_state = ?and execution_frequency = ?"
  6143. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  6144. }
  6145. } else {
  6146. if len(keyword) > 0 {
  6147. 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 ?"
  6148. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  6149. } else {
  6150. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and execution_state = ?"
  6151. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6152. }
  6153. }
  6154. }
  6155. } else {
  6156. if cost_type > 0 {
  6157. if len(execution_frequency) > 0 {
  6158. if len(keyword) > 0 {
  6159. 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 ?"
  6160. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  6161. } else {
  6162. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and is_settle = ? and execution_frequency = ?"
  6163. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  6164. }
  6165. }
  6166. } else {
  6167. if len(execution_frequency) > 0 {
  6168. if len(keyword) > 0 {
  6169. 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 ?"
  6170. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  6171. } else {
  6172. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and execution_frequency = ?"
  6173. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  6174. }
  6175. } else {
  6176. if len(keyword) > 0 {
  6177. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and advice_name like ?"
  6178. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  6179. } else {
  6180. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ?"
  6181. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6182. }
  6183. }
  6184. }
  6185. }
  6186. }
  6187. } else if patientType == 1 {
  6188. if patient_id > 0 {
  6189. if execution_state > 0 {
  6190. if cost_type > 0 {
  6191. if len(execution_frequency) > 0 {
  6192. if len(keyword) > 0 {
  6193. 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 ?"
  6194. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  6195. } else {
  6196. 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 = ?"
  6197. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  6198. }
  6199. } else {
  6200. if len(keyword) > 0 {
  6201. 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 ?"
  6202. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, keyword)
  6203. } else {
  6204. 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 = ?"
  6205. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  6206. }
  6207. }
  6208. } else {
  6209. if len(execution_frequency) > 0 {
  6210. if len(keyword) > 0 {
  6211. 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 ?"
  6212. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  6213. } else {
  6214. 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 = ?"
  6215. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  6216. }
  6217. } else {
  6218. if len(keyword) > 0 {
  6219. 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 ?"
  6220. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, keyword)
  6221. } else {
  6222. 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 = ?"
  6223. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  6224. }
  6225. }
  6226. }
  6227. } else {
  6228. if cost_type > 0 {
  6229. if len(execution_frequency) > 0 {
  6230. if len(keyword) > 0 {
  6231. 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 ?"
  6232. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  6233. } else {
  6234. 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 = ?"
  6235. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  6236. }
  6237. } else {
  6238. if len(keyword) > 0 {
  6239. 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 ?"
  6240. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, keyword)
  6241. } else {
  6242. 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 = ?"
  6243. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  6244. }
  6245. }
  6246. } else {
  6247. if len(execution_frequency) > 0 {
  6248. if len(keyword) > 0 {
  6249. 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 ?"
  6250. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency, keyword)
  6251. } else {
  6252. 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 = ?"
  6253. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  6254. }
  6255. } else {
  6256. if len(keyword) > 0 {
  6257. 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 ?"
  6258. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, keyword)
  6259. } else {
  6260. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ?"
  6261. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  6262. }
  6263. }
  6264. }
  6265. }
  6266. } else {
  6267. if execution_state > 0 {
  6268. if cost_type > 0 {
  6269. if len(execution_frequency) > 0 {
  6270. if len(keyword) > 0 {
  6271. 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 ?"
  6272. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  6273. } else {
  6274. 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 = ?"
  6275. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  6276. }
  6277. } else {
  6278. if len(keyword) > 0 {
  6279. 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 ?"
  6280. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, keyword)
  6281. } else {
  6282. 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 = ?"
  6283. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  6284. }
  6285. }
  6286. } else {
  6287. if len(execution_frequency) > 0 {
  6288. if len(keyword) > 0 {
  6289. 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 ?"
  6290. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency, keyword)
  6291. } else {
  6292. 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 = ?"
  6293. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  6294. }
  6295. } else {
  6296. if len(keyword) > 0 {
  6297. 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 ?"
  6298. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, keyword)
  6299. } else {
  6300. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and execution_state = ?"
  6301. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  6302. }
  6303. }
  6304. }
  6305. } else {
  6306. if cost_type > 0 {
  6307. if len(execution_frequency) > 0 {
  6308. if len(keyword) > 0 {
  6309. 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 ?"
  6310. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency, keyword)
  6311. } else {
  6312. 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 = ?"
  6313. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  6314. }
  6315. } else {
  6316. if len(keyword) > 0 {
  6317. 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 ?"
  6318. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, keyword)
  6319. } else {
  6320. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and is_settle = ?"
  6321. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  6322. }
  6323. }
  6324. } else {
  6325. if len(execution_frequency) > 0 {
  6326. if len(keyword) > 0 {
  6327. 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 ?"
  6328. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency, keyword)
  6329. } else {
  6330. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and execution_frequency = ?"
  6331. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  6332. }
  6333. } else {
  6334. if len(keyword) > 0 {
  6335. 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 ?"
  6336. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, keyword)
  6337. } else {
  6338. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ?"
  6339. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  6340. }
  6341. }
  6342. }
  6343. }
  6344. }
  6345. } else if patientType == 2 {
  6346. if patient_id > 0 {
  6347. if execution_state > 0 {
  6348. if cost_type > 0 {
  6349. if len(execution_frequency) > 0 {
  6350. if len(keyword) > 0 {
  6351. 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 ?"
  6352. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  6353. } else {
  6354. 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=?"
  6355. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  6356. }
  6357. } else {
  6358. if len(keyword) > 0 {
  6359. 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 ?"
  6360. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  6361. } else {
  6362. 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 = ?"
  6363. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6364. }
  6365. }
  6366. } else {
  6367. if len(execution_frequency) > 0 {
  6368. if len(keyword) > 0 {
  6369. 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 ?"
  6370. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  6371. } else {
  6372. 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=?"
  6373. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  6374. }
  6375. } else {
  6376. if len(keyword) > 0 {
  6377. 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 ?"
  6378. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  6379. } else {
  6380. 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 = ?"
  6381. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6382. }
  6383. }
  6384. }
  6385. } else {
  6386. if cost_type > 0 {
  6387. if len(execution_frequency) > 0 {
  6388. if len(keyword) > 0 {
  6389. 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 ?"
  6390. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  6391. } else {
  6392. 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=?"
  6393. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  6394. }
  6395. } else {
  6396. if len(keyword) > 0 {
  6397. 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 ?"
  6398. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  6399. } else {
  6400. 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 = ?"
  6401. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6402. }
  6403. }
  6404. } else {
  6405. if len(execution_frequency) > 0 {
  6406. if len(keyword) > 0 {
  6407. 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 ?"
  6408. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  6409. } else {
  6410. 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=?"
  6411. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  6412. }
  6413. } else {
  6414. if len(keyword) > 0 {
  6415. 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 ?"
  6416. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  6417. } else {
  6418. 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 = ?"
  6419. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6420. }
  6421. }
  6422. }
  6423. }
  6424. } else {
  6425. if execution_state > 0 {
  6426. if cost_type > 0 {
  6427. if len(execution_frequency) > 0 {
  6428. if len(keyword) > 0 {
  6429. 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 ?"
  6430. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  6431. } else {
  6432. 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 = ?"
  6433. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  6434. }
  6435. } else {
  6436. if len(keyword) > 0 {
  6437. 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 ?"
  6438. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  6439. } else {
  6440. 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 = ?"
  6441. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6442. }
  6443. }
  6444. } else {
  6445. if len(execution_frequency) > 0 {
  6446. if len(keyword) > 0 {
  6447. 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 ?"
  6448. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  6449. } else {
  6450. 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 = ? "
  6451. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  6452. }
  6453. } else {
  6454. if len(keyword) > 0 {
  6455. 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 ?"
  6456. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  6457. } else {
  6458. 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 = ?"
  6459. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6460. }
  6461. }
  6462. }
  6463. } else {
  6464. if cost_type > 0 {
  6465. if len(execution_frequency) > 0 {
  6466. if len(keyword) > 0 {
  6467. 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 ?"
  6468. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  6469. } else {
  6470. 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 = ?"
  6471. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  6472. }
  6473. } else {
  6474. if len(keyword) > 0 {
  6475. 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 ?"
  6476. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  6477. } else {
  6478. 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 = ?"
  6479. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6480. }
  6481. }
  6482. } else {
  6483. if len(execution_frequency) > 0 {
  6484. if len(keyword) > 0 {
  6485. 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 ?"
  6486. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  6487. } else {
  6488. 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 = ?"
  6489. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  6490. }
  6491. } else {
  6492. if len(keyword) > 0 {
  6493. 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 ?"
  6494. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  6495. } else {
  6496. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0"
  6497. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6498. }
  6499. }
  6500. }
  6501. }
  6502. }
  6503. }
  6504. }
  6505. db := readDb.Table("xt_schedule")
  6506. if scheduleType > 0 {
  6507. db = db.Where("schedule_type = ?", scheduleType)
  6508. }
  6509. if partitonType > 0 {
  6510. db = db.Where("partition_id = ?", partitonType)
  6511. }
  6512. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6513. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6514. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6515. }).
  6516. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6517. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6518. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6519. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6520. Preload("DoctorAdvices", adviceCondition...).
  6521. Where("status = 1 AND user_org_id = ?", orgID)
  6522. if scheduleDate != 0 {
  6523. db = db.Where("schedule_date = ?", scheduleDate)
  6524. }
  6525. err := db.Find(&vms).Error
  6526. return vms, err
  6527. }
  6528. 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) {
  6529. var vms []*MScheduleDoctorAdviceVM
  6530. adviceWhere := ""
  6531. adviceCondition := []interface{}{}
  6532. if adviceType == 0 {
  6533. if patientType == 0 {
  6534. if patient_id > 0 {
  6535. if execution_state > 0 {
  6536. if cost_type > 0 {
  6537. 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 = ?"
  6538. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6539. } else {
  6540. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  6541. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6542. }
  6543. } else {
  6544. if cost_type > 0 {
  6545. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and is_settle = ?"
  6546. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6547. } else {
  6548. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
  6549. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6550. }
  6551. }
  6552. } else {
  6553. if execution_state > 0 {
  6554. if cost_type > 0 {
  6555. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and is_settle = ?"
  6556. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6557. } else {
  6558. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ?"
  6559. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6560. }
  6561. } else {
  6562. if cost_type > 0 {
  6563. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ?"
  6564. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6565. } else {
  6566. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  6567. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6568. }
  6569. }
  6570. }
  6571. } else if patientType == 1 {
  6572. if patient_id > 0 {
  6573. if execution_state > 0 {
  6574. if cost_type > 0 {
  6575. 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 = ?"
  6576. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  6577. } else {
  6578. 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= ?"
  6579. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  6580. }
  6581. } else {
  6582. if cost_type > 0 {
  6583. 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=?"
  6584. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  6585. } else {
  6586. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
  6587. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  6588. }
  6589. }
  6590. } else {
  6591. if execution_state > 0 {
  6592. if cost_type > 0 {
  6593. 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=?"
  6594. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  6595. } else {
  6596. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  6597. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  6598. }
  6599. } else {
  6600. if cost_type > 0 {
  6601. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and is_settle=?"
  6602. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  6603. } else {
  6604. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  6605. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  6606. }
  6607. }
  6608. }
  6609. } else if patientType == 2 {
  6610. if patient_id > 0 {
  6611. if execution_state > 0 {
  6612. if cost_type > 0 {
  6613. 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=?"
  6614. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6615. } else {
  6616. 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 = ?"
  6617. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6618. }
  6619. } else {
  6620. if cost_type > 0 {
  6621. 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=?"
  6622. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6623. } else {
  6624. 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 = ?)"
  6625. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6626. }
  6627. }
  6628. } else {
  6629. if execution_state > 0 {
  6630. if cost_type > 0 {
  6631. 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=?"
  6632. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6633. } else {
  6634. 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 = ?"
  6635. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6636. }
  6637. } else {
  6638. if cost_type > 0 {
  6639. 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 = ?"
  6640. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6641. } else {
  6642. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  6643. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6644. }
  6645. }
  6646. }
  6647. }
  6648. } else if adviceType == 1 {
  6649. if patientType == 0 {
  6650. if patient_id > 0 {
  6651. if execution_state > 0 {
  6652. if cost_type > 0 {
  6653. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  6654. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6655. } else {
  6656. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ?"
  6657. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6658. }
  6659. } else {
  6660. if cost_type > 0 {
  6661. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? "
  6662. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6663. } else {
  6664. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
  6665. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6666. }
  6667. }
  6668. } else {
  6669. if execution_state > 0 {
  6670. if cost_type > 0 {
  6671. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ?"
  6672. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6673. } else {
  6674. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ?"
  6675. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6676. }
  6677. } else {
  6678. if cost_type > 0 {
  6679. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = ? "
  6680. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6681. } else {
  6682. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  6683. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6684. }
  6685. }
  6686. }
  6687. } else if patientType == 1 {
  6688. if patient_id > 0 {
  6689. if execution_state > 0 {
  6690. if cost_type > 0 {
  6691. 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 = ?"
  6692. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  6693. } else {
  6694. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  6695. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  6696. }
  6697. } else {
  6698. if cost_type > 0 {
  6699. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  6700. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  6701. } else {
  6702. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
  6703. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  6704. }
  6705. }
  6706. } else {
  6707. if execution_state > 0 {
  6708. if cost_type > 0 {
  6709. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=? and is_settle = ?"
  6710. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  6711. } else {
  6712. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?"
  6713. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  6714. }
  6715. } else {
  6716. if cost_type > 0 {
  6717. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? "
  6718. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  6719. } else {
  6720. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  6721. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  6722. }
  6723. }
  6724. }
  6725. } else if patientType == 2 {
  6726. if patient_id > 0 {
  6727. if execution_state > 0 {
  6728. if cost_type > 0 {
  6729. 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 = ?"
  6730. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6731. } else {
  6732. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  6733. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6734. }
  6735. } else {
  6736. if cost_type > 0 {
  6737. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  6738. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6739. } else {
  6740. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
  6741. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6742. }
  6743. }
  6744. } else {
  6745. if execution_state > 0 {
  6746. if cost_type > 0 {
  6747. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  6748. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6749. } else {
  6750. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ?"
  6751. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6752. }
  6753. } else {
  6754. if cost_type > 0 {
  6755. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ?"
  6756. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6757. } else {
  6758. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  6759. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6760. }
  6761. }
  6762. }
  6763. }
  6764. } else if adviceType == 3 {
  6765. if patientType == 0 {
  6766. if patient_id > 0 {
  6767. if execution_state > 0 {
  6768. if cost_type > 0 {
  6769. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  6770. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6771. } else {
  6772. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ?"
  6773. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6774. }
  6775. } else {
  6776. if cost_type > 0 {
  6777. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? "
  6778. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6779. } else {
  6780. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? "
  6781. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6782. }
  6783. }
  6784. } else {
  6785. if execution_state > 0 {
  6786. if cost_type > 0 {
  6787. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ?"
  6788. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6789. } else {
  6790. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? "
  6791. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6792. }
  6793. } else {
  6794. if cost_type > 0 {
  6795. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? "
  6796. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6797. } else {
  6798. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  6799. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6800. }
  6801. }
  6802. }
  6803. } else if patientType == 1 {
  6804. if patient_id > 0 {
  6805. if execution_state > 0 {
  6806. if cost_type > 0 {
  6807. 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 = ?"
  6808. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  6809. } else {
  6810. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  6811. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  6812. }
  6813. } else {
  6814. if cost_type > 0 {
  6815. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  6816. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  6817. } else {
  6818. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
  6819. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  6820. }
  6821. }
  6822. } else {
  6823. if execution_state > 0 {
  6824. if cost_type > 0 {
  6825. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? and is_settle = ?"
  6826. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  6827. } else {
  6828. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? "
  6829. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  6830. }
  6831. } else {
  6832. if cost_type > 0 {
  6833. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ?"
  6834. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  6835. } else {
  6836. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  6837. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  6838. }
  6839. }
  6840. }
  6841. } else if patientType == 2 {
  6842. if patient_id > 0 {
  6843. if execution_state > 0 {
  6844. if cost_type > 0 {
  6845. 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 = ?"
  6846. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6847. } else {
  6848. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  6849. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6850. }
  6851. } else {
  6852. if cost_type > 0 {
  6853. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  6854. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6855. } else {
  6856. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ?"
  6857. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6858. }
  6859. }
  6860. } else {
  6861. if execution_state > 0 {
  6862. if cost_type > 0 {
  6863. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and is_settle = ?"
  6864. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6865. } else {
  6866. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ?"
  6867. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6868. }
  6869. } else {
  6870. if cost_type > 0 {
  6871. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ?"
  6872. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6873. } else {
  6874. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  6875. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6876. }
  6877. }
  6878. }
  6879. }
  6880. } else if adviceType == 2 && len(deliverWay) > 0 {
  6881. if patientType == 0 {
  6882. if patient_id > 0 {
  6883. if execution_state > 0 {
  6884. if cost_type > 0 {
  6885. 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 = ?"
  6886. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  6887. } else {
  6888. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  6889. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  6890. }
  6891. } else {
  6892. if cost_type > 0 {
  6893. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and is_settle = ?"
  6894. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  6895. } else {
  6896. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ?"
  6897. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  6898. }
  6899. }
  6900. } else {
  6901. if execution_state > 0 {
  6902. if cost_type > 0 {
  6903. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and is_settle = ?"
  6904. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  6905. } else {
  6906. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ?"
  6907. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  6908. }
  6909. } else {
  6910. if cost_type > 0 {
  6911. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and is_settle = ?"
  6912. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  6913. } else {
  6914. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  6915. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  6916. }
  6917. }
  6918. }
  6919. } else if patientType == 1 {
  6920. if patient_id > 0 {
  6921. if execution_state > 0 {
  6922. if cost_type > 0 {
  6923. 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 = ?"
  6924. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type)
  6925. } else {
  6926. 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 = ?"
  6927. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state)
  6928. }
  6929. } else {
  6930. if cost_type > 0 {
  6931. 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 = ?"
  6932. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type)
  6933. } else {
  6934. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ?"
  6935. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
  6936. }
  6937. }
  6938. } else {
  6939. if execution_state > 0 {
  6940. if cost_type > 0 {
  6941. 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 = ?"
  6942. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type)
  6943. } else {
  6944. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ?"
  6945. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state)
  6946. }
  6947. } else {
  6948. if cost_type > 0 {
  6949. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and is_settle = ?"
  6950. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type)
  6951. } else {
  6952. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  6953. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  6954. }
  6955. }
  6956. }
  6957. } else if patientType == 2 {
  6958. if patient_id > 0 {
  6959. if execution_state > 0 {
  6960. if cost_type > 0 {
  6961. 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 = ?"
  6962. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  6963. } else {
  6964. 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 = ?"
  6965. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  6966. }
  6967. } else {
  6968. if cost_type > 0 {
  6969. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and is_settle = ?"
  6970. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  6971. } else {
  6972. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ?"
  6973. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  6974. }
  6975. }
  6976. } else {
  6977. if execution_state > 0 {
  6978. if cost_type > 0 {
  6979. 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 = ?"
  6980. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  6981. } else {
  6982. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ?"
  6983. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  6984. }
  6985. } else {
  6986. if cost_type > 0 {
  6987. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and is_settle = ?"
  6988. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  6989. } else {
  6990. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  6991. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  6992. }
  6993. }
  6994. }
  6995. }
  6996. } else if adviceType == 2 && len(deliverWay) <= 0 {
  6997. if patientType == 0 {
  6998. if patient_id > 0 {
  6999. if execution_state > 0 {
  7000. if cost_type > 0 {
  7001. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  7002. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  7003. } else {
  7004. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ?"
  7005. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  7006. }
  7007. } else {
  7008. if cost_type > 0 {
  7009. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and is_settle = ?"
  7010. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  7011. } else {
  7012. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ?"
  7013. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  7014. }
  7015. }
  7016. } else {
  7017. if execution_state > 0 {
  7018. if cost_type > 0 {
  7019. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ? and is_settle = ?"
  7020. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  7021. } else {
  7022. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?"
  7023. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  7024. }
  7025. } else {
  7026. if cost_type > 0 {
  7027. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and is_settle = ?"
  7028. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  7029. } else {
  7030. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  7031. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  7032. }
  7033. }
  7034. }
  7035. } else if patientType == 1 {
  7036. if patient_id > 0 {
  7037. if execution_state > 0 {
  7038. if cost_type > 0 {
  7039. 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 = ?"
  7040. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  7041. } else {
  7042. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  7043. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  7044. }
  7045. } else {
  7046. if cost_type > 0 {
  7047. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  7048. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  7049. } else {
  7050. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ?"
  7051. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  7052. }
  7053. }
  7054. } else {
  7055. if execution_state > 0 {
  7056. if cost_type > 0 {
  7057. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ? and is_settle = ?"
  7058. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  7059. } else {
  7060. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ?"
  7061. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  7062. }
  7063. } else {
  7064. if cost_type > 0 {
  7065. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and is_settle = ?"
  7066. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  7067. } else {
  7068. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?"
  7069. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  7070. }
  7071. }
  7072. }
  7073. } else if patientType == 2 {
  7074. if patient_id > 0 {
  7075. if execution_state > 0 {
  7076. if cost_type > 0 {
  7077. 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 = ?"
  7078. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  7079. } else {
  7080. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  7081. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  7082. }
  7083. } else {
  7084. if cost_type > 0 {
  7085. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  7086. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  7087. } else {
  7088. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ?"
  7089. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  7090. }
  7091. }
  7092. } else {
  7093. if execution_state > 0 {
  7094. if cost_type > 0 {
  7095. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  7096. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  7097. } else {
  7098. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ?"
  7099. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  7100. }
  7101. } else {
  7102. if cost_type > 0 {
  7103. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and is_settle = ?"
  7104. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  7105. } else {
  7106. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  7107. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  7108. }
  7109. }
  7110. }
  7111. }
  7112. }
  7113. db := readDb.Table("xt_schedule")
  7114. if scheduleType > 0 {
  7115. db = db.Where("schedule_type = ?", scheduleType)
  7116. }
  7117. if partitonType > 0 {
  7118. db = db.Where("partition_id = ?", partitonType)
  7119. }
  7120. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7121. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7122. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7123. }).
  7124. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7125. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7126. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7127. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7128. Preload("DoctorAdvices", adviceCondition...).
  7129. Where("status = 1 AND user_org_id = ?", orgID)
  7130. if scheduleDate != 0 {
  7131. db = db.Where("schedule_date = ?", scheduleDate)
  7132. }
  7133. err := db.Find(&vms).Error
  7134. return vms, err
  7135. }
  7136. func GetLastPatientOrder(id int64) (models.XtDialysisOrder, error) {
  7137. order := models.XtDialysisOrder{}
  7138. err := XTReadDB().Where("id = ? and status = 1", id).Find(&order).Error
  7139. return order, err
  7140. }
  7141. func UpdateMobilePatient(org_id int64, patient_id int64, schedule_remark string) error {
  7142. order := models.XtPatients{}
  7143. 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
  7144. 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
  7145. return err
  7146. }
  7147. func GetDialysisTotalCount(org_id int64, patient_id int64) (models.BloodDialysisOrderCount, error) {
  7148. order := models.BloodDialysisOrderCount{}
  7149. db := XTReadDB().Table("xt_dialysis_order as o")
  7150. 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
  7151. return order, err
  7152. }
  7153. func GetDialysisTotalCountOne(org_id int64, patient_id int64) (models.BloodDialysisOrderCount, error) {
  7154. order := models.BloodDialysisOrderCount{}
  7155. db := XTReadDB().Table("xt_dialysis_order as o")
  7156. 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>=1735660800 and x.schedule_date = o.dialysis_date and x.status = 1 ", org_id, patient_id).Scan(&order).Error
  7157. return order, err
  7158. }
  7159. func UpdateDialysisOrder(patient_id int64, dialysis_date int64, user_org_id int64, dialysis_total int64) (models.DialysisOrder, error) {
  7160. order := models.DialysisOrder{}
  7161. 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
  7162. return order, err
  7163. }
  7164. func UpdateDeviceInformation(patientid int64, dialysis_date int64) error {
  7165. information := models.DeviceInformation{}
  7166. err := UserWriteDB().Model(&information).Where("patient_id = ? and date = ? and status = 1", patientid, dialysis_date).Update(map[string]interface{}{"status": 0}).Error
  7167. return err
  7168. }
  7169. func MobileGetDoubleCheckSix(orgID int64, patientID int64, recordDate int64) (models.DoubleCheck, error) {
  7170. var record models.DoubleCheck
  7171. err := readDb.Where("patient_id = ? and user_org_id = ? and status = 1 and check_date = ?", patientID, orgID, recordDate).First(&record).Error
  7172. return record, err
  7173. }
  7174. func GetFirstMonitor(patient_id int64, monit_date int64) (models.MonitoringRecord, error) {
  7175. record := models.MonitoringRecord{}
  7176. err := XTReadDB().Where("patient_id = ? and monitoring_date = ? and status=1", patient_id, monit_date).First(&record).Error
  7177. return record, err
  7178. }
  7179. func GetFirstMonitorOne(patient_id int64, monit_date int64, org_id int64) (models.MonitoringRecord, error) {
  7180. record := models.MonitoringRecord{}
  7181. err := XTReadDB().Where("patient_id = ? and monitoring_date = ? and status=1 and user_org_id=?", patient_id, monit_date, org_id).First(&record).Error
  7182. return record, err
  7183. }
  7184. func GetLastMonitor(patient_id int64, monit_date int64, org_id int64) (models.MonitoringRecord, error) {
  7185. record := models.MonitoringRecord{}
  7186. err := XTReadDB().Where("patient_id = ? and monitoring_date = ? and status=1 and user_org_id = ?", patient_id, monit_date, org_id).Last(&record).Error
  7187. return record, err
  7188. }
  7189. func UpdateFirstMonitor(id int64, catheter_operation string) (models.MonitoringRecord, error) {
  7190. record := models.MonitoringRecord{}
  7191. err := XTWriteDB().Model(&record).Where("id = ? and status= 1", id).Updates(map[string]interface{}{"dispose": catheter_operation}).Error
  7192. return record, err
  7193. }
  7194. 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) {
  7195. var vms []*HisMScheduleDoctorAdviceVM
  7196. if len(deliverWay) > 0 {
  7197. db := readDb.Table("xt_schedule")
  7198. if scheduleType > 0 {
  7199. db = db.Where("schedule_type = ?", scheduleType)
  7200. }
  7201. if partitionType > 0 {
  7202. db = db.Where("partition_id = ?", partitionType)
  7203. }
  7204. if patient_id > 0 {
  7205. if execution_state > 0 {
  7206. if cost_type > 0 {
  7207. if len(execution_frequency) > 0 {
  7208. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7209. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7210. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7211. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7212. 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).
  7213. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7214. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7215. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7216. Where("status = 1 AND user_org_id = ?", orgID)
  7217. if scheduleDate != 0 {
  7218. db = db.Where("schedule_date = ?", scheduleDate)
  7219. }
  7220. err = db.Find(&vms).Error
  7221. } else {
  7222. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7223. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7224. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7225. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7226. 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).
  7227. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7228. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7229. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7230. Where("status = 1 AND user_org_id = ?", orgID)
  7231. if scheduleDate != 0 {
  7232. db = db.Where("schedule_date = ?", scheduleDate)
  7233. }
  7234. err = db.Find(&vms).Error
  7235. }
  7236. } else {
  7237. if len(execution_frequency) > 0 {
  7238. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7239. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7240. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7241. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7242. 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).
  7243. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7244. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7245. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7246. Where("status = 1 AND user_org_id = ?", orgID)
  7247. if scheduleDate != 0 {
  7248. db = db.Where("schedule_date = ?", scheduleDate)
  7249. }
  7250. err = db.Find(&vms).Error
  7251. } else {
  7252. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7253. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7254. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7255. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7256. 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).
  7257. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7258. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7259. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7260. Where("status = 1 AND user_org_id = ?", orgID)
  7261. if scheduleDate != 0 {
  7262. db = db.Where("schedule_date = ?", scheduleDate)
  7263. }
  7264. err = db.Find(&vms).Error
  7265. }
  7266. }
  7267. } else {
  7268. if cost_type > 0 {
  7269. if len(execution_frequency) > 0 {
  7270. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7271. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7272. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7273. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7274. 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).
  7275. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7276. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7277. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7278. Where("status = 1 AND user_org_id = ?", orgID)
  7279. if scheduleDate != 0 {
  7280. db = db.Where("schedule_date = ?", scheduleDate)
  7281. }
  7282. err = db.Find(&vms).Error
  7283. } else {
  7284. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7285. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7286. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7287. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7288. 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).
  7289. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7290. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7291. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7292. Where("status = 1 AND user_org_id = ?", orgID)
  7293. if scheduleDate != 0 {
  7294. db = db.Where("schedule_date = ?", scheduleDate)
  7295. }
  7296. err = db.Find(&vms).Error
  7297. }
  7298. } else {
  7299. if len(execution_frequency) > 0 {
  7300. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7301. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7302. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7303. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7304. 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).
  7305. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7306. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7307. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7308. Where("status = 1 AND user_org_id = ?", orgID)
  7309. if scheduleDate != 0 {
  7310. db = db.Where("schedule_date = ?", scheduleDate)
  7311. }
  7312. err = db.Find(&vms).Error
  7313. } else {
  7314. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7315. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7316. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7317. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7318. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ?", orgID, scheduleDate, deliverWay, patient_id).
  7319. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7320. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7321. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7322. Where("status = 1 AND user_org_id = ?", orgID)
  7323. if scheduleDate != 0 {
  7324. db = db.Where("schedule_date = ?", scheduleDate)
  7325. }
  7326. err = db.Find(&vms).Error
  7327. }
  7328. }
  7329. }
  7330. } else {
  7331. if execution_state > 0 {
  7332. if cost_type > 0 {
  7333. if len(execution_frequency) > 0 {
  7334. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7335. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7336. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7337. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7338. 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).
  7339. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7340. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7341. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7342. Where("status = 1 AND user_org_id = ?", orgID)
  7343. if scheduleDate != 0 {
  7344. db = db.Where("schedule_date = ?", scheduleDate)
  7345. }
  7346. err = db.Find(&vms).Error
  7347. } else {
  7348. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7349. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7350. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7351. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7352. 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).
  7353. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7354. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7355. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7356. Where("status = 1 AND user_org_id = ?", orgID)
  7357. if scheduleDate != 0 {
  7358. db = db.Where("schedule_date = ?", scheduleDate)
  7359. }
  7360. err = db.Find(&vms).Error
  7361. }
  7362. } else {
  7363. if len(execution_frequency) > 0 {
  7364. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7365. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7366. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7367. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7368. 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).
  7369. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7370. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7371. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7372. Where("status = 1 AND user_org_id = ?", orgID)
  7373. if scheduleDate != 0 {
  7374. db = db.Where("schedule_date = ?", scheduleDate)
  7375. }
  7376. err = db.Find(&vms).Error
  7377. } else {
  7378. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7379. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7380. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7381. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7382. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_state = ?", orgID, scheduleDate, deliverWay, execution_state).
  7383. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7384. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7385. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7386. Where("status = 1 AND user_org_id = ?", orgID)
  7387. if scheduleDate != 0 {
  7388. db = db.Where("schedule_date = ?", scheduleDate)
  7389. }
  7390. err = db.Find(&vms).Error
  7391. }
  7392. }
  7393. } else {
  7394. if cost_type > 0 {
  7395. if len(execution_frequency) > 0 {
  7396. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7397. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7398. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7399. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7400. 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).
  7401. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7402. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7403. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7404. Where("status = 1 AND user_org_id = ?", orgID)
  7405. if scheduleDate != 0 {
  7406. db = db.Where("schedule_date = ?", scheduleDate)
  7407. }
  7408. err = db.Find(&vms).Error
  7409. } else {
  7410. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7411. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7412. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7413. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7414. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and is_settle = ?", orgID, scheduleDate, deliverWay, cost_type).
  7415. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7416. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7417. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7418. Where("status = 1 AND user_org_id = ?", orgID)
  7419. if scheduleDate != 0 {
  7420. db = db.Where("schedule_date = ?", scheduleDate)
  7421. }
  7422. err = db.Find(&vms).Error
  7423. }
  7424. } else {
  7425. if len(execution_frequency) > 0 {
  7426. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7427. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7428. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7429. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7430. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_frequency = ?", orgID, scheduleDate, deliverWay, execution_frequency).
  7431. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7432. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7433. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7434. Where("status = 1 AND user_org_id = ?", orgID)
  7435. if scheduleDate != 0 {
  7436. db = db.Where("schedule_date = ?", scheduleDate)
  7437. }
  7438. err = db.Find(&vms).Error
  7439. } else {
  7440. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7441. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7442. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7443. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7444. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  7445. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7446. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7447. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7448. Where("status = 1 AND user_org_id = ?", orgID)
  7449. if scheduleDate != 0 {
  7450. db = db.Where("schedule_date = ?", scheduleDate)
  7451. }
  7452. err = db.Find(&vms).Error
  7453. }
  7454. }
  7455. }
  7456. }
  7457. } else {
  7458. db := readDb.Table("xt_schedule")
  7459. if scheduleType > 0 {
  7460. db = db.Where("schedule_type = ?", scheduleType)
  7461. }
  7462. if partitionType > 0 {
  7463. db = db.Where("partition_id = ?", partitionType)
  7464. }
  7465. if patient_id > 0 {
  7466. if execution_state > 0 {
  7467. fmt.Println("execution_state---------------------", execution_state)
  7468. if cost_type > 0 {
  7469. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7470. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7471. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7472. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7473. 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).
  7474. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7475. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7476. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7477. Where("status = 1 AND user_org_id = ?", orgID)
  7478. if scheduleDate != 0 {
  7479. db = db.Where("schedule_date = ?", scheduleDate)
  7480. }
  7481. err = db.Find(&vms).Error
  7482. } else {
  7483. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7484. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7485. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7486. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7487. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and execution_state = ?", orgID, scheduleDate, patient_id, execution_state).
  7488. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7489. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7490. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7491. Where("status = 1 AND user_org_id = ?", orgID)
  7492. if scheduleDate != 0 {
  7493. db = db.Where("schedule_date = ?", scheduleDate)
  7494. }
  7495. err = db.Find(&vms).Error
  7496. }
  7497. } else {
  7498. if cost_type > 0 {
  7499. if len(execution_frequency) > 0 {
  7500. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7501. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7502. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7503. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7504. 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).
  7505. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7506. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7507. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7508. Where("status = 1 AND user_org_id = ?", orgID)
  7509. if scheduleDate != 0 {
  7510. db = db.Where("schedule_date = ?", scheduleDate)
  7511. }
  7512. err = db.Find(&vms).Error
  7513. } else {
  7514. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7515. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7516. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7517. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7518. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and is_settle = ?", orgID, scheduleDate, patient_id, cost_type).
  7519. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7520. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7521. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7522. Where("status = 1 AND user_org_id = ?", orgID)
  7523. if scheduleDate != 0 {
  7524. db = db.Where("schedule_date = ?", scheduleDate)
  7525. }
  7526. err = db.Find(&vms).Error
  7527. }
  7528. } else {
  7529. if len(execution_frequency) > 0 {
  7530. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7531. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7532. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7533. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7534. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and execution_frequency = ?", orgID, scheduleDate, patient_id, execution_frequency).
  7535. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7536. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7537. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7538. Where("status = 1 AND user_org_id = ?", orgID)
  7539. if scheduleDate != 0 {
  7540. db = db.Where("schedule_date = ?", scheduleDate)
  7541. }
  7542. err = db.Find(&vms).Error
  7543. } else {
  7544. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7545. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7546. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7547. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7548. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7549. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7550. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7551. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7552. Where("status = 1 AND user_org_id = ?", orgID)
  7553. if scheduleDate != 0 {
  7554. db = db.Where("schedule_date = ?", scheduleDate)
  7555. }
  7556. err = db.Find(&vms).Error
  7557. }
  7558. }
  7559. }
  7560. } else {
  7561. if execution_state > 0 {
  7562. if cost_type > 0 {
  7563. if len(execution_frequency) > 0 {
  7564. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7565. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7566. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7567. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7568. 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).
  7569. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7570. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7571. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7572. Where("status = 1 AND user_org_id = ?", orgID)
  7573. if scheduleDate != 0 {
  7574. db = db.Where("schedule_date = ?", scheduleDate)
  7575. }
  7576. err = db.Find(&vms).Error
  7577. } else {
  7578. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7579. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7580. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7581. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7582. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ? and is_settle = ?", orgID, scheduleDate, execution_state, cost_type).
  7583. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7584. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7585. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7586. Where("status = 1 AND user_org_id = ?", orgID)
  7587. if scheduleDate != 0 {
  7588. db = db.Where("schedule_date = ?", scheduleDate)
  7589. }
  7590. err = db.Find(&vms).Error
  7591. }
  7592. } else {
  7593. if len(execution_frequency) > 0 {
  7594. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7595. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7596. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7597. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7598. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ? and execution_frequency = ?", orgID, scheduleDate, execution_state, execution_frequency).
  7599. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7600. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7601. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7602. Where("status = 1 AND user_org_id = ?", orgID)
  7603. if scheduleDate != 0 {
  7604. db = db.Where("schedule_date = ?", scheduleDate)
  7605. }
  7606. err = db.Find(&vms).Error
  7607. } else {
  7608. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7609. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7610. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7611. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7612. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ?", orgID, scheduleDate, execution_state).
  7613. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7614. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7615. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7616. Where("status = 1 AND user_org_id = ?", orgID)
  7617. if scheduleDate != 0 {
  7618. db = db.Where("schedule_date = ?", scheduleDate)
  7619. }
  7620. err = db.Find(&vms).Error
  7621. }
  7622. }
  7623. } else {
  7624. if cost_type > 0 {
  7625. if len(execution_frequency) > 0 {
  7626. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7627. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7628. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7629. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7630. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and is_settle = ?", orgID, scheduleDate, cost_type).
  7631. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7632. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7633. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7634. Where("status = 1 AND user_org_id = ?", orgID)
  7635. if scheduleDate != 0 {
  7636. db = db.Where("schedule_date = ?", scheduleDate)
  7637. }
  7638. err = db.Find(&vms).Error
  7639. } else {
  7640. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7641. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7642. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7643. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7644. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and is_settle = ? and execution_frequency = ?", orgID, scheduleDate, cost_type, execution_frequency).
  7645. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7646. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7647. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7648. Where("status = 1 AND user_org_id = ?", orgID)
  7649. if scheduleDate != 0 {
  7650. db = db.Where("schedule_date = ?", scheduleDate)
  7651. }
  7652. err = db.Find(&vms).Error
  7653. }
  7654. } else {
  7655. if len(execution_frequency) > 0 {
  7656. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7657. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7658. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7659. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7660. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_frequency = ?", orgID, scheduleDate, execution_frequency).
  7661. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7662. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7663. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7664. Where("status = 1 AND user_org_id = ?", orgID)
  7665. if scheduleDate != 0 {
  7666. db = db.Where("schedule_date = ?", scheduleDate)
  7667. }
  7668. err = db.Find(&vms).Error
  7669. } else {
  7670. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7671. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7672. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7673. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7674. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ?", orgID, scheduleDate).
  7675. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7676. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7677. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7678. Where("status = 1 AND user_org_id = ?", orgID)
  7679. if scheduleDate != 0 {
  7680. db = db.Where("schedule_date = ?", scheduleDate)
  7681. }
  7682. err = db.Find(&vms).Error
  7683. }
  7684. }
  7685. }
  7686. }
  7687. }
  7688. return vms, err
  7689. }
  7690. func GetPatientDryWeight(org_id int64, patient_id int64) (weight []*models.SgjPatientDryweight, err error) {
  7691. err = XTReadDB().Where("user_org_id = ? and patient_id = ? and status =1", org_id, patient_id).Order("id desc").Limit(6).Find(&weight).Error
  7692. return weight, err
  7693. }
  7694. 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) {
  7695. fmt.Println("deliverWay-----------------", deliverWay)
  7696. fmt.Println("execution_frequency------------------", execution_frequency)
  7697. fmt.Println("adviceType-----------------", adviceType)
  7698. fmt.Println("patientType----------------", patientType)
  7699. fmt.Println("patient_id----------------", patient_id)
  7700. fmt.Println("execution_state----------------", execution_state)
  7701. fmt.Println("cost_type---------------------", cost_type)
  7702. fmt.Println("execution_frequency", execution_frequency)
  7703. var vms []*MScheduleDoctorAdviceVM
  7704. adviceWhere := ""
  7705. keyword = "%" + keyword + "%"
  7706. adviceCondition := []interface{}{}
  7707. if adviceType == 1 {
  7708. if patientType == 0 {
  7709. if patient_id > 0 {
  7710. if execution_state > 0 {
  7711. if cost_type > 0 {
  7712. if len(execution_frequency) > 0 {
  7713. if len(keyword) > 0 {
  7714. if len(deliverWay) > 0 {
  7715. 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 ?"
  7716. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency, deliverWay, keyword)
  7717. } else {
  7718. 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 ?"
  7719. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency, keyword)
  7720. }
  7721. } else {
  7722. if len(deliverWay) > 0 {
  7723. 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 =?"
  7724. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency, deliverWay)
  7725. } else {
  7726. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  7727. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency)
  7728. }
  7729. }
  7730. } else {
  7731. if len(keyword) > 0 {
  7732. if len(deliverWay) > 0 {
  7733. 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 =?"
  7734. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, keyword, deliverWay)
  7735. } else {
  7736. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  7737. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, keyword)
  7738. }
  7739. } else {
  7740. if len(deliverWay) > 0 {
  7741. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ? and delivery_way =?"
  7742. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, deliverWay)
  7743. } else {
  7744. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ?"
  7745. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type)
  7746. }
  7747. }
  7748. }
  7749. } else {
  7750. if len(execution_frequency) > 0 {
  7751. if len(keyword) > 0 {
  7752. if len(deliverWay) > 0 {
  7753. 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 =?"
  7754. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency, keyword, deliverWay)
  7755. } else {
  7756. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  7757. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency, keyword)
  7758. }
  7759. } else {
  7760. if len(deliverWay) > 0 {
  7761. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and execution_frequency = ? and delivery_way =?"
  7762. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency, deliverWay)
  7763. } else {
  7764. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and execution_frequency = ?"
  7765. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency)
  7766. }
  7767. }
  7768. } else {
  7769. if len(keyword) > 0 {
  7770. if len(deliverWay) > 0 {
  7771. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and advice_name like ? and delivery_way =?"
  7772. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, keyword, deliverWay)
  7773. } else {
  7774. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and advice_name like ?"
  7775. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, keyword)
  7776. }
  7777. } else {
  7778. if len(deliverWay) > 0 {
  7779. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and delivery_way =?"
  7780. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, deliverWay)
  7781. } else {
  7782. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ?"
  7783. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state)
  7784. }
  7785. }
  7786. }
  7787. }
  7788. } else {
  7789. if cost_type > 0 {
  7790. if len(execution_frequency) > 0 {
  7791. if len(keyword) > 0 {
  7792. if len(deliverWay) > 0 {
  7793. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  7794. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency, keyword, deliverWay)
  7795. } else {
  7796. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  7797. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency, keyword)
  7798. }
  7799. } else {
  7800. if len(deliverWay) > 0 {
  7801. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and execution_frequency = ? and delivery_way =?"
  7802. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency, deliverWay)
  7803. } else {
  7804. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and execution_frequency = ?"
  7805. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency)
  7806. }
  7807. }
  7808. } else {
  7809. if len(keyword) > 0 {
  7810. if len(deliverWay) > 0 {
  7811. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and advice_name like ? and delivery_way =?"
  7812. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, keyword, deliverWay)
  7813. } else {
  7814. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and advice_name like ?"
  7815. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, keyword)
  7816. }
  7817. } else {
  7818. if len(deliverWay) > 0 {
  7819. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and delivery_way =?"
  7820. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, deliverWay)
  7821. } else {
  7822. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? "
  7823. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type)
  7824. }
  7825. }
  7826. }
  7827. } else {
  7828. if len(execution_frequency) > 0 {
  7829. if len(keyword) > 0 {
  7830. if len(deliverWay) > 0 {
  7831. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  7832. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency, keyword, deliverWay)
  7833. } else {
  7834. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_frequency = ? and advice_name like ?"
  7835. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency, keyword)
  7836. }
  7837. } else {
  7838. if len(deliverWay) > 0 {
  7839. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_frequency = ? and delivery_way =?"
  7840. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency, deliverWay)
  7841. } else {
  7842. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_frequency = ?"
  7843. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency)
  7844. }
  7845. }
  7846. } else {
  7847. if len(keyword) > 0 {
  7848. if len(deliverWay) > 0 {
  7849. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and advice_name like ? and delivery_way =?"
  7850. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, keyword, deliverWay)
  7851. } else {
  7852. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and advice_name like ?"
  7853. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, keyword)
  7854. }
  7855. } else {
  7856. if len(deliverWay) > 0 {
  7857. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and delivery_way =?"
  7858. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, deliverWay)
  7859. } else {
  7860. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? "
  7861. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id)
  7862. }
  7863. }
  7864. }
  7865. }
  7866. }
  7867. } else {
  7868. if execution_state > 0 {
  7869. if cost_type > 0 {
  7870. if len(execution_frequency) > 0 {
  7871. if len(keyword) > 0 {
  7872. if len(deliverWay) > 0 {
  7873. 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 =?"
  7874. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency, keyword, deliverWay)
  7875. } else {
  7876. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  7877. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency, keyword)
  7878. }
  7879. } else {
  7880. if len(deliverWay) > 0 {
  7881. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and execution_frequency = ? and delivery_way =?"
  7882. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency, deliverWay)
  7883. } else {
  7884. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and execution_frequency = ?"
  7885. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency)
  7886. }
  7887. }
  7888. } else {
  7889. if len(keyword) > 0 {
  7890. if len(deliverWay) > 0 {
  7891. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and advice_name like ? and delivery_way =?"
  7892. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, keyword, deliverWay)
  7893. } else {
  7894. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and advice_name like ?"
  7895. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, keyword)
  7896. }
  7897. } else {
  7898. if len(deliverWay) > 0 {
  7899. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and delivery_way =?"
  7900. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, deliverWay)
  7901. } else {
  7902. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ?"
  7903. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type)
  7904. }
  7905. }
  7906. }
  7907. } else {
  7908. if len(execution_frequency) > 0 {
  7909. if len(keyword) > 0 {
  7910. if len(deliverWay) > 0 {
  7911. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  7912. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency, keyword, deliverWay)
  7913. } else {
  7914. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and execution_frequency = ? and advice_name like ?"
  7915. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency, keyword)
  7916. }
  7917. } else {
  7918. if len(deliverWay) > 0 {
  7919. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and execution_frequency = ? and delivery_way =?"
  7920. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency, deliverWay)
  7921. } else {
  7922. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and execution_frequency = ?"
  7923. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency)
  7924. }
  7925. }
  7926. } else {
  7927. if len(keyword) > 0 {
  7928. if len(deliverWay) > 0 {
  7929. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and advice_name like ? and delivery_way =?"
  7930. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, keyword, deliverWay)
  7931. } else {
  7932. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and advice_name like ?"
  7933. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, keyword)
  7934. }
  7935. } else {
  7936. if len(deliverWay) > 0 {
  7937. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and delivery_way =?"
  7938. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, deliverWay)
  7939. } else {
  7940. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ?"
  7941. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state)
  7942. }
  7943. }
  7944. }
  7945. }
  7946. } else {
  7947. if cost_type > 0 {
  7948. if len(keyword) > 0 {
  7949. if len(deliverWay) > 0 {
  7950. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and is_settle = ? and advice_name like ? and delivery_way =?"
  7951. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, keyword, deliverWay)
  7952. } else {
  7953. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and is_settle = ? and advice_name like ?"
  7954. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, keyword)
  7955. }
  7956. } else {
  7957. if len(deliverWay) > 0 {
  7958. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and is_settle = ? and delivery_way =?"
  7959. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, deliverWay)
  7960. } else {
  7961. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and is_settle = ? "
  7962. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type)
  7963. }
  7964. }
  7965. } else {
  7966. if len(keyword) > 0 {
  7967. if len(deliverWay) > 0 {
  7968. if len(execution_frequency) > 0 {
  7969. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and advice_name like ? and delivery_way =? and execution_frequency =? "
  7970. adviceCondition = append(adviceCondition, adviceWhere, orgID, keyword, deliverWay, execution_frequency)
  7971. } else {
  7972. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and advice_name like ? and delivery_way =?"
  7973. adviceCondition = append(adviceCondition, adviceWhere, orgID, keyword, deliverWay)
  7974. }
  7975. } else {
  7976. if len(execution_frequency) > 0 {
  7977. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and advice_name like ? and execution_frequency =?"
  7978. adviceCondition = append(adviceCondition, adviceWhere, orgID, keyword, execution_frequency)
  7979. } else {
  7980. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and advice_name like ?"
  7981. adviceCondition = append(adviceCondition, adviceWhere, orgID, keyword)
  7982. }
  7983. }
  7984. } else {
  7985. if len(deliverWay) > 0 {
  7986. if len(execution_frequency) > 0 {
  7987. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and delivery_way =? and execution_frequency =?"
  7988. adviceCondition = append(adviceCondition, adviceWhere, orgID, deliverWay, execution_frequency)
  7989. } else {
  7990. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and delivery_way =?"
  7991. adviceCondition = append(adviceCondition, adviceWhere, orgID, deliverWay)
  7992. }
  7993. } else {
  7994. if len(execution_frequency) > 0 {
  7995. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_frequency =?"
  7996. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_frequency)
  7997. } else {
  7998. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 "
  7999. adviceCondition = append(adviceCondition, adviceWhere, orgID)
  8000. }
  8001. }
  8002. }
  8003. }
  8004. }
  8005. }
  8006. } else if patientType == 1 {
  8007. if patient_id > 0 {
  8008. if execution_state > 0 {
  8009. if cost_type > 0 {
  8010. if len(execution_frequency) > 0 {
  8011. if len(keyword) > 0 {
  8012. if len(deliverWay) > 0 {
  8013. 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 =?"
  8014. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword, deliverWay)
  8015. } else {
  8016. 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 ?"
  8017. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  8018. }
  8019. } else {
  8020. if len(keyword) > 0 {
  8021. if len(deliverWay) > 0 {
  8022. 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 =?"
  8023. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, execution_frequency, deliverWay)
  8024. }
  8025. } else {
  8026. if len(deliverWay) > 0 {
  8027. 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 =?"
  8028. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, execution_frequency, deliverWay)
  8029. } else {
  8030. 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 = ?"
  8031. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  8032. }
  8033. }
  8034. }
  8035. } else {
  8036. if len(keyword) > 0 {
  8037. if len(deliverWay) > 0 {
  8038. 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 =?"
  8039. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, keyword, deliverWay)
  8040. } else {
  8041. 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 ?"
  8042. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, keyword)
  8043. }
  8044. } else {
  8045. if len(deliverWay) > 0 {
  8046. 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 =?"
  8047. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, deliverWay)
  8048. } else {
  8049. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  8050. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type)
  8051. }
  8052. }
  8053. }
  8054. } else {
  8055. if len(execution_frequency) > 0 {
  8056. if len(keyword) > 0 {
  8057. if len(deliverWay) > 0 {
  8058. 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 =?"
  8059. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, execution_frequency, keyword, deliverWay)
  8060. } else {
  8061. 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 ?"
  8062. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  8063. }
  8064. } else {
  8065. if len(deliverWay) > 0 {
  8066. 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 =?"
  8067. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, execution_frequency, deliverWay)
  8068. } else {
  8069. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  8070. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, execution_frequency)
  8071. }
  8072. }
  8073. } else {
  8074. if len(keyword) > 0 {
  8075. if len(deliverWay) > 0 {
  8076. 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 =?"
  8077. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, keyword, deliverWay)
  8078. } else {
  8079. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  8080. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, keyword)
  8081. }
  8082. } else {
  8083. if len(deliverWay) > 0 {
  8084. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and delivery_way =?"
  8085. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, deliverWay)
  8086. } else {
  8087. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  8088. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state)
  8089. }
  8090. }
  8091. }
  8092. }
  8093. } else {
  8094. if cost_type > 0 {
  8095. if len(execution_frequency) > 0 {
  8096. if len(keyword) > 0 {
  8097. if len(deliverWay) > 0 {
  8098. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ?and execution_frequency = ? and advice_name like ? and delivery_way =?"
  8099. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, execution_frequency, keyword, deliverWay)
  8100. } else {
  8101. 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 ?"
  8102. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  8103. }
  8104. } else {
  8105. if len(deliverWay) > 0 {
  8106. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ?and execution_frequency = ? and delivery_way =?"
  8107. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, execution_frequency, deliverWay)
  8108. } else {
  8109. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ?and execution_frequency = ?"
  8110. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, execution_frequency)
  8111. }
  8112. }
  8113. } else {
  8114. if len(keyword) > 0 {
  8115. if len(deliverWay) > 0 {
  8116. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ? and advice_name like ? and delivery_way =?"
  8117. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, keyword, deliverWay)
  8118. } else {
  8119. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  8120. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, keyword)
  8121. }
  8122. } else {
  8123. if len(deliverWay) > 0 {
  8124. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ? and delivery_way =? "
  8125. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, deliverWay)
  8126. } else {
  8127. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  8128. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type)
  8129. }
  8130. }
  8131. }
  8132. } else {
  8133. if len(execution_frequency) > 0 {
  8134. if len(keyword) > 0 {
  8135. if len(deliverWay) > 0 {
  8136. 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 =? "
  8137. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_frequency, keyword, deliverWay)
  8138. } else {
  8139. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  8140. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_frequency, keyword)
  8141. }
  8142. } else {
  8143. if len(deliverWay) > 0 {
  8144. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_frequency = ? and delivery_way =? "
  8145. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_frequency, deliverWay)
  8146. } else {
  8147. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  8148. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_frequency)
  8149. }
  8150. }
  8151. } else {
  8152. if len(keyword) > 0 {
  8153. if len(deliverWay) > 0 {
  8154. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and advice_name like ? and delivery_way =?"
  8155. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, keyword, deliverWay)
  8156. } else {
  8157. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and advice_name like ?"
  8158. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, keyword)
  8159. }
  8160. } else {
  8161. if len(deliverWay) > 0 {
  8162. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and delivery_way =?"
  8163. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, deliverWay)
  8164. } else {
  8165. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ?"
  8166. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id)
  8167. }
  8168. }
  8169. }
  8170. }
  8171. }
  8172. } else {
  8173. if execution_state > 0 {
  8174. if cost_type > 0 {
  8175. if len(execution_frequency) > 0 {
  8176. if len(keyword) > 0 {
  8177. if len(deliverWay) > 0 {
  8178. 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 =?"
  8179. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, execution_frequency, keyword, deliverWay)
  8180. } else {
  8181. 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 ?"
  8182. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  8183. }
  8184. } else {
  8185. if len(deliverWay) > 0 {
  8186. 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 =?"
  8187. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, execution_frequency, deliverWay)
  8188. } else {
  8189. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ?and execution_frequency = ?"
  8190. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, execution_frequency)
  8191. }
  8192. }
  8193. } else {
  8194. if len(keyword) > 0 {
  8195. if len(deliverWay) > 0 {
  8196. 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 =?"
  8197. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, keyword, deliverWay)
  8198. } else {
  8199. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ? and advice_name like ?"
  8200. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, keyword)
  8201. }
  8202. } else {
  8203. if len(deliverWay) > 0 {
  8204. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ? and delivery_way =?"
  8205. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, deliverWay)
  8206. } else {
  8207. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ?"
  8208. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type)
  8209. }
  8210. }
  8211. }
  8212. } else {
  8213. if len(execution_frequency) > 0 {
  8214. if len(keyword) > 0 {
  8215. if len(deliverWay) > 0 {
  8216. 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 =?"
  8217. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, execution_frequency, keyword, deliverWay)
  8218. } else {
  8219. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=?and execution_frequency = ? and advice_name like ?"
  8220. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, execution_frequency, keyword)
  8221. }
  8222. } else {
  8223. if len(deliverWay) > 0 {
  8224. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=?and execution_frequency = ? and delivery_way =?"
  8225. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, execution_frequency, deliverWay)
  8226. } else {
  8227. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=?and execution_frequency = ?"
  8228. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, execution_frequency)
  8229. }
  8230. }
  8231. } else {
  8232. if len(keyword) > 0 {
  8233. if len(deliverWay) > 0 {
  8234. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and advice_name like ? and delivery_way =?"
  8235. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, keyword, deliverWay)
  8236. } else {
  8237. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and advice_name like ?"
  8238. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, keyword)
  8239. }
  8240. } else {
  8241. if len(deliverWay) > 0 {
  8242. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and delivery_way =?"
  8243. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, deliverWay)
  8244. } else {
  8245. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=?"
  8246. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state)
  8247. }
  8248. }
  8249. }
  8250. }
  8251. } else {
  8252. if cost_type > 0 {
  8253. if len(execution_frequency) > 0 {
  8254. if len(keyword) > 0 {
  8255. if len(deliverWay) > 0 {
  8256. 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 =?"
  8257. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, execution_frequency, keyword, deliverWay)
  8258. } else {
  8259. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  8260. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, execution_frequency, keyword)
  8261. }
  8262. } else {
  8263. if len(deliverWay) > 0 {
  8264. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and execution_frequency = ? and delivery_way =?"
  8265. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, execution_frequency, deliverWay)
  8266. } else {
  8267. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  8268. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, execution_frequency)
  8269. }
  8270. }
  8271. } else {
  8272. if len(keyword) > 0 {
  8273. if len(deliverWay) > 0 {
  8274. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and advice_name like ? and delivery_way =?"
  8275. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, keyword, deliverWay)
  8276. } else {
  8277. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and advice_name like ?"
  8278. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, keyword)
  8279. }
  8280. } else {
  8281. if len(deliverWay) > 0 {
  8282. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and delivery_way =?"
  8283. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, deliverWay)
  8284. } else {
  8285. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? "
  8286. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type)
  8287. }
  8288. }
  8289. }
  8290. } else {
  8291. if len(execution_frequency) > 0 {
  8292. if len(keyword) > 0 {
  8293. if len(deliverWay) > 0 {
  8294. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  8295. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_frequency, keyword, deliverWay)
  8296. } else {
  8297. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_frequency = ? and advice_name like ?"
  8298. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_frequency, keyword)
  8299. }
  8300. } else {
  8301. if len(deliverWay) > 0 {
  8302. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_frequency = ? and delivery_way =?"
  8303. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_frequency, deliverWay)
  8304. } else {
  8305. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_frequency = ?"
  8306. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_frequency)
  8307. }
  8308. }
  8309. } else {
  8310. if len(keyword) > 0 {
  8311. if len(deliverWay) > 0 {
  8312. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and advice_name like ? and delivery_way =?"
  8313. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, keyword, deliverWay)
  8314. } else {
  8315. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and advice_name like ?"
  8316. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, keyword)
  8317. }
  8318. } else {
  8319. if len(deliverWay) > 0 {
  8320. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and delivery_way =?"
  8321. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, deliverWay)
  8322. } else {
  8323. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? "
  8324. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId)
  8325. }
  8326. }
  8327. }
  8328. }
  8329. }
  8330. }
  8331. } else if patientType == 2 {
  8332. if patient_id > 0 {
  8333. if execution_state > 0 {
  8334. if cost_type > 0 {
  8335. if len(execution_frequency) > 0 {
  8336. if len(keyword) > 0 {
  8337. if len(deliverWay) > 0 {
  8338. 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 =?"
  8339. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency, keyword, deliverWay)
  8340. } else {
  8341. 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 ?"
  8342. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency, keyword)
  8343. }
  8344. } else {
  8345. if len(deliverWay) > 0 {
  8346. 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 =?"
  8347. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency, deliverWay)
  8348. } else {
  8349. 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 = ?"
  8350. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency)
  8351. }
  8352. }
  8353. } else {
  8354. if len(keyword) > 0 {
  8355. if len(deliverWay) > 0 {
  8356. 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 =?"
  8357. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, keyword, deliverWay)
  8358. } else {
  8359. 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 ?"
  8360. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, keyword)
  8361. }
  8362. } else {
  8363. if len(deliverWay) > 0 {
  8364. 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 =?"
  8365. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, deliverWay)
  8366. } else {
  8367. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ?"
  8368. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type)
  8369. }
  8370. }
  8371. }
  8372. } else {
  8373. if len(execution_frequency) > 0 {
  8374. if len(keyword) > 0 {
  8375. if len(deliverWay) > 0 {
  8376. 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 =?"
  8377. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency, keyword, deliverWay)
  8378. } else {
  8379. 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 ?"
  8380. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency, keyword)
  8381. }
  8382. } else {
  8383. if len(deliverWay) > 0 {
  8384. 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 =?"
  8385. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency, deliverWay)
  8386. } else {
  8387. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and execution_frequency = ?"
  8388. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency)
  8389. }
  8390. }
  8391. } else {
  8392. if len(keyword) > 0 {
  8393. if len(deliverWay) > 0 {
  8394. 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 =?"
  8395. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, keyword, deliverWay)
  8396. } else {
  8397. 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 ?"
  8398. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, keyword)
  8399. }
  8400. } else {
  8401. if len(deliverWay) > 0 {
  8402. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and delivery_way =?"
  8403. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, deliverWay)
  8404. } else {
  8405. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  8406. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state)
  8407. }
  8408. }
  8409. }
  8410. }
  8411. } else {
  8412. if cost_type > 0 {
  8413. if len(execution_frequency) > 0 {
  8414. if len(keyword) > 0 {
  8415. if len(deliverWay) > 0 {
  8416. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  8417. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency, keyword, deliverWay)
  8418. } else {
  8419. 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 ?"
  8420. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency, keyword)
  8421. }
  8422. } else {
  8423. if len(deliverWay) > 0 {
  8424. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and is_settle = ? and execution_frequency = ? and delivery_way =?"
  8425. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency, deliverWay)
  8426. } else {
  8427. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and is_settle = ? and execution_frequency = ?"
  8428. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency)
  8429. }
  8430. }
  8431. } else {
  8432. if len(keyword) > 0 {
  8433. if len(deliverWay) > 0 {
  8434. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and is_settle = ? and advice_name like ? and delivery_way =?"
  8435. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, keyword, deliverWay)
  8436. } else {
  8437. 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 ?"
  8438. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, keyword)
  8439. }
  8440. } else {
  8441. if len(deliverWay) > 0 {
  8442. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and is_settle = ? and delivery_way =?"
  8443. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, deliverWay)
  8444. } else {
  8445. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  8446. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type)
  8447. }
  8448. }
  8449. }
  8450. } else {
  8451. if len(execution_frequency) > 0 {
  8452. if len(keyword) > 0 {
  8453. if len(deliverWay) > 0 {
  8454. 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 =?"
  8455. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency, keyword, deliverWay)
  8456. } else {
  8457. 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 ?"
  8458. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency, keyword)
  8459. }
  8460. } else {
  8461. if len(deliverWay) > 0 {
  8462. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_frequency = ? and delivery_way =?"
  8463. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency, deliverWay)
  8464. } else {
  8465. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_frequency = ?"
  8466. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency)
  8467. }
  8468. }
  8469. } else {
  8470. if len(keyword) > 0 {
  8471. if len(deliverWay) > 0 {
  8472. 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 =?"
  8473. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, keyword, deliverWay)
  8474. } else {
  8475. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and advice_name like ?"
  8476. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, keyword)
  8477. }
  8478. } else {
  8479. if len(deliverWay) > 0 {
  8480. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and delivery_way =?"
  8481. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, deliverWay)
  8482. } else {
  8483. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ?"
  8484. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id)
  8485. }
  8486. }
  8487. }
  8488. }
  8489. }
  8490. } else {
  8491. if execution_state > 0 {
  8492. if cost_type > 0 {
  8493. if len(execution_frequency) > 0 {
  8494. if len(keyword) > 0 {
  8495. if len(deliverWay) > 0 {
  8496. 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 =?"
  8497. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency, keyword, deliverWay)
  8498. } else {
  8499. 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 ?"
  8500. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency, keyword)
  8501. }
  8502. } else {
  8503. if len(deliverWay) > 0 {
  8504. 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 =?"
  8505. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency, deliverWay)
  8506. } else {
  8507. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ? and execution_frequency = ?"
  8508. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency)
  8509. }
  8510. }
  8511. } else {
  8512. if len(keyword) > 0 {
  8513. if len(deliverWay) > 0 {
  8514. 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 =?"
  8515. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, keyword, deliverWay)
  8516. } else {
  8517. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ? and advice_name like ?"
  8518. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, keyword)
  8519. }
  8520. } else {
  8521. if len(deliverWay) > 0 {
  8522. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ? and delivery_way =?"
  8523. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, deliverWay)
  8524. } else {
  8525. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  8526. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type)
  8527. }
  8528. }
  8529. }
  8530. } else {
  8531. if len(execution_frequency) > 0 {
  8532. if len(keyword) > 0 {
  8533. if len(deliverWay) > 0 {
  8534. 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 =?"
  8535. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency, keyword, deliverWay)
  8536. } else {
  8537. 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 ?"
  8538. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency, keyword)
  8539. }
  8540. } else {
  8541. if len(deliverWay) > 0 {
  8542. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ? and execution_frequency = ? and delivery_way =?"
  8543. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency, deliverWay)
  8544. } else {
  8545. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ? and execution_frequency = ?"
  8546. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency)
  8547. }
  8548. }
  8549. } else {
  8550. if len(keyword) > 0 {
  8551. if len(deliverWay) > 0 {
  8552. 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 =?"
  8553. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, keyword, deliverWay)
  8554. } else {
  8555. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ? and advice_name like ?"
  8556. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, keyword)
  8557. }
  8558. } else {
  8559. if len(deliverWay) > 0 {
  8560. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ? and delivery_way =?"
  8561. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, deliverWay)
  8562. } else {
  8563. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ?"
  8564. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state)
  8565. }
  8566. }
  8567. }
  8568. }
  8569. } else {
  8570. if cost_type > 0 {
  8571. if len(execution_frequency) > 0 {
  8572. if len(keyword) > 0 {
  8573. if len(deliverWay) > 0 {
  8574. 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 =?"
  8575. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, execution_frequency, keyword, deliverWay)
  8576. } else {
  8577. 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 ?"
  8578. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, execution_frequency, keyword)
  8579. }
  8580. } else {
  8581. if len(deliverWay) > 0 {
  8582. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ? and execution_frequency = ? and delivery_way =?"
  8583. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, execution_frequency, deliverWay)
  8584. } else {
  8585. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  8586. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, execution_frequency)
  8587. }
  8588. }
  8589. } else {
  8590. if len(keyword) > 0 {
  8591. if len(deliverWay) > 0 {
  8592. 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 =?"
  8593. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, keyword, deliverWay)
  8594. } else {
  8595. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ? and advice_name like ?"
  8596. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, keyword)
  8597. }
  8598. } else {
  8599. if len(deliverWay) > 0 {
  8600. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ? and delivery_way =?"
  8601. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, deliverWay)
  8602. } else {
  8603. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ?"
  8604. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type)
  8605. }
  8606. }
  8607. }
  8608. } else {
  8609. if len(execution_frequency) > 0 {
  8610. if len(keyword) > 0 {
  8611. if len(deliverWay) > 0 {
  8612. 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 =?"
  8613. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_frequency, keyword, deliverWay)
  8614. } else {
  8615. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_frequency = ? and advice_name like ?"
  8616. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_frequency, keyword)
  8617. }
  8618. } else {
  8619. if len(deliverWay) > 0 {
  8620. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_frequency = ? and delivery_way =?"
  8621. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_frequency, deliverWay)
  8622. } else {
  8623. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_frequency = ?"
  8624. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_frequency)
  8625. }
  8626. }
  8627. } else {
  8628. if len(keyword) > 0 {
  8629. if len(deliverWay) > 0 {
  8630. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and advice_name like ? and delivery_way =?"
  8631. adviceCondition = append(adviceCondition, adviceWhere, orgID, keyword, deliverWay)
  8632. } else {
  8633. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and advice_name like ?"
  8634. adviceCondition = append(adviceCondition, adviceWhere, orgID, keyword)
  8635. }
  8636. } else {
  8637. if len(deliverWay) > 0 {
  8638. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and delivery_way =?"
  8639. adviceCondition = append(adviceCondition, adviceWhere, orgID, deliverWay)
  8640. } else {
  8641. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0"
  8642. adviceCondition = append(adviceCondition, adviceWhere, orgID)
  8643. }
  8644. }
  8645. }
  8646. }
  8647. }
  8648. }
  8649. }
  8650. }
  8651. db := readDb.Table("xt_schedule")
  8652. if scheduleType > 0 {
  8653. db = db.Where("schedule_type = ?", scheduleType)
  8654. }
  8655. if partitonType > 0 {
  8656. db = db.Where("partition_id = ?", partitonType)
  8657. }
  8658. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  8659. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  8660. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  8661. }).
  8662. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  8663. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  8664. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  8665. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  8666. Preload("DoctorAdvices", adviceCondition...).
  8667. Where("status = 1 AND user_org_id = ?", orgID)
  8668. if scheduleDate != 0 {
  8669. db = db.Where("schedule_date = ?", scheduleDate)
  8670. }
  8671. err := db.Find(&vms).Error
  8672. return vms, err
  8673. }
  8674. func GetLastAcceptTreatment(user_org_id int64, patient_id int64) (models.ReceiveTreatmentAsses, error) {
  8675. treatmentAsses := models.ReceiveTreatmentAsses{}
  8676. err := XTReadDB().Where("user_org_id = ? and patient_id = ? and status=1 and admission_number<>''", user_org_id, patient_id).Last(&treatmentAsses).Error
  8677. return treatmentAsses, err
  8678. }
  8679. func GetDrugIsShow(id int64, org_id int64) (models.XtBaseDrug, error) {
  8680. baseDrug := models.XtBaseDrug{}
  8681. err := XTReadDB().Where("id = ? and status =1 and org_id = ?", id, org_id).Find(&baseDrug).Error
  8682. return baseDrug, err
  8683. }
  8684. func GetDoctorAdviceByAdviceName(advice_name string, user_org_id int64) (models.BaseDrugLibSeven, error) {
  8685. drugLib := models.BaseDrugLibSeven{}
  8686. err := XTReadDB().Where("drug_name = ? and org_id = ? and status=1", advice_name, user_org_id).Find(&drugLib).Error
  8687. return drugLib, err
  8688. }