mobile_dialysis_service.go 539KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006
  1. package service
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "strconv"
  6. "time"
  7. "XT_New/models"
  8. "github.com/jinzhu/gorm"
  9. )
  10. // func GetSchedualPatients(orgID int64) ([]*MDialysisScheduleVM, error) {
  11. // var vms []*MDialysisScheduleVM
  12. // err := readDb.
  13. // Table("xt_schedule as sch").
  14. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  15. // Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  16. // Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
  17. // Preload("TreatmentMode", "status = 1").
  18. // Preload("DialysisOrder", "status = 1 AND user_org_id = ?", orgID).
  19. // Preload("DialysisOrder.MonitoringRecords", "status = 1 AND user_org_id = ?", orgID).
  20. // Where("sch.status = 1 AND sch.user_org_id = ? AND schedule_date = 1536768000", orgID).
  21. // Find(&vms).
  22. // Error
  23. // return vms, err
  24. // }
  25. func MobileGetDialysisScheduals(orgID int64, scheduleDate int64, scheduleType int64) ([]*MDialysisScheduleVMForList, error) {
  26. var vms []*MDialysisScheduleVMForList
  27. db := readDb.
  28. Table("xt_schedule as sch").
  29. Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
  30. if scheduleDate != 0 {
  31. db = db.Where("schedule_date = ?", scheduleDate)
  32. }
  33. if scheduleType != 0 {
  34. db = db.Where("schedule_type = ?", scheduleType)
  35. }
  36. err := db.Find(&vms).Error
  37. //err := db.Preload("DialysisLastOrder", func(db *gorm.DB) *gorm.DB {
  38. // return db.Order("dialysis_date desc").Where(" status = 1 AND user_org_id = ? and dialysis_date>=1672502400 && dialysis_date < ?", orgID, scheduleDate)
  39. //}).Preload("DialysisSolution", "status = 1 and user_org_id = ? and solution_status = 1", orgID).Find(&vms).Error
  40. return vms, err
  41. }
  42. func GetMonitDialysisOrder(user_org_id int64, patient_id int64, scheduleDate int64) (*models.MDialysisOrderForList, error) {
  43. order := models.MDialysisOrderForList{}
  44. err := XTReadDB().Where("user_org_id = ? and status =1 and patient_id = ?", user_org_id, patient_id).Order("id desc").Last(&order).Error
  45. return &order, err
  46. }
  47. func GetMonitDialysisSolution(user_org_id int64, patient_id int64, mode_id int64) (*models.DialysisSolution, error) {
  48. solution := models.DialysisSolution{}
  49. err := XTReadDB().Where("user_org_id = ? and patient_id =? and solution_status = 1 and mode_id = ? and status=1", user_org_id, patient_id, mode_id).Find(&solution).Error
  50. return &solution, err
  51. }
  52. func MobileGetWaitingScheduals(orgID int64, scheduleDate int64) ([]*MDialysisScheduleVM, error) {
  53. var vms []*MDialysisScheduleVM
  54. db := readDb.
  55. Table("xt_schedule as sch").
  56. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  57. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  58. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  59. // Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
  60. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  61. Preload("AssessmentBeforeDislysis", "status = 1 AND user_org_id = ? AND assessment_date = ? ", orgID, scheduleDate).
  62. Preload("DialysisOrder", "status = 1 AND user_org_id = ?", orgID).
  63. Preload("Advices", "status = 1 AND user_org_id = ? AND advice_type = 2 ", orgID).
  64. Preload("TreatmentMode", "status = 1").
  65. Preload("TreatmentSummary", "status = 1 AND user_org_id = ?", orgID).
  66. Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
  67. if scheduleDate != 0 {
  68. db = db.Where("schedule_date = ?", scheduleDate)
  69. }
  70. err := db.Find(&vms).Error
  71. return vms, err
  72. }
  73. type VMTreatmentSummary struct {
  74. ID int64 `gorm:"column:id" json:"id"`
  75. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  76. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  77. AssessmentDate int64 `gorm:"column:assessment_date" json:"assessment_date"`
  78. DialysisSummary string `gorm:"column:dialysis_summary" json:"dialysis_summary" form:"dialysis_summary"`
  79. }
  80. func (VMTreatmentSummary) TableName() string {
  81. return "xt_treatment_summary"
  82. }
  83. type AssessmentAfterDislysis struct {
  84. ID int64 `gorm:"column:id" json:"id"`
  85. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  86. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  87. AssessmentDate int64 `gorm:"column:assessment_date" json:"assessment_date"`
  88. WeightAfter float64 `gorm:"column:weight_after" json:"weight_after"`
  89. Status int64 `gorm:"column:status" json:"status"`
  90. }
  91. func (AssessmentAfterDislysis) TableName() string {
  92. return "xt_assessment_after_dislysis"
  93. }
  94. type MDialysisScheduleVM struct {
  95. ID int64 `gorm:"column:id" json:"id"`
  96. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  97. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  98. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  99. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  100. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  101. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  102. ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week"`
  103. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  104. Status int64 `gorm:"column:status" json:"status"`
  105. SchedualPatient *MSchedualPatientVMList `gorm:"ForeignKey:PatientId" json:"patient"`
  106. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  107. DialysisOrder *MDialysisOrderVMList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  108. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  109. AssessmentBeforeDislysis *models.PredialysisEvaluationList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_before_dislysis"`
  110. AssessmentAfterDislysis *AssessmentAfterDislysis `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_after_dislysis"`
  111. HisAdvices []*VMHisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"his_doctor_advice"`
  112. Advices []*VMDoctorAdvice `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  113. TreatmentSummary *VMTreatmentSummary `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"treatment_summary"`
  114. NewDeviceInformation *NewDeviceInformation `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"device_information"`
  115. }
  116. func (MDialysisScheduleVM) TableName() string {
  117. return "xt_schedule"
  118. }
  119. type MDialysisScheduleVMForList struct {
  120. ID int64 `gorm:"column:id" json:"id"`
  121. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  122. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  123. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  124. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  125. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  126. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  127. ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week"`
  128. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  129. Status int64 `gorm:"column:status" json:"status"`
  130. SchedualPatient *models.MSchedualPatientList `gorm:"ForeignKey:PatientId" json:"patient"`
  131. DeviceNumber *models.MDeviceNumberForList `gorm:"ForeignKey:BedId" json:"device_number"`
  132. DialysisOrder *models.MDialysisOrderForList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  133. DialysisLastOrder *models.MDialysisOrderForList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"last_order"`
  134. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  135. AssessmentBeforeDislysis *models.PredialysisEvaluationList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_before_dislysis"`
  136. AssessmentAfterDislysis *models.VMAssessmentAfterDislysis `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_after_dislysis"`
  137. HisAdvices []VMHisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"his_doctor_advice"`
  138. Advices []models.VMDoctorAdviceForList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  139. TreatmentSummary *models.VMTreatmentSummaryForList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"treatment_summary"`
  140. DialysisSolution *models.DialysisSolution `gorm:"ForeignKey:PatientId,ModeId;AssociationForeignKey:PatientId,ModeId" json:"dialysis_solution"`
  141. DoubleCheck *models.DoubleCheck `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dobule_check"`
  142. NewDeviceInformation *NewDeviceInformation `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"device_information"`
  143. //VMMonitoringRecord []models.VMMonitoringRecord `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"monitor_record"`
  144. }
  145. func (MDialysisScheduleVMForList) TableName() string {
  146. return "xt_schedule"
  147. }
  148. type MDeviceNumberVM struct {
  149. models.DeviceNumber
  150. Zone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"zone"`
  151. }
  152. func (MDeviceNumberVM) TableName() string {
  153. return "xt_device_number"
  154. }
  155. type MSchedualPatientVMList struct {
  156. ID int64 `gorm:"column:id" json:"id" form:"id"`
  157. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  158. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  159. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  160. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
  161. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  162. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  163. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  164. Age int64 `gorm:"column:age" json:"age"`
  165. Name string `gorm:"column:name" json:"name" form:"name"`
  166. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  167. UserSysBeforeCount int64 `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
  168. TrobleShoot int64 `gorm:"column:troble_shoot" json:"troble_shoot" form:"troble_shoot"`
  169. SchRemark string `gorm:"column:sch_remark" json:"sch_remark" form:"sch_remark"`
  170. ScheduleRemark string `gorm:"column:schedule_remark" json:"schedule_remark" form:"schedule_remark"`
  171. FirstLetter string `gorm:"column:first_letter" json:"first_letter" form:"first_letter"`
  172. }
  173. func (MSchedualPatientVMList) TableName() string {
  174. return "xt_patients"
  175. }
  176. type MSchedualPatientVM struct {
  177. ID int64 `gorm:"column:id" json:"id" form:"id"`
  178. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  179. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  180. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  181. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  182. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
  183. AdmissionNumber string `gorm:"column:admission_number" json:"admission_number" form:"admission_number"`
  184. Source int64 `gorm:"column:source" json:"source" form:"source"`
  185. Lapseto int64 `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
  186. PartitionId int64 `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
  187. BedId int64 `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
  188. Name string `gorm:"column:name" json:"name" form:"name"`
  189. Alias string `gorm:"column:alias" json:"alias" form:"alias"`
  190. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  191. Nation string `gorm:"column:nation" json:"nation" form:"nation"`
  192. NativePlace string `gorm:"column:native_place" json:"native_place" form:"native_place"`
  193. MaritalStatus int64 `gorm:"column:marital_status" json:"marital_status" form:"marital_status"`
  194. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  195. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  196. ReimbursementWayId int64 `gorm:"column:reimbursement_way_id" json:"reimbursement_way_id" form:"reimbursement_way_id"`
  197. HealthCareType int64 `gorm:"column:health_care_type" json:"health_care_type" form:"health_care_type"`
  198. HealthCareNo string `gorm:"column:health_care_no" json:"health_care_no" form:"health_care_no"`
  199. HealthCareDueDate int64 `gorm:"column:health_care_due_date" json:"health_care_due_date" form:"health_care_due_date"`
  200. Height int64 `gorm:"column:height" json:"height" form:"height"`
  201. BloodType int64 `gorm:"column:blood_type" json:"blood_type" form:"blood_type"`
  202. Rh int64 `gorm:"column:rh" json:"rh" form:"rh"`
  203. HealthCareDueAlertDate int64 `gorm:"column:health_care_due_alert_date" json:"health_care_due_alert_date" form:"health_care_due_alert_date"`
  204. EducationLevel int64 `gorm:"column:education_level" json:"education_level" form:"education_level"`
  205. Profession int64 `gorm:"column:profession" json:"profession" form:"profession"`
  206. Phone string `gorm:"column:phone" json:"phone" form:"phone"`
  207. HomeTelephone string `gorm:"column:home_telephone" json:"home_telephone" form:"home_telephone"`
  208. RelativePhone string `gorm:"column:relative_phone" json:"relative_phone" form:"relative_phone"`
  209. RelativeRelations string `gorm:"column:relative_relations" json:"relative_relations" form:"relative_relations"`
  210. HomeAddress string `gorm:"column:home_address" json:"home_address" form:"home_address"`
  211. WorkUnit string `gorm:"column:work_unit" json:"work_unit" form:"work_unit"`
  212. UnitAddress string `gorm:"column:unit_address" json:"unit_address" form:"unit_address"`
  213. Children int64 `gorm:"column:children" json:"children" form:"children"`
  214. ReceivingDate int64 `gorm:"column:receiving_date" json:"receiving_date" form:"receiving_date"`
  215. IsHospitalFirstDialysis int64 `gorm:"column:is_hospital_first_dialysis" json:"is_hospital_first_dialysis" form:"is_hospital_first_dialysis"`
  216. FirstDialysisDate int64 `gorm:"column:first_dialysis_date" json:"first_dialysis_date" form:"first_dialysis_date"`
  217. FirstDialysisHospital string `gorm:"column:first_dialysis_hospital" json:"first_dialysis_hospital" form:"first_dialysis_hospital"`
  218. InductionPeriod int64 `gorm:"column:induction_period" json:"induction_period" form:"induction_period"`
  219. InitialDialysis int64 `gorm:"column:initial_dialysis" json:"initial_dialysis" form:"initial_dialysis"`
  220. TotalDialysis int64 `gorm:"column:total_dialysis" json:"total_dialysis" form:"total_dialysis"`
  221. AttendingDoctorId int64 `gorm:"column:attending_doctor_id" json:"attending_doctor_id" form:"attending_doctor_id"`
  222. HeadNurseId int64 `gorm:"column:head_nurse_id" json:"head_nurse_id" form:"head_nurse_id"`
  223. Evaluate string `gorm:"column:evaluate" json:"evaluate" form:"evaluate"`
  224. Diagnose string `gorm:"column:diagnose" json:"diagnose" form:"diagnose"`
  225. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  226. RegistrarsId int64 `gorm:"column:registrars_id" json:"registrars_id" form:"registrars_id"`
  227. Registrars string `gorm:"column:registrars" json:"registrars" form:"registrars"`
  228. QrCode string `gorm:"column:qr_code" json:"qr_code" form:"qr_code"`
  229. BindingState int64 `gorm:"column:binding_state" json:"binding_state" form:"binding_state"`
  230. PatientComplains string `gorm:"column:patient_complains" json:"patient_complains"` // 主诉
  231. PresentHistory string `gorm:"column:present_history" json:"present_history"` // 现病史
  232. PastHistory string `gorm:"column:past_history" json:"past_history"` // 既往史
  233. Temperature float64 `gorm:"column:temperature" json:"temperature"` // 体格检查-体温
  234. Pulse int64 `gorm:"column:pulse" json:"pulse"` // 体格检查-脉搏
  235. Respiratory int64 `gorm:"column:respiratory" json:"respiratory"` // 体格检查-呼吸频率
  236. SBP int64 `gorm:"column:sbp" json:"sbp"` // 体格检查-收缩压
  237. DBP int64 `gorm:"column:dbp" json:"dbp"` // 体格检查-舒张压
  238. Status int64 `gorm:"column:status" json:"status" form:"status"`
  239. Age int64 `gorm:"column:age" json:"age"`
  240. IsOpenRemind int64 `gorm:"column:is_open_remind" json:"is_open_remind"`
  241. DialysisAge int64 `gorm:"column:dialysis_age" json:"dialysis_age" form:"dialysis_age"`
  242. ExpenseKind int64 `gorm:"column:expense_kind" json:"expense_kind" form:"expense_kind"`
  243. TellPhone string `gorm:"column:tell_phone" json:"tell_phone" form:"tell_phone"`
  244. FirstTreatmentDate int64 `gorm:"column:first_treatment_date" json:"first_treatment_date" form:"first_treatment_date"`
  245. ContactName string `gorm:"column:contact_name" json:"contact_name" form:"contact_name"`
  246. UserSysBeforeCount int64 `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
  247. FirstLetter string `gorm:"column:first_letter" json:"first_letter" form:"first_letter"`
  248. }
  249. func (MSchedualPatientVM) TableName() string {
  250. return "xt_patients"
  251. }
  252. type MDialysisOrderVM struct {
  253. ID int64 `gorm:"column:id" json:"id"`
  254. DialysisDate int64 `gorm:"column:dialysis_date" json:"dialysis_date"`
  255. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  256. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  257. Stage int64 `gorm:"column:stage" json:"stage"`
  258. BedID int64 `gorm:"column:bed_id" json:"bed_id"`
  259. StartNurse int64 `gorm:"column:start_nurse" json:"start_nurse"`
  260. FinishNurse int64 `gorm:"column:finish_nurse" json:"finish_nurse"`
  261. Status int64 `gorm:"column:status" json:"status"`
  262. PunctureNurse int64 `gorm:"column:puncture_nurse" json:"puncture_nurse"`
  263. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedID" json:"device_number"`
  264. MonitoringRecords []*models.MonitoringRecord `gorm:"ForeignKey:DialysisOrderId" json:"monitoring_records"`
  265. Creator int64 `gorm:"column:creator" json:"creator"`
  266. Modifier int64 `gorm:"column:modifier" json:"modifier"`
  267. FinishCreator int64 `gorm:"column:finish_creator" json:"finish_creator"`
  268. FinishModifier int64 `gorm:"column:finish_modifier" json:"finish_modifier"`
  269. SchedualType int64 `gorm:"column:schedual_type" json:"schedual_type"`
  270. WashpipeNurse int64 `gorm:"column:washpipe_nurse" json:"washpipe_nurse" form:"washpipe_nurse"`
  271. DialysisIrrigation string `gorm:"column:dialysis_irrigation" json:"dialysis_irrigation" form:"dialysis_irrigation"`
  272. DialysisDialyszers string `gorm:"column:dialysis_dialyszers" json:"dialysis_dialyszers" form:"dialysis_dialyszers"`
  273. }
  274. func (MDialysisOrderVM) TableName() string {
  275. return "xt_dialysis_order"
  276. }
  277. type MDialysisOrderVMList struct {
  278. ID int64 `gorm:"column:id" json:"id"`
  279. DialysisDate int64 `gorm:"column:dialysis_date" json:"dialysis_date"`
  280. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  281. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  282. // PrescriptionId int64 `gorm:"column:prescription_id" json:"prescription_id"`
  283. Stage int64 `gorm:"column:stage" json:"stage"`
  284. // Remark string `gorm:"column:remark" json:"remark"`
  285. BedID int64 `gorm:"column:bed_id" json:"bed_id"`
  286. StartNurse int64 `gorm:"column:start_nurse" json:"start_nurse"`
  287. Status int64 `gorm:"column:status" json:"status"`
  288. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedID" json:"device_number"`
  289. Creator int64 `gorm:"column:creator" json:"creator"`
  290. WashpipeNurse int64 `gorm:"column:washpipe_nurse" json:"washpipe_nurse" form:"washpipe_nurse"`
  291. NucleinDate int64 `gorm:"column:nuclein_date" json:"nuclein_date" form:"nuclein_date"`
  292. DialysisIrrigation string `gorm:"column:dialysis_irrigation" json:"dialysis_irrigation" form:"dialysis_irrigation"`
  293. DialysisDialyszers string `gorm:"column:dialysis_dialyszers" json:"dialysis_dialyszers" form:"dialysis_dialyszers"`
  294. ScheduleRemark string `gorm:"column:schedule_remark" json:"schedule_remark" form:"schedule_remark"`
  295. }
  296. func (MDialysisOrderVMList) TableName() string {
  297. return "xt_dialysis_order"
  298. }
  299. type VMDoctorAdvice struct {
  300. ID int64 `gorm:"column:id" json:"id" form:"id"`
  301. GroupNo int64 `gorm:"column:groupno" json:"groupno" form:"groupno"`
  302. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  303. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  304. AdviceDate int64 `gorm:"column:advice_date" json:"advice_date" form:"advice_date"`
  305. Status int64 `gorm:"column:status" json:"status" form:"status"`
  306. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
  307. RecordDate int64 `gorm:"column:record_date" json:"record_date"`
  308. CheckTime int64 `gorm:"column:check_time" json:"check_time" form:"check_time"`
  309. CheckState int64 `gorm:"column:check_state" json:"check_state" form:"check_state"`
  310. ParentId int64 `gorm:"column:parent_id" json:"parent_id" form:"parent_id"`
  311. }
  312. func (VMDoctorAdvice) TableName() string {
  313. return "xt_doctor_advice"
  314. }
  315. type VMHisDoctorAdviceInfo struct {
  316. ID int64 `gorm:"column:id" json:"id" form:"id"`
  317. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  318. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  319. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  320. ExecutionTime int64 `gorm:"column:execution_time" json:"execution_time" form:"execution_time"`
  321. ExecutionStaff int64 `gorm:"column:execution_staff" json:"execution_staff" form:"execution_staff"`
  322. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
  323. IsMedicine int64 `gorm:"column:is_medicine" json:"is_medicine" form:"is_medicine"`
  324. ExecutionFrequencyId int64 `gorm:"column:execution_frequency_id" json:"execution_frequency_id" form:"execution_frequency_id"`
  325. IsSelfDrug int64 `gorm:"column:is_self_drug" json:"is_self_drug" form:"is_self_drug"`
  326. }
  327. func (VMHisDoctorAdviceInfo) TableName() string {
  328. return "his_doctor_advice_info"
  329. }
  330. type VMAssessmentAfterDislysis struct {
  331. ID int64 `gorm:"column:id" json:"id"`
  332. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  333. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  334. AssessmentDate int64 `gorm:"column:assessment_date" json:"assessment_date"`
  335. WeightAfter float64 `gorm:"column:weight_after" json:"weight_after"`
  336. Status int64 `gorm:"column:status" json:"status"`
  337. }
  338. func (VMAssessmentAfterDislysis) TableName() string {
  339. return "xt_assessment_after_dislysis"
  340. }
  341. type NewDeviceInformation struct {
  342. ID int64 `gorm:"column:id" json:"id" form:"id"`
  343. Date int64 `gorm:"column:date" json:"date" form:"date"`
  344. Class int64 `gorm:"column:class" json:"class" form:"class"`
  345. Zone int64 `gorm:"column:zone" json:"zone" form:"zone"`
  346. BedNumber int64 `gorm:"column:bed_number" json:"bed_number" form:"bed_number"`
  347. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  348. Status int64 `gorm:"column:status" json:"status" form:"status"`
  349. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  350. EquimentId int64 `gorm:"column:equiment_id" json:"equiment_id" form:"equiment_id"`
  351. Bed string `gorm:"column:bed" json:"bed" form:"bed"`
  352. Stime int64 `gorm:"column:stime" json:"stime" form:"stime"`
  353. }
  354. func (NewDeviceInformation) TableName() string {
  355. return "xt_device_information"
  356. }
  357. // 获取透析记录
  358. func MobileGetDialysisRecord(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  359. var record models.DialysisOrder
  360. err := readDb.Model(&models.DialysisOrder{}).Where("user_org_id = ? AND patient_id = ? AND dialysis_date = ?", orgID, patientID, recordDate).First(&record).Error
  361. if err != nil {
  362. if err == gorm.ErrRecordNotFound {
  363. return nil, nil
  364. } else {
  365. return nil, err
  366. }
  367. }
  368. return &record, nil
  369. }
  370. // 用户基本信息
  371. func MobileGetPatientDetail(orgID int64, patientID int64) (*MPatient, error) {
  372. var patient MPatient
  373. //err := readDb.Model(&MPatient{}).Where("status = 1 AND user_org_id = ? AND id = ?", orgID, patientID).First(&patient).Error
  374. //if err != nil {
  375. // if err == gorm.ErrRecordNotFound {
  376. // return nil, nil
  377. // } else {
  378. // return nil, err
  379. // }
  380. //}
  381. //return &patient, nil
  382. redis := RedisClient()
  383. defer redis.Close()
  384. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":patient_info"
  385. patient_info_str, _ := redis.Get(key).Result()
  386. if len(patient_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  387. err = readDb.Model(&patient).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
  388. if err != nil {
  389. if err == gorm.ErrRecordNotFound {
  390. return &patient, nil
  391. } else {
  392. return &patient, err
  393. }
  394. } else {
  395. if patient.ID > 0 {
  396. //缓存数据
  397. patient_info_json, err := json.Marshal(&patient)
  398. if err == nil {
  399. redis.Set(key, patient_info_json, time.Second*60*60*18)
  400. }
  401. }
  402. return &patient, nil
  403. }
  404. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  405. json.Unmarshal([]byte(patient_info_str), &patient)
  406. return &patient, nil
  407. }
  408. }
  409. func MobileGetSchedualDetailOne(orgID int64, patientID int64, schedualDate int64) (*MDialysisScheduleVM, error) {
  410. var vm MDialysisScheduleVM
  411. err := readDb.
  412. Table("xt_schedule").
  413. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  414. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  415. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  416. First(&vm).Error
  417. return &vm, err
  418. }
  419. // 用户排班信息
  420. func MobileGetSchedualDetailSix(orgID int64, patientID int64, schedualDate int64) (*MDialysisScheduleVM, error) {
  421. var vm MDialysisScheduleVM
  422. err := readDb.
  423. Table("xt_schedule").
  424. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  425. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  426. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  427. First(&vm).Error
  428. if err != nil {
  429. if err == gorm.ErrRecordNotFound {
  430. return nil, nil
  431. } else {
  432. return nil, err
  433. }
  434. }
  435. return &vm, err
  436. }
  437. // 用户排班信息
  438. func MobileGetSchedualDetail(orgID int64, patientID int64, schedualDate int64) (*MDialysisScheduleVM, error) {
  439. redis := RedisClient()
  440. defer redis.Close()
  441. var vm MDialysisScheduleVM
  442. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(schedualDate, 10) + ":schedual_detail"
  443. redis.Set(key, "", time.Second)
  444. schedual_detail_str, _ := redis.Get(key).Result()
  445. if len(schedual_detail_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  446. err := readDb.
  447. Table("xt_schedule").
  448. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  449. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  450. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  451. First(&vm).Error
  452. if err != nil {
  453. if err == gorm.ErrRecordNotFound {
  454. return nil, nil
  455. } else {
  456. return nil, err
  457. }
  458. } else {
  459. if vm.ID > 0 {
  460. //缓存数据
  461. schedual_detail_str, err := json.Marshal(vm)
  462. if err == nil {
  463. redis.Set(key, schedual_detail_str, time.Second*60*60*18)
  464. }
  465. } else {
  466. redis.Set(key, "null", time.Second*60*60*18)
  467. }
  468. return &vm, nil
  469. }
  470. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  471. if schedual_detail_str == "null" {
  472. return &vm, nil
  473. }
  474. json.Unmarshal([]byte(schedual_detail_str), &vm)
  475. return &vm, nil
  476. }
  477. }
  478. // 用户排班信息
  479. func MobileGetPatientSchedual(orgID int64, patientID int64, schedualDate int64) (*models.Schedule, error) {
  480. var schedule models.Schedule
  481. err := readDb.
  482. Table("xt_schedule").
  483. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  484. First(&schedule).Error
  485. if err != nil {
  486. if err == gorm.ErrRecordNotFound {
  487. return nil, nil
  488. } else {
  489. return nil, err
  490. }
  491. }
  492. return &schedule, nil
  493. }
  494. type MPatient struct {
  495. ID int64 `gorm:"column:id" json:"id" form:"id"`
  496. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  497. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  498. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  499. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  500. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
  501. AdmissionNumber string `gorm:"column:admission_number" json:"admission_number" form:"admission_number"`
  502. Source int64 `gorm:"column:source" json:"source" form:"source"`
  503. Lapseto int64 `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
  504. PartitionId int64 `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
  505. BedId int64 `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
  506. Name string `gorm:"column:name" json:"name" form:"name"`
  507. Alias string `gorm:"column:alias" json:"alias" form:"alias"`
  508. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  509. Nation string `gorm:"column:nation" json:"nation" form:"nation"`
  510. NativePlace string `gorm:"column:native_place" json:"native_place" form:"native_place"`
  511. MaritalStatus int64 `gorm:"column:marital_status" json:"marital_status" form:"marital_status"`
  512. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  513. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  514. ReimbursementWayId int64 `gorm:"column:reimbursement_way_id" json:"reimbursement_way_id" form:"reimbursement_way_id"`
  515. HealthCareType int64 `gorm:"column:health_care_type" json:"health_care_type" form:"health_care_type"`
  516. HealthCareNo string `gorm:"column:health_care_no" json:"health_care_no" form:"health_care_no"`
  517. HealthCareDueDate int64 `gorm:"column:health_care_due_date" json:"health_care_due_date" form:"health_care_due_date"`
  518. Height int64 `gorm:"column:height" json:"height" form:"height"`
  519. BloodType int64 `gorm:"column:blood_type" json:"blood_type" form:"blood_type"`
  520. Rh int64 `gorm:"column:rh" json:"rh" form:"rh"`
  521. HealthCareDueAlertDate int64 `gorm:"column:health_care_due_alert_date" json:"health_care_due_alert_date" form:"health_care_due_alert_date"`
  522. EducationLevel int64 `gorm:"column:education_level" json:"education_level" form:"education_level"`
  523. Profession int64 `gorm:"column:profession" json:"profession" form:"profession"`
  524. Phone string `gorm:"column:phone" json:"phone" form:"phone"`
  525. HomeTelephone string `gorm:"column:home_telephone" json:"home_telephone" form:"home_telephone"`
  526. RelativePhone string `gorm:"column:relative_phone" json:"relative_phone" form:"relative_phone"`
  527. RelativeRelations string `gorm:"column:relative_relations" json:"relative_relations" form:"relative_relations"`
  528. HomeAddress string `gorm:"column:home_address" json:"home_address" form:"home_address"`
  529. WorkUnit string `gorm:"column:work_unit" json:"work_unit" form:"work_unit"`
  530. UnitAddress string `gorm:"column:unit_address" json:"unit_address" form:"unit_address"`
  531. Children int64 `gorm:"column:children" json:"children" form:"children"`
  532. ReceivingDate int64 `gorm:"column:receiving_date" json:"receiving_date" form:"receiving_date"`
  533. IsHospitalFirstDialysis int64 `gorm:"column:is_hospital_first_dialysis" json:"is_hospital_first_dialysis" form:"is_hospital_first_dialysis"`
  534. FirstDialysisDate int64 `gorm:"column:first_dialysis_date" json:"first_dialysis_date" form:"first_dialysis_date"`
  535. FirstDialysisHospital string `gorm:"column:first_dialysis_hospital" json:"first_dialysis_hospital" form:"first_dialysis_hospital"`
  536. InductionPeriod int64 `gorm:"column:induction_period" json:"induction_period" form:"induction_period"`
  537. InitialDialysis int64 `gorm:"column:initial_dialysis" json:"initial_dialysis" form:"initial_dialysis"`
  538. TotalDialysis int64 `gorm:"column:total_dialysis" json:"total_dialysis" form:"total_dialysis"`
  539. AttendingDoctorId int64 `gorm:"column:attending_doctor_id" json:"attending_doctor_id" form:"attending_doctor_id"`
  540. HeadNurseId int64 `gorm:"column:head_nurse_id" json:"head_nurse_id" form:"head_nurse_id"`
  541. Evaluate string `gorm:"column:evaluate" json:"evaluate" form:"evaluate"`
  542. Diagnose string `gorm:"column:diagnose" json:"diagnose" form:"diagnose"`
  543. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  544. RegistrarsId int64 `gorm:"column:registrars_id" json:"registrars_id" form:"registrars_id"`
  545. Registrars string `gorm:"column:registrars" json:"registrars" form:"registrars"`
  546. QrCode string `gorm:"column:qr_code" json:"qr_code" form:"qr_code"`
  547. BindingState int64 `gorm:"column:binding_state" json:"binding_state" form:"binding_state"`
  548. PatientComplains string `gorm:"column:patient_complains" json:"patient_complains"` // 主诉
  549. PresentHistory string `gorm:"column:present_history" json:"present_history"` // 现病史
  550. PastHistory string `gorm:"column:past_history" json:"past_history"` // 既往史
  551. Temperature float64 `gorm:"column:temperature" json:"temperature"` // 体格检查-体温
  552. Pulse int64 `gorm:"column:pulse" json:"pulse"` // 体格检查-脉搏
  553. Respiratory int64 `gorm:"column:respiratory" json:"respiratory"` // 体格检查-呼吸频率
  554. SBP int64 `gorm:"column:sbp" json:"sbp"` // 体格检查-收缩压
  555. DBP int64 `gorm:"column:dbp" json:"dbp"` // 体格检查-舒张压
  556. Status int64 `gorm:"column:status" json:"status" form:"status"`
  557. Age int64 `gorm:"column:age" json:"age"`
  558. IsOpenRemind int64 `gorm:"column:is_open_remind" json:"is_open_remind"`
  559. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  560. DialysisAge int64 `gorm:"column:dialysis_age" json:"dialysis_age" form:"dialysis_age"`
  561. ExpenseKind int64 `gorm:"column:expense_kind" json:"expense_kind" form:"expense_kind"`
  562. TellPhone string `gorm:"column:tell_phone" json:"tell_phone" form:"tell_phone"`
  563. FirstTreatmentDate int64 `gorm:"column:first_treatment_date" json:"first_treatment_date" form:"first_treatment_date"`
  564. ContactName string `gorm:"column:contact_name" json:"contact_name" form:"contact_name"`
  565. UserSysBeforeCount int64 `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
  566. }
  567. func (MPatient) TableName() string {
  568. return "xt_patients"
  569. }
  570. // 接诊评估
  571. func MobileGetReceiverTreatmentAccessRecord(orgID int64, patientID int64, recordDate int64) (*models.ReceiveTreatmentAsses, error) {
  572. var record models.ReceiveTreatmentAsses
  573. redis := RedisClient()
  574. defer redis.Close()
  575. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":receive_treatment_asses"
  576. receive_treatment_asses_str, _ := redis.Get(key).Result()
  577. if len(receive_treatment_asses_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  578. err = readDb.Model(&models.ReceiveTreatmentAsses{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  579. if err != nil {
  580. if err == gorm.ErrRecordNotFound {
  581. if record.ID <= 0 {
  582. redis.Set(key, "", time.Second*60*60*18)
  583. }
  584. return nil, nil
  585. } else {
  586. return nil, err
  587. }
  588. } else {
  589. if record.ID > 0 {
  590. //缓存数据
  591. receive_treatment_asses_str, err := json.Marshal(record)
  592. if err == nil {
  593. redis.Set(key, receive_treatment_asses_str, time.Second*60*60*18)
  594. }
  595. } else {
  596. redis.Set(key, "null", time.Second*60*60*18)
  597. }
  598. return &record, nil
  599. }
  600. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  601. if receive_treatment_asses_str == "null" {
  602. return &record, nil
  603. }
  604. json.Unmarshal([]byte(receive_treatment_asses_str), &record)
  605. return &record, nil
  606. }
  607. }
  608. // 透前评估
  609. func MobileGetPredialysisEvaluationOne(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
  610. var record models.PredialysisEvaluation
  611. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  612. if err != nil {
  613. if err == gorm.ErrRecordNotFound {
  614. return nil, nil
  615. } else {
  616. return nil, err
  617. }
  618. }
  619. return &record, nil
  620. }
  621. func MobileGetPredialysisEvaluationTwo(orgID int64, patientID int64, recordDate int64) (models.PredialysisEvaluation, error) {
  622. var record models.PredialysisEvaluation
  623. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  624. return record, err
  625. }
  626. // 透前评估
  627. func MobileGetPredialysisEvaluation(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
  628. var record models.PredialysisEvaluation
  629. redis := RedisClient()
  630. defer redis.Close()
  631. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":assessment_before_dislysis"
  632. assessment_before_dislysis_str, _ := redis.Get(key).Result()
  633. redis.Set(key, "", time.Second)
  634. if len(assessment_before_dislysis_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  635. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  636. if err != nil {
  637. if err == gorm.ErrRecordNotFound {
  638. if record.ID <= 0 {
  639. redis.Set(key, "", time.Second*60*60*18)
  640. }
  641. return nil, nil
  642. } else {
  643. return nil, err
  644. }
  645. } else {
  646. if record.ID > 0 {
  647. //缓存数据
  648. assessment_before_dislysis_str, err := json.Marshal(record)
  649. if err == nil {
  650. redis.Set(key, assessment_before_dislysis_str, time.Second*60*60*18)
  651. }
  652. } else {
  653. redis.Set(key, "null", time.Second*60*60*18)
  654. }
  655. return &record, nil
  656. }
  657. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  658. if assessment_before_dislysis_str == "null" {
  659. return &record, nil
  660. } else {
  661. json.Unmarshal([]byte(assessment_before_dislysis_str), &record)
  662. return &record, nil
  663. }
  664. }
  665. }
  666. // 获取 maxDate 之前一次的透前评估记录
  667. func MobileGetLastTimePredialysisEvaluationOne(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
  668. var record models.PredialysisEvaluation
  669. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date < ?", patientID, orgID, maxDate).Order("assessment_date desc").First(&record).Error
  670. if err != nil {
  671. if err == gorm.ErrRecordNotFound {
  672. return nil, nil
  673. } else {
  674. return nil, err
  675. }
  676. }
  677. return &record, nil
  678. }
  679. // 获取 maxDate 之前一次的透前评估记录
  680. func MobileGetLastTimePredialysisEvaluation(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
  681. var record models.PredialysisEvaluation
  682. redis := RedisClient()
  683. defer redis.Close()
  684. // cur_date := time.Now().Format("2006-01-02")
  685. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(maxDate, 10) + ":assessment_before_dislysis_last"
  686. assessment_before_dislysis_last_str, _ := redis.Get(key).Result()
  687. if len(assessment_before_dislysis_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  688. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date < ?", patientID, orgID, maxDate).Order("assessment_date desc").First(&record).Error
  689. if err != nil {
  690. if err == gorm.ErrRecordNotFound {
  691. if record.ID <= 0 {
  692. redis.Set(key, "", time.Second*60*60*18)
  693. }
  694. return nil, nil
  695. } else {
  696. return nil, err
  697. }
  698. } else {
  699. if record.ID > 0 {
  700. //缓存数据
  701. assessment_before_dislysis_last_str, err := json.Marshal(record)
  702. if err == nil {
  703. redis.Set(key, assessment_before_dislysis_last_str, time.Second*60*60*4)
  704. }
  705. } else {
  706. redis.Set(key, "null", time.Second*60*60*18)
  707. }
  708. return &record, nil
  709. }
  710. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  711. if assessment_before_dislysis_last_str == "null" {
  712. return &record, nil
  713. } else {
  714. json.Unmarshal([]byte(assessment_before_dislysis_last_str), &record)
  715. return &record, nil
  716. }
  717. }
  718. }
  719. // 临时医嘱
  720. func MobileGetDoctorAdvices(orgID int64, patientID int64, recordDate int64) ([]*models.DoctorAdvice, error) {
  721. var records []*models.DoctorAdvice
  722. // err := readDb.Model(&models.DoctorAdvice{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).Find(&records).Error
  723. err := readDb.
  724. Model(&models.DoctorAdvice{}).
  725. Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? and (advice_type = 2 or advice_type = 3)", patientID, orgID, recordDate).
  726. Select("id,user_org_id,patient_id,advice_type,advice_date,record_date,start_time,advice_name,advice_desc,reminder_date, drug_spec, drug_spec_unit,single_dose,single_dose_unit,prescribing_number,prescribing_number_unit,delivery_way,execution_frequency,advice_doctor,status,created_time,updated_time,advice_affirm,remark,stop_time,stop_reason,stop_doctor,stop_state,parent_id,execution_time,execution_staff,execution_state,checker, check_state, check_time,way,drug_id,drug_name_id,IF(parent_id>0, parent_id, id) as advice_order,groupno,is_medicine").
  727. Order("start_time asc, groupno desc, advice_order desc, id").
  728. Scan(&records).Error
  729. if err != nil {
  730. return nil, err
  731. }
  732. return records, nil
  733. }
  734. func MobileGetDoctorAdvicesByGroups(orgID int64, patientID int64, recordDate int64) ([]*models.DoctorAdvice, error) {
  735. var records []*models.DoctorAdvice
  736. redis := RedisClient()
  737. defer redis.Close()
  738. // cur_date := time.Now().Format("2006-01-02")
  739. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":doctor_advices"
  740. //fmt.Println("key23233232323323wi", key)
  741. redis.Set(key, "", time.Second)
  742. doctor_advices_str, _ := redis.Get(key).Result()
  743. if len(doctor_advices_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  744. err := readDb.Model(&models.DoctorAdvice{}).
  745. Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? and (advice_type = 2 || advice_type = 3)", patientID, orgID, recordDate).
  746. Select("id, user_org_id, patient_id, advice_type, advice_date, record_date, start_time, advice_name,advice_desc, reminder_date, drug_spec, drug_spec_unit, single_dose, single_dose_unit, prescribing_number, prescribing_number_unit, delivery_way, execution_frequency, advice_doctor, status, created_time,updated_time, advice_affirm, remark, stop_time, stop_reason, stop_doctor, stop_state, parent_id, execution_time, execution_staff, execution_state, checker, check_state, check_time, groupno,way,drug_id,is_medicine,drug_name_id, IF(parent_id > 0, parent_id, id) as advice_order").
  747. Order("start_time asc, groupno desc, advice_order desc, id asc").
  748. Scan(&records).Error
  749. if err != nil {
  750. if err == gorm.ErrRecordNotFound {
  751. if len(records) <= 0 {
  752. redis.Set(key, "", time.Second*60*60*18)
  753. }
  754. return nil, nil
  755. } else {
  756. return nil, err
  757. }
  758. } else {
  759. if len(records) > 0 {
  760. //缓存数据
  761. doctor_advices_str, err := json.Marshal(records)
  762. if err == nil {
  763. redis.Set(key, doctor_advices_str, time.Second*60*60*18)
  764. return records, nil
  765. }
  766. } else {
  767. redis.Set(key, "null", time.Second*60*60*18)
  768. return records, nil
  769. }
  770. return records, nil
  771. }
  772. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  773. if doctor_advices_str == "null" {
  774. return records, nil
  775. } else {
  776. json.Unmarshal([]byte(doctor_advices_str), &records)
  777. return records, nil
  778. }
  779. }
  780. }
  781. // 透析记录
  782. func MobileGetSchedualDialysisRecordTen(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  783. var record models.DialysisOrder
  784. err := readDb.Model(&models.DialysisOrder{}).Preload("DeviceNumber", "org_id = ?", orgID).Where("user_org_id = ? AND patient_id = ? AND dialysis_date = ?", orgID, patientID, recordDate).First(&record).Error
  785. if err != nil {
  786. if err == gorm.ErrRecordNotFound {
  787. return nil, nil
  788. } else {
  789. return nil, err
  790. }
  791. }
  792. return &record, nil
  793. }
  794. //func MobileGetSchedualDialysisRecord(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  795. // var record models.DialysisOrder
  796. //
  797. // err := readDb.Model(&models.DialysisOrder{}).Preload("DeviceNumber", "org_id = ? AND status = 1", orgID).Where("user_org_id = ? AND patient_id = ? AND dialysis_date = ?", orgID, patientID, recordDate).First(&record).Error
  798. //
  799. //
  800. // return &record,err
  801. //}
  802. // 透析记录
  803. func MobileGetSchedualDialysisRecord(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  804. var record models.DialysisOrder
  805. redis := RedisClient()
  806. defer redis.Close()
  807. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":dialysis_order"
  808. dialysis_order_str, _ := redis.Get(key).Result()
  809. if len(dialysis_order_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  810. err := readDb.Model(&models.DialysisOrder{}).Preload("DeviceNumber", "org_id = ? AND status = 1", orgID).Where("user_org_id = ? AND patient_id = ? AND dialysis_date = ?", orgID, patientID, recordDate).First(&record).Error
  811. if err != nil {
  812. if err == gorm.ErrRecordNotFound {
  813. return nil, nil
  814. } else {
  815. return nil, err
  816. }
  817. } else {
  818. if record.ID > 0 {
  819. //缓存数据
  820. dialysis_order_str, err := json.Marshal(record)
  821. if err == nil {
  822. redis.Set(key, dialysis_order_str, time.Second*60*60*18)
  823. }
  824. } else {
  825. redis.Set(key, "null", time.Second*60*60*18)
  826. }
  827. return &record, nil
  828. }
  829. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  830. if dialysis_order_str == "null" {
  831. err = readDb.Model(&models.DialysisOrder{}).Preload("DeviceNumber", "org_id = ? AND status = 1", orgID).Where("user_org_id = ? AND patient_id = ? AND dialysis_date = ?", orgID, patientID, recordDate).First(&record).Error
  832. return &record, nil
  833. } else {
  834. json.Unmarshal([]byte(dialysis_order_str), &record)
  835. return &record, nil
  836. }
  837. }
  838. }
  839. // 双人核对
  840. func MobileGetDoubleCheck(orgID int64, patientID int64, recordDate int64) (*models.DoubleCheck, error) {
  841. var record models.DoubleCheck
  842. redis := RedisClient()
  843. defer redis.Close()
  844. // cur_date := time.Now().Format("2006-01-02")
  845. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":double_check"
  846. double_check_str, _ := redis.Get(key).Result()
  847. if len(double_check_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  848. err := readDb.Model(&models.DoubleCheck{}).Where("patient_id = ? and user_org_id = ? and status = 1 and check_date = ?", patientID, orgID, recordDate).First(&record).Error
  849. if err != nil {
  850. if err == gorm.ErrRecordNotFound {
  851. if record.ID <= 0 {
  852. redis.Set(key, "null", time.Second*60*60*18)
  853. }
  854. return nil, nil
  855. } else {
  856. return nil, err
  857. }
  858. } else {
  859. if record.ID > 0 {
  860. //缓存数据
  861. double_check_str, err := json.Marshal(record)
  862. if err == nil {
  863. redis.Set(key, double_check_str, time.Second*60*60*18)
  864. }
  865. } else {
  866. redis.Set(key, "null", time.Second*60*60*18)
  867. }
  868. return &record, nil
  869. }
  870. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  871. if double_check_str == "null" {
  872. return &record, nil
  873. } else {
  874. json.Unmarshal([]byte(double_check_str), &record)
  875. return &record, nil
  876. }
  877. }
  878. }
  879. // 透析监测记录
  880. func MobileGetMonitorRecords(orgID int64, patientID int64, recordDate int64) ([]*models.MonitoringRecord, error) {
  881. var records []*models.MonitoringRecord
  882. redis := RedisClient()
  883. defer redis.Close()
  884. // cur_date := time.Now().Format("2006-01-02")
  885. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":monitor_records"
  886. redis.Set(key, "", time.Second)
  887. monitor_records_str, _ := redis.Get(key).Result()
  888. if len(monitor_records_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  889. err := readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ?", patientID, orgID, recordDate).Order("operate_time asc").Find(&records).Error
  890. if err != nil {
  891. if err == gorm.ErrRecordNotFound {
  892. //if len(records) <= 0 {
  893. // redis.Set(key, "null", time.Second*60*60*18)
  894. //}
  895. return nil, nil
  896. } else {
  897. return nil, err
  898. }
  899. } else {
  900. if len(records) > 0 {
  901. //缓存数据
  902. monitor_records_str, err := json.Marshal(records)
  903. if err == nil {
  904. redis.Set(key, monitor_records_str, time.Second*60*60*18)
  905. }
  906. } else {
  907. redis.Set(key, "null", time.Second*60*60*18)
  908. }
  909. return records, nil
  910. }
  911. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  912. if monitor_records_str == "null" {
  913. return records, nil
  914. } else {
  915. json.Unmarshal([]byte(monitor_records_str), &records)
  916. return records, nil
  917. }
  918. }
  919. }
  920. func MobileGetMonitorRecordFirst(orgID int64, patientID int64, recordDate int64) (*models.MonitoringRecord, error) {
  921. var records models.MonitoringRecord
  922. err := readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ?", patientID, orgID, recordDate).Order("operate_time asc").First(&records).Error
  923. if err != nil {
  924. return nil, err
  925. }
  926. return &records, nil
  927. }
  928. func MobileGetLastMonitorRecordOne(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  929. var record models.MonitoringRecord
  930. err := readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ?", patientID, orgID, beforeDate).Order("operate_time desc").First(&record).Error
  931. if err != nil {
  932. if err == gorm.ErrRecordNotFound {
  933. return nil, nil
  934. } else {
  935. return nil, err
  936. }
  937. }
  938. return &record, nil
  939. }
  940. func MobileGetLastMonitorRecord(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  941. var record models.MonitoringRecord
  942. redis := RedisClient()
  943. defer redis.Close()
  944. // cur_date := time.Now().Format("2006-01-02")
  945. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(beforeDate, 10) + ":monitor_record_last"
  946. monitor_record_last_str, _ := redis.Get(key).Result()
  947. redis.Set(key, "", time.Second)
  948. if len(monitor_record_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  949. 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
  950. if err != nil {
  951. if err == gorm.ErrRecordNotFound {
  952. if record.ID <= 0 {
  953. redis.Set(key, "null", time.Second*60*60*18)
  954. }
  955. return nil, nil
  956. } else {
  957. return nil, err
  958. }
  959. } else {
  960. if record.ID > 0 {
  961. //缓存数据
  962. monitor_record_last_str, err := json.Marshal(record)
  963. if err == nil {
  964. redis.Set(key, monitor_record_last_str, time.Second*60*60*18)
  965. }
  966. } else {
  967. redis.Set(key, "null", time.Second*60*60*18)
  968. }
  969. return &record, nil
  970. }
  971. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  972. if monitor_record_last_str == "null" {
  973. return &record, nil
  974. } else {
  975. json.Unmarshal([]byte(monitor_record_last_str), &record)
  976. return &record, nil
  977. }
  978. }
  979. }
  980. func MobileGetAssessmentAfterDislysisOne(orgID int64, patientID int64, recordDate int64) (*models.AssessmentAfterDislysis, error) {
  981. var record models.AssessmentAfterDislysis
  982. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  983. if err != nil {
  984. if err == gorm.ErrRecordNotFound {
  985. return nil, nil
  986. } else {
  987. return nil, err
  988. }
  989. }
  990. return &record, nil
  991. }
  992. // 透后评估
  993. func MobileGetAssessmentAfterDislysis(orgID int64, patientID int64, recordDate int64) (*models.AssessmentAfterDislysis, error) {
  994. var record models.AssessmentAfterDislysis
  995. redis := RedisClient()
  996. defer redis.Close()
  997. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":assessment_after_dislysis"
  998. redis.Set(key, "", time.Second)
  999. assessment_after_dislysis_str, _ := redis.Get(key).Result()
  1000. if len(assessment_after_dislysis_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1001. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  1002. if err != nil {
  1003. if err == gorm.ErrRecordNotFound {
  1004. if record.ID <= 0 {
  1005. redis.Set(key, "null", time.Second*60*60*18)
  1006. }
  1007. return nil, nil
  1008. } else {
  1009. return nil, err
  1010. }
  1011. } else {
  1012. if record.ID > 0 {
  1013. //缓存数据
  1014. assessment_after_dislysis_str, err := json.Marshal(record)
  1015. if err == nil {
  1016. redis.Set(key, assessment_after_dislysis_str, time.Second*60*60*18)
  1017. }
  1018. } else {
  1019. redis.Set(key, "null", time.Second*60*60*18)
  1020. }
  1021. return &record, nil
  1022. }
  1023. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1024. if assessment_after_dislysis_str == "null" {
  1025. return &record, nil
  1026. } else {
  1027. json.Unmarshal([]byte(assessment_after_dislysis_str), &record)
  1028. return &record, nil
  1029. }
  1030. }
  1031. }
  1032. // 获取 maxDate 之前一次的透后评估记录
  1033. func MobileGetLastTimeAssessmentAfterDislysis(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  1034. var record models.AssessmentAfterDislysis
  1035. redis := RedisClient()
  1036. defer redis.Close()
  1037. // cur_date := time.Now().Format("2006-01-02")
  1038. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(maxDate, 10) + ":assessment_after_dislysis_last"
  1039. redis.Set(key, "", time.Second)
  1040. assessment_after_dislysis_last_str, _ := redis.Get(key).Result()
  1041. if len(assessment_after_dislysis_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1042. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where(" patient_id = ? and user_org_id = ? and status = 1 and assessment_date>=1725120000 and assessment_date < ?", patientID, orgID, maxDate).Order("assessment_date desc").First(&record).Error
  1043. if err != nil {
  1044. if err == gorm.ErrRecordNotFound {
  1045. if record.ID <= 0 {
  1046. redis.Set(key, "null", time.Second*60*60*18)
  1047. }
  1048. return nil, nil
  1049. } else {
  1050. return nil, err
  1051. }
  1052. } else {
  1053. if record.ID > 0 {
  1054. //缓存数据
  1055. assessment_after_dislysis_last_str, err := json.Marshal(record)
  1056. if err == nil {
  1057. redis.Set(key, assessment_after_dislysis_last_str, time.Second*60*60*18)
  1058. }
  1059. } else {
  1060. redis.Set(key, "null", time.Second*60*60*18)
  1061. }
  1062. return &record, nil
  1063. }
  1064. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1065. if assessment_after_dislysis_last_str == "null" {
  1066. return &record, nil
  1067. } else {
  1068. json.Unmarshal([]byte(assessment_after_dislysis_last_str), &record)
  1069. return &record, nil
  1070. }
  1071. }
  1072. }
  1073. func MobileGetLastTimeAssessmentAfterDislysisOne(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  1074. var record models.AssessmentAfterDislysis
  1075. 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
  1076. if err != nil {
  1077. if err == gorm.ErrRecordNotFound {
  1078. return nil, nil
  1079. } else {
  1080. return nil, err
  1081. }
  1082. }
  1083. return &record, nil
  1084. }
  1085. func MobileGetLastTimeAssessmentAfterDislysisTwo(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  1086. var record models.AssessmentAfterDislysis
  1087. 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
  1088. return &record, nil
  1089. }
  1090. func MobileGetLast(orgID int64, patientID int64, maxDate int64) (models.AssessmentAfterDislysis, error) {
  1091. dislysis := models.AssessmentAfterDislysis{}
  1092. 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
  1093. return dislysis, err
  1094. }
  1095. // 治疗小结
  1096. func MobileGetTreatmentSummary(orgID int64, patientID int64, recordDate int64) (*models.TreatmentSummary, error) {
  1097. var record models.TreatmentSummary
  1098. redis := RedisClient()
  1099. defer redis.Close()
  1100. // cur_date := time.Now().Format("2006-01-02")
  1101. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":treatment_summary"
  1102. treatment_summary_str, _ := redis.Get(key).Result()
  1103. if len(treatment_summary_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1104. err := readDb.Model(&models.TreatmentSummary{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  1105. if err != nil {
  1106. if err == gorm.ErrRecordNotFound {
  1107. if record.ID <= 0 {
  1108. redis.Set(key, "null", time.Second*60*60*18)
  1109. }
  1110. return nil, nil
  1111. } else {
  1112. return nil, err
  1113. }
  1114. } else {
  1115. if record.ID > 0 {
  1116. //缓存数据
  1117. treatment_summary_str, err := json.Marshal(record)
  1118. if err == nil {
  1119. redis.Set(key, treatment_summary_str, time.Second*60*60*18)
  1120. }
  1121. } else {
  1122. redis.Set(key, "null", time.Second*60*60*18)
  1123. }
  1124. return &record, nil
  1125. }
  1126. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1127. if treatment_summary_str == "null" {
  1128. return &record, nil
  1129. } else {
  1130. json.Unmarshal([]byte(treatment_summary_str), &record)
  1131. return &record, nil
  1132. }
  1133. }
  1134. }
  1135. // 透析处方
  1136. func MobileGetDialysisPrescribe(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  1137. var record models.DialysisPrescription
  1138. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).Find(&record).Error
  1139. if err != nil {
  1140. if err == gorm.ErrRecordNotFound {
  1141. return nil, nil
  1142. } else {
  1143. return nil, err
  1144. }
  1145. }
  1146. return &record, nil
  1147. }
  1148. func MobileGetDialysisPrescribeOne(orgID int64, patientID int64, recordDate int64) (models.DialysisPrescription, error) {
  1149. var record models.DialysisPrescription
  1150. err = readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).Find(&record).Error
  1151. return record, nil
  1152. }
  1153. func UpdateMobileGetDialysisPrescribe(id int64, dewater_amount float64) error {
  1154. err := XTWriteDB().Model(&models.DialysisPrescription{}).Where("id=? and status=1", id).Updates(map[string]interface{}{"target_ultrafiltration": dewater_amount, "prescription_water": dewater_amount}).Error
  1155. return err
  1156. }
  1157. func UpdateMobileGetDialysisPrescribeOne(id int64, dewater_amount float64) error {
  1158. err := XTWriteDB().Model(&models.DialysisPrescription{}).Where("id=? and status=1", id).Updates(map[string]interface{}{"target_ultrafiltration": dewater_amount}).Error
  1159. return err
  1160. }
  1161. func MobileGetDialysisSchedual(orgID int64, patientID int64, scheduleDate int64) (*models.XtSchedule, error) {
  1162. var schedule models.XtSchedule
  1163. err := readDb.Model(&models.XtSchedule{}).Where("patient_id = ? and user_org_id = ? and status = 1 and schedule_date = ?", patientID, orgID, scheduleDate).First(&schedule).Error
  1164. if err != nil {
  1165. if err == gorm.ErrRecordNotFound {
  1166. return nil, nil
  1167. } else {
  1168. return nil, err
  1169. }
  1170. }
  1171. return &schedule, nil
  1172. }
  1173. // 透析方案
  1174. func MobileGetDialysisSolution(orgID int64, patientID int64) (*models.DialysisSolution, error) {
  1175. var record models.DialysisSolution
  1176. err := readDb.Model(&models.DialysisSolution{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  1177. if err != nil {
  1178. if err == gorm.ErrRecordNotFound {
  1179. return nil, nil
  1180. } else {
  1181. return nil, err
  1182. }
  1183. }
  1184. return &record, nil
  1185. }
  1186. func MobileGetPatientById(orgID int64, patientID int64) (*models.Patients, error) {
  1187. var patient models.Patients
  1188. err := readDb.Model(&models.Patients{}).Where("id = ? and user_org_id = ? and status = 1", patientID, orgID).First(&patient).Error
  1189. if err != nil {
  1190. if err == gorm.ErrRecordNotFound {
  1191. return nil, nil
  1192. } else {
  1193. return nil, err
  1194. }
  1195. }
  1196. return &patient, nil
  1197. }
  1198. func DisableMonitor(orgID int64, patientID int64, recordID int64, admin_user_id int64) error {
  1199. fmt.Println()
  1200. tx := writeDb.Begin()
  1201. updateTime := time.Now().Unix()
  1202. 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
  1203. if err != nil {
  1204. tx.Rollback()
  1205. return err
  1206. }
  1207. tx.Commit()
  1208. return nil
  1209. }
  1210. func GetMonitorById(id int64, orgId int64) (models.MonitoringRecord, error) {
  1211. record := models.MonitoringRecord{}
  1212. err := XTReadDB().Where("id = ? and user_org_id =?", id, orgId).Find(&record).Error
  1213. return record, err
  1214. }
  1215. func GetMonitor(orgID int64, patientID int64, id int64) (*models.MonitoringRecord, error) {
  1216. var monitor models.MonitoringRecord
  1217. var err error
  1218. err = readDb.Model(&models.MonitoringRecord{}).Where("id = ? AND user_org_id = ? AND patient_id = ? AND status = 1 ", id, orgID, patientID).Find(&monitor).Error
  1219. if err == gorm.ErrRecordNotFound {
  1220. return nil, nil
  1221. }
  1222. if err != nil {
  1223. return nil, err
  1224. }
  1225. return &monitor, nil
  1226. }
  1227. type MScheduleDoctorAdviceVM struct {
  1228. ID int64 `gorm:"column:id" json:"id"`
  1229. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  1230. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  1231. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  1232. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1233. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  1234. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  1235. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  1236. Status int64 `gorm:"column:status" json:"status"`
  1237. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  1238. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  1239. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  1240. DoctorAdvices []*MDoctorAdviceVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  1241. Prescription *models.DialysisPrescriptionTwenty `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  1242. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  1243. }
  1244. func (MScheduleDoctorAdviceVM) TableName() string {
  1245. return "xt_schedule"
  1246. }
  1247. type MScheduleDoctorAdviceVMOne struct {
  1248. ID int64 `gorm:"column:id" json:"id"`
  1249. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  1250. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  1251. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  1252. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1253. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  1254. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  1255. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  1256. Status int64 `gorm:"column:status" json:"status"`
  1257. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  1258. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  1259. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  1260. DoctorAdvices []*MDoctorAdviceVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  1261. Prescription *models.DialysisPrescriptionTwenty `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  1262. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  1263. }
  1264. func (MScheduleDoctorAdviceVMOne) TableName() string {
  1265. return "xt_schedule"
  1266. }
  1267. type MDoctorAdviceVM struct {
  1268. ID int64 `gorm:"column:id" json:"id"`
  1269. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  1270. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1271. AdviceType int64 `gorm:"column:advice_type" json:"advice_type"`
  1272. AdviceDate int64 `gorm:"column:advice_date" json:"advice_date"`
  1273. StartTime int64 `gorm:"column:start_time" json:"start_time"`
  1274. AdviceName string `gorm:"column:advice_name" json:"advice_name"`
  1275. AdviceDesc string `gorm:"column:advice_desc" json:"advice_desc"`
  1276. ReminderDate int64 `gorm:"column:reminder_date" json:"reminder_date"`
  1277. SingleDose float64 `gorm:"column:single_dose" json:"single_dose"`
  1278. SingleDoseUnit string `gorm:"column:single_dose_unit" json:"single_dose_unit"`
  1279. PrescribingNumber float64 `gorm:"column:prescribing_number" json:"prescribing_number"`
  1280. PrescribingNumberUnit string `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit"`
  1281. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way"`
  1282. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency"`
  1283. AdviceDoctor int64 `gorm:"column:advice_doctor" json:"advice_doctor"`
  1284. Status int64 `gorm:"column:status" json:"status"`
  1285. CreatedTime int64 `gorm:"column:created_time" json:"created_time"`
  1286. UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time"`
  1287. AdviceAffirm string `gorm:"column:advice_affirm" json:"advice_affirm"`
  1288. Remark string `gorm:"column:remark" json:"remark"`
  1289. StopTime int64 `gorm:"column:stop_time" json:"stop_time"`
  1290. StopReason string `gorm:"column:stop_reason" json:"stop_reason"`
  1291. StopDoctor int64 `gorm:"column:stop_doctor" json:"stop_doctor"`
  1292. StopState int64 `gorm:"column:stop_state" json:"stop_state"`
  1293. ParentId int64 `gorm:"column:parent_id" json:"parent_id"`
  1294. ExecutionTime int64 `gorm:"column:execution_time" json:"execution_time"`
  1295. ExecutionStaff int64 `gorm:"column:execution_staff" json:"execution_staff"`
  1296. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state"`
  1297. Checker int64 `gorm:"column:checker" json:"checker"`
  1298. RecordDate int64 `gorm:"column:record_date" json:"record_date"`
  1299. DialysisOrderId int64 `gorm:"column:dialysis_order_id" json:"dialysis_order_id"`
  1300. CheckTime int64 `gorm:"column:check_time" json:"check_time"`
  1301. CheckState int64 `gorm:"column:check_state" json:"check_state"`
  1302. DrugSpec float64 `gorm:"column:drug_spec" json:"drug_spec"`
  1303. DrugSpecUnit string `gorm:"column:drug_spec_unit" json:"drug_spec_unit"`
  1304. Groupno int64 `gorm:"column:groupno" json:"groupno"`
  1305. RemindType int64 `gorm:"column:remind_type" json:"remind_type"`
  1306. FrequencyType int64 `gorm:"column:frequency_type" json:"frequency_type"`
  1307. DayCount int64 `gorm:"column:day_count" json:"day_count"`
  1308. WeekDay string `gorm:"column:week_day" json:"week_day"`
  1309. TemplateId string `gorm:"column:template_id" json:"template_id"`
  1310. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1311. IsMedicine int64 `gorm:"column:is_medicine" json:"is_medicine" form:"is_medicine"`
  1312. IsSettle int64 `gorm:"column:is_settle" json:"is_settle" form:"is_settle"`
  1313. }
  1314. func (MDoctorAdviceVM) TableName() string {
  1315. return "xt_doctor_advice"
  1316. }
  1317. func MobileGetScheduleDoctorAdvices(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string) ([]*MScheduleDoctorAdviceVM, error) {
  1318. var vms []*MScheduleDoctorAdviceVM
  1319. adviceWhere := ""
  1320. adviceCondition := []interface{}{}
  1321. if adviceType == 0 {
  1322. if patientType == 0 {
  1323. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  1324. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1325. } else if patientType == 1 {
  1326. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  1327. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1328. } else if patientType == 2 {
  1329. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  1330. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1331. }
  1332. } else if adviceType == 1 {
  1333. if patientType == 0 {
  1334. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  1335. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1336. } else if patientType == 1 {
  1337. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  1338. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1339. } else if patientType == 2 {
  1340. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  1341. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1342. }
  1343. } else if adviceType == 3 {
  1344. if patientType == 0 {
  1345. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  1346. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1347. } else if patientType == 1 {
  1348. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  1349. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1350. } else if patientType == 2 {
  1351. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  1352. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1353. }
  1354. } else if adviceType == 2 && len(deliverWay) > 0 {
  1355. if patientType == 0 {
  1356. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  1357. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1358. } else if patientType == 1 {
  1359. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  1360. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  1361. } else if patientType == 2 {
  1362. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  1363. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1364. }
  1365. } else if adviceType == 2 && len(deliverWay) <= 0 {
  1366. if patientType == 0 {
  1367. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  1368. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1369. } else if patientType == 1 {
  1370. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND (advice_doctor = ? or execution_staff = ?)"
  1371. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, adminUserId)
  1372. } else if patientType == 2 {
  1373. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  1374. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1375. }
  1376. }
  1377. db := readDb.
  1378. Table("xt_schedule").
  1379. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1380. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1381. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1382. }).
  1383. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1384. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1385. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1386. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  1387. Preload("DoctorAdvices", adviceCondition...).
  1388. Where("status = 1 AND user_org_id = ?", orgID)
  1389. if scheduleDate != 0 {
  1390. db = db.Where("schedule_date = ?", scheduleDate)
  1391. }
  1392. err := db.Find(&vms).Error
  1393. return vms, err
  1394. }
  1395. func MobileGetScheduleDoctorAdvicesTwo(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string) ([]*MScheduleDoctorAdviceVMOne, error) {
  1396. var vms []*MScheduleDoctorAdviceVMOne
  1397. adviceWhere := ""
  1398. adviceCondition := []interface{}{}
  1399. if adviceType == 0 {
  1400. if patientType == 0 {
  1401. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  1402. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1403. } else if patientType == 1 {
  1404. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  1405. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1406. } else if patientType == 2 {
  1407. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  1408. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1409. } else if patientType == 3 {
  1410. 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"
  1411. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1412. } else if patientType == 4 {
  1413. 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)"
  1414. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1415. }
  1416. } else if adviceType == 1 {
  1417. if patientType == 0 {
  1418. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  1419. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1420. } else if patientType == 1 {
  1421. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  1422. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1423. } else if patientType == 2 {
  1424. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  1425. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1426. } else if patientType == 3 {
  1427. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = 1"
  1428. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1429. } else if patientType == 4 {
  1430. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and (is_settle = 0 or is_settle = 2)"
  1431. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1432. }
  1433. } else if adviceType == 3 {
  1434. if patientType == 0 {
  1435. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  1436. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1437. } else if patientType == 1 {
  1438. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  1439. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1440. } else if patientType == 2 {
  1441. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  1442. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1443. } else if patientType == 3 {
  1444. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 and is_settle = 1"
  1445. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1446. } else if patientType == 4 {
  1447. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 and (is_settle = 0 or is_settle = 2)"
  1448. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1449. }
  1450. } else if adviceType == 2 && len(deliverWay) > 0 {
  1451. if patientType == 0 {
  1452. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  1453. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1454. } else if patientType == 1 {
  1455. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  1456. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  1457. } else if patientType == 2 {
  1458. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  1459. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1460. } else if patientType == 3 {
  1461. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 and delivery_way = ? and is_settle = 1"
  1462. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1463. } else if patientType == 4 {
  1464. 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)"
  1465. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1466. }
  1467. } else if adviceType == 2 && len(deliverWay) <= 0 {
  1468. if patientType == 0 {
  1469. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  1470. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1471. } else if patientType == 1 {
  1472. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND (advice_doctor = ? or execution_staff = ?)"
  1473. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, adminUserId)
  1474. } else if patientType == 2 {
  1475. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  1476. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1477. } else if patientType == 3 {
  1478. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 and is_settle = 1"
  1479. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1480. } else if patientType == 4 {
  1481. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 and (is_settle = 0 or is_settle = 2)"
  1482. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1483. }
  1484. }
  1485. db := readDb.
  1486. Table("xt_schedule").
  1487. //Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1488. //Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1489. // return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1490. //}).
  1491. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1492. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1493. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1494. Preload("DoctorAdvices", adviceCondition...).
  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. return vms, err
  1501. }
  1502. func GetHisDoctorAdvices(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleDoctorAdviceVM, error) {
  1503. var vms []*HisMScheduleDoctorAdviceVM
  1504. if len(deliverWay) > 0 {
  1505. if patientType == 0 {
  1506. db := readDb.
  1507. Table("xt_schedule").
  1508. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  1509. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1510. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1511. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1512. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1513. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1514. }).
  1515. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1516. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1517. Where("status = 1 AND user_org_id = ?", orgID)
  1518. if scheduleDate != 0 {
  1519. db = db.Where("schedule_date = ?", scheduleDate)
  1520. }
  1521. err = db.Find(&vms).Error
  1522. }
  1523. if patientType > 0 {
  1524. db := readDb.
  1525. Table("xt_schedule").
  1526. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1527. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1528. 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).
  1529. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1530. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1531. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1532. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1533. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1534. }).Where("status = 1 AND user_org_id = ?", orgID)
  1535. if scheduleDate != 0 {
  1536. db = db.Where("schedule_date = ?", scheduleDate)
  1537. }
  1538. err = db.Find(&vms).Error
  1539. }
  1540. } else {
  1541. if patientType == 0 {
  1542. db := readDb.
  1543. Table("xt_schedule").
  1544. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? ", orgID, scheduleDate).
  1545. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1546. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1547. return db.Where("status = 1 AND user_org_id = ? and dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1548. }).
  1549. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1550. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1551. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1552. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1553. Where("status = 1 AND user_org_id = ?", orgID)
  1554. if scheduleDate != 0 {
  1555. db = db.Where("schedule_date = ?", scheduleDate)
  1556. }
  1557. err = db.Find(&vms).Error
  1558. }
  1559. if patientType > 0 {
  1560. db := readDb.
  1561. Table("xt_schedule").
  1562. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1563. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1564. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1565. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1566. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1567. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1568. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1569. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1570. Where("status = 1 AND user_org_id = ?", orgID)
  1571. if scheduleDate != 0 {
  1572. db = db.Where("schedule_date = ?", scheduleDate)
  1573. }
  1574. err = db.Find(&vms).Error
  1575. }
  1576. }
  1577. return vms, err
  1578. }
  1579. func GetHisDoctorAdvicesTwo(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleDoctorAdviceVMOne, error) {
  1580. var vms []*HisMScheduleDoctorAdviceVMOne
  1581. if len(deliverWay) > 0 {
  1582. if patientType == 0 {
  1583. db := readDb.
  1584. Table("xt_schedule").
  1585. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  1586. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1587. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1588. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1589. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1590. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1591. }).
  1592. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1593. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1594. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1595. Where("status = 1 AND user_org_id = ?", orgID)
  1596. if scheduleDate != 0 {
  1597. db = db.Where("schedule_date = ?", scheduleDate)
  1598. }
  1599. err = db.Find(&vms).Error
  1600. }
  1601. if patientType > 0 {
  1602. if patientType == 1 {
  1603. db := readDb.
  1604. Table("xt_schedule").
  1605. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1606. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1607. 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).
  1608. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1609. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1610. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1611. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1612. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1613. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1614. Where("status = 1 AND user_org_id = ?", orgID)
  1615. if scheduleDate != 0 {
  1616. db = db.Where("schedule_date = ?", scheduleDate)
  1617. }
  1618. err = db.Find(&vms).Error
  1619. }
  1620. if patientType == 2 {
  1621. db := readDb.
  1622. Table("xt_schedule").
  1623. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1624. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1625. 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).
  1626. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1627. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1628. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1629. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1630. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1631. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Where("status = 1 AND user_org_id = ?", orgID)
  1632. if scheduleDate != 0 {
  1633. db = db.Where("schedule_date = ?", scheduleDate)
  1634. }
  1635. err = db.Find(&vms).Error
  1636. }
  1637. if patientType == 3 {
  1638. db := readDb.
  1639. Table("xt_schedule").
  1640. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1641. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1642. 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).
  1643. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1644. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1645. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1646. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1647. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1648. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Where("status = 1 AND user_org_id = ?", orgID)
  1649. if scheduleDate != 0 {
  1650. db = db.Where("schedule_date = ?", scheduleDate)
  1651. }
  1652. err = db.Find(&vms).Error
  1653. }
  1654. if patientType == 4 {
  1655. db := readDb.
  1656. Table("xt_schedule").
  1657. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1658. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1659. 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).
  1660. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1661. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1662. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1663. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1664. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1665. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Where("status = 1 AND user_org_id = ?", orgID)
  1666. if scheduleDate != 0 {
  1667. db = db.Where("schedule_date = ?", scheduleDate)
  1668. }
  1669. err = db.Find(&vms).Error
  1670. }
  1671. }
  1672. } else {
  1673. if patientType == 0 {
  1674. db := readDb.
  1675. Table("xt_schedule").
  1676. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? ", orgID, scheduleDate).
  1677. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1678. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1679. return db.Where("status = 1 AND user_org_id = ? and dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1680. }).
  1681. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1682. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1683. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1684. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1685. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1686. Where("status = 1 AND user_org_id = ?", orgID)
  1687. if scheduleDate != 0 {
  1688. db = db.Where("schedule_date = ?", scheduleDate)
  1689. }
  1690. err = db.Find(&vms).Error
  1691. }
  1692. if patientType > 0 {
  1693. if patientType == 1 {
  1694. db := readDb.
  1695. Table("xt_schedule").
  1696. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1697. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1698. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1699. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1700. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1701. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1702. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1703. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1704. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1705. Where("status = 1 AND user_org_id = ?", orgID)
  1706. if scheduleDate != 0 {
  1707. db = db.Where("schedule_date = ?", scheduleDate)
  1708. }
  1709. err = db.Find(&vms).Error
  1710. }
  1711. if patientType == 2 {
  1712. db := readDb.
  1713. Table("xt_schedule").
  1714. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1715. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1716. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1717. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1718. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1719. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1720. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1721. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1722. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1723. Where("status = 1 AND user_org_id = ?", orgID)
  1724. if scheduleDate != 0 {
  1725. db = db.Where("schedule_date = ?", scheduleDate)
  1726. }
  1727. err = db.Find(&vms).Error
  1728. }
  1729. if patientType == 3 {
  1730. db := readDb.
  1731. Table("xt_schedule").
  1732. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1733. 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).
  1734. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  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. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1739. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1740. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1741. Where("status = 1 AND user_org_id = ?", orgID)
  1742. if scheduleDate != 0 {
  1743. db = db.Where("schedule_date = ?", scheduleDate)
  1744. }
  1745. err = db.Find(&vms).Error
  1746. }
  1747. if patientType == 4 {
  1748. db := readDb.
  1749. Table("xt_schedule").
  1750. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1751. 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).
  1752. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1753. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1754. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1755. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1756. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1757. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1758. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1759. Where("status = 1 AND user_org_id = ?", orgID)
  1760. if scheduleDate != 0 {
  1761. db = db.Where("schedule_date = ?", scheduleDate)
  1762. }
  1763. err = db.Find(&vms).Error
  1764. }
  1765. }
  1766. }
  1767. return vms, err
  1768. }
  1769. func GetMobileHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleProjectVM, error) {
  1770. var vms []*HisMScheduleProjectVM
  1771. //if patientType == 0 {
  1772. // db := readDb.
  1773. // Table("xt_schedule").
  1774. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1775. // Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1776. // return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1777. // }).
  1778. // Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1779. // Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1780. // Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1781. // Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1782. // return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1783. // }).
  1784. // Where("status = 1 AND user_org_id = ?", orgID)
  1785. // if scheduleDate != 0 {
  1786. // db = db.Where("schedule_date = ?", scheduleDate)
  1787. // }
  1788. // err = db.Find(&vms).Error
  1789. //}
  1790. //if patientType > 0 {
  1791. // db := readDb.
  1792. // Table("xt_schedule").
  1793. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1794. // Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1795. // return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1796. // }).
  1797. // Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1798. // Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1799. // Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1800. // Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1801. // Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1802. // return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1803. // }).
  1804. // Where("status = 1 AND user_org_id = ?", orgID)
  1805. // if scheduleDate != 0 {
  1806. // db = db.Where("schedule_date = ?", scheduleDate)
  1807. // }
  1808. // err = db.Find(&vms).Error
  1809. //}
  1810. db := readDb.Table("xt_schedule").Where("status = 1")
  1811. if orgID > 0 {
  1812. db = db.Where("user_org_id = ?", orgID)
  1813. }
  1814. if scheduleDate > 0 {
  1815. db = db.Where("schedule_date =?", scheduleDate)
  1816. }
  1817. err = db.Find(&vms).Error
  1818. if patientType == 0 {
  1819. db := readDb.
  1820. Table("xt_schedule").
  1821. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1822. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1823. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1824. }).
  1825. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1826. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1827. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1828. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1829. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1830. }).
  1831. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  1832. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  1833. }).
  1834. Where("status = 1 AND user_org_id = ?", orgID)
  1835. if scheduleDate != 0 {
  1836. db = db.Where("schedule_date = ?", scheduleDate)
  1837. }
  1838. err = db.Find(&vms).Error
  1839. }
  1840. if patientType > 0 {
  1841. db := readDb.
  1842. Table("xt_schedule").
  1843. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1844. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1845. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1846. }).
  1847. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1848. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1849. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1850. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1851. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1852. }).
  1853. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  1854. 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")
  1855. }).
  1856. Where("status = 1 AND user_org_id = ?", orgID)
  1857. if scheduleDate != 0 {
  1858. db = db.Where("schedule_date = ?", scheduleDate)
  1859. }
  1860. err = db.Find(&vms).Error
  1861. }
  1862. return vms, err
  1863. }
  1864. func MobileCreateDialysisOrder(orgID int64, patientID int64, order *models.DialysisOrder) error {
  1865. now := time.Now()
  1866. tx := writeDb.Begin()
  1867. if createOrderErr := tx.Model(&models.DialysisOrder{}).Create(order).Error; createOrderErr != nil {
  1868. tx.Rollback()
  1869. return createOrderErr
  1870. }
  1871. // 更新透析记录 ID
  1872. // 透析处方
  1873. 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 {
  1874. tx.Rollback()
  1875. return err
  1876. }
  1877. // 接诊评估
  1878. 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 {
  1879. tx.Rollback()
  1880. return err
  1881. }
  1882. // 透前评估
  1883. 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 {
  1884. tx.Rollback()
  1885. return err
  1886. }
  1887. // 临时医嘱
  1888. 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 {
  1889. tx.Rollback()
  1890. return err
  1891. }
  1892. // 双人核对
  1893. 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 {
  1894. tx.Rollback()
  1895. return err
  1896. }
  1897. // 透后评估
  1898. 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 {
  1899. tx.Rollback()
  1900. return err
  1901. }
  1902. // 治疗小结
  1903. 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 {
  1904. tx.Rollback()
  1905. return err
  1906. }
  1907. // 透析监测
  1908. 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 {
  1909. tx.Rollback()
  1910. return err
  1911. }
  1912. tx.Commit()
  1913. return nil
  1914. }
  1915. type MobileUrgentSchedulePatientVM struct {
  1916. ID int64 `gorm:"column:id" json:"id"`
  1917. Name string `gorm:"column:name" json:"name"`
  1918. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no"`
  1919. }
  1920. func (MobileUrgentSchedulePatientVM) TableName() string {
  1921. return "xt_patients"
  1922. }
  1923. type MobileUrgentScheduleTreatmentModeVM struct {
  1924. ID int64 `gorm:"column:id" json:"id"`
  1925. Name string `gorm:"column:name" json:"name"`
  1926. }
  1927. func (MobileUrgentScheduleTreatmentModeVM) TableName() string {
  1928. return "xt_treatment_mode"
  1929. }
  1930. func MobileGetAllPatientsForUrgentSchedule(orgID int64, record_date int64) ([]*MobileUrgentSchedulePatientVM, error) {
  1931. var vms []*MobileUrgentSchedulePatientVM = make([]*MobileUrgentSchedulePatientVM, 0)
  1932. 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()
  1933. defer rows.Close()
  1934. if err != nil {
  1935. return nil, err
  1936. }
  1937. for rows.Next() {
  1938. var vm MobileUrgentSchedulePatientVM
  1939. readDb.ScanRows(rows, &vm)
  1940. vms = append(vms, &vm)
  1941. }
  1942. return vms, nil
  1943. }
  1944. func MobileGetAllTrearmentModesForUrgentSchedule() ([]*MobileUrgentScheduleTreatmentModeVM, error) {
  1945. var modes []*MobileUrgentScheduleTreatmentModeVM
  1946. err := readDb.Model(&MobileUrgentScheduleTreatmentModeVM{}).Where("status = 1").Find(&modes).Error
  1947. if err != nil {
  1948. return nil, err
  1949. }
  1950. return modes, nil
  1951. }
  1952. type MobileUrgentScheduleScheduleListVM struct {
  1953. ID int64 `gorm:"column:id" json:"id"`
  1954. // ZoneID int64 `gorm:"column:partition_id" json:"zone_id"`
  1955. DeviceNumberID int64 `gorm:"column:bed_id" json:"bed_id"`
  1956. PatientID int64 `gorm:"column:patient_id" json:"patient_id"`
  1957. ScheduleType int `gorm:"column:schedule_type" json:"schedule_type"`
  1958. DeviceNumber *models.DeviceNumber `gorm:"ForeignKey:DeviceNumberID" json:"device_number"`
  1959. // DeviceZone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"device_zone"`
  1960. }
  1961. func (MobileUrgentScheduleScheduleListVM) TableName() string {
  1962. return "xt_schedule"
  1963. }
  1964. func MobileGetSchedulesForUrgentSchedule(orgID int64, scheduleDate int64, schedule_type int) (schedules []*MobileUrgentScheduleScheduleListVM, err error) {
  1965. db := readDb.
  1966. Model(&MobileUrgentScheduleScheduleListVM{}).
  1967. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1968. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND schedule_type = ? ", orgID, scheduleDate, schedule_type)
  1969. err = db.Find(&schedules).Error
  1970. if err != nil {
  1971. return nil, err
  1972. }
  1973. return schedules, nil
  1974. }
  1975. func MobileGetOtherSchedulesForUrgentSchedule(orgID int64, scheduleDate int64, schedule_type int) ([]*MobileUrgentScheduleScheduleListVM, error) {
  1976. var vms []*MobileUrgentScheduleScheduleListVM = make([]*MobileUrgentScheduleScheduleListVM, 0)
  1977. 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()
  1978. defer rows.Close()
  1979. if err != nil {
  1980. return nil, err
  1981. }
  1982. for rows.Next() {
  1983. var vm MobileUrgentScheduleScheduleListVM
  1984. readDb.ScanRows(rows, &vm)
  1985. vms = append(vms, &vm)
  1986. }
  1987. return vms, nil
  1988. }
  1989. type MobileUrgentScheduleDeviceNumberVM struct {
  1990. ID int64 `gorm:"column:id" json:"id"`
  1991. Number string `gorm:"column:number" json:"number"`
  1992. ZoneID int64 `gorm:"column:zone_id" json:"zone_id"`
  1993. Zone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"zone"`
  1994. }
  1995. func (MobileUrgentScheduleDeviceNumberVM) TableName() string {
  1996. return "xt_device_number"
  1997. }
  1998. func MobileGetAllDeviceNumbersForUrgentSchedule(orgID int64, record_date int64, schedule_type int) ([]*DeviceNumberViewModel, error) {
  1999. var vms []*DeviceNumberViewModel = make([]*DeviceNumberViewModel, 0)
  2000. 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()
  2001. defer rows.Close()
  2002. if err != nil {
  2003. return nil, err
  2004. }
  2005. for rows.Next() {
  2006. var vm DeviceNumberViewModel
  2007. readDb.ScanRows(rows, &vm)
  2008. vms = append(vms, &vm)
  2009. }
  2010. return vms, nil
  2011. //var deviceNumbers []*MobileUrgentScheduleDeviceNumberVM
  2012. //db := readDb.
  2013. // Model(&MobileUrgentScheduleDeviceNumberVM{}).
  2014. // Preload("Zone", "status = 1 AND org_id = ?", orgID).
  2015. // Where("status = 1 AND org_id = ?", orgID)
  2016. //err := db.Order("zone_id asc").Find(&deviceNumbers).Error
  2017. //if err != nil {
  2018. // return nil, err
  2019. //}
  2020. //return deviceNumbers, nil
  2021. }
  2022. func GetValidScheduleMonitorRecordCount() (int64, error) {
  2023. var total int64
  2024. err := readDb.Model(&models.MonitoringRecord{}).Where("status = 1 AND operate_time = 0 AND monitoring_date <> 0").Count(&total).Error
  2025. return total, err
  2026. }
  2027. func GetTop1000ValidScheduleMonitorRecord() ([]*models.MonitoringRecord, error) {
  2028. var monitors []*models.MonitoringRecord
  2029. err := readDb.Model(&models.MonitoringRecord{}).Where("status = 1 AND operate_time = 0 AND monitoring_date <> 0").Order("id asc").Limit(100).Find(&monitors).Error
  2030. if err != nil {
  2031. return nil, err
  2032. }
  2033. return monitors, nil
  2034. }
  2035. func BatchUpdateMonitors(monitors []*models.MonitoringRecord) error {
  2036. tx := writeDb.Begin()
  2037. for index := 0; index < len(monitors); index++ {
  2038. tx.Save(monitors[index])
  2039. }
  2040. return tx.Commit().Error
  2041. }
  2042. func ModifyStartDialysisOrder(order *models.DialysisOrder) error {
  2043. tx := writeDb.Begin()
  2044. updateTime := time.Now().Unix()
  2045. 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, "blood_flow_volume": order.BloodFlowVolume, "blood_drawing": order.BloodDrawing, "dialysis_strainer": order.DialysisStrainer}).Error
  2046. if err != nil {
  2047. tx.Rollback()
  2048. return err
  2049. }
  2050. tx.Commit()
  2051. return err
  2052. }
  2053. func UpdateScheduleByBedId(patient_id int64, schedule_date int64, bed_id int64, schedule_type int64, zone_id int64) error {
  2054. err := XTWriteDB().Model(&models.XtSchedule{}).Where("patient_id = ? and schedule_date = ? and status=1", patient_id, schedule_date).Updates(map[string]interface{}{"bed_id": bed_id, "schedule_type": schedule_type, "partition_id": zone_id}).Error
  2055. return err
  2056. }
  2057. func ModifyFinishDialysisOrder(order *models.DialysisOrder) error {
  2058. tx := writeDb.Begin()
  2059. updateTime := time.Now().Unix()
  2060. 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, "condenser": order.Condenser}).Error
  2061. if err != nil {
  2062. tx.Rollback()
  2063. return err
  2064. }
  2065. tx.Commit()
  2066. return err
  2067. }
  2068. func MobileGetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  2069. var record models.SgjPatientDryweight
  2070. err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  2071. if err != nil {
  2072. if err == gorm.ErrRecordNotFound {
  2073. return nil, nil
  2074. } else {
  2075. return nil, err
  2076. }
  2077. }
  2078. return &record, nil
  2079. }
  2080. //func MobileGetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  2081. // var record models.SgjPatientDryweight
  2082. // redis := RedisClient()
  2083. // defer redis.Close()
  2084. //
  2085. // key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":last_dry_weight"
  2086. // last_dry_weight_str, _ := redis.Get(key).Result()
  2087. //
  2088. // if len(last_dry_weight_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2089. // err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  2090. // if err != nil {
  2091. // if err == gorm.ErrRecordNotFound {
  2092. // if record.ID <= 0 {
  2093. // redis.Set(key, "null", time.Second*60*60*18)
  2094. // }
  2095. // return nil, nil
  2096. // } else {
  2097. // return nil, err
  2098. // }
  2099. // } else {
  2100. // if record.ID > 0 {
  2101. // //缓存数据
  2102. // last_dry_weight_str, err := json.Marshal(record)
  2103. // if err == nil {
  2104. // redis.Set(key, last_dry_weight_str, time.Second*60*60*18)
  2105. // return nil, err
  2106. // }
  2107. // } else {
  2108. // redis.Set(key, "null", time.Second*60*60*18)
  2109. // return nil, err
  2110. // }
  2111. // return &record, nil
  2112. // }
  2113. // } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2114. // if last_dry_weight_str == "null" {
  2115. // return &record, nil
  2116. // } else {
  2117. // json.Unmarshal([]byte(last_dry_weight_str), &record)
  2118. // return &record, nil
  2119. // }
  2120. //
  2121. // }
  2122. //}
  2123. // 透析方案
  2124. func MobileGetDialysisSolutionByModeIdSix(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  2125. var record models.DialysisSolution
  2126. err := readDb.Model(&models.DialysisSolution{}).Where("patient_id = ? and user_org_id = ? and status = 1 AND mode_id = ? and solution_status =1", patientID, orgID, mode_id).Last(&record).Error
  2127. if err != nil {
  2128. if err == gorm.ErrRecordNotFound {
  2129. return nil, nil
  2130. } else {
  2131. return nil, err
  2132. }
  2133. }
  2134. return &record, nil
  2135. }
  2136. // 透析方案
  2137. func MobileGetDialysisSolutionByModeIdSevenTwety(orgID int64, patientID int64, mode_id int64) (models.DialysisSolution, error) {
  2138. var record models.DialysisSolution
  2139. err = readDb.Model(&models.DialysisSolution{}).Where("patient_id = ? and user_org_id = ? and status = 1 AND mode_id = ? and solution_status =1", patientID, orgID, mode_id).Last(&record).Error
  2140. return record, nil
  2141. }
  2142. // 透析方案
  2143. func MobileGetDialysisSolutionByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  2144. var record models.DialysisSolution
  2145. redis := RedisClient()
  2146. defer redis.Close()
  2147. // cur_date := time.Now().Format("2006-01-02")
  2148. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2149. dialysis_solution_str, _ := redis.Get(key).Result()
  2150. redis.Set(key, "", time.Second*60)
  2151. if len(dialysis_solution_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2152. err := readDb.Model(&models.DialysisSolution{}).Where("patient_id = ? and user_org_id = ? and status = 1 AND mode_id = ? and solution_status=1", patientID, orgID, mode_id).Last(&record).Error
  2153. if err != nil {
  2154. if err == gorm.ErrRecordNotFound {
  2155. if record.ID <= 0 {
  2156. redis.Set(key, "null", time.Second*60*60*18)
  2157. }
  2158. return nil, nil
  2159. } else {
  2160. return nil, err
  2161. }
  2162. } else {
  2163. if record.ID > 0 {
  2164. //缓存数据
  2165. dialysis_solution_str, err := json.Marshal(record)
  2166. if err == nil {
  2167. redis.Set(key, dialysis_solution_str, time.Second*60*60*18)
  2168. }
  2169. } else {
  2170. redis.Set(key, "null", time.Second*60*60*18)
  2171. }
  2172. return &record, nil
  2173. }
  2174. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2175. if dialysis_solution_str == "null" {
  2176. return &record, nil
  2177. } else {
  2178. json.Unmarshal([]byte(dialysis_solution_str), &record)
  2179. return &record, nil
  2180. }
  2181. }
  2182. }
  2183. // 透析处方
  2184. func MobileGetDialysisPrescribeByModeId(orgID int64, patientID int64, recordDate int64, mode_id int64) (*models.DialysisPrescription, error) {
  2185. var record models.DialysisPrescription
  2186. redis := RedisClient()
  2187. defer redis.Close()
  2188. // cur_date := time.Now().Format("2006-01-02")
  2189. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2190. redis.Set(key, "", time.Second)
  2191. dialysis_prescribe_str, _ := redis.Get(key).Result()
  2192. if len(dialysis_prescribe_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2193. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? AND mode_id = ?", patientID, orgID, recordDate, mode_id).First(&record).Error
  2194. if err != nil {
  2195. if err == gorm.ErrRecordNotFound {
  2196. if record.ID <= 0 {
  2197. redis.Set(key, "null", time.Second*60*60*18)
  2198. }
  2199. return nil, nil
  2200. } else {
  2201. return nil, err
  2202. }
  2203. } else {
  2204. if record.ID > 0 {
  2205. //缓存数据
  2206. dialysis_prescribe_str, err := json.Marshal(record)
  2207. if err == nil {
  2208. redis.Set(key, dialysis_prescribe_str, time.Second*60*60*18)
  2209. }
  2210. } else {
  2211. redis.Set(key, "null", time.Second*60*60*18)
  2212. }
  2213. return &record, nil
  2214. }
  2215. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2216. if dialysis_prescribe_str == "null" {
  2217. return &record, nil
  2218. } else {
  2219. json.Unmarshal([]byte(dialysis_prescribe_str), &record)
  2220. return &record, nil
  2221. }
  2222. }
  2223. }
  2224. func MobileGetDialysisPrescribeByModeIdSix(orgID int64, patientID int64, recordDate int64, mode_id int64) (*models.DialysisPrescription, error) {
  2225. var record models.DialysisPrescription
  2226. 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
  2227. if err != nil {
  2228. if err == gorm.ErrRecordNotFound {
  2229. return nil, nil
  2230. } else {
  2231. return nil, err
  2232. }
  2233. }
  2234. return &record, nil
  2235. }
  2236. func MobileGetDialysisPrescribeByModeIdOne(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  2237. var record models.DialysisPrescription
  2238. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  2239. if err != nil {
  2240. if err == gorm.ErrRecordNotFound {
  2241. return nil, nil
  2242. } else {
  2243. return nil, err
  2244. }
  2245. }
  2246. return &record, nil
  2247. }
  2248. //func MobileGetDialysisPrescribeByModeIdOne(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  2249. // var record models.DialysisPrescription
  2250. // redis := RedisClient()
  2251. // defer redis.Close()
  2252. //
  2253. // // cur_date := time.Now().Format("2006-01-02")
  2254. // key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":dialysis_prescribe_by_mode"
  2255. // dialysis_prescribe_by_mode_str, _ := redis.Get(key).Result()
  2256. //
  2257. // if len(dialysis_prescribe_by_mode_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2258. // err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  2259. // if err != nil {
  2260. // if err == gorm.ErrRecordNotFound {
  2261. // if record.ID <= 0 {
  2262. // redis.Set(key, "null", time.Second*60*60*18)
  2263. // }
  2264. // return nil, nil
  2265. // } else {
  2266. // return nil, err
  2267. // }
  2268. // } else {
  2269. //
  2270. // if record.ID > 0 {
  2271. // //缓存数据
  2272. // dialysis_prescribe_by_mode_str, err := json.Marshal(record)
  2273. //
  2274. // if err == nil {
  2275. // redis.Set(key, dialysis_prescribe_by_mode_str, time.Second*60*60*18)
  2276. // return nil, err
  2277. // }
  2278. // } else {
  2279. // redis.Set(key, "null", time.Second*60*60*18)
  2280. // return nil, err
  2281. // }
  2282. // return &record, nil
  2283. // }
  2284. // } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2285. // if dialysis_prescribe_by_mode_str == "null" {
  2286. // json.Unmarshal([]byte(dialysis_prescribe_by_mode_str), &record)
  2287. // return &record, nil
  2288. // } else {
  2289. // json.Unmarshal([]byte(dialysis_prescribe_by_mode_str), &record)
  2290. // return &record, nil
  2291. // }
  2292. //
  2293. // }
  2294. //}
  2295. func MobileGetLastDialysisPrescribe(orgID int64, patientID int64) (*models.DialysisPrescription, error) {
  2296. var record models.DialysisPrescription
  2297. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 ", patientID, orgID).Last(&record).Error
  2298. if err != nil {
  2299. if err == gorm.ErrRecordNotFound {
  2300. return nil, nil
  2301. } else {
  2302. return nil, err
  2303. }
  2304. }
  2305. return &record, nil
  2306. }
  2307. func MobileGetLastDialysisPrescribeByModeIdSix(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2308. var record models.DialysisPrescription
  2309. 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
  2310. //if err != nil {
  2311. // if err == gorm.ErrRecordNotFound {
  2312. // return nil, nil
  2313. // } else {
  2314. // return nil, err
  2315. // }
  2316. //}
  2317. return &record, err
  2318. }
  2319. func MobileGetLastDialysisPrescribeByModeIdTen(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2320. var record models.DialysisPrescription
  2321. 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
  2322. if err != nil {
  2323. if err == gorm.ErrRecordNotFound {
  2324. return nil, nil
  2325. } else {
  2326. return nil, err
  2327. }
  2328. }
  2329. return &record, err
  2330. }
  2331. func MobileGetLastDialysisPrescribeByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2332. var record models.DialysisPrescription
  2333. redis := RedisClient()
  2334. defer redis.Close()
  2335. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  2336. dialysis_prescribe_by_mode_id, _ := redis.Get(key).Result()
  2337. if len(dialysis_prescribe_by_mode_id) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2338. 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
  2339. if err != nil {
  2340. if err == gorm.ErrRecordNotFound {
  2341. if record.ID <= 0 {
  2342. redis.Set(key, "null", time.Second*60*60*18)
  2343. }
  2344. return nil, nil
  2345. } else {
  2346. return nil, err
  2347. }
  2348. } else {
  2349. if record.ID > 0 {
  2350. //缓存数据
  2351. dialysis_prescribe_by_mode_str, err := json.Marshal(record)
  2352. if err == nil {
  2353. redis.Set(key, dialysis_prescribe_by_mode_str, time.Second*60*60*18)
  2354. return nil, err
  2355. }
  2356. } else {
  2357. redis.Set(key, "null", time.Second*60*60*18)
  2358. return nil, err
  2359. }
  2360. return &record, nil
  2361. }
  2362. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2363. if dialysis_prescribe_by_mode_id == "null" {
  2364. return &record, nil
  2365. } else {
  2366. json.Unmarshal([]byte(dialysis_prescribe_by_mode_id), &record)
  2367. return &record, nil
  2368. }
  2369. }
  2370. }
  2371. func MobileGetLastDialysisPrescribeByModeIdOne(orgID int64, patientID int64, mode_id int64) (models.DialysisPrescription, error) {
  2372. var record models.DialysisPrescription
  2373. 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
  2374. return record, err
  2375. }
  2376. func GetAllAvaildDeviceNumbers(orgID int64, record_date int64, schedule_type int) ([]*DeviceNumberViewModel, error) {
  2377. var vms []*DeviceNumberViewModel = make([]*DeviceNumberViewModel, 0)
  2378. 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()
  2379. defer rows.Close()
  2380. if err != nil {
  2381. return nil, err
  2382. }
  2383. for rows.Next() {
  2384. var vm DeviceNumberViewModel
  2385. readDb.ScanRows(rows, &vm)
  2386. vms = append(vms, &vm)
  2387. }
  2388. return vms, nil
  2389. }
  2390. // 获取 maxDate 之前一次的透前评估记录
  2391. func GetLastTimePredialysisEvaluation(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
  2392. var record models.PredialysisEvaluation
  2393. 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
  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 GetLastTimeOrder(orgID int64, patientID int64, maxDate int64) (*models.DialysisOrder, error) {
  2404. var record models.DialysisOrder
  2405. 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
  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 GetLastMonitorRecord(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  2416. var record models.MonitoringRecord
  2417. 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
  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 GetLastMonitorRecordTwenty(orgID int64, patientID int64, beforeDate int64) (models.MonitoringRecord, error) {
  2428. var record models.MonitoringRecord
  2429. err = readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ? and ultrafiltration_volume_one!=''", patientID, orgID, beforeDate).Order("operate_time desc").First(&record).Error
  2430. return record, nil
  2431. }
  2432. func GetLastMonitorRecordTwentyOne(orgID int64, patientID int64, beforeDate int64) (models.MonitoringRecord, error) {
  2433. var record models.MonitoringRecord
  2434. err = readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ? and monitor_systolic_blood_pressure_one!=''", patientID, orgID, beforeDate).Order("operate_time desc").First(&record).Error
  2435. return record, nil
  2436. }
  2437. func GetLastMonitorRecordTwentyTwo(orgID int64, patientID int64, beforeDate int64) (models.MonitoringRecord, error) {
  2438. var record models.MonitoringRecord
  2439. err = readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ? and monitor_diastolic_blood_pressure_one!=''", patientID, orgID, beforeDate).Order("operate_time desc").First(&record).Error
  2440. return record, nil
  2441. }
  2442. func GetLastMonitorRecordTwentyThree(orgID int64, patientID int64, beforeDate int64) (models.MonitoringRecord, error) {
  2443. var record models.MonitoringRecord
  2444. err = readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ? and pulse_frequency_one!=''", patientID, orgID, beforeDate).Order("operate_time desc").First(&record).Error
  2445. return record, nil
  2446. }
  2447. func GetLastMonitorRecordTwentyFour(orgID int64, patientID int64, beforeDate int64) (models.MonitoringRecord, error) {
  2448. var record models.MonitoringRecord
  2449. err = readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ? and displacement_quantity_one!=''", patientID, orgID, beforeDate).Order("operate_time desc").First(&record).Error
  2450. return record, nil
  2451. }
  2452. // 获取 maxDate 之前一次的透后评估记录
  2453. func GetLastTimeAssessmentAfterDislysis(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  2454. var record models.AssessmentAfterDislysis
  2455. 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
  2456. if err != nil {
  2457. if err == gorm.ErrRecordNotFound {
  2458. return nil, nil
  2459. } else {
  2460. return nil, err
  2461. }
  2462. }
  2463. return &record, nil
  2464. }
  2465. // 透析处方
  2466. func GetDialysisPrescribe(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  2467. var record models.DialysisPrescription
  2468. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  2469. if err != nil {
  2470. if err == gorm.ErrRecordNotFound {
  2471. return nil, nil
  2472. } else {
  2473. return nil, err
  2474. }
  2475. }
  2476. return &record, nil
  2477. }
  2478. // 透析方案
  2479. func GetDialysisSolution(orgID int64, patientID int64, mode_id int64) (models.DialysisSolution, error) {
  2480. var record models.DialysisSolution
  2481. 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
  2482. return record, err
  2483. }
  2484. func GetDialysisSolutionOne(orgID int64, mode_id int64) (*models.DialysisSolution, error) {
  2485. var record models.DialysisSolution
  2486. err := readDb.Model(&models.DialysisSolution{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2487. if err != nil {
  2488. if err == gorm.ErrRecordNotFound {
  2489. return nil, nil
  2490. } else {
  2491. return nil, err
  2492. }
  2493. }
  2494. return &record, nil
  2495. }
  2496. func GetLastDialysisPrescribeByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2497. var record models.DialysisPrescription
  2498. 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
  2499. if err != nil {
  2500. if err == gorm.ErrRecordNotFound {
  2501. return nil, nil
  2502. } else {
  2503. return nil, err
  2504. }
  2505. }
  2506. return &record, nil
  2507. }
  2508. func GetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  2509. var record models.SgjPatientDryweight
  2510. err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  2511. if err != nil {
  2512. if err == gorm.ErrRecordNotFound {
  2513. return nil, nil
  2514. } else {
  2515. return nil, err
  2516. }
  2517. }
  2518. return &record, nil
  2519. }
  2520. func MobileGetSystemDialysisPrescribeByModeIdSix(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2521. var record models.SystemPrescription
  2522. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).First(&record).Error
  2523. if err != nil {
  2524. if err == gorm.ErrRecordNotFound {
  2525. return nil, nil
  2526. } else {
  2527. return nil, err
  2528. }
  2529. }
  2530. return &record, nil
  2531. }
  2532. func MobileGetSystemDialysisPrescribeByModeId(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2533. var record models.SystemPrescription
  2534. redis := RedisClient()
  2535. defer redis.Close()
  2536. // cur_date := time.Now().Format("2006-01-02")
  2537. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  2538. system_dialysis_prescribe_str, _ := redis.Get(key).Result()
  2539. if len(system_dialysis_prescribe_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2540. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2541. if err != nil {
  2542. if err == gorm.ErrRecordNotFound {
  2543. if record.ID <= 0 {
  2544. redis.Set(key, "null", time.Second*60*60*18)
  2545. }
  2546. return nil, nil
  2547. } else {
  2548. return nil, err
  2549. }
  2550. } else {
  2551. if record.ID > 0 {
  2552. //缓存数据
  2553. system_dialysis_prescribe_str, err := json.Marshal(record)
  2554. if err == nil {
  2555. redis.Set(key, system_dialysis_prescribe_str, time.Second*60*60*18)
  2556. }
  2557. } else {
  2558. redis.Set(key, "null", time.Second*60*60*18)
  2559. }
  2560. return &record, nil
  2561. }
  2562. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2563. if system_dialysis_prescribe_str == "null" {
  2564. return &record, nil
  2565. } else {
  2566. json.Unmarshal([]byte(system_dialysis_prescribe_str), &record)
  2567. return &record, nil
  2568. }
  2569. }
  2570. }
  2571. func MobileGetSystemDialysisPrescribeByModeIdOne(orgID int64, mode_id int64) (models.SystemPrescription, error) {
  2572. var record models.SystemPrescription
  2573. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2574. return record, err
  2575. }
  2576. func GetSystemDialysisPrescribeByModeId(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2577. var record models.SystemPrescription
  2578. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2579. if err != nil {
  2580. if err == gorm.ErrRecordNotFound {
  2581. return nil, nil
  2582. } else {
  2583. return nil, err
  2584. }
  2585. }
  2586. return &record, nil
  2587. }
  2588. func GetDialysisOrderCount(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2589. 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
  2590. return
  2591. }
  2592. func GetDialysisOrderCountOne(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2593. 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
  2594. return
  2595. }
  2596. func GetDialysisOrderCountTwo(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2597. err = readDb.Model(&models.DialysisOrder{}).Where("dialysis_date>=1704038400 and dialysis_date <= ? AND status = 1 AND stage = 2 AND user_org_id = ? AND patient_id = ?", recordDate, orgID, patient_id).Count(&count).Error
  2598. return
  2599. }
  2600. func GetFirstDateOfMonth(d time.Time) time.Time {
  2601. d = d.AddDate(0, 0, -d.Day()+1)
  2602. return GetZeroTime(d)
  2603. }
  2604. func GetZeroTime(d time.Time) time.Time {
  2605. return time.Date(d.Year(), d.Month(), d.Day(), 0, 0, 0, 0, d.Location())
  2606. }
  2607. func GetDialysisCountByPatientId(startime int64, endtime int64, patientid int64, orgid int64) (order []*models.BloodDialysisOrderCount, err error) {
  2608. db := XTReadDB().Table("xt_dialysis_order as o")
  2609. 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
  2610. return order, err
  2611. }
  2612. func FindConsumablesByDate(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error) {
  2613. 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
  2614. return
  2615. }
  2616. func FindConsumablesByDateTwo(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error) {
  2617. 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
  2618. return
  2619. }
  2620. func FindConsumablesByDateThree(orgID int64, patient_id int64, recordDate int64) (consumables []*models.BloodAutomaticReduceDetail, err error) {
  2621. 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
  2622. return
  2623. }
  2624. func FindHisPrescription(orgID int64, patient_id int64, recordDate int64) (project []*models.HisPrescriptionProject, err error) {
  2625. err = readDb.Model(&models.HisPrescriptionProject{}).Where("user_org_id = ? AND patient_id = ? AND record_date = ? AND status = 1 and type =3", orgID, patient_id, recordDate).Find(&project).Error
  2626. return
  2627. }
  2628. //func FindLastConsumables(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error){
  2629. // 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
  2630. // return
  2631. //}
  2632. //
  2633. func GetLastTimeConsumables(orgID int64, patientID int64, maxDate int64) (prepare []*models.DialysisBeforePrepare, err error) {
  2634. 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
  2635. return
  2636. }
  2637. type GoodsType struct {
  2638. ID int64 `gorm:"column:id" json:"id"`
  2639. TypeName string `gorm:"column:type_name" json:"type_name"`
  2640. Remark string `gorm:"column:remark" json:"remark"`
  2641. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2642. Status int64 `gorm:"column:status" json:"status"`
  2643. Type int64 `gorm:"column:type" json:"type"`
  2644. }
  2645. func (GoodsType) TableName() string {
  2646. return "xt_goods_type"
  2647. }
  2648. type VMGoodInfo struct {
  2649. ID int64 `gorm:"column:id" json:"id"`
  2650. SpecificationName string `gorm:"column:specification_name" json:"specification_name"`
  2651. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2652. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2653. GoodName string `gorm:"column:good_name" json:"good_name" form:"good_name"`
  2654. GoodUnit int64 `gorm:"column:good_unit" json:"good_unit" form:"good_unit"`
  2655. Total float64 `gorm:"column:total" json:"total" form:"total"`
  2656. PackingUnit string `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
  2657. MedicalInsuranceNumber string `gorm:"column:medical_insurance_number" json:"medical_insurance_number" form:"medical_insurance_number"`
  2658. }
  2659. func (VMGoodInfo) TableName() string {
  2660. return "xt_good_information"
  2661. }
  2662. type AutomaticReduceDetail struct {
  2663. ID int64 `gorm:"column:id" json:"id"`
  2664. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2665. Status int64 `gorm:"column:status" json:"status"`
  2666. RecordTime int64 `gorm:"column:record_time" json:"record_time"`
  2667. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2668. GoodId int64 `gorm:"column:good_id" json:"good_id"`
  2669. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2670. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"info"`
  2671. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"type"`
  2672. Count int64 `gorm:"column:count" json:"count"`
  2673. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  2674. }
  2675. func (AutomaticReduceDetail) TableName() string {
  2676. return "xt_automatic_reduce_detail"
  2677. }
  2678. type DialysisBeforePrepare struct {
  2679. ID int64 `gorm:"column:id" json:"id" form:"id"`
  2680. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  2681. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  2682. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  2683. GoodId int64 `gorm:"column:good_id" json:"good_id" form:"good_id"`
  2684. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id" form:"good_type_id"`
  2685. Count int64 `gorm:"column:count" json:"count" form:"count"`
  2686. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  2687. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  2688. Creater int64 `gorm:"column:creater" json:"creater" form:"creater"`
  2689. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  2690. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"info"`
  2691. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"type"`
  2692. }
  2693. func (DialysisBeforePrepare) TableName() string {
  2694. return "dialysis_before_prepare"
  2695. }
  2696. type MDialysisGoodsVM struct {
  2697. ID int64 `gorm:"column:id" json:"id"`
  2698. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2699. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2700. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2701. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2702. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2703. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2704. ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week"`
  2705. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2706. Status int64 `gorm:"column:status" json:"status"`
  2707. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2708. SchedualPatient *MSchedualPatientVMList `gorm:"ForeignKey:PatientId" json:"patient"`
  2709. AutomaticReduceDetail []*AutomaticReduceDetail `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"good_user"`
  2710. LastAutomaticReduceDetail []*AutomaticReduceDetail `gorm:"-" json:"last_good_user"`
  2711. DialysisBeforePrepare []*DialysisBeforePrepare `gorm:"ForeignKey:PatientId,ScheduleDate;AssociationForeignKey:PatientId,RecordDate" json:"good_user_detail"`
  2712. LastDialysisBeforePrepare []*DialysisBeforePrepare `gorm:"-" json:"last_good_user_detail"`
  2713. Project []*models.HisPrescriptionProject `gorm:"-" json:"project"`
  2714. //WarehouseOutInfo []*models.WarehouseOutInfoSeven `gorm:"ForeignKey:PatientId,ScheduleDate;AssociationForeignKey:PatientId,SysRecordTime" json:"ware_house_out_info"`
  2715. DialysisPrescription models.DialysisPrescriptionListSix `gorm:"ForeignKey:PatientId,ModeId;AssociationForeignKey:PatientId,ModeId" json:"prescription"`
  2716. }
  2717. func (MDialysisGoodsVM) TableName() string {
  2718. return "xt_schedule"
  2719. }
  2720. type VMWarehouseOutInfo struct {
  2721. ID int64 `gorm:"column:id" json:"id"`
  2722. WarehouseOutId int64 `gorm:"column:warehouse_out_id" json:"warehouse_out_id"`
  2723. GoodId int64 `gorm:"column:good_id" json:"good_id"`
  2724. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2725. Count int64 `gorm:"column:count" json:"count"`
  2726. Price float64 `gorm:"column:price" json:"price"`
  2727. TotalPrice float64 `gorm:"column:total_price" json:"total_price"`
  2728. Status int64 `gorm:"column:status" json:"status"`
  2729. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2730. WarehouseOutOrderNumber string `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number"`
  2731. GoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"good_info"`
  2732. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"good_type"`
  2733. IsSys int64 `gorm:"column:is_sys" json:"is_sys"`
  2734. SysRecordTime int64 `gorm:"column:sys_record_time" json:"sys_record_time"`
  2735. Mtime int64 `gorm:"column:mtime" json:"mtime"`
  2736. Ctime int64 `gorm:"column:ctime" json:"ctime"`
  2737. }
  2738. func (VMWarehouseOutInfo) TableName() string {
  2739. return "xt_warehouse_out_info"
  2740. }
  2741. type DialysisGoodsDate struct {
  2742. RecordDate int64
  2743. }
  2744. type DialysisGoodsDetailDate struct {
  2745. RecordTime int64
  2746. }
  2747. 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) {
  2748. var vms []*MDialysisGoodsVM
  2749. var total int64
  2750. db := readDb.
  2751. Table("xt_schedule as sch").
  2752. Preload("DialysisPrescription", "status=1 and user_org_id =? and solution_status = 1", orgID).
  2753. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  2754. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2755. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2756. Preload("DialysisBeforePrepare", func(db *gorm.DB) *gorm.DB {
  2757. 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)
  2758. }).
  2759. Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
  2760. 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")
  2761. }).Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
  2762. if scheduleDate != 0 {
  2763. db = db.Where("schedule_date = ?", scheduleDate)
  2764. }
  2765. if schedule_type != 0 {
  2766. db = db.Where("schedule_type = ?", schedule_type)
  2767. }
  2768. if partition_id != 0 {
  2769. db = db.Where("partition_id = ?", partition_id)
  2770. }
  2771. if patient_id != 0 {
  2772. db = db.Where("patient_id = ?", patient_id)
  2773. }
  2774. err := db.Find(&vms).Error
  2775. return vms, err, total
  2776. }
  2777. func GetLastDialysisGoods(patient_id int64, orgID int64, record_time int64) (goodUser []*AutomaticReduceDetail, err error) {
  2778. var Id []*DialysisGoodsDetailDate
  2779. 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
  2780. if len(Id) > 0 {
  2781. 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
  2782. }
  2783. return
  2784. }
  2785. func GetLastDialysisBeforePrepare(patient_id int64, orgID int64, record_time int64) (goodUser []*DialysisBeforePrepare, err error) {
  2786. var Id []*DialysisGoodsDate
  2787. 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
  2788. if len(Id) > 0 {
  2789. 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
  2790. }
  2791. return
  2792. }
  2793. func GetPatientAutoMatic(patient_id int64, orgID int64, record_time int64, good_id int64) (auto []*models.AutomaticReduceDetail, err error) {
  2794. err = XTReadDB().Where("patient_id = ? and org_id = ? and record_time = ? and good_id =? and status=1", patient_id, orgID, record_time, good_id).Find(&auto).Error
  2795. return auto, err
  2796. }
  2797. func GetAllWarehouseOutSumList(patient_id int64, orgID int64, record_time int64) (info []*models.WarehouseOutInfoSeven, err error) {
  2798. err = XTReadDB().Where("patient_id = ? and org_id = ? and sys_record_time = ? and status = 1", patient_id, orgID, record_time).Find(&info).Error
  2799. return info, err
  2800. }
  2801. func MobileGetGoodsStatistics(orgID int64, start_time int64, end_time int64) (list []*models.StockInfo, err error) {
  2802. db := readDb.Model(&models.StockInfo{})
  2803. db = db.Where("xt_good_information.org_id = ? AND xt_good_information.status = 1", orgID)
  2804. 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")
  2805. db = db.Preload("QueryWarehouseOutInfo", func(db *gorm.DB) *gorm.DB {
  2806. 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)
  2807. })
  2808. db = db.Preload("GoodsType", "org_id = ? AND status = 1", orgID)
  2809. err = db.Order("ctime desc").Find(&list).Error
  2810. return
  2811. }
  2812. 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) {
  2813. var vms []*MDialysisGoodsVM
  2814. var total int64
  2815. db := readDb.
  2816. Model(&models.Schedule{}).
  2817. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  2818. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2819. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2820. Preload("DialysisBeforePrepare", func(db *gorm.DB) *gorm.DB {
  2821. 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)
  2822. }).Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
  2823. 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)
  2824. }).Where("xt_schedule.status = 1 AND xt_schedule.user_org_id = ?", orgID)
  2825. if scheduleDate != 0 {
  2826. db = db.Where("schedule_date = ?", scheduleDate)
  2827. }
  2828. if patient_id != 0 {
  2829. db = db.Where("patient_id = ?", patient_id)
  2830. }
  2831. if len(keywords) != 0 {
  2832. keywords = "%" + keywords + "%"
  2833. 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)
  2834. if schedule_type != 0 {
  2835. db = db.Where("schedule_type = ?", schedule_type)
  2836. }
  2837. if partition_id != 0 {
  2838. db = db.Where("partition_id = ?", partition_id)
  2839. }
  2840. if good_type == 1 {
  2841. db = db.Where("patient_id in(?)", ids)
  2842. }
  2843. if good_type == 2 {
  2844. if len(ids) > 0 {
  2845. db = db.Where("patient_id not in(?)", ids)
  2846. }
  2847. }
  2848. } else {
  2849. if schedule_type != 0 {
  2850. db = db.Where("schedule_type = ?", schedule_type)
  2851. }
  2852. if partition_id != 0 {
  2853. db = db.Where("partition_id = ?", partition_id)
  2854. }
  2855. if good_type == 1 {
  2856. db = db.Where("patient_id in(?)", ids)
  2857. }
  2858. if good_type == 2 {
  2859. if len(ids) > 0 {
  2860. db = db.Where("patient_id not in(?)", ids)
  2861. }
  2862. }
  2863. db = db.Count(&total)
  2864. offset := (page - 1) * limit
  2865. db = db.Offset(offset).Limit(limit)
  2866. }
  2867. err := db.Find(&vms).Error
  2868. return vms, err, total
  2869. }
  2870. func GetLastDialysisGoodsTwo(patient_id int64, orgID int64, record_time int64) (goodUser []*AutomaticReduceDetail, err error) {
  2871. var Id []*DialysisGoodsDetailDate
  2872. 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
  2873. if len(Id) > 0 {
  2874. 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
  2875. }
  2876. return
  2877. }
  2878. func GetLastDialysisBeforePrepareTwo(patient_id int64, orgID int64, record_time int64) (goodUser []*DialysisBeforePrepare, err error) {
  2879. var Id []*DialysisGoodsDate
  2880. 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
  2881. if len(Id) > 0 {
  2882. 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
  2883. }
  2884. return
  2885. }
  2886. func GetAssessmentBefor(orgid int64, patientid int64, recorddate int64) (*models.PredialysisEvaluation, error) {
  2887. evaluation := models.PredialysisEvaluation{}
  2888. err := XTReadDB().Model(&evaluation).Where("user_org_id = ? and patient_id = ? and assessment_date = ? and status = 1", orgid, patientid, recorddate).Find(&evaluation).Error
  2889. if err == gorm.ErrRecordNotFound {
  2890. return nil, err
  2891. }
  2892. if err != nil {
  2893. return nil, err
  2894. }
  2895. return &evaluation, nil
  2896. }
  2897. func GetAssessmentBeforThrity(orgid int64, patientid int64, recorddate int64) (models.PredialysisEvaluation, error) {
  2898. evaluation := models.PredialysisEvaluation{}
  2899. err := XTReadDB().Model(&evaluation).Where("user_org_id = ? and patient_id = ? and assessment_date = ? and status = 1", orgid, patientid, recorddate).Find(&evaluation).Error
  2900. return evaluation, err
  2901. }
  2902. func GetAssessmentBeforFourty(orgid int64, patientid int64, recorddate int64) (models.XtAssessmentBeforeDislysis, error) {
  2903. evaluation := models.XtAssessmentBeforeDislysis{}
  2904. err := XTReadDB().Model(&evaluation).Where("user_org_id = ? and patient_id = ? and assessment_date = ? and status = 1", orgid, patientid, recorddate).Find(&evaluation).Error
  2905. return evaluation, err
  2906. }
  2907. func GetHisPrescriptionTemplateList(user_org_id int64, patient_id int64, mode_id int64) (models.HisPrescriptionTemplateSix, error) {
  2908. templateSix := models.HisPrescriptionTemplateSix{}
  2909. err := XTReadDB().Where("user_org_id = ? and patient_id = ? and mode = ? and status =1", user_org_id, patient_id, mode_id).Preload("HisPrescriptionInfoTemplateSix", func(db *gorm.DB) *gorm.DB {
  2910. return db.Where("status = 1 AND user_org_id = ? and type =2", user_org_id).Preload("HisPrescriptionProjectTemplateSeven", func(db *gorm.DB) *gorm.DB {
  2911. return db.Where("status = 1 AND user_org_id = ? and type =3", user_org_id).Preload("GoodInfo", "org_id = ? and status=1 ", user_org_id)
  2912. })
  2913. }).Find(&templateSix).Error
  2914. return templateSix, err
  2915. }
  2916. func GetAllHisDoctorAdvice(orgid int64, patientid int64, recorddate int64) (his []*models.HisDoctorAdviceInfo, err error) {
  2917. redis := RedisClient()
  2918. defer redis.Close()
  2919. key := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patientid, 10) + ":" + strconv.FormatInt(recorddate, 10) + ":his_doctor_advice"
  2920. his_doctor_advice_str, _ := redis.Get(key).Result()
  2921. redis.Set(key, "", time.Second)
  2922. if len(his_doctor_advice_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2923. 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
  2924. if err != nil {
  2925. if err == gorm.ErrRecordNotFound {
  2926. if len(his) <= 0 {
  2927. redis.Set(key, "null", time.Second*60*60*18)
  2928. }
  2929. return his, nil
  2930. } else {
  2931. return his, err
  2932. }
  2933. } else {
  2934. if len(his) > 0 {
  2935. //缓存数据
  2936. his_doctor_advice_str, err := json.Marshal(his)
  2937. if err == nil {
  2938. redis.Set(key, his_doctor_advice_str, time.Second*60*60*18)
  2939. }
  2940. } else {
  2941. redis.Set(key, "null", time.Second*60*60*18)
  2942. }
  2943. return his, nil
  2944. }
  2945. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2946. json.Unmarshal([]byte(his_doctor_advice_str), &his)
  2947. return his, nil
  2948. }
  2949. }
  2950. func GetLastDialysisPrescriptionByPatientId(orgid int64, patientid int64, recorddate int64) (*models.DialysisPrescription, error) {
  2951. prescription := models.DialysisPrescription{}
  2952. err := readDb.Model(&models.DialysisPrescription{}).Where("user_org_id = ? and patient_id = ? and record_date = ? and status = 1", orgid, patientid, recorddate).Find(&prescription).Error
  2953. if err == gorm.ErrRecordNotFound {
  2954. return nil, err
  2955. }
  2956. if err != nil {
  2957. return nil, err
  2958. }
  2959. return &prescription, nil
  2960. }
  2961. func GetLastDialysisPrescriptionByPatientIdTwo(orgid int64, patientid int64, recorddate int64) (models.DialysisPrescription, error) {
  2962. prescription := models.DialysisPrescription{}
  2963. err := readDb.Model(&models.DialysisPrescription{}).Where("user_org_id = ? and patient_id = ? and record_date = ? and status = 1", orgid, patientid, recorddate).Find(&prescription).Error
  2964. return prescription, err
  2965. }
  2966. type HisMScheduleDoctorAdviceVM struct {
  2967. ID int64 `gorm:"column:id" json:"id"`
  2968. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2969. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2970. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2971. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2972. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2973. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2974. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2975. Status int64 `gorm:"column:status" json:"status"`
  2976. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  2977. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  2978. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2979. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  2980. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  2981. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  2982. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  2983. }
  2984. func (HisMScheduleDoctorAdviceVM) TableName() string {
  2985. return "xt_schedule"
  2986. }
  2987. type HisMScheduleDoctorAdviceVMOne struct {
  2988. ID int64 `gorm:"column:id" json:"id"`
  2989. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2990. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2991. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2992. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2993. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2994. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2995. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2996. Status int64 `gorm:"column:status" json:"status"`
  2997. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  2998. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  2999. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  3000. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  3001. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  3002. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  3003. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  3004. }
  3005. func (HisMScheduleDoctorAdviceVMOne) TableName() string {
  3006. return "xt_schedule"
  3007. }
  3008. type HisMScheduleProjectVM struct {
  3009. ID int64 `gorm:"column:id" json:"id"`
  3010. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  3011. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  3012. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  3013. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  3014. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  3015. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  3016. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  3017. Status int64 `gorm:"column:status" json:"status"`
  3018. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  3019. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  3020. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  3021. Prescription *models.DialysisPrescriptionTwenty `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  3022. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  3023. HisPrescriptionTeamProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"team_project"`
  3024. }
  3025. func (HisMScheduleProjectVM) TableName() string {
  3026. return "xt_schedule"
  3027. }
  3028. func GetHisDoctorConfig(orgid int64) (models.XtHisConfig, error) {
  3029. config := models.XtHisConfig{}
  3030. err := XTReadDB().Model(&config).Where("user_org_id = ? and status =1", orgid).Find(&config).Error
  3031. return config, err
  3032. }
  3033. func GetHisDoctorPatientById(orgid int64, patientid int64, recordtime int64) (advice []*models.HisDoctorAdviceInfo, err error) {
  3034. db := XTReadDB().Table("his_doctor_advice_info as x").Where("x.status = 1")
  3035. if orgid > 0 {
  3036. db = db.Where("x.user_org_id = ?", orgid)
  3037. }
  3038. if patientid > 0 {
  3039. db = db.Where("x.patient_id =?", patientid)
  3040. }
  3041. if recordtime > 0 {
  3042. db = db.Where("x.advice_date = ?", recordtime)
  3043. }
  3044. 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
  3045. return advice, err
  3046. }
  3047. func GetDoctorAdviceCount(startime int64, endtime int64, deliveway string, orgid int64) (advice []*models.BloodDoctorAdvice, err error) {
  3048. db := XTReadDB().Table("xt_doctor_advice as x").Where("x.status = 1 and x.advice_type =2")
  3049. if startime > 0 {
  3050. db = db.Where("x.advice_date >= ?", startime)
  3051. }
  3052. if endtime > 0 {
  3053. db = db.Where("x.advice_date<=?", endtime)
  3054. }
  3055. if orgid > 0 {
  3056. db = db.Where("x.user_org_id = ?", orgid)
  3057. }
  3058. if len(deliveway) > 0 {
  3059. db = db.Where("x.delivery_way = ?", deliveway)
  3060. }
  3061. 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
  3062. return advice, err
  3063. }
  3064. func GetHisDoctorAdviceCount(startime int64, endtime int64, deliveway string, orgid int64) (advice []*models.BloodDoctorAdvice, err error) {
  3065. db := XTReadDB().Table("his_doctor_advice_info as x").Where("x.status = 1 and x.advice_type =2")
  3066. if startime > 0 {
  3067. db = db.Where("x.advice_date >= ?", startime)
  3068. }
  3069. if endtime > 0 {
  3070. db = db.Where("x.advice_date<=?", endtime)
  3071. }
  3072. if orgid > 0 {
  3073. db = db.Where("x.user_org_id = ?", orgid)
  3074. }
  3075. if len(deliveway) > 0 {
  3076. db = db.Where("x.delivery_way = ?", deliveway)
  3077. }
  3078. 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
  3079. return advice, err
  3080. }
  3081. 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) {
  3082. var vms []*MScheduleDoctorAdviceVM
  3083. adviceWhere := ""
  3084. adviceCondition := []interface{}{}
  3085. if adviceType == 0 {
  3086. if patientType == 0 {
  3087. if patient_id > 0 {
  3088. if execution_state > 0 {
  3089. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  3090. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3091. } else {
  3092. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
  3093. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3094. }
  3095. } else {
  3096. if execution_state > 0 {
  3097. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ?"
  3098. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3099. } else {
  3100. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  3101. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3102. }
  3103. }
  3104. } else if patientType == 1 {
  3105. if patient_id > 0 {
  3106. if execution_state > 0 {
  3107. 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= ?"
  3108. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3109. } else {
  3110. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
  3111. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3112. }
  3113. } else {
  3114. if execution_state > 0 {
  3115. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  3116. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3117. } else {
  3118. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  3119. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3120. }
  3121. }
  3122. } else if patientType == 2 {
  3123. if patient_id > 0 {
  3124. if execution_state > 0 {
  3125. 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 = ?"
  3126. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3127. } else {
  3128. 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 = ?)"
  3129. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3130. }
  3131. } else {
  3132. if execution_state > 0 {
  3133. 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 = ?"
  3134. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3135. } else {
  3136. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  3137. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3138. }
  3139. }
  3140. }
  3141. } else if adviceType == 1 {
  3142. if patientType == 0 {
  3143. if patient_id > 0 {
  3144. if execution_state > 0 {
  3145. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ?"
  3146. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3147. } else {
  3148. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
  3149. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3150. }
  3151. } else {
  3152. if execution_state > 0 {
  3153. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ?"
  3154. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3155. } else {
  3156. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  3157. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3158. }
  3159. }
  3160. } else if patientType == 1 {
  3161. if patient_id > 0 {
  3162. if execution_state > 0 {
  3163. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  3164. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3165. } else {
  3166. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
  3167. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3168. }
  3169. } else {
  3170. if execution_state > 0 {
  3171. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?"
  3172. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3173. } else {
  3174. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  3175. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3176. }
  3177. }
  3178. } else if patientType == 2 {
  3179. if patient_id > 0 {
  3180. if execution_state > 0 {
  3181. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  3182. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3183. } else {
  3184. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
  3185. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3186. }
  3187. } else {
  3188. if execution_state > 0 {
  3189. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ?"
  3190. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3191. } else {
  3192. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  3193. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3194. }
  3195. }
  3196. }
  3197. } else if adviceType == 3 {
  3198. if patientType == 0 {
  3199. if patient_id > 0 {
  3200. if execution_state > 0 {
  3201. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ?"
  3202. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3203. } else {
  3204. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? "
  3205. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3206. }
  3207. } else {
  3208. if execution_state > 0 {
  3209. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? "
  3210. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3211. } else {
  3212. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  3213. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3214. }
  3215. }
  3216. } else if patientType == 1 {
  3217. if patient_id > 0 {
  3218. if execution_state > 0 {
  3219. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  3220. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3221. } else {
  3222. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
  3223. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3224. }
  3225. } else {
  3226. if execution_state > 0 {
  3227. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? "
  3228. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3229. } else {
  3230. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  3231. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3232. }
  3233. }
  3234. } else if patientType == 2 {
  3235. if patient_id > 0 {
  3236. if execution_state > 0 {
  3237. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  3238. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3239. } else {
  3240. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ?"
  3241. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3242. }
  3243. } else {
  3244. if execution_state > 0 {
  3245. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ?"
  3246. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3247. } else {
  3248. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  3249. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3250. }
  3251. }
  3252. }
  3253. } else if adviceType == 2 && len(deliverWay) > 0 {
  3254. if patientType == 0 {
  3255. if patient_id > 0 {
  3256. if execution_state > 0 {
  3257. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  3258. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  3259. } else {
  3260. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ?"
  3261. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  3262. }
  3263. } else {
  3264. if execution_state > 0 {
  3265. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ?"
  3266. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  3267. } else {
  3268. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  3269. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  3270. }
  3271. }
  3272. } else if patientType == 1 {
  3273. if patient_id > 0 {
  3274. if execution_state > 0 {
  3275. 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 = ?"
  3276. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state)
  3277. } else {
  3278. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ?"
  3279. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
  3280. }
  3281. } else {
  3282. if execution_state > 0 {
  3283. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ?"
  3284. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state)
  3285. } else {
  3286. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  3287. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  3288. }
  3289. }
  3290. } else if patientType == 2 {
  3291. if patient_id > 0 {
  3292. if execution_state > 0 {
  3293. 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 = ?"
  3294. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  3295. } else {
  3296. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ?"
  3297. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  3298. }
  3299. } else {
  3300. if execution_state > 0 {
  3301. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ?"
  3302. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  3303. } else {
  3304. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  3305. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  3306. }
  3307. }
  3308. }
  3309. } else if adviceType == 2 && len(deliverWay) <= 0 {
  3310. if patientType == 0 {
  3311. if patient_id > 0 {
  3312. if execution_state > 0 {
  3313. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ?"
  3314. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3315. } else {
  3316. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ?"
  3317. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3318. }
  3319. } else {
  3320. if execution_state > 0 {
  3321. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?"
  3322. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3323. } else {
  3324. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  3325. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3326. }
  3327. }
  3328. } else if patientType == 1 {
  3329. if patient_id > 0 {
  3330. if execution_state > 0 {
  3331. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  3332. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3333. } else {
  3334. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ?"
  3335. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3336. }
  3337. } else {
  3338. if execution_state > 0 {
  3339. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ?"
  3340. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3341. } else {
  3342. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?"
  3343. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3344. }
  3345. }
  3346. } else if patientType == 2 {
  3347. if patient_id > 0 {
  3348. if execution_state > 0 {
  3349. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  3350. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3351. } else {
  3352. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ?"
  3353. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3354. }
  3355. } else {
  3356. if execution_state > 0 {
  3357. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ?"
  3358. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3359. } else {
  3360. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  3361. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3362. }
  3363. }
  3364. }
  3365. }
  3366. db := readDb.Table("xt_schedule")
  3367. if scheduleType > 0 {
  3368. db = db.Where("schedule_type = ?", scheduleType)
  3369. }
  3370. if partitonType > 0 {
  3371. db = db.Where("partition_id = ?", partitonType)
  3372. }
  3373. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3374. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3375. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3376. }).
  3377. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3378. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3379. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3380. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3381. Preload("DoctorAdvices", adviceCondition...).
  3382. Where("status = 1 AND user_org_id = ?", orgID)
  3383. if scheduleDate != 0 {
  3384. db = db.Where("schedule_date = ?", scheduleDate)
  3385. }
  3386. err := db.Find(&vms).Error
  3387. return vms, err
  3388. }
  3389. func GetHisDoctorAdvicesOne(orgID int64, scheduleDate int64, deliverWay string, scheduleType int64, partitionType int64, patient_id int64, execution_state int64, cost_type int64) ([]*HisMScheduleDoctorAdviceVM, error) {
  3390. var vms []*HisMScheduleDoctorAdviceVM
  3391. if len(deliverWay) > 0 {
  3392. db := readDb.Table("xt_schedule")
  3393. if scheduleType > 0 {
  3394. db = db.Where("schedule_type = ?", scheduleType)
  3395. }
  3396. if partitionType > 0 {
  3397. db = db.Where("partition_id = ?", partitionType)
  3398. }
  3399. if patient_id > 0 {
  3400. if execution_state > 0 {
  3401. if cost_type > 0 {
  3402. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  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 = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3406. 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).
  3407. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3408. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).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. } else {
  3416. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3417. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3418. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3419. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3420. 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).
  3421. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3422. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3423. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3424. Where("status = 1 AND user_org_id = ?", orgID)
  3425. if scheduleDate != 0 {
  3426. db = db.Where("schedule_date = ?", scheduleDate)
  3427. }
  3428. err = db.Find(&vms).Error
  3429. }
  3430. } else {
  3431. if cost_type > 0 {
  3432. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3433. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3434. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3435. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3436. 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).
  3437. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3438. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3439. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3440. Where("status = 1 AND user_org_id = ?", orgID)
  3441. if scheduleDate != 0 {
  3442. db = db.Where("schedule_date = ?", scheduleDate)
  3443. }
  3444. err = db.Find(&vms).Error
  3445. } else {
  3446. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3447. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3448. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3449. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3450. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ?", orgID, scheduleDate, deliverWay, patient_id).
  3451. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3452. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3453. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3454. Where("status = 1 AND user_org_id = ?", orgID)
  3455. if scheduleDate != 0 {
  3456. db = db.Where("schedule_date = ?", scheduleDate)
  3457. }
  3458. err = db.Find(&vms).Error
  3459. }
  3460. }
  3461. } else {
  3462. if execution_state > 0 {
  3463. if cost_type > 0 {
  3464. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3465. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3466. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3467. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3468. 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).
  3469. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3470. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3471. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3472. Where("status = 1 AND user_org_id = ?", orgID)
  3473. if scheduleDate != 0 {
  3474. db = db.Where("schedule_date = ?", scheduleDate)
  3475. }
  3476. err = db.Find(&vms).Error
  3477. } else {
  3478. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3479. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3480. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3481. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3482. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_state = ?", orgID, scheduleDate, deliverWay, execution_state).
  3483. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3484. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3485. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3486. Where("status = 1 AND user_org_id = ?", orgID)
  3487. if scheduleDate != 0 {
  3488. db = db.Where("schedule_date = ?", scheduleDate)
  3489. }
  3490. err = db.Find(&vms).Error
  3491. }
  3492. } else {
  3493. if cost_type > 0 {
  3494. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3495. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3496. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3497. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3498. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and is_settle = ?", orgID, scheduleDate, deliverWay, cost_type).
  3499. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3500. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3501. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3502. Where("status = 1 AND user_org_id = ?", orgID)
  3503. if scheduleDate != 0 {
  3504. db = db.Where("schedule_date = ?", scheduleDate)
  3505. }
  3506. err = db.Find(&vms).Error
  3507. } else {
  3508. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3509. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3510. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3511. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3512. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  3513. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3514. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3515. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3516. Where("status = 1 AND user_org_id = ?", orgID)
  3517. if scheduleDate != 0 {
  3518. db = db.Where("schedule_date = ?", scheduleDate)
  3519. }
  3520. err = db.Find(&vms).Error
  3521. }
  3522. }
  3523. }
  3524. } else {
  3525. db := readDb.Table("xt_schedule")
  3526. if scheduleType > 0 {
  3527. db = db.Where("schedule_type = ?", scheduleType)
  3528. }
  3529. if partitionType > 0 {
  3530. db = db.Where("partition_id = ?", partitionType)
  3531. }
  3532. if patient_id > 0 {
  3533. if execution_state > 0 {
  3534. if cost_type > 0 {
  3535. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  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 = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3539. 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).
  3540. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3541. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).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. } else {
  3549. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3550. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3551. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3552. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3553. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and execution_state = ?", orgID, scheduleDate, patient_id, execution_state).
  3554. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3555. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3556. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3557. Where("status = 1 AND user_org_id = ?", orgID)
  3558. if scheduleDate != 0 {
  3559. db = db.Where("schedule_date = ?", scheduleDate)
  3560. }
  3561. err = db.Find(&vms).Error
  3562. }
  3563. } else {
  3564. if cost_type > 0 {
  3565. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3566. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3567. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3568. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3569. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and is_settle = ?", orgID, scheduleDate, patient_id, cost_type).
  3570. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3571. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3572. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3573. Where("status = 1 AND user_org_id = ?", orgID)
  3574. if scheduleDate != 0 {
  3575. db = db.Where("schedule_date = ?", scheduleDate)
  3576. }
  3577. err = db.Find(&vms).Error
  3578. } else {
  3579. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3580. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3581. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3582. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3583. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3584. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3585. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3586. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3587. Where("status = 1 AND user_org_id = ?", orgID)
  3588. if scheduleDate != 0 {
  3589. db = db.Where("schedule_date = ?", scheduleDate)
  3590. }
  3591. err = db.Find(&vms).Error
  3592. }
  3593. }
  3594. } else {
  3595. if execution_state > 0 {
  3596. if cost_type > 0 {
  3597. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3598. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3599. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3600. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3601. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ? and is_settle = ?", orgID, scheduleDate, execution_state, cost_type).
  3602. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3603. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3604. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3605. Where("status = 1 AND user_org_id = ?", orgID)
  3606. if scheduleDate != 0 {
  3607. db = db.Where("schedule_date = ?", scheduleDate)
  3608. }
  3609. err = db.Find(&vms).Error
  3610. } else {
  3611. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3612. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3613. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3614. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3615. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ?", orgID, scheduleDate, execution_state).
  3616. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3617. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3618. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3619. Where("status = 1 AND user_org_id = ?", orgID)
  3620. if scheduleDate != 0 {
  3621. db = db.Where("schedule_date = ?", scheduleDate)
  3622. }
  3623. err = db.Find(&vms).Error
  3624. }
  3625. } else {
  3626. if cost_type > 0 {
  3627. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3628. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3629. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3630. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3631. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and is_settle = ?", orgID, scheduleDate, cost_type).
  3632. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3633. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3634. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3635. Where("status = 1 AND user_org_id = ?", orgID)
  3636. if scheduleDate != 0 {
  3637. db = db.Where("schedule_date = ?", scheduleDate)
  3638. }
  3639. err = db.Find(&vms).Error
  3640. } else {
  3641. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3642. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3643. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3644. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3645. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ?", orgID, scheduleDate).
  3646. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3647. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3648. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3649. Where("status = 1 AND user_org_id = ?", orgID)
  3650. if scheduleDate != 0 {
  3651. db = db.Where("schedule_date = ?", scheduleDate)
  3652. }
  3653. err = db.Find(&vms).Error
  3654. }
  3655. }
  3656. }
  3657. }
  3658. return vms, err
  3659. }
  3660. func BatchDeleteMonitor(ids []string) (err error) {
  3661. if len(ids) == 1 {
  3662. err = XTWriteDB().Model(&models.MonitoringRecord{}).Where("id=?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3663. } else {
  3664. err = XTWriteDB().Model(models.MonitoringRecord{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3665. }
  3666. return
  3667. }
  3668. func GetPatientDialysisRecordList(patientid int64, startime int64, endtime int64) (order []*models.XtDialysisOrders, err error) {
  3669. db := XTReadDB().Table("xt_dialysis_order as x").Where("x.status = 1")
  3670. //table := XTReadDB().Table("xt_schedule as s")
  3671. //fmt.Println(table)
  3672. if patientid > 0 {
  3673. db = db.Where("x.patient_id = ?", patientid)
  3674. }
  3675. if startime > 0 {
  3676. db = db.Where("x.dialysis_date>=?", startime)
  3677. }
  3678. if endtime > 0 {
  3679. db = db.Where("x.dialysis_date <= ?", endtime)
  3680. }
  3681. err = db.Select("x.id,x.dialysis_date,x.schedual_type,s.mode_id").Where("s.status=1").Joins("left join xt_schedule as s on x.patient_id = s.patient_id and x.dialysis_date = s.schedule_date ").Group("x.id").Scan(&order).Error
  3682. return order, err
  3683. }
  3684. func GetPatientDialysisRecordListOne(patientid int64, startime int64, endtime int64) (order []*models.XtScheduleSixTy, err error) {
  3685. db := XTReadDB().Table("xt_schedule as x").Where("x.status = 1")
  3686. //table := XTReadDB().Table("xt_schedule as s")
  3687. //fmt.Println(table)
  3688. if patientid > 0 {
  3689. db = db.Where("x.patient_id = ?", patientid)
  3690. }
  3691. if startime > 0 {
  3692. db = db.Where("x.schedule_date>=?", startime)
  3693. }
  3694. if endtime > 0 {
  3695. db = db.Where("x.schedule_date <= ?", endtime)
  3696. }
  3697. err = db.Select("x.id,x.schedule_date,x.schedule_type,x.mode_id").Find(&order).Error
  3698. return order, err
  3699. }
  3700. func BatchDeleteAdvice(ids []string) (err error) {
  3701. if len(ids) == 1 {
  3702. err = XTWriteDB().Model(&models.DoctorAdvice{}).Where("id=?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3703. } else {
  3704. err = XTWriteDB().Model(models.DoctorAdvice{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3705. }
  3706. return
  3707. }
  3708. func BatchDeleteHisAdvice(ids []string) (err error) {
  3709. if len(ids) == 1 {
  3710. err = XTWriteDB().Model(&models.HisDoctorAdviceInfo{}).Where("id = ?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3711. } else {
  3712. err = XTWriteDB().Model(models.HisDoctorAdviceInfo{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3713. }
  3714. return
  3715. }
  3716. func UpdateAutoReduceDetail(good_id int64, count int64, record_time int64, patient_id int64) (models.AutomaticReduceDetail, error) {
  3717. detail := models.AutomaticReduceDetail{}
  3718. 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
  3719. return detail, err
  3720. }
  3721. func DeleteAutoReduceDetail(good_id int64, record_time int64, patient_id int64) error {
  3722. detail := models.AutomaticReduceDetail{}
  3723. 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
  3724. return err
  3725. }
  3726. func DeleteDialysisBeforOne(good_id int64, record_time int64, patient_id int64) error {
  3727. detail := models.DialysisBeforePrepare{}
  3728. 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
  3729. return err
  3730. }
  3731. func BatchAdviceCheck(ids []string, creator int64) error {
  3732. advice := models.XtDoctorAdvice{}
  3733. 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
  3734. return err
  3735. }
  3736. func BatchHisAdviceCheck(ids []string, creator int64) error {
  3737. advice := models.HisDoctorAdviceInfo{}
  3738. 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
  3739. return err
  3740. }
  3741. func BatchAdviceExecution(ids []string, creator int64, execution_state int64) error {
  3742. advice := models.XtDoctorAdvice{}
  3743. 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
  3744. return err
  3745. }
  3746. func BatchHisAdviceExecution(ids []string, creator int64, execution_state int64) error {
  3747. advice := models.HisDoctorAdviceInfo{}
  3748. 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
  3749. return err
  3750. }
  3751. func GetAdviceExecutionById(ids []string) (doctor []*models.XtDoctorAdvice, err error) {
  3752. err = XTReadDB().Model(&doctor).Where("id IN(?) AND status = 1", ids).Find(&doctor).Error
  3753. return doctor, err
  3754. }
  3755. func GetHisAdviceExecutionById(ids []string) (doctor []*models.HisDoctorAdviceInfo, err error) {
  3756. err = XTReadDB().Model(&doctor).Where("id IN(?) AND status = 1", ids).Find(&doctor).Error
  3757. return doctor, err
  3758. }
  3759. func GetHisProjectConfig(orgid int64) (models.XtHisProjectConfig, error) {
  3760. config := models.XtHisProjectConfig{}
  3761. err := XTReadDB().Model(&config).Where("user_org_id = ? and status =1", orgid).Find(&config).Error
  3762. return config, err
  3763. }
  3764. func GetHisPrescriptionProject(org_id int64, patient_id int64, record_date int64) (project []*models.HisPrescriptionProject, err error) {
  3765. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("GoodInfo", func(db *gorm.DB) *gorm.DB {
  3766. return db.Preload("GoodsType", "status = 1").Where("status = 1 and is_warehouse = 1")
  3767. }).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
  3768. return
  3769. }
  3770. func GetPCHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64, patient_id int64, execution_state int64) ([]*HisMScheduleProjectVM, error) {
  3771. var vms []*HisMScheduleProjectVM
  3772. if patientType == 0 {
  3773. if patient_id > 0 {
  3774. if execution_state == 1 {
  3775. db := readDb.
  3776. Table("xt_schedule").
  3777. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3778. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3779. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3780. }).
  3781. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3782. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3783. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3784. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3785. 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")
  3786. }).
  3787. Preload("HisPrescriptionTeamProject", 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("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  3789. }).Where("status = 1 AND user_org_id = ?", orgID)
  3790. if scheduleDate != 0 {
  3791. db = db.Where("schedule_date = ?", scheduleDate)
  3792. }
  3793. err = db.Find(&vms).Error
  3794. } else if execution_state == 2 {
  3795. db := readDb.
  3796. Table("xt_schedule").
  3797. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3798. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3799. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3800. }).
  3801. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3802. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3803. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3804. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3805. 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")
  3806. }).
  3807. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3808. 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")
  3809. }).Where("status = 1 AND user_org_id = ?", orgID)
  3810. if scheduleDate != 0 {
  3811. db = db.Where("schedule_date = ?", scheduleDate)
  3812. }
  3813. err = db.Find(&vms).Error
  3814. } else if execution_state == 0 {
  3815. db := readDb.
  3816. Table("xt_schedule").
  3817. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3818. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3819. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3820. }).
  3821. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3822. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3823. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3824. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3825. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3826. }).
  3827. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3828. 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")
  3829. }).Where("status = 1 AND user_org_id = ?", orgID)
  3830. if scheduleDate != 0 {
  3831. db = db.Where("schedule_date = ?", scheduleDate)
  3832. }
  3833. err = db.Find(&vms).Error
  3834. }
  3835. } else {
  3836. if patient_id > 0 {
  3837. if execution_state == 1 {
  3838. db := readDb.
  3839. Table("xt_schedule").
  3840. Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
  3841. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3842. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3843. }).
  3844. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3845. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3846. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3847. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3848. 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")
  3849. }).
  3850. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3851. 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")
  3852. }).Where("status = 1 AND user_org_id = ?", orgID)
  3853. if scheduleDate != 0 {
  3854. db = db.Where("schedule_date = ?", scheduleDate)
  3855. }
  3856. err = db.Find(&vms).Error
  3857. } else if execution_state == 2 {
  3858. db := readDb.
  3859. Table("xt_schedule").
  3860. Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
  3861. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3862. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3863. }).
  3864. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3865. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3866. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3867. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3868. 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")
  3869. }).
  3870. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3871. 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")
  3872. }).Where("status = 1 AND user_org_id = ?", orgID)
  3873. if scheduleDate != 0 {
  3874. db = db.Where("schedule_date = ?", scheduleDate)
  3875. }
  3876. err = db.Find(&vms).Error
  3877. } else if execution_state == 0 {
  3878. db := readDb.
  3879. Table("xt_schedule").
  3880. Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
  3881. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3882. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3883. }).
  3884. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3885. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3886. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3887. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3888. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3889. }).
  3890. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3891. 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")
  3892. }).Where("status = 1 AND user_org_id = ?", orgID)
  3893. if scheduleDate != 0 {
  3894. db = db.Where("schedule_date = ?", scheduleDate)
  3895. }
  3896. err = db.Find(&vms).Error
  3897. }
  3898. } else {
  3899. if execution_state == 1 {
  3900. db := readDb.
  3901. Table("xt_schedule").
  3902. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3903. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3904. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3905. }).
  3906. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3907. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3908. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3909. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3910. 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")
  3911. }).
  3912. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3913. 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")
  3914. }).Where("status = 1 AND user_org_id = ?", orgID)
  3915. if scheduleDate != 0 {
  3916. db = db.Where("schedule_date = ?", scheduleDate)
  3917. }
  3918. err = db.Find(&vms).Error
  3919. } else if execution_state == 2 {
  3920. fmt.Println("j氯332n323232n323ℹ️33232323232")
  3921. db := readDb.
  3922. Table("xt_schedule").
  3923. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3924. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3925. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3926. }).
  3927. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3928. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3929. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3930. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3931. 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")
  3932. }).
  3933. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3934. 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")
  3935. }).Where("status = 1 AND user_org_id = ?", orgID)
  3936. if scheduleDate != 0 {
  3937. db = db.Where("schedule_date = ?", scheduleDate)
  3938. }
  3939. err = db.Find(&vms).Error
  3940. } else if execution_state == 0 {
  3941. db := readDb.
  3942. Table("xt_schedule").
  3943. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3944. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3945. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3946. }).
  3947. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3948. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3949. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3950. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3951. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3952. }).
  3953. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3954. 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")
  3955. }).Where("status = 1 AND user_org_id = ?", orgID)
  3956. if scheduleDate != 0 {
  3957. db = db.Where("schedule_date = ?", scheduleDate)
  3958. }
  3959. err = db.Find(&vms).Error
  3960. }
  3961. }
  3962. }
  3963. }
  3964. if patientType > 0 {
  3965. if execution_state == 1 {
  3966. db := readDb.
  3967. Table("xt_schedule").
  3968. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3969. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3970. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3971. }).
  3972. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3973. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3974. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3975. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  3976. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3977. 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")
  3978. }).
  3979. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3980. 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")
  3981. }).Where("status = 1 AND user_org_id = ?", orgID)
  3982. if scheduleDate != 0 {
  3983. db = db.Where("schedule_date = ?", scheduleDate)
  3984. }
  3985. err = db.Find(&vms).Error
  3986. } else if execution_state == 2 {
  3987. db := readDb.
  3988. Table("xt_schedule").
  3989. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3990. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3991. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3992. }).
  3993. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3994. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3995. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3996. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  3997. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3998. 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")
  3999. }).
  4000. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  4001. 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")
  4002. }).Where("status = 1 AND user_org_id = ?", orgID)
  4003. if scheduleDate != 0 {
  4004. db = db.Where("schedule_date = ?", scheduleDate)
  4005. }
  4006. err = db.Find(&vms).Error
  4007. } else if execution_state == 0 {
  4008. db := readDb.
  4009. Table("xt_schedule").
  4010. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  4011. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  4012. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  4013. }).
  4014. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  4015. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  4016. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  4017. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  4018. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  4019. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  4020. }).
  4021. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  4022. 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")
  4023. }).Where("status = 1 AND user_org_id = ?", orgID)
  4024. if scheduleDate != 0 {
  4025. db = db.Where("schedule_date = ?", scheduleDate)
  4026. }
  4027. err = db.Find(&vms).Error
  4028. }
  4029. }
  4030. return vms, err
  4031. }
  4032. func UpdateStockGoods(good_id int64, record_time int64, patient_id int64, count int64) error {
  4033. prepare := models.DialysisBeforePrepare{}
  4034. var err error
  4035. if count > 0 {
  4036. 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
  4037. }
  4038. if count <= 0 {
  4039. err = XTWriteDB().Model(&prepare).Where("good_id= ? and record_date = ? and patient_id = ? and count <> 0 and status = 1", good_id, record_time, patient_id).Updates(map[string]interface{}{"count": count, "status": 0}).Error
  4040. }
  4041. return err
  4042. }
  4043. func UPdateAutoStockGoods(good_id int64, record_time int64, patient_id int64, count int64) error {
  4044. detail := models.AutomaticReduceDetail{}
  4045. 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
  4046. return err
  4047. }
  4048. func MobileGetDialysisSolutionByModeIdSeven(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  4049. var record models.DialysisSolution
  4050. 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
  4051. if err != nil {
  4052. if err == gorm.ErrRecordNotFound {
  4053. return nil, nil
  4054. } else {
  4055. return nil, err
  4056. }
  4057. }
  4058. return &record, nil
  4059. }
  4060. func MobileGetLastDialysisPrescribeByModeIdSeven(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  4061. var record models.DialysisPrescription
  4062. 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
  4063. if err != nil {
  4064. if err == gorm.ErrRecordNotFound {
  4065. return nil, nil
  4066. } else {
  4067. return nil, err
  4068. }
  4069. }
  4070. return &record, nil
  4071. }
  4072. func MobileGetLastDialysisPrescription(patientID int64, orgID int64) (models.DialysisPrescriptionThrity, error) {
  4073. prescription := models.DialysisPrescriptionThrity{}
  4074. err := readDb.Model(&prescription).Where("patient_id = ? and user_org_id = ? and status = 1 and remark<>''", patientID, orgID).Last(&prescription).Error
  4075. return prescription, err
  4076. }
  4077. func MobileGetSystemDialysisPrescribeByModeIdSeven(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  4078. var record models.SystemPrescription
  4079. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).First(&record).Error
  4080. if err != nil {
  4081. if err == gorm.ErrRecordNotFound {
  4082. return nil, nil
  4083. } else {
  4084. return nil, err
  4085. }
  4086. }
  4087. return &record, nil
  4088. }
  4089. // 透前评估
  4090. func MobileGetPredialysisEvaluationSeven(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
  4091. var record models.PredialysisEvaluation
  4092. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  4093. if err != nil {
  4094. if err == gorm.ErrRecordNotFound {
  4095. return nil, nil
  4096. } else {
  4097. return nil, err
  4098. }
  4099. }
  4100. return &record, nil
  4101. }
  4102. //
  4103. //func MobileGetDialysisGoodsSix(orgID int64, scheduleDate int64) (prepare []*models.DialysisBeforePrepare, err error) {
  4104. //
  4105. // 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
  4106. // return prepare, err
  4107. //}
  4108. func GetMobileAutoReduce(orgID int64, scheduleDate int64) (auto []*models.AutomaticReduceDetail, err error) {
  4109. err = readDb.Where("org_id = ? and status = 1 and record_time = ?", orgID, scheduleDate).Find(&auto).Error
  4110. return auto, err
  4111. }
  4112. func GetRoleList(orgid int64, admin_user_id int64) (models.SgjUserAdminRole, error) {
  4113. role := models.SgjUserAdminRole{}
  4114. err = readUserDb.Where("org_id = ? and admin_user_id = ? and status =1 ", orgid, admin_user_id).Find(&role).Error
  4115. return role, err
  4116. }
  4117. func GetDialysisGood(orgID int64, scheduleDate int64) (auto []*models.AutomaticReduceDetail, err error) {
  4118. err = readDb.Where("org_id = ? and status = 1 and record_time >= ?", orgID, scheduleDate).Group("patient_id").Find(&auto).Error
  4119. return auto, err
  4120. }
  4121. func GetGoodWarehouseOutInfo(orgId int64, patient_id int64, sys_record_time int64) (outifno []*models.WarehouseOutInfoSeven, err error) {
  4122. err = readDb.Where("org_id = ? and patient_id = ? and sys_record_time = ? and status = 1", orgId, patient_id, sys_record_time).Find(&outifno).Error
  4123. return outifno, err
  4124. }
  4125. func GetLastDilysisOrder(orgid int64, patient_id int64, dialysis_date int64) (models.DialysisOrder, error) {
  4126. order := models.DialysisOrder{}
  4127. err = XTReadDB().Where("user_org_id = ? and patient_id = ? and dialysis_date < ? and status= 1", orgid, patient_id, dialysis_date).Last(&order).Error
  4128. return order, err
  4129. }
  4130. func GetFistMonitor(orgid int64, patient_id int64, dialysis_date int64) (models.MonitoringRecord, error) {
  4131. record := models.MonitoringRecord{}
  4132. err := XTReadDB().Where("org_id = ? and patient_id = ? and monitoring_date = ? and status = 1", orgid, patient_id, dialysis_date).Find(&record).Error
  4133. return record, err
  4134. }
  4135. func GetFistMonitorSix(orgid int64, patient_id int64, dialysis_date int64) (record []*models.MonitoringRecord, err error) {
  4136. err = XTReadDB().Where("user_org_id = ? and patient_id = ? and monitoring_date = ? and status = 1", orgid, patient_id, dialysis_date).Find(&record).Error
  4137. return record, err
  4138. }
  4139. func MobileGetScheduleDoctorAdvicesOne(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string, scheduleType int64, partitonType int64, patient_id int64, execution_state int64, cost_type int64, execution_frequency string, keyword string) ([]*MScheduleDoctorAdviceVM, error) {
  4140. var vms []*MScheduleDoctorAdviceVM
  4141. keyword = "%" + keyword + "%"
  4142. adviceWhere := ""
  4143. adviceCondition := []interface{}{}
  4144. if adviceType == 0 {
  4145. if patientType == 0 {
  4146. if patient_id > 0 {
  4147. if execution_state > 0 {
  4148. if cost_type > 0 {
  4149. if len(execution_frequency) > 0 {
  4150. if len(keyword) > 0 {
  4151. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  4152. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4153. } else {
  4154. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ? and is_settle = ? and execution_frequency = ?"
  4155. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4156. }
  4157. } else {
  4158. if len(keyword) > 0 {
  4159. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ? and is_settle = ? and advice_name like ?"
  4160. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  4161. } else {
  4162. 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 = ?"
  4163. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4164. }
  4165. }
  4166. } else {
  4167. if len(execution_frequency) > 0 {
  4168. if len(keyword) > 0 {
  4169. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ? and execution_frequency = ? and advice_name like ?"
  4170. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  4171. } else {
  4172. 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 = ?"
  4173. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4174. }
  4175. } else {
  4176. if len(keyword) > 0 {
  4177. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ? and advice_name like ?"
  4178. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  4179. } else {
  4180. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  4181. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4182. }
  4183. }
  4184. }
  4185. } else {
  4186. if cost_type > 0 {
  4187. if len(execution_frequency) > 0 {
  4188. 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 = ?"
  4189. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4190. } else {
  4191. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and is_settle = ?"
  4192. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4193. }
  4194. } else {
  4195. if len(execution_frequency) > 0 {
  4196. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_frequency = ?"
  4197. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4198. } else {
  4199. if len(keyword) > 0 {
  4200. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and advice_name like ?"
  4201. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  4202. } else {
  4203. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
  4204. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4205. }
  4206. }
  4207. }
  4208. }
  4209. } else {
  4210. if execution_state > 0 {
  4211. if cost_type > 0 {
  4212. if len(execution_frequency) > 0 {
  4213. if len(keyword) > 0 {
  4214. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  4215. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  4216. } else {
  4217. 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 = ?"
  4218. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4219. }
  4220. } else {
  4221. if len(keyword) > 0 {
  4222. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and is_settle = ? and advice_name like ?"
  4223. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  4224. } else {
  4225. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and is_settle = ?"
  4226. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4227. }
  4228. }
  4229. } else {
  4230. if len(execution_frequency) > 0 {
  4231. if len(keyword) > 0 {
  4232. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and execution_frequency = ? and advice_name like ?"
  4233. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  4234. } else {
  4235. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and execution_frequency = ?"
  4236. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4237. }
  4238. } else {
  4239. if len(keyword) > 0 {
  4240. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and advice_name like ?"
  4241. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  4242. } else {
  4243. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ?"
  4244. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4245. }
  4246. }
  4247. }
  4248. } else {
  4249. if cost_type > 0 {
  4250. if len(execution_frequency) > 0 {
  4251. if len(keyword) > 0 {
  4252. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ? and execution_frequency = ? and advice_name like ?"
  4253. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  4254. } else {
  4255. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ? and execution_frequency = ?"
  4256. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  4257. }
  4258. } else {
  4259. if len(keyword) > 0 {
  4260. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ? and advice_name like ?"
  4261. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  4262. } else {
  4263. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ?"
  4264. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4265. }
  4266. }
  4267. } else {
  4268. if len(execution_frequency) > 0 {
  4269. if len(keyword) > 0 {
  4270. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_frequency = ? and advice_name like ?"
  4271. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  4272. } else {
  4273. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_frequency = ?"
  4274. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  4275. }
  4276. } else {
  4277. if len(keyword) > 0 {
  4278. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and advice_name like ?"
  4279. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  4280. } else {
  4281. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  4282. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4283. }
  4284. }
  4285. }
  4286. }
  4287. }
  4288. } else if patientType == 1 {
  4289. if patient_id > 0 {
  4290. if execution_state > 0 {
  4291. if cost_type > 0 {
  4292. if len(execution_frequency) > 0 {
  4293. if len(keyword) > 0 {
  4294. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  4295. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4296. } else {
  4297. 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 = ?"
  4298. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  4299. }
  4300. } else {
  4301. if len(keyword) > 0 {
  4302. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ? and is_settle = ? and advice_name like ?"
  4303. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, keyword)
  4304. } else {
  4305. 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 = ?"
  4306. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  4307. }
  4308. }
  4309. } else {
  4310. if len(execution_frequency) > 0 {
  4311. if len(keyword) > 0 {
  4312. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ? and execution_frequency = ? and advice_name like ?"
  4313. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  4314. } else {
  4315. 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 = ?"
  4316. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  4317. }
  4318. } else {
  4319. if len(keyword) > 0 {
  4320. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ? and advice_name like ?"
  4321. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, keyword)
  4322. } else {
  4323. 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= ?"
  4324. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  4325. }
  4326. }
  4327. }
  4328. } else {
  4329. if cost_type > 0 {
  4330. if len(execution_frequency) > 0 {
  4331. if len(keyword) > 0 {
  4332. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ? and is_settle=? and execution_frequency = ? and advice_name like ?"
  4333. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  4334. } else {
  4335. 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 = ?"
  4336. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  4337. }
  4338. } else {
  4339. if len(keyword) > 0 {
  4340. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ? and is_settle=? and advice_name like ?"
  4341. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, keyword)
  4342. } else {
  4343. 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=?"
  4344. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  4345. }
  4346. }
  4347. } else {
  4348. if len(execution_frequency) > 0 {
  4349. if len(keyword) > 0 {
  4350. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_frequency = ? and advice_name like ?"
  4351. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency, keyword)
  4352. } else {
  4353. 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 = ?"
  4354. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  4355. }
  4356. } else {
  4357. if len(keyword) > 0 {
  4358. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ? and advice_name like ?"
  4359. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, keyword)
  4360. } else {
  4361. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
  4362. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  4363. }
  4364. }
  4365. }
  4366. }
  4367. } else {
  4368. if execution_state > 0 {
  4369. if cost_type > 0 {
  4370. if len(execution_frequency) > 0 {
  4371. if len(keyword) > 0 {
  4372. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ? and is_settle=? and execution_frequency = ? and advice_name like ?"
  4373. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  4374. } else {
  4375. 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 = ?"
  4376. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  4377. }
  4378. } else {
  4379. if len(keyword) > 0 {
  4380. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ? and is_settle=? and advice_name like ?"
  4381. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, keyword)
  4382. } else {
  4383. 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=?"
  4384. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  4385. }
  4386. }
  4387. } else {
  4388. if len(execution_frequency) > 0 {
  4389. if len(keyword) > 0 {
  4390. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ? and execution_frequency = ? and advice_name like ?"
  4391. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency, keyword)
  4392. } else {
  4393. 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 = ?"
  4394. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  4395. }
  4396. } else {
  4397. if len(keyword) > 0 {
  4398. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ? and advice_name like ?"
  4399. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, keyword)
  4400. } else {
  4401. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  4402. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  4403. }
  4404. }
  4405. }
  4406. } else {
  4407. if cost_type > 0 {
  4408. if len(execution_frequency) > 0 {
  4409. if len(keyword) > 0 {
  4410. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and is_settle=? and execution_frequency = ? and advice_name like ?"
  4411. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency, keyword)
  4412. } else {
  4413. 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 = ?"
  4414. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  4415. }
  4416. } else {
  4417. if len(keyword) > 0 {
  4418. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and is_settle=? and advice_name like ?"
  4419. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, keyword)
  4420. } else {
  4421. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and is_settle=?"
  4422. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  4423. }
  4424. }
  4425. } else {
  4426. if len(execution_frequency) > 0 {
  4427. if len(keyword) > 0 {
  4428. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_frequency = ? and advice_name like ?"
  4429. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency, keyword)
  4430. } else {
  4431. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_frequency = ?"
  4432. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  4433. }
  4434. } else {
  4435. if len(keyword) > 0 {
  4436. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and advice_name like ?"
  4437. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, keyword)
  4438. } else {
  4439. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  4440. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  4441. }
  4442. }
  4443. }
  4444. }
  4445. }
  4446. } else if patientType == 2 {
  4447. if patient_id > 0 {
  4448. if execution_state > 0 {
  4449. if cost_type > 0 {
  4450. if len(execution_frequency) > 0 {
  4451. if len(keyword) > 0 {
  4452. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?) and execution_state = ? and is_settle=? and execution_frequency = ? and advice_name like ?"
  4453. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4454. } else {
  4455. 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 = ?"
  4456. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4457. }
  4458. } else {
  4459. if len(keyword) > 0 {
  4460. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?) and execution_state = ? and is_settle=? and advice_name like ?"
  4461. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  4462. } else {
  4463. 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=?"
  4464. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4465. }
  4466. }
  4467. } else {
  4468. if len(execution_frequency) > 0 {
  4469. if len(keyword) > 0 {
  4470. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?) and execution_state = ?and execution_frequency = ? and advice_name like ?"
  4471. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  4472. } else {
  4473. 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 = ?"
  4474. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4475. }
  4476. } else {
  4477. if len(keyword) > 0 {
  4478. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?) and execution_state = ? and advice_name like ?"
  4479. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  4480. } else {
  4481. 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 = ?"
  4482. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4483. }
  4484. }
  4485. }
  4486. } else {
  4487. if cost_type > 0 {
  4488. if len(execution_frequency) > 0 {
  4489. if len(keyword) > 0 {
  4490. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?) and is_settle=? and execution_frequency = ? and advice_name like ?"
  4491. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  4492. } else {
  4493. 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 = ?"
  4494. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4495. }
  4496. } else {
  4497. if len(keyword) > 0 {
  4498. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?) and is_settle=? and advice_name like ?"
  4499. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  4500. } else {
  4501. 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=?"
  4502. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4503. }
  4504. }
  4505. } else {
  4506. if len(execution_frequency) > 0 {
  4507. if len(keyword) > 0 {
  4508. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?)and execution_frequency = ? and advice_name like ?"
  4509. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  4510. } else {
  4511. 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 = ?"
  4512. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4513. }
  4514. } else {
  4515. if len(keyword) > 0 {
  4516. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?) and advice_name like ?"
  4517. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  4518. } else {
  4519. 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 = ?)"
  4520. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4521. }
  4522. }
  4523. }
  4524. }
  4525. } else {
  4526. if execution_state > 0 {
  4527. if cost_type > 0 {
  4528. if len(execution_frequency) > 0 {
  4529. if len(keyword) > 0 {
  4530. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1) and execution_state = ? and is_settle=? and execution_frequency = ? and advice_name like ?"
  4531. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  4532. } else {
  4533. 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 = ?"
  4534. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4535. }
  4536. } else {
  4537. if len(keyword) > 0 {
  4538. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1) and execution_state = ? and is_settle=? and advice_name like ?"
  4539. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  4540. } else {
  4541. 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=?"
  4542. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4543. }
  4544. }
  4545. } else {
  4546. if len(execution_frequency) > 0 {
  4547. if len(keyword) > 0 {
  4548. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1) and execution_state = ? and execution_frequency = ? and advice_name like ?"
  4549. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  4550. } else {
  4551. 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 = ?"
  4552. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4553. }
  4554. } else {
  4555. if len(keyword) > 0 {
  4556. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1) and execution_state = ? and advice_name like ?"
  4557. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  4558. } else {
  4559. 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 = ?"
  4560. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4561. }
  4562. }
  4563. }
  4564. } else {
  4565. if cost_type > 0 {
  4566. if len(execution_frequency) > 0 {
  4567. if len(keyword) > 0 {
  4568. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1) and is_settle = ? and execution_frequency = ? and advice_name like ?"
  4569. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  4570. } else {
  4571. 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 = ?"
  4572. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  4573. }
  4574. } else {
  4575. if len(keyword) > 0 {
  4576. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1) and is_settle = ? and advice_name like ?"
  4577. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  4578. } else {
  4579. 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 = ?"
  4580. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4581. }
  4582. }
  4583. } else {
  4584. if len(execution_frequency) > 0 {
  4585. if len(keyword) > 0 {
  4586. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1) and execution_frequency = ? and advice_name like ?"
  4587. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  4588. } else {
  4589. 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 = ?"
  4590. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  4591. }
  4592. } else {
  4593. if len(keyword) > 0 {
  4594. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1) and advice_name like ?"
  4595. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  4596. } else {
  4597. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  4598. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4599. }
  4600. }
  4601. }
  4602. }
  4603. }
  4604. }
  4605. } else if adviceType == 1 {
  4606. if patientType == 0 {
  4607. if patient_id > 0 {
  4608. if execution_state > 0 {
  4609. if cost_type > 0 {
  4610. if len(execution_frequency) > 0 {
  4611. if len(keyword) > 0 {
  4612. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  4613. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4614. } else {
  4615. 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 = ?"
  4616. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4617. }
  4618. } else {
  4619. if len(keyword) > 0 {
  4620. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  4621. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  4622. } else {
  4623. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  4624. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4625. }
  4626. }
  4627. } else {
  4628. if len(execution_frequency) > 0 {
  4629. if len(keyword) > 0 {
  4630. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  4631. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  4632. } else {
  4633. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  4634. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4635. }
  4636. } else {
  4637. if len(keyword) > 0 {
  4638. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  4639. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  4640. } else {
  4641. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ?"
  4642. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4643. }
  4644. }
  4645. }
  4646. } else {
  4647. if cost_type > 0 {
  4648. if len(execution_frequency) > 0 {
  4649. if len(keyword) > 0 {
  4650. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  4651. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  4652. } else {
  4653. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  4654. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4655. }
  4656. } else {
  4657. if len(keyword) > 0 {
  4658. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? and advice_name like ? "
  4659. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  4660. } else {
  4661. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? "
  4662. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4663. }
  4664. }
  4665. } else {
  4666. if len(execution_frequency) > 0 {
  4667. if len(keyword) > 0 {
  4668. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and advice_name like ?"
  4669. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  4670. } else {
  4671. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
  4672. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4673. }
  4674. }
  4675. }
  4676. }
  4677. } else {
  4678. if execution_state > 0 {
  4679. if cost_type > 0 {
  4680. if len(execution_frequency) > 0 {
  4681. if len(keyword) > 0 {
  4682. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  4683. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  4684. } else {
  4685. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  4686. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4687. }
  4688. } else {
  4689. if len(keyword) > 0 {
  4690. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  4691. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  4692. } else {
  4693. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ?"
  4694. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4695. }
  4696. }
  4697. } else {
  4698. if len(execution_frequency) > 0 {
  4699. if len(keyword) > 0 {
  4700. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  4701. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  4702. } else {
  4703. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and execution_frequency = ?"
  4704. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4705. }
  4706. } else {
  4707. if len(keyword) > 0 {
  4708. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and advice_name like ?"
  4709. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  4710. } else {
  4711. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ?"
  4712. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4713. }
  4714. }
  4715. }
  4716. } else {
  4717. if cost_type > 0 {
  4718. if len(keyword) > 0 {
  4719. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = ? and advice_name like ?"
  4720. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  4721. } else {
  4722. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = ? "
  4723. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4724. }
  4725. } else {
  4726. if len(keyword) > 0 {
  4727. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and advice_name like ?"
  4728. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  4729. } else {
  4730. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  4731. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4732. }
  4733. }
  4734. }
  4735. }
  4736. } else if patientType == 1 {
  4737. if patient_id > 0 {
  4738. if execution_state > 0 {
  4739. if cost_type > 0 {
  4740. if len(execution_frequency) > 0 {
  4741. if len(keyword) > 0 {
  4742. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  4743. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4744. } else {
  4745. 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 = ?"
  4746. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  4747. }
  4748. } else {
  4749. if len(keyword) > 0 {
  4750. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  4751. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, keyword)
  4752. } else {
  4753. 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 = ?"
  4754. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  4755. }
  4756. }
  4757. } else {
  4758. if len(execution_frequency) > 0 {
  4759. if len(keyword) > 0 {
  4760. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  4761. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  4762. } else {
  4763. 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 = ?"
  4764. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  4765. }
  4766. } else {
  4767. if len(keyword) > 0 {
  4768. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  4769. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, keyword)
  4770. } else {
  4771. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  4772. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  4773. }
  4774. }
  4775. }
  4776. } else {
  4777. if cost_type > 0 {
  4778. if len(execution_frequency) > 0 {
  4779. if len(keyword) > 0 {
  4780. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and is_settle = ?and execution_frequency = ? and advice_name like ?"
  4781. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  4782. } else {
  4783. 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 = ?"
  4784. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  4785. }
  4786. } else {
  4787. if len(keyword) > 0 {
  4788. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  4789. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, keyword)
  4790. } else {
  4791. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  4792. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  4793. }
  4794. }
  4795. } else {
  4796. if len(execution_frequency) > 0 {
  4797. if len(keyword) > 0 {
  4798. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  4799. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency, keyword)
  4800. } else {
  4801. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  4802. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  4803. }
  4804. } else {
  4805. if len(keyword) > 0 {
  4806. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and advice_name like ?"
  4807. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, keyword)
  4808. } else {
  4809. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
  4810. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  4811. }
  4812. }
  4813. }
  4814. }
  4815. } else {
  4816. if execution_state > 0 {
  4817. if cost_type > 0 {
  4818. if len(execution_frequency) > 0 {
  4819. if len(keyword) > 0 {
  4820. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=? and is_settle = ?and execution_frequency = ? and advice_name like ?"
  4821. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  4822. } else {
  4823. 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 = ?"
  4824. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  4825. }
  4826. } else {
  4827. if len(keyword) > 0 {
  4828. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=? and is_settle = ? and advice_name like ?"
  4829. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, keyword)
  4830. } else {
  4831. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=? and is_settle = ?"
  4832. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  4833. }
  4834. }
  4835. } else {
  4836. if len(execution_frequency) > 0 {
  4837. if len(keyword) > 0 {
  4838. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?and execution_frequency = ? and advice_name like ?"
  4839. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency, keyword)
  4840. } else {
  4841. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?and execution_frequency = ?"
  4842. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  4843. }
  4844. } else {
  4845. if len(keyword) > 0 {
  4846. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=? and advice_name like ?"
  4847. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, keyword)
  4848. } else {
  4849. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?"
  4850. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  4851. }
  4852. }
  4853. }
  4854. } else {
  4855. if cost_type > 0 {
  4856. if len(execution_frequency) > 0 {
  4857. if len(keyword) > 0 {
  4858. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  4859. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency, keyword)
  4860. } else {
  4861. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  4862. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  4863. }
  4864. } else {
  4865. if len(keyword) > 0 {
  4866. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? and advice_name like ?"
  4867. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, keyword)
  4868. } else {
  4869. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? "
  4870. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  4871. }
  4872. }
  4873. } else {
  4874. if len(execution_frequency) > 0 {
  4875. if len(keyword) > 0 {
  4876. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_frequency = ? and advice_name like ?"
  4877. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency, keyword)
  4878. } else {
  4879. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_frequency = ?"
  4880. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  4881. }
  4882. } else {
  4883. if len(keyword) > 0 {
  4884. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and advice_name like ?"
  4885. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, keyword)
  4886. } else {
  4887. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  4888. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  4889. }
  4890. }
  4891. }
  4892. }
  4893. }
  4894. } else if patientType == 2 {
  4895. if patient_id > 0 {
  4896. if execution_state > 0 {
  4897. if cost_type > 0 {
  4898. if len(execution_frequency) > 0 {
  4899. if len(keyword) > 0 {
  4900. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ?and execution_frequency = ? and advice_name like ?"
  4901. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4902. } else {
  4903. 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 = ?"
  4904. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4905. }
  4906. } else {
  4907. if len(keyword) > 0 {
  4908. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  4909. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  4910. } else {
  4911. 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 = ?"
  4912. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4913. }
  4914. }
  4915. } else {
  4916. if len(execution_frequency) > 0 {
  4917. if len(keyword) > 0 {
  4918. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  4919. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  4920. } else {
  4921. 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 = ?"
  4922. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4923. }
  4924. } else {
  4925. if len(keyword) > 0 {
  4926. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ? and advice_name like ?"
  4927. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  4928. } else {
  4929. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  4930. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4931. }
  4932. }
  4933. }
  4934. } else {
  4935. if cost_type > 0 {
  4936. if len(execution_frequency) > 0 {
  4937. if len(keyword) > 0 {
  4938. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  4939. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  4940. } else {
  4941. 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 = ?"
  4942. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4943. }
  4944. } else {
  4945. if len(keyword) > 0 {
  4946. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and is_settle = ? and advice_name like ?"
  4947. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  4948. } else {
  4949. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  4950. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4951. }
  4952. }
  4953. } else {
  4954. if len(execution_frequency) > 0 {
  4955. if len(keyword) > 0 {
  4956. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_frequency = ? and advice_name like ?"
  4957. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  4958. } else {
  4959. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_frequency = ?"
  4960. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4961. }
  4962. } else {
  4963. if len(keyword) > 0 {
  4964. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and advice_name like ?"
  4965. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  4966. } else {
  4967. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
  4968. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4969. }
  4970. }
  4971. }
  4972. }
  4973. } else {
  4974. if execution_state > 0 {
  4975. if cost_type > 0 {
  4976. if len(execution_frequency) > 0 {
  4977. if len(keyword) > 0 {
  4978. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  4979. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  4980. } else {
  4981. 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 = ?"
  4982. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4983. }
  4984. } else {
  4985. if len(keyword) > 0 {
  4986. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and is_settle = ? and advice_name like ?"
  4987. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  4988. } else {
  4989. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  4990. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4991. }
  4992. }
  4993. } else {
  4994. if len(execution_frequency) > 0 {
  4995. if len(keyword) > 0 {
  4996. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and execution_frequency = ? and advice_name like ?"
  4997. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  4998. } else {
  4999. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and execution_frequency = ?"
  5000. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  5001. }
  5002. } else {
  5003. if len(keyword) > 0 {
  5004. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and advice_name like ?"
  5005. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  5006. } else {
  5007. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ?"
  5008. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5009. }
  5010. }
  5011. }
  5012. } else {
  5013. if cost_type > 0 {
  5014. if len(execution_frequency) > 0 {
  5015. if len(keyword) > 0 {
  5016. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5017. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  5018. } else {
  5019. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  5020. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  5021. }
  5022. } else {
  5023. if len(keyword) > 0 {
  5024. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ? and advice_name like ?"
  5025. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  5026. } else {
  5027. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ?"
  5028. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5029. }
  5030. }
  5031. } else {
  5032. if len(execution_frequency) > 0 {
  5033. if len(keyword) > 0 {
  5034. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_frequency = ? and advice_name like ?"
  5035. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  5036. } else {
  5037. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_frequency = ?"
  5038. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  5039. }
  5040. } else {
  5041. if len(keyword) > 0 {
  5042. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and advice_name like ?"
  5043. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  5044. } else {
  5045. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  5046. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5047. }
  5048. }
  5049. }
  5050. }
  5051. }
  5052. }
  5053. } else if adviceType == 3 {
  5054. if patientType == 0 {
  5055. if patient_id > 0 {
  5056. if execution_state > 0 {
  5057. if cost_type > 0 {
  5058. if len(execution_frequency) > 0 {
  5059. if len(keyword) > 0 {
  5060. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency =? and advice_name like ?"
  5061. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5062. } else {
  5063. 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 =?"
  5064. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  5065. }
  5066. } else {
  5067. if len(keyword) > 0 {
  5068. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5069. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  5070. } else {
  5071. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  5072. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5073. }
  5074. }
  5075. } else {
  5076. if len(execution_frequency) > 0 {
  5077. if len(keyword) > 0 {
  5078. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency =? and advice_name like ?"
  5079. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  5080. } else {
  5081. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency =?"
  5082. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  5083. }
  5084. } else {
  5085. if len(keyword) > 0 {
  5086. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  5087. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  5088. } else {
  5089. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ?"
  5090. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5091. }
  5092. }
  5093. }
  5094. } else {
  5095. if cost_type > 0 {
  5096. if len(execution_frequency) > 0 {
  5097. if len(keyword) > 0 {
  5098. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency =? and advice_name like ?"
  5099. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  5100. } else {
  5101. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency =?"
  5102. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  5103. }
  5104. } else {
  5105. if len(keyword) > 0 {
  5106. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  5107. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  5108. } else {
  5109. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? "
  5110. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5111. }
  5112. }
  5113. } else {
  5114. if len(execution_frequency) > 0 {
  5115. if len(keyword) > 0 {
  5116. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_frequency =? and advice_name like ?"
  5117. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  5118. } else {
  5119. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_frequency =?"
  5120. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  5121. }
  5122. } else {
  5123. if len(keyword) > 0 {
  5124. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and advice_name like ?"
  5125. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  5126. } else {
  5127. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? "
  5128. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5129. }
  5130. }
  5131. }
  5132. }
  5133. } else {
  5134. if execution_state > 0 {
  5135. if cost_type > 0 {
  5136. if len(execution_frequency) > 0 {
  5137. if len(keyword) > 0 {
  5138. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ? and execution_frequency =? and advice_name like ?"
  5139. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  5140. } else {
  5141. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ? and execution_frequency =?"
  5142. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  5143. }
  5144. } else {
  5145. if len(keyword) > 0 {
  5146. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ? and advice_name like ?"
  5147. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  5148. } else {
  5149. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ?"
  5150. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5151. }
  5152. }
  5153. } else {
  5154. if len(execution_frequency) > 0 {
  5155. if len(keyword) > 0 {
  5156. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and execution_frequency =? and advice_name like ?"
  5157. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  5158. } else {
  5159. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and execution_frequency =?"
  5160. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  5161. }
  5162. } else {
  5163. if len(keyword) > 0 {
  5164. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and advice_name like ?"
  5165. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  5166. } else {
  5167. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? "
  5168. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5169. }
  5170. }
  5171. }
  5172. } else {
  5173. if cost_type > 0 {
  5174. if len(execution_frequency) > 0 {
  5175. if len(keyword) > 0 {
  5176. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? and execution_frequency =? and advice_name like ?"
  5177. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  5178. } else {
  5179. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? and execution_frequency =?"
  5180. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  5181. }
  5182. } else {
  5183. if len(keyword) > 0 {
  5184. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? and advice_name like ?"
  5185. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  5186. } else {
  5187. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? "
  5188. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5189. }
  5190. }
  5191. } else {
  5192. if len(execution_frequency) > 0 {
  5193. if len(keyword) > 0 {
  5194. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_frequency =? and advice_name like ?"
  5195. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  5196. } else {
  5197. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_frequency =?"
  5198. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  5199. }
  5200. } else {
  5201. if len(keyword) > 0 {
  5202. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and advice_name like ?"
  5203. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  5204. } else {
  5205. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  5206. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5207. }
  5208. }
  5209. }
  5210. }
  5211. }
  5212. } else if patientType == 1 {
  5213. if patient_id > 0 {
  5214. if execution_state > 0 {
  5215. if cost_type > 0 {
  5216. if len(execution_frequency) > 0 {
  5217. if len(keyword) > 0 {
  5218. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5219. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5220. } else {
  5221. 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 = ?"
  5222. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  5223. }
  5224. } else {
  5225. if len(keyword) > 0 {
  5226. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5227. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, keyword)
  5228. } else {
  5229. 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 = ?"
  5230. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  5231. }
  5232. }
  5233. } else {
  5234. if len(execution_frequency) > 0 {
  5235. if len(keyword) > 0 {
  5236. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5237. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  5238. } else {
  5239. 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 = ?"
  5240. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  5241. }
  5242. } else {
  5243. if len(keyword) > 0 {
  5244. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  5245. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, keyword)
  5246. } else {
  5247. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  5248. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  5249. }
  5250. }
  5251. }
  5252. } else {
  5253. if cost_type > 0 {
  5254. if len(execution_frequency) > 0 {
  5255. if len(keyword) > 0 {
  5256. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5257. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  5258. } else {
  5259. 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 = ?"
  5260. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  5261. }
  5262. } else {
  5263. if len(keyword) > 0 {
  5264. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  5265. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, keyword)
  5266. } else {
  5267. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  5268. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  5269. }
  5270. }
  5271. } else {
  5272. if len(execution_frequency) > 0 {
  5273. if len(keyword) > 0 {
  5274. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  5275. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency, keyword)
  5276. } else {
  5277. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  5278. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  5279. }
  5280. } else {
  5281. if len(keyword) > 0 {
  5282. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and advice_name like ?"
  5283. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, keyword)
  5284. } else {
  5285. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
  5286. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  5287. }
  5288. }
  5289. }
  5290. }
  5291. } else {
  5292. if execution_state > 0 {
  5293. if cost_type > 0 {
  5294. if len(execution_frequency) > 0 {
  5295. if len(keyword) > 0 {
  5296. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5297. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  5298. } else {
  5299. 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 = ?"
  5300. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  5301. }
  5302. } else {
  5303. if len(keyword) > 0 {
  5304. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? and is_settle = ? and advice_name like ?"
  5305. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, keyword)
  5306. } else {
  5307. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? and is_settle = ?"
  5308. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  5309. }
  5310. }
  5311. } else {
  5312. if len(execution_frequency) > 0 {
  5313. if len(keyword) > 0 {
  5314. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =?and execution_frequency = ? and avice_name like ? "
  5315. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency, keyword)
  5316. } else {
  5317. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =?and execution_frequency = ? "
  5318. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  5319. }
  5320. } else {
  5321. if len(keyword) > 0 {
  5322. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? and advice_name like ?"
  5323. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, keyword)
  5324. } else {
  5325. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? "
  5326. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  5327. }
  5328. }
  5329. }
  5330. } else {
  5331. if cost_type > 0 {
  5332. if len(execution_frequency) > 0 {
  5333. if len(keyword) > 0 {
  5334. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5335. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency, keyword)
  5336. } else {
  5337. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  5338. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  5339. }
  5340. } else {
  5341. if len(keyword) > 0 {
  5342. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ? and advice_name like ?"
  5343. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, keyword)
  5344. } else {
  5345. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ?"
  5346. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  5347. }
  5348. }
  5349. } else {
  5350. if len(execution_frequency) > 0 {
  5351. if len(keyword) > 0 {
  5352. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_frequency = ? and advice_name like ?"
  5353. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency, keyword)
  5354. } else {
  5355. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_frequency = ?"
  5356. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  5357. }
  5358. } else {
  5359. if len(keyword) > 0 {
  5360. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and advice_name like ?"
  5361. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, keyword)
  5362. } else {
  5363. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  5364. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  5365. }
  5366. }
  5367. }
  5368. }
  5369. }
  5370. } else if patientType == 2 {
  5371. if patient_id > 0 {
  5372. if execution_state > 0 {
  5373. if cost_type > 0 {
  5374. if len(execution_frequency) > 0 {
  5375. if len(keyword) > 0 {
  5376. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5377. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5378. } else {
  5379. 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 = ?"
  5380. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  5381. }
  5382. } else {
  5383. if len(keyword) > 0 {
  5384. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5385. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  5386. } else {
  5387. 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 = ?"
  5388. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5389. }
  5390. }
  5391. } else {
  5392. if len(execution_frequency) > 0 {
  5393. if len(keyword) > 0 {
  5394. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5395. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  5396. } else {
  5397. 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 = ?"
  5398. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  5399. }
  5400. } else {
  5401. if len(keyword) > 0 {
  5402. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ? and advice_name like ?"
  5403. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  5404. } else {
  5405. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  5406. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5407. }
  5408. }
  5409. }
  5410. } else {
  5411. if cost_type > 0 {
  5412. if len(execution_frequency) > 0 {
  5413. if len(keyword) > 0 {
  5414. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5415. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  5416. } else {
  5417. 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 = ?"
  5418. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  5419. }
  5420. } else {
  5421. if len(keyword) > 0 {
  5422. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and is_settle = ? and advice_name like ?"
  5423. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  5424. } else {
  5425. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  5426. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5427. }
  5428. }
  5429. } else {
  5430. if len(execution_frequency) > 0 {
  5431. if len(keyword) > 0 {
  5432. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_frequency = ? and advice_name like ?"
  5433. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  5434. } else {
  5435. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_frequency = ?"
  5436. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  5437. }
  5438. } else {
  5439. if len(keyword) > 0 {
  5440. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and advice_name like ?"
  5441. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  5442. } else {
  5443. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ?"
  5444. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5445. }
  5446. }
  5447. }
  5448. }
  5449. } else {
  5450. if execution_state > 0 {
  5451. if cost_type > 0 {
  5452. if len(execution_frequency) > 0 {
  5453. if len(keyword) > 0 {
  5454. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5455. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  5456. } else {
  5457. 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 = ?"
  5458. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  5459. }
  5460. } else {
  5461. if len(keyword) > 0 {
  5462. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and is_settle = ? and advice_name like ?"
  5463. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  5464. } else {
  5465. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and is_settle = ?"
  5466. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5467. }
  5468. }
  5469. } else {
  5470. if len(execution_frequency) > 0 {
  5471. if len(keyword) > 0 {
  5472. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and execution_frequency = ? and advice_name like ?"
  5473. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  5474. } else {
  5475. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and execution_frequency = ?"
  5476. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  5477. }
  5478. } else {
  5479. if len(keyword) > 0 {
  5480. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and advice_name like ?"
  5481. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  5482. } else {
  5483. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ?"
  5484. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5485. }
  5486. }
  5487. }
  5488. } else {
  5489. if cost_type > 0 {
  5490. if len(execution_frequency) > 0 {
  5491. if len(keyword) > 0 {
  5492. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5493. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  5494. } else {
  5495. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  5496. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  5497. }
  5498. } else {
  5499. if len(keyword) > 0 {
  5500. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ? and advice_name like ?"
  5501. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  5502. } else {
  5503. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ?"
  5504. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5505. }
  5506. }
  5507. } else {
  5508. if len(execution_frequency) > 0 {
  5509. if len(keyword) > 0 {
  5510. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_frequency = ? and advice_name like ?"
  5511. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  5512. } else {
  5513. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_frequency = ?"
  5514. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  5515. }
  5516. } else {
  5517. if len(keyword) > 0 {
  5518. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and advice_name like ?"
  5519. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  5520. } else {
  5521. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  5522. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5523. }
  5524. }
  5525. }
  5526. }
  5527. }
  5528. }
  5529. } else if adviceType == 2 && len(deliverWay) > 0 {
  5530. if patientType == 0 {
  5531. if patient_id > 0 {
  5532. if execution_state > 0 {
  5533. if cost_type > 0 {
  5534. if len(execution_frequency) > 0 {
  5535. if len(keyword) > 0 {
  5536. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5537. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5538. } else {
  5539. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5540. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency)
  5541. }
  5542. } else {
  5543. if len(keyword) > 0 {
  5544. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5545. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, keyword)
  5546. } else {
  5547. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  5548. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  5549. }
  5550. }
  5551. } else {
  5552. if len(execution_frequency) > 0 {
  5553. if len(keyword) > 0 {
  5554. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5555. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency, keyword)
  5556. } else {
  5557. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  5558. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency)
  5559. }
  5560. } else {
  5561. if len(keyword) > 0 {
  5562. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  5563. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, keyword)
  5564. } else {
  5565. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  5566. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  5567. }
  5568. }
  5569. }
  5570. } else {
  5571. if cost_type > 0 {
  5572. if len(execution_frequency) > 0 {
  5573. if len(keyword) > 0 {
  5574. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5575. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency, keyword)
  5576. } else {
  5577. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  5578. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency)
  5579. }
  5580. } else {
  5581. if len(keyword) > 0 {
  5582. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  5583. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, keyword)
  5584. } else {
  5585. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and is_settle = ?"
  5586. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  5587. }
  5588. }
  5589. } else {
  5590. if len(execution_frequency) > 0 {
  5591. if len(keyword) > 0 {
  5592. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  5593. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency, keyword)
  5594. } else {
  5595. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and execution_frequency = ?"
  5596. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency)
  5597. }
  5598. } else {
  5599. if len(keyword) > 0 {
  5600. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and advice_name like ?"
  5601. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, keyword)
  5602. } else {
  5603. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ?"
  5604. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  5605. }
  5606. }
  5607. }
  5608. }
  5609. } else {
  5610. if execution_state > 0 {
  5611. if cost_type > 0 {
  5612. if len(execution_frequency) > 0 {
  5613. if len(keyword) > 0 {
  5614. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5615. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency, keyword)
  5616. } else {
  5617. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5618. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency)
  5619. }
  5620. } else {
  5621. if len(keyword) > 0 {
  5622. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5623. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, keyword)
  5624. } else {
  5625. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and execution_state = ? and is_settle = ?"
  5626. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  5627. }
  5628. }
  5629. } else {
  5630. if len(execution_frequency) > 0 {
  5631. if len(keyword) > 0 {
  5632. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5633. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency, keyword)
  5634. } else {
  5635. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and execution_state = ? and execution_frequency = ?"
  5636. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency)
  5637. }
  5638. } else {
  5639. if len(keyword) > 0 {
  5640. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and execution_state = ? and advice_name like ?"
  5641. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, keyword)
  5642. } else {
  5643. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and execution_state = ?"
  5644. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  5645. }
  5646. }
  5647. }
  5648. } else {
  5649. if cost_type > 0 {
  5650. if len(execution_frequency) > 0 {
  5651. if len(keyword) > 0 {
  5652. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5653. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, execution_frequency, keyword)
  5654. } else {
  5655. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and is_settle = ? and execution_frequency = ?"
  5656. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, execution_frequency)
  5657. }
  5658. } else {
  5659. if len(keyword) > 0 {
  5660. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3)2 AND record_date = ? and delivery_way = ? and is_settle = ? and advice_name like ?"
  5661. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, keyword)
  5662. } else {
  5663. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and is_settle = ?"
  5664. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  5665. }
  5666. }
  5667. } else {
  5668. if len(execution_frequency) > 0 {
  5669. if len(keyword) > 0 {
  5670. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and execution_frequency = ? and advice_name like ?"
  5671. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_frequency, keyword)
  5672. } else {
  5673. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and execution_frequency = ?"
  5674. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_frequency)
  5675. }
  5676. } else {
  5677. if len(keyword) > 0 {
  5678. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and advice_name like ?"
  5679. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, keyword)
  5680. } else {
  5681. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ?"
  5682. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  5683. }
  5684. }
  5685. }
  5686. }
  5687. }
  5688. } else if patientType == 1 {
  5689. if patient_id > 0 {
  5690. if execution_state > 0 {
  5691. if cost_type > 0 {
  5692. if len(execution_frequency) > 0 {
  5693. if len(keyword) > 0 {
  5694. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5695. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5696. } else {
  5697. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5698. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type, execution_frequency)
  5699. }
  5700. } else {
  5701. if len(keyword) > 0 {
  5702. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5703. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type, keyword)
  5704. } else {
  5705. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  5706. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type)
  5707. }
  5708. }
  5709. } else {
  5710. if len(execution_frequency) > 0 {
  5711. if len(keyword) > 0 {
  5712. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5713. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, execution_frequency, keyword)
  5714. } else {
  5715. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  5716. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, execution_frequency)
  5717. }
  5718. } else {
  5719. if len(keyword) > 0 {
  5720. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  5721. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, keyword)
  5722. } else {
  5723. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  5724. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state)
  5725. }
  5726. }
  5727. }
  5728. } else {
  5729. if cost_type > 0 {
  5730. if len(execution_frequency) > 0 {
  5731. if len(keyword) > 0 {
  5732. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5733. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type, execution_frequency, keyword)
  5734. } else {
  5735. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  5736. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type, execution_frequency)
  5737. }
  5738. } else {
  5739. if len(keyword) > 0 {
  5740. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  5741. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type, keyword)
  5742. } else {
  5743. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and is_settle = ?"
  5744. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type)
  5745. }
  5746. }
  5747. } else {
  5748. if len(execution_frequency) > 0 {
  5749. if len(keyword) > 0 {
  5750. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  5751. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_frequency, keyword)
  5752. } else {
  5753. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_frequency = ?"
  5754. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_frequency)
  5755. }
  5756. } else {
  5757. if len(keyword) > 0 {
  5758. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and avice_name like ?"
  5759. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, keyword)
  5760. } else {
  5761. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ?"
  5762. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
  5763. }
  5764. }
  5765. }
  5766. }
  5767. } else {
  5768. if execution_state > 0 {
  5769. if cost_type > 0 {
  5770. if len(execution_frequency) > 0 {
  5771. if len(keyword) > 0 {
  5772. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5773. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type, execution_frequency, keyword)
  5774. } else {
  5775. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5776. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type, execution_frequency)
  5777. }
  5778. } else {
  5779. if len(keyword) > 0 {
  5780. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5781. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type, keyword)
  5782. } else {
  5783. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and execution_state = ? and is_settle = ?"
  5784. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type)
  5785. }
  5786. }
  5787. } else {
  5788. if len(execution_frequency) > 0 {
  5789. if len(keyword) > 0 {
  5790. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5791. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, execution_frequency, keyword)
  5792. } else {
  5793. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and execution_state = ? and execution_frequency = ?"
  5794. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, execution_frequency)
  5795. }
  5796. } else {
  5797. if len(keyword) > 0 {
  5798. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and execution_state = ? and advice_name like ?"
  5799. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, keyword)
  5800. } else {
  5801. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and execution_state = ?"
  5802. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state)
  5803. }
  5804. }
  5805. }
  5806. } else {
  5807. if cost_type > 0 {
  5808. if len(execution_frequency) > 0 {
  5809. if len(keyword) > 0 {
  5810. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND(advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5811. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type, execution_frequency, keyword)
  5812. } else {
  5813. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and is_settle = ? and execution_frequency = ?"
  5814. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type, execution_frequency)
  5815. }
  5816. } else {
  5817. if len(keyword) > 0 {
  5818. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and is_settle = ? and advice_name like ?"
  5819. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type, keyword)
  5820. } else {
  5821. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and is_settle = ?"
  5822. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type)
  5823. }
  5824. }
  5825. } else {
  5826. if len(execution_frequency) > 0 {
  5827. if len(keyword) > 0 {
  5828. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and execution_frequency = ? and advic_name like ?"
  5829. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_frequency, keyword)
  5830. } else {
  5831. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and execution_frequency = ?"
  5832. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_frequency)
  5833. }
  5834. } else {
  5835. if len(keyword) > 0 {
  5836. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and advice_name like ?"
  5837. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, keyword)
  5838. } else {
  5839. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? "
  5840. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  5841. }
  5842. }
  5843. }
  5844. }
  5845. }
  5846. } else if patientType == 2 {
  5847. if patient_id > 0 {
  5848. if execution_state > 0 {
  5849. if cost_type > 0 {
  5850. if len(execution_frequency) > 0 {
  5851. if len(keyword) > 0 {
  5852. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5853. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5854. } else {
  5855. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5856. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency)
  5857. }
  5858. } else {
  5859. if len(keyword) > 0 {
  5860. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5861. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, keyword)
  5862. } else {
  5863. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3)2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  5864. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  5865. }
  5866. }
  5867. } else {
  5868. if len(execution_frequency) > 0 {
  5869. if len(keyword) > 0 {
  5870. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5871. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency, keyword)
  5872. } else {
  5873. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  5874. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency)
  5875. }
  5876. } else {
  5877. if len(keyword) > 0 {
  5878. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  5879. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, keyword)
  5880. } else {
  5881. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ?"
  5882. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  5883. }
  5884. }
  5885. }
  5886. } else {
  5887. if cost_type > 0 {
  5888. if len(execution_frequency) > 0 {
  5889. if len(keyword) > 0 {
  5890. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5891. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency, keyword)
  5892. } else {
  5893. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  5894. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency)
  5895. }
  5896. } else {
  5897. if len(keyword) > 0 {
  5898. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  5899. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, keyword)
  5900. } else {
  5901. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and is_settle = ?"
  5902. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  5903. }
  5904. }
  5905. } else {
  5906. if len(execution_frequency) > 0 {
  5907. if len(keyword) > 0 {
  5908. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  5909. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency, keyword)
  5910. } else {
  5911. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_frequency = ?"
  5912. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency)
  5913. }
  5914. } else {
  5915. if len(keyword) > 0 {
  5916. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and advice_name like ?"
  5917. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, keyword)
  5918. } else {
  5919. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ?"
  5920. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  5921. }
  5922. }
  5923. }
  5924. }
  5925. } else {
  5926. if execution_state > 0 {
  5927. if cost_type > 0 {
  5928. if len(execution_frequency) > 0 {
  5929. if len(keyword) > 0 {
  5930. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5931. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency, keyword)
  5932. } else {
  5933. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5934. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency)
  5935. }
  5936. } else {
  5937. if len(keyword) > 0 {
  5938. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5939. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, keyword)
  5940. } else {
  5941. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and execution_state = ? and is_settle = ?"
  5942. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  5943. }
  5944. }
  5945. } else {
  5946. if len(execution_frequency) > 0 {
  5947. if len(keyword) > 0 {
  5948. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5949. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency, keyword)
  5950. } else {
  5951. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and execution_state = ? and execution_frequency = ?"
  5952. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency)
  5953. }
  5954. } else {
  5955. if len(keyword) > 0 {
  5956. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and execution_state = ? and advice_name like ?"
  5957. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, keyword)
  5958. } else {
  5959. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and execution_state = ?"
  5960. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  5961. }
  5962. }
  5963. }
  5964. } else {
  5965. if cost_type > 0 {
  5966. if len(execution_frequency) > 0 {
  5967. if len(keyword) > 0 {
  5968. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and is_settle = ? and advice_name like ?"
  5969. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, keyword)
  5970. } else {
  5971. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and is_settle = ?"
  5972. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  5973. }
  5974. } else {
  5975. if len(keyword) > 0 {
  5976. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and is_settle = ? and advice_name like ?"
  5977. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, keyword)
  5978. } else {
  5979. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and is_settle = ?"
  5980. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  5981. }
  5982. }
  5983. } else {
  5984. if len(keyword) > 0 {
  5985. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and advice_name like ?"
  5986. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, keyword)
  5987. } else {
  5988. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ?"
  5989. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  5990. }
  5991. }
  5992. }
  5993. }
  5994. }
  5995. } else if adviceType == 2 && len(deliverWay) <= 0 {
  5996. if patientType == 0 {
  5997. if patient_id > 0 {
  5998. if execution_state > 0 {
  5999. if cost_type > 0 {
  6000. if len(execution_frequency) > 0 {
  6001. if len(keyword) > 0 {
  6002. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6003. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  6004. } else {
  6005. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  6006. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  6007. }
  6008. } else {
  6009. if len(keyword) > 0 {
  6010. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  6011. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  6012. } else {
  6013. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  6014. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6015. }
  6016. }
  6017. } else {
  6018. if len(execution_frequency) > 0 {
  6019. if len(keyword) > 0 {
  6020. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  6021. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  6022. } else {
  6023. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  6024. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  6025. }
  6026. } else {
  6027. if len(keyword) > 0 {
  6028. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  6029. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  6030. } else {
  6031. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and execution_state = ?"
  6032. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6033. }
  6034. }
  6035. }
  6036. } else {
  6037. if cost_type > 0 {
  6038. if len(execution_frequency) > 0 {
  6039. if len(keyword) > 0 {
  6040. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6041. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  6042. } else {
  6043. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  6044. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  6045. }
  6046. } else {
  6047. if len(keyword) > 0 {
  6048. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  6049. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  6050. } else {
  6051. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and is_settle = ?"
  6052. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6053. }
  6054. }
  6055. } else {
  6056. if len(execution_frequency) > 0 {
  6057. if len(keyword) > 0 {
  6058. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  6059. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  6060. } else {
  6061. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and execution_frequency = ?"
  6062. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  6063. }
  6064. } else {
  6065. if len(keyword) > 0 {
  6066. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and advice_name like ?"
  6067. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  6068. } else {
  6069. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ?"
  6070. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6071. }
  6072. }
  6073. }
  6074. }
  6075. } else {
  6076. if execution_state > 0 {
  6077. if cost_type > 0 {
  6078. if len(execution_frequency) > 0 {
  6079. if len(keyword) > 0 {
  6080. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6081. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  6082. } else {
  6083. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  6084. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  6085. }
  6086. } else {
  6087. if len(keyword) > 0 {
  6088. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  6089. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  6090. } else {
  6091. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and execution_state = ? and is_settle = ?"
  6092. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6093. }
  6094. }
  6095. } else {
  6096. if len(execution_frequency) > 0 {
  6097. if len(keyword) > 0 {
  6098. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and execution_state = ?and execution_frequency = ? and advice_name like ?"
  6099. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  6100. } else {
  6101. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and execution_state = ?and execution_frequency = ?"
  6102. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  6103. }
  6104. } else {
  6105. if len(keyword) > 0 {
  6106. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and execution_state = ? and advice_name like ?"
  6107. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  6108. } else {
  6109. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and execution_state = ?"
  6110. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6111. }
  6112. }
  6113. }
  6114. } else {
  6115. if cost_type > 0 {
  6116. if len(execution_frequency) > 0 {
  6117. if len(keyword) > 0 {
  6118. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6119. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  6120. } else {
  6121. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and is_settle = ? and execution_frequency = ?"
  6122. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  6123. }
  6124. }
  6125. } else {
  6126. if len(execution_frequency) > 0 {
  6127. if len(keyword) > 0 {
  6128. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and execution_frequency = ? and advice_name like ?"
  6129. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  6130. } else {
  6131. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and execution_frequency = ?"
  6132. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  6133. }
  6134. } else {
  6135. if len(keyword) > 0 {
  6136. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and advice_name like ?"
  6137. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  6138. } else {
  6139. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ?"
  6140. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6141. }
  6142. }
  6143. }
  6144. }
  6145. }
  6146. } else if patientType == 1 {
  6147. if patient_id > 0 {
  6148. if execution_state > 0 {
  6149. if cost_type > 0 {
  6150. if len(execution_frequency) > 0 {
  6151. if len(keyword) > 0 {
  6152. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6153. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  6154. } else {
  6155. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  6156. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  6157. }
  6158. } else {
  6159. if len(keyword) > 0 {
  6160. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  6161. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, keyword)
  6162. } else {
  6163. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  6164. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  6165. }
  6166. }
  6167. } else {
  6168. if len(execution_frequency) > 0 {
  6169. if len(keyword) > 0 {
  6170. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  6171. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  6172. } else {
  6173. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  6174. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  6175. }
  6176. } else {
  6177. if len(keyword) > 0 {
  6178. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  6179. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, keyword)
  6180. } else {
  6181. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  6182. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  6183. }
  6184. }
  6185. }
  6186. } else {
  6187. if cost_type > 0 {
  6188. if len(execution_frequency) > 0 {
  6189. if len(keyword) > 0 {
  6190. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3)2 AND advice_doctor = ? and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6191. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  6192. } else {
  6193. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  6194. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  6195. }
  6196. } else {
  6197. if len(keyword) > 0 {
  6198. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  6199. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, keyword)
  6200. } else {
  6201. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  6202. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  6203. }
  6204. }
  6205. } else {
  6206. if len(execution_frequency) > 0 {
  6207. if len(keyword) > 0 {
  6208. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  6209. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency, keyword)
  6210. } else {
  6211. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  6212. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  6213. }
  6214. } else {
  6215. if len(keyword) > 0 {
  6216. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and advice_name like ?"
  6217. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, keyword)
  6218. } else {
  6219. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ?"
  6220. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  6221. }
  6222. }
  6223. }
  6224. }
  6225. } else {
  6226. if execution_state > 0 {
  6227. if cost_type > 0 {
  6228. if len(execution_frequency) > 0 {
  6229. if len(keyword) > 0 {
  6230. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6231. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  6232. } else {
  6233. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  6234. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  6235. }
  6236. } else {
  6237. if len(keyword) > 0 {
  6238. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  6239. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, keyword)
  6240. } else {
  6241. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and execution_state = ? and is_settle = ?"
  6242. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  6243. }
  6244. }
  6245. } else {
  6246. if len(execution_frequency) > 0 {
  6247. if len(keyword) > 0 {
  6248. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  6249. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency, keyword)
  6250. } else {
  6251. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and execution_state = ? and execution_frequency = ?"
  6252. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  6253. }
  6254. } else {
  6255. if len(keyword) > 0 {
  6256. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and execution_state = ? and advice_name like ?"
  6257. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, keyword)
  6258. } else {
  6259. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and execution_state = ?"
  6260. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  6261. }
  6262. }
  6263. }
  6264. } else {
  6265. if cost_type > 0 {
  6266. if len(execution_frequency) > 0 {
  6267. if len(keyword) > 0 {
  6268. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6269. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency, keyword)
  6270. } else {
  6271. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  6272. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  6273. }
  6274. } else {
  6275. if len(keyword) > 0 {
  6276. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and is_settle = ? and advice_name like ?"
  6277. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, keyword)
  6278. } else {
  6279. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and is_settle = ?"
  6280. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  6281. }
  6282. }
  6283. } else {
  6284. if len(execution_frequency) > 0 {
  6285. if len(keyword) > 0 {
  6286. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and execution_frequency = ? and advice_name like ?"
  6287. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency, keyword)
  6288. } else {
  6289. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and execution_frequency = ?"
  6290. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  6291. }
  6292. } else {
  6293. if len(keyword) > 0 {
  6294. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and advice_name like ?"
  6295. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, keyword)
  6296. } else {
  6297. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ?"
  6298. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  6299. }
  6300. }
  6301. }
  6302. }
  6303. }
  6304. } else if patientType == 2 {
  6305. if patient_id > 0 {
  6306. if execution_state > 0 {
  6307. if cost_type > 0 {
  6308. if len(execution_frequency) > 0 {
  6309. if len(keyword) > 0 {
  6310. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency=? and advice_name like ?"
  6311. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  6312. } else {
  6313. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency=?"
  6314. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  6315. }
  6316. } else {
  6317. if len(keyword) > 0 {
  6318. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  6319. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  6320. } else {
  6321. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3)2 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ?"
  6322. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6323. }
  6324. }
  6325. } else {
  6326. if len(execution_frequency) > 0 {
  6327. if len(keyword) > 0 {
  6328. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and execution_state = ? and execution_frequency=? and advice_name like ?"
  6329. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  6330. } else {
  6331. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and execution_state = ? and execution_frequency=?"
  6332. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  6333. }
  6334. } else {
  6335. if len(keyword) > 0 {
  6336. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and execution_state = ? and advice_name like ?"
  6337. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  6338. } else {
  6339. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  6340. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6341. }
  6342. }
  6343. }
  6344. } else {
  6345. if cost_type > 0 {
  6346. if len(execution_frequency) > 0 {
  6347. if len(keyword) > 0 {
  6348. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and is_settle = ? and execution_frequency=? and advice_name like ?"
  6349. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  6350. } else {
  6351. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and is_settle = ? and execution_frequency=?"
  6352. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  6353. }
  6354. } else {
  6355. if len(keyword) > 0 {
  6356. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and is_settle = ? and advice_name like ?"
  6357. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  6358. } else {
  6359. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  6360. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6361. }
  6362. }
  6363. } else {
  6364. if len(execution_frequency) > 0 {
  6365. if len(keyword) > 0 {
  6366. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and execution_frequency=? and advice_name like ?"
  6367. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  6368. } else {
  6369. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and execution_frequency=?"
  6370. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  6371. }
  6372. } else {
  6373. if len(keyword) > 0 {
  6374. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and advice_name like ?"
  6375. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  6376. } else {
  6377. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ?"
  6378. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6379. }
  6380. }
  6381. }
  6382. }
  6383. } else {
  6384. if execution_state > 0 {
  6385. if cost_type > 0 {
  6386. if len(execution_frequency) > 0 {
  6387. if len(keyword) > 0 {
  6388. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6389. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  6390. } else {
  6391. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and execution_state = ? and is_settle = ? and execution_frequency = ?"
  6392. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  6393. }
  6394. } else {
  6395. if len(keyword) > 0 {
  6396. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and execution_state = ? and is_settle = ? and advice_name like ?"
  6397. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  6398. } else {
  6399. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  6400. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6401. }
  6402. }
  6403. } else {
  6404. if len(execution_frequency) > 0 {
  6405. if len(keyword) > 0 {
  6406. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and execution_state = ? and execution_frequency = ? and advice_name like ?"
  6407. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  6408. } else {
  6409. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and execution_state = ? and execution_frequency = ? "
  6410. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  6411. }
  6412. } else {
  6413. if len(keyword) > 0 {
  6414. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and execution_state = ? and advice_name like ?"
  6415. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  6416. } else {
  6417. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND a(advice_type = 2 or advice_type =3) AND execution_staff = 0 and execution_state = ?"
  6418. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6419. }
  6420. }
  6421. }
  6422. } else {
  6423. if cost_type > 0 {
  6424. if len(execution_frequency) > 0 {
  6425. if len(keyword) > 0 {
  6426. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6427. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  6428. } else {
  6429. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  6430. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  6431. }
  6432. } else {
  6433. if len(keyword) > 0 {
  6434. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and is_settle = ? and advice_name like ?"
  6435. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  6436. } else {
  6437. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and is_settle = ?"
  6438. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6439. }
  6440. }
  6441. } else {
  6442. if len(execution_frequency) > 0 {
  6443. if len(keyword) > 0 {
  6444. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and execution_frequency = ? and advice_name like ?"
  6445. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  6446. } else {
  6447. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and execution_frequency = ?"
  6448. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  6449. }
  6450. } else {
  6451. if len(keyword) > 0 {
  6452. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and advice_name like ?"
  6453. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  6454. } else {
  6455. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0"
  6456. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6457. }
  6458. }
  6459. }
  6460. }
  6461. }
  6462. }
  6463. }
  6464. db := readDb.Table("xt_schedule")
  6465. if scheduleType > 0 {
  6466. db = db.Where("schedule_type = ?", scheduleType)
  6467. }
  6468. if partitonType > 0 {
  6469. db = db.Where("partition_id = ?", partitonType)
  6470. }
  6471. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6472. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6473. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6474. }).
  6475. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6476. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6477. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6478. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6479. Preload("DoctorAdvices", adviceCondition...).
  6480. Where("status = 1 AND user_org_id = ?", orgID)
  6481. if scheduleDate != 0 {
  6482. db = db.Where("schedule_date = ?", scheduleDate)
  6483. }
  6484. err := db.Find(&vms).Error
  6485. return vms, err
  6486. }
  6487. 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) {
  6488. var vms []*MScheduleDoctorAdviceVM
  6489. adviceWhere := ""
  6490. adviceCondition := []interface{}{}
  6491. if adviceType == 0 {
  6492. if patientType == 0 {
  6493. if patient_id > 0 {
  6494. if execution_state > 0 {
  6495. if cost_type > 0 {
  6496. 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 = ?"
  6497. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6498. } else {
  6499. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  6500. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6501. }
  6502. } else {
  6503. if cost_type > 0 {
  6504. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and is_settle = ?"
  6505. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6506. } else {
  6507. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
  6508. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6509. }
  6510. }
  6511. } else {
  6512. if execution_state > 0 {
  6513. if cost_type > 0 {
  6514. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and is_settle = ?"
  6515. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6516. } else {
  6517. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ?"
  6518. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6519. }
  6520. } else {
  6521. if cost_type > 0 {
  6522. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ?"
  6523. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6524. } else {
  6525. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  6526. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6527. }
  6528. }
  6529. }
  6530. } else if patientType == 1 {
  6531. if patient_id > 0 {
  6532. if execution_state > 0 {
  6533. if cost_type > 0 {
  6534. 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 = ?"
  6535. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  6536. } else {
  6537. 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= ?"
  6538. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  6539. }
  6540. } else {
  6541. if cost_type > 0 {
  6542. 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=?"
  6543. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  6544. } else {
  6545. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
  6546. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  6547. }
  6548. }
  6549. } else {
  6550. if execution_state > 0 {
  6551. if cost_type > 0 {
  6552. 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=?"
  6553. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  6554. } else {
  6555. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  6556. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  6557. }
  6558. } else {
  6559. if cost_type > 0 {
  6560. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and is_settle=?"
  6561. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  6562. } else {
  6563. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  6564. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  6565. }
  6566. }
  6567. }
  6568. } else if patientType == 2 {
  6569. if patient_id > 0 {
  6570. if execution_state > 0 {
  6571. if cost_type > 0 {
  6572. 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=?"
  6573. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6574. } else {
  6575. 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 = ?"
  6576. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6577. }
  6578. } else {
  6579. if cost_type > 0 {
  6580. 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=?"
  6581. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6582. } else {
  6583. 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 = ?)"
  6584. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6585. }
  6586. }
  6587. } else {
  6588. if execution_state > 0 {
  6589. if cost_type > 0 {
  6590. 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=?"
  6591. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6592. } else {
  6593. 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 = ?"
  6594. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6595. }
  6596. } else {
  6597. if cost_type > 0 {
  6598. 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 = ?"
  6599. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6600. } else {
  6601. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  6602. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6603. }
  6604. }
  6605. }
  6606. }
  6607. } else if adviceType == 1 {
  6608. if patientType == 0 {
  6609. if patient_id > 0 {
  6610. if execution_state > 0 {
  6611. if cost_type > 0 {
  6612. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  6613. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6614. } else {
  6615. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ?"
  6616. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6617. }
  6618. } else {
  6619. if cost_type > 0 {
  6620. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? "
  6621. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6622. } else {
  6623. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
  6624. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6625. }
  6626. }
  6627. } else {
  6628. if execution_state > 0 {
  6629. if cost_type > 0 {
  6630. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ?"
  6631. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6632. } else {
  6633. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ?"
  6634. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6635. }
  6636. } else {
  6637. if cost_type > 0 {
  6638. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = ? "
  6639. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6640. } else {
  6641. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  6642. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6643. }
  6644. }
  6645. }
  6646. } else if patientType == 1 {
  6647. if patient_id > 0 {
  6648. if execution_state > 0 {
  6649. if cost_type > 0 {
  6650. 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 = ?"
  6651. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  6652. } else {
  6653. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  6654. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  6655. }
  6656. } else {
  6657. if cost_type > 0 {
  6658. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  6659. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  6660. } else {
  6661. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
  6662. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  6663. }
  6664. }
  6665. } else {
  6666. if execution_state > 0 {
  6667. if cost_type > 0 {
  6668. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=? and is_settle = ?"
  6669. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  6670. } else {
  6671. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?"
  6672. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  6673. }
  6674. } else {
  6675. if cost_type > 0 {
  6676. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? "
  6677. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  6678. } else {
  6679. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  6680. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  6681. }
  6682. }
  6683. }
  6684. } else if patientType == 2 {
  6685. if patient_id > 0 {
  6686. if execution_state > 0 {
  6687. if cost_type > 0 {
  6688. 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 = ?"
  6689. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6690. } else {
  6691. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  6692. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6693. }
  6694. } else {
  6695. if cost_type > 0 {
  6696. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  6697. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6698. } else {
  6699. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
  6700. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6701. }
  6702. }
  6703. } else {
  6704. if execution_state > 0 {
  6705. if cost_type > 0 {
  6706. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  6707. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6708. } else {
  6709. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ?"
  6710. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6711. }
  6712. } else {
  6713. if cost_type > 0 {
  6714. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ?"
  6715. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6716. } else {
  6717. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  6718. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6719. }
  6720. }
  6721. }
  6722. }
  6723. } else if adviceType == 3 {
  6724. if patientType == 0 {
  6725. if patient_id > 0 {
  6726. if execution_state > 0 {
  6727. if cost_type > 0 {
  6728. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  6729. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6730. } else {
  6731. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ?"
  6732. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6733. }
  6734. } else {
  6735. if cost_type > 0 {
  6736. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? "
  6737. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6738. } else {
  6739. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? "
  6740. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6741. }
  6742. }
  6743. } else {
  6744. if execution_state > 0 {
  6745. if cost_type > 0 {
  6746. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ?"
  6747. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6748. } else {
  6749. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? "
  6750. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6751. }
  6752. } else {
  6753. if cost_type > 0 {
  6754. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? "
  6755. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6756. } else {
  6757. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  6758. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6759. }
  6760. }
  6761. }
  6762. } else if patientType == 1 {
  6763. if patient_id > 0 {
  6764. if execution_state > 0 {
  6765. if cost_type > 0 {
  6766. 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 = ?"
  6767. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  6768. } else {
  6769. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  6770. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  6771. }
  6772. } else {
  6773. if cost_type > 0 {
  6774. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  6775. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  6776. } else {
  6777. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
  6778. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  6779. }
  6780. }
  6781. } else {
  6782. if execution_state > 0 {
  6783. if cost_type > 0 {
  6784. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? and is_settle = ?"
  6785. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  6786. } else {
  6787. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? "
  6788. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  6789. }
  6790. } else {
  6791. if cost_type > 0 {
  6792. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ?"
  6793. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  6794. } else {
  6795. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  6796. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  6797. }
  6798. }
  6799. }
  6800. } else if patientType == 2 {
  6801. if patient_id > 0 {
  6802. if execution_state > 0 {
  6803. if cost_type > 0 {
  6804. 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 = ?"
  6805. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6806. } else {
  6807. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  6808. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6809. }
  6810. } else {
  6811. if cost_type > 0 {
  6812. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  6813. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6814. } else {
  6815. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ?"
  6816. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6817. }
  6818. }
  6819. } else {
  6820. if execution_state > 0 {
  6821. if cost_type > 0 {
  6822. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and is_settle = ?"
  6823. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6824. } else {
  6825. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ?"
  6826. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6827. }
  6828. } else {
  6829. if cost_type > 0 {
  6830. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ?"
  6831. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6832. } else {
  6833. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  6834. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6835. }
  6836. }
  6837. }
  6838. }
  6839. } else if adviceType == 2 && len(deliverWay) > 0 {
  6840. if patientType == 0 {
  6841. if patient_id > 0 {
  6842. if execution_state > 0 {
  6843. if cost_type > 0 {
  6844. 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 = ?"
  6845. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  6846. } else {
  6847. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  6848. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  6849. }
  6850. } else {
  6851. if cost_type > 0 {
  6852. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and is_settle = ?"
  6853. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  6854. } else {
  6855. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ?"
  6856. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  6857. }
  6858. }
  6859. } else {
  6860. if execution_state > 0 {
  6861. if cost_type > 0 {
  6862. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and is_settle = ?"
  6863. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  6864. } else {
  6865. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ?"
  6866. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  6867. }
  6868. } else {
  6869. if cost_type > 0 {
  6870. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and is_settle = ?"
  6871. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  6872. } else {
  6873. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  6874. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  6875. }
  6876. }
  6877. }
  6878. } else if patientType == 1 {
  6879. if patient_id > 0 {
  6880. if execution_state > 0 {
  6881. if cost_type > 0 {
  6882. 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 = ?"
  6883. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type)
  6884. } else {
  6885. 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 = ?"
  6886. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state)
  6887. }
  6888. } else {
  6889. if cost_type > 0 {
  6890. 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 = ?"
  6891. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type)
  6892. } else {
  6893. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ?"
  6894. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
  6895. }
  6896. }
  6897. } else {
  6898. if execution_state > 0 {
  6899. if cost_type > 0 {
  6900. 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 = ?"
  6901. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type)
  6902. } else {
  6903. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ?"
  6904. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state)
  6905. }
  6906. } else {
  6907. if cost_type > 0 {
  6908. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and is_settle = ?"
  6909. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type)
  6910. } else {
  6911. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  6912. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  6913. }
  6914. }
  6915. }
  6916. } else if patientType == 2 {
  6917. if patient_id > 0 {
  6918. if execution_state > 0 {
  6919. if cost_type > 0 {
  6920. 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 = ?"
  6921. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  6922. } else {
  6923. 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 = ?"
  6924. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  6925. }
  6926. } else {
  6927. if cost_type > 0 {
  6928. 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 = ?"
  6929. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  6930. } else {
  6931. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ?"
  6932. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  6933. }
  6934. }
  6935. } else {
  6936. if execution_state > 0 {
  6937. if cost_type > 0 {
  6938. 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 = ?"
  6939. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  6940. } else {
  6941. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ?"
  6942. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  6943. }
  6944. } else {
  6945. if cost_type > 0 {
  6946. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and is_settle = ?"
  6947. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  6948. } else {
  6949. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  6950. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  6951. }
  6952. }
  6953. }
  6954. }
  6955. } else if adviceType == 2 && len(deliverWay) <= 0 {
  6956. if patientType == 0 {
  6957. if patient_id > 0 {
  6958. if execution_state > 0 {
  6959. if cost_type > 0 {
  6960. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  6961. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6962. } else {
  6963. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ?"
  6964. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6965. }
  6966. } else {
  6967. if cost_type > 0 {
  6968. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and is_settle = ?"
  6969. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6970. } else {
  6971. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ?"
  6972. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6973. }
  6974. }
  6975. } else {
  6976. if execution_state > 0 {
  6977. if cost_type > 0 {
  6978. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ? and is_settle = ?"
  6979. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6980. } else {
  6981. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?"
  6982. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6983. }
  6984. } else {
  6985. if cost_type > 0 {
  6986. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and is_settle = ?"
  6987. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6988. } else {
  6989. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  6990. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6991. }
  6992. }
  6993. }
  6994. } else if patientType == 1 {
  6995. if patient_id > 0 {
  6996. if execution_state > 0 {
  6997. if cost_type > 0 {
  6998. 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 = ?"
  6999. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  7000. } else {
  7001. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  7002. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  7003. }
  7004. } else {
  7005. if cost_type > 0 {
  7006. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  7007. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  7008. } else {
  7009. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ?"
  7010. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  7011. }
  7012. }
  7013. } else {
  7014. if execution_state > 0 {
  7015. if cost_type > 0 {
  7016. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ? and is_settle = ?"
  7017. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  7018. } else {
  7019. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ?"
  7020. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  7021. }
  7022. } else {
  7023. if cost_type > 0 {
  7024. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and is_settle = ?"
  7025. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  7026. } else {
  7027. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?"
  7028. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  7029. }
  7030. }
  7031. }
  7032. } else if patientType == 2 {
  7033. if patient_id > 0 {
  7034. if execution_state > 0 {
  7035. if cost_type > 0 {
  7036. 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 = ?"
  7037. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  7038. } else {
  7039. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  7040. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  7041. }
  7042. } else {
  7043. if cost_type > 0 {
  7044. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  7045. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  7046. } else {
  7047. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ?"
  7048. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  7049. }
  7050. }
  7051. } else {
  7052. if execution_state > 0 {
  7053. if cost_type > 0 {
  7054. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  7055. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  7056. } else {
  7057. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ?"
  7058. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  7059. }
  7060. } else {
  7061. if cost_type > 0 {
  7062. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and is_settle = ?"
  7063. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  7064. } else {
  7065. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  7066. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  7067. }
  7068. }
  7069. }
  7070. }
  7071. }
  7072. db := readDb.Table("xt_schedule")
  7073. if scheduleType > 0 {
  7074. db = db.Where("schedule_type = ?", scheduleType)
  7075. }
  7076. if partitonType > 0 {
  7077. db = db.Where("partition_id = ?", partitonType)
  7078. }
  7079. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7080. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7081. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7082. }).
  7083. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7084. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7085. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7086. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7087. Preload("DoctorAdvices", adviceCondition...).
  7088. Where("status = 1 AND user_org_id = ?", orgID)
  7089. if scheduleDate != 0 {
  7090. db = db.Where("schedule_date = ?", scheduleDate)
  7091. }
  7092. err := db.Find(&vms).Error
  7093. return vms, err
  7094. }
  7095. func GetLastPatientOrder(id int64) (models.XtDialysisOrder, error) {
  7096. order := models.XtDialysisOrder{}
  7097. err := XTReadDB().Where("id = ? and status = 1", id).Find(&order).Error
  7098. return order, err
  7099. }
  7100. func UpdateMobilePatient(org_id int64, patient_id int64, schedule_remark string) error {
  7101. order := models.XtPatients{}
  7102. 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
  7103. 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
  7104. return err
  7105. }
  7106. func GetDialysisTotalCount(org_id int64, patient_id int64) (models.BloodDialysisOrderCount, error) {
  7107. order := models.BloodDialysisOrderCount{}
  7108. db := XTReadDB().Table("xt_dialysis_order as o")
  7109. 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
  7110. return order, err
  7111. }
  7112. func GetDialysisTotalCountOne(org_id int64, patient_id int64) (models.BloodDialysisOrderCount, error) {
  7113. order := models.BloodDialysisOrderCount{}
  7114. db := XTReadDB().Table("xt_dialysis_order as o")
  7115. 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>=1704038400 and x.schedule_date = o.dialysis_date and x.status = 1 ", org_id, patient_id).Scan(&order).Error
  7116. return order, err
  7117. }
  7118. func UpdateDialysisOrder(patient_id int64, dialysis_date int64, user_org_id int64, dialysis_total int64) (models.DialysisOrder, error) {
  7119. order := models.DialysisOrder{}
  7120. 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
  7121. return order, err
  7122. }
  7123. func UpdateDeviceInformation(patientid int64, dialysis_date int64) error {
  7124. information := models.DeviceInformation{}
  7125. err := UserWriteDB().Model(&information).Where("patient_id = ? and date = ? and status = 1", patientid, dialysis_date).Update(map[string]interface{}{"status": 0}).Error
  7126. return err
  7127. }
  7128. func MobileGetDoubleCheckSix(orgID int64, patientID int64, recordDate int64) (models.DoubleCheck, error) {
  7129. var record models.DoubleCheck
  7130. err := readDb.Where("patient_id = ? and user_org_id = ? and status = 1 and check_date = ?", patientID, orgID, recordDate).First(&record).Error
  7131. return record, err
  7132. }
  7133. func GetFirstMonitor(patient_id int64, monit_date int64) (models.MonitoringRecord, error) {
  7134. record := models.MonitoringRecord{}
  7135. err := XTReadDB().Where("patient_id = ? and monitoring_date = ? and status=1", patient_id, monit_date).First(&record).Error
  7136. return record, err
  7137. }
  7138. func GetFirstMonitorOne(patient_id int64, monit_date int64, org_id int64) (models.MonitoringRecord, error) {
  7139. record := models.MonitoringRecord{}
  7140. err := XTReadDB().Where("patient_id = ? and monitoring_date = ? and status=1 and user_org_id=?", patient_id, monit_date, org_id).First(&record).Error
  7141. return record, err
  7142. }
  7143. func GetLastMonitor(patient_id int64, monit_date int64, org_id int64) (models.MonitoringRecord, error) {
  7144. record := models.MonitoringRecord{}
  7145. err := XTReadDB().Where("patient_id = ? and monitoring_date = ? and status=1 and user_org_id = ?", patient_id, monit_date, org_id).Last(&record).Error
  7146. return record, err
  7147. }
  7148. func UpdateFirstMonitor(id int64, catheter_operation string) (models.MonitoringRecord, error) {
  7149. record := models.MonitoringRecord{}
  7150. err := XTWriteDB().Model(&record).Where("id = ? and status= 1", id).Updates(map[string]interface{}{"dispose": catheter_operation}).Error
  7151. return record, err
  7152. }
  7153. 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) {
  7154. var vms []*HisMScheduleDoctorAdviceVM
  7155. if len(deliverWay) > 0 {
  7156. db := readDb.Table("xt_schedule")
  7157. if scheduleType > 0 {
  7158. db = db.Where("schedule_type = ?", scheduleType)
  7159. }
  7160. if partitionType > 0 {
  7161. db = db.Where("partition_id = ?", partitionType)
  7162. }
  7163. if patient_id > 0 {
  7164. if execution_state > 0 {
  7165. if cost_type > 0 {
  7166. if len(execution_frequency) > 0 {
  7167. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7168. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7169. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7170. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7171. 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).
  7172. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7173. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7174. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7175. Where("status = 1 AND user_org_id = ?", orgID)
  7176. if scheduleDate != 0 {
  7177. db = db.Where("schedule_date = ?", scheduleDate)
  7178. }
  7179. err = db.Find(&vms).Error
  7180. } else {
  7181. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7182. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7183. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7184. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7185. 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).
  7186. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7187. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7188. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7189. Where("status = 1 AND user_org_id = ?", orgID)
  7190. if scheduleDate != 0 {
  7191. db = db.Where("schedule_date = ?", scheduleDate)
  7192. }
  7193. err = db.Find(&vms).Error
  7194. }
  7195. } else {
  7196. if len(execution_frequency) > 0 {
  7197. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7198. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7199. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7200. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7201. 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).
  7202. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7203. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7204. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7205. Where("status = 1 AND user_org_id = ?", orgID)
  7206. if scheduleDate != 0 {
  7207. db = db.Where("schedule_date = ?", scheduleDate)
  7208. }
  7209. err = db.Find(&vms).Error
  7210. } else {
  7211. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7212. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7213. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7214. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7215. 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).
  7216. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7217. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7218. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7219. Where("status = 1 AND user_org_id = ?", orgID)
  7220. if scheduleDate != 0 {
  7221. db = db.Where("schedule_date = ?", scheduleDate)
  7222. }
  7223. err = db.Find(&vms).Error
  7224. }
  7225. }
  7226. } else {
  7227. if cost_type > 0 {
  7228. if len(execution_frequency) > 0 {
  7229. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7230. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7231. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7232. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7233. 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).
  7234. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7235. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7236. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7237. Where("status = 1 AND user_org_id = ?", orgID)
  7238. if scheduleDate != 0 {
  7239. db = db.Where("schedule_date = ?", scheduleDate)
  7240. }
  7241. err = db.Find(&vms).Error
  7242. } else {
  7243. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7244. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7245. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7246. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7247. 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).
  7248. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7249. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7250. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7251. Where("status = 1 AND user_org_id = ?", orgID)
  7252. if scheduleDate != 0 {
  7253. db = db.Where("schedule_date = ?", scheduleDate)
  7254. }
  7255. err = db.Find(&vms).Error
  7256. }
  7257. } else {
  7258. if len(execution_frequency) > 0 {
  7259. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7260. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7261. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7262. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7263. 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).
  7264. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7265. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7266. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7267. Where("status = 1 AND user_org_id = ?", orgID)
  7268. if scheduleDate != 0 {
  7269. db = db.Where("schedule_date = ?", scheduleDate)
  7270. }
  7271. err = db.Find(&vms).Error
  7272. } else {
  7273. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7274. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7275. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7276. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7277. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ?", orgID, scheduleDate, deliverWay, patient_id).
  7278. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7279. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7280. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7281. Where("status = 1 AND user_org_id = ?", orgID)
  7282. if scheduleDate != 0 {
  7283. db = db.Where("schedule_date = ?", scheduleDate)
  7284. }
  7285. err = db.Find(&vms).Error
  7286. }
  7287. }
  7288. }
  7289. } else {
  7290. if execution_state > 0 {
  7291. if cost_type > 0 {
  7292. if len(execution_frequency) > 0 {
  7293. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7294. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7295. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7296. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7297. 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).
  7298. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7299. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7300. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7301. Where("status = 1 AND user_org_id = ?", orgID)
  7302. if scheduleDate != 0 {
  7303. db = db.Where("schedule_date = ?", scheduleDate)
  7304. }
  7305. err = db.Find(&vms).Error
  7306. } else {
  7307. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7308. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7309. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7310. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7311. 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).
  7312. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7313. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7314. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7315. Where("status = 1 AND user_org_id = ?", orgID)
  7316. if scheduleDate != 0 {
  7317. db = db.Where("schedule_date = ?", scheduleDate)
  7318. }
  7319. err = db.Find(&vms).Error
  7320. }
  7321. } else {
  7322. if len(execution_frequency) > 0 {
  7323. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7324. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7325. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7326. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7327. 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).
  7328. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7329. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7330. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7331. Where("status = 1 AND user_org_id = ?", orgID)
  7332. if scheduleDate != 0 {
  7333. db = db.Where("schedule_date = ?", scheduleDate)
  7334. }
  7335. err = db.Find(&vms).Error
  7336. } else {
  7337. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7338. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7339. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7340. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7341. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_state = ?", orgID, scheduleDate, deliverWay, execution_state).
  7342. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7343. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7344. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7345. Where("status = 1 AND user_org_id = ?", orgID)
  7346. if scheduleDate != 0 {
  7347. db = db.Where("schedule_date = ?", scheduleDate)
  7348. }
  7349. err = db.Find(&vms).Error
  7350. }
  7351. }
  7352. } else {
  7353. if cost_type > 0 {
  7354. if len(execution_frequency) > 0 {
  7355. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7356. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7357. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7358. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7359. 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).
  7360. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7361. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7362. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7363. Where("status = 1 AND user_org_id = ?", orgID)
  7364. if scheduleDate != 0 {
  7365. db = db.Where("schedule_date = ?", scheduleDate)
  7366. }
  7367. err = db.Find(&vms).Error
  7368. } else {
  7369. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7370. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7371. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7372. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7373. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and is_settle = ?", orgID, scheduleDate, deliverWay, cost_type).
  7374. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7375. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7376. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7377. Where("status = 1 AND user_org_id = ?", orgID)
  7378. if scheduleDate != 0 {
  7379. db = db.Where("schedule_date = ?", scheduleDate)
  7380. }
  7381. err = db.Find(&vms).Error
  7382. }
  7383. } else {
  7384. if len(execution_frequency) > 0 {
  7385. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7386. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7387. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7388. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7389. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_frequency = ?", orgID, scheduleDate, deliverWay, execution_frequency).
  7390. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7391. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7392. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7393. Where("status = 1 AND user_org_id = ?", orgID)
  7394. if scheduleDate != 0 {
  7395. db = db.Where("schedule_date = ?", scheduleDate)
  7396. }
  7397. err = db.Find(&vms).Error
  7398. } else {
  7399. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7400. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7401. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7402. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7403. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  7404. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7405. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7406. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7407. Where("status = 1 AND user_org_id = ?", orgID)
  7408. if scheduleDate != 0 {
  7409. db = db.Where("schedule_date = ?", scheduleDate)
  7410. }
  7411. err = db.Find(&vms).Error
  7412. }
  7413. }
  7414. }
  7415. }
  7416. } else {
  7417. db := readDb.Table("xt_schedule")
  7418. if scheduleType > 0 {
  7419. db = db.Where("schedule_type = ?", scheduleType)
  7420. }
  7421. if partitionType > 0 {
  7422. db = db.Where("partition_id = ?", partitionType)
  7423. }
  7424. if patient_id > 0 {
  7425. if execution_state > 0 {
  7426. fmt.Println("execution_state---------------------", execution_state)
  7427. if cost_type > 0 {
  7428. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7429. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7430. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7431. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7432. 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).
  7433. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7434. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7435. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7436. Where("status = 1 AND user_org_id = ?", orgID)
  7437. if scheduleDate != 0 {
  7438. db = db.Where("schedule_date = ?", scheduleDate)
  7439. }
  7440. err = db.Find(&vms).Error
  7441. } else {
  7442. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7443. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7444. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7445. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7446. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and execution_state = ?", orgID, scheduleDate, patient_id, execution_state).
  7447. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7448. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7449. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7450. Where("status = 1 AND user_org_id = ?", orgID)
  7451. if scheduleDate != 0 {
  7452. db = db.Where("schedule_date = ?", scheduleDate)
  7453. }
  7454. err = db.Find(&vms).Error
  7455. }
  7456. } else {
  7457. if cost_type > 0 {
  7458. if len(execution_frequency) > 0 {
  7459. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7460. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7461. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7462. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7463. 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).
  7464. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7465. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7466. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7467. Where("status = 1 AND user_org_id = ?", orgID)
  7468. if scheduleDate != 0 {
  7469. db = db.Where("schedule_date = ?", scheduleDate)
  7470. }
  7471. err = db.Find(&vms).Error
  7472. } else {
  7473. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7474. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7475. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7476. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7477. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and is_settle = ?", orgID, scheduleDate, patient_id, cost_type).
  7478. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7479. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7480. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7481. Where("status = 1 AND user_org_id = ?", orgID)
  7482. if scheduleDate != 0 {
  7483. db = db.Where("schedule_date = ?", scheduleDate)
  7484. }
  7485. err = db.Find(&vms).Error
  7486. }
  7487. } else {
  7488. if len(execution_frequency) > 0 {
  7489. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7490. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7491. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7492. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7493. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and execution_frequency = ?", orgID, scheduleDate, patient_id, execution_frequency).
  7494. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7495. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7496. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7497. Where("status = 1 AND user_org_id = ?", orgID)
  7498. if scheduleDate != 0 {
  7499. db = db.Where("schedule_date = ?", scheduleDate)
  7500. }
  7501. err = db.Find(&vms).Error
  7502. } else {
  7503. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7504. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7505. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7506. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7507. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7508. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7509. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7510. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7511. Where("status = 1 AND user_org_id = ?", orgID)
  7512. if scheduleDate != 0 {
  7513. db = db.Where("schedule_date = ?", scheduleDate)
  7514. }
  7515. err = db.Find(&vms).Error
  7516. }
  7517. }
  7518. }
  7519. } else {
  7520. if execution_state > 0 {
  7521. if cost_type > 0 {
  7522. if len(execution_frequency) > 0 {
  7523. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7524. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7525. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7526. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7527. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ? and is_settle = ? and execution_frequency = ?", orgID, scheduleDate, execution_state, cost_type, execution_frequency).
  7528. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7529. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7530. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7531. Where("status = 1 AND user_org_id = ?", orgID)
  7532. if scheduleDate != 0 {
  7533. db = db.Where("schedule_date = ?", scheduleDate)
  7534. }
  7535. err = db.Find(&vms).Error
  7536. } else {
  7537. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7538. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7539. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7540. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7541. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ? and is_settle = ?", orgID, scheduleDate, execution_state, cost_type).
  7542. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7543. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7544. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7545. Where("status = 1 AND user_org_id = ?", orgID)
  7546. if scheduleDate != 0 {
  7547. db = db.Where("schedule_date = ?", scheduleDate)
  7548. }
  7549. err = db.Find(&vms).Error
  7550. }
  7551. } else {
  7552. if len(execution_frequency) > 0 {
  7553. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7554. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7555. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7556. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7557. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ? and execution_frequency = ?", orgID, scheduleDate, execution_state, execution_frequency).
  7558. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7559. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7560. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7561. Where("status = 1 AND user_org_id = ?", orgID)
  7562. if scheduleDate != 0 {
  7563. db = db.Where("schedule_date = ?", scheduleDate)
  7564. }
  7565. err = db.Find(&vms).Error
  7566. } else {
  7567. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7568. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7569. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7570. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7571. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ?", orgID, scheduleDate, execution_state).
  7572. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7573. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7574. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7575. Where("status = 1 AND user_org_id = ?", orgID)
  7576. if scheduleDate != 0 {
  7577. db = db.Where("schedule_date = ?", scheduleDate)
  7578. }
  7579. err = db.Find(&vms).Error
  7580. }
  7581. }
  7582. } else {
  7583. if cost_type > 0 {
  7584. if len(execution_frequency) > 0 {
  7585. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7586. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7587. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7588. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7589. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and is_settle = ?", orgID, scheduleDate, cost_type).
  7590. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7591. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7592. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7593. Where("status = 1 AND user_org_id = ?", orgID)
  7594. if scheduleDate != 0 {
  7595. db = db.Where("schedule_date = ?", scheduleDate)
  7596. }
  7597. err = db.Find(&vms).Error
  7598. } else {
  7599. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7600. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7601. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7602. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7603. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and is_settle = ? and execution_frequency = ?", orgID, scheduleDate, cost_type, execution_frequency).
  7604. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7605. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7606. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7607. Where("status = 1 AND user_org_id = ?", orgID)
  7608. if scheduleDate != 0 {
  7609. db = db.Where("schedule_date = ?", scheduleDate)
  7610. }
  7611. err = db.Find(&vms).Error
  7612. }
  7613. } else {
  7614. if len(execution_frequency) > 0 {
  7615. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7616. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7617. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7618. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7619. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_frequency = ?", orgID, scheduleDate, execution_frequency).
  7620. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7621. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7622. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7623. Where("status = 1 AND user_org_id = ?", orgID)
  7624. if scheduleDate != 0 {
  7625. db = db.Where("schedule_date = ?", scheduleDate)
  7626. }
  7627. err = db.Find(&vms).Error
  7628. } else {
  7629. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7630. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7631. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7632. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7633. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ?", orgID, scheduleDate).
  7634. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7635. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7636. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7637. Where("status = 1 AND user_org_id = ?", orgID)
  7638. if scheduleDate != 0 {
  7639. db = db.Where("schedule_date = ?", scheduleDate)
  7640. }
  7641. err = db.Find(&vms).Error
  7642. }
  7643. }
  7644. }
  7645. }
  7646. }
  7647. return vms, err
  7648. }
  7649. func GetPatientDryWeight(org_id int64, patient_id int64) (weight []*models.SgjPatientDryweight, err error) {
  7650. err = XTReadDB().Where("user_org_id = ? and patient_id = ? and status =1", org_id, patient_id).Order("id desc").Limit(6).Find(&weight).Error
  7651. return weight, err
  7652. }
  7653. func MobileGetLongScheduleDoctorAdvices(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string, scheduleType int64, partitonType int64, patient_id int64, execution_state int64, cost_type int64, execution_frequency string, keyword string) ([]*MScheduleDoctorAdviceVM, error) {
  7654. fmt.Println("deliverWay-----------------", deliverWay)
  7655. fmt.Println("execution_frequency------------------", execution_frequency)
  7656. fmt.Println("adviceType-----------------", adviceType)
  7657. fmt.Println("patientType----------------", patientType)
  7658. fmt.Println("patient_id----------------", patient_id)
  7659. fmt.Println("execution_state----------------", execution_state)
  7660. fmt.Println("cost_type---------------------", cost_type)
  7661. fmt.Println("execution_frequency", execution_frequency)
  7662. var vms []*MScheduleDoctorAdviceVM
  7663. adviceWhere := ""
  7664. keyword = "%" + keyword + "%"
  7665. adviceCondition := []interface{}{}
  7666. if adviceType == 1 {
  7667. if patientType == 0 {
  7668. if patient_id > 0 {
  7669. if execution_state > 0 {
  7670. if cost_type > 0 {
  7671. if len(execution_frequency) > 0 {
  7672. if len(keyword) > 0 {
  7673. if len(deliverWay) > 0 {
  7674. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and delivery_way = ? and advice_name like ?"
  7675. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency, deliverWay, keyword)
  7676. } else {
  7677. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  7678. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency, keyword)
  7679. }
  7680. } else {
  7681. if len(deliverWay) > 0 {
  7682. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and delivery_way =?"
  7683. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency, deliverWay)
  7684. } else {
  7685. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  7686. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency)
  7687. }
  7688. }
  7689. } else {
  7690. if len(keyword) > 0 {
  7691. if len(deliverWay) > 0 {
  7692. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ? and delivery_way =?"
  7693. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, keyword, deliverWay)
  7694. } else {
  7695. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  7696. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, keyword)
  7697. }
  7698. } else {
  7699. if len(deliverWay) > 0 {
  7700. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ? and delivery_way =?"
  7701. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, deliverWay)
  7702. } else {
  7703. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ?"
  7704. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type)
  7705. }
  7706. }
  7707. }
  7708. } else {
  7709. if len(execution_frequency) > 0 {
  7710. if len(keyword) > 0 {
  7711. if len(deliverWay) > 0 {
  7712. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  7713. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency, keyword, deliverWay)
  7714. } else {
  7715. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  7716. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency, keyword)
  7717. }
  7718. } else {
  7719. if len(deliverWay) > 0 {
  7720. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and execution_frequency = ? and delivery_way =?"
  7721. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency, deliverWay)
  7722. } else {
  7723. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and execution_frequency = ?"
  7724. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency)
  7725. }
  7726. }
  7727. } else {
  7728. if len(keyword) > 0 {
  7729. if len(deliverWay) > 0 {
  7730. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and advice_name like ? and delivery_way =?"
  7731. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, keyword, deliverWay)
  7732. } else {
  7733. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and advice_name like ?"
  7734. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, keyword)
  7735. }
  7736. } else {
  7737. if len(deliverWay) > 0 {
  7738. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and delivery_way =?"
  7739. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, deliverWay)
  7740. } else {
  7741. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ?"
  7742. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state)
  7743. }
  7744. }
  7745. }
  7746. }
  7747. } else {
  7748. if cost_type > 0 {
  7749. if len(execution_frequency) > 0 {
  7750. if len(keyword) > 0 {
  7751. if len(deliverWay) > 0 {
  7752. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  7753. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency, keyword, deliverWay)
  7754. } else {
  7755. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  7756. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency, keyword)
  7757. }
  7758. } else {
  7759. if len(deliverWay) > 0 {
  7760. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and execution_frequency = ? and delivery_way =?"
  7761. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency, deliverWay)
  7762. } else {
  7763. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and execution_frequency = ?"
  7764. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency)
  7765. }
  7766. }
  7767. } else {
  7768. if len(keyword) > 0 {
  7769. if len(deliverWay) > 0 {
  7770. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and advice_name like ? and delivery_way =?"
  7771. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, keyword, deliverWay)
  7772. } else {
  7773. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and advice_name like ?"
  7774. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, keyword)
  7775. }
  7776. } else {
  7777. if len(deliverWay) > 0 {
  7778. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and delivery_way =?"
  7779. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, deliverWay)
  7780. } else {
  7781. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? "
  7782. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type)
  7783. }
  7784. }
  7785. }
  7786. } else {
  7787. if len(execution_frequency) > 0 {
  7788. if len(keyword) > 0 {
  7789. if len(deliverWay) > 0 {
  7790. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  7791. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency, keyword, deliverWay)
  7792. } else {
  7793. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_frequency = ? and advice_name like ?"
  7794. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency, keyword)
  7795. }
  7796. } else {
  7797. if len(deliverWay) > 0 {
  7798. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_frequency = ? and delivery_way =?"
  7799. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency, deliverWay)
  7800. } else {
  7801. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_frequency = ?"
  7802. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency)
  7803. }
  7804. }
  7805. } else {
  7806. if len(keyword) > 0 {
  7807. if len(deliverWay) > 0 {
  7808. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and advice_name like ? and delivery_way =?"
  7809. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, keyword, deliverWay)
  7810. } else {
  7811. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and advice_name like ?"
  7812. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, keyword)
  7813. }
  7814. } else {
  7815. if len(deliverWay) > 0 {
  7816. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and delivery_way =?"
  7817. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, deliverWay)
  7818. } else {
  7819. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? "
  7820. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id)
  7821. }
  7822. }
  7823. }
  7824. }
  7825. }
  7826. } else {
  7827. if execution_state > 0 {
  7828. if cost_type > 0 {
  7829. if len(execution_frequency) > 0 {
  7830. if len(keyword) > 0 {
  7831. if len(deliverWay) > 0 {
  7832. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  7833. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency, keyword, deliverWay)
  7834. } else {
  7835. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  7836. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency, keyword)
  7837. }
  7838. } else {
  7839. if len(deliverWay) > 0 {
  7840. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and execution_frequency = ? and delivery_way =?"
  7841. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency, deliverWay)
  7842. } else {
  7843. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and execution_frequency = ?"
  7844. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency)
  7845. }
  7846. }
  7847. } else {
  7848. if len(keyword) > 0 {
  7849. if len(deliverWay) > 0 {
  7850. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and advice_name like ? and delivery_way =?"
  7851. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, keyword, deliverWay)
  7852. } else {
  7853. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and advice_name like ?"
  7854. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, keyword)
  7855. }
  7856. } else {
  7857. if len(deliverWay) > 0 {
  7858. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and delivery_way =?"
  7859. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, deliverWay)
  7860. } else {
  7861. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ?"
  7862. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type)
  7863. }
  7864. }
  7865. }
  7866. } else {
  7867. if len(execution_frequency) > 0 {
  7868. if len(keyword) > 0 {
  7869. if len(deliverWay) > 0 {
  7870. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  7871. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency, keyword, deliverWay)
  7872. } else {
  7873. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and execution_frequency = ? and advice_name like ?"
  7874. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency, keyword)
  7875. }
  7876. } else {
  7877. if len(deliverWay) > 0 {
  7878. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and execution_frequency = ? and delivery_way =?"
  7879. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency, deliverWay)
  7880. } else {
  7881. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and execution_frequency = ?"
  7882. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency)
  7883. }
  7884. }
  7885. } else {
  7886. if len(keyword) > 0 {
  7887. if len(deliverWay) > 0 {
  7888. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and advice_name like ? and delivery_way =?"
  7889. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, keyword, deliverWay)
  7890. } else {
  7891. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and advice_name like ?"
  7892. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, keyword)
  7893. }
  7894. } else {
  7895. if len(deliverWay) > 0 {
  7896. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and delivery_way =?"
  7897. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, deliverWay)
  7898. } else {
  7899. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ?"
  7900. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state)
  7901. }
  7902. }
  7903. }
  7904. }
  7905. } else {
  7906. if cost_type > 0 {
  7907. if len(keyword) > 0 {
  7908. if len(deliverWay) > 0 {
  7909. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and is_settle = ? and advice_name like ? and delivery_way =?"
  7910. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, keyword, deliverWay)
  7911. } else {
  7912. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and is_settle = ? and advice_name like ?"
  7913. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, keyword)
  7914. }
  7915. } else {
  7916. if len(deliverWay) > 0 {
  7917. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and is_settle = ? and delivery_way =?"
  7918. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, deliverWay)
  7919. } else {
  7920. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and is_settle = ? "
  7921. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type)
  7922. }
  7923. }
  7924. } else {
  7925. if len(keyword) > 0 {
  7926. if len(deliverWay) > 0 {
  7927. if len(execution_frequency) > 0 {
  7928. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and advice_name like ? and delivery_way =? and execution_frequency =? "
  7929. adviceCondition = append(adviceCondition, adviceWhere, orgID, keyword, deliverWay, execution_frequency)
  7930. } else {
  7931. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and advice_name like ? and delivery_way =?"
  7932. adviceCondition = append(adviceCondition, adviceWhere, orgID, keyword, deliverWay)
  7933. }
  7934. } else {
  7935. if len(execution_frequency) > 0 {
  7936. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and advice_name like ? and execution_frequency =?"
  7937. adviceCondition = append(adviceCondition, adviceWhere, orgID, keyword, execution_frequency)
  7938. } else {
  7939. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and advice_name like ?"
  7940. adviceCondition = append(adviceCondition, adviceWhere, orgID, keyword)
  7941. }
  7942. }
  7943. } else {
  7944. if len(deliverWay) > 0 {
  7945. if len(execution_frequency) > 0 {
  7946. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and delivery_way =? and execution_frequency =?"
  7947. adviceCondition = append(adviceCondition, adviceWhere, orgID, deliverWay, execution_frequency)
  7948. } else {
  7949. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and delivery_way =?"
  7950. adviceCondition = append(adviceCondition, adviceWhere, orgID, deliverWay)
  7951. }
  7952. } else {
  7953. if len(execution_frequency) > 0 {
  7954. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_frequency =?"
  7955. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_frequency)
  7956. } else {
  7957. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 "
  7958. adviceCondition = append(adviceCondition, adviceWhere, orgID)
  7959. }
  7960. }
  7961. }
  7962. }
  7963. }
  7964. }
  7965. } else if patientType == 1 {
  7966. if patient_id > 0 {
  7967. if execution_state > 0 {
  7968. if cost_type > 0 {
  7969. if len(execution_frequency) > 0 {
  7970. if len(keyword) > 0 {
  7971. if len(deliverWay) > 0 {
  7972. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  7973. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword, deliverWay)
  7974. } else {
  7975. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  7976. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  7977. }
  7978. } else {
  7979. if len(keyword) > 0 {
  7980. if len(deliverWay) > 0 {
  7981. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and delivery_way =?"
  7982. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, execution_frequency, deliverWay)
  7983. }
  7984. } else {
  7985. if len(deliverWay) > 0 {
  7986. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and delivery_way =?"
  7987. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, execution_frequency, deliverWay)
  7988. } else {
  7989. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  7990. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  7991. }
  7992. }
  7993. }
  7994. } else {
  7995. if len(keyword) > 0 {
  7996. if len(deliverWay) > 0 {
  7997. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ? and delivery_way =?"
  7998. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, keyword, deliverWay)
  7999. } else {
  8000. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  8001. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, keyword)
  8002. }
  8003. } else {
  8004. if len(deliverWay) > 0 {
  8005. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and delivery_way =?"
  8006. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, deliverWay)
  8007. } else {
  8008. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  8009. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type)
  8010. }
  8011. }
  8012. }
  8013. } else {
  8014. if len(execution_frequency) > 0 {
  8015. if len(keyword) > 0 {
  8016. if len(deliverWay) > 0 {
  8017. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  8018. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, execution_frequency, keyword, deliverWay)
  8019. } else {
  8020. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  8021. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  8022. }
  8023. } else {
  8024. if len(deliverWay) > 0 {
  8025. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and delivery_way =?"
  8026. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, execution_frequency, deliverWay)
  8027. } else {
  8028. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  8029. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, execution_frequency)
  8030. }
  8031. }
  8032. } else {
  8033. if len(keyword) > 0 {
  8034. if len(deliverWay) > 0 {
  8035. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and advice_name like ? and delivery_way =?"
  8036. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, keyword, deliverWay)
  8037. } else {
  8038. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  8039. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, keyword)
  8040. }
  8041. } else {
  8042. if len(deliverWay) > 0 {
  8043. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and delivery_way =?"
  8044. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, deliverWay)
  8045. } else {
  8046. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  8047. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state)
  8048. }
  8049. }
  8050. }
  8051. }
  8052. } else {
  8053. if cost_type > 0 {
  8054. if len(execution_frequency) > 0 {
  8055. if len(keyword) > 0 {
  8056. if len(deliverWay) > 0 {
  8057. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ?and execution_frequency = ? and advice_name like ? and delivery_way =?"
  8058. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, execution_frequency, keyword, deliverWay)
  8059. } else {
  8060. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ?and execution_frequency = ? and advice_name like ?"
  8061. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  8062. }
  8063. } else {
  8064. if len(deliverWay) > 0 {
  8065. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ?and execution_frequency = ? and delivery_way =?"
  8066. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, execution_frequency, deliverWay)
  8067. } else {
  8068. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ?and execution_frequency = ?"
  8069. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, execution_frequency)
  8070. }
  8071. }
  8072. } else {
  8073. if len(keyword) > 0 {
  8074. if len(deliverWay) > 0 {
  8075. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ? and advice_name like ? and delivery_way =?"
  8076. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, keyword, deliverWay)
  8077. } else {
  8078. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  8079. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, keyword)
  8080. }
  8081. } else {
  8082. if len(deliverWay) > 0 {
  8083. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ? and delivery_way =? "
  8084. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, deliverWay)
  8085. } else {
  8086. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  8087. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type)
  8088. }
  8089. }
  8090. }
  8091. } else {
  8092. if len(execution_frequency) > 0 {
  8093. if len(keyword) > 0 {
  8094. if len(deliverWay) > 0 {
  8095. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_frequency = ? and advice_name like ? and delivery_way =? "
  8096. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_frequency, keyword, deliverWay)
  8097. } else {
  8098. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  8099. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_frequency, keyword)
  8100. }
  8101. } else {
  8102. if len(deliverWay) > 0 {
  8103. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_frequency = ? and delivery_way =? "
  8104. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_frequency, deliverWay)
  8105. } else {
  8106. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  8107. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_frequency)
  8108. }
  8109. }
  8110. } else {
  8111. if len(keyword) > 0 {
  8112. if len(deliverWay) > 0 {
  8113. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and advice_name like ? and delivery_way =?"
  8114. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, keyword, deliverWay)
  8115. } else {
  8116. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and advice_name like ?"
  8117. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, keyword)
  8118. }
  8119. } else {
  8120. if len(deliverWay) > 0 {
  8121. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and delivery_way =?"
  8122. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, deliverWay)
  8123. } else {
  8124. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ?"
  8125. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id)
  8126. }
  8127. }
  8128. }
  8129. }
  8130. }
  8131. } else {
  8132. if execution_state > 0 {
  8133. if cost_type > 0 {
  8134. if len(execution_frequency) > 0 {
  8135. if len(keyword) > 0 {
  8136. if len(deliverWay) > 0 {
  8137. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ?and execution_frequency = ? and advice_name like ? and delivery_way =?"
  8138. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, execution_frequency, keyword, deliverWay)
  8139. } else {
  8140. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ?and execution_frequency = ? and advice_name like ?"
  8141. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  8142. }
  8143. } else {
  8144. if len(deliverWay) > 0 {
  8145. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ?and execution_frequency = ? and delivery_way =?"
  8146. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, execution_frequency, deliverWay)
  8147. } else {
  8148. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ?and execution_frequency = ?"
  8149. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, execution_frequency)
  8150. }
  8151. }
  8152. } else {
  8153. if len(keyword) > 0 {
  8154. if len(deliverWay) > 0 {
  8155. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ? and advice_name like ? and delivery_way =?"
  8156. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, keyword, deliverWay)
  8157. } else {
  8158. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ? and advice_name like ?"
  8159. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, keyword)
  8160. }
  8161. } else {
  8162. if len(deliverWay) > 0 {
  8163. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ? and delivery_way =?"
  8164. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, deliverWay)
  8165. } else {
  8166. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ?"
  8167. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type)
  8168. }
  8169. }
  8170. }
  8171. } else {
  8172. if len(execution_frequency) > 0 {
  8173. if len(keyword) > 0 {
  8174. if len(deliverWay) > 0 {
  8175. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=?and execution_frequency = ? and advice_name like ? and delivery_way =?"
  8176. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, execution_frequency, keyword, deliverWay)
  8177. } else {
  8178. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=?and execution_frequency = ? and advice_name like ?"
  8179. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, execution_frequency, keyword)
  8180. }
  8181. } else {
  8182. if len(deliverWay) > 0 {
  8183. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=?and execution_frequency = ? and delivery_way =?"
  8184. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, execution_frequency, deliverWay)
  8185. } else {
  8186. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=?and execution_frequency = ?"
  8187. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, execution_frequency)
  8188. }
  8189. }
  8190. } else {
  8191. if len(keyword) > 0 {
  8192. if len(deliverWay) > 0 {
  8193. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and advice_name like ? and delivery_way =?"
  8194. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, keyword, deliverWay)
  8195. } else {
  8196. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and advice_name like ?"
  8197. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, keyword)
  8198. }
  8199. } else {
  8200. if len(deliverWay) > 0 {
  8201. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and delivery_way =?"
  8202. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, deliverWay)
  8203. } else {
  8204. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=?"
  8205. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state)
  8206. }
  8207. }
  8208. }
  8209. }
  8210. } else {
  8211. if cost_type > 0 {
  8212. if len(execution_frequency) > 0 {
  8213. if len(keyword) > 0 {
  8214. if len(deliverWay) > 0 {
  8215. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  8216. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, execution_frequency, keyword, deliverWay)
  8217. } else {
  8218. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  8219. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, execution_frequency, keyword)
  8220. }
  8221. } else {
  8222. if len(deliverWay) > 0 {
  8223. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and execution_frequency = ? and delivery_way =?"
  8224. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, execution_frequency, deliverWay)
  8225. } else {
  8226. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  8227. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, execution_frequency)
  8228. }
  8229. }
  8230. } else {
  8231. if len(keyword) > 0 {
  8232. if len(deliverWay) > 0 {
  8233. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and advice_name like ? and delivery_way =?"
  8234. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, keyword, deliverWay)
  8235. } else {
  8236. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and advice_name like ?"
  8237. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, keyword)
  8238. }
  8239. } else {
  8240. if len(deliverWay) > 0 {
  8241. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and delivery_way =?"
  8242. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, deliverWay)
  8243. } else {
  8244. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? "
  8245. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type)
  8246. }
  8247. }
  8248. }
  8249. } else {
  8250. if len(execution_frequency) > 0 {
  8251. if len(keyword) > 0 {
  8252. if len(deliverWay) > 0 {
  8253. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  8254. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_frequency, keyword, deliverWay)
  8255. } else {
  8256. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_frequency = ? and advice_name like ?"
  8257. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_frequency, keyword)
  8258. }
  8259. } else {
  8260. if len(deliverWay) > 0 {
  8261. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_frequency = ? and delivery_way =?"
  8262. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_frequency, deliverWay)
  8263. } else {
  8264. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_frequency = ?"
  8265. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_frequency)
  8266. }
  8267. }
  8268. } else {
  8269. if len(keyword) > 0 {
  8270. if len(deliverWay) > 0 {
  8271. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and advice_name like ? and delivery_way =?"
  8272. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, keyword, deliverWay)
  8273. } else {
  8274. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and advice_name like ?"
  8275. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, keyword)
  8276. }
  8277. } else {
  8278. if len(deliverWay) > 0 {
  8279. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and delivery_way =?"
  8280. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, deliverWay)
  8281. } else {
  8282. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? "
  8283. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId)
  8284. }
  8285. }
  8286. }
  8287. }
  8288. }
  8289. }
  8290. } else if patientType == 2 {
  8291. if patient_id > 0 {
  8292. if execution_state > 0 {
  8293. if cost_type > 0 {
  8294. if len(execution_frequency) > 0 {
  8295. if len(keyword) > 0 {
  8296. if len(deliverWay) > 0 {
  8297. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ?and execution_frequency = ? and advice_name like ? and delivery_way =?"
  8298. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency, keyword, deliverWay)
  8299. } else {
  8300. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ?and execution_frequency = ? and advice_name like ?"
  8301. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency, keyword)
  8302. }
  8303. } else {
  8304. if len(deliverWay) > 0 {
  8305. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ?and execution_frequency = ? and delivery_way =?"
  8306. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency, deliverWay)
  8307. } else {
  8308. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ?and execution_frequency = ?"
  8309. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency)
  8310. }
  8311. }
  8312. } else {
  8313. if len(keyword) > 0 {
  8314. if len(deliverWay) > 0 {
  8315. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ? and delivery_way =?"
  8316. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, keyword, deliverWay)
  8317. } else {
  8318. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  8319. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, keyword)
  8320. }
  8321. } else {
  8322. if len(deliverWay) > 0 {
  8323. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ? and delivery_way =?"
  8324. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, deliverWay)
  8325. } else {
  8326. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ?"
  8327. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type)
  8328. }
  8329. }
  8330. }
  8331. } else {
  8332. if len(execution_frequency) > 0 {
  8333. if len(keyword) > 0 {
  8334. if len(deliverWay) > 0 {
  8335. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  8336. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency, keyword, deliverWay)
  8337. } else {
  8338. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  8339. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency, keyword)
  8340. }
  8341. } else {
  8342. if len(deliverWay) > 0 {
  8343. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and execution_frequency = ? and delivery_way =?"
  8344. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency, deliverWay)
  8345. } else {
  8346. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and execution_frequency = ?"
  8347. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency)
  8348. }
  8349. }
  8350. } else {
  8351. if len(keyword) > 0 {
  8352. if len(deliverWay) > 0 {
  8353. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and advice_name like ? and delivery_way =?"
  8354. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, keyword, deliverWay)
  8355. } else {
  8356. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and advice_name like ?"
  8357. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, keyword)
  8358. }
  8359. } else {
  8360. if len(deliverWay) > 0 {
  8361. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and delivery_way =?"
  8362. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, deliverWay)
  8363. } else {
  8364. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  8365. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state)
  8366. }
  8367. }
  8368. }
  8369. }
  8370. } else {
  8371. if cost_type > 0 {
  8372. if len(execution_frequency) > 0 {
  8373. if len(keyword) > 0 {
  8374. if len(deliverWay) > 0 {
  8375. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  8376. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency, keyword, deliverWay)
  8377. } else {
  8378. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  8379. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency, keyword)
  8380. }
  8381. } else {
  8382. if len(deliverWay) > 0 {
  8383. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and is_settle = ? and execution_frequency = ? and delivery_way =?"
  8384. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency, deliverWay)
  8385. } else {
  8386. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and is_settle = ? and execution_frequency = ?"
  8387. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency)
  8388. }
  8389. }
  8390. } else {
  8391. if len(keyword) > 0 {
  8392. if len(deliverWay) > 0 {
  8393. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and is_settle = ? and advice_name like ? and delivery_way =?"
  8394. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, keyword, deliverWay)
  8395. } else {
  8396. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and is_settle = ? and advice_name like ?"
  8397. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, keyword)
  8398. }
  8399. } else {
  8400. if len(deliverWay) > 0 {
  8401. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and is_settle = ? and delivery_way =?"
  8402. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, deliverWay)
  8403. } else {
  8404. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  8405. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type)
  8406. }
  8407. }
  8408. }
  8409. } else {
  8410. if len(execution_frequency) > 0 {
  8411. if len(keyword) > 0 {
  8412. if len(deliverWay) > 0 {
  8413. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  8414. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency, keyword, deliverWay)
  8415. } else {
  8416. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_frequency = ? and advice_name like ?"
  8417. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency, keyword)
  8418. }
  8419. } else {
  8420. if len(deliverWay) > 0 {
  8421. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_frequency = ? and delivery_way =?"
  8422. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency, deliverWay)
  8423. } else {
  8424. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_frequency = ?"
  8425. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency)
  8426. }
  8427. }
  8428. } else {
  8429. if len(keyword) > 0 {
  8430. if len(deliverWay) > 0 {
  8431. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and advice_name like ? and delivery_way =?"
  8432. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, keyword, deliverWay)
  8433. } else {
  8434. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and advice_name like ?"
  8435. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, keyword)
  8436. }
  8437. } else {
  8438. if len(deliverWay) > 0 {
  8439. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and delivery_way =?"
  8440. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, deliverWay)
  8441. } else {
  8442. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ?"
  8443. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id)
  8444. }
  8445. }
  8446. }
  8447. }
  8448. }
  8449. } else {
  8450. if execution_state > 0 {
  8451. if cost_type > 0 {
  8452. if len(execution_frequency) > 0 {
  8453. if len(keyword) > 0 {
  8454. if len(deliverWay) > 0 {
  8455. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  8456. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency, keyword, deliverWay)
  8457. } else {
  8458. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  8459. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency, keyword)
  8460. }
  8461. } else {
  8462. if len(deliverWay) > 0 {
  8463. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ? and execution_frequency = ? and delivery_way =?"
  8464. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency, deliverWay)
  8465. } else {
  8466. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ? and execution_frequency = ?"
  8467. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency)
  8468. }
  8469. }
  8470. } else {
  8471. if len(keyword) > 0 {
  8472. if len(deliverWay) > 0 {
  8473. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ? and advice_name like ? and delivery_way =?"
  8474. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, keyword, deliverWay)
  8475. } else {
  8476. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ? and advice_name like ?"
  8477. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, keyword)
  8478. }
  8479. } else {
  8480. if len(deliverWay) > 0 {
  8481. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ? and delivery_way =?"
  8482. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, deliverWay)
  8483. } else {
  8484. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  8485. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type)
  8486. }
  8487. }
  8488. }
  8489. } else {
  8490. if len(execution_frequency) > 0 {
  8491. if len(keyword) > 0 {
  8492. if len(deliverWay) > 0 {
  8493. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  8494. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency, keyword, deliverWay)
  8495. } else {
  8496. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ? and execution_frequency = ? and advice_name like ?"
  8497. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency, keyword)
  8498. }
  8499. } else {
  8500. if len(deliverWay) > 0 {
  8501. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ? and execution_frequency = ? and delivery_way =?"
  8502. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency, deliverWay)
  8503. } else {
  8504. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ? and execution_frequency = ?"
  8505. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency)
  8506. }
  8507. }
  8508. } else {
  8509. if len(keyword) > 0 {
  8510. if len(deliverWay) > 0 {
  8511. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ? and advice_name like ? and delivery_way =?"
  8512. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, keyword, deliverWay)
  8513. } else {
  8514. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ? and advice_name like ?"
  8515. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, keyword)
  8516. }
  8517. } else {
  8518. if len(deliverWay) > 0 {
  8519. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ? and delivery_way =?"
  8520. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, deliverWay)
  8521. } else {
  8522. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ?"
  8523. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state)
  8524. }
  8525. }
  8526. }
  8527. }
  8528. } else {
  8529. if cost_type > 0 {
  8530. if len(execution_frequency) > 0 {
  8531. if len(keyword) > 0 {
  8532. if len(deliverWay) > 0 {
  8533. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  8534. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, execution_frequency, keyword, deliverWay)
  8535. } else {
  8536. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ? and execution_frequency = ? and advice_name like ?"
  8537. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, execution_frequency, keyword)
  8538. }
  8539. } else {
  8540. if len(deliverWay) > 0 {
  8541. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ? and execution_frequency = ? and delivery_way =?"
  8542. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, execution_frequency, deliverWay)
  8543. } else {
  8544. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  8545. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, execution_frequency)
  8546. }
  8547. }
  8548. } else {
  8549. if len(keyword) > 0 {
  8550. if len(deliverWay) > 0 {
  8551. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ? and advice_name like ? and delivery_way =?"
  8552. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, keyword, deliverWay)
  8553. } else {
  8554. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ? and advice_name like ?"
  8555. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, keyword)
  8556. }
  8557. } else {
  8558. if len(deliverWay) > 0 {
  8559. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ? and delivery_way =?"
  8560. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, deliverWay)
  8561. } else {
  8562. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ?"
  8563. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type)
  8564. }
  8565. }
  8566. }
  8567. } else {
  8568. if len(execution_frequency) > 0 {
  8569. if len(keyword) > 0 {
  8570. if len(deliverWay) > 0 {
  8571. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_frequency = ? and advice_name like ? and delivery_way =?"
  8572. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_frequency, keyword, deliverWay)
  8573. } else {
  8574. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_frequency = ? and advice_name like ?"
  8575. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_frequency, keyword)
  8576. }
  8577. } else {
  8578. if len(deliverWay) > 0 {
  8579. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_frequency = ? and delivery_way =?"
  8580. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_frequency, deliverWay)
  8581. } else {
  8582. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_frequency = ?"
  8583. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_frequency)
  8584. }
  8585. }
  8586. } else {
  8587. if len(keyword) > 0 {
  8588. if len(deliverWay) > 0 {
  8589. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and advice_name like ? and delivery_way =?"
  8590. adviceCondition = append(adviceCondition, adviceWhere, orgID, keyword, deliverWay)
  8591. } else {
  8592. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and advice_name like ?"
  8593. adviceCondition = append(adviceCondition, adviceWhere, orgID, keyword)
  8594. }
  8595. } else {
  8596. if len(deliverWay) > 0 {
  8597. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and delivery_way =?"
  8598. adviceCondition = append(adviceCondition, adviceWhere, orgID, deliverWay)
  8599. } else {
  8600. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0"
  8601. adviceCondition = append(adviceCondition, adviceWhere, orgID)
  8602. }
  8603. }
  8604. }
  8605. }
  8606. }
  8607. }
  8608. }
  8609. }
  8610. db := readDb.Table("xt_schedule")
  8611. if scheduleType > 0 {
  8612. db = db.Where("schedule_type = ?", scheduleType)
  8613. }
  8614. if partitonType > 0 {
  8615. db = db.Where("partition_id = ?", partitonType)
  8616. }
  8617. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  8618. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  8619. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  8620. }).
  8621. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  8622. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  8623. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  8624. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  8625. Preload("DoctorAdvices", adviceCondition...).
  8626. Where("status = 1 AND user_org_id = ?", orgID)
  8627. if scheduleDate != 0 {
  8628. db = db.Where("schedule_date = ?", scheduleDate)
  8629. }
  8630. err := db.Find(&vms).Error
  8631. return vms, err
  8632. }
  8633. func GetLastAcceptTreatment(user_org_id int64, patient_id int64) (models.ReceiveTreatmentAsses, error) {
  8634. treatmentAsses := models.ReceiveTreatmentAsses{}
  8635. err := XTReadDB().Where("user_org_id = ? and patient_id = ? and status=1 and admission_number<>''", user_org_id, patient_id).Last(&treatmentAsses).Error
  8636. return treatmentAsses, err
  8637. }
  8638. func GetDrugIsShow(id int64, org_id int64) (models.XtBaseDrug, error) {
  8639. baseDrug := models.XtBaseDrug{}
  8640. err := XTReadDB().Where("id = ? and status =1 and org_id = ?", id, org_id).Find(&baseDrug).Error
  8641. return baseDrug, err
  8642. }