mobile_dialysis_service.go 540KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051
  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. func GetDialysisPrescribeOne(orgID int64, patientID int64, recordDate int64) (models.DialysisPrescription, error) {
  2479. var record models.DialysisPrescription
  2480. err = readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  2481. return record, err
  2482. }
  2483. // 透析方案
  2484. func GetDialysisSolution(orgID int64, patientID int64, mode_id int64) (models.DialysisSolution, error) {
  2485. var record models.DialysisSolution
  2486. 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
  2487. return record, err
  2488. }
  2489. func GetDialysisSolutionOne(orgID int64, mode_id int64) (*models.DialysisSolution, error) {
  2490. var record models.DialysisSolution
  2491. err := readDb.Model(&models.DialysisSolution{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2492. if err != nil {
  2493. if err == gorm.ErrRecordNotFound {
  2494. return nil, nil
  2495. } else {
  2496. return nil, err
  2497. }
  2498. }
  2499. return &record, nil
  2500. }
  2501. func GetLastDialysisPrescribeByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2502. var record models.DialysisPrescription
  2503. 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
  2504. if err != nil {
  2505. if err == gorm.ErrRecordNotFound {
  2506. return nil, nil
  2507. } else {
  2508. return nil, err
  2509. }
  2510. }
  2511. return &record, nil
  2512. }
  2513. func GetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  2514. var record models.SgjPatientDryweight
  2515. err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  2516. if err != nil {
  2517. if err == gorm.ErrRecordNotFound {
  2518. return nil, nil
  2519. } else {
  2520. return nil, err
  2521. }
  2522. }
  2523. return &record, nil
  2524. }
  2525. func MobileGetSystemDialysisPrescribeByModeIdSix(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2526. var record models.SystemPrescription
  2527. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).First(&record).Error
  2528. if err != nil {
  2529. if err == gorm.ErrRecordNotFound {
  2530. return nil, nil
  2531. } else {
  2532. return nil, err
  2533. }
  2534. }
  2535. return &record, nil
  2536. }
  2537. func MobileGetSystemDialysisPrescribeByModeId(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2538. var record models.SystemPrescription
  2539. redis := RedisClient()
  2540. defer redis.Close()
  2541. // cur_date := time.Now().Format("2006-01-02")
  2542. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  2543. system_dialysis_prescribe_str, _ := redis.Get(key).Result()
  2544. if len(system_dialysis_prescribe_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2545. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2546. if err != nil {
  2547. if err == gorm.ErrRecordNotFound {
  2548. if record.ID <= 0 {
  2549. redis.Set(key, "null", time.Second*60*60*18)
  2550. }
  2551. return nil, nil
  2552. } else {
  2553. return nil, err
  2554. }
  2555. } else {
  2556. if record.ID > 0 {
  2557. //缓存数据
  2558. system_dialysis_prescribe_str, err := json.Marshal(record)
  2559. if err == nil {
  2560. redis.Set(key, system_dialysis_prescribe_str, time.Second*60*60*18)
  2561. }
  2562. } else {
  2563. redis.Set(key, "null", time.Second*60*60*18)
  2564. }
  2565. return &record, nil
  2566. }
  2567. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2568. if system_dialysis_prescribe_str == "null" {
  2569. return &record, nil
  2570. } else {
  2571. json.Unmarshal([]byte(system_dialysis_prescribe_str), &record)
  2572. return &record, nil
  2573. }
  2574. }
  2575. }
  2576. func MobileGetSystemDialysisPrescribeByModeIdOne(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. return record, err
  2580. }
  2581. func GetSystemDialysisPrescribeByModeId(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2582. var record models.SystemPrescription
  2583. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2584. if err != nil {
  2585. if err == gorm.ErrRecordNotFound {
  2586. return nil, nil
  2587. } else {
  2588. return nil, err
  2589. }
  2590. }
  2591. return &record, nil
  2592. }
  2593. func GetDialysisOrderCount(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2594. 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
  2595. return
  2596. }
  2597. func GetDialysisOrderCountOne(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2598. 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
  2599. return
  2600. }
  2601. func GetDialysisOrderCountTwo(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2602. 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
  2603. return
  2604. }
  2605. func GetFirstDateOfMonth(d time.Time) time.Time {
  2606. d = d.AddDate(0, 0, -d.Day()+1)
  2607. return GetZeroTime(d)
  2608. }
  2609. func GetZeroTime(d time.Time) time.Time {
  2610. return time.Date(d.Year(), d.Month(), d.Day(), 0, 0, 0, 0, d.Location())
  2611. }
  2612. func GetDialysisCountByPatientId(startime int64, endtime int64, patientid int64, orgid int64) (order []*models.BloodDialysisOrderCount, err error) {
  2613. db := XTReadDB().Table("xt_dialysis_order as o")
  2614. 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
  2615. return order, err
  2616. }
  2617. func FindConsumablesByDate(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error) {
  2618. 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
  2619. return
  2620. }
  2621. func FindConsumablesByDateTwo(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error) {
  2622. 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
  2623. return
  2624. }
  2625. func FindConsumablesByDateThree(orgID int64, patient_id int64, recordDate int64) (consumables []*models.BloodAutomaticReduceDetail, err error) {
  2626. 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
  2627. return
  2628. }
  2629. func FindHisPrescription(orgID int64, patient_id int64, recordDate int64) (project []*models.HisPrescriptionProject, err error) {
  2630. 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
  2631. return
  2632. }
  2633. //func FindLastConsumables(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error){
  2634. // 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
  2635. // return
  2636. //}
  2637. //
  2638. func GetLastTimeConsumables(orgID int64, patientID int64, maxDate int64) (prepare []*models.DialysisBeforePrepare, err error) {
  2639. 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
  2640. return
  2641. }
  2642. type GoodsType struct {
  2643. ID int64 `gorm:"column:id" json:"id"`
  2644. TypeName string `gorm:"column:type_name" json:"type_name"`
  2645. Remark string `gorm:"column:remark" json:"remark"`
  2646. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2647. Status int64 `gorm:"column:status" json:"status"`
  2648. Type int64 `gorm:"column:type" json:"type"`
  2649. }
  2650. func (GoodsType) TableName() string {
  2651. return "xt_goods_type"
  2652. }
  2653. type VMGoodInfo struct {
  2654. ID int64 `gorm:"column:id" json:"id"`
  2655. SpecificationName string `gorm:"column:specification_name" json:"specification_name"`
  2656. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2657. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2658. GoodName string `gorm:"column:good_name" json:"good_name" form:"good_name"`
  2659. GoodUnit int64 `gorm:"column:good_unit" json:"good_unit" form:"good_unit"`
  2660. Total float64 `gorm:"column:total" json:"total" form:"total"`
  2661. PackingUnit string `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
  2662. MedicalInsuranceNumber string `gorm:"column:medical_insurance_number" json:"medical_insurance_number" form:"medical_insurance_number"`
  2663. }
  2664. func (VMGoodInfo) TableName() string {
  2665. return "xt_good_information"
  2666. }
  2667. type AutomaticReduceDetail struct {
  2668. ID int64 `gorm:"column:id" json:"id"`
  2669. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2670. Status int64 `gorm:"column:status" json:"status"`
  2671. RecordTime int64 `gorm:"column:record_time" json:"record_time"`
  2672. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2673. GoodId int64 `gorm:"column:good_id" json:"good_id"`
  2674. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2675. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"info"`
  2676. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"type"`
  2677. Count int64 `gorm:"column:count" json:"count"`
  2678. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  2679. }
  2680. func (AutomaticReduceDetail) TableName() string {
  2681. return "xt_automatic_reduce_detail"
  2682. }
  2683. type DialysisBeforePrepare struct {
  2684. ID int64 `gorm:"column:id" json:"id" form:"id"`
  2685. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  2686. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  2687. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  2688. GoodId int64 `gorm:"column:good_id" json:"good_id" form:"good_id"`
  2689. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id" form:"good_type_id"`
  2690. Count int64 `gorm:"column:count" json:"count" form:"count"`
  2691. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  2692. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  2693. Creater int64 `gorm:"column:creater" json:"creater" form:"creater"`
  2694. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  2695. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"info"`
  2696. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"type"`
  2697. }
  2698. func (DialysisBeforePrepare) TableName() string {
  2699. return "dialysis_before_prepare"
  2700. }
  2701. type MDialysisGoodsVM struct {
  2702. ID int64 `gorm:"column:id" json:"id"`
  2703. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2704. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2705. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2706. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2707. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2708. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2709. ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week"`
  2710. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2711. Status int64 `gorm:"column:status" json:"status"`
  2712. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2713. SchedualPatient *MSchedualPatientVMList `gorm:"ForeignKey:PatientId" json:"patient"`
  2714. AutomaticReduceDetail []*AutomaticReduceDetail `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"good_user"`
  2715. LastAutomaticReduceDetail []*AutomaticReduceDetail `gorm:"-" json:"last_good_user"`
  2716. DialysisBeforePrepare []*DialysisBeforePrepare `gorm:"ForeignKey:PatientId,ScheduleDate;AssociationForeignKey:PatientId,RecordDate" json:"good_user_detail"`
  2717. LastDialysisBeforePrepare []*DialysisBeforePrepare `gorm:"-" json:"last_good_user_detail"`
  2718. Project []*models.HisPrescriptionProject `gorm:"-" json:"project"`
  2719. //WarehouseOutInfo []*models.WarehouseOutInfoSeven `gorm:"ForeignKey:PatientId,ScheduleDate;AssociationForeignKey:PatientId,SysRecordTime" json:"ware_house_out_info"`
  2720. DialysisPrescription models.DialysisPrescriptionListSix `gorm:"ForeignKey:PatientId,ModeId;AssociationForeignKey:PatientId,ModeId" json:"prescription"`
  2721. }
  2722. func (MDialysisGoodsVM) TableName() string {
  2723. return "xt_schedule"
  2724. }
  2725. type VMWarehouseOutInfo struct {
  2726. ID int64 `gorm:"column:id" json:"id"`
  2727. WarehouseOutId int64 `gorm:"column:warehouse_out_id" json:"warehouse_out_id"`
  2728. GoodId int64 `gorm:"column:good_id" json:"good_id"`
  2729. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2730. Count int64 `gorm:"column:count" json:"count"`
  2731. Price float64 `gorm:"column:price" json:"price"`
  2732. TotalPrice float64 `gorm:"column:total_price" json:"total_price"`
  2733. Status int64 `gorm:"column:status" json:"status"`
  2734. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2735. WarehouseOutOrderNumber string `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number"`
  2736. GoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"good_info"`
  2737. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"good_type"`
  2738. IsSys int64 `gorm:"column:is_sys" json:"is_sys"`
  2739. SysRecordTime int64 `gorm:"column:sys_record_time" json:"sys_record_time"`
  2740. Mtime int64 `gorm:"column:mtime" json:"mtime"`
  2741. Ctime int64 `gorm:"column:ctime" json:"ctime"`
  2742. }
  2743. func (VMWarehouseOutInfo) TableName() string {
  2744. return "xt_warehouse_out_info"
  2745. }
  2746. type DialysisGoodsDate struct {
  2747. RecordDate int64
  2748. }
  2749. type DialysisGoodsDetailDate struct {
  2750. RecordTime int64
  2751. }
  2752. 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) {
  2753. var vms []*MDialysisGoodsVM
  2754. var total int64
  2755. db := readDb.
  2756. Table("xt_schedule as sch").
  2757. Preload("DialysisPrescription", "status=1 and user_org_id =? and solution_status = 1", orgID).
  2758. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  2759. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2760. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2761. Preload("DialysisBeforePrepare", func(db *gorm.DB) *gorm.DB {
  2762. 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)
  2763. }).
  2764. Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
  2765. 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")
  2766. }).Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
  2767. if scheduleDate != 0 {
  2768. db = db.Where("schedule_date = ?", scheduleDate)
  2769. }
  2770. if schedule_type != 0 {
  2771. db = db.Where("schedule_type = ?", schedule_type)
  2772. }
  2773. if partition_id != 0 {
  2774. db = db.Where("partition_id = ?", partition_id)
  2775. }
  2776. if patient_id != 0 {
  2777. db = db.Where("patient_id = ?", patient_id)
  2778. }
  2779. err := db.Find(&vms).Error
  2780. return vms, err, total
  2781. }
  2782. func GetLastDialysisGoods(patient_id int64, orgID int64, record_time int64) (goodUser []*AutomaticReduceDetail, err error) {
  2783. var Id []*DialysisGoodsDetailDate
  2784. 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
  2785. if len(Id) > 0 {
  2786. 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
  2787. }
  2788. return
  2789. }
  2790. func GetLastDialysisBeforePrepare(patient_id int64, orgID int64, record_time int64) (goodUser []*DialysisBeforePrepare, err error) {
  2791. var Id []*DialysisGoodsDate
  2792. 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
  2793. if len(Id) > 0 {
  2794. 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
  2795. }
  2796. return
  2797. }
  2798. func GetPatientAutoMatic(patient_id int64, orgID int64, record_time int64, good_id int64) (auto []*models.AutomaticReduceDetail, err error) {
  2799. 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
  2800. return auto, err
  2801. }
  2802. func GetAllWarehouseOutSumList(patient_id int64, orgID int64, record_time int64) (info []*models.WarehouseOutInfoSeven, err error) {
  2803. err = XTReadDB().Where("patient_id = ? and org_id = ? and sys_record_time = ? and status = 1", patient_id, orgID, record_time).Preload("GoodInfo", "status=1 and org_id = ?", orgID).Find(&info).Error
  2804. return info, err
  2805. }
  2806. func MobileGetGoodsStatistics(orgID int64, start_time int64, end_time int64) (list []*models.StockInfo, err error) {
  2807. db := readDb.Model(&models.StockInfo{})
  2808. db = db.Where("xt_good_information.org_id = ? AND xt_good_information.status = 1", orgID)
  2809. 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")
  2810. db = db.Preload("QueryWarehouseOutInfo", func(db *gorm.DB) *gorm.DB {
  2811. 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)
  2812. })
  2813. db = db.Preload("GoodsType", "org_id = ? AND status = 1", orgID)
  2814. err = db.Order("ctime desc").Find(&list).Error
  2815. return
  2816. }
  2817. 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) {
  2818. var vms []*MDialysisGoodsVM
  2819. var total int64
  2820. db := readDb.
  2821. Model(&models.Schedule{}).
  2822. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  2823. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2824. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2825. Preload("DialysisBeforePrepare", func(db *gorm.DB) *gorm.DB {
  2826. 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)
  2827. }).Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
  2828. 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)
  2829. }).Where("xt_schedule.status = 1 AND xt_schedule.user_org_id = ?", orgID)
  2830. if scheduleDate != 0 {
  2831. db = db.Where("schedule_date = ?", scheduleDate)
  2832. }
  2833. if patient_id != 0 {
  2834. db = db.Where("patient_id = ?", patient_id)
  2835. }
  2836. if len(keywords) != 0 {
  2837. keywords = "%" + keywords + "%"
  2838. 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)
  2839. if schedule_type != 0 {
  2840. db = db.Where("schedule_type = ?", schedule_type)
  2841. }
  2842. if partition_id != 0 {
  2843. db = db.Where("partition_id = ?", partition_id)
  2844. }
  2845. if good_type == 1 {
  2846. db = db.Where("patient_id in(?)", ids)
  2847. }
  2848. if good_type == 2 {
  2849. if len(ids) > 0 {
  2850. db = db.Where("patient_id not in(?)", ids)
  2851. }
  2852. }
  2853. } else {
  2854. if schedule_type != 0 {
  2855. db = db.Where("schedule_type = ?", schedule_type)
  2856. }
  2857. if partition_id != 0 {
  2858. db = db.Where("partition_id = ?", partition_id)
  2859. }
  2860. if good_type == 1 {
  2861. db = db.Where("patient_id in(?)", ids)
  2862. }
  2863. if good_type == 2 {
  2864. if len(ids) > 0 {
  2865. db = db.Where("patient_id not in(?)", ids)
  2866. }
  2867. }
  2868. db = db.Count(&total)
  2869. offset := (page - 1) * limit
  2870. db = db.Offset(offset).Limit(limit)
  2871. }
  2872. err := db.Find(&vms).Error
  2873. return vms, err, total
  2874. }
  2875. func GetLastDialysisGoodsTwo(patient_id int64, orgID int64, record_time int64) (goodUser []*AutomaticReduceDetail, err error) {
  2876. var Id []*DialysisGoodsDetailDate
  2877. 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
  2878. if len(Id) > 0 {
  2879. 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
  2880. }
  2881. return
  2882. }
  2883. func GetLastDialysisBeforePrepareTwo(patient_id int64, orgID int64, record_time int64) (goodUser []*DialysisBeforePrepare, err error) {
  2884. var Id []*DialysisGoodsDate
  2885. 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
  2886. if len(Id) > 0 {
  2887. 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
  2888. }
  2889. return
  2890. }
  2891. func GetAssessmentBefor(orgid int64, patientid int64, recorddate int64) (*models.PredialysisEvaluation, error) {
  2892. evaluation := models.PredialysisEvaluation{}
  2893. err := XTReadDB().Model(&evaluation).Where("user_org_id = ? and patient_id = ? and assessment_date = ? and status = 1", orgid, patientid, recorddate).Find(&evaluation).Error
  2894. if err == gorm.ErrRecordNotFound {
  2895. return nil, err
  2896. }
  2897. if err != nil {
  2898. return nil, err
  2899. }
  2900. return &evaluation, nil
  2901. }
  2902. func GetAssessmentBeforThrity(orgid int64, patientid int64, recorddate int64) (models.PredialysisEvaluation, error) {
  2903. evaluation := models.PredialysisEvaluation{}
  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 GetAssessmentBeforFourty(orgid int64, patientid int64, recorddate int64) (models.XtAssessmentBeforeDislysis, error) {
  2908. evaluation := models.XtAssessmentBeforeDislysis{}
  2909. err := XTReadDB().Model(&evaluation).Where("user_org_id = ? and patient_id = ? and assessment_date = ? and status = 1", orgid, patientid, recorddate).Find(&evaluation).Error
  2910. return evaluation, err
  2911. }
  2912. func GetHisPrescriptionTemplateList(user_org_id int64, patient_id int64, mode_id int64) (models.HisPrescriptionTemplateSix, error) {
  2913. templateSix := models.HisPrescriptionTemplateSix{}
  2914. 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 {
  2915. return db.Where("status = 1 AND user_org_id = ? and type =2", user_org_id).Preload("HisPrescriptionProjectTemplateSeven", func(db *gorm.DB) *gorm.DB {
  2916. 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)
  2917. })
  2918. }).Find(&templateSix).Error
  2919. return templateSix, err
  2920. }
  2921. func GetAllHisDoctorAdvice(orgid int64, patientid int64, recorddate int64) (his []*models.HisDoctorAdviceInfo, err error) {
  2922. redis := RedisClient()
  2923. defer redis.Close()
  2924. key := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patientid, 10) + ":" + strconv.FormatInt(recorddate, 10) + ":his_doctor_advice"
  2925. his_doctor_advice_str, _ := redis.Get(key).Result()
  2926. redis.Set(key, "", time.Second)
  2927. if orgid != 10721 {
  2928. if len(his_doctor_advice_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2929. 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
  2930. if err != nil {
  2931. if err == gorm.ErrRecordNotFound {
  2932. if len(his) <= 0 {
  2933. redis.Set(key, "null", time.Second*60*60*18)
  2934. }
  2935. return his, nil
  2936. } else {
  2937. return his, err
  2938. }
  2939. } else {
  2940. if len(his) > 0 {
  2941. //缓存数据
  2942. his_doctor_advice_str, err := json.Marshal(his)
  2943. if err == nil {
  2944. redis.Set(key, his_doctor_advice_str, time.Second*60*60*18)
  2945. }
  2946. } else {
  2947. redis.Set(key, "null", time.Second*60*60*18)
  2948. }
  2949. return his, nil
  2950. }
  2951. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2952. json.Unmarshal([]byte(his_doctor_advice_str), &his)
  2953. return his, nil
  2954. }
  2955. }
  2956. if orgid == 10721 {
  2957. if len(his_doctor_advice_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2958. var keyword = "胰岛素"
  2959. keyword = "%" + keyword + "%"
  2960. err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date = ? and execution_frequency!='上机前' and delivery_way!='口服' and advice_name not like ?", patientid, orgid, recorddate, keyword).Order("created_time asc").Find(&his).Error
  2961. if err != nil {
  2962. if err == gorm.ErrRecordNotFound {
  2963. if len(his) <= 0 {
  2964. redis.Set(key, "null", time.Second*60*60*18)
  2965. }
  2966. return his, nil
  2967. } else {
  2968. return his, err
  2969. }
  2970. } else {
  2971. if len(his) > 0 {
  2972. //缓存数据
  2973. his_doctor_advice_str, err := json.Marshal(his)
  2974. if err == nil {
  2975. redis.Set(key, his_doctor_advice_str, time.Second*60*60*18)
  2976. }
  2977. } else {
  2978. redis.Set(key, "null", time.Second*60*60*18)
  2979. }
  2980. return his, nil
  2981. }
  2982. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2983. json.Unmarshal([]byte(his_doctor_advice_str), &his)
  2984. return his, nil
  2985. }
  2986. }
  2987. return his, nil
  2988. }
  2989. func GetLastDialysisPrescriptionByPatientId(orgid int64, patientid int64, recorddate int64) (*models.DialysisPrescription, error) {
  2990. prescription := models.DialysisPrescription{}
  2991. err := readDb.Model(&models.DialysisPrescription{}).Where("user_org_id = ? and patient_id = ? and record_date = ? and status = 1", orgid, patientid, recorddate).Find(&prescription).Error
  2992. if err == gorm.ErrRecordNotFound {
  2993. return nil, err
  2994. }
  2995. if err != nil {
  2996. return nil, err
  2997. }
  2998. return &prescription, nil
  2999. }
  3000. func GetLastDialysisPrescriptionByPatientIdTwo(orgid int64, patientid int64, recorddate int64) (models.DialysisPrescription, error) {
  3001. prescription := models.DialysisPrescription{}
  3002. err := readDb.Model(&models.DialysisPrescription{}).Where("user_org_id = ? and patient_id = ? and record_date = ? and status = 1", orgid, patientid, recorddate).Find(&prescription).Error
  3003. return prescription, err
  3004. }
  3005. type HisMScheduleDoctorAdviceVM struct {
  3006. ID int64 `gorm:"column:id" json:"id"`
  3007. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  3008. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  3009. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  3010. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  3011. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  3012. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  3013. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  3014. Status int64 `gorm:"column:status" json:"status"`
  3015. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  3016. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  3017. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  3018. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  3019. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  3020. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  3021. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  3022. }
  3023. func (HisMScheduleDoctorAdviceVM) TableName() string {
  3024. return "xt_schedule"
  3025. }
  3026. type HisMScheduleDoctorAdviceVMOne struct {
  3027. ID int64 `gorm:"column:id" json:"id"`
  3028. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  3029. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  3030. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  3031. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  3032. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  3033. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  3034. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  3035. Status int64 `gorm:"column:status" json:"status"`
  3036. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  3037. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  3038. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  3039. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  3040. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  3041. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  3042. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  3043. }
  3044. func (HisMScheduleDoctorAdviceVMOne) TableName() string {
  3045. return "xt_schedule"
  3046. }
  3047. type HisMScheduleProjectVM struct {
  3048. ID int64 `gorm:"column:id" json:"id"`
  3049. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  3050. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  3051. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  3052. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  3053. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  3054. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  3055. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  3056. Status int64 `gorm:"column:status" json:"status"`
  3057. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  3058. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  3059. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  3060. Prescription *models.DialysisPrescriptionTwenty `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  3061. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  3062. HisPrescriptionTeamProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"team_project"`
  3063. }
  3064. func (HisMScheduleProjectVM) TableName() string {
  3065. return "xt_schedule"
  3066. }
  3067. func GetHisDoctorConfig(orgid int64) (models.XtHisConfig, error) {
  3068. config := models.XtHisConfig{}
  3069. err := XTReadDB().Model(&config).Where("user_org_id = ? and status =1", orgid).Find(&config).Error
  3070. return config, err
  3071. }
  3072. func GetHisDoctorPatientById(orgid int64, patientid int64, recordtime int64) (advice []*models.HisDoctorAdviceInfo, err error) {
  3073. db := XTReadDB().Table("his_doctor_advice_info as x").Where("x.status = 1")
  3074. if orgid > 0 {
  3075. db = db.Where("x.user_org_id = ?", orgid)
  3076. }
  3077. if patientid > 0 {
  3078. db = db.Where("x.patient_id =?", patientid)
  3079. }
  3080. if recordtime > 0 {
  3081. db = db.Where("x.advice_date = ?", recordtime)
  3082. }
  3083. 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
  3084. return advice, err
  3085. }
  3086. func GetDoctorAdviceCount(startime int64, endtime int64, deliveway string, orgid int64) (advice []*models.BloodDoctorAdvice, err error) {
  3087. db := XTReadDB().Table("xt_doctor_advice as x").Where("x.status = 1 and x.advice_type =2")
  3088. if startime > 0 {
  3089. db = db.Where("x.advice_date >= ?", startime)
  3090. }
  3091. if endtime > 0 {
  3092. db = db.Where("x.advice_date<=?", endtime)
  3093. }
  3094. if orgid > 0 {
  3095. db = db.Where("x.user_org_id = ?", orgid)
  3096. }
  3097. if len(deliveway) > 0 {
  3098. db = db.Where("x.delivery_way = ?", deliveway)
  3099. }
  3100. 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
  3101. return advice, err
  3102. }
  3103. func GetHisDoctorAdviceCount(startime int64, endtime int64, deliveway string, orgid int64) (advice []*models.BloodDoctorAdvice, err error) {
  3104. db := XTReadDB().Table("his_doctor_advice_info as x").Where("x.status = 1 and x.advice_type =2")
  3105. if startime > 0 {
  3106. db = db.Where("x.advice_date >= ?", startime)
  3107. }
  3108. if endtime > 0 {
  3109. db = db.Where("x.advice_date<=?", endtime)
  3110. }
  3111. if orgid > 0 {
  3112. db = db.Where("x.user_org_id = ?", orgid)
  3113. }
  3114. if len(deliveway) > 0 {
  3115. db = db.Where("x.delivery_way = ?", deliveway)
  3116. }
  3117. 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
  3118. return advice, err
  3119. }
  3120. 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) {
  3121. var vms []*MScheduleDoctorAdviceVM
  3122. adviceWhere := ""
  3123. adviceCondition := []interface{}{}
  3124. if adviceType == 0 {
  3125. if patientType == 0 {
  3126. if patient_id > 0 {
  3127. if execution_state > 0 {
  3128. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  3129. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3130. } else {
  3131. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
  3132. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3133. }
  3134. } else {
  3135. if execution_state > 0 {
  3136. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ?"
  3137. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3138. } else {
  3139. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  3140. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3141. }
  3142. }
  3143. } else if patientType == 1 {
  3144. if patient_id > 0 {
  3145. if execution_state > 0 {
  3146. 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= ?"
  3147. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3148. } else {
  3149. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
  3150. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3151. }
  3152. } else {
  3153. if execution_state > 0 {
  3154. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  3155. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3156. } else {
  3157. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  3158. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3159. }
  3160. }
  3161. } else if patientType == 2 {
  3162. if patient_id > 0 {
  3163. if execution_state > 0 {
  3164. 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 = ?"
  3165. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3166. } else {
  3167. 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 = ?)"
  3168. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3169. }
  3170. } else {
  3171. if execution_state > 0 {
  3172. 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 = ?"
  3173. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3174. } else {
  3175. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  3176. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3177. }
  3178. }
  3179. }
  3180. } else if adviceType == 1 {
  3181. if patientType == 0 {
  3182. if patient_id > 0 {
  3183. if execution_state > 0 {
  3184. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ?"
  3185. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3186. } else {
  3187. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
  3188. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3189. }
  3190. } else {
  3191. if execution_state > 0 {
  3192. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ?"
  3193. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3194. } else {
  3195. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  3196. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3197. }
  3198. }
  3199. } else if patientType == 1 {
  3200. if patient_id > 0 {
  3201. if execution_state > 0 {
  3202. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  3203. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3204. } else {
  3205. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
  3206. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3207. }
  3208. } else {
  3209. if execution_state > 0 {
  3210. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?"
  3211. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3212. } else {
  3213. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  3214. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3215. }
  3216. }
  3217. } else if patientType == 2 {
  3218. if patient_id > 0 {
  3219. if execution_state > 0 {
  3220. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  3221. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3222. } else {
  3223. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
  3224. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3225. }
  3226. } else {
  3227. if execution_state > 0 {
  3228. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ?"
  3229. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3230. } else {
  3231. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  3232. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3233. }
  3234. }
  3235. }
  3236. } else if adviceType == 3 {
  3237. if patientType == 0 {
  3238. if patient_id > 0 {
  3239. if execution_state > 0 {
  3240. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ?"
  3241. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3242. } else {
  3243. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? "
  3244. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3245. }
  3246. } else {
  3247. if execution_state > 0 {
  3248. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? "
  3249. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3250. } else {
  3251. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  3252. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3253. }
  3254. }
  3255. } else if patientType == 1 {
  3256. if patient_id > 0 {
  3257. if execution_state > 0 {
  3258. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  3259. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3260. } else {
  3261. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
  3262. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3263. }
  3264. } else {
  3265. if execution_state > 0 {
  3266. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? "
  3267. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3268. } else {
  3269. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  3270. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3271. }
  3272. }
  3273. } else if patientType == 2 {
  3274. if patient_id > 0 {
  3275. if execution_state > 0 {
  3276. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  3277. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3278. } else {
  3279. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ?"
  3280. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3281. }
  3282. } else {
  3283. if execution_state > 0 {
  3284. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ?"
  3285. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3286. } else {
  3287. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  3288. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3289. }
  3290. }
  3291. }
  3292. } else if adviceType == 2 && len(deliverWay) > 0 {
  3293. if patientType == 0 {
  3294. if patient_id > 0 {
  3295. if execution_state > 0 {
  3296. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  3297. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  3298. } else {
  3299. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ?"
  3300. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  3301. }
  3302. } else {
  3303. if execution_state > 0 {
  3304. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ?"
  3305. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  3306. } else {
  3307. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  3308. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  3309. }
  3310. }
  3311. } else if patientType == 1 {
  3312. if patient_id > 0 {
  3313. if execution_state > 0 {
  3314. 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 = ?"
  3315. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state)
  3316. } else {
  3317. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ?"
  3318. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
  3319. }
  3320. } else {
  3321. if execution_state > 0 {
  3322. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ?"
  3323. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state)
  3324. } else {
  3325. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  3326. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  3327. }
  3328. }
  3329. } else if patientType == 2 {
  3330. if patient_id > 0 {
  3331. if execution_state > 0 {
  3332. 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 = ?"
  3333. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  3334. } else {
  3335. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ?"
  3336. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  3337. }
  3338. } else {
  3339. if execution_state > 0 {
  3340. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ?"
  3341. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  3342. } else {
  3343. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  3344. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  3345. }
  3346. }
  3347. }
  3348. } else if adviceType == 2 && len(deliverWay) <= 0 {
  3349. if patientType == 0 {
  3350. if patient_id > 0 {
  3351. if execution_state > 0 {
  3352. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ?"
  3353. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3354. } else {
  3355. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ?"
  3356. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3357. }
  3358. } else {
  3359. if execution_state > 0 {
  3360. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?"
  3361. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3362. } else {
  3363. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  3364. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3365. }
  3366. }
  3367. } else if patientType == 1 {
  3368. if patient_id > 0 {
  3369. if execution_state > 0 {
  3370. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  3371. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3372. } else {
  3373. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ?"
  3374. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3375. }
  3376. } else {
  3377. if execution_state > 0 {
  3378. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ?"
  3379. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3380. } else {
  3381. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?"
  3382. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3383. }
  3384. }
  3385. } else if patientType == 2 {
  3386. if patient_id > 0 {
  3387. if execution_state > 0 {
  3388. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  3389. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3390. } else {
  3391. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ?"
  3392. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3393. }
  3394. } else {
  3395. if execution_state > 0 {
  3396. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ?"
  3397. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3398. } else {
  3399. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  3400. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3401. }
  3402. }
  3403. }
  3404. }
  3405. db := readDb.Table("xt_schedule")
  3406. if scheduleType > 0 {
  3407. db = db.Where("schedule_type = ?", scheduleType)
  3408. }
  3409. if partitonType > 0 {
  3410. db = db.Where("partition_id = ?", partitonType)
  3411. }
  3412. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3413. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3414. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3415. }).
  3416. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3417. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3418. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3419. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3420. Preload("DoctorAdvices", adviceCondition...).
  3421. Where("status = 1 AND user_org_id = ?", orgID)
  3422. if scheduleDate != 0 {
  3423. db = db.Where("schedule_date = ?", scheduleDate)
  3424. }
  3425. err := db.Find(&vms).Error
  3426. return vms, err
  3427. }
  3428. func GetHisDoctorAdvicesOne(orgID int64, scheduleDate int64, deliverWay string, scheduleType int64, partitionType int64, patient_id int64, execution_state int64, cost_type int64) ([]*HisMScheduleDoctorAdviceVM, error) {
  3429. var vms []*HisMScheduleDoctorAdviceVM
  3430. if len(deliverWay) > 0 {
  3431. db := readDb.Table("xt_schedule")
  3432. if scheduleType > 0 {
  3433. db = db.Where("schedule_type = ?", scheduleType)
  3434. }
  3435. if partitionType > 0 {
  3436. db = db.Where("partition_id = ?", partitionType)
  3437. }
  3438. if patient_id > 0 {
  3439. if execution_state > 0 {
  3440. if cost_type > 0 {
  3441. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3442. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3443. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3444. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3445. 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).
  3446. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3447. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3448. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3449. Where("status = 1 AND user_org_id = ?", orgID)
  3450. if scheduleDate != 0 {
  3451. db = db.Where("schedule_date = ?", scheduleDate)
  3452. }
  3453. err = db.Find(&vms).Error
  3454. } else {
  3455. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3456. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3457. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3458. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3459. 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).
  3460. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3461. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3462. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3463. Where("status = 1 AND user_org_id = ?", orgID)
  3464. if scheduleDate != 0 {
  3465. db = db.Where("schedule_date = ?", scheduleDate)
  3466. }
  3467. err = db.Find(&vms).Error
  3468. }
  3469. } else {
  3470. if cost_type > 0 {
  3471. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3472. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3473. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3474. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3475. 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).
  3476. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3477. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3478. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3479. Where("status = 1 AND user_org_id = ?", orgID)
  3480. if scheduleDate != 0 {
  3481. db = db.Where("schedule_date = ?", scheduleDate)
  3482. }
  3483. err = db.Find(&vms).Error
  3484. } else {
  3485. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3486. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3487. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3488. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3489. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ?", orgID, scheduleDate, deliverWay, patient_id).
  3490. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3491. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3492. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3493. Where("status = 1 AND user_org_id = ?", orgID)
  3494. if scheduleDate != 0 {
  3495. db = db.Where("schedule_date = ?", scheduleDate)
  3496. }
  3497. err = db.Find(&vms).Error
  3498. }
  3499. }
  3500. } else {
  3501. if execution_state > 0 {
  3502. if cost_type > 0 {
  3503. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3504. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3505. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3506. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3507. 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).
  3508. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3509. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3510. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3511. Where("status = 1 AND user_org_id = ?", orgID)
  3512. if scheduleDate != 0 {
  3513. db = db.Where("schedule_date = ?", scheduleDate)
  3514. }
  3515. err = db.Find(&vms).Error
  3516. } else {
  3517. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3518. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3519. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3520. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3521. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_state = ?", orgID, scheduleDate, deliverWay, execution_state).
  3522. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3523. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3524. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3525. Where("status = 1 AND user_org_id = ?", orgID)
  3526. if scheduleDate != 0 {
  3527. db = db.Where("schedule_date = ?", scheduleDate)
  3528. }
  3529. err = db.Find(&vms).Error
  3530. }
  3531. } else {
  3532. if cost_type > 0 {
  3533. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3534. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3535. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3536. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3537. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and is_settle = ?", orgID, scheduleDate, deliverWay, cost_type).
  3538. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3539. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3540. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3541. Where("status = 1 AND user_org_id = ?", orgID)
  3542. if scheduleDate != 0 {
  3543. db = db.Where("schedule_date = ?", scheduleDate)
  3544. }
  3545. err = db.Find(&vms).Error
  3546. } else {
  3547. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3548. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3549. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3550. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3551. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  3552. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3553. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3554. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3555. Where("status = 1 AND user_org_id = ?", orgID)
  3556. if scheduleDate != 0 {
  3557. db = db.Where("schedule_date = ?", scheduleDate)
  3558. }
  3559. err = db.Find(&vms).Error
  3560. }
  3561. }
  3562. }
  3563. } else {
  3564. db := readDb.Table("xt_schedule")
  3565. if scheduleType > 0 {
  3566. db = db.Where("schedule_type = ?", scheduleType)
  3567. }
  3568. if partitionType > 0 {
  3569. db = db.Where("partition_id = ?", partitionType)
  3570. }
  3571. if patient_id > 0 {
  3572. if execution_state > 0 {
  3573. if cost_type > 0 {
  3574. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3575. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3576. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3577. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3578. 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).
  3579. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3580. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3581. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3582. Where("status = 1 AND user_org_id = ?", orgID)
  3583. if scheduleDate != 0 {
  3584. db = db.Where("schedule_date = ?", scheduleDate)
  3585. }
  3586. err = db.Find(&vms).Error
  3587. } else {
  3588. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3589. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3590. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3591. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3592. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and execution_state = ?", orgID, scheduleDate, patient_id, execution_state).
  3593. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3594. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3595. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3596. Where("status = 1 AND user_org_id = ?", orgID)
  3597. if scheduleDate != 0 {
  3598. db = db.Where("schedule_date = ?", scheduleDate)
  3599. }
  3600. err = db.Find(&vms).Error
  3601. }
  3602. } else {
  3603. if cost_type > 0 {
  3604. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3605. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3606. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3607. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3608. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and is_settle = ?", orgID, scheduleDate, patient_id, cost_type).
  3609. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3610. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3611. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3612. Where("status = 1 AND user_org_id = ?", orgID)
  3613. if scheduleDate != 0 {
  3614. db = db.Where("schedule_date = ?", scheduleDate)
  3615. }
  3616. err = db.Find(&vms).Error
  3617. } else {
  3618. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3619. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3620. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3621. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3622. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3623. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3624. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3625. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3626. Where("status = 1 AND user_org_id = ?", orgID)
  3627. if scheduleDate != 0 {
  3628. db = db.Where("schedule_date = ?", scheduleDate)
  3629. }
  3630. err = db.Find(&vms).Error
  3631. }
  3632. }
  3633. } else {
  3634. if execution_state > 0 {
  3635. if cost_type > 0 {
  3636. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3637. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3638. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3639. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3640. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ? and is_settle = ?", orgID, scheduleDate, execution_state, cost_type).
  3641. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3642. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3643. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3644. Where("status = 1 AND user_org_id = ?", orgID)
  3645. if scheduleDate != 0 {
  3646. db = db.Where("schedule_date = ?", scheduleDate)
  3647. }
  3648. err = db.Find(&vms).Error
  3649. } else {
  3650. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3651. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3652. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3653. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3654. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ?", orgID, scheduleDate, execution_state).
  3655. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3656. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3657. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3658. Where("status = 1 AND user_org_id = ?", orgID)
  3659. if scheduleDate != 0 {
  3660. db = db.Where("schedule_date = ?", scheduleDate)
  3661. }
  3662. err = db.Find(&vms).Error
  3663. }
  3664. } else {
  3665. if cost_type > 0 {
  3666. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3667. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3668. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3669. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3670. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and is_settle = ?", orgID, scheduleDate, cost_type).
  3671. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3672. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3673. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3674. Where("status = 1 AND user_org_id = ?", orgID)
  3675. if scheduleDate != 0 {
  3676. db = db.Where("schedule_date = ?", scheduleDate)
  3677. }
  3678. err = db.Find(&vms).Error
  3679. } else {
  3680. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3681. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3682. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3683. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3684. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ?", orgID, scheduleDate).
  3685. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3686. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3687. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3688. Where("status = 1 AND user_org_id = ?", orgID)
  3689. if scheduleDate != 0 {
  3690. db = db.Where("schedule_date = ?", scheduleDate)
  3691. }
  3692. err = db.Find(&vms).Error
  3693. }
  3694. }
  3695. }
  3696. }
  3697. return vms, err
  3698. }
  3699. func BatchDeleteMonitor(ids []string) (err error) {
  3700. if len(ids) == 1 {
  3701. err = XTWriteDB().Model(&models.MonitoringRecord{}).Where("id=?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3702. } else {
  3703. err = XTWriteDB().Model(models.MonitoringRecord{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3704. }
  3705. return
  3706. }
  3707. func GetPatientDialysisRecordList(patientid int64, startime int64, endtime int64) (order []*models.XtDialysisOrders, err error) {
  3708. db := XTReadDB().Table("xt_dialysis_order as x").Where("x.status = 1")
  3709. //table := XTReadDB().Table("xt_schedule as s")
  3710. //fmt.Println(table)
  3711. if patientid > 0 {
  3712. db = db.Where("x.patient_id = ?", patientid)
  3713. }
  3714. if startime > 0 {
  3715. db = db.Where("x.dialysis_date>=?", startime)
  3716. }
  3717. if endtime > 0 {
  3718. db = db.Where("x.dialysis_date <= ?", endtime)
  3719. }
  3720. 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
  3721. return order, err
  3722. }
  3723. func GetPatientDialysisRecordListOne(patientid int64, startime int64, endtime int64) (order []*models.XtScheduleSixTy, err error) {
  3724. db := XTReadDB().Table("xt_schedule as x").Where("x.status = 1")
  3725. //table := XTReadDB().Table("xt_schedule as s")
  3726. //fmt.Println(table)
  3727. if patientid > 0 {
  3728. db = db.Where("x.patient_id = ?", patientid)
  3729. }
  3730. if startime > 0 {
  3731. db = db.Where("x.schedule_date>=?", startime)
  3732. }
  3733. if endtime > 0 {
  3734. db = db.Where("x.schedule_date <= ?", endtime)
  3735. }
  3736. err = db.Select("x.id,x.schedule_date,x.schedule_type,x.mode_id").Find(&order).Error
  3737. return order, err
  3738. }
  3739. func BatchDeleteAdvice(ids []string) (err error) {
  3740. if len(ids) == 1 {
  3741. err = XTWriteDB().Model(&models.DoctorAdvice{}).Where("id=?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3742. } else {
  3743. err = XTWriteDB().Model(models.DoctorAdvice{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3744. }
  3745. return
  3746. }
  3747. func BatchDeleteHisAdvice(ids []string) (err error) {
  3748. if len(ids) == 1 {
  3749. err = XTWriteDB().Model(&models.HisDoctorAdviceInfo{}).Where("id = ?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3750. } else {
  3751. err = XTWriteDB().Model(models.HisDoctorAdviceInfo{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3752. }
  3753. return
  3754. }
  3755. func UpdateAutoReduceDetail(good_id int64, count int64, record_time int64, patient_id int64) (models.AutomaticReduceDetail, error) {
  3756. detail := models.AutomaticReduceDetail{}
  3757. 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
  3758. return detail, err
  3759. }
  3760. func DeleteAutoReduceDetail(good_id int64, record_time int64, patient_id int64) error {
  3761. detail := models.AutomaticReduceDetail{}
  3762. 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
  3763. return err
  3764. }
  3765. func DeleteDialysisBeforOne(good_id int64, record_time int64, patient_id int64) error {
  3766. detail := models.DialysisBeforePrepare{}
  3767. 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
  3768. return err
  3769. }
  3770. func BatchAdviceCheck(ids []string, creator int64) error {
  3771. advice := models.XtDoctorAdvice{}
  3772. 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
  3773. return err
  3774. }
  3775. func BatchHisAdviceCheck(ids []string, creator int64) error {
  3776. advice := models.HisDoctorAdviceInfo{}
  3777. 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
  3778. return err
  3779. }
  3780. func BatchAdviceExecution(ids []string, creator int64, execution_state int64) error {
  3781. advice := models.XtDoctorAdvice{}
  3782. 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
  3783. return err
  3784. }
  3785. func BatchHisAdviceExecution(ids []string, creator int64, execution_state int64) error {
  3786. advice := models.HisDoctorAdviceInfo{}
  3787. 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
  3788. return err
  3789. }
  3790. func GetAdviceExecutionById(ids []string) (doctor []*models.XtDoctorAdvice, err error) {
  3791. err = XTReadDB().Model(&doctor).Where("id IN(?) AND status = 1", ids).Find(&doctor).Error
  3792. return doctor, err
  3793. }
  3794. func GetHisAdviceExecutionById(ids []string) (doctor []*models.HisDoctorAdviceInfo, err error) {
  3795. err = XTReadDB().Model(&doctor).Where("id IN(?) AND status = 1", ids).Find(&doctor).Error
  3796. return doctor, err
  3797. }
  3798. func GetHisProjectConfig(orgid int64) (models.XtHisProjectConfig, error) {
  3799. config := models.XtHisProjectConfig{}
  3800. err := XTReadDB().Model(&config).Where("user_org_id = ? and status =1", orgid).Find(&config).Error
  3801. return config, err
  3802. }
  3803. func GetHisPrescriptionProject(org_id int64, patient_id int64, record_date int64) (project []*models.HisPrescriptionProject, err error) {
  3804. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("GoodInfo", func(db *gorm.DB) *gorm.DB {
  3805. return db.Preload("GoodsType", "status = 1").Where("status = 1 and is_warehouse = 1")
  3806. }).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
  3807. return
  3808. }
  3809. func GetPCHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64, patient_id int64, execution_state int64) ([]*HisMScheduleProjectVM, error) {
  3810. var vms []*HisMScheduleProjectVM
  3811. if patientType == 0 {
  3812. if patient_id > 0 {
  3813. if execution_state == 1 {
  3814. db := readDb.
  3815. Table("xt_schedule").
  3816. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3817. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3818. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3819. }).
  3820. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3821. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3822. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3823. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3824. 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")
  3825. }).
  3826. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3827. 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")
  3828. }).Where("status = 1 AND user_org_id = ?", orgID)
  3829. if scheduleDate != 0 {
  3830. db = db.Where("schedule_date = ?", scheduleDate)
  3831. }
  3832. err = db.Find(&vms).Error
  3833. } else if execution_state == 2 {
  3834. db := readDb.
  3835. Table("xt_schedule").
  3836. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3837. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3838. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3839. }).
  3840. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3841. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3842. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3843. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3844. 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")
  3845. }).
  3846. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3847. 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")
  3848. }).Where("status = 1 AND user_org_id = ?", orgID)
  3849. if scheduleDate != 0 {
  3850. db = db.Where("schedule_date = ?", scheduleDate)
  3851. }
  3852. err = db.Find(&vms).Error
  3853. } else if execution_state == 0 {
  3854. db := readDb.
  3855. Table("xt_schedule").
  3856. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3857. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3858. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3859. }).
  3860. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3861. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3862. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3863. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3864. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3865. }).
  3866. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3867. 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")
  3868. }).Where("status = 1 AND user_org_id = ?", orgID)
  3869. if scheduleDate != 0 {
  3870. db = db.Where("schedule_date = ?", scheduleDate)
  3871. }
  3872. err = db.Find(&vms).Error
  3873. }
  3874. } else {
  3875. if patient_id > 0 {
  3876. if execution_state == 1 {
  3877. db := readDb.
  3878. Table("xt_schedule").
  3879. Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
  3880. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3881. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3882. }).
  3883. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3884. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3885. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3886. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3887. 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")
  3888. }).
  3889. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3890. 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")
  3891. }).Where("status = 1 AND user_org_id = ?", orgID)
  3892. if scheduleDate != 0 {
  3893. db = db.Where("schedule_date = ?", scheduleDate)
  3894. }
  3895. err = db.Find(&vms).Error
  3896. } else if execution_state == 2 {
  3897. db := readDb.
  3898. Table("xt_schedule").
  3899. Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
  3900. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3901. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3902. }).
  3903. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3904. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3905. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3906. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3907. 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")
  3908. }).
  3909. Preload("HisPrescriptionTeamProject", 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 = 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  3911. }).Where("status = 1 AND user_org_id = ?", orgID)
  3912. if scheduleDate != 0 {
  3913. db = db.Where("schedule_date = ?", scheduleDate)
  3914. }
  3915. err = db.Find(&vms).Error
  3916. } else if execution_state == 0 {
  3917. db := readDb.
  3918. Table("xt_schedule").
  3919. Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
  3920. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3921. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3922. }).
  3923. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3924. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3925. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3926. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3927. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3928. }).
  3929. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3930. 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")
  3931. }).Where("status = 1 AND user_org_id = ?", orgID)
  3932. if scheduleDate != 0 {
  3933. db = db.Where("schedule_date = ?", scheduleDate)
  3934. }
  3935. err = db.Find(&vms).Error
  3936. }
  3937. } else {
  3938. if execution_state == 1 {
  3939. db := readDb.
  3940. Table("xt_schedule").
  3941. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3942. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3943. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3944. }).
  3945. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3946. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3947. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3948. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3949. 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")
  3950. }).
  3951. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3952. 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")
  3953. }).Where("status = 1 AND user_org_id = ?", orgID)
  3954. if scheduleDate != 0 {
  3955. db = db.Where("schedule_date = ?", scheduleDate)
  3956. }
  3957. err = db.Find(&vms).Error
  3958. } else if execution_state == 2 {
  3959. fmt.Println("j氯332n323232n323ℹ️33232323232")
  3960. db := readDb.
  3961. Table("xt_schedule").
  3962. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3963. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3964. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3965. }).
  3966. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3967. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3968. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3969. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3970. 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")
  3971. }).
  3972. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3973. 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")
  3974. }).Where("status = 1 AND user_org_id = ?", orgID)
  3975. if scheduleDate != 0 {
  3976. db = db.Where("schedule_date = ?", scheduleDate)
  3977. }
  3978. err = db.Find(&vms).Error
  3979. } else if execution_state == 0 {
  3980. db := readDb.
  3981. Table("xt_schedule").
  3982. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3983. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3984. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3985. }).
  3986. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3987. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3988. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3989. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3990. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3991. }).
  3992. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3993. 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")
  3994. }).Where("status = 1 AND user_org_id = ?", orgID)
  3995. if scheduleDate != 0 {
  3996. db = db.Where("schedule_date = ?", scheduleDate)
  3997. }
  3998. err = db.Find(&vms).Error
  3999. }
  4000. }
  4001. }
  4002. }
  4003. if patientType > 0 {
  4004. if execution_state == 1 {
  4005. db := readDb.
  4006. Table("xt_schedule").
  4007. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  4008. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  4009. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  4010. }).
  4011. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  4012. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  4013. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  4014. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  4015. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  4016. 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")
  4017. }).
  4018. Preload("HisPrescriptionTeamProject", 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("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  4020. }).Where("status = 1 AND user_org_id = ?", orgID)
  4021. if scheduleDate != 0 {
  4022. db = db.Where("schedule_date = ?", scheduleDate)
  4023. }
  4024. err = db.Find(&vms).Error
  4025. } else if execution_state == 2 {
  4026. db := readDb.
  4027. Table("xt_schedule").
  4028. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  4029. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  4030. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  4031. }).
  4032. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  4033. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  4034. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  4035. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  4036. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  4037. 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")
  4038. }).
  4039. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  4040. 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")
  4041. }).Where("status = 1 AND user_org_id = ?", orgID)
  4042. if scheduleDate != 0 {
  4043. db = db.Where("schedule_date = ?", scheduleDate)
  4044. }
  4045. err = db.Find(&vms).Error
  4046. } else if execution_state == 0 {
  4047. db := readDb.
  4048. Table("xt_schedule").
  4049. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  4050. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  4051. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  4052. }).
  4053. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  4054. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  4055. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  4056. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  4057. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  4058. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  4059. }).
  4060. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  4061. 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")
  4062. }).Where("status = 1 AND user_org_id = ?", orgID)
  4063. if scheduleDate != 0 {
  4064. db = db.Where("schedule_date = ?", scheduleDate)
  4065. }
  4066. err = db.Find(&vms).Error
  4067. }
  4068. }
  4069. return vms, err
  4070. }
  4071. func UpdateStockGoods(good_id int64, record_time int64, patient_id int64, count int64) error {
  4072. prepare := models.DialysisBeforePrepare{}
  4073. var err error
  4074. if count > 0 {
  4075. 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
  4076. }
  4077. if count <= 0 {
  4078. 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
  4079. }
  4080. return err
  4081. }
  4082. func UPdateAutoStockGoods(good_id int64, record_time int64, patient_id int64, count int64) error {
  4083. detail := models.AutomaticReduceDetail{}
  4084. 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
  4085. return err
  4086. }
  4087. func MobileGetDialysisSolutionByModeIdSeven(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  4088. var record models.DialysisSolution
  4089. 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
  4090. if err != nil {
  4091. if err == gorm.ErrRecordNotFound {
  4092. return nil, nil
  4093. } else {
  4094. return nil, err
  4095. }
  4096. }
  4097. return &record, nil
  4098. }
  4099. func MobileGetLastDialysisPrescribeByModeIdSeven(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  4100. var record models.DialysisPrescription
  4101. 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
  4102. if err != nil {
  4103. if err == gorm.ErrRecordNotFound {
  4104. return nil, nil
  4105. } else {
  4106. return nil, err
  4107. }
  4108. }
  4109. return &record, nil
  4110. }
  4111. func MobileGetLastDialysisPrescription(patientID int64, orgID int64) (models.DialysisPrescriptionThrity, error) {
  4112. prescription := models.DialysisPrescriptionThrity{}
  4113. err := readDb.Model(&prescription).Where("patient_id = ? and user_org_id = ? and status = 1 and remark<>''", patientID, orgID).Last(&prescription).Error
  4114. return prescription, err
  4115. }
  4116. func MobileGetSystemDialysisPrescribeByModeIdSeven(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  4117. var record models.SystemPrescription
  4118. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).First(&record).Error
  4119. if err != nil {
  4120. if err == gorm.ErrRecordNotFound {
  4121. return nil, nil
  4122. } else {
  4123. return nil, err
  4124. }
  4125. }
  4126. return &record, nil
  4127. }
  4128. // 透前评估
  4129. func MobileGetPredialysisEvaluationSeven(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
  4130. var record models.PredialysisEvaluation
  4131. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  4132. if err != nil {
  4133. if err == gorm.ErrRecordNotFound {
  4134. return nil, nil
  4135. } else {
  4136. return nil, err
  4137. }
  4138. }
  4139. return &record, nil
  4140. }
  4141. //
  4142. //func MobileGetDialysisGoodsSix(orgID int64, scheduleDate int64) (prepare []*models.DialysisBeforePrepare, err error) {
  4143. //
  4144. // 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
  4145. // return prepare, err
  4146. //}
  4147. func GetMobileAutoReduce(orgID int64, scheduleDate int64) (auto []*models.AutomaticReduceDetail, err error) {
  4148. err = readDb.Where("org_id = ? and status = 1 and record_time = ?", orgID, scheduleDate).Find(&auto).Error
  4149. return auto, err
  4150. }
  4151. func GetRoleList(orgid int64, admin_user_id int64) (models.SgjUserAdminRole, error) {
  4152. role := models.SgjUserAdminRole{}
  4153. err = readUserDb.Where("org_id = ? and admin_user_id = ? and status =1 ", orgid, admin_user_id).Find(&role).Error
  4154. return role, err
  4155. }
  4156. func GetDialysisGood(orgID int64, scheduleDate int64) (auto []*models.AutomaticReduceDetail, err error) {
  4157. err = readDb.Where("org_id = ? and status = 1 and record_time >= ?", orgID, scheduleDate).Group("patient_id").Find(&auto).Error
  4158. return auto, err
  4159. }
  4160. func GetGoodWarehouseOutInfo(orgId int64, patient_id int64, sys_record_time int64) (outifno []*models.WarehouseOutInfoSeven, err error) {
  4161. err = readDb.Where("org_id = ? and patient_id = ? and sys_record_time = ? and status = 1", orgId, patient_id, sys_record_time).Find(&outifno).Error
  4162. return outifno, err
  4163. }
  4164. func GetLastDilysisOrder(orgid int64, patient_id int64, dialysis_date int64) (models.DialysisOrder, error) {
  4165. order := models.DialysisOrder{}
  4166. err = XTReadDB().Where("user_org_id = ? and patient_id = ? and dialysis_date < ? and status= 1", orgid, patient_id, dialysis_date).Last(&order).Error
  4167. return order, err
  4168. }
  4169. func GetFistMonitor(orgid int64, patient_id int64, dialysis_date int64) (models.MonitoringRecord, error) {
  4170. record := models.MonitoringRecord{}
  4171. err := XTReadDB().Where("org_id = ? and patient_id = ? and monitoring_date = ? and status = 1", orgid, patient_id, dialysis_date).Find(&record).Error
  4172. return record, err
  4173. }
  4174. func GetFistMonitorSix(orgid int64, patient_id int64, dialysis_date int64) (record []*models.MonitoringRecord, err error) {
  4175. err = XTReadDB().Where("user_org_id = ? and patient_id = ? and monitoring_date = ? and status = 1", orgid, patient_id, dialysis_date).Find(&record).Error
  4176. return record, err
  4177. }
  4178. 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) {
  4179. var vms []*MScheduleDoctorAdviceVM
  4180. keyword = "%" + keyword + "%"
  4181. adviceWhere := ""
  4182. adviceCondition := []interface{}{}
  4183. if adviceType == 0 {
  4184. if patientType == 0 {
  4185. if patient_id > 0 {
  4186. if execution_state > 0 {
  4187. if cost_type > 0 {
  4188. if len(execution_frequency) > 0 {
  4189. if len(keyword) > 0 {
  4190. 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 ?"
  4191. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4192. } else {
  4193. 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 = ?"
  4194. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4195. }
  4196. } else {
  4197. if len(keyword) > 0 {
  4198. 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 ?"
  4199. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  4200. } else {
  4201. 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 = ?"
  4202. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4203. }
  4204. }
  4205. } else {
  4206. if len(execution_frequency) > 0 {
  4207. if len(keyword) > 0 {
  4208. 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 ?"
  4209. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  4210. } else {
  4211. 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 = ?"
  4212. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4213. }
  4214. } else {
  4215. if len(keyword) > 0 {
  4216. 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 ?"
  4217. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  4218. } else {
  4219. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  4220. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4221. }
  4222. }
  4223. }
  4224. } else {
  4225. if cost_type > 0 {
  4226. if len(execution_frequency) > 0 {
  4227. 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 = ?"
  4228. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4229. } else {
  4230. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and is_settle = ?"
  4231. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4232. }
  4233. } else {
  4234. if len(execution_frequency) > 0 {
  4235. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_frequency = ?"
  4236. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4237. } else {
  4238. if len(keyword) > 0 {
  4239. 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 ?"
  4240. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  4241. } else {
  4242. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
  4243. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4244. }
  4245. }
  4246. }
  4247. }
  4248. } else {
  4249. if execution_state > 0 {
  4250. if cost_type > 0 {
  4251. if len(execution_frequency) > 0 {
  4252. if len(keyword) > 0 {
  4253. 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 ?"
  4254. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  4255. } else {
  4256. 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 = ?"
  4257. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4258. }
  4259. } else {
  4260. if len(keyword) > 0 {
  4261. 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 ?"
  4262. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  4263. } else {
  4264. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and is_settle = ?"
  4265. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4266. }
  4267. }
  4268. } else {
  4269. if len(execution_frequency) > 0 {
  4270. if len(keyword) > 0 {
  4271. 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 ?"
  4272. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  4273. } else {
  4274. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and execution_frequency = ?"
  4275. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4276. }
  4277. } else {
  4278. if len(keyword) > 0 {
  4279. 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 ?"
  4280. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  4281. } else {
  4282. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ?"
  4283. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4284. }
  4285. }
  4286. }
  4287. } else {
  4288. if cost_type > 0 {
  4289. if len(execution_frequency) > 0 {
  4290. if len(keyword) > 0 {
  4291. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ? and execution_frequency = ? and advice_name like ?"
  4292. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  4293. } else {
  4294. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ? and execution_frequency = ?"
  4295. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  4296. }
  4297. } else {
  4298. if len(keyword) > 0 {
  4299. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ? and advice_name like ?"
  4300. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  4301. } else {
  4302. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ?"
  4303. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4304. }
  4305. }
  4306. } else {
  4307. if len(execution_frequency) > 0 {
  4308. if len(keyword) > 0 {
  4309. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_frequency = ? and advice_name like ?"
  4310. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  4311. } else {
  4312. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_frequency = ?"
  4313. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  4314. }
  4315. } else {
  4316. if len(keyword) > 0 {
  4317. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and advice_name like ?"
  4318. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  4319. } else {
  4320. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  4321. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4322. }
  4323. }
  4324. }
  4325. }
  4326. }
  4327. } else if patientType == 1 {
  4328. if patient_id > 0 {
  4329. if execution_state > 0 {
  4330. if cost_type > 0 {
  4331. if len(execution_frequency) > 0 {
  4332. if len(keyword) > 0 {
  4333. 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 ?"
  4334. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4335. } else {
  4336. 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 = ?"
  4337. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  4338. }
  4339. } else {
  4340. if len(keyword) > 0 {
  4341. 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 ?"
  4342. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, keyword)
  4343. } else {
  4344. 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 = ?"
  4345. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  4346. }
  4347. }
  4348. } else {
  4349. if len(execution_frequency) > 0 {
  4350. if len(keyword) > 0 {
  4351. 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 ?"
  4352. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  4353. } else {
  4354. 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 = ?"
  4355. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  4356. }
  4357. } else {
  4358. if len(keyword) > 0 {
  4359. 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 ?"
  4360. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, keyword)
  4361. } else {
  4362. 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= ?"
  4363. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  4364. }
  4365. }
  4366. }
  4367. } else {
  4368. if cost_type > 0 {
  4369. if len(execution_frequency) > 0 {
  4370. if len(keyword) > 0 {
  4371. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ? and is_settle=? and execution_frequency = ? and advice_name like ?"
  4372. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  4373. } else {
  4374. 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 = ?"
  4375. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  4376. }
  4377. } else {
  4378. if len(keyword) > 0 {
  4379. 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 ?"
  4380. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, keyword)
  4381. } else {
  4382. 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=?"
  4383. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  4384. }
  4385. }
  4386. } else {
  4387. if len(execution_frequency) > 0 {
  4388. if len(keyword) > 0 {
  4389. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_frequency = ? and advice_name like ?"
  4390. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency, keyword)
  4391. } else {
  4392. 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 = ?"
  4393. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  4394. }
  4395. } else {
  4396. if len(keyword) > 0 {
  4397. 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 ?"
  4398. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, keyword)
  4399. } else {
  4400. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
  4401. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  4402. }
  4403. }
  4404. }
  4405. }
  4406. } else {
  4407. if execution_state > 0 {
  4408. if cost_type > 0 {
  4409. if len(execution_frequency) > 0 {
  4410. if len(keyword) > 0 {
  4411. 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 ?"
  4412. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  4413. } else {
  4414. 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 = ?"
  4415. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  4416. }
  4417. } else {
  4418. if len(keyword) > 0 {
  4419. 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 ?"
  4420. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, keyword)
  4421. } else {
  4422. 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=?"
  4423. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  4424. }
  4425. }
  4426. } else {
  4427. if len(execution_frequency) > 0 {
  4428. if len(keyword) > 0 {
  4429. 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 ?"
  4430. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency, keyword)
  4431. } else {
  4432. 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 = ?"
  4433. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  4434. }
  4435. } else {
  4436. if len(keyword) > 0 {
  4437. 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 ?"
  4438. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, keyword)
  4439. } else {
  4440. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  4441. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  4442. }
  4443. }
  4444. }
  4445. } else {
  4446. if cost_type > 0 {
  4447. if len(execution_frequency) > 0 {
  4448. if len(keyword) > 0 {
  4449. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and is_settle=? and execution_frequency = ? and advice_name like ?"
  4450. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency, keyword)
  4451. } else {
  4452. 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 = ?"
  4453. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  4454. }
  4455. } else {
  4456. if len(keyword) > 0 {
  4457. 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 ?"
  4458. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, keyword)
  4459. } else {
  4460. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and is_settle=?"
  4461. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  4462. }
  4463. }
  4464. } else {
  4465. if len(execution_frequency) > 0 {
  4466. if len(keyword) > 0 {
  4467. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_frequency = ? and advice_name like ?"
  4468. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency, keyword)
  4469. } else {
  4470. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_frequency = ?"
  4471. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  4472. }
  4473. } else {
  4474. if len(keyword) > 0 {
  4475. 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 ?"
  4476. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, keyword)
  4477. } else {
  4478. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  4479. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  4480. }
  4481. }
  4482. }
  4483. }
  4484. }
  4485. } else if patientType == 2 {
  4486. if patient_id > 0 {
  4487. if execution_state > 0 {
  4488. if cost_type > 0 {
  4489. if len(execution_frequency) > 0 {
  4490. if len(keyword) > 0 {
  4491. 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 ?"
  4492. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4493. } else {
  4494. 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 = ?"
  4495. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4496. }
  4497. } else {
  4498. if len(keyword) > 0 {
  4499. 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 ?"
  4500. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  4501. } else {
  4502. 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=?"
  4503. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4504. }
  4505. }
  4506. } else {
  4507. if len(execution_frequency) > 0 {
  4508. if len(keyword) > 0 {
  4509. 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 ?"
  4510. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  4511. } else {
  4512. 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 = ?"
  4513. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4514. }
  4515. } else {
  4516. if len(keyword) > 0 {
  4517. 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 ?"
  4518. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  4519. } else {
  4520. 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 = ?"
  4521. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4522. }
  4523. }
  4524. }
  4525. } else {
  4526. if cost_type > 0 {
  4527. if len(execution_frequency) > 0 {
  4528. if len(keyword) > 0 {
  4529. 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 ?"
  4530. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  4531. } else {
  4532. 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 = ?"
  4533. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4534. }
  4535. } else {
  4536. if len(keyword) > 0 {
  4537. 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 ?"
  4538. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  4539. } else {
  4540. 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=?"
  4541. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4542. }
  4543. }
  4544. } else {
  4545. if len(execution_frequency) > 0 {
  4546. if len(keyword) > 0 {
  4547. 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 ?"
  4548. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  4549. } else {
  4550. 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 = ?"
  4551. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4552. }
  4553. } else {
  4554. if len(keyword) > 0 {
  4555. 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 ?"
  4556. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  4557. } else {
  4558. 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 = ?)"
  4559. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4560. }
  4561. }
  4562. }
  4563. }
  4564. } else {
  4565. if execution_state > 0 {
  4566. if cost_type > 0 {
  4567. if len(execution_frequency) > 0 {
  4568. if len(keyword) > 0 {
  4569. adviceWhere = "status = 1 AND user_org_id = ? AND 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 ?"
  4570. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  4571. } else {
  4572. 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 = ?"
  4573. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4574. }
  4575. } else {
  4576. if len(keyword) > 0 {
  4577. 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 ?"
  4578. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  4579. } else {
  4580. 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=?"
  4581. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4582. }
  4583. }
  4584. } else {
  4585. if len(execution_frequency) > 0 {
  4586. if len(keyword) > 0 {
  4587. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1) and execution_state = ? and execution_frequency = ? and advice_name like ?"
  4588. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  4589. } else {
  4590. 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 = ?"
  4591. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4592. }
  4593. } else {
  4594. if len(keyword) > 0 {
  4595. 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 ?"
  4596. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  4597. } else {
  4598. 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 = ?"
  4599. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4600. }
  4601. }
  4602. }
  4603. } else {
  4604. if cost_type > 0 {
  4605. if len(execution_frequency) > 0 {
  4606. if len(keyword) > 0 {
  4607. 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 ?"
  4608. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  4609. } else {
  4610. 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 = ?"
  4611. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  4612. }
  4613. } else {
  4614. if len(keyword) > 0 {
  4615. 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 ?"
  4616. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  4617. } else {
  4618. 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 = ?"
  4619. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4620. }
  4621. }
  4622. } else {
  4623. if len(execution_frequency) > 0 {
  4624. if len(keyword) > 0 {
  4625. 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 ?"
  4626. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  4627. } else {
  4628. 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 = ?"
  4629. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  4630. }
  4631. } else {
  4632. if len(keyword) > 0 {
  4633. 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 ?"
  4634. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  4635. } else {
  4636. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  4637. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4638. }
  4639. }
  4640. }
  4641. }
  4642. }
  4643. }
  4644. } else if adviceType == 1 {
  4645. if patientType == 0 {
  4646. if patient_id > 0 {
  4647. if execution_state > 0 {
  4648. if cost_type > 0 {
  4649. if len(execution_frequency) > 0 {
  4650. if len(keyword) > 0 {
  4651. 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 ?"
  4652. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4653. } else {
  4654. 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 = ?"
  4655. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4656. }
  4657. } else {
  4658. if len(keyword) > 0 {
  4659. 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 ?"
  4660. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  4661. } else {
  4662. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  4663. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4664. }
  4665. }
  4666. } else {
  4667. if len(execution_frequency) > 0 {
  4668. if len(keyword) > 0 {
  4669. 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 ?"
  4670. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  4671. } else {
  4672. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  4673. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4674. }
  4675. } else {
  4676. if len(keyword) > 0 {
  4677. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  4678. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  4679. } else {
  4680. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ?"
  4681. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4682. }
  4683. }
  4684. }
  4685. } else {
  4686. if cost_type > 0 {
  4687. if len(execution_frequency) > 0 {
  4688. if len(keyword) > 0 {
  4689. 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 ?"
  4690. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  4691. } else {
  4692. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  4693. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4694. }
  4695. } else {
  4696. if len(keyword) > 0 {
  4697. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? and advice_name like ? "
  4698. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  4699. } else {
  4700. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? "
  4701. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4702. }
  4703. }
  4704. } else {
  4705. if len(execution_frequency) > 0 {
  4706. if len(keyword) > 0 {
  4707. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and advice_name like ?"
  4708. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  4709. } else {
  4710. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
  4711. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4712. }
  4713. }
  4714. }
  4715. }
  4716. } else {
  4717. if execution_state > 0 {
  4718. if cost_type > 0 {
  4719. if len(execution_frequency) > 0 {
  4720. if len(keyword) > 0 {
  4721. 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 ?"
  4722. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  4723. } else {
  4724. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  4725. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4726. }
  4727. } else {
  4728. if len(keyword) > 0 {
  4729. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  4730. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  4731. } else {
  4732. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ?"
  4733. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4734. }
  4735. }
  4736. } else {
  4737. if len(execution_frequency) > 0 {
  4738. if len(keyword) > 0 {
  4739. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  4740. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  4741. } else {
  4742. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and execution_frequency = ?"
  4743. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4744. }
  4745. } else {
  4746. if len(keyword) > 0 {
  4747. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and advice_name like ?"
  4748. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  4749. } else {
  4750. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ?"
  4751. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4752. }
  4753. }
  4754. }
  4755. } else {
  4756. if cost_type > 0 {
  4757. if len(keyword) > 0 {
  4758. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = ? and advice_name like ?"
  4759. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  4760. } else {
  4761. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = ? "
  4762. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4763. }
  4764. } else {
  4765. if len(keyword) > 0 {
  4766. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and advice_name like ?"
  4767. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  4768. } else {
  4769. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  4770. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4771. }
  4772. }
  4773. }
  4774. }
  4775. } else if patientType == 1 {
  4776. if patient_id > 0 {
  4777. if execution_state > 0 {
  4778. if cost_type > 0 {
  4779. if len(execution_frequency) > 0 {
  4780. if len(keyword) > 0 {
  4781. 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 ?"
  4782. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4783. } else {
  4784. 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 = ?"
  4785. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  4786. }
  4787. } else {
  4788. if len(keyword) > 0 {
  4789. 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 ?"
  4790. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, keyword)
  4791. } else {
  4792. 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 = ?"
  4793. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  4794. }
  4795. }
  4796. } else {
  4797. if len(execution_frequency) > 0 {
  4798. if len(keyword) > 0 {
  4799. 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 ?"
  4800. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  4801. } else {
  4802. 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 = ?"
  4803. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  4804. }
  4805. } else {
  4806. if len(keyword) > 0 {
  4807. 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 ?"
  4808. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, keyword)
  4809. } else {
  4810. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  4811. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  4812. }
  4813. }
  4814. }
  4815. } else {
  4816. if cost_type > 0 {
  4817. if len(execution_frequency) > 0 {
  4818. if len(keyword) > 0 {
  4819. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and is_settle = ?and execution_frequency = ? and advice_name like ?"
  4820. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  4821. } else {
  4822. 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 = ?"
  4823. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  4824. }
  4825. } else {
  4826. if len(keyword) > 0 {
  4827. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  4828. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, keyword)
  4829. } else {
  4830. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  4831. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  4832. }
  4833. }
  4834. } else {
  4835. if len(execution_frequency) > 0 {
  4836. if len(keyword) > 0 {
  4837. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  4838. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency, keyword)
  4839. } else {
  4840. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  4841. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  4842. }
  4843. } else {
  4844. if len(keyword) > 0 {
  4845. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and advice_name like ?"
  4846. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, keyword)
  4847. } else {
  4848. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
  4849. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  4850. }
  4851. }
  4852. }
  4853. }
  4854. } else {
  4855. if execution_state > 0 {
  4856. if cost_type > 0 {
  4857. if len(execution_frequency) > 0 {
  4858. if len(keyword) > 0 {
  4859. 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 ?"
  4860. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  4861. } else {
  4862. 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 = ?"
  4863. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  4864. }
  4865. } else {
  4866. if len(keyword) > 0 {
  4867. 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 ?"
  4868. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, keyword)
  4869. } else {
  4870. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=? and is_settle = ?"
  4871. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  4872. }
  4873. }
  4874. } else {
  4875. if len(execution_frequency) > 0 {
  4876. if len(keyword) > 0 {
  4877. 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 ?"
  4878. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency, keyword)
  4879. } else {
  4880. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?and execution_frequency = ?"
  4881. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  4882. }
  4883. } else {
  4884. if len(keyword) > 0 {
  4885. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=? and advice_name like ?"
  4886. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, keyword)
  4887. } else {
  4888. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?"
  4889. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  4890. }
  4891. }
  4892. }
  4893. } else {
  4894. if cost_type > 0 {
  4895. if len(execution_frequency) > 0 {
  4896. if len(keyword) > 0 {
  4897. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  4898. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency, keyword)
  4899. } else {
  4900. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  4901. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  4902. }
  4903. } else {
  4904. if len(keyword) > 0 {
  4905. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? and advice_name like ?"
  4906. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, keyword)
  4907. } else {
  4908. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? "
  4909. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  4910. }
  4911. }
  4912. } else {
  4913. if len(execution_frequency) > 0 {
  4914. if len(keyword) > 0 {
  4915. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_frequency = ? and advice_name like ?"
  4916. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency, keyword)
  4917. } else {
  4918. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_frequency = ?"
  4919. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  4920. }
  4921. } else {
  4922. if len(keyword) > 0 {
  4923. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and advice_name like ?"
  4924. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, keyword)
  4925. } else {
  4926. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  4927. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  4928. }
  4929. }
  4930. }
  4931. }
  4932. }
  4933. } else if patientType == 2 {
  4934. if patient_id > 0 {
  4935. if execution_state > 0 {
  4936. if cost_type > 0 {
  4937. if len(execution_frequency) > 0 {
  4938. if len(keyword) > 0 {
  4939. 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 ?"
  4940. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4941. } else {
  4942. 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 = ?"
  4943. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4944. }
  4945. } else {
  4946. if len(keyword) > 0 {
  4947. 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 ?"
  4948. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  4949. } else {
  4950. 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 = ?"
  4951. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4952. }
  4953. }
  4954. } else {
  4955. if len(execution_frequency) > 0 {
  4956. if len(keyword) > 0 {
  4957. 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 ?"
  4958. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  4959. } else {
  4960. 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 = ?"
  4961. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4962. }
  4963. } else {
  4964. if len(keyword) > 0 {
  4965. 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 ?"
  4966. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  4967. } else {
  4968. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  4969. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4970. }
  4971. }
  4972. }
  4973. } else {
  4974. if cost_type > 0 {
  4975. if len(execution_frequency) > 0 {
  4976. if len(keyword) > 0 {
  4977. 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 ?"
  4978. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  4979. } else {
  4980. 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 = ?"
  4981. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4982. }
  4983. } else {
  4984. if len(keyword) > 0 {
  4985. 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 ?"
  4986. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  4987. } else {
  4988. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  4989. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4990. }
  4991. }
  4992. } else {
  4993. if len(execution_frequency) > 0 {
  4994. if len(keyword) > 0 {
  4995. 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 ?"
  4996. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  4997. } else {
  4998. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_frequency = ?"
  4999. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  5000. }
  5001. } else {
  5002. if len(keyword) > 0 {
  5003. 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 ?"
  5004. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  5005. } else {
  5006. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
  5007. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5008. }
  5009. }
  5010. }
  5011. }
  5012. } else {
  5013. if execution_state > 0 {
  5014. if cost_type > 0 {
  5015. if len(execution_frequency) > 0 {
  5016. if len(keyword) > 0 {
  5017. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5018. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  5019. } else {
  5020. 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 = ?"
  5021. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  5022. }
  5023. } else {
  5024. if len(keyword) > 0 {
  5025. 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 ?"
  5026. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  5027. } else {
  5028. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  5029. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5030. }
  5031. }
  5032. } else {
  5033. if len(execution_frequency) > 0 {
  5034. if len(keyword) > 0 {
  5035. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5036. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  5037. } else {
  5038. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and execution_frequency = ?"
  5039. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  5040. }
  5041. } else {
  5042. if len(keyword) > 0 {
  5043. 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 ?"
  5044. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  5045. } else {
  5046. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ?"
  5047. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5048. }
  5049. }
  5050. }
  5051. } else {
  5052. if cost_type > 0 {
  5053. if len(execution_frequency) > 0 {
  5054. if len(keyword) > 0 {
  5055. 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 ?"
  5056. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  5057. } else {
  5058. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  5059. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  5060. }
  5061. } else {
  5062. if len(keyword) > 0 {
  5063. 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 ?"
  5064. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  5065. } else {
  5066. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ?"
  5067. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5068. }
  5069. }
  5070. } else {
  5071. if len(execution_frequency) > 0 {
  5072. if len(keyword) > 0 {
  5073. 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 ?"
  5074. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  5075. } else {
  5076. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_frequency = ?"
  5077. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  5078. }
  5079. } else {
  5080. if len(keyword) > 0 {
  5081. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and advice_name like ?"
  5082. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  5083. } else {
  5084. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  5085. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5086. }
  5087. }
  5088. }
  5089. }
  5090. }
  5091. }
  5092. } else if adviceType == 3 {
  5093. if patientType == 0 {
  5094. if patient_id > 0 {
  5095. if execution_state > 0 {
  5096. if cost_type > 0 {
  5097. if len(execution_frequency) > 0 {
  5098. if len(keyword) > 0 {
  5099. 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 ?"
  5100. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5101. } else {
  5102. 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 =?"
  5103. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  5104. }
  5105. } else {
  5106. if len(keyword) > 0 {
  5107. 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 ?"
  5108. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  5109. } else {
  5110. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  5111. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5112. }
  5113. }
  5114. } else {
  5115. if len(execution_frequency) > 0 {
  5116. if len(keyword) > 0 {
  5117. 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 ?"
  5118. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  5119. } else {
  5120. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency =?"
  5121. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  5122. }
  5123. } else {
  5124. if len(keyword) > 0 {
  5125. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  5126. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  5127. } else {
  5128. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ?"
  5129. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5130. }
  5131. }
  5132. }
  5133. } else {
  5134. if cost_type > 0 {
  5135. if len(execution_frequency) > 0 {
  5136. if len(keyword) > 0 {
  5137. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency =? and advice_name like ?"
  5138. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  5139. } else {
  5140. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency =?"
  5141. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  5142. }
  5143. } else {
  5144. if len(keyword) > 0 {
  5145. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  5146. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  5147. } else {
  5148. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? "
  5149. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5150. }
  5151. }
  5152. } else {
  5153. if len(execution_frequency) > 0 {
  5154. if len(keyword) > 0 {
  5155. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_frequency =? and advice_name like ?"
  5156. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  5157. } else {
  5158. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_frequency =?"
  5159. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  5160. }
  5161. } else {
  5162. if len(keyword) > 0 {
  5163. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and advice_name like ?"
  5164. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  5165. } else {
  5166. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? "
  5167. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5168. }
  5169. }
  5170. }
  5171. }
  5172. } else {
  5173. if execution_state > 0 {
  5174. if cost_type > 0 {
  5175. if len(execution_frequency) > 0 {
  5176. if len(keyword) > 0 {
  5177. 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 ?"
  5178. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  5179. } else {
  5180. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ? and execution_frequency =?"
  5181. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  5182. }
  5183. } else {
  5184. if len(keyword) > 0 {
  5185. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ? and advice_name like ?"
  5186. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  5187. } else {
  5188. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ?"
  5189. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5190. }
  5191. }
  5192. } else {
  5193. if len(execution_frequency) > 0 {
  5194. if len(keyword) > 0 {
  5195. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and execution_frequency =? and advice_name like ?"
  5196. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  5197. } else {
  5198. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and execution_frequency =?"
  5199. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  5200. }
  5201. } else {
  5202. if len(keyword) > 0 {
  5203. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and advice_name like ?"
  5204. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  5205. } else {
  5206. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? "
  5207. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5208. }
  5209. }
  5210. }
  5211. } else {
  5212. if cost_type > 0 {
  5213. if len(execution_frequency) > 0 {
  5214. if len(keyword) > 0 {
  5215. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? and execution_frequency =? and advice_name like ?"
  5216. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  5217. } else {
  5218. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? and execution_frequency =?"
  5219. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  5220. }
  5221. } else {
  5222. if len(keyword) > 0 {
  5223. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? and advice_name like ?"
  5224. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  5225. } else {
  5226. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? "
  5227. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5228. }
  5229. }
  5230. } else {
  5231. if len(execution_frequency) > 0 {
  5232. if len(keyword) > 0 {
  5233. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_frequency =? and advice_name like ?"
  5234. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  5235. } else {
  5236. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_frequency =?"
  5237. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  5238. }
  5239. } else {
  5240. if len(keyword) > 0 {
  5241. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and advice_name like ?"
  5242. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  5243. } else {
  5244. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  5245. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5246. }
  5247. }
  5248. }
  5249. }
  5250. }
  5251. } else if patientType == 1 {
  5252. if patient_id > 0 {
  5253. if execution_state > 0 {
  5254. if cost_type > 0 {
  5255. if len(execution_frequency) > 0 {
  5256. if len(keyword) > 0 {
  5257. 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 ?"
  5258. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5259. } else {
  5260. 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 = ?"
  5261. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  5262. }
  5263. } else {
  5264. if len(keyword) > 0 {
  5265. 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 ?"
  5266. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, keyword)
  5267. } else {
  5268. 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 = ?"
  5269. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  5270. }
  5271. }
  5272. } else {
  5273. if len(execution_frequency) > 0 {
  5274. if len(keyword) > 0 {
  5275. 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 ?"
  5276. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  5277. } else {
  5278. 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 = ?"
  5279. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  5280. }
  5281. } else {
  5282. if len(keyword) > 0 {
  5283. 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 ?"
  5284. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, keyword)
  5285. } else {
  5286. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  5287. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  5288. }
  5289. }
  5290. }
  5291. } else {
  5292. if cost_type > 0 {
  5293. if len(execution_frequency) > 0 {
  5294. if len(keyword) > 0 {
  5295. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5296. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  5297. } else {
  5298. 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 = ?"
  5299. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  5300. }
  5301. } else {
  5302. if len(keyword) > 0 {
  5303. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  5304. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, keyword)
  5305. } else {
  5306. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  5307. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  5308. }
  5309. }
  5310. } else {
  5311. if len(execution_frequency) > 0 {
  5312. if len(keyword) > 0 {
  5313. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  5314. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency, keyword)
  5315. } else {
  5316. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  5317. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  5318. }
  5319. } else {
  5320. if len(keyword) > 0 {
  5321. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and advice_name like ?"
  5322. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, keyword)
  5323. } else {
  5324. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
  5325. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  5326. }
  5327. }
  5328. }
  5329. }
  5330. } else {
  5331. if execution_state > 0 {
  5332. if cost_type > 0 {
  5333. if len(execution_frequency) > 0 {
  5334. if len(keyword) > 0 {
  5335. 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 ?"
  5336. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  5337. } else {
  5338. 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 = ?"
  5339. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  5340. }
  5341. } else {
  5342. if len(keyword) > 0 {
  5343. 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 ?"
  5344. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, keyword)
  5345. } else {
  5346. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? and is_settle = ?"
  5347. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  5348. }
  5349. }
  5350. } else {
  5351. if len(execution_frequency) > 0 {
  5352. if len(keyword) > 0 {
  5353. 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 ? "
  5354. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency, keyword)
  5355. } else {
  5356. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =?and execution_frequency = ? "
  5357. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  5358. }
  5359. } else {
  5360. if len(keyword) > 0 {
  5361. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? and advice_name like ?"
  5362. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, keyword)
  5363. } else {
  5364. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? "
  5365. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  5366. }
  5367. }
  5368. }
  5369. } else {
  5370. if cost_type > 0 {
  5371. if len(execution_frequency) > 0 {
  5372. if len(keyword) > 0 {
  5373. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5374. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency, keyword)
  5375. } else {
  5376. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  5377. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  5378. }
  5379. } else {
  5380. if len(keyword) > 0 {
  5381. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ? and advice_name like ?"
  5382. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, keyword)
  5383. } else {
  5384. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ?"
  5385. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  5386. }
  5387. }
  5388. } else {
  5389. if len(execution_frequency) > 0 {
  5390. if len(keyword) > 0 {
  5391. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_frequency = ? and advice_name like ?"
  5392. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency, keyword)
  5393. } else {
  5394. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_frequency = ?"
  5395. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  5396. }
  5397. } else {
  5398. if len(keyword) > 0 {
  5399. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and advice_name like ?"
  5400. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, keyword)
  5401. } else {
  5402. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  5403. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  5404. }
  5405. }
  5406. }
  5407. }
  5408. }
  5409. } else if patientType == 2 {
  5410. if patient_id > 0 {
  5411. if execution_state > 0 {
  5412. if cost_type > 0 {
  5413. if len(execution_frequency) > 0 {
  5414. if len(keyword) > 0 {
  5415. 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 ?"
  5416. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5417. } else {
  5418. 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 = ?"
  5419. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  5420. }
  5421. } else {
  5422. if len(keyword) > 0 {
  5423. 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 ?"
  5424. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  5425. } else {
  5426. 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 = ?"
  5427. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5428. }
  5429. }
  5430. } else {
  5431. if len(execution_frequency) > 0 {
  5432. if len(keyword) > 0 {
  5433. 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 ?"
  5434. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  5435. } else {
  5436. 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 = ?"
  5437. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  5438. }
  5439. } else {
  5440. if len(keyword) > 0 {
  5441. 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 ?"
  5442. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  5443. } else {
  5444. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  5445. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5446. }
  5447. }
  5448. }
  5449. } else {
  5450. if cost_type > 0 {
  5451. if len(execution_frequency) > 0 {
  5452. if len(keyword) > 0 {
  5453. 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 ?"
  5454. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  5455. } else {
  5456. 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 = ?"
  5457. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  5458. }
  5459. } else {
  5460. if len(keyword) > 0 {
  5461. 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 ?"
  5462. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  5463. } else {
  5464. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  5465. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5466. }
  5467. }
  5468. } else {
  5469. if len(execution_frequency) > 0 {
  5470. if len(keyword) > 0 {
  5471. 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 ?"
  5472. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  5473. } else {
  5474. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_frequency = ?"
  5475. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  5476. }
  5477. } else {
  5478. if len(keyword) > 0 {
  5479. 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 ?"
  5480. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  5481. } else {
  5482. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ?"
  5483. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5484. }
  5485. }
  5486. }
  5487. }
  5488. } else {
  5489. if execution_state > 0 {
  5490. if cost_type > 0 {
  5491. if len(execution_frequency) > 0 {
  5492. if len(keyword) > 0 {
  5493. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5494. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  5495. } else {
  5496. 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 = ?"
  5497. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  5498. }
  5499. } else {
  5500. if len(keyword) > 0 {
  5501. 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 ?"
  5502. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  5503. } else {
  5504. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and is_settle = ?"
  5505. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5506. }
  5507. }
  5508. } else {
  5509. if len(execution_frequency) > 0 {
  5510. if len(keyword) > 0 {
  5511. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and execution_frequency = ? and advice_name like ?"
  5512. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  5513. } else {
  5514. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and execution_frequency = ?"
  5515. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  5516. }
  5517. } else {
  5518. if len(keyword) > 0 {
  5519. 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 ?"
  5520. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  5521. } else {
  5522. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ?"
  5523. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5524. }
  5525. }
  5526. }
  5527. } else {
  5528. if cost_type > 0 {
  5529. if len(execution_frequency) > 0 {
  5530. if len(keyword) > 0 {
  5531. 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 ?"
  5532. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  5533. } else {
  5534. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  5535. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  5536. }
  5537. } else {
  5538. if len(keyword) > 0 {
  5539. 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 ?"
  5540. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  5541. } else {
  5542. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ?"
  5543. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5544. }
  5545. }
  5546. } else {
  5547. if len(execution_frequency) > 0 {
  5548. if len(keyword) > 0 {
  5549. 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 ?"
  5550. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  5551. } else {
  5552. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_frequency = ?"
  5553. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  5554. }
  5555. } else {
  5556. if len(keyword) > 0 {
  5557. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and advice_name like ?"
  5558. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  5559. } else {
  5560. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  5561. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5562. }
  5563. }
  5564. }
  5565. }
  5566. }
  5567. }
  5568. } else if adviceType == 2 && len(deliverWay) > 0 {
  5569. if patientType == 0 {
  5570. if patient_id > 0 {
  5571. if execution_state > 0 {
  5572. if cost_type > 0 {
  5573. if len(execution_frequency) > 0 {
  5574. if len(keyword) > 0 {
  5575. 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 ?"
  5576. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5577. } else {
  5578. 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 = ?"
  5579. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency)
  5580. }
  5581. } else {
  5582. if len(keyword) > 0 {
  5583. 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 ?"
  5584. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, keyword)
  5585. } else {
  5586. 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 = ?"
  5587. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  5588. }
  5589. }
  5590. } else {
  5591. if len(execution_frequency) > 0 {
  5592. if len(keyword) > 0 {
  5593. 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 ?"
  5594. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency, keyword)
  5595. } else {
  5596. 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 = ?"
  5597. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency)
  5598. }
  5599. } else {
  5600. if len(keyword) > 0 {
  5601. 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 ?"
  5602. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, keyword)
  5603. } else {
  5604. 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 = ?"
  5605. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  5606. }
  5607. }
  5608. }
  5609. } else {
  5610. if cost_type > 0 {
  5611. if len(execution_frequency) > 0 {
  5612. if len(keyword) > 0 {
  5613. adviceWhere = "status = 1 AND user_org_id = ? AND (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 ?"
  5614. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency, keyword)
  5615. } else {
  5616. 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 = ?"
  5617. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency)
  5618. }
  5619. } else {
  5620. if len(keyword) > 0 {
  5621. 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 ?"
  5622. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, keyword)
  5623. } else {
  5624. 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 = ?"
  5625. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  5626. }
  5627. }
  5628. } else {
  5629. if len(execution_frequency) > 0 {
  5630. if len(keyword) > 0 {
  5631. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  5632. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency, keyword)
  5633. } else {
  5634. 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 = ?"
  5635. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency)
  5636. }
  5637. } else {
  5638. if len(keyword) > 0 {
  5639. 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 ?"
  5640. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, keyword)
  5641. } else {
  5642. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ?"
  5643. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  5644. }
  5645. }
  5646. }
  5647. }
  5648. } else {
  5649. if execution_state > 0 {
  5650. if cost_type > 0 {
  5651. if len(execution_frequency) > 0 {
  5652. if len(keyword) > 0 {
  5653. 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 ?"
  5654. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency, keyword)
  5655. } else {
  5656. 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 = ?"
  5657. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency)
  5658. }
  5659. } else {
  5660. if len(keyword) > 0 {
  5661. 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 ?"
  5662. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, keyword)
  5663. } else {
  5664. 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 = ?"
  5665. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  5666. }
  5667. }
  5668. } else {
  5669. if len(execution_frequency) > 0 {
  5670. if len(keyword) > 0 {
  5671. 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 ?"
  5672. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency, keyword)
  5673. } else {
  5674. 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 = ?"
  5675. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency)
  5676. }
  5677. } else {
  5678. if len(keyword) > 0 {
  5679. 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 ?"
  5680. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, keyword)
  5681. } else {
  5682. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and execution_state = ?"
  5683. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  5684. }
  5685. }
  5686. }
  5687. } else {
  5688. if cost_type > 0 {
  5689. if len(execution_frequency) > 0 {
  5690. if len(keyword) > 0 {
  5691. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5692. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, execution_frequency, keyword)
  5693. } else {
  5694. 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 = ?"
  5695. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, execution_frequency)
  5696. }
  5697. } else {
  5698. if len(keyword) > 0 {
  5699. 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 ?"
  5700. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, keyword)
  5701. } else {
  5702. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and is_settle = ?"
  5703. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  5704. }
  5705. }
  5706. } else {
  5707. if len(execution_frequency) > 0 {
  5708. if len(keyword) > 0 {
  5709. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and execution_frequency = ? and advice_name like ?"
  5710. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_frequency, keyword)
  5711. } else {
  5712. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and execution_frequency = ?"
  5713. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_frequency)
  5714. }
  5715. } else {
  5716. if len(keyword) > 0 {
  5717. 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 ?"
  5718. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, keyword)
  5719. } else {
  5720. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ?"
  5721. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  5722. }
  5723. }
  5724. }
  5725. }
  5726. }
  5727. } else if patientType == 1 {
  5728. if patient_id > 0 {
  5729. if execution_state > 0 {
  5730. if cost_type > 0 {
  5731. if len(execution_frequency) > 0 {
  5732. if len(keyword) > 0 {
  5733. 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 ?"
  5734. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5735. } else {
  5736. 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 = ?"
  5737. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type, execution_frequency)
  5738. }
  5739. } else {
  5740. if len(keyword) > 0 {
  5741. 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 ?"
  5742. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type, keyword)
  5743. } else {
  5744. 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 = ?"
  5745. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type)
  5746. }
  5747. }
  5748. } else {
  5749. if len(execution_frequency) > 0 {
  5750. if len(keyword) > 0 {
  5751. 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 ?"
  5752. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, execution_frequency, keyword)
  5753. } else {
  5754. 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 = ?"
  5755. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, execution_frequency)
  5756. }
  5757. } else {
  5758. if len(keyword) > 0 {
  5759. 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 ?"
  5760. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, keyword)
  5761. } else {
  5762. 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 = ?"
  5763. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state)
  5764. }
  5765. }
  5766. }
  5767. } else {
  5768. if cost_type > 0 {
  5769. if len(execution_frequency) > 0 {
  5770. if len(keyword) > 0 {
  5771. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5772. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type, execution_frequency, keyword)
  5773. } else {
  5774. 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 = ?"
  5775. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type, execution_frequency)
  5776. }
  5777. } else {
  5778. if len(keyword) > 0 {
  5779. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  5780. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type, keyword)
  5781. } else {
  5782. 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 = ?"
  5783. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type)
  5784. }
  5785. }
  5786. } else {
  5787. if len(execution_frequency) > 0 {
  5788. if len(keyword) > 0 {
  5789. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  5790. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_frequency, keyword)
  5791. } else {
  5792. 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 = ?"
  5793. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_frequency)
  5794. }
  5795. } else {
  5796. if len(keyword) > 0 {
  5797. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and avice_name like ?"
  5798. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, keyword)
  5799. } else {
  5800. 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 = ?"
  5801. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
  5802. }
  5803. }
  5804. }
  5805. }
  5806. } else {
  5807. if execution_state > 0 {
  5808. if cost_type > 0 {
  5809. if len(execution_frequency) > 0 {
  5810. if len(keyword) > 0 {
  5811. 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 ?"
  5812. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type, execution_frequency, keyword)
  5813. } else {
  5814. 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 = ?"
  5815. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type, execution_frequency)
  5816. }
  5817. } else {
  5818. if len(keyword) > 0 {
  5819. 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 ?"
  5820. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type, keyword)
  5821. } else {
  5822. 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 = ?"
  5823. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type)
  5824. }
  5825. }
  5826. } else {
  5827. if len(execution_frequency) > 0 {
  5828. if len(keyword) > 0 {
  5829. 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 ?"
  5830. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, execution_frequency, keyword)
  5831. } else {
  5832. 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 = ?"
  5833. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, execution_frequency)
  5834. }
  5835. } else {
  5836. if len(keyword) > 0 {
  5837. 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 ?"
  5838. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, keyword)
  5839. } else {
  5840. 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 = ?"
  5841. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state)
  5842. }
  5843. }
  5844. }
  5845. } else {
  5846. if cost_type > 0 {
  5847. if len(execution_frequency) > 0 {
  5848. if len(keyword) > 0 {
  5849. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND(advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5850. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type, execution_frequency, keyword)
  5851. } else {
  5852. 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 = ?"
  5853. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type, execution_frequency)
  5854. }
  5855. } else {
  5856. if len(keyword) > 0 {
  5857. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and is_settle = ? and advice_name like ?"
  5858. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type, keyword)
  5859. } else {
  5860. 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 = ?"
  5861. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type)
  5862. }
  5863. }
  5864. } else {
  5865. if len(execution_frequency) > 0 {
  5866. if len(keyword) > 0 {
  5867. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and execution_frequency = ? and advic_name like ?"
  5868. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_frequency, keyword)
  5869. } else {
  5870. 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 = ?"
  5871. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_frequency)
  5872. }
  5873. } else {
  5874. if len(keyword) > 0 {
  5875. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and advice_name like ?"
  5876. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, keyword)
  5877. } else {
  5878. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? "
  5879. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  5880. }
  5881. }
  5882. }
  5883. }
  5884. }
  5885. } else if patientType == 2 {
  5886. if patient_id > 0 {
  5887. if execution_state > 0 {
  5888. if cost_type > 0 {
  5889. if len(execution_frequency) > 0 {
  5890. if len(keyword) > 0 {
  5891. 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 ?"
  5892. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5893. } else {
  5894. 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 = ?"
  5895. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency)
  5896. }
  5897. } else {
  5898. if len(keyword) > 0 {
  5899. 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 ?"
  5900. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, keyword)
  5901. } else {
  5902. 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 = ?"
  5903. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  5904. }
  5905. }
  5906. } else {
  5907. if len(execution_frequency) > 0 {
  5908. if len(keyword) > 0 {
  5909. 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 ?"
  5910. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency, keyword)
  5911. } else {
  5912. 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 = ?"
  5913. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency)
  5914. }
  5915. } else {
  5916. if len(keyword) > 0 {
  5917. 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 ?"
  5918. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, keyword)
  5919. } else {
  5920. 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 = ?"
  5921. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  5922. }
  5923. }
  5924. }
  5925. } else {
  5926. if cost_type > 0 {
  5927. if len(execution_frequency) > 0 {
  5928. if len(keyword) > 0 {
  5929. 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 ?"
  5930. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency, keyword)
  5931. } else {
  5932. 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 = ?"
  5933. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency)
  5934. }
  5935. } else {
  5936. if len(keyword) > 0 {
  5937. 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 ?"
  5938. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, keyword)
  5939. } else {
  5940. 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 = ?"
  5941. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  5942. }
  5943. }
  5944. } else {
  5945. if len(execution_frequency) > 0 {
  5946. if len(keyword) > 0 {
  5947. 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 ?"
  5948. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency, keyword)
  5949. } else {
  5950. 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 = ?"
  5951. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency)
  5952. }
  5953. } else {
  5954. if len(keyword) > 0 {
  5955. 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 ?"
  5956. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, keyword)
  5957. } else {
  5958. 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 = ?"
  5959. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  5960. }
  5961. }
  5962. }
  5963. }
  5964. } else {
  5965. if execution_state > 0 {
  5966. if cost_type > 0 {
  5967. if len(execution_frequency) > 0 {
  5968. if len(keyword) > 0 {
  5969. 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 ?"
  5970. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency, keyword)
  5971. } else {
  5972. 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 = ?"
  5973. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency)
  5974. }
  5975. } else {
  5976. if len(keyword) > 0 {
  5977. 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 ?"
  5978. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, keyword)
  5979. } else {
  5980. 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 = ?"
  5981. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  5982. }
  5983. }
  5984. } else {
  5985. if len(execution_frequency) > 0 {
  5986. if len(keyword) > 0 {
  5987. 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 ?"
  5988. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency, keyword)
  5989. } else {
  5990. 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 = ?"
  5991. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency)
  5992. }
  5993. } else {
  5994. if len(keyword) > 0 {
  5995. 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 ?"
  5996. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, keyword)
  5997. } else {
  5998. 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 = ?"
  5999. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  6000. }
  6001. }
  6002. }
  6003. } else {
  6004. if cost_type > 0 {
  6005. if len(execution_frequency) > 0 {
  6006. if len(keyword) > 0 {
  6007. 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 ?"
  6008. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, keyword)
  6009. } else {
  6010. 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 = ?"
  6011. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  6012. }
  6013. } else {
  6014. if len(keyword) > 0 {
  6015. 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 ?"
  6016. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, keyword)
  6017. } else {
  6018. 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 = ?"
  6019. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  6020. }
  6021. }
  6022. } else {
  6023. if len(keyword) > 0 {
  6024. 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 ?"
  6025. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, keyword)
  6026. } else {
  6027. 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 = ?"
  6028. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  6029. }
  6030. }
  6031. }
  6032. }
  6033. }
  6034. } else if adviceType == 2 && len(deliverWay) <= 0 {
  6035. if patientType == 0 {
  6036. if patient_id > 0 {
  6037. if execution_state > 0 {
  6038. if cost_type > 0 {
  6039. if len(execution_frequency) > 0 {
  6040. if len(keyword) > 0 {
  6041. 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 ?"
  6042. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  6043. } else {
  6044. 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 = ?"
  6045. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  6046. }
  6047. } else {
  6048. if len(keyword) > 0 {
  6049. 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 ?"
  6050. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  6051. } else {
  6052. 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 = ?"
  6053. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6054. }
  6055. }
  6056. } else {
  6057. if len(execution_frequency) > 0 {
  6058. if len(keyword) > 0 {
  6059. 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 ?"
  6060. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  6061. } else {
  6062. 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 = ?"
  6063. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  6064. }
  6065. } else {
  6066. if len(keyword) > 0 {
  6067. 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 ?"
  6068. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  6069. } else {
  6070. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and execution_state = ?"
  6071. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6072. }
  6073. }
  6074. }
  6075. } else {
  6076. if cost_type > 0 {
  6077. if len(execution_frequency) > 0 {
  6078. if len(keyword) > 0 {
  6079. 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 ?"
  6080. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  6081. } else {
  6082. 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 = ?"
  6083. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  6084. }
  6085. } else {
  6086. if len(keyword) > 0 {
  6087. 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 ?"
  6088. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  6089. } else {
  6090. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and is_settle = ?"
  6091. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6092. }
  6093. }
  6094. } else {
  6095. if len(execution_frequency) > 0 {
  6096. if len(keyword) > 0 {
  6097. 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 ?"
  6098. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  6099. } else {
  6100. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and execution_frequency = ?"
  6101. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  6102. }
  6103. } else {
  6104. if len(keyword) > 0 {
  6105. 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 ?"
  6106. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  6107. } else {
  6108. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ?"
  6109. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6110. }
  6111. }
  6112. }
  6113. }
  6114. } else {
  6115. if execution_state > 0 {
  6116. if cost_type > 0 {
  6117. if len(execution_frequency) > 0 {
  6118. if len(keyword) > 0 {
  6119. 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 ?"
  6120. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  6121. } else {
  6122. 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 = ?"
  6123. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  6124. }
  6125. } else {
  6126. if len(keyword) > 0 {
  6127. 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 ?"
  6128. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  6129. } else {
  6130. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and execution_state = ? and is_settle = ?"
  6131. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6132. }
  6133. }
  6134. } else {
  6135. if len(execution_frequency) > 0 {
  6136. if len(keyword) > 0 {
  6137. 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 ?"
  6138. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  6139. } else {
  6140. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and execution_state = ?and execution_frequency = ?"
  6141. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  6142. }
  6143. } else {
  6144. if len(keyword) > 0 {
  6145. 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 ?"
  6146. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  6147. } else {
  6148. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and execution_state = ?"
  6149. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6150. }
  6151. }
  6152. }
  6153. } else {
  6154. if cost_type > 0 {
  6155. if len(execution_frequency) > 0 {
  6156. if len(keyword) > 0 {
  6157. 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 ?"
  6158. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  6159. } else {
  6160. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and is_settle = ? and execution_frequency = ?"
  6161. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  6162. }
  6163. }
  6164. } else {
  6165. if len(execution_frequency) > 0 {
  6166. if len(keyword) > 0 {
  6167. 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 ?"
  6168. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  6169. } else {
  6170. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and execution_frequency = ?"
  6171. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  6172. }
  6173. } else {
  6174. if len(keyword) > 0 {
  6175. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and advice_name like ?"
  6176. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  6177. } else {
  6178. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ?"
  6179. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6180. }
  6181. }
  6182. }
  6183. }
  6184. }
  6185. } else if patientType == 1 {
  6186. if patient_id > 0 {
  6187. if execution_state > 0 {
  6188. if cost_type > 0 {
  6189. if len(execution_frequency) > 0 {
  6190. if len(keyword) > 0 {
  6191. 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 ?"
  6192. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  6193. } else {
  6194. 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 = ?"
  6195. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  6196. }
  6197. } else {
  6198. if len(keyword) > 0 {
  6199. 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 ?"
  6200. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, keyword)
  6201. } else {
  6202. 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 = ?"
  6203. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  6204. }
  6205. }
  6206. } else {
  6207. if len(execution_frequency) > 0 {
  6208. if len(keyword) > 0 {
  6209. 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 ?"
  6210. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  6211. } else {
  6212. 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 = ?"
  6213. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  6214. }
  6215. } else {
  6216. if len(keyword) > 0 {
  6217. 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 ?"
  6218. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, keyword)
  6219. } else {
  6220. 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 = ?"
  6221. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  6222. }
  6223. }
  6224. }
  6225. } else {
  6226. if cost_type > 0 {
  6227. if len(execution_frequency) > 0 {
  6228. if len(keyword) > 0 {
  6229. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3)2 AND advice_doctor = ? and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6230. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  6231. } else {
  6232. 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 = ?"
  6233. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  6234. }
  6235. } else {
  6236. if len(keyword) > 0 {
  6237. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  6238. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, keyword)
  6239. } else {
  6240. 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 = ?"
  6241. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  6242. }
  6243. }
  6244. } else {
  6245. if len(execution_frequency) > 0 {
  6246. if len(keyword) > 0 {
  6247. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  6248. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency, keyword)
  6249. } else {
  6250. 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 = ?"
  6251. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  6252. }
  6253. } else {
  6254. if len(keyword) > 0 {
  6255. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and advice_name like ?"
  6256. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, keyword)
  6257. } else {
  6258. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ?"
  6259. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  6260. }
  6261. }
  6262. }
  6263. }
  6264. } else {
  6265. if execution_state > 0 {
  6266. if cost_type > 0 {
  6267. if len(execution_frequency) > 0 {
  6268. if len(keyword) > 0 {
  6269. 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 ?"
  6270. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  6271. } else {
  6272. 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 = ?"
  6273. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  6274. }
  6275. } else {
  6276. if len(keyword) > 0 {
  6277. 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 ?"
  6278. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, keyword)
  6279. } else {
  6280. 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 = ?"
  6281. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  6282. }
  6283. }
  6284. } else {
  6285. if len(execution_frequency) > 0 {
  6286. if len(keyword) > 0 {
  6287. 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 ?"
  6288. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency, keyword)
  6289. } else {
  6290. 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 = ?"
  6291. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  6292. }
  6293. } else {
  6294. if len(keyword) > 0 {
  6295. 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 ?"
  6296. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, keyword)
  6297. } else {
  6298. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and execution_state = ?"
  6299. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  6300. }
  6301. }
  6302. }
  6303. } else {
  6304. if cost_type > 0 {
  6305. if len(execution_frequency) > 0 {
  6306. if len(keyword) > 0 {
  6307. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6308. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency, keyword)
  6309. } else {
  6310. 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 = ?"
  6311. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  6312. }
  6313. } else {
  6314. if len(keyword) > 0 {
  6315. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and is_settle = ? and advice_name like ?"
  6316. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, keyword)
  6317. } else {
  6318. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and is_settle = ?"
  6319. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  6320. }
  6321. }
  6322. } else {
  6323. if len(execution_frequency) > 0 {
  6324. if len(keyword) > 0 {
  6325. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and execution_frequency = ? and advice_name like ?"
  6326. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency, keyword)
  6327. } else {
  6328. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and execution_frequency = ?"
  6329. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  6330. }
  6331. } else {
  6332. if len(keyword) > 0 {
  6333. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and advice_name like ?"
  6334. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, keyword)
  6335. } else {
  6336. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ?"
  6337. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  6338. }
  6339. }
  6340. }
  6341. }
  6342. }
  6343. } else if patientType == 2 {
  6344. if patient_id > 0 {
  6345. if execution_state > 0 {
  6346. if cost_type > 0 {
  6347. if len(execution_frequency) > 0 {
  6348. if len(keyword) > 0 {
  6349. 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 ?"
  6350. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  6351. } else {
  6352. 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=?"
  6353. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  6354. }
  6355. } else {
  6356. if len(keyword) > 0 {
  6357. 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 ?"
  6358. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  6359. } else {
  6360. 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 = ?"
  6361. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6362. }
  6363. }
  6364. } else {
  6365. if len(execution_frequency) > 0 {
  6366. if len(keyword) > 0 {
  6367. 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 ?"
  6368. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  6369. } else {
  6370. 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=?"
  6371. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  6372. }
  6373. } else {
  6374. if len(keyword) > 0 {
  6375. 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 ?"
  6376. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  6377. } else {
  6378. 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 = ?"
  6379. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6380. }
  6381. }
  6382. }
  6383. } else {
  6384. if cost_type > 0 {
  6385. if len(execution_frequency) > 0 {
  6386. if len(keyword) > 0 {
  6387. 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 ?"
  6388. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  6389. } else {
  6390. 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=?"
  6391. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  6392. }
  6393. } else {
  6394. if len(keyword) > 0 {
  6395. 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 ?"
  6396. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  6397. } else {
  6398. 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 = ?"
  6399. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6400. }
  6401. }
  6402. } else {
  6403. if len(execution_frequency) > 0 {
  6404. if len(keyword) > 0 {
  6405. 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 ?"
  6406. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  6407. } else {
  6408. 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=?"
  6409. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  6410. }
  6411. } else {
  6412. if len(keyword) > 0 {
  6413. 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 ?"
  6414. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  6415. } else {
  6416. 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 = ?"
  6417. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6418. }
  6419. }
  6420. }
  6421. }
  6422. } else {
  6423. if execution_state > 0 {
  6424. if cost_type > 0 {
  6425. if len(execution_frequency) > 0 {
  6426. if len(keyword) > 0 {
  6427. 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 ?"
  6428. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  6429. } else {
  6430. 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 = ?"
  6431. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  6432. }
  6433. } else {
  6434. if len(keyword) > 0 {
  6435. 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 ?"
  6436. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  6437. } else {
  6438. 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 = ?"
  6439. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6440. }
  6441. }
  6442. } else {
  6443. if len(execution_frequency) > 0 {
  6444. if len(keyword) > 0 {
  6445. 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 ?"
  6446. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  6447. } else {
  6448. 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 = ? "
  6449. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  6450. }
  6451. } else {
  6452. if len(keyword) > 0 {
  6453. 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 ?"
  6454. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  6455. } else {
  6456. 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 = ?"
  6457. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6458. }
  6459. }
  6460. }
  6461. } else {
  6462. if cost_type > 0 {
  6463. if len(execution_frequency) > 0 {
  6464. if len(keyword) > 0 {
  6465. 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 ?"
  6466. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  6467. } else {
  6468. 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 = ?"
  6469. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  6470. }
  6471. } else {
  6472. if len(keyword) > 0 {
  6473. 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 ?"
  6474. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  6475. } else {
  6476. 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 = ?"
  6477. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6478. }
  6479. }
  6480. } else {
  6481. if len(execution_frequency) > 0 {
  6482. if len(keyword) > 0 {
  6483. 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 ?"
  6484. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  6485. } else {
  6486. 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 = ?"
  6487. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  6488. }
  6489. } else {
  6490. if len(keyword) > 0 {
  6491. 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 ?"
  6492. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  6493. } else {
  6494. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0"
  6495. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6496. }
  6497. }
  6498. }
  6499. }
  6500. }
  6501. }
  6502. }
  6503. db := readDb.Table("xt_schedule")
  6504. if scheduleType > 0 {
  6505. db = db.Where("schedule_type = ?", scheduleType)
  6506. }
  6507. if partitonType > 0 {
  6508. db = db.Where("partition_id = ?", partitonType)
  6509. }
  6510. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6511. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6512. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6513. }).
  6514. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6515. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6516. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6517. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6518. Preload("DoctorAdvices", adviceCondition...).
  6519. Where("status = 1 AND user_org_id = ?", orgID)
  6520. if scheduleDate != 0 {
  6521. db = db.Where("schedule_date = ?", scheduleDate)
  6522. }
  6523. err := db.Find(&vms).Error
  6524. return vms, err
  6525. }
  6526. 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) {
  6527. var vms []*MScheduleDoctorAdviceVM
  6528. adviceWhere := ""
  6529. adviceCondition := []interface{}{}
  6530. if adviceType == 0 {
  6531. if patientType == 0 {
  6532. if patient_id > 0 {
  6533. if execution_state > 0 {
  6534. if cost_type > 0 {
  6535. 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 = ?"
  6536. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6537. } else {
  6538. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  6539. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6540. }
  6541. } else {
  6542. if cost_type > 0 {
  6543. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and is_settle = ?"
  6544. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6545. } else {
  6546. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
  6547. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6548. }
  6549. }
  6550. } else {
  6551. if execution_state > 0 {
  6552. if cost_type > 0 {
  6553. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and is_settle = ?"
  6554. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6555. } else {
  6556. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ?"
  6557. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6558. }
  6559. } else {
  6560. if cost_type > 0 {
  6561. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ?"
  6562. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6563. } else {
  6564. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  6565. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6566. }
  6567. }
  6568. }
  6569. } else if patientType == 1 {
  6570. if patient_id > 0 {
  6571. if execution_state > 0 {
  6572. if cost_type > 0 {
  6573. 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 = ?"
  6574. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  6575. } else {
  6576. 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= ?"
  6577. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  6578. }
  6579. } else {
  6580. if cost_type > 0 {
  6581. 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=?"
  6582. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  6583. } else {
  6584. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
  6585. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  6586. }
  6587. }
  6588. } else {
  6589. if execution_state > 0 {
  6590. if cost_type > 0 {
  6591. 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=?"
  6592. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  6593. } else {
  6594. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  6595. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  6596. }
  6597. } else {
  6598. if cost_type > 0 {
  6599. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and is_settle=?"
  6600. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  6601. } else {
  6602. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  6603. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  6604. }
  6605. }
  6606. }
  6607. } else if patientType == 2 {
  6608. if patient_id > 0 {
  6609. if execution_state > 0 {
  6610. if cost_type > 0 {
  6611. 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=?"
  6612. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6613. } else {
  6614. 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 = ?"
  6615. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6616. }
  6617. } else {
  6618. if cost_type > 0 {
  6619. 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=?"
  6620. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6621. } else {
  6622. 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 = ?)"
  6623. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6624. }
  6625. }
  6626. } else {
  6627. if execution_state > 0 {
  6628. if cost_type > 0 {
  6629. 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=?"
  6630. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6631. } else {
  6632. 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 = ?"
  6633. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6634. }
  6635. } else {
  6636. if cost_type > 0 {
  6637. 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 = ?"
  6638. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6639. } else {
  6640. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  6641. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6642. }
  6643. }
  6644. }
  6645. }
  6646. } else if adviceType == 1 {
  6647. if patientType == 0 {
  6648. if patient_id > 0 {
  6649. if execution_state > 0 {
  6650. if cost_type > 0 {
  6651. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  6652. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6653. } else {
  6654. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ?"
  6655. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6656. }
  6657. } else {
  6658. if cost_type > 0 {
  6659. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? "
  6660. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6661. } else {
  6662. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
  6663. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6664. }
  6665. }
  6666. } else {
  6667. if execution_state > 0 {
  6668. if cost_type > 0 {
  6669. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ?"
  6670. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6671. } else {
  6672. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ?"
  6673. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6674. }
  6675. } else {
  6676. if cost_type > 0 {
  6677. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = ? "
  6678. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6679. } else {
  6680. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  6681. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6682. }
  6683. }
  6684. }
  6685. } else if patientType == 1 {
  6686. if patient_id > 0 {
  6687. if execution_state > 0 {
  6688. if cost_type > 0 {
  6689. 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 = ?"
  6690. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  6691. } else {
  6692. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  6693. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  6694. }
  6695. } else {
  6696. if cost_type > 0 {
  6697. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  6698. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  6699. } else {
  6700. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
  6701. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  6702. }
  6703. }
  6704. } else {
  6705. if execution_state > 0 {
  6706. if cost_type > 0 {
  6707. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=? and is_settle = ?"
  6708. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  6709. } else {
  6710. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?"
  6711. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  6712. }
  6713. } else {
  6714. if cost_type > 0 {
  6715. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? "
  6716. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  6717. } else {
  6718. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  6719. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  6720. }
  6721. }
  6722. }
  6723. } else if patientType == 2 {
  6724. if patient_id > 0 {
  6725. if execution_state > 0 {
  6726. if cost_type > 0 {
  6727. 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 = ?"
  6728. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6729. } else {
  6730. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  6731. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6732. }
  6733. } else {
  6734. if cost_type > 0 {
  6735. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  6736. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6737. } else {
  6738. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
  6739. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6740. }
  6741. }
  6742. } else {
  6743. if execution_state > 0 {
  6744. if cost_type > 0 {
  6745. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  6746. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6747. } else {
  6748. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ?"
  6749. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6750. }
  6751. } else {
  6752. if cost_type > 0 {
  6753. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ?"
  6754. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6755. } else {
  6756. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  6757. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6758. }
  6759. }
  6760. }
  6761. }
  6762. } else if adviceType == 3 {
  6763. if patientType == 0 {
  6764. if patient_id > 0 {
  6765. if execution_state > 0 {
  6766. if cost_type > 0 {
  6767. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  6768. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6769. } else {
  6770. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ?"
  6771. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6772. }
  6773. } else {
  6774. if cost_type > 0 {
  6775. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? "
  6776. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6777. } else {
  6778. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? "
  6779. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6780. }
  6781. }
  6782. } else {
  6783. if execution_state > 0 {
  6784. if cost_type > 0 {
  6785. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ?"
  6786. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6787. } else {
  6788. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? "
  6789. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6790. }
  6791. } else {
  6792. if cost_type > 0 {
  6793. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? "
  6794. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6795. } else {
  6796. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  6797. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6798. }
  6799. }
  6800. }
  6801. } else if patientType == 1 {
  6802. if patient_id > 0 {
  6803. if execution_state > 0 {
  6804. if cost_type > 0 {
  6805. 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 = ?"
  6806. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  6807. } else {
  6808. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  6809. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  6810. }
  6811. } else {
  6812. if cost_type > 0 {
  6813. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  6814. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  6815. } else {
  6816. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
  6817. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  6818. }
  6819. }
  6820. } else {
  6821. if execution_state > 0 {
  6822. if cost_type > 0 {
  6823. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? and is_settle = ?"
  6824. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  6825. } else {
  6826. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? "
  6827. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  6828. }
  6829. } else {
  6830. if cost_type > 0 {
  6831. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ?"
  6832. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  6833. } else {
  6834. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  6835. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  6836. }
  6837. }
  6838. }
  6839. } else if patientType == 2 {
  6840. if patient_id > 0 {
  6841. if execution_state > 0 {
  6842. if cost_type > 0 {
  6843. 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 = ?"
  6844. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6845. } else {
  6846. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  6847. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6848. }
  6849. } else {
  6850. if cost_type > 0 {
  6851. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  6852. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6853. } else {
  6854. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ?"
  6855. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6856. }
  6857. }
  6858. } else {
  6859. if execution_state > 0 {
  6860. if cost_type > 0 {
  6861. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and is_settle = ?"
  6862. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6863. } else {
  6864. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ?"
  6865. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6866. }
  6867. } else {
  6868. if cost_type > 0 {
  6869. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ?"
  6870. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6871. } else {
  6872. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  6873. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6874. }
  6875. }
  6876. }
  6877. }
  6878. } else if adviceType == 2 && len(deliverWay) > 0 {
  6879. if patientType == 0 {
  6880. if patient_id > 0 {
  6881. if execution_state > 0 {
  6882. if cost_type > 0 {
  6883. 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 = ?"
  6884. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  6885. } else {
  6886. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  6887. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  6888. }
  6889. } else {
  6890. if cost_type > 0 {
  6891. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and is_settle = ?"
  6892. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  6893. } else {
  6894. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ?"
  6895. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  6896. }
  6897. }
  6898. } else {
  6899. if execution_state > 0 {
  6900. if cost_type > 0 {
  6901. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and is_settle = ?"
  6902. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  6903. } else {
  6904. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ?"
  6905. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  6906. }
  6907. } else {
  6908. if cost_type > 0 {
  6909. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and is_settle = ?"
  6910. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  6911. } else {
  6912. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  6913. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  6914. }
  6915. }
  6916. }
  6917. } else if patientType == 1 {
  6918. if patient_id > 0 {
  6919. if execution_state > 0 {
  6920. if cost_type > 0 {
  6921. 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 = ?"
  6922. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type)
  6923. } else {
  6924. 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 = ?"
  6925. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state)
  6926. }
  6927. } else {
  6928. if cost_type > 0 {
  6929. 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 = ?"
  6930. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type)
  6931. } else {
  6932. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ?"
  6933. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
  6934. }
  6935. }
  6936. } else {
  6937. if execution_state > 0 {
  6938. if cost_type > 0 {
  6939. 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 = ?"
  6940. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type)
  6941. } else {
  6942. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ?"
  6943. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state)
  6944. }
  6945. } else {
  6946. if cost_type > 0 {
  6947. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and is_settle = ?"
  6948. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type)
  6949. } else {
  6950. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  6951. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  6952. }
  6953. }
  6954. }
  6955. } else if patientType == 2 {
  6956. if patient_id > 0 {
  6957. if execution_state > 0 {
  6958. if cost_type > 0 {
  6959. 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 = ?"
  6960. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  6961. } else {
  6962. 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 = ?"
  6963. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  6964. }
  6965. } else {
  6966. if cost_type > 0 {
  6967. 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 = ?"
  6968. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  6969. } else {
  6970. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ?"
  6971. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  6972. }
  6973. }
  6974. } else {
  6975. if execution_state > 0 {
  6976. if cost_type > 0 {
  6977. 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 = ?"
  6978. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  6979. } else {
  6980. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ?"
  6981. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  6982. }
  6983. } else {
  6984. if cost_type > 0 {
  6985. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and is_settle = ?"
  6986. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  6987. } else {
  6988. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  6989. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  6990. }
  6991. }
  6992. }
  6993. }
  6994. } else if adviceType == 2 && len(deliverWay) <= 0 {
  6995. if patientType == 0 {
  6996. if patient_id > 0 {
  6997. if execution_state > 0 {
  6998. if cost_type > 0 {
  6999. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  7000. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  7001. } else {
  7002. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ?"
  7003. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  7004. }
  7005. } else {
  7006. if cost_type > 0 {
  7007. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and is_settle = ?"
  7008. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  7009. } else {
  7010. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ?"
  7011. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  7012. }
  7013. }
  7014. } else {
  7015. if execution_state > 0 {
  7016. if cost_type > 0 {
  7017. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ? and is_settle = ?"
  7018. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  7019. } else {
  7020. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?"
  7021. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  7022. }
  7023. } else {
  7024. if cost_type > 0 {
  7025. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and is_settle = ?"
  7026. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  7027. } else {
  7028. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  7029. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  7030. }
  7031. }
  7032. }
  7033. } else if patientType == 1 {
  7034. if patient_id > 0 {
  7035. if execution_state > 0 {
  7036. if cost_type > 0 {
  7037. 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 = ?"
  7038. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  7039. } else {
  7040. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  7041. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  7042. }
  7043. } else {
  7044. if cost_type > 0 {
  7045. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  7046. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  7047. } else {
  7048. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ?"
  7049. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  7050. }
  7051. }
  7052. } else {
  7053. if execution_state > 0 {
  7054. if cost_type > 0 {
  7055. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ? and is_settle = ?"
  7056. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  7057. } else {
  7058. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ?"
  7059. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  7060. }
  7061. } else {
  7062. if cost_type > 0 {
  7063. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and is_settle = ?"
  7064. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  7065. } else {
  7066. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?"
  7067. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  7068. }
  7069. }
  7070. }
  7071. } else if patientType == 2 {
  7072. if patient_id > 0 {
  7073. if execution_state > 0 {
  7074. if cost_type > 0 {
  7075. 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 = ?"
  7076. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  7077. } else {
  7078. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  7079. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  7080. }
  7081. } else {
  7082. if cost_type > 0 {
  7083. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  7084. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  7085. } else {
  7086. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ?"
  7087. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  7088. }
  7089. }
  7090. } else {
  7091. if execution_state > 0 {
  7092. if cost_type > 0 {
  7093. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  7094. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  7095. } else {
  7096. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ?"
  7097. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  7098. }
  7099. } else {
  7100. if cost_type > 0 {
  7101. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and is_settle = ?"
  7102. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  7103. } else {
  7104. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  7105. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  7106. }
  7107. }
  7108. }
  7109. }
  7110. }
  7111. db := readDb.Table("xt_schedule")
  7112. if scheduleType > 0 {
  7113. db = db.Where("schedule_type = ?", scheduleType)
  7114. }
  7115. if partitonType > 0 {
  7116. db = db.Where("partition_id = ?", partitonType)
  7117. }
  7118. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7119. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7120. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7121. }).
  7122. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7123. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7124. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7125. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7126. Preload("DoctorAdvices", adviceCondition...).
  7127. Where("status = 1 AND user_org_id = ?", orgID)
  7128. if scheduleDate != 0 {
  7129. db = db.Where("schedule_date = ?", scheduleDate)
  7130. }
  7131. err := db.Find(&vms).Error
  7132. return vms, err
  7133. }
  7134. func GetLastPatientOrder(id int64) (models.XtDialysisOrder, error) {
  7135. order := models.XtDialysisOrder{}
  7136. err := XTReadDB().Where("id = ? and status = 1", id).Find(&order).Error
  7137. return order, err
  7138. }
  7139. func UpdateMobilePatient(org_id int64, patient_id int64, schedule_remark string) error {
  7140. order := models.XtPatients{}
  7141. 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
  7142. 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
  7143. return err
  7144. }
  7145. func GetDialysisTotalCount(org_id int64, patient_id int64) (models.BloodDialysisOrderCount, error) {
  7146. order := models.BloodDialysisOrderCount{}
  7147. db := XTReadDB().Table("xt_dialysis_order as o")
  7148. 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
  7149. return order, err
  7150. }
  7151. func GetDialysisTotalCountOne(org_id int64, patient_id int64) (models.BloodDialysisOrderCount, error) {
  7152. order := models.BloodDialysisOrderCount{}
  7153. db := XTReadDB().Table("xt_dialysis_order as o")
  7154. 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
  7155. return order, err
  7156. }
  7157. func UpdateDialysisOrder(patient_id int64, dialysis_date int64, user_org_id int64, dialysis_total int64) (models.DialysisOrder, error) {
  7158. order := models.DialysisOrder{}
  7159. 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
  7160. return order, err
  7161. }
  7162. func UpdateDeviceInformation(patientid int64, dialysis_date int64) error {
  7163. information := models.DeviceInformation{}
  7164. err := UserWriteDB().Model(&information).Where("patient_id = ? and date = ? and status = 1", patientid, dialysis_date).Update(map[string]interface{}{"status": 0}).Error
  7165. return err
  7166. }
  7167. func MobileGetDoubleCheckSix(orgID int64, patientID int64, recordDate int64) (models.DoubleCheck, error) {
  7168. var record models.DoubleCheck
  7169. err := readDb.Where("patient_id = ? and user_org_id = ? and status = 1 and check_date = ?", patientID, orgID, recordDate).First(&record).Error
  7170. return record, err
  7171. }
  7172. func GetFirstMonitor(patient_id int64, monit_date int64) (models.MonitoringRecord, error) {
  7173. record := models.MonitoringRecord{}
  7174. err := XTReadDB().Where("patient_id = ? and monitoring_date = ? and status=1", patient_id, monit_date).First(&record).Error
  7175. return record, err
  7176. }
  7177. func GetFirstMonitorOne(patient_id int64, monit_date int64, org_id int64) (models.MonitoringRecord, error) {
  7178. record := models.MonitoringRecord{}
  7179. err := XTReadDB().Where("patient_id = ? and monitoring_date = ? and status=1 and user_org_id=?", patient_id, monit_date, org_id).First(&record).Error
  7180. return record, err
  7181. }
  7182. func GetLastMonitor(patient_id int64, monit_date int64, org_id int64) (models.MonitoringRecord, error) {
  7183. record := models.MonitoringRecord{}
  7184. err := XTReadDB().Where("patient_id = ? and monitoring_date = ? and status=1 and user_org_id = ?", patient_id, monit_date, org_id).Last(&record).Error
  7185. return record, err
  7186. }
  7187. func UpdateFirstMonitor(id int64, catheter_operation string) (models.MonitoringRecord, error) {
  7188. record := models.MonitoringRecord{}
  7189. err := XTWriteDB().Model(&record).Where("id = ? and status= 1", id).Updates(map[string]interface{}{"dispose": catheter_operation}).Error
  7190. return record, err
  7191. }
  7192. 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) {
  7193. var vms []*HisMScheduleDoctorAdviceVM
  7194. if len(deliverWay) > 0 {
  7195. db := readDb.Table("xt_schedule")
  7196. if scheduleType > 0 {
  7197. db = db.Where("schedule_type = ?", scheduleType)
  7198. }
  7199. if partitionType > 0 {
  7200. db = db.Where("partition_id = ?", partitionType)
  7201. }
  7202. if patient_id > 0 {
  7203. if execution_state > 0 {
  7204. if cost_type > 0 {
  7205. if len(execution_frequency) > 0 {
  7206. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7207. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7208. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7209. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7210. 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).
  7211. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7212. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7213. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7214. Where("status = 1 AND user_org_id = ?", orgID)
  7215. if scheduleDate != 0 {
  7216. db = db.Where("schedule_date = ?", scheduleDate)
  7217. }
  7218. err = db.Find(&vms).Error
  7219. } else {
  7220. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7221. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7222. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7223. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7224. 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).
  7225. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7226. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7227. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7228. Where("status = 1 AND user_org_id = ?", orgID)
  7229. if scheduleDate != 0 {
  7230. db = db.Where("schedule_date = ?", scheduleDate)
  7231. }
  7232. err = db.Find(&vms).Error
  7233. }
  7234. } else {
  7235. if len(execution_frequency) > 0 {
  7236. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7237. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7238. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7239. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7240. 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).
  7241. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7242. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7243. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7244. Where("status = 1 AND user_org_id = ?", orgID)
  7245. if scheduleDate != 0 {
  7246. db = db.Where("schedule_date = ?", scheduleDate)
  7247. }
  7248. err = db.Find(&vms).Error
  7249. } else {
  7250. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7251. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7252. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7253. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7254. 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).
  7255. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7256. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7257. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7258. Where("status = 1 AND user_org_id = ?", orgID)
  7259. if scheduleDate != 0 {
  7260. db = db.Where("schedule_date = ?", scheduleDate)
  7261. }
  7262. err = db.Find(&vms).Error
  7263. }
  7264. }
  7265. } else {
  7266. if cost_type > 0 {
  7267. if len(execution_frequency) > 0 {
  7268. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7269. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7270. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7271. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7272. 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).
  7273. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7274. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7275. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7276. Where("status = 1 AND user_org_id = ?", orgID)
  7277. if scheduleDate != 0 {
  7278. db = db.Where("schedule_date = ?", scheduleDate)
  7279. }
  7280. err = db.Find(&vms).Error
  7281. } else {
  7282. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7283. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7284. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7285. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7286. 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).
  7287. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7288. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7289. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7290. Where("status = 1 AND user_org_id = ?", orgID)
  7291. if scheduleDate != 0 {
  7292. db = db.Where("schedule_date = ?", scheduleDate)
  7293. }
  7294. err = db.Find(&vms).Error
  7295. }
  7296. } else {
  7297. if len(execution_frequency) > 0 {
  7298. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7299. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7300. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7301. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7302. 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).
  7303. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7304. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7305. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7306. Where("status = 1 AND user_org_id = ?", orgID)
  7307. if scheduleDate != 0 {
  7308. db = db.Where("schedule_date = ?", scheduleDate)
  7309. }
  7310. err = db.Find(&vms).Error
  7311. } else {
  7312. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7313. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7314. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7315. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7316. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ?", orgID, scheduleDate, deliverWay, patient_id).
  7317. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7318. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7319. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7320. Where("status = 1 AND user_org_id = ?", orgID)
  7321. if scheduleDate != 0 {
  7322. db = db.Where("schedule_date = ?", scheduleDate)
  7323. }
  7324. err = db.Find(&vms).Error
  7325. }
  7326. }
  7327. }
  7328. } else {
  7329. if execution_state > 0 {
  7330. if cost_type > 0 {
  7331. if len(execution_frequency) > 0 {
  7332. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7333. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7334. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7335. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7336. 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).
  7337. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7338. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7339. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7340. Where("status = 1 AND user_org_id = ?", orgID)
  7341. if scheduleDate != 0 {
  7342. db = db.Where("schedule_date = ?", scheduleDate)
  7343. }
  7344. err = db.Find(&vms).Error
  7345. } else {
  7346. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7347. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7348. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7349. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7350. 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).
  7351. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7352. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7353. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7354. Where("status = 1 AND user_org_id = ?", orgID)
  7355. if scheduleDate != 0 {
  7356. db = db.Where("schedule_date = ?", scheduleDate)
  7357. }
  7358. err = db.Find(&vms).Error
  7359. }
  7360. } else {
  7361. if len(execution_frequency) > 0 {
  7362. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7363. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7364. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7365. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7366. 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).
  7367. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7368. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7369. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7370. Where("status = 1 AND user_org_id = ?", orgID)
  7371. if scheduleDate != 0 {
  7372. db = db.Where("schedule_date = ?", scheduleDate)
  7373. }
  7374. err = db.Find(&vms).Error
  7375. } else {
  7376. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7377. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7378. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7379. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7380. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_state = ?", orgID, scheduleDate, deliverWay, execution_state).
  7381. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7382. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7383. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7384. Where("status = 1 AND user_org_id = ?", orgID)
  7385. if scheduleDate != 0 {
  7386. db = db.Where("schedule_date = ?", scheduleDate)
  7387. }
  7388. err = db.Find(&vms).Error
  7389. }
  7390. }
  7391. } else {
  7392. if cost_type > 0 {
  7393. if len(execution_frequency) > 0 {
  7394. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7395. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7396. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7397. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7398. 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).
  7399. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7400. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7401. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7402. Where("status = 1 AND user_org_id = ?", orgID)
  7403. if scheduleDate != 0 {
  7404. db = db.Where("schedule_date = ?", scheduleDate)
  7405. }
  7406. err = db.Find(&vms).Error
  7407. } else {
  7408. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7409. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7410. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7411. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7412. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and is_settle = ?", orgID, scheduleDate, deliverWay, cost_type).
  7413. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7414. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7415. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7416. Where("status = 1 AND user_org_id = ?", orgID)
  7417. if scheduleDate != 0 {
  7418. db = db.Where("schedule_date = ?", scheduleDate)
  7419. }
  7420. err = db.Find(&vms).Error
  7421. }
  7422. } else {
  7423. if len(execution_frequency) > 0 {
  7424. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7425. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7426. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7427. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7428. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_frequency = ?", orgID, scheduleDate, deliverWay, execution_frequency).
  7429. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7430. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7431. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7432. Where("status = 1 AND user_org_id = ?", orgID)
  7433. if scheduleDate != 0 {
  7434. db = db.Where("schedule_date = ?", scheduleDate)
  7435. }
  7436. err = db.Find(&vms).Error
  7437. } else {
  7438. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7439. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7440. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7441. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7442. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  7443. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7444. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7445. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7446. Where("status = 1 AND user_org_id = ?", orgID)
  7447. if scheduleDate != 0 {
  7448. db = db.Where("schedule_date = ?", scheduleDate)
  7449. }
  7450. err = db.Find(&vms).Error
  7451. }
  7452. }
  7453. }
  7454. }
  7455. } else {
  7456. db := readDb.Table("xt_schedule")
  7457. if scheduleType > 0 {
  7458. db = db.Where("schedule_type = ?", scheduleType)
  7459. }
  7460. if partitionType > 0 {
  7461. db = db.Where("partition_id = ?", partitionType)
  7462. }
  7463. if patient_id > 0 {
  7464. if execution_state > 0 {
  7465. fmt.Println("execution_state---------------------", execution_state)
  7466. if cost_type > 0 {
  7467. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7468. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7469. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7470. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7471. 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).
  7472. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7473. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7474. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7475. Where("status = 1 AND user_org_id = ?", orgID)
  7476. if scheduleDate != 0 {
  7477. db = db.Where("schedule_date = ?", scheduleDate)
  7478. }
  7479. err = db.Find(&vms).Error
  7480. } else {
  7481. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7482. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7483. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7484. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7485. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and execution_state = ?", orgID, scheduleDate, patient_id, execution_state).
  7486. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7487. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7488. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7489. Where("status = 1 AND user_org_id = ?", orgID)
  7490. if scheduleDate != 0 {
  7491. db = db.Where("schedule_date = ?", scheduleDate)
  7492. }
  7493. err = db.Find(&vms).Error
  7494. }
  7495. } else {
  7496. if cost_type > 0 {
  7497. if len(execution_frequency) > 0 {
  7498. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7499. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7500. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7501. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7502. 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).
  7503. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7504. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7505. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7506. Where("status = 1 AND user_org_id = ?", orgID)
  7507. if scheduleDate != 0 {
  7508. db = db.Where("schedule_date = ?", scheduleDate)
  7509. }
  7510. err = db.Find(&vms).Error
  7511. } else {
  7512. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7513. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7514. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7515. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7516. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and is_settle = ?", orgID, scheduleDate, patient_id, cost_type).
  7517. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7518. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7519. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7520. Where("status = 1 AND user_org_id = ?", orgID)
  7521. if scheduleDate != 0 {
  7522. db = db.Where("schedule_date = ?", scheduleDate)
  7523. }
  7524. err = db.Find(&vms).Error
  7525. }
  7526. } else {
  7527. if len(execution_frequency) > 0 {
  7528. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7529. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7530. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7531. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7532. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and execution_frequency = ?", orgID, scheduleDate, patient_id, execution_frequency).
  7533. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7534. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7535. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7536. Where("status = 1 AND user_org_id = ?", orgID)
  7537. if scheduleDate != 0 {
  7538. db = db.Where("schedule_date = ?", scheduleDate)
  7539. }
  7540. err = db.Find(&vms).Error
  7541. } else {
  7542. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7543. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7544. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7545. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7546. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7547. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7548. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7549. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7550. Where("status = 1 AND user_org_id = ?", orgID)
  7551. if scheduleDate != 0 {
  7552. db = db.Where("schedule_date = ?", scheduleDate)
  7553. }
  7554. err = db.Find(&vms).Error
  7555. }
  7556. }
  7557. }
  7558. } else {
  7559. if execution_state > 0 {
  7560. if cost_type > 0 {
  7561. if len(execution_frequency) > 0 {
  7562. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7563. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7564. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7565. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7566. 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).
  7567. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7568. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7569. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7570. Where("status = 1 AND user_org_id = ?", orgID)
  7571. if scheduleDate != 0 {
  7572. db = db.Where("schedule_date = ?", scheduleDate)
  7573. }
  7574. err = db.Find(&vms).Error
  7575. } else {
  7576. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7577. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7578. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7579. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7580. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ? and is_settle = ?", orgID, scheduleDate, execution_state, cost_type).
  7581. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7582. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7583. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7584. Where("status = 1 AND user_org_id = ?", orgID)
  7585. if scheduleDate != 0 {
  7586. db = db.Where("schedule_date = ?", scheduleDate)
  7587. }
  7588. err = db.Find(&vms).Error
  7589. }
  7590. } else {
  7591. if len(execution_frequency) > 0 {
  7592. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7593. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7594. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7595. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7596. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ? and execution_frequency = ?", orgID, scheduleDate, execution_state, execution_frequency).
  7597. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7598. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7599. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7600. Where("status = 1 AND user_org_id = ?", orgID)
  7601. if scheduleDate != 0 {
  7602. db = db.Where("schedule_date = ?", scheduleDate)
  7603. }
  7604. err = db.Find(&vms).Error
  7605. } else {
  7606. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7607. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7608. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7609. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7610. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ?", orgID, scheduleDate, execution_state).
  7611. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7612. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7613. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7614. Where("status = 1 AND user_org_id = ?", orgID)
  7615. if scheduleDate != 0 {
  7616. db = db.Where("schedule_date = ?", scheduleDate)
  7617. }
  7618. err = db.Find(&vms).Error
  7619. }
  7620. }
  7621. } else {
  7622. if cost_type > 0 {
  7623. if len(execution_frequency) > 0 {
  7624. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7625. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7626. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7627. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7628. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and is_settle = ?", orgID, scheduleDate, cost_type).
  7629. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7630. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7631. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7632. Where("status = 1 AND user_org_id = ?", orgID)
  7633. if scheduleDate != 0 {
  7634. db = db.Where("schedule_date = ?", scheduleDate)
  7635. }
  7636. err = db.Find(&vms).Error
  7637. } else {
  7638. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7639. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7640. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7641. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7642. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and is_settle = ? and execution_frequency = ?", orgID, scheduleDate, cost_type, execution_frequency).
  7643. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7644. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7645. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7646. Where("status = 1 AND user_org_id = ?", orgID)
  7647. if scheduleDate != 0 {
  7648. db = db.Where("schedule_date = ?", scheduleDate)
  7649. }
  7650. err = db.Find(&vms).Error
  7651. }
  7652. } else {
  7653. if len(execution_frequency) > 0 {
  7654. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7655. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7656. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7657. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7658. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_frequency = ?", orgID, scheduleDate, execution_frequency).
  7659. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7660. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7661. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7662. Where("status = 1 AND user_org_id = ?", orgID)
  7663. if scheduleDate != 0 {
  7664. db = db.Where("schedule_date = ?", scheduleDate)
  7665. }
  7666. err = db.Find(&vms).Error
  7667. } else {
  7668. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7669. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7670. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7671. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7672. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ?", orgID, scheduleDate).
  7673. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7674. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7675. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7676. Where("status = 1 AND user_org_id = ?", orgID)
  7677. if scheduleDate != 0 {
  7678. db = db.Where("schedule_date = ?", scheduleDate)
  7679. }
  7680. err = db.Find(&vms).Error
  7681. }
  7682. }
  7683. }
  7684. }
  7685. }
  7686. return vms, err
  7687. }
  7688. func GetPatientDryWeight(org_id int64, patient_id int64) (weight []*models.SgjPatientDryweight, err error) {
  7689. err = XTReadDB().Where("user_org_id = ? and patient_id = ? and status =1", org_id, patient_id).Order("id desc").Limit(6).Find(&weight).Error
  7690. return weight, err
  7691. }
  7692. 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) {
  7693. fmt.Println("deliverWay-----------------", deliverWay)
  7694. fmt.Println("execution_frequency------------------", execution_frequency)
  7695. fmt.Println("adviceType-----------------", adviceType)
  7696. fmt.Println("patientType----------------", patientType)
  7697. fmt.Println("patient_id----------------", patient_id)
  7698. fmt.Println("execution_state----------------", execution_state)
  7699. fmt.Println("cost_type---------------------", cost_type)
  7700. fmt.Println("execution_frequency", execution_frequency)
  7701. var vms []*MScheduleDoctorAdviceVM
  7702. adviceWhere := ""
  7703. keyword = "%" + keyword + "%"
  7704. adviceCondition := []interface{}{}
  7705. if adviceType == 1 {
  7706. if patientType == 0 {
  7707. if patient_id > 0 {
  7708. if execution_state > 0 {
  7709. if cost_type > 0 {
  7710. if len(execution_frequency) > 0 {
  7711. if len(keyword) > 0 {
  7712. if len(deliverWay) > 0 {
  7713. 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 ?"
  7714. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency, deliverWay, keyword)
  7715. } else {
  7716. 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 ?"
  7717. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency, keyword)
  7718. }
  7719. } else {
  7720. if len(deliverWay) > 0 {
  7721. 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 =?"
  7722. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency, deliverWay)
  7723. } else {
  7724. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  7725. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency)
  7726. }
  7727. }
  7728. } else {
  7729. if len(keyword) > 0 {
  7730. if len(deliverWay) > 0 {
  7731. 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 =?"
  7732. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, keyword, deliverWay)
  7733. } else {
  7734. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  7735. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, keyword)
  7736. }
  7737. } else {
  7738. if len(deliverWay) > 0 {
  7739. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ? and delivery_way =?"
  7740. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, deliverWay)
  7741. } else {
  7742. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ?"
  7743. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type)
  7744. }
  7745. }
  7746. }
  7747. } else {
  7748. if len(execution_frequency) > 0 {
  7749. if len(keyword) > 0 {
  7750. if len(deliverWay) > 0 {
  7751. 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 =?"
  7752. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency, keyword, deliverWay)
  7753. } else {
  7754. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  7755. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency, keyword)
  7756. }
  7757. } else {
  7758. if len(deliverWay) > 0 {
  7759. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and execution_frequency = ? and delivery_way =?"
  7760. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency, deliverWay)
  7761. } else {
  7762. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and execution_frequency = ?"
  7763. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency)
  7764. }
  7765. }
  7766. } else {
  7767. if len(keyword) > 0 {
  7768. if len(deliverWay) > 0 {
  7769. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and advice_name like ? and delivery_way =?"
  7770. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, keyword, deliverWay)
  7771. } else {
  7772. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and advice_name like ?"
  7773. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, keyword)
  7774. }
  7775. } else {
  7776. if len(deliverWay) > 0 {
  7777. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and delivery_way =?"
  7778. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, deliverWay)
  7779. } else {
  7780. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ?"
  7781. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state)
  7782. }
  7783. }
  7784. }
  7785. }
  7786. } else {
  7787. if cost_type > 0 {
  7788. if len(execution_frequency) > 0 {
  7789. if len(keyword) > 0 {
  7790. if len(deliverWay) > 0 {
  7791. 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 =?"
  7792. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency, keyword, deliverWay)
  7793. } else {
  7794. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  7795. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency, keyword)
  7796. }
  7797. } else {
  7798. if len(deliverWay) > 0 {
  7799. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and execution_frequency = ? and delivery_way =?"
  7800. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency, deliverWay)
  7801. } else {
  7802. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and execution_frequency = ?"
  7803. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency)
  7804. }
  7805. }
  7806. } else {
  7807. if len(keyword) > 0 {
  7808. if len(deliverWay) > 0 {
  7809. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and advice_name like ? and delivery_way =?"
  7810. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, keyword, deliverWay)
  7811. } else {
  7812. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and advice_name like ?"
  7813. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, keyword)
  7814. }
  7815. } else {
  7816. if len(deliverWay) > 0 {
  7817. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and delivery_way =?"
  7818. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, deliverWay)
  7819. } else {
  7820. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? "
  7821. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type)
  7822. }
  7823. }
  7824. }
  7825. } else {
  7826. if len(execution_frequency) > 0 {
  7827. if len(keyword) > 0 {
  7828. if len(deliverWay) > 0 {
  7829. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  7830. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency, keyword, deliverWay)
  7831. } else {
  7832. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_frequency = ? and advice_name like ?"
  7833. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency, keyword)
  7834. }
  7835. } else {
  7836. if len(deliverWay) > 0 {
  7837. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_frequency = ? and delivery_way =?"
  7838. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency, deliverWay)
  7839. } else {
  7840. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_frequency = ?"
  7841. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency)
  7842. }
  7843. }
  7844. } else {
  7845. if len(keyword) > 0 {
  7846. if len(deliverWay) > 0 {
  7847. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and advice_name like ? and delivery_way =?"
  7848. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, keyword, deliverWay)
  7849. } else {
  7850. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and advice_name like ?"
  7851. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, keyword)
  7852. }
  7853. } else {
  7854. if len(deliverWay) > 0 {
  7855. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and delivery_way =?"
  7856. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, deliverWay)
  7857. } else {
  7858. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? "
  7859. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id)
  7860. }
  7861. }
  7862. }
  7863. }
  7864. }
  7865. } else {
  7866. if execution_state > 0 {
  7867. if cost_type > 0 {
  7868. if len(execution_frequency) > 0 {
  7869. if len(keyword) > 0 {
  7870. if len(deliverWay) > 0 {
  7871. 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 =?"
  7872. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency, keyword, deliverWay)
  7873. } else {
  7874. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  7875. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency, keyword)
  7876. }
  7877. } else {
  7878. if len(deliverWay) > 0 {
  7879. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and execution_frequency = ? and delivery_way =?"
  7880. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency, deliverWay)
  7881. } else {
  7882. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and execution_frequency = ?"
  7883. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency)
  7884. }
  7885. }
  7886. } else {
  7887. if len(keyword) > 0 {
  7888. if len(deliverWay) > 0 {
  7889. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and advice_name like ? and delivery_way =?"
  7890. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, keyword, deliverWay)
  7891. } else {
  7892. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and advice_name like ?"
  7893. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, keyword)
  7894. }
  7895. } else {
  7896. if len(deliverWay) > 0 {
  7897. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and delivery_way =?"
  7898. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, deliverWay)
  7899. } else {
  7900. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ?"
  7901. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type)
  7902. }
  7903. }
  7904. }
  7905. } else {
  7906. if len(execution_frequency) > 0 {
  7907. if len(keyword) > 0 {
  7908. if len(deliverWay) > 0 {
  7909. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  7910. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency, keyword, deliverWay)
  7911. } else {
  7912. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and execution_frequency = ? and advice_name like ?"
  7913. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency, keyword)
  7914. }
  7915. } else {
  7916. if len(deliverWay) > 0 {
  7917. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and execution_frequency = ? and delivery_way =?"
  7918. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency, deliverWay)
  7919. } else {
  7920. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and execution_frequency = ?"
  7921. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency)
  7922. }
  7923. }
  7924. } else {
  7925. if len(keyword) > 0 {
  7926. if len(deliverWay) > 0 {
  7927. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and advice_name like ? and delivery_way =?"
  7928. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, keyword, deliverWay)
  7929. } else {
  7930. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and advice_name like ?"
  7931. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, keyword)
  7932. }
  7933. } else {
  7934. if len(deliverWay) > 0 {
  7935. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and delivery_way =?"
  7936. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, deliverWay)
  7937. } else {
  7938. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ?"
  7939. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state)
  7940. }
  7941. }
  7942. }
  7943. }
  7944. } else {
  7945. if cost_type > 0 {
  7946. if len(keyword) > 0 {
  7947. if len(deliverWay) > 0 {
  7948. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and is_settle = ? and advice_name like ? and delivery_way =?"
  7949. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, keyword, deliverWay)
  7950. } else {
  7951. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and is_settle = ? and advice_name like ?"
  7952. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, keyword)
  7953. }
  7954. } else {
  7955. if len(deliverWay) > 0 {
  7956. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and is_settle = ? and delivery_way =?"
  7957. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, deliverWay)
  7958. } else {
  7959. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and is_settle = ? "
  7960. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type)
  7961. }
  7962. }
  7963. } else {
  7964. if len(keyword) > 0 {
  7965. if len(deliverWay) > 0 {
  7966. if len(execution_frequency) > 0 {
  7967. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and advice_name like ? and delivery_way =? and execution_frequency =? "
  7968. adviceCondition = append(adviceCondition, adviceWhere, orgID, keyword, deliverWay, execution_frequency)
  7969. } else {
  7970. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and advice_name like ? and delivery_way =?"
  7971. adviceCondition = append(adviceCondition, adviceWhere, orgID, keyword, deliverWay)
  7972. }
  7973. } else {
  7974. if len(execution_frequency) > 0 {
  7975. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and advice_name like ? and execution_frequency =?"
  7976. adviceCondition = append(adviceCondition, adviceWhere, orgID, keyword, execution_frequency)
  7977. } else {
  7978. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and advice_name like ?"
  7979. adviceCondition = append(adviceCondition, adviceWhere, orgID, keyword)
  7980. }
  7981. }
  7982. } else {
  7983. if len(deliverWay) > 0 {
  7984. if len(execution_frequency) > 0 {
  7985. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and delivery_way =? and execution_frequency =?"
  7986. adviceCondition = append(adviceCondition, adviceWhere, orgID, deliverWay, execution_frequency)
  7987. } else {
  7988. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and delivery_way =?"
  7989. adviceCondition = append(adviceCondition, adviceWhere, orgID, deliverWay)
  7990. }
  7991. } else {
  7992. if len(execution_frequency) > 0 {
  7993. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_frequency =?"
  7994. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_frequency)
  7995. } else {
  7996. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 "
  7997. adviceCondition = append(adviceCondition, adviceWhere, orgID)
  7998. }
  7999. }
  8000. }
  8001. }
  8002. }
  8003. }
  8004. } else if patientType == 1 {
  8005. if patient_id > 0 {
  8006. if execution_state > 0 {
  8007. if cost_type > 0 {
  8008. if len(execution_frequency) > 0 {
  8009. if len(keyword) > 0 {
  8010. if len(deliverWay) > 0 {
  8011. 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 =?"
  8012. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword, deliverWay)
  8013. } else {
  8014. 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 ?"
  8015. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  8016. }
  8017. } else {
  8018. if len(keyword) > 0 {
  8019. if len(deliverWay) > 0 {
  8020. 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 =?"
  8021. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, execution_frequency, deliverWay)
  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 is_settle = ? and execution_frequency = ? and delivery_way =?"
  8026. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, 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 is_settle = ? and execution_frequency = ?"
  8029. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  8030. }
  8031. }
  8032. }
  8033. } else {
  8034. if len(keyword) > 0 {
  8035. if len(deliverWay) > 0 {
  8036. 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 =?"
  8037. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, keyword, deliverWay)
  8038. } else {
  8039. 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 ?"
  8040. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, keyword)
  8041. }
  8042. } else {
  8043. if len(deliverWay) > 0 {
  8044. 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 =?"
  8045. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, deliverWay)
  8046. } else {
  8047. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  8048. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type)
  8049. }
  8050. }
  8051. }
  8052. } else {
  8053. if len(execution_frequency) > 0 {
  8054. if len(keyword) > 0 {
  8055. if len(deliverWay) > 0 {
  8056. 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 =?"
  8057. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, execution_frequency, keyword, deliverWay)
  8058. } else {
  8059. 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 ?"
  8060. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  8061. }
  8062. } else {
  8063. if len(deliverWay) > 0 {
  8064. 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 =?"
  8065. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, execution_frequency, deliverWay)
  8066. } else {
  8067. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  8068. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, execution_frequency)
  8069. }
  8070. }
  8071. } else {
  8072. if len(keyword) > 0 {
  8073. if len(deliverWay) > 0 {
  8074. 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 =?"
  8075. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, keyword, deliverWay)
  8076. } else {
  8077. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  8078. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, keyword)
  8079. }
  8080. } else {
  8081. if len(deliverWay) > 0 {
  8082. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and delivery_way =?"
  8083. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, deliverWay)
  8084. } else {
  8085. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  8086. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state)
  8087. }
  8088. }
  8089. }
  8090. }
  8091. } else {
  8092. if cost_type > 0 {
  8093. if len(execution_frequency) > 0 {
  8094. if len(keyword) > 0 {
  8095. if len(deliverWay) > 0 {
  8096. 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 =?"
  8097. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, execution_frequency, keyword, deliverWay)
  8098. } else {
  8099. 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 ?"
  8100. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  8101. }
  8102. } else {
  8103. if len(deliverWay) > 0 {
  8104. 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 =?"
  8105. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, execution_frequency, deliverWay)
  8106. } else {
  8107. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ?and execution_frequency = ?"
  8108. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, execution_frequency)
  8109. }
  8110. }
  8111. } else {
  8112. if len(keyword) > 0 {
  8113. if len(deliverWay) > 0 {
  8114. 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 =?"
  8115. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, keyword, deliverWay)
  8116. } else {
  8117. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  8118. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, keyword)
  8119. }
  8120. } else {
  8121. if len(deliverWay) > 0 {
  8122. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ? and delivery_way =? "
  8123. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, deliverWay)
  8124. } else {
  8125. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  8126. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type)
  8127. }
  8128. }
  8129. }
  8130. } else {
  8131. if len(execution_frequency) > 0 {
  8132. if len(keyword) > 0 {
  8133. if len(deliverWay) > 0 {
  8134. 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 =? "
  8135. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_frequency, keyword, deliverWay)
  8136. } else {
  8137. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  8138. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_frequency, keyword)
  8139. }
  8140. } else {
  8141. if len(deliverWay) > 0 {
  8142. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_frequency = ? and delivery_way =? "
  8143. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_frequency, deliverWay)
  8144. } else {
  8145. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  8146. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_frequency)
  8147. }
  8148. }
  8149. } else {
  8150. if len(keyword) > 0 {
  8151. if len(deliverWay) > 0 {
  8152. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and advice_name like ? and delivery_way =?"
  8153. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, keyword, deliverWay)
  8154. } else {
  8155. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and advice_name like ?"
  8156. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, keyword)
  8157. }
  8158. } else {
  8159. if len(deliverWay) > 0 {
  8160. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and delivery_way =?"
  8161. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, deliverWay)
  8162. } else {
  8163. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ?"
  8164. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id)
  8165. }
  8166. }
  8167. }
  8168. }
  8169. }
  8170. } else {
  8171. if execution_state > 0 {
  8172. if cost_type > 0 {
  8173. if len(execution_frequency) > 0 {
  8174. if len(keyword) > 0 {
  8175. if len(deliverWay) > 0 {
  8176. 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 =?"
  8177. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, execution_frequency, keyword, deliverWay)
  8178. } else {
  8179. 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 ?"
  8180. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  8181. }
  8182. } else {
  8183. if len(deliverWay) > 0 {
  8184. 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 =?"
  8185. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, execution_frequency, deliverWay)
  8186. } else {
  8187. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ?and execution_frequency = ?"
  8188. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, execution_frequency)
  8189. }
  8190. }
  8191. } else {
  8192. if len(keyword) > 0 {
  8193. if len(deliverWay) > 0 {
  8194. 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 =?"
  8195. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, keyword, deliverWay)
  8196. } else {
  8197. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ? and advice_name like ?"
  8198. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, keyword)
  8199. }
  8200. } else {
  8201. if len(deliverWay) > 0 {
  8202. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ? and delivery_way =?"
  8203. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, deliverWay)
  8204. } else {
  8205. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ?"
  8206. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type)
  8207. }
  8208. }
  8209. }
  8210. } else {
  8211. if len(execution_frequency) > 0 {
  8212. if len(keyword) > 0 {
  8213. if len(deliverWay) > 0 {
  8214. 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 =?"
  8215. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, execution_frequency, keyword, deliverWay)
  8216. } else {
  8217. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=?and execution_frequency = ? and advice_name like ?"
  8218. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, execution_frequency, keyword)
  8219. }
  8220. } else {
  8221. if len(deliverWay) > 0 {
  8222. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=?and execution_frequency = ? and delivery_way =?"
  8223. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, execution_frequency, deliverWay)
  8224. } else {
  8225. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=?and execution_frequency = ?"
  8226. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, execution_frequency)
  8227. }
  8228. }
  8229. } else {
  8230. if len(keyword) > 0 {
  8231. if len(deliverWay) > 0 {
  8232. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and advice_name like ? and delivery_way =?"
  8233. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, keyword, deliverWay)
  8234. } else {
  8235. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and advice_name like ?"
  8236. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, keyword)
  8237. }
  8238. } else {
  8239. if len(deliverWay) > 0 {
  8240. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and delivery_way =?"
  8241. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, deliverWay)
  8242. } else {
  8243. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=?"
  8244. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state)
  8245. }
  8246. }
  8247. }
  8248. }
  8249. } else {
  8250. if cost_type > 0 {
  8251. if len(execution_frequency) > 0 {
  8252. if len(keyword) > 0 {
  8253. if len(deliverWay) > 0 {
  8254. 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 =?"
  8255. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, execution_frequency, keyword, deliverWay)
  8256. } else {
  8257. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  8258. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, execution_frequency, keyword)
  8259. }
  8260. } else {
  8261. if len(deliverWay) > 0 {
  8262. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and execution_frequency = ? and delivery_way =?"
  8263. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, execution_frequency, deliverWay)
  8264. } else {
  8265. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  8266. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, execution_frequency)
  8267. }
  8268. }
  8269. } else {
  8270. if len(keyword) > 0 {
  8271. if len(deliverWay) > 0 {
  8272. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and advice_name like ? and delivery_way =?"
  8273. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, keyword, deliverWay)
  8274. } else {
  8275. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and advice_name like ?"
  8276. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, keyword)
  8277. }
  8278. } else {
  8279. if len(deliverWay) > 0 {
  8280. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and delivery_way =?"
  8281. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, deliverWay)
  8282. } else {
  8283. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? "
  8284. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type)
  8285. }
  8286. }
  8287. }
  8288. } else {
  8289. if len(execution_frequency) > 0 {
  8290. if len(keyword) > 0 {
  8291. if len(deliverWay) > 0 {
  8292. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  8293. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_frequency, keyword, deliverWay)
  8294. } else {
  8295. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_frequency = ? and advice_name like ?"
  8296. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_frequency, keyword)
  8297. }
  8298. } else {
  8299. if len(deliverWay) > 0 {
  8300. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_frequency = ? and delivery_way =?"
  8301. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_frequency, deliverWay)
  8302. } else {
  8303. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_frequency = ?"
  8304. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_frequency)
  8305. }
  8306. }
  8307. } else {
  8308. if len(keyword) > 0 {
  8309. if len(deliverWay) > 0 {
  8310. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and advice_name like ? and delivery_way =?"
  8311. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, keyword, deliverWay)
  8312. } else {
  8313. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and advice_name like ?"
  8314. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, keyword)
  8315. }
  8316. } else {
  8317. if len(deliverWay) > 0 {
  8318. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and delivery_way =?"
  8319. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, deliverWay)
  8320. } else {
  8321. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? "
  8322. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId)
  8323. }
  8324. }
  8325. }
  8326. }
  8327. }
  8328. }
  8329. } else if patientType == 2 {
  8330. if patient_id > 0 {
  8331. if execution_state > 0 {
  8332. if cost_type > 0 {
  8333. if len(execution_frequency) > 0 {
  8334. if len(keyword) > 0 {
  8335. if len(deliverWay) > 0 {
  8336. 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 =?"
  8337. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency, keyword, deliverWay)
  8338. } else {
  8339. 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 ?"
  8340. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency, keyword)
  8341. }
  8342. } else {
  8343. if len(deliverWay) > 0 {
  8344. 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 =?"
  8345. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency, deliverWay)
  8346. } else {
  8347. 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 = ?"
  8348. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency)
  8349. }
  8350. }
  8351. } else {
  8352. if len(keyword) > 0 {
  8353. if len(deliverWay) > 0 {
  8354. 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 =?"
  8355. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, keyword, deliverWay)
  8356. } else {
  8357. 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 ?"
  8358. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, keyword)
  8359. }
  8360. } else {
  8361. if len(deliverWay) > 0 {
  8362. 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 =?"
  8363. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, deliverWay)
  8364. } else {
  8365. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ?"
  8366. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type)
  8367. }
  8368. }
  8369. }
  8370. } else {
  8371. if len(execution_frequency) > 0 {
  8372. if len(keyword) > 0 {
  8373. if len(deliverWay) > 0 {
  8374. 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 =?"
  8375. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency, keyword, deliverWay)
  8376. } else {
  8377. 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 ?"
  8378. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency, keyword)
  8379. }
  8380. } else {
  8381. if len(deliverWay) > 0 {
  8382. 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 =?"
  8383. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency, deliverWay)
  8384. } else {
  8385. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and execution_frequency = ?"
  8386. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency)
  8387. }
  8388. }
  8389. } else {
  8390. if len(keyword) > 0 {
  8391. if len(deliverWay) > 0 {
  8392. 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 =?"
  8393. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, keyword, deliverWay)
  8394. } else {
  8395. 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 ?"
  8396. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, keyword)
  8397. }
  8398. } else {
  8399. if len(deliverWay) > 0 {
  8400. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and delivery_way =?"
  8401. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, deliverWay)
  8402. } else {
  8403. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  8404. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state)
  8405. }
  8406. }
  8407. }
  8408. }
  8409. } else {
  8410. if cost_type > 0 {
  8411. if len(execution_frequency) > 0 {
  8412. if len(keyword) > 0 {
  8413. if len(deliverWay) > 0 {
  8414. 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 =?"
  8415. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency, keyword, deliverWay)
  8416. } else {
  8417. 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 ?"
  8418. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency, keyword)
  8419. }
  8420. } else {
  8421. if len(deliverWay) > 0 {
  8422. 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 =?"
  8423. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency, deliverWay)
  8424. } else {
  8425. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and is_settle = ? and execution_frequency = ?"
  8426. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency)
  8427. }
  8428. }
  8429. } else {
  8430. if len(keyword) > 0 {
  8431. if len(deliverWay) > 0 {
  8432. 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 =?"
  8433. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, keyword, deliverWay)
  8434. } else {
  8435. 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 ?"
  8436. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, keyword)
  8437. }
  8438. } else {
  8439. if len(deliverWay) > 0 {
  8440. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and is_settle = ? and delivery_way =?"
  8441. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, deliverWay)
  8442. } else {
  8443. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  8444. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type)
  8445. }
  8446. }
  8447. }
  8448. } else {
  8449. if len(execution_frequency) > 0 {
  8450. if len(keyword) > 0 {
  8451. if len(deliverWay) > 0 {
  8452. 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 =?"
  8453. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency, keyword, deliverWay)
  8454. } else {
  8455. 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 ?"
  8456. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency, keyword)
  8457. }
  8458. } else {
  8459. if len(deliverWay) > 0 {
  8460. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_frequency = ? and delivery_way =?"
  8461. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency, deliverWay)
  8462. } else {
  8463. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_frequency = ?"
  8464. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency)
  8465. }
  8466. }
  8467. } else {
  8468. if len(keyword) > 0 {
  8469. if len(deliverWay) > 0 {
  8470. 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 =?"
  8471. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, keyword, deliverWay)
  8472. } else {
  8473. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and advice_name like ?"
  8474. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, keyword)
  8475. }
  8476. } else {
  8477. if len(deliverWay) > 0 {
  8478. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and delivery_way =?"
  8479. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, deliverWay)
  8480. } else {
  8481. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ?"
  8482. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id)
  8483. }
  8484. }
  8485. }
  8486. }
  8487. }
  8488. } else {
  8489. if execution_state > 0 {
  8490. if cost_type > 0 {
  8491. if len(execution_frequency) > 0 {
  8492. if len(keyword) > 0 {
  8493. if len(deliverWay) > 0 {
  8494. 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 =?"
  8495. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency, keyword, deliverWay)
  8496. } else {
  8497. 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 ?"
  8498. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency, keyword)
  8499. }
  8500. } else {
  8501. if len(deliverWay) > 0 {
  8502. 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 =?"
  8503. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency, deliverWay)
  8504. } else {
  8505. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ? and execution_frequency = ?"
  8506. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency)
  8507. }
  8508. }
  8509. } else {
  8510. if len(keyword) > 0 {
  8511. if len(deliverWay) > 0 {
  8512. 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 =?"
  8513. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, keyword, deliverWay)
  8514. } else {
  8515. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ? and advice_name like ?"
  8516. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, keyword)
  8517. }
  8518. } else {
  8519. if len(deliverWay) > 0 {
  8520. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ? and delivery_way =?"
  8521. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, deliverWay)
  8522. } else {
  8523. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  8524. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type)
  8525. }
  8526. }
  8527. }
  8528. } else {
  8529. if len(execution_frequency) > 0 {
  8530. if len(keyword) > 0 {
  8531. if len(deliverWay) > 0 {
  8532. 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 =?"
  8533. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency, keyword, deliverWay)
  8534. } else {
  8535. 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 ?"
  8536. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency, keyword)
  8537. }
  8538. } else {
  8539. if len(deliverWay) > 0 {
  8540. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ? and execution_frequency = ? and delivery_way =?"
  8541. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency, deliverWay)
  8542. } else {
  8543. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ? and execution_frequency = ?"
  8544. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency)
  8545. }
  8546. }
  8547. } else {
  8548. if len(keyword) > 0 {
  8549. if len(deliverWay) > 0 {
  8550. 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 =?"
  8551. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, keyword, deliverWay)
  8552. } else {
  8553. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ? and advice_name like ?"
  8554. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, keyword)
  8555. }
  8556. } else {
  8557. if len(deliverWay) > 0 {
  8558. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ? and delivery_way =?"
  8559. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, deliverWay)
  8560. } else {
  8561. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ?"
  8562. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state)
  8563. }
  8564. }
  8565. }
  8566. }
  8567. } else {
  8568. if cost_type > 0 {
  8569. if len(execution_frequency) > 0 {
  8570. if len(keyword) > 0 {
  8571. if len(deliverWay) > 0 {
  8572. 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 =?"
  8573. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, execution_frequency, keyword, deliverWay)
  8574. } else {
  8575. 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 ?"
  8576. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, execution_frequency, keyword)
  8577. }
  8578. } else {
  8579. if len(deliverWay) > 0 {
  8580. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ? and execution_frequency = ? and delivery_way =?"
  8581. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, execution_frequency, deliverWay)
  8582. } else {
  8583. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  8584. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, execution_frequency)
  8585. }
  8586. }
  8587. } else {
  8588. if len(keyword) > 0 {
  8589. if len(deliverWay) > 0 {
  8590. 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 =?"
  8591. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, keyword, deliverWay)
  8592. } else {
  8593. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ? and advice_name like ?"
  8594. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, keyword)
  8595. }
  8596. } else {
  8597. if len(deliverWay) > 0 {
  8598. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ? and delivery_way =?"
  8599. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, deliverWay)
  8600. } else {
  8601. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ?"
  8602. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type)
  8603. }
  8604. }
  8605. }
  8606. } else {
  8607. if len(execution_frequency) > 0 {
  8608. if len(keyword) > 0 {
  8609. if len(deliverWay) > 0 {
  8610. 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 =?"
  8611. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_frequency, keyword, deliverWay)
  8612. } else {
  8613. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_frequency = ? and advice_name like ?"
  8614. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_frequency, keyword)
  8615. }
  8616. } else {
  8617. if len(deliverWay) > 0 {
  8618. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_frequency = ? and delivery_way =?"
  8619. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_frequency, deliverWay)
  8620. } else {
  8621. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_frequency = ?"
  8622. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_frequency)
  8623. }
  8624. }
  8625. } else {
  8626. if len(keyword) > 0 {
  8627. if len(deliverWay) > 0 {
  8628. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and advice_name like ? and delivery_way =?"
  8629. adviceCondition = append(adviceCondition, adviceWhere, orgID, keyword, deliverWay)
  8630. } else {
  8631. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and advice_name like ?"
  8632. adviceCondition = append(adviceCondition, adviceWhere, orgID, keyword)
  8633. }
  8634. } else {
  8635. if len(deliverWay) > 0 {
  8636. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and delivery_way =?"
  8637. adviceCondition = append(adviceCondition, adviceWhere, orgID, deliverWay)
  8638. } else {
  8639. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0"
  8640. adviceCondition = append(adviceCondition, adviceWhere, orgID)
  8641. }
  8642. }
  8643. }
  8644. }
  8645. }
  8646. }
  8647. }
  8648. }
  8649. db := readDb.Table("xt_schedule")
  8650. if scheduleType > 0 {
  8651. db = db.Where("schedule_type = ?", scheduleType)
  8652. }
  8653. if partitonType > 0 {
  8654. db = db.Where("partition_id = ?", partitonType)
  8655. }
  8656. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  8657. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  8658. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  8659. }).
  8660. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  8661. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  8662. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  8663. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  8664. Preload("DoctorAdvices", adviceCondition...).
  8665. Where("status = 1 AND user_org_id = ?", orgID)
  8666. if scheduleDate != 0 {
  8667. db = db.Where("schedule_date = ?", scheduleDate)
  8668. }
  8669. err := db.Find(&vms).Error
  8670. return vms, err
  8671. }
  8672. func GetLastAcceptTreatment(user_org_id int64, patient_id int64) (models.ReceiveTreatmentAsses, error) {
  8673. treatmentAsses := models.ReceiveTreatmentAsses{}
  8674. err := XTReadDB().Where("user_org_id = ? and patient_id = ? and status=1 and admission_number<>''", user_org_id, patient_id).Last(&treatmentAsses).Error
  8675. return treatmentAsses, err
  8676. }
  8677. func GetDrugIsShow(id int64, org_id int64) (models.XtBaseDrug, error) {
  8678. baseDrug := models.XtBaseDrug{}
  8679. err := XTReadDB().Where("id = ? and status =1 and org_id = ?", id, org_id).Find(&baseDrug).Error
  8680. return baseDrug, err
  8681. }