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. Height int64 `gorm:"column:height" json:"height" form:"height"`
  174. }
  175. func (MSchedualPatientVMList) TableName() string {
  176. return "xt_patients"
  177. }
  178. type MSchedualPatientVM struct {
  179. ID int64 `gorm:"column:id" json:"id" form:"id"`
  180. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  181. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  182. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  183. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  184. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
  185. AdmissionNumber string `gorm:"column:admission_number" json:"admission_number" form:"admission_number"`
  186. Source int64 `gorm:"column:source" json:"source" form:"source"`
  187. Lapseto int64 `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
  188. PartitionId int64 `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
  189. BedId int64 `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
  190. Name string `gorm:"column:name" json:"name" form:"name"`
  191. Alias string `gorm:"column:alias" json:"alias" form:"alias"`
  192. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  193. Nation string `gorm:"column:nation" json:"nation" form:"nation"`
  194. NativePlace string `gorm:"column:native_place" json:"native_place" form:"native_place"`
  195. MaritalStatus int64 `gorm:"column:marital_status" json:"marital_status" form:"marital_status"`
  196. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  197. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  198. ReimbursementWayId int64 `gorm:"column:reimbursement_way_id" json:"reimbursement_way_id" form:"reimbursement_way_id"`
  199. HealthCareType int64 `gorm:"column:health_care_type" json:"health_care_type" form:"health_care_type"`
  200. HealthCareNo string `gorm:"column:health_care_no" json:"health_care_no" form:"health_care_no"`
  201. HealthCareDueDate int64 `gorm:"column:health_care_due_date" json:"health_care_due_date" form:"health_care_due_date"`
  202. Height int64 `gorm:"column:height" json:"height" form:"height"`
  203. BloodType int64 `gorm:"column:blood_type" json:"blood_type" form:"blood_type"`
  204. Rh int64 `gorm:"column:rh" json:"rh" form:"rh"`
  205. HealthCareDueAlertDate int64 `gorm:"column:health_care_due_alert_date" json:"health_care_due_alert_date" form:"health_care_due_alert_date"`
  206. EducationLevel int64 `gorm:"column:education_level" json:"education_level" form:"education_level"`
  207. Profession int64 `gorm:"column:profession" json:"profession" form:"profession"`
  208. Phone string `gorm:"column:phone" json:"phone" form:"phone"`
  209. HomeTelephone string `gorm:"column:home_telephone" json:"home_telephone" form:"home_telephone"`
  210. RelativePhone string `gorm:"column:relative_phone" json:"relative_phone" form:"relative_phone"`
  211. RelativeRelations string `gorm:"column:relative_relations" json:"relative_relations" form:"relative_relations"`
  212. HomeAddress string `gorm:"column:home_address" json:"home_address" form:"home_address"`
  213. WorkUnit string `gorm:"column:work_unit" json:"work_unit" form:"work_unit"`
  214. UnitAddress string `gorm:"column:unit_address" json:"unit_address" form:"unit_address"`
  215. Children int64 `gorm:"column:children" json:"children" form:"children"`
  216. ReceivingDate int64 `gorm:"column:receiving_date" json:"receiving_date" form:"receiving_date"`
  217. IsHospitalFirstDialysis int64 `gorm:"column:is_hospital_first_dialysis" json:"is_hospital_first_dialysis" form:"is_hospital_first_dialysis"`
  218. FirstDialysisDate int64 `gorm:"column:first_dialysis_date" json:"first_dialysis_date" form:"first_dialysis_date"`
  219. FirstDialysisHospital string `gorm:"column:first_dialysis_hospital" json:"first_dialysis_hospital" form:"first_dialysis_hospital"`
  220. InductionPeriod int64 `gorm:"column:induction_period" json:"induction_period" form:"induction_period"`
  221. InitialDialysis int64 `gorm:"column:initial_dialysis" json:"initial_dialysis" form:"initial_dialysis"`
  222. TotalDialysis int64 `gorm:"column:total_dialysis" json:"total_dialysis" form:"total_dialysis"`
  223. AttendingDoctorId int64 `gorm:"column:attending_doctor_id" json:"attending_doctor_id" form:"attending_doctor_id"`
  224. HeadNurseId int64 `gorm:"column:head_nurse_id" json:"head_nurse_id" form:"head_nurse_id"`
  225. Evaluate string `gorm:"column:evaluate" json:"evaluate" form:"evaluate"`
  226. Diagnose string `gorm:"column:diagnose" json:"diagnose" form:"diagnose"`
  227. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  228. RegistrarsId int64 `gorm:"column:registrars_id" json:"registrars_id" form:"registrars_id"`
  229. Registrars string `gorm:"column:registrars" json:"registrars" form:"registrars"`
  230. QrCode string `gorm:"column:qr_code" json:"qr_code" form:"qr_code"`
  231. BindingState int64 `gorm:"column:binding_state" json:"binding_state" form:"binding_state"`
  232. PatientComplains string `gorm:"column:patient_complains" json:"patient_complains"` // 主诉
  233. PresentHistory string `gorm:"column:present_history" json:"present_history"` // 现病史
  234. PastHistory string `gorm:"column:past_history" json:"past_history"` // 既往史
  235. Temperature float64 `gorm:"column:temperature" json:"temperature"` // 体格检查-体温
  236. Pulse int64 `gorm:"column:pulse" json:"pulse"` // 体格检查-脉搏
  237. Respiratory int64 `gorm:"column:respiratory" json:"respiratory"` // 体格检查-呼吸频率
  238. SBP int64 `gorm:"column:sbp" json:"sbp"` // 体格检查-收缩压
  239. DBP int64 `gorm:"column:dbp" json:"dbp"` // 体格检查-舒张压
  240. Status int64 `gorm:"column:status" json:"status" form:"status"`
  241. Age int64 `gorm:"column:age" json:"age"`
  242. IsOpenRemind int64 `gorm:"column:is_open_remind" json:"is_open_remind"`
  243. DialysisAge int64 `gorm:"column:dialysis_age" json:"dialysis_age" form:"dialysis_age"`
  244. ExpenseKind int64 `gorm:"column:expense_kind" json:"expense_kind" form:"expense_kind"`
  245. TellPhone string `gorm:"column:tell_phone" json:"tell_phone" form:"tell_phone"`
  246. FirstTreatmentDate int64 `gorm:"column:first_treatment_date" json:"first_treatment_date" form:"first_treatment_date"`
  247. ContactName string `gorm:"column:contact_name" json:"contact_name" form:"contact_name"`
  248. UserSysBeforeCount int64 `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
  249. FirstLetter string `gorm:"column:first_letter" json:"first_letter" form:"first_letter"`
  250. }
  251. func (MSchedualPatientVM) TableName() string {
  252. return "xt_patients"
  253. }
  254. type MDialysisOrderVM struct {
  255. ID int64 `gorm:"column:id" json:"id"`
  256. DialysisDate int64 `gorm:"column:dialysis_date" json:"dialysis_date"`
  257. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  258. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  259. Stage int64 `gorm:"column:stage" json:"stage"`
  260. BedID int64 `gorm:"column:bed_id" json:"bed_id"`
  261. StartNurse int64 `gorm:"column:start_nurse" json:"start_nurse"`
  262. FinishNurse int64 `gorm:"column:finish_nurse" json:"finish_nurse"`
  263. Status int64 `gorm:"column:status" json:"status"`
  264. PunctureNurse int64 `gorm:"column:puncture_nurse" json:"puncture_nurse"`
  265. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedID" json:"device_number"`
  266. MonitoringRecords []*models.MonitoringRecord `gorm:"ForeignKey:DialysisOrderId" json:"monitoring_records"`
  267. Creator int64 `gorm:"column:creator" json:"creator"`
  268. Modifier int64 `gorm:"column:modifier" json:"modifier"`
  269. FinishCreator int64 `gorm:"column:finish_creator" json:"finish_creator"`
  270. FinishModifier int64 `gorm:"column:finish_modifier" json:"finish_modifier"`
  271. SchedualType int64 `gorm:"column:schedual_type" json:"schedual_type"`
  272. WashpipeNurse int64 `gorm:"column:washpipe_nurse" json:"washpipe_nurse" form:"washpipe_nurse"`
  273. DialysisIrrigation string `gorm:"column:dialysis_irrigation" json:"dialysis_irrigation" form:"dialysis_irrigation"`
  274. DialysisDialyszers string `gorm:"column:dialysis_dialyszers" json:"dialysis_dialyszers" form:"dialysis_dialyszers"`
  275. }
  276. func (MDialysisOrderVM) TableName() string {
  277. return "xt_dialysis_order"
  278. }
  279. type MDialysisOrderVMList struct {
  280. ID int64 `gorm:"column:id" json:"id"`
  281. DialysisDate int64 `gorm:"column:dialysis_date" json:"dialysis_date"`
  282. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  283. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  284. // PrescriptionId int64 `gorm:"column:prescription_id" json:"prescription_id"`
  285. Stage int64 `gorm:"column:stage" json:"stage"`
  286. // Remark string `gorm:"column:remark" json:"remark"`
  287. BedID int64 `gorm:"column:bed_id" json:"bed_id"`
  288. StartNurse int64 `gorm:"column:start_nurse" json:"start_nurse"`
  289. Status int64 `gorm:"column:status" json:"status"`
  290. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedID" json:"device_number"`
  291. Creator int64 `gorm:"column:creator" json:"creator"`
  292. WashpipeNurse int64 `gorm:"column:washpipe_nurse" json:"washpipe_nurse" form:"washpipe_nurse"`
  293. NucleinDate int64 `gorm:"column:nuclein_date" json:"nuclein_date" form:"nuclein_date"`
  294. DialysisIrrigation string `gorm:"column:dialysis_irrigation" json:"dialysis_irrigation" form:"dialysis_irrigation"`
  295. DialysisDialyszers string `gorm:"column:dialysis_dialyszers" json:"dialysis_dialyszers" form:"dialysis_dialyszers"`
  296. ScheduleRemark string `gorm:"column:schedule_remark" json:"schedule_remark" form:"schedule_remark"`
  297. }
  298. func (MDialysisOrderVMList) TableName() string {
  299. return "xt_dialysis_order"
  300. }
  301. type VMDoctorAdvice struct {
  302. ID int64 `gorm:"column:id" json:"id" form:"id"`
  303. GroupNo int64 `gorm:"column:groupno" json:"groupno" form:"groupno"`
  304. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  305. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  306. AdviceDate int64 `gorm:"column:advice_date" json:"advice_date" form:"advice_date"`
  307. Status int64 `gorm:"column:status" json:"status" form:"status"`
  308. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
  309. RecordDate int64 `gorm:"column:record_date" json:"record_date"`
  310. CheckTime int64 `gorm:"column:check_time" json:"check_time" form:"check_time"`
  311. CheckState int64 `gorm:"column:check_state" json:"check_state" form:"check_state"`
  312. ParentId int64 `gorm:"column:parent_id" json:"parent_id" form:"parent_id"`
  313. }
  314. func (VMDoctorAdvice) TableName() string {
  315. return "xt_doctor_advice"
  316. }
  317. type VMHisDoctorAdviceInfo struct {
  318. ID int64 `gorm:"column:id" json:"id" form:"id"`
  319. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  320. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  321. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  322. ExecutionTime int64 `gorm:"column:execution_time" json:"execution_time" form:"execution_time"`
  323. ExecutionStaff int64 `gorm:"column:execution_staff" json:"execution_staff" form:"execution_staff"`
  324. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
  325. IsMedicine int64 `gorm:"column:is_medicine" json:"is_medicine" form:"is_medicine"`
  326. ExecutionFrequencyId int64 `gorm:"column:execution_frequency_id" json:"execution_frequency_id" form:"execution_frequency_id"`
  327. IsSelfDrug int64 `gorm:"column:is_self_drug" json:"is_self_drug" form:"is_self_drug"`
  328. }
  329. func (VMHisDoctorAdviceInfo) TableName() string {
  330. return "his_doctor_advice_info"
  331. }
  332. type VMAssessmentAfterDislysis struct {
  333. ID int64 `gorm:"column:id" json:"id"`
  334. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  335. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  336. AssessmentDate int64 `gorm:"column:assessment_date" json:"assessment_date"`
  337. WeightAfter float64 `gorm:"column:weight_after" json:"weight_after"`
  338. Status int64 `gorm:"column:status" json:"status"`
  339. }
  340. func (VMAssessmentAfterDislysis) TableName() string {
  341. return "xt_assessment_after_dislysis"
  342. }
  343. type NewDeviceInformation struct {
  344. ID int64 `gorm:"column:id" json:"id" form:"id"`
  345. Date int64 `gorm:"column:date" json:"date" form:"date"`
  346. Class int64 `gorm:"column:class" json:"class" form:"class"`
  347. Zone int64 `gorm:"column:zone" json:"zone" form:"zone"`
  348. BedNumber int64 `gorm:"column:bed_number" json:"bed_number" form:"bed_number"`
  349. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  350. Status int64 `gorm:"column:status" json:"status" form:"status"`
  351. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  352. EquimentId int64 `gorm:"column:equiment_id" json:"equiment_id" form:"equiment_id"`
  353. Bed string `gorm:"column:bed" json:"bed" form:"bed"`
  354. Stime int64 `gorm:"column:stime" json:"stime" form:"stime"`
  355. }
  356. func (NewDeviceInformation) TableName() string {
  357. return "xt_device_information"
  358. }
  359. // 获取透析记录
  360. func MobileGetDialysisRecord(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  361. var record models.DialysisOrder
  362. err := readDb.Model(&models.DialysisOrder{}).Where("user_org_id = ? AND patient_id = ? AND dialysis_date = ?", orgID, patientID, recordDate).First(&record).Error
  363. if err != nil {
  364. if err == gorm.ErrRecordNotFound {
  365. return nil, nil
  366. } else {
  367. return nil, err
  368. }
  369. }
  370. return &record, nil
  371. }
  372. // 用户基本信息
  373. func MobileGetPatientDetail(orgID int64, patientID int64) (*MPatient, error) {
  374. var patient MPatient
  375. //err := readDb.Model(&MPatient{}).Where("status = 1 AND user_org_id = ? AND id = ?", orgID, patientID).First(&patient).Error
  376. //if err != nil {
  377. // if err == gorm.ErrRecordNotFound {
  378. // return nil, nil
  379. // } else {
  380. // return nil, err
  381. // }
  382. //}
  383. //return &patient, nil
  384. redis := RedisClient()
  385. defer redis.Close()
  386. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":patient_info"
  387. patient_info_str, _ := redis.Get(key).Result()
  388. if len(patient_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  389. err = readDb.Model(&patient).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
  390. if err != nil {
  391. if err == gorm.ErrRecordNotFound {
  392. return &patient, nil
  393. } else {
  394. return &patient, err
  395. }
  396. } else {
  397. if patient.ID > 0 {
  398. //缓存数据
  399. patient_info_json, err := json.Marshal(&patient)
  400. if err == nil {
  401. redis.Set(key, patient_info_json, time.Second*60*60*18)
  402. }
  403. }
  404. return &patient, nil
  405. }
  406. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  407. json.Unmarshal([]byte(patient_info_str), &patient)
  408. return &patient, nil
  409. }
  410. }
  411. func MobileGetSchedualDetailOne(orgID int64, patientID int64, schedualDate int64) (*MDialysisScheduleVM, error) {
  412. var vm MDialysisScheduleVM
  413. err := readDb.
  414. Table("xt_schedule").
  415. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  416. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  417. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  418. First(&vm).Error
  419. return &vm, err
  420. }
  421. // 用户排班信息
  422. func MobileGetSchedualDetailSix(orgID int64, patientID int64, schedualDate int64) (*MDialysisScheduleVM, error) {
  423. var vm MDialysisScheduleVM
  424. err := readDb.
  425. Table("xt_schedule").
  426. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  427. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  428. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  429. First(&vm).Error
  430. if err != nil {
  431. if err == gorm.ErrRecordNotFound {
  432. return nil, nil
  433. } else {
  434. return nil, err
  435. }
  436. }
  437. return &vm, err
  438. }
  439. // 用户排班信息
  440. func MobileGetSchedualDetail(orgID int64, patientID int64, schedualDate int64) (*MDialysisScheduleVM, error) {
  441. redis := RedisClient()
  442. defer redis.Close()
  443. var vm MDialysisScheduleVM
  444. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(schedualDate, 10) + ":schedual_detail"
  445. redis.Set(key, "", time.Second)
  446. schedual_detail_str, _ := redis.Get(key).Result()
  447. if len(schedual_detail_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  448. err := readDb.
  449. Table("xt_schedule").
  450. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  451. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  452. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  453. First(&vm).Error
  454. if err != nil {
  455. if err == gorm.ErrRecordNotFound {
  456. return nil, nil
  457. } else {
  458. return nil, err
  459. }
  460. } else {
  461. if vm.ID > 0 {
  462. //缓存数据
  463. schedual_detail_str, err := json.Marshal(vm)
  464. if err == nil {
  465. redis.Set(key, schedual_detail_str, time.Second*60*60*18)
  466. }
  467. } else {
  468. redis.Set(key, "null", time.Second*60*60*18)
  469. }
  470. return &vm, nil
  471. }
  472. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  473. if schedual_detail_str == "null" {
  474. return &vm, nil
  475. }
  476. json.Unmarshal([]byte(schedual_detail_str), &vm)
  477. return &vm, nil
  478. }
  479. }
  480. // 用户排班信息
  481. func MobileGetPatientSchedual(orgID int64, patientID int64, schedualDate int64) (*models.Schedule, error) {
  482. var schedule models.Schedule
  483. err := readDb.
  484. Table("xt_schedule").
  485. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  486. First(&schedule).Error
  487. if err != nil {
  488. if err == gorm.ErrRecordNotFound {
  489. return nil, nil
  490. } else {
  491. return nil, err
  492. }
  493. }
  494. return &schedule, nil
  495. }
  496. type MPatient struct {
  497. ID int64 `gorm:"column:id" json:"id" form:"id"`
  498. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  499. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  500. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  501. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  502. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
  503. AdmissionNumber string `gorm:"column:admission_number" json:"admission_number" form:"admission_number"`
  504. Source int64 `gorm:"column:source" json:"source" form:"source"`
  505. Lapseto int64 `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
  506. PartitionId int64 `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
  507. BedId int64 `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
  508. Name string `gorm:"column:name" json:"name" form:"name"`
  509. Alias string `gorm:"column:alias" json:"alias" form:"alias"`
  510. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  511. Nation string `gorm:"column:nation" json:"nation" form:"nation"`
  512. NativePlace string `gorm:"column:native_place" json:"native_place" form:"native_place"`
  513. MaritalStatus int64 `gorm:"column:marital_status" json:"marital_status" form:"marital_status"`
  514. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  515. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  516. ReimbursementWayId int64 `gorm:"column:reimbursement_way_id" json:"reimbursement_way_id" form:"reimbursement_way_id"`
  517. HealthCareType int64 `gorm:"column:health_care_type" json:"health_care_type" form:"health_care_type"`
  518. HealthCareNo string `gorm:"column:health_care_no" json:"health_care_no" form:"health_care_no"`
  519. HealthCareDueDate int64 `gorm:"column:health_care_due_date" json:"health_care_due_date" form:"health_care_due_date"`
  520. Height int64 `gorm:"column:height" json:"height" form:"height"`
  521. BloodType int64 `gorm:"column:blood_type" json:"blood_type" form:"blood_type"`
  522. Rh int64 `gorm:"column:rh" json:"rh" form:"rh"`
  523. HealthCareDueAlertDate int64 `gorm:"column:health_care_due_alert_date" json:"health_care_due_alert_date" form:"health_care_due_alert_date"`
  524. EducationLevel int64 `gorm:"column:education_level" json:"education_level" form:"education_level"`
  525. Profession int64 `gorm:"column:profession" json:"profession" form:"profession"`
  526. Phone string `gorm:"column:phone" json:"phone" form:"phone"`
  527. HomeTelephone string `gorm:"column:home_telephone" json:"home_telephone" form:"home_telephone"`
  528. RelativePhone string `gorm:"column:relative_phone" json:"relative_phone" form:"relative_phone"`
  529. RelativeRelations string `gorm:"column:relative_relations" json:"relative_relations" form:"relative_relations"`
  530. HomeAddress string `gorm:"column:home_address" json:"home_address" form:"home_address"`
  531. WorkUnit string `gorm:"column:work_unit" json:"work_unit" form:"work_unit"`
  532. UnitAddress string `gorm:"column:unit_address" json:"unit_address" form:"unit_address"`
  533. Children int64 `gorm:"column:children" json:"children" form:"children"`
  534. ReceivingDate int64 `gorm:"column:receiving_date" json:"receiving_date" form:"receiving_date"`
  535. IsHospitalFirstDialysis int64 `gorm:"column:is_hospital_first_dialysis" json:"is_hospital_first_dialysis" form:"is_hospital_first_dialysis"`
  536. FirstDialysisDate int64 `gorm:"column:first_dialysis_date" json:"first_dialysis_date" form:"first_dialysis_date"`
  537. FirstDialysisHospital string `gorm:"column:first_dialysis_hospital" json:"first_dialysis_hospital" form:"first_dialysis_hospital"`
  538. InductionPeriod int64 `gorm:"column:induction_period" json:"induction_period" form:"induction_period"`
  539. InitialDialysis int64 `gorm:"column:initial_dialysis" json:"initial_dialysis" form:"initial_dialysis"`
  540. TotalDialysis int64 `gorm:"column:total_dialysis" json:"total_dialysis" form:"total_dialysis"`
  541. AttendingDoctorId int64 `gorm:"column:attending_doctor_id" json:"attending_doctor_id" form:"attending_doctor_id"`
  542. HeadNurseId int64 `gorm:"column:head_nurse_id" json:"head_nurse_id" form:"head_nurse_id"`
  543. Evaluate string `gorm:"column:evaluate" json:"evaluate" form:"evaluate"`
  544. Diagnose string `gorm:"column:diagnose" json:"diagnose" form:"diagnose"`
  545. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  546. RegistrarsId int64 `gorm:"column:registrars_id" json:"registrars_id" form:"registrars_id"`
  547. Registrars string `gorm:"column:registrars" json:"registrars" form:"registrars"`
  548. QrCode string `gorm:"column:qr_code" json:"qr_code" form:"qr_code"`
  549. BindingState int64 `gorm:"column:binding_state" json:"binding_state" form:"binding_state"`
  550. PatientComplains string `gorm:"column:patient_complains" json:"patient_complains"` // 主诉
  551. PresentHistory string `gorm:"column:present_history" json:"present_history"` // 现病史
  552. PastHistory string `gorm:"column:past_history" json:"past_history"` // 既往史
  553. Temperature float64 `gorm:"column:temperature" json:"temperature"` // 体格检查-体温
  554. Pulse int64 `gorm:"column:pulse" json:"pulse"` // 体格检查-脉搏
  555. Respiratory int64 `gorm:"column:respiratory" json:"respiratory"` // 体格检查-呼吸频率
  556. SBP int64 `gorm:"column:sbp" json:"sbp"` // 体格检查-收缩压
  557. DBP int64 `gorm:"column:dbp" json:"dbp"` // 体格检查-舒张压
  558. Status int64 `gorm:"column:status" json:"status" form:"status"`
  559. Age int64 `gorm:"column:age" json:"age"`
  560. IsOpenRemind int64 `gorm:"column:is_open_remind" json:"is_open_remind"`
  561. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  562. DialysisAge int64 `gorm:"column:dialysis_age" json:"dialysis_age" form:"dialysis_age"`
  563. ExpenseKind int64 `gorm:"column:expense_kind" json:"expense_kind" form:"expense_kind"`
  564. TellPhone string `gorm:"column:tell_phone" json:"tell_phone" form:"tell_phone"`
  565. FirstTreatmentDate int64 `gorm:"column:first_treatment_date" json:"first_treatment_date" form:"first_treatment_date"`
  566. ContactName string `gorm:"column:contact_name" json:"contact_name" form:"contact_name"`
  567. UserSysBeforeCount int64 `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
  568. }
  569. func (MPatient) TableName() string {
  570. return "xt_patients"
  571. }
  572. // 接诊评估
  573. func MobileGetReceiverTreatmentAccessRecord(orgID int64, patientID int64, recordDate int64) (*models.ReceiveTreatmentAsses, error) {
  574. var record models.ReceiveTreatmentAsses
  575. redis := RedisClient()
  576. defer redis.Close()
  577. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":receive_treatment_asses"
  578. receive_treatment_asses_str, _ := redis.Get(key).Result()
  579. if len(receive_treatment_asses_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  580. err = readDb.Model(&models.ReceiveTreatmentAsses{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  581. if err != nil {
  582. if err == gorm.ErrRecordNotFound {
  583. if record.ID <= 0 {
  584. redis.Set(key, "", time.Second*60*60*18)
  585. }
  586. return nil, nil
  587. } else {
  588. return nil, err
  589. }
  590. } else {
  591. if record.ID > 0 {
  592. //缓存数据
  593. receive_treatment_asses_str, err := json.Marshal(record)
  594. if err == nil {
  595. redis.Set(key, receive_treatment_asses_str, time.Second*60*60*18)
  596. }
  597. } else {
  598. redis.Set(key, "null", time.Second*60*60*18)
  599. }
  600. return &record, nil
  601. }
  602. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  603. if receive_treatment_asses_str == "null" {
  604. return &record, nil
  605. }
  606. json.Unmarshal([]byte(receive_treatment_asses_str), &record)
  607. return &record, nil
  608. }
  609. }
  610. // 透前评估
  611. func MobileGetPredialysisEvaluationOne(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
  612. var record models.PredialysisEvaluation
  613. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  614. if err != nil {
  615. if err == gorm.ErrRecordNotFound {
  616. return nil, nil
  617. } else {
  618. return nil, err
  619. }
  620. }
  621. return &record, nil
  622. }
  623. func MobileGetPredialysisEvaluationTwo(orgID int64, patientID int64, recordDate int64) (models.PredialysisEvaluation, error) {
  624. var record models.PredialysisEvaluation
  625. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  626. return record, err
  627. }
  628. // 透前评估
  629. func MobileGetPredialysisEvaluation(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
  630. var record models.PredialysisEvaluation
  631. redis := RedisClient()
  632. defer redis.Close()
  633. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":assessment_before_dislysis"
  634. assessment_before_dislysis_str, _ := redis.Get(key).Result()
  635. redis.Set(key, "", time.Second)
  636. if len(assessment_before_dislysis_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  637. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  638. if err != nil {
  639. if err == gorm.ErrRecordNotFound {
  640. if record.ID <= 0 {
  641. redis.Set(key, "", time.Second*60*60*18)
  642. }
  643. return nil, nil
  644. } else {
  645. return nil, err
  646. }
  647. } else {
  648. if record.ID > 0 {
  649. //缓存数据
  650. assessment_before_dislysis_str, err := json.Marshal(record)
  651. if err == nil {
  652. redis.Set(key, assessment_before_dislysis_str, time.Second*60*60*18)
  653. }
  654. } else {
  655. redis.Set(key, "null", time.Second*60*60*18)
  656. }
  657. return &record, nil
  658. }
  659. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  660. if assessment_before_dislysis_str == "null" {
  661. return &record, nil
  662. } else {
  663. json.Unmarshal([]byte(assessment_before_dislysis_str), &record)
  664. return &record, nil
  665. }
  666. }
  667. }
  668. // 获取 maxDate 之前一次的透前评估记录
  669. func MobileGetLastTimePredialysisEvaluationOne(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
  670. var record models.PredialysisEvaluation
  671. 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
  672. if err != nil {
  673. if err == gorm.ErrRecordNotFound {
  674. return nil, nil
  675. } else {
  676. return nil, err
  677. }
  678. }
  679. return &record, nil
  680. }
  681. // 获取 maxDate 之前一次的透前评估记录
  682. func MobileGetLastTimePredialysisEvaluation(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
  683. var record models.PredialysisEvaluation
  684. redis := RedisClient()
  685. defer redis.Close()
  686. // cur_date := time.Now().Format("2006-01-02")
  687. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(maxDate, 10) + ":assessment_before_dislysis_last"
  688. assessment_before_dislysis_last_str, _ := redis.Get(key).Result()
  689. if len(assessment_before_dislysis_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  690. 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
  691. if err != nil {
  692. if err == gorm.ErrRecordNotFound {
  693. if record.ID <= 0 {
  694. redis.Set(key, "", time.Second*60*60*18)
  695. }
  696. return nil, nil
  697. } else {
  698. return nil, err
  699. }
  700. } else {
  701. if record.ID > 0 {
  702. //缓存数据
  703. assessment_before_dislysis_last_str, err := json.Marshal(record)
  704. if err == nil {
  705. redis.Set(key, assessment_before_dislysis_last_str, time.Second*60*60*4)
  706. }
  707. } else {
  708. redis.Set(key, "null", time.Second*60*60*18)
  709. }
  710. return &record, nil
  711. }
  712. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  713. if assessment_before_dislysis_last_str == "null" {
  714. return &record, nil
  715. } else {
  716. json.Unmarshal([]byte(assessment_before_dislysis_last_str), &record)
  717. return &record, nil
  718. }
  719. }
  720. }
  721. // 临时医嘱
  722. func MobileGetDoctorAdvices(orgID int64, patientID int64, recordDate int64) ([]*models.DoctorAdvice, error) {
  723. var records []*models.DoctorAdvice
  724. // err := readDb.Model(&models.DoctorAdvice{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).Find(&records).Error
  725. err := readDb.
  726. Model(&models.DoctorAdvice{}).
  727. Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? and (advice_type = 2 or advice_type = 3)", patientID, orgID, recordDate).
  728. 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").
  729. Order("start_time asc, groupno desc, advice_order desc, id").
  730. Scan(&records).Error
  731. if err != nil {
  732. return nil, err
  733. }
  734. return records, nil
  735. }
  736. func MobileGetDoctorAdvicesByGroups(orgID int64, patientID int64, recordDate int64) ([]*models.DoctorAdvice, error) {
  737. var records []*models.DoctorAdvice
  738. redis := RedisClient()
  739. defer redis.Close()
  740. // cur_date := time.Now().Format("2006-01-02")
  741. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":doctor_advices"
  742. //fmt.Println("key23233232323323wi", key)
  743. redis.Set(key, "", time.Second)
  744. doctor_advices_str, _ := redis.Get(key).Result()
  745. if len(doctor_advices_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  746. err := readDb.Model(&models.DoctorAdvice{}).
  747. Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? and (advice_type = 2 || advice_type = 3)", patientID, orgID, recordDate).
  748. 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").
  749. Order("start_time asc, groupno desc, advice_order desc, id asc").
  750. Scan(&records).Error
  751. if err != nil {
  752. if err == gorm.ErrRecordNotFound {
  753. if len(records) <= 0 {
  754. redis.Set(key, "", time.Second*60*60*18)
  755. }
  756. return nil, nil
  757. } else {
  758. return nil, err
  759. }
  760. } else {
  761. if len(records) > 0 {
  762. //缓存数据
  763. doctor_advices_str, err := json.Marshal(records)
  764. if err == nil {
  765. redis.Set(key, doctor_advices_str, time.Second*60*60*18)
  766. return records, nil
  767. }
  768. } else {
  769. redis.Set(key, "null", time.Second*60*60*18)
  770. return records, nil
  771. }
  772. return records, nil
  773. }
  774. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  775. if doctor_advices_str == "null" {
  776. return records, nil
  777. } else {
  778. json.Unmarshal([]byte(doctor_advices_str), &records)
  779. return records, nil
  780. }
  781. }
  782. }
  783. // 透析记录
  784. func MobileGetSchedualDialysisRecordTen(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  785. var record models.DialysisOrder
  786. 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
  787. if err != nil {
  788. if err == gorm.ErrRecordNotFound {
  789. return nil, nil
  790. } else {
  791. return nil, err
  792. }
  793. }
  794. return &record, nil
  795. }
  796. //func MobileGetSchedualDialysisRecord(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  797. // var record models.DialysisOrder
  798. //
  799. // 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
  800. //
  801. //
  802. // return &record,err
  803. //}
  804. // 透析记录
  805. func MobileGetSchedualDialysisRecord(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  806. var record models.DialysisOrder
  807. redis := RedisClient()
  808. defer redis.Close()
  809. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":dialysis_order"
  810. dialysis_order_str, _ := redis.Get(key).Result()
  811. if len(dialysis_order_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  812. 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
  813. if err != nil {
  814. if err == gorm.ErrRecordNotFound {
  815. return nil, nil
  816. } else {
  817. return nil, err
  818. }
  819. } else {
  820. if record.ID > 0 {
  821. //缓存数据
  822. dialysis_order_str, err := json.Marshal(record)
  823. if err == nil {
  824. redis.Set(key, dialysis_order_str, time.Second*60*60*18)
  825. }
  826. } else {
  827. redis.Set(key, "null", time.Second*60*60*18)
  828. }
  829. return &record, nil
  830. }
  831. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  832. if dialysis_order_str == "null" {
  833. 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
  834. return &record, nil
  835. } else {
  836. json.Unmarshal([]byte(dialysis_order_str), &record)
  837. return &record, nil
  838. }
  839. }
  840. }
  841. // 双人核对
  842. func MobileGetDoubleCheck(orgID int64, patientID int64, recordDate int64) (*models.DoubleCheck, error) {
  843. var record models.DoubleCheck
  844. redis := RedisClient()
  845. defer redis.Close()
  846. // cur_date := time.Now().Format("2006-01-02")
  847. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":double_check"
  848. double_check_str, _ := redis.Get(key).Result()
  849. if len(double_check_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  850. err := readDb.Model(&models.DoubleCheck{}).Where("patient_id = ? and user_org_id = ? and status = 1 and check_date = ?", patientID, orgID, recordDate).First(&record).Error
  851. if err != nil {
  852. if err == gorm.ErrRecordNotFound {
  853. if record.ID <= 0 {
  854. redis.Set(key, "null", time.Second*60*60*18)
  855. }
  856. return nil, nil
  857. } else {
  858. return nil, err
  859. }
  860. } else {
  861. if record.ID > 0 {
  862. //缓存数据
  863. double_check_str, err := json.Marshal(record)
  864. if err == nil {
  865. redis.Set(key, double_check_str, time.Second*60*60*18)
  866. }
  867. } else {
  868. redis.Set(key, "null", time.Second*60*60*18)
  869. }
  870. return &record, nil
  871. }
  872. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  873. if double_check_str == "null" {
  874. return &record, nil
  875. } else {
  876. json.Unmarshal([]byte(double_check_str), &record)
  877. return &record, nil
  878. }
  879. }
  880. }
  881. // 透析监测记录
  882. func MobileGetMonitorRecords(orgID int64, patientID int64, recordDate int64) ([]*models.MonitoringRecord, error) {
  883. var records []*models.MonitoringRecord
  884. redis := RedisClient()
  885. defer redis.Close()
  886. // cur_date := time.Now().Format("2006-01-02")
  887. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":monitor_records"
  888. redis.Set(key, "", time.Second)
  889. monitor_records_str, _ := redis.Get(key).Result()
  890. if len(monitor_records_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  891. 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
  892. if err != nil {
  893. if err == gorm.ErrRecordNotFound {
  894. //if len(records) <= 0 {
  895. // redis.Set(key, "null", time.Second*60*60*18)
  896. //}
  897. return nil, nil
  898. } else {
  899. return nil, err
  900. }
  901. } else {
  902. if len(records) > 0 {
  903. //缓存数据
  904. monitor_records_str, err := json.Marshal(records)
  905. if err == nil {
  906. redis.Set(key, monitor_records_str, time.Second*60*60*18)
  907. }
  908. } else {
  909. redis.Set(key, "null", time.Second*60*60*18)
  910. }
  911. return records, nil
  912. }
  913. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  914. if monitor_records_str == "null" {
  915. return records, nil
  916. } else {
  917. json.Unmarshal([]byte(monitor_records_str), &records)
  918. return records, nil
  919. }
  920. }
  921. }
  922. func MobileGetMonitorRecordFirst(orgID int64, patientID int64, recordDate int64) (*models.MonitoringRecord, error) {
  923. var records models.MonitoringRecord
  924. 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
  925. if err != nil {
  926. return nil, err
  927. }
  928. return &records, nil
  929. }
  930. func MobileGetLastMonitorRecordOne(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  931. var record models.MonitoringRecord
  932. 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
  933. if err != nil {
  934. if err == gorm.ErrRecordNotFound {
  935. return nil, nil
  936. } else {
  937. return nil, err
  938. }
  939. }
  940. return &record, nil
  941. }
  942. func MobileGetLastMonitorRecord(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  943. var record models.MonitoringRecord
  944. redis := RedisClient()
  945. defer redis.Close()
  946. // cur_date := time.Now().Format("2006-01-02")
  947. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(beforeDate, 10) + ":monitor_record_last"
  948. monitor_record_last_str, _ := redis.Get(key).Result()
  949. redis.Set(key, "", time.Second)
  950. if len(monitor_record_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  951. 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
  952. if err != nil {
  953. if err == gorm.ErrRecordNotFound {
  954. if record.ID <= 0 {
  955. redis.Set(key, "null", time.Second*60*60*18)
  956. }
  957. return nil, nil
  958. } else {
  959. return nil, err
  960. }
  961. } else {
  962. if record.ID > 0 {
  963. //缓存数据
  964. monitor_record_last_str, err := json.Marshal(record)
  965. if err == nil {
  966. redis.Set(key, monitor_record_last_str, time.Second*60*60*18)
  967. }
  968. } else {
  969. redis.Set(key, "null", time.Second*60*60*18)
  970. }
  971. return &record, nil
  972. }
  973. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  974. if monitor_record_last_str == "null" {
  975. return &record, nil
  976. } else {
  977. json.Unmarshal([]byte(monitor_record_last_str), &record)
  978. return &record, nil
  979. }
  980. }
  981. }
  982. func MobileGetAssessmentAfterDislysisOne(orgID int64, patientID int64, recordDate int64) (*models.AssessmentAfterDislysis, error) {
  983. var record models.AssessmentAfterDislysis
  984. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  985. if err != nil {
  986. if err == gorm.ErrRecordNotFound {
  987. return nil, nil
  988. } else {
  989. return nil, err
  990. }
  991. }
  992. return &record, nil
  993. }
  994. // 透后评估
  995. func MobileGetAssessmentAfterDislysis(orgID int64, patientID int64, recordDate int64) (*models.AssessmentAfterDislysis, error) {
  996. var record models.AssessmentAfterDislysis
  997. redis := RedisClient()
  998. defer redis.Close()
  999. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":assessment_after_dislysis"
  1000. redis.Set(key, "", time.Second)
  1001. assessment_after_dislysis_str, _ := redis.Get(key).Result()
  1002. if len(assessment_after_dislysis_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1003. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  1004. if err != nil {
  1005. if err == gorm.ErrRecordNotFound {
  1006. if record.ID <= 0 {
  1007. redis.Set(key, "null", time.Second*60*60*18)
  1008. }
  1009. return nil, nil
  1010. } else {
  1011. return nil, err
  1012. }
  1013. } else {
  1014. if record.ID > 0 {
  1015. //缓存数据
  1016. assessment_after_dislysis_str, err := json.Marshal(record)
  1017. if err == nil {
  1018. redis.Set(key, assessment_after_dislysis_str, time.Second*60*60*18)
  1019. }
  1020. } else {
  1021. redis.Set(key, "null", time.Second*60*60*18)
  1022. }
  1023. return &record, nil
  1024. }
  1025. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1026. if assessment_after_dislysis_str == "null" {
  1027. return &record, nil
  1028. } else {
  1029. json.Unmarshal([]byte(assessment_after_dislysis_str), &record)
  1030. return &record, nil
  1031. }
  1032. }
  1033. }
  1034. // 获取 maxDate 之前一次的透后评估记录
  1035. func MobileGetLastTimeAssessmentAfterDislysis(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  1036. var record models.AssessmentAfterDislysis
  1037. redis := RedisClient()
  1038. defer redis.Close()
  1039. // cur_date := time.Now().Format("2006-01-02")
  1040. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(maxDate, 10) + ":assessment_after_dislysis_last"
  1041. redis.Set(key, "", time.Second)
  1042. assessment_after_dislysis_last_str, _ := redis.Get(key).Result()
  1043. if len(assessment_after_dislysis_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1044. 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
  1045. if err != nil {
  1046. if err == gorm.ErrRecordNotFound {
  1047. if record.ID <= 0 {
  1048. redis.Set(key, "null", time.Second*60*60*18)
  1049. }
  1050. return nil, nil
  1051. } else {
  1052. return nil, err
  1053. }
  1054. } else {
  1055. if record.ID > 0 {
  1056. //缓存数据
  1057. assessment_after_dislysis_last_str, err := json.Marshal(record)
  1058. if err == nil {
  1059. redis.Set(key, assessment_after_dislysis_last_str, time.Second*60*60*18)
  1060. }
  1061. } else {
  1062. redis.Set(key, "null", time.Second*60*60*18)
  1063. }
  1064. return &record, nil
  1065. }
  1066. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1067. if assessment_after_dislysis_last_str == "null" {
  1068. return &record, nil
  1069. } else {
  1070. json.Unmarshal([]byte(assessment_after_dislysis_last_str), &record)
  1071. return &record, nil
  1072. }
  1073. }
  1074. }
  1075. func MobileGetLastTimeAssessmentAfterDislysisOne(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  1076. var record models.AssessmentAfterDislysis
  1077. 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
  1078. if err != nil {
  1079. if err == gorm.ErrRecordNotFound {
  1080. return nil, nil
  1081. } else {
  1082. return nil, err
  1083. }
  1084. }
  1085. return &record, nil
  1086. }
  1087. func MobileGetLastTimeAssessmentAfterDislysisTwo(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  1088. var record models.AssessmentAfterDislysis
  1089. 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
  1090. return &record, nil
  1091. }
  1092. func MobileGetLast(orgID int64, patientID int64, maxDate int64) (models.AssessmentAfterDislysis, error) {
  1093. dislysis := models.AssessmentAfterDislysis{}
  1094. 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
  1095. return dislysis, err
  1096. }
  1097. // 治疗小结
  1098. func MobileGetTreatmentSummary(orgID int64, patientID int64, recordDate int64) (*models.TreatmentSummary, error) {
  1099. var record models.TreatmentSummary
  1100. redis := RedisClient()
  1101. defer redis.Close()
  1102. // cur_date := time.Now().Format("2006-01-02")
  1103. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":treatment_summary"
  1104. treatment_summary_str, _ := redis.Get(key).Result()
  1105. if len(treatment_summary_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1106. err := readDb.Model(&models.TreatmentSummary{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  1107. if err != nil {
  1108. if err == gorm.ErrRecordNotFound {
  1109. if record.ID <= 0 {
  1110. redis.Set(key, "null", time.Second*60*60*18)
  1111. }
  1112. return nil, nil
  1113. } else {
  1114. return nil, err
  1115. }
  1116. } else {
  1117. if record.ID > 0 {
  1118. //缓存数据
  1119. treatment_summary_str, err := json.Marshal(record)
  1120. if err == nil {
  1121. redis.Set(key, treatment_summary_str, time.Second*60*60*18)
  1122. }
  1123. } else {
  1124. redis.Set(key, "null", time.Second*60*60*18)
  1125. }
  1126. return &record, nil
  1127. }
  1128. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1129. if treatment_summary_str == "null" {
  1130. return &record, nil
  1131. } else {
  1132. json.Unmarshal([]byte(treatment_summary_str), &record)
  1133. return &record, nil
  1134. }
  1135. }
  1136. }
  1137. // 透析处方
  1138. func MobileGetDialysisPrescribe(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  1139. var record models.DialysisPrescription
  1140. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).Find(&record).Error
  1141. if err != nil {
  1142. if err == gorm.ErrRecordNotFound {
  1143. return nil, nil
  1144. } else {
  1145. return nil, err
  1146. }
  1147. }
  1148. return &record, nil
  1149. }
  1150. func MobileGetDialysisPrescribeOne(orgID int64, patientID int64, recordDate int64) (models.DialysisPrescription, error) {
  1151. var record models.DialysisPrescription
  1152. err = readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).Find(&record).Error
  1153. return record, nil
  1154. }
  1155. func UpdateMobileGetDialysisPrescribe(id int64, dewater_amount float64) error {
  1156. err := XTWriteDB().Model(&models.DialysisPrescription{}).Where("id=? and status=1", id).Updates(map[string]interface{}{"target_ultrafiltration": dewater_amount, "prescription_water": dewater_amount}).Error
  1157. return err
  1158. }
  1159. func UpdateMobileGetDialysisPrescribeOne(id int64, dewater_amount float64) error {
  1160. err := XTWriteDB().Model(&models.DialysisPrescription{}).Where("id=? and status=1", id).Updates(map[string]interface{}{"target_ultrafiltration": dewater_amount}).Error
  1161. return err
  1162. }
  1163. func MobileGetDialysisSchedual(orgID int64, patientID int64, scheduleDate int64) (*models.XtSchedule, error) {
  1164. var schedule models.XtSchedule
  1165. err := readDb.Model(&models.XtSchedule{}).Where("patient_id = ? and user_org_id = ? and status = 1 and schedule_date = ?", patientID, orgID, scheduleDate).First(&schedule).Error
  1166. if err != nil {
  1167. if err == gorm.ErrRecordNotFound {
  1168. return nil, nil
  1169. } else {
  1170. return nil, err
  1171. }
  1172. }
  1173. return &schedule, nil
  1174. }
  1175. // 透析方案
  1176. func MobileGetDialysisSolution(orgID int64, patientID int64) (*models.DialysisSolution, error) {
  1177. var record models.DialysisSolution
  1178. err := readDb.Model(&models.DialysisSolution{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  1179. if err != nil {
  1180. if err == gorm.ErrRecordNotFound {
  1181. return nil, nil
  1182. } else {
  1183. return nil, err
  1184. }
  1185. }
  1186. return &record, nil
  1187. }
  1188. func MobileGetPatientById(orgID int64, patientID int64) (*models.Patients, error) {
  1189. var patient models.Patients
  1190. err := readDb.Model(&models.Patients{}).Where("id = ? and user_org_id = ? and status = 1", patientID, orgID).First(&patient).Error
  1191. if err != nil {
  1192. if err == gorm.ErrRecordNotFound {
  1193. return nil, nil
  1194. } else {
  1195. return nil, err
  1196. }
  1197. }
  1198. return &patient, nil
  1199. }
  1200. func DisableMonitor(orgID int64, patientID int64, recordID int64, admin_user_id int64) error {
  1201. fmt.Println()
  1202. tx := writeDb.Begin()
  1203. updateTime := time.Now().Unix()
  1204. 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
  1205. if err != nil {
  1206. tx.Rollback()
  1207. return err
  1208. }
  1209. tx.Commit()
  1210. return nil
  1211. }
  1212. func GetMonitorById(id int64, orgId int64) (models.MonitoringRecord, error) {
  1213. record := models.MonitoringRecord{}
  1214. err := XTReadDB().Where("id = ? and user_org_id =?", id, orgId).Find(&record).Error
  1215. return record, err
  1216. }
  1217. func GetMonitor(orgID int64, patientID int64, id int64) (*models.MonitoringRecord, error) {
  1218. var monitor models.MonitoringRecord
  1219. var err error
  1220. err = readDb.Model(&models.MonitoringRecord{}).Where("id = ? AND user_org_id = ? AND patient_id = ? AND status = 1 ", id, orgID, patientID).Find(&monitor).Error
  1221. if err == gorm.ErrRecordNotFound {
  1222. return nil, nil
  1223. }
  1224. if err != nil {
  1225. return nil, err
  1226. }
  1227. return &monitor, nil
  1228. }
  1229. type MScheduleDoctorAdviceVM struct {
  1230. ID int64 `gorm:"column:id" json:"id"`
  1231. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  1232. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  1233. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  1234. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1235. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  1236. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  1237. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  1238. Status int64 `gorm:"column:status" json:"status"`
  1239. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  1240. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  1241. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  1242. DoctorAdvices []*MDoctorAdviceVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  1243. Prescription *models.DialysisPrescriptionTwenty `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  1244. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  1245. }
  1246. func (MScheduleDoctorAdviceVM) TableName() string {
  1247. return "xt_schedule"
  1248. }
  1249. type MScheduleDoctorAdviceVMOne struct {
  1250. ID int64 `gorm:"column:id" json:"id"`
  1251. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  1252. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  1253. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  1254. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1255. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  1256. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  1257. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  1258. Status int64 `gorm:"column:status" json:"status"`
  1259. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  1260. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  1261. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  1262. DoctorAdvices []*MDoctorAdviceVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  1263. Prescription *models.DialysisPrescriptionTwenty `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  1264. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  1265. }
  1266. func (MScheduleDoctorAdviceVMOne) TableName() string {
  1267. return "xt_schedule"
  1268. }
  1269. type MDoctorAdviceVM struct {
  1270. ID int64 `gorm:"column:id" json:"id"`
  1271. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  1272. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1273. AdviceType int64 `gorm:"column:advice_type" json:"advice_type"`
  1274. AdviceDate int64 `gorm:"column:advice_date" json:"advice_date"`
  1275. StartTime int64 `gorm:"column:start_time" json:"start_time"`
  1276. AdviceName string `gorm:"column:advice_name" json:"advice_name"`
  1277. AdviceDesc string `gorm:"column:advice_desc" json:"advice_desc"`
  1278. ReminderDate int64 `gorm:"column:reminder_date" json:"reminder_date"`
  1279. SingleDose float64 `gorm:"column:single_dose" json:"single_dose"`
  1280. SingleDoseUnit string `gorm:"column:single_dose_unit" json:"single_dose_unit"`
  1281. PrescribingNumber float64 `gorm:"column:prescribing_number" json:"prescribing_number"`
  1282. PrescribingNumberUnit string `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit"`
  1283. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way"`
  1284. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency"`
  1285. AdviceDoctor int64 `gorm:"column:advice_doctor" json:"advice_doctor"`
  1286. Status int64 `gorm:"column:status" json:"status"`
  1287. CreatedTime int64 `gorm:"column:created_time" json:"created_time"`
  1288. UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time"`
  1289. AdviceAffirm string `gorm:"column:advice_affirm" json:"advice_affirm"`
  1290. Remark string `gorm:"column:remark" json:"remark"`
  1291. StopTime int64 `gorm:"column:stop_time" json:"stop_time"`
  1292. StopReason string `gorm:"column:stop_reason" json:"stop_reason"`
  1293. StopDoctor int64 `gorm:"column:stop_doctor" json:"stop_doctor"`
  1294. StopState int64 `gorm:"column:stop_state" json:"stop_state"`
  1295. ParentId int64 `gorm:"column:parent_id" json:"parent_id"`
  1296. ExecutionTime int64 `gorm:"column:execution_time" json:"execution_time"`
  1297. ExecutionStaff int64 `gorm:"column:execution_staff" json:"execution_staff"`
  1298. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state"`
  1299. Checker int64 `gorm:"column:checker" json:"checker"`
  1300. RecordDate int64 `gorm:"column:record_date" json:"record_date"`
  1301. DialysisOrderId int64 `gorm:"column:dialysis_order_id" json:"dialysis_order_id"`
  1302. CheckTime int64 `gorm:"column:check_time" json:"check_time"`
  1303. CheckState int64 `gorm:"column:check_state" json:"check_state"`
  1304. DrugSpec float64 `gorm:"column:drug_spec" json:"drug_spec"`
  1305. DrugSpecUnit string `gorm:"column:drug_spec_unit" json:"drug_spec_unit"`
  1306. Groupno int64 `gorm:"column:groupno" json:"groupno"`
  1307. RemindType int64 `gorm:"column:remind_type" json:"remind_type"`
  1308. FrequencyType int64 `gorm:"column:frequency_type" json:"frequency_type"`
  1309. DayCount int64 `gorm:"column:day_count" json:"day_count"`
  1310. WeekDay string `gorm:"column:week_day" json:"week_day"`
  1311. TemplateId string `gorm:"column:template_id" json:"template_id"`
  1312. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1313. IsMedicine int64 `gorm:"column:is_medicine" json:"is_medicine" form:"is_medicine"`
  1314. IsSettle int64 `gorm:"column:is_settle" json:"is_settle" form:"is_settle"`
  1315. }
  1316. func (MDoctorAdviceVM) TableName() string {
  1317. return "xt_doctor_advice"
  1318. }
  1319. func MobileGetScheduleDoctorAdvices(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string) ([]*MScheduleDoctorAdviceVM, error) {
  1320. var vms []*MScheduleDoctorAdviceVM
  1321. adviceWhere := ""
  1322. adviceCondition := []interface{}{}
  1323. if adviceType == 0 {
  1324. if patientType == 0 {
  1325. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  1326. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1327. } else if patientType == 1 {
  1328. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  1329. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1330. } else if patientType == 2 {
  1331. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  1332. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1333. }
  1334. } else if adviceType == 1 {
  1335. if patientType == 0 {
  1336. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  1337. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1338. } else if patientType == 1 {
  1339. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  1340. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1341. } else if patientType == 2 {
  1342. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  1343. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1344. }
  1345. } else if adviceType == 3 {
  1346. if patientType == 0 {
  1347. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  1348. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1349. } else if patientType == 1 {
  1350. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  1351. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1352. } else if patientType == 2 {
  1353. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  1354. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1355. }
  1356. } else if adviceType == 2 && len(deliverWay) > 0 {
  1357. if patientType == 0 {
  1358. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  1359. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1360. } else if patientType == 1 {
  1361. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  1362. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  1363. } else if patientType == 2 {
  1364. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  1365. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1366. }
  1367. } else if adviceType == 2 && len(deliverWay) <= 0 {
  1368. if patientType == 0 {
  1369. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  1370. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1371. } else if patientType == 1 {
  1372. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND (advice_doctor = ? or execution_staff = ?)"
  1373. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, adminUserId)
  1374. } else if patientType == 2 {
  1375. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  1376. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1377. }
  1378. }
  1379. db := readDb.
  1380. Table("xt_schedule").
  1381. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1382. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1383. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1384. }).
  1385. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1386. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1387. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1388. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  1389. Preload("DoctorAdvices", adviceCondition...).
  1390. Where("status = 1 AND user_org_id = ?", orgID)
  1391. if scheduleDate != 0 {
  1392. db = db.Where("schedule_date = ?", scheduleDate)
  1393. }
  1394. err := db.Find(&vms).Error
  1395. return vms, err
  1396. }
  1397. func MobileGetScheduleDoctorAdvicesTwo(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string) ([]*MScheduleDoctorAdviceVMOne, error) {
  1398. var vms []*MScheduleDoctorAdviceVMOne
  1399. adviceWhere := ""
  1400. adviceCondition := []interface{}{}
  1401. if adviceType == 0 {
  1402. if patientType == 0 {
  1403. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  1404. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1405. } else if patientType == 1 {
  1406. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  1407. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1408. } else if patientType == 2 {
  1409. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  1410. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1411. } else if patientType == 3 {
  1412. 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"
  1413. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1414. } else if patientType == 4 {
  1415. 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)"
  1416. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1417. }
  1418. } else if adviceType == 1 {
  1419. if patientType == 0 {
  1420. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  1421. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1422. } else if patientType == 1 {
  1423. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  1424. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1425. } else if patientType == 2 {
  1426. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  1427. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1428. } else if patientType == 3 {
  1429. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = 1"
  1430. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1431. } else if patientType == 4 {
  1432. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and (is_settle = 0 or is_settle = 2)"
  1433. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1434. }
  1435. } else if adviceType == 3 {
  1436. if patientType == 0 {
  1437. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  1438. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1439. } else if patientType == 1 {
  1440. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  1441. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1442. } else if patientType == 2 {
  1443. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  1444. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1445. } else if patientType == 3 {
  1446. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 and is_settle = 1"
  1447. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1448. } else if patientType == 4 {
  1449. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 and (is_settle = 0 or is_settle = 2)"
  1450. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1451. }
  1452. } else if adviceType == 2 && len(deliverWay) > 0 {
  1453. if patientType == 0 {
  1454. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  1455. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1456. } else if patientType == 1 {
  1457. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  1458. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  1459. } else if patientType == 2 {
  1460. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  1461. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1462. } else if patientType == 3 {
  1463. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 and delivery_way = ? and is_settle = 1"
  1464. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1465. } else if patientType == 4 {
  1466. 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)"
  1467. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1468. }
  1469. } else if adviceType == 2 && len(deliverWay) <= 0 {
  1470. if patientType == 0 {
  1471. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  1472. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1473. } else if patientType == 1 {
  1474. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND (advice_doctor = ? or execution_staff = ?)"
  1475. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, adminUserId)
  1476. } else if patientType == 2 {
  1477. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  1478. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1479. } else if patientType == 3 {
  1480. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 and is_settle = 1"
  1481. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1482. } else if patientType == 4 {
  1483. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 and (is_settle = 0 or is_settle = 2)"
  1484. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1485. }
  1486. }
  1487. db := readDb.
  1488. Table("xt_schedule").
  1489. //Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1490. //Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1491. // return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1492. //}).
  1493. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1494. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1495. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1496. Preload("DoctorAdvices", adviceCondition...).
  1497. Where("status = 1 AND user_org_id = ?", orgID)
  1498. if scheduleDate != 0 {
  1499. db = db.Where("schedule_date = ?", scheduleDate)
  1500. }
  1501. err := db.Find(&vms).Error
  1502. return vms, err
  1503. }
  1504. func GetHisDoctorAdvices(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleDoctorAdviceVM, error) {
  1505. var vms []*HisMScheduleDoctorAdviceVM
  1506. if len(deliverWay) > 0 {
  1507. if patientType == 0 {
  1508. db := readDb.
  1509. Table("xt_schedule").
  1510. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  1511. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1512. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1513. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1514. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1515. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1516. }).
  1517. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1518. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1519. Where("status = 1 AND user_org_id = ?", orgID)
  1520. if scheduleDate != 0 {
  1521. db = db.Where("schedule_date = ?", scheduleDate)
  1522. }
  1523. err = db.Find(&vms).Error
  1524. }
  1525. if patientType > 0 {
  1526. db := readDb.
  1527. Table("xt_schedule").
  1528. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1529. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1530. 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).
  1531. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1532. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1533. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1534. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1535. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1536. }).Where("status = 1 AND user_org_id = ?", orgID)
  1537. if scheduleDate != 0 {
  1538. db = db.Where("schedule_date = ?", scheduleDate)
  1539. }
  1540. err = db.Find(&vms).Error
  1541. }
  1542. } else {
  1543. if patientType == 0 {
  1544. db := readDb.
  1545. Table("xt_schedule").
  1546. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? ", orgID, scheduleDate).
  1547. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1548. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1549. return db.Where("status = 1 AND user_org_id = ? and dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1550. }).
  1551. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1552. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1553. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1554. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1555. Where("status = 1 AND user_org_id = ?", orgID)
  1556. if scheduleDate != 0 {
  1557. db = db.Where("schedule_date = ?", scheduleDate)
  1558. }
  1559. err = db.Find(&vms).Error
  1560. }
  1561. if patientType > 0 {
  1562. db := readDb.
  1563. Table("xt_schedule").
  1564. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1565. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1566. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1567. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1568. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1569. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1570. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1571. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1572. Where("status = 1 AND user_org_id = ?", orgID)
  1573. if scheduleDate != 0 {
  1574. db = db.Where("schedule_date = ?", scheduleDate)
  1575. }
  1576. err = db.Find(&vms).Error
  1577. }
  1578. }
  1579. return vms, err
  1580. }
  1581. func GetHisDoctorAdvicesTwo(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleDoctorAdviceVMOne, error) {
  1582. var vms []*HisMScheduleDoctorAdviceVMOne
  1583. if len(deliverWay) > 0 {
  1584. if patientType == 0 {
  1585. db := readDb.
  1586. Table("xt_schedule").
  1587. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  1588. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1589. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1590. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1591. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1592. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1593. }).
  1594. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1595. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1596. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1597. Where("status = 1 AND user_org_id = ?", orgID)
  1598. if scheduleDate != 0 {
  1599. db = db.Where("schedule_date = ?", scheduleDate)
  1600. }
  1601. err = db.Find(&vms).Error
  1602. }
  1603. if patientType > 0 {
  1604. if patientType == 1 {
  1605. db := readDb.
  1606. Table("xt_schedule").
  1607. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1608. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1609. 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).
  1610. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1611. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1612. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1613. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1614. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1615. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1616. Where("status = 1 AND user_org_id = ?", orgID)
  1617. if scheduleDate != 0 {
  1618. db = db.Where("schedule_date = ?", scheduleDate)
  1619. }
  1620. err = db.Find(&vms).Error
  1621. }
  1622. if patientType == 2 {
  1623. db := readDb.
  1624. Table("xt_schedule").
  1625. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1626. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1627. 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).
  1628. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1629. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1630. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1631. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1632. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1633. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Where("status = 1 AND user_org_id = ?", orgID)
  1634. if scheduleDate != 0 {
  1635. db = db.Where("schedule_date = ?", scheduleDate)
  1636. }
  1637. err = db.Find(&vms).Error
  1638. }
  1639. if patientType == 3 {
  1640. db := readDb.
  1641. Table("xt_schedule").
  1642. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1643. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1644. 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).
  1645. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1646. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1647. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1648. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1649. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1650. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Where("status = 1 AND user_org_id = ?", orgID)
  1651. if scheduleDate != 0 {
  1652. db = db.Where("schedule_date = ?", scheduleDate)
  1653. }
  1654. err = db.Find(&vms).Error
  1655. }
  1656. if patientType == 4 {
  1657. db := readDb.
  1658. Table("xt_schedule").
  1659. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1660. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1661. 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).
  1662. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1663. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1664. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1665. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1666. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1667. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Where("status = 1 AND user_org_id = ?", orgID)
  1668. if scheduleDate != 0 {
  1669. db = db.Where("schedule_date = ?", scheduleDate)
  1670. }
  1671. err = db.Find(&vms).Error
  1672. }
  1673. }
  1674. } else {
  1675. if patientType == 0 {
  1676. db := readDb.
  1677. Table("xt_schedule").
  1678. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? ", orgID, scheduleDate).
  1679. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1680. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1681. return db.Where("status = 1 AND user_org_id = ? and dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1682. }).
  1683. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1684. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1685. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1686. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1687. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1688. Where("status = 1 AND user_org_id = ?", orgID)
  1689. if scheduleDate != 0 {
  1690. db = db.Where("schedule_date = ?", scheduleDate)
  1691. }
  1692. err = db.Find(&vms).Error
  1693. }
  1694. if patientType > 0 {
  1695. if patientType == 1 {
  1696. db := readDb.
  1697. Table("xt_schedule").
  1698. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1699. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1700. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1701. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1702. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1703. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1704. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1705. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1706. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1707. Where("status = 1 AND user_org_id = ?", orgID)
  1708. if scheduleDate != 0 {
  1709. db = db.Where("schedule_date = ?", scheduleDate)
  1710. }
  1711. err = db.Find(&vms).Error
  1712. }
  1713. if patientType == 2 {
  1714. db := readDb.
  1715. Table("xt_schedule").
  1716. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1717. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1718. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1719. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1720. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1721. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1722. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1723. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1724. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1725. Where("status = 1 AND user_org_id = ?", orgID)
  1726. if scheduleDate != 0 {
  1727. db = db.Where("schedule_date = ?", scheduleDate)
  1728. }
  1729. err = db.Find(&vms).Error
  1730. }
  1731. if patientType == 3 {
  1732. db := readDb.
  1733. Table("xt_schedule").
  1734. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1735. 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).
  1736. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1737. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1738. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1739. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1740. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1741. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1742. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1743. Where("status = 1 AND user_org_id = ?", orgID)
  1744. if scheduleDate != 0 {
  1745. db = db.Where("schedule_date = ?", scheduleDate)
  1746. }
  1747. err = db.Find(&vms).Error
  1748. }
  1749. if patientType == 4 {
  1750. db := readDb.
  1751. Table("xt_schedule").
  1752. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1753. 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).
  1754. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1755. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1756. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1757. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1758. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1759. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1760. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1761. Where("status = 1 AND user_org_id = ?", orgID)
  1762. if scheduleDate != 0 {
  1763. db = db.Where("schedule_date = ?", scheduleDate)
  1764. }
  1765. err = db.Find(&vms).Error
  1766. }
  1767. }
  1768. }
  1769. return vms, err
  1770. }
  1771. func GetMobileHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleProjectVM, error) {
  1772. var vms []*HisMScheduleProjectVM
  1773. //if patientType == 0 {
  1774. // db := readDb.
  1775. // Table("xt_schedule").
  1776. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1777. // Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1778. // return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1779. // }).
  1780. // Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1781. // Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1782. // Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1783. // Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1784. // return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1785. // }).
  1786. // Where("status = 1 AND user_org_id = ?", orgID)
  1787. // if scheduleDate != 0 {
  1788. // db = db.Where("schedule_date = ?", scheduleDate)
  1789. // }
  1790. // err = db.Find(&vms).Error
  1791. //}
  1792. //if patientType > 0 {
  1793. // db := readDb.
  1794. // Table("xt_schedule").
  1795. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1796. // Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1797. // return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1798. // }).
  1799. // Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1800. // Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1801. // Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1802. // Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1803. // Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1804. // return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1805. // }).
  1806. // Where("status = 1 AND user_org_id = ?", orgID)
  1807. // if scheduleDate != 0 {
  1808. // db = db.Where("schedule_date = ?", scheduleDate)
  1809. // }
  1810. // err = db.Find(&vms).Error
  1811. //}
  1812. db := readDb.Table("xt_schedule").Where("status = 1")
  1813. if orgID > 0 {
  1814. db = db.Where("user_org_id = ?", orgID)
  1815. }
  1816. if scheduleDate > 0 {
  1817. db = db.Where("schedule_date =?", scheduleDate)
  1818. }
  1819. err = db.Find(&vms).Error
  1820. if patientType == 0 {
  1821. db := readDb.
  1822. Table("xt_schedule").
  1823. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1824. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1825. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1826. }).
  1827. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1828. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1829. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1830. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1831. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1832. }).
  1833. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  1834. 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")
  1835. }).
  1836. Where("status = 1 AND user_org_id = ?", orgID)
  1837. if scheduleDate != 0 {
  1838. db = db.Where("schedule_date = ?", scheduleDate)
  1839. }
  1840. err = db.Find(&vms).Error
  1841. }
  1842. if patientType > 0 {
  1843. db := readDb.
  1844. Table("xt_schedule").
  1845. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1846. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1847. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1848. }).
  1849. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1850. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1851. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1852. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1853. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1854. }).
  1855. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  1856. 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")
  1857. }).
  1858. Where("status = 1 AND user_org_id = ?", orgID)
  1859. if scheduleDate != 0 {
  1860. db = db.Where("schedule_date = ?", scheduleDate)
  1861. }
  1862. err = db.Find(&vms).Error
  1863. }
  1864. return vms, err
  1865. }
  1866. func MobileCreateDialysisOrder(orgID int64, patientID int64, order *models.DialysisOrder) error {
  1867. now := time.Now()
  1868. tx := writeDb.Begin()
  1869. if createOrderErr := tx.Model(&models.DialysisOrder{}).Create(order).Error; createOrderErr != nil {
  1870. tx.Rollback()
  1871. return createOrderErr
  1872. }
  1873. // 更新透析记录 ID
  1874. // 透析处方
  1875. 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 {
  1876. tx.Rollback()
  1877. return err
  1878. }
  1879. // 接诊评估
  1880. 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 {
  1881. tx.Rollback()
  1882. return err
  1883. }
  1884. // 透前评估
  1885. 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 {
  1886. tx.Rollback()
  1887. return err
  1888. }
  1889. // 临时医嘱
  1890. 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 {
  1891. tx.Rollback()
  1892. return err
  1893. }
  1894. // 双人核对
  1895. 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 {
  1896. tx.Rollback()
  1897. return err
  1898. }
  1899. // 透后评估
  1900. 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 {
  1901. tx.Rollback()
  1902. return err
  1903. }
  1904. // 治疗小结
  1905. 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 {
  1906. tx.Rollback()
  1907. return err
  1908. }
  1909. // 透析监测
  1910. 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 {
  1911. tx.Rollback()
  1912. return err
  1913. }
  1914. tx.Commit()
  1915. return nil
  1916. }
  1917. type MobileUrgentSchedulePatientVM struct {
  1918. ID int64 `gorm:"column:id" json:"id"`
  1919. Name string `gorm:"column:name" json:"name"`
  1920. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no"`
  1921. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  1922. }
  1923. func (MobileUrgentSchedulePatientVM) TableName() string {
  1924. return "xt_patients"
  1925. }
  1926. type MobileUrgentScheduleTreatmentModeVM struct {
  1927. ID int64 `gorm:"column:id" json:"id"`
  1928. Name string `gorm:"column:name" json:"name"`
  1929. }
  1930. func (MobileUrgentScheduleTreatmentModeVM) TableName() string {
  1931. return "xt_treatment_mode"
  1932. }
  1933. func MobileGetAllPatientsForUrgentSchedule(orgID int64, record_date int64) ([]*MobileUrgentSchedulePatientVM, error) {
  1934. var vms []*MobileUrgentSchedulePatientVM = make([]*MobileUrgentSchedulePatientVM, 0)
  1935. 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()
  1936. defer rows.Close()
  1937. if err != nil {
  1938. return nil, err
  1939. }
  1940. for rows.Next() {
  1941. var vm MobileUrgentSchedulePatientVM
  1942. readDb.ScanRows(rows, &vm)
  1943. vms = append(vms, &vm)
  1944. }
  1945. return vms, nil
  1946. }
  1947. func MobileGetAllTrearmentModesForUrgentSchedule() ([]*MobileUrgentScheduleTreatmentModeVM, error) {
  1948. var modes []*MobileUrgentScheduleTreatmentModeVM
  1949. err := readDb.Model(&MobileUrgentScheduleTreatmentModeVM{}).Where("status = 1").Find(&modes).Error
  1950. if err != nil {
  1951. return nil, err
  1952. }
  1953. return modes, nil
  1954. }
  1955. type MobileUrgentScheduleScheduleListVM struct {
  1956. ID int64 `gorm:"column:id" json:"id"`
  1957. // ZoneID int64 `gorm:"column:partition_id" json:"zone_id"`
  1958. DeviceNumberID int64 `gorm:"column:bed_id" json:"bed_id"`
  1959. PatientID int64 `gorm:"column:patient_id" json:"patient_id"`
  1960. ScheduleType int `gorm:"column:schedule_type" json:"schedule_type"`
  1961. DeviceNumber *models.DeviceNumber `gorm:"ForeignKey:DeviceNumberID" json:"device_number"`
  1962. // DeviceZone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"device_zone"`
  1963. }
  1964. func (MobileUrgentScheduleScheduleListVM) TableName() string {
  1965. return "xt_schedule"
  1966. }
  1967. func MobileGetSchedulesForUrgentSchedule(orgID int64, scheduleDate int64, schedule_type int) (schedules []*MobileUrgentScheduleScheduleListVM, err error) {
  1968. db := readDb.
  1969. Model(&MobileUrgentScheduleScheduleListVM{}).
  1970. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1971. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND schedule_type = ? ", orgID, scheduleDate, schedule_type)
  1972. err = db.Find(&schedules).Error
  1973. if err != nil {
  1974. return nil, err
  1975. }
  1976. return schedules, nil
  1977. }
  1978. func MobileGetOtherSchedulesForUrgentSchedule(orgID int64, scheduleDate int64, schedule_type int) ([]*MobileUrgentScheduleScheduleListVM, error) {
  1979. var vms []*MobileUrgentScheduleScheduleListVM = make([]*MobileUrgentScheduleScheduleListVM, 0)
  1980. 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()
  1981. defer rows.Close()
  1982. if err != nil {
  1983. return nil, err
  1984. }
  1985. for rows.Next() {
  1986. var vm MobileUrgentScheduleScheduleListVM
  1987. readDb.ScanRows(rows, &vm)
  1988. vms = append(vms, &vm)
  1989. }
  1990. return vms, nil
  1991. }
  1992. type MobileUrgentScheduleDeviceNumberVM struct {
  1993. ID int64 `gorm:"column:id" json:"id"`
  1994. Number string `gorm:"column:number" json:"number"`
  1995. ZoneID int64 `gorm:"column:zone_id" json:"zone_id"`
  1996. Zone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"zone"`
  1997. }
  1998. func (MobileUrgentScheduleDeviceNumberVM) TableName() string {
  1999. return "xt_device_number"
  2000. }
  2001. func MobileGetAllDeviceNumbersForUrgentSchedule(orgID int64, record_date int64, schedule_type int) ([]*DeviceNumberViewModel, error) {
  2002. var vms []*DeviceNumberViewModel = make([]*DeviceNumberViewModel, 0)
  2003. 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()
  2004. defer rows.Close()
  2005. if err != nil {
  2006. return nil, err
  2007. }
  2008. for rows.Next() {
  2009. var vm DeviceNumberViewModel
  2010. readDb.ScanRows(rows, &vm)
  2011. vms = append(vms, &vm)
  2012. }
  2013. return vms, nil
  2014. //var deviceNumbers []*MobileUrgentScheduleDeviceNumberVM
  2015. //db := readDb.
  2016. // Model(&MobileUrgentScheduleDeviceNumberVM{}).
  2017. // Preload("Zone", "status = 1 AND org_id = ?", orgID).
  2018. // Where("status = 1 AND org_id = ?", orgID)
  2019. //err := db.Order("zone_id asc").Find(&deviceNumbers).Error
  2020. //if err != nil {
  2021. // return nil, err
  2022. //}
  2023. //return deviceNumbers, nil
  2024. }
  2025. func GetValidScheduleMonitorRecordCount() (int64, error) {
  2026. var total int64
  2027. err := readDb.Model(&models.MonitoringRecord{}).Where("status = 1 AND operate_time = 0 AND monitoring_date <> 0").Count(&total).Error
  2028. return total, err
  2029. }
  2030. func GetTop1000ValidScheduleMonitorRecord() ([]*models.MonitoringRecord, error) {
  2031. var monitors []*models.MonitoringRecord
  2032. err := readDb.Model(&models.MonitoringRecord{}).Where("status = 1 AND operate_time = 0 AND monitoring_date <> 0").Order("id asc").Limit(100).Find(&monitors).Error
  2033. if err != nil {
  2034. return nil, err
  2035. }
  2036. return monitors, nil
  2037. }
  2038. func BatchUpdateMonitors(monitors []*models.MonitoringRecord) error {
  2039. tx := writeDb.Begin()
  2040. for index := 0; index < len(monitors); index++ {
  2041. tx.Save(monitors[index])
  2042. }
  2043. return tx.Commit().Error
  2044. }
  2045. func ModifyStartDialysisOrder(order *models.DialysisOrder) error {
  2046. tx := writeDb.Begin()
  2047. updateTime := time.Now().Unix()
  2048. 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
  2049. if err != nil {
  2050. tx.Rollback()
  2051. return err
  2052. }
  2053. tx.Commit()
  2054. return err
  2055. }
  2056. func UpdateScheduleByBedId(patient_id int64, schedule_date int64, bed_id int64, schedule_type int64, zone_id int64) error {
  2057. 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
  2058. return err
  2059. }
  2060. func ModifyFinishDialysisOrder(order *models.DialysisOrder) error {
  2061. tx := writeDb.Begin()
  2062. updateTime := time.Now().Unix()
  2063. 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
  2064. if err != nil {
  2065. tx.Rollback()
  2066. return err
  2067. }
  2068. tx.Commit()
  2069. return err
  2070. }
  2071. func MobileGetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  2072. var record models.SgjPatientDryweight
  2073. err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  2074. if err != nil {
  2075. if err == gorm.ErrRecordNotFound {
  2076. return nil, nil
  2077. } else {
  2078. return nil, err
  2079. }
  2080. }
  2081. return &record, nil
  2082. }
  2083. //func MobileGetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  2084. // var record models.SgjPatientDryweight
  2085. // redis := RedisClient()
  2086. // defer redis.Close()
  2087. //
  2088. // key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":last_dry_weight"
  2089. // last_dry_weight_str, _ := redis.Get(key).Result()
  2090. //
  2091. // if len(last_dry_weight_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2092. // err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  2093. // if err != nil {
  2094. // if err == gorm.ErrRecordNotFound {
  2095. // if record.ID <= 0 {
  2096. // redis.Set(key, "null", time.Second*60*60*18)
  2097. // }
  2098. // return nil, nil
  2099. // } else {
  2100. // return nil, err
  2101. // }
  2102. // } else {
  2103. // if record.ID > 0 {
  2104. // //缓存数据
  2105. // last_dry_weight_str, err := json.Marshal(record)
  2106. // if err == nil {
  2107. // redis.Set(key, last_dry_weight_str, time.Second*60*60*18)
  2108. // return nil, err
  2109. // }
  2110. // } else {
  2111. // redis.Set(key, "null", time.Second*60*60*18)
  2112. // return nil, err
  2113. // }
  2114. // return &record, nil
  2115. // }
  2116. // } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2117. // if last_dry_weight_str == "null" {
  2118. // return &record, nil
  2119. // } else {
  2120. // json.Unmarshal([]byte(last_dry_weight_str), &record)
  2121. // return &record, nil
  2122. // }
  2123. //
  2124. // }
  2125. //}
  2126. // 透析方案
  2127. func MobileGetDialysisSolutionByModeIdSix(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  2128. var record models.DialysisSolution
  2129. 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
  2130. if err != nil {
  2131. if err == gorm.ErrRecordNotFound {
  2132. return nil, nil
  2133. } else {
  2134. return nil, err
  2135. }
  2136. }
  2137. return &record, nil
  2138. }
  2139. // 透析方案
  2140. func MobileGetDialysisSolutionByModeIdSevenTwety(orgID int64, patientID int64, mode_id int64) (models.DialysisSolution, error) {
  2141. var record models.DialysisSolution
  2142. 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
  2143. return record, nil
  2144. }
  2145. // 透析方案
  2146. func MobileGetDialysisSolutionByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  2147. var record models.DialysisSolution
  2148. redis := RedisClient()
  2149. defer redis.Close()
  2150. // cur_date := time.Now().Format("2006-01-02")
  2151. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2152. dialysis_solution_str, _ := redis.Get(key).Result()
  2153. redis.Set(key, "", time.Second*60)
  2154. if len(dialysis_solution_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2155. 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
  2156. if err != nil {
  2157. if err == gorm.ErrRecordNotFound {
  2158. if record.ID <= 0 {
  2159. redis.Set(key, "null", time.Second*60*60*18)
  2160. }
  2161. return nil, nil
  2162. } else {
  2163. return nil, err
  2164. }
  2165. } else {
  2166. if record.ID > 0 {
  2167. //缓存数据
  2168. dialysis_solution_str, err := json.Marshal(record)
  2169. if err == nil {
  2170. redis.Set(key, dialysis_solution_str, time.Second*60*60*18)
  2171. }
  2172. } else {
  2173. redis.Set(key, "null", time.Second*60*60*18)
  2174. }
  2175. return &record, nil
  2176. }
  2177. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2178. if dialysis_solution_str == "null" {
  2179. return &record, nil
  2180. } else {
  2181. json.Unmarshal([]byte(dialysis_solution_str), &record)
  2182. return &record, nil
  2183. }
  2184. }
  2185. }
  2186. // 透析处方
  2187. func MobileGetDialysisPrescribeByModeId(orgID int64, patientID int64, recordDate int64, mode_id int64) (*models.DialysisPrescription, error) {
  2188. var record models.DialysisPrescription
  2189. redis := RedisClient()
  2190. defer redis.Close()
  2191. // cur_date := time.Now().Format("2006-01-02")
  2192. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2193. redis.Set(key, "", time.Second)
  2194. dialysis_prescribe_str, _ := redis.Get(key).Result()
  2195. if len(dialysis_prescribe_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2196. 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
  2197. if err != nil {
  2198. if err == gorm.ErrRecordNotFound {
  2199. if record.ID <= 0 {
  2200. redis.Set(key, "null", time.Second*60*60*18)
  2201. }
  2202. return nil, nil
  2203. } else {
  2204. return nil, err
  2205. }
  2206. } else {
  2207. if record.ID > 0 {
  2208. //缓存数据
  2209. dialysis_prescribe_str, err := json.Marshal(record)
  2210. if err == nil {
  2211. redis.Set(key, dialysis_prescribe_str, time.Second*60*60*18)
  2212. }
  2213. } else {
  2214. redis.Set(key, "null", time.Second*60*60*18)
  2215. }
  2216. return &record, nil
  2217. }
  2218. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2219. if dialysis_prescribe_str == "null" {
  2220. return &record, nil
  2221. } else {
  2222. json.Unmarshal([]byte(dialysis_prescribe_str), &record)
  2223. return &record, nil
  2224. }
  2225. }
  2226. }
  2227. func MobileGetDialysisPrescribeByModeIdSix(orgID int64, patientID int64, recordDate int64, mode_id int64) (*models.DialysisPrescription, error) {
  2228. var record models.DialysisPrescription
  2229. 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
  2230. if err != nil {
  2231. if err == gorm.ErrRecordNotFound {
  2232. return nil, nil
  2233. } else {
  2234. return nil, err
  2235. }
  2236. }
  2237. return &record, nil
  2238. }
  2239. func MobileGetDialysisPrescribeByModeIdOne(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  2240. var record models.DialysisPrescription
  2241. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  2242. if err != nil {
  2243. if err == gorm.ErrRecordNotFound {
  2244. return nil, nil
  2245. } else {
  2246. return nil, err
  2247. }
  2248. }
  2249. return &record, nil
  2250. }
  2251. //func MobileGetDialysisPrescribeByModeIdOne(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  2252. // var record models.DialysisPrescription
  2253. // redis := RedisClient()
  2254. // defer redis.Close()
  2255. //
  2256. // // cur_date := time.Now().Format("2006-01-02")
  2257. // key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":dialysis_prescribe_by_mode"
  2258. // dialysis_prescribe_by_mode_str, _ := redis.Get(key).Result()
  2259. //
  2260. // if len(dialysis_prescribe_by_mode_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2261. // err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  2262. // if err != nil {
  2263. // if err == gorm.ErrRecordNotFound {
  2264. // if record.ID <= 0 {
  2265. // redis.Set(key, "null", time.Second*60*60*18)
  2266. // }
  2267. // return nil, nil
  2268. // } else {
  2269. // return nil, err
  2270. // }
  2271. // } else {
  2272. //
  2273. // if record.ID > 0 {
  2274. // //缓存数据
  2275. // dialysis_prescribe_by_mode_str, err := json.Marshal(record)
  2276. //
  2277. // if err == nil {
  2278. // redis.Set(key, dialysis_prescribe_by_mode_str, time.Second*60*60*18)
  2279. // return nil, err
  2280. // }
  2281. // } else {
  2282. // redis.Set(key, "null", time.Second*60*60*18)
  2283. // return nil, err
  2284. // }
  2285. // return &record, nil
  2286. // }
  2287. // } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2288. // if dialysis_prescribe_by_mode_str == "null" {
  2289. // json.Unmarshal([]byte(dialysis_prescribe_by_mode_str), &record)
  2290. // return &record, nil
  2291. // } else {
  2292. // json.Unmarshal([]byte(dialysis_prescribe_by_mode_str), &record)
  2293. // return &record, nil
  2294. // }
  2295. //
  2296. // }
  2297. //}
  2298. func MobileGetLastDialysisPrescribe(orgID int64, patientID int64) (*models.DialysisPrescription, error) {
  2299. var record models.DialysisPrescription
  2300. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 ", patientID, orgID).Last(&record).Error
  2301. if err != nil {
  2302. if err == gorm.ErrRecordNotFound {
  2303. return nil, nil
  2304. } else {
  2305. return nil, err
  2306. }
  2307. }
  2308. return &record, nil
  2309. }
  2310. func MobileGetLastDialysisPrescribeByModeIdSix(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2311. var record models.DialysisPrescription
  2312. 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
  2313. //if err != nil {
  2314. // if err == gorm.ErrRecordNotFound {
  2315. // return nil, nil
  2316. // } else {
  2317. // return nil, err
  2318. // }
  2319. //}
  2320. return &record, err
  2321. }
  2322. func MobileGetLastDialysisPrescribeByModeIdTen(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2323. var record models.DialysisPrescription
  2324. 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
  2325. if err != nil {
  2326. if err == gorm.ErrRecordNotFound {
  2327. return nil, nil
  2328. } else {
  2329. return nil, err
  2330. }
  2331. }
  2332. return &record, err
  2333. }
  2334. func MobileGetLastDialysisPrescribeByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2335. var record models.DialysisPrescription
  2336. redis := RedisClient()
  2337. defer redis.Close()
  2338. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  2339. dialysis_prescribe_by_mode_id, _ := redis.Get(key).Result()
  2340. if len(dialysis_prescribe_by_mode_id) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2341. 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
  2342. if err != nil {
  2343. if err == gorm.ErrRecordNotFound {
  2344. if record.ID <= 0 {
  2345. redis.Set(key, "null", time.Second*60*60*18)
  2346. }
  2347. return nil, nil
  2348. } else {
  2349. return nil, err
  2350. }
  2351. } else {
  2352. if record.ID > 0 {
  2353. //缓存数据
  2354. dialysis_prescribe_by_mode_str, err := json.Marshal(record)
  2355. if err == nil {
  2356. redis.Set(key, dialysis_prescribe_by_mode_str, time.Second*60*60*18)
  2357. return nil, err
  2358. }
  2359. } else {
  2360. redis.Set(key, "null", time.Second*60*60*18)
  2361. return nil, err
  2362. }
  2363. return &record, nil
  2364. }
  2365. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2366. if dialysis_prescribe_by_mode_id == "null" {
  2367. return &record, nil
  2368. } else {
  2369. json.Unmarshal([]byte(dialysis_prescribe_by_mode_id), &record)
  2370. return &record, nil
  2371. }
  2372. }
  2373. }
  2374. func MobileGetLastDialysisPrescribeByModeIdOne(orgID int64, patientID int64, mode_id int64) (models.DialysisPrescription, error) {
  2375. var record models.DialysisPrescription
  2376. 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
  2377. return record, err
  2378. }
  2379. func GetAllAvaildDeviceNumbers(orgID int64, record_date int64, schedule_type int) ([]*DeviceNumberViewModel, error) {
  2380. var vms []*DeviceNumberViewModel = make([]*DeviceNumberViewModel, 0)
  2381. 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()
  2382. defer rows.Close()
  2383. if err != nil {
  2384. return nil, err
  2385. }
  2386. for rows.Next() {
  2387. var vm DeviceNumberViewModel
  2388. readDb.ScanRows(rows, &vm)
  2389. vms = append(vms, &vm)
  2390. }
  2391. return vms, nil
  2392. }
  2393. // 获取 maxDate 之前一次的透前评估记录
  2394. func GetLastTimePredialysisEvaluation(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
  2395. var record models.PredialysisEvaluation
  2396. 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
  2397. if err != nil {
  2398. if err == gorm.ErrRecordNotFound {
  2399. return nil, nil
  2400. } else {
  2401. return nil, err
  2402. }
  2403. }
  2404. return &record, nil
  2405. }
  2406. func GetLastTimeOrder(orgID int64, patientID int64, maxDate int64) (*models.DialysisOrder, error) {
  2407. var record models.DialysisOrder
  2408. 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
  2409. if err != nil {
  2410. if err == gorm.ErrRecordNotFound {
  2411. return nil, nil
  2412. } else {
  2413. return nil, err
  2414. }
  2415. }
  2416. return &record, nil
  2417. }
  2418. func GetLastMonitorRecord(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  2419. var record models.MonitoringRecord
  2420. 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
  2421. if err != nil {
  2422. if err == gorm.ErrRecordNotFound {
  2423. return nil, nil
  2424. } else {
  2425. return nil, err
  2426. }
  2427. }
  2428. return &record, nil
  2429. }
  2430. func GetLastMonitorRecordTwenty(orgID int64, patientID int64, beforeDate int64) (models.MonitoringRecord, error) {
  2431. var record models.MonitoringRecord
  2432. 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
  2433. return record, nil
  2434. }
  2435. func GetLastMonitorRecordTwentyOne(orgID int64, patientID int64, beforeDate int64) (models.MonitoringRecord, error) {
  2436. var record models.MonitoringRecord
  2437. 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
  2438. return record, nil
  2439. }
  2440. func GetLastMonitorRecordTwentyTwo(orgID int64, patientID int64, beforeDate int64) (models.MonitoringRecord, error) {
  2441. var record models.MonitoringRecord
  2442. 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
  2443. return record, nil
  2444. }
  2445. func GetLastMonitorRecordTwentyThree(orgID int64, patientID int64, beforeDate int64) (models.MonitoringRecord, error) {
  2446. var record models.MonitoringRecord
  2447. 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
  2448. return record, nil
  2449. }
  2450. func GetLastMonitorRecordTwentyFour(orgID int64, patientID int64, beforeDate int64) (models.MonitoringRecord, error) {
  2451. var record models.MonitoringRecord
  2452. 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
  2453. return record, nil
  2454. }
  2455. // 获取 maxDate 之前一次的透后评估记录
  2456. func GetLastTimeAssessmentAfterDislysis(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  2457. var record models.AssessmentAfterDislysis
  2458. 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
  2459. if err != nil {
  2460. if err == gorm.ErrRecordNotFound {
  2461. return nil, nil
  2462. } else {
  2463. return nil, err
  2464. }
  2465. }
  2466. return &record, nil
  2467. }
  2468. // 透析处方
  2469. func GetDialysisPrescribe(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  2470. var record models.DialysisPrescription
  2471. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  2472. if err != nil {
  2473. if err == gorm.ErrRecordNotFound {
  2474. return nil, nil
  2475. } else {
  2476. return nil, err
  2477. }
  2478. }
  2479. return &record, nil
  2480. }
  2481. func GetDialysisPrescribeOne(orgID int64, patientID int64, recordDate int64) (models.DialysisPrescription, error) {
  2482. var record models.DialysisPrescription
  2483. err = readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  2484. return record, err
  2485. }
  2486. // 透析方案
  2487. func GetDialysisSolution(orgID int64, patientID int64, mode_id int64) (models.DialysisSolution, error) {
  2488. var record models.DialysisSolution
  2489. 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
  2490. return record, err
  2491. }
  2492. func GetDialysisSolutionOne(orgID int64, mode_id int64) (*models.DialysisSolution, error) {
  2493. var record models.DialysisSolution
  2494. err := readDb.Model(&models.DialysisSolution{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2495. if err != nil {
  2496. if err == gorm.ErrRecordNotFound {
  2497. return nil, nil
  2498. } else {
  2499. return nil, err
  2500. }
  2501. }
  2502. return &record, nil
  2503. }
  2504. func GetLastDialysisPrescribeByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2505. var record models.DialysisPrescription
  2506. 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
  2507. if err != nil {
  2508. if err == gorm.ErrRecordNotFound {
  2509. return nil, nil
  2510. } else {
  2511. return nil, err
  2512. }
  2513. }
  2514. return &record, nil
  2515. }
  2516. func GetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  2517. var record models.SgjPatientDryweight
  2518. err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  2519. if err != nil {
  2520. if err == gorm.ErrRecordNotFound {
  2521. return nil, nil
  2522. } else {
  2523. return nil, err
  2524. }
  2525. }
  2526. return &record, nil
  2527. }
  2528. func MobileGetSystemDialysisPrescribeByModeIdSix(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2529. var record models.SystemPrescription
  2530. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).First(&record).Error
  2531. if err != nil {
  2532. if err == gorm.ErrRecordNotFound {
  2533. return nil, nil
  2534. } else {
  2535. return nil, err
  2536. }
  2537. }
  2538. return &record, nil
  2539. }
  2540. func MobileGetSystemDialysisPrescribeByModeId(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2541. var record models.SystemPrescription
  2542. redis := RedisClient()
  2543. defer redis.Close()
  2544. // cur_date := time.Now().Format("2006-01-02")
  2545. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  2546. system_dialysis_prescribe_str, _ := redis.Get(key).Result()
  2547. if len(system_dialysis_prescribe_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2548. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2549. if err != nil {
  2550. if err == gorm.ErrRecordNotFound {
  2551. if record.ID <= 0 {
  2552. redis.Set(key, "null", time.Second*60*60*18)
  2553. }
  2554. return nil, nil
  2555. } else {
  2556. return nil, err
  2557. }
  2558. } else {
  2559. if record.ID > 0 {
  2560. //缓存数据
  2561. system_dialysis_prescribe_str, err := json.Marshal(record)
  2562. if err == nil {
  2563. redis.Set(key, system_dialysis_prescribe_str, time.Second*60*60*18)
  2564. }
  2565. } else {
  2566. redis.Set(key, "null", time.Second*60*60*18)
  2567. }
  2568. return &record, nil
  2569. }
  2570. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2571. if system_dialysis_prescribe_str == "null" {
  2572. return &record, nil
  2573. } else {
  2574. json.Unmarshal([]byte(system_dialysis_prescribe_str), &record)
  2575. return &record, nil
  2576. }
  2577. }
  2578. }
  2579. func MobileGetSystemDialysisPrescribeByModeIdOne(orgID int64, mode_id int64) (models.SystemPrescription, error) {
  2580. var record models.SystemPrescription
  2581. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2582. return record, err
  2583. }
  2584. func GetSystemDialysisPrescribeByModeId(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2585. var record models.SystemPrescription
  2586. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2587. if err != nil {
  2588. if err == gorm.ErrRecordNotFound {
  2589. return nil, nil
  2590. } else {
  2591. return nil, err
  2592. }
  2593. }
  2594. return &record, nil
  2595. }
  2596. func GetDialysisOrderCount(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2597. 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
  2598. return
  2599. }
  2600. func GetDialysisOrderCountOne(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2601. 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
  2602. return
  2603. }
  2604. func GetDialysisOrderCountTwo(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2605. 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
  2606. return
  2607. }
  2608. func GetFirstDateOfMonth(d time.Time) time.Time {
  2609. d = d.AddDate(0, 0, -d.Day()+1)
  2610. return GetZeroTime(d)
  2611. }
  2612. func GetZeroTime(d time.Time) time.Time {
  2613. return time.Date(d.Year(), d.Month(), d.Day(), 0, 0, 0, 0, d.Location())
  2614. }
  2615. func GetDialysisCountByPatientId(startime int64, endtime int64, patientid int64, orgid int64) (order []*models.BloodDialysisOrderCount, err error) {
  2616. db := XTReadDB().Table("xt_dialysis_order as o")
  2617. 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
  2618. return order, err
  2619. }
  2620. func FindConsumablesByDate(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error) {
  2621. 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
  2622. return
  2623. }
  2624. func FindConsumablesByDateTwo(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error) {
  2625. 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
  2626. return
  2627. }
  2628. func FindConsumablesByDateThree(orgID int64, patient_id int64, recordDate int64) (consumables []*models.BloodAutomaticReduceDetail, err error) {
  2629. 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
  2630. return
  2631. }
  2632. func FindHisPrescription(orgID int64, patient_id int64, recordDate int64) (project []*models.HisPrescriptionProject, err error) {
  2633. 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
  2634. return
  2635. }
  2636. //func FindLastConsumables(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error){
  2637. // 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
  2638. // return
  2639. //}
  2640. //
  2641. func GetLastTimeConsumables(orgID int64, patientID int64, maxDate int64) (prepare []*models.DialysisBeforePrepare, err error) {
  2642. 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
  2643. return
  2644. }
  2645. type GoodsType struct {
  2646. ID int64 `gorm:"column:id" json:"id"`
  2647. TypeName string `gorm:"column:type_name" json:"type_name"`
  2648. Remark string `gorm:"column:remark" json:"remark"`
  2649. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2650. Status int64 `gorm:"column:status" json:"status"`
  2651. Type int64 `gorm:"column:type" json:"type"`
  2652. }
  2653. func (GoodsType) TableName() string {
  2654. return "xt_goods_type"
  2655. }
  2656. type VMGoodInfo struct {
  2657. ID int64 `gorm:"column:id" json:"id"`
  2658. SpecificationName string `gorm:"column:specification_name" json:"specification_name"`
  2659. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2660. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2661. GoodName string `gorm:"column:good_name" json:"good_name" form:"good_name"`
  2662. GoodUnit int64 `gorm:"column:good_unit" json:"good_unit" form:"good_unit"`
  2663. Total float64 `gorm:"column:total" json:"total" form:"total"`
  2664. PackingUnit string `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
  2665. MedicalInsuranceNumber string `gorm:"column:medical_insurance_number" json:"medical_insurance_number" form:"medical_insurance_number"`
  2666. }
  2667. func (VMGoodInfo) TableName() string {
  2668. return "xt_good_information"
  2669. }
  2670. type AutomaticReduceDetail struct {
  2671. ID int64 `gorm:"column:id" json:"id"`
  2672. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2673. Status int64 `gorm:"column:status" json:"status"`
  2674. RecordTime int64 `gorm:"column:record_time" json:"record_time"`
  2675. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2676. GoodId int64 `gorm:"column:good_id" json:"good_id"`
  2677. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2678. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"info"`
  2679. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"type"`
  2680. Count int64 `gorm:"column:count" json:"count"`
  2681. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  2682. }
  2683. func (AutomaticReduceDetail) TableName() string {
  2684. return "xt_automatic_reduce_detail"
  2685. }
  2686. type DialysisBeforePrepare struct {
  2687. ID int64 `gorm:"column:id" json:"id" form:"id"`
  2688. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  2689. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  2690. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  2691. GoodId int64 `gorm:"column:good_id" json:"good_id" form:"good_id"`
  2692. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id" form:"good_type_id"`
  2693. Count int64 `gorm:"column:count" json:"count" form:"count"`
  2694. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  2695. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  2696. Creater int64 `gorm:"column:creater" json:"creater" form:"creater"`
  2697. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  2698. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"info"`
  2699. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"type"`
  2700. }
  2701. func (DialysisBeforePrepare) TableName() string {
  2702. return "dialysis_before_prepare"
  2703. }
  2704. type MDialysisGoodsVM struct {
  2705. ID int64 `gorm:"column:id" json:"id"`
  2706. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2707. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2708. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2709. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2710. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2711. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2712. ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week"`
  2713. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2714. Status int64 `gorm:"column:status" json:"status"`
  2715. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2716. SchedualPatient *MSchedualPatientVMList `gorm:"ForeignKey:PatientId" json:"patient"`
  2717. AutomaticReduceDetail []*AutomaticReduceDetail `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"good_user"`
  2718. LastAutomaticReduceDetail []*AutomaticReduceDetail `gorm:"-" json:"last_good_user"`
  2719. DialysisBeforePrepare []*DialysisBeforePrepare `gorm:"ForeignKey:PatientId,ScheduleDate;AssociationForeignKey:PatientId,RecordDate" json:"good_user_detail"`
  2720. LastDialysisBeforePrepare []*DialysisBeforePrepare `gorm:"-" json:"last_good_user_detail"`
  2721. Project []*models.HisPrescriptionProject `gorm:"-" json:"project"`
  2722. //WarehouseOutInfo []*models.WarehouseOutInfoSeven `gorm:"ForeignKey:PatientId,ScheduleDate;AssociationForeignKey:PatientId,SysRecordTime" json:"ware_house_out_info"`
  2723. DialysisPrescription models.DialysisPrescriptionListSix `gorm:"ForeignKey:PatientId,ModeId;AssociationForeignKey:PatientId,ModeId" json:"prescription"`
  2724. }
  2725. func (MDialysisGoodsVM) TableName() string {
  2726. return "xt_schedule"
  2727. }
  2728. type VMWarehouseOutInfo struct {
  2729. ID int64 `gorm:"column:id" json:"id"`
  2730. WarehouseOutId int64 `gorm:"column:warehouse_out_id" json:"warehouse_out_id"`
  2731. GoodId int64 `gorm:"column:good_id" json:"good_id"`
  2732. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2733. Count int64 `gorm:"column:count" json:"count"`
  2734. Price float64 `gorm:"column:price" json:"price"`
  2735. TotalPrice float64 `gorm:"column:total_price" json:"total_price"`
  2736. Status int64 `gorm:"column:status" json:"status"`
  2737. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2738. WarehouseOutOrderNumber string `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number"`
  2739. GoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"good_info"`
  2740. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"good_type"`
  2741. IsSys int64 `gorm:"column:is_sys" json:"is_sys"`
  2742. SysRecordTime int64 `gorm:"column:sys_record_time" json:"sys_record_time"`
  2743. Mtime int64 `gorm:"column:mtime" json:"mtime"`
  2744. Ctime int64 `gorm:"column:ctime" json:"ctime"`
  2745. }
  2746. func (VMWarehouseOutInfo) TableName() string {
  2747. return "xt_warehouse_out_info"
  2748. }
  2749. type DialysisGoodsDate struct {
  2750. RecordDate int64
  2751. }
  2752. type DialysisGoodsDetailDate struct {
  2753. RecordTime int64
  2754. }
  2755. 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) {
  2756. var vms []*MDialysisGoodsVM
  2757. var total int64
  2758. db := readDb.
  2759. Table("xt_schedule as sch").
  2760. Preload("DialysisPrescription", "status=1 and user_org_id =? and solution_status = 1", orgID).
  2761. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  2762. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2763. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2764. Preload("DialysisBeforePrepare", func(db *gorm.DB) *gorm.DB {
  2765. return db.Preload("VMGoodInfo", "status = 1 AND org_id = ? and find_in_set('停用',good_status) = 0", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0) ", orgID).Where("status = 1 AND user_org_id = ? AND record_date = ? AND count > 0 ", orgID, scheduleDate)
  2766. }).
  2767. Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
  2768. 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")
  2769. }).Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
  2770. if scheduleDate != 0 {
  2771. db = db.Where("schedule_date = ?", scheduleDate)
  2772. }
  2773. if schedule_type != 0 {
  2774. db = db.Where("schedule_type = ?", schedule_type)
  2775. }
  2776. if partition_id != 0 {
  2777. db = db.Where("partition_id = ?", partition_id)
  2778. }
  2779. if patient_id != 0 {
  2780. db = db.Where("patient_id = ?", patient_id)
  2781. }
  2782. err := db.Find(&vms).Error
  2783. return vms, err, total
  2784. }
  2785. func GetLastDialysisGoods(patient_id int64, orgID int64, record_time int64) (goodUser []*AutomaticReduceDetail, err error) {
  2786. var Id []*DialysisGoodsDetailDate
  2787. 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
  2788. if len(Id) > 0 {
  2789. 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
  2790. }
  2791. return
  2792. }
  2793. func GetLastDialysisBeforePrepare(patient_id int64, orgID int64, record_time int64) (goodUser []*DialysisBeforePrepare, err error) {
  2794. var Id []*DialysisGoodsDate
  2795. 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
  2796. if len(Id) > 0 {
  2797. 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
  2798. }
  2799. return
  2800. }
  2801. func GetPatientAutoMatic(patient_id int64, orgID int64, record_time int64, good_id int64) (auto []*models.AutomaticReduceDetail, err error) {
  2802. 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
  2803. return auto, err
  2804. }
  2805. func GetAllWarehouseOutSumList(patient_id int64, orgID int64, record_time int64) (info []*models.WarehouseOutInfoSeven, err error) {
  2806. 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
  2807. return info, err
  2808. }
  2809. func MobileGetGoodsStatistics(orgID int64, start_time int64, end_time int64) (list []*models.StockInfo, err error) {
  2810. db := readDb.Model(&models.StockInfo{})
  2811. db = db.Where("xt_good_information.org_id = ? AND xt_good_information.status = 1", orgID)
  2812. 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")
  2813. db = db.Preload("QueryWarehouseOutInfo", func(db *gorm.DB) *gorm.DB {
  2814. 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)
  2815. })
  2816. db = db.Preload("GoodsType", "org_id = ? AND status = 1", orgID)
  2817. err = db.Order("ctime desc").Find(&list).Error
  2818. return
  2819. }
  2820. 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) {
  2821. var vms []*MDialysisGoodsVM
  2822. var total int64
  2823. db := readDb.
  2824. Model(&models.Schedule{}).
  2825. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  2826. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2827. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2828. Preload("DialysisBeforePrepare", func(db *gorm.DB) *gorm.DB {
  2829. 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)
  2830. }).Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
  2831. 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)
  2832. }).Where("xt_schedule.status = 1 AND xt_schedule.user_org_id = ?", orgID)
  2833. if scheduleDate != 0 {
  2834. db = db.Where("schedule_date = ?", scheduleDate)
  2835. }
  2836. if patient_id != 0 {
  2837. db = db.Where("patient_id = ?", patient_id)
  2838. }
  2839. if len(keywords) != 0 {
  2840. keywords = "%" + keywords + "%"
  2841. 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)
  2842. if schedule_type != 0 {
  2843. db = db.Where("schedule_type = ?", schedule_type)
  2844. }
  2845. if partition_id != 0 {
  2846. db = db.Where("partition_id = ?", partition_id)
  2847. }
  2848. if good_type == 1 {
  2849. db = db.Where("patient_id in(?)", ids)
  2850. }
  2851. if good_type == 2 {
  2852. if len(ids) > 0 {
  2853. db = db.Where("patient_id not in(?)", ids)
  2854. }
  2855. }
  2856. } else {
  2857. if schedule_type != 0 {
  2858. db = db.Where("schedule_type = ?", schedule_type)
  2859. }
  2860. if partition_id != 0 {
  2861. db = db.Where("partition_id = ?", partition_id)
  2862. }
  2863. if good_type == 1 {
  2864. db = db.Where("patient_id in(?)", ids)
  2865. }
  2866. if good_type == 2 {
  2867. if len(ids) > 0 {
  2868. db = db.Where("patient_id not in(?)", ids)
  2869. }
  2870. }
  2871. db = db.Count(&total)
  2872. offset := (page - 1) * limit
  2873. db = db.Offset(offset).Limit(limit)
  2874. }
  2875. err := db.Find(&vms).Error
  2876. return vms, err, total
  2877. }
  2878. func GetLastDialysisGoodsTwo(patient_id int64, orgID int64, record_time int64) (goodUser []*AutomaticReduceDetail, err error) {
  2879. var Id []*DialysisGoodsDetailDate
  2880. 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
  2881. if len(Id) > 0 {
  2882. 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
  2883. }
  2884. return
  2885. }
  2886. func GetLastDialysisBeforePrepareTwo(patient_id int64, orgID int64, record_time int64) (goodUser []*DialysisBeforePrepare, err error) {
  2887. var Id []*DialysisGoodsDate
  2888. 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
  2889. if len(Id) > 0 {
  2890. 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
  2891. }
  2892. return
  2893. }
  2894. func GetAssessmentBefor(orgid int64, patientid int64, recorddate int64) (*models.PredialysisEvaluation, error) {
  2895. evaluation := models.PredialysisEvaluation{}
  2896. err := XTReadDB().Model(&evaluation).Where("user_org_id = ? and patient_id = ? and assessment_date = ? and status = 1", orgid, patientid, recorddate).Find(&evaluation).Error
  2897. if err == gorm.ErrRecordNotFound {
  2898. return nil, err
  2899. }
  2900. if err != nil {
  2901. return nil, err
  2902. }
  2903. return &evaluation, nil
  2904. }
  2905. func GetAssessmentBeforThrity(orgid int64, patientid int64, recorddate int64) (models.PredialysisEvaluation, error) {
  2906. evaluation := models.PredialysisEvaluation{}
  2907. err := XTReadDB().Model(&evaluation).Where("user_org_id = ? and patient_id = ? and assessment_date = ? and status = 1", orgid, patientid, recorddate).Find(&evaluation).Error
  2908. return evaluation, err
  2909. }
  2910. func GetAssessmentBeforFourty(orgid int64, patientid int64, recorddate int64) (models.XtAssessmentBeforeDislysis, error) {
  2911. evaluation := models.XtAssessmentBeforeDislysis{}
  2912. err := XTReadDB().Model(&evaluation).Where("user_org_id = ? and patient_id = ? and assessment_date = ? and status = 1", orgid, patientid, recorddate).Find(&evaluation).Error
  2913. return evaluation, err
  2914. }
  2915. func GetHisPrescriptionTemplateList(user_org_id int64, patient_id int64, mode_id int64) (models.HisPrescriptionTemplateSix, error) {
  2916. templateSix := models.HisPrescriptionTemplateSix{}
  2917. 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 {
  2918. return db.Where("status = 1 AND user_org_id = ? and type =2", user_org_id).Preload("HisPrescriptionProjectTemplateSeven", func(db *gorm.DB) *gorm.DB {
  2919. 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)
  2920. })
  2921. }).Find(&templateSix).Error
  2922. return templateSix, err
  2923. }
  2924. func GetAllHisDoctorAdvice(orgid int64, patientid int64, recorddate int64) (his []*models.HisDoctorAdviceInfo, err error) {
  2925. redis := RedisClient()
  2926. defer redis.Close()
  2927. key := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patientid, 10) + ":" + strconv.FormatInt(recorddate, 10) + ":his_doctor_advice"
  2928. his_doctor_advice_str, _ := redis.Get(key).Result()
  2929. redis.Set(key, "", time.Second)
  2930. if orgid != 10721 {
  2931. if len(his_doctor_advice_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2932. 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
  2933. if err != nil {
  2934. if err == gorm.ErrRecordNotFound {
  2935. if len(his) <= 0 {
  2936. redis.Set(key, "null", time.Second*60*60*18)
  2937. }
  2938. return his, nil
  2939. } else {
  2940. return his, err
  2941. }
  2942. } else {
  2943. if len(his) > 0 {
  2944. //缓存数据
  2945. his_doctor_advice_str, err := json.Marshal(his)
  2946. if err == nil {
  2947. redis.Set(key, his_doctor_advice_str, time.Second*60*60*18)
  2948. }
  2949. } else {
  2950. redis.Set(key, "null", time.Second*60*60*18)
  2951. }
  2952. return his, nil
  2953. }
  2954. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2955. json.Unmarshal([]byte(his_doctor_advice_str), &his)
  2956. return his, nil
  2957. }
  2958. }
  2959. if orgid == 10721 {
  2960. if len(his_doctor_advice_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2961. var keyword = "胰岛素"
  2962. keyword = "%" + keyword + "%"
  2963. 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
  2964. if err != nil {
  2965. if err == gorm.ErrRecordNotFound {
  2966. if len(his) <= 0 {
  2967. redis.Set(key, "null", time.Second*60*60*18)
  2968. }
  2969. return his, nil
  2970. } else {
  2971. return his, err
  2972. }
  2973. } else {
  2974. if len(his) > 0 {
  2975. //缓存数据
  2976. his_doctor_advice_str, err := json.Marshal(his)
  2977. if err == nil {
  2978. redis.Set(key, his_doctor_advice_str, time.Second*60*60*18)
  2979. }
  2980. } else {
  2981. redis.Set(key, "null", time.Second*60*60*18)
  2982. }
  2983. return his, nil
  2984. }
  2985. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2986. json.Unmarshal([]byte(his_doctor_advice_str), &his)
  2987. return his, nil
  2988. }
  2989. }
  2990. return his, nil
  2991. }
  2992. func GetLastDialysisPrescriptionByPatientId(orgid int64, patientid int64, recorddate int64) (*models.DialysisPrescription, error) {
  2993. prescription := models.DialysisPrescription{}
  2994. err := readDb.Model(&models.DialysisPrescription{}).Where("user_org_id = ? and patient_id = ? and record_date = ? and status = 1", orgid, patientid, recorddate).Find(&prescription).Error
  2995. if err == gorm.ErrRecordNotFound {
  2996. return nil, err
  2997. }
  2998. if err != nil {
  2999. return nil, err
  3000. }
  3001. return &prescription, nil
  3002. }
  3003. func GetLastDialysisPrescriptionByPatientIdTwo(orgid int64, patientid int64, recorddate int64) (models.DialysisPrescription, error) {
  3004. prescription := models.DialysisPrescription{}
  3005. err := readDb.Model(&models.DialysisPrescription{}).Where("user_org_id = ? and patient_id = ? and record_date = ? and status = 1", orgid, patientid, recorddate).Find(&prescription).Error
  3006. return prescription, err
  3007. }
  3008. type HisMScheduleDoctorAdviceVM struct {
  3009. ID int64 `gorm:"column:id" json:"id"`
  3010. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  3011. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  3012. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  3013. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  3014. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  3015. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  3016. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  3017. Status int64 `gorm:"column:status" json:"status"`
  3018. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  3019. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  3020. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  3021. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  3022. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  3023. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  3024. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  3025. }
  3026. func (HisMScheduleDoctorAdviceVM) TableName() string {
  3027. return "xt_schedule"
  3028. }
  3029. type HisMScheduleDoctorAdviceVMOne struct {
  3030. ID int64 `gorm:"column:id" json:"id"`
  3031. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  3032. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  3033. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  3034. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  3035. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  3036. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  3037. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  3038. Status int64 `gorm:"column:status" json:"status"`
  3039. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  3040. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  3041. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  3042. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  3043. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  3044. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  3045. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  3046. }
  3047. func (HisMScheduleDoctorAdviceVMOne) TableName() string {
  3048. return "xt_schedule"
  3049. }
  3050. type HisMScheduleProjectVM struct {
  3051. ID int64 `gorm:"column:id" json:"id"`
  3052. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  3053. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  3054. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  3055. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  3056. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  3057. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  3058. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  3059. Status int64 `gorm:"column:status" json:"status"`
  3060. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  3061. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  3062. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  3063. Prescription *models.DialysisPrescriptionTwenty `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  3064. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  3065. HisPrescriptionTeamProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"team_project"`
  3066. }
  3067. func (HisMScheduleProjectVM) TableName() string {
  3068. return "xt_schedule"
  3069. }
  3070. func GetHisDoctorConfig(orgid int64) (models.XtHisConfig, error) {
  3071. config := models.XtHisConfig{}
  3072. err := XTReadDB().Model(&config).Where("user_org_id = ? and status =1", orgid).Find(&config).Error
  3073. return config, err
  3074. }
  3075. func GetHisDoctorPatientById(orgid int64, patientid int64, recordtime int64) (advice []*models.HisDoctorAdviceInfo, err error) {
  3076. db := XTReadDB().Table("his_doctor_advice_info as x").Where("x.status = 1")
  3077. if orgid > 0 {
  3078. db = db.Where("x.user_org_id = ?", orgid)
  3079. }
  3080. if patientid > 0 {
  3081. db = db.Where("x.patient_id =?", patientid)
  3082. }
  3083. if recordtime > 0 {
  3084. db = db.Where("x.advice_date = ?", recordtime)
  3085. }
  3086. 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
  3087. return advice, err
  3088. }
  3089. func GetDoctorAdviceCount(startime int64, endtime int64, deliveway string, orgid int64) (advice []*models.BloodDoctorAdvice, err error) {
  3090. db := XTReadDB().Table("xt_doctor_advice as x").Where("x.status = 1 and x.advice_type =2")
  3091. if startime > 0 {
  3092. db = db.Where("x.advice_date >= ?", startime)
  3093. }
  3094. if endtime > 0 {
  3095. db = db.Where("x.advice_date<=?", endtime)
  3096. }
  3097. if orgid > 0 {
  3098. db = db.Where("x.user_org_id = ?", orgid)
  3099. }
  3100. if len(deliveway) > 0 {
  3101. db = db.Where("x.delivery_way = ?", deliveway)
  3102. }
  3103. 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
  3104. return advice, err
  3105. }
  3106. func GetHisDoctorAdviceCount(startime int64, endtime int64, deliveway string, orgid int64) (advice []*models.BloodDoctorAdvice, err error) {
  3107. db := XTReadDB().Table("his_doctor_advice_info as x").Where("x.status = 1 and x.advice_type =2")
  3108. if startime > 0 {
  3109. db = db.Where("x.advice_date >= ?", startime)
  3110. }
  3111. if endtime > 0 {
  3112. db = db.Where("x.advice_date<=?", endtime)
  3113. }
  3114. if orgid > 0 {
  3115. db = db.Where("x.user_org_id = ?", orgid)
  3116. }
  3117. if len(deliveway) > 0 {
  3118. db = db.Where("x.delivery_way = ?", deliveway)
  3119. }
  3120. 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
  3121. return advice, err
  3122. }
  3123. 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) {
  3124. var vms []*MScheduleDoctorAdviceVM
  3125. adviceWhere := ""
  3126. adviceCondition := []interface{}{}
  3127. if adviceType == 0 {
  3128. if patientType == 0 {
  3129. if patient_id > 0 {
  3130. if execution_state > 0 {
  3131. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  3132. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3133. } else {
  3134. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
  3135. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3136. }
  3137. } else {
  3138. if execution_state > 0 {
  3139. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ?"
  3140. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3141. } else {
  3142. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  3143. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3144. }
  3145. }
  3146. } else if patientType == 1 {
  3147. if patient_id > 0 {
  3148. if execution_state > 0 {
  3149. 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= ?"
  3150. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3151. } else {
  3152. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
  3153. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3154. }
  3155. } else {
  3156. if execution_state > 0 {
  3157. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  3158. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3159. } else {
  3160. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  3161. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3162. }
  3163. }
  3164. } else if patientType == 2 {
  3165. if patient_id > 0 {
  3166. if execution_state > 0 {
  3167. 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 = ?"
  3168. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3169. } else {
  3170. 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 = ?)"
  3171. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3172. }
  3173. } else {
  3174. if execution_state > 0 {
  3175. 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 = ?"
  3176. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3177. } else {
  3178. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  3179. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3180. }
  3181. }
  3182. }
  3183. } else if adviceType == 1 {
  3184. if patientType == 0 {
  3185. if patient_id > 0 {
  3186. if execution_state > 0 {
  3187. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ?"
  3188. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3189. } else {
  3190. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
  3191. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3192. }
  3193. } else {
  3194. if execution_state > 0 {
  3195. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ?"
  3196. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3197. } else {
  3198. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  3199. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3200. }
  3201. }
  3202. } else if patientType == 1 {
  3203. if patient_id > 0 {
  3204. if execution_state > 0 {
  3205. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  3206. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3207. } else {
  3208. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
  3209. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3210. }
  3211. } else {
  3212. if execution_state > 0 {
  3213. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?"
  3214. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3215. } else {
  3216. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  3217. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3218. }
  3219. }
  3220. } else if patientType == 2 {
  3221. if patient_id > 0 {
  3222. if execution_state > 0 {
  3223. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  3224. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3225. } else {
  3226. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
  3227. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3228. }
  3229. } else {
  3230. if execution_state > 0 {
  3231. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ?"
  3232. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3233. } else {
  3234. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  3235. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3236. }
  3237. }
  3238. }
  3239. } else if adviceType == 3 {
  3240. if patientType == 0 {
  3241. if patient_id > 0 {
  3242. if execution_state > 0 {
  3243. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ?"
  3244. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3245. } else {
  3246. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? "
  3247. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3248. }
  3249. } else {
  3250. if execution_state > 0 {
  3251. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? "
  3252. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3253. } else {
  3254. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  3255. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3256. }
  3257. }
  3258. } else if patientType == 1 {
  3259. if patient_id > 0 {
  3260. if execution_state > 0 {
  3261. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  3262. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3263. } else {
  3264. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
  3265. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3266. }
  3267. } else {
  3268. if execution_state > 0 {
  3269. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? "
  3270. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3271. } else {
  3272. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  3273. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3274. }
  3275. }
  3276. } else if patientType == 2 {
  3277. if patient_id > 0 {
  3278. if execution_state > 0 {
  3279. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  3280. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3281. } else {
  3282. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ?"
  3283. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3284. }
  3285. } else {
  3286. if execution_state > 0 {
  3287. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ?"
  3288. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3289. } else {
  3290. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  3291. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3292. }
  3293. }
  3294. }
  3295. } else if adviceType == 2 && len(deliverWay) > 0 {
  3296. if patientType == 0 {
  3297. if patient_id > 0 {
  3298. if execution_state > 0 {
  3299. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  3300. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  3301. } else {
  3302. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ?"
  3303. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  3304. }
  3305. } else {
  3306. if execution_state > 0 {
  3307. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ?"
  3308. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  3309. } else {
  3310. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  3311. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  3312. }
  3313. }
  3314. } else if patientType == 1 {
  3315. if patient_id > 0 {
  3316. if execution_state > 0 {
  3317. 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 = ?"
  3318. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state)
  3319. } else {
  3320. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ?"
  3321. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
  3322. }
  3323. } else {
  3324. if execution_state > 0 {
  3325. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ?"
  3326. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state)
  3327. } else {
  3328. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  3329. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  3330. }
  3331. }
  3332. } else if patientType == 2 {
  3333. if patient_id > 0 {
  3334. if execution_state > 0 {
  3335. 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 = ?"
  3336. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  3337. } else {
  3338. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ?"
  3339. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  3340. }
  3341. } else {
  3342. if execution_state > 0 {
  3343. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ?"
  3344. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  3345. } else {
  3346. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  3347. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  3348. }
  3349. }
  3350. }
  3351. } else if adviceType == 2 && len(deliverWay) <= 0 {
  3352. if patientType == 0 {
  3353. if patient_id > 0 {
  3354. if execution_state > 0 {
  3355. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ?"
  3356. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3357. } else {
  3358. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ?"
  3359. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3360. }
  3361. } else {
  3362. if execution_state > 0 {
  3363. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?"
  3364. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3365. } else {
  3366. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  3367. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3368. }
  3369. }
  3370. } else if patientType == 1 {
  3371. if patient_id > 0 {
  3372. if execution_state > 0 {
  3373. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  3374. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3375. } else {
  3376. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ?"
  3377. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3378. }
  3379. } else {
  3380. if execution_state > 0 {
  3381. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ?"
  3382. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3383. } else {
  3384. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?"
  3385. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3386. }
  3387. }
  3388. } else if patientType == 2 {
  3389. if patient_id > 0 {
  3390. if execution_state > 0 {
  3391. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  3392. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3393. } else {
  3394. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ?"
  3395. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3396. }
  3397. } else {
  3398. if execution_state > 0 {
  3399. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ?"
  3400. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3401. } else {
  3402. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  3403. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3404. }
  3405. }
  3406. }
  3407. }
  3408. db := readDb.Table("xt_schedule")
  3409. if scheduleType > 0 {
  3410. db = db.Where("schedule_type = ?", scheduleType)
  3411. }
  3412. if partitonType > 0 {
  3413. db = db.Where("partition_id = ?", partitonType)
  3414. }
  3415. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3416. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3417. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3418. }).
  3419. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3420. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3421. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3422. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3423. Preload("DoctorAdvices", adviceCondition...).
  3424. Where("status = 1 AND user_org_id = ?", orgID)
  3425. if scheduleDate != 0 {
  3426. db = db.Where("schedule_date = ?", scheduleDate)
  3427. }
  3428. err := db.Find(&vms).Error
  3429. return vms, err
  3430. }
  3431. func GetHisDoctorAdvicesOne(orgID int64, scheduleDate int64, deliverWay string, scheduleType int64, partitionType int64, patient_id int64, execution_state int64, cost_type int64) ([]*HisMScheduleDoctorAdviceVM, error) {
  3432. var vms []*HisMScheduleDoctorAdviceVM
  3433. if len(deliverWay) > 0 {
  3434. db := readDb.Table("xt_schedule")
  3435. if scheduleType > 0 {
  3436. db = db.Where("schedule_type = ?", scheduleType)
  3437. }
  3438. if partitionType > 0 {
  3439. db = db.Where("partition_id = ?", partitionType)
  3440. }
  3441. if patient_id > 0 {
  3442. if execution_state > 0 {
  3443. if cost_type > 0 {
  3444. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3445. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3446. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3447. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3448. 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).
  3449. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3450. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3451. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3452. Where("status = 1 AND user_org_id = ?", orgID)
  3453. if scheduleDate != 0 {
  3454. db = db.Where("schedule_date = ?", scheduleDate)
  3455. }
  3456. err = db.Find(&vms).Error
  3457. } else {
  3458. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3459. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3460. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3461. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3462. 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).
  3463. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3464. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3465. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3466. Where("status = 1 AND user_org_id = ?", orgID)
  3467. if scheduleDate != 0 {
  3468. db = db.Where("schedule_date = ?", scheduleDate)
  3469. }
  3470. err = db.Find(&vms).Error
  3471. }
  3472. } else {
  3473. if cost_type > 0 {
  3474. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3475. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3476. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3477. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3478. 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).
  3479. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3480. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3481. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3482. Where("status = 1 AND user_org_id = ?", orgID)
  3483. if scheduleDate != 0 {
  3484. db = db.Where("schedule_date = ?", scheduleDate)
  3485. }
  3486. err = db.Find(&vms).Error
  3487. } else {
  3488. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3489. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3490. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3491. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3492. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ?", orgID, scheduleDate, deliverWay, patient_id).
  3493. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3494. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3495. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3496. Where("status = 1 AND user_org_id = ?", orgID)
  3497. if scheduleDate != 0 {
  3498. db = db.Where("schedule_date = ?", scheduleDate)
  3499. }
  3500. err = db.Find(&vms).Error
  3501. }
  3502. }
  3503. } else {
  3504. if execution_state > 0 {
  3505. if cost_type > 0 {
  3506. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3507. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3508. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3509. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3510. 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).
  3511. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3512. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3513. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3514. Where("status = 1 AND user_org_id = ?", orgID)
  3515. if scheduleDate != 0 {
  3516. db = db.Where("schedule_date = ?", scheduleDate)
  3517. }
  3518. err = db.Find(&vms).Error
  3519. } else {
  3520. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3521. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3522. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3523. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3524. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_state = ?", orgID, scheduleDate, deliverWay, execution_state).
  3525. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3526. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3527. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3528. Where("status = 1 AND user_org_id = ?", orgID)
  3529. if scheduleDate != 0 {
  3530. db = db.Where("schedule_date = ?", scheduleDate)
  3531. }
  3532. err = db.Find(&vms).Error
  3533. }
  3534. } else {
  3535. if cost_type > 0 {
  3536. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3537. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3538. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3539. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3540. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and is_settle = ?", orgID, scheduleDate, deliverWay, cost_type).
  3541. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3542. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3543. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3544. Where("status = 1 AND user_org_id = ?", orgID)
  3545. if scheduleDate != 0 {
  3546. db = db.Where("schedule_date = ?", scheduleDate)
  3547. }
  3548. err = db.Find(&vms).Error
  3549. } else {
  3550. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3551. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3552. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3553. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3554. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  3555. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3556. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3557. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3558. Where("status = 1 AND user_org_id = ?", orgID)
  3559. if scheduleDate != 0 {
  3560. db = db.Where("schedule_date = ?", scheduleDate)
  3561. }
  3562. err = db.Find(&vms).Error
  3563. }
  3564. }
  3565. }
  3566. } else {
  3567. db := readDb.Table("xt_schedule")
  3568. if scheduleType > 0 {
  3569. db = db.Where("schedule_type = ?", scheduleType)
  3570. }
  3571. if partitionType > 0 {
  3572. db = db.Where("partition_id = ?", partitionType)
  3573. }
  3574. if patient_id > 0 {
  3575. if execution_state > 0 {
  3576. if cost_type > 0 {
  3577. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3578. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3579. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3580. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3581. 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).
  3582. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3583. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3584. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3585. Where("status = 1 AND user_org_id = ?", orgID)
  3586. if scheduleDate != 0 {
  3587. db = db.Where("schedule_date = ?", scheduleDate)
  3588. }
  3589. err = db.Find(&vms).Error
  3590. } else {
  3591. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3592. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3593. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3594. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3595. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and execution_state = ?", orgID, scheduleDate, patient_id, execution_state).
  3596. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3597. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3598. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3599. Where("status = 1 AND user_org_id = ?", orgID)
  3600. if scheduleDate != 0 {
  3601. db = db.Where("schedule_date = ?", scheduleDate)
  3602. }
  3603. err = db.Find(&vms).Error
  3604. }
  3605. } else {
  3606. if cost_type > 0 {
  3607. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3608. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3609. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3610. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3611. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and is_settle = ?", orgID, scheduleDate, patient_id, cost_type).
  3612. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3613. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3614. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3615. Where("status = 1 AND user_org_id = ?", orgID)
  3616. if scheduleDate != 0 {
  3617. db = db.Where("schedule_date = ?", scheduleDate)
  3618. }
  3619. err = db.Find(&vms).Error
  3620. } else {
  3621. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3622. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3623. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3624. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3625. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3626. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3627. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3628. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3629. Where("status = 1 AND user_org_id = ?", orgID)
  3630. if scheduleDate != 0 {
  3631. db = db.Where("schedule_date = ?", scheduleDate)
  3632. }
  3633. err = db.Find(&vms).Error
  3634. }
  3635. }
  3636. } else {
  3637. if execution_state > 0 {
  3638. if cost_type > 0 {
  3639. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3640. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3641. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3642. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3643. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ? and is_settle = ?", orgID, scheduleDate, execution_state, cost_type).
  3644. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3645. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3646. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3647. Where("status = 1 AND user_org_id = ?", orgID)
  3648. if scheduleDate != 0 {
  3649. db = db.Where("schedule_date = ?", scheduleDate)
  3650. }
  3651. err = db.Find(&vms).Error
  3652. } else {
  3653. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3654. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3655. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3656. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3657. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ?", orgID, scheduleDate, execution_state).
  3658. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3659. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3660. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3661. Where("status = 1 AND user_org_id = ?", orgID)
  3662. if scheduleDate != 0 {
  3663. db = db.Where("schedule_date = ?", scheduleDate)
  3664. }
  3665. err = db.Find(&vms).Error
  3666. }
  3667. } else {
  3668. if cost_type > 0 {
  3669. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3670. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3671. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3672. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3673. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and is_settle = ?", orgID, scheduleDate, cost_type).
  3674. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3675. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3676. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3677. Where("status = 1 AND user_org_id = ?", orgID)
  3678. if scheduleDate != 0 {
  3679. db = db.Where("schedule_date = ?", scheduleDate)
  3680. }
  3681. err = db.Find(&vms).Error
  3682. } else {
  3683. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3684. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3685. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3686. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3687. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ?", orgID, scheduleDate).
  3688. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3689. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3690. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3691. Where("status = 1 AND user_org_id = ?", orgID)
  3692. if scheduleDate != 0 {
  3693. db = db.Where("schedule_date = ?", scheduleDate)
  3694. }
  3695. err = db.Find(&vms).Error
  3696. }
  3697. }
  3698. }
  3699. }
  3700. return vms, err
  3701. }
  3702. func BatchDeleteMonitor(ids []string) (err error) {
  3703. if len(ids) == 1 {
  3704. err = XTWriteDB().Model(&models.MonitoringRecord{}).Where("id=?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3705. } else {
  3706. err = XTWriteDB().Model(models.MonitoringRecord{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3707. }
  3708. return
  3709. }
  3710. func GetPatientDialysisRecordList(patientid int64, startime int64, endtime int64) (order []*models.XtDialysisOrders, err error) {
  3711. db := XTReadDB().Table("xt_dialysis_order as x").Where("x.status = 1")
  3712. //table := XTReadDB().Table("xt_schedule as s")
  3713. //fmt.Println(table)
  3714. if patientid > 0 {
  3715. db = db.Where("x.patient_id = ?", patientid)
  3716. }
  3717. if startime > 0 {
  3718. db = db.Where("x.dialysis_date>=?", startime)
  3719. }
  3720. if endtime > 0 {
  3721. db = db.Where("x.dialysis_date <= ?", endtime)
  3722. }
  3723. 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
  3724. return order, err
  3725. }
  3726. func GetPatientDialysisRecordListOne(patientid int64, startime int64, endtime int64) (order []*models.XtScheduleSixTy, err error) {
  3727. db := XTReadDB().Table("xt_schedule as x").Where("x.status = 1")
  3728. //table := XTReadDB().Table("xt_schedule as s")
  3729. //fmt.Println(table)
  3730. if patientid > 0 {
  3731. db = db.Where("x.patient_id = ?", patientid)
  3732. }
  3733. if startime > 0 {
  3734. db = db.Where("x.schedule_date>=?", startime)
  3735. }
  3736. if endtime > 0 {
  3737. db = db.Where("x.schedule_date <= ?", endtime)
  3738. }
  3739. err = db.Select("x.id,x.schedule_date,x.schedule_type,x.mode_id").Find(&order).Error
  3740. return order, err
  3741. }
  3742. func BatchDeleteAdvice(ids []string) (err error) {
  3743. if len(ids) == 1 {
  3744. err = XTWriteDB().Model(&models.DoctorAdvice{}).Where("id=?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3745. } else {
  3746. err = XTWriteDB().Model(models.DoctorAdvice{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3747. }
  3748. return
  3749. }
  3750. func BatchDeleteHisAdvice(ids []string) (err error) {
  3751. if len(ids) == 1 {
  3752. err = XTWriteDB().Model(&models.HisDoctorAdviceInfo{}).Where("id = ?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3753. } else {
  3754. err = XTWriteDB().Model(models.HisDoctorAdviceInfo{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3755. }
  3756. return
  3757. }
  3758. func UpdateAutoReduceDetail(good_id int64, count int64, record_time int64, patient_id int64) (models.AutomaticReduceDetail, error) {
  3759. detail := models.AutomaticReduceDetail{}
  3760. err := XTWriteDB().Model(&detail).Where("good_id = ? and status = 1 and record_time = ? and patient_id = ?", good_id, record_time, patient_id).Updates(map[string]interface{}{"count": count}).Error
  3761. return detail, err
  3762. }
  3763. func DeleteAutoReduceDetail(good_id int64, record_time int64, patient_id int64) error {
  3764. detail := models.AutomaticReduceDetail{}
  3765. 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
  3766. return err
  3767. }
  3768. func DeleteDialysisBeforOne(good_id int64, record_time int64, patient_id int64) error {
  3769. detail := models.DialysisBeforePrepare{}
  3770. 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
  3771. return err
  3772. }
  3773. func BatchAdviceCheck(ids []string, creator int64) error {
  3774. advice := models.XtDoctorAdvice{}
  3775. err := XTWriteDB().Model(&advice).Where("id IN(?) and status = 1", ids).Updates(map[string]interface{}{"check_state": 1, "checker": creator, "check_time": time.Now().Unix()}).Error
  3776. return err
  3777. }
  3778. func BatchHisAdviceCheck(ids []string, creator int64) error {
  3779. advice := models.HisDoctorAdviceInfo{}
  3780. 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
  3781. return err
  3782. }
  3783. func BatchAdviceExecution(ids []string, creator int64, execution_state int64) error {
  3784. advice := models.XtDoctorAdvice{}
  3785. err := XTWriteDB().Model(&advice).Where("id IN(?) and status = 1", ids).Updates(map[string]interface{}{"execution_state": 1, "execution_staff": creator, "execution_time": execution_state}).Error
  3786. return err
  3787. }
  3788. func BatchHisAdviceExecution(ids []string, creator int64, execution_state int64) error {
  3789. advice := models.HisDoctorAdviceInfo{}
  3790. 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
  3791. return err
  3792. }
  3793. func GetAdviceExecutionById(ids []string) (doctor []*models.XtDoctorAdvice, err error) {
  3794. err = XTReadDB().Model(&doctor).Where("id IN(?) AND status = 1", ids).Find(&doctor).Error
  3795. return doctor, err
  3796. }
  3797. func GetHisAdviceExecutionById(ids []string) (doctor []*models.HisDoctorAdviceInfo, err error) {
  3798. err = XTReadDB().Model(&doctor).Where("id IN(?) AND status = 1", ids).Find(&doctor).Error
  3799. return doctor, err
  3800. }
  3801. func GetHisProjectConfig(orgid int64) (models.XtHisProjectConfig, error) {
  3802. config := models.XtHisProjectConfig{}
  3803. err := XTReadDB().Model(&config).Where("user_org_id = ? and status =1", orgid).Find(&config).Error
  3804. return config, err
  3805. }
  3806. func GetHisPrescriptionProject(org_id int64, patient_id int64, record_date int64) (project []*models.HisPrescriptionProject, err error) {
  3807. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("GoodInfo", func(db *gorm.DB) *gorm.DB {
  3808. return db.Preload("GoodsType", "status = 1").Where("status = 1 and is_warehouse = 1")
  3809. }).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
  3810. return
  3811. }
  3812. func GetPCHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64, patient_id int64, execution_state int64) ([]*HisMScheduleProjectVM, error) {
  3813. var vms []*HisMScheduleProjectVM
  3814. if patientType == 0 {
  3815. if patient_id > 0 {
  3816. if execution_state == 1 {
  3817. db := readDb.
  3818. Table("xt_schedule").
  3819. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3820. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3821. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3822. }).
  3823. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3824. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3825. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3826. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3827. 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")
  3828. }).
  3829. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3830. 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")
  3831. }).Where("status = 1 AND user_org_id = ?", orgID)
  3832. if scheduleDate != 0 {
  3833. db = db.Where("schedule_date = ?", scheduleDate)
  3834. }
  3835. err = db.Find(&vms).Error
  3836. } else if execution_state == 2 {
  3837. db := readDb.
  3838. Table("xt_schedule").
  3839. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3840. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3841. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3842. }).
  3843. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3844. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3845. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3846. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3847. 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")
  3848. }).
  3849. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3850. 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")
  3851. }).Where("status = 1 AND user_org_id = ?", orgID)
  3852. if scheduleDate != 0 {
  3853. db = db.Where("schedule_date = ?", scheduleDate)
  3854. }
  3855. err = db.Find(&vms).Error
  3856. } else if execution_state == 0 {
  3857. db := readDb.
  3858. Table("xt_schedule").
  3859. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3860. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3861. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3862. }).
  3863. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3864. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3865. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3866. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3867. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3868. }).
  3869. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3870. 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")
  3871. }).Where("status = 1 AND user_org_id = ?", orgID)
  3872. if scheduleDate != 0 {
  3873. db = db.Where("schedule_date = ?", scheduleDate)
  3874. }
  3875. err = db.Find(&vms).Error
  3876. }
  3877. } else {
  3878. if patient_id > 0 {
  3879. if execution_state == 1 {
  3880. db := readDb.
  3881. Table("xt_schedule").
  3882. Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
  3883. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3884. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3885. }).
  3886. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3887. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3888. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3889. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3890. 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")
  3891. }).
  3892. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3893. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0 and execution_state = ?", orgID, scheduleDate, execution_state).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  3894. }).Where("status = 1 AND user_org_id = ?", orgID)
  3895. if scheduleDate != 0 {
  3896. db = db.Where("schedule_date = ?", scheduleDate)
  3897. }
  3898. err = db.Find(&vms).Error
  3899. } else if execution_state == 2 {
  3900. db := readDb.
  3901. Table("xt_schedule").
  3902. Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
  3903. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3904. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3905. }).
  3906. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3907. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3908. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3909. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3910. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0 and execution_state = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3911. }).
  3912. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3913. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0 and execution_state = 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  3914. }).Where("status = 1 AND user_org_id = ?", orgID)
  3915. if scheduleDate != 0 {
  3916. db = db.Where("schedule_date = ?", scheduleDate)
  3917. }
  3918. err = db.Find(&vms).Error
  3919. } else if execution_state == 0 {
  3920. db := readDb.
  3921. Table("xt_schedule").
  3922. Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
  3923. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3924. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3925. }).
  3926. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3927. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3928. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3929. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3930. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3931. }).
  3932. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3933. 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")
  3934. }).Where("status = 1 AND user_org_id = ?", orgID)
  3935. if scheduleDate != 0 {
  3936. db = db.Where("schedule_date = ?", scheduleDate)
  3937. }
  3938. err = db.Find(&vms).Error
  3939. }
  3940. } else {
  3941. if execution_state == 1 {
  3942. db := readDb.
  3943. Table("xt_schedule").
  3944. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3945. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3946. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3947. }).
  3948. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3949. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3950. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3951. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3952. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0 and execution_state = ?", orgID, scheduleDate, execution_state).Preload("HisProject").Preload("GoodInfo", "status=1")
  3953. }).
  3954. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3955. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0 and execution_state = ?", orgID, scheduleDate, execution_state).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  3956. }).Where("status = 1 AND user_org_id = ?", orgID)
  3957. if scheduleDate != 0 {
  3958. db = db.Where("schedule_date = ?", scheduleDate)
  3959. }
  3960. err = db.Find(&vms).Error
  3961. } else if execution_state == 2 {
  3962. fmt.Println("j氯332n323232n323ℹ️33232323232")
  3963. db := readDb.
  3964. Table("xt_schedule").
  3965. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3966. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3967. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3968. }).
  3969. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3970. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3971. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3972. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3973. 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")
  3974. }).
  3975. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3976. 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")
  3977. }).Where("status = 1 AND user_org_id = ?", orgID)
  3978. if scheduleDate != 0 {
  3979. db = db.Where("schedule_date = ?", scheduleDate)
  3980. }
  3981. err = db.Find(&vms).Error
  3982. } else if execution_state == 0 {
  3983. db := readDb.
  3984. Table("xt_schedule").
  3985. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3986. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3987. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3988. }).
  3989. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3990. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3991. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3992. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3993. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3994. }).
  3995. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3996. 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")
  3997. }).Where("status = 1 AND user_org_id = ?", orgID)
  3998. if scheduleDate != 0 {
  3999. db = db.Where("schedule_date = ?", scheduleDate)
  4000. }
  4001. err = db.Find(&vms).Error
  4002. }
  4003. }
  4004. }
  4005. }
  4006. if patientType > 0 {
  4007. if execution_state == 1 {
  4008. db := readDb.
  4009. Table("xt_schedule").
  4010. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  4011. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  4012. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  4013. }).
  4014. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  4015. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  4016. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  4017. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  4018. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  4019. 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")
  4020. }).
  4021. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  4022. 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")
  4023. }).Where("status = 1 AND user_org_id = ?", orgID)
  4024. if scheduleDate != 0 {
  4025. db = db.Where("schedule_date = ?", scheduleDate)
  4026. }
  4027. err = db.Find(&vms).Error
  4028. } else if execution_state == 2 {
  4029. db := readDb.
  4030. Table("xt_schedule").
  4031. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  4032. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  4033. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  4034. }).
  4035. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  4036. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  4037. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  4038. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  4039. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  4040. 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")
  4041. }).
  4042. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  4043. 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")
  4044. }).Where("status = 1 AND user_org_id = ?", orgID)
  4045. if scheduleDate != 0 {
  4046. db = db.Where("schedule_date = ?", scheduleDate)
  4047. }
  4048. err = db.Find(&vms).Error
  4049. } else if execution_state == 0 {
  4050. db := readDb.
  4051. Table("xt_schedule").
  4052. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  4053. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  4054. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  4055. }).
  4056. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  4057. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  4058. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  4059. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  4060. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  4061. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  4062. }).
  4063. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  4064. 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")
  4065. }).Where("status = 1 AND user_org_id = ?", orgID)
  4066. if scheduleDate != 0 {
  4067. db = db.Where("schedule_date = ?", scheduleDate)
  4068. }
  4069. err = db.Find(&vms).Error
  4070. }
  4071. }
  4072. return vms, err
  4073. }
  4074. func UpdateStockGoods(good_id int64, record_time int64, patient_id int64, count int64) error {
  4075. prepare := models.DialysisBeforePrepare{}
  4076. var err error
  4077. if count > 0 {
  4078. 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
  4079. }
  4080. if count <= 0 {
  4081. 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
  4082. }
  4083. return err
  4084. }
  4085. func UPdateAutoStockGoods(good_id int64, record_time int64, patient_id int64, count int64) error {
  4086. detail := models.AutomaticReduceDetail{}
  4087. 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
  4088. return err
  4089. }
  4090. func MobileGetDialysisSolutionByModeIdSeven(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  4091. var record models.DialysisSolution
  4092. 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
  4093. if err != nil {
  4094. if err == gorm.ErrRecordNotFound {
  4095. return nil, nil
  4096. } else {
  4097. return nil, err
  4098. }
  4099. }
  4100. return &record, nil
  4101. }
  4102. func MobileGetLastDialysisPrescribeByModeIdSeven(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  4103. var record models.DialysisPrescription
  4104. 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
  4105. if err != nil {
  4106. if err == gorm.ErrRecordNotFound {
  4107. return nil, nil
  4108. } else {
  4109. return nil, err
  4110. }
  4111. }
  4112. return &record, nil
  4113. }
  4114. func MobileGetLastDialysisPrescription(patientID int64, orgID int64) (models.DialysisPrescriptionThrity, error) {
  4115. prescription := models.DialysisPrescriptionThrity{}
  4116. err := readDb.Model(&prescription).Where("patient_id = ? and user_org_id = ? and status = 1 and remark<>''", patientID, orgID).Last(&prescription).Error
  4117. return prescription, err
  4118. }
  4119. func MobileGetSystemDialysisPrescribeByModeIdSeven(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  4120. var record models.SystemPrescription
  4121. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).First(&record).Error
  4122. if err != nil {
  4123. if err == gorm.ErrRecordNotFound {
  4124. return nil, nil
  4125. } else {
  4126. return nil, err
  4127. }
  4128. }
  4129. return &record, nil
  4130. }
  4131. // 透前评估
  4132. func MobileGetPredialysisEvaluationSeven(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
  4133. var record models.PredialysisEvaluation
  4134. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  4135. if err != nil {
  4136. if err == gorm.ErrRecordNotFound {
  4137. return nil, nil
  4138. } else {
  4139. return nil, err
  4140. }
  4141. }
  4142. return &record, nil
  4143. }
  4144. //
  4145. //func MobileGetDialysisGoodsSix(orgID int64, scheduleDate int64) (prepare []*models.DialysisBeforePrepare, err error) {
  4146. //
  4147. // 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
  4148. // return prepare, err
  4149. //}
  4150. func GetMobileAutoReduce(orgID int64, scheduleDate int64) (auto []*models.AutomaticReduceDetail, err error) {
  4151. err = readDb.Where("org_id = ? and status = 1 and record_time = ?", orgID, scheduleDate).Find(&auto).Error
  4152. return auto, err
  4153. }
  4154. func GetRoleList(orgid int64, admin_user_id int64) (models.SgjUserAdminRole, error) {
  4155. role := models.SgjUserAdminRole{}
  4156. err = readUserDb.Where("org_id = ? and admin_user_id = ? and status =1 ", orgid, admin_user_id).Find(&role).Error
  4157. return role, err
  4158. }
  4159. func GetDialysisGood(orgID int64, scheduleDate int64) (auto []*models.AutomaticReduceDetail, err error) {
  4160. err = readDb.Where("org_id = ? and status = 1 and record_time >= ?", orgID, scheduleDate).Group("patient_id").Find(&auto).Error
  4161. return auto, err
  4162. }
  4163. func GetGoodWarehouseOutInfo(orgId int64, patient_id int64, sys_record_time int64) (outifno []*models.WarehouseOutInfoSeven, err error) {
  4164. err = readDb.Where("org_id = ? and patient_id = ? and sys_record_time = ? and status = 1", orgId, patient_id, sys_record_time).Find(&outifno).Error
  4165. return outifno, err
  4166. }
  4167. func GetLastDilysisOrder(orgid int64, patient_id int64, dialysis_date int64) (models.DialysisOrder, error) {
  4168. order := models.DialysisOrder{}
  4169. err = XTReadDB().Where("user_org_id = ? and patient_id = ? and dialysis_date < ? and status= 1", orgid, patient_id, dialysis_date).Last(&order).Error
  4170. return order, err
  4171. }
  4172. func GetFistMonitor(orgid int64, patient_id int64, dialysis_date int64) (models.MonitoringRecord, error) {
  4173. record := models.MonitoringRecord{}
  4174. err := XTReadDB().Where("org_id = ? and patient_id = ? and monitoring_date = ? and status = 1", orgid, patient_id, dialysis_date).Find(&record).Error
  4175. return record, err
  4176. }
  4177. func GetFistMonitorSix(orgid int64, patient_id int64, dialysis_date int64) (record []*models.MonitoringRecord, err error) {
  4178. err = XTReadDB().Where("user_org_id = ? and patient_id = ? and monitoring_date = ? and status = 1", orgid, patient_id, dialysis_date).Find(&record).Error
  4179. return record, err
  4180. }
  4181. 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) {
  4182. var vms []*MScheduleDoctorAdviceVM
  4183. keyword = "%" + keyword + "%"
  4184. adviceWhere := ""
  4185. adviceCondition := []interface{}{}
  4186. if adviceType == 0 {
  4187. if patientType == 0 {
  4188. if patient_id > 0 {
  4189. if execution_state > 0 {
  4190. if cost_type > 0 {
  4191. if len(execution_frequency) > 0 {
  4192. if len(keyword) > 0 {
  4193. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  4194. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4195. } else {
  4196. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ? and is_settle = ? and execution_frequency = ?"
  4197. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4198. }
  4199. } else {
  4200. if len(keyword) > 0 {
  4201. 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 ?"
  4202. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  4203. } else {
  4204. 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 = ?"
  4205. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4206. }
  4207. }
  4208. } else {
  4209. if len(execution_frequency) > 0 {
  4210. if len(keyword) > 0 {
  4211. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ? and execution_frequency = ? and advice_name like ?"
  4212. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  4213. } else {
  4214. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ? and execution_frequency = ?"
  4215. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4216. }
  4217. } else {
  4218. if len(keyword) > 0 {
  4219. 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 ?"
  4220. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  4221. } else {
  4222. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  4223. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4224. }
  4225. }
  4226. }
  4227. } else {
  4228. if cost_type > 0 {
  4229. if len(execution_frequency) > 0 {
  4230. 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 = ?"
  4231. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4232. } else {
  4233. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and is_settle = ?"
  4234. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4235. }
  4236. } else {
  4237. if len(execution_frequency) > 0 {
  4238. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_frequency = ?"
  4239. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4240. } else {
  4241. if len(keyword) > 0 {
  4242. 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 ?"
  4243. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  4244. } else {
  4245. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
  4246. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4247. }
  4248. }
  4249. }
  4250. }
  4251. } else {
  4252. if execution_state > 0 {
  4253. if cost_type > 0 {
  4254. if len(execution_frequency) > 0 {
  4255. if len(keyword) > 0 {
  4256. 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 ?"
  4257. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  4258. } else {
  4259. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and is_settle = ? and execution_frequency = ?"
  4260. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4261. }
  4262. } else {
  4263. if len(keyword) > 0 {
  4264. 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 ?"
  4265. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  4266. } else {
  4267. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and is_settle = ?"
  4268. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4269. }
  4270. }
  4271. } else {
  4272. if len(execution_frequency) > 0 {
  4273. if len(keyword) > 0 {
  4274. 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 ?"
  4275. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  4276. } else {
  4277. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and execution_frequency = ?"
  4278. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4279. }
  4280. } else {
  4281. if len(keyword) > 0 {
  4282. 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 ?"
  4283. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  4284. } else {
  4285. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ?"
  4286. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4287. }
  4288. }
  4289. }
  4290. } else {
  4291. if cost_type > 0 {
  4292. if len(execution_frequency) > 0 {
  4293. if len(keyword) > 0 {
  4294. 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 ?"
  4295. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  4296. } else {
  4297. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ? and execution_frequency = ?"
  4298. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  4299. }
  4300. } else {
  4301. if len(keyword) > 0 {
  4302. 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 ?"
  4303. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  4304. } else {
  4305. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ?"
  4306. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4307. }
  4308. }
  4309. } else {
  4310. if len(execution_frequency) > 0 {
  4311. if len(keyword) > 0 {
  4312. 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 ?"
  4313. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  4314. } else {
  4315. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_frequency = ?"
  4316. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  4317. }
  4318. } else {
  4319. if len(keyword) > 0 {
  4320. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and advice_name like ?"
  4321. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  4322. } else {
  4323. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  4324. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4325. }
  4326. }
  4327. }
  4328. }
  4329. }
  4330. } else if patientType == 1 {
  4331. if patient_id > 0 {
  4332. if execution_state > 0 {
  4333. if cost_type > 0 {
  4334. if len(execution_frequency) > 0 {
  4335. if len(keyword) > 0 {
  4336. 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 ?"
  4337. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4338. } else {
  4339. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ? and is_settle = ? and execution_frequency = ?"
  4340. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  4341. }
  4342. } else {
  4343. if len(keyword) > 0 {
  4344. 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 ?"
  4345. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, keyword)
  4346. } else {
  4347. 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 = ?"
  4348. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  4349. }
  4350. }
  4351. } else {
  4352. if len(execution_frequency) > 0 {
  4353. if len(keyword) > 0 {
  4354. 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 ?"
  4355. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  4356. } else {
  4357. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ? and execution_frequency = ?"
  4358. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  4359. }
  4360. } else {
  4361. if len(keyword) > 0 {
  4362. 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 ?"
  4363. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, keyword)
  4364. } else {
  4365. 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= ?"
  4366. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  4367. }
  4368. }
  4369. }
  4370. } else {
  4371. if cost_type > 0 {
  4372. if len(execution_frequency) > 0 {
  4373. if len(keyword) > 0 {
  4374. 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 ?"
  4375. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  4376. } else {
  4377. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ? and is_settle=? and execution_frequency = ?"
  4378. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  4379. }
  4380. } else {
  4381. if len(keyword) > 0 {
  4382. 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 ?"
  4383. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, keyword)
  4384. } else {
  4385. 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=?"
  4386. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  4387. }
  4388. }
  4389. } else {
  4390. if len(execution_frequency) > 0 {
  4391. if len(keyword) > 0 {
  4392. 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 ?"
  4393. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency, keyword)
  4394. } else {
  4395. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_frequency = ?"
  4396. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  4397. }
  4398. } else {
  4399. if len(keyword) > 0 {
  4400. 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 ?"
  4401. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, keyword)
  4402. } else {
  4403. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
  4404. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  4405. }
  4406. }
  4407. }
  4408. }
  4409. } else {
  4410. if execution_state > 0 {
  4411. if cost_type > 0 {
  4412. if len(execution_frequency) > 0 {
  4413. if len(keyword) > 0 {
  4414. 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 ?"
  4415. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  4416. } else {
  4417. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ? and is_settle=? and execution_frequency = ?"
  4418. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  4419. }
  4420. } else {
  4421. if len(keyword) > 0 {
  4422. 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 ?"
  4423. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, keyword)
  4424. } else {
  4425. 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=?"
  4426. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  4427. }
  4428. }
  4429. } else {
  4430. if len(execution_frequency) > 0 {
  4431. if len(keyword) > 0 {
  4432. 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 ?"
  4433. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency, keyword)
  4434. } else {
  4435. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ? and execution_frequency = ?"
  4436. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  4437. }
  4438. } else {
  4439. if len(keyword) > 0 {
  4440. 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 ?"
  4441. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, keyword)
  4442. } else {
  4443. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  4444. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  4445. }
  4446. }
  4447. }
  4448. } else {
  4449. if cost_type > 0 {
  4450. if len(execution_frequency) > 0 {
  4451. if len(keyword) > 0 {
  4452. 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 ?"
  4453. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency, keyword)
  4454. } else {
  4455. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and is_settle=? and execution_frequency = ?"
  4456. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  4457. }
  4458. } else {
  4459. if len(keyword) > 0 {
  4460. 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 ?"
  4461. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, keyword)
  4462. } else {
  4463. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and is_settle=?"
  4464. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  4465. }
  4466. }
  4467. } else {
  4468. if len(execution_frequency) > 0 {
  4469. if len(keyword) > 0 {
  4470. 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 ?"
  4471. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency, keyword)
  4472. } else {
  4473. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_frequency = ?"
  4474. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  4475. }
  4476. } else {
  4477. if len(keyword) > 0 {
  4478. 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 ?"
  4479. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, keyword)
  4480. } else {
  4481. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  4482. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  4483. }
  4484. }
  4485. }
  4486. }
  4487. }
  4488. } else if patientType == 2 {
  4489. if patient_id > 0 {
  4490. if execution_state > 0 {
  4491. if cost_type > 0 {
  4492. if len(execution_frequency) > 0 {
  4493. if len(keyword) > 0 {
  4494. 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 ?"
  4495. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4496. } else {
  4497. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?) and execution_state = ? and is_settle=? and execution_frequency = ?"
  4498. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4499. }
  4500. } else {
  4501. if len(keyword) > 0 {
  4502. 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 ?"
  4503. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  4504. } else {
  4505. 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=?"
  4506. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4507. }
  4508. }
  4509. } else {
  4510. if len(execution_frequency) > 0 {
  4511. if len(keyword) > 0 {
  4512. 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 ?"
  4513. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  4514. } else {
  4515. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?) and execution_state = ?and execution_frequency = ?"
  4516. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4517. }
  4518. } else {
  4519. if len(keyword) > 0 {
  4520. 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 ?"
  4521. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  4522. } else {
  4523. 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 = ?"
  4524. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4525. }
  4526. }
  4527. }
  4528. } else {
  4529. if cost_type > 0 {
  4530. if len(execution_frequency) > 0 {
  4531. if len(keyword) > 0 {
  4532. 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 ?"
  4533. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  4534. } else {
  4535. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?) and is_settle=? and execution_frequency = ?"
  4536. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4537. }
  4538. } else {
  4539. if len(keyword) > 0 {
  4540. 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 ?"
  4541. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  4542. } else {
  4543. 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=?"
  4544. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4545. }
  4546. }
  4547. } else {
  4548. if len(execution_frequency) > 0 {
  4549. if len(keyword) > 0 {
  4550. 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 ?"
  4551. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  4552. } else {
  4553. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?)and execution_frequency = ?"
  4554. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4555. }
  4556. } else {
  4557. if len(keyword) > 0 {
  4558. 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 ?"
  4559. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  4560. } else {
  4561. 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 = ?)"
  4562. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4563. }
  4564. }
  4565. }
  4566. }
  4567. } else {
  4568. if execution_state > 0 {
  4569. if cost_type > 0 {
  4570. if len(execution_frequency) > 0 {
  4571. if len(keyword) > 0 {
  4572. 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 ?"
  4573. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  4574. } else {
  4575. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1) and execution_state = ? and is_settle=? and execution_frequency = ?"
  4576. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4577. }
  4578. } else {
  4579. if len(keyword) > 0 {
  4580. 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 ?"
  4581. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  4582. } else {
  4583. 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=?"
  4584. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4585. }
  4586. }
  4587. } else {
  4588. if len(execution_frequency) > 0 {
  4589. if len(keyword) > 0 {
  4590. 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 ?"
  4591. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  4592. } else {
  4593. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1) and execution_state = ? and execution_frequency = ?"
  4594. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4595. }
  4596. } else {
  4597. if len(keyword) > 0 {
  4598. 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 ?"
  4599. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  4600. } else {
  4601. 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 = ?"
  4602. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4603. }
  4604. }
  4605. }
  4606. } else {
  4607. if cost_type > 0 {
  4608. if len(execution_frequency) > 0 {
  4609. if len(keyword) > 0 {
  4610. 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 ?"
  4611. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  4612. } else {
  4613. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1) and is_settle = ? and execution_frequency = ?"
  4614. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  4615. }
  4616. } else {
  4617. if len(keyword) > 0 {
  4618. 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 ?"
  4619. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  4620. } else {
  4621. 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 = ?"
  4622. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4623. }
  4624. }
  4625. } else {
  4626. if len(execution_frequency) > 0 {
  4627. if len(keyword) > 0 {
  4628. 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 ?"
  4629. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  4630. } else {
  4631. 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 = ?"
  4632. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  4633. }
  4634. } else {
  4635. if len(keyword) > 0 {
  4636. 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 ?"
  4637. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  4638. } else {
  4639. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  4640. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4641. }
  4642. }
  4643. }
  4644. }
  4645. }
  4646. }
  4647. } else if adviceType == 1 {
  4648. if patientType == 0 {
  4649. if patient_id > 0 {
  4650. if execution_state > 0 {
  4651. if cost_type > 0 {
  4652. if len(execution_frequency) > 0 {
  4653. if len(keyword) > 0 {
  4654. 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 ?"
  4655. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4656. } else {
  4657. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  4658. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4659. }
  4660. } else {
  4661. if len(keyword) > 0 {
  4662. 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 ?"
  4663. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  4664. } else {
  4665. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  4666. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4667. }
  4668. }
  4669. } else {
  4670. if len(execution_frequency) > 0 {
  4671. if len(keyword) > 0 {
  4672. 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 ?"
  4673. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  4674. } else {
  4675. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  4676. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4677. }
  4678. } else {
  4679. if len(keyword) > 0 {
  4680. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  4681. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  4682. } else {
  4683. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ?"
  4684. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4685. }
  4686. }
  4687. }
  4688. } else {
  4689. if cost_type > 0 {
  4690. if len(execution_frequency) > 0 {
  4691. if len(keyword) > 0 {
  4692. 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 ?"
  4693. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  4694. } else {
  4695. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  4696. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4697. }
  4698. } else {
  4699. if len(keyword) > 0 {
  4700. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? and advice_name like ? "
  4701. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  4702. } else {
  4703. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? "
  4704. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4705. }
  4706. }
  4707. } else {
  4708. if len(execution_frequency) > 0 {
  4709. if len(keyword) > 0 {
  4710. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and advice_name like ?"
  4711. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  4712. } else {
  4713. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
  4714. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4715. }
  4716. }
  4717. }
  4718. }
  4719. } else {
  4720. if execution_state > 0 {
  4721. if cost_type > 0 {
  4722. if len(execution_frequency) > 0 {
  4723. if len(keyword) > 0 {
  4724. 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 ?"
  4725. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  4726. } else {
  4727. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  4728. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4729. }
  4730. } else {
  4731. if len(keyword) > 0 {
  4732. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  4733. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  4734. } else {
  4735. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ?"
  4736. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4737. }
  4738. }
  4739. } else {
  4740. if len(execution_frequency) > 0 {
  4741. if len(keyword) > 0 {
  4742. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  4743. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  4744. } else {
  4745. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and execution_frequency = ?"
  4746. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4747. }
  4748. } else {
  4749. if len(keyword) > 0 {
  4750. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and advice_name like ?"
  4751. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  4752. } else {
  4753. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ?"
  4754. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4755. }
  4756. }
  4757. }
  4758. } else {
  4759. if cost_type > 0 {
  4760. if len(keyword) > 0 {
  4761. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = ? and advice_name like ?"
  4762. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  4763. } else {
  4764. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = ? "
  4765. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4766. }
  4767. } else {
  4768. if len(keyword) > 0 {
  4769. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and advice_name like ?"
  4770. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  4771. } else {
  4772. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  4773. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4774. }
  4775. }
  4776. }
  4777. }
  4778. } else if patientType == 1 {
  4779. if patient_id > 0 {
  4780. if execution_state > 0 {
  4781. if cost_type > 0 {
  4782. if len(execution_frequency) > 0 {
  4783. if len(keyword) > 0 {
  4784. 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 ?"
  4785. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4786. } else {
  4787. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  4788. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  4789. }
  4790. } else {
  4791. if len(keyword) > 0 {
  4792. 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 ?"
  4793. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, keyword)
  4794. } else {
  4795. 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 = ?"
  4796. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  4797. }
  4798. }
  4799. } else {
  4800. if len(execution_frequency) > 0 {
  4801. if len(keyword) > 0 {
  4802. 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 ?"
  4803. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  4804. } else {
  4805. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  4806. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  4807. }
  4808. } else {
  4809. if len(keyword) > 0 {
  4810. 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 ?"
  4811. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, keyword)
  4812. } else {
  4813. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  4814. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  4815. }
  4816. }
  4817. }
  4818. } else {
  4819. if cost_type > 0 {
  4820. if len(execution_frequency) > 0 {
  4821. if len(keyword) > 0 {
  4822. 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 ?"
  4823. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  4824. } else {
  4825. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and is_settle = ?and execution_frequency = ?"
  4826. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  4827. }
  4828. } else {
  4829. if len(keyword) > 0 {
  4830. 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 ?"
  4831. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, keyword)
  4832. } else {
  4833. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  4834. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  4835. }
  4836. }
  4837. } else {
  4838. if len(execution_frequency) > 0 {
  4839. if len(keyword) > 0 {
  4840. 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 ?"
  4841. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency, keyword)
  4842. } else {
  4843. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  4844. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  4845. }
  4846. } else {
  4847. if len(keyword) > 0 {
  4848. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and advice_name like ?"
  4849. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, keyword)
  4850. } else {
  4851. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
  4852. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  4853. }
  4854. }
  4855. }
  4856. }
  4857. } else {
  4858. if execution_state > 0 {
  4859. if cost_type > 0 {
  4860. if len(execution_frequency) > 0 {
  4861. if len(keyword) > 0 {
  4862. 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 ?"
  4863. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  4864. } else {
  4865. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=? and is_settle = ?and execution_frequency = ?"
  4866. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  4867. }
  4868. } else {
  4869. if len(keyword) > 0 {
  4870. 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 ?"
  4871. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, keyword)
  4872. } else {
  4873. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=? and is_settle = ?"
  4874. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  4875. }
  4876. }
  4877. } else {
  4878. if len(execution_frequency) > 0 {
  4879. if len(keyword) > 0 {
  4880. 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 ?"
  4881. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency, keyword)
  4882. } else {
  4883. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?and execution_frequency = ?"
  4884. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  4885. }
  4886. } else {
  4887. if len(keyword) > 0 {
  4888. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=? and advice_name like ?"
  4889. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, keyword)
  4890. } else {
  4891. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?"
  4892. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  4893. }
  4894. }
  4895. }
  4896. } else {
  4897. if cost_type > 0 {
  4898. if len(execution_frequency) > 0 {
  4899. if len(keyword) > 0 {
  4900. 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 ?"
  4901. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency, keyword)
  4902. } else {
  4903. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  4904. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  4905. }
  4906. } else {
  4907. if len(keyword) > 0 {
  4908. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? and advice_name like ?"
  4909. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, keyword)
  4910. } else {
  4911. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? "
  4912. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  4913. }
  4914. }
  4915. } else {
  4916. if len(execution_frequency) > 0 {
  4917. if len(keyword) > 0 {
  4918. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_frequency = ? and advice_name like ?"
  4919. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency, keyword)
  4920. } else {
  4921. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_frequency = ?"
  4922. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  4923. }
  4924. } else {
  4925. if len(keyword) > 0 {
  4926. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and advice_name like ?"
  4927. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, keyword)
  4928. } else {
  4929. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  4930. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  4931. }
  4932. }
  4933. }
  4934. }
  4935. }
  4936. } else if patientType == 2 {
  4937. if patient_id > 0 {
  4938. if execution_state > 0 {
  4939. if cost_type > 0 {
  4940. if len(execution_frequency) > 0 {
  4941. if len(keyword) > 0 {
  4942. 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 ?"
  4943. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4944. } else {
  4945. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ?and execution_frequency = ?"
  4946. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4947. }
  4948. } else {
  4949. if len(keyword) > 0 {
  4950. 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 ?"
  4951. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  4952. } else {
  4953. 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 = ?"
  4954. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4955. }
  4956. }
  4957. } else {
  4958. if len(execution_frequency) > 0 {
  4959. if len(keyword) > 0 {
  4960. 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 ?"
  4961. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  4962. } else {
  4963. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ? and execution_frequency = ?"
  4964. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4965. }
  4966. } else {
  4967. if len(keyword) > 0 {
  4968. 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 ?"
  4969. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  4970. } else {
  4971. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  4972. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4973. }
  4974. }
  4975. }
  4976. } else {
  4977. if cost_type > 0 {
  4978. if len(execution_frequency) > 0 {
  4979. if len(keyword) > 0 {
  4980. 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 ?"
  4981. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  4982. } else {
  4983. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and is_settle = ? and execution_frequency = ?"
  4984. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4985. }
  4986. } else {
  4987. if len(keyword) > 0 {
  4988. 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 ?"
  4989. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  4990. } else {
  4991. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  4992. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4993. }
  4994. }
  4995. } else {
  4996. if len(execution_frequency) > 0 {
  4997. if len(keyword) > 0 {
  4998. 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 ?"
  4999. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  5000. } else {
  5001. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_frequency = ?"
  5002. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  5003. }
  5004. } else {
  5005. if len(keyword) > 0 {
  5006. 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 ?"
  5007. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  5008. } else {
  5009. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
  5010. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5011. }
  5012. }
  5013. }
  5014. }
  5015. } else {
  5016. if execution_state > 0 {
  5017. if cost_type > 0 {
  5018. if len(execution_frequency) > 0 {
  5019. if len(keyword) > 0 {
  5020. 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 ?"
  5021. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  5022. } else {
  5023. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5024. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  5025. }
  5026. } else {
  5027. if len(keyword) > 0 {
  5028. 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 ?"
  5029. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  5030. } else {
  5031. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  5032. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5033. }
  5034. }
  5035. } else {
  5036. if len(execution_frequency) > 0 {
  5037. if len(keyword) > 0 {
  5038. 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 ?"
  5039. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  5040. } else {
  5041. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and execution_frequency = ?"
  5042. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  5043. }
  5044. } else {
  5045. if len(keyword) > 0 {
  5046. 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 ?"
  5047. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  5048. } else {
  5049. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ?"
  5050. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5051. }
  5052. }
  5053. }
  5054. } else {
  5055. if cost_type > 0 {
  5056. if len(execution_frequency) > 0 {
  5057. if len(keyword) > 0 {
  5058. 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 ?"
  5059. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  5060. } else {
  5061. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  5062. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  5063. }
  5064. } else {
  5065. if len(keyword) > 0 {
  5066. 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 ?"
  5067. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  5068. } else {
  5069. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ?"
  5070. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5071. }
  5072. }
  5073. } else {
  5074. if len(execution_frequency) > 0 {
  5075. if len(keyword) > 0 {
  5076. 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 ?"
  5077. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  5078. } else {
  5079. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_frequency = ?"
  5080. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  5081. }
  5082. } else {
  5083. if len(keyword) > 0 {
  5084. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and advice_name like ?"
  5085. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  5086. } else {
  5087. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  5088. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5089. }
  5090. }
  5091. }
  5092. }
  5093. }
  5094. }
  5095. } else if adviceType == 3 {
  5096. if patientType == 0 {
  5097. if patient_id > 0 {
  5098. if execution_state > 0 {
  5099. if cost_type > 0 {
  5100. if len(execution_frequency) > 0 {
  5101. if len(keyword) > 0 {
  5102. 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 ?"
  5103. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5104. } else {
  5105. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency =?"
  5106. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  5107. }
  5108. } else {
  5109. if len(keyword) > 0 {
  5110. 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 ?"
  5111. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  5112. } else {
  5113. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  5114. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5115. }
  5116. }
  5117. } else {
  5118. if len(execution_frequency) > 0 {
  5119. if len(keyword) > 0 {
  5120. 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 ?"
  5121. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  5122. } else {
  5123. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency =?"
  5124. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  5125. }
  5126. } else {
  5127. if len(keyword) > 0 {
  5128. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  5129. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  5130. } else {
  5131. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ?"
  5132. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5133. }
  5134. }
  5135. }
  5136. } else {
  5137. if cost_type > 0 {
  5138. if len(execution_frequency) > 0 {
  5139. if len(keyword) > 0 {
  5140. 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 ?"
  5141. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  5142. } else {
  5143. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency =?"
  5144. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  5145. }
  5146. } else {
  5147. if len(keyword) > 0 {
  5148. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  5149. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  5150. } else {
  5151. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? "
  5152. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5153. }
  5154. }
  5155. } else {
  5156. if len(execution_frequency) > 0 {
  5157. if len(keyword) > 0 {
  5158. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_frequency =? and advice_name like ?"
  5159. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  5160. } else {
  5161. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_frequency =?"
  5162. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  5163. }
  5164. } else {
  5165. if len(keyword) > 0 {
  5166. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and advice_name like ?"
  5167. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  5168. } else {
  5169. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? "
  5170. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5171. }
  5172. }
  5173. }
  5174. }
  5175. } else {
  5176. if execution_state > 0 {
  5177. if cost_type > 0 {
  5178. if len(execution_frequency) > 0 {
  5179. if len(keyword) > 0 {
  5180. 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 ?"
  5181. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  5182. } else {
  5183. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ? and execution_frequency =?"
  5184. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  5185. }
  5186. } else {
  5187. if len(keyword) > 0 {
  5188. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ? and advice_name like ?"
  5189. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  5190. } else {
  5191. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ?"
  5192. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5193. }
  5194. }
  5195. } else {
  5196. if len(execution_frequency) > 0 {
  5197. if len(keyword) > 0 {
  5198. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and execution_frequency =? and advice_name like ?"
  5199. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  5200. } else {
  5201. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and execution_frequency =?"
  5202. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  5203. }
  5204. } else {
  5205. if len(keyword) > 0 {
  5206. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and advice_name like ?"
  5207. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  5208. } else {
  5209. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? "
  5210. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5211. }
  5212. }
  5213. }
  5214. } else {
  5215. if cost_type > 0 {
  5216. if len(execution_frequency) > 0 {
  5217. if len(keyword) > 0 {
  5218. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? and execution_frequency =? and advice_name like ?"
  5219. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  5220. } else {
  5221. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? and execution_frequency =?"
  5222. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  5223. }
  5224. } else {
  5225. if len(keyword) > 0 {
  5226. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? and advice_name like ?"
  5227. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  5228. } else {
  5229. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? "
  5230. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5231. }
  5232. }
  5233. } else {
  5234. if len(execution_frequency) > 0 {
  5235. if len(keyword) > 0 {
  5236. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_frequency =? and advice_name like ?"
  5237. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  5238. } else {
  5239. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_frequency =?"
  5240. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  5241. }
  5242. } else {
  5243. if len(keyword) > 0 {
  5244. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and advice_name like ?"
  5245. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  5246. } else {
  5247. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  5248. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5249. }
  5250. }
  5251. }
  5252. }
  5253. }
  5254. } else if patientType == 1 {
  5255. if patient_id > 0 {
  5256. if execution_state > 0 {
  5257. if cost_type > 0 {
  5258. if len(execution_frequency) > 0 {
  5259. if len(keyword) > 0 {
  5260. 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 ?"
  5261. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5262. } else {
  5263. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5264. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  5265. }
  5266. } else {
  5267. if len(keyword) > 0 {
  5268. 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 ?"
  5269. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, keyword)
  5270. } else {
  5271. 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 = ?"
  5272. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  5273. }
  5274. }
  5275. } else {
  5276. if len(execution_frequency) > 0 {
  5277. if len(keyword) > 0 {
  5278. 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 ?"
  5279. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  5280. } else {
  5281. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  5282. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  5283. }
  5284. } else {
  5285. if len(keyword) > 0 {
  5286. 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 ?"
  5287. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, keyword)
  5288. } else {
  5289. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  5290. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  5291. }
  5292. }
  5293. }
  5294. } else {
  5295. if cost_type > 0 {
  5296. if len(execution_frequency) > 0 {
  5297. if len(keyword) > 0 {
  5298. 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 ?"
  5299. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  5300. } else {
  5301. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  5302. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  5303. }
  5304. } else {
  5305. if len(keyword) > 0 {
  5306. 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 ?"
  5307. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, keyword)
  5308. } else {
  5309. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  5310. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  5311. }
  5312. }
  5313. } else {
  5314. if len(execution_frequency) > 0 {
  5315. if len(keyword) > 0 {
  5316. 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 ?"
  5317. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency, keyword)
  5318. } else {
  5319. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  5320. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  5321. }
  5322. } else {
  5323. if len(keyword) > 0 {
  5324. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and advice_name like ?"
  5325. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, keyword)
  5326. } else {
  5327. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
  5328. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  5329. }
  5330. }
  5331. }
  5332. }
  5333. } else {
  5334. if execution_state > 0 {
  5335. if cost_type > 0 {
  5336. if len(execution_frequency) > 0 {
  5337. if len(keyword) > 0 {
  5338. 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 ?"
  5339. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  5340. } else {
  5341. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? and is_settle = ? and execution_frequency = ?"
  5342. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  5343. }
  5344. } else {
  5345. if len(keyword) > 0 {
  5346. 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 ?"
  5347. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, keyword)
  5348. } else {
  5349. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? and is_settle = ?"
  5350. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  5351. }
  5352. }
  5353. } else {
  5354. if len(execution_frequency) > 0 {
  5355. if len(keyword) > 0 {
  5356. 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 ? "
  5357. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency, keyword)
  5358. } else {
  5359. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =?and execution_frequency = ? "
  5360. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  5361. }
  5362. } else {
  5363. if len(keyword) > 0 {
  5364. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? and advice_name like ?"
  5365. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, keyword)
  5366. } else {
  5367. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? "
  5368. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  5369. }
  5370. }
  5371. }
  5372. } else {
  5373. if cost_type > 0 {
  5374. if len(execution_frequency) > 0 {
  5375. if len(keyword) > 0 {
  5376. 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 ?"
  5377. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency, keyword)
  5378. } else {
  5379. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  5380. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  5381. }
  5382. } else {
  5383. if len(keyword) > 0 {
  5384. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ? and advice_name like ?"
  5385. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, keyword)
  5386. } else {
  5387. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ?"
  5388. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  5389. }
  5390. }
  5391. } else {
  5392. if len(execution_frequency) > 0 {
  5393. if len(keyword) > 0 {
  5394. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_frequency = ? and advice_name like ?"
  5395. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency, keyword)
  5396. } else {
  5397. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_frequency = ?"
  5398. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  5399. }
  5400. } else {
  5401. if len(keyword) > 0 {
  5402. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and advice_name like ?"
  5403. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, keyword)
  5404. } else {
  5405. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  5406. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  5407. }
  5408. }
  5409. }
  5410. }
  5411. }
  5412. } else if patientType == 2 {
  5413. if patient_id > 0 {
  5414. if execution_state > 0 {
  5415. if cost_type > 0 {
  5416. if len(execution_frequency) > 0 {
  5417. if len(keyword) > 0 {
  5418. 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 ?"
  5419. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5420. } else {
  5421. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5422. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  5423. }
  5424. } else {
  5425. if len(keyword) > 0 {
  5426. 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 ?"
  5427. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  5428. } else {
  5429. 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 = ?"
  5430. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5431. }
  5432. }
  5433. } else {
  5434. if len(execution_frequency) > 0 {
  5435. if len(keyword) > 0 {
  5436. 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 ?"
  5437. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  5438. } else {
  5439. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ? and execution_frequency = ?"
  5440. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  5441. }
  5442. } else {
  5443. if len(keyword) > 0 {
  5444. 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 ?"
  5445. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  5446. } else {
  5447. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  5448. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5449. }
  5450. }
  5451. }
  5452. } else {
  5453. if cost_type > 0 {
  5454. if len(execution_frequency) > 0 {
  5455. if len(keyword) > 0 {
  5456. 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 ?"
  5457. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  5458. } else {
  5459. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and is_settle = ? and execution_frequency = ?"
  5460. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  5461. }
  5462. } else {
  5463. if len(keyword) > 0 {
  5464. 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 ?"
  5465. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  5466. } else {
  5467. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  5468. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5469. }
  5470. }
  5471. } else {
  5472. if len(execution_frequency) > 0 {
  5473. if len(keyword) > 0 {
  5474. 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 ?"
  5475. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  5476. } else {
  5477. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_frequency = ?"
  5478. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  5479. }
  5480. } else {
  5481. if len(keyword) > 0 {
  5482. 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 ?"
  5483. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  5484. } else {
  5485. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ?"
  5486. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5487. }
  5488. }
  5489. }
  5490. }
  5491. } else {
  5492. if execution_state > 0 {
  5493. if cost_type > 0 {
  5494. if len(execution_frequency) > 0 {
  5495. if len(keyword) > 0 {
  5496. 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 ?"
  5497. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  5498. } else {
  5499. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and is_settle = ? and execution_frequency = ?"
  5500. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  5501. }
  5502. } else {
  5503. if len(keyword) > 0 {
  5504. 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 ?"
  5505. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  5506. } else {
  5507. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and is_settle = ?"
  5508. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5509. }
  5510. }
  5511. } else {
  5512. if len(execution_frequency) > 0 {
  5513. if len(keyword) > 0 {
  5514. 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 ?"
  5515. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  5516. } else {
  5517. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and execution_frequency = ?"
  5518. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  5519. }
  5520. } else {
  5521. if len(keyword) > 0 {
  5522. 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 ?"
  5523. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  5524. } else {
  5525. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ?"
  5526. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5527. }
  5528. }
  5529. }
  5530. } else {
  5531. if cost_type > 0 {
  5532. if len(execution_frequency) > 0 {
  5533. if len(keyword) > 0 {
  5534. 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 ?"
  5535. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  5536. } else {
  5537. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  5538. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  5539. }
  5540. } else {
  5541. if len(keyword) > 0 {
  5542. 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 ?"
  5543. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  5544. } else {
  5545. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ?"
  5546. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5547. }
  5548. }
  5549. } else {
  5550. if len(execution_frequency) > 0 {
  5551. if len(keyword) > 0 {
  5552. 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 ?"
  5553. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  5554. } else {
  5555. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_frequency = ?"
  5556. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  5557. }
  5558. } else {
  5559. if len(keyword) > 0 {
  5560. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and advice_name like ?"
  5561. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  5562. } else {
  5563. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  5564. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5565. }
  5566. }
  5567. }
  5568. }
  5569. }
  5570. }
  5571. } else if adviceType == 2 && len(deliverWay) > 0 {
  5572. if patientType == 0 {
  5573. if patient_id > 0 {
  5574. if execution_state > 0 {
  5575. if cost_type > 0 {
  5576. if len(execution_frequency) > 0 {
  5577. if len(keyword) > 0 {
  5578. 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 ?"
  5579. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5580. } else {
  5581. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5582. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency)
  5583. }
  5584. } else {
  5585. if len(keyword) > 0 {
  5586. 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 ?"
  5587. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, keyword)
  5588. } else {
  5589. 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 = ?"
  5590. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  5591. }
  5592. }
  5593. } else {
  5594. if len(execution_frequency) > 0 {
  5595. if len(keyword) > 0 {
  5596. 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 ?"
  5597. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency, keyword)
  5598. } else {
  5599. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  5600. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency)
  5601. }
  5602. } else {
  5603. if len(keyword) > 0 {
  5604. 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 ?"
  5605. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, keyword)
  5606. } else {
  5607. 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 = ?"
  5608. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  5609. }
  5610. }
  5611. }
  5612. } else {
  5613. if cost_type > 0 {
  5614. if len(execution_frequency) > 0 {
  5615. if len(keyword) > 0 {
  5616. 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 ?"
  5617. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency, keyword)
  5618. } else {
  5619. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  5620. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency)
  5621. }
  5622. } else {
  5623. if len(keyword) > 0 {
  5624. 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 ?"
  5625. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, keyword)
  5626. } else {
  5627. 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 = ?"
  5628. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  5629. }
  5630. }
  5631. } else {
  5632. if len(execution_frequency) > 0 {
  5633. if len(keyword) > 0 {
  5634. 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 ?"
  5635. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency, keyword)
  5636. } else {
  5637. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and execution_frequency = ?"
  5638. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency)
  5639. }
  5640. } else {
  5641. if len(keyword) > 0 {
  5642. 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 ?"
  5643. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, keyword)
  5644. } else {
  5645. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ?"
  5646. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  5647. }
  5648. }
  5649. }
  5650. }
  5651. } else {
  5652. if execution_state > 0 {
  5653. if cost_type > 0 {
  5654. if len(execution_frequency) > 0 {
  5655. if len(keyword) > 0 {
  5656. 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 ?"
  5657. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency, keyword)
  5658. } else {
  5659. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5660. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency)
  5661. }
  5662. } else {
  5663. if len(keyword) > 0 {
  5664. 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 ?"
  5665. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, keyword)
  5666. } else {
  5667. 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 = ?"
  5668. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  5669. }
  5670. }
  5671. } else {
  5672. if len(execution_frequency) > 0 {
  5673. if len(keyword) > 0 {
  5674. 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 ?"
  5675. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency, keyword)
  5676. } else {
  5677. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and execution_state = ? and execution_frequency = ?"
  5678. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency)
  5679. }
  5680. } else {
  5681. if len(keyword) > 0 {
  5682. 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 ?"
  5683. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, keyword)
  5684. } else {
  5685. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and execution_state = ?"
  5686. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  5687. }
  5688. }
  5689. }
  5690. } else {
  5691. if cost_type > 0 {
  5692. if len(execution_frequency) > 0 {
  5693. if len(keyword) > 0 {
  5694. 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 ?"
  5695. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, execution_frequency, keyword)
  5696. } else {
  5697. 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 = ?"
  5698. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, execution_frequency)
  5699. }
  5700. } else {
  5701. if len(keyword) > 0 {
  5702. 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 ?"
  5703. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, keyword)
  5704. } else {
  5705. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and is_settle = ?"
  5706. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  5707. }
  5708. }
  5709. } else {
  5710. if len(execution_frequency) > 0 {
  5711. if len(keyword) > 0 {
  5712. 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 ?"
  5713. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_frequency, keyword)
  5714. } else {
  5715. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and execution_frequency = ?"
  5716. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_frequency)
  5717. }
  5718. } else {
  5719. if len(keyword) > 0 {
  5720. 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 ?"
  5721. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, keyword)
  5722. } else {
  5723. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ?"
  5724. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  5725. }
  5726. }
  5727. }
  5728. }
  5729. }
  5730. } else if patientType == 1 {
  5731. if patient_id > 0 {
  5732. if execution_state > 0 {
  5733. if cost_type > 0 {
  5734. if len(execution_frequency) > 0 {
  5735. if len(keyword) > 0 {
  5736. 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 ?"
  5737. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5738. } else {
  5739. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5740. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type, execution_frequency)
  5741. }
  5742. } else {
  5743. if len(keyword) > 0 {
  5744. 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 ?"
  5745. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type, keyword)
  5746. } else {
  5747. 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 = ?"
  5748. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type)
  5749. }
  5750. }
  5751. } else {
  5752. if len(execution_frequency) > 0 {
  5753. if len(keyword) > 0 {
  5754. 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 ?"
  5755. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, execution_frequency, keyword)
  5756. } else {
  5757. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  5758. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, execution_frequency)
  5759. }
  5760. } else {
  5761. if len(keyword) > 0 {
  5762. 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 ?"
  5763. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, keyword)
  5764. } else {
  5765. 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 = ?"
  5766. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state)
  5767. }
  5768. }
  5769. }
  5770. } else {
  5771. if cost_type > 0 {
  5772. if len(execution_frequency) > 0 {
  5773. if len(keyword) > 0 {
  5774. 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 ?"
  5775. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type, execution_frequency, keyword)
  5776. } else {
  5777. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  5778. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type, execution_frequency)
  5779. }
  5780. } else {
  5781. if len(keyword) > 0 {
  5782. 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 ?"
  5783. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type, keyword)
  5784. } else {
  5785. 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 = ?"
  5786. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type)
  5787. }
  5788. }
  5789. } else {
  5790. if len(execution_frequency) > 0 {
  5791. if len(keyword) > 0 {
  5792. 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 ?"
  5793. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_frequency, keyword)
  5794. } else {
  5795. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_frequency = ?"
  5796. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_frequency)
  5797. }
  5798. } else {
  5799. if len(keyword) > 0 {
  5800. 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 ?"
  5801. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, keyword)
  5802. } else {
  5803. 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 = ?"
  5804. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
  5805. }
  5806. }
  5807. }
  5808. }
  5809. } else {
  5810. if execution_state > 0 {
  5811. if cost_type > 0 {
  5812. if len(execution_frequency) > 0 {
  5813. if len(keyword) > 0 {
  5814. 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 ?"
  5815. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type, execution_frequency, keyword)
  5816. } else {
  5817. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5818. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type, execution_frequency)
  5819. }
  5820. } else {
  5821. if len(keyword) > 0 {
  5822. 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 ?"
  5823. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type, keyword)
  5824. } else {
  5825. 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 = ?"
  5826. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type)
  5827. }
  5828. }
  5829. } else {
  5830. if len(execution_frequency) > 0 {
  5831. if len(keyword) > 0 {
  5832. 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 ?"
  5833. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, execution_frequency, keyword)
  5834. } else {
  5835. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and execution_state = ? and execution_frequency = ?"
  5836. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, execution_frequency)
  5837. }
  5838. } else {
  5839. if len(keyword) > 0 {
  5840. 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 ?"
  5841. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, keyword)
  5842. } else {
  5843. 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 = ?"
  5844. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state)
  5845. }
  5846. }
  5847. }
  5848. } else {
  5849. if cost_type > 0 {
  5850. if len(execution_frequency) > 0 {
  5851. if len(keyword) > 0 {
  5852. 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 ?"
  5853. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type, execution_frequency, keyword)
  5854. } else {
  5855. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and is_settle = ? and execution_frequency = ?"
  5856. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type, execution_frequency)
  5857. }
  5858. } else {
  5859. if len(keyword) > 0 {
  5860. 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 ?"
  5861. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type, keyword)
  5862. } else {
  5863. 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 = ?"
  5864. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type)
  5865. }
  5866. }
  5867. } else {
  5868. if len(execution_frequency) > 0 {
  5869. if len(keyword) > 0 {
  5870. 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 ?"
  5871. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_frequency, keyword)
  5872. } else {
  5873. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and execution_frequency = ?"
  5874. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_frequency)
  5875. }
  5876. } else {
  5877. if len(keyword) > 0 {
  5878. 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 ?"
  5879. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, keyword)
  5880. } else {
  5881. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? "
  5882. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  5883. }
  5884. }
  5885. }
  5886. }
  5887. }
  5888. } else if patientType == 2 {
  5889. if patient_id > 0 {
  5890. if execution_state > 0 {
  5891. if cost_type > 0 {
  5892. if len(execution_frequency) > 0 {
  5893. if len(keyword) > 0 {
  5894. 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 ?"
  5895. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5896. } else {
  5897. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5898. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency)
  5899. }
  5900. } else {
  5901. if len(keyword) > 0 {
  5902. 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 ?"
  5903. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, keyword)
  5904. } else {
  5905. 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 = ?"
  5906. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  5907. }
  5908. }
  5909. } else {
  5910. if len(execution_frequency) > 0 {
  5911. if len(keyword) > 0 {
  5912. 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 ?"
  5913. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency, keyword)
  5914. } else {
  5915. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  5916. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency)
  5917. }
  5918. } else {
  5919. if len(keyword) > 0 {
  5920. 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 ?"
  5921. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, keyword)
  5922. } else {
  5923. 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 = ?"
  5924. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  5925. }
  5926. }
  5927. }
  5928. } else {
  5929. if cost_type > 0 {
  5930. if len(execution_frequency) > 0 {
  5931. if len(keyword) > 0 {
  5932. 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 ?"
  5933. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency, keyword)
  5934. } else {
  5935. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  5936. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency)
  5937. }
  5938. } else {
  5939. if len(keyword) > 0 {
  5940. 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 ?"
  5941. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, keyword)
  5942. } else {
  5943. 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 = ?"
  5944. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  5945. }
  5946. }
  5947. } else {
  5948. if len(execution_frequency) > 0 {
  5949. if len(keyword) > 0 {
  5950. 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 ?"
  5951. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency, keyword)
  5952. } else {
  5953. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_frequency = ?"
  5954. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency)
  5955. }
  5956. } else {
  5957. if len(keyword) > 0 {
  5958. 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 ?"
  5959. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, keyword)
  5960. } else {
  5961. 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 = ?"
  5962. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  5963. }
  5964. }
  5965. }
  5966. }
  5967. } else {
  5968. if execution_state > 0 {
  5969. if cost_type > 0 {
  5970. if len(execution_frequency) > 0 {
  5971. if len(keyword) > 0 {
  5972. 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 ?"
  5973. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency, keyword)
  5974. } else {
  5975. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5976. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency)
  5977. }
  5978. } else {
  5979. if len(keyword) > 0 {
  5980. 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 ?"
  5981. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, keyword)
  5982. } else {
  5983. 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 = ?"
  5984. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  5985. }
  5986. }
  5987. } else {
  5988. if len(execution_frequency) > 0 {
  5989. if len(keyword) > 0 {
  5990. 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 ?"
  5991. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency, keyword)
  5992. } else {
  5993. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and execution_state = ? and execution_frequency = ?"
  5994. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency)
  5995. }
  5996. } else {
  5997. if len(keyword) > 0 {
  5998. 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 ?"
  5999. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, keyword)
  6000. } else {
  6001. 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 = ?"
  6002. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  6003. }
  6004. }
  6005. }
  6006. } else {
  6007. if cost_type > 0 {
  6008. if len(execution_frequency) > 0 {
  6009. if len(keyword) > 0 {
  6010. 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 ?"
  6011. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, keyword)
  6012. } else {
  6013. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and is_settle = ?"
  6014. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  6015. }
  6016. } else {
  6017. if len(keyword) > 0 {
  6018. 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 ?"
  6019. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, keyword)
  6020. } else {
  6021. 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 = ?"
  6022. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  6023. }
  6024. }
  6025. } else {
  6026. if len(keyword) > 0 {
  6027. 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 ?"
  6028. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, keyword)
  6029. } else {
  6030. 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 = ?"
  6031. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  6032. }
  6033. }
  6034. }
  6035. }
  6036. }
  6037. } else if adviceType == 2 && len(deliverWay) <= 0 {
  6038. if patientType == 0 {
  6039. if patient_id > 0 {
  6040. if execution_state > 0 {
  6041. if cost_type > 0 {
  6042. if len(execution_frequency) > 0 {
  6043. if len(keyword) > 0 {
  6044. 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 ?"
  6045. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  6046. } else {
  6047. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  6048. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  6049. }
  6050. } else {
  6051. if len(keyword) > 0 {
  6052. 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 ?"
  6053. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  6054. } else {
  6055. 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 = ?"
  6056. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6057. }
  6058. }
  6059. } else {
  6060. if len(execution_frequency) > 0 {
  6061. if len(keyword) > 0 {
  6062. 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 ?"
  6063. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  6064. } else {
  6065. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  6066. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  6067. }
  6068. } else {
  6069. if len(keyword) > 0 {
  6070. 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 ?"
  6071. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  6072. } else {
  6073. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and execution_state = ?"
  6074. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6075. }
  6076. }
  6077. }
  6078. } else {
  6079. if cost_type > 0 {
  6080. if len(execution_frequency) > 0 {
  6081. if len(keyword) > 0 {
  6082. 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 ?"
  6083. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  6084. } else {
  6085. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  6086. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  6087. }
  6088. } else {
  6089. if len(keyword) > 0 {
  6090. 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 ?"
  6091. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  6092. } else {
  6093. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and is_settle = ?"
  6094. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6095. }
  6096. }
  6097. } else {
  6098. if len(execution_frequency) > 0 {
  6099. if len(keyword) > 0 {
  6100. 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 ?"
  6101. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  6102. } else {
  6103. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and execution_frequency = ?"
  6104. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  6105. }
  6106. } else {
  6107. if len(keyword) > 0 {
  6108. 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 ?"
  6109. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  6110. } else {
  6111. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ?"
  6112. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6113. }
  6114. }
  6115. }
  6116. }
  6117. } else {
  6118. if execution_state > 0 {
  6119. if cost_type > 0 {
  6120. if len(execution_frequency) > 0 {
  6121. if len(keyword) > 0 {
  6122. 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 ?"
  6123. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  6124. } else {
  6125. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  6126. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  6127. }
  6128. } else {
  6129. if len(keyword) > 0 {
  6130. 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 ?"
  6131. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  6132. } else {
  6133. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and execution_state = ? and is_settle = ?"
  6134. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6135. }
  6136. }
  6137. } else {
  6138. if len(execution_frequency) > 0 {
  6139. if len(keyword) > 0 {
  6140. 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 ?"
  6141. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  6142. } else {
  6143. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and execution_state = ?and execution_frequency = ?"
  6144. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  6145. }
  6146. } else {
  6147. if len(keyword) > 0 {
  6148. 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 ?"
  6149. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  6150. } else {
  6151. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and execution_state = ?"
  6152. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6153. }
  6154. }
  6155. }
  6156. } else {
  6157. if cost_type > 0 {
  6158. if len(execution_frequency) > 0 {
  6159. if len(keyword) > 0 {
  6160. 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 ?"
  6161. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  6162. } else {
  6163. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and is_settle = ? and execution_frequency = ?"
  6164. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  6165. }
  6166. }
  6167. } else {
  6168. if len(execution_frequency) > 0 {
  6169. if len(keyword) > 0 {
  6170. 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 ?"
  6171. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  6172. } else {
  6173. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and execution_frequency = ?"
  6174. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  6175. }
  6176. } else {
  6177. if len(keyword) > 0 {
  6178. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and advice_name like ?"
  6179. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  6180. } else {
  6181. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ?"
  6182. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6183. }
  6184. }
  6185. }
  6186. }
  6187. }
  6188. } else if patientType == 1 {
  6189. if patient_id > 0 {
  6190. if execution_state > 0 {
  6191. if cost_type > 0 {
  6192. if len(execution_frequency) > 0 {
  6193. if len(keyword) > 0 {
  6194. 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 ?"
  6195. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  6196. } else {
  6197. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  6198. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  6199. }
  6200. } else {
  6201. if len(keyword) > 0 {
  6202. 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 ?"
  6203. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, keyword)
  6204. } else {
  6205. 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 = ?"
  6206. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  6207. }
  6208. }
  6209. } else {
  6210. if len(execution_frequency) > 0 {
  6211. if len(keyword) > 0 {
  6212. 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 ?"
  6213. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  6214. } else {
  6215. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  6216. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  6217. }
  6218. } else {
  6219. if len(keyword) > 0 {
  6220. 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 ?"
  6221. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, keyword)
  6222. } else {
  6223. 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 = ?"
  6224. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  6225. }
  6226. }
  6227. }
  6228. } else {
  6229. if cost_type > 0 {
  6230. if len(execution_frequency) > 0 {
  6231. if len(keyword) > 0 {
  6232. 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 ?"
  6233. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  6234. } else {
  6235. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  6236. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  6237. }
  6238. } else {
  6239. if len(keyword) > 0 {
  6240. 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 ?"
  6241. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, keyword)
  6242. } else {
  6243. 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 = ?"
  6244. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  6245. }
  6246. }
  6247. } else {
  6248. if len(execution_frequency) > 0 {
  6249. if len(keyword) > 0 {
  6250. 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 ?"
  6251. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency, keyword)
  6252. } else {
  6253. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  6254. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  6255. }
  6256. } else {
  6257. if len(keyword) > 0 {
  6258. 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 ?"
  6259. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, keyword)
  6260. } else {
  6261. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ?"
  6262. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  6263. }
  6264. }
  6265. }
  6266. }
  6267. } else {
  6268. if execution_state > 0 {
  6269. if cost_type > 0 {
  6270. if len(execution_frequency) > 0 {
  6271. if len(keyword) > 0 {
  6272. 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 ?"
  6273. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  6274. } else {
  6275. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  6276. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  6277. }
  6278. } else {
  6279. if len(keyword) > 0 {
  6280. 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 ?"
  6281. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, keyword)
  6282. } else {
  6283. 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 = ?"
  6284. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  6285. }
  6286. }
  6287. } else {
  6288. if len(execution_frequency) > 0 {
  6289. if len(keyword) > 0 {
  6290. 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 ?"
  6291. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency, keyword)
  6292. } else {
  6293. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and execution_state = ? and execution_frequency = ?"
  6294. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  6295. }
  6296. } else {
  6297. if len(keyword) > 0 {
  6298. 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 ?"
  6299. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, keyword)
  6300. } else {
  6301. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and execution_state = ?"
  6302. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  6303. }
  6304. }
  6305. }
  6306. } else {
  6307. if cost_type > 0 {
  6308. if len(execution_frequency) > 0 {
  6309. if len(keyword) > 0 {
  6310. 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 ?"
  6311. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency, keyword)
  6312. } else {
  6313. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  6314. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  6315. }
  6316. } else {
  6317. if len(keyword) > 0 {
  6318. 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 ?"
  6319. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, keyword)
  6320. } else {
  6321. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and is_settle = ?"
  6322. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  6323. }
  6324. }
  6325. } else {
  6326. if len(execution_frequency) > 0 {
  6327. if len(keyword) > 0 {
  6328. 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 ?"
  6329. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency, keyword)
  6330. } else {
  6331. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and execution_frequency = ?"
  6332. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  6333. }
  6334. } else {
  6335. if len(keyword) > 0 {
  6336. 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 ?"
  6337. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, keyword)
  6338. } else {
  6339. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ?"
  6340. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  6341. }
  6342. }
  6343. }
  6344. }
  6345. }
  6346. } else if patientType == 2 {
  6347. if patient_id > 0 {
  6348. if execution_state > 0 {
  6349. if cost_type > 0 {
  6350. if len(execution_frequency) > 0 {
  6351. if len(keyword) > 0 {
  6352. 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 ?"
  6353. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  6354. } else {
  6355. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency=?"
  6356. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  6357. }
  6358. } else {
  6359. if len(keyword) > 0 {
  6360. 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 ?"
  6361. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  6362. } else {
  6363. 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 = ?"
  6364. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6365. }
  6366. }
  6367. } else {
  6368. if len(execution_frequency) > 0 {
  6369. if len(keyword) > 0 {
  6370. 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 ?"
  6371. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  6372. } else {
  6373. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and execution_state = ? and execution_frequency=?"
  6374. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  6375. }
  6376. } else {
  6377. if len(keyword) > 0 {
  6378. 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 ?"
  6379. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  6380. } else {
  6381. 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 = ?"
  6382. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6383. }
  6384. }
  6385. }
  6386. } else {
  6387. if cost_type > 0 {
  6388. if len(execution_frequency) > 0 {
  6389. if len(keyword) > 0 {
  6390. 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 ?"
  6391. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  6392. } else {
  6393. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and is_settle = ? and execution_frequency=?"
  6394. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  6395. }
  6396. } else {
  6397. if len(keyword) > 0 {
  6398. 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 ?"
  6399. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  6400. } else {
  6401. 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 = ?"
  6402. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6403. }
  6404. }
  6405. } else {
  6406. if len(execution_frequency) > 0 {
  6407. if len(keyword) > 0 {
  6408. 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 ?"
  6409. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  6410. } else {
  6411. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and execution_frequency=?"
  6412. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  6413. }
  6414. } else {
  6415. if len(keyword) > 0 {
  6416. 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 ?"
  6417. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  6418. } else {
  6419. 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 = ?"
  6420. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6421. }
  6422. }
  6423. }
  6424. }
  6425. } else {
  6426. if execution_state > 0 {
  6427. if cost_type > 0 {
  6428. if len(execution_frequency) > 0 {
  6429. if len(keyword) > 0 {
  6430. 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 ?"
  6431. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  6432. } else {
  6433. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and execution_state = ? and is_settle = ? and execution_frequency = ?"
  6434. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  6435. }
  6436. } else {
  6437. if len(keyword) > 0 {
  6438. 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 ?"
  6439. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  6440. } else {
  6441. 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 = ?"
  6442. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6443. }
  6444. }
  6445. } else {
  6446. if len(execution_frequency) > 0 {
  6447. if len(keyword) > 0 {
  6448. 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 ?"
  6449. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  6450. } else {
  6451. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and execution_state = ? and execution_frequency = ? "
  6452. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  6453. }
  6454. } else {
  6455. if len(keyword) > 0 {
  6456. 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 ?"
  6457. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  6458. } else {
  6459. 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 = ?"
  6460. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6461. }
  6462. }
  6463. }
  6464. } else {
  6465. if cost_type > 0 {
  6466. if len(execution_frequency) > 0 {
  6467. if len(keyword) > 0 {
  6468. 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 ?"
  6469. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  6470. } else {
  6471. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  6472. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  6473. }
  6474. } else {
  6475. if len(keyword) > 0 {
  6476. 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 ?"
  6477. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  6478. } else {
  6479. 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 = ?"
  6480. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6481. }
  6482. }
  6483. } else {
  6484. if len(execution_frequency) > 0 {
  6485. if len(keyword) > 0 {
  6486. 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 ?"
  6487. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  6488. } else {
  6489. 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 = ?"
  6490. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  6491. }
  6492. } else {
  6493. if len(keyword) > 0 {
  6494. 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 ?"
  6495. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  6496. } else {
  6497. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0"
  6498. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6499. }
  6500. }
  6501. }
  6502. }
  6503. }
  6504. }
  6505. }
  6506. db := readDb.Table("xt_schedule")
  6507. if scheduleType > 0 {
  6508. db = db.Where("schedule_type = ?", scheduleType)
  6509. }
  6510. if partitonType > 0 {
  6511. db = db.Where("partition_id = ?", partitonType)
  6512. }
  6513. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6514. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6515. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6516. }).
  6517. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6518. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6519. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6520. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6521. Preload("DoctorAdvices", adviceCondition...).
  6522. Where("status = 1 AND user_org_id = ?", orgID)
  6523. if scheduleDate != 0 {
  6524. db = db.Where("schedule_date = ?", scheduleDate)
  6525. }
  6526. err := db.Find(&vms).Error
  6527. return vms, err
  6528. }
  6529. 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) {
  6530. var vms []*MScheduleDoctorAdviceVM
  6531. adviceWhere := ""
  6532. adviceCondition := []interface{}{}
  6533. if adviceType == 0 {
  6534. if patientType == 0 {
  6535. if patient_id > 0 {
  6536. if execution_state > 0 {
  6537. if cost_type > 0 {
  6538. 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 = ?"
  6539. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6540. } else {
  6541. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  6542. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6543. }
  6544. } else {
  6545. if cost_type > 0 {
  6546. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and is_settle = ?"
  6547. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6548. } else {
  6549. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
  6550. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6551. }
  6552. }
  6553. } else {
  6554. if execution_state > 0 {
  6555. if cost_type > 0 {
  6556. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and is_settle = ?"
  6557. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6558. } else {
  6559. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ?"
  6560. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6561. }
  6562. } else {
  6563. if cost_type > 0 {
  6564. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ?"
  6565. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6566. } else {
  6567. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  6568. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6569. }
  6570. }
  6571. }
  6572. } else if patientType == 1 {
  6573. if patient_id > 0 {
  6574. if execution_state > 0 {
  6575. if cost_type > 0 {
  6576. 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 = ?"
  6577. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  6578. } else {
  6579. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  6580. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  6581. }
  6582. } else {
  6583. if cost_type > 0 {
  6584. 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=?"
  6585. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  6586. } else {
  6587. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
  6588. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  6589. }
  6590. }
  6591. } else {
  6592. if execution_state > 0 {
  6593. if cost_type > 0 {
  6594. 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=?"
  6595. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  6596. } else {
  6597. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  6598. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  6599. }
  6600. } else {
  6601. if cost_type > 0 {
  6602. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and is_settle=?"
  6603. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  6604. } else {
  6605. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  6606. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  6607. }
  6608. }
  6609. }
  6610. } else if patientType == 2 {
  6611. if patient_id > 0 {
  6612. if execution_state > 0 {
  6613. if cost_type > 0 {
  6614. 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=?"
  6615. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6616. } else {
  6617. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?) and execution_state = ?"
  6618. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6619. }
  6620. } else {
  6621. if cost_type > 0 {
  6622. 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=?"
  6623. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6624. } else {
  6625. 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 = ?)"
  6626. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6627. }
  6628. }
  6629. } else {
  6630. if execution_state > 0 {
  6631. if cost_type > 0 {
  6632. 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=?"
  6633. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6634. } else {
  6635. 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 = ?"
  6636. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6637. }
  6638. } else {
  6639. if cost_type > 0 {
  6640. 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 = ?"
  6641. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6642. } else {
  6643. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  6644. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6645. }
  6646. }
  6647. }
  6648. }
  6649. } else if adviceType == 1 {
  6650. if patientType == 0 {
  6651. if patient_id > 0 {
  6652. if execution_state > 0 {
  6653. if cost_type > 0 {
  6654. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  6655. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6656. } else {
  6657. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ?"
  6658. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6659. }
  6660. } else {
  6661. if cost_type > 0 {
  6662. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? "
  6663. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6664. } else {
  6665. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
  6666. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6667. }
  6668. }
  6669. } else {
  6670. if execution_state > 0 {
  6671. if cost_type > 0 {
  6672. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ?"
  6673. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6674. } else {
  6675. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ?"
  6676. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6677. }
  6678. } else {
  6679. if cost_type > 0 {
  6680. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = ? "
  6681. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6682. } else {
  6683. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  6684. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6685. }
  6686. }
  6687. }
  6688. } else if patientType == 1 {
  6689. if patient_id > 0 {
  6690. if execution_state > 0 {
  6691. if cost_type > 0 {
  6692. 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 = ?"
  6693. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  6694. } else {
  6695. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  6696. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  6697. }
  6698. } else {
  6699. if cost_type > 0 {
  6700. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  6701. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  6702. } else {
  6703. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
  6704. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  6705. }
  6706. }
  6707. } else {
  6708. if execution_state > 0 {
  6709. if cost_type > 0 {
  6710. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=? and is_settle = ?"
  6711. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  6712. } else {
  6713. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?"
  6714. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  6715. }
  6716. } else {
  6717. if cost_type > 0 {
  6718. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? "
  6719. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  6720. } else {
  6721. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  6722. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  6723. }
  6724. }
  6725. }
  6726. } else if patientType == 2 {
  6727. if patient_id > 0 {
  6728. if execution_state > 0 {
  6729. if cost_type > 0 {
  6730. 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 = ?"
  6731. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6732. } else {
  6733. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  6734. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6735. }
  6736. } else {
  6737. if cost_type > 0 {
  6738. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  6739. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6740. } else {
  6741. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
  6742. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6743. }
  6744. }
  6745. } else {
  6746. if execution_state > 0 {
  6747. if cost_type > 0 {
  6748. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  6749. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6750. } else {
  6751. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ?"
  6752. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6753. }
  6754. } else {
  6755. if cost_type > 0 {
  6756. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ?"
  6757. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6758. } else {
  6759. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  6760. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6761. }
  6762. }
  6763. }
  6764. }
  6765. } else if adviceType == 3 {
  6766. if patientType == 0 {
  6767. if patient_id > 0 {
  6768. if execution_state > 0 {
  6769. if cost_type > 0 {
  6770. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  6771. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6772. } else {
  6773. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ?"
  6774. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6775. }
  6776. } else {
  6777. if cost_type > 0 {
  6778. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? "
  6779. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6780. } else {
  6781. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? "
  6782. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6783. }
  6784. }
  6785. } else {
  6786. if execution_state > 0 {
  6787. if cost_type > 0 {
  6788. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ?"
  6789. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6790. } else {
  6791. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? "
  6792. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6793. }
  6794. } else {
  6795. if cost_type > 0 {
  6796. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? "
  6797. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6798. } else {
  6799. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  6800. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6801. }
  6802. }
  6803. }
  6804. } else if patientType == 1 {
  6805. if patient_id > 0 {
  6806. if execution_state > 0 {
  6807. if cost_type > 0 {
  6808. 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 = ?"
  6809. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  6810. } else {
  6811. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  6812. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  6813. }
  6814. } else {
  6815. if cost_type > 0 {
  6816. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  6817. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  6818. } else {
  6819. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
  6820. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  6821. }
  6822. }
  6823. } else {
  6824. if execution_state > 0 {
  6825. if cost_type > 0 {
  6826. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? and is_settle = ?"
  6827. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  6828. } else {
  6829. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? "
  6830. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  6831. }
  6832. } else {
  6833. if cost_type > 0 {
  6834. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ?"
  6835. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  6836. } else {
  6837. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  6838. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  6839. }
  6840. }
  6841. }
  6842. } else if patientType == 2 {
  6843. if patient_id > 0 {
  6844. if execution_state > 0 {
  6845. if cost_type > 0 {
  6846. 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 = ?"
  6847. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6848. } else {
  6849. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  6850. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6851. }
  6852. } else {
  6853. if cost_type > 0 {
  6854. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  6855. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6856. } else {
  6857. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ?"
  6858. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6859. }
  6860. }
  6861. } else {
  6862. if execution_state > 0 {
  6863. if cost_type > 0 {
  6864. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and is_settle = ?"
  6865. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6866. } else {
  6867. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ?"
  6868. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6869. }
  6870. } else {
  6871. if cost_type > 0 {
  6872. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ?"
  6873. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6874. } else {
  6875. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  6876. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6877. }
  6878. }
  6879. }
  6880. }
  6881. } else if adviceType == 2 && len(deliverWay) > 0 {
  6882. if patientType == 0 {
  6883. if patient_id > 0 {
  6884. if execution_state > 0 {
  6885. if cost_type > 0 {
  6886. 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 = ?"
  6887. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  6888. } else {
  6889. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  6890. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  6891. }
  6892. } else {
  6893. if cost_type > 0 {
  6894. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and is_settle = ?"
  6895. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  6896. } else {
  6897. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ?"
  6898. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  6899. }
  6900. }
  6901. } else {
  6902. if execution_state > 0 {
  6903. if cost_type > 0 {
  6904. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and is_settle = ?"
  6905. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  6906. } else {
  6907. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ?"
  6908. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  6909. }
  6910. } else {
  6911. if cost_type > 0 {
  6912. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and is_settle = ?"
  6913. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  6914. } else {
  6915. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  6916. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  6917. }
  6918. }
  6919. }
  6920. } else if patientType == 1 {
  6921. if patient_id > 0 {
  6922. if execution_state > 0 {
  6923. if cost_type > 0 {
  6924. 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 = ?"
  6925. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type)
  6926. } else {
  6927. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  6928. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state)
  6929. }
  6930. } else {
  6931. if cost_type > 0 {
  6932. 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 = ?"
  6933. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type)
  6934. } else {
  6935. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ?"
  6936. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
  6937. }
  6938. }
  6939. } else {
  6940. if execution_state > 0 {
  6941. if cost_type > 0 {
  6942. 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 = ?"
  6943. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type)
  6944. } else {
  6945. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ?"
  6946. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state)
  6947. }
  6948. } else {
  6949. if cost_type > 0 {
  6950. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and is_settle = ?"
  6951. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type)
  6952. } else {
  6953. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  6954. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  6955. }
  6956. }
  6957. }
  6958. } else if patientType == 2 {
  6959. if patient_id > 0 {
  6960. if execution_state > 0 {
  6961. if cost_type > 0 {
  6962. 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 = ?"
  6963. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  6964. } else {
  6965. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ?"
  6966. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  6967. }
  6968. } else {
  6969. if cost_type > 0 {
  6970. 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 = ?"
  6971. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  6972. } else {
  6973. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ?"
  6974. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  6975. }
  6976. }
  6977. } else {
  6978. if execution_state > 0 {
  6979. if cost_type > 0 {
  6980. 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 = ?"
  6981. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  6982. } else {
  6983. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ?"
  6984. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  6985. }
  6986. } else {
  6987. if cost_type > 0 {
  6988. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and is_settle = ?"
  6989. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  6990. } else {
  6991. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  6992. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  6993. }
  6994. }
  6995. }
  6996. }
  6997. } else if adviceType == 2 && len(deliverWay) <= 0 {
  6998. if patientType == 0 {
  6999. if patient_id > 0 {
  7000. if execution_state > 0 {
  7001. if cost_type > 0 {
  7002. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  7003. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  7004. } else {
  7005. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ?"
  7006. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  7007. }
  7008. } else {
  7009. if cost_type > 0 {
  7010. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and is_settle = ?"
  7011. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  7012. } else {
  7013. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ?"
  7014. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  7015. }
  7016. }
  7017. } else {
  7018. if execution_state > 0 {
  7019. if cost_type > 0 {
  7020. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ? and is_settle = ?"
  7021. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  7022. } else {
  7023. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?"
  7024. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  7025. }
  7026. } else {
  7027. if cost_type > 0 {
  7028. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and is_settle = ?"
  7029. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  7030. } else {
  7031. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  7032. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  7033. }
  7034. }
  7035. }
  7036. } else if patientType == 1 {
  7037. if patient_id > 0 {
  7038. if execution_state > 0 {
  7039. if cost_type > 0 {
  7040. 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 = ?"
  7041. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  7042. } else {
  7043. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  7044. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  7045. }
  7046. } else {
  7047. if cost_type > 0 {
  7048. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  7049. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  7050. } else {
  7051. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ?"
  7052. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  7053. }
  7054. }
  7055. } else {
  7056. if execution_state > 0 {
  7057. if cost_type > 0 {
  7058. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ? and is_settle = ?"
  7059. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  7060. } else {
  7061. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ?"
  7062. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  7063. }
  7064. } else {
  7065. if cost_type > 0 {
  7066. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and is_settle = ?"
  7067. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  7068. } else {
  7069. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?"
  7070. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  7071. }
  7072. }
  7073. }
  7074. } else if patientType == 2 {
  7075. if patient_id > 0 {
  7076. if execution_state > 0 {
  7077. if cost_type > 0 {
  7078. 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 = ?"
  7079. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  7080. } else {
  7081. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  7082. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  7083. }
  7084. } else {
  7085. if cost_type > 0 {
  7086. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  7087. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  7088. } else {
  7089. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ?"
  7090. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  7091. }
  7092. }
  7093. } else {
  7094. if execution_state > 0 {
  7095. if cost_type > 0 {
  7096. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  7097. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  7098. } else {
  7099. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ?"
  7100. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  7101. }
  7102. } else {
  7103. if cost_type > 0 {
  7104. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and is_settle = ?"
  7105. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  7106. } else {
  7107. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  7108. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  7109. }
  7110. }
  7111. }
  7112. }
  7113. }
  7114. db := readDb.Table("xt_schedule")
  7115. if scheduleType > 0 {
  7116. db = db.Where("schedule_type = ?", scheduleType)
  7117. }
  7118. if partitonType > 0 {
  7119. db = db.Where("partition_id = ?", partitonType)
  7120. }
  7121. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7122. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7123. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7124. }).
  7125. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7126. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7127. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7128. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7129. Preload("DoctorAdvices", adviceCondition...).
  7130. Where("status = 1 AND user_org_id = ?", orgID)
  7131. if scheduleDate != 0 {
  7132. db = db.Where("schedule_date = ?", scheduleDate)
  7133. }
  7134. err := db.Find(&vms).Error
  7135. return vms, err
  7136. }
  7137. func GetLastPatientOrder(id int64) (models.XtDialysisOrder, error) {
  7138. order := models.XtDialysisOrder{}
  7139. err := XTReadDB().Where("id = ? and status = 1", id).Find(&order).Error
  7140. return order, err
  7141. }
  7142. func UpdateMobilePatient(org_id int64, patient_id int64, schedule_remark string) error {
  7143. order := models.XtPatients{}
  7144. 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
  7145. 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
  7146. return err
  7147. }
  7148. func GetDialysisTotalCount(org_id int64, patient_id int64) (models.BloodDialysisOrderCount, error) {
  7149. order := models.BloodDialysisOrderCount{}
  7150. db := XTReadDB().Table("xt_dialysis_order as o")
  7151. 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
  7152. return order, err
  7153. }
  7154. func GetDialysisTotalCountOne(org_id int64, patient_id int64) (models.BloodDialysisOrderCount, error) {
  7155. order := models.BloodDialysisOrderCount{}
  7156. db := XTReadDB().Table("xt_dialysis_order as o")
  7157. 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
  7158. return order, err
  7159. }
  7160. func UpdateDialysisOrder(patient_id int64, dialysis_date int64, user_org_id int64, dialysis_total int64) (models.DialysisOrder, error) {
  7161. order := models.DialysisOrder{}
  7162. 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
  7163. return order, err
  7164. }
  7165. func UpdateDeviceInformation(patientid int64, dialysis_date int64) error {
  7166. information := models.DeviceInformation{}
  7167. err := UserWriteDB().Model(&information).Where("patient_id = ? and date = ? and status = 1", patientid, dialysis_date).Update(map[string]interface{}{"status": 0}).Error
  7168. return err
  7169. }
  7170. func MobileGetDoubleCheckSix(orgID int64, patientID int64, recordDate int64) (models.DoubleCheck, error) {
  7171. var record models.DoubleCheck
  7172. err := readDb.Where("patient_id = ? and user_org_id = ? and status = 1 and check_date = ?", patientID, orgID, recordDate).First(&record).Error
  7173. return record, err
  7174. }
  7175. func GetFirstMonitor(patient_id int64, monit_date int64) (models.MonitoringRecord, error) {
  7176. record := models.MonitoringRecord{}
  7177. err := XTReadDB().Where("patient_id = ? and monitoring_date = ? and status=1", patient_id, monit_date).First(&record).Error
  7178. return record, err
  7179. }
  7180. func GetFirstMonitorOne(patient_id int64, monit_date int64, org_id int64) (models.MonitoringRecord, error) {
  7181. record := models.MonitoringRecord{}
  7182. err := XTReadDB().Where("patient_id = ? and monitoring_date = ? and status=1 and user_org_id=?", patient_id, monit_date, org_id).First(&record).Error
  7183. return record, err
  7184. }
  7185. func GetLastMonitor(patient_id int64, monit_date int64, org_id int64) (models.MonitoringRecord, error) {
  7186. record := models.MonitoringRecord{}
  7187. err := XTReadDB().Where("patient_id = ? and monitoring_date = ? and status=1 and user_org_id = ?", patient_id, monit_date, org_id).Last(&record).Error
  7188. return record, err
  7189. }
  7190. func UpdateFirstMonitor(id int64, catheter_operation string) (models.MonitoringRecord, error) {
  7191. record := models.MonitoringRecord{}
  7192. err := XTWriteDB().Model(&record).Where("id = ? and status= 1", id).Updates(map[string]interface{}{"dispose": catheter_operation}).Error
  7193. return record, err
  7194. }
  7195. 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) {
  7196. var vms []*HisMScheduleDoctorAdviceVM
  7197. if len(deliverWay) > 0 {
  7198. db := readDb.Table("xt_schedule")
  7199. if scheduleType > 0 {
  7200. db = db.Where("schedule_type = ?", scheduleType)
  7201. }
  7202. if partitionType > 0 {
  7203. db = db.Where("partition_id = ?", partitionType)
  7204. }
  7205. if patient_id > 0 {
  7206. if execution_state > 0 {
  7207. if cost_type > 0 {
  7208. if len(execution_frequency) > 0 {
  7209. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7210. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7211. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7212. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7213. 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).
  7214. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7215. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7216. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7217. Where("status = 1 AND user_org_id = ?", orgID)
  7218. if scheduleDate != 0 {
  7219. db = db.Where("schedule_date = ?", scheduleDate)
  7220. }
  7221. err = db.Find(&vms).Error
  7222. } else {
  7223. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7224. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7225. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7226. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7227. 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).
  7228. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7229. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7230. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7231. Where("status = 1 AND user_org_id = ?", orgID)
  7232. if scheduleDate != 0 {
  7233. db = db.Where("schedule_date = ?", scheduleDate)
  7234. }
  7235. err = db.Find(&vms).Error
  7236. }
  7237. } else {
  7238. if len(execution_frequency) > 0 {
  7239. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7240. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7241. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7242. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7243. 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).
  7244. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7245. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7246. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7247. Where("status = 1 AND user_org_id = ?", orgID)
  7248. if scheduleDate != 0 {
  7249. db = db.Where("schedule_date = ?", scheduleDate)
  7250. }
  7251. err = db.Find(&vms).Error
  7252. } else {
  7253. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7254. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7255. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7256. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7257. 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).
  7258. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7259. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7260. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7261. Where("status = 1 AND user_org_id = ?", orgID)
  7262. if scheduleDate != 0 {
  7263. db = db.Where("schedule_date = ?", scheduleDate)
  7264. }
  7265. err = db.Find(&vms).Error
  7266. }
  7267. }
  7268. } else {
  7269. if cost_type > 0 {
  7270. if len(execution_frequency) > 0 {
  7271. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7272. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7273. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7274. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7275. 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).
  7276. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7277. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7278. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7279. Where("status = 1 AND user_org_id = ?", orgID)
  7280. if scheduleDate != 0 {
  7281. db = db.Where("schedule_date = ?", scheduleDate)
  7282. }
  7283. err = db.Find(&vms).Error
  7284. } else {
  7285. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7286. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7287. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7288. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7289. 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).
  7290. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7291. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7292. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7293. Where("status = 1 AND user_org_id = ?", orgID)
  7294. if scheduleDate != 0 {
  7295. db = db.Where("schedule_date = ?", scheduleDate)
  7296. }
  7297. err = db.Find(&vms).Error
  7298. }
  7299. } else {
  7300. if len(execution_frequency) > 0 {
  7301. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7302. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7303. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7304. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7305. 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).
  7306. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7307. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7308. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7309. Where("status = 1 AND user_org_id = ?", orgID)
  7310. if scheduleDate != 0 {
  7311. db = db.Where("schedule_date = ?", scheduleDate)
  7312. }
  7313. err = db.Find(&vms).Error
  7314. } else {
  7315. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7316. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7317. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7318. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7319. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ?", orgID, scheduleDate, deliverWay, patient_id).
  7320. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7321. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7322. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7323. Where("status = 1 AND user_org_id = ?", orgID)
  7324. if scheduleDate != 0 {
  7325. db = db.Where("schedule_date = ?", scheduleDate)
  7326. }
  7327. err = db.Find(&vms).Error
  7328. }
  7329. }
  7330. }
  7331. } else {
  7332. if execution_state > 0 {
  7333. if cost_type > 0 {
  7334. if len(execution_frequency) > 0 {
  7335. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7336. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7337. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7338. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7339. 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).
  7340. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7341. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7342. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7343. Where("status = 1 AND user_org_id = ?", orgID)
  7344. if scheduleDate != 0 {
  7345. db = db.Where("schedule_date = ?", scheduleDate)
  7346. }
  7347. err = db.Find(&vms).Error
  7348. } else {
  7349. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7350. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7351. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7352. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7353. 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).
  7354. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7355. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7356. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7357. Where("status = 1 AND user_org_id = ?", orgID)
  7358. if scheduleDate != 0 {
  7359. db = db.Where("schedule_date = ?", scheduleDate)
  7360. }
  7361. err = db.Find(&vms).Error
  7362. }
  7363. } else {
  7364. if len(execution_frequency) > 0 {
  7365. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7366. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7367. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7368. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7369. 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).
  7370. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7371. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7372. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7373. Where("status = 1 AND user_org_id = ?", orgID)
  7374. if scheduleDate != 0 {
  7375. db = db.Where("schedule_date = ?", scheduleDate)
  7376. }
  7377. err = db.Find(&vms).Error
  7378. } else {
  7379. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7380. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7381. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7382. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7383. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_state = ?", orgID, scheduleDate, deliverWay, execution_state).
  7384. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7385. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7386. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7387. Where("status = 1 AND user_org_id = ?", orgID)
  7388. if scheduleDate != 0 {
  7389. db = db.Where("schedule_date = ?", scheduleDate)
  7390. }
  7391. err = db.Find(&vms).Error
  7392. }
  7393. }
  7394. } else {
  7395. if cost_type > 0 {
  7396. if len(execution_frequency) > 0 {
  7397. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7398. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7399. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7400. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7401. 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).
  7402. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7403. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7404. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7405. Where("status = 1 AND user_org_id = ?", orgID)
  7406. if scheduleDate != 0 {
  7407. db = db.Where("schedule_date = ?", scheduleDate)
  7408. }
  7409. err = db.Find(&vms).Error
  7410. } else {
  7411. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7412. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7413. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7414. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7415. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and is_settle = ?", orgID, scheduleDate, deliverWay, cost_type).
  7416. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7417. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7418. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7419. Where("status = 1 AND user_org_id = ?", orgID)
  7420. if scheduleDate != 0 {
  7421. db = db.Where("schedule_date = ?", scheduleDate)
  7422. }
  7423. err = db.Find(&vms).Error
  7424. }
  7425. } else {
  7426. if len(execution_frequency) > 0 {
  7427. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7428. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7429. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7430. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7431. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_frequency = ?", orgID, scheduleDate, deliverWay, execution_frequency).
  7432. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7433. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7434. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7435. Where("status = 1 AND user_org_id = ?", orgID)
  7436. if scheduleDate != 0 {
  7437. db = db.Where("schedule_date = ?", scheduleDate)
  7438. }
  7439. err = db.Find(&vms).Error
  7440. } else {
  7441. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7442. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7443. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7444. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7445. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  7446. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7447. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7448. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7449. Where("status = 1 AND user_org_id = ?", orgID)
  7450. if scheduleDate != 0 {
  7451. db = db.Where("schedule_date = ?", scheduleDate)
  7452. }
  7453. err = db.Find(&vms).Error
  7454. }
  7455. }
  7456. }
  7457. }
  7458. } else {
  7459. db := readDb.Table("xt_schedule")
  7460. if scheduleType > 0 {
  7461. db = db.Where("schedule_type = ?", scheduleType)
  7462. }
  7463. if partitionType > 0 {
  7464. db = db.Where("partition_id = ?", partitionType)
  7465. }
  7466. if patient_id > 0 {
  7467. if execution_state > 0 {
  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. }