mobile_dialysis_service.go 376KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233
  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. 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
  3913. return err
  3914. }
  3915. func UPdateAutoStockGoods(good_id int64, record_time int64, patient_id int64, count int64) error {
  3916. detail := models.AutomaticReduceDetail{}
  3917. 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
  3918. return err
  3919. }
  3920. func MobileGetDialysisSolutionByModeIdSeven(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  3921. var record models.DialysisSolution
  3922. 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
  3923. if err != nil {
  3924. if err == gorm.ErrRecordNotFound {
  3925. return nil, nil
  3926. } else {
  3927. return nil, err
  3928. }
  3929. }
  3930. return &record, nil
  3931. }
  3932. func MobileGetLastDialysisPrescribeByModeIdSeven(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  3933. var record models.DialysisPrescription
  3934. 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
  3935. if err != nil {
  3936. if err == gorm.ErrRecordNotFound {
  3937. return nil, nil
  3938. } else {
  3939. return nil, err
  3940. }
  3941. }
  3942. return &record, nil
  3943. }
  3944. func MobileGetLastDialysisPrescription(patientID int64, orgID int64) (models.DialysisPrescriptionThrity, error) {
  3945. prescription := models.DialysisPrescriptionThrity{}
  3946. err := readDb.Model(&prescription).Where("patient_id = ? and user_org_id = ? and status = 1 and remark<>''", patientID, orgID).Last(&prescription).Error
  3947. return prescription, err
  3948. }
  3949. func MobileGetSystemDialysisPrescribeByModeIdSeven(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  3950. var record models.SystemPrescription
  3951. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).First(&record).Error
  3952. if err != nil {
  3953. if err == gorm.ErrRecordNotFound {
  3954. return nil, nil
  3955. } else {
  3956. return nil, err
  3957. }
  3958. }
  3959. return &record, nil
  3960. }
  3961. // 透前评估
  3962. func MobileGetPredialysisEvaluationSeven(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
  3963. var record models.PredialysisEvaluation
  3964. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  3965. if err != nil {
  3966. if err == gorm.ErrRecordNotFound {
  3967. return nil, nil
  3968. } else {
  3969. return nil, err
  3970. }
  3971. }
  3972. return &record, nil
  3973. }
  3974. //
  3975. //func MobileGetDialysisGoodsSix(orgID int64, scheduleDate int64) (prepare []*models.DialysisBeforePrepare, err error) {
  3976. //
  3977. // 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
  3978. // return prepare, err
  3979. //}
  3980. func GetMobileAutoReduce(orgID int64, scheduleDate int64) (auto []*models.AutomaticReduceDetail, err error) {
  3981. err = readDb.Where("org_id = ? and status = 1 and record_time = ?", orgID, scheduleDate).Find(&auto).Error
  3982. return auto, err
  3983. }
  3984. func GetRoleList(orgid int64, admin_user_id int64) (models.SgjUserAdminRole, error) {
  3985. role := models.SgjUserAdminRole{}
  3986. err = readUserDb.Where("org_id = ? and admin_user_id = ? and status =1 ", orgid, admin_user_id).Find(&role).Error
  3987. return role, err
  3988. }
  3989. func GetDialysisGood(orgID int64, scheduleDate int64) (auto []*models.AutomaticReduceDetail, err error) {
  3990. err = readDb.Where("org_id = ? and status = 1 and record_time >= ?", orgID, scheduleDate).Group("patient_id").Find(&auto).Error
  3991. return auto, err
  3992. }
  3993. func GetGoodWarehouseOutInfo(orgId int64, patient_id int64, sys_record_time int64) (outifno []*models.WarehouseOutInfoSeven, err error) {
  3994. err = readDb.Where("org_id = ? and patient_id = ? and sys_record_time = ? and status = 1", orgId, patient_id, sys_record_time).Find(&outifno).Error
  3995. return outifno, err
  3996. }
  3997. func GetLastDilysisOrder(orgid int64, patient_id int64, dialysis_date int64) (models.DialysisOrder, error) {
  3998. order := models.DialysisOrder{}
  3999. err = XTReadDB().Where("user_org_id = ? and patient_id = ? and dialysis_date < ? and status= 1", orgid, patient_id, dialysis_date).Last(&order).Error
  4000. return order, err
  4001. }
  4002. func GetFistMonitor(orgid int64, patient_id int64, dialysis_date int64) (models.MonitoringRecord, error) {
  4003. record := models.MonitoringRecord{}
  4004. err := XTReadDB().Where("org_id = ? and patient_id = ? and monitoring_date = ? and status = 1", orgid, patient_id, dialysis_date).Find(&record).Error
  4005. return record, err
  4006. }
  4007. 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) {
  4008. fmt.Println("execution_frequency---------------------------", execution_frequency)
  4009. fmt.Println("cost_type-----------", cost_type)
  4010. fmt.Println("adviceType-----------", adviceType)
  4011. fmt.Println("patientType---------", patientType)
  4012. fmt.Println("len(deliverWay)--------", len(deliverWay))
  4013. var vms []*MScheduleDoctorAdviceVM
  4014. adviceWhere := ""
  4015. adviceCondition := []interface{}{}
  4016. if adviceType == 0 {
  4017. if patientType == 0 {
  4018. if patient_id > 0 {
  4019. if execution_state > 0 {
  4020. if cost_type > 0 {
  4021. if len(execution_frequency) > 0 {
  4022. 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 = ?"
  4023. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4024. } else {
  4025. 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 = ?"
  4026. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4027. }
  4028. } else {
  4029. if len(execution_frequency) > 0 {
  4030. 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 = ?"
  4031. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4032. } else {
  4033. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  4034. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4035. }
  4036. }
  4037. } else {
  4038. if cost_type > 0 {
  4039. if len(execution_frequency) > 0 {
  4040. 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 = ?"
  4041. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4042. } else {
  4043. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and is_settle = ?"
  4044. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4045. }
  4046. } else {
  4047. if len(execution_frequency) > 0 {
  4048. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_frequency = ?"
  4049. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4050. } else {
  4051. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
  4052. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4053. }
  4054. }
  4055. }
  4056. } else {
  4057. if execution_state > 0 {
  4058. if cost_type > 0 {
  4059. if len(execution_frequency) > 0 {
  4060. 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 = ?"
  4061. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4062. } else {
  4063. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and is_settle = ?"
  4064. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4065. }
  4066. } else {
  4067. if len(execution_frequency) > 0 {
  4068. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and execution_frequency = ?"
  4069. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4070. } else {
  4071. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ?"
  4072. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4073. }
  4074. }
  4075. } else {
  4076. if cost_type > 0 {
  4077. if len(execution_frequency) > 0 {
  4078. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ? and execution_frequency = ?"
  4079. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  4080. } else {
  4081. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ?"
  4082. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4083. }
  4084. } else {
  4085. if len(execution_frequency) > 0 {
  4086. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_frequency = ?"
  4087. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  4088. } else {
  4089. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  4090. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4091. }
  4092. }
  4093. }
  4094. }
  4095. } else if patientType == 1 {
  4096. if patient_id > 0 {
  4097. if execution_state > 0 {
  4098. if cost_type > 0 {
  4099. if len(execution_frequency) > 0 {
  4100. 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 = ?"
  4101. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  4102. } else {
  4103. 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 = ?"
  4104. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  4105. }
  4106. } else {
  4107. if len(execution_frequency) > 0 {
  4108. 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 = ?"
  4109. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  4110. } else {
  4111. 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= ?"
  4112. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  4113. }
  4114. }
  4115. } else {
  4116. if cost_type > 0 {
  4117. if len(execution_frequency) > 0 {
  4118. 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 = ?"
  4119. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  4120. } else {
  4121. 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=?"
  4122. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  4123. }
  4124. } else {
  4125. if len(execution_frequency) > 0 {
  4126. 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 = ?"
  4127. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  4128. } else {
  4129. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
  4130. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  4131. }
  4132. }
  4133. }
  4134. } else {
  4135. if execution_state > 0 {
  4136. if cost_type > 0 {
  4137. if len(execution_frequency) > 0 {
  4138. 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 = ?"
  4139. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  4140. } else {
  4141. 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=?"
  4142. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  4143. }
  4144. } else {
  4145. if len(execution_frequency) > 0 {
  4146. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ? and execution_frequency = ?"
  4147. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  4148. } else {
  4149. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  4150. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  4151. }
  4152. }
  4153. } else {
  4154. if cost_type > 0 {
  4155. if len(execution_frequency) > 0 {
  4156. 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 = ?"
  4157. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  4158. } else {
  4159. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and is_settle=?"
  4160. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  4161. }
  4162. } else {
  4163. if len(execution_frequency) > 0 {
  4164. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_frequency = ?"
  4165. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  4166. } else {
  4167. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  4168. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  4169. }
  4170. }
  4171. }
  4172. }
  4173. } else if patientType == 2 {
  4174. if patient_id > 0 {
  4175. if execution_state > 0 {
  4176. if cost_type > 0 {
  4177. if len(execution_frequency) > 0 {
  4178. 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 = ?"
  4179. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4180. } else {
  4181. 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=?"
  4182. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4183. }
  4184. } else {
  4185. if len(execution_frequency) > 0 {
  4186. 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 = ?"
  4187. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4188. } else {
  4189. 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 = ?"
  4190. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4191. }
  4192. }
  4193. } else {
  4194. if cost_type > 0 {
  4195. if len(execution_frequency) > 0 {
  4196. 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 = ?"
  4197. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4198. } else {
  4199. 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=?"
  4200. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4201. }
  4202. } else {
  4203. if len(execution_frequency) > 0 {
  4204. 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 = ?"
  4205. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4206. } else {
  4207. 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 = ?)"
  4208. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4209. }
  4210. }
  4211. }
  4212. } else {
  4213. if execution_state > 0 {
  4214. if cost_type > 0 {
  4215. if len(execution_frequency) > 0 {
  4216. 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 = ?"
  4217. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4218. } else {
  4219. 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=?"
  4220. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4221. }
  4222. } else {
  4223. if len(execution_frequency) > 0 {
  4224. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1) and execution_state = ? and execution_frequency = ?"
  4225. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4226. } else {
  4227. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  4228. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4229. }
  4230. }
  4231. } else {
  4232. if cost_type > 0 {
  4233. if len(execution_frequency) > 0 {
  4234. 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 = ?"
  4235. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  4236. } else {
  4237. 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 = ?"
  4238. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4239. }
  4240. } else {
  4241. if len(execution_frequency) > 0 {
  4242. 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 = ?"
  4243. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  4244. } else {
  4245. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  4246. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4247. }
  4248. }
  4249. }
  4250. }
  4251. }
  4252. } else if adviceType == 1 {
  4253. if patientType == 0 {
  4254. if patient_id > 0 {
  4255. if execution_state > 0 {
  4256. if cost_type > 0 {
  4257. if len(execution_frequency) > 0 {
  4258. 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 = ?"
  4259. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4260. } else {
  4261. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  4262. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4263. }
  4264. } else {
  4265. if len(execution_frequency) > 0 {
  4266. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  4267. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4268. } else {
  4269. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ?"
  4270. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4271. }
  4272. }
  4273. } else {
  4274. if cost_type > 0 {
  4275. if len(execution_frequency) > 0 {
  4276. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  4277. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4278. } else {
  4279. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? "
  4280. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4281. }
  4282. } else {
  4283. if len(execution_frequency) > 0 {
  4284. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_frequency = ?"
  4285. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4286. } else {
  4287. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
  4288. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4289. }
  4290. }
  4291. }
  4292. } else {
  4293. if execution_state > 0 {
  4294. if cost_type > 0 {
  4295. if len(execution_frequency) > 0 {
  4296. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  4297. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4298. } else {
  4299. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ?"
  4300. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4301. }
  4302. } else {
  4303. if len(execution_frequency) > 0 {
  4304. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and execution_frequency = ?"
  4305. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4306. } else {
  4307. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ?"
  4308. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4309. }
  4310. }
  4311. } else {
  4312. if cost_type > 0 {
  4313. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = ? "
  4314. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4315. } else {
  4316. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  4317. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4318. }
  4319. }
  4320. }
  4321. } else if patientType == 1 {
  4322. if patient_id > 0 {
  4323. if execution_state > 0 {
  4324. if cost_type > 0 {
  4325. if len(execution_frequency) > 0 {
  4326. 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 = ?"
  4327. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  4328. } else {
  4329. 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 = ?"
  4330. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  4331. }
  4332. } else {
  4333. if len(execution_frequency) > 0 {
  4334. 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 = ?"
  4335. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  4336. } else {
  4337. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  4338. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  4339. }
  4340. }
  4341. } else {
  4342. if cost_type > 0 {
  4343. if len(execution_frequency) > 0 {
  4344. 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 = ?"
  4345. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  4346. } else {
  4347. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  4348. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  4349. }
  4350. } else {
  4351. if len(execution_frequency) > 0 {
  4352. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  4353. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  4354. } else {
  4355. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
  4356. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  4357. }
  4358. }
  4359. }
  4360. } else {
  4361. if execution_state > 0 {
  4362. if cost_type > 0 {
  4363. if len(execution_frequency) > 0 {
  4364. 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 = ?"
  4365. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  4366. } else {
  4367. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=? and is_settle = ?"
  4368. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  4369. }
  4370. } else {
  4371. if len(execution_frequency) > 0 {
  4372. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?and execution_frequency = ?"
  4373. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  4374. } else {
  4375. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?"
  4376. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  4377. }
  4378. }
  4379. } else {
  4380. if cost_type > 0 {
  4381. if len(execution_frequency) > 0 {
  4382. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  4383. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  4384. } else {
  4385. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? "
  4386. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  4387. }
  4388. } else {
  4389. if len(execution_frequency) > 0 {
  4390. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_frequency = ?"
  4391. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  4392. } else {
  4393. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  4394. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  4395. }
  4396. }
  4397. }
  4398. }
  4399. } else if patientType == 2 {
  4400. if patient_id > 0 {
  4401. if execution_state > 0 {
  4402. if cost_type > 0 {
  4403. if len(execution_frequency) > 0 {
  4404. 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 = ?"
  4405. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4406. } else {
  4407. 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 = ?"
  4408. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4409. }
  4410. } else {
  4411. if len(execution_frequency) > 0 {
  4412. 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 = ?"
  4413. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4414. } else {
  4415. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  4416. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4417. }
  4418. }
  4419. } else {
  4420. if cost_type > 0 {
  4421. if len(execution_frequency) > 0 {
  4422. 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 = ?"
  4423. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4424. } else {
  4425. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  4426. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4427. }
  4428. } else {
  4429. if len(execution_frequency) > 0 {
  4430. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_frequency = ?"
  4431. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4432. } else {
  4433. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
  4434. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4435. }
  4436. }
  4437. }
  4438. } else {
  4439. if execution_state > 0 {
  4440. if cost_type > 0 {
  4441. if len(execution_frequency) > 0 {
  4442. 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 = ?"
  4443. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4444. } else {
  4445. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  4446. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4447. }
  4448. } else {
  4449. if len(execution_frequency) > 0 {
  4450. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and execution_frequency = ?"
  4451. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4452. } else {
  4453. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ?"
  4454. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4455. }
  4456. }
  4457. } else {
  4458. if cost_type > 0 {
  4459. if len(execution_frequency) > 0 {
  4460. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  4461. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  4462. } else {
  4463. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ?"
  4464. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4465. }
  4466. } else {
  4467. if len(execution_frequency) > 0 {
  4468. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_frequency = ?"
  4469. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  4470. } else {
  4471. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  4472. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4473. }
  4474. }
  4475. }
  4476. }
  4477. }
  4478. } else if adviceType == 3 {
  4479. if patientType == 0 {
  4480. if patient_id > 0 {
  4481. if execution_state > 0 {
  4482. if cost_type > 0 {
  4483. if len(execution_frequency) > 0 {
  4484. 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 =?"
  4485. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4486. } else {
  4487. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  4488. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4489. }
  4490. } else {
  4491. if len(execution_frequency) > 0 {
  4492. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency =?"
  4493. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4494. } else {
  4495. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ?"
  4496. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4497. }
  4498. }
  4499. } else {
  4500. if cost_type > 0 {
  4501. if len(execution_frequency) > 0 {
  4502. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency =?"
  4503. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4504. } else {
  4505. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? "
  4506. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4507. }
  4508. } else {
  4509. if len(execution_frequency) > 0 {
  4510. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_frequency =?"
  4511. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4512. } else {
  4513. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? "
  4514. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4515. }
  4516. }
  4517. }
  4518. } else {
  4519. if execution_state > 0 {
  4520. if cost_type > 0 {
  4521. if len(execution_frequency) > 0 {
  4522. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ? and execution_frequency =?"
  4523. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4524. } else {
  4525. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ?"
  4526. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4527. }
  4528. } else {
  4529. if len(execution_frequency) > 0 {
  4530. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and execution_frequency =?"
  4531. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4532. } else {
  4533. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? "
  4534. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4535. }
  4536. }
  4537. } else {
  4538. if cost_type > 0 {
  4539. if len(execution_frequency) > 0 {
  4540. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? and execution_frequency =?"
  4541. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  4542. } else {
  4543. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? "
  4544. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4545. }
  4546. } else {
  4547. if len(execution_frequency) > 0 {
  4548. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_frequency =?"
  4549. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  4550. } else {
  4551. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  4552. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4553. }
  4554. }
  4555. }
  4556. }
  4557. } else if patientType == 1 {
  4558. if patient_id > 0 {
  4559. if execution_state > 0 {
  4560. if cost_type > 0 {
  4561. if len(execution_frequency) > 0 {
  4562. 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 = ?"
  4563. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  4564. } else {
  4565. 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 = ?"
  4566. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  4567. }
  4568. } else {
  4569. if len(execution_frequency) > 0 {
  4570. 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 = ?"
  4571. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  4572. } else {
  4573. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  4574. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  4575. }
  4576. }
  4577. } else {
  4578. if cost_type > 0 {
  4579. if len(execution_frequency) > 0 {
  4580. 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 = ?"
  4581. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  4582. } else {
  4583. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  4584. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  4585. }
  4586. } else {
  4587. if len(execution_frequency) > 0 {
  4588. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  4589. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  4590. } else {
  4591. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
  4592. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  4593. }
  4594. }
  4595. }
  4596. } else {
  4597. if execution_state > 0 {
  4598. if cost_type > 0 {
  4599. if len(execution_frequency) > 0 {
  4600. 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 = ?"
  4601. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  4602. } else {
  4603. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? and is_settle = ?"
  4604. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  4605. }
  4606. } else {
  4607. if len(execution_frequency) > 0 {
  4608. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =?and execution_frequency = ? "
  4609. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  4610. } else {
  4611. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? "
  4612. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  4613. }
  4614. }
  4615. } else {
  4616. if cost_type > 0 {
  4617. if len(execution_frequency) > 0 {
  4618. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  4619. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  4620. } else {
  4621. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ?"
  4622. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  4623. }
  4624. } else {
  4625. if len(execution_frequency) > 0 {
  4626. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_frequency = ?"
  4627. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  4628. } else {
  4629. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  4630. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  4631. }
  4632. }
  4633. }
  4634. }
  4635. } else if patientType == 2 {
  4636. if patient_id > 0 {
  4637. if execution_state > 0 {
  4638. if cost_type > 0 {
  4639. if len(execution_frequency) > 0 {
  4640. 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 = ?"
  4641. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4642. } else {
  4643. 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 = ?"
  4644. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4645. }
  4646. } else {
  4647. if len(execution_frequency) > 0 {
  4648. 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 = ?"
  4649. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4650. } else {
  4651. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  4652. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4653. }
  4654. }
  4655. } else {
  4656. if cost_type > 0 {
  4657. if len(execution_frequency) > 0 {
  4658. 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 = ?"
  4659. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4660. } else {
  4661. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  4662. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4663. }
  4664. } else {
  4665. if len(execution_frequency) > 0 {
  4666. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_frequency = ?"
  4667. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4668. } else {
  4669. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ?"
  4670. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4671. }
  4672. }
  4673. }
  4674. } else {
  4675. if execution_state > 0 {
  4676. if cost_type > 0 {
  4677. if len(execution_frequency) > 0 {
  4678. 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 = ?"
  4679. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4680. } else {
  4681. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and is_settle = ?"
  4682. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4683. }
  4684. } else {
  4685. if len(execution_frequency) > 0 {
  4686. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and execution_frequency = ?"
  4687. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4688. } else {
  4689. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ?"
  4690. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4691. }
  4692. }
  4693. } else {
  4694. if cost_type > 0 {
  4695. if len(execution_frequency) > 0 {
  4696. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  4697. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  4698. } else {
  4699. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ?"
  4700. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4701. }
  4702. } else {
  4703. if len(execution_frequency) > 0 {
  4704. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_frequency = ?"
  4705. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  4706. } else {
  4707. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  4708. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4709. }
  4710. }
  4711. }
  4712. }
  4713. }
  4714. } else if adviceType == 2 && len(deliverWay) > 0 {
  4715. if patientType == 0 {
  4716. if patient_id > 0 {
  4717. if execution_state > 0 {
  4718. if cost_type > 0 {
  4719. if len(execution_frequency) > 0 {
  4720. 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 = ?"
  4721. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency)
  4722. } else {
  4723. 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 = ?"
  4724. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  4725. }
  4726. } else {
  4727. if len(execution_frequency) > 0 {
  4728. 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 = ?"
  4729. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency)
  4730. } else {
  4731. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  4732. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  4733. }
  4734. }
  4735. } else {
  4736. if cost_type > 0 {
  4737. if len(execution_frequency) > 0 {
  4738. 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 = ?"
  4739. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency)
  4740. } else {
  4741. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and is_settle = ?"
  4742. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  4743. }
  4744. } else {
  4745. if len(execution_frequency) > 0 {
  4746. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_frequency = ?"
  4747. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency)
  4748. } else {
  4749. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ?"
  4750. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  4751. }
  4752. }
  4753. }
  4754. } else {
  4755. if execution_state > 0 {
  4756. if cost_type > 0 {
  4757. if len(execution_frequency) > 0 {
  4758. 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 = ?"
  4759. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency)
  4760. } else {
  4761. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and is_settle = ?"
  4762. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  4763. }
  4764. } else {
  4765. if len(execution_frequency) > 0 {
  4766. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and execution_frequency = ?"
  4767. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency)
  4768. } else {
  4769. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ?"
  4770. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  4771. }
  4772. }
  4773. } else {
  4774. if cost_type > 0 {
  4775. if len(execution_frequency) > 0 {
  4776. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and is_settle = ? and execution_frequency = ?"
  4777. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, execution_frequency)
  4778. } else {
  4779. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and is_settle = ?"
  4780. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  4781. }
  4782. } else {
  4783. if len(execution_frequency) > 0 {
  4784. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_frequency = ?"
  4785. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_frequency)
  4786. } else {
  4787. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  4788. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  4789. }
  4790. }
  4791. }
  4792. }
  4793. } else if patientType == 1 {
  4794. if patient_id > 0 {
  4795. if execution_state > 0 {
  4796. if cost_type > 0 {
  4797. if len(execution_frequency) > 0 {
  4798. 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 = ?"
  4799. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type, execution_frequency)
  4800. } else {
  4801. 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 = ?"
  4802. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type)
  4803. }
  4804. } else {
  4805. if len(execution_frequency) > 0 {
  4806. 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 = ?"
  4807. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, execution_frequency)
  4808. } else {
  4809. 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 = ?"
  4810. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state)
  4811. }
  4812. }
  4813. } else {
  4814. if cost_type > 0 {
  4815. if len(execution_frequency) > 0 {
  4816. 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 = ?"
  4817. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type, execution_frequency)
  4818. } else {
  4819. 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 = ?"
  4820. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type)
  4821. }
  4822. } else {
  4823. if len(execution_frequency) > 0 {
  4824. 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 = ?"
  4825. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_frequency)
  4826. } else {
  4827. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ?"
  4828. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
  4829. }
  4830. }
  4831. }
  4832. } else {
  4833. if execution_state > 0 {
  4834. if cost_type > 0 {
  4835. if len(execution_frequency) > 0 {
  4836. 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 = ?"
  4837. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type, execution_frequency)
  4838. } else {
  4839. 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 = ?"
  4840. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type)
  4841. }
  4842. } else {
  4843. if len(execution_frequency) > 0 {
  4844. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ? and execution_frequency = ?"
  4845. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, execution_frequency)
  4846. } else {
  4847. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ?"
  4848. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state)
  4849. }
  4850. }
  4851. } else {
  4852. if cost_type > 0 {
  4853. if len(execution_frequency) > 0 {
  4854. 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 = ?"
  4855. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type, execution_frequency)
  4856. } else {
  4857. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and is_settle = ?"
  4858. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type)
  4859. }
  4860. } else {
  4861. if len(execution_frequency) > 0 {
  4862. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_frequency = ?"
  4863. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_frequency)
  4864. } else {
  4865. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  4866. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  4867. }
  4868. }
  4869. }
  4870. }
  4871. } else if patientType == 2 {
  4872. if patient_id > 0 {
  4873. if execution_state > 0 {
  4874. if cost_type > 0 {
  4875. if len(execution_frequency) > 0 {
  4876. 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 = ?"
  4877. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency)
  4878. } else {
  4879. 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 = ?"
  4880. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  4881. }
  4882. } else {
  4883. if len(execution_frequency) > 0 {
  4884. 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 = ?"
  4885. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency)
  4886. } else {
  4887. 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 = ?"
  4888. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  4889. }
  4890. }
  4891. } else {
  4892. if cost_type > 0 {
  4893. if len(execution_frequency) > 0 {
  4894. 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 = ?"
  4895. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency)
  4896. } else {
  4897. 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 = ?"
  4898. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  4899. }
  4900. } else {
  4901. if len(execution_frequency) > 0 {
  4902. 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 = ?"
  4903. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency)
  4904. } else {
  4905. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ?"
  4906. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  4907. }
  4908. }
  4909. }
  4910. } else {
  4911. if execution_state > 0 {
  4912. if cost_type > 0 {
  4913. if len(execution_frequency) > 0 {
  4914. 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 = ?"
  4915. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency)
  4916. } else {
  4917. 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 = ?"
  4918. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  4919. }
  4920. } else {
  4921. if len(execution_frequency) > 0 {
  4922. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ? and execution_frequency = ?"
  4923. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency)
  4924. } else {
  4925. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ?"
  4926. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  4927. }
  4928. }
  4929. } else {
  4930. if cost_type > 0 {
  4931. if len(execution_frequency) > 0 {
  4932. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and is_settle = ?"
  4933. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  4934. } else {
  4935. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and is_settle = ?"
  4936. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  4937. }
  4938. } else {
  4939. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  4940. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  4941. }
  4942. }
  4943. }
  4944. }
  4945. } else if adviceType == 2 && len(deliverWay) <= 0 {
  4946. fmt.Println("寄哪里233223322323233232", patientType)
  4947. fmt.Println("patient_id", patient_id)
  4948. fmt.Println("execution_state000000", execution_state)
  4949. fmt.Println("cost_type", cost_type)
  4950. fmt.Println("len23323232", len(execution_frequency))
  4951. if patientType == 0 {
  4952. if patient_id > 0 {
  4953. if execution_state > 0 {
  4954. if cost_type > 0 {
  4955. if len(execution_frequency) > 0 {
  4956. 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 = ?"
  4957. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4958. } else {
  4959. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  4960. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4961. }
  4962. } else {
  4963. if len(execution_frequency) > 0 {
  4964. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  4965. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4966. } else {
  4967. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ?"
  4968. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4969. }
  4970. }
  4971. } else {
  4972. if cost_type > 0 {
  4973. if len(execution_frequency) > 0 {
  4974. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  4975. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4976. } else {
  4977. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and is_settle = ?"
  4978. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4979. }
  4980. } else {
  4981. if len(execution_frequency) > 0 {
  4982. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_frequency = ?"
  4983. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4984. } else {
  4985. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ?"
  4986. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4987. }
  4988. }
  4989. }
  4990. } else {
  4991. if execution_state > 0 {
  4992. if cost_type > 0 {
  4993. if len(execution_frequency) > 0 {
  4994. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  4995. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4996. } else {
  4997. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ? and is_settle = ?"
  4998. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4999. }
  5000. } else {
  5001. if len(execution_frequency) > 0 {
  5002. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?and execution_frequency = ?"
  5003. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  5004. } else {
  5005. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?"
  5006. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5007. }
  5008. }
  5009. } else {
  5010. if cost_type > 0 {
  5011. if len(execution_frequency) > 0 {
  5012. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and is_settle = ? and execution_frequency = ?"
  5013. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  5014. }
  5015. } else {
  5016. if len(execution_frequency) > 0 {
  5017. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_frequency = ?"
  5018. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  5019. } else {
  5020. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  5021. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5022. }
  5023. }
  5024. }
  5025. }
  5026. } else if patientType == 1 {
  5027. if patient_id > 0 {
  5028. if execution_state > 0 {
  5029. if cost_type > 0 {
  5030. if len(execution_frequency) > 0 {
  5031. 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 = ?"
  5032. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  5033. } else {
  5034. 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 = ?"
  5035. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  5036. }
  5037. } else {
  5038. if len(execution_frequency) > 0 {
  5039. 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 = ?"
  5040. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  5041. } else {
  5042. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  5043. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  5044. }
  5045. }
  5046. } else {
  5047. if cost_type > 0 {
  5048. if len(execution_frequency) > 0 {
  5049. 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 = ?"
  5050. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  5051. } else {
  5052. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  5053. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  5054. }
  5055. } else {
  5056. if len(execution_frequency) > 0 {
  5057. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  5058. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  5059. } else {
  5060. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ?"
  5061. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  5062. }
  5063. }
  5064. }
  5065. } else {
  5066. if execution_state > 0 {
  5067. if cost_type > 0 {
  5068. if len(execution_frequency) > 0 {
  5069. 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 = ?"
  5070. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  5071. } else {
  5072. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ? and is_settle = ?"
  5073. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  5074. }
  5075. } else {
  5076. if len(execution_frequency) > 0 {
  5077. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ? and execution_frequency = ?"
  5078. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  5079. } else {
  5080. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ?"
  5081. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  5082. }
  5083. }
  5084. } else {
  5085. if cost_type > 0 {
  5086. if len(execution_frequency) > 0 {
  5087. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  5088. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  5089. } else {
  5090. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and is_settle = ?"
  5091. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  5092. }
  5093. } else {
  5094. if len(execution_frequency) > 0 {
  5095. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_frequency = ?"
  5096. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  5097. } else {
  5098. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?"
  5099. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  5100. }
  5101. }
  5102. }
  5103. }
  5104. } else if patientType == 2 {
  5105. if patient_id > 0 {
  5106. if execution_state > 0 {
  5107. if cost_type > 0 {
  5108. if len(execution_frequency) > 0 {
  5109. 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=?"
  5110. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  5111. } else {
  5112. 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 = ?"
  5113. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5114. }
  5115. } else {
  5116. if len(execution_frequency) > 0 {
  5117. 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=?"
  5118. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  5119. } else {
  5120. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  5121. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5122. }
  5123. }
  5124. } else {
  5125. if cost_type > 0 {
  5126. if len(execution_frequency) > 0 {
  5127. 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=?"
  5128. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  5129. } else {
  5130. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  5131. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5132. }
  5133. } else {
  5134. if len(execution_frequency) > 0 {
  5135. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_frequency=?"
  5136. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  5137. } else {
  5138. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ?"
  5139. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5140. }
  5141. }
  5142. }
  5143. } else {
  5144. if execution_state > 0 {
  5145. if cost_type > 0 {
  5146. if len(execution_frequency) > 0 {
  5147. 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 = ?"
  5148. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  5149. } else {
  5150. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  5151. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5152. }
  5153. } else {
  5154. if len(execution_frequency) > 0 {
  5155. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ? and execution_frequency = ?"
  5156. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  5157. } else {
  5158. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ?"
  5159. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5160. }
  5161. }
  5162. } else {
  5163. if cost_type > 0 {
  5164. if len(execution_frequency) > 0 {
  5165. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  5166. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  5167. } else {
  5168. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and is_settle = ?"
  5169. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5170. }
  5171. } else {
  5172. if len(execution_frequency) > 0 {
  5173. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_frequency = ?"
  5174. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  5175. } else {
  5176. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  5177. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5178. }
  5179. }
  5180. }
  5181. }
  5182. }
  5183. }
  5184. db := readDb.Table("xt_schedule")
  5185. if scheduleType > 0 {
  5186. db = db.Where("schedule_type = ?", scheduleType)
  5187. }
  5188. if partitonType > 0 {
  5189. db = db.Where("partition_id = ?", partitonType)
  5190. }
  5191. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  5192. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  5193. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  5194. }).
  5195. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  5196. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  5197. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  5198. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  5199. Preload("DoctorAdvices", adviceCondition...).
  5200. Where("status = 1 AND user_org_id = ?", orgID)
  5201. if scheduleDate != 0 {
  5202. db = db.Where("schedule_date = ?", scheduleDate)
  5203. }
  5204. err := db.Find(&vms).Error
  5205. return vms, err
  5206. }
  5207. 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) {
  5208. var vms []*MScheduleDoctorAdviceVM
  5209. adviceWhere := ""
  5210. adviceCondition := []interface{}{}
  5211. if adviceType == 0 {
  5212. if patientType == 0 {
  5213. if patient_id > 0 {
  5214. if execution_state > 0 {
  5215. if cost_type > 0 {
  5216. 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 = ?"
  5217. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5218. } else {
  5219. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  5220. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5221. }
  5222. } else {
  5223. if cost_type > 0 {
  5224. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and is_settle = ?"
  5225. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5226. } else {
  5227. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
  5228. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5229. }
  5230. }
  5231. } else {
  5232. if execution_state > 0 {
  5233. if cost_type > 0 {
  5234. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and is_settle = ?"
  5235. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5236. } else {
  5237. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ?"
  5238. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5239. }
  5240. } else {
  5241. if cost_type > 0 {
  5242. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ?"
  5243. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5244. } else {
  5245. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  5246. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5247. }
  5248. }
  5249. }
  5250. } else if patientType == 1 {
  5251. if patient_id > 0 {
  5252. if execution_state > 0 {
  5253. if cost_type > 0 {
  5254. 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 = ?"
  5255. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  5256. } else {
  5257. 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= ?"
  5258. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  5259. }
  5260. } else {
  5261. if cost_type > 0 {
  5262. 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=?"
  5263. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  5264. } else {
  5265. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
  5266. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  5267. }
  5268. }
  5269. } else {
  5270. if execution_state > 0 {
  5271. if cost_type > 0 {
  5272. 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=?"
  5273. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  5274. } else {
  5275. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  5276. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  5277. }
  5278. } else {
  5279. if cost_type > 0 {
  5280. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and is_settle=?"
  5281. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  5282. } else {
  5283. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  5284. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  5285. }
  5286. }
  5287. }
  5288. } else if patientType == 2 {
  5289. if patient_id > 0 {
  5290. if execution_state > 0 {
  5291. if cost_type > 0 {
  5292. 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=?"
  5293. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5294. } else {
  5295. 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 = ?"
  5296. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5297. }
  5298. } else {
  5299. if cost_type > 0 {
  5300. 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=?"
  5301. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5302. } else {
  5303. 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 = ?)"
  5304. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5305. }
  5306. }
  5307. } else {
  5308. if execution_state > 0 {
  5309. if cost_type > 0 {
  5310. 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=?"
  5311. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5312. } else {
  5313. 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 = ?"
  5314. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5315. }
  5316. } else {
  5317. if cost_type > 0 {
  5318. 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 = ?"
  5319. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5320. } else {
  5321. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  5322. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5323. }
  5324. }
  5325. }
  5326. }
  5327. } else if adviceType == 1 {
  5328. if patientType == 0 {
  5329. if patient_id > 0 {
  5330. if execution_state > 0 {
  5331. if cost_type > 0 {
  5332. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  5333. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5334. } else {
  5335. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ?"
  5336. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5337. }
  5338. } else {
  5339. if cost_type > 0 {
  5340. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? "
  5341. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5342. } else {
  5343. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
  5344. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5345. }
  5346. }
  5347. } else {
  5348. if execution_state > 0 {
  5349. if cost_type > 0 {
  5350. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ?"
  5351. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5352. } else {
  5353. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ?"
  5354. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5355. }
  5356. } else {
  5357. if cost_type > 0 {
  5358. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = ? "
  5359. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5360. } else {
  5361. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  5362. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5363. }
  5364. }
  5365. }
  5366. } else if patientType == 1 {
  5367. if patient_id > 0 {
  5368. if execution_state > 0 {
  5369. if cost_type > 0 {
  5370. 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 = ?"
  5371. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  5372. } else {
  5373. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  5374. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  5375. }
  5376. } else {
  5377. if cost_type > 0 {
  5378. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  5379. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  5380. } else {
  5381. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
  5382. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  5383. }
  5384. }
  5385. } else {
  5386. if execution_state > 0 {
  5387. if cost_type > 0 {
  5388. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=? and is_settle = ?"
  5389. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  5390. } else {
  5391. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?"
  5392. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  5393. }
  5394. } else {
  5395. if cost_type > 0 {
  5396. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? "
  5397. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  5398. } else {
  5399. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  5400. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  5401. }
  5402. }
  5403. }
  5404. } else if patientType == 2 {
  5405. if patient_id > 0 {
  5406. if execution_state > 0 {
  5407. if cost_type > 0 {
  5408. 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 = ?"
  5409. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5410. } else {
  5411. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  5412. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5413. }
  5414. } else {
  5415. if cost_type > 0 {
  5416. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  5417. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5418. } else {
  5419. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
  5420. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5421. }
  5422. }
  5423. } else {
  5424. if execution_state > 0 {
  5425. if cost_type > 0 {
  5426. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  5427. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5428. } else {
  5429. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ?"
  5430. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5431. }
  5432. } else {
  5433. if cost_type > 0 {
  5434. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ?"
  5435. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5436. } else {
  5437. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  5438. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5439. }
  5440. }
  5441. }
  5442. }
  5443. } else if adviceType == 3 {
  5444. if patientType == 0 {
  5445. if patient_id > 0 {
  5446. if execution_state > 0 {
  5447. if cost_type > 0 {
  5448. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  5449. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5450. } else {
  5451. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ?"
  5452. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5453. }
  5454. } else {
  5455. if cost_type > 0 {
  5456. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? "
  5457. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5458. } else {
  5459. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? "
  5460. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5461. }
  5462. }
  5463. } else {
  5464. if execution_state > 0 {
  5465. if cost_type > 0 {
  5466. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ?"
  5467. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5468. } else {
  5469. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? "
  5470. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5471. }
  5472. } else {
  5473. if cost_type > 0 {
  5474. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? "
  5475. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5476. } else {
  5477. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  5478. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5479. }
  5480. }
  5481. }
  5482. } else if patientType == 1 {
  5483. if patient_id > 0 {
  5484. if execution_state > 0 {
  5485. if cost_type > 0 {
  5486. 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 = ?"
  5487. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  5488. } else {
  5489. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  5490. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  5491. }
  5492. } else {
  5493. if cost_type > 0 {
  5494. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  5495. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  5496. } else {
  5497. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
  5498. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  5499. }
  5500. }
  5501. } else {
  5502. if execution_state > 0 {
  5503. if cost_type > 0 {
  5504. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? and is_settle = ?"
  5505. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  5506. } else {
  5507. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? "
  5508. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  5509. }
  5510. } else {
  5511. if cost_type > 0 {
  5512. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ?"
  5513. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  5514. } else {
  5515. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  5516. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  5517. }
  5518. }
  5519. }
  5520. } else if patientType == 2 {
  5521. if patient_id > 0 {
  5522. if execution_state > 0 {
  5523. if cost_type > 0 {
  5524. 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 = ?"
  5525. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5526. } else {
  5527. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  5528. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5529. }
  5530. } else {
  5531. if cost_type > 0 {
  5532. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  5533. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5534. } else {
  5535. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ?"
  5536. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5537. }
  5538. }
  5539. } else {
  5540. if execution_state > 0 {
  5541. if cost_type > 0 {
  5542. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and is_settle = ?"
  5543. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5544. } else {
  5545. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ?"
  5546. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5547. }
  5548. } else {
  5549. if cost_type > 0 {
  5550. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ?"
  5551. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5552. } else {
  5553. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  5554. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5555. }
  5556. }
  5557. }
  5558. }
  5559. } else if adviceType == 2 && len(deliverWay) > 0 {
  5560. if patientType == 0 {
  5561. if patient_id > 0 {
  5562. if execution_state > 0 {
  5563. if cost_type > 0 {
  5564. 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 = ?"
  5565. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  5566. } else {
  5567. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  5568. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  5569. }
  5570. } else {
  5571. if cost_type > 0 {
  5572. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and is_settle = ?"
  5573. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  5574. } else {
  5575. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ?"
  5576. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  5577. }
  5578. }
  5579. } else {
  5580. if execution_state > 0 {
  5581. if cost_type > 0 {
  5582. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and is_settle = ?"
  5583. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  5584. } else {
  5585. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ?"
  5586. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  5587. }
  5588. } else {
  5589. if cost_type > 0 {
  5590. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and is_settle = ?"
  5591. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  5592. } else {
  5593. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  5594. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  5595. }
  5596. }
  5597. }
  5598. } else if patientType == 1 {
  5599. if patient_id > 0 {
  5600. if execution_state > 0 {
  5601. if cost_type > 0 {
  5602. 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 = ?"
  5603. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type)
  5604. } else {
  5605. 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 = ?"
  5606. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state)
  5607. }
  5608. } else {
  5609. if cost_type > 0 {
  5610. 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 = ?"
  5611. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type)
  5612. } else {
  5613. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ?"
  5614. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
  5615. }
  5616. }
  5617. } else {
  5618. if execution_state > 0 {
  5619. if cost_type > 0 {
  5620. 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 = ?"
  5621. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type)
  5622. } else {
  5623. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ?"
  5624. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state)
  5625. }
  5626. } else {
  5627. if cost_type > 0 {
  5628. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and is_settle = ?"
  5629. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type)
  5630. } else {
  5631. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  5632. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  5633. }
  5634. }
  5635. }
  5636. } else if patientType == 2 {
  5637. if patient_id > 0 {
  5638. if execution_state > 0 {
  5639. if cost_type > 0 {
  5640. 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 = ?"
  5641. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  5642. } else {
  5643. 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 = ?"
  5644. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  5645. }
  5646. } else {
  5647. if cost_type > 0 {
  5648. 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 = ?"
  5649. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  5650. } else {
  5651. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ?"
  5652. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  5653. }
  5654. }
  5655. } else {
  5656. if execution_state > 0 {
  5657. if cost_type > 0 {
  5658. 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 = ?"
  5659. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  5660. } else {
  5661. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ?"
  5662. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  5663. }
  5664. } else {
  5665. if cost_type > 0 {
  5666. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and is_settle = ?"
  5667. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  5668. } else {
  5669. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  5670. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  5671. }
  5672. }
  5673. }
  5674. }
  5675. } else if adviceType == 2 && len(deliverWay) <= 0 {
  5676. if patientType == 0 {
  5677. if patient_id > 0 {
  5678. if execution_state > 0 {
  5679. if cost_type > 0 {
  5680. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  5681. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5682. } else {
  5683. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ?"
  5684. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5685. }
  5686. } else {
  5687. if cost_type > 0 {
  5688. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and is_settle = ?"
  5689. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5690. } else {
  5691. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ?"
  5692. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5693. }
  5694. }
  5695. } else {
  5696. if execution_state > 0 {
  5697. if cost_type > 0 {
  5698. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ? and is_settle = ?"
  5699. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5700. } else {
  5701. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?"
  5702. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5703. }
  5704. } else {
  5705. if cost_type > 0 {
  5706. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and is_settle = ?"
  5707. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5708. } else {
  5709. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  5710. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5711. }
  5712. }
  5713. }
  5714. } else if patientType == 1 {
  5715. if patient_id > 0 {
  5716. if execution_state > 0 {
  5717. if cost_type > 0 {
  5718. 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 = ?"
  5719. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  5720. } else {
  5721. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  5722. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  5723. }
  5724. } else {
  5725. if cost_type > 0 {
  5726. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  5727. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  5728. } else {
  5729. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ?"
  5730. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  5731. }
  5732. }
  5733. } else {
  5734. if execution_state > 0 {
  5735. if cost_type > 0 {
  5736. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ? and is_settle = ?"
  5737. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  5738. } else {
  5739. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ?"
  5740. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  5741. }
  5742. } else {
  5743. if cost_type > 0 {
  5744. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and is_settle = ?"
  5745. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  5746. } else {
  5747. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?"
  5748. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  5749. }
  5750. }
  5751. }
  5752. } else if patientType == 2 {
  5753. if patient_id > 0 {
  5754. if execution_state > 0 {
  5755. if cost_type > 0 {
  5756. 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 = ?"
  5757. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5758. } else {
  5759. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  5760. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5761. }
  5762. } else {
  5763. if cost_type > 0 {
  5764. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  5765. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5766. } else {
  5767. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ?"
  5768. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5769. }
  5770. }
  5771. } else {
  5772. if execution_state > 0 {
  5773. if cost_type > 0 {
  5774. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  5775. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5776. } else {
  5777. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ?"
  5778. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5779. }
  5780. } else {
  5781. if cost_type > 0 {
  5782. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and is_settle = ?"
  5783. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5784. } else {
  5785. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  5786. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5787. }
  5788. }
  5789. }
  5790. }
  5791. }
  5792. db := readDb.Table("xt_schedule")
  5793. if scheduleType > 0 {
  5794. db = db.Where("schedule_type = ?", scheduleType)
  5795. }
  5796. if partitonType > 0 {
  5797. db = db.Where("partition_id = ?", partitonType)
  5798. }
  5799. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  5800. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  5801. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  5802. }).
  5803. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  5804. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  5805. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  5806. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  5807. Preload("DoctorAdvices", adviceCondition...).
  5808. Where("status = 1 AND user_org_id = ?", orgID)
  5809. if scheduleDate != 0 {
  5810. db = db.Where("schedule_date = ?", scheduleDate)
  5811. }
  5812. err := db.Find(&vms).Error
  5813. return vms, err
  5814. }
  5815. func GetLastPatientOrder(id int64) (models.XtDialysisOrder, error) {
  5816. order := models.XtDialysisOrder{}
  5817. err := XTReadDB().Where("id = ? and status = 1", id).Find(&order).Error
  5818. return order, err
  5819. }
  5820. func UpdateMobilePatient(org_id int64, patient_id int64, schedule_remark string) error {
  5821. order := models.XtPatients{}
  5822. 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
  5823. 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
  5824. return err
  5825. }
  5826. func GetDialysisTotalCount(org_id int64, patient_id int64) (models.BloodDialysisOrderCount, error) {
  5827. order := models.BloodDialysisOrderCount{}
  5828. db := XTReadDB().Table("xt_dialysis_order as o")
  5829. 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
  5830. return order, err
  5831. }
  5832. func GetDialysisTotalCountOne(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 o.dialysis_date>=1672502400 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 UpdateDialysisOrder(patient_id int64, dialysis_date int64, user_org_id int64, dialysis_total int64) (models.DialysisOrder, error) {
  5839. order := models.DialysisOrder{}
  5840. 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
  5841. return order, err
  5842. }
  5843. func UpdateDeviceInformation(patientid int64, dialysis_date int64) error {
  5844. information := models.DeviceInformation{}
  5845. err := UserWriteDB().Model(&information).Where("patient_id = ? and date = ? and status = 1", patientid, dialysis_date).Update(map[string]interface{}{"status": 0}).Error
  5846. return err
  5847. }
  5848. func MobileGetDoubleCheckSix(orgID int64, patientID int64, recordDate int64) (models.DoubleCheck, error) {
  5849. var record models.DoubleCheck
  5850. err := readDb.Where("patient_id = ? and user_org_id = ? and status = 1 and check_date = ?", patientID, orgID, recordDate).First(&record).Error
  5851. return record, err
  5852. }
  5853. func GetFirstMonitor(patient_id int64, monit_date int64) (models.MonitoringRecord, error) {
  5854. record := models.MonitoringRecord{}
  5855. err := XTReadDB().Where("patient_id = ? and monitoring_date = ? and status=1", patient_id, monit_date).First(&record).Error
  5856. return record, err
  5857. }
  5858. func UpdateFirstMonitor(id int64, catheter_operation string) (models.MonitoringRecord, error) {
  5859. record := models.MonitoringRecord{}
  5860. err := XTWriteDB().Model(&record).Where("id = ? and status= 1", id).Updates(map[string]interface{}{"dispose": catheter_operation}).Error
  5861. return record, err
  5862. }
  5863. 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) {
  5864. var vms []*HisMScheduleDoctorAdviceVM
  5865. if len(deliverWay) > 0 {
  5866. db := readDb.Table("xt_schedule")
  5867. if scheduleType > 0 {
  5868. db = db.Where("schedule_type = ?", scheduleType)
  5869. }
  5870. if partitionType > 0 {
  5871. db = db.Where("partition_id = ?", partitionType)
  5872. }
  5873. if patient_id > 0 {
  5874. if execution_state > 0 {
  5875. if cost_type > 0 {
  5876. if len(execution_frequency) > 0 {
  5877. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  5878. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  5879. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  5880. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  5881. 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).
  5882. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  5883. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  5884. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  5885. Where("status = 1 AND user_org_id = ?", orgID)
  5886. if scheduleDate != 0 {
  5887. db = db.Where("schedule_date = ?", scheduleDate)
  5888. }
  5889. err = db.Find(&vms).Error
  5890. } else {
  5891. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  5892. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  5893. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  5894. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  5895. 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).
  5896. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  5897. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  5898. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  5899. Where("status = 1 AND user_org_id = ?", orgID)
  5900. if scheduleDate != 0 {
  5901. db = db.Where("schedule_date = ?", scheduleDate)
  5902. }
  5903. err = db.Find(&vms).Error
  5904. }
  5905. } else {
  5906. if len(execution_frequency) > 0 {
  5907. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  5908. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  5909. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  5910. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  5911. 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).
  5912. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  5913. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  5914. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  5915. Where("status = 1 AND user_org_id = ?", orgID)
  5916. if scheduleDate != 0 {
  5917. db = db.Where("schedule_date = ?", scheduleDate)
  5918. }
  5919. err = db.Find(&vms).Error
  5920. } else {
  5921. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  5922. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  5923. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  5924. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  5925. 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).
  5926. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  5927. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  5928. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  5929. Where("status = 1 AND user_org_id = ?", orgID)
  5930. if scheduleDate != 0 {
  5931. db = db.Where("schedule_date = ?", scheduleDate)
  5932. }
  5933. err = db.Find(&vms).Error
  5934. }
  5935. }
  5936. } else {
  5937. if cost_type > 0 {
  5938. if len(execution_frequency) > 0 {
  5939. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  5940. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  5941. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  5942. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  5943. 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).
  5944. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  5945. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  5946. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  5947. Where("status = 1 AND user_org_id = ?", orgID)
  5948. if scheduleDate != 0 {
  5949. db = db.Where("schedule_date = ?", scheduleDate)
  5950. }
  5951. err = db.Find(&vms).Error
  5952. } else {
  5953. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  5954. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  5955. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  5956. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  5957. 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).
  5958. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  5959. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  5960. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  5961. Where("status = 1 AND user_org_id = ?", orgID)
  5962. if scheduleDate != 0 {
  5963. db = db.Where("schedule_date = ?", scheduleDate)
  5964. }
  5965. err = db.Find(&vms).Error
  5966. }
  5967. } else {
  5968. if len(execution_frequency) > 0 {
  5969. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  5970. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  5971. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  5972. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  5973. 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).
  5974. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  5975. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  5976. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  5977. Where("status = 1 AND user_org_id = ?", orgID)
  5978. if scheduleDate != 0 {
  5979. db = db.Where("schedule_date = ?", scheduleDate)
  5980. }
  5981. err = db.Find(&vms).Error
  5982. } else {
  5983. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  5984. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  5985. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  5986. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  5987. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ?", orgID, scheduleDate, deliverWay, patient_id).
  5988. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  5989. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  5990. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  5991. Where("status = 1 AND user_org_id = ?", orgID)
  5992. if scheduleDate != 0 {
  5993. db = db.Where("schedule_date = ?", scheduleDate)
  5994. }
  5995. err = db.Find(&vms).Error
  5996. }
  5997. }
  5998. }
  5999. } else {
  6000. if execution_state > 0 {
  6001. if cost_type > 0 {
  6002. if len(execution_frequency) > 0 {
  6003. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6004. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6005. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6006. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6007. 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).
  6008. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6009. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6010. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6011. Where("status = 1 AND user_org_id = ?", orgID)
  6012. if scheduleDate != 0 {
  6013. db = db.Where("schedule_date = ?", scheduleDate)
  6014. }
  6015. err = db.Find(&vms).Error
  6016. } else {
  6017. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6018. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6019. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6020. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6021. 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).
  6022. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6023. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6024. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6025. Where("status = 1 AND user_org_id = ?", orgID)
  6026. if scheduleDate != 0 {
  6027. db = db.Where("schedule_date = ?", scheduleDate)
  6028. }
  6029. err = db.Find(&vms).Error
  6030. }
  6031. } else {
  6032. if len(execution_frequency) > 0 {
  6033. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6034. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6035. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6036. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6037. 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).
  6038. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6039. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6040. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6041. Where("status = 1 AND user_org_id = ?", orgID)
  6042. if scheduleDate != 0 {
  6043. db = db.Where("schedule_date = ?", scheduleDate)
  6044. }
  6045. err = db.Find(&vms).Error
  6046. } else {
  6047. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6048. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6049. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6050. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6051. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_state = ?", orgID, scheduleDate, deliverWay, execution_state).
  6052. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6053. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6054. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6055. Where("status = 1 AND user_org_id = ?", orgID)
  6056. if scheduleDate != 0 {
  6057. db = db.Where("schedule_date = ?", scheduleDate)
  6058. }
  6059. err = db.Find(&vms).Error
  6060. }
  6061. }
  6062. } else {
  6063. if cost_type > 0 {
  6064. if len(execution_frequency) > 0 {
  6065. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6066. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6067. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6068. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6069. 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).
  6070. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6071. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6072. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6073. Where("status = 1 AND user_org_id = ?", orgID)
  6074. if scheduleDate != 0 {
  6075. db = db.Where("schedule_date = ?", scheduleDate)
  6076. }
  6077. err = db.Find(&vms).Error
  6078. } else {
  6079. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6080. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6081. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6082. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6083. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and is_settle = ?", orgID, scheduleDate, deliverWay, cost_type).
  6084. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6085. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6086. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6087. Where("status = 1 AND user_org_id = ?", orgID)
  6088. if scheduleDate != 0 {
  6089. db = db.Where("schedule_date = ?", scheduleDate)
  6090. }
  6091. err = db.Find(&vms).Error
  6092. }
  6093. } else {
  6094. if len(execution_frequency) > 0 {
  6095. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6096. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6097. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6098. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6099. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_frequency = ?", orgID, scheduleDate, deliverWay, execution_frequency).
  6100. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6101. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6102. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6103. Where("status = 1 AND user_org_id = ?", orgID)
  6104. if scheduleDate != 0 {
  6105. db = db.Where("schedule_date = ?", scheduleDate)
  6106. }
  6107. err = db.Find(&vms).Error
  6108. } else {
  6109. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6110. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6111. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6112. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6113. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  6114. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6115. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6116. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6117. Where("status = 1 AND user_org_id = ?", orgID)
  6118. if scheduleDate != 0 {
  6119. db = db.Where("schedule_date = ?", scheduleDate)
  6120. }
  6121. err = db.Find(&vms).Error
  6122. }
  6123. }
  6124. }
  6125. }
  6126. } else {
  6127. db := readDb.Table("xt_schedule")
  6128. if scheduleType > 0 {
  6129. db = db.Where("schedule_type = ?", scheduleType)
  6130. }
  6131. if partitionType > 0 {
  6132. db = db.Where("partition_id = ?", partitionType)
  6133. }
  6134. if patient_id > 0 {
  6135. if execution_state > 0 {
  6136. if cost_type > 0 {
  6137. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  6138. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6139. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6140. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  6141. 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).
  6142. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6143. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6144. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6145. Where("status = 1 AND user_org_id = ?", orgID)
  6146. if scheduleDate != 0 {
  6147. db = db.Where("schedule_date = ?", scheduleDate)
  6148. }
  6149. err = db.Find(&vms).Error
  6150. } else {
  6151. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  6152. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6153. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6154. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  6155. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and execution_state = ?", orgID, scheduleDate, patient_id, execution_state).
  6156. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6157. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6158. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6159. Where("status = 1 AND user_org_id = ?", orgID)
  6160. if scheduleDate != 0 {
  6161. db = db.Where("schedule_date = ?", scheduleDate)
  6162. }
  6163. err = db.Find(&vms).Error
  6164. }
  6165. } else {
  6166. if cost_type > 0 {
  6167. if len(execution_frequency) > 0 {
  6168. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  6169. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6170. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6171. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  6172. 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).
  6173. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6174. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6175. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6176. Where("status = 1 AND user_org_id = ?", orgID)
  6177. if scheduleDate != 0 {
  6178. db = db.Where("schedule_date = ?", scheduleDate)
  6179. }
  6180. err = db.Find(&vms).Error
  6181. } else {
  6182. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  6183. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6184. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6185. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  6186. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and is_settle = ?", orgID, scheduleDate, patient_id, cost_type).
  6187. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6188. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6189. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6190. Where("status = 1 AND user_org_id = ?", orgID)
  6191. if scheduleDate != 0 {
  6192. db = db.Where("schedule_date = ?", scheduleDate)
  6193. }
  6194. err = db.Find(&vms).Error
  6195. }
  6196. } else {
  6197. if len(execution_frequency) > 0 {
  6198. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  6199. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6200. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6201. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  6202. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and execution_frequency = ?", orgID, scheduleDate, patient_id, execution_frequency).
  6203. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6204. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6205. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6206. Where("status = 1 AND user_org_id = ?", orgID)
  6207. if scheduleDate != 0 {
  6208. db = db.Where("schedule_date = ?", scheduleDate)
  6209. }
  6210. err = db.Find(&vms).Error
  6211. } else {
  6212. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  6213. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6214. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6215. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  6216. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  6217. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6218. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6219. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6220. Where("status = 1 AND user_org_id = ?", orgID)
  6221. if scheduleDate != 0 {
  6222. db = db.Where("schedule_date = ?", scheduleDate)
  6223. }
  6224. err = db.Find(&vms).Error
  6225. }
  6226. }
  6227. }
  6228. } else {
  6229. if execution_state > 0 {
  6230. if cost_type > 0 {
  6231. if len(execution_frequency) > 0 {
  6232. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6233. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6234. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6235. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6236. 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).
  6237. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6238. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6239. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6240. Where("status = 1 AND user_org_id = ?", orgID)
  6241. if scheduleDate != 0 {
  6242. db = db.Where("schedule_date = ?", scheduleDate)
  6243. }
  6244. err = db.Find(&vms).Error
  6245. } else {
  6246. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6247. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6248. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6249. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6250. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ? and is_settle = ?", orgID, scheduleDate, execution_state, cost_type).
  6251. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6252. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6253. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6254. Where("status = 1 AND user_org_id = ?", orgID)
  6255. if scheduleDate != 0 {
  6256. db = db.Where("schedule_date = ?", scheduleDate)
  6257. }
  6258. err = db.Find(&vms).Error
  6259. }
  6260. } else {
  6261. if len(execution_frequency) > 0 {
  6262. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6263. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6264. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6265. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6266. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ? and execution_frequency = ?", orgID, scheduleDate, execution_state, execution_frequency).
  6267. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6268. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6269. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6270. Where("status = 1 AND user_org_id = ?", orgID)
  6271. if scheduleDate != 0 {
  6272. db = db.Where("schedule_date = ?", scheduleDate)
  6273. }
  6274. err = db.Find(&vms).Error
  6275. } else {
  6276. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6277. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6278. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6279. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6280. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ?", orgID, scheduleDate, execution_state).
  6281. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6282. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6283. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6284. Where("status = 1 AND user_org_id = ?", orgID)
  6285. if scheduleDate != 0 {
  6286. db = db.Where("schedule_date = ?", scheduleDate)
  6287. }
  6288. err = db.Find(&vms).Error
  6289. }
  6290. }
  6291. } else {
  6292. if cost_type > 0 {
  6293. if len(execution_frequency) > 0 {
  6294. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6295. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6296. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6297. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6298. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and is_settle = ?", orgID, scheduleDate, cost_type).
  6299. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6300. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6301. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6302. Where("status = 1 AND user_org_id = ?", orgID)
  6303. if scheduleDate != 0 {
  6304. db = db.Where("schedule_date = ?", scheduleDate)
  6305. }
  6306. err = db.Find(&vms).Error
  6307. } else {
  6308. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6309. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6310. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6311. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6312. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and is_settle = ? and execution_frequency = ?", orgID, scheduleDate, cost_type, execution_frequency).
  6313. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6314. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6315. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6316. Where("status = 1 AND user_org_id = ?", orgID)
  6317. if scheduleDate != 0 {
  6318. db = db.Where("schedule_date = ?", scheduleDate)
  6319. }
  6320. err = db.Find(&vms).Error
  6321. }
  6322. } else {
  6323. if len(execution_frequency) > 0 {
  6324. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6325. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6326. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6327. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6328. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_frequency = ?", orgID, scheduleDate, execution_frequency).
  6329. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6330. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6331. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6332. Where("status = 1 AND user_org_id = ?", orgID)
  6333. if scheduleDate != 0 {
  6334. db = db.Where("schedule_date = ?", scheduleDate)
  6335. }
  6336. err = db.Find(&vms).Error
  6337. } else {
  6338. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6339. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6340. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6341. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6342. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ?", orgID, scheduleDate).
  6343. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6344. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6345. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6346. Where("status = 1 AND user_org_id = ?", orgID)
  6347. if scheduleDate != 0 {
  6348. db = db.Where("schedule_date = ?", scheduleDate)
  6349. }
  6350. err = db.Find(&vms).Error
  6351. }
  6352. }
  6353. }
  6354. }
  6355. }
  6356. return vms, err
  6357. }