mobile_dialysis_service.go 477KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970
  1. package service
  2. import (
  3. "XT_New/models"
  4. "encoding/json"
  5. "fmt"
  6. "github.com/jinzhu/gorm"
  7. "strconv"
  8. "time"
  9. )
  10. // func GetSchedualPatients(orgID int64) ([]*MDialysisScheduleVM, error) {
  11. // var vms []*MDialysisScheduleVM
  12. // err := readDb.
  13. // Table("xt_schedule as sch").
  14. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  15. // Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  16. // Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
  17. // Preload("TreatmentMode", "status = 1").
  18. // Preload("DialysisOrder", "status = 1 AND user_org_id = ?", orgID).
  19. // Preload("DialysisOrder.MonitoringRecords", "status = 1 AND user_org_id = ?", orgID).
  20. // Where("sch.status = 1 AND sch.user_org_id = ? AND schedule_date = 1536768000", orgID).
  21. // Find(&vms).
  22. // Error
  23. // return vms, err
  24. // }
  25. func MobileGetDialysisScheduals(orgID int64, scheduleDate int64, scheduleType int64) ([]*MDialysisScheduleVMForList, error) {
  26. var vms []*MDialysisScheduleVMForList
  27. db := readDb.
  28. Table("xt_schedule as sch").
  29. Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
  30. if scheduleDate != 0 {
  31. db = db.Where("schedule_date = ?", scheduleDate)
  32. }
  33. if scheduleType != 0 {
  34. db = db.Where("schedule_type = ?", scheduleType)
  35. }
  36. err := db.Find(&vms).Error
  37. //err := db.Preload("DialysisLastOrder", func(db *gorm.DB) *gorm.DB {
  38. // return db.Order("dialysis_date desc").Where(" status = 1 AND user_org_id = ? and dialysis_date>=1672502400 && dialysis_date < ?", orgID, scheduleDate)
  39. //}).Preload("DialysisSolution", "status = 1 and user_org_id = ? and solution_status = 1", orgID).Find(&vms).Error
  40. return vms, err
  41. }
  42. func GetMonitDialysisOrder(user_org_id int64, patient_id int64, scheduleDate int64) (*models.MDialysisOrderForList, error) {
  43. order := models.MDialysisOrderForList{}
  44. err := XTReadDB().Where("user_org_id = ? and status =1 and patient_id = ?", user_org_id, patient_id).Order("id desc").Last(&order).Error
  45. return &order, err
  46. }
  47. func GetMonitDialysisSolution(user_org_id int64, patient_id int64, mode_id int64) (*models.DialysisSolution, error) {
  48. solution := models.DialysisSolution{}
  49. err := XTReadDB().Where("user_org_id = ? and patient_id =? and solution_status = 1 and mode_id = ?", user_org_id, patient_id, mode_id).Find(&solution).Error
  50. return &solution, err
  51. }
  52. func MobileGetWaitingScheduals(orgID int64, scheduleDate int64) ([]*MDialysisScheduleVM, error) {
  53. var vms []*MDialysisScheduleVM
  54. db := readDb.
  55. Table("xt_schedule as sch").
  56. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  57. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  58. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  59. // Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
  60. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  61. Preload("AssessmentBeforeDislysis", "status = 1 AND user_org_id = ? AND assessment_date = ? ", orgID, scheduleDate).
  62. Preload("DialysisOrder", "status = 1 AND user_org_id = ?", orgID).
  63. Preload("Advices", "status = 1 AND user_org_id = ? AND advice_type = 2 ", orgID).
  64. Preload("TreatmentMode", "status = 1").
  65. Preload("TreatmentSummary", "status = 1 AND user_org_id = ?", orgID).
  66. Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
  67. if scheduleDate != 0 {
  68. db = db.Where("schedule_date = ?", scheduleDate)
  69. }
  70. err := db.Find(&vms).Error
  71. return vms, err
  72. }
  73. type VMTreatmentSummary struct {
  74. ID int64 `gorm:"column:id" json:"id"`
  75. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  76. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  77. AssessmentDate int64 `gorm:"column:assessment_date" json:"assessment_date"`
  78. DialysisSummary string `gorm:"column:dialysis_summary" json:"dialysis_summary" form:"dialysis_summary"`
  79. }
  80. func (VMTreatmentSummary) TableName() string {
  81. return "xt_treatment_summary"
  82. }
  83. type AssessmentAfterDislysis struct {
  84. ID int64 `gorm:"column:id" json:"id"`
  85. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  86. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  87. AssessmentDate int64 `gorm:"column:assessment_date" json:"assessment_date"`
  88. WeightAfter float64 `gorm:"column:weight_after" json:"weight_after"`
  89. Status int64 `gorm:"column:status" json:"status"`
  90. }
  91. func (AssessmentAfterDislysis) TableName() string {
  92. return "xt_assessment_after_dislysis"
  93. }
  94. type MDialysisScheduleVM struct {
  95. ID int64 `gorm:"column:id" json:"id"`
  96. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  97. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  98. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  99. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  100. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  101. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  102. ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week"`
  103. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  104. Status int64 `gorm:"column:status" json:"status"`
  105. SchedualPatient *MSchedualPatientVMList `gorm:"ForeignKey:PatientId" json:"patient"`
  106. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  107. DialysisOrder *MDialysisOrderVMList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  108. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  109. AssessmentBeforeDislysis *models.PredialysisEvaluationList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_before_dislysis"`
  110. AssessmentAfterDislysis *AssessmentAfterDislysis `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_after_dislysis"`
  111. HisAdvices []*VMHisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"his_doctor_advice"`
  112. Advices []*VMDoctorAdvice `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  113. TreatmentSummary *VMTreatmentSummary `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"treatment_summary"`
  114. NewDeviceInformation *NewDeviceInformation `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"device_information"`
  115. }
  116. func (MDialysisScheduleVM) TableName() string {
  117. return "xt_schedule"
  118. }
  119. type MDialysisScheduleVMForList struct {
  120. ID int64 `gorm:"column:id" json:"id"`
  121. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  122. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  123. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  124. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  125. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  126. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  127. ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week"`
  128. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  129. Status int64 `gorm:"column:status" json:"status"`
  130. SchedualPatient *models.MSchedualPatientList `gorm:"ForeignKey:PatientId" json:"patient"`
  131. DeviceNumber *models.MDeviceNumberForList `gorm:"ForeignKey:BedId" json:"device_number"`
  132. DialysisOrder *models.MDialysisOrderForList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  133. DialysisLastOrder *models.MDialysisOrderForList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"last_order"`
  134. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  135. AssessmentBeforeDislysis *models.PredialysisEvaluationList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_before_dislysis"`
  136. AssessmentAfterDislysis *models.VMAssessmentAfterDislysis `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_after_dislysis"`
  137. HisAdvices []VMHisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"his_doctor_advice"`
  138. Advices []models.VMDoctorAdviceForList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  139. TreatmentSummary *models.VMTreatmentSummaryForList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"treatment_summary"`
  140. DialysisSolution *models.DialysisSolution `gorm:"ForeignKey:PatientId,ModeId;AssociationForeignKey:PatientId,ModeId" json:"dialysis_solution"`
  141. DoubleCheck *models.DoubleCheck `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dobule_check"`
  142. NewDeviceInformation *NewDeviceInformation `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"device_information"`
  143. //VMMonitoringRecord []models.VMMonitoringRecord `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"monitor_record"`
  144. }
  145. func (MDialysisScheduleVMForList) TableName() string {
  146. return "xt_schedule"
  147. }
  148. type MDeviceNumberVM struct {
  149. models.DeviceNumber
  150. Zone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"zone"`
  151. }
  152. func (MDeviceNumberVM) TableName() string {
  153. return "xt_device_number"
  154. }
  155. type MSchedualPatientVMList struct {
  156. ID int64 `gorm:"column:id" json:"id" form:"id"`
  157. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  158. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  159. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  160. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
  161. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  162. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  163. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  164. Age int64 `gorm:"column:age" json:"age"`
  165. Name string `gorm:"column:name" json:"name" form:"name"`
  166. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  167. UserSysBeforeCount int64 `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
  168. TrobleShoot int64 `gorm:"column:troble_shoot" json:"troble_shoot" form:"troble_shoot"`
  169. SchRemark string `gorm:"column:sch_remark" json:"sch_remark" form:"sch_remark"`
  170. ScheduleRemark string `gorm:"column:schedule_remark" json:"schedule_remark" form:"schedule_remark"`
  171. }
  172. func (MSchedualPatientVMList) TableName() string {
  173. return "xt_patients"
  174. }
  175. type MSchedualPatientVM struct {
  176. ID int64 `gorm:"column:id" json:"id" form:"id"`
  177. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  178. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  179. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  180. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  181. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
  182. AdmissionNumber string `gorm:"column:admission_number" json:"admission_number" form:"admission_number"`
  183. Source int64 `gorm:"column:source" json:"source" form:"source"`
  184. Lapseto int64 `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
  185. PartitionId int64 `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
  186. BedId int64 `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
  187. Name string `gorm:"column:name" json:"name" form:"name"`
  188. Alias string `gorm:"column:alias" json:"alias" form:"alias"`
  189. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  190. Nation string `gorm:"column:nation" json:"nation" form:"nation"`
  191. NativePlace string `gorm:"column:native_place" json:"native_place" form:"native_place"`
  192. MaritalStatus int64 `gorm:"column:marital_status" json:"marital_status" form:"marital_status"`
  193. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  194. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  195. ReimbursementWayId int64 `gorm:"column:reimbursement_way_id" json:"reimbursement_way_id" form:"reimbursement_way_id"`
  196. HealthCareType int64 `gorm:"column:health_care_type" json:"health_care_type" form:"health_care_type"`
  197. HealthCareNo string `gorm:"column:health_care_no" json:"health_care_no" form:"health_care_no"`
  198. HealthCareDueDate int64 `gorm:"column:health_care_due_date" json:"health_care_due_date" form:"health_care_due_date"`
  199. Height int64 `gorm:"column:height" json:"height" form:"height"`
  200. BloodType int64 `gorm:"column:blood_type" json:"blood_type" form:"blood_type"`
  201. Rh int64 `gorm:"column:rh" json:"rh" form:"rh"`
  202. HealthCareDueAlertDate int64 `gorm:"column:health_care_due_alert_date" json:"health_care_due_alert_date" form:"health_care_due_alert_date"`
  203. EducationLevel int64 `gorm:"column:education_level" json:"education_level" form:"education_level"`
  204. Profession int64 `gorm:"column:profession" json:"profession" form:"profession"`
  205. Phone string `gorm:"column:phone" json:"phone" form:"phone"`
  206. HomeTelephone string `gorm:"column:home_telephone" json:"home_telephone" form:"home_telephone"`
  207. RelativePhone string `gorm:"column:relative_phone" json:"relative_phone" form:"relative_phone"`
  208. RelativeRelations string `gorm:"column:relative_relations" json:"relative_relations" form:"relative_relations"`
  209. HomeAddress string `gorm:"column:home_address" json:"home_address" form:"home_address"`
  210. WorkUnit string `gorm:"column:work_unit" json:"work_unit" form:"work_unit"`
  211. UnitAddress string `gorm:"column:unit_address" json:"unit_address" form:"unit_address"`
  212. Children int64 `gorm:"column:children" json:"children" form:"children"`
  213. ReceivingDate int64 `gorm:"column:receiving_date" json:"receiving_date" form:"receiving_date"`
  214. IsHospitalFirstDialysis int64 `gorm:"column:is_hospital_first_dialysis" json:"is_hospital_first_dialysis" form:"is_hospital_first_dialysis"`
  215. FirstDialysisDate int64 `gorm:"column:first_dialysis_date" json:"first_dialysis_date" form:"first_dialysis_date"`
  216. FirstDialysisHospital string `gorm:"column:first_dialysis_hospital" json:"first_dialysis_hospital" form:"first_dialysis_hospital"`
  217. InductionPeriod int64 `gorm:"column:induction_period" json:"induction_period" form:"induction_period"`
  218. InitialDialysis int64 `gorm:"column:initial_dialysis" json:"initial_dialysis" form:"initial_dialysis"`
  219. TotalDialysis int64 `gorm:"column:total_dialysis" json:"total_dialysis" form:"total_dialysis"`
  220. AttendingDoctorId int64 `gorm:"column:attending_doctor_id" json:"attending_doctor_id" form:"attending_doctor_id"`
  221. HeadNurseId int64 `gorm:"column:head_nurse_id" json:"head_nurse_id" form:"head_nurse_id"`
  222. Evaluate string `gorm:"column:evaluate" json:"evaluate" form:"evaluate"`
  223. Diagnose string `gorm:"column:diagnose" json:"diagnose" form:"diagnose"`
  224. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  225. RegistrarsId int64 `gorm:"column:registrars_id" json:"registrars_id" form:"registrars_id"`
  226. Registrars string `gorm:"column:registrars" json:"registrars" form:"registrars"`
  227. QrCode string `gorm:"column:qr_code" json:"qr_code" form:"qr_code"`
  228. BindingState int64 `gorm:"column:binding_state" json:"binding_state" form:"binding_state"`
  229. PatientComplains string `gorm:"column:patient_complains" json:"patient_complains"` // 主诉
  230. PresentHistory string `gorm:"column:present_history" json:"present_history"` // 现病史
  231. PastHistory string `gorm:"column:past_history" json:"past_history"` // 既往史
  232. Temperature float64 `gorm:"column:temperature" json:"temperature"` // 体格检查-体温
  233. Pulse int64 `gorm:"column:pulse" json:"pulse"` // 体格检查-脉搏
  234. Respiratory int64 `gorm:"column:respiratory" json:"respiratory"` // 体格检查-呼吸频率
  235. SBP int64 `gorm:"column:sbp" json:"sbp"` // 体格检查-收缩压
  236. DBP int64 `gorm:"column:dbp" json:"dbp"` // 体格检查-舒张压
  237. Status int64 `gorm:"column:status" json:"status" form:"status"`
  238. Age int64 `gorm:"column:age" json:"age"`
  239. IsOpenRemind int64 `gorm:"column:is_open_remind" json:"is_open_remind"`
  240. DialysisAge int64 `gorm:"column:dialysis_age" json:"dialysis_age" form:"dialysis_age"`
  241. ExpenseKind int64 `gorm:"column:expense_kind" json:"expense_kind" form:"expense_kind"`
  242. TellPhone string `gorm:"column:tell_phone" json:"tell_phone" form:"tell_phone"`
  243. FirstTreatmentDate int64 `gorm:"column:first_treatment_date" json:"first_treatment_date" form:"first_treatment_date"`
  244. ContactName string `gorm:"column:contact_name" json:"contact_name" form:"contact_name"`
  245. UserSysBeforeCount int64 `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
  246. }
  247. func (MSchedualPatientVM) TableName() string {
  248. return "xt_patients"
  249. }
  250. type MDialysisOrderVM struct {
  251. ID int64 `gorm:"column:id" json:"id"`
  252. DialysisDate int64 `gorm:"column:dialysis_date" json:"dialysis_date"`
  253. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  254. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  255. Stage int64 `gorm:"column:stage" json:"stage"`
  256. BedID int64 `gorm:"column:bed_id" json:"bed_id"`
  257. StartNurse int64 `gorm:"column:start_nurse" json:"start_nurse"`
  258. FinishNurse int64 `gorm:"column:finish_nurse" json:"finish_nurse"`
  259. Status int64 `gorm:"column:status" json:"status"`
  260. PunctureNurse int64 `gorm:"column:puncture_nurse" json:"puncture_nurse"`
  261. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedID" json:"device_number"`
  262. MonitoringRecords []*models.MonitoringRecord `gorm:"ForeignKey:DialysisOrderId" json:"monitoring_records"`
  263. Creator int64 `gorm:"column:creator" json:"creator"`
  264. Modifier int64 `gorm:"column:modifier" json:"modifier"`
  265. FinishCreator int64 `gorm:"column:finish_creator" json:"finish_creator"`
  266. FinishModifier int64 `gorm:"column:finish_modifier" json:"finish_modifier"`
  267. SchedualType int64 `gorm:"column:schedual_type" json:"schedual_type"`
  268. WashpipeNurse int64 `gorm:"column:washpipe_nurse" json:"washpipe_nurse" form:"washpipe_nurse"`
  269. DialysisIrrigation string `gorm:"column:dialysis_irrigation" json:"dialysis_irrigation" form:"dialysis_irrigation"`
  270. DialysisDialyszers string `gorm:"column:dialysis_dialyszers" json:"dialysis_dialyszers" form:"dialysis_dialyszers"`
  271. }
  272. func (MDialysisOrderVM) TableName() string {
  273. return "xt_dialysis_order"
  274. }
  275. type MDialysisOrderVMList struct {
  276. ID int64 `gorm:"column:id" json:"id"`
  277. DialysisDate int64 `gorm:"column:dialysis_date" json:"dialysis_date"`
  278. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  279. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  280. // PrescriptionId int64 `gorm:"column:prescription_id" json:"prescription_id"`
  281. Stage int64 `gorm:"column:stage" json:"stage"`
  282. // Remark string `gorm:"column:remark" json:"remark"`
  283. BedID int64 `gorm:"column:bed_id" json:"bed_id"`
  284. StartNurse int64 `gorm:"column:start_nurse" json:"start_nurse"`
  285. Status int64 `gorm:"column:status" json:"status"`
  286. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedID" json:"device_number"`
  287. Creator int64 `gorm:"column:creator" json:"creator"`
  288. WashpipeNurse int64 `gorm:"column:washpipe_nurse" json:"washpipe_nurse" form:"washpipe_nurse"`
  289. NucleinDate int64 `gorm:"column:nuclein_date" json:"nuclein_date" form:"nuclein_date"`
  290. DialysisIrrigation string `gorm:"column:dialysis_irrigation" json:"dialysis_irrigation" form:"dialysis_irrigation"`
  291. DialysisDialyszers string `gorm:"column:dialysis_dialyszers" json:"dialysis_dialyszers" form:"dialysis_dialyszers"`
  292. ScheduleRemark string `gorm:"column:schedule_remark" json:"schedule_remark" form:"schedule_remark"`
  293. }
  294. func (MDialysisOrderVMList) TableName() string {
  295. return "xt_dialysis_order"
  296. }
  297. type VMDoctorAdvice struct {
  298. ID int64 `gorm:"column:id" json:"id" form:"id"`
  299. GroupNo int64 `gorm:"column:groupno" json:"groupno" form:"groupno"`
  300. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  301. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  302. AdviceDate int64 `gorm:"column:advice_date" json:"advice_date" form:"advice_date"`
  303. Status int64 `gorm:"column:status" json:"status" form:"status"`
  304. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
  305. RecordDate int64 `gorm:"column:record_date" json:"record_date"`
  306. CheckTime int64 `gorm:"column:check_time" json:"check_time" form:"check_time"`
  307. CheckState int64 `gorm:"column:check_state" json:"check_state" form:"check_state"`
  308. ParentId int64 `gorm:"column:parent_id" json:"parent_id" form:"parent_id"`
  309. }
  310. func (VMDoctorAdvice) TableName() string {
  311. return "xt_doctor_advice"
  312. }
  313. type VMHisDoctorAdviceInfo struct {
  314. ID int64 `gorm:"column:id" json:"id" form:"id"`
  315. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  316. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  317. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  318. ExecutionTime int64 `gorm:"column:execution_time" json:"execution_time" form:"execution_time"`
  319. ExecutionStaff int64 `gorm:"column:execution_staff" json:"execution_staff" form:"execution_staff"`
  320. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
  321. IsMedicine int64 `gorm:"column:is_medicine" json:"is_medicine" form:"is_medicine"`
  322. ExecutionFrequencyId int64 `gorm:"column:execution_frequency_id" json:"execution_frequency_id" form:"execution_frequency_id"`
  323. IsSelfDrug int64 `gorm:"column:is_self_drug" json:"is_self_drug" form:"is_self_drug"`
  324. }
  325. func (VMHisDoctorAdviceInfo) TableName() string {
  326. return "his_doctor_advice_info"
  327. }
  328. type VMAssessmentAfterDislysis struct {
  329. ID int64 `gorm:"column:id" json:"id"`
  330. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  331. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  332. AssessmentDate int64 `gorm:"column:assessment_date" json:"assessment_date"`
  333. WeightAfter float64 `gorm:"column:weight_after" json:"weight_after"`
  334. Status int64 `gorm:"column:status" json:"status"`
  335. }
  336. func (VMAssessmentAfterDislysis) TableName() string {
  337. return "xt_assessment_after_dislysis"
  338. }
  339. type NewDeviceInformation struct {
  340. ID int64 `gorm:"column:id" json:"id" form:"id"`
  341. Date int64 `gorm:"column:date" json:"date" form:"date"`
  342. Class int64 `gorm:"column:class" json:"class" form:"class"`
  343. Zone int64 `gorm:"column:zone" json:"zone" form:"zone"`
  344. BedNumber int64 `gorm:"column:bed_number" json:"bed_number" form:"bed_number"`
  345. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  346. Status int64 `gorm:"column:status" json:"status" form:"status"`
  347. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  348. EquimentId int64 `gorm:"column:equiment_id" json:"equiment_id" form:"equiment_id"`
  349. Bed string `gorm:"column:bed" json:"bed" form:"bed"`
  350. Stime int64 `gorm:"column:stime" json:"stime" form:"stime"`
  351. }
  352. func (NewDeviceInformation) TableName() string {
  353. return "xt_device_information"
  354. }
  355. // 获取透析记录
  356. func MobileGetDialysisRecord(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  357. var record models.DialysisOrder
  358. err := readDb.Model(&models.DialysisOrder{}).Where("user_org_id = ? AND patient_id = ? AND dialysis_date = ?", orgID, patientID, recordDate).First(&record).Error
  359. if err != nil {
  360. if err == gorm.ErrRecordNotFound {
  361. return nil, nil
  362. } else {
  363. return nil, err
  364. }
  365. }
  366. return &record, nil
  367. }
  368. // 用户基本信息
  369. func MobileGetPatientDetail(orgID int64, patientID int64) (*MPatient, error) {
  370. var patient MPatient
  371. //err := readDb.Model(&MPatient{}).Where("status = 1 AND user_org_id = ? AND id = ?", orgID, patientID).First(&patient).Error
  372. //if err != nil {
  373. // if err == gorm.ErrRecordNotFound {
  374. // return nil, nil
  375. // } else {
  376. // return nil, err
  377. // }
  378. //}
  379. //return &patient, nil
  380. redis := RedisClient()
  381. defer redis.Close()
  382. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":patient_info"
  383. patient_info_str, _ := redis.Get(key).Result()
  384. if len(patient_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  385. err = readDb.Model(&patient).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
  386. if err != nil {
  387. if err == gorm.ErrRecordNotFound {
  388. return &patient, nil
  389. } else {
  390. return &patient, err
  391. }
  392. } else {
  393. if patient.ID > 0 {
  394. //缓存数据
  395. patient_info_json, err := json.Marshal(&patient)
  396. if err == nil {
  397. redis.Set(key, patient_info_json, time.Second*60*60*18)
  398. }
  399. }
  400. return &patient, nil
  401. }
  402. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  403. json.Unmarshal([]byte(patient_info_str), &patient)
  404. return &patient, nil
  405. }
  406. }
  407. func MobileGetSchedualDetailOne(orgID int64, patientID int64, schedualDate int64) (*MDialysisScheduleVM, error) {
  408. var vm MDialysisScheduleVM
  409. err := readDb.
  410. Table("xt_schedule").
  411. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  412. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  413. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  414. First(&vm).Error
  415. return &vm, err
  416. }
  417. // 用户排班信息
  418. func MobileGetSchedualDetailSix(orgID int64, patientID int64, schedualDate int64) (*MDialysisScheduleVM, error) {
  419. var vm MDialysisScheduleVM
  420. err := readDb.
  421. Table("xt_schedule").
  422. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  423. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  424. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  425. First(&vm).Error
  426. if err != nil {
  427. if err == gorm.ErrRecordNotFound {
  428. return nil, nil
  429. } else {
  430. return nil, err
  431. }
  432. }
  433. return &vm, err
  434. }
  435. // 用户排班信息
  436. func MobileGetSchedualDetail(orgID int64, patientID int64, schedualDate int64) (*MDialysisScheduleVM, error) {
  437. redis := RedisClient()
  438. defer redis.Close()
  439. var vm MDialysisScheduleVM
  440. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(schedualDate, 10) + ":schedual_detail"
  441. redis.Set(key, "", time.Second)
  442. schedual_detail_str, _ := redis.Get(key).Result()
  443. if len(schedual_detail_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  444. err := readDb.
  445. Table("xt_schedule").
  446. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  447. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  448. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  449. First(&vm).Error
  450. if err != nil {
  451. if err == gorm.ErrRecordNotFound {
  452. return nil, nil
  453. } else {
  454. return nil, err
  455. }
  456. } else {
  457. if vm.ID > 0 {
  458. //缓存数据
  459. schedual_detail_str, err := json.Marshal(vm)
  460. if err == nil {
  461. redis.Set(key, schedual_detail_str, time.Second*60*60*18)
  462. }
  463. } else {
  464. redis.Set(key, "null", time.Second*60*60*18)
  465. }
  466. return &vm, nil
  467. }
  468. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  469. if schedual_detail_str == "null" {
  470. return &vm, nil
  471. }
  472. json.Unmarshal([]byte(schedual_detail_str), &vm)
  473. return &vm, nil
  474. }
  475. }
  476. // 用户排班信息
  477. func MobileGetPatientSchedual(orgID int64, patientID int64, schedualDate int64) (*models.Schedule, error) {
  478. var schedule models.Schedule
  479. err := readDb.
  480. Table("xt_schedule").
  481. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  482. First(&schedule).Error
  483. if err != nil {
  484. if err == gorm.ErrRecordNotFound {
  485. return nil, nil
  486. } else {
  487. return nil, err
  488. }
  489. }
  490. return &schedule, nil
  491. }
  492. type MPatient struct {
  493. ID int64 `gorm:"column:id" json:"id" form:"id"`
  494. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  495. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  496. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  497. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  498. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
  499. AdmissionNumber string `gorm:"column:admission_number" json:"admission_number" form:"admission_number"`
  500. Source int64 `gorm:"column:source" json:"source" form:"source"`
  501. Lapseto int64 `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
  502. PartitionId int64 `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
  503. BedId int64 `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
  504. Name string `gorm:"column:name" json:"name" form:"name"`
  505. Alias string `gorm:"column:alias" json:"alias" form:"alias"`
  506. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  507. Nation string `gorm:"column:nation" json:"nation" form:"nation"`
  508. NativePlace string `gorm:"column:native_place" json:"native_place" form:"native_place"`
  509. MaritalStatus int64 `gorm:"column:marital_status" json:"marital_status" form:"marital_status"`
  510. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  511. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  512. ReimbursementWayId int64 `gorm:"column:reimbursement_way_id" json:"reimbursement_way_id" form:"reimbursement_way_id"`
  513. HealthCareType int64 `gorm:"column:health_care_type" json:"health_care_type" form:"health_care_type"`
  514. HealthCareNo string `gorm:"column:health_care_no" json:"health_care_no" form:"health_care_no"`
  515. HealthCareDueDate int64 `gorm:"column:health_care_due_date" json:"health_care_due_date" form:"health_care_due_date"`
  516. Height int64 `gorm:"column:height" json:"height" form:"height"`
  517. BloodType int64 `gorm:"column:blood_type" json:"blood_type" form:"blood_type"`
  518. Rh int64 `gorm:"column:rh" json:"rh" form:"rh"`
  519. HealthCareDueAlertDate int64 `gorm:"column:health_care_due_alert_date" json:"health_care_due_alert_date" form:"health_care_due_alert_date"`
  520. EducationLevel int64 `gorm:"column:education_level" json:"education_level" form:"education_level"`
  521. Profession int64 `gorm:"column:profession" json:"profession" form:"profession"`
  522. Phone string `gorm:"column:phone" json:"phone" form:"phone"`
  523. HomeTelephone string `gorm:"column:home_telephone" json:"home_telephone" form:"home_telephone"`
  524. RelativePhone string `gorm:"column:relative_phone" json:"relative_phone" form:"relative_phone"`
  525. RelativeRelations string `gorm:"column:relative_relations" json:"relative_relations" form:"relative_relations"`
  526. HomeAddress string `gorm:"column:home_address" json:"home_address" form:"home_address"`
  527. WorkUnit string `gorm:"column:work_unit" json:"work_unit" form:"work_unit"`
  528. UnitAddress string `gorm:"column:unit_address" json:"unit_address" form:"unit_address"`
  529. Children int64 `gorm:"column:children" json:"children" form:"children"`
  530. ReceivingDate int64 `gorm:"column:receiving_date" json:"receiving_date" form:"receiving_date"`
  531. IsHospitalFirstDialysis int64 `gorm:"column:is_hospital_first_dialysis" json:"is_hospital_first_dialysis" form:"is_hospital_first_dialysis"`
  532. FirstDialysisDate int64 `gorm:"column:first_dialysis_date" json:"first_dialysis_date" form:"first_dialysis_date"`
  533. FirstDialysisHospital string `gorm:"column:first_dialysis_hospital" json:"first_dialysis_hospital" form:"first_dialysis_hospital"`
  534. InductionPeriod int64 `gorm:"column:induction_period" json:"induction_period" form:"induction_period"`
  535. InitialDialysis int64 `gorm:"column:initial_dialysis" json:"initial_dialysis" form:"initial_dialysis"`
  536. TotalDialysis int64 `gorm:"column:total_dialysis" json:"total_dialysis" form:"total_dialysis"`
  537. AttendingDoctorId int64 `gorm:"column:attending_doctor_id" json:"attending_doctor_id" form:"attending_doctor_id"`
  538. HeadNurseId int64 `gorm:"column:head_nurse_id" json:"head_nurse_id" form:"head_nurse_id"`
  539. Evaluate string `gorm:"column:evaluate" json:"evaluate" form:"evaluate"`
  540. Diagnose string `gorm:"column:diagnose" json:"diagnose" form:"diagnose"`
  541. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  542. RegistrarsId int64 `gorm:"column:registrars_id" json:"registrars_id" form:"registrars_id"`
  543. Registrars string `gorm:"column:registrars" json:"registrars" form:"registrars"`
  544. QrCode string `gorm:"column:qr_code" json:"qr_code" form:"qr_code"`
  545. BindingState int64 `gorm:"column:binding_state" json:"binding_state" form:"binding_state"`
  546. PatientComplains string `gorm:"column:patient_complains" json:"patient_complains"` // 主诉
  547. PresentHistory string `gorm:"column:present_history" json:"present_history"` // 现病史
  548. PastHistory string `gorm:"column:past_history" json:"past_history"` // 既往史
  549. Temperature float64 `gorm:"column:temperature" json:"temperature"` // 体格检查-体温
  550. Pulse int64 `gorm:"column:pulse" json:"pulse"` // 体格检查-脉搏
  551. Respiratory int64 `gorm:"column:respiratory" json:"respiratory"` // 体格检查-呼吸频率
  552. SBP int64 `gorm:"column:sbp" json:"sbp"` // 体格检查-收缩压
  553. DBP int64 `gorm:"column:dbp" json:"dbp"` // 体格检查-舒张压
  554. Status int64 `gorm:"column:status" json:"status" form:"status"`
  555. Age int64 `gorm:"column:age" json:"age"`
  556. IsOpenRemind int64 `gorm:"column:is_open_remind" json:"is_open_remind"`
  557. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  558. DialysisAge int64 `gorm:"column:dialysis_age" json:"dialysis_age" form:"dialysis_age"`
  559. ExpenseKind int64 `gorm:"column:expense_kind" json:"expense_kind" form:"expense_kind"`
  560. TellPhone string `gorm:"column:tell_phone" json:"tell_phone" form:"tell_phone"`
  561. FirstTreatmentDate int64 `gorm:"column:first_treatment_date" json:"first_treatment_date" form:"first_treatment_date"`
  562. ContactName string `gorm:"column:contact_name" json:"contact_name" form:"contact_name"`
  563. UserSysBeforeCount int64 `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
  564. }
  565. func (MPatient) TableName() string {
  566. return "xt_patients"
  567. }
  568. // 接诊评估
  569. func MobileGetReceiverTreatmentAccessRecord(orgID int64, patientID int64, recordDate int64) (*models.ReceiveTreatmentAsses, error) {
  570. var record models.ReceiveTreatmentAsses
  571. redis := RedisClient()
  572. defer redis.Close()
  573. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":receive_treatment_asses"
  574. receive_treatment_asses_str, _ := redis.Get(key).Result()
  575. if len(receive_treatment_asses_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  576. err = readDb.Model(&models.ReceiveTreatmentAsses{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  577. if err != nil {
  578. if err == gorm.ErrRecordNotFound {
  579. if record.ID <= 0 {
  580. redis.Set(key, "", time.Second*60*60*18)
  581. }
  582. return nil, nil
  583. } else {
  584. return nil, err
  585. }
  586. } else {
  587. if record.ID > 0 {
  588. //缓存数据
  589. receive_treatment_asses_str, err := json.Marshal(record)
  590. if err == nil {
  591. redis.Set(key, receive_treatment_asses_str, time.Second*60*60*18)
  592. }
  593. } else {
  594. redis.Set(key, "null", time.Second*60*60*18)
  595. }
  596. return &record, nil
  597. }
  598. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  599. if receive_treatment_asses_str == "null" {
  600. return &record, nil
  601. }
  602. json.Unmarshal([]byte(receive_treatment_asses_str), &record)
  603. return &record, nil
  604. }
  605. }
  606. // 透前评估
  607. func MobileGetPredialysisEvaluationOne(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
  608. var record models.PredialysisEvaluation
  609. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  610. if err != nil {
  611. if err == gorm.ErrRecordNotFound {
  612. return nil, nil
  613. } else {
  614. return nil, err
  615. }
  616. }
  617. return &record, nil
  618. }
  619. func MobileGetPredialysisEvaluationTwo(orgID int64, patientID int64, recordDate int64) (models.PredialysisEvaluation, error) {
  620. var record models.PredialysisEvaluation
  621. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  622. return record, err
  623. }
  624. // 透前评估
  625. func MobileGetPredialysisEvaluation(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
  626. var record models.PredialysisEvaluation
  627. redis := RedisClient()
  628. defer redis.Close()
  629. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":assessment_before_dislysis"
  630. assessment_before_dislysis_str, _ := redis.Get(key).Result()
  631. redis.Set(key, "", time.Second)
  632. if len(assessment_before_dislysis_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  633. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  634. if err != nil {
  635. if err == gorm.ErrRecordNotFound {
  636. if record.ID <= 0 {
  637. redis.Set(key, "", time.Second*60*60*18)
  638. }
  639. return nil, nil
  640. } else {
  641. return nil, err
  642. }
  643. } else {
  644. if record.ID > 0 {
  645. //缓存数据
  646. assessment_before_dislysis_str, err := json.Marshal(record)
  647. if err == nil {
  648. redis.Set(key, assessment_before_dislysis_str, time.Second*60*60*18)
  649. }
  650. } else {
  651. redis.Set(key, "null", time.Second*60*60*18)
  652. }
  653. return &record, nil
  654. }
  655. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  656. if assessment_before_dislysis_str == "null" {
  657. return &record, nil
  658. } else {
  659. json.Unmarshal([]byte(assessment_before_dislysis_str), &record)
  660. return &record, nil
  661. }
  662. }
  663. }
  664. // 获取 maxDate 之前一次的透前评估记录
  665. func MobileGetLastTimePredialysisEvaluationOne(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
  666. var record models.PredialysisEvaluation
  667. 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
  668. if err != nil {
  669. if err == gorm.ErrRecordNotFound {
  670. return nil, nil
  671. } else {
  672. return nil, err
  673. }
  674. }
  675. return &record, nil
  676. }
  677. // 获取 maxDate 之前一次的透前评估记录
  678. func MobileGetLastTimePredialysisEvaluation(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
  679. var record models.PredialysisEvaluation
  680. redis := RedisClient()
  681. defer redis.Close()
  682. // cur_date := time.Now().Format("2006-01-02")
  683. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(maxDate, 10) + ":assessment_before_dislysis_last"
  684. assessment_before_dislysis_last_str, _ := redis.Get(key).Result()
  685. if len(assessment_before_dislysis_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  686. 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
  687. if err != nil {
  688. if err == gorm.ErrRecordNotFound {
  689. if record.ID <= 0 {
  690. redis.Set(key, "", time.Second*60*60*18)
  691. }
  692. return nil, nil
  693. } else {
  694. return nil, err
  695. }
  696. } else {
  697. if record.ID > 0 {
  698. //缓存数据
  699. assessment_before_dislysis_last_str, err := json.Marshal(record)
  700. if err == nil {
  701. redis.Set(key, assessment_before_dislysis_last_str, time.Second*60*60*4)
  702. }
  703. } else {
  704. redis.Set(key, "null", time.Second*60*60*18)
  705. }
  706. return &record, nil
  707. }
  708. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  709. if assessment_before_dislysis_last_str == "null" {
  710. return &record, nil
  711. } else {
  712. json.Unmarshal([]byte(assessment_before_dislysis_last_str), &record)
  713. return &record, nil
  714. }
  715. }
  716. }
  717. // 临时医嘱
  718. func MobileGetDoctorAdvices(orgID int64, patientID int64, recordDate int64) ([]*models.DoctorAdvice, error) {
  719. var records []*models.DoctorAdvice
  720. // err := readDb.Model(&models.DoctorAdvice{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).Find(&records).Error
  721. err := readDb.
  722. Model(&models.DoctorAdvice{}).
  723. Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? and (advice_type = 2 or advice_type = 3)", patientID, orgID, recordDate).
  724. 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").
  725. Order("start_time asc, groupno desc, advice_order desc, id").
  726. Scan(&records).Error
  727. if err != nil {
  728. return nil, err
  729. }
  730. return records, nil
  731. }
  732. func MobileGetDoctorAdvicesByGroups(orgID int64, patientID int64, recordDate int64) ([]*models.DoctorAdvice, error) {
  733. var records []*models.DoctorAdvice
  734. redis := RedisClient()
  735. defer redis.Close()
  736. // cur_date := time.Now().Format("2006-01-02")
  737. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":doctor_advices"
  738. //fmt.Println("key23233232323323wi", key)
  739. redis.Set(key, "", time.Second)
  740. doctor_advices_str, _ := redis.Get(key).Result()
  741. if len(doctor_advices_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  742. err := readDb.Model(&models.DoctorAdvice{}).
  743. Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? and (advice_type = 2 || advice_type = 3)", patientID, orgID, recordDate).
  744. 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").
  745. Order("start_time asc, groupno desc, advice_order desc, id asc").
  746. Scan(&records).Error
  747. if err != nil {
  748. if err == gorm.ErrRecordNotFound {
  749. if len(records) <= 0 {
  750. redis.Set(key, "", time.Second*60*60*18)
  751. }
  752. return nil, nil
  753. } else {
  754. return nil, err
  755. }
  756. } else {
  757. if len(records) > 0 {
  758. //缓存数据
  759. doctor_advices_str, err := json.Marshal(records)
  760. if err == nil {
  761. redis.Set(key, doctor_advices_str, time.Second*60*60*18)
  762. return records, nil
  763. }
  764. } else {
  765. redis.Set(key, "null", time.Second*60*60*18)
  766. return records, nil
  767. }
  768. return records, nil
  769. }
  770. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  771. if doctor_advices_str == "null" {
  772. return records, nil
  773. } else {
  774. json.Unmarshal([]byte(doctor_advices_str), &records)
  775. return records, nil
  776. }
  777. }
  778. }
  779. // 透析记录
  780. func MobileGetSchedualDialysisRecordTen(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  781. var record models.DialysisOrder
  782. 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
  783. if err != nil {
  784. if err == gorm.ErrRecordNotFound {
  785. return nil, nil
  786. } else {
  787. return nil, err
  788. }
  789. }
  790. return &record, nil
  791. }
  792. //func MobileGetSchedualDialysisRecord(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  793. // var record models.DialysisOrder
  794. //
  795. // 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
  796. //
  797. //
  798. // return &record,err
  799. //}
  800. // 透析记录
  801. func MobileGetSchedualDialysisRecord(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  802. var record models.DialysisOrder
  803. redis := RedisClient()
  804. defer redis.Close()
  805. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":dialysis_order"
  806. dialysis_order_str, _ := redis.Get(key).Result()
  807. if len(dialysis_order_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  808. 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
  809. if err != nil {
  810. if err == gorm.ErrRecordNotFound {
  811. return nil, nil
  812. } else {
  813. return nil, err
  814. }
  815. } else {
  816. if record.ID > 0 {
  817. //缓存数据
  818. dialysis_order_str, err := json.Marshal(record)
  819. if err == nil {
  820. redis.Set(key, dialysis_order_str, time.Second*60*60*18)
  821. }
  822. } else {
  823. redis.Set(key, "null", time.Second*60*60*18)
  824. }
  825. return &record, nil
  826. }
  827. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  828. if dialysis_order_str == "null" {
  829. 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
  830. return &record, nil
  831. } else {
  832. json.Unmarshal([]byte(dialysis_order_str), &record)
  833. return &record, nil
  834. }
  835. }
  836. }
  837. // 双人核对
  838. func MobileGetDoubleCheck(orgID int64, patientID int64, recordDate int64) (*models.DoubleCheck, error) {
  839. var record models.DoubleCheck
  840. redis := RedisClient()
  841. defer redis.Close()
  842. // cur_date := time.Now().Format("2006-01-02")
  843. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":double_check"
  844. double_check_str, _ := redis.Get(key).Result()
  845. if len(double_check_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  846. err := readDb.Model(&models.DoubleCheck{}).Where("patient_id = ? and user_org_id = ? and status = 1 and check_date = ?", patientID, orgID, recordDate).First(&record).Error
  847. if err != nil {
  848. if err == gorm.ErrRecordNotFound {
  849. if record.ID <= 0 {
  850. redis.Set(key, "null", time.Second*60*60*18)
  851. }
  852. return nil, nil
  853. } else {
  854. return nil, err
  855. }
  856. } else {
  857. if record.ID > 0 {
  858. //缓存数据
  859. double_check_str, err := json.Marshal(record)
  860. if err == nil {
  861. redis.Set(key, double_check_str, time.Second*60*60*18)
  862. }
  863. } else {
  864. redis.Set(key, "null", time.Second*60*60*18)
  865. }
  866. return &record, nil
  867. }
  868. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  869. if double_check_str == "null" {
  870. return &record, nil
  871. } else {
  872. json.Unmarshal([]byte(double_check_str), &record)
  873. return &record, nil
  874. }
  875. }
  876. }
  877. // 透析监测记录
  878. func MobileGetMonitorRecords(orgID int64, patientID int64, recordDate int64) ([]*models.MonitoringRecord, error) {
  879. var records []*models.MonitoringRecord
  880. redis := RedisClient()
  881. defer redis.Close()
  882. // cur_date := time.Now().Format("2006-01-02")
  883. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":monitor_records"
  884. redis.Set(key, "", time.Second)
  885. monitor_records_str, _ := redis.Get(key).Result()
  886. if len(monitor_records_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  887. 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
  888. if err != nil {
  889. if err == gorm.ErrRecordNotFound {
  890. //if len(records) <= 0 {
  891. // redis.Set(key, "null", time.Second*60*60*18)
  892. //}
  893. return nil, nil
  894. } else {
  895. return nil, err
  896. }
  897. } else {
  898. if len(records) > 0 {
  899. //缓存数据
  900. monitor_records_str, err := json.Marshal(records)
  901. if err == nil {
  902. redis.Set(key, monitor_records_str, time.Second*60*60*18)
  903. }
  904. } else {
  905. redis.Set(key, "null", time.Second*60*60*18)
  906. }
  907. return records, nil
  908. }
  909. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  910. if monitor_records_str == "null" {
  911. return records, nil
  912. } else {
  913. json.Unmarshal([]byte(monitor_records_str), &records)
  914. return records, nil
  915. }
  916. }
  917. }
  918. func MobileGetMonitorRecordFirst(orgID int64, patientID int64, recordDate int64) (*models.MonitoringRecord, error) {
  919. var records models.MonitoringRecord
  920. 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
  921. if err != nil {
  922. return nil, err
  923. }
  924. return &records, nil
  925. }
  926. func MobileGetLastMonitorRecordOne(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  927. var record models.MonitoringRecord
  928. 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
  929. if err != nil {
  930. if err == gorm.ErrRecordNotFound {
  931. return nil, nil
  932. } else {
  933. return nil, err
  934. }
  935. }
  936. return &record, nil
  937. }
  938. func MobileGetLastMonitorRecord(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  939. var record models.MonitoringRecord
  940. redis := RedisClient()
  941. defer redis.Close()
  942. // cur_date := time.Now().Format("2006-01-02")
  943. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(beforeDate, 10) + ":monitor_record_last"
  944. monitor_record_last_str, _ := redis.Get(key).Result()
  945. if len(monitor_record_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  946. 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
  947. if err != nil {
  948. if err == gorm.ErrRecordNotFound {
  949. if record.ID <= 0 {
  950. redis.Set(key, "null", time.Second*60*60*18)
  951. }
  952. return nil, nil
  953. } else {
  954. return nil, err
  955. }
  956. } else {
  957. if record.ID > 0 {
  958. //缓存数据
  959. monitor_record_last_str, err := json.Marshal(record)
  960. if err == nil {
  961. redis.Set(key, monitor_record_last_str, time.Second*60*60*18)
  962. }
  963. } else {
  964. redis.Set(key, "null", time.Second*60*60*18)
  965. }
  966. return &record, nil
  967. }
  968. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  969. if monitor_record_last_str == "null" {
  970. return &record, nil
  971. } else {
  972. json.Unmarshal([]byte(monitor_record_last_str), &record)
  973. return &record, nil
  974. }
  975. }
  976. }
  977. func MobileGetAssessmentAfterDislysisOne(orgID int64, patientID int64, recordDate int64) (*models.AssessmentAfterDislysis, error) {
  978. var record models.AssessmentAfterDislysis
  979. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  980. if err != nil {
  981. if err == gorm.ErrRecordNotFound {
  982. return nil, nil
  983. } else {
  984. return nil, err
  985. }
  986. }
  987. return &record, nil
  988. }
  989. // 透后评估
  990. func MobileGetAssessmentAfterDislysis(orgID int64, patientID int64, recordDate int64) (*models.AssessmentAfterDislysis, error) {
  991. var record models.AssessmentAfterDislysis
  992. redis := RedisClient()
  993. defer redis.Close()
  994. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":assessment_after_dislysis"
  995. redis.Set(key, "", time.Second)
  996. assessment_after_dislysis_str, _ := redis.Get(key).Result()
  997. if len(assessment_after_dislysis_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  998. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  999. if err != nil {
  1000. if err == gorm.ErrRecordNotFound {
  1001. if record.ID <= 0 {
  1002. redis.Set(key, "null", time.Second*60*60*18)
  1003. }
  1004. return nil, nil
  1005. } else {
  1006. return nil, err
  1007. }
  1008. } else {
  1009. if record.ID > 0 {
  1010. //缓存数据
  1011. assessment_after_dislysis_str, err := json.Marshal(record)
  1012. if err == nil {
  1013. redis.Set(key, assessment_after_dislysis_str, time.Second*60*60*18)
  1014. }
  1015. } else {
  1016. redis.Set(key, "null", time.Second*60*60*18)
  1017. }
  1018. return &record, nil
  1019. }
  1020. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1021. if assessment_after_dislysis_str == "null" {
  1022. return &record, nil
  1023. } else {
  1024. json.Unmarshal([]byte(assessment_after_dislysis_str), &record)
  1025. return &record, nil
  1026. }
  1027. }
  1028. }
  1029. // 获取 maxDate 之前一次的透后评估记录
  1030. func MobileGetLastTimeAssessmentAfterDislysis(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  1031. var record models.AssessmentAfterDislysis
  1032. redis := RedisClient()
  1033. defer redis.Close()
  1034. // cur_date := time.Now().Format("2006-01-02")
  1035. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(maxDate, 10) + ":assessment_after_dislysis_last"
  1036. assessment_after_dislysis_last_str, _ := redis.Get(key).Result()
  1037. if len(assessment_after_dislysis_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1038. 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
  1039. if err != nil {
  1040. if err == gorm.ErrRecordNotFound {
  1041. if record.ID <= 0 {
  1042. redis.Set(key, "null", time.Second*60*60*18)
  1043. }
  1044. return nil, nil
  1045. } else {
  1046. return nil, err
  1047. }
  1048. } else {
  1049. if record.ID > 0 {
  1050. //缓存数据
  1051. assessment_after_dislysis_last_str, err := json.Marshal(record)
  1052. if err == nil {
  1053. redis.Set(key, assessment_after_dislysis_last_str, time.Second*60*60*18)
  1054. }
  1055. } else {
  1056. redis.Set(key, "null", time.Second*60*60*18)
  1057. }
  1058. return &record, nil
  1059. }
  1060. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1061. if assessment_after_dislysis_last_str == "null" {
  1062. return &record, nil
  1063. } else {
  1064. json.Unmarshal([]byte(assessment_after_dislysis_last_str), &record)
  1065. return &record, nil
  1066. }
  1067. }
  1068. }
  1069. func MobileGetLastTimeAssessmentAfterDislysisOne(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  1070. var record models.AssessmentAfterDislysis
  1071. 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
  1072. if err != nil {
  1073. if err == gorm.ErrRecordNotFound {
  1074. return nil, nil
  1075. } else {
  1076. return nil, err
  1077. }
  1078. }
  1079. return &record, nil
  1080. }
  1081. func MobileGetLast(orgID int64, patientID int64, maxDate int64) (models.AssessmentAfterDislysis, error) {
  1082. dislysis := models.AssessmentAfterDislysis{}
  1083. 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
  1084. return dislysis, err
  1085. }
  1086. // 治疗小结
  1087. func MobileGetTreatmentSummary(orgID int64, patientID int64, recordDate int64) (*models.TreatmentSummary, error) {
  1088. var record models.TreatmentSummary
  1089. redis := RedisClient()
  1090. defer redis.Close()
  1091. // cur_date := time.Now().Format("2006-01-02")
  1092. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":treatment_summary"
  1093. treatment_summary_str, _ := redis.Get(key).Result()
  1094. if len(treatment_summary_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1095. err := readDb.Model(&models.TreatmentSummary{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  1096. if err != nil {
  1097. if err == gorm.ErrRecordNotFound {
  1098. if record.ID <= 0 {
  1099. redis.Set(key, "null", time.Second*60*60*18)
  1100. }
  1101. return nil, nil
  1102. } else {
  1103. return nil, err
  1104. }
  1105. } else {
  1106. if record.ID > 0 {
  1107. //缓存数据
  1108. treatment_summary_str, err := json.Marshal(record)
  1109. if err == nil {
  1110. redis.Set(key, treatment_summary_str, time.Second*60*60*18)
  1111. }
  1112. } else {
  1113. redis.Set(key, "null", time.Second*60*60*18)
  1114. }
  1115. return &record, nil
  1116. }
  1117. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1118. if treatment_summary_str == "null" {
  1119. return &record, nil
  1120. } else {
  1121. json.Unmarshal([]byte(treatment_summary_str), &record)
  1122. return &record, nil
  1123. }
  1124. }
  1125. }
  1126. // 透析处方
  1127. func MobileGetDialysisPrescribe(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  1128. var record models.DialysisPrescription
  1129. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).Find(&record).Error
  1130. if err != nil {
  1131. if err == gorm.ErrRecordNotFound {
  1132. return nil, nil
  1133. } else {
  1134. return nil, err
  1135. }
  1136. }
  1137. return &record, nil
  1138. }
  1139. func MobileGetDialysisSchedual(orgID int64, patientID int64, scheduleDate int64) (*models.XtSchedule, error) {
  1140. var schedule models.XtSchedule
  1141. err := readDb.Model(&models.XtSchedule{}).Where("patient_id = ? and user_org_id = ? and status = 1 and schedule_date = ?", patientID, orgID, scheduleDate).First(&schedule).Error
  1142. if err != nil {
  1143. if err == gorm.ErrRecordNotFound {
  1144. return nil, nil
  1145. } else {
  1146. return nil, err
  1147. }
  1148. }
  1149. return &schedule, nil
  1150. }
  1151. // 透析方案
  1152. func MobileGetDialysisSolution(orgID int64, patientID int64) (*models.DialysisSolution, error) {
  1153. var record models.DialysisSolution
  1154. err := readDb.Model(&models.DialysisSolution{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  1155. if err != nil {
  1156. if err == gorm.ErrRecordNotFound {
  1157. return nil, nil
  1158. } else {
  1159. return nil, err
  1160. }
  1161. }
  1162. return &record, nil
  1163. }
  1164. func MobileGetPatientById(orgID int64, patientID int64) (*models.Patients, error) {
  1165. var patient models.Patients
  1166. err := readDb.Model(&models.Patients{}).Where("id = ? and user_org_id = ? and status = 1", patientID, orgID).First(&patient).Error
  1167. if err != nil {
  1168. if err == gorm.ErrRecordNotFound {
  1169. return nil, nil
  1170. } else {
  1171. return nil, err
  1172. }
  1173. }
  1174. return &patient, nil
  1175. }
  1176. func DisableMonitor(orgID int64, patientID int64, recordID int64, admin_user_id int64) error {
  1177. fmt.Println()
  1178. tx := writeDb.Begin()
  1179. updateTime := time.Now().Unix()
  1180. 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
  1181. if err != nil {
  1182. tx.Rollback()
  1183. return err
  1184. }
  1185. tx.Commit()
  1186. return nil
  1187. }
  1188. func GetMonitorById(id int64, orgId int64) (models.MonitoringRecord, error) {
  1189. record := models.MonitoringRecord{}
  1190. err := XTReadDB().Where("id = ? and user_org_id =?", id, orgId).Find(&record).Error
  1191. return record, err
  1192. }
  1193. func GetMonitor(orgID int64, patientID int64, id int64) (*models.MonitoringRecord, error) {
  1194. var monitor models.MonitoringRecord
  1195. var err error
  1196. err = readDb.Model(&models.MonitoringRecord{}).Where("id = ? AND user_org_id = ? AND patient_id = ? AND status = 1 ", id, orgID, patientID).Find(&monitor).Error
  1197. if err == gorm.ErrRecordNotFound {
  1198. return nil, nil
  1199. }
  1200. if err != nil {
  1201. return nil, err
  1202. }
  1203. return &monitor, nil
  1204. }
  1205. type MScheduleDoctorAdviceVM struct {
  1206. ID int64 `gorm:"column:id" json:"id"`
  1207. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  1208. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  1209. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  1210. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1211. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  1212. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  1213. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  1214. Status int64 `gorm:"column:status" json:"status"`
  1215. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  1216. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  1217. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  1218. DoctorAdvices []*MDoctorAdviceVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  1219. Prescription *models.DialysisPrescriptionTwenty `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  1220. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  1221. }
  1222. func (MScheduleDoctorAdviceVM) TableName() string {
  1223. return "xt_schedule"
  1224. }
  1225. type MScheduleDoctorAdviceVMOne struct {
  1226. ID int64 `gorm:"column:id" json:"id"`
  1227. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  1228. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  1229. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  1230. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1231. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  1232. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  1233. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  1234. Status int64 `gorm:"column:status" json:"status"`
  1235. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  1236. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  1237. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  1238. DoctorAdvices []*MDoctorAdviceVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  1239. Prescription *models.DialysisPrescriptionTwenty `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  1240. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  1241. }
  1242. func (MScheduleDoctorAdviceVMOne) TableName() string {
  1243. return "xt_schedule"
  1244. }
  1245. type MDoctorAdviceVM struct {
  1246. ID int64 `gorm:"column:id" json:"id"`
  1247. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  1248. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1249. AdviceType int64 `gorm:"column:advice_type" json:"advice_type"`
  1250. AdviceDate int64 `gorm:"column:advice_date" json:"advice_date"`
  1251. StartTime int64 `gorm:"column:start_time" json:"start_time"`
  1252. AdviceName string `gorm:"column:advice_name" json:"advice_name"`
  1253. AdviceDesc string `gorm:"column:advice_desc" json:"advice_desc"`
  1254. ReminderDate int64 `gorm:"column:reminder_date" json:"reminder_date"`
  1255. SingleDose float64 `gorm:"column:single_dose" json:"single_dose"`
  1256. SingleDoseUnit string `gorm:"column:single_dose_unit" json:"single_dose_unit"`
  1257. PrescribingNumber float64 `gorm:"column:prescribing_number" json:"prescribing_number"`
  1258. PrescribingNumberUnit string `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit"`
  1259. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way"`
  1260. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency"`
  1261. AdviceDoctor int64 `gorm:"column:advice_doctor" json:"advice_doctor"`
  1262. Status int64 `gorm:"column:status" json:"status"`
  1263. CreatedTime int64 `gorm:"column:created_time" json:"created_time"`
  1264. UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time"`
  1265. AdviceAffirm string `gorm:"column:advice_affirm" json:"advice_affirm"`
  1266. Remark string `gorm:"column:remark" json:"remark"`
  1267. StopTime int64 `gorm:"column:stop_time" json:"stop_time"`
  1268. StopReason string `gorm:"column:stop_reason" json:"stop_reason"`
  1269. StopDoctor int64 `gorm:"column:stop_doctor" json:"stop_doctor"`
  1270. StopState int64 `gorm:"column:stop_state" json:"stop_state"`
  1271. ParentId int64 `gorm:"column:parent_id" json:"parent_id"`
  1272. ExecutionTime int64 `gorm:"column:execution_time" json:"execution_time"`
  1273. ExecutionStaff int64 `gorm:"column:execution_staff" json:"execution_staff"`
  1274. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state"`
  1275. Checker int64 `gorm:"column:checker" json:"checker"`
  1276. RecordDate int64 `gorm:"column:record_date" json:"record_date"`
  1277. DialysisOrderId int64 `gorm:"column:dialysis_order_id" json:"dialysis_order_id"`
  1278. CheckTime int64 `gorm:"column:check_time" json:"check_time"`
  1279. CheckState int64 `gorm:"column:check_state" json:"check_state"`
  1280. DrugSpec float64 `gorm:"column:drug_spec" json:"drug_spec"`
  1281. DrugSpecUnit string `gorm:"column:drug_spec_unit" json:"drug_spec_unit"`
  1282. Groupno int64 `gorm:"column:groupno" json:"groupno"`
  1283. RemindType int64 `gorm:"column:remind_type" json:"remind_type"`
  1284. FrequencyType int64 `gorm:"column:frequency_type" json:"frequency_type"`
  1285. DayCount int64 `gorm:"column:day_count" json:"day_count"`
  1286. WeekDay string `gorm:"column:week_day" json:"week_day"`
  1287. TemplateId string `gorm:"column:template_id" json:"template_id"`
  1288. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1289. IsMedicine int64 `gorm:"column:is_medicine" json:"is_medicine" form:"is_medicine"`
  1290. IsSettle int64 `gorm:"column:is_settle" json:"is_settle" form:"is_settle"`
  1291. }
  1292. func (MDoctorAdviceVM) TableName() string {
  1293. return "xt_doctor_advice"
  1294. }
  1295. func MobileGetScheduleDoctorAdvices(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string) ([]*MScheduleDoctorAdviceVM, error) {
  1296. var vms []*MScheduleDoctorAdviceVM
  1297. adviceWhere := ""
  1298. adviceCondition := []interface{}{}
  1299. if adviceType == 0 {
  1300. if patientType == 0 {
  1301. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  1302. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1303. } else if patientType == 1 {
  1304. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  1305. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1306. } else if patientType == 2 {
  1307. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  1308. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1309. }
  1310. } else if adviceType == 1 {
  1311. if patientType == 0 {
  1312. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  1313. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1314. } else if patientType == 1 {
  1315. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  1316. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1317. } else if patientType == 2 {
  1318. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  1319. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1320. }
  1321. } else if adviceType == 3 {
  1322. if patientType == 0 {
  1323. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  1324. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1325. } else if patientType == 1 {
  1326. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  1327. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1328. } else if patientType == 2 {
  1329. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  1330. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1331. }
  1332. } else if adviceType == 2 && len(deliverWay) > 0 {
  1333. if patientType == 0 {
  1334. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  1335. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1336. } else if patientType == 1 {
  1337. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  1338. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  1339. } else if patientType == 2 {
  1340. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  1341. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1342. }
  1343. } else if adviceType == 2 && len(deliverWay) <= 0 {
  1344. if patientType == 0 {
  1345. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  1346. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1347. } else if patientType == 1 {
  1348. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND (advice_doctor = ? or execution_staff = ?)"
  1349. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, adminUserId)
  1350. } else if patientType == 2 {
  1351. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  1352. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1353. }
  1354. }
  1355. db := readDb.
  1356. Table("xt_schedule").
  1357. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1358. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1359. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1360. }).
  1361. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1362. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1363. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1364. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  1365. Preload("DoctorAdvices", adviceCondition...).
  1366. Where("status = 1 AND user_org_id = ?", orgID)
  1367. if scheduleDate != 0 {
  1368. db = db.Where("schedule_date = ?", scheduleDate)
  1369. }
  1370. err := db.Find(&vms).Error
  1371. return vms, err
  1372. }
  1373. func MobileGetScheduleDoctorAdvicesTwo(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string) ([]*MScheduleDoctorAdviceVMOne, error) {
  1374. var vms []*MScheduleDoctorAdviceVMOne
  1375. adviceWhere := ""
  1376. adviceCondition := []interface{}{}
  1377. if adviceType == 0 {
  1378. if patientType == 0 {
  1379. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  1380. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1381. } else if patientType == 1 {
  1382. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  1383. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1384. } else if patientType == 2 {
  1385. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  1386. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1387. } else if patientType == 3 {
  1388. 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"
  1389. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1390. } else if patientType == 4 {
  1391. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1) and (is_settle = 0 or is_settle = 2)"
  1392. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1393. }
  1394. } else if adviceType == 1 {
  1395. if patientType == 0 {
  1396. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  1397. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1398. } else if patientType == 1 {
  1399. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  1400. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1401. } else if patientType == 2 {
  1402. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  1403. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1404. } else if patientType == 3 {
  1405. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = 1"
  1406. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1407. } else if patientType == 4 {
  1408. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and (is_settle = 0 or is_settle = 2)"
  1409. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1410. }
  1411. } else if adviceType == 3 {
  1412. if patientType == 0 {
  1413. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  1414. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1415. } else if patientType == 1 {
  1416. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  1417. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1418. } else if patientType == 2 {
  1419. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  1420. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1421. } else if patientType == 3 {
  1422. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 and is_settle = 1"
  1423. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1424. } else if patientType == 4 {
  1425. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 and (is_settle = 0 or is_settle = 2)"
  1426. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1427. }
  1428. } else if adviceType == 2 && len(deliverWay) > 0 {
  1429. if patientType == 0 {
  1430. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  1431. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1432. } else if patientType == 1 {
  1433. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  1434. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  1435. } else if patientType == 2 {
  1436. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  1437. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1438. } else if patientType == 3 {
  1439. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 and delivery_way = ? and is_settle = 1"
  1440. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1441. } else if patientType == 4 {
  1442. 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)"
  1443. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1444. }
  1445. } else if adviceType == 2 && len(deliverWay) <= 0 {
  1446. if patientType == 0 {
  1447. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  1448. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1449. } else if patientType == 1 {
  1450. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND (advice_doctor = ? or execution_staff = ?)"
  1451. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, adminUserId)
  1452. } else if patientType == 2 {
  1453. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  1454. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1455. } else if patientType == 3 {
  1456. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 and is_settle = 1"
  1457. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1458. } else if patientType == 4 {
  1459. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 and (is_settle = 0 or is_settle = 2)"
  1460. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1461. }
  1462. }
  1463. db := readDb.
  1464. Table("xt_schedule").
  1465. //Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1466. //Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1467. // return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1468. //}).
  1469. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1470. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1471. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1472. Preload("DoctorAdvices", adviceCondition...).
  1473. Where("status = 1 AND user_org_id = ?", orgID)
  1474. if scheduleDate != 0 {
  1475. db = db.Where("schedule_date = ?", scheduleDate)
  1476. }
  1477. err := db.Find(&vms).Error
  1478. return vms, err
  1479. }
  1480. func GetHisDoctorAdvices(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleDoctorAdviceVM, error) {
  1481. var vms []*HisMScheduleDoctorAdviceVM
  1482. if len(deliverWay) > 0 {
  1483. if patientType == 0 {
  1484. db := readDb.
  1485. Table("xt_schedule").
  1486. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  1487. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1488. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1489. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  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. Where("status = 1 AND user_org_id = ?", orgID)
  1496. if scheduleDate != 0 {
  1497. db = db.Where("schedule_date = ?", scheduleDate)
  1498. }
  1499. err = db.Find(&vms).Error
  1500. }
  1501. if patientType > 0 {
  1502. db := readDb.
  1503. Table("xt_schedule").
  1504. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1505. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1506. 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).
  1507. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1508. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1509. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1510. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1511. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1512. }).Where("status = 1 AND user_org_id = ?", orgID)
  1513. if scheduleDate != 0 {
  1514. db = db.Where("schedule_date = ?", scheduleDate)
  1515. }
  1516. err = db.Find(&vms).Error
  1517. }
  1518. } else {
  1519. if patientType == 0 {
  1520. db := readDb.
  1521. Table("xt_schedule").
  1522. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? ", orgID, scheduleDate).
  1523. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1524. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1525. return db.Where("status = 1 AND user_org_id = ? and dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1526. }).
  1527. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1528. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1529. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1530. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1531. Where("status = 1 AND user_org_id = ?", orgID)
  1532. if scheduleDate != 0 {
  1533. db = db.Where("schedule_date = ?", scheduleDate)
  1534. }
  1535. err = db.Find(&vms).Error
  1536. }
  1537. if patientType > 0 {
  1538. db := readDb.
  1539. Table("xt_schedule").
  1540. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1541. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1542. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1543. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1544. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1545. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1546. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1547. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1548. Where("status = 1 AND user_org_id = ?", orgID)
  1549. if scheduleDate != 0 {
  1550. db = db.Where("schedule_date = ?", scheduleDate)
  1551. }
  1552. err = db.Find(&vms).Error
  1553. }
  1554. }
  1555. return vms, err
  1556. }
  1557. func GetHisDoctorAdvicesTwo(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleDoctorAdviceVMOne, error) {
  1558. var vms []*HisMScheduleDoctorAdviceVMOne
  1559. if len(deliverWay) > 0 {
  1560. if patientType == 0 {
  1561. db := readDb.
  1562. Table("xt_schedule").
  1563. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  1564. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1565. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1566. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1567. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1568. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1569. }).
  1570. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1571. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1572. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1573. Where("status = 1 AND user_org_id = ?", orgID)
  1574. if scheduleDate != 0 {
  1575. db = db.Where("schedule_date = ?", scheduleDate)
  1576. }
  1577. err = db.Find(&vms).Error
  1578. }
  1579. if patientType > 0 {
  1580. if patientType == 1 {
  1581. db := readDb.
  1582. Table("xt_schedule").
  1583. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1584. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1585. 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).
  1586. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1587. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1588. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1589. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1590. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1591. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1592. Where("status = 1 AND user_org_id = ?", orgID)
  1593. if scheduleDate != 0 {
  1594. db = db.Where("schedule_date = ?", scheduleDate)
  1595. }
  1596. err = db.Find(&vms).Error
  1597. }
  1598. if patientType == 2 {
  1599. db := readDb.
  1600. Table("xt_schedule").
  1601. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1602. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1603. 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).
  1604. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1605. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1606. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1607. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1608. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1609. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Where("status = 1 AND user_org_id = ?", orgID)
  1610. if scheduleDate != 0 {
  1611. db = db.Where("schedule_date = ?", scheduleDate)
  1612. }
  1613. err = db.Find(&vms).Error
  1614. }
  1615. if patientType == 3 {
  1616. db := readDb.
  1617. Table("xt_schedule").
  1618. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1619. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1620. 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).
  1621. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1622. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1623. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1624. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1625. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1626. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Where("status = 1 AND user_org_id = ?", orgID)
  1627. if scheduleDate != 0 {
  1628. db = db.Where("schedule_date = ?", scheduleDate)
  1629. }
  1630. err = db.Find(&vms).Error
  1631. }
  1632. if patientType == 4 {
  1633. db := readDb.
  1634. Table("xt_schedule").
  1635. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1636. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1637. 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).
  1638. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1639. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1640. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1641. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1642. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1643. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Where("status = 1 AND user_org_id = ?", orgID)
  1644. if scheduleDate != 0 {
  1645. db = db.Where("schedule_date = ?", scheduleDate)
  1646. }
  1647. err = db.Find(&vms).Error
  1648. }
  1649. }
  1650. } else {
  1651. if patientType == 0 {
  1652. db := readDb.
  1653. Table("xt_schedule").
  1654. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? ", orgID, scheduleDate).
  1655. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1656. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1657. return db.Where("status = 1 AND user_org_id = ? and dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1658. }).
  1659. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1660. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1661. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1662. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1663. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1664. Where("status = 1 AND user_org_id = ?", orgID)
  1665. if scheduleDate != 0 {
  1666. db = db.Where("schedule_date = ?", scheduleDate)
  1667. }
  1668. err = db.Find(&vms).Error
  1669. }
  1670. if patientType > 0 {
  1671. if patientType == 1 {
  1672. db := readDb.
  1673. Table("xt_schedule").
  1674. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1675. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1676. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1677. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1678. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1679. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1680. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1681. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1682. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1683. Where("status = 1 AND user_org_id = ?", orgID)
  1684. if scheduleDate != 0 {
  1685. db = db.Where("schedule_date = ?", scheduleDate)
  1686. }
  1687. err = db.Find(&vms).Error
  1688. }
  1689. if patientType == 2 {
  1690. db := readDb.
  1691. Table("xt_schedule").
  1692. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1693. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1694. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1695. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1696. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1697. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1698. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1699. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1700. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1701. Where("status = 1 AND user_org_id = ?", orgID)
  1702. if scheduleDate != 0 {
  1703. db = db.Where("schedule_date = ?", scheduleDate)
  1704. }
  1705. err = db.Find(&vms).Error
  1706. }
  1707. if patientType == 3 {
  1708. db := readDb.
  1709. Table("xt_schedule").
  1710. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1711. 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).
  1712. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1713. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1714. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1715. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1716. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1717. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1718. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1719. Where("status = 1 AND user_org_id = ?", orgID)
  1720. if scheduleDate != 0 {
  1721. db = db.Where("schedule_date = ?", scheduleDate)
  1722. }
  1723. err = db.Find(&vms).Error
  1724. }
  1725. if patientType == 4 {
  1726. db := readDb.
  1727. Table("xt_schedule").
  1728. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1729. 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).
  1730. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1731. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1732. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1733. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1734. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1735. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1736. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1737. Where("status = 1 AND user_org_id = ?", orgID)
  1738. if scheduleDate != 0 {
  1739. db = db.Where("schedule_date = ?", scheduleDate)
  1740. }
  1741. err = db.Find(&vms).Error
  1742. }
  1743. }
  1744. }
  1745. return vms, err
  1746. }
  1747. func GetMobileHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleProjectVM, error) {
  1748. var vms []*HisMScheduleProjectVM
  1749. //if patientType == 0 {
  1750. // db := readDb.
  1751. // Table("xt_schedule").
  1752. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1753. // Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1754. // return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1755. // }).
  1756. // Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1757. // Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1758. // Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1759. // Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1760. // return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1761. // }).
  1762. // Where("status = 1 AND user_org_id = ?", orgID)
  1763. // if scheduleDate != 0 {
  1764. // db = db.Where("schedule_date = ?", scheduleDate)
  1765. // }
  1766. // err = db.Find(&vms).Error
  1767. //}
  1768. //if patientType > 0 {
  1769. // db := readDb.
  1770. // Table("xt_schedule").
  1771. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1772. // Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1773. // return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1774. // }).
  1775. // Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1776. // Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1777. // Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1778. // Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1779. // Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1780. // return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1781. // }).
  1782. // Where("status = 1 AND user_org_id = ?", orgID)
  1783. // if scheduleDate != 0 {
  1784. // db = db.Where("schedule_date = ?", scheduleDate)
  1785. // }
  1786. // err = db.Find(&vms).Error
  1787. //}
  1788. db := readDb.Table("xt_schedule").Where("status = 1")
  1789. if orgID > 0 {
  1790. db = db.Where("user_org_id = ?", orgID)
  1791. }
  1792. if scheduleDate > 0 {
  1793. db = db.Where("schedule_date =?", scheduleDate)
  1794. }
  1795. err = db.Find(&vms).Error
  1796. if patientType == 0 {
  1797. db := readDb.
  1798. Table("xt_schedule").
  1799. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1800. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1801. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1802. }).
  1803. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1804. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1805. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1806. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1807. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1808. }).
  1809. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  1810. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  1811. }).
  1812. Where("status = 1 AND user_org_id = ?", orgID)
  1813. if scheduleDate != 0 {
  1814. db = db.Where("schedule_date = ?", scheduleDate)
  1815. }
  1816. err = db.Find(&vms).Error
  1817. }
  1818. if patientType > 0 {
  1819. db := readDb.
  1820. Table("xt_schedule").
  1821. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1822. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1823. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1824. }).
  1825. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1826. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1827. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1828. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1829. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1830. }).
  1831. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  1832. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  1833. }).
  1834. Where("status = 1 AND user_org_id = ?", orgID)
  1835. if scheduleDate != 0 {
  1836. db = db.Where("schedule_date = ?", scheduleDate)
  1837. }
  1838. err = db.Find(&vms).Error
  1839. }
  1840. return vms, err
  1841. }
  1842. func MobileCreateDialysisOrder(orgID int64, patientID int64, order *models.DialysisOrder) error {
  1843. now := time.Now()
  1844. tx := writeDb.Begin()
  1845. if createOrderErr := tx.Model(&models.DialysisOrder{}).Create(order).Error; createOrderErr != nil {
  1846. tx.Rollback()
  1847. return createOrderErr
  1848. }
  1849. // 更新透析记录 ID
  1850. // 透析处方
  1851. 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 {
  1852. tx.Rollback()
  1853. return err
  1854. }
  1855. // 接诊评估
  1856. 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 {
  1857. tx.Rollback()
  1858. return err
  1859. }
  1860. // 透前评估
  1861. 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 {
  1862. tx.Rollback()
  1863. return err
  1864. }
  1865. // 临时医嘱
  1866. 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 {
  1867. tx.Rollback()
  1868. return err
  1869. }
  1870. // 双人核对
  1871. 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 {
  1872. tx.Rollback()
  1873. return err
  1874. }
  1875. // 透后评估
  1876. 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 {
  1877. tx.Rollback()
  1878. return err
  1879. }
  1880. // 治疗小结
  1881. 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 {
  1882. tx.Rollback()
  1883. return err
  1884. }
  1885. // 透析监测
  1886. 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 {
  1887. tx.Rollback()
  1888. return err
  1889. }
  1890. tx.Commit()
  1891. return nil
  1892. }
  1893. type MobileUrgentSchedulePatientVM struct {
  1894. ID int64 `gorm:"column:id" json:"id"`
  1895. Name string `gorm:"column:name" json:"name"`
  1896. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no"`
  1897. }
  1898. func (MobileUrgentSchedulePatientVM) TableName() string {
  1899. return "xt_patients"
  1900. }
  1901. type MobileUrgentScheduleTreatmentModeVM struct {
  1902. ID int64 `gorm:"column:id" json:"id"`
  1903. Name string `gorm:"column:name" json:"name"`
  1904. }
  1905. func (MobileUrgentScheduleTreatmentModeVM) TableName() string {
  1906. return "xt_treatment_mode"
  1907. }
  1908. func MobileGetAllPatientsForUrgentSchedule(orgID int64, record_date int64) ([]*MobileUrgentSchedulePatientVM, error) {
  1909. var vms []*MobileUrgentSchedulePatientVM = make([]*MobileUrgentSchedulePatientVM, 0)
  1910. rows, err := readDb.Raw("SELECT p.* FROM xt_patients as p WHERE (p.user_org_id = ? AND p.status = 1 AND p.lapseto = 1) AND NOT EXISTS (Select * FROM `xt_dialysis_order` as d Where d.`dialysis_date` = ? AND d.`status` = 1 AND d.`patient_id` = p.id AND d.user_org_id = p.user_org_id )", orgID, record_date).Rows()
  1911. defer rows.Close()
  1912. if err != nil {
  1913. return nil, err
  1914. }
  1915. for rows.Next() {
  1916. var vm MobileUrgentSchedulePatientVM
  1917. readDb.ScanRows(rows, &vm)
  1918. vms = append(vms, &vm)
  1919. }
  1920. return vms, nil
  1921. }
  1922. func MobileGetAllTrearmentModesForUrgentSchedule() ([]*MobileUrgentScheduleTreatmentModeVM, error) {
  1923. var modes []*MobileUrgentScheduleTreatmentModeVM
  1924. err := readDb.Model(&MobileUrgentScheduleTreatmentModeVM{}).Where("status = 1").Find(&modes).Error
  1925. if err != nil {
  1926. return nil, err
  1927. }
  1928. return modes, nil
  1929. }
  1930. type MobileUrgentScheduleScheduleListVM struct {
  1931. ID int64 `gorm:"column:id" json:"id"`
  1932. // ZoneID int64 `gorm:"column:partition_id" json:"zone_id"`
  1933. DeviceNumberID int64 `gorm:"column:bed_id" json:"bed_id"`
  1934. PatientID int64 `gorm:"column:patient_id" json:"patient_id"`
  1935. ScheduleType int `gorm:"column:schedule_type" json:"schedule_type"`
  1936. DeviceNumber *models.DeviceNumber `gorm:"ForeignKey:DeviceNumberID" json:"device_number"`
  1937. // DeviceZone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"device_zone"`
  1938. }
  1939. func (MobileUrgentScheduleScheduleListVM) TableName() string {
  1940. return "xt_schedule"
  1941. }
  1942. func MobileGetSchedulesForUrgentSchedule(orgID int64, scheduleDate int64, schedule_type int) (schedules []*MobileUrgentScheduleScheduleListVM, err error) {
  1943. db := readDb.
  1944. Model(&MobileUrgentScheduleScheduleListVM{}).
  1945. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1946. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND schedule_type = ? ", orgID, scheduleDate, schedule_type)
  1947. err = db.Find(&schedules).Error
  1948. if err != nil {
  1949. return nil, err
  1950. }
  1951. return schedules, nil
  1952. }
  1953. func MobileGetOtherSchedulesForUrgentSchedule(orgID int64, scheduleDate int64, schedule_type int) ([]*MobileUrgentScheduleScheduleListVM, error) {
  1954. var vms []*MobileUrgentScheduleScheduleListVM = make([]*MobileUrgentScheduleScheduleListVM, 0)
  1955. 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()
  1956. defer rows.Close()
  1957. if err != nil {
  1958. return nil, err
  1959. }
  1960. for rows.Next() {
  1961. var vm MobileUrgentScheduleScheduleListVM
  1962. readDb.ScanRows(rows, &vm)
  1963. vms = append(vms, &vm)
  1964. }
  1965. return vms, nil
  1966. }
  1967. type MobileUrgentScheduleDeviceNumberVM struct {
  1968. ID int64 `gorm:"column:id" json:"id"`
  1969. Number string `gorm:"column:number" json:"number"`
  1970. ZoneID int64 `gorm:"column:zone_id" json:"zone_id"`
  1971. Zone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"zone"`
  1972. }
  1973. func (MobileUrgentScheduleDeviceNumberVM) TableName() string {
  1974. return "xt_device_number"
  1975. }
  1976. func MobileGetAllDeviceNumbersForUrgentSchedule(orgID int64, record_date int64, schedule_type int) ([]*DeviceNumberViewModel, error) {
  1977. var vms []*DeviceNumberViewModel = make([]*DeviceNumberViewModel, 0)
  1978. 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()
  1979. defer rows.Close()
  1980. if err != nil {
  1981. return nil, err
  1982. }
  1983. for rows.Next() {
  1984. var vm DeviceNumberViewModel
  1985. readDb.ScanRows(rows, &vm)
  1986. vms = append(vms, &vm)
  1987. }
  1988. return vms, nil
  1989. //var deviceNumbers []*MobileUrgentScheduleDeviceNumberVM
  1990. //db := readDb.
  1991. // Model(&MobileUrgentScheduleDeviceNumberVM{}).
  1992. // Preload("Zone", "status = 1 AND org_id = ?", orgID).
  1993. // Where("status = 1 AND org_id = ?", orgID)
  1994. //err := db.Order("zone_id asc").Find(&deviceNumbers).Error
  1995. //if err != nil {
  1996. // return nil, err
  1997. //}
  1998. //return deviceNumbers, nil
  1999. }
  2000. func GetValidScheduleMonitorRecordCount() (int64, error) {
  2001. var total int64
  2002. err := readDb.Model(&models.MonitoringRecord{}).Where("status = 1 AND operate_time = 0 AND monitoring_date <> 0").Count(&total).Error
  2003. return total, err
  2004. }
  2005. func GetTop1000ValidScheduleMonitorRecord() ([]*models.MonitoringRecord, error) {
  2006. var monitors []*models.MonitoringRecord
  2007. err := readDb.Model(&models.MonitoringRecord{}).Where("status = 1 AND operate_time = 0 AND monitoring_date <> 0").Order("id asc").Limit(100).Find(&monitors).Error
  2008. if err != nil {
  2009. return nil, err
  2010. }
  2011. return monitors, nil
  2012. }
  2013. func BatchUpdateMonitors(monitors []*models.MonitoringRecord) error {
  2014. tx := writeDb.Begin()
  2015. for index := 0; index < len(monitors); index++ {
  2016. tx.Save(monitors[index])
  2017. }
  2018. return tx.Commit().Error
  2019. }
  2020. func ModifyStartDialysisOrder(order *models.DialysisOrder) error {
  2021. tx := writeDb.Begin()
  2022. updateTime := time.Now().Unix()
  2023. err := tx.Model(&models.DialysisOrder{}).Where("user_org_id = ? AND id = ? AND status = 1 ", order.UserOrgId, order.ID).Updates(map[string]interface{}{"start_nurse": order.StartNurse, "updated_time": updateTime, "bed_id": order.BedID, "puncture_nurse": order.PunctureNurse, "start_time": order.StartTime, "modifier": order.Modifier, "schedual_type": order.SchedualType, "washpipe_nurse": order.WashpipeNurse, "change_nurse": order.ChangeNurse, "difficult_puncture_nurse": order.DifficultPunctureNurse, "new_fistula_nurse": order.NewFistulaNurse, "quality_nurse_id": order.QualityNurseId, "puncture_needle": order.PunctureNeedle, "puncture_way": order.PunctureWay, "dialysis_dialyszers": order.DialysisDialyszers, "dialysis_irrigation": order.DialysisIrrigation, "blood_access_id": order.BloodAccessId, "nuclein_date": order.NucleinDate, "schedule_remark": order.ScheduleRemark, "order_remark": order.OrderRemark, "catheter_operation": order.CatheterOperation}).Error
  2024. if err != nil {
  2025. tx.Rollback()
  2026. return err
  2027. }
  2028. tx.Commit()
  2029. return err
  2030. }
  2031. func ModifyFinishDialysisOrder(order *models.DialysisOrder) error {
  2032. tx := writeDb.Begin()
  2033. updateTime := time.Now().Unix()
  2034. err := tx.Model(&models.DialysisOrder{}).Where("user_org_id = ? AND id = ? AND status = 1 ", order.UserOrgId, order.ID).Updates(map[string]interface{}{"finish_nurse": order.FinishNurse, "updated_time": updateTime, "end_time": order.EndTime, "finish_modifier": order.FinishModifier, "puncture_point_haematoma": order.PuncturePointHaematoma, "blood_access_internal_fistula": order.BloodAccessInternalFistula, "catheter": order.Catheter, "cruor": order.Cruor, "mission": order.Mission}).Error
  2035. if err != nil {
  2036. tx.Rollback()
  2037. return err
  2038. }
  2039. tx.Commit()
  2040. return err
  2041. }
  2042. func MobileGetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  2043. var record models.SgjPatientDryweight
  2044. err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  2045. if err != nil {
  2046. if err == gorm.ErrRecordNotFound {
  2047. return nil, nil
  2048. } else {
  2049. return nil, err
  2050. }
  2051. }
  2052. return &record, nil
  2053. }
  2054. //func MobileGetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  2055. // var record models.SgjPatientDryweight
  2056. // redis := RedisClient()
  2057. // defer redis.Close()
  2058. //
  2059. // key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":last_dry_weight"
  2060. // last_dry_weight_str, _ := redis.Get(key).Result()
  2061. //
  2062. // if len(last_dry_weight_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2063. // err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  2064. // if err != nil {
  2065. // if err == gorm.ErrRecordNotFound {
  2066. // if record.ID <= 0 {
  2067. // redis.Set(key, "null", time.Second*60*60*18)
  2068. // }
  2069. // return nil, nil
  2070. // } else {
  2071. // return nil, err
  2072. // }
  2073. // } else {
  2074. // if record.ID > 0 {
  2075. // //缓存数据
  2076. // last_dry_weight_str, err := json.Marshal(record)
  2077. // if err == nil {
  2078. // redis.Set(key, last_dry_weight_str, time.Second*60*60*18)
  2079. // return nil, err
  2080. // }
  2081. // } else {
  2082. // redis.Set(key, "null", time.Second*60*60*18)
  2083. // return nil, err
  2084. // }
  2085. // return &record, nil
  2086. // }
  2087. // } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2088. // if last_dry_weight_str == "null" {
  2089. // return &record, nil
  2090. // } else {
  2091. // json.Unmarshal([]byte(last_dry_weight_str), &record)
  2092. // return &record, nil
  2093. // }
  2094. //
  2095. // }
  2096. //}
  2097. // 透析方案
  2098. func MobileGetDialysisSolutionByModeIdSix(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  2099. var record models.DialysisSolution
  2100. 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
  2101. if err != nil {
  2102. if err == gorm.ErrRecordNotFound {
  2103. return nil, nil
  2104. } else {
  2105. return nil, err
  2106. }
  2107. }
  2108. return &record, nil
  2109. }
  2110. // 透析方案
  2111. func MobileGetDialysisSolutionByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  2112. var record models.DialysisSolution
  2113. redis := RedisClient()
  2114. defer redis.Close()
  2115. // cur_date := time.Now().Format("2006-01-02")
  2116. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2117. dialysis_solution_str, _ := redis.Get(key).Result()
  2118. if len(dialysis_solution_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2119. 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
  2120. if err != nil {
  2121. if err == gorm.ErrRecordNotFound {
  2122. if record.ID <= 0 {
  2123. redis.Set(key, "null", time.Second*60*60*18)
  2124. }
  2125. return nil, nil
  2126. } else {
  2127. return nil, err
  2128. }
  2129. } else {
  2130. if record.ID > 0 {
  2131. //缓存数据
  2132. dialysis_solution_str, err := json.Marshal(record)
  2133. if err == nil {
  2134. redis.Set(key, dialysis_solution_str, time.Second*60*60*18)
  2135. }
  2136. } else {
  2137. redis.Set(key, "null", time.Second*60*60*18)
  2138. }
  2139. return &record, nil
  2140. }
  2141. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2142. if dialysis_solution_str == "null" {
  2143. return &record, nil
  2144. } else {
  2145. json.Unmarshal([]byte(dialysis_solution_str), &record)
  2146. return &record, nil
  2147. }
  2148. }
  2149. }
  2150. // 透析处方
  2151. func MobileGetDialysisPrescribeByModeId(orgID int64, patientID int64, recordDate int64, mode_id int64) (*models.DialysisPrescription, error) {
  2152. var record models.DialysisPrescription
  2153. redis := RedisClient()
  2154. defer redis.Close()
  2155. // cur_date := time.Now().Format("2006-01-02")
  2156. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2157. redis.Set(key, "", time.Second)
  2158. dialysis_prescribe_str, _ := redis.Get(key).Result()
  2159. if len(dialysis_prescribe_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2160. 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
  2161. if err != nil {
  2162. if err == gorm.ErrRecordNotFound {
  2163. if record.ID <= 0 {
  2164. redis.Set(key, "null", time.Second*60*60*18)
  2165. }
  2166. return nil, nil
  2167. } else {
  2168. return nil, err
  2169. }
  2170. } else {
  2171. if record.ID > 0 {
  2172. //缓存数据
  2173. dialysis_prescribe_str, err := json.Marshal(record)
  2174. if err == nil {
  2175. redis.Set(key, dialysis_prescribe_str, time.Second*60*60*18)
  2176. }
  2177. } else {
  2178. redis.Set(key, "null", time.Second*60*60*18)
  2179. }
  2180. return &record, nil
  2181. }
  2182. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2183. if dialysis_prescribe_str == "null" {
  2184. return &record, nil
  2185. } else {
  2186. json.Unmarshal([]byte(dialysis_prescribe_str), &record)
  2187. return &record, nil
  2188. }
  2189. }
  2190. }
  2191. func MobileGetDialysisPrescribeByModeIdSix(orgID int64, patientID int64, recordDate int64, mode_id int64) (*models.DialysisPrescription, error) {
  2192. var record models.DialysisPrescription
  2193. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? AND mode_id = ?", patientID, orgID, recordDate, mode_id).First(&record).Error
  2194. if err != nil {
  2195. if err == gorm.ErrRecordNotFound {
  2196. return nil, nil
  2197. } else {
  2198. return nil, err
  2199. }
  2200. }
  2201. return &record, nil
  2202. }
  2203. func MobileGetDialysisPrescribeByModeIdOne(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  2204. var record models.DialysisPrescription
  2205. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  2206. if err != nil {
  2207. if err == gorm.ErrRecordNotFound {
  2208. return nil, nil
  2209. } else {
  2210. return nil, err
  2211. }
  2212. }
  2213. return &record, nil
  2214. }
  2215. //func MobileGetDialysisPrescribeByModeIdOne(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  2216. // var record models.DialysisPrescription
  2217. // redis := RedisClient()
  2218. // defer redis.Close()
  2219. //
  2220. // // cur_date := time.Now().Format("2006-01-02")
  2221. // key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":dialysis_prescribe_by_mode"
  2222. // dialysis_prescribe_by_mode_str, _ := redis.Get(key).Result()
  2223. //
  2224. // if len(dialysis_prescribe_by_mode_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2225. // err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  2226. // if err != nil {
  2227. // if err == gorm.ErrRecordNotFound {
  2228. // if record.ID <= 0 {
  2229. // redis.Set(key, "null", time.Second*60*60*18)
  2230. // }
  2231. // return nil, nil
  2232. // } else {
  2233. // return nil, err
  2234. // }
  2235. // } else {
  2236. //
  2237. // if record.ID > 0 {
  2238. // //缓存数据
  2239. // dialysis_prescribe_by_mode_str, err := json.Marshal(record)
  2240. //
  2241. // if err == nil {
  2242. // redis.Set(key, dialysis_prescribe_by_mode_str, time.Second*60*60*18)
  2243. // return nil, err
  2244. // }
  2245. // } else {
  2246. // redis.Set(key, "null", time.Second*60*60*18)
  2247. // return nil, err
  2248. // }
  2249. // return &record, nil
  2250. // }
  2251. // } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2252. // if dialysis_prescribe_by_mode_str == "null" {
  2253. // json.Unmarshal([]byte(dialysis_prescribe_by_mode_str), &record)
  2254. // return &record, nil
  2255. // } else {
  2256. // json.Unmarshal([]byte(dialysis_prescribe_by_mode_str), &record)
  2257. // return &record, nil
  2258. // }
  2259. //
  2260. // }
  2261. //}
  2262. func MobileGetLastDialysisPrescribe(orgID int64, patientID int64) (*models.DialysisPrescription, error) {
  2263. var record models.DialysisPrescription
  2264. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 ", patientID, orgID).Last(&record).Error
  2265. if err != nil {
  2266. if err == gorm.ErrRecordNotFound {
  2267. return nil, nil
  2268. } else {
  2269. return nil, err
  2270. }
  2271. }
  2272. return &record, nil
  2273. }
  2274. func MobileGetLastDialysisPrescribeByModeIdSix(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2275. var record models.DialysisPrescription
  2276. 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
  2277. //if err != nil {
  2278. // if err == gorm.ErrRecordNotFound {
  2279. // return nil, nil
  2280. // } else {
  2281. // return nil, err
  2282. // }
  2283. //}
  2284. return &record, err
  2285. }
  2286. func MobileGetLastDialysisPrescribeByModeIdTen(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2287. var record models.DialysisPrescription
  2288. 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
  2289. if err != nil {
  2290. if err == gorm.ErrRecordNotFound {
  2291. return nil, nil
  2292. } else {
  2293. return nil, err
  2294. }
  2295. }
  2296. return &record, err
  2297. }
  2298. func MobileGetLastDialysisPrescribeByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2299. var record models.DialysisPrescription
  2300. redis := RedisClient()
  2301. defer redis.Close()
  2302. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  2303. dialysis_prescribe_by_mode_id, _ := redis.Get(key).Result()
  2304. if len(dialysis_prescribe_by_mode_id) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2305. 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
  2306. if err != nil {
  2307. if err == gorm.ErrRecordNotFound {
  2308. if record.ID <= 0 {
  2309. redis.Set(key, "null", time.Second*60*60*18)
  2310. }
  2311. return nil, nil
  2312. } else {
  2313. return nil, err
  2314. }
  2315. } else {
  2316. if record.ID > 0 {
  2317. //缓存数据
  2318. dialysis_prescribe_by_mode_str, err := json.Marshal(record)
  2319. if err == nil {
  2320. redis.Set(key, dialysis_prescribe_by_mode_str, time.Second*60*60*18)
  2321. return nil, err
  2322. }
  2323. } else {
  2324. redis.Set(key, "null", time.Second*60*60*18)
  2325. return nil, err
  2326. }
  2327. return &record, nil
  2328. }
  2329. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2330. if dialysis_prescribe_by_mode_id == "null" {
  2331. return &record, nil
  2332. } else {
  2333. json.Unmarshal([]byte(dialysis_prescribe_by_mode_id), &record)
  2334. return &record, nil
  2335. }
  2336. }
  2337. }
  2338. func MobileGetLastDialysisPrescribeByModeIdOne(orgID int64, patientID int64, mode_id int64) (models.DialysisPrescription, error) {
  2339. var record models.DialysisPrescription
  2340. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and mode_id = ?", patientID, orgID, mode_id).Last(&record).Error
  2341. return record, err
  2342. }
  2343. func GetAllAvaildDeviceNumbers(orgID int64, record_date int64, schedule_type int) ([]*DeviceNumberViewModel, error) {
  2344. var vms []*DeviceNumberViewModel = make([]*DeviceNumberViewModel, 0)
  2345. 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()
  2346. defer rows.Close()
  2347. if err != nil {
  2348. return nil, err
  2349. }
  2350. for rows.Next() {
  2351. var vm DeviceNumberViewModel
  2352. readDb.ScanRows(rows, &vm)
  2353. vms = append(vms, &vm)
  2354. }
  2355. return vms, nil
  2356. }
  2357. // 获取 maxDate 之前一次的透前评估记录
  2358. func GetLastTimePredialysisEvaluation(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
  2359. var record models.PredialysisEvaluation
  2360. 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
  2361. if err != nil {
  2362. if err == gorm.ErrRecordNotFound {
  2363. return nil, nil
  2364. } else {
  2365. return nil, err
  2366. }
  2367. }
  2368. return &record, nil
  2369. }
  2370. func GetLastTimeOrder(orgID int64, patientID int64, maxDate int64) (*models.DialysisOrder, error) {
  2371. var record models.DialysisOrder
  2372. 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
  2373. if err != nil {
  2374. if err == gorm.ErrRecordNotFound {
  2375. return nil, nil
  2376. } else {
  2377. return nil, err
  2378. }
  2379. }
  2380. return &record, nil
  2381. }
  2382. func GetLastMonitorRecord(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  2383. var record models.MonitoringRecord
  2384. 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
  2385. if err != nil {
  2386. if err == gorm.ErrRecordNotFound {
  2387. return nil, nil
  2388. } else {
  2389. return nil, err
  2390. }
  2391. }
  2392. return &record, nil
  2393. }
  2394. // 获取 maxDate 之前一次的透后评估记录
  2395. func GetLastTimeAssessmentAfterDislysis(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  2396. var record models.AssessmentAfterDislysis
  2397. 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
  2398. if err != nil {
  2399. if err == gorm.ErrRecordNotFound {
  2400. return nil, nil
  2401. } else {
  2402. return nil, err
  2403. }
  2404. }
  2405. return &record, nil
  2406. }
  2407. // 透析处方
  2408. func GetDialysisPrescribe(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  2409. var record models.DialysisPrescription
  2410. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  2411. if err != nil {
  2412. if err == gorm.ErrRecordNotFound {
  2413. return nil, nil
  2414. } else {
  2415. return nil, err
  2416. }
  2417. }
  2418. return &record, nil
  2419. }
  2420. // 透析方案
  2421. func GetDialysisSolution(orgID int64, patientID int64, mode_id int64) (models.DialysisSolution, error) {
  2422. var record models.DialysisSolution
  2423. 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
  2424. return record, err
  2425. }
  2426. func GetDialysisSolutionOne(orgID int64, mode_id int64) (*models.DialysisSolution, error) {
  2427. var record models.DialysisSolution
  2428. err := readDb.Model(&models.DialysisSolution{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2429. if err != nil {
  2430. if err == gorm.ErrRecordNotFound {
  2431. return nil, nil
  2432. } else {
  2433. return nil, err
  2434. }
  2435. }
  2436. return &record, nil
  2437. }
  2438. func GetLastDialysisPrescribeByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2439. var record models.DialysisPrescription
  2440. 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
  2441. if err != nil {
  2442. if err == gorm.ErrRecordNotFound {
  2443. return nil, nil
  2444. } else {
  2445. return nil, err
  2446. }
  2447. }
  2448. return &record, nil
  2449. }
  2450. func GetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  2451. var record models.SgjPatientDryweight
  2452. err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  2453. if err != nil {
  2454. if err == gorm.ErrRecordNotFound {
  2455. return nil, nil
  2456. } else {
  2457. return nil, err
  2458. }
  2459. }
  2460. return &record, nil
  2461. }
  2462. func MobileGetSystemDialysisPrescribeByModeIdSix(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2463. var record models.SystemPrescription
  2464. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).First(&record).Error
  2465. if err != nil {
  2466. if err == gorm.ErrRecordNotFound {
  2467. return nil, nil
  2468. } else {
  2469. return nil, err
  2470. }
  2471. }
  2472. return &record, nil
  2473. }
  2474. func MobileGetSystemDialysisPrescribeByModeId(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2475. var record models.SystemPrescription
  2476. redis := RedisClient()
  2477. defer redis.Close()
  2478. // cur_date := time.Now().Format("2006-01-02")
  2479. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  2480. system_dialysis_prescribe_str, _ := redis.Get(key).Result()
  2481. if len(system_dialysis_prescribe_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2482. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2483. if err != nil {
  2484. if err == gorm.ErrRecordNotFound {
  2485. if record.ID <= 0 {
  2486. redis.Set(key, "null", time.Second*60*60*18)
  2487. }
  2488. return nil, nil
  2489. } else {
  2490. return nil, err
  2491. }
  2492. } else {
  2493. if record.ID > 0 {
  2494. //缓存数据
  2495. system_dialysis_prescribe_str, err := json.Marshal(record)
  2496. if err == nil {
  2497. redis.Set(key, system_dialysis_prescribe_str, time.Second*60*60*18)
  2498. }
  2499. } else {
  2500. redis.Set(key, "null", time.Second*60*60*18)
  2501. }
  2502. return &record, nil
  2503. }
  2504. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2505. if system_dialysis_prescribe_str == "null" {
  2506. return &record, nil
  2507. } else {
  2508. json.Unmarshal([]byte(system_dialysis_prescribe_str), &record)
  2509. return &record, nil
  2510. }
  2511. }
  2512. }
  2513. func MobileGetSystemDialysisPrescribeByModeIdOne(orgID int64, mode_id int64) (models.SystemPrescription, error) {
  2514. var record models.SystemPrescription
  2515. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2516. return record, err
  2517. }
  2518. func GetSystemDialysisPrescribeByModeId(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2519. var record models.SystemPrescription
  2520. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2521. if err != nil {
  2522. if err == gorm.ErrRecordNotFound {
  2523. return nil, nil
  2524. } else {
  2525. return nil, err
  2526. }
  2527. }
  2528. return &record, nil
  2529. }
  2530. func GetDialysisOrderCount(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2531. 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
  2532. return
  2533. }
  2534. func GetDialysisOrderCountOne(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2535. err = readDb.Model(&models.DialysisOrder{}).Where("dialysis_date>=1640966400 and dialysis_date <= ? AND status = 1 AND stage = 2 AND user_org_id = ? AND patient_id = ?", recordDate, orgID, patient_id).Count(&count).Error
  2536. return
  2537. }
  2538. func GetDialysisOrderCountTwo(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2539. err = readDb.Model(&models.DialysisOrder{}).Where("dialysis_date>=1672502400 and dialysis_date <= ? AND status = 1 AND stage = 2 AND user_org_id = ? AND patient_id = ?", recordDate, orgID, patient_id).Count(&count).Error
  2540. return
  2541. }
  2542. func GetFirstDateOfMonth(d time.Time) time.Time {
  2543. d = d.AddDate(0, 0, -d.Day()+1)
  2544. return GetZeroTime(d)
  2545. }
  2546. func GetZeroTime(d time.Time) time.Time {
  2547. return time.Date(d.Year(), d.Month(), d.Day(), 0, 0, 0, 0, d.Location())
  2548. }
  2549. func GetDialysisCountByPatientId(startime int64, endtime int64, patientid int64, orgid int64) (order []*models.BloodDialysisOrderCount, err error) {
  2550. db := XTReadDB().Table("xt_dialysis_order as o")
  2551. 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
  2552. return order, err
  2553. }
  2554. func FindConsumablesByDate(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error) {
  2555. 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
  2556. return
  2557. }
  2558. func FindConsumablesByDateTwo(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error) {
  2559. 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
  2560. return
  2561. }
  2562. func FindConsumablesByDateThree(orgID int64, patient_id int64, recordDate int64) (consumables []*models.BloodAutomaticReduceDetail, err error) {
  2563. 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
  2564. return
  2565. }
  2566. //func FindLastConsumables(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error){
  2567. // 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
  2568. // return
  2569. //}
  2570. //
  2571. func GetLastTimeConsumables(orgID int64, patientID int64, maxDate int64) (prepare []*models.DialysisBeforePrepare, err error) {
  2572. 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
  2573. return
  2574. }
  2575. type GoodsType struct {
  2576. ID int64 `gorm:"column:id" json:"id"`
  2577. TypeName string `gorm:"column:type_name" json:"type_name"`
  2578. Remark string `gorm:"column:remark" json:"remark"`
  2579. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2580. Status int64 `gorm:"column:status" json:"status"`
  2581. Type int64 `gorm:"column:type" json:"type"`
  2582. }
  2583. func (GoodsType) TableName() string {
  2584. return "xt_goods_type"
  2585. }
  2586. type VMGoodInfo struct {
  2587. ID int64 `gorm:"column:id" json:"id"`
  2588. SpecificationName string `gorm:"column:specification_name" json:"specification_name"`
  2589. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2590. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2591. GoodName string `gorm:"column:good_name" json:"good_name" form:"good_name"`
  2592. GoodUnit int64 `gorm:"column:good_unit" json:"good_unit" form:"good_unit"`
  2593. Total float64 `gorm:"column:total" json:"total" form:"total"`
  2594. PackingUnit string `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
  2595. MedicalInsuranceNumber string `gorm:"column:medical_insurance_number" json:"medical_insurance_number" form:"medical_insurance_number"`
  2596. }
  2597. func (VMGoodInfo) TableName() string {
  2598. return "xt_good_information"
  2599. }
  2600. type AutomaticReduceDetail struct {
  2601. ID int64 `gorm:"column:id" json:"id"`
  2602. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2603. Status int64 `gorm:"column:status" json:"status"`
  2604. RecordTime int64 `gorm:"column:record_time" json:"record_time"`
  2605. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2606. GoodId int64 `gorm:"column:good_id" json:"good_id"`
  2607. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2608. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"info"`
  2609. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"type"`
  2610. Count int64 `gorm:"column:count" json:"count"`
  2611. }
  2612. func (AutomaticReduceDetail) TableName() string {
  2613. return "xt_automatic_reduce_detail"
  2614. }
  2615. type DialysisBeforePrepare struct {
  2616. ID int64 `gorm:"column:id" json:"id" form:"id"`
  2617. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  2618. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  2619. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  2620. GoodId int64 `gorm:"column:good_id" json:"good_id" form:"good_id"`
  2621. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id" form:"good_type_id"`
  2622. Count int64 `gorm:"column:count" json:"count" form:"count"`
  2623. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  2624. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  2625. Creater int64 `gorm:"column:creater" json:"creater" form:"creater"`
  2626. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  2627. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"info"`
  2628. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"type"`
  2629. }
  2630. func (DialysisBeforePrepare) TableName() string {
  2631. return "dialysis_before_prepare"
  2632. }
  2633. type MDialysisGoodsVM struct {
  2634. ID int64 `gorm:"column:id" json:"id"`
  2635. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2636. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2637. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2638. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2639. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2640. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2641. ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week"`
  2642. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2643. Status int64 `gorm:"column:status" json:"status"`
  2644. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2645. SchedualPatient *MSchedualPatientVMList `gorm:"ForeignKey:PatientId" json:"patient"`
  2646. AutomaticReduceDetail []*AutomaticReduceDetail `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"good_user"`
  2647. LastAutomaticReduceDetail []*AutomaticReduceDetail `gorm:"-" json:"last_good_user"`
  2648. DialysisBeforePrepare []*DialysisBeforePrepare `gorm:"ForeignKey:PatientId,ScheduleDate;AssociationForeignKey:PatientId,RecordDate" json:"good_user_detail"`
  2649. LastDialysisBeforePrepare []*DialysisBeforePrepare `gorm:"-" json:"last_good_user_detail"`
  2650. Project []*models.HisPrescriptionProject `gorm:"-" json:"project"`
  2651. //WarehouseOutInfo []*models.WarehouseOutInfoSeven `gorm:"ForeignKey:PatientId,ScheduleDate;AssociationForeignKey:PatientId,SysRecordTime" json:"ware_house_out_info"`
  2652. }
  2653. func (MDialysisGoodsVM) TableName() string {
  2654. return "xt_schedule"
  2655. }
  2656. type VMWarehouseOutInfo struct {
  2657. ID int64 `gorm:"column:id" json:"id"`
  2658. WarehouseOutId int64 `gorm:"column:warehouse_out_id" json:"warehouse_out_id"`
  2659. GoodId int64 `gorm:"column:good_id" json:"good_id"`
  2660. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2661. Count int64 `gorm:"column:count" json:"count"`
  2662. Price float64 `gorm:"column:price" json:"price"`
  2663. TotalPrice float64 `gorm:"column:total_price" json:"total_price"`
  2664. Status int64 `gorm:"column:status" json:"status"`
  2665. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2666. WarehouseOutOrderNumber string `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number"`
  2667. GoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"good_info"`
  2668. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"good_type"`
  2669. IsSys int64 `gorm:"column:is_sys" json:"is_sys"`
  2670. SysRecordTime int64 `gorm:"column:sys_record_time" json:"sys_record_time"`
  2671. Mtime int64 `gorm:"column:mtime" json:"mtime"`
  2672. Ctime int64 `gorm:"column:ctime" json:"ctime"`
  2673. }
  2674. func (VMWarehouseOutInfo) TableName() string {
  2675. return "xt_warehouse_out_info"
  2676. }
  2677. type DialysisGoodsDate struct {
  2678. RecordDate int64
  2679. }
  2680. type DialysisGoodsDetailDate struct {
  2681. RecordTime int64
  2682. }
  2683. 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) {
  2684. var vms []*MDialysisGoodsVM
  2685. var total int64
  2686. db := readDb.
  2687. Table("xt_schedule as sch").
  2688. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  2689. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2690. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2691. Preload("DialysisBeforePrepare", func(db *gorm.DB) *gorm.DB {
  2692. 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)
  2693. }).
  2694. Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
  2695. 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")
  2696. }).Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
  2697. if scheduleDate != 0 {
  2698. db = db.Where("schedule_date = ?", scheduleDate)
  2699. }
  2700. if schedule_type != 0 {
  2701. db = db.Where("schedule_type = ?", schedule_type)
  2702. }
  2703. if partition_id != 0 {
  2704. db = db.Where("partition_id = ?", partition_id)
  2705. }
  2706. if patient_id != 0 {
  2707. db = db.Where("patient_id = ?", patient_id)
  2708. }
  2709. err := db.Find(&vms).Error
  2710. return vms, err, total
  2711. }
  2712. func GetLastDialysisGoods(patient_id int64, orgID int64, record_time int64) (goodUser []*AutomaticReduceDetail, err error) {
  2713. var Id []*DialysisGoodsDetailDate
  2714. 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
  2715. if len(Id) > 0 {
  2716. 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
  2717. }
  2718. return
  2719. }
  2720. func GetLastDialysisBeforePrepare(patient_id int64, orgID int64, record_time int64) (goodUser []*DialysisBeforePrepare, err error) {
  2721. var Id []*DialysisGoodsDate
  2722. 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
  2723. if len(Id) > 0 {
  2724. 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
  2725. }
  2726. return
  2727. }
  2728. func GetAllWarehouseOutSumList(patient_id int64, orgID int64, record_time int64) (info []*models.WarehouseOutInfoSeven, err error) {
  2729. err = XTReadDB().Where("patient_id = ? and org_id = ? and sys_record_time = ? and status = 1", patient_id, orgID, record_time).Find(&info).Error
  2730. return info, err
  2731. }
  2732. func MobileGetGoodsStatistics(orgID int64, start_time int64, end_time int64) (list []*models.StockInfo, err error) {
  2733. db := readDb.Model(&models.StockInfo{})
  2734. db = db.Where("xt_good_information.org_id = ? AND xt_good_information.status = 1", orgID)
  2735. 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")
  2736. db = db.Preload("QueryWarehouseOutInfo", func(db *gorm.DB) *gorm.DB {
  2737. 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)
  2738. })
  2739. db = db.Preload("GoodsType", "org_id = ? AND status = 1", orgID)
  2740. err = db.Order("ctime desc").Find(&list).Error
  2741. return
  2742. }
  2743. 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) {
  2744. var vms []*MDialysisGoodsVM
  2745. var total int64
  2746. db := readDb.
  2747. Model(&models.Schedule{}).
  2748. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  2749. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2750. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2751. Preload("DialysisBeforePrepare", func(db *gorm.DB) *gorm.DB {
  2752. 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)
  2753. }).Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
  2754. 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)
  2755. }).Where("xt_schedule.status = 1 AND xt_schedule.user_org_id = ?", orgID)
  2756. if scheduleDate != 0 {
  2757. db = db.Where("schedule_date = ?", scheduleDate)
  2758. }
  2759. if patient_id != 0 {
  2760. db = db.Where("patient_id = ?", patient_id)
  2761. }
  2762. if len(keywords) != 0 {
  2763. keywords = "%" + keywords + "%"
  2764. 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)
  2765. if schedule_type != 0 {
  2766. db = db.Where("schedule_type = ?", schedule_type)
  2767. }
  2768. if partition_id != 0 {
  2769. db = db.Where("partition_id = ?", partition_id)
  2770. }
  2771. if good_type == 1 {
  2772. db = db.Where("patient_id in(?)", ids)
  2773. }
  2774. if good_type == 2 {
  2775. if len(ids) > 0 {
  2776. db = db.Where("patient_id not in(?)", ids)
  2777. }
  2778. }
  2779. } else {
  2780. if schedule_type != 0 {
  2781. db = db.Where("schedule_type = ?", schedule_type)
  2782. }
  2783. if partition_id != 0 {
  2784. db = db.Where("partition_id = ?", partition_id)
  2785. }
  2786. if good_type == 1 {
  2787. db = db.Where("patient_id in(?)", ids)
  2788. }
  2789. if good_type == 2 {
  2790. if len(ids) > 0 {
  2791. db = db.Where("patient_id not in(?)", ids)
  2792. }
  2793. }
  2794. db = db.Count(&total)
  2795. offset := (page - 1) * limit
  2796. db = db.Offset(offset).Limit(limit)
  2797. }
  2798. err := db.Find(&vms).Error
  2799. return vms, err, total
  2800. }
  2801. func GetLastDialysisGoodsTwo(patient_id int64, orgID int64, record_time int64) (goodUser []*AutomaticReduceDetail, err error) {
  2802. var Id []*DialysisGoodsDetailDate
  2803. 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
  2804. if len(Id) > 0 {
  2805. 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
  2806. }
  2807. return
  2808. }
  2809. func GetLastDialysisBeforePrepareTwo(patient_id int64, orgID int64, record_time int64) (goodUser []*DialysisBeforePrepare, err error) {
  2810. var Id []*DialysisGoodsDate
  2811. 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
  2812. if len(Id) > 0 {
  2813. 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
  2814. }
  2815. return
  2816. }
  2817. func GetAssessmentBefor(orgid int64, patientid int64, recorddate int64) (*models.PredialysisEvaluation, error) {
  2818. evaluation := models.PredialysisEvaluation{}
  2819. err := XTReadDB().Model(&evaluation).Where("user_org_id = ? and patient_id = ? and assessment_date = ? and status = 1", orgid, patientid, recorddate).Find(&evaluation).Error
  2820. if err == gorm.ErrRecordNotFound {
  2821. return nil, err
  2822. }
  2823. if err != nil {
  2824. return nil, err
  2825. }
  2826. return &evaluation, nil
  2827. }
  2828. func GetAssessmentBeforThrity(orgid int64, patientid int64, recorddate int64) (models.PredialysisEvaluation, error) {
  2829. evaluation := models.PredialysisEvaluation{}
  2830. err := XTReadDB().Model(&evaluation).Where("user_org_id = ? and patient_id = ? and assessment_date = ? and status = 1", orgid, patientid, recorddate).Find(&evaluation).Error
  2831. return evaluation, err
  2832. }
  2833. func GetAllHisDoctorAdvice(orgid int64, patientid int64, recorddate int64) (his []*models.HisDoctorAdviceInfo, err error) {
  2834. redis := RedisClient()
  2835. defer redis.Close()
  2836. key := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patientid, 10) + ":" + strconv.FormatInt(recorddate, 10) + ":his_doctor_advice"
  2837. his_doctor_advice_str, _ := redis.Get(key).Result()
  2838. redis.Set(key, "", time.Second)
  2839. if len(his_doctor_advice_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2840. 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
  2841. if err != nil {
  2842. if err == gorm.ErrRecordNotFound {
  2843. if len(his) <= 0 {
  2844. redis.Set(key, "null", time.Second*60*60*18)
  2845. }
  2846. return his, nil
  2847. } else {
  2848. return his, err
  2849. }
  2850. } else {
  2851. if len(his) > 0 {
  2852. //缓存数据
  2853. his_doctor_advice_str, err := json.Marshal(his)
  2854. if err == nil {
  2855. redis.Set(key, his_doctor_advice_str, time.Second*60*60*18)
  2856. }
  2857. } else {
  2858. redis.Set(key, "null", time.Second*60*60*18)
  2859. }
  2860. return his, nil
  2861. }
  2862. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2863. json.Unmarshal([]byte(his_doctor_advice_str), &his)
  2864. return his, nil
  2865. }
  2866. }
  2867. func GetLastDialysisPrescriptionByPatientId(orgid int64, patientid int64, recorddate int64) (*models.DialysisPrescription, error) {
  2868. prescription := models.DialysisPrescription{}
  2869. err := readDb.Model(&models.DialysisPrescription{}).Where("user_org_id = ? and patient_id = ? and record_date = ? and status = 1", orgid, patientid, recorddate).Find(&prescription).Error
  2870. if err == gorm.ErrRecordNotFound {
  2871. return nil, err
  2872. }
  2873. if err != nil {
  2874. return nil, err
  2875. }
  2876. return &prescription, nil
  2877. }
  2878. func GetLastDialysisPrescriptionByPatientIdTwo(orgid int64, patientid int64, recorddate int64) (models.DialysisPrescription, error) {
  2879. prescription := models.DialysisPrescription{}
  2880. err := readDb.Model(&models.DialysisPrescription{}).Where("user_org_id = ? and patient_id = ? and record_date = ? and status = 1", orgid, patientid, recorddate).Find(&prescription).Error
  2881. return prescription, err
  2882. }
  2883. type HisMScheduleDoctorAdviceVM struct {
  2884. ID int64 `gorm:"column:id" json:"id"`
  2885. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2886. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2887. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2888. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2889. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2890. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2891. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2892. Status int64 `gorm:"column:status" json:"status"`
  2893. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  2894. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  2895. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2896. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  2897. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  2898. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  2899. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  2900. }
  2901. func (HisMScheduleDoctorAdviceVM) TableName() string {
  2902. return "xt_schedule"
  2903. }
  2904. type HisMScheduleDoctorAdviceVMOne struct {
  2905. ID int64 `gorm:"column:id" json:"id"`
  2906. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2907. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2908. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2909. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2910. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2911. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2912. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2913. Status int64 `gorm:"column:status" json:"status"`
  2914. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  2915. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  2916. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2917. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  2918. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  2919. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  2920. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  2921. }
  2922. func (HisMScheduleDoctorAdviceVMOne) TableName() string {
  2923. return "xt_schedule"
  2924. }
  2925. type HisMScheduleProjectVM struct {
  2926. ID int64 `gorm:"column:id" json:"id"`
  2927. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2928. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2929. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2930. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2931. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2932. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2933. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2934. Status int64 `gorm:"column:status" json:"status"`
  2935. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  2936. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  2937. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2938. Prescription *models.DialysisPrescriptionTwenty `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  2939. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  2940. HisPrescriptionTeamProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"team_project"`
  2941. }
  2942. func (HisMScheduleProjectVM) TableName() string {
  2943. return "xt_schedule"
  2944. }
  2945. func GetHisDoctorConfig(orgid int64) (models.XtHisConfig, error) {
  2946. config := models.XtHisConfig{}
  2947. err := XTReadDB().Model(&config).Where("user_org_id = ? and status =1", orgid).Find(&config).Error
  2948. return config, err
  2949. }
  2950. func GetHisDoctorPatientById(orgid int64, patientid int64, recordtime int64) (advice []*models.HisDoctorAdviceInfo, err error) {
  2951. db := XTReadDB().Table("his_doctor_advice_info as x").Where("x.status = 1")
  2952. if orgid > 0 {
  2953. db = db.Where("x.user_org_id = ?", orgid)
  2954. }
  2955. if patientid > 0 {
  2956. db = db.Where("x.patient_id =?", patientid)
  2957. }
  2958. if recordtime > 0 {
  2959. db = db.Where("x.advice_date = ?", recordtime)
  2960. }
  2961. 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
  2962. return advice, err
  2963. }
  2964. func GetDoctorAdviceCount(startime int64, endtime int64, deliveway string, orgid int64) (advice []*models.BloodDoctorAdvice, err error) {
  2965. db := XTReadDB().Table("xt_doctor_advice as x").Where("x.status = 1 and x.advice_type =2")
  2966. if startime > 0 {
  2967. db = db.Where("x.advice_date >= ?", startime)
  2968. }
  2969. if endtime > 0 {
  2970. db = db.Where("x.advice_date<=?", endtime)
  2971. }
  2972. if orgid > 0 {
  2973. db = db.Where("x.user_org_id = ?", orgid)
  2974. }
  2975. if len(deliveway) > 0 {
  2976. db = db.Where("x.delivery_way = ?", deliveway)
  2977. }
  2978. 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
  2979. return advice, err
  2980. }
  2981. func GetHisDoctorAdviceCount(startime int64, endtime int64, deliveway string, orgid int64) (advice []*models.BloodDoctorAdvice, err error) {
  2982. db := XTReadDB().Table("his_doctor_advice_info as x").Where("x.status = 1 and x.advice_type =2")
  2983. if startime > 0 {
  2984. db = db.Where("x.advice_date >= ?", startime)
  2985. }
  2986. if endtime > 0 {
  2987. db = db.Where("x.advice_date<=?", endtime)
  2988. }
  2989. if orgid > 0 {
  2990. db = db.Where("x.user_org_id = ?", orgid)
  2991. }
  2992. if len(deliveway) > 0 {
  2993. db = db.Where("x.delivery_way = ?", deliveway)
  2994. }
  2995. 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
  2996. return advice, err
  2997. }
  2998. 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) {
  2999. var vms []*MScheduleDoctorAdviceVM
  3000. adviceWhere := ""
  3001. adviceCondition := []interface{}{}
  3002. if adviceType == 0 {
  3003. if patientType == 0 {
  3004. if patient_id > 0 {
  3005. if execution_state > 0 {
  3006. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  3007. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3008. } else {
  3009. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
  3010. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3011. }
  3012. } else {
  3013. if execution_state > 0 {
  3014. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ?"
  3015. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3016. } else {
  3017. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  3018. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3019. }
  3020. }
  3021. } else if patientType == 1 {
  3022. if patient_id > 0 {
  3023. if execution_state > 0 {
  3024. 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= ?"
  3025. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3026. } else {
  3027. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
  3028. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3029. }
  3030. } else {
  3031. if execution_state > 0 {
  3032. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  3033. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3034. } else {
  3035. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  3036. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3037. }
  3038. }
  3039. } else if patientType == 2 {
  3040. if patient_id > 0 {
  3041. if execution_state > 0 {
  3042. 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 = ?"
  3043. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3044. } else {
  3045. 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 = ?)"
  3046. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3047. }
  3048. } else {
  3049. if execution_state > 0 {
  3050. 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 = ?"
  3051. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3052. } else {
  3053. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  3054. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3055. }
  3056. }
  3057. }
  3058. } else if adviceType == 1 {
  3059. if patientType == 0 {
  3060. if patient_id > 0 {
  3061. if execution_state > 0 {
  3062. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ?"
  3063. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3064. } else {
  3065. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
  3066. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3067. }
  3068. } else {
  3069. if execution_state > 0 {
  3070. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ?"
  3071. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3072. } else {
  3073. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  3074. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3075. }
  3076. }
  3077. } else if patientType == 1 {
  3078. if patient_id > 0 {
  3079. if execution_state > 0 {
  3080. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  3081. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3082. } else {
  3083. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
  3084. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3085. }
  3086. } else {
  3087. if execution_state > 0 {
  3088. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?"
  3089. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3090. } else {
  3091. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  3092. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3093. }
  3094. }
  3095. } else if patientType == 2 {
  3096. if patient_id > 0 {
  3097. if execution_state > 0 {
  3098. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  3099. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3100. } else {
  3101. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
  3102. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3103. }
  3104. } else {
  3105. if execution_state > 0 {
  3106. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ?"
  3107. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3108. } else {
  3109. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  3110. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3111. }
  3112. }
  3113. }
  3114. } else if adviceType == 3 {
  3115. if patientType == 0 {
  3116. if patient_id > 0 {
  3117. if execution_state > 0 {
  3118. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ?"
  3119. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3120. } else {
  3121. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? "
  3122. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3123. }
  3124. } else {
  3125. if execution_state > 0 {
  3126. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? "
  3127. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3128. } else {
  3129. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  3130. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3131. }
  3132. }
  3133. } else if patientType == 1 {
  3134. if patient_id > 0 {
  3135. if execution_state > 0 {
  3136. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  3137. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3138. } else {
  3139. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
  3140. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3141. }
  3142. } else {
  3143. if execution_state > 0 {
  3144. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? "
  3145. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3146. } else {
  3147. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  3148. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3149. }
  3150. }
  3151. } else if patientType == 2 {
  3152. if patient_id > 0 {
  3153. if execution_state > 0 {
  3154. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  3155. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3156. } else {
  3157. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ?"
  3158. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3159. }
  3160. } else {
  3161. if execution_state > 0 {
  3162. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ?"
  3163. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3164. } else {
  3165. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  3166. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3167. }
  3168. }
  3169. }
  3170. } else if adviceType == 2 && len(deliverWay) > 0 {
  3171. if patientType == 0 {
  3172. if patient_id > 0 {
  3173. if execution_state > 0 {
  3174. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  3175. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  3176. } else {
  3177. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ?"
  3178. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  3179. }
  3180. } else {
  3181. if execution_state > 0 {
  3182. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ?"
  3183. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  3184. } else {
  3185. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  3186. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  3187. }
  3188. }
  3189. } else if patientType == 1 {
  3190. if patient_id > 0 {
  3191. if execution_state > 0 {
  3192. 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 = ?"
  3193. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state)
  3194. } else {
  3195. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ?"
  3196. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
  3197. }
  3198. } else {
  3199. if execution_state > 0 {
  3200. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ?"
  3201. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state)
  3202. } else {
  3203. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  3204. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  3205. }
  3206. }
  3207. } else if patientType == 2 {
  3208. if patient_id > 0 {
  3209. if execution_state > 0 {
  3210. 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 = ?"
  3211. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  3212. } else {
  3213. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ?"
  3214. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  3215. }
  3216. } else {
  3217. if execution_state > 0 {
  3218. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ?"
  3219. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  3220. } else {
  3221. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  3222. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  3223. }
  3224. }
  3225. }
  3226. } else if adviceType == 2 && len(deliverWay) <= 0 {
  3227. if patientType == 0 {
  3228. if patient_id > 0 {
  3229. if execution_state > 0 {
  3230. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ?"
  3231. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3232. } else {
  3233. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ?"
  3234. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3235. }
  3236. } else {
  3237. if execution_state > 0 {
  3238. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?"
  3239. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3240. } else {
  3241. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  3242. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3243. }
  3244. }
  3245. } else if patientType == 1 {
  3246. if patient_id > 0 {
  3247. if execution_state > 0 {
  3248. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  3249. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3250. } else {
  3251. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ?"
  3252. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3253. }
  3254. } else {
  3255. if execution_state > 0 {
  3256. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ?"
  3257. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3258. } else {
  3259. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?"
  3260. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3261. }
  3262. }
  3263. } else if patientType == 2 {
  3264. if patient_id > 0 {
  3265. if execution_state > 0 {
  3266. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  3267. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3268. } else {
  3269. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ?"
  3270. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3271. }
  3272. } else {
  3273. if execution_state > 0 {
  3274. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ?"
  3275. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3276. } else {
  3277. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  3278. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3279. }
  3280. }
  3281. }
  3282. }
  3283. db := readDb.Table("xt_schedule")
  3284. if scheduleType > 0 {
  3285. db = db.Where("schedule_type = ?", scheduleType)
  3286. }
  3287. if partitonType > 0 {
  3288. db = db.Where("partition_id = ?", partitonType)
  3289. }
  3290. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3291. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3292. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3293. }).
  3294. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3295. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3296. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3297. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3298. Preload("DoctorAdvices", adviceCondition...).
  3299. Where("status = 1 AND user_org_id = ?", orgID)
  3300. if scheduleDate != 0 {
  3301. db = db.Where("schedule_date = ?", scheduleDate)
  3302. }
  3303. err := db.Find(&vms).Error
  3304. return vms, err
  3305. }
  3306. func GetHisDoctorAdvicesOne(orgID int64, scheduleDate int64, deliverWay string, scheduleType int64, partitionType int64, patient_id int64, execution_state int64, cost_type int64) ([]*HisMScheduleDoctorAdviceVM, error) {
  3307. var vms []*HisMScheduleDoctorAdviceVM
  3308. if len(deliverWay) > 0 {
  3309. db := readDb.Table("xt_schedule")
  3310. if scheduleType > 0 {
  3311. db = db.Where("schedule_type = ?", scheduleType)
  3312. }
  3313. if partitionType > 0 {
  3314. db = db.Where("partition_id = ?", partitionType)
  3315. }
  3316. if patient_id > 0 {
  3317. if execution_state > 0 {
  3318. if cost_type > 0 {
  3319. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3320. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3321. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3322. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3323. 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).
  3324. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3325. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3326. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3327. Where("status = 1 AND user_org_id = ?", orgID)
  3328. if scheduleDate != 0 {
  3329. db = db.Where("schedule_date = ?", scheduleDate)
  3330. }
  3331. err = db.Find(&vms).Error
  3332. } else {
  3333. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3334. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3335. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3336. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3337. 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).
  3338. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3339. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3340. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3341. Where("status = 1 AND user_org_id = ?", orgID)
  3342. if scheduleDate != 0 {
  3343. db = db.Where("schedule_date = ?", scheduleDate)
  3344. }
  3345. err = db.Find(&vms).Error
  3346. }
  3347. } else {
  3348. if cost_type > 0 {
  3349. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3350. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3351. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3352. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3353. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ? and is_settle", orgID, scheduleDate, deliverWay, patient_id, cost_type).
  3354. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3355. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3356. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3357. Where("status = 1 AND user_org_id = ?", orgID)
  3358. if scheduleDate != 0 {
  3359. db = db.Where("schedule_date = ?", scheduleDate)
  3360. }
  3361. err = db.Find(&vms).Error
  3362. } else {
  3363. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3364. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3365. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3366. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3367. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ?", orgID, scheduleDate, deliverWay, patient_id).
  3368. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3369. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3370. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3371. Where("status = 1 AND user_org_id = ?", orgID)
  3372. if scheduleDate != 0 {
  3373. db = db.Where("schedule_date = ?", scheduleDate)
  3374. }
  3375. err = db.Find(&vms).Error
  3376. }
  3377. }
  3378. } else {
  3379. if execution_state > 0 {
  3380. if cost_type > 0 {
  3381. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3382. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3383. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3384. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3385. 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).
  3386. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3387. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3388. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3389. Where("status = 1 AND user_org_id = ?", orgID)
  3390. if scheduleDate != 0 {
  3391. db = db.Where("schedule_date = ?", scheduleDate)
  3392. }
  3393. err = db.Find(&vms).Error
  3394. } else {
  3395. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3396. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3397. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3398. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3399. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_state = ?", orgID, scheduleDate, deliverWay, execution_state).
  3400. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3401. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3402. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3403. Where("status = 1 AND user_org_id = ?", orgID)
  3404. if scheduleDate != 0 {
  3405. db = db.Where("schedule_date = ?", scheduleDate)
  3406. }
  3407. err = db.Find(&vms).Error
  3408. }
  3409. } else {
  3410. if cost_type > 0 {
  3411. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3412. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3413. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3414. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3415. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and is_settle = ?", orgID, scheduleDate, deliverWay, cost_type).
  3416. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3417. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3418. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3419. Where("status = 1 AND user_org_id = ?", orgID)
  3420. if scheduleDate != 0 {
  3421. db = db.Where("schedule_date = ?", scheduleDate)
  3422. }
  3423. err = db.Find(&vms).Error
  3424. } else {
  3425. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3426. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3427. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3428. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3429. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  3430. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3431. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3432. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3433. Where("status = 1 AND user_org_id = ?", orgID)
  3434. if scheduleDate != 0 {
  3435. db = db.Where("schedule_date = ?", scheduleDate)
  3436. }
  3437. err = db.Find(&vms).Error
  3438. }
  3439. }
  3440. }
  3441. } else {
  3442. db := readDb.Table("xt_schedule")
  3443. if scheduleType > 0 {
  3444. db = db.Where("schedule_type = ?", scheduleType)
  3445. }
  3446. if partitionType > 0 {
  3447. db = db.Where("partition_id = ?", partitionType)
  3448. }
  3449. if patient_id > 0 {
  3450. if execution_state > 0 {
  3451. if cost_type > 0 {
  3452. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3453. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3454. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3455. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3456. 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).
  3457. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3458. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3459. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3460. Where("status = 1 AND user_org_id = ?", orgID)
  3461. if scheduleDate != 0 {
  3462. db = db.Where("schedule_date = ?", scheduleDate)
  3463. }
  3464. err = db.Find(&vms).Error
  3465. } else {
  3466. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3467. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3468. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3469. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3470. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and execution_state = ?", orgID, scheduleDate, patient_id, execution_state).
  3471. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3472. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3473. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3474. Where("status = 1 AND user_org_id = ?", orgID)
  3475. if scheduleDate != 0 {
  3476. db = db.Where("schedule_date = ?", scheduleDate)
  3477. }
  3478. err = db.Find(&vms).Error
  3479. }
  3480. } else {
  3481. if cost_type > 0 {
  3482. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3483. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3484. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3485. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3486. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and is_settle = ?", orgID, scheduleDate, patient_id, cost_type).
  3487. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3488. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3489. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3490. Where("status = 1 AND user_org_id = ?", orgID)
  3491. if scheduleDate != 0 {
  3492. db = db.Where("schedule_date = ?", scheduleDate)
  3493. }
  3494. err = db.Find(&vms).Error
  3495. } else {
  3496. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3497. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3498. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3499. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3500. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3501. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3502. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3503. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3504. Where("status = 1 AND user_org_id = ?", orgID)
  3505. if scheduleDate != 0 {
  3506. db = db.Where("schedule_date = ?", scheduleDate)
  3507. }
  3508. err = db.Find(&vms).Error
  3509. }
  3510. }
  3511. } else {
  3512. if execution_state > 0 {
  3513. if cost_type > 0 {
  3514. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3515. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3516. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3517. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3518. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ? and is_settle = ?", orgID, scheduleDate, execution_state, cost_type).
  3519. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3520. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3521. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3522. Where("status = 1 AND user_org_id = ?", orgID)
  3523. if scheduleDate != 0 {
  3524. db = db.Where("schedule_date = ?", scheduleDate)
  3525. }
  3526. err = db.Find(&vms).Error
  3527. } else {
  3528. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3529. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3530. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3531. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3532. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ?", orgID, scheduleDate, execution_state).
  3533. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3534. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3535. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3536. Where("status = 1 AND user_org_id = ?", orgID)
  3537. if scheduleDate != 0 {
  3538. db = db.Where("schedule_date = ?", scheduleDate)
  3539. }
  3540. err = db.Find(&vms).Error
  3541. }
  3542. } else {
  3543. if cost_type > 0 {
  3544. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3545. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3546. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3547. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3548. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and is_settle = ?", orgID, scheduleDate, cost_type).
  3549. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3550. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3551. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3552. Where("status = 1 AND user_org_id = ?", orgID)
  3553. if scheduleDate != 0 {
  3554. db = db.Where("schedule_date = ?", scheduleDate)
  3555. }
  3556. err = db.Find(&vms).Error
  3557. } else {
  3558. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3559. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3560. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3561. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3562. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ?", orgID, scheduleDate).
  3563. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3564. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3565. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3566. Where("status = 1 AND user_org_id = ?", orgID)
  3567. if scheduleDate != 0 {
  3568. db = db.Where("schedule_date = ?", scheduleDate)
  3569. }
  3570. err = db.Find(&vms).Error
  3571. }
  3572. }
  3573. }
  3574. }
  3575. return vms, err
  3576. }
  3577. func BatchDeleteMonitor(ids []string) (err error) {
  3578. if len(ids) == 1 {
  3579. err = XTWriteDB().Model(&models.MonitoringRecord{}).Where("id=?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3580. } else {
  3581. err = XTWriteDB().Model(models.MonitoringRecord{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3582. }
  3583. return
  3584. }
  3585. func GetPatientDialysisRecordList(patientid int64, startime int64, endtime int64) (order []*models.XtDialysisOrders, err error) {
  3586. db := XTReadDB().Table("xt_dialysis_order as x").Where("x.status = 1")
  3587. //table := XTReadDB().Table("xt_schedule as s")
  3588. //fmt.Println(table)
  3589. if patientid > 0 {
  3590. db = db.Where("x.patient_id = ?", patientid)
  3591. }
  3592. if startime > 0 {
  3593. db = db.Where("x.dialysis_date>=?", startime)
  3594. }
  3595. if endtime > 0 {
  3596. db = db.Where("x.dialysis_date <= ?", endtime)
  3597. }
  3598. err = db.Select("x.id,x.dialysis_date,x.schedual_type,s.mode_id").Joins("left join xt_schedule as s on x.patient_id = s.patient_id and x.dialysis_date = s.schedule_date ").Scan(&order).Error
  3599. return order, err
  3600. }
  3601. func BatchDeleteAdvice(ids []string) (err error) {
  3602. if len(ids) == 1 {
  3603. err = XTWriteDB().Model(&models.DoctorAdvice{}).Where("id=?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3604. } else {
  3605. err = XTWriteDB().Model(models.DoctorAdvice{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3606. }
  3607. return
  3608. }
  3609. func BatchDeleteHisAdvice(ids []string) (err error) {
  3610. if len(ids) == 1 {
  3611. err = XTWriteDB().Model(&models.HisDoctorAdviceInfo{}).Where("id = ?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3612. } else {
  3613. err = XTWriteDB().Model(models.HisDoctorAdviceInfo{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3614. }
  3615. return
  3616. }
  3617. func UpdateAutoReduceDetail(good_id int64, count int64, record_time int64, patient_id int64) (models.AutomaticReduceDetail, error) {
  3618. detail := models.AutomaticReduceDetail{}
  3619. 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
  3620. return detail, err
  3621. }
  3622. func DeleteAutoReduceDetail(good_id int64, record_time int64, patient_id int64) error {
  3623. detail := models.AutomaticReduceDetail{}
  3624. 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
  3625. return err
  3626. }
  3627. func DeleteDialysisBeforOne(good_id int64, record_time int64, patient_id int64) error {
  3628. detail := models.DialysisBeforePrepare{}
  3629. 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
  3630. return err
  3631. }
  3632. func BatchAdviceCheck(ids []string, creator int64) error {
  3633. advice := models.XtDoctorAdvice{}
  3634. 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
  3635. return err
  3636. }
  3637. func BatchHisAdviceCheck(ids []string, creator int64) error {
  3638. advice := models.HisDoctorAdviceInfo{}
  3639. 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
  3640. return err
  3641. }
  3642. func BatchAdviceExecution(ids []string, creator int64, execution_state int64) error {
  3643. advice := models.XtDoctorAdvice{}
  3644. 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
  3645. return err
  3646. }
  3647. func BatchHisAdviceExecution(ids []string, creator int64, execution_state int64) error {
  3648. advice := models.HisDoctorAdviceInfo{}
  3649. 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
  3650. return err
  3651. }
  3652. func GetAdviceExecutionById(ids []string) (doctor []*models.XtDoctorAdvice, err error) {
  3653. err = XTReadDB().Model(&doctor).Where("id IN(?) AND status = 1", ids).Find(&doctor).Error
  3654. return doctor, err
  3655. }
  3656. func GetHisAdviceExecutionById(ids []string) (doctor []*models.HisDoctorAdviceInfo, err error) {
  3657. err = XTReadDB().Model(&doctor).Where("id IN(?) AND status = 1", ids).Find(&doctor).Error
  3658. return doctor, err
  3659. }
  3660. func GetHisProjectConfig(orgid int64) (models.XtHisProjectConfig, error) {
  3661. config := models.XtHisProjectConfig{}
  3662. err := XTReadDB().Model(&config).Where("user_org_id = ? and status =1", orgid).Find(&config).Error
  3663. return config, err
  3664. }
  3665. func GetHisPrescriptionProject(org_id int64, patient_id int64, record_date int64) (project []*models.HisPrescriptionProject, err error) {
  3666. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("GoodInfo", func(db *gorm.DB) *gorm.DB {
  3667. return db.Preload("GoodsType", "status = 1").Where("status = 1 and is_warehouse = 1")
  3668. }).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
  3669. return
  3670. }
  3671. func GetPCHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64, patient_id int64, execution_state int64) ([]*HisMScheduleProjectVM, error) {
  3672. var vms []*HisMScheduleProjectVM
  3673. if patientType == 0 {
  3674. if patient_id > 0 {
  3675. if execution_state == 1 {
  3676. db := readDb.
  3677. Table("xt_schedule").
  3678. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3679. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3680. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3681. }).
  3682. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3683. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3684. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3685. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3686. 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")
  3687. }).
  3688. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3689. 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")
  3690. }).Where("status = 1 AND user_org_id = ?", orgID)
  3691. if scheduleDate != 0 {
  3692. db = db.Where("schedule_date = ?", scheduleDate)
  3693. }
  3694. err = db.Find(&vms).Error
  3695. } else if execution_state == 2 {
  3696. db := readDb.
  3697. Table("xt_schedule").
  3698. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3699. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3700. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3701. }).
  3702. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3703. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3704. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3705. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3706. 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")
  3707. }).
  3708. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3709. 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")
  3710. }).Where("status = 1 AND user_org_id = ?", orgID)
  3711. if scheduleDate != 0 {
  3712. db = db.Where("schedule_date = ?", scheduleDate)
  3713. }
  3714. err = db.Find(&vms).Error
  3715. } else if execution_state == 0 {
  3716. db := readDb.
  3717. Table("xt_schedule").
  3718. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3719. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3720. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3721. }).
  3722. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3723. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3724. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3725. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3726. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3727. }).
  3728. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3729. 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")
  3730. }).Where("status = 1 AND user_org_id = ?", orgID)
  3731. if scheduleDate != 0 {
  3732. db = db.Where("schedule_date = ?", scheduleDate)
  3733. }
  3734. err = db.Find(&vms).Error
  3735. }
  3736. } else {
  3737. if patient_id > 0 {
  3738. if execution_state == 1 {
  3739. db := readDb.
  3740. Table("xt_schedule").
  3741. Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
  3742. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3743. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3744. }).
  3745. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3746. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3747. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3748. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3749. 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")
  3750. }).
  3751. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3752. 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")
  3753. }).Where("status = 1 AND user_org_id = ?", orgID)
  3754. if scheduleDate != 0 {
  3755. db = db.Where("schedule_date = ?", scheduleDate)
  3756. }
  3757. err = db.Find(&vms).Error
  3758. } else if execution_state == 2 {
  3759. db := readDb.
  3760. Table("xt_schedule").
  3761. Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
  3762. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3763. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3764. }).
  3765. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3766. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3767. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3768. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3769. 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")
  3770. }).
  3771. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3772. 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")
  3773. }).Where("status = 1 AND user_org_id = ?", orgID)
  3774. if scheduleDate != 0 {
  3775. db = db.Where("schedule_date = ?", scheduleDate)
  3776. }
  3777. err = db.Find(&vms).Error
  3778. } else if execution_state == 0 {
  3779. db := readDb.
  3780. Table("xt_schedule").
  3781. Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
  3782. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3783. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3784. }).
  3785. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3786. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3787. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3788. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3789. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3790. }).
  3791. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3792. 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")
  3793. }).Where("status = 1 AND user_org_id = ?", orgID)
  3794. if scheduleDate != 0 {
  3795. db = db.Where("schedule_date = ?", scheduleDate)
  3796. }
  3797. err = db.Find(&vms).Error
  3798. }
  3799. } else {
  3800. if execution_state == 1 {
  3801. db := readDb.
  3802. Table("xt_schedule").
  3803. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3804. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3805. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3806. }).
  3807. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3808. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3809. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3810. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3811. 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")
  3812. }).
  3813. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3814. 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")
  3815. }).Where("status = 1 AND user_org_id = ?", orgID)
  3816. if scheduleDate != 0 {
  3817. db = db.Where("schedule_date = ?", scheduleDate)
  3818. }
  3819. err = db.Find(&vms).Error
  3820. } else if execution_state == 2 {
  3821. fmt.Println("j氯332n323232n323ℹ️33232323232")
  3822. db := readDb.
  3823. Table("xt_schedule").
  3824. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3825. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3826. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3827. }).
  3828. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3829. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3830. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3831. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3832. 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")
  3833. }).
  3834. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3835. 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")
  3836. }).Where("status = 1 AND user_org_id = ?", orgID)
  3837. if scheduleDate != 0 {
  3838. db = db.Where("schedule_date = ?", scheduleDate)
  3839. }
  3840. err = db.Find(&vms).Error
  3841. } else if execution_state == 0 {
  3842. db := readDb.
  3843. Table("xt_schedule").
  3844. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3845. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3846. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3847. }).
  3848. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3849. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3850. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3851. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3852. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3853. }).
  3854. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3855. 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")
  3856. }).Where("status = 1 AND user_org_id = ?", orgID)
  3857. if scheduleDate != 0 {
  3858. db = db.Where("schedule_date = ?", scheduleDate)
  3859. }
  3860. err = db.Find(&vms).Error
  3861. }
  3862. }
  3863. }
  3864. }
  3865. if patientType > 0 {
  3866. if execution_state == 1 {
  3867. db := readDb.
  3868. Table("xt_schedule").
  3869. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3870. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3871. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3872. }).
  3873. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3874. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3875. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3876. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  3877. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3878. 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")
  3879. }).
  3880. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3881. 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")
  3882. }).Where("status = 1 AND user_org_id = ?", orgID)
  3883. if scheduleDate != 0 {
  3884. db = db.Where("schedule_date = ?", scheduleDate)
  3885. }
  3886. err = db.Find(&vms).Error
  3887. } else if execution_state == 2 {
  3888. db := readDb.
  3889. Table("xt_schedule").
  3890. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3891. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3892. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3893. }).
  3894. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3895. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3896. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3897. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  3898. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3899. 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")
  3900. }).
  3901. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3902. 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")
  3903. }).Where("status = 1 AND user_org_id = ?", orgID)
  3904. if scheduleDate != 0 {
  3905. db = db.Where("schedule_date = ?", scheduleDate)
  3906. }
  3907. err = db.Find(&vms).Error
  3908. } else if execution_state == 0 {
  3909. db := readDb.
  3910. Table("xt_schedule").
  3911. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3912. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3913. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3914. }).
  3915. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3916. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3917. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3918. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  3919. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3920. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3921. }).
  3922. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3923. 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")
  3924. }).Where("status = 1 AND user_org_id = ?", orgID)
  3925. if scheduleDate != 0 {
  3926. db = db.Where("schedule_date = ?", scheduleDate)
  3927. }
  3928. err = db.Find(&vms).Error
  3929. }
  3930. }
  3931. return vms, err
  3932. }
  3933. func UpdateStockGoods(good_id int64, record_time int64, patient_id int64, count int64) error {
  3934. prepare := models.DialysisBeforePrepare{}
  3935. var err error
  3936. if count > 0 {
  3937. 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
  3938. }
  3939. if count <= 0 {
  3940. 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
  3941. }
  3942. return err
  3943. }
  3944. func UPdateAutoStockGoods(good_id int64, record_time int64, patient_id int64, count int64) error {
  3945. detail := models.AutomaticReduceDetail{}
  3946. 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
  3947. return err
  3948. }
  3949. func MobileGetDialysisSolutionByModeIdSeven(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  3950. var record models.DialysisSolution
  3951. 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
  3952. if err != nil {
  3953. if err == gorm.ErrRecordNotFound {
  3954. return nil, nil
  3955. } else {
  3956. return nil, err
  3957. }
  3958. }
  3959. return &record, nil
  3960. }
  3961. func MobileGetLastDialysisPrescribeByModeIdSeven(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  3962. var record models.DialysisPrescription
  3963. 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
  3964. if err != nil {
  3965. if err == gorm.ErrRecordNotFound {
  3966. return nil, nil
  3967. } else {
  3968. return nil, err
  3969. }
  3970. }
  3971. return &record, nil
  3972. }
  3973. func MobileGetLastDialysisPrescription(patientID int64, orgID int64) (models.DialysisPrescriptionThrity, error) {
  3974. prescription := models.DialysisPrescriptionThrity{}
  3975. err := readDb.Model(&prescription).Where("patient_id = ? and user_org_id = ? and status = 1 and remark<>''", patientID, orgID).Last(&prescription).Error
  3976. return prescription, err
  3977. }
  3978. func MobileGetSystemDialysisPrescribeByModeIdSeven(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  3979. var record models.SystemPrescription
  3980. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).First(&record).Error
  3981. if err != nil {
  3982. if err == gorm.ErrRecordNotFound {
  3983. return nil, nil
  3984. } else {
  3985. return nil, err
  3986. }
  3987. }
  3988. return &record, nil
  3989. }
  3990. // 透前评估
  3991. func MobileGetPredialysisEvaluationSeven(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
  3992. var record models.PredialysisEvaluation
  3993. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  3994. if err != nil {
  3995. if err == gorm.ErrRecordNotFound {
  3996. return nil, nil
  3997. } else {
  3998. return nil, err
  3999. }
  4000. }
  4001. return &record, nil
  4002. }
  4003. //
  4004. //func MobileGetDialysisGoodsSix(orgID int64, scheduleDate int64) (prepare []*models.DialysisBeforePrepare, err error) {
  4005. //
  4006. // 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
  4007. // return prepare, err
  4008. //}
  4009. func GetMobileAutoReduce(orgID int64, scheduleDate int64) (auto []*models.AutomaticReduceDetail, err error) {
  4010. err = readDb.Where("org_id = ? and status = 1 and record_time = ?", orgID, scheduleDate).Find(&auto).Error
  4011. return auto, err
  4012. }
  4013. func GetRoleList(orgid int64, admin_user_id int64) (models.SgjUserAdminRole, error) {
  4014. role := models.SgjUserAdminRole{}
  4015. err = readUserDb.Where("org_id = ? and admin_user_id = ? and status =1 ", orgid, admin_user_id).Find(&role).Error
  4016. return role, err
  4017. }
  4018. func GetDialysisGood(orgID int64, scheduleDate int64) (auto []*models.AutomaticReduceDetail, err error) {
  4019. err = readDb.Where("org_id = ? and status = 1 and record_time >= ?", orgID, scheduleDate).Group("patient_id").Find(&auto).Error
  4020. return auto, err
  4021. }
  4022. func GetGoodWarehouseOutInfo(orgId int64, patient_id int64, sys_record_time int64) (outifno []*models.WarehouseOutInfoSeven, err error) {
  4023. err = readDb.Where("org_id = ? and patient_id = ? and sys_record_time = ? and status = 1", orgId, patient_id, sys_record_time).Find(&outifno).Error
  4024. return outifno, err
  4025. }
  4026. func GetLastDilysisOrder(orgid int64, patient_id int64, dialysis_date int64) (models.DialysisOrder, error) {
  4027. order := models.DialysisOrder{}
  4028. err = XTReadDB().Where("user_org_id = ? and patient_id = ? and dialysis_date < ? and status= 1", orgid, patient_id, dialysis_date).Last(&order).Error
  4029. return order, err
  4030. }
  4031. func GetFistMonitor(orgid int64, patient_id int64, dialysis_date int64) (models.MonitoringRecord, error) {
  4032. record := models.MonitoringRecord{}
  4033. err := XTReadDB().Where("org_id = ? and patient_id = ? and monitoring_date = ? and status = 1", orgid, patient_id, dialysis_date).Find(&record).Error
  4034. return record, err
  4035. }
  4036. func GetFistMonitorSix(orgid int64, patient_id int64, dialysis_date int64) (record []*models.MonitoringRecord, err error) {
  4037. err = XTReadDB().Where("user_org_id = ? and patient_id = ? and monitoring_date = ? and status = 1", orgid, patient_id, dialysis_date).Find(&record).Error
  4038. return record, err
  4039. }
  4040. 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) {
  4041. var vms []*MScheduleDoctorAdviceVM
  4042. keyword = "%" + keyword + "%"
  4043. adviceWhere := ""
  4044. adviceCondition := []interface{}{}
  4045. if adviceType == 0 {
  4046. if patientType == 0 {
  4047. if patient_id > 0 {
  4048. if execution_state > 0 {
  4049. if cost_type > 0 {
  4050. if len(execution_frequency) > 0 {
  4051. if len(keyword) > 0 {
  4052. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  4053. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4054. } else {
  4055. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ? and is_settle = ? and execution_frequency = ?"
  4056. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4057. }
  4058. } else {
  4059. if len(keyword) > 0 {
  4060. 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 ?"
  4061. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  4062. } else {
  4063. 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 = ?"
  4064. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4065. }
  4066. }
  4067. } else {
  4068. if len(execution_frequency) > 0 {
  4069. if len(keyword) > 0 {
  4070. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ? and execution_frequency = ? and advice_name like ?"
  4071. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  4072. } else {
  4073. 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 = ?"
  4074. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4075. }
  4076. } else {
  4077. if len(keyword) > 0 {
  4078. 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 ?"
  4079. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  4080. } else {
  4081. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  4082. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4083. }
  4084. }
  4085. }
  4086. } else {
  4087. if cost_type > 0 {
  4088. if len(execution_frequency) > 0 {
  4089. 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 = ?"
  4090. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4091. } else {
  4092. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and is_settle = ?"
  4093. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4094. }
  4095. } else {
  4096. if len(execution_frequency) > 0 {
  4097. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_frequency = ?"
  4098. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4099. } else {
  4100. if len(keyword) > 0 {
  4101. 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 ?"
  4102. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  4103. } else {
  4104. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
  4105. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4106. }
  4107. }
  4108. }
  4109. }
  4110. } else {
  4111. if execution_state > 0 {
  4112. if cost_type > 0 {
  4113. if len(execution_frequency) > 0 {
  4114. if len(keyword) > 0 {
  4115. 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 ?"
  4116. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  4117. } else {
  4118. 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 = ?"
  4119. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4120. }
  4121. } else {
  4122. if len(keyword) > 0 {
  4123. 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 ?"
  4124. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  4125. } else {
  4126. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and is_settle = ?"
  4127. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4128. }
  4129. }
  4130. } else {
  4131. if len(execution_frequency) > 0 {
  4132. if len(keyword) > 0 {
  4133. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and execution_frequency = ? and advice_name like ?"
  4134. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  4135. } else {
  4136. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and execution_frequency = ?"
  4137. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4138. }
  4139. } else {
  4140. if len(keyword) > 0 {
  4141. 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 ?"
  4142. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  4143. } else {
  4144. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ?"
  4145. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4146. }
  4147. }
  4148. }
  4149. } else {
  4150. if cost_type > 0 {
  4151. if len(execution_frequency) > 0 {
  4152. if len(keyword) > 0 {
  4153. 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 ?"
  4154. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  4155. } else {
  4156. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ? and execution_frequency = ?"
  4157. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  4158. }
  4159. } else {
  4160. if len(keyword) > 0 {
  4161. 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 ?"
  4162. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  4163. } else {
  4164. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ?"
  4165. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4166. }
  4167. }
  4168. } else {
  4169. if len(execution_frequency) > 0 {
  4170. if len(keyword) > 0 {
  4171. 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 ?"
  4172. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  4173. } else {
  4174. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_frequency = ?"
  4175. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  4176. }
  4177. } else {
  4178. if len(keyword) > 0 {
  4179. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and advice_name like ?"
  4180. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  4181. } else {
  4182. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  4183. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4184. }
  4185. }
  4186. }
  4187. }
  4188. }
  4189. } else if patientType == 1 {
  4190. if patient_id > 0 {
  4191. if execution_state > 0 {
  4192. if cost_type > 0 {
  4193. if len(execution_frequency) > 0 {
  4194. if len(keyword) > 0 {
  4195. 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 ?"
  4196. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4197. } else {
  4198. 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 = ?"
  4199. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  4200. }
  4201. } else {
  4202. if len(keyword) > 0 {
  4203. 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 ?"
  4204. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, keyword)
  4205. } else {
  4206. 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 = ?"
  4207. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  4208. }
  4209. }
  4210. } else {
  4211. if len(execution_frequency) > 0 {
  4212. if len(keyword) > 0 {
  4213. 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 ?"
  4214. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  4215. } else {
  4216. 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 = ?"
  4217. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  4218. }
  4219. } else {
  4220. if len(keyword) > 0 {
  4221. 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 ?"
  4222. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, keyword)
  4223. } else {
  4224. 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= ?"
  4225. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  4226. }
  4227. }
  4228. }
  4229. } else {
  4230. if cost_type > 0 {
  4231. if len(execution_frequency) > 0 {
  4232. if len(keyword) > 0 {
  4233. 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 ?"
  4234. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  4235. } else {
  4236. 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 = ?"
  4237. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  4238. }
  4239. } else {
  4240. if len(keyword) > 0 {
  4241. 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 ?"
  4242. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, keyword)
  4243. } else {
  4244. 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=?"
  4245. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  4246. }
  4247. }
  4248. } else {
  4249. if len(execution_frequency) > 0 {
  4250. if len(keyword) > 0 {
  4251. 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 ?"
  4252. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency, keyword)
  4253. } else {
  4254. 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 = ?"
  4255. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  4256. }
  4257. } else {
  4258. if len(keyword) > 0 {
  4259. 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 ?"
  4260. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, keyword)
  4261. } else {
  4262. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
  4263. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  4264. }
  4265. }
  4266. }
  4267. }
  4268. } else {
  4269. if execution_state > 0 {
  4270. if cost_type > 0 {
  4271. if len(execution_frequency) > 0 {
  4272. if len(keyword) > 0 {
  4273. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ? and is_settle=? and execution_frequency = ? and advice_name like ?"
  4274. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  4275. } else {
  4276. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ? and is_settle=? and execution_frequency = ?"
  4277. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  4278. }
  4279. } else {
  4280. if len(keyword) > 0 {
  4281. 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 ?"
  4282. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, keyword)
  4283. } else {
  4284. 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=?"
  4285. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  4286. }
  4287. }
  4288. } else {
  4289. if len(execution_frequency) > 0 {
  4290. if len(keyword) > 0 {
  4291. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ? and execution_frequency = ? and advice_name like ?"
  4292. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency, keyword)
  4293. } else {
  4294. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ? and execution_frequency = ?"
  4295. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  4296. }
  4297. } else {
  4298. if len(keyword) > 0 {
  4299. 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 ?"
  4300. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, keyword)
  4301. } else {
  4302. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  4303. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  4304. }
  4305. }
  4306. }
  4307. } else {
  4308. if cost_type > 0 {
  4309. if len(execution_frequency) > 0 {
  4310. if len(keyword) > 0 {
  4311. 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 ?"
  4312. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency, keyword)
  4313. } else {
  4314. 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 = ?"
  4315. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  4316. }
  4317. } else {
  4318. if len(keyword) > 0 {
  4319. 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 ?"
  4320. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, keyword)
  4321. } else {
  4322. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and is_settle=?"
  4323. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  4324. }
  4325. }
  4326. } else {
  4327. if len(execution_frequency) > 0 {
  4328. if len(keyword) > 0 {
  4329. 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 ?"
  4330. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency, keyword)
  4331. } else {
  4332. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_frequency = ?"
  4333. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  4334. }
  4335. } else {
  4336. if len(keyword) > 0 {
  4337. 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 ?"
  4338. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, keyword)
  4339. } else {
  4340. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  4341. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  4342. }
  4343. }
  4344. }
  4345. }
  4346. }
  4347. } else if patientType == 2 {
  4348. if patient_id > 0 {
  4349. if execution_state > 0 {
  4350. if cost_type > 0 {
  4351. if len(execution_frequency) > 0 {
  4352. if len(keyword) > 0 {
  4353. 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 ?"
  4354. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4355. } else {
  4356. 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 = ?"
  4357. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4358. }
  4359. } else {
  4360. if len(keyword) > 0 {
  4361. 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 ?"
  4362. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  4363. } else {
  4364. 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=?"
  4365. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4366. }
  4367. }
  4368. } else {
  4369. if len(execution_frequency) > 0 {
  4370. if len(keyword) > 0 {
  4371. 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 ?"
  4372. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  4373. } else {
  4374. 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 = ?"
  4375. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4376. }
  4377. } else {
  4378. if len(keyword) > 0 {
  4379. 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 ?"
  4380. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  4381. } else {
  4382. 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 = ?"
  4383. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4384. }
  4385. }
  4386. }
  4387. } else {
  4388. if cost_type > 0 {
  4389. if len(execution_frequency) > 0 {
  4390. if len(keyword) > 0 {
  4391. 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 ?"
  4392. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  4393. } else {
  4394. 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 = ?"
  4395. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4396. }
  4397. } else {
  4398. if len(keyword) > 0 {
  4399. 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 ?"
  4400. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  4401. } else {
  4402. 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=?"
  4403. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4404. }
  4405. }
  4406. } else {
  4407. if len(execution_frequency) > 0 {
  4408. if len(keyword) > 0 {
  4409. 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 ?"
  4410. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  4411. } else {
  4412. 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 = ?"
  4413. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4414. }
  4415. } else {
  4416. if len(keyword) > 0 {
  4417. 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 ?"
  4418. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  4419. } else {
  4420. 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 = ?)"
  4421. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4422. }
  4423. }
  4424. }
  4425. }
  4426. } else {
  4427. if execution_state > 0 {
  4428. if cost_type > 0 {
  4429. if len(execution_frequency) > 0 {
  4430. if len(keyword) > 0 {
  4431. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1) and execution_state = ? and is_settle=? and execution_frequency = ? and advice_name like ?"
  4432. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  4433. } else {
  4434. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1) and execution_state = ? and is_settle=? and execution_frequency = ?"
  4435. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4436. }
  4437. } else {
  4438. if len(keyword) > 0 {
  4439. 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 ?"
  4440. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  4441. } else {
  4442. 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=?"
  4443. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4444. }
  4445. }
  4446. } else {
  4447. if len(execution_frequency) > 0 {
  4448. if len(keyword) > 0 {
  4449. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1) and execution_state = ? and execution_frequency = ? and advice_name like ?"
  4450. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  4451. } else {
  4452. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1) and execution_state = ? and execution_frequency = ?"
  4453. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4454. }
  4455. } else {
  4456. if len(keyword) > 0 {
  4457. 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 ?"
  4458. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  4459. } else {
  4460. 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 = ?"
  4461. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4462. }
  4463. }
  4464. }
  4465. } else {
  4466. if cost_type > 0 {
  4467. if len(execution_frequency) > 0 {
  4468. if len(keyword) > 0 {
  4469. 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 ?"
  4470. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  4471. } else {
  4472. 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 = ?"
  4473. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  4474. }
  4475. } else {
  4476. if len(keyword) > 0 {
  4477. 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 ?"
  4478. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  4479. } else {
  4480. 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 = ?"
  4481. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4482. }
  4483. }
  4484. } else {
  4485. if len(execution_frequency) > 0 {
  4486. if len(keyword) > 0 {
  4487. 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 ?"
  4488. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  4489. } else {
  4490. 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 = ?"
  4491. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  4492. }
  4493. } else {
  4494. if len(keyword) > 0 {
  4495. 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 ?"
  4496. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  4497. } else {
  4498. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  4499. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4500. }
  4501. }
  4502. }
  4503. }
  4504. }
  4505. }
  4506. } else if adviceType == 1 {
  4507. if patientType == 0 {
  4508. if patient_id > 0 {
  4509. if execution_state > 0 {
  4510. if cost_type > 0 {
  4511. if len(execution_frequency) > 0 {
  4512. if len(keyword) > 0 {
  4513. 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 ?"
  4514. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4515. } else {
  4516. 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 = ?"
  4517. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4518. }
  4519. } else {
  4520. if len(keyword) > 0 {
  4521. 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 ?"
  4522. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  4523. } else {
  4524. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  4525. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4526. }
  4527. }
  4528. } else {
  4529. if len(execution_frequency) > 0 {
  4530. if len(keyword) > 0 {
  4531. 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 ?"
  4532. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  4533. } else {
  4534. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  4535. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4536. }
  4537. } else {
  4538. if len(keyword) > 0 {
  4539. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  4540. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  4541. } else {
  4542. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ?"
  4543. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4544. }
  4545. }
  4546. }
  4547. } else {
  4548. if cost_type > 0 {
  4549. if len(execution_frequency) > 0 {
  4550. if len(keyword) > 0 {
  4551. 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 ?"
  4552. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  4553. } else {
  4554. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  4555. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4556. }
  4557. } else {
  4558. if len(keyword) > 0 {
  4559. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? and advice_name like ? "
  4560. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  4561. } else {
  4562. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? "
  4563. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4564. }
  4565. }
  4566. } else {
  4567. if len(execution_frequency) > 0 {
  4568. if len(keyword) > 0 {
  4569. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and advice_name like ?"
  4570. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  4571. } else {
  4572. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
  4573. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4574. }
  4575. }
  4576. }
  4577. }
  4578. } else {
  4579. if execution_state > 0 {
  4580. if cost_type > 0 {
  4581. if len(execution_frequency) > 0 {
  4582. if len(keyword) > 0 {
  4583. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  4584. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  4585. } else {
  4586. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  4587. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4588. }
  4589. } else {
  4590. if len(keyword) > 0 {
  4591. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  4592. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  4593. } else {
  4594. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ?"
  4595. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4596. }
  4597. }
  4598. } else {
  4599. if len(execution_frequency) > 0 {
  4600. if len(keyword) > 0 {
  4601. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  4602. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  4603. } else {
  4604. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and execution_frequency = ?"
  4605. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4606. }
  4607. } else {
  4608. if len(keyword) > 0 {
  4609. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and advice_name like ?"
  4610. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  4611. } else {
  4612. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ?"
  4613. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4614. }
  4615. }
  4616. }
  4617. } else {
  4618. if cost_type > 0 {
  4619. if len(keyword) > 0 {
  4620. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = ? and advice_name like ?"
  4621. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  4622. } else {
  4623. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = ? "
  4624. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4625. }
  4626. } else {
  4627. if len(keyword) > 0 {
  4628. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and advice_name like ?"
  4629. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  4630. } else {
  4631. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  4632. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4633. }
  4634. }
  4635. }
  4636. }
  4637. } else if patientType == 1 {
  4638. if patient_id > 0 {
  4639. if execution_state > 0 {
  4640. if cost_type > 0 {
  4641. if len(execution_frequency) > 0 {
  4642. if len(keyword) > 0 {
  4643. 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 ?"
  4644. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4645. } else {
  4646. 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 = ?"
  4647. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  4648. }
  4649. } else {
  4650. if len(keyword) > 0 {
  4651. 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 ?"
  4652. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, keyword)
  4653. } else {
  4654. 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 = ?"
  4655. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  4656. }
  4657. }
  4658. } else {
  4659. if len(execution_frequency) > 0 {
  4660. if len(keyword) > 0 {
  4661. 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 ?"
  4662. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  4663. } else {
  4664. 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 = ?"
  4665. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  4666. }
  4667. } else {
  4668. if len(keyword) > 0 {
  4669. 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 ?"
  4670. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, keyword)
  4671. } else {
  4672. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  4673. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  4674. }
  4675. }
  4676. }
  4677. } else {
  4678. if cost_type > 0 {
  4679. if len(execution_frequency) > 0 {
  4680. if len(keyword) > 0 {
  4681. 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 ?"
  4682. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  4683. } else {
  4684. 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 = ?"
  4685. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  4686. }
  4687. } else {
  4688. if len(keyword) > 0 {
  4689. 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 ?"
  4690. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, keyword)
  4691. } else {
  4692. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  4693. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  4694. }
  4695. }
  4696. } else {
  4697. if len(execution_frequency) > 0 {
  4698. if len(keyword) > 0 {
  4699. 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 ?"
  4700. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency, keyword)
  4701. } else {
  4702. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  4703. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  4704. }
  4705. } else {
  4706. if len(keyword) > 0 {
  4707. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and advice_name like ?"
  4708. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, keyword)
  4709. } else {
  4710. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
  4711. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  4712. }
  4713. }
  4714. }
  4715. }
  4716. } else {
  4717. if execution_state > 0 {
  4718. if cost_type > 0 {
  4719. if len(execution_frequency) > 0 {
  4720. if len(keyword) > 0 {
  4721. 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 ?"
  4722. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  4723. } else {
  4724. 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 = ?"
  4725. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  4726. }
  4727. } else {
  4728. if len(keyword) > 0 {
  4729. 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 ?"
  4730. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, keyword)
  4731. } else {
  4732. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=? and is_settle = ?"
  4733. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  4734. }
  4735. }
  4736. } else {
  4737. if len(execution_frequency) > 0 {
  4738. if len(keyword) > 0 {
  4739. 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 ?"
  4740. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency, keyword)
  4741. } else {
  4742. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?and execution_frequency = ?"
  4743. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  4744. }
  4745. } else {
  4746. if len(keyword) > 0 {
  4747. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=? and advice_name like ?"
  4748. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, keyword)
  4749. } else {
  4750. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?"
  4751. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  4752. }
  4753. }
  4754. }
  4755. } else {
  4756. if cost_type > 0 {
  4757. if len(execution_frequency) > 0 {
  4758. if len(keyword) > 0 {
  4759. 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 ?"
  4760. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency, keyword)
  4761. } else {
  4762. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  4763. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  4764. }
  4765. } else {
  4766. if len(keyword) > 0 {
  4767. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? and advice_name like ?"
  4768. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, keyword)
  4769. } else {
  4770. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? "
  4771. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  4772. }
  4773. }
  4774. } else {
  4775. if len(execution_frequency) > 0 {
  4776. if len(keyword) > 0 {
  4777. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_frequency = ? and advice_name like ?"
  4778. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency, keyword)
  4779. } else {
  4780. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_frequency = ?"
  4781. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  4782. }
  4783. } else {
  4784. if len(keyword) > 0 {
  4785. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and advice_name like ?"
  4786. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, keyword)
  4787. } else {
  4788. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  4789. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  4790. }
  4791. }
  4792. }
  4793. }
  4794. }
  4795. } else if patientType == 2 {
  4796. if patient_id > 0 {
  4797. if execution_state > 0 {
  4798. if cost_type > 0 {
  4799. if len(execution_frequency) > 0 {
  4800. if len(keyword) > 0 {
  4801. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ?and execution_frequency = ? and advice_name like ?"
  4802. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4803. } else {
  4804. 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 = ?"
  4805. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4806. }
  4807. } else {
  4808. if len(keyword) > 0 {
  4809. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  4810. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  4811. } else {
  4812. 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 = ?"
  4813. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4814. }
  4815. }
  4816. } else {
  4817. if len(execution_frequency) > 0 {
  4818. if len(keyword) > 0 {
  4819. 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 ?"
  4820. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  4821. } else {
  4822. 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 = ?"
  4823. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4824. }
  4825. } else {
  4826. if len(keyword) > 0 {
  4827. 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 ?"
  4828. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  4829. } else {
  4830. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  4831. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4832. }
  4833. }
  4834. }
  4835. } else {
  4836. if cost_type > 0 {
  4837. if len(execution_frequency) > 0 {
  4838. if len(keyword) > 0 {
  4839. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  4840. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  4841. } else {
  4842. 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 = ?"
  4843. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4844. }
  4845. } else {
  4846. if len(keyword) > 0 {
  4847. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and is_settle = ? and advice_name like ?"
  4848. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  4849. } else {
  4850. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  4851. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4852. }
  4853. }
  4854. } else {
  4855. if len(execution_frequency) > 0 {
  4856. if len(keyword) > 0 {
  4857. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_frequency = ? and advice_name like ?"
  4858. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  4859. } else {
  4860. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_frequency = ?"
  4861. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4862. }
  4863. } else {
  4864. if len(keyword) > 0 {
  4865. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and advice_name like ?"
  4866. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  4867. } else {
  4868. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
  4869. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4870. }
  4871. }
  4872. }
  4873. }
  4874. } else {
  4875. if execution_state > 0 {
  4876. if cost_type > 0 {
  4877. if len(execution_frequency) > 0 {
  4878. if len(keyword) > 0 {
  4879. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  4880. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  4881. } else {
  4882. 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 = ?"
  4883. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4884. }
  4885. } else {
  4886. if len(keyword) > 0 {
  4887. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and is_settle = ? and advice_name like ?"
  4888. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  4889. } else {
  4890. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  4891. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4892. }
  4893. }
  4894. } else {
  4895. if len(execution_frequency) > 0 {
  4896. if len(keyword) > 0 {
  4897. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and execution_frequency = ? and advice_name like ?"
  4898. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  4899. } else {
  4900. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and execution_frequency = ?"
  4901. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4902. }
  4903. } else {
  4904. if len(keyword) > 0 {
  4905. 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 ?"
  4906. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  4907. } else {
  4908. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ?"
  4909. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4910. }
  4911. }
  4912. }
  4913. } else {
  4914. if cost_type > 0 {
  4915. if len(execution_frequency) > 0 {
  4916. if len(keyword) > 0 {
  4917. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ? and execution_frequency = ? and advice_name like ?"
  4918. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  4919. } else {
  4920. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  4921. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  4922. }
  4923. } else {
  4924. if len(keyword) > 0 {
  4925. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ? and advice_name like ?"
  4926. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  4927. } else {
  4928. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ?"
  4929. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4930. }
  4931. }
  4932. } else {
  4933. if len(execution_frequency) > 0 {
  4934. if len(keyword) > 0 {
  4935. 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 ?"
  4936. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  4937. } else {
  4938. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_frequency = ?"
  4939. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  4940. }
  4941. } else {
  4942. if len(keyword) > 0 {
  4943. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and advice_name like ?"
  4944. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  4945. } else {
  4946. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  4947. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4948. }
  4949. }
  4950. }
  4951. }
  4952. }
  4953. }
  4954. } else if adviceType == 3 {
  4955. if patientType == 0 {
  4956. if patient_id > 0 {
  4957. if execution_state > 0 {
  4958. if cost_type > 0 {
  4959. if len(execution_frequency) > 0 {
  4960. if len(keyword) > 0 {
  4961. 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 ?"
  4962. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4963. } else {
  4964. 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 =?"
  4965. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4966. }
  4967. } else {
  4968. if len(keyword) > 0 {
  4969. 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 ?"
  4970. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  4971. } else {
  4972. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  4973. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4974. }
  4975. }
  4976. } else {
  4977. if len(execution_frequency) > 0 {
  4978. if len(keyword) > 0 {
  4979. 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 ?"
  4980. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  4981. } else {
  4982. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency =?"
  4983. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4984. }
  4985. } else {
  4986. if len(keyword) > 0 {
  4987. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  4988. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  4989. } else {
  4990. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ?"
  4991. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4992. }
  4993. }
  4994. }
  4995. } else {
  4996. if cost_type > 0 {
  4997. if len(execution_frequency) > 0 {
  4998. if len(keyword) > 0 {
  4999. 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 ?"
  5000. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  5001. } else {
  5002. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency =?"
  5003. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  5004. }
  5005. } else {
  5006. if len(keyword) > 0 {
  5007. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  5008. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  5009. } else {
  5010. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? "
  5011. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5012. }
  5013. }
  5014. } else {
  5015. if len(execution_frequency) > 0 {
  5016. if len(keyword) > 0 {
  5017. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_frequency =? and advice_name like ?"
  5018. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  5019. } else {
  5020. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_frequency =?"
  5021. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  5022. }
  5023. } else {
  5024. if len(keyword) > 0 {
  5025. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and advice_name like ?"
  5026. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  5027. } else {
  5028. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? "
  5029. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5030. }
  5031. }
  5032. }
  5033. }
  5034. } else {
  5035. if execution_state > 0 {
  5036. if cost_type > 0 {
  5037. if len(execution_frequency) > 0 {
  5038. if len(keyword) > 0 {
  5039. 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 ?"
  5040. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  5041. } else {
  5042. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ? and execution_frequency =?"
  5043. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  5044. }
  5045. } else {
  5046. if len(keyword) > 0 {
  5047. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ? and advice_name like ?"
  5048. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  5049. } else {
  5050. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ?"
  5051. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5052. }
  5053. }
  5054. } else {
  5055. if len(execution_frequency) > 0 {
  5056. if len(keyword) > 0 {
  5057. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and execution_frequency =? and advice_name like ?"
  5058. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  5059. } else {
  5060. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and execution_frequency =?"
  5061. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  5062. }
  5063. } else {
  5064. if len(keyword) > 0 {
  5065. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and advice_name like ?"
  5066. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  5067. } else {
  5068. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? "
  5069. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5070. }
  5071. }
  5072. }
  5073. } else {
  5074. if cost_type > 0 {
  5075. if len(execution_frequency) > 0 {
  5076. if len(keyword) > 0 {
  5077. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? and execution_frequency =? and advice_name like ?"
  5078. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  5079. } else {
  5080. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? and execution_frequency =?"
  5081. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  5082. }
  5083. } else {
  5084. if len(keyword) > 0 {
  5085. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? and advice_name like ?"
  5086. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  5087. } else {
  5088. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? "
  5089. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5090. }
  5091. }
  5092. } else {
  5093. if len(execution_frequency) > 0 {
  5094. if len(keyword) > 0 {
  5095. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_frequency =? and advice_name like ?"
  5096. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  5097. } else {
  5098. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_frequency =?"
  5099. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  5100. }
  5101. } else {
  5102. if len(keyword) > 0 {
  5103. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and advice_name like ?"
  5104. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  5105. } else {
  5106. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  5107. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5108. }
  5109. }
  5110. }
  5111. }
  5112. }
  5113. } else if patientType == 1 {
  5114. if patient_id > 0 {
  5115. if execution_state > 0 {
  5116. if cost_type > 0 {
  5117. if len(execution_frequency) > 0 {
  5118. if len(keyword) > 0 {
  5119. 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 ?"
  5120. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5121. } else {
  5122. 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 = ?"
  5123. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  5124. }
  5125. } else {
  5126. if len(keyword) > 0 {
  5127. 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 ?"
  5128. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, keyword)
  5129. } else {
  5130. 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 = ?"
  5131. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  5132. }
  5133. }
  5134. } else {
  5135. if len(execution_frequency) > 0 {
  5136. if len(keyword) > 0 {
  5137. 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 ?"
  5138. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  5139. } else {
  5140. 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 = ?"
  5141. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  5142. }
  5143. } else {
  5144. if len(keyword) > 0 {
  5145. 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 ?"
  5146. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, keyword)
  5147. } else {
  5148. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  5149. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  5150. }
  5151. }
  5152. }
  5153. } else {
  5154. if cost_type > 0 {
  5155. if len(execution_frequency) > 0 {
  5156. if len(keyword) > 0 {
  5157. 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 ?"
  5158. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  5159. } else {
  5160. 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 = ?"
  5161. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  5162. }
  5163. } else {
  5164. if len(keyword) > 0 {
  5165. 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 ?"
  5166. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, keyword)
  5167. } else {
  5168. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  5169. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  5170. }
  5171. }
  5172. } else {
  5173. if len(execution_frequency) > 0 {
  5174. if len(keyword) > 0 {
  5175. 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 ?"
  5176. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency, keyword)
  5177. } else {
  5178. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  5179. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  5180. }
  5181. } else {
  5182. if len(keyword) > 0 {
  5183. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and advice_name like ?"
  5184. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, keyword)
  5185. } else {
  5186. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
  5187. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  5188. }
  5189. }
  5190. }
  5191. }
  5192. } else {
  5193. if execution_state > 0 {
  5194. if cost_type > 0 {
  5195. if len(execution_frequency) > 0 {
  5196. if len(keyword) > 0 {
  5197. 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 ?"
  5198. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  5199. } else {
  5200. 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 = ?"
  5201. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  5202. }
  5203. } else {
  5204. if len(keyword) > 0 {
  5205. 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 ?"
  5206. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, keyword)
  5207. } else {
  5208. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? and is_settle = ?"
  5209. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  5210. }
  5211. }
  5212. } else {
  5213. if len(execution_frequency) > 0 {
  5214. if len(keyword) > 0 {
  5215. 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 ? "
  5216. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency, keyword)
  5217. } else {
  5218. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =?and execution_frequency = ? "
  5219. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  5220. }
  5221. } else {
  5222. if len(keyword) > 0 {
  5223. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? and advice_name like ?"
  5224. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, keyword)
  5225. } else {
  5226. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? "
  5227. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  5228. }
  5229. }
  5230. }
  5231. } else {
  5232. if cost_type > 0 {
  5233. if len(execution_frequency) > 0 {
  5234. if len(keyword) > 0 {
  5235. 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 ?"
  5236. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency, keyword)
  5237. } else {
  5238. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  5239. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  5240. }
  5241. } else {
  5242. if len(keyword) > 0 {
  5243. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ? and advice_name like ?"
  5244. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, keyword)
  5245. } else {
  5246. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ?"
  5247. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  5248. }
  5249. }
  5250. } else {
  5251. if len(execution_frequency) > 0 {
  5252. if len(keyword) > 0 {
  5253. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_frequency = ? and advice_name like ?"
  5254. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency, keyword)
  5255. } else {
  5256. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_frequency = ?"
  5257. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  5258. }
  5259. } else {
  5260. if len(keyword) > 0 {
  5261. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and advice_name like ?"
  5262. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, keyword)
  5263. } else {
  5264. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  5265. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  5266. }
  5267. }
  5268. }
  5269. }
  5270. }
  5271. } else if patientType == 2 {
  5272. if patient_id > 0 {
  5273. if execution_state > 0 {
  5274. if cost_type > 0 {
  5275. if len(execution_frequency) > 0 {
  5276. if len(keyword) > 0 {
  5277. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5278. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5279. } else {
  5280. 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 = ?"
  5281. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  5282. }
  5283. } else {
  5284. if len(keyword) > 0 {
  5285. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5286. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  5287. } else {
  5288. 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 = ?"
  5289. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5290. }
  5291. }
  5292. } else {
  5293. if len(execution_frequency) > 0 {
  5294. if len(keyword) > 0 {
  5295. 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 ?"
  5296. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  5297. } else {
  5298. 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 = ?"
  5299. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  5300. }
  5301. } else {
  5302. if len(keyword) > 0 {
  5303. 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 ?"
  5304. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  5305. } else {
  5306. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  5307. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5308. }
  5309. }
  5310. }
  5311. } else {
  5312. if cost_type > 0 {
  5313. if len(execution_frequency) > 0 {
  5314. if len(keyword) > 0 {
  5315. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5316. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  5317. } else {
  5318. 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 = ?"
  5319. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  5320. }
  5321. } else {
  5322. if len(keyword) > 0 {
  5323. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and is_settle = ? and advice_name like ?"
  5324. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  5325. } else {
  5326. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  5327. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5328. }
  5329. }
  5330. } else {
  5331. if len(execution_frequency) > 0 {
  5332. if len(keyword) > 0 {
  5333. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_frequency = ? and advice_name like ?"
  5334. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  5335. } else {
  5336. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_frequency = ?"
  5337. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  5338. }
  5339. } else {
  5340. if len(keyword) > 0 {
  5341. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and advice_name like ?"
  5342. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  5343. } else {
  5344. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ?"
  5345. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5346. }
  5347. }
  5348. }
  5349. }
  5350. } else {
  5351. if execution_state > 0 {
  5352. if cost_type > 0 {
  5353. if len(execution_frequency) > 0 {
  5354. if len(keyword) > 0 {
  5355. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5356. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  5357. } else {
  5358. 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 = ?"
  5359. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  5360. }
  5361. } else {
  5362. if len(keyword) > 0 {
  5363. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and is_settle = ? and advice_name like ?"
  5364. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  5365. } else {
  5366. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and is_settle = ?"
  5367. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5368. }
  5369. }
  5370. } else {
  5371. if len(execution_frequency) > 0 {
  5372. if len(keyword) > 0 {
  5373. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and execution_frequency = ? and advice_name like ?"
  5374. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  5375. } else {
  5376. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and execution_frequency = ?"
  5377. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  5378. }
  5379. } else {
  5380. if len(keyword) > 0 {
  5381. 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 ?"
  5382. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  5383. } else {
  5384. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ?"
  5385. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5386. }
  5387. }
  5388. }
  5389. } else {
  5390. if cost_type > 0 {
  5391. if len(execution_frequency) > 0 {
  5392. if len(keyword) > 0 {
  5393. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5394. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  5395. } else {
  5396. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  5397. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  5398. }
  5399. } else {
  5400. if len(keyword) > 0 {
  5401. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ? and advice_name like ?"
  5402. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  5403. } else {
  5404. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ?"
  5405. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5406. }
  5407. }
  5408. } else {
  5409. if len(execution_frequency) > 0 {
  5410. if len(keyword) > 0 {
  5411. 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 ?"
  5412. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  5413. } else {
  5414. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_frequency = ?"
  5415. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  5416. }
  5417. } else {
  5418. if len(keyword) > 0 {
  5419. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and advice_name like ?"
  5420. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  5421. } else {
  5422. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  5423. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5424. }
  5425. }
  5426. }
  5427. }
  5428. }
  5429. }
  5430. } else if adviceType == 2 && len(deliverWay) > 0 {
  5431. if patientType == 0 {
  5432. if patient_id > 0 {
  5433. if execution_state > 0 {
  5434. if cost_type > 0 {
  5435. if len(execution_frequency) > 0 {
  5436. if len(keyword) > 0 {
  5437. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5438. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5439. } else {
  5440. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5441. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency)
  5442. }
  5443. } else {
  5444. if len(keyword) > 0 {
  5445. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5446. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, keyword)
  5447. } else {
  5448. 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 = ?"
  5449. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  5450. }
  5451. }
  5452. } else {
  5453. if len(execution_frequency) > 0 {
  5454. if len(keyword) > 0 {
  5455. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5456. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency, keyword)
  5457. } else {
  5458. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  5459. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency)
  5460. }
  5461. } else {
  5462. if len(keyword) > 0 {
  5463. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  5464. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, keyword)
  5465. } else {
  5466. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  5467. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  5468. }
  5469. }
  5470. }
  5471. } else {
  5472. if cost_type > 0 {
  5473. if len(execution_frequency) > 0 {
  5474. if len(keyword) > 0 {
  5475. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5476. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency, keyword)
  5477. } else {
  5478. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  5479. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency)
  5480. }
  5481. } else {
  5482. if len(keyword) > 0 {
  5483. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  5484. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, keyword)
  5485. } else {
  5486. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and is_settle = ?"
  5487. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  5488. }
  5489. }
  5490. } else {
  5491. if len(execution_frequency) > 0 {
  5492. if len(keyword) > 0 {
  5493. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  5494. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency, keyword)
  5495. } else {
  5496. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_frequency = ?"
  5497. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency)
  5498. }
  5499. } else {
  5500. if len(keyword) > 0 {
  5501. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and advice_name like ?"
  5502. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, keyword)
  5503. } else {
  5504. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ?"
  5505. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  5506. }
  5507. }
  5508. }
  5509. }
  5510. } else {
  5511. if execution_state > 0 {
  5512. if cost_type > 0 {
  5513. if len(execution_frequency) > 0 {
  5514. if len(keyword) > 0 {
  5515. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5516. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency, keyword)
  5517. } else {
  5518. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5519. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency)
  5520. }
  5521. } else {
  5522. if len(keyword) > 0 {
  5523. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5524. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, keyword)
  5525. } else {
  5526. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and is_settle = ?"
  5527. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  5528. }
  5529. }
  5530. } else {
  5531. if len(execution_frequency) > 0 {
  5532. if len(keyword) > 0 {
  5533. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5534. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency, keyword)
  5535. } else {
  5536. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and execution_frequency = ?"
  5537. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency)
  5538. }
  5539. } else {
  5540. if len(keyword) > 0 {
  5541. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and advice_name like ?"
  5542. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, keyword)
  5543. } else {
  5544. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ?"
  5545. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  5546. }
  5547. }
  5548. }
  5549. } else {
  5550. if cost_type > 0 {
  5551. if len(execution_frequency) > 0 {
  5552. if len(keyword) > 0 {
  5553. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5554. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, execution_frequency, keyword)
  5555. } else {
  5556. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and is_settle = ? and execution_frequency = ?"
  5557. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, execution_frequency)
  5558. }
  5559. } else {
  5560. if len(keyword) > 0 {
  5561. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and is_settle = ? and advice_name like ?"
  5562. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, keyword)
  5563. } else {
  5564. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and is_settle = ?"
  5565. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  5566. }
  5567. }
  5568. } else {
  5569. if len(execution_frequency) > 0 {
  5570. if len(keyword) > 0 {
  5571. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_frequency = ? and advice_name like ?"
  5572. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_frequency, keyword)
  5573. } else {
  5574. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_frequency = ?"
  5575. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_frequency)
  5576. }
  5577. } else {
  5578. if len(keyword) > 0 {
  5579. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and advice_name like ?"
  5580. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, keyword)
  5581. } else {
  5582. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  5583. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  5584. }
  5585. }
  5586. }
  5587. }
  5588. }
  5589. } else if patientType == 1 {
  5590. if patient_id > 0 {
  5591. if execution_state > 0 {
  5592. if cost_type > 0 {
  5593. if len(execution_frequency) > 0 {
  5594. if len(keyword) > 0 {
  5595. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5596. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5597. } else {
  5598. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5599. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type, execution_frequency)
  5600. }
  5601. } else {
  5602. if len(keyword) > 0 {
  5603. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5604. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type, keyword)
  5605. } else {
  5606. 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 = ?"
  5607. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type)
  5608. }
  5609. }
  5610. } else {
  5611. if len(execution_frequency) > 0 {
  5612. if len(keyword) > 0 {
  5613. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5614. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, execution_frequency, keyword)
  5615. } else {
  5616. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  5617. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, execution_frequency)
  5618. }
  5619. } else {
  5620. if len(keyword) > 0 {
  5621. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  5622. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, keyword)
  5623. } else {
  5624. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  5625. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state)
  5626. }
  5627. }
  5628. }
  5629. } else {
  5630. if cost_type > 0 {
  5631. if len(execution_frequency) > 0 {
  5632. if len(keyword) > 0 {
  5633. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5634. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type, execution_frequency, keyword)
  5635. } else {
  5636. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  5637. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type, execution_frequency)
  5638. }
  5639. } else {
  5640. if len(keyword) > 0 {
  5641. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  5642. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type, keyword)
  5643. } else {
  5644. 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 = ?"
  5645. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type)
  5646. }
  5647. }
  5648. } else {
  5649. if len(execution_frequency) > 0 {
  5650. if len(keyword) > 0 {
  5651. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  5652. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_frequency, keyword)
  5653. } else {
  5654. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_frequency = ?"
  5655. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_frequency)
  5656. }
  5657. } else {
  5658. if len(keyword) > 0 {
  5659. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and avice_name like ?"
  5660. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, keyword)
  5661. } else {
  5662. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ?"
  5663. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
  5664. }
  5665. }
  5666. }
  5667. }
  5668. } else {
  5669. if execution_state > 0 {
  5670. if cost_type > 0 {
  5671. if len(execution_frequency) > 0 {
  5672. if len(keyword) > 0 {
  5673. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5674. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type, execution_frequency, keyword)
  5675. } else {
  5676. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5677. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type, execution_frequency)
  5678. }
  5679. } else {
  5680. if len(keyword) > 0 {
  5681. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5682. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type, keyword)
  5683. } else {
  5684. 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 = ?"
  5685. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type)
  5686. }
  5687. }
  5688. } else {
  5689. if len(execution_frequency) > 0 {
  5690. if len(keyword) > 0 {
  5691. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5692. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, execution_frequency, keyword)
  5693. } else {
  5694. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ? and execution_frequency = ?"
  5695. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, execution_frequency)
  5696. }
  5697. } else {
  5698. if len(keyword) > 0 {
  5699. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ? and advice_name like ?"
  5700. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, keyword)
  5701. } else {
  5702. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ?"
  5703. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state)
  5704. }
  5705. }
  5706. }
  5707. } else {
  5708. if cost_type > 0 {
  5709. if len(execution_frequency) > 0 {
  5710. if len(keyword) > 0 {
  5711. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5712. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type, execution_frequency, keyword)
  5713. } else {
  5714. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and is_settle = ? and execution_frequency = ?"
  5715. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type, execution_frequency)
  5716. }
  5717. } else {
  5718. if len(keyword) > 0 {
  5719. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and is_settle = ? and advice_name like ?"
  5720. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type, keyword)
  5721. } else {
  5722. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and is_settle = ?"
  5723. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type)
  5724. }
  5725. }
  5726. } else {
  5727. if len(execution_frequency) > 0 {
  5728. if len(keyword) > 0 {
  5729. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_frequency = ? and advic_name like ?"
  5730. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_frequency, keyword)
  5731. } else {
  5732. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_frequency = ?"
  5733. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_frequency)
  5734. }
  5735. } else {
  5736. if len(keyword) > 0 {
  5737. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and advice_name like ?"
  5738. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, keyword)
  5739. } else {
  5740. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  5741. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  5742. }
  5743. }
  5744. }
  5745. }
  5746. }
  5747. } else if patientType == 2 {
  5748. if patient_id > 0 {
  5749. if execution_state > 0 {
  5750. if cost_type > 0 {
  5751. if len(execution_frequency) > 0 {
  5752. if len(keyword) > 0 {
  5753. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5754. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5755. } else {
  5756. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5757. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency)
  5758. }
  5759. } else {
  5760. if len(keyword) > 0 {
  5761. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5762. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, keyword)
  5763. } else {
  5764. 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 = ?"
  5765. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  5766. }
  5767. }
  5768. } else {
  5769. if len(execution_frequency) > 0 {
  5770. if len(keyword) > 0 {
  5771. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5772. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency, keyword)
  5773. } else {
  5774. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  5775. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency)
  5776. }
  5777. } else {
  5778. if len(keyword) > 0 {
  5779. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  5780. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, keyword)
  5781. } else {
  5782. 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 = ?"
  5783. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  5784. }
  5785. }
  5786. }
  5787. } else {
  5788. if cost_type > 0 {
  5789. if len(execution_frequency) > 0 {
  5790. if len(keyword) > 0 {
  5791. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5792. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency, keyword)
  5793. } else {
  5794. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  5795. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency)
  5796. }
  5797. } else {
  5798. if len(keyword) > 0 {
  5799. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  5800. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, keyword)
  5801. } else {
  5802. 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 = ?"
  5803. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  5804. }
  5805. }
  5806. } else {
  5807. if len(execution_frequency) > 0 {
  5808. if len(keyword) > 0 {
  5809. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  5810. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency, keyword)
  5811. } else {
  5812. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_frequency = ?"
  5813. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency)
  5814. }
  5815. } else {
  5816. if len(keyword) > 0 {
  5817. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and advice_name like ?"
  5818. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, keyword)
  5819. } else {
  5820. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ?"
  5821. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  5822. }
  5823. }
  5824. }
  5825. }
  5826. } else {
  5827. if execution_state > 0 {
  5828. if cost_type > 0 {
  5829. if len(execution_frequency) > 0 {
  5830. if len(keyword) > 0 {
  5831. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5832. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency, keyword)
  5833. } else {
  5834. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5835. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency)
  5836. }
  5837. } else {
  5838. if len(keyword) > 0 {
  5839. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5840. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, keyword)
  5841. } else {
  5842. 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 = ?"
  5843. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  5844. }
  5845. }
  5846. } else {
  5847. if len(execution_frequency) > 0 {
  5848. if len(keyword) > 0 {
  5849. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5850. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency, keyword)
  5851. } else {
  5852. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ? and execution_frequency = ?"
  5853. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency)
  5854. }
  5855. } else {
  5856. if len(keyword) > 0 {
  5857. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ? and advice_name like ?"
  5858. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, keyword)
  5859. } else {
  5860. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ?"
  5861. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  5862. }
  5863. }
  5864. }
  5865. } else {
  5866. if cost_type > 0 {
  5867. if len(execution_frequency) > 0 {
  5868. if len(keyword) > 0 {
  5869. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and is_settle = ? and advice_name like ?"
  5870. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, keyword)
  5871. } else {
  5872. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and is_settle = ?"
  5873. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  5874. }
  5875. } else {
  5876. if len(keyword) > 0 {
  5877. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and is_settle = ? and advice_name like ?"
  5878. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, keyword)
  5879. } else {
  5880. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and is_settle = ?"
  5881. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  5882. }
  5883. }
  5884. } else {
  5885. if len(keyword) > 0 {
  5886. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and advice_name like ?"
  5887. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, keyword)
  5888. } else {
  5889. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  5890. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  5891. }
  5892. }
  5893. }
  5894. }
  5895. }
  5896. } else if adviceType == 2 && len(deliverWay) <= 0 {
  5897. if patientType == 0 {
  5898. if patient_id > 0 {
  5899. if execution_state > 0 {
  5900. if cost_type > 0 {
  5901. if len(execution_frequency) > 0 {
  5902. if len(keyword) > 0 {
  5903. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5904. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5905. } else {
  5906. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5907. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  5908. }
  5909. } else {
  5910. if len(keyword) > 0 {
  5911. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5912. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  5913. } else {
  5914. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  5915. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5916. }
  5917. }
  5918. } else {
  5919. if len(execution_frequency) > 0 {
  5920. if len(keyword) > 0 {
  5921. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5922. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  5923. } else {
  5924. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  5925. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  5926. }
  5927. } else {
  5928. if len(keyword) > 0 {
  5929. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  5930. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  5931. } else {
  5932. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ?"
  5933. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5934. }
  5935. }
  5936. }
  5937. } else {
  5938. if cost_type > 0 {
  5939. if len(execution_frequency) > 0 {
  5940. if len(keyword) > 0 {
  5941. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5942. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  5943. } else {
  5944. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  5945. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  5946. }
  5947. } else {
  5948. if len(keyword) > 0 {
  5949. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  5950. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  5951. } else {
  5952. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and is_settle = ?"
  5953. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5954. }
  5955. }
  5956. } else {
  5957. if len(execution_frequency) > 0 {
  5958. if len(keyword) > 0 {
  5959. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  5960. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  5961. } else {
  5962. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_frequency = ?"
  5963. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  5964. }
  5965. } else {
  5966. if len(keyword) > 0 {
  5967. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and advice_name like ?"
  5968. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  5969. } else {
  5970. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ?"
  5971. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5972. }
  5973. }
  5974. }
  5975. }
  5976. } else {
  5977. if execution_state > 0 {
  5978. if cost_type > 0 {
  5979. if len(execution_frequency) > 0 {
  5980. if len(keyword) > 0 {
  5981. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5982. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  5983. } else {
  5984. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5985. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  5986. }
  5987. } else {
  5988. if len(keyword) > 0 {
  5989. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5990. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  5991. } else {
  5992. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ? and is_settle = ?"
  5993. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5994. }
  5995. }
  5996. } else {
  5997. if len(execution_frequency) > 0 {
  5998. if len(keyword) > 0 {
  5999. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?and execution_frequency = ? and advice_name like ?"
  6000. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  6001. } else {
  6002. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?and execution_frequency = ?"
  6003. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  6004. }
  6005. } else {
  6006. if len(keyword) > 0 {
  6007. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ? and advice_name like ?"
  6008. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  6009. } else {
  6010. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?"
  6011. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6012. }
  6013. }
  6014. }
  6015. } else {
  6016. if cost_type > 0 {
  6017. if len(execution_frequency) > 0 {
  6018. if len(keyword) > 0 {
  6019. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6020. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  6021. } else {
  6022. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and is_settle = ? and execution_frequency = ?"
  6023. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  6024. }
  6025. }
  6026. } else {
  6027. if len(execution_frequency) > 0 {
  6028. if len(keyword) > 0 {
  6029. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_frequency = ? and advice_name like ?"
  6030. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  6031. } else {
  6032. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_frequency = ?"
  6033. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  6034. }
  6035. } else {
  6036. if len(keyword) > 0 {
  6037. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and advice_name like ?"
  6038. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  6039. } else {
  6040. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  6041. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6042. }
  6043. }
  6044. }
  6045. }
  6046. }
  6047. } else if patientType == 1 {
  6048. if patient_id > 0 {
  6049. if execution_state > 0 {
  6050. if cost_type > 0 {
  6051. if len(execution_frequency) > 0 {
  6052. if len(keyword) > 0 {
  6053. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6054. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  6055. } else {
  6056. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  6057. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  6058. }
  6059. } else {
  6060. if len(keyword) > 0 {
  6061. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  6062. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, keyword)
  6063. } else {
  6064. 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 = ?"
  6065. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  6066. }
  6067. }
  6068. } else {
  6069. if len(execution_frequency) > 0 {
  6070. if len(keyword) > 0 {
  6071. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  6072. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  6073. } else {
  6074. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  6075. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  6076. }
  6077. } else {
  6078. if len(keyword) > 0 {
  6079. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  6080. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, keyword)
  6081. } else {
  6082. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  6083. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  6084. }
  6085. }
  6086. }
  6087. } else {
  6088. if cost_type > 0 {
  6089. if len(execution_frequency) > 0 {
  6090. if len(keyword) > 0 {
  6091. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6092. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  6093. } else {
  6094. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  6095. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  6096. }
  6097. } else {
  6098. if len(keyword) > 0 {
  6099. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  6100. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, keyword)
  6101. } else {
  6102. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  6103. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  6104. }
  6105. }
  6106. } else {
  6107. if len(execution_frequency) > 0 {
  6108. if len(keyword) > 0 {
  6109. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  6110. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency, keyword)
  6111. } else {
  6112. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  6113. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  6114. }
  6115. } else {
  6116. if len(keyword) > 0 {
  6117. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and advice_name like ?"
  6118. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, keyword)
  6119. } else {
  6120. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ?"
  6121. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  6122. }
  6123. }
  6124. }
  6125. }
  6126. } else {
  6127. if execution_state > 0 {
  6128. if cost_type > 0 {
  6129. if len(execution_frequency) > 0 {
  6130. if len(keyword) > 0 {
  6131. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6132. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  6133. } else {
  6134. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  6135. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  6136. }
  6137. } else {
  6138. if len(keyword) > 0 {
  6139. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  6140. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, keyword)
  6141. } else {
  6142. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ? and is_settle = ?"
  6143. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  6144. }
  6145. }
  6146. } else {
  6147. if len(execution_frequency) > 0 {
  6148. if len(keyword) > 0 {
  6149. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  6150. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency, keyword)
  6151. } else {
  6152. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ? and execution_frequency = ?"
  6153. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  6154. }
  6155. } else {
  6156. if len(keyword) > 0 {
  6157. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ? and advice_name like ?"
  6158. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, keyword)
  6159. } else {
  6160. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ?"
  6161. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  6162. }
  6163. }
  6164. }
  6165. } else {
  6166. if cost_type > 0 {
  6167. if len(execution_frequency) > 0 {
  6168. if len(keyword) > 0 {
  6169. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6170. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency, keyword)
  6171. } else {
  6172. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  6173. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  6174. }
  6175. } else {
  6176. if len(keyword) > 0 {
  6177. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and is_settle = ? and advice_name like ?"
  6178. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, keyword)
  6179. } else {
  6180. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and is_settle = ?"
  6181. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  6182. }
  6183. }
  6184. } else {
  6185. if len(execution_frequency) > 0 {
  6186. if len(keyword) > 0 {
  6187. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_frequency = ? and advice_name like ?"
  6188. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency, keyword)
  6189. } else {
  6190. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_frequency = ?"
  6191. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  6192. }
  6193. } else {
  6194. if len(keyword) > 0 {
  6195. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and advice_name like ?"
  6196. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, keyword)
  6197. } else {
  6198. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?"
  6199. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  6200. }
  6201. }
  6202. }
  6203. }
  6204. }
  6205. } else if patientType == 2 {
  6206. if patient_id > 0 {
  6207. if execution_state > 0 {
  6208. if cost_type > 0 {
  6209. if len(execution_frequency) > 0 {
  6210. if len(keyword) > 0 {
  6211. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency=? and advice_name like ?"
  6212. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  6213. } else {
  6214. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency=?"
  6215. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  6216. }
  6217. } else {
  6218. if len(keyword) > 0 {
  6219. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  6220. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  6221. } else {
  6222. 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 = ?"
  6223. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6224. }
  6225. }
  6226. } else {
  6227. if len(execution_frequency) > 0 {
  6228. if len(keyword) > 0 {
  6229. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ? and execution_frequency=? and advice_name like ?"
  6230. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  6231. } else {
  6232. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ? and execution_frequency=?"
  6233. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  6234. }
  6235. } else {
  6236. if len(keyword) > 0 {
  6237. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ? and advice_name like ?"
  6238. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  6239. } else {
  6240. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  6241. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6242. }
  6243. }
  6244. }
  6245. } else {
  6246. if cost_type > 0 {
  6247. if len(execution_frequency) > 0 {
  6248. if len(keyword) > 0 {
  6249. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and is_settle = ? and execution_frequency=? and advice_name like ?"
  6250. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  6251. } else {
  6252. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and is_settle = ? and execution_frequency=?"
  6253. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  6254. }
  6255. } else {
  6256. if len(keyword) > 0 {
  6257. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and is_settle = ? and advice_name like ?"
  6258. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  6259. } else {
  6260. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  6261. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6262. }
  6263. }
  6264. } else {
  6265. if len(execution_frequency) > 0 {
  6266. if len(keyword) > 0 {
  6267. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_frequency=? and advice_name like ?"
  6268. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  6269. } else {
  6270. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_frequency=?"
  6271. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  6272. }
  6273. } else {
  6274. if len(keyword) > 0 {
  6275. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and advice_name like ?"
  6276. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  6277. } else {
  6278. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ?"
  6279. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6280. }
  6281. }
  6282. }
  6283. }
  6284. } else {
  6285. if execution_state > 0 {
  6286. if cost_type > 0 {
  6287. if len(execution_frequency) > 0 {
  6288. if len(keyword) > 0 {
  6289. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6290. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  6291. } else {
  6292. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ? and is_settle = ? and execution_frequency = ?"
  6293. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  6294. }
  6295. } else {
  6296. if len(keyword) > 0 {
  6297. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ? and is_settle = ? and advice_name like ?"
  6298. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  6299. } else {
  6300. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  6301. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6302. }
  6303. }
  6304. } else {
  6305. if len(execution_frequency) > 0 {
  6306. if len(keyword) > 0 {
  6307. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ? and execution_frequency = ? and advice_name like ?"
  6308. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  6309. } else {
  6310. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ? and execution_frequency = ? "
  6311. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  6312. }
  6313. } else {
  6314. if len(keyword) > 0 {
  6315. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ? and advice_name like ?"
  6316. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  6317. } else {
  6318. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ?"
  6319. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6320. }
  6321. }
  6322. }
  6323. } else {
  6324. if cost_type > 0 {
  6325. if len(execution_frequency) > 0 {
  6326. if len(keyword) > 0 {
  6327. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6328. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  6329. } else {
  6330. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  6331. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  6332. }
  6333. } else {
  6334. if len(keyword) > 0 {
  6335. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and is_settle = ? and advice_name like ?"
  6336. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  6337. } else {
  6338. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and is_settle = ?"
  6339. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6340. }
  6341. }
  6342. } else {
  6343. if len(execution_frequency) > 0 {
  6344. if len(keyword) > 0 {
  6345. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_frequency = ? and advice_name like ?"
  6346. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  6347. } else {
  6348. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_frequency = ?"
  6349. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  6350. }
  6351. } else {
  6352. if len(keyword) > 0 {
  6353. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and advice_name like ?"
  6354. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  6355. } else {
  6356. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  6357. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6358. }
  6359. }
  6360. }
  6361. }
  6362. }
  6363. }
  6364. }
  6365. db := readDb.Table("xt_schedule")
  6366. if scheduleType > 0 {
  6367. db = db.Where("schedule_type = ?", scheduleType)
  6368. }
  6369. if partitonType > 0 {
  6370. db = db.Where("partition_id = ?", partitonType)
  6371. }
  6372. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6373. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6374. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6375. }).
  6376. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6377. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6378. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6379. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6380. Preload("DoctorAdvices", adviceCondition...).
  6381. Where("status = 1 AND user_org_id = ?", orgID)
  6382. if scheduleDate != 0 {
  6383. db = db.Where("schedule_date = ?", scheduleDate)
  6384. }
  6385. err := db.Find(&vms).Error
  6386. return vms, err
  6387. }
  6388. 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) {
  6389. var vms []*MScheduleDoctorAdviceVM
  6390. adviceWhere := ""
  6391. adviceCondition := []interface{}{}
  6392. if adviceType == 0 {
  6393. if patientType == 0 {
  6394. if patient_id > 0 {
  6395. if execution_state > 0 {
  6396. if cost_type > 0 {
  6397. 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 = ?"
  6398. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6399. } else {
  6400. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  6401. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6402. }
  6403. } else {
  6404. if cost_type > 0 {
  6405. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and is_settle = ?"
  6406. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6407. } else {
  6408. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
  6409. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6410. }
  6411. }
  6412. } else {
  6413. if execution_state > 0 {
  6414. if cost_type > 0 {
  6415. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and is_settle = ?"
  6416. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6417. } else {
  6418. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ?"
  6419. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6420. }
  6421. } else {
  6422. if cost_type > 0 {
  6423. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ?"
  6424. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6425. } else {
  6426. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  6427. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6428. }
  6429. }
  6430. }
  6431. } else if patientType == 1 {
  6432. if patient_id > 0 {
  6433. if execution_state > 0 {
  6434. if cost_type > 0 {
  6435. 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 = ?"
  6436. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  6437. } else {
  6438. 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= ?"
  6439. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  6440. }
  6441. } else {
  6442. if cost_type > 0 {
  6443. 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=?"
  6444. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  6445. } else {
  6446. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
  6447. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  6448. }
  6449. }
  6450. } else {
  6451. if execution_state > 0 {
  6452. if cost_type > 0 {
  6453. 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=?"
  6454. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  6455. } else {
  6456. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  6457. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  6458. }
  6459. } else {
  6460. if cost_type > 0 {
  6461. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and is_settle=?"
  6462. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  6463. } else {
  6464. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  6465. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  6466. }
  6467. }
  6468. }
  6469. } else if patientType == 2 {
  6470. if patient_id > 0 {
  6471. if execution_state > 0 {
  6472. if cost_type > 0 {
  6473. 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=?"
  6474. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6475. } else {
  6476. 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 = ?"
  6477. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6478. }
  6479. } else {
  6480. if cost_type > 0 {
  6481. 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=?"
  6482. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6483. } else {
  6484. 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 = ?)"
  6485. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6486. }
  6487. }
  6488. } else {
  6489. if execution_state > 0 {
  6490. if cost_type > 0 {
  6491. 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=?"
  6492. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6493. } else {
  6494. 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 = ?"
  6495. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6496. }
  6497. } else {
  6498. if cost_type > 0 {
  6499. 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 = ?"
  6500. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6501. } else {
  6502. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  6503. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6504. }
  6505. }
  6506. }
  6507. }
  6508. } else if adviceType == 1 {
  6509. if patientType == 0 {
  6510. if patient_id > 0 {
  6511. if execution_state > 0 {
  6512. if cost_type > 0 {
  6513. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  6514. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6515. } else {
  6516. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ?"
  6517. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6518. }
  6519. } else {
  6520. if cost_type > 0 {
  6521. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? "
  6522. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6523. } else {
  6524. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
  6525. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6526. }
  6527. }
  6528. } else {
  6529. if execution_state > 0 {
  6530. if cost_type > 0 {
  6531. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ?"
  6532. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6533. } else {
  6534. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ?"
  6535. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6536. }
  6537. } else {
  6538. if cost_type > 0 {
  6539. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = ? "
  6540. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6541. } else {
  6542. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  6543. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6544. }
  6545. }
  6546. }
  6547. } else if patientType == 1 {
  6548. if patient_id > 0 {
  6549. if execution_state > 0 {
  6550. if cost_type > 0 {
  6551. 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 = ?"
  6552. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  6553. } else {
  6554. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  6555. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  6556. }
  6557. } else {
  6558. if cost_type > 0 {
  6559. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  6560. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  6561. } else {
  6562. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
  6563. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  6564. }
  6565. }
  6566. } else {
  6567. if execution_state > 0 {
  6568. if cost_type > 0 {
  6569. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=? and is_settle = ?"
  6570. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  6571. } else {
  6572. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?"
  6573. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  6574. }
  6575. } else {
  6576. if cost_type > 0 {
  6577. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? "
  6578. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  6579. } else {
  6580. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  6581. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  6582. }
  6583. }
  6584. }
  6585. } else if patientType == 2 {
  6586. if patient_id > 0 {
  6587. if execution_state > 0 {
  6588. if cost_type > 0 {
  6589. 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 = ?"
  6590. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6591. } else {
  6592. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  6593. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6594. }
  6595. } else {
  6596. if cost_type > 0 {
  6597. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  6598. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6599. } else {
  6600. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
  6601. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6602. }
  6603. }
  6604. } else {
  6605. if execution_state > 0 {
  6606. if cost_type > 0 {
  6607. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  6608. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6609. } else {
  6610. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ?"
  6611. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6612. }
  6613. } else {
  6614. if cost_type > 0 {
  6615. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ?"
  6616. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6617. } else {
  6618. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  6619. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6620. }
  6621. }
  6622. }
  6623. }
  6624. } else if adviceType == 3 {
  6625. if patientType == 0 {
  6626. if patient_id > 0 {
  6627. if execution_state > 0 {
  6628. if cost_type > 0 {
  6629. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  6630. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6631. } else {
  6632. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ?"
  6633. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6634. }
  6635. } else {
  6636. if cost_type > 0 {
  6637. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? "
  6638. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6639. } else {
  6640. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? "
  6641. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6642. }
  6643. }
  6644. } else {
  6645. if execution_state > 0 {
  6646. if cost_type > 0 {
  6647. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ?"
  6648. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6649. } else {
  6650. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? "
  6651. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6652. }
  6653. } else {
  6654. if cost_type > 0 {
  6655. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? "
  6656. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6657. } else {
  6658. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  6659. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6660. }
  6661. }
  6662. }
  6663. } else if patientType == 1 {
  6664. if patient_id > 0 {
  6665. if execution_state > 0 {
  6666. if cost_type > 0 {
  6667. 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 = ?"
  6668. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  6669. } else {
  6670. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  6671. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  6672. }
  6673. } else {
  6674. if cost_type > 0 {
  6675. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  6676. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  6677. } else {
  6678. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
  6679. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  6680. }
  6681. }
  6682. } else {
  6683. if execution_state > 0 {
  6684. if cost_type > 0 {
  6685. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? and is_settle = ?"
  6686. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  6687. } else {
  6688. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? "
  6689. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  6690. }
  6691. } else {
  6692. if cost_type > 0 {
  6693. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ?"
  6694. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  6695. } else {
  6696. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  6697. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  6698. }
  6699. }
  6700. }
  6701. } else if patientType == 2 {
  6702. if patient_id > 0 {
  6703. if execution_state > 0 {
  6704. if cost_type > 0 {
  6705. 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 = ?"
  6706. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6707. } else {
  6708. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  6709. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6710. }
  6711. } else {
  6712. if cost_type > 0 {
  6713. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  6714. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6715. } else {
  6716. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ?"
  6717. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6718. }
  6719. }
  6720. } else {
  6721. if execution_state > 0 {
  6722. if cost_type > 0 {
  6723. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and is_settle = ?"
  6724. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6725. } else {
  6726. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ?"
  6727. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6728. }
  6729. } else {
  6730. if cost_type > 0 {
  6731. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ?"
  6732. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6733. } else {
  6734. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  6735. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6736. }
  6737. }
  6738. }
  6739. }
  6740. } else if adviceType == 2 && len(deliverWay) > 0 {
  6741. if patientType == 0 {
  6742. if patient_id > 0 {
  6743. if execution_state > 0 {
  6744. if cost_type > 0 {
  6745. 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 = ?"
  6746. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  6747. } else {
  6748. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  6749. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  6750. }
  6751. } else {
  6752. if cost_type > 0 {
  6753. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and is_settle = ?"
  6754. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  6755. } else {
  6756. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ?"
  6757. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  6758. }
  6759. }
  6760. } else {
  6761. if execution_state > 0 {
  6762. if cost_type > 0 {
  6763. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and is_settle = ?"
  6764. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  6765. } else {
  6766. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ?"
  6767. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  6768. }
  6769. } else {
  6770. if cost_type > 0 {
  6771. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and is_settle = ?"
  6772. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  6773. } else {
  6774. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  6775. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  6776. }
  6777. }
  6778. }
  6779. } else if patientType == 1 {
  6780. if patient_id > 0 {
  6781. if execution_state > 0 {
  6782. if cost_type > 0 {
  6783. 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 = ?"
  6784. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type)
  6785. } else {
  6786. 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 = ?"
  6787. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state)
  6788. }
  6789. } else {
  6790. if cost_type > 0 {
  6791. 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 = ?"
  6792. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type)
  6793. } else {
  6794. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ?"
  6795. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
  6796. }
  6797. }
  6798. } else {
  6799. if execution_state > 0 {
  6800. if cost_type > 0 {
  6801. 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 = ?"
  6802. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type)
  6803. } else {
  6804. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ?"
  6805. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state)
  6806. }
  6807. } else {
  6808. if cost_type > 0 {
  6809. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and is_settle = ?"
  6810. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type)
  6811. } else {
  6812. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  6813. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  6814. }
  6815. }
  6816. }
  6817. } else if patientType == 2 {
  6818. if patient_id > 0 {
  6819. if execution_state > 0 {
  6820. if cost_type > 0 {
  6821. 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 = ?"
  6822. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  6823. } else {
  6824. 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 = ?"
  6825. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  6826. }
  6827. } else {
  6828. if cost_type > 0 {
  6829. 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 = ?"
  6830. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  6831. } else {
  6832. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ?"
  6833. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  6834. }
  6835. }
  6836. } else {
  6837. if execution_state > 0 {
  6838. if cost_type > 0 {
  6839. 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 = ?"
  6840. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  6841. } else {
  6842. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ?"
  6843. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  6844. }
  6845. } else {
  6846. if cost_type > 0 {
  6847. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and is_settle = ?"
  6848. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  6849. } else {
  6850. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  6851. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  6852. }
  6853. }
  6854. }
  6855. }
  6856. } else if adviceType == 2 && len(deliverWay) <= 0 {
  6857. if patientType == 0 {
  6858. if patient_id > 0 {
  6859. if execution_state > 0 {
  6860. if cost_type > 0 {
  6861. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  6862. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6863. } else {
  6864. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ?"
  6865. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6866. }
  6867. } else {
  6868. if cost_type > 0 {
  6869. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and is_settle = ?"
  6870. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6871. } else {
  6872. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ?"
  6873. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6874. }
  6875. }
  6876. } else {
  6877. if execution_state > 0 {
  6878. if cost_type > 0 {
  6879. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ? and is_settle = ?"
  6880. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6881. } else {
  6882. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?"
  6883. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6884. }
  6885. } else {
  6886. if cost_type > 0 {
  6887. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and is_settle = ?"
  6888. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6889. } else {
  6890. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  6891. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6892. }
  6893. }
  6894. }
  6895. } else if patientType == 1 {
  6896. if patient_id > 0 {
  6897. if execution_state > 0 {
  6898. if cost_type > 0 {
  6899. 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 = ?"
  6900. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  6901. } else {
  6902. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  6903. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  6904. }
  6905. } else {
  6906. if cost_type > 0 {
  6907. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  6908. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  6909. } else {
  6910. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ?"
  6911. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  6912. }
  6913. }
  6914. } else {
  6915. if execution_state > 0 {
  6916. if cost_type > 0 {
  6917. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ? and is_settle = ?"
  6918. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  6919. } else {
  6920. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ?"
  6921. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  6922. }
  6923. } else {
  6924. if cost_type > 0 {
  6925. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and is_settle = ?"
  6926. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  6927. } else {
  6928. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?"
  6929. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  6930. }
  6931. }
  6932. }
  6933. } else if patientType == 2 {
  6934. if patient_id > 0 {
  6935. if execution_state > 0 {
  6936. if cost_type > 0 {
  6937. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ?"
  6938. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6939. } else {
  6940. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  6941. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6942. }
  6943. } else {
  6944. if cost_type > 0 {
  6945. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  6946. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6947. } else {
  6948. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ?"
  6949. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6950. }
  6951. }
  6952. } else {
  6953. if execution_state > 0 {
  6954. if cost_type > 0 {
  6955. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  6956. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6957. } else {
  6958. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ?"
  6959. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6960. }
  6961. } else {
  6962. if cost_type > 0 {
  6963. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and is_settle = ?"
  6964. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6965. } else {
  6966. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  6967. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6968. }
  6969. }
  6970. }
  6971. }
  6972. }
  6973. db := readDb.Table("xt_schedule")
  6974. if scheduleType > 0 {
  6975. db = db.Where("schedule_type = ?", scheduleType)
  6976. }
  6977. if partitonType > 0 {
  6978. db = db.Where("partition_id = ?", partitonType)
  6979. }
  6980. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6981. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6982. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6983. }).
  6984. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6985. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6986. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6987. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6988. Preload("DoctorAdvices", adviceCondition...).
  6989. Where("status = 1 AND user_org_id = ?", orgID)
  6990. if scheduleDate != 0 {
  6991. db = db.Where("schedule_date = ?", scheduleDate)
  6992. }
  6993. err := db.Find(&vms).Error
  6994. return vms, err
  6995. }
  6996. func GetLastPatientOrder(id int64) (models.XtDialysisOrder, error) {
  6997. order := models.XtDialysisOrder{}
  6998. err := XTReadDB().Where("id = ? and status = 1", id).Find(&order).Error
  6999. return order, err
  7000. }
  7001. func UpdateMobilePatient(org_id int64, patient_id int64, schedule_remark string) error {
  7002. order := models.XtPatients{}
  7003. 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
  7004. 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
  7005. return err
  7006. }
  7007. func GetDialysisTotalCount(org_id int64, patient_id int64) (models.BloodDialysisOrderCount, error) {
  7008. order := models.BloodDialysisOrderCount{}
  7009. db := XTReadDB().Table("xt_dialysis_order as o")
  7010. 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
  7011. return order, err
  7012. }
  7013. func GetDialysisTotalCountOne(org_id int64, patient_id int64) (models.BloodDialysisOrderCount, error) {
  7014. order := models.BloodDialysisOrderCount{}
  7015. db := XTReadDB().Table("xt_dialysis_order as o")
  7016. err = db.Raw("select count(o.id) as count,o.patient_id from xt_dialysis_order as o left join xt_schedule as x on x.patient_id = o.patient_id where o.status =1 and o.user_org_id = ? and o.patient_id = ? and o.dialysis_date>=1672502400 and x.schedule_date = o.dialysis_date and x.status = 1 ", org_id, patient_id).Scan(&order).Error
  7017. return order, err
  7018. }
  7019. func UpdateDialysisOrder(patient_id int64, dialysis_date int64, user_org_id int64, dialysis_total int64) (models.DialysisOrder, error) {
  7020. order := models.DialysisOrder{}
  7021. 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
  7022. return order, err
  7023. }
  7024. func UpdateDeviceInformation(patientid int64, dialysis_date int64) error {
  7025. information := models.DeviceInformation{}
  7026. err := UserWriteDB().Model(&information).Where("patient_id = ? and date = ? and status = 1", patientid, dialysis_date).Update(map[string]interface{}{"status": 0}).Error
  7027. return err
  7028. }
  7029. func MobileGetDoubleCheckSix(orgID int64, patientID int64, recordDate int64) (models.DoubleCheck, error) {
  7030. var record models.DoubleCheck
  7031. err := readDb.Where("patient_id = ? and user_org_id = ? and status = 1 and check_date = ?", patientID, orgID, recordDate).First(&record).Error
  7032. return record, err
  7033. }
  7034. func GetFirstMonitor(patient_id int64, monit_date int64) (models.MonitoringRecord, error) {
  7035. record := models.MonitoringRecord{}
  7036. err := XTReadDB().Where("patient_id = ? and monitoring_date = ? and status=1", patient_id, monit_date).First(&record).Error
  7037. return record, err
  7038. }
  7039. func UpdateFirstMonitor(id int64, catheter_operation string) (models.MonitoringRecord, error) {
  7040. record := models.MonitoringRecord{}
  7041. err := XTWriteDB().Model(&record).Where("id = ? and status= 1", id).Updates(map[string]interface{}{"dispose": catheter_operation}).Error
  7042. return record, err
  7043. }
  7044. 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) {
  7045. var vms []*HisMScheduleDoctorAdviceVM
  7046. if len(deliverWay) > 0 {
  7047. db := readDb.Table("xt_schedule")
  7048. if scheduleType > 0 {
  7049. db = db.Where("schedule_type = ?", scheduleType)
  7050. }
  7051. if partitionType > 0 {
  7052. db = db.Where("partition_id = ?", partitionType)
  7053. }
  7054. if patient_id > 0 {
  7055. if execution_state > 0 {
  7056. if cost_type > 0 {
  7057. if len(execution_frequency) > 0 {
  7058. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7059. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7060. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7061. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7062. 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).
  7063. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7064. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7065. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7066. Where("status = 1 AND user_org_id = ?", orgID)
  7067. if scheduleDate != 0 {
  7068. db = db.Where("schedule_date = ?", scheduleDate)
  7069. }
  7070. err = db.Find(&vms).Error
  7071. } else {
  7072. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7073. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7074. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7075. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7076. 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).
  7077. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7078. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7079. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7080. Where("status = 1 AND user_org_id = ?", orgID)
  7081. if scheduleDate != 0 {
  7082. db = db.Where("schedule_date = ?", scheduleDate)
  7083. }
  7084. err = db.Find(&vms).Error
  7085. }
  7086. } else {
  7087. if len(execution_frequency) > 0 {
  7088. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7089. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7090. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7091. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7092. 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).
  7093. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7094. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7095. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7096. Where("status = 1 AND user_org_id = ?", orgID)
  7097. if scheduleDate != 0 {
  7098. db = db.Where("schedule_date = ?", scheduleDate)
  7099. }
  7100. err = db.Find(&vms).Error
  7101. } else {
  7102. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7103. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7104. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7105. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7106. 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).
  7107. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7108. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7109. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7110. Where("status = 1 AND user_org_id = ?", orgID)
  7111. if scheduleDate != 0 {
  7112. db = db.Where("schedule_date = ?", scheduleDate)
  7113. }
  7114. err = db.Find(&vms).Error
  7115. }
  7116. }
  7117. } else {
  7118. if cost_type > 0 {
  7119. if len(execution_frequency) > 0 {
  7120. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7121. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7122. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7123. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7124. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ? and is_settle = ? and execution_frequency =?", orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency).
  7125. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7126. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7127. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7128. Where("status = 1 AND user_org_id = ?", orgID)
  7129. if scheduleDate != 0 {
  7130. db = db.Where("schedule_date = ?", scheduleDate)
  7131. }
  7132. err = db.Find(&vms).Error
  7133. } else {
  7134. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7135. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7136. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7137. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7138. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ? and is_settle", orgID, scheduleDate, deliverWay, patient_id, cost_type).
  7139. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7140. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7141. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7142. Where("status = 1 AND user_org_id = ?", orgID)
  7143. if scheduleDate != 0 {
  7144. db = db.Where("schedule_date = ?", scheduleDate)
  7145. }
  7146. err = db.Find(&vms).Error
  7147. }
  7148. } else {
  7149. if len(execution_frequency) > 0 {
  7150. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7151. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7152. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7153. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7154. 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).
  7155. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7156. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7157. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7158. Where("status = 1 AND user_org_id = ?", orgID)
  7159. if scheduleDate != 0 {
  7160. db = db.Where("schedule_date = ?", scheduleDate)
  7161. }
  7162. err = db.Find(&vms).Error
  7163. } else {
  7164. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7165. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7166. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7167. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7168. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ?", orgID, scheduleDate, deliverWay, patient_id).
  7169. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7170. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7171. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7172. Where("status = 1 AND user_org_id = ?", orgID)
  7173. if scheduleDate != 0 {
  7174. db = db.Where("schedule_date = ?", scheduleDate)
  7175. }
  7176. err = db.Find(&vms).Error
  7177. }
  7178. }
  7179. }
  7180. } else {
  7181. if execution_state > 0 {
  7182. if cost_type > 0 {
  7183. if len(execution_frequency) > 0 {
  7184. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7185. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7186. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7187. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7188. 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).
  7189. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7190. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7191. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7192. Where("status = 1 AND user_org_id = ?", orgID)
  7193. if scheduleDate != 0 {
  7194. db = db.Where("schedule_date = ?", scheduleDate)
  7195. }
  7196. err = db.Find(&vms).Error
  7197. } else {
  7198. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7199. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7200. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7201. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7202. 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).
  7203. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7204. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7205. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7206. Where("status = 1 AND user_org_id = ?", orgID)
  7207. if scheduleDate != 0 {
  7208. db = db.Where("schedule_date = ?", scheduleDate)
  7209. }
  7210. err = db.Find(&vms).Error
  7211. }
  7212. } else {
  7213. if len(execution_frequency) > 0 {
  7214. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7215. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7216. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7217. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7218. 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).
  7219. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7220. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7221. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7222. Where("status = 1 AND user_org_id = ?", orgID)
  7223. if scheduleDate != 0 {
  7224. db = db.Where("schedule_date = ?", scheduleDate)
  7225. }
  7226. err = db.Find(&vms).Error
  7227. } else {
  7228. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7229. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7230. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7231. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7232. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_state = ?", orgID, scheduleDate, deliverWay, execution_state).
  7233. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7234. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7235. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7236. Where("status = 1 AND user_org_id = ?", orgID)
  7237. if scheduleDate != 0 {
  7238. db = db.Where("schedule_date = ?", scheduleDate)
  7239. }
  7240. err = db.Find(&vms).Error
  7241. }
  7242. }
  7243. } else {
  7244. if cost_type > 0 {
  7245. if len(execution_frequency) > 0 {
  7246. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7247. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7248. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7249. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7250. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and is_settle = ? and execution_frequency = ?", orgID, scheduleDate, deliverWay, cost_type, execution_frequency).
  7251. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7252. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7253. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7254. Where("status = 1 AND user_org_id = ?", orgID)
  7255. if scheduleDate != 0 {
  7256. db = db.Where("schedule_date = ?", scheduleDate)
  7257. }
  7258. err = db.Find(&vms).Error
  7259. } else {
  7260. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7261. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7262. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7263. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7264. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and is_settle = ?", orgID, scheduleDate, deliverWay, cost_type).
  7265. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7266. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7267. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7268. Where("status = 1 AND user_org_id = ?", orgID)
  7269. if scheduleDate != 0 {
  7270. db = db.Where("schedule_date = ?", scheduleDate)
  7271. }
  7272. err = db.Find(&vms).Error
  7273. }
  7274. } else {
  7275. if len(execution_frequency) > 0 {
  7276. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7277. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7278. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7279. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7280. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_frequency = ?", orgID, scheduleDate, deliverWay, execution_frequency).
  7281. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7282. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7283. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7284. Where("status = 1 AND user_org_id = ?", orgID)
  7285. if scheduleDate != 0 {
  7286. db = db.Where("schedule_date = ?", scheduleDate)
  7287. }
  7288. err = db.Find(&vms).Error
  7289. } else {
  7290. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7291. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7292. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7293. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7294. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  7295. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7296. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7297. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7298. Where("status = 1 AND user_org_id = ?", orgID)
  7299. if scheduleDate != 0 {
  7300. db = db.Where("schedule_date = ?", scheduleDate)
  7301. }
  7302. err = db.Find(&vms).Error
  7303. }
  7304. }
  7305. }
  7306. }
  7307. } else {
  7308. db := readDb.Table("xt_schedule")
  7309. if scheduleType > 0 {
  7310. db = db.Where("schedule_type = ?", scheduleType)
  7311. }
  7312. if partitionType > 0 {
  7313. db = db.Where("partition_id = ?", partitionType)
  7314. }
  7315. if patient_id > 0 {
  7316. if execution_state > 0 {
  7317. if cost_type > 0 {
  7318. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7319. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7320. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7321. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7322. 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).
  7323. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7324. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7325. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7326. Where("status = 1 AND user_org_id = ?", orgID)
  7327. if scheduleDate != 0 {
  7328. db = db.Where("schedule_date = ?", scheduleDate)
  7329. }
  7330. err = db.Find(&vms).Error
  7331. } else {
  7332. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7333. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7334. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7335. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7336. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and execution_state = ?", orgID, scheduleDate, patient_id, execution_state).
  7337. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7338. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7339. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7340. Where("status = 1 AND user_org_id = ?", orgID)
  7341. if scheduleDate != 0 {
  7342. db = db.Where("schedule_date = ?", scheduleDate)
  7343. }
  7344. err = db.Find(&vms).Error
  7345. }
  7346. } else {
  7347. if cost_type > 0 {
  7348. if len(execution_frequency) > 0 {
  7349. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  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 = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7353. 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).
  7354. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7355. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).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. } else {
  7363. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7364. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7365. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7366. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7367. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and is_settle = ?", orgID, scheduleDate, patient_id, cost_type).
  7368. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7369. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7370. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7371. Where("status = 1 AND user_org_id = ?", orgID)
  7372. if scheduleDate != 0 {
  7373. db = db.Where("schedule_date = ?", scheduleDate)
  7374. }
  7375. err = db.Find(&vms).Error
  7376. }
  7377. } else {
  7378. if len(execution_frequency) > 0 {
  7379. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  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 = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7383. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and execution_frequency = ?", orgID, scheduleDate, patient_id, execution_frequency).
  7384. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7385. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).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. } else {
  7393. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7394. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7395. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7396. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7397. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7398. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7399. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7400. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7401. Where("status = 1 AND user_org_id = ?", orgID)
  7402. if scheduleDate != 0 {
  7403. db = db.Where("schedule_date = ?", scheduleDate)
  7404. }
  7405. err = db.Find(&vms).Error
  7406. }
  7407. }
  7408. }
  7409. } else {
  7410. if execution_state > 0 {
  7411. if cost_type > 0 {
  7412. if len(execution_frequency) > 0 {
  7413. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7414. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7415. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7416. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7417. 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).
  7418. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7419. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7420. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7421. Where("status = 1 AND user_org_id = ?", orgID)
  7422. if scheduleDate != 0 {
  7423. db = db.Where("schedule_date = ?", scheduleDate)
  7424. }
  7425. err = db.Find(&vms).Error
  7426. } else {
  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 execution_state = ? and is_settle = ?", orgID, scheduleDate, execution_state, cost_type).
  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. }
  7441. } else {
  7442. if len(execution_frequency) > 0 {
  7443. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7444. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7445. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7446. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7447. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ? and execution_frequency = ?", orgID, scheduleDate, execution_state, execution_frequency).
  7448. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7449. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7450. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7451. Where("status = 1 AND user_org_id = ?", orgID)
  7452. if scheduleDate != 0 {
  7453. db = db.Where("schedule_date = ?", scheduleDate)
  7454. }
  7455. err = db.Find(&vms).Error
  7456. } else {
  7457. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7458. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7459. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7460. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7461. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ?", orgID, scheduleDate, execution_state).
  7462. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7463. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7464. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7465. Where("status = 1 AND user_org_id = ?", orgID)
  7466. if scheduleDate != 0 {
  7467. db = db.Where("schedule_date = ?", scheduleDate)
  7468. }
  7469. err = db.Find(&vms).Error
  7470. }
  7471. }
  7472. } else {
  7473. if cost_type > 0 {
  7474. if len(execution_frequency) > 0 {
  7475. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7476. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7477. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7478. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7479. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and is_settle = ?", orgID, scheduleDate, cost_type).
  7480. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7481. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7482. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7483. Where("status = 1 AND user_org_id = ?", orgID)
  7484. if scheduleDate != 0 {
  7485. db = db.Where("schedule_date = ?", scheduleDate)
  7486. }
  7487. err = db.Find(&vms).Error
  7488. } else {
  7489. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7490. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7491. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7492. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7493. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and is_settle = ? and execution_frequency = ?", orgID, scheduleDate, cost_type, execution_frequency).
  7494. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7495. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7496. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7497. Where("status = 1 AND user_org_id = ?", orgID)
  7498. if scheduleDate != 0 {
  7499. db = db.Where("schedule_date = ?", scheduleDate)
  7500. }
  7501. err = db.Find(&vms).Error
  7502. }
  7503. } else {
  7504. if len(execution_frequency) > 0 {
  7505. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7506. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7507. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7508. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7509. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_frequency = ?", orgID, scheduleDate, execution_frequency).
  7510. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7511. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7512. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7513. Where("status = 1 AND user_org_id = ?", orgID)
  7514. if scheduleDate != 0 {
  7515. db = db.Where("schedule_date = ?", scheduleDate)
  7516. }
  7517. err = db.Find(&vms).Error
  7518. } else {
  7519. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7520. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7521. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7522. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7523. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ?", orgID, scheduleDate).
  7524. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7525. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7526. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7527. Where("status = 1 AND user_org_id = ?", orgID)
  7528. if scheduleDate != 0 {
  7529. db = db.Where("schedule_date = ?", scheduleDate)
  7530. }
  7531. err = db.Find(&vms).Error
  7532. }
  7533. }
  7534. }
  7535. }
  7536. }
  7537. return vms, err
  7538. }
  7539. func GetPatientDryWeight(org_id int64, patient_id int64) (weight []*models.SgjPatientDryweight, err error) {
  7540. err = XTReadDB().Where("user_org_id = ? and patient_id = ? and status =1", org_id, patient_id).Order("id desc").Limit(6).Find(&weight).Error
  7541. return weight, err
  7542. }
  7543. func MobileGetLongScheduleDoctorAdvices(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string, scheduleType int64, partitonType int64, patient_id int64, execution_state int64, cost_type int64, execution_frequency string) ([]*MScheduleDoctorAdviceVM, error) {
  7544. var vms []*MScheduleDoctorAdviceVM
  7545. adviceWhere := ""
  7546. adviceCondition := []interface{}{}
  7547. if adviceType == 1 {
  7548. if patientType == 0 {
  7549. if patient_id > 0 {
  7550. if execution_state > 0 {
  7551. if cost_type > 0 {
  7552. if len(execution_frequency) > 0 {
  7553. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  7554. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency)
  7555. } else {
  7556. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ?"
  7557. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type)
  7558. }
  7559. } else {
  7560. if len(execution_frequency) > 0 {
  7561. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and execution_frequency = ?"
  7562. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency)
  7563. } else {
  7564. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ?"
  7565. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state)
  7566. }
  7567. }
  7568. } else {
  7569. if cost_type > 0 {
  7570. if len(execution_frequency) > 0 {
  7571. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and execution_frequency = ?"
  7572. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency)
  7573. } else {
  7574. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? "
  7575. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type)
  7576. }
  7577. } else {
  7578. if len(execution_frequency) > 0 {
  7579. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_frequency = ?"
  7580. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency)
  7581. } else {
  7582. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? "
  7583. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id)
  7584. }
  7585. }
  7586. }
  7587. } else {
  7588. if execution_state > 0 {
  7589. if cost_type > 0 {
  7590. if len(execution_frequency) > 0 {
  7591. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and execution_frequency = ?"
  7592. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency)
  7593. } else {
  7594. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ?"
  7595. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type)
  7596. }
  7597. } else {
  7598. if len(execution_frequency) > 0 {
  7599. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and execution_frequency = ?"
  7600. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency)
  7601. } else {
  7602. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ?"
  7603. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state)
  7604. }
  7605. }
  7606. } else {
  7607. if cost_type > 0 {
  7608. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and is_settle = ? "
  7609. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type)
  7610. } else {
  7611. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 "
  7612. adviceCondition = append(adviceCondition, adviceWhere, orgID)
  7613. }
  7614. }
  7615. }
  7616. } else if patientType == 1 {
  7617. if patient_id > 0 {
  7618. if execution_state > 0 {
  7619. if cost_type > 0 {
  7620. if len(execution_frequency) > 0 {
  7621. 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 = ?"
  7622. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  7623. } else {
  7624. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  7625. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type)
  7626. }
  7627. } else {
  7628. if len(execution_frequency) > 0 {
  7629. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  7630. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, execution_frequency)
  7631. } else {
  7632. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  7633. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state)
  7634. }
  7635. }
  7636. } else {
  7637. if cost_type > 0 {
  7638. if len(execution_frequency) > 0 {
  7639. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ?and execution_frequency = ?"
  7640. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, execution_frequency)
  7641. } else {
  7642. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  7643. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type)
  7644. }
  7645. } else {
  7646. if len(execution_frequency) > 0 {
  7647. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  7648. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_frequency)
  7649. } else {
  7650. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ?"
  7651. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id)
  7652. }
  7653. }
  7654. }
  7655. } else {
  7656. if execution_state > 0 {
  7657. if cost_type > 0 {
  7658. if len(execution_frequency) > 0 {
  7659. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ?and execution_frequency = ?"
  7660. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, execution_frequency)
  7661. } else {
  7662. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ?"
  7663. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type)
  7664. }
  7665. } else {
  7666. if len(execution_frequency) > 0 {
  7667. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=?and execution_frequency = ?"
  7668. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, execution_frequency)
  7669. } else {
  7670. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=?"
  7671. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state)
  7672. }
  7673. }
  7674. } else {
  7675. if cost_type > 0 {
  7676. if len(execution_frequency) > 0 {
  7677. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  7678. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, execution_frequency)
  7679. } else {
  7680. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? "
  7681. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type)
  7682. }
  7683. } else {
  7684. if len(execution_frequency) > 0 {
  7685. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_frequency = ?"
  7686. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_frequency)
  7687. } else {
  7688. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? "
  7689. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId)
  7690. }
  7691. }
  7692. }
  7693. }
  7694. } else if patientType == 2 {
  7695. if patient_id > 0 {
  7696. if execution_state > 0 {
  7697. if cost_type > 0 {
  7698. if len(execution_frequency) > 0 {
  7699. 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 = ?"
  7700. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency)
  7701. } else {
  7702. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ?"
  7703. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type)
  7704. }
  7705. } else {
  7706. if len(execution_frequency) > 0 {
  7707. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and execution_frequency = ?"
  7708. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency)
  7709. } else {
  7710. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  7711. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state)
  7712. }
  7713. }
  7714. } else {
  7715. if cost_type > 0 {
  7716. if len(execution_frequency) > 0 {
  7717. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and is_settle = ? and execution_frequency = ?"
  7718. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency)
  7719. } else {
  7720. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  7721. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type)
  7722. }
  7723. } else {
  7724. if len(execution_frequency) > 0 {
  7725. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_frequency = ?"
  7726. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency)
  7727. } else {
  7728. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ?"
  7729. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id)
  7730. }
  7731. }
  7732. }
  7733. } else {
  7734. if execution_state > 0 {
  7735. if cost_type > 0 {
  7736. if len(execution_frequency) > 0 {
  7737. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ? and execution_frequency = ?"
  7738. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency)
  7739. } else {
  7740. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  7741. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type)
  7742. }
  7743. } else {
  7744. if len(execution_frequency) > 0 {
  7745. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ? and execution_frequency = ?"
  7746. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency)
  7747. } else {
  7748. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ?"
  7749. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state)
  7750. }
  7751. }
  7752. } else {
  7753. if cost_type > 0 {
  7754. if len(execution_frequency) > 0 {
  7755. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  7756. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, execution_frequency)
  7757. } else {
  7758. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ?"
  7759. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type)
  7760. }
  7761. } else {
  7762. if len(execution_frequency) > 0 {
  7763. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_frequency = ?"
  7764. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_frequency)
  7765. } else {
  7766. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0"
  7767. adviceCondition = append(adviceCondition, adviceWhere, orgID)
  7768. }
  7769. }
  7770. }
  7771. }
  7772. }
  7773. }
  7774. db := readDb.Table("xt_schedule")
  7775. if scheduleType > 0 {
  7776. db = db.Where("schedule_type = ?", scheduleType)
  7777. }
  7778. if partitonType > 0 {
  7779. db = db.Where("partition_id = ?", partitonType)
  7780. }
  7781. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7782. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7783. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7784. }).
  7785. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7786. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7787. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7788. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7789. Preload("DoctorAdvices", adviceCondition...).
  7790. Where("status = 1 AND user_org_id = ?", orgID)
  7791. if scheduleDate != 0 {
  7792. db = db.Where("schedule_date = ?", scheduleDate)
  7793. }
  7794. err := db.Find(&vms).Error
  7795. return vms, err
  7796. }