mobile_dialysis_service.go 393KB

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