mobile_dialysis_service.go 478KB

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