mobile_dialysis_service.go 377KB

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