mobile_dialysis_service.go 541KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063
  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. DialysisSolution *models.DialysisSolution `gorm:"ForeignKey:PatientId,ModeId;AssociationForeignKey:PatientId,ModeId" json:"dialysis_solution"`
  116. }
  117. func (MDialysisScheduleVM) TableName() string {
  118. return "xt_schedule"
  119. }
  120. type MDialysisScheduleVMForList struct {
  121. ID int64 `gorm:"column:id" json:"id"`
  122. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  123. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  124. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  125. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  126. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  127. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  128. ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week"`
  129. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  130. Status int64 `gorm:"column:status" json:"status"`
  131. SchedualPatient *models.MSchedualPatientList `gorm:"ForeignKey:PatientId" json:"patient"`
  132. DeviceNumber *models.MDeviceNumberForList `gorm:"ForeignKey:BedId" json:"device_number"`
  133. DialysisOrder *models.MDialysisOrderForList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  134. DialysisLastOrder *models.MDialysisOrderForList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"last_order"`
  135. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  136. AssessmentBeforeDislysis *models.PredialysisEvaluationList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_before_dislysis"`
  137. AssessmentAfterDislysis *models.VMAssessmentAfterDislysis `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_after_dislysis"`
  138. HisAdvices []VMHisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"his_doctor_advice"`
  139. Advices []models.VMDoctorAdviceForList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  140. TreatmentSummary *models.VMTreatmentSummaryForList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"treatment_summary"`
  141. DialysisSolution *models.DialysisSolution `gorm:"ForeignKey:PatientId,ModeId;AssociationForeignKey:PatientId,ModeId" json:"dialysis_solution"`
  142. DoubleCheck *models.DoubleCheck `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dobule_check"`
  143. NewDeviceInformation *NewDeviceInformation `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"device_information"`
  144. //VMMonitoringRecord []models.VMMonitoringRecord `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"monitor_record"`
  145. }
  146. func (MDialysisScheduleVMForList) TableName() string {
  147. return "xt_schedule"
  148. }
  149. type MDeviceNumberVM struct {
  150. models.DeviceNumber
  151. Zone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"zone"`
  152. }
  153. func (MDeviceNumberVM) TableName() string {
  154. return "xt_device_number"
  155. }
  156. type MSchedualPatientVMList struct {
  157. ID int64 `gorm:"column:id" json:"id" form:"id"`
  158. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  159. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  160. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  161. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
  162. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  163. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  164. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  165. Age int64 `gorm:"column:age" json:"age"`
  166. Name string `gorm:"column:name" json:"name" form:"name"`
  167. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  168. UserSysBeforeCount int64 `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
  169. TrobleShoot int64 `gorm:"column:troble_shoot" json:"troble_shoot" form:"troble_shoot"`
  170. SchRemark string `gorm:"column:sch_remark" json:"sch_remark" form:"sch_remark"`
  171. ScheduleRemark string `gorm:"column:schedule_remark" json:"schedule_remark" form:"schedule_remark"`
  172. FirstLetter string `gorm:"column:first_letter" json:"first_letter" form:"first_letter"`
  173. Height int64 `gorm:"column:height" json:"height" form:"height"`
  174. }
  175. func (MSchedualPatientVMList) TableName() string {
  176. return "xt_patients"
  177. }
  178. type MSchedualPatientVM struct {
  179. ID int64 `gorm:"column:id" json:"id" form:"id"`
  180. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  181. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  182. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  183. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  184. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
  185. AdmissionNumber string `gorm:"column:admission_number" json:"admission_number" form:"admission_number"`
  186. Source int64 `gorm:"column:source" json:"source" form:"source"`
  187. Lapseto int64 `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
  188. PartitionId int64 `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
  189. BedId int64 `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
  190. Name string `gorm:"column:name" json:"name" form:"name"`
  191. Alias string `gorm:"column:alias" json:"alias" form:"alias"`
  192. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  193. Nation string `gorm:"column:nation" json:"nation" form:"nation"`
  194. NativePlace string `gorm:"column:native_place" json:"native_place" form:"native_place"`
  195. MaritalStatus int64 `gorm:"column:marital_status" json:"marital_status" form:"marital_status"`
  196. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  197. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  198. ReimbursementWayId int64 `gorm:"column:reimbursement_way_id" json:"reimbursement_way_id" form:"reimbursement_way_id"`
  199. HealthCareType int64 `gorm:"column:health_care_type" json:"health_care_type" form:"health_care_type"`
  200. HealthCareNo string `gorm:"column:health_care_no" json:"health_care_no" form:"health_care_no"`
  201. HealthCareDueDate int64 `gorm:"column:health_care_due_date" json:"health_care_due_date" form:"health_care_due_date"`
  202. Height int64 `gorm:"column:height" json:"height" form:"height"`
  203. BloodType int64 `gorm:"column:blood_type" json:"blood_type" form:"blood_type"`
  204. Rh int64 `gorm:"column:rh" json:"rh" form:"rh"`
  205. HealthCareDueAlertDate int64 `gorm:"column:health_care_due_alert_date" json:"health_care_due_alert_date" form:"health_care_due_alert_date"`
  206. EducationLevel int64 `gorm:"column:education_level" json:"education_level" form:"education_level"`
  207. Profession int64 `gorm:"column:profession" json:"profession" form:"profession"`
  208. Phone string `gorm:"column:phone" json:"phone" form:"phone"`
  209. HomeTelephone string `gorm:"column:home_telephone" json:"home_telephone" form:"home_telephone"`
  210. RelativePhone string `gorm:"column:relative_phone" json:"relative_phone" form:"relative_phone"`
  211. RelativeRelations string `gorm:"column:relative_relations" json:"relative_relations" form:"relative_relations"`
  212. HomeAddress string `gorm:"column:home_address" json:"home_address" form:"home_address"`
  213. WorkUnit string `gorm:"column:work_unit" json:"work_unit" form:"work_unit"`
  214. UnitAddress string `gorm:"column:unit_address" json:"unit_address" form:"unit_address"`
  215. Children int64 `gorm:"column:children" json:"children" form:"children"`
  216. ReceivingDate int64 `gorm:"column:receiving_date" json:"receiving_date" form:"receiving_date"`
  217. IsHospitalFirstDialysis int64 `gorm:"column:is_hospital_first_dialysis" json:"is_hospital_first_dialysis" form:"is_hospital_first_dialysis"`
  218. FirstDialysisDate int64 `gorm:"column:first_dialysis_date" json:"first_dialysis_date" form:"first_dialysis_date"`
  219. FirstDialysisHospital string `gorm:"column:first_dialysis_hospital" json:"first_dialysis_hospital" form:"first_dialysis_hospital"`
  220. InductionPeriod int64 `gorm:"column:induction_period" json:"induction_period" form:"induction_period"`
  221. InitialDialysis int64 `gorm:"column:initial_dialysis" json:"initial_dialysis" form:"initial_dialysis"`
  222. TotalDialysis int64 `gorm:"column:total_dialysis" json:"total_dialysis" form:"total_dialysis"`
  223. AttendingDoctorId int64 `gorm:"column:attending_doctor_id" json:"attending_doctor_id" form:"attending_doctor_id"`
  224. HeadNurseId int64 `gorm:"column:head_nurse_id" json:"head_nurse_id" form:"head_nurse_id"`
  225. Evaluate string `gorm:"column:evaluate" json:"evaluate" form:"evaluate"`
  226. Diagnose string `gorm:"column:diagnose" json:"diagnose" form:"diagnose"`
  227. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  228. RegistrarsId int64 `gorm:"column:registrars_id" json:"registrars_id" form:"registrars_id"`
  229. Registrars string `gorm:"column:registrars" json:"registrars" form:"registrars"`
  230. QrCode string `gorm:"column:qr_code" json:"qr_code" form:"qr_code"`
  231. BindingState int64 `gorm:"column:binding_state" json:"binding_state" form:"binding_state"`
  232. PatientComplains string `gorm:"column:patient_complains" json:"patient_complains"` // 主诉
  233. PresentHistory string `gorm:"column:present_history" json:"present_history"` // 现病史
  234. PastHistory string `gorm:"column:past_history" json:"past_history"` // 既往史
  235. Temperature float64 `gorm:"column:temperature" json:"temperature"` // 体格检查-体温
  236. Pulse int64 `gorm:"column:pulse" json:"pulse"` // 体格检查-脉搏
  237. Respiratory int64 `gorm:"column:respiratory" json:"respiratory"` // 体格检查-呼吸频率
  238. SBP int64 `gorm:"column:sbp" json:"sbp"` // 体格检查-收缩压
  239. DBP int64 `gorm:"column:dbp" json:"dbp"` // 体格检查-舒张压
  240. Status int64 `gorm:"column:status" json:"status" form:"status"`
  241. Age int64 `gorm:"column:age" json:"age"`
  242. IsOpenRemind int64 `gorm:"column:is_open_remind" json:"is_open_remind"`
  243. DialysisAge int64 `gorm:"column:dialysis_age" json:"dialysis_age" form:"dialysis_age"`
  244. ExpenseKind int64 `gorm:"column:expense_kind" json:"expense_kind" form:"expense_kind"`
  245. TellPhone string `gorm:"column:tell_phone" json:"tell_phone" form:"tell_phone"`
  246. FirstTreatmentDate int64 `gorm:"column:first_treatment_date" json:"first_treatment_date" form:"first_treatment_date"`
  247. ContactName string `gorm:"column:contact_name" json:"contact_name" form:"contact_name"`
  248. UserSysBeforeCount int64 `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
  249. FirstLetter string `gorm:"column:first_letter" json:"first_letter" form:"first_letter"`
  250. }
  251. func (MSchedualPatientVM) TableName() string {
  252. return "xt_patients"
  253. }
  254. type MDialysisOrderVM struct {
  255. ID int64 `gorm:"column:id" json:"id"`
  256. DialysisDate int64 `gorm:"column:dialysis_date" json:"dialysis_date"`
  257. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  258. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  259. Stage int64 `gorm:"column:stage" json:"stage"`
  260. BedID int64 `gorm:"column:bed_id" json:"bed_id"`
  261. StartNurse int64 `gorm:"column:start_nurse" json:"start_nurse"`
  262. FinishNurse int64 `gorm:"column:finish_nurse" json:"finish_nurse"`
  263. Status int64 `gorm:"column:status" json:"status"`
  264. PunctureNurse int64 `gorm:"column:puncture_nurse" json:"puncture_nurse"`
  265. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedID" json:"device_number"`
  266. MonitoringRecords []*models.MonitoringRecord `gorm:"ForeignKey:DialysisOrderId" json:"monitoring_records"`
  267. Creator int64 `gorm:"column:creator" json:"creator"`
  268. Modifier int64 `gorm:"column:modifier" json:"modifier"`
  269. FinishCreator int64 `gorm:"column:finish_creator" json:"finish_creator"`
  270. FinishModifier int64 `gorm:"column:finish_modifier" json:"finish_modifier"`
  271. SchedualType int64 `gorm:"column:schedual_type" json:"schedual_type"`
  272. WashpipeNurse int64 `gorm:"column:washpipe_nurse" json:"washpipe_nurse" form:"washpipe_nurse"`
  273. DialysisIrrigation string `gorm:"column:dialysis_irrigation" json:"dialysis_irrigation" form:"dialysis_irrigation"`
  274. DialysisDialyszers string `gorm:"column:dialysis_dialyszers" json:"dialysis_dialyszers" form:"dialysis_dialyszers"`
  275. }
  276. func (MDialysisOrderVM) TableName() string {
  277. return "xt_dialysis_order"
  278. }
  279. type MDialysisOrderVMList struct {
  280. ID int64 `gorm:"column:id" json:"id"`
  281. DialysisDate int64 `gorm:"column:dialysis_date" json:"dialysis_date"`
  282. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  283. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  284. // PrescriptionId int64 `gorm:"column:prescription_id" json:"prescription_id"`
  285. Stage int64 `gorm:"column:stage" json:"stage"`
  286. // Remark string `gorm:"column:remark" json:"remark"`
  287. BedID int64 `gorm:"column:bed_id" json:"bed_id"`
  288. StartNurse int64 `gorm:"column:start_nurse" json:"start_nurse"`
  289. Status int64 `gorm:"column:status" json:"status"`
  290. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedID" json:"device_number"`
  291. Creator int64 `gorm:"column:creator" json:"creator"`
  292. WashpipeNurse int64 `gorm:"column:washpipe_nurse" json:"washpipe_nurse" form:"washpipe_nurse"`
  293. NucleinDate int64 `gorm:"column:nuclein_date" json:"nuclein_date" form:"nuclein_date"`
  294. DialysisIrrigation string `gorm:"column:dialysis_irrigation" json:"dialysis_irrigation" form:"dialysis_irrigation"`
  295. DialysisDialyszers string `gorm:"column:dialysis_dialyszers" json:"dialysis_dialyszers" form:"dialysis_dialyszers"`
  296. ScheduleRemark string `gorm:"column:schedule_remark" json:"schedule_remark" form:"schedule_remark"`
  297. }
  298. func (MDialysisOrderVMList) TableName() string {
  299. return "xt_dialysis_order"
  300. }
  301. type VMDoctorAdvice struct {
  302. ID int64 `gorm:"column:id" json:"id" form:"id"`
  303. GroupNo int64 `gorm:"column:groupno" json:"groupno" form:"groupno"`
  304. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  305. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  306. AdviceDate int64 `gorm:"column:advice_date" json:"advice_date" form:"advice_date"`
  307. Status int64 `gorm:"column:status" json:"status" form:"status"`
  308. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
  309. RecordDate int64 `gorm:"column:record_date" json:"record_date"`
  310. CheckTime int64 `gorm:"column:check_time" json:"check_time" form:"check_time"`
  311. CheckState int64 `gorm:"column:check_state" json:"check_state" form:"check_state"`
  312. ParentId int64 `gorm:"column:parent_id" json:"parent_id" form:"parent_id"`
  313. }
  314. func (VMDoctorAdvice) TableName() string {
  315. return "xt_doctor_advice"
  316. }
  317. type VMHisDoctorAdviceInfo struct {
  318. ID int64 `gorm:"column:id" json:"id" form:"id"`
  319. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  320. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  321. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  322. ExecutionTime int64 `gorm:"column:execution_time" json:"execution_time" form:"execution_time"`
  323. ExecutionStaff int64 `gorm:"column:execution_staff" json:"execution_staff" form:"execution_staff"`
  324. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
  325. IsMedicine int64 `gorm:"column:is_medicine" json:"is_medicine" form:"is_medicine"`
  326. ExecutionFrequencyId int64 `gorm:"column:execution_frequency_id" json:"execution_frequency_id" form:"execution_frequency_id"`
  327. IsSelfDrug int64 `gorm:"column:is_self_drug" json:"is_self_drug" form:"is_self_drug"`
  328. }
  329. func (VMHisDoctorAdviceInfo) TableName() string {
  330. return "his_doctor_advice_info"
  331. }
  332. type VMAssessmentAfterDislysis struct {
  333. ID int64 `gorm:"column:id" json:"id"`
  334. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  335. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  336. AssessmentDate int64 `gorm:"column:assessment_date" json:"assessment_date"`
  337. WeightAfter float64 `gorm:"column:weight_after" json:"weight_after"`
  338. Status int64 `gorm:"column:status" json:"status"`
  339. }
  340. func (VMAssessmentAfterDislysis) TableName() string {
  341. return "xt_assessment_after_dislysis"
  342. }
  343. type NewDeviceInformation struct {
  344. ID int64 `gorm:"column:id" json:"id" form:"id"`
  345. Date int64 `gorm:"column:date" json:"date" form:"date"`
  346. Class int64 `gorm:"column:class" json:"class" form:"class"`
  347. Zone int64 `gorm:"column:zone" json:"zone" form:"zone"`
  348. BedNumber int64 `gorm:"column:bed_number" json:"bed_number" form:"bed_number"`
  349. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  350. Status int64 `gorm:"column:status" json:"status" form:"status"`
  351. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  352. EquimentId int64 `gorm:"column:equiment_id" json:"equiment_id" form:"equiment_id"`
  353. Bed string `gorm:"column:bed" json:"bed" form:"bed"`
  354. Stime int64 `gorm:"column:stime" json:"stime" form:"stime"`
  355. }
  356. func (NewDeviceInformation) TableName() string {
  357. return "xt_device_information"
  358. }
  359. // 获取透析记录
  360. func MobileGetDialysisRecord(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  361. var record models.DialysisOrder
  362. err := readDb.Model(&models.DialysisOrder{}).Where("user_org_id = ? AND patient_id = ? AND dialysis_date = ?", orgID, patientID, recordDate).First(&record).Error
  363. if err != nil {
  364. if err == gorm.ErrRecordNotFound {
  365. return nil, nil
  366. } else {
  367. return nil, err
  368. }
  369. }
  370. return &record, nil
  371. }
  372. // 用户基本信息
  373. func MobileGetPatientDetail(orgID int64, patientID int64) (*MPatient, error) {
  374. var patient MPatient
  375. //err := readDb.Model(&MPatient{}).Where("status = 1 AND user_org_id = ? AND id = ?", orgID, patientID).First(&patient).Error
  376. //if err != nil {
  377. // if err == gorm.ErrRecordNotFound {
  378. // return nil, nil
  379. // } else {
  380. // return nil, err
  381. // }
  382. //}
  383. //return &patient, nil
  384. redis := RedisClient()
  385. defer redis.Close()
  386. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":patient_info"
  387. patient_info_str, _ := redis.Get(key).Result()
  388. if len(patient_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  389. err = readDb.Model(&patient).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
  390. if err != nil {
  391. if err == gorm.ErrRecordNotFound {
  392. return &patient, nil
  393. } else {
  394. return &patient, err
  395. }
  396. } else {
  397. if patient.ID > 0 {
  398. //缓存数据
  399. patient_info_json, err := json.Marshal(&patient)
  400. if err == nil {
  401. redis.Set(key, patient_info_json, time.Second*60*60*18)
  402. }
  403. }
  404. return &patient, nil
  405. }
  406. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  407. json.Unmarshal([]byte(patient_info_str), &patient)
  408. return &patient, nil
  409. }
  410. }
  411. func MobileGetSchedualDetailOne(orgID int64, patientID int64, schedualDate int64) (*MDialysisScheduleVM, error) {
  412. var vm MDialysisScheduleVM
  413. err := readDb.
  414. Table("xt_schedule").
  415. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  416. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  417. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  418. First(&vm).Error
  419. return &vm, err
  420. }
  421. // 用户排班信息
  422. func MobileGetSchedualDetailSix(orgID int64, patientID int64, schedualDate int64) (*MDialysisScheduleVM, error) {
  423. var vm MDialysisScheduleVM
  424. err := readDb.
  425. Table("xt_schedule").
  426. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  427. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  428. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  429. First(&vm).Error
  430. if err != nil {
  431. if err == gorm.ErrRecordNotFound {
  432. return nil, nil
  433. } else {
  434. return nil, err
  435. }
  436. }
  437. return &vm, err
  438. }
  439. // 用户排班信息
  440. func MobileGetSchedualDetail(orgID int64, patientID int64, schedualDate int64) (*MDialysisScheduleVM, error) {
  441. redis := RedisClient()
  442. defer redis.Close()
  443. var vm MDialysisScheduleVM
  444. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(schedualDate, 10) + ":schedual_detail"
  445. redis.Set(key, "", time.Second)
  446. schedual_detail_str, _ := redis.Get(key).Result()
  447. if len(schedual_detail_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  448. err := readDb.
  449. Table("xt_schedule").
  450. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  451. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  452. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  453. First(&vm).Error
  454. if err != nil {
  455. if err == gorm.ErrRecordNotFound {
  456. return nil, nil
  457. } else {
  458. return nil, err
  459. }
  460. } else {
  461. if vm.ID > 0 {
  462. //缓存数据
  463. schedual_detail_str, err := json.Marshal(vm)
  464. if err == nil {
  465. redis.Set(key, schedual_detail_str, time.Second*60*60*18)
  466. }
  467. } else {
  468. redis.Set(key, "null", time.Second*60*60*18)
  469. }
  470. return &vm, nil
  471. }
  472. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  473. if schedual_detail_str == "null" {
  474. return &vm, nil
  475. }
  476. json.Unmarshal([]byte(schedual_detail_str), &vm)
  477. return &vm, nil
  478. }
  479. }
  480. // 用户排班信息
  481. func MobileGetPatientSchedual(orgID int64, patientID int64, schedualDate int64) (*models.Schedule, error) {
  482. var schedule models.Schedule
  483. err := readDb.
  484. Table("xt_schedule").
  485. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  486. First(&schedule).Error
  487. if err != nil {
  488. if err == gorm.ErrRecordNotFound {
  489. return nil, nil
  490. } else {
  491. return nil, err
  492. }
  493. }
  494. return &schedule, nil
  495. }
  496. type MPatient struct {
  497. ID int64 `gorm:"column:id" json:"id" form:"id"`
  498. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  499. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  500. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  501. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  502. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
  503. AdmissionNumber string `gorm:"column:admission_number" json:"admission_number" form:"admission_number"`
  504. Source int64 `gorm:"column:source" json:"source" form:"source"`
  505. Lapseto int64 `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
  506. PartitionId int64 `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
  507. BedId int64 `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
  508. Name string `gorm:"column:name" json:"name" form:"name"`
  509. Alias string `gorm:"column:alias" json:"alias" form:"alias"`
  510. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  511. Nation string `gorm:"column:nation" json:"nation" form:"nation"`
  512. NativePlace string `gorm:"column:native_place" json:"native_place" form:"native_place"`
  513. MaritalStatus int64 `gorm:"column:marital_status" json:"marital_status" form:"marital_status"`
  514. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  515. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  516. ReimbursementWayId int64 `gorm:"column:reimbursement_way_id" json:"reimbursement_way_id" form:"reimbursement_way_id"`
  517. HealthCareType int64 `gorm:"column:health_care_type" json:"health_care_type" form:"health_care_type"`
  518. HealthCareNo string `gorm:"column:health_care_no" json:"health_care_no" form:"health_care_no"`
  519. HealthCareDueDate int64 `gorm:"column:health_care_due_date" json:"health_care_due_date" form:"health_care_due_date"`
  520. Height int64 `gorm:"column:height" json:"height" form:"height"`
  521. BloodType int64 `gorm:"column:blood_type" json:"blood_type" form:"blood_type"`
  522. Rh int64 `gorm:"column:rh" json:"rh" form:"rh"`
  523. HealthCareDueAlertDate int64 `gorm:"column:health_care_due_alert_date" json:"health_care_due_alert_date" form:"health_care_due_alert_date"`
  524. EducationLevel int64 `gorm:"column:education_level" json:"education_level" form:"education_level"`
  525. Profession int64 `gorm:"column:profession" json:"profession" form:"profession"`
  526. Phone string `gorm:"column:phone" json:"phone" form:"phone"`
  527. HomeTelephone string `gorm:"column:home_telephone" json:"home_telephone" form:"home_telephone"`
  528. RelativePhone string `gorm:"column:relative_phone" json:"relative_phone" form:"relative_phone"`
  529. RelativeRelations string `gorm:"column:relative_relations" json:"relative_relations" form:"relative_relations"`
  530. HomeAddress string `gorm:"column:home_address" json:"home_address" form:"home_address"`
  531. WorkUnit string `gorm:"column:work_unit" json:"work_unit" form:"work_unit"`
  532. UnitAddress string `gorm:"column:unit_address" json:"unit_address" form:"unit_address"`
  533. Children int64 `gorm:"column:children" json:"children" form:"children"`
  534. ReceivingDate int64 `gorm:"column:receiving_date" json:"receiving_date" form:"receiving_date"`
  535. IsHospitalFirstDialysis int64 `gorm:"column:is_hospital_first_dialysis" json:"is_hospital_first_dialysis" form:"is_hospital_first_dialysis"`
  536. FirstDialysisDate int64 `gorm:"column:first_dialysis_date" json:"first_dialysis_date" form:"first_dialysis_date"`
  537. FirstDialysisHospital string `gorm:"column:first_dialysis_hospital" json:"first_dialysis_hospital" form:"first_dialysis_hospital"`
  538. InductionPeriod int64 `gorm:"column:induction_period" json:"induction_period" form:"induction_period"`
  539. InitialDialysis int64 `gorm:"column:initial_dialysis" json:"initial_dialysis" form:"initial_dialysis"`
  540. TotalDialysis int64 `gorm:"column:total_dialysis" json:"total_dialysis" form:"total_dialysis"`
  541. AttendingDoctorId int64 `gorm:"column:attending_doctor_id" json:"attending_doctor_id" form:"attending_doctor_id"`
  542. HeadNurseId int64 `gorm:"column:head_nurse_id" json:"head_nurse_id" form:"head_nurse_id"`
  543. Evaluate string `gorm:"column:evaluate" json:"evaluate" form:"evaluate"`
  544. Diagnose string `gorm:"column:diagnose" json:"diagnose" form:"diagnose"`
  545. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  546. RegistrarsId int64 `gorm:"column:registrars_id" json:"registrars_id" form:"registrars_id"`
  547. Registrars string `gorm:"column:registrars" json:"registrars" form:"registrars"`
  548. QrCode string `gorm:"column:qr_code" json:"qr_code" form:"qr_code"`
  549. BindingState int64 `gorm:"column:binding_state" json:"binding_state" form:"binding_state"`
  550. PatientComplains string `gorm:"column:patient_complains" json:"patient_complains"` // 主诉
  551. PresentHistory string `gorm:"column:present_history" json:"present_history"` // 现病史
  552. PastHistory string `gorm:"column:past_history" json:"past_history"` // 既往史
  553. Temperature float64 `gorm:"column:temperature" json:"temperature"` // 体格检查-体温
  554. Pulse int64 `gorm:"column:pulse" json:"pulse"` // 体格检查-脉搏
  555. Respiratory int64 `gorm:"column:respiratory" json:"respiratory"` // 体格检查-呼吸频率
  556. SBP int64 `gorm:"column:sbp" json:"sbp"` // 体格检查-收缩压
  557. DBP int64 `gorm:"column:dbp" json:"dbp"` // 体格检查-舒张压
  558. Status int64 `gorm:"column:status" json:"status" form:"status"`
  559. Age int64 `gorm:"column:age" json:"age"`
  560. IsOpenRemind int64 `gorm:"column:is_open_remind" json:"is_open_remind"`
  561. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  562. DialysisAge int64 `gorm:"column:dialysis_age" json:"dialysis_age" form:"dialysis_age"`
  563. ExpenseKind int64 `gorm:"column:expense_kind" json:"expense_kind" form:"expense_kind"`
  564. TellPhone string `gorm:"column:tell_phone" json:"tell_phone" form:"tell_phone"`
  565. FirstTreatmentDate int64 `gorm:"column:first_treatment_date" json:"first_treatment_date" form:"first_treatment_date"`
  566. ContactName string `gorm:"column:contact_name" json:"contact_name" form:"contact_name"`
  567. UserSysBeforeCount int64 `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
  568. }
  569. func (MPatient) TableName() string {
  570. return "xt_patients"
  571. }
  572. // 接诊评估
  573. func MobileGetReceiverTreatmentAccessRecord(orgID int64, patientID int64, recordDate int64) (*models.ReceiveTreatmentAsses, error) {
  574. var record models.ReceiveTreatmentAsses
  575. redis := RedisClient()
  576. defer redis.Close()
  577. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":receive_treatment_asses"
  578. receive_treatment_asses_str, _ := redis.Get(key).Result()
  579. if len(receive_treatment_asses_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  580. err = readDb.Model(&models.ReceiveTreatmentAsses{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  581. if err != nil {
  582. if err == gorm.ErrRecordNotFound {
  583. if record.ID <= 0 {
  584. redis.Set(key, "", time.Second*60*60*18)
  585. }
  586. return nil, nil
  587. } else {
  588. return nil, err
  589. }
  590. } else {
  591. if record.ID > 0 {
  592. //缓存数据
  593. receive_treatment_asses_str, err := json.Marshal(record)
  594. if err == nil {
  595. redis.Set(key, receive_treatment_asses_str, time.Second*60*60*18)
  596. }
  597. } else {
  598. redis.Set(key, "null", time.Second*60*60*18)
  599. }
  600. return &record, nil
  601. }
  602. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  603. if receive_treatment_asses_str == "null" {
  604. return &record, nil
  605. }
  606. json.Unmarshal([]byte(receive_treatment_asses_str), &record)
  607. return &record, nil
  608. }
  609. }
  610. // 透前评估
  611. func MobileGetPredialysisEvaluationOne(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
  612. var record models.PredialysisEvaluation
  613. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  614. if err != nil {
  615. if err == gorm.ErrRecordNotFound {
  616. return nil, nil
  617. } else {
  618. return nil, err
  619. }
  620. }
  621. return &record, nil
  622. }
  623. func MobileGetPredialysisEvaluationTwo(orgID int64, patientID int64, recordDate int64) (models.PredialysisEvaluation, error) {
  624. var record models.PredialysisEvaluation
  625. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  626. return record, err
  627. }
  628. // 透前评估
  629. func MobileGetPredialysisEvaluation(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
  630. var record models.PredialysisEvaluation
  631. redis := RedisClient()
  632. defer redis.Close()
  633. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":assessment_before_dislysis"
  634. assessment_before_dislysis_str, _ := redis.Get(key).Result()
  635. redis.Set(key, "", time.Second)
  636. if len(assessment_before_dislysis_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  637. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  638. if err != nil {
  639. if err == gorm.ErrRecordNotFound {
  640. if record.ID <= 0 {
  641. redis.Set(key, "", time.Second*60*60*18)
  642. }
  643. return nil, nil
  644. } else {
  645. return nil, err
  646. }
  647. } else {
  648. if record.ID > 0 {
  649. //缓存数据
  650. assessment_before_dislysis_str, err := json.Marshal(record)
  651. if err == nil {
  652. redis.Set(key, assessment_before_dislysis_str, time.Second*60*60*18)
  653. }
  654. } else {
  655. redis.Set(key, "null", time.Second*60*60*18)
  656. }
  657. return &record, nil
  658. }
  659. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  660. if assessment_before_dislysis_str == "null" {
  661. return &record, nil
  662. } else {
  663. json.Unmarshal([]byte(assessment_before_dislysis_str), &record)
  664. return &record, nil
  665. }
  666. }
  667. }
  668. // 获取 maxDate 之前一次的透前评估记录
  669. func MobileGetLastTimePredialysisEvaluationOne(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
  670. var record models.PredialysisEvaluation
  671. 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
  672. if err != nil {
  673. if err == gorm.ErrRecordNotFound {
  674. return nil, nil
  675. } else {
  676. return nil, err
  677. }
  678. }
  679. return &record, nil
  680. }
  681. // 获取 maxDate 之前一次的透前评估记录
  682. func MobileGetLastTimePredialysisEvaluation(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
  683. var record models.PredialysisEvaluation
  684. redis := RedisClient()
  685. defer redis.Close()
  686. // cur_date := time.Now().Format("2006-01-02")
  687. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(maxDate, 10) + ":assessment_before_dislysis_last"
  688. assessment_before_dislysis_last_str, _ := redis.Get(key).Result()
  689. if len(assessment_before_dislysis_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  690. 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
  691. if err != nil {
  692. if err == gorm.ErrRecordNotFound {
  693. if record.ID <= 0 {
  694. redis.Set(key, "", time.Second*60*60*18)
  695. }
  696. return nil, nil
  697. } else {
  698. return nil, err
  699. }
  700. } else {
  701. if record.ID > 0 {
  702. //缓存数据
  703. assessment_before_dislysis_last_str, err := json.Marshal(record)
  704. if err == nil {
  705. redis.Set(key, assessment_before_dislysis_last_str, time.Second*60*60*4)
  706. }
  707. } else {
  708. redis.Set(key, "null", time.Second*60*60*18)
  709. }
  710. return &record, nil
  711. }
  712. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  713. if assessment_before_dislysis_last_str == "null" {
  714. return &record, nil
  715. } else {
  716. json.Unmarshal([]byte(assessment_before_dislysis_last_str), &record)
  717. return &record, nil
  718. }
  719. }
  720. }
  721. // 临时医嘱
  722. func MobileGetDoctorAdvices(orgID int64, patientID int64, recordDate int64) ([]*models.DoctorAdvice, error) {
  723. var records []*models.DoctorAdvice
  724. // err := readDb.Model(&models.DoctorAdvice{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).Find(&records).Error
  725. err := readDb.
  726. Model(&models.DoctorAdvice{}).
  727. Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? and (advice_type = 2 or advice_type = 3)", patientID, orgID, recordDate).
  728. 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").
  729. Order("start_time asc, groupno desc, advice_order desc, id").
  730. Scan(&records).Error
  731. if err != nil {
  732. return nil, err
  733. }
  734. return records, nil
  735. }
  736. func MobileGetDoctorAdvicesByGroups(orgID int64, patientID int64, recordDate int64) ([]*models.DoctorAdvice, error) {
  737. var records []*models.DoctorAdvice
  738. redis := RedisClient()
  739. defer redis.Close()
  740. // cur_date := time.Now().Format("2006-01-02")
  741. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":doctor_advices"
  742. //fmt.Println("key23233232323323wi", key)
  743. redis.Set(key, "", time.Second)
  744. doctor_advices_str, _ := redis.Get(key).Result()
  745. if len(doctor_advices_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  746. err := readDb.Model(&models.DoctorAdvice{}).
  747. Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? and (advice_type = 2 || advice_type = 3)", patientID, orgID, recordDate).
  748. 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").
  749. Order("start_time asc, groupno desc, advice_order desc, id asc").
  750. Scan(&records).Error
  751. if err != nil {
  752. if err == gorm.ErrRecordNotFound {
  753. if len(records) <= 0 {
  754. redis.Set(key, "", time.Second*60*60*18)
  755. }
  756. return nil, nil
  757. } else {
  758. return nil, err
  759. }
  760. } else {
  761. if len(records) > 0 {
  762. //缓存数据
  763. doctor_advices_str, err := json.Marshal(records)
  764. if err == nil {
  765. redis.Set(key, doctor_advices_str, time.Second*60*60*18)
  766. return records, nil
  767. }
  768. } else {
  769. redis.Set(key, "null", time.Second*60*60*18)
  770. return records, nil
  771. }
  772. return records, nil
  773. }
  774. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  775. if doctor_advices_str == "null" {
  776. return records, nil
  777. } else {
  778. json.Unmarshal([]byte(doctor_advices_str), &records)
  779. return records, nil
  780. }
  781. }
  782. }
  783. // 透析记录
  784. func MobileGetSchedualDialysisRecordTen(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  785. var record models.DialysisOrder
  786. 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
  787. if err != nil {
  788. if err == gorm.ErrRecordNotFound {
  789. return nil, nil
  790. } else {
  791. return nil, err
  792. }
  793. }
  794. return &record, nil
  795. }
  796. //func MobileGetSchedualDialysisRecord(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  797. // var record models.DialysisOrder
  798. //
  799. // 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
  800. //
  801. //
  802. // return &record,err
  803. //}
  804. // 透析记录
  805. func MobileGetSchedualDialysisRecord(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  806. var record models.DialysisOrder
  807. redis := RedisClient()
  808. defer redis.Close()
  809. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":dialysis_order"
  810. dialysis_order_str, _ := redis.Get(key).Result()
  811. if len(dialysis_order_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  812. 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
  813. if err != nil {
  814. if err == gorm.ErrRecordNotFound {
  815. return nil, nil
  816. } else {
  817. return nil, err
  818. }
  819. } else {
  820. if record.ID > 0 {
  821. //缓存数据
  822. dialysis_order_str, err := json.Marshal(record)
  823. if err == nil {
  824. redis.Set(key, dialysis_order_str, time.Second*60*60*18)
  825. }
  826. } else {
  827. redis.Set(key, "null", time.Second*60*60*18)
  828. }
  829. return &record, nil
  830. }
  831. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  832. if dialysis_order_str == "null" {
  833. 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
  834. return &record, nil
  835. } else {
  836. json.Unmarshal([]byte(dialysis_order_str), &record)
  837. return &record, nil
  838. }
  839. }
  840. }
  841. // 双人核对
  842. func MobileGetDoubleCheck(orgID int64, patientID int64, recordDate int64) (*models.DoubleCheck, error) {
  843. var record models.DoubleCheck
  844. redis := RedisClient()
  845. defer redis.Close()
  846. // cur_date := time.Now().Format("2006-01-02")
  847. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":double_check"
  848. double_check_str, _ := redis.Get(key).Result()
  849. if len(double_check_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  850. err := readDb.Model(&models.DoubleCheck{}).Where("patient_id = ? and user_org_id = ? and status = 1 and check_date = ?", patientID, orgID, recordDate).First(&record).Error
  851. if err != nil {
  852. if err == gorm.ErrRecordNotFound {
  853. if record.ID <= 0 {
  854. redis.Set(key, "null", time.Second*60*60*18)
  855. }
  856. return nil, nil
  857. } else {
  858. return nil, err
  859. }
  860. } else {
  861. if record.ID > 0 {
  862. //缓存数据
  863. double_check_str, err := json.Marshal(record)
  864. if err == nil {
  865. redis.Set(key, double_check_str, time.Second*60*60*18)
  866. }
  867. } else {
  868. redis.Set(key, "null", time.Second*60*60*18)
  869. }
  870. return &record, nil
  871. }
  872. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  873. if double_check_str == "null" {
  874. return &record, nil
  875. } else {
  876. json.Unmarshal([]byte(double_check_str), &record)
  877. return &record, nil
  878. }
  879. }
  880. }
  881. // 透析监测记录
  882. func MobileGetMonitorRecords(orgID int64, patientID int64, recordDate int64) ([]*models.MonitoringRecord, error) {
  883. var records []*models.MonitoringRecord
  884. redis := RedisClient()
  885. defer redis.Close()
  886. // cur_date := time.Now().Format("2006-01-02")
  887. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":monitor_records"
  888. redis.Set(key, "", time.Second)
  889. monitor_records_str, _ := redis.Get(key).Result()
  890. if len(monitor_records_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  891. 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
  892. if err != nil {
  893. if err == gorm.ErrRecordNotFound {
  894. //if len(records) <= 0 {
  895. // redis.Set(key, "null", time.Second*60*60*18)
  896. //}
  897. return nil, nil
  898. } else {
  899. return nil, err
  900. }
  901. } else {
  902. if len(records) > 0 {
  903. //缓存数据
  904. monitor_records_str, err := json.Marshal(records)
  905. if err == nil {
  906. redis.Set(key, monitor_records_str, time.Second*60*60*18)
  907. }
  908. } else {
  909. redis.Set(key, "null", time.Second*60*60*18)
  910. }
  911. return records, nil
  912. }
  913. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  914. if monitor_records_str == "null" {
  915. return records, nil
  916. } else {
  917. json.Unmarshal([]byte(monitor_records_str), &records)
  918. return records, nil
  919. }
  920. }
  921. }
  922. func MobileGetMonitorRecordFirst(orgID int64, patientID int64, recordDate int64) (*models.MonitoringRecord, error) {
  923. var records models.MonitoringRecord
  924. 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
  925. if err != nil {
  926. return nil, err
  927. }
  928. return &records, nil
  929. }
  930. func MobileGetLastMonitorRecordOne(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  931. var record models.MonitoringRecord
  932. 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
  933. if err != nil {
  934. if err == gorm.ErrRecordNotFound {
  935. return nil, nil
  936. } else {
  937. return nil, err
  938. }
  939. }
  940. return &record, nil
  941. }
  942. func MobileGetLastMonitorRecord(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  943. var record models.MonitoringRecord
  944. redis := RedisClient()
  945. defer redis.Close()
  946. // cur_date := time.Now().Format("2006-01-02")
  947. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(beforeDate, 10) + ":monitor_record_last"
  948. monitor_record_last_str, _ := redis.Get(key).Result()
  949. redis.Set(key, "", time.Second)
  950. if len(monitor_record_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  951. 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
  952. if err != nil {
  953. if err == gorm.ErrRecordNotFound {
  954. if record.ID <= 0 {
  955. redis.Set(key, "null", time.Second*60*60*18)
  956. }
  957. return nil, nil
  958. } else {
  959. return nil, err
  960. }
  961. } else {
  962. if record.ID > 0 {
  963. //缓存数据
  964. monitor_record_last_str, err := json.Marshal(record)
  965. if err == nil {
  966. redis.Set(key, monitor_record_last_str, time.Second*60*60*18)
  967. }
  968. } else {
  969. redis.Set(key, "null", time.Second*60*60*18)
  970. }
  971. return &record, nil
  972. }
  973. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  974. if monitor_record_last_str == "null" {
  975. return &record, nil
  976. } else {
  977. json.Unmarshal([]byte(monitor_record_last_str), &record)
  978. return &record, nil
  979. }
  980. }
  981. }
  982. func MobileGetAssessmentAfterDislysisOne(orgID int64, patientID int64, recordDate int64) (*models.AssessmentAfterDislysis, error) {
  983. var record models.AssessmentAfterDislysis
  984. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  985. if err != nil {
  986. if err == gorm.ErrRecordNotFound {
  987. return nil, nil
  988. } else {
  989. return nil, err
  990. }
  991. }
  992. return &record, nil
  993. }
  994. // 透后评估
  995. func MobileGetAssessmentAfterDislysis(orgID int64, patientID int64, recordDate int64) (*models.AssessmentAfterDislysis, error) {
  996. var record models.AssessmentAfterDislysis
  997. redis := RedisClient()
  998. defer redis.Close()
  999. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":assessment_after_dislysis"
  1000. redis.Set(key, "", time.Second)
  1001. assessment_after_dislysis_str, _ := redis.Get(key).Result()
  1002. if len(assessment_after_dislysis_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1003. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  1004. if err != nil {
  1005. if err == gorm.ErrRecordNotFound {
  1006. if record.ID <= 0 {
  1007. redis.Set(key, "null", time.Second*60*60*18)
  1008. }
  1009. return nil, nil
  1010. } else {
  1011. return nil, err
  1012. }
  1013. } else {
  1014. if record.ID > 0 {
  1015. //缓存数据
  1016. assessment_after_dislysis_str, err := json.Marshal(record)
  1017. if err == nil {
  1018. redis.Set(key, assessment_after_dislysis_str, time.Second*60*60*18)
  1019. }
  1020. } else {
  1021. redis.Set(key, "null", time.Second*60*60*18)
  1022. }
  1023. return &record, nil
  1024. }
  1025. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1026. if assessment_after_dislysis_str == "null" {
  1027. return &record, nil
  1028. } else {
  1029. json.Unmarshal([]byte(assessment_after_dislysis_str), &record)
  1030. return &record, nil
  1031. }
  1032. }
  1033. }
  1034. // 获取 maxDate 之前一次的透后评估记录
  1035. func MobileGetLastTimeAssessmentAfterDislysis(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  1036. var record models.AssessmentAfterDislysis
  1037. redis := RedisClient()
  1038. defer redis.Close()
  1039. // cur_date := time.Now().Format("2006-01-02")
  1040. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(maxDate, 10) + ":assessment_after_dislysis_last"
  1041. redis.Set(key, "", time.Second)
  1042. assessment_after_dislysis_last_str, _ := redis.Get(key).Result()
  1043. if len(assessment_after_dislysis_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1044. 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
  1045. if err != nil {
  1046. if err == gorm.ErrRecordNotFound {
  1047. if record.ID <= 0 {
  1048. redis.Set(key, "null", time.Second*60*60*18)
  1049. }
  1050. return nil, nil
  1051. } else {
  1052. return nil, err
  1053. }
  1054. } else {
  1055. if record.ID > 0 {
  1056. //缓存数据
  1057. assessment_after_dislysis_last_str, err := json.Marshal(record)
  1058. if err == nil {
  1059. redis.Set(key, assessment_after_dislysis_last_str, time.Second*60*60*18)
  1060. }
  1061. } else {
  1062. redis.Set(key, "null", time.Second*60*60*18)
  1063. }
  1064. return &record, nil
  1065. }
  1066. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1067. if assessment_after_dislysis_last_str == "null" {
  1068. return &record, nil
  1069. } else {
  1070. json.Unmarshal([]byte(assessment_after_dislysis_last_str), &record)
  1071. return &record, nil
  1072. }
  1073. }
  1074. }
  1075. func MobileGetLastTimeAssessmentAfterDislysisOne(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  1076. var record models.AssessmentAfterDislysis
  1077. 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
  1078. if err != nil {
  1079. if err == gorm.ErrRecordNotFound {
  1080. return nil, nil
  1081. } else {
  1082. return nil, err
  1083. }
  1084. }
  1085. return &record, nil
  1086. }
  1087. func MobileGetLastTimeAssessmentAfterDislysisTwo(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  1088. var record models.AssessmentAfterDislysis
  1089. 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
  1090. return &record, nil
  1091. }
  1092. func MobileGetLast(orgID int64, patientID int64, maxDate int64) (models.AssessmentAfterDislysis, error) {
  1093. dislysis := models.AssessmentAfterDislysis{}
  1094. 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
  1095. return dislysis, err
  1096. }
  1097. // 治疗小结
  1098. func MobileGetTreatmentSummary(orgID int64, patientID int64, recordDate int64) (*models.TreatmentSummary, error) {
  1099. var record models.TreatmentSummary
  1100. redis := RedisClient()
  1101. defer redis.Close()
  1102. // cur_date := time.Now().Format("2006-01-02")
  1103. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":treatment_summary"
  1104. treatment_summary_str, _ := redis.Get(key).Result()
  1105. if len(treatment_summary_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1106. err := readDb.Model(&models.TreatmentSummary{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  1107. if err != nil {
  1108. if err == gorm.ErrRecordNotFound {
  1109. if record.ID <= 0 {
  1110. redis.Set(key, "null", time.Second*60*60*18)
  1111. }
  1112. return nil, nil
  1113. } else {
  1114. return nil, err
  1115. }
  1116. } else {
  1117. if record.ID > 0 {
  1118. //缓存数据
  1119. treatment_summary_str, err := json.Marshal(record)
  1120. if err == nil {
  1121. redis.Set(key, treatment_summary_str, time.Second*60*60*18)
  1122. }
  1123. } else {
  1124. redis.Set(key, "null", time.Second*60*60*18)
  1125. }
  1126. return &record, nil
  1127. }
  1128. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1129. if treatment_summary_str == "null" {
  1130. return &record, nil
  1131. } else {
  1132. json.Unmarshal([]byte(treatment_summary_str), &record)
  1133. return &record, nil
  1134. }
  1135. }
  1136. }
  1137. // 透析处方
  1138. func MobileGetDialysisPrescribe(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  1139. var record models.DialysisPrescription
  1140. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).Find(&record).Error
  1141. if err != nil {
  1142. if err == gorm.ErrRecordNotFound {
  1143. return nil, nil
  1144. } else {
  1145. return nil, err
  1146. }
  1147. }
  1148. return &record, nil
  1149. }
  1150. func MobileGetDialysisPrescribeOne(orgID int64, patientID int64, recordDate int64) (models.DialysisPrescription, error) {
  1151. var record models.DialysisPrescription
  1152. err = readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).Find(&record).Error
  1153. return record, nil
  1154. }
  1155. func UpdateMobileGetDialysisPrescribe(id int64, dewater_amount float64) error {
  1156. err := XTWriteDB().Model(&models.DialysisPrescription{}).Where("id=? and status=1", id).Updates(map[string]interface{}{"target_ultrafiltration": dewater_amount, "prescription_water": dewater_amount}).Error
  1157. return err
  1158. }
  1159. func UpdateMobileGetDialysisPrescribeOne(id int64, dewater_amount float64) error {
  1160. err := XTWriteDB().Model(&models.DialysisPrescription{}).Where("id=? and status=1", id).Updates(map[string]interface{}{"target_ultrafiltration": dewater_amount}).Error
  1161. return err
  1162. }
  1163. func MobileGetDialysisSchedual(orgID int64, patientID int64, scheduleDate int64) (*models.XtSchedule, error) {
  1164. var schedule models.XtSchedule
  1165. err := readDb.Model(&models.XtSchedule{}).Where("patient_id = ? and user_org_id = ? and status = 1 and schedule_date = ?", patientID, orgID, scheduleDate).First(&schedule).Error
  1166. if err != nil {
  1167. if err == gorm.ErrRecordNotFound {
  1168. return nil, nil
  1169. } else {
  1170. return nil, err
  1171. }
  1172. }
  1173. return &schedule, nil
  1174. }
  1175. // 透析方案
  1176. func MobileGetDialysisSolution(orgID int64, patientID int64) (*models.DialysisSolution, error) {
  1177. var record models.DialysisSolution
  1178. err := readDb.Model(&models.DialysisSolution{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  1179. if err != nil {
  1180. if err == gorm.ErrRecordNotFound {
  1181. return nil, nil
  1182. } else {
  1183. return nil, err
  1184. }
  1185. }
  1186. return &record, nil
  1187. }
  1188. func MobileGetPatientById(orgID int64, patientID int64) (*models.Patients, error) {
  1189. var patient models.Patients
  1190. err := readDb.Model(&models.Patients{}).Where("id = ? and user_org_id = ? and status = 1", patientID, orgID).First(&patient).Error
  1191. if err != nil {
  1192. if err == gorm.ErrRecordNotFound {
  1193. return nil, nil
  1194. } else {
  1195. return nil, err
  1196. }
  1197. }
  1198. return &patient, nil
  1199. }
  1200. func DisableMonitor(orgID int64, patientID int64, recordID int64, admin_user_id int64) error {
  1201. fmt.Println()
  1202. tx := writeDb.Begin()
  1203. updateTime := time.Now().Unix()
  1204. 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
  1205. if err != nil {
  1206. tx.Rollback()
  1207. return err
  1208. }
  1209. tx.Commit()
  1210. return nil
  1211. }
  1212. func GetMonitorById(id int64, orgId int64) (models.MonitoringRecord, error) {
  1213. record := models.MonitoringRecord{}
  1214. err := XTReadDB().Where("id = ? and user_org_id =?", id, orgId).Find(&record).Error
  1215. return record, err
  1216. }
  1217. func GetMonitor(orgID int64, patientID int64, id int64) (*models.MonitoringRecord, error) {
  1218. var monitor models.MonitoringRecord
  1219. var err error
  1220. err = readDb.Model(&models.MonitoringRecord{}).Where("id = ? AND user_org_id = ? AND patient_id = ? AND status = 1 ", id, orgID, patientID).Find(&monitor).Error
  1221. if err == gorm.ErrRecordNotFound {
  1222. return nil, nil
  1223. }
  1224. if err != nil {
  1225. return nil, err
  1226. }
  1227. return &monitor, nil
  1228. }
  1229. type MScheduleDoctorAdviceVM struct {
  1230. ID int64 `gorm:"column:id" json:"id"`
  1231. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  1232. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  1233. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  1234. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1235. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  1236. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  1237. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  1238. Status int64 `gorm:"column:status" json:"status"`
  1239. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  1240. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  1241. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  1242. DoctorAdvices []*MDoctorAdviceVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  1243. Prescription *models.DialysisPrescriptionTwenty `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  1244. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  1245. }
  1246. func (MScheduleDoctorAdviceVM) TableName() string {
  1247. return "xt_schedule"
  1248. }
  1249. type MScheduleDoctorAdviceVMOne struct {
  1250. ID int64 `gorm:"column:id" json:"id"`
  1251. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  1252. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  1253. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  1254. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1255. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  1256. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  1257. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  1258. Status int64 `gorm:"column:status" json:"status"`
  1259. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  1260. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  1261. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  1262. DoctorAdvices []*MDoctorAdviceVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  1263. Prescription *models.DialysisPrescriptionTwenty `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  1264. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  1265. }
  1266. func (MScheduleDoctorAdviceVMOne) TableName() string {
  1267. return "xt_schedule"
  1268. }
  1269. type MDoctorAdviceVM struct {
  1270. ID int64 `gorm:"column:id" json:"id"`
  1271. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  1272. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1273. AdviceType int64 `gorm:"column:advice_type" json:"advice_type"`
  1274. AdviceDate int64 `gorm:"column:advice_date" json:"advice_date"`
  1275. StartTime int64 `gorm:"column:start_time" json:"start_time"`
  1276. AdviceName string `gorm:"column:advice_name" json:"advice_name"`
  1277. AdviceDesc string `gorm:"column:advice_desc" json:"advice_desc"`
  1278. ReminderDate int64 `gorm:"column:reminder_date" json:"reminder_date"`
  1279. SingleDose float64 `gorm:"column:single_dose" json:"single_dose"`
  1280. SingleDoseUnit string `gorm:"column:single_dose_unit" json:"single_dose_unit"`
  1281. PrescribingNumber float64 `gorm:"column:prescribing_number" json:"prescribing_number"`
  1282. PrescribingNumberUnit string `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit"`
  1283. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way"`
  1284. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency"`
  1285. AdviceDoctor int64 `gorm:"column:advice_doctor" json:"advice_doctor"`
  1286. Status int64 `gorm:"column:status" json:"status"`
  1287. CreatedTime int64 `gorm:"column:created_time" json:"created_time"`
  1288. UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time"`
  1289. AdviceAffirm string `gorm:"column:advice_affirm" json:"advice_affirm"`
  1290. Remark string `gorm:"column:remark" json:"remark"`
  1291. StopTime int64 `gorm:"column:stop_time" json:"stop_time"`
  1292. StopReason string `gorm:"column:stop_reason" json:"stop_reason"`
  1293. StopDoctor int64 `gorm:"column:stop_doctor" json:"stop_doctor"`
  1294. StopState int64 `gorm:"column:stop_state" json:"stop_state"`
  1295. ParentId int64 `gorm:"column:parent_id" json:"parent_id"`
  1296. ExecutionTime int64 `gorm:"column:execution_time" json:"execution_time"`
  1297. ExecutionStaff int64 `gorm:"column:execution_staff" json:"execution_staff"`
  1298. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state"`
  1299. Checker int64 `gorm:"column:checker" json:"checker"`
  1300. RecordDate int64 `gorm:"column:record_date" json:"record_date"`
  1301. DialysisOrderId int64 `gorm:"column:dialysis_order_id" json:"dialysis_order_id"`
  1302. CheckTime int64 `gorm:"column:check_time" json:"check_time"`
  1303. CheckState int64 `gorm:"column:check_state" json:"check_state"`
  1304. DrugSpec float64 `gorm:"column:drug_spec" json:"drug_spec"`
  1305. DrugSpecUnit string `gorm:"column:drug_spec_unit" json:"drug_spec_unit"`
  1306. Groupno int64 `gorm:"column:groupno" json:"groupno"`
  1307. RemindType int64 `gorm:"column:remind_type" json:"remind_type"`
  1308. FrequencyType int64 `gorm:"column:frequency_type" json:"frequency_type"`
  1309. DayCount int64 `gorm:"column:day_count" json:"day_count"`
  1310. WeekDay string `gorm:"column:week_day" json:"week_day"`
  1311. TemplateId string `gorm:"column:template_id" json:"template_id"`
  1312. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1313. IsMedicine int64 `gorm:"column:is_medicine" json:"is_medicine" form:"is_medicine"`
  1314. IsSettle int64 `gorm:"column:is_settle" json:"is_settle" form:"is_settle"`
  1315. }
  1316. func (MDoctorAdviceVM) TableName() string {
  1317. return "xt_doctor_advice"
  1318. }
  1319. func MobileGetScheduleDoctorAdvices(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string) ([]*MScheduleDoctorAdviceVM, error) {
  1320. var vms []*MScheduleDoctorAdviceVM
  1321. adviceWhere := ""
  1322. adviceCondition := []interface{}{}
  1323. if adviceType == 0 {
  1324. if patientType == 0 {
  1325. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  1326. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1327. } else if patientType == 1 {
  1328. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  1329. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1330. } else if patientType == 2 {
  1331. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  1332. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1333. }
  1334. } else if adviceType == 1 {
  1335. if patientType == 0 {
  1336. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  1337. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1338. } else if patientType == 1 {
  1339. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  1340. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1341. } else if patientType == 2 {
  1342. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  1343. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1344. }
  1345. } else if adviceType == 3 {
  1346. if patientType == 0 {
  1347. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  1348. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1349. } else if patientType == 1 {
  1350. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  1351. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1352. } else if patientType == 2 {
  1353. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  1354. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1355. }
  1356. } else if adviceType == 2 && len(deliverWay) > 0 {
  1357. if patientType == 0 {
  1358. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  1359. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1360. } else if patientType == 1 {
  1361. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  1362. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  1363. } else if patientType == 2 {
  1364. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  1365. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1366. }
  1367. } else if adviceType == 2 && len(deliverWay) <= 0 {
  1368. if patientType == 0 {
  1369. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  1370. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1371. } else if patientType == 1 {
  1372. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND (advice_doctor = ? or execution_staff = ?)"
  1373. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, adminUserId)
  1374. } else if patientType == 2 {
  1375. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  1376. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1377. }
  1378. }
  1379. db := readDb.
  1380. Table("xt_schedule").
  1381. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1382. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1383. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1384. }).
  1385. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1386. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1387. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1388. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  1389. Preload("DoctorAdvices", adviceCondition...).
  1390. Where("status = 1 AND user_org_id = ?", orgID)
  1391. if scheduleDate != 0 {
  1392. db = db.Where("schedule_date = ?", scheduleDate)
  1393. }
  1394. err := db.Find(&vms).Error
  1395. return vms, err
  1396. }
  1397. func MobileGetScheduleDoctorAdvicesTwo(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string) ([]*MScheduleDoctorAdviceVMOne, error) {
  1398. var vms []*MScheduleDoctorAdviceVMOne
  1399. adviceWhere := ""
  1400. adviceCondition := []interface{}{}
  1401. if adviceType == 0 {
  1402. if patientType == 0 {
  1403. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  1404. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1405. } else if patientType == 1 {
  1406. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  1407. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1408. } else if patientType == 2 {
  1409. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  1410. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1411. } else if patientType == 3 {
  1412. 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"
  1413. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1414. } else if patientType == 4 {
  1415. 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)"
  1416. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1417. }
  1418. } else if adviceType == 1 {
  1419. if patientType == 0 {
  1420. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  1421. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1422. } else if patientType == 1 {
  1423. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  1424. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1425. } else if patientType == 2 {
  1426. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  1427. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1428. } else if patientType == 3 {
  1429. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = 1"
  1430. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1431. } else if patientType == 4 {
  1432. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and (is_settle = 0 or is_settle = 2)"
  1433. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1434. }
  1435. } else if adviceType == 3 {
  1436. if patientType == 0 {
  1437. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  1438. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1439. } else if patientType == 1 {
  1440. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  1441. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1442. } else if patientType == 2 {
  1443. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  1444. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1445. } else if patientType == 3 {
  1446. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 and is_settle = 1"
  1447. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1448. } else if patientType == 4 {
  1449. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 and (is_settle = 0 or is_settle = 2)"
  1450. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1451. }
  1452. } else if adviceType == 2 && len(deliverWay) > 0 {
  1453. if patientType == 0 {
  1454. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  1455. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1456. } else if patientType == 1 {
  1457. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  1458. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  1459. } else if patientType == 2 {
  1460. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  1461. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1462. } else if patientType == 3 {
  1463. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 and delivery_way = ? and is_settle = 1"
  1464. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1465. } else if patientType == 4 {
  1466. 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)"
  1467. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1468. }
  1469. } else if adviceType == 2 && len(deliverWay) <= 0 {
  1470. if patientType == 0 {
  1471. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  1472. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1473. } else if patientType == 1 {
  1474. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND (advice_doctor = ? or execution_staff = ?)"
  1475. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, adminUserId)
  1476. } else if patientType == 2 {
  1477. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  1478. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1479. } else if patientType == 3 {
  1480. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 and is_settle = 1"
  1481. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1482. } else if patientType == 4 {
  1483. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 and (is_settle = 0 or is_settle = 2)"
  1484. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1485. }
  1486. }
  1487. db := readDb.
  1488. Table("xt_schedule").
  1489. //Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1490. //Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1491. // return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1492. //}).
  1493. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1494. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1495. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1496. Preload("DoctorAdvices", adviceCondition...).
  1497. Where("status = 1 AND user_org_id = ?", orgID)
  1498. if scheduleDate != 0 {
  1499. db = db.Where("schedule_date = ?", scheduleDate)
  1500. }
  1501. err := db.Find(&vms).Error
  1502. return vms, err
  1503. }
  1504. func GetHisDoctorAdvices(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleDoctorAdviceVM, error) {
  1505. var vms []*HisMScheduleDoctorAdviceVM
  1506. if len(deliverWay) > 0 {
  1507. if patientType == 0 {
  1508. db := readDb.
  1509. Table("xt_schedule").
  1510. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  1511. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1512. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1513. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1514. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1515. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1516. }).
  1517. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1518. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1519. Where("status = 1 AND user_org_id = ?", orgID)
  1520. if scheduleDate != 0 {
  1521. db = db.Where("schedule_date = ?", scheduleDate)
  1522. }
  1523. err = db.Find(&vms).Error
  1524. }
  1525. if patientType > 0 {
  1526. db := readDb.
  1527. Table("xt_schedule").
  1528. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1529. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1530. 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).
  1531. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1532. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1533. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1534. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1535. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1536. }).Where("status = 1 AND user_org_id = ?", orgID)
  1537. if scheduleDate != 0 {
  1538. db = db.Where("schedule_date = ?", scheduleDate)
  1539. }
  1540. err = db.Find(&vms).Error
  1541. }
  1542. } else {
  1543. if patientType == 0 {
  1544. db := readDb.
  1545. Table("xt_schedule").
  1546. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? ", orgID, scheduleDate).
  1547. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1548. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1549. return db.Where("status = 1 AND user_org_id = ? and dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1550. }).
  1551. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1552. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1553. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1554. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1555. Where("status = 1 AND user_org_id = ?", orgID)
  1556. if scheduleDate != 0 {
  1557. db = db.Where("schedule_date = ?", scheduleDate)
  1558. }
  1559. err = db.Find(&vms).Error
  1560. }
  1561. if patientType > 0 {
  1562. db := readDb.
  1563. Table("xt_schedule").
  1564. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1565. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1566. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1567. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1568. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1569. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1570. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1571. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1572. Where("status = 1 AND user_org_id = ?", orgID)
  1573. if scheduleDate != 0 {
  1574. db = db.Where("schedule_date = ?", scheduleDate)
  1575. }
  1576. err = db.Find(&vms).Error
  1577. }
  1578. }
  1579. return vms, err
  1580. }
  1581. func GetHisDoctorAdvicesTwo(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleDoctorAdviceVMOne, error) {
  1582. var vms []*HisMScheduleDoctorAdviceVMOne
  1583. if len(deliverWay) > 0 {
  1584. if patientType == 0 {
  1585. db := readDb.
  1586. Table("xt_schedule").
  1587. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  1588. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1589. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1590. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1591. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1592. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1593. }).
  1594. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1595. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1596. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1597. Where("status = 1 AND user_org_id = ?", orgID)
  1598. if scheduleDate != 0 {
  1599. db = db.Where("schedule_date = ?", scheduleDate)
  1600. }
  1601. err = db.Find(&vms).Error
  1602. }
  1603. if patientType > 0 {
  1604. if patientType == 1 {
  1605. db := readDb.
  1606. Table("xt_schedule").
  1607. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1608. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1609. 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).
  1610. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1611. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1612. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1613. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1614. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1615. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1616. Where("status = 1 AND user_org_id = ?", orgID)
  1617. if scheduleDate != 0 {
  1618. db = db.Where("schedule_date = ?", scheduleDate)
  1619. }
  1620. err = db.Find(&vms).Error
  1621. }
  1622. if patientType == 2 {
  1623. db := readDb.
  1624. Table("xt_schedule").
  1625. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1626. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1627. 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).
  1628. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1629. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1630. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1631. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1632. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1633. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Where("status = 1 AND user_org_id = ?", orgID)
  1634. if scheduleDate != 0 {
  1635. db = db.Where("schedule_date = ?", scheduleDate)
  1636. }
  1637. err = db.Find(&vms).Error
  1638. }
  1639. if patientType == 3 {
  1640. db := readDb.
  1641. Table("xt_schedule").
  1642. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1643. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1644. 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).
  1645. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1646. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1647. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1648. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1649. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1650. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Where("status = 1 AND user_org_id = ?", orgID)
  1651. if scheduleDate != 0 {
  1652. db = db.Where("schedule_date = ?", scheduleDate)
  1653. }
  1654. err = db.Find(&vms).Error
  1655. }
  1656. if patientType == 4 {
  1657. db := readDb.
  1658. Table("xt_schedule").
  1659. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1660. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1661. 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).
  1662. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1663. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1664. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1665. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1666. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1667. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Where("status = 1 AND user_org_id = ?", orgID)
  1668. if scheduleDate != 0 {
  1669. db = db.Where("schedule_date = ?", scheduleDate)
  1670. }
  1671. err = db.Find(&vms).Error
  1672. }
  1673. }
  1674. } else {
  1675. if patientType == 0 {
  1676. db := readDb.
  1677. Table("xt_schedule").
  1678. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? ", orgID, scheduleDate).
  1679. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1680. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1681. return db.Where("status = 1 AND user_org_id = ? and dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1682. }).
  1683. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1684. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1685. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1686. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1687. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1688. Where("status = 1 AND user_org_id = ?", orgID)
  1689. if scheduleDate != 0 {
  1690. db = db.Where("schedule_date = ?", scheduleDate)
  1691. }
  1692. err = db.Find(&vms).Error
  1693. }
  1694. if patientType > 0 {
  1695. if patientType == 1 {
  1696. db := readDb.
  1697. Table("xt_schedule").
  1698. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1699. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1700. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1701. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1702. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1703. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1704. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1705. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1706. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1707. Where("status = 1 AND user_org_id = ?", orgID)
  1708. if scheduleDate != 0 {
  1709. db = db.Where("schedule_date = ?", scheduleDate)
  1710. }
  1711. err = db.Find(&vms).Error
  1712. }
  1713. if patientType == 2 {
  1714. db := readDb.
  1715. Table("xt_schedule").
  1716. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1717. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1718. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1719. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1720. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1721. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1722. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1723. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1724. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1725. Where("status = 1 AND user_org_id = ?", orgID)
  1726. if scheduleDate != 0 {
  1727. db = db.Where("schedule_date = ?", scheduleDate)
  1728. }
  1729. err = db.Find(&vms).Error
  1730. }
  1731. if patientType == 3 {
  1732. db := readDb.
  1733. Table("xt_schedule").
  1734. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1735. 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).
  1736. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1737. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1738. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1739. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1740. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1741. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1742. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1743. Where("status = 1 AND user_org_id = ?", orgID)
  1744. if scheduleDate != 0 {
  1745. db = db.Where("schedule_date = ?", scheduleDate)
  1746. }
  1747. err = db.Find(&vms).Error
  1748. }
  1749. if patientType == 4 {
  1750. db := readDb.
  1751. Table("xt_schedule").
  1752. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1753. 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).
  1754. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1755. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1756. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1757. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1758. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1759. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1760. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1761. Where("status = 1 AND user_org_id = ?", orgID)
  1762. if scheduleDate != 0 {
  1763. db = db.Where("schedule_date = ?", scheduleDate)
  1764. }
  1765. err = db.Find(&vms).Error
  1766. }
  1767. }
  1768. }
  1769. return vms, err
  1770. }
  1771. func GetMobileHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleProjectVM, error) {
  1772. var vms []*HisMScheduleProjectVM
  1773. //if patientType == 0 {
  1774. // db := readDb.
  1775. // Table("xt_schedule").
  1776. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1777. // Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1778. // return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1779. // }).
  1780. // Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1781. // Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1782. // Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1783. // Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1784. // return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1785. // }).
  1786. // Where("status = 1 AND user_org_id = ?", orgID)
  1787. // if scheduleDate != 0 {
  1788. // db = db.Where("schedule_date = ?", scheduleDate)
  1789. // }
  1790. // err = db.Find(&vms).Error
  1791. //}
  1792. //if patientType > 0 {
  1793. // db := readDb.
  1794. // Table("xt_schedule").
  1795. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1796. // Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1797. // return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1798. // }).
  1799. // Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1800. // Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1801. // Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1802. // Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1803. // Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1804. // return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1805. // }).
  1806. // Where("status = 1 AND user_org_id = ?", orgID)
  1807. // if scheduleDate != 0 {
  1808. // db = db.Where("schedule_date = ?", scheduleDate)
  1809. // }
  1810. // err = db.Find(&vms).Error
  1811. //}
  1812. db := readDb.Table("xt_schedule").Where("status = 1")
  1813. if orgID > 0 {
  1814. db = db.Where("user_org_id = ?", orgID)
  1815. }
  1816. if scheduleDate > 0 {
  1817. db = db.Where("schedule_date =?", scheduleDate)
  1818. }
  1819. err = db.Find(&vms).Error
  1820. if patientType == 0 {
  1821. db := readDb.
  1822. Table("xt_schedule").
  1823. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1824. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1825. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1826. }).
  1827. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1828. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1829. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1830. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1831. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1832. }).
  1833. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  1834. 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")
  1835. }).
  1836. Where("status = 1 AND user_org_id = ?", orgID)
  1837. if scheduleDate != 0 {
  1838. db = db.Where("schedule_date = ?", scheduleDate)
  1839. }
  1840. err = db.Find(&vms).Error
  1841. }
  1842. if patientType > 0 {
  1843. db := readDb.
  1844. Table("xt_schedule").
  1845. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1846. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1847. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1848. }).
  1849. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1850. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1851. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1852. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1853. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1854. }).
  1855. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  1856. 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")
  1857. }).
  1858. Where("status = 1 AND user_org_id = ?", orgID)
  1859. if scheduleDate != 0 {
  1860. db = db.Where("schedule_date = ?", scheduleDate)
  1861. }
  1862. err = db.Find(&vms).Error
  1863. }
  1864. return vms, err
  1865. }
  1866. func MobileCreateDialysisOrder(orgID int64, patientID int64, order *models.DialysisOrder) error {
  1867. now := time.Now()
  1868. tx := writeDb.Begin()
  1869. if createOrderErr := tx.Model(&models.DialysisOrder{}).Create(order).Error; createOrderErr != nil {
  1870. tx.Rollback()
  1871. return createOrderErr
  1872. }
  1873. // 更新透析记录 ID
  1874. // 透析处方
  1875. 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 {
  1876. tx.Rollback()
  1877. return err
  1878. }
  1879. // 接诊评估
  1880. 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 {
  1881. tx.Rollback()
  1882. return err
  1883. }
  1884. // 透前评估
  1885. 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 {
  1886. tx.Rollback()
  1887. return err
  1888. }
  1889. // 临时医嘱
  1890. 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 {
  1891. tx.Rollback()
  1892. return err
  1893. }
  1894. // 双人核对
  1895. 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 {
  1896. tx.Rollback()
  1897. return err
  1898. }
  1899. // 透后评估
  1900. 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 {
  1901. tx.Rollback()
  1902. return err
  1903. }
  1904. // 治疗小结
  1905. 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 {
  1906. tx.Rollback()
  1907. return err
  1908. }
  1909. // 透析监测
  1910. 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 {
  1911. tx.Rollback()
  1912. return err
  1913. }
  1914. tx.Commit()
  1915. return nil
  1916. }
  1917. type MobileUrgentSchedulePatientVM struct {
  1918. ID int64 `gorm:"column:id" json:"id"`
  1919. Name string `gorm:"column:name" json:"name"`
  1920. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no"`
  1921. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  1922. }
  1923. func (MobileUrgentSchedulePatientVM) TableName() string {
  1924. return "xt_patients"
  1925. }
  1926. type MobileUrgentScheduleTreatmentModeVM struct {
  1927. ID int64 `gorm:"column:id" json:"id"`
  1928. Name string `gorm:"column:name" json:"name"`
  1929. }
  1930. func (MobileUrgentScheduleTreatmentModeVM) TableName() string {
  1931. return "xt_treatment_mode"
  1932. }
  1933. func MobileGetAllPatientsForUrgentSchedule(orgID int64, record_date int64) ([]*MobileUrgentSchedulePatientVM, error) {
  1934. var vms []*MobileUrgentSchedulePatientVM = make([]*MobileUrgentSchedulePatientVM, 0)
  1935. 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 p.patient_type =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()
  1936. defer rows.Close()
  1937. if err != nil {
  1938. return nil, err
  1939. }
  1940. for rows.Next() {
  1941. var vm MobileUrgentSchedulePatientVM
  1942. readDb.ScanRows(rows, &vm)
  1943. vms = append(vms, &vm)
  1944. }
  1945. return vms, nil
  1946. }
  1947. func MobileGetAllTrearmentModesForUrgentSchedule() ([]*MobileUrgentScheduleTreatmentModeVM, error) {
  1948. var modes []*MobileUrgentScheduleTreatmentModeVM
  1949. err := readDb.Model(&MobileUrgentScheduleTreatmentModeVM{}).Where("status = 1").Find(&modes).Error
  1950. if err != nil {
  1951. return nil, err
  1952. }
  1953. return modes, nil
  1954. }
  1955. type MobileUrgentScheduleScheduleListVM struct {
  1956. ID int64 `gorm:"column:id" json:"id"`
  1957. // ZoneID int64 `gorm:"column:partition_id" json:"zone_id"`
  1958. DeviceNumberID int64 `gorm:"column:bed_id" json:"bed_id"`
  1959. PatientID int64 `gorm:"column:patient_id" json:"patient_id"`
  1960. ScheduleType int `gorm:"column:schedule_type" json:"schedule_type"`
  1961. DeviceNumber *models.DeviceNumber `gorm:"ForeignKey:DeviceNumberID" json:"device_number"`
  1962. // DeviceZone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"device_zone"`
  1963. }
  1964. func (MobileUrgentScheduleScheduleListVM) TableName() string {
  1965. return "xt_schedule"
  1966. }
  1967. func MobileGetSchedulesForUrgentSchedule(orgID int64, scheduleDate int64, schedule_type int) (schedules []*MobileUrgentScheduleScheduleListVM, err error) {
  1968. db := readDb.
  1969. Model(&MobileUrgentScheduleScheduleListVM{}).
  1970. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1971. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND schedule_type = ? ", orgID, scheduleDate, schedule_type)
  1972. err = db.Find(&schedules).Error
  1973. if err != nil {
  1974. return nil, err
  1975. }
  1976. return schedules, nil
  1977. }
  1978. func MobileGetOtherSchedulesForUrgentSchedule(orgID int64, scheduleDate int64, schedule_type int) ([]*MobileUrgentScheduleScheduleListVM, error) {
  1979. var vms []*MobileUrgentScheduleScheduleListVM = make([]*MobileUrgentScheduleScheduleListVM, 0)
  1980. 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()
  1981. defer rows.Close()
  1982. if err != nil {
  1983. return nil, err
  1984. }
  1985. for rows.Next() {
  1986. var vm MobileUrgentScheduleScheduleListVM
  1987. readDb.ScanRows(rows, &vm)
  1988. vms = append(vms, &vm)
  1989. }
  1990. return vms, nil
  1991. }
  1992. type MobileUrgentScheduleDeviceNumberVM struct {
  1993. ID int64 `gorm:"column:id" json:"id"`
  1994. Number string `gorm:"column:number" json:"number"`
  1995. ZoneID int64 `gorm:"column:zone_id" json:"zone_id"`
  1996. Zone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"zone"`
  1997. }
  1998. func (MobileUrgentScheduleDeviceNumberVM) TableName() string {
  1999. return "xt_device_number"
  2000. }
  2001. func MobileGetAllDeviceNumbersForUrgentSchedule(orgID int64, record_date int64, schedule_type int) ([]*DeviceNumberViewModel, error) {
  2002. var vms []*DeviceNumberViewModel = make([]*DeviceNumberViewModel, 0)
  2003. 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()
  2004. defer rows.Close()
  2005. if err != nil {
  2006. return nil, err
  2007. }
  2008. for rows.Next() {
  2009. var vm DeviceNumberViewModel
  2010. readDb.ScanRows(rows, &vm)
  2011. vms = append(vms, &vm)
  2012. }
  2013. return vms, nil
  2014. //var deviceNumbers []*MobileUrgentScheduleDeviceNumberVM
  2015. //db := readDb.
  2016. // Model(&MobileUrgentScheduleDeviceNumberVM{}).
  2017. // Preload("Zone", "status = 1 AND org_id = ?", orgID).
  2018. // Where("status = 1 AND org_id = ?", orgID)
  2019. //err := db.Order("zone_id asc").Find(&deviceNumbers).Error
  2020. //if err != nil {
  2021. // return nil, err
  2022. //}
  2023. //return deviceNumbers, nil
  2024. }
  2025. func GetValidScheduleMonitorRecordCount() (int64, error) {
  2026. var total int64
  2027. err := readDb.Model(&models.MonitoringRecord{}).Where("status = 1 AND operate_time = 0 AND monitoring_date <> 0").Count(&total).Error
  2028. return total, err
  2029. }
  2030. func GetTop1000ValidScheduleMonitorRecord() ([]*models.MonitoringRecord, error) {
  2031. var monitors []*models.MonitoringRecord
  2032. err := readDb.Model(&models.MonitoringRecord{}).Where("status = 1 AND operate_time = 0 AND monitoring_date <> 0").Order("id asc").Limit(100).Find(&monitors).Error
  2033. if err != nil {
  2034. return nil, err
  2035. }
  2036. return monitors, nil
  2037. }
  2038. func BatchUpdateMonitors(monitors []*models.MonitoringRecord) error {
  2039. tx := writeDb.Begin()
  2040. for index := 0; index < len(monitors); index++ {
  2041. tx.Save(monitors[index])
  2042. }
  2043. return tx.Commit().Error
  2044. }
  2045. func ModifyStartDialysisOrder(order *models.DialysisOrder) error {
  2046. tx := writeDb.Begin()
  2047. updateTime := time.Now().Unix()
  2048. 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
  2049. if err != nil {
  2050. tx.Rollback()
  2051. return err
  2052. }
  2053. tx.Commit()
  2054. return err
  2055. }
  2056. func UpdateScheduleByBedId(patient_id int64, schedule_date int64, bed_id int64, schedule_type int64, zone_id int64) error {
  2057. 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
  2058. return err
  2059. }
  2060. func ModifyFinishDialysisOrder(order *models.DialysisOrder) error {
  2061. tx := writeDb.Begin()
  2062. updateTime := time.Now().Unix()
  2063. 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
  2064. if err != nil {
  2065. tx.Rollback()
  2066. return err
  2067. }
  2068. tx.Commit()
  2069. return err
  2070. }
  2071. func MobileGetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  2072. var record models.SgjPatientDryweight
  2073. err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  2074. if err != nil {
  2075. if err == gorm.ErrRecordNotFound {
  2076. return nil, nil
  2077. } else {
  2078. return nil, err
  2079. }
  2080. }
  2081. return &record, nil
  2082. }
  2083. //func MobileGetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  2084. // var record models.SgjPatientDryweight
  2085. // redis := RedisClient()
  2086. // defer redis.Close()
  2087. //
  2088. // key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":last_dry_weight"
  2089. // last_dry_weight_str, _ := redis.Get(key).Result()
  2090. //
  2091. // if len(last_dry_weight_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2092. // err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  2093. // if err != nil {
  2094. // if err == gorm.ErrRecordNotFound {
  2095. // if record.ID <= 0 {
  2096. // redis.Set(key, "null", time.Second*60*60*18)
  2097. // }
  2098. // return nil, nil
  2099. // } else {
  2100. // return nil, err
  2101. // }
  2102. // } else {
  2103. // if record.ID > 0 {
  2104. // //缓存数据
  2105. // last_dry_weight_str, err := json.Marshal(record)
  2106. // if err == nil {
  2107. // redis.Set(key, last_dry_weight_str, time.Second*60*60*18)
  2108. // return nil, err
  2109. // }
  2110. // } else {
  2111. // redis.Set(key, "null", time.Second*60*60*18)
  2112. // return nil, err
  2113. // }
  2114. // return &record, nil
  2115. // }
  2116. // } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2117. // if last_dry_weight_str == "null" {
  2118. // return &record, nil
  2119. // } else {
  2120. // json.Unmarshal([]byte(last_dry_weight_str), &record)
  2121. // return &record, nil
  2122. // }
  2123. //
  2124. // }
  2125. //}
  2126. // 透析方案
  2127. func MobileGetDialysisSolutionByModeIdSix(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  2128. var record models.DialysisSolution
  2129. 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
  2130. if err != nil {
  2131. if err == gorm.ErrRecordNotFound {
  2132. return nil, nil
  2133. } else {
  2134. return nil, err
  2135. }
  2136. }
  2137. return &record, nil
  2138. }
  2139. // 透析方案
  2140. func MobileGetDialysisSolutionByModeIdSevenTwety(orgID int64, patientID int64, mode_id int64) (models.DialysisSolution, error) {
  2141. var record models.DialysisSolution
  2142. 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
  2143. return record, nil
  2144. }
  2145. // 透析方案
  2146. func MobileGetDialysisSolutionByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  2147. var record models.DialysisSolution
  2148. redis := RedisClient()
  2149. defer redis.Close()
  2150. // cur_date := time.Now().Format("2006-01-02")
  2151. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2152. dialysis_solution_str, _ := redis.Get(key).Result()
  2153. redis.Set(key, "", time.Second*60)
  2154. if len(dialysis_solution_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2155. 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
  2156. if err != nil {
  2157. if err == gorm.ErrRecordNotFound {
  2158. if record.ID <= 0 {
  2159. redis.Set(key, "null", time.Second*60*60*18)
  2160. }
  2161. return nil, nil
  2162. } else {
  2163. return nil, err
  2164. }
  2165. } else {
  2166. if record.ID > 0 {
  2167. //缓存数据
  2168. dialysis_solution_str, err := json.Marshal(record)
  2169. if err == nil {
  2170. redis.Set(key, dialysis_solution_str, time.Second*60*60*18)
  2171. }
  2172. } else {
  2173. redis.Set(key, "null", time.Second*60*60*18)
  2174. }
  2175. return &record, nil
  2176. }
  2177. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2178. if dialysis_solution_str == "null" {
  2179. return &record, nil
  2180. } else {
  2181. json.Unmarshal([]byte(dialysis_solution_str), &record)
  2182. return &record, nil
  2183. }
  2184. }
  2185. }
  2186. // 透析处方
  2187. func MobileGetDialysisPrescribeByModeId(orgID int64, patientID int64, recordDate int64, mode_id int64) (*models.DialysisPrescription, error) {
  2188. var record models.DialysisPrescription
  2189. redis := RedisClient()
  2190. defer redis.Close()
  2191. // cur_date := time.Now().Format("2006-01-02")
  2192. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2193. redis.Set(key, "", time.Second)
  2194. dialysis_prescribe_str, _ := redis.Get(key).Result()
  2195. if len(dialysis_prescribe_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2196. 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
  2197. if err != nil {
  2198. if err == gorm.ErrRecordNotFound {
  2199. if record.ID <= 0 {
  2200. redis.Set(key, "null", time.Second*60*60*18)
  2201. }
  2202. return nil, nil
  2203. } else {
  2204. return nil, err
  2205. }
  2206. } else {
  2207. if record.ID > 0 {
  2208. //缓存数据
  2209. dialysis_prescribe_str, err := json.Marshal(record)
  2210. if err == nil {
  2211. redis.Set(key, dialysis_prescribe_str, time.Second*60*60*18)
  2212. }
  2213. } else {
  2214. redis.Set(key, "null", time.Second*60*60*18)
  2215. }
  2216. return &record, nil
  2217. }
  2218. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2219. if dialysis_prescribe_str == "null" {
  2220. return &record, nil
  2221. } else {
  2222. json.Unmarshal([]byte(dialysis_prescribe_str), &record)
  2223. return &record, nil
  2224. }
  2225. }
  2226. }
  2227. func MobileGetDialysisPrescribeByModeIdSix(orgID int64, patientID int64, recordDate int64, mode_id int64) (*models.DialysisPrescription, error) {
  2228. var record models.DialysisPrescription
  2229. 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
  2230. if err != nil {
  2231. if err == gorm.ErrRecordNotFound {
  2232. return nil, nil
  2233. } else {
  2234. return nil, err
  2235. }
  2236. }
  2237. return &record, nil
  2238. }
  2239. func MobileGetDialysisPrescribeByModeIdOne(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  2240. var record models.DialysisPrescription
  2241. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  2242. if err != nil {
  2243. if err == gorm.ErrRecordNotFound {
  2244. return nil, nil
  2245. } else {
  2246. return nil, err
  2247. }
  2248. }
  2249. return &record, nil
  2250. }
  2251. //func MobileGetDialysisPrescribeByModeIdOne(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  2252. // var record models.DialysisPrescription
  2253. // redis := RedisClient()
  2254. // defer redis.Close()
  2255. //
  2256. // // cur_date := time.Now().Format("2006-01-02")
  2257. // key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":dialysis_prescribe_by_mode"
  2258. // dialysis_prescribe_by_mode_str, _ := redis.Get(key).Result()
  2259. //
  2260. // if len(dialysis_prescribe_by_mode_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2261. // err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  2262. // if err != nil {
  2263. // if err == gorm.ErrRecordNotFound {
  2264. // if record.ID <= 0 {
  2265. // redis.Set(key, "null", time.Second*60*60*18)
  2266. // }
  2267. // return nil, nil
  2268. // } else {
  2269. // return nil, err
  2270. // }
  2271. // } else {
  2272. //
  2273. // if record.ID > 0 {
  2274. // //缓存数据
  2275. // dialysis_prescribe_by_mode_str, err := json.Marshal(record)
  2276. //
  2277. // if err == nil {
  2278. // redis.Set(key, dialysis_prescribe_by_mode_str, time.Second*60*60*18)
  2279. // return nil, err
  2280. // }
  2281. // } else {
  2282. // redis.Set(key, "null", time.Second*60*60*18)
  2283. // return nil, err
  2284. // }
  2285. // return &record, nil
  2286. // }
  2287. // } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2288. // if dialysis_prescribe_by_mode_str == "null" {
  2289. // json.Unmarshal([]byte(dialysis_prescribe_by_mode_str), &record)
  2290. // return &record, nil
  2291. // } else {
  2292. // json.Unmarshal([]byte(dialysis_prescribe_by_mode_str), &record)
  2293. // return &record, nil
  2294. // }
  2295. //
  2296. // }
  2297. //}
  2298. func MobileGetLastDialysisPrescribe(orgID int64, patientID int64) (*models.DialysisPrescription, error) {
  2299. var record models.DialysisPrescription
  2300. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 ", patientID, orgID).Last(&record).Error
  2301. if err != nil {
  2302. if err == gorm.ErrRecordNotFound {
  2303. return nil, nil
  2304. } else {
  2305. return nil, err
  2306. }
  2307. }
  2308. return &record, nil
  2309. }
  2310. func MobileGetLastDialysisPrescribeByModeIdSix(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2311. var record models.DialysisPrescription
  2312. 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
  2313. //if err != nil {
  2314. // if err == gorm.ErrRecordNotFound {
  2315. // return nil, nil
  2316. // } else {
  2317. // return nil, err
  2318. // }
  2319. //}
  2320. return &record, err
  2321. }
  2322. func MobileGetLastDialysisPrescribeByModeIdTen(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2323. var record models.DialysisPrescription
  2324. 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
  2325. if err != nil {
  2326. if err == gorm.ErrRecordNotFound {
  2327. return nil, nil
  2328. } else {
  2329. return nil, err
  2330. }
  2331. }
  2332. return &record, err
  2333. }
  2334. func MobileGetLastDialysisPrescribeByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2335. var record models.DialysisPrescription
  2336. redis := RedisClient()
  2337. defer redis.Close()
  2338. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  2339. dialysis_prescribe_by_mode_id, _ := redis.Get(key).Result()
  2340. if len(dialysis_prescribe_by_mode_id) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2341. 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
  2342. if err != nil {
  2343. if err == gorm.ErrRecordNotFound {
  2344. if record.ID <= 0 {
  2345. redis.Set(key, "null", time.Second*60*60*18)
  2346. }
  2347. return nil, nil
  2348. } else {
  2349. return nil, err
  2350. }
  2351. } else {
  2352. if record.ID > 0 {
  2353. //缓存数据
  2354. dialysis_prescribe_by_mode_str, err := json.Marshal(record)
  2355. if err == nil {
  2356. redis.Set(key, dialysis_prescribe_by_mode_str, time.Second*60*60*18)
  2357. return nil, err
  2358. }
  2359. } else {
  2360. redis.Set(key, "null", time.Second*60*60*18)
  2361. return nil, err
  2362. }
  2363. return &record, nil
  2364. }
  2365. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2366. if dialysis_prescribe_by_mode_id == "null" {
  2367. return &record, nil
  2368. } else {
  2369. json.Unmarshal([]byte(dialysis_prescribe_by_mode_id), &record)
  2370. return &record, nil
  2371. }
  2372. }
  2373. }
  2374. func MobileGetLastDialysisPrescribeByModeIdOne(orgID int64, patientID int64, mode_id int64) (models.DialysisPrescription, error) {
  2375. var record models.DialysisPrescription
  2376. 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
  2377. return record, err
  2378. }
  2379. func GetAllAvaildDeviceNumbers(orgID int64, record_date int64, schedule_type int) ([]*DeviceNumberViewModel, error) {
  2380. var vms []*DeviceNumberViewModel = make([]*DeviceNumberViewModel, 0)
  2381. 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()
  2382. defer rows.Close()
  2383. if err != nil {
  2384. return nil, err
  2385. }
  2386. for rows.Next() {
  2387. var vm DeviceNumberViewModel
  2388. readDb.ScanRows(rows, &vm)
  2389. vms = append(vms, &vm)
  2390. }
  2391. return vms, nil
  2392. }
  2393. // 获取 maxDate 之前一次的透前评估记录
  2394. func GetLastTimePredialysisEvaluation(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
  2395. var record models.PredialysisEvaluation
  2396. 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
  2397. if err != nil {
  2398. if err == gorm.ErrRecordNotFound {
  2399. return nil, nil
  2400. } else {
  2401. return nil, err
  2402. }
  2403. }
  2404. return &record, nil
  2405. }
  2406. func GetLastTimeOrder(orgID int64, patientID int64, maxDate int64) (*models.DialysisOrder, error) {
  2407. var record models.DialysisOrder
  2408. 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
  2409. if err != nil {
  2410. if err == gorm.ErrRecordNotFound {
  2411. return nil, nil
  2412. } else {
  2413. return nil, err
  2414. }
  2415. }
  2416. return &record, nil
  2417. }
  2418. func GetLastMonitorRecord(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  2419. var record models.MonitoringRecord
  2420. 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
  2421. if err != nil {
  2422. if err == gorm.ErrRecordNotFound {
  2423. return nil, nil
  2424. } else {
  2425. return nil, err
  2426. }
  2427. }
  2428. return &record, nil
  2429. }
  2430. func GetLastMonitorRecordTwenty(orgID int64, patientID int64, beforeDate int64) (models.MonitoringRecord, error) {
  2431. var record models.MonitoringRecord
  2432. 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
  2433. return record, nil
  2434. }
  2435. func GetLastMonitorRecordTwentyOne(orgID int64, patientID int64, beforeDate int64) (models.MonitoringRecord, error) {
  2436. var record models.MonitoringRecord
  2437. 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
  2438. return record, nil
  2439. }
  2440. func GetLastMonitorRecordTwentyTwo(orgID int64, patientID int64, beforeDate int64) (models.MonitoringRecord, error) {
  2441. var record models.MonitoringRecord
  2442. 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
  2443. return record, nil
  2444. }
  2445. func GetLastMonitorRecordTwentyThree(orgID int64, patientID int64, beforeDate int64) (models.MonitoringRecord, error) {
  2446. var record models.MonitoringRecord
  2447. 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
  2448. return record, nil
  2449. }
  2450. func GetLastMonitorRecordTwentyFour(orgID int64, patientID int64, beforeDate int64) (models.MonitoringRecord, error) {
  2451. var record models.MonitoringRecord
  2452. 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
  2453. return record, nil
  2454. }
  2455. // 获取 maxDate 之前一次的透后评估记录
  2456. func GetLastTimeAssessmentAfterDislysis(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  2457. var record models.AssessmentAfterDislysis
  2458. 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
  2459. if err != nil {
  2460. if err == gorm.ErrRecordNotFound {
  2461. return nil, nil
  2462. } else {
  2463. return nil, err
  2464. }
  2465. }
  2466. return &record, nil
  2467. }
  2468. // 透析处方
  2469. func GetDialysisPrescribe(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  2470. var record models.DialysisPrescription
  2471. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  2472. if err != nil {
  2473. if err == gorm.ErrRecordNotFound {
  2474. return nil, nil
  2475. } else {
  2476. return nil, err
  2477. }
  2478. }
  2479. return &record, nil
  2480. }
  2481. func GetDialysisPrescribeOne(orgID int64, patientID int64, recordDate int64) (models.DialysisPrescription, error) {
  2482. var record models.DialysisPrescription
  2483. err = readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  2484. return record, err
  2485. }
  2486. // 透析方案
  2487. func GetDialysisSolution(orgID int64, patientID int64, mode_id int64) (models.DialysisSolution, error) {
  2488. var record models.DialysisSolution
  2489. 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
  2490. return record, err
  2491. }
  2492. func GetDialysisSolutionOne(orgID int64, mode_id int64) (*models.DialysisSolution, error) {
  2493. var record models.DialysisSolution
  2494. err := readDb.Model(&models.DialysisSolution{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2495. if err != nil {
  2496. if err == gorm.ErrRecordNotFound {
  2497. return nil, nil
  2498. } else {
  2499. return nil, err
  2500. }
  2501. }
  2502. return &record, nil
  2503. }
  2504. func GetLastDialysisPrescribeByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2505. var record models.DialysisPrescription
  2506. 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
  2507. if err != nil {
  2508. if err == gorm.ErrRecordNotFound {
  2509. return nil, nil
  2510. } else {
  2511. return nil, err
  2512. }
  2513. }
  2514. return &record, nil
  2515. }
  2516. func GetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  2517. var record models.SgjPatientDryweight
  2518. err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  2519. if err != nil {
  2520. if err == gorm.ErrRecordNotFound {
  2521. return nil, nil
  2522. } else {
  2523. return nil, err
  2524. }
  2525. }
  2526. return &record, nil
  2527. }
  2528. func MobileGetSystemDialysisPrescribeByModeIdSix(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2529. var record models.SystemPrescription
  2530. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).First(&record).Error
  2531. if err != nil {
  2532. if err == gorm.ErrRecordNotFound {
  2533. return nil, nil
  2534. } else {
  2535. return nil, err
  2536. }
  2537. }
  2538. return &record, nil
  2539. }
  2540. func MobileGetSystemDialysisPrescribeByModeId(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2541. var record models.SystemPrescription
  2542. redis := RedisClient()
  2543. defer redis.Close()
  2544. // cur_date := time.Now().Format("2006-01-02")
  2545. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  2546. system_dialysis_prescribe_str, _ := redis.Get(key).Result()
  2547. if len(system_dialysis_prescribe_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2548. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2549. if err != nil {
  2550. if err == gorm.ErrRecordNotFound {
  2551. if record.ID <= 0 {
  2552. redis.Set(key, "null", time.Second*60*60*18)
  2553. }
  2554. return nil, nil
  2555. } else {
  2556. return nil, err
  2557. }
  2558. } else {
  2559. if record.ID > 0 {
  2560. //缓存数据
  2561. system_dialysis_prescribe_str, err := json.Marshal(record)
  2562. if err == nil {
  2563. redis.Set(key, system_dialysis_prescribe_str, time.Second*60*60*18)
  2564. }
  2565. } else {
  2566. redis.Set(key, "null", time.Second*60*60*18)
  2567. }
  2568. return &record, nil
  2569. }
  2570. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2571. if system_dialysis_prescribe_str == "null" {
  2572. return &record, nil
  2573. } else {
  2574. json.Unmarshal([]byte(system_dialysis_prescribe_str), &record)
  2575. return &record, nil
  2576. }
  2577. }
  2578. }
  2579. func MobileGetSystemDialysisPrescribeByModeIdOne(orgID int64, mode_id int64) (models.SystemPrescription, error) {
  2580. var record models.SystemPrescription
  2581. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2582. return record, err
  2583. }
  2584. func GetSystemDialysisPrescribeByModeId(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2585. var record models.SystemPrescription
  2586. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2587. if err != nil {
  2588. if err == gorm.ErrRecordNotFound {
  2589. return nil, nil
  2590. } else {
  2591. return nil, err
  2592. }
  2593. }
  2594. return &record, nil
  2595. }
  2596. func GetDialysisOrderCount(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2597. 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
  2598. return
  2599. }
  2600. func GetDialysisOrderCountOne(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2601. 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
  2602. return
  2603. }
  2604. func GetDialysisOrderCountTwo(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2605. err = readDb.Model(&models.DialysisOrder{}).Where("dialysis_date>=1735660800 and dialysis_date <= ? AND status = 1 AND stage = 2 AND user_org_id = ? AND patient_id = ?", recordDate, orgID, patient_id).Count(&count).Error
  2606. return
  2607. }
  2608. func GetFirstDateOfMonth(d time.Time) time.Time {
  2609. d = d.AddDate(0, 0, -d.Day()+1)
  2610. return GetZeroTime(d)
  2611. }
  2612. func GetZeroTime(d time.Time) time.Time {
  2613. return time.Date(d.Year(), d.Month(), d.Day(), 0, 0, 0, 0, d.Location())
  2614. }
  2615. func GetDialysisCountByPatientId(startime int64, endtime int64, patientid int64, orgid int64) (order []*models.BloodDialysisOrderCount, err error) {
  2616. db := XTReadDB().Table("xt_dialysis_order as o")
  2617. 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
  2618. return order, err
  2619. }
  2620. func FindConsumablesByDate(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error) {
  2621. 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
  2622. return
  2623. }
  2624. func FindConsumablesByDateTwo(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error) {
  2625. 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
  2626. return
  2627. }
  2628. func FindConsumablesByDateThree(orgID int64, patient_id int64, recordDate int64) (consumables []*models.BloodAutomaticReduceDetail, err error) {
  2629. 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
  2630. return
  2631. }
  2632. func FindHisPrescription(orgID int64, patient_id int64, recordDate int64) (project []*models.HisPrescriptionProject, err error) {
  2633. 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
  2634. return
  2635. }
  2636. //func FindLastConsumables(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error){
  2637. // 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
  2638. // return
  2639. //}
  2640. //
  2641. func GetLastTimeConsumables(orgID int64, patientID int64, maxDate int64) (prepare []*models.DialysisBeforePrepare, err error) {
  2642. 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
  2643. return
  2644. }
  2645. type GoodsType struct {
  2646. ID int64 `gorm:"column:id" json:"id"`
  2647. TypeName string `gorm:"column:type_name" json:"type_name"`
  2648. Remark string `gorm:"column:remark" json:"remark"`
  2649. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2650. Status int64 `gorm:"column:status" json:"status"`
  2651. Type int64 `gorm:"column:type" json:"type"`
  2652. }
  2653. func (GoodsType) TableName() string {
  2654. return "xt_goods_type"
  2655. }
  2656. type VMGoodInfo struct {
  2657. ID int64 `gorm:"column:id" json:"id"`
  2658. SpecificationName string `gorm:"column:specification_name" json:"specification_name"`
  2659. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2660. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2661. GoodName string `gorm:"column:good_name" json:"good_name" form:"good_name"`
  2662. GoodUnit int64 `gorm:"column:good_unit" json:"good_unit" form:"good_unit"`
  2663. Total float64 `gorm:"column:total" json:"total" form:"total"`
  2664. PackingUnit string `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
  2665. MedicalInsuranceNumber string `gorm:"column:medical_insurance_number" json:"medical_insurance_number" form:"medical_insurance_number"`
  2666. }
  2667. func (VMGoodInfo) TableName() string {
  2668. return "xt_good_information"
  2669. }
  2670. type AutomaticReduceDetail struct {
  2671. ID int64 `gorm:"column:id" json:"id"`
  2672. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2673. Status int64 `gorm:"column:status" json:"status"`
  2674. RecordTime int64 `gorm:"column:record_time" json:"record_time"`
  2675. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2676. GoodId int64 `gorm:"column:good_id" json:"good_id"`
  2677. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2678. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"info"`
  2679. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"type"`
  2680. Count int64 `gorm:"column:count" json:"count"`
  2681. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  2682. }
  2683. func (AutomaticReduceDetail) TableName() string {
  2684. return "xt_automatic_reduce_detail"
  2685. }
  2686. type DialysisBeforePrepare struct {
  2687. ID int64 `gorm:"column:id" json:"id" form:"id"`
  2688. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  2689. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  2690. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  2691. GoodId int64 `gorm:"column:good_id" json:"good_id" form:"good_id"`
  2692. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id" form:"good_type_id"`
  2693. Count int64 `gorm:"column:count" json:"count" form:"count"`
  2694. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  2695. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  2696. Creater int64 `gorm:"column:creater" json:"creater" form:"creater"`
  2697. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  2698. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"info"`
  2699. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"type"`
  2700. }
  2701. func (DialysisBeforePrepare) TableName() string {
  2702. return "dialysis_before_prepare"
  2703. }
  2704. type MDialysisGoodsVM struct {
  2705. ID int64 `gorm:"column:id" json:"id"`
  2706. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2707. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2708. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2709. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2710. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2711. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2712. ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week"`
  2713. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2714. Status int64 `gorm:"column:status" json:"status"`
  2715. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2716. SchedualPatient *MSchedualPatientVMList `gorm:"ForeignKey:PatientId" json:"patient"`
  2717. AutomaticReduceDetail []*AutomaticReduceDetail `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"good_user"`
  2718. LastAutomaticReduceDetail []*AutomaticReduceDetail `gorm:"-" json:"last_good_user"`
  2719. DialysisBeforePrepare []*DialysisBeforePrepare `gorm:"ForeignKey:PatientId,ScheduleDate;AssociationForeignKey:PatientId,RecordDate" json:"good_user_detail"`
  2720. LastDialysisBeforePrepare []*DialysisBeforePrepare `gorm:"-" json:"last_good_user_detail"`
  2721. Project []*models.HisPrescriptionProject `gorm:"-" json:"project"`
  2722. //WarehouseOutInfo []*models.WarehouseOutInfoSeven `gorm:"ForeignKey:PatientId,ScheduleDate;AssociationForeignKey:PatientId,SysRecordTime" json:"ware_house_out_info"`
  2723. DialysisPrescription models.DialysisPrescriptionListSix `gorm:"ForeignKey:PatientId,ModeId;AssociationForeignKey:PatientId,ModeId" json:"prescription"`
  2724. }
  2725. func (MDialysisGoodsVM) TableName() string {
  2726. return "xt_schedule"
  2727. }
  2728. type VMWarehouseOutInfo struct {
  2729. ID int64 `gorm:"column:id" json:"id"`
  2730. WarehouseOutId int64 `gorm:"column:warehouse_out_id" json:"warehouse_out_id"`
  2731. GoodId int64 `gorm:"column:good_id" json:"good_id"`
  2732. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2733. Count int64 `gorm:"column:count" json:"count"`
  2734. Price float64 `gorm:"column:price" json:"price"`
  2735. TotalPrice float64 `gorm:"column:total_price" json:"total_price"`
  2736. Status int64 `gorm:"column:status" json:"status"`
  2737. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2738. WarehouseOutOrderNumber string `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number"`
  2739. GoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"good_info"`
  2740. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"good_type"`
  2741. IsSys int64 `gorm:"column:is_sys" json:"is_sys"`
  2742. SysRecordTime int64 `gorm:"column:sys_record_time" json:"sys_record_time"`
  2743. Mtime int64 `gorm:"column:mtime" json:"mtime"`
  2744. Ctime int64 `gorm:"column:ctime" json:"ctime"`
  2745. }
  2746. func (VMWarehouseOutInfo) TableName() string {
  2747. return "xt_warehouse_out_info"
  2748. }
  2749. type DialysisGoodsDate struct {
  2750. RecordDate int64
  2751. }
  2752. type DialysisGoodsDetailDate struct {
  2753. RecordTime int64
  2754. }
  2755. 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) {
  2756. var vms []*MDialysisGoodsVM
  2757. var total int64
  2758. db := readDb.
  2759. Table("xt_schedule as sch").
  2760. Preload("DialysisPrescription", "status=1 and user_org_id =? and solution_status = 1", orgID).
  2761. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  2762. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2763. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2764. Preload("DialysisBeforePrepare", 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 user_org_id = ? AND record_date = ? AND count > 0 ", orgID, scheduleDate)
  2766. }).
  2767. Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
  2768. 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")
  2769. }).Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
  2770. if scheduleDate != 0 {
  2771. db = db.Where("schedule_date = ?", scheduleDate)
  2772. }
  2773. if schedule_type != 0 {
  2774. db = db.Where("schedule_type = ?", schedule_type)
  2775. }
  2776. if partition_id != 0 {
  2777. db = db.Where("partition_id = ?", partition_id)
  2778. }
  2779. if patient_id != 0 {
  2780. db = db.Where("patient_id = ?", patient_id)
  2781. }
  2782. err := db.Find(&vms).Error
  2783. return vms, err, total
  2784. }
  2785. func GetLastDialysisGoods(patient_id int64, orgID int64, record_time int64) (goodUser []*AutomaticReduceDetail, err error) {
  2786. var Id []*DialysisGoodsDetailDate
  2787. 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
  2788. if len(Id) > 0 {
  2789. 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
  2790. }
  2791. return
  2792. }
  2793. func GetLastDialysisBeforePrepare(patient_id int64, orgID int64, record_time int64) (goodUser []*DialysisBeforePrepare, err error) {
  2794. var Id []*DialysisGoodsDate
  2795. 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
  2796. if len(Id) > 0 {
  2797. 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
  2798. }
  2799. return
  2800. }
  2801. func GetPatientAutoMatic(patient_id int64, orgID int64, record_time int64, good_id int64) (auto []*models.AutomaticReduceDetail, err error) {
  2802. 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
  2803. return auto, err
  2804. }
  2805. func GetAllWarehouseOutSumList(patient_id int64, orgID int64, record_time int64) (info []*models.WarehouseOutInfoSeven, err error) {
  2806. 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
  2807. return info, err
  2808. }
  2809. func MobileGetGoodsStatistics(orgID int64, start_time int64, end_time int64) (list []*models.StockInfo, err error) {
  2810. db := readDb.Model(&models.StockInfo{})
  2811. db = db.Where("xt_good_information.org_id = ? AND xt_good_information.status = 1", orgID)
  2812. 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")
  2813. db = db.Preload("QueryWarehouseOutInfo", func(db *gorm.DB) *gorm.DB {
  2814. 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)
  2815. })
  2816. db = db.Preload("GoodsType", "org_id = ? AND status = 1", orgID)
  2817. err = db.Order("ctime desc").Find(&list).Error
  2818. return
  2819. }
  2820. 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) {
  2821. var vms []*MDialysisGoodsVM
  2822. var total int64
  2823. db := readDb.
  2824. Model(&models.Schedule{}).
  2825. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  2826. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2827. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2828. Preload("DialysisBeforePrepare", func(db *gorm.DB) *gorm.DB {
  2829. 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)
  2830. }).Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
  2831. 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)
  2832. }).Where("xt_schedule.status = 1 AND xt_schedule.user_org_id = ?", orgID)
  2833. if scheduleDate != 0 {
  2834. db = db.Where("schedule_date = ?", scheduleDate)
  2835. }
  2836. if patient_id != 0 {
  2837. db = db.Where("patient_id = ?", patient_id)
  2838. }
  2839. if len(keywords) != 0 {
  2840. keywords = "%" + keywords + "%"
  2841. 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)
  2842. if schedule_type != 0 {
  2843. db = db.Where("schedule_type = ?", schedule_type)
  2844. }
  2845. if partition_id != 0 {
  2846. db = db.Where("partition_id = ?", partition_id)
  2847. }
  2848. if good_type == 1 {
  2849. db = db.Where("patient_id in(?)", ids)
  2850. }
  2851. if good_type == 2 {
  2852. if len(ids) > 0 {
  2853. db = db.Where("patient_id not in(?)", ids)
  2854. }
  2855. }
  2856. } else {
  2857. if schedule_type != 0 {
  2858. db = db.Where("schedule_type = ?", schedule_type)
  2859. }
  2860. if partition_id != 0 {
  2861. db = db.Where("partition_id = ?", partition_id)
  2862. }
  2863. if good_type == 1 {
  2864. db = db.Where("patient_id in(?)", ids)
  2865. }
  2866. if good_type == 2 {
  2867. if len(ids) > 0 {
  2868. db = db.Where("patient_id not in(?)", ids)
  2869. }
  2870. }
  2871. db = db.Count(&total)
  2872. offset := (page - 1) * limit
  2873. db = db.Offset(offset).Limit(limit)
  2874. }
  2875. err := db.Find(&vms).Error
  2876. return vms, err, total
  2877. }
  2878. func GetLastDialysisGoodsTwo(patient_id int64, orgID int64, record_time int64) (goodUser []*AutomaticReduceDetail, err error) {
  2879. var Id []*DialysisGoodsDetailDate
  2880. 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
  2881. if len(Id) > 0 {
  2882. 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
  2883. }
  2884. return
  2885. }
  2886. func GetLastDialysisBeforePrepareTwo(patient_id int64, orgID int64, record_time int64) (goodUser []*DialysisBeforePrepare, err error) {
  2887. var Id []*DialysisGoodsDate
  2888. 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
  2889. if len(Id) > 0 {
  2890. 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
  2891. }
  2892. return
  2893. }
  2894. func GetAssessmentBefor(orgid int64, patientid int64, recorddate int64) (*models.PredialysisEvaluation, error) {
  2895. evaluation := models.PredialysisEvaluation{}
  2896. err := XTReadDB().Model(&evaluation).Where("user_org_id = ? and patient_id = ? and assessment_date = ? and status = 1", orgid, patientid, recorddate).Find(&evaluation).Error
  2897. if err == gorm.ErrRecordNotFound {
  2898. return nil, err
  2899. }
  2900. if err != nil {
  2901. return nil, err
  2902. }
  2903. return &evaluation, nil
  2904. }
  2905. func GetAssessmentBeforThrity(orgid int64, patientid int64, recorddate int64) (models.PredialysisEvaluation, error) {
  2906. evaluation := models.PredialysisEvaluation{}
  2907. err := XTReadDB().Model(&evaluation).Where("user_org_id = ? and patient_id = ? and assessment_date = ? and status = 1", orgid, patientid, recorddate).Find(&evaluation).Error
  2908. return evaluation, err
  2909. }
  2910. func GetAssessmentBeforFourty(orgid int64, patientid int64, recorddate int64) (models.XtAssessmentBeforeDislysis, error) {
  2911. evaluation := models.XtAssessmentBeforeDislysis{}
  2912. err := XTReadDB().Model(&evaluation).Where("user_org_id = ? and patient_id = ? and assessment_date = ? and status = 1", orgid, patientid, recorddate).Find(&evaluation).Error
  2913. return evaluation, err
  2914. }
  2915. func GetHisPrescriptionTemplateList(user_org_id int64, patient_id int64, mode_id int64) (models.HisPrescriptionTemplateSix, error) {
  2916. templateSix := models.HisPrescriptionTemplateSix{}
  2917. 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 {
  2918. return db.Where("status = 1 AND user_org_id = ? and type =2", user_org_id).Preload("HisPrescriptionProjectTemplateSeven", func(db *gorm.DB) *gorm.DB {
  2919. 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)
  2920. })
  2921. }).Find(&templateSix).Error
  2922. return templateSix, err
  2923. }
  2924. func GetAllHisDoctorAdvice(orgid int64, patientid int64, recorddate int64) (his []*models.HisDoctorAdviceInfo, err error) {
  2925. redis := RedisClient()
  2926. defer redis.Close()
  2927. key := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patientid, 10) + ":" + strconv.FormatInt(recorddate, 10) + ":his_doctor_advice"
  2928. his_doctor_advice_str, _ := redis.Get(key).Result()
  2929. redis.Set(key, "", time.Second)
  2930. if orgid != 10721 {
  2931. if len(his_doctor_advice_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2932. 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
  2933. if err != nil {
  2934. if err == gorm.ErrRecordNotFound {
  2935. if len(his) <= 0 {
  2936. redis.Set(key, "null", time.Second*60*60*18)
  2937. }
  2938. return his, nil
  2939. } else {
  2940. return his, err
  2941. }
  2942. } else {
  2943. if len(his) > 0 {
  2944. //缓存数据
  2945. his_doctor_advice_str, err := json.Marshal(his)
  2946. if err == nil {
  2947. redis.Set(key, his_doctor_advice_str, time.Second*60*60*18)
  2948. }
  2949. } else {
  2950. redis.Set(key, "null", time.Second*60*60*18)
  2951. }
  2952. return his, nil
  2953. }
  2954. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2955. json.Unmarshal([]byte(his_doctor_advice_str), &his)
  2956. return his, nil
  2957. }
  2958. }
  2959. if orgid == 10721 {
  2960. if len(his_doctor_advice_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2961. var keyword = "胰岛素"
  2962. keyword = "%" + keyword + "%"
  2963. 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
  2964. if err != nil {
  2965. if err == gorm.ErrRecordNotFound {
  2966. if len(his) <= 0 {
  2967. redis.Set(key, "null", time.Second*60*60*18)
  2968. }
  2969. return his, nil
  2970. } else {
  2971. return his, err
  2972. }
  2973. } else {
  2974. if len(his) > 0 {
  2975. //缓存数据
  2976. his_doctor_advice_str, err := json.Marshal(his)
  2977. if err == nil {
  2978. redis.Set(key, his_doctor_advice_str, time.Second*60*60*18)
  2979. }
  2980. } else {
  2981. redis.Set(key, "null", time.Second*60*60*18)
  2982. }
  2983. return his, nil
  2984. }
  2985. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2986. json.Unmarshal([]byte(his_doctor_advice_str), &his)
  2987. return his, nil
  2988. }
  2989. }
  2990. return his, nil
  2991. }
  2992. func GetLastDialysisPrescriptionByPatientId(orgid int64, patientid int64, recorddate int64) (*models.DialysisPrescription, error) {
  2993. prescription := models.DialysisPrescription{}
  2994. err := readDb.Model(&models.DialysisPrescription{}).Where("user_org_id = ? and patient_id = ? and record_date = ? and status = 1", orgid, patientid, recorddate).Find(&prescription).Error
  2995. if err == gorm.ErrRecordNotFound {
  2996. return nil, err
  2997. }
  2998. if err != nil {
  2999. return nil, err
  3000. }
  3001. return &prescription, nil
  3002. }
  3003. func GetLastDialysisPrescriptionByPatientIdTwo(orgid int64, patientid int64, recorddate int64) (models.DialysisPrescription, error) {
  3004. prescription := models.DialysisPrescription{}
  3005. err := readDb.Model(&models.DialysisPrescription{}).Where("user_org_id = ? and patient_id = ? and record_date = ? and status = 1", orgid, patientid, recorddate).Find(&prescription).Error
  3006. return prescription, err
  3007. }
  3008. type HisMScheduleDoctorAdviceVM struct {
  3009. ID int64 `gorm:"column:id" json:"id"`
  3010. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  3011. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  3012. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  3013. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  3014. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  3015. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  3016. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  3017. Status int64 `gorm:"column:status" json:"status"`
  3018. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  3019. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  3020. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  3021. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  3022. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  3023. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  3024. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  3025. }
  3026. func (HisMScheduleDoctorAdviceVM) TableName() string {
  3027. return "xt_schedule"
  3028. }
  3029. type HisMScheduleDoctorAdviceVMOne struct {
  3030. ID int64 `gorm:"column:id" json:"id"`
  3031. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  3032. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  3033. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  3034. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  3035. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  3036. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  3037. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  3038. Status int64 `gorm:"column:status" json:"status"`
  3039. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  3040. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  3041. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  3042. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  3043. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  3044. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  3045. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  3046. }
  3047. func (HisMScheduleDoctorAdviceVMOne) TableName() string {
  3048. return "xt_schedule"
  3049. }
  3050. type HisMScheduleProjectVM struct {
  3051. ID int64 `gorm:"column:id" json:"id"`
  3052. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  3053. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  3054. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  3055. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  3056. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  3057. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  3058. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  3059. Status int64 `gorm:"column:status" json:"status"`
  3060. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  3061. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  3062. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  3063. Prescription *models.DialysisPrescriptionTwenty `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  3064. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  3065. HisPrescriptionTeamProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"team_project"`
  3066. }
  3067. func (HisMScheduleProjectVM) TableName() string {
  3068. return "xt_schedule"
  3069. }
  3070. func GetHisDoctorConfig(orgid int64) (models.XtHisConfig, error) {
  3071. config := models.XtHisConfig{}
  3072. err := XTReadDB().Model(&config).Where("user_org_id = ? and status =1", orgid).Find(&config).Error
  3073. return config, err
  3074. }
  3075. func GetHisDoctorPatientById(orgid int64, patientid int64, recordtime int64) (advice []*models.HisDoctorAdviceInfo, err error) {
  3076. db := XTReadDB().Table("his_doctor_advice_info as x").Where("x.status = 1")
  3077. if orgid > 0 {
  3078. db = db.Where("x.user_org_id = ?", orgid)
  3079. }
  3080. if patientid > 0 {
  3081. db = db.Where("x.patient_id =?", patientid)
  3082. }
  3083. if recordtime > 0 {
  3084. db = db.Where("x.advice_date = ?", recordtime)
  3085. }
  3086. 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
  3087. return advice, err
  3088. }
  3089. func GetDoctorAdviceCount(startime int64, endtime int64, deliveway string, orgid int64) (advice []*models.BloodDoctorAdvice, err error) {
  3090. db := XTReadDB().Table("xt_doctor_advice as x").Where("x.status = 1 and x.advice_type =2")
  3091. if startime > 0 {
  3092. db = db.Where("x.advice_date >= ?", startime)
  3093. }
  3094. if endtime > 0 {
  3095. db = db.Where("x.advice_date<=?", endtime)
  3096. }
  3097. if orgid > 0 {
  3098. db = db.Where("x.user_org_id = ?", orgid)
  3099. }
  3100. if len(deliveway) > 0 {
  3101. db = db.Where("x.delivery_way = ?", deliveway)
  3102. }
  3103. 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
  3104. return advice, err
  3105. }
  3106. func GetHisDoctorAdviceCount(startime int64, endtime int64, deliveway string, orgid int64) (advice []*models.BloodDoctorAdvice, err error) {
  3107. db := XTReadDB().Table("his_doctor_advice_info as x").Where("x.status = 1 and x.advice_type =2")
  3108. if startime > 0 {
  3109. db = db.Where("x.advice_date >= ?", startime)
  3110. }
  3111. if endtime > 0 {
  3112. db = db.Where("x.advice_date<=?", endtime)
  3113. }
  3114. if orgid > 0 {
  3115. db = db.Where("x.user_org_id = ?", orgid)
  3116. }
  3117. if len(deliveway) > 0 {
  3118. db = db.Where("x.delivery_way = ?", deliveway)
  3119. }
  3120. 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
  3121. return advice, err
  3122. }
  3123. 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) {
  3124. var vms []*MScheduleDoctorAdviceVM
  3125. adviceWhere := ""
  3126. adviceCondition := []interface{}{}
  3127. if adviceType == 0 {
  3128. if patientType == 0 {
  3129. if patient_id > 0 {
  3130. if execution_state > 0 {
  3131. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  3132. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3133. } else {
  3134. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
  3135. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3136. }
  3137. } else {
  3138. if execution_state > 0 {
  3139. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ?"
  3140. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3141. } else {
  3142. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  3143. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3144. }
  3145. }
  3146. } else if patientType == 1 {
  3147. if patient_id > 0 {
  3148. if execution_state > 0 {
  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 = ? and execution_state= ?"
  3150. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3151. } else {
  3152. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
  3153. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3154. }
  3155. } else {
  3156. if execution_state > 0 {
  3157. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  3158. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3159. } else {
  3160. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  3161. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3162. }
  3163. }
  3164. } else if patientType == 2 {
  3165. if patient_id > 0 {
  3166. if execution_state > 0 {
  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 = ?) and execution_state = ?"
  3168. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3169. } else {
  3170. 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 = ?)"
  3171. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3172. }
  3173. } else {
  3174. if execution_state > 0 {
  3175. 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 = ?"
  3176. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3177. } else {
  3178. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  3179. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3180. }
  3181. }
  3182. }
  3183. } else if adviceType == 1 {
  3184. if patientType == 0 {
  3185. if patient_id > 0 {
  3186. if execution_state > 0 {
  3187. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ?"
  3188. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3189. } else {
  3190. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
  3191. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3192. }
  3193. } else {
  3194. if execution_state > 0 {
  3195. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ?"
  3196. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3197. } else {
  3198. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  3199. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3200. }
  3201. }
  3202. } else if patientType == 1 {
  3203. if patient_id > 0 {
  3204. if execution_state > 0 {
  3205. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  3206. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3207. } else {
  3208. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
  3209. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3210. }
  3211. } else {
  3212. if execution_state > 0 {
  3213. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?"
  3214. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3215. } else {
  3216. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  3217. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3218. }
  3219. }
  3220. } else if patientType == 2 {
  3221. if patient_id > 0 {
  3222. if execution_state > 0 {
  3223. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  3224. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3225. } else {
  3226. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
  3227. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3228. }
  3229. } else {
  3230. if execution_state > 0 {
  3231. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ?"
  3232. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3233. } else {
  3234. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  3235. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3236. }
  3237. }
  3238. }
  3239. } else if adviceType == 3 {
  3240. if patientType == 0 {
  3241. if patient_id > 0 {
  3242. if execution_state > 0 {
  3243. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ?"
  3244. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3245. } else {
  3246. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? "
  3247. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3248. }
  3249. } else {
  3250. if execution_state > 0 {
  3251. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? "
  3252. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3253. } else {
  3254. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  3255. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3256. }
  3257. }
  3258. } else if patientType == 1 {
  3259. if patient_id > 0 {
  3260. if execution_state > 0 {
  3261. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  3262. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3263. } else {
  3264. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
  3265. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3266. }
  3267. } else {
  3268. if execution_state > 0 {
  3269. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? "
  3270. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3271. } else {
  3272. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  3273. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3274. }
  3275. }
  3276. } else if patientType == 2 {
  3277. if patient_id > 0 {
  3278. if execution_state > 0 {
  3279. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  3280. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3281. } else {
  3282. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ?"
  3283. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3284. }
  3285. } else {
  3286. if execution_state > 0 {
  3287. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ?"
  3288. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3289. } else {
  3290. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  3291. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3292. }
  3293. }
  3294. }
  3295. } else if adviceType == 2 && len(deliverWay) > 0 {
  3296. if patientType == 0 {
  3297. if patient_id > 0 {
  3298. if execution_state > 0 {
  3299. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  3300. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  3301. } else {
  3302. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ?"
  3303. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  3304. }
  3305. } else {
  3306. if execution_state > 0 {
  3307. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ?"
  3308. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  3309. } else {
  3310. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  3311. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  3312. }
  3313. }
  3314. } else if patientType == 1 {
  3315. if patient_id > 0 {
  3316. if execution_state > 0 {
  3317. 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 = ?"
  3318. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state)
  3319. } else {
  3320. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ?"
  3321. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
  3322. }
  3323. } else {
  3324. if execution_state > 0 {
  3325. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ?"
  3326. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state)
  3327. } else {
  3328. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  3329. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  3330. }
  3331. }
  3332. } else if patientType == 2 {
  3333. if patient_id > 0 {
  3334. if execution_state > 0 {
  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 = ? and execution_state = ?"
  3336. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  3337. } else {
  3338. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ?"
  3339. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  3340. }
  3341. } else {
  3342. if execution_state > 0 {
  3343. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ?"
  3344. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  3345. } else {
  3346. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  3347. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  3348. }
  3349. }
  3350. }
  3351. } else if adviceType == 2 && len(deliverWay) <= 0 {
  3352. if patientType == 0 {
  3353. if patient_id > 0 {
  3354. if execution_state > 0 {
  3355. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ?"
  3356. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3357. } else {
  3358. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ?"
  3359. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3360. }
  3361. } else {
  3362. if execution_state > 0 {
  3363. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?"
  3364. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3365. } else {
  3366. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  3367. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3368. }
  3369. }
  3370. } else if patientType == 1 {
  3371. if patient_id > 0 {
  3372. if execution_state > 0 {
  3373. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  3374. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3375. } else {
  3376. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ?"
  3377. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3378. }
  3379. } else {
  3380. if execution_state > 0 {
  3381. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ?"
  3382. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3383. } else {
  3384. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?"
  3385. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3386. }
  3387. }
  3388. } else if patientType == 2 {
  3389. if patient_id > 0 {
  3390. if execution_state > 0 {
  3391. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  3392. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3393. } else {
  3394. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ?"
  3395. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3396. }
  3397. } else {
  3398. if execution_state > 0 {
  3399. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ?"
  3400. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3401. } else {
  3402. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  3403. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3404. }
  3405. }
  3406. }
  3407. }
  3408. db := readDb.Table("xt_schedule")
  3409. if scheduleType > 0 {
  3410. db = db.Where("schedule_type = ?", scheduleType)
  3411. }
  3412. if partitonType > 0 {
  3413. db = db.Where("partition_id = ?", partitonType)
  3414. }
  3415. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3416. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3417. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3418. }).
  3419. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3420. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3421. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3422. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3423. Preload("DoctorAdvices", adviceCondition...).
  3424. Where("status = 1 AND user_org_id = ?", orgID)
  3425. if scheduleDate != 0 {
  3426. db = db.Where("schedule_date = ?", scheduleDate)
  3427. }
  3428. err := db.Find(&vms).Error
  3429. return vms, err
  3430. }
  3431. func GetHisDoctorAdvicesOne(orgID int64, scheduleDate int64, deliverWay string, scheduleType int64, partitionType int64, patient_id int64, execution_state int64, cost_type int64) ([]*HisMScheduleDoctorAdviceVM, error) {
  3432. var vms []*HisMScheduleDoctorAdviceVM
  3433. if len(deliverWay) > 0 {
  3434. db := readDb.Table("xt_schedule")
  3435. if scheduleType > 0 {
  3436. db = db.Where("schedule_type = ?", scheduleType)
  3437. }
  3438. if partitionType > 0 {
  3439. db = db.Where("partition_id = ?", partitionType)
  3440. }
  3441. if patient_id > 0 {
  3442. if execution_state > 0 {
  3443. if cost_type > 0 {
  3444. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3445. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3446. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3447. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3448. 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).
  3449. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3450. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3451. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3452. Where("status = 1 AND user_org_id = ?", orgID)
  3453. if scheduleDate != 0 {
  3454. db = db.Where("schedule_date = ?", scheduleDate)
  3455. }
  3456. err = db.Find(&vms).Error
  3457. } else {
  3458. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3459. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3460. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3461. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3462. 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).
  3463. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3464. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3465. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3466. Where("status = 1 AND user_org_id = ?", orgID)
  3467. if scheduleDate != 0 {
  3468. db = db.Where("schedule_date = ?", scheduleDate)
  3469. }
  3470. err = db.Find(&vms).Error
  3471. }
  3472. } else {
  3473. if cost_type > 0 {
  3474. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3475. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3476. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3477. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3478. 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).
  3479. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3480. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3481. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3482. Where("status = 1 AND user_org_id = ?", orgID)
  3483. if scheduleDate != 0 {
  3484. db = db.Where("schedule_date = ?", scheduleDate)
  3485. }
  3486. err = db.Find(&vms).Error
  3487. } else {
  3488. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3489. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3490. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3491. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3492. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ?", orgID, scheduleDate, deliverWay, patient_id).
  3493. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3494. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3495. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3496. Where("status = 1 AND user_org_id = ?", orgID)
  3497. if scheduleDate != 0 {
  3498. db = db.Where("schedule_date = ?", scheduleDate)
  3499. }
  3500. err = db.Find(&vms).Error
  3501. }
  3502. }
  3503. } else {
  3504. if execution_state > 0 {
  3505. if cost_type > 0 {
  3506. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3507. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3508. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3509. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3510. 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).
  3511. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3512. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3513. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3514. Where("status = 1 AND user_org_id = ?", orgID)
  3515. if scheduleDate != 0 {
  3516. db = db.Where("schedule_date = ?", scheduleDate)
  3517. }
  3518. err = db.Find(&vms).Error
  3519. } else {
  3520. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3521. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3522. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3523. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3524. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_state = ?", orgID, scheduleDate, deliverWay, execution_state).
  3525. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3526. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3527. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3528. Where("status = 1 AND user_org_id = ?", orgID)
  3529. if scheduleDate != 0 {
  3530. db = db.Where("schedule_date = ?", scheduleDate)
  3531. }
  3532. err = db.Find(&vms).Error
  3533. }
  3534. } else {
  3535. if cost_type > 0 {
  3536. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3537. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3538. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3539. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3540. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and is_settle = ?", orgID, scheduleDate, deliverWay, cost_type).
  3541. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3542. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3543. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3544. Where("status = 1 AND user_org_id = ?", orgID)
  3545. if scheduleDate != 0 {
  3546. db = db.Where("schedule_date = ?", scheduleDate)
  3547. }
  3548. err = db.Find(&vms).Error
  3549. } else {
  3550. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3551. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3552. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3553. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3554. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  3555. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3556. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3557. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3558. Where("status = 1 AND user_org_id = ?", orgID)
  3559. if scheduleDate != 0 {
  3560. db = db.Where("schedule_date = ?", scheduleDate)
  3561. }
  3562. err = db.Find(&vms).Error
  3563. }
  3564. }
  3565. }
  3566. } else {
  3567. db := readDb.Table("xt_schedule")
  3568. if scheduleType > 0 {
  3569. db = db.Where("schedule_type = ?", scheduleType)
  3570. }
  3571. if partitionType > 0 {
  3572. db = db.Where("partition_id = ?", partitionType)
  3573. }
  3574. if patient_id > 0 {
  3575. if execution_state > 0 {
  3576. if cost_type > 0 {
  3577. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3578. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3579. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3580. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3581. 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).
  3582. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3583. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3584. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3585. Where("status = 1 AND user_org_id = ?", orgID)
  3586. if scheduleDate != 0 {
  3587. db = db.Where("schedule_date = ?", scheduleDate)
  3588. }
  3589. err = db.Find(&vms).Error
  3590. } else {
  3591. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3592. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3593. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3594. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3595. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and execution_state = ?", orgID, scheduleDate, patient_id, execution_state).
  3596. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3597. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3598. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3599. Where("status = 1 AND user_org_id = ?", orgID)
  3600. if scheduleDate != 0 {
  3601. db = db.Where("schedule_date = ?", scheduleDate)
  3602. }
  3603. err = db.Find(&vms).Error
  3604. }
  3605. } else {
  3606. if cost_type > 0 {
  3607. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3608. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3609. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3610. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3611. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and is_settle = ?", orgID, scheduleDate, patient_id, cost_type).
  3612. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3613. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3614. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3615. Where("status = 1 AND user_org_id = ?", orgID)
  3616. if scheduleDate != 0 {
  3617. db = db.Where("schedule_date = ?", scheduleDate)
  3618. }
  3619. err = db.Find(&vms).Error
  3620. } else {
  3621. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3622. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3623. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3624. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3625. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3626. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3627. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3628. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3629. Where("status = 1 AND user_org_id = ?", orgID)
  3630. if scheduleDate != 0 {
  3631. db = db.Where("schedule_date = ?", scheduleDate)
  3632. }
  3633. err = db.Find(&vms).Error
  3634. }
  3635. }
  3636. } else {
  3637. if execution_state > 0 {
  3638. if cost_type > 0 {
  3639. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3640. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3641. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3642. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3643. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ? and is_settle = ?", orgID, scheduleDate, execution_state, cost_type).
  3644. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3645. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3646. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3647. Where("status = 1 AND user_org_id = ?", orgID)
  3648. if scheduleDate != 0 {
  3649. db = db.Where("schedule_date = ?", scheduleDate)
  3650. }
  3651. err = db.Find(&vms).Error
  3652. } else {
  3653. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3654. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3655. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3656. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3657. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ?", orgID, scheduleDate, execution_state).
  3658. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3659. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3660. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3661. Where("status = 1 AND user_org_id = ?", orgID)
  3662. if scheduleDate != 0 {
  3663. db = db.Where("schedule_date = ?", scheduleDate)
  3664. }
  3665. err = db.Find(&vms).Error
  3666. }
  3667. } else {
  3668. if cost_type > 0 {
  3669. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3670. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3671. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3672. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3673. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and is_settle = ?", orgID, scheduleDate, cost_type).
  3674. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3675. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3676. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3677. Where("status = 1 AND user_org_id = ?", orgID)
  3678. if scheduleDate != 0 {
  3679. db = db.Where("schedule_date = ?", scheduleDate)
  3680. }
  3681. err = db.Find(&vms).Error
  3682. } else {
  3683. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3684. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3685. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3686. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3687. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ?", orgID, scheduleDate).
  3688. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3689. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3690. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3691. Where("status = 1 AND user_org_id = ?", orgID)
  3692. if scheduleDate != 0 {
  3693. db = db.Where("schedule_date = ?", scheduleDate)
  3694. }
  3695. err = db.Find(&vms).Error
  3696. }
  3697. }
  3698. }
  3699. }
  3700. return vms, err
  3701. }
  3702. func BatchDeleteMonitor(ids []string) (err error) {
  3703. if len(ids) == 1 {
  3704. err = XTWriteDB().Model(&models.MonitoringRecord{}).Where("id=?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3705. } else {
  3706. err = XTWriteDB().Model(models.MonitoringRecord{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3707. }
  3708. return
  3709. }
  3710. func GetPatientDialysisRecordList(patientid int64, startime int64, endtime int64) (order []*models.XtDialysisOrders, err error) {
  3711. db := XTReadDB().Table("xt_dialysis_order as x").Where("x.status = 1")
  3712. //table := XTReadDB().Table("xt_schedule as s")
  3713. //fmt.Println(table)
  3714. if patientid > 0 {
  3715. db = db.Where("x.patient_id = ?", patientid)
  3716. }
  3717. if startime > 0 {
  3718. db = db.Where("x.dialysis_date>=?", startime)
  3719. }
  3720. if endtime > 0 {
  3721. db = db.Where("x.dialysis_date <= ?", endtime)
  3722. }
  3723. 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
  3724. return order, err
  3725. }
  3726. func GetPatientDialysisRecordListOne(patientid int64, startime int64, endtime int64) (order []*models.XtScheduleSixTy, err error) {
  3727. db := XTReadDB().Table("xt_schedule as x").Where("x.status = 1")
  3728. //table := XTReadDB().Table("xt_schedule as s")
  3729. //fmt.Println(table)
  3730. if patientid > 0 {
  3731. db = db.Where("x.patient_id = ?", patientid)
  3732. }
  3733. if startime > 0 {
  3734. db = db.Where("x.schedule_date>=?", startime)
  3735. }
  3736. if endtime > 0 {
  3737. db = db.Where("x.schedule_date <= ?", endtime)
  3738. }
  3739. err = db.Select("x.id,x.schedule_date,x.schedule_type,x.mode_id").Find(&order).Error
  3740. return order, err
  3741. }
  3742. func BatchDeleteAdvice(ids []string) (err error) {
  3743. if len(ids) == 1 {
  3744. err = XTWriteDB().Model(&models.DoctorAdvice{}).Where("id=?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3745. } else {
  3746. err = XTWriteDB().Model(models.DoctorAdvice{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3747. }
  3748. return
  3749. }
  3750. func BatchDeleteHisAdvice(ids []string) (err error) {
  3751. if len(ids) == 1 {
  3752. err = XTWriteDB().Model(&models.HisDoctorAdviceInfo{}).Where("id = ?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3753. } else {
  3754. err = XTWriteDB().Model(models.HisDoctorAdviceInfo{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3755. }
  3756. return
  3757. }
  3758. func UpdateAutoReduceDetail(good_id int64, count int64, record_time int64, patient_id int64) (models.AutomaticReduceDetail, error) {
  3759. detail := models.AutomaticReduceDetail{}
  3760. 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
  3761. return detail, err
  3762. }
  3763. func DeleteAutoReduceDetail(good_id int64, record_time int64, patient_id int64) error {
  3764. detail := models.AutomaticReduceDetail{}
  3765. 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
  3766. return err
  3767. }
  3768. func DeleteDialysisBeforOne(good_id int64, record_time int64, patient_id int64) error {
  3769. detail := models.DialysisBeforePrepare{}
  3770. 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
  3771. return err
  3772. }
  3773. func BatchAdviceCheck(ids []string, creator int64) error {
  3774. advice := models.XtDoctorAdvice{}
  3775. 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
  3776. return err
  3777. }
  3778. func BatchHisAdviceCheck(ids []string, creator int64) error {
  3779. advice := models.HisDoctorAdviceInfo{}
  3780. 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
  3781. return err
  3782. }
  3783. func BatchAdviceExecution(ids []string, creator int64, execution_state int64) error {
  3784. advice := models.XtDoctorAdvice{}
  3785. 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
  3786. return err
  3787. }
  3788. func BatchHisAdviceExecution(ids []string, creator int64, execution_state int64) error {
  3789. advice := models.HisDoctorAdviceInfo{}
  3790. 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
  3791. return err
  3792. }
  3793. func GetAdviceExecutionById(ids []string) (doctor []*models.XtDoctorAdvice, err error) {
  3794. err = XTReadDB().Model(&doctor).Where("id IN(?) AND status = 1", ids).Find(&doctor).Error
  3795. return doctor, err
  3796. }
  3797. func GetHisAdviceExecutionById(ids []string) (doctor []*models.HisDoctorAdviceInfo, err error) {
  3798. err = XTReadDB().Model(&doctor).Where("id IN(?) AND status = 1", ids).Find(&doctor).Error
  3799. return doctor, err
  3800. }
  3801. func GetHisProjectConfig(orgid int64) (models.XtHisProjectConfig, error) {
  3802. config := models.XtHisProjectConfig{}
  3803. err := XTReadDB().Model(&config).Where("user_org_id = ? and status =1", orgid).Find(&config).Error
  3804. return config, err
  3805. }
  3806. func GetHisPrescriptionProject(org_id int64, patient_id int64, record_date int64) (project []*models.HisPrescriptionProject, err error) {
  3807. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("GoodInfo", func(db *gorm.DB) *gorm.DB {
  3808. return db.Preload("GoodsType", "status = 1").Where("status = 1 and is_warehouse = 1")
  3809. }).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
  3810. return
  3811. }
  3812. func GetPCHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64, patient_id int64, execution_state int64) ([]*HisMScheduleProjectVM, error) {
  3813. var vms []*HisMScheduleProjectVM
  3814. if patientType == 0 {
  3815. if patient_id > 0 {
  3816. if execution_state == 1 {
  3817. db := readDb.
  3818. Table("xt_schedule").
  3819. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3820. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3821. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3822. }).
  3823. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3824. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3825. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3826. Preload("HisPrescriptionProject", 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("HisProject").Preload("GoodInfo", "status=1")
  3828. }).
  3829. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3830. 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")
  3831. }).Where("status = 1 AND user_org_id = ?", orgID)
  3832. if scheduleDate != 0 {
  3833. db = db.Where("schedule_date = ?", scheduleDate)
  3834. }
  3835. err = db.Find(&vms).Error
  3836. } else if execution_state == 2 {
  3837. db := readDb.
  3838. Table("xt_schedule").
  3839. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3840. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3841. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3842. }).
  3843. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3844. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3845. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3846. Preload("HisPrescriptionProject", 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("HisProject").Preload("GoodInfo", "status=1")
  3848. }).
  3849. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3850. 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")
  3851. }).Where("status = 1 AND user_org_id = ?", orgID)
  3852. if scheduleDate != 0 {
  3853. db = db.Where("schedule_date = ?", scheduleDate)
  3854. }
  3855. err = db.Find(&vms).Error
  3856. } else if execution_state == 0 {
  3857. db := readDb.
  3858. Table("xt_schedule").
  3859. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3860. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3861. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3862. }).
  3863. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3864. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3865. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3866. Preload("HisPrescriptionProject", 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("HisProject").Preload("GoodInfo", "status=1")
  3868. }).
  3869. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3870. 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")
  3871. }).Where("status = 1 AND user_org_id = ?", orgID)
  3872. if scheduleDate != 0 {
  3873. db = db.Where("schedule_date = ?", scheduleDate)
  3874. }
  3875. err = db.Find(&vms).Error
  3876. }
  3877. } else {
  3878. if patient_id > 0 {
  3879. if execution_state == 1 {
  3880. db := readDb.
  3881. Table("xt_schedule").
  3882. Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
  3883. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3884. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3885. }).
  3886. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3887. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3888. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3889. Preload("HisPrescriptionProject", 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("HisProject").Preload("GoodInfo", "status=1")
  3891. }).
  3892. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3893. 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")
  3894. }).Where("status = 1 AND user_org_id = ?", orgID)
  3895. if scheduleDate != 0 {
  3896. db = db.Where("schedule_date = ?", scheduleDate)
  3897. }
  3898. err = db.Find(&vms).Error
  3899. } else if execution_state == 2 {
  3900. db := readDb.
  3901. Table("xt_schedule").
  3902. Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
  3903. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3904. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3905. }).
  3906. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3907. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3908. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3909. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3910. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0 and execution_state = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3911. }).
  3912. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3913. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0 and execution_state = 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  3914. }).Where("status = 1 AND user_org_id = ?", orgID)
  3915. if scheduleDate != 0 {
  3916. db = db.Where("schedule_date = ?", scheduleDate)
  3917. }
  3918. err = db.Find(&vms).Error
  3919. } else if execution_state == 0 {
  3920. db := readDb.
  3921. Table("xt_schedule").
  3922. Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
  3923. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3924. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3925. }).
  3926. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3927. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3928. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3929. Preload("HisPrescriptionProject", 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("HisProject").Preload("GoodInfo", "status=1")
  3931. }).
  3932. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3933. 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")
  3934. }).Where("status = 1 AND user_org_id = ?", orgID)
  3935. if scheduleDate != 0 {
  3936. db = db.Where("schedule_date = ?", scheduleDate)
  3937. }
  3938. err = db.Find(&vms).Error
  3939. }
  3940. } else {
  3941. if execution_state == 1 {
  3942. db := readDb.
  3943. Table("xt_schedule").
  3944. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3945. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3946. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3947. }).
  3948. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3949. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3950. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3951. Preload("HisPrescriptionProject", 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("HisProject").Preload("GoodInfo", "status=1")
  3953. }).
  3954. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3955. 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")
  3956. }).Where("status = 1 AND user_org_id = ?", orgID)
  3957. if scheduleDate != 0 {
  3958. db = db.Where("schedule_date = ?", scheduleDate)
  3959. }
  3960. err = db.Find(&vms).Error
  3961. } else if execution_state == 2 {
  3962. fmt.Println("j氯332n323232n323ℹ️33232323232")
  3963. db := readDb.
  3964. Table("xt_schedule").
  3965. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3966. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3967. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3968. }).
  3969. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3970. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3971. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3972. Preload("HisPrescriptionProject", 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("HisProject").Preload("GoodInfo", "status=1")
  3974. }).
  3975. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3976. 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")
  3977. }).Where("status = 1 AND user_org_id = ?", orgID)
  3978. if scheduleDate != 0 {
  3979. db = db.Where("schedule_date = ?", scheduleDate)
  3980. }
  3981. err = db.Find(&vms).Error
  3982. } else if execution_state == 0 {
  3983. db := readDb.
  3984. Table("xt_schedule").
  3985. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3986. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3987. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3988. }).
  3989. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3990. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3991. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3992. Preload("HisPrescriptionProject", 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("HisProject").Preload("GoodInfo", "status=1")
  3994. }).
  3995. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3996. 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")
  3997. }).Where("status = 1 AND user_org_id = ?", orgID)
  3998. if scheduleDate != 0 {
  3999. db = db.Where("schedule_date = ?", scheduleDate)
  4000. }
  4001. err = db.Find(&vms).Error
  4002. }
  4003. }
  4004. }
  4005. }
  4006. if patientType > 0 {
  4007. if execution_state == 1 {
  4008. db := readDb.
  4009. Table("xt_schedule").
  4010. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  4011. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  4012. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  4013. }).
  4014. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  4015. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  4016. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  4017. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  4018. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  4019. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0 and execution_state = 1", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  4020. }).
  4021. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  4022. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  4023. }).Where("status = 1 AND user_org_id = ?", orgID)
  4024. if scheduleDate != 0 {
  4025. db = db.Where("schedule_date = ?", scheduleDate)
  4026. }
  4027. err = db.Find(&vms).Error
  4028. } else if execution_state == 2 {
  4029. db := readDb.
  4030. Table("xt_schedule").
  4031. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  4032. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  4033. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  4034. }).
  4035. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  4036. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  4037. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  4038. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  4039. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  4040. 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")
  4041. }).
  4042. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  4043. 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")
  4044. }).Where("status = 1 AND user_org_id = ?", orgID)
  4045. if scheduleDate != 0 {
  4046. db = db.Where("schedule_date = ?", scheduleDate)
  4047. }
  4048. err = db.Find(&vms).Error
  4049. } else if execution_state == 0 {
  4050. db := readDb.
  4051. Table("xt_schedule").
  4052. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  4053. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  4054. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  4055. }).
  4056. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  4057. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  4058. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  4059. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  4060. Preload("HisPrescriptionProject", 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("HisProject").Preload("GoodInfo", "status=1")
  4062. }).
  4063. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  4064. 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")
  4065. }).Where("status = 1 AND user_org_id = ?", orgID)
  4066. if scheduleDate != 0 {
  4067. db = db.Where("schedule_date = ?", scheduleDate)
  4068. }
  4069. err = db.Find(&vms).Error
  4070. }
  4071. }
  4072. return vms, err
  4073. }
  4074. func UpdateStockGoods(good_id int64, record_time int64, patient_id int64, count int64) error {
  4075. prepare := models.DialysisBeforePrepare{}
  4076. var err error
  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}).Error
  4079. }
  4080. if count <= 0 {
  4081. 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
  4082. }
  4083. return err
  4084. }
  4085. func UPdateAutoStockGoods(good_id int64, record_time int64, patient_id int64, count int64) error {
  4086. detail := models.AutomaticReduceDetail{}
  4087. 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
  4088. return err
  4089. }
  4090. func MobileGetDialysisSolutionByModeIdSeven(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  4091. var record models.DialysisSolution
  4092. 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
  4093. if err != nil {
  4094. if err == gorm.ErrRecordNotFound {
  4095. return nil, nil
  4096. } else {
  4097. return nil, err
  4098. }
  4099. }
  4100. return &record, nil
  4101. }
  4102. func MobileGetLastDialysisPrescribeByModeIdSeven(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  4103. var record models.DialysisPrescription
  4104. 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
  4105. if err != nil {
  4106. if err == gorm.ErrRecordNotFound {
  4107. return nil, nil
  4108. } else {
  4109. return nil, err
  4110. }
  4111. }
  4112. return &record, nil
  4113. }
  4114. func MobileGetLastDialysisPrescription(patientID int64, orgID int64) (models.DialysisPrescriptionThrity, error) {
  4115. prescription := models.DialysisPrescriptionThrity{}
  4116. err := readDb.Model(&prescription).Where("patient_id = ? and user_org_id = ? and status = 1 and remark<>''", patientID, orgID).Last(&prescription).Error
  4117. return prescription, err
  4118. }
  4119. func MobileGetSystemDialysisPrescribeByModeIdSeven(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  4120. var record models.SystemPrescription
  4121. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).First(&record).Error
  4122. if err != nil {
  4123. if err == gorm.ErrRecordNotFound {
  4124. return nil, nil
  4125. } else {
  4126. return nil, err
  4127. }
  4128. }
  4129. return &record, nil
  4130. }
  4131. // 透前评估
  4132. func MobileGetPredialysisEvaluationSeven(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
  4133. var record models.PredialysisEvaluation
  4134. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  4135. if err != nil {
  4136. if err == gorm.ErrRecordNotFound {
  4137. return nil, nil
  4138. } else {
  4139. return nil, err
  4140. }
  4141. }
  4142. return &record, nil
  4143. }
  4144. //
  4145. //func MobileGetDialysisGoodsSix(orgID int64, scheduleDate int64) (prepare []*models.DialysisBeforePrepare, err error) {
  4146. //
  4147. // 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
  4148. // return prepare, err
  4149. //}
  4150. func GetMobileAutoReduce(orgID int64, scheduleDate int64) (auto []*models.AutomaticReduceDetail, err error) {
  4151. err = readDb.Where("org_id = ? and status = 1 and record_time = ?", orgID, scheduleDate).Find(&auto).Error
  4152. return auto, err
  4153. }
  4154. func GetRoleList(orgid int64, admin_user_id int64) (models.SgjUserAdminRole, error) {
  4155. role := models.SgjUserAdminRole{}
  4156. err = readUserDb.Where("org_id = ? and admin_user_id = ? and status =1 ", orgid, admin_user_id).Find(&role).Error
  4157. return role, err
  4158. }
  4159. func GetDialysisGood(orgID int64, scheduleDate int64) (auto []*models.AutomaticReduceDetail, err error) {
  4160. err = readDb.Where("org_id = ? and status = 1 and record_time >= ?", orgID, scheduleDate).Group("patient_id").Find(&auto).Error
  4161. return auto, err
  4162. }
  4163. func GetGoodWarehouseOutInfo(orgId int64, patient_id int64, sys_record_time int64) (outifno []*models.WarehouseOutInfoSeven, err error) {
  4164. err = readDb.Where("org_id = ? and patient_id = ? and sys_record_time = ? and status = 1", orgId, patient_id, sys_record_time).Find(&outifno).Error
  4165. return outifno, err
  4166. }
  4167. func GetLastDilysisOrder(orgid int64, patient_id int64, dialysis_date int64) (models.DialysisOrder, error) {
  4168. order := models.DialysisOrder{}
  4169. err = XTReadDB().Where("user_org_id = ? and patient_id = ? and dialysis_date < ? and status= 1", orgid, patient_id, dialysis_date).Last(&order).Error
  4170. return order, err
  4171. }
  4172. func GetFistMonitor(orgid int64, patient_id int64, dialysis_date int64) (models.MonitoringRecord, error) {
  4173. record := models.MonitoringRecord{}
  4174. err := XTReadDB().Where("org_id = ? and patient_id = ? and monitoring_date = ? and status = 1", orgid, patient_id, dialysis_date).Find(&record).Error
  4175. return record, err
  4176. }
  4177. func GetFistMonitorSix(orgid int64, patient_id int64, dialysis_date int64) (record []*models.MonitoringRecord, err error) {
  4178. err = XTReadDB().Where("user_org_id = ? and patient_id = ? and monitoring_date = ? and status = 1", orgid, patient_id, dialysis_date).Find(&record).Error
  4179. return record, err
  4180. }
  4181. 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) {
  4182. var vms []*MScheduleDoctorAdviceVM
  4183. keyword = "%" + keyword + "%"
  4184. adviceWhere := ""
  4185. adviceCondition := []interface{}{}
  4186. if adviceType == 0 {
  4187. if patientType == 0 {
  4188. if patient_id > 0 {
  4189. if execution_state > 0 {
  4190. if cost_type > 0 {
  4191. if len(execution_frequency) > 0 {
  4192. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  4194. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4195. } else {
  4196. 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 = ?"
  4197. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4198. }
  4199. } else {
  4200. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  4202. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  4203. } else {
  4204. 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 = ?"
  4205. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4206. }
  4207. }
  4208. } else {
  4209. if len(execution_frequency) > 0 {
  4210. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  4212. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  4213. } else {
  4214. 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 = ?"
  4215. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4216. }
  4217. } else {
  4218. if len(keyword) > 0 {
  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= ? and advice_name like ?"
  4220. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  4221. } else {
  4222. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  4223. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4224. }
  4225. }
  4226. }
  4227. } else {
  4228. if cost_type > 0 {
  4229. if len(execution_frequency) > 0 {
  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 = ? and execution_frequency = ?"
  4231. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4232. } else {
  4233. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and is_settle = ?"
  4234. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4235. }
  4236. } else {
  4237. if len(execution_frequency) > 0 {
  4238. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_frequency = ?"
  4239. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4240. } else {
  4241. if len(keyword) > 0 {
  4242. 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 ?"
  4243. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  4244. } else {
  4245. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
  4246. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4247. }
  4248. }
  4249. }
  4250. }
  4251. } else {
  4252. if execution_state > 0 {
  4253. if cost_type > 0 {
  4254. if len(execution_frequency) > 0 {
  4255. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  4257. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  4258. } else {
  4259. 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 = ?"
  4260. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4261. }
  4262. } else {
  4263. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  4265. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  4266. } else {
  4267. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and is_settle = ?"
  4268. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4269. }
  4270. }
  4271. } else {
  4272. if len(execution_frequency) > 0 {
  4273. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  4275. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  4276. } else {
  4277. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and execution_frequency = ?"
  4278. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4279. }
  4280. } else {
  4281. if len(keyword) > 0 {
  4282. 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 ?"
  4283. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  4284. } else {
  4285. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ?"
  4286. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4287. }
  4288. }
  4289. }
  4290. } else {
  4291. if cost_type > 0 {
  4292. if len(execution_frequency) > 0 {
  4293. if len(keyword) > 0 {
  4294. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ? and execution_frequency = ? and advice_name like ?"
  4295. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  4296. } else {
  4297. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ? and execution_frequency = ?"
  4298. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  4299. }
  4300. } else {
  4301. if len(keyword) > 0 {
  4302. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ? and advice_name like ?"
  4303. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  4304. } else {
  4305. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ?"
  4306. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4307. }
  4308. }
  4309. } else {
  4310. if len(execution_frequency) > 0 {
  4311. if len(keyword) > 0 {
  4312. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_frequency = ? and advice_name like ?"
  4313. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  4314. } else {
  4315. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_frequency = ?"
  4316. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  4317. }
  4318. } else {
  4319. if len(keyword) > 0 {
  4320. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and advice_name like ?"
  4321. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  4322. } else {
  4323. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  4324. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4325. }
  4326. }
  4327. }
  4328. }
  4329. }
  4330. } else if patientType == 1 {
  4331. if patient_id > 0 {
  4332. if execution_state > 0 {
  4333. if cost_type > 0 {
  4334. if len(execution_frequency) > 0 {
  4335. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  4337. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4338. } else {
  4339. 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 = ?"
  4340. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  4341. }
  4342. } else {
  4343. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  4345. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, keyword)
  4346. } else {
  4347. 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 = ?"
  4348. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  4349. }
  4350. }
  4351. } else {
  4352. if len(execution_frequency) > 0 {
  4353. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  4355. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  4356. } else {
  4357. 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 = ?"
  4358. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  4359. }
  4360. } else {
  4361. if len(keyword) > 0 {
  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= ? and advice_name like ?"
  4363. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, keyword)
  4364. } else {
  4365. 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= ?"
  4366. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  4367. }
  4368. }
  4369. }
  4370. } else {
  4371. if cost_type > 0 {
  4372. if len(execution_frequency) > 0 {
  4373. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  4375. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  4376. } else {
  4377. 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 = ?"
  4378. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  4379. }
  4380. } else {
  4381. if len(keyword) > 0 {
  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=? and advice_name like ?"
  4383. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, keyword)
  4384. } else {
  4385. 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=?"
  4386. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  4387. }
  4388. }
  4389. } else {
  4390. if len(execution_frequency) > 0 {
  4391. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  4393. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency, keyword)
  4394. } else {
  4395. 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 = ?"
  4396. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  4397. }
  4398. } else {
  4399. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  4401. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, keyword)
  4402. } else {
  4403. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
  4404. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  4405. }
  4406. }
  4407. }
  4408. }
  4409. } else {
  4410. if execution_state > 0 {
  4411. if cost_type > 0 {
  4412. if len(execution_frequency) > 0 {
  4413. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  4415. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  4416. } else {
  4417. 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 = ?"
  4418. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  4419. }
  4420. } else {
  4421. if len(keyword) > 0 {
  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=? and advice_name like ?"
  4423. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, keyword)
  4424. } else {
  4425. 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=?"
  4426. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  4427. }
  4428. }
  4429. } else {
  4430. if len(execution_frequency) > 0 {
  4431. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  4433. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency, keyword)
  4434. } else {
  4435. 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 = ?"
  4436. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  4437. }
  4438. } else {
  4439. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  4441. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, keyword)
  4442. } else {
  4443. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  4444. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  4445. }
  4446. }
  4447. }
  4448. } else {
  4449. if cost_type > 0 {
  4450. if len(execution_frequency) > 0 {
  4451. if len(keyword) > 0 {
  4452. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and is_settle=? and execution_frequency = ? and advice_name like ?"
  4453. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency, keyword)
  4454. } else {
  4455. 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 = ?"
  4456. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  4457. }
  4458. } else {
  4459. if len(keyword) > 0 {
  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=? and advice_name like ?"
  4461. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, keyword)
  4462. } else {
  4463. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and is_settle=?"
  4464. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  4465. }
  4466. }
  4467. } else {
  4468. if len(execution_frequency) > 0 {
  4469. if len(keyword) > 0 {
  4470. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_frequency = ? and advice_name like ?"
  4471. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency, keyword)
  4472. } else {
  4473. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_frequency = ?"
  4474. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  4475. }
  4476. } else {
  4477. if len(keyword) > 0 {
  4478. 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 ?"
  4479. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, keyword)
  4480. } else {
  4481. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  4482. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  4483. }
  4484. }
  4485. }
  4486. }
  4487. }
  4488. } else if patientType == 2 {
  4489. if patient_id > 0 {
  4490. if execution_state > 0 {
  4491. if cost_type > 0 {
  4492. if len(execution_frequency) > 0 {
  4493. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  4495. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4496. } else {
  4497. 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 = ?"
  4498. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4499. }
  4500. } else {
  4501. if len(keyword) > 0 {
  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=? and advice_name like ?"
  4503. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  4504. } else {
  4505. 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=?"
  4506. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4507. }
  4508. }
  4509. } else {
  4510. if len(execution_frequency) > 0 {
  4511. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  4513. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  4514. } else {
  4515. 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 = ?"
  4516. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4517. }
  4518. } else {
  4519. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  4521. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  4522. } else {
  4523. 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 = ?"
  4524. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4525. }
  4526. }
  4527. }
  4528. } else {
  4529. if cost_type > 0 {
  4530. if len(execution_frequency) > 0 {
  4531. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  4533. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  4534. } else {
  4535. 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 = ?"
  4536. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4537. }
  4538. } else {
  4539. if len(keyword) > 0 {
  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=? and advice_name like ?"
  4541. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  4542. } else {
  4543. 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=?"
  4544. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4545. }
  4546. }
  4547. } else {
  4548. if len(execution_frequency) > 0 {
  4549. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  4551. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  4552. } else {
  4553. 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 = ?"
  4554. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4555. }
  4556. } else {
  4557. if len(keyword) > 0 {
  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 = ?) and advice_name like ?"
  4559. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  4560. } else {
  4561. 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 = ?)"
  4562. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4563. }
  4564. }
  4565. }
  4566. }
  4567. } else {
  4568. if execution_state > 0 {
  4569. if cost_type > 0 {
  4570. if len(execution_frequency) > 0 {
  4571. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  4573. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  4574. } else {
  4575. 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 = ?"
  4576. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4577. }
  4578. } else {
  4579. if len(keyword) > 0 {
  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=? and advice_name like ?"
  4581. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  4582. } else {
  4583. 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=?"
  4584. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4585. }
  4586. }
  4587. } else {
  4588. if len(execution_frequency) > 0 {
  4589. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  4591. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  4592. } else {
  4593. 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 = ?"
  4594. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4595. }
  4596. } else {
  4597. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  4599. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  4600. } else {
  4601. 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 = ?"
  4602. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4603. }
  4604. }
  4605. }
  4606. } else {
  4607. if cost_type > 0 {
  4608. if len(execution_frequency) > 0 {
  4609. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  4611. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  4612. } else {
  4613. 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 = ?"
  4614. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  4615. }
  4616. } else {
  4617. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  4619. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  4620. } else {
  4621. 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 = ?"
  4622. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4623. }
  4624. }
  4625. } else {
  4626. if len(execution_frequency) > 0 {
  4627. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  4629. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  4630. } else {
  4631. 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 = ?"
  4632. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  4633. }
  4634. } else {
  4635. if len(keyword) > 0 {
  4636. 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 ?"
  4637. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  4638. } else {
  4639. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  4640. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4641. }
  4642. }
  4643. }
  4644. }
  4645. }
  4646. }
  4647. } else if adviceType == 1 {
  4648. if patientType == 0 {
  4649. if patient_id > 0 {
  4650. if execution_state > 0 {
  4651. if cost_type > 0 {
  4652. if len(execution_frequency) > 0 {
  4653. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  4655. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4656. } else {
  4657. 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 = ?"
  4658. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4659. }
  4660. } else {
  4661. if len(keyword) > 0 {
  4662. 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 ?"
  4663. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  4664. } else {
  4665. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  4666. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4667. }
  4668. }
  4669. } else {
  4670. if len(execution_frequency) > 0 {
  4671. if len(keyword) > 0 {
  4672. 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 ?"
  4673. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  4674. } else {
  4675. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  4676. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4677. }
  4678. } else {
  4679. if len(keyword) > 0 {
  4680. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  4681. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  4682. } else {
  4683. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ?"
  4684. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4685. }
  4686. }
  4687. }
  4688. } else {
  4689. if cost_type > 0 {
  4690. if len(execution_frequency) > 0 {
  4691. if len(keyword) > 0 {
  4692. 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 ?"
  4693. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  4694. } else {
  4695. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  4696. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4697. }
  4698. } else {
  4699. if len(keyword) > 0 {
  4700. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? and advice_name like ? "
  4701. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  4702. } else {
  4703. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? "
  4704. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4705. }
  4706. }
  4707. } else {
  4708. if len(execution_frequency) > 0 {
  4709. if len(keyword) > 0 {
  4710. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and advice_name like ?"
  4711. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  4712. } else {
  4713. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
  4714. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4715. }
  4716. }
  4717. }
  4718. }
  4719. } else {
  4720. if execution_state > 0 {
  4721. if cost_type > 0 {
  4722. if len(execution_frequency) > 0 {
  4723. if len(keyword) > 0 {
  4724. 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 ?"
  4725. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  4726. } else {
  4727. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  4728. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4729. }
  4730. } else {
  4731. if len(keyword) > 0 {
  4732. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  4733. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  4734. } else {
  4735. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ?"
  4736. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4737. }
  4738. }
  4739. } else {
  4740. if len(execution_frequency) > 0 {
  4741. if len(keyword) > 0 {
  4742. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  4743. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  4744. } else {
  4745. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and execution_frequency = ?"
  4746. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4747. }
  4748. } else {
  4749. if len(keyword) > 0 {
  4750. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and advice_name like ?"
  4751. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  4752. } else {
  4753. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ?"
  4754. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4755. }
  4756. }
  4757. }
  4758. } else {
  4759. if cost_type > 0 {
  4760. if len(keyword) > 0 {
  4761. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = ? and advice_name like ?"
  4762. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  4763. } else {
  4764. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = ? "
  4765. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4766. }
  4767. } else {
  4768. if len(keyword) > 0 {
  4769. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and advice_name like ?"
  4770. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  4771. } else {
  4772. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  4773. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4774. }
  4775. }
  4776. }
  4777. }
  4778. } else if patientType == 1 {
  4779. if patient_id > 0 {
  4780. if execution_state > 0 {
  4781. if cost_type > 0 {
  4782. if len(execution_frequency) > 0 {
  4783. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  4785. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4786. } else {
  4787. 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 = ?"
  4788. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  4789. }
  4790. } else {
  4791. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  4793. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, keyword)
  4794. } else {
  4795. 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 = ?"
  4796. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  4797. }
  4798. }
  4799. } else {
  4800. if len(execution_frequency) > 0 {
  4801. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  4803. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  4804. } else {
  4805. 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 = ?"
  4806. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  4807. }
  4808. } else {
  4809. if len(keyword) > 0 {
  4810. 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 ?"
  4811. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, keyword)
  4812. } else {
  4813. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  4814. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  4815. }
  4816. }
  4817. }
  4818. } else {
  4819. if cost_type > 0 {
  4820. if len(execution_frequency) > 0 {
  4821. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  4823. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  4824. } else {
  4825. 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 = ?"
  4826. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  4827. }
  4828. } else {
  4829. if len(keyword) > 0 {
  4830. 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 ?"
  4831. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, keyword)
  4832. } else {
  4833. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  4834. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  4835. }
  4836. }
  4837. } else {
  4838. if len(execution_frequency) > 0 {
  4839. if len(keyword) > 0 {
  4840. 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 ?"
  4841. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency, keyword)
  4842. } else {
  4843. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  4844. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  4845. }
  4846. } else {
  4847. if len(keyword) > 0 {
  4848. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and advice_name like ?"
  4849. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, keyword)
  4850. } else {
  4851. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
  4852. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  4853. }
  4854. }
  4855. }
  4856. }
  4857. } else {
  4858. if execution_state > 0 {
  4859. if cost_type > 0 {
  4860. if len(execution_frequency) > 0 {
  4861. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  4863. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  4864. } else {
  4865. 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 = ?"
  4866. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  4867. }
  4868. } else {
  4869. if len(keyword) > 0 {
  4870. 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 ?"
  4871. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, keyword)
  4872. } else {
  4873. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=? and is_settle = ?"
  4874. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  4875. }
  4876. }
  4877. } else {
  4878. if len(execution_frequency) > 0 {
  4879. if len(keyword) > 0 {
  4880. 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 ?"
  4881. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency, keyword)
  4882. } else {
  4883. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?and execution_frequency = ?"
  4884. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  4885. }
  4886. } else {
  4887. if len(keyword) > 0 {
  4888. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=? and advice_name like ?"
  4889. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, keyword)
  4890. } else {
  4891. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?"
  4892. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  4893. }
  4894. }
  4895. }
  4896. } else {
  4897. if cost_type > 0 {
  4898. if len(execution_frequency) > 0 {
  4899. if len(keyword) > 0 {
  4900. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  4901. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency, keyword)
  4902. } else {
  4903. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  4904. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  4905. }
  4906. } else {
  4907. if len(keyword) > 0 {
  4908. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? and advice_name like ?"
  4909. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, keyword)
  4910. } else {
  4911. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? "
  4912. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  4913. }
  4914. }
  4915. } else {
  4916. if len(execution_frequency) > 0 {
  4917. if len(keyword) > 0 {
  4918. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_frequency = ? and advice_name like ?"
  4919. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency, keyword)
  4920. } else {
  4921. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_frequency = ?"
  4922. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  4923. }
  4924. } else {
  4925. if len(keyword) > 0 {
  4926. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and advice_name like ?"
  4927. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, keyword)
  4928. } else {
  4929. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  4930. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  4931. }
  4932. }
  4933. }
  4934. }
  4935. }
  4936. } else if patientType == 2 {
  4937. if patient_id > 0 {
  4938. if execution_state > 0 {
  4939. if cost_type > 0 {
  4940. if len(execution_frequency) > 0 {
  4941. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  4943. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4944. } else {
  4945. 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 = ?"
  4946. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4947. }
  4948. } else {
  4949. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  4951. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  4952. } else {
  4953. 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 = ?"
  4954. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4955. }
  4956. }
  4957. } else {
  4958. if len(execution_frequency) > 0 {
  4959. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  4961. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  4962. } else {
  4963. 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 = ?"
  4964. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4965. }
  4966. } else {
  4967. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  4969. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  4970. } else {
  4971. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  4972. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4973. }
  4974. }
  4975. }
  4976. } else {
  4977. if cost_type > 0 {
  4978. if len(execution_frequency) > 0 {
  4979. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  4981. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  4982. } else {
  4983. 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 = ?"
  4984. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4985. }
  4986. } else {
  4987. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  4989. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  4990. } else {
  4991. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  4992. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4993. }
  4994. }
  4995. } else {
  4996. if len(execution_frequency) > 0 {
  4997. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  4999. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  5000. } else {
  5001. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_frequency = ?"
  5002. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  5003. }
  5004. } else {
  5005. if len(keyword) > 0 {
  5006. 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 ?"
  5007. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  5008. } else {
  5009. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
  5010. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5011. }
  5012. }
  5013. }
  5014. }
  5015. } else {
  5016. if execution_state > 0 {
  5017. if cost_type > 0 {
  5018. if len(execution_frequency) > 0 {
  5019. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  5021. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  5022. } else {
  5023. 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 = ?"
  5024. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  5025. }
  5026. } else {
  5027. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  5029. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  5030. } else {
  5031. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  5032. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5033. }
  5034. }
  5035. } else {
  5036. if len(execution_frequency) > 0 {
  5037. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  5039. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  5040. } else {
  5041. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and execution_frequency = ?"
  5042. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  5043. }
  5044. } else {
  5045. if len(keyword) > 0 {
  5046. 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 ?"
  5047. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  5048. } else {
  5049. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ?"
  5050. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5051. }
  5052. }
  5053. }
  5054. } else {
  5055. if cost_type > 0 {
  5056. if len(execution_frequency) > 0 {
  5057. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  5059. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  5060. } else {
  5061. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  5062. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  5063. }
  5064. } else {
  5065. if len(keyword) > 0 {
  5066. 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 ?"
  5067. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  5068. } else {
  5069. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ?"
  5070. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5071. }
  5072. }
  5073. } else {
  5074. if len(execution_frequency) > 0 {
  5075. if len(keyword) > 0 {
  5076. 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 ?"
  5077. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  5078. } else {
  5079. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_frequency = ?"
  5080. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  5081. }
  5082. } else {
  5083. if len(keyword) > 0 {
  5084. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and advice_name like ?"
  5085. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  5086. } else {
  5087. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  5088. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5089. }
  5090. }
  5091. }
  5092. }
  5093. }
  5094. }
  5095. } else if adviceType == 3 {
  5096. if patientType == 0 {
  5097. if patient_id > 0 {
  5098. if execution_state > 0 {
  5099. if cost_type > 0 {
  5100. if len(execution_frequency) > 0 {
  5101. if len(keyword) > 0 {
  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 =? and advice_name like ?"
  5103. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5104. } else {
  5105. 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 =?"
  5106. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  5107. }
  5108. } else {
  5109. if len(keyword) > 0 {
  5110. 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 ?"
  5111. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  5112. } else {
  5113. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  5114. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5115. }
  5116. }
  5117. } else {
  5118. if len(execution_frequency) > 0 {
  5119. if len(keyword) > 0 {
  5120. 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 ?"
  5121. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  5122. } else {
  5123. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency =?"
  5124. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  5125. }
  5126. } else {
  5127. if len(keyword) > 0 {
  5128. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  5129. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  5130. } else {
  5131. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ?"
  5132. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5133. }
  5134. }
  5135. }
  5136. } else {
  5137. if cost_type > 0 {
  5138. if len(execution_frequency) > 0 {
  5139. if len(keyword) > 0 {
  5140. 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 ?"
  5141. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  5142. } else {
  5143. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency =?"
  5144. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  5145. }
  5146. } else {
  5147. if len(keyword) > 0 {
  5148. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  5149. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  5150. } else {
  5151. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? "
  5152. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5153. }
  5154. }
  5155. } else {
  5156. if len(execution_frequency) > 0 {
  5157. if len(keyword) > 0 {
  5158. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_frequency =? and advice_name like ?"
  5159. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  5160. } else {
  5161. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_frequency =?"
  5162. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  5163. }
  5164. } else {
  5165. if len(keyword) > 0 {
  5166. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and advice_name like ?"
  5167. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  5168. } else {
  5169. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? "
  5170. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5171. }
  5172. }
  5173. }
  5174. }
  5175. } else {
  5176. if execution_state > 0 {
  5177. if cost_type > 0 {
  5178. if len(execution_frequency) > 0 {
  5179. if len(keyword) > 0 {
  5180. 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 ?"
  5181. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  5182. } else {
  5183. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ? and execution_frequency =?"
  5184. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  5185. }
  5186. } else {
  5187. if len(keyword) > 0 {
  5188. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ? and advice_name like ?"
  5189. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  5190. } else {
  5191. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ?"
  5192. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5193. }
  5194. }
  5195. } else {
  5196. if len(execution_frequency) > 0 {
  5197. if len(keyword) > 0 {
  5198. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and execution_frequency =? and advice_name like ?"
  5199. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  5200. } else {
  5201. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and execution_frequency =?"
  5202. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  5203. }
  5204. } else {
  5205. if len(keyword) > 0 {
  5206. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and advice_name like ?"
  5207. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  5208. } else {
  5209. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? "
  5210. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5211. }
  5212. }
  5213. }
  5214. } else {
  5215. if cost_type > 0 {
  5216. if len(execution_frequency) > 0 {
  5217. if len(keyword) > 0 {
  5218. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? and execution_frequency =? and advice_name like ?"
  5219. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  5220. } else {
  5221. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? and execution_frequency =?"
  5222. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  5223. }
  5224. } else {
  5225. if len(keyword) > 0 {
  5226. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? and advice_name like ?"
  5227. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  5228. } else {
  5229. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? "
  5230. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5231. }
  5232. }
  5233. } else {
  5234. if len(execution_frequency) > 0 {
  5235. if len(keyword) > 0 {
  5236. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_frequency =? and advice_name like ?"
  5237. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  5238. } else {
  5239. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_frequency =?"
  5240. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  5241. }
  5242. } else {
  5243. if len(keyword) > 0 {
  5244. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and advice_name like ?"
  5245. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  5246. } else {
  5247. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  5248. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5249. }
  5250. }
  5251. }
  5252. }
  5253. }
  5254. } else if patientType == 1 {
  5255. if patient_id > 0 {
  5256. if execution_state > 0 {
  5257. if cost_type > 0 {
  5258. if len(execution_frequency) > 0 {
  5259. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  5261. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5262. } else {
  5263. 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 = ?"
  5264. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  5265. }
  5266. } else {
  5267. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  5269. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, keyword)
  5270. } else {
  5271. 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 = ?"
  5272. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  5273. }
  5274. }
  5275. } else {
  5276. if len(execution_frequency) > 0 {
  5277. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  5279. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  5280. } else {
  5281. 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 = ?"
  5282. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  5283. }
  5284. } else {
  5285. if len(keyword) > 0 {
  5286. 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 ?"
  5287. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, keyword)
  5288. } else {
  5289. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  5290. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  5291. }
  5292. }
  5293. }
  5294. } else {
  5295. if cost_type > 0 {
  5296. if len(execution_frequency) > 0 {
  5297. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  5299. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  5300. } else {
  5301. 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 = ?"
  5302. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  5303. }
  5304. } else {
  5305. if len(keyword) > 0 {
  5306. 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 ?"
  5307. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, keyword)
  5308. } else {
  5309. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  5310. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  5311. }
  5312. }
  5313. } else {
  5314. if len(execution_frequency) > 0 {
  5315. if len(keyword) > 0 {
  5316. 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 ?"
  5317. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency, keyword)
  5318. } else {
  5319. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  5320. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  5321. }
  5322. } else {
  5323. if len(keyword) > 0 {
  5324. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and advice_name like ?"
  5325. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, keyword)
  5326. } else {
  5327. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
  5328. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  5329. }
  5330. }
  5331. }
  5332. }
  5333. } else {
  5334. if execution_state > 0 {
  5335. if cost_type > 0 {
  5336. if len(execution_frequency) > 0 {
  5337. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  5339. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  5340. } else {
  5341. 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 = ?"
  5342. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  5343. }
  5344. } else {
  5345. if len(keyword) > 0 {
  5346. 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 ?"
  5347. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, keyword)
  5348. } else {
  5349. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? and is_settle = ?"
  5350. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  5351. }
  5352. }
  5353. } else {
  5354. if len(execution_frequency) > 0 {
  5355. if len(keyword) > 0 {
  5356. 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 ? "
  5357. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency, keyword)
  5358. } else {
  5359. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =?and execution_frequency = ? "
  5360. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  5361. }
  5362. } else {
  5363. if len(keyword) > 0 {
  5364. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? and advice_name like ?"
  5365. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, keyword)
  5366. } else {
  5367. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? "
  5368. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  5369. }
  5370. }
  5371. }
  5372. } else {
  5373. if cost_type > 0 {
  5374. if len(execution_frequency) > 0 {
  5375. if len(keyword) > 0 {
  5376. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5377. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency, keyword)
  5378. } else {
  5379. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  5380. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  5381. }
  5382. } else {
  5383. if len(keyword) > 0 {
  5384. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ? and advice_name like ?"
  5385. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, keyword)
  5386. } else {
  5387. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ?"
  5388. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  5389. }
  5390. }
  5391. } else {
  5392. if len(execution_frequency) > 0 {
  5393. if len(keyword) > 0 {
  5394. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_frequency = ? and advice_name like ?"
  5395. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency, keyword)
  5396. } else {
  5397. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_frequency = ?"
  5398. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  5399. }
  5400. } else {
  5401. if len(keyword) > 0 {
  5402. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and advice_name like ?"
  5403. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, keyword)
  5404. } else {
  5405. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  5406. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  5407. }
  5408. }
  5409. }
  5410. }
  5411. }
  5412. } else if patientType == 2 {
  5413. if patient_id > 0 {
  5414. if execution_state > 0 {
  5415. if cost_type > 0 {
  5416. if len(execution_frequency) > 0 {
  5417. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  5419. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5420. } else {
  5421. 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 = ?"
  5422. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  5423. }
  5424. } else {
  5425. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  5427. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  5428. } else {
  5429. 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 = ?"
  5430. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5431. }
  5432. }
  5433. } else {
  5434. if len(execution_frequency) > 0 {
  5435. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  5437. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  5438. } else {
  5439. 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 = ?"
  5440. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  5441. }
  5442. } else {
  5443. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  5445. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  5446. } else {
  5447. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  5448. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5449. }
  5450. }
  5451. }
  5452. } else {
  5453. if cost_type > 0 {
  5454. if len(execution_frequency) > 0 {
  5455. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  5457. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  5458. } else {
  5459. 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 = ?"
  5460. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  5461. }
  5462. } else {
  5463. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  5465. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  5466. } else {
  5467. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  5468. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5469. }
  5470. }
  5471. } else {
  5472. if len(execution_frequency) > 0 {
  5473. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  5475. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  5476. } else {
  5477. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_frequency = ?"
  5478. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  5479. }
  5480. } else {
  5481. if len(keyword) > 0 {
  5482. 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 ?"
  5483. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  5484. } else {
  5485. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ?"
  5486. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5487. }
  5488. }
  5489. }
  5490. }
  5491. } else {
  5492. if execution_state > 0 {
  5493. if cost_type > 0 {
  5494. if len(execution_frequency) > 0 {
  5495. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  5497. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  5498. } else {
  5499. 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 = ?"
  5500. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  5501. }
  5502. } else {
  5503. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  5505. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  5506. } else {
  5507. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and is_settle = ?"
  5508. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5509. }
  5510. }
  5511. } else {
  5512. if len(execution_frequency) > 0 {
  5513. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  5515. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  5516. } else {
  5517. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and execution_frequency = ?"
  5518. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  5519. }
  5520. } else {
  5521. if len(keyword) > 0 {
  5522. 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 ?"
  5523. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  5524. } else {
  5525. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ?"
  5526. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5527. }
  5528. }
  5529. }
  5530. } else {
  5531. if cost_type > 0 {
  5532. if len(execution_frequency) > 0 {
  5533. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  5535. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  5536. } else {
  5537. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  5538. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  5539. }
  5540. } else {
  5541. if len(keyword) > 0 {
  5542. 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 ?"
  5543. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  5544. } else {
  5545. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ?"
  5546. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5547. }
  5548. }
  5549. } else {
  5550. if len(execution_frequency) > 0 {
  5551. if len(keyword) > 0 {
  5552. 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 ?"
  5553. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  5554. } else {
  5555. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_frequency = ?"
  5556. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  5557. }
  5558. } else {
  5559. if len(keyword) > 0 {
  5560. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and advice_name like ?"
  5561. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  5562. } else {
  5563. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  5564. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5565. }
  5566. }
  5567. }
  5568. }
  5569. }
  5570. }
  5571. } else if adviceType == 2 && len(deliverWay) > 0 {
  5572. if patientType == 0 {
  5573. if patient_id > 0 {
  5574. if execution_state > 0 {
  5575. if cost_type > 0 {
  5576. if len(execution_frequency) > 0 {
  5577. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  5579. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5580. } else {
  5581. 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 = ?"
  5582. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency)
  5583. }
  5584. } else {
  5585. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  5587. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, keyword)
  5588. } else {
  5589. 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 = ?"
  5590. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  5591. }
  5592. }
  5593. } else {
  5594. if len(execution_frequency) > 0 {
  5595. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  5597. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency, keyword)
  5598. } else {
  5599. 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 = ?"
  5600. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency)
  5601. }
  5602. } else {
  5603. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  5605. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, keyword)
  5606. } else {
  5607. 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 = ?"
  5608. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  5609. }
  5610. }
  5611. }
  5612. } else {
  5613. if cost_type > 0 {
  5614. if len(execution_frequency) > 0 {
  5615. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  5617. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency, keyword)
  5618. } else {
  5619. 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 = ?"
  5620. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency)
  5621. }
  5622. } else {
  5623. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  5625. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, keyword)
  5626. } else {
  5627. 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 = ?"
  5628. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  5629. }
  5630. }
  5631. } else {
  5632. if len(execution_frequency) > 0 {
  5633. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  5635. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency, keyword)
  5636. } else {
  5637. 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 = ?"
  5638. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency)
  5639. }
  5640. } else {
  5641. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  5643. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, keyword)
  5644. } else {
  5645. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ?"
  5646. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  5647. }
  5648. }
  5649. }
  5650. }
  5651. } else {
  5652. if execution_state > 0 {
  5653. if cost_type > 0 {
  5654. if len(execution_frequency) > 0 {
  5655. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  5657. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency, keyword)
  5658. } else {
  5659. 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 = ?"
  5660. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency)
  5661. }
  5662. } else {
  5663. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  5665. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, keyword)
  5666. } else {
  5667. 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 = ?"
  5668. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  5669. }
  5670. }
  5671. } else {
  5672. if len(execution_frequency) > 0 {
  5673. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  5675. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency, keyword)
  5676. } else {
  5677. 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 = ?"
  5678. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency)
  5679. }
  5680. } else {
  5681. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  5683. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, keyword)
  5684. } else {
  5685. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and execution_state = ?"
  5686. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  5687. }
  5688. }
  5689. }
  5690. } else {
  5691. if cost_type > 0 {
  5692. if len(execution_frequency) > 0 {
  5693. if len(keyword) > 0 {
  5694. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5695. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, execution_frequency, keyword)
  5696. } else {
  5697. 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 = ?"
  5698. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, execution_frequency)
  5699. }
  5700. } else {
  5701. if len(keyword) > 0 {
  5702. 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 ?"
  5703. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, keyword)
  5704. } else {
  5705. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and is_settle = ?"
  5706. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  5707. }
  5708. }
  5709. } else {
  5710. if len(execution_frequency) > 0 {
  5711. if len(keyword) > 0 {
  5712. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and execution_frequency = ? and advice_name like ?"
  5713. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_frequency, keyword)
  5714. } else {
  5715. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and execution_frequency = ?"
  5716. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_frequency)
  5717. }
  5718. } else {
  5719. if len(keyword) > 0 {
  5720. 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 ?"
  5721. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, keyword)
  5722. } else {
  5723. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ?"
  5724. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  5725. }
  5726. }
  5727. }
  5728. }
  5729. }
  5730. } else if patientType == 1 {
  5731. if patient_id > 0 {
  5732. if execution_state > 0 {
  5733. if cost_type > 0 {
  5734. if len(execution_frequency) > 0 {
  5735. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  5737. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5738. } else {
  5739. 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 = ?"
  5740. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type, execution_frequency)
  5741. }
  5742. } else {
  5743. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  5745. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type, keyword)
  5746. } else {
  5747. 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 = ?"
  5748. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type)
  5749. }
  5750. }
  5751. } else {
  5752. if len(execution_frequency) > 0 {
  5753. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  5755. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, execution_frequency, keyword)
  5756. } else {
  5757. 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 = ?"
  5758. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, execution_frequency)
  5759. }
  5760. } else {
  5761. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  5763. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, keyword)
  5764. } else {
  5765. 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 = ?"
  5766. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state)
  5767. }
  5768. }
  5769. }
  5770. } else {
  5771. if cost_type > 0 {
  5772. if len(execution_frequency) > 0 {
  5773. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  5775. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type, execution_frequency, keyword)
  5776. } else {
  5777. 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 = ?"
  5778. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type, execution_frequency)
  5779. }
  5780. } else {
  5781. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  5783. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type, keyword)
  5784. } else {
  5785. 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 = ?"
  5786. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type)
  5787. }
  5788. }
  5789. } else {
  5790. if len(execution_frequency) > 0 {
  5791. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  5793. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_frequency, keyword)
  5794. } else {
  5795. 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 = ?"
  5796. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_frequency)
  5797. }
  5798. } else {
  5799. if len(keyword) > 0 {
  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 = ? and avice_name like ?"
  5801. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, keyword)
  5802. } else {
  5803. 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 = ?"
  5804. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
  5805. }
  5806. }
  5807. }
  5808. }
  5809. } else {
  5810. if execution_state > 0 {
  5811. if cost_type > 0 {
  5812. if len(execution_frequency) > 0 {
  5813. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  5815. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type, execution_frequency, keyword)
  5816. } else {
  5817. 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 = ?"
  5818. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type, execution_frequency)
  5819. }
  5820. } else {
  5821. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  5823. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type, keyword)
  5824. } else {
  5825. 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 = ?"
  5826. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type)
  5827. }
  5828. }
  5829. } else {
  5830. if len(execution_frequency) > 0 {
  5831. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  5833. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, execution_frequency, keyword)
  5834. } else {
  5835. 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 = ?"
  5836. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, execution_frequency)
  5837. }
  5838. } else {
  5839. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  5841. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, keyword)
  5842. } else {
  5843. 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 = ?"
  5844. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state)
  5845. }
  5846. }
  5847. }
  5848. } else {
  5849. if cost_type > 0 {
  5850. if len(execution_frequency) > 0 {
  5851. if len(keyword) > 0 {
  5852. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND(advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5853. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type, execution_frequency, keyword)
  5854. } else {
  5855. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and is_settle = ? and execution_frequency = ?"
  5856. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type, execution_frequency)
  5857. }
  5858. } else {
  5859. if len(keyword) > 0 {
  5860. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and is_settle = ? and advice_name like ?"
  5861. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type, keyword)
  5862. } else {
  5863. 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 = ?"
  5864. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type)
  5865. }
  5866. }
  5867. } else {
  5868. if len(execution_frequency) > 0 {
  5869. if len(keyword) > 0 {
  5870. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and execution_frequency = ? and advic_name like ?"
  5871. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_frequency, keyword)
  5872. } else {
  5873. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and execution_frequency = ?"
  5874. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_frequency)
  5875. }
  5876. } else {
  5877. if len(keyword) > 0 {
  5878. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and advice_name like ?"
  5879. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, keyword)
  5880. } else {
  5881. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? "
  5882. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  5883. }
  5884. }
  5885. }
  5886. }
  5887. }
  5888. } else if patientType == 2 {
  5889. if patient_id > 0 {
  5890. if execution_state > 0 {
  5891. if cost_type > 0 {
  5892. if len(execution_frequency) > 0 {
  5893. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  5895. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5896. } else {
  5897. 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 = ?"
  5898. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency)
  5899. }
  5900. } else {
  5901. if len(keyword) > 0 {
  5902. 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 ?"
  5903. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, keyword)
  5904. } else {
  5905. 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 = ?"
  5906. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  5907. }
  5908. }
  5909. } else {
  5910. if len(execution_frequency) > 0 {
  5911. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  5913. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency, keyword)
  5914. } else {
  5915. 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 = ?"
  5916. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency)
  5917. }
  5918. } else {
  5919. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  5921. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, keyword)
  5922. } else {
  5923. 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 = ?"
  5924. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  5925. }
  5926. }
  5927. }
  5928. } else {
  5929. if cost_type > 0 {
  5930. if len(execution_frequency) > 0 {
  5931. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  5933. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency, keyword)
  5934. } else {
  5935. 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 = ?"
  5936. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency)
  5937. }
  5938. } else {
  5939. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  5941. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, keyword)
  5942. } else {
  5943. 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 = ?"
  5944. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  5945. }
  5946. }
  5947. } else {
  5948. if len(execution_frequency) > 0 {
  5949. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  5951. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency, keyword)
  5952. } else {
  5953. 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 = ?"
  5954. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency)
  5955. }
  5956. } else {
  5957. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  5959. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, keyword)
  5960. } else {
  5961. 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 = ?"
  5962. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  5963. }
  5964. }
  5965. }
  5966. }
  5967. } else {
  5968. if execution_state > 0 {
  5969. if cost_type > 0 {
  5970. if len(execution_frequency) > 0 {
  5971. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  5973. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency, keyword)
  5974. } else {
  5975. 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 = ?"
  5976. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency)
  5977. }
  5978. } else {
  5979. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  5981. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, keyword)
  5982. } else {
  5983. 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 = ?"
  5984. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  5985. }
  5986. }
  5987. } else {
  5988. if len(execution_frequency) > 0 {
  5989. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  5991. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency, keyword)
  5992. } else {
  5993. 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 = ?"
  5994. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency)
  5995. }
  5996. } else {
  5997. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  5999. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, keyword)
  6000. } else {
  6001. 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 = ?"
  6002. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  6003. }
  6004. }
  6005. }
  6006. } else {
  6007. if cost_type > 0 {
  6008. if len(execution_frequency) > 0 {
  6009. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  6011. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, keyword)
  6012. } else {
  6013. 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 = ?"
  6014. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  6015. }
  6016. } else {
  6017. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  6019. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, keyword)
  6020. } else {
  6021. 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 = ?"
  6022. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  6023. }
  6024. }
  6025. } else {
  6026. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  6028. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, keyword)
  6029. } else {
  6030. 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 = ?"
  6031. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  6032. }
  6033. }
  6034. }
  6035. }
  6036. }
  6037. } else if adviceType == 2 && len(deliverWay) <= 0 {
  6038. if patientType == 0 {
  6039. if patient_id > 0 {
  6040. if execution_state > 0 {
  6041. if cost_type > 0 {
  6042. if len(execution_frequency) > 0 {
  6043. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  6045. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  6046. } else {
  6047. 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 = ?"
  6048. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  6049. }
  6050. } else {
  6051. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  6053. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  6054. } else {
  6055. 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 = ?"
  6056. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6057. }
  6058. }
  6059. } else {
  6060. if len(execution_frequency) > 0 {
  6061. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  6063. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  6064. } else {
  6065. 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 = ?"
  6066. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  6067. }
  6068. } else {
  6069. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  6071. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  6072. } else {
  6073. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and execution_state = ?"
  6074. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6075. }
  6076. }
  6077. }
  6078. } else {
  6079. if cost_type > 0 {
  6080. if len(execution_frequency) > 0 {
  6081. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  6083. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  6084. } else {
  6085. 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 = ?"
  6086. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  6087. }
  6088. } else {
  6089. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  6091. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  6092. } else {
  6093. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and is_settle = ?"
  6094. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6095. }
  6096. }
  6097. } else {
  6098. if len(execution_frequency) > 0 {
  6099. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  6101. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  6102. } else {
  6103. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and execution_frequency = ?"
  6104. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  6105. }
  6106. } else {
  6107. if len(keyword) > 0 {
  6108. 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 ?"
  6109. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  6110. } else {
  6111. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ?"
  6112. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6113. }
  6114. }
  6115. }
  6116. }
  6117. } else {
  6118. if execution_state > 0 {
  6119. if cost_type > 0 {
  6120. if len(execution_frequency) > 0 {
  6121. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  6123. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  6124. } else {
  6125. 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 = ?"
  6126. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  6127. }
  6128. } else {
  6129. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  6131. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  6132. } else {
  6133. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and execution_state = ? and is_settle = ?"
  6134. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6135. }
  6136. }
  6137. } else {
  6138. if len(execution_frequency) > 0 {
  6139. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  6141. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  6142. } else {
  6143. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and execution_state = ?and execution_frequency = ?"
  6144. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  6145. }
  6146. } else {
  6147. if len(keyword) > 0 {
  6148. 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 ?"
  6149. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  6150. } else {
  6151. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and execution_state = ?"
  6152. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6153. }
  6154. }
  6155. }
  6156. } else {
  6157. if cost_type > 0 {
  6158. if len(execution_frequency) > 0 {
  6159. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  6161. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  6162. } else {
  6163. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and is_settle = ? and execution_frequency = ?"
  6164. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  6165. }
  6166. }
  6167. } else {
  6168. if len(execution_frequency) > 0 {
  6169. if len(keyword) > 0 {
  6170. 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 ?"
  6171. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  6172. } else {
  6173. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and execution_frequency = ?"
  6174. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  6175. }
  6176. } else {
  6177. if len(keyword) > 0 {
  6178. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and advice_name like ?"
  6179. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  6180. } else {
  6181. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ?"
  6182. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6183. }
  6184. }
  6185. }
  6186. }
  6187. }
  6188. } else if patientType == 1 {
  6189. if patient_id > 0 {
  6190. if execution_state > 0 {
  6191. if cost_type > 0 {
  6192. if len(execution_frequency) > 0 {
  6193. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  6195. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  6196. } else {
  6197. 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 = ?"
  6198. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  6199. }
  6200. } else {
  6201. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  6203. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, keyword)
  6204. } else {
  6205. 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 = ?"
  6206. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  6207. }
  6208. }
  6209. } else {
  6210. if len(execution_frequency) > 0 {
  6211. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  6213. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  6214. } else {
  6215. 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 = ?"
  6216. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  6217. }
  6218. } else {
  6219. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  6221. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, keyword)
  6222. } else {
  6223. 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 = ?"
  6224. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  6225. }
  6226. }
  6227. }
  6228. } else {
  6229. if cost_type > 0 {
  6230. if len(execution_frequency) > 0 {
  6231. if len(keyword) > 0 {
  6232. 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 ?"
  6233. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  6234. } else {
  6235. 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 = ?"
  6236. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  6237. }
  6238. } else {
  6239. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  6241. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, keyword)
  6242. } else {
  6243. 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 = ?"
  6244. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  6245. }
  6246. }
  6247. } else {
  6248. if len(execution_frequency) > 0 {
  6249. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  6251. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency, keyword)
  6252. } else {
  6253. 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 = ?"
  6254. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  6255. }
  6256. } else {
  6257. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  6259. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, keyword)
  6260. } else {
  6261. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ?"
  6262. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  6263. }
  6264. }
  6265. }
  6266. }
  6267. } else {
  6268. if execution_state > 0 {
  6269. if cost_type > 0 {
  6270. if len(execution_frequency) > 0 {
  6271. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  6273. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  6274. } else {
  6275. 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 = ?"
  6276. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  6277. }
  6278. } else {
  6279. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  6281. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, keyword)
  6282. } else {
  6283. 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 = ?"
  6284. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  6285. }
  6286. }
  6287. } else {
  6288. if len(execution_frequency) > 0 {
  6289. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  6291. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency, keyword)
  6292. } else {
  6293. 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 = ?"
  6294. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  6295. }
  6296. } else {
  6297. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  6299. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, keyword)
  6300. } else {
  6301. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and execution_state = ?"
  6302. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  6303. }
  6304. }
  6305. }
  6306. } else {
  6307. if cost_type > 0 {
  6308. if len(execution_frequency) > 0 {
  6309. if len(keyword) > 0 {
  6310. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6311. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency, keyword)
  6312. } else {
  6313. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  6314. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  6315. }
  6316. } else {
  6317. if len(keyword) > 0 {
  6318. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and is_settle = ? and advice_name like ?"
  6319. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, keyword)
  6320. } else {
  6321. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and is_settle = ?"
  6322. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  6323. }
  6324. }
  6325. } else {
  6326. if len(execution_frequency) > 0 {
  6327. if len(keyword) > 0 {
  6328. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and execution_frequency = ? and advice_name like ?"
  6329. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency, keyword)
  6330. } else {
  6331. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and execution_frequency = ?"
  6332. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  6333. }
  6334. } else {
  6335. if len(keyword) > 0 {
  6336. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and advice_name like ?"
  6337. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, keyword)
  6338. } else {
  6339. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ?"
  6340. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  6341. }
  6342. }
  6343. }
  6344. }
  6345. }
  6346. } else if patientType == 2 {
  6347. if patient_id > 0 {
  6348. if execution_state > 0 {
  6349. if cost_type > 0 {
  6350. if len(execution_frequency) > 0 {
  6351. if len(keyword) > 0 {
  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=? and advice_name like ?"
  6353. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  6354. } else {
  6355. 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=?"
  6356. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  6357. }
  6358. } else {
  6359. if len(keyword) > 0 {
  6360. 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 ?"
  6361. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  6362. } else {
  6363. 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 = ?"
  6364. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6365. }
  6366. }
  6367. } else {
  6368. if len(execution_frequency) > 0 {
  6369. if len(keyword) > 0 {
  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=? and advice_name like ?"
  6371. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  6372. } else {
  6373. 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=?"
  6374. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  6375. }
  6376. } else {
  6377. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  6379. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  6380. } else {
  6381. 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 = ?"
  6382. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6383. }
  6384. }
  6385. }
  6386. } else {
  6387. if cost_type > 0 {
  6388. if len(execution_frequency) > 0 {
  6389. if len(keyword) > 0 {
  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=? and advice_name like ?"
  6391. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  6392. } else {
  6393. 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=?"
  6394. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  6395. }
  6396. } else {
  6397. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  6399. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  6400. } else {
  6401. 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 = ?"
  6402. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6403. }
  6404. }
  6405. } else {
  6406. if len(execution_frequency) > 0 {
  6407. if len(keyword) > 0 {
  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=? and advice_name like ?"
  6409. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  6410. } else {
  6411. 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=?"
  6412. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  6413. }
  6414. } else {
  6415. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  6417. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  6418. } else {
  6419. 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 = ?"
  6420. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6421. }
  6422. }
  6423. }
  6424. }
  6425. } else {
  6426. if execution_state > 0 {
  6427. if cost_type > 0 {
  6428. if len(execution_frequency) > 0 {
  6429. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  6431. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  6432. } else {
  6433. 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 = ?"
  6434. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  6435. }
  6436. } else {
  6437. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  6439. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  6440. } else {
  6441. 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 = ?"
  6442. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6443. }
  6444. }
  6445. } else {
  6446. if len(execution_frequency) > 0 {
  6447. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  6449. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  6450. } else {
  6451. 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 = ? "
  6452. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  6453. }
  6454. } else {
  6455. if len(keyword) > 0 {
  6456. 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 ?"
  6457. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  6458. } else {
  6459. 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 = ?"
  6460. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6461. }
  6462. }
  6463. }
  6464. } else {
  6465. if cost_type > 0 {
  6466. if len(execution_frequency) > 0 {
  6467. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  6469. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  6470. } else {
  6471. 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 = ?"
  6472. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  6473. }
  6474. } else {
  6475. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  6477. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  6478. } else {
  6479. 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 = ?"
  6480. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6481. }
  6482. }
  6483. } else {
  6484. if len(execution_frequency) > 0 {
  6485. if len(keyword) > 0 {
  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 = ? and advice_name like ?"
  6487. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  6488. } else {
  6489. 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 = ?"
  6490. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  6491. }
  6492. } else {
  6493. if len(keyword) > 0 {
  6494. 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 ?"
  6495. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  6496. } else {
  6497. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0"
  6498. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6499. }
  6500. }
  6501. }
  6502. }
  6503. }
  6504. }
  6505. }
  6506. db := readDb.Table("xt_schedule")
  6507. if scheduleType > 0 {
  6508. db = db.Where("schedule_type = ?", scheduleType)
  6509. }
  6510. if partitonType > 0 {
  6511. db = db.Where("partition_id = ?", partitonType)
  6512. }
  6513. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6514. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6515. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6516. }).
  6517. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6518. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6519. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6520. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6521. Preload("DoctorAdvices", adviceCondition...).
  6522. Where("status = 1 AND user_org_id = ?", orgID)
  6523. if scheduleDate != 0 {
  6524. db = db.Where("schedule_date = ?", scheduleDate)
  6525. }
  6526. err := db.Find(&vms).Error
  6527. return vms, err
  6528. }
  6529. 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) {
  6530. var vms []*MScheduleDoctorAdviceVM
  6531. adviceWhere := ""
  6532. adviceCondition := []interface{}{}
  6533. if adviceType == 0 {
  6534. if patientType == 0 {
  6535. if patient_id > 0 {
  6536. if execution_state > 0 {
  6537. if cost_type > 0 {
  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= ? and is_settle = ?"
  6539. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6540. } else {
  6541. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  6542. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6543. }
  6544. } else {
  6545. if cost_type > 0 {
  6546. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and is_settle = ?"
  6547. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6548. } else {
  6549. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
  6550. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6551. }
  6552. }
  6553. } else {
  6554. if execution_state > 0 {
  6555. if cost_type > 0 {
  6556. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and is_settle = ?"
  6557. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6558. } else {
  6559. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ?"
  6560. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6561. }
  6562. } else {
  6563. if cost_type > 0 {
  6564. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ?"
  6565. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6566. } else {
  6567. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  6568. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6569. }
  6570. }
  6571. }
  6572. } else if patientType == 1 {
  6573. if patient_id > 0 {
  6574. if execution_state > 0 {
  6575. if cost_type > 0 {
  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= ? and is_settle = ?"
  6577. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  6578. } else {
  6579. 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= ?"
  6580. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  6581. }
  6582. } else {
  6583. if cost_type > 0 {
  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 = ? and is_settle=?"
  6585. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  6586. } else {
  6587. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
  6588. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  6589. }
  6590. }
  6591. } else {
  6592. if execution_state > 0 {
  6593. if cost_type > 0 {
  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 = ? and is_settle=?"
  6595. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  6596. } else {
  6597. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  6598. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  6599. }
  6600. } else {
  6601. if cost_type > 0 {
  6602. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and is_settle=?"
  6603. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  6604. } else {
  6605. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  6606. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  6607. }
  6608. }
  6609. }
  6610. } else if patientType == 2 {
  6611. if patient_id > 0 {
  6612. if execution_state > 0 {
  6613. if cost_type > 0 {
  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 = ? and is_settle=?"
  6615. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6616. } else {
  6617. 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 = ?"
  6618. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6619. }
  6620. } else {
  6621. if cost_type > 0 {
  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 = ?) and is_settle=?"
  6623. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6624. } else {
  6625. 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 = ?)"
  6626. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6627. }
  6628. }
  6629. } else {
  6630. if execution_state > 0 {
  6631. if cost_type > 0 {
  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 = ? and is_settle=?"
  6633. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6634. } else {
  6635. 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 = ?"
  6636. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6637. }
  6638. } else {
  6639. if cost_type > 0 {
  6640. 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 = ?"
  6641. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6642. } else {
  6643. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  6644. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6645. }
  6646. }
  6647. }
  6648. }
  6649. } else if adviceType == 1 {
  6650. if patientType == 0 {
  6651. if patient_id > 0 {
  6652. if execution_state > 0 {
  6653. if cost_type > 0 {
  6654. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  6655. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6656. } else {
  6657. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ?"
  6658. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6659. }
  6660. } else {
  6661. if cost_type > 0 {
  6662. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? "
  6663. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6664. } else {
  6665. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
  6666. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6667. }
  6668. }
  6669. } else {
  6670. if execution_state > 0 {
  6671. if cost_type > 0 {
  6672. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ?"
  6673. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6674. } else {
  6675. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ?"
  6676. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6677. }
  6678. } else {
  6679. if cost_type > 0 {
  6680. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = ? "
  6681. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6682. } else {
  6683. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  6684. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6685. }
  6686. }
  6687. }
  6688. } else if patientType == 1 {
  6689. if patient_id > 0 {
  6690. if execution_state > 0 {
  6691. if cost_type > 0 {
  6692. 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 = ?"
  6693. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  6694. } else {
  6695. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  6696. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  6697. }
  6698. } else {
  6699. if cost_type > 0 {
  6700. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  6701. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  6702. } else {
  6703. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
  6704. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  6705. }
  6706. }
  6707. } else {
  6708. if execution_state > 0 {
  6709. if cost_type > 0 {
  6710. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=? and is_settle = ?"
  6711. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  6712. } else {
  6713. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?"
  6714. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  6715. }
  6716. } else {
  6717. if cost_type > 0 {
  6718. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? "
  6719. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  6720. } else {
  6721. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  6722. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  6723. }
  6724. }
  6725. }
  6726. } else if patientType == 2 {
  6727. if patient_id > 0 {
  6728. if execution_state > 0 {
  6729. if cost_type > 0 {
  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 = ? and is_settle = ?"
  6731. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6732. } else {
  6733. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  6734. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6735. }
  6736. } else {
  6737. if cost_type > 0 {
  6738. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  6739. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6740. } else {
  6741. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
  6742. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6743. }
  6744. }
  6745. } else {
  6746. if execution_state > 0 {
  6747. if cost_type > 0 {
  6748. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  6749. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6750. } else {
  6751. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ?"
  6752. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6753. }
  6754. } else {
  6755. if cost_type > 0 {
  6756. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ?"
  6757. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6758. } else {
  6759. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  6760. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6761. }
  6762. }
  6763. }
  6764. }
  6765. } else if adviceType == 3 {
  6766. if patientType == 0 {
  6767. if patient_id > 0 {
  6768. if execution_state > 0 {
  6769. if cost_type > 0 {
  6770. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  6771. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6772. } else {
  6773. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ?"
  6774. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6775. }
  6776. } else {
  6777. if cost_type > 0 {
  6778. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? "
  6779. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6780. } else {
  6781. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? "
  6782. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6783. }
  6784. }
  6785. } else {
  6786. if execution_state > 0 {
  6787. if cost_type > 0 {
  6788. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ?"
  6789. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6790. } else {
  6791. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? "
  6792. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6793. }
  6794. } else {
  6795. if cost_type > 0 {
  6796. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? "
  6797. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6798. } else {
  6799. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  6800. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6801. }
  6802. }
  6803. }
  6804. } else if patientType == 1 {
  6805. if patient_id > 0 {
  6806. if execution_state > 0 {
  6807. if cost_type > 0 {
  6808. 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 = ?"
  6809. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  6810. } else {
  6811. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  6812. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  6813. }
  6814. } else {
  6815. if cost_type > 0 {
  6816. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  6817. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  6818. } else {
  6819. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
  6820. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  6821. }
  6822. }
  6823. } else {
  6824. if execution_state > 0 {
  6825. if cost_type > 0 {
  6826. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? and is_settle = ?"
  6827. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  6828. } else {
  6829. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? "
  6830. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  6831. }
  6832. } else {
  6833. if cost_type > 0 {
  6834. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ?"
  6835. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  6836. } else {
  6837. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  6838. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  6839. }
  6840. }
  6841. }
  6842. } else if patientType == 2 {
  6843. if patient_id > 0 {
  6844. if execution_state > 0 {
  6845. if cost_type > 0 {
  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 = ? and is_settle = ?"
  6847. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6848. } else {
  6849. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  6850. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6851. }
  6852. } else {
  6853. if cost_type > 0 {
  6854. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  6855. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6856. } else {
  6857. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ?"
  6858. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6859. }
  6860. }
  6861. } else {
  6862. if execution_state > 0 {
  6863. if cost_type > 0 {
  6864. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and is_settle = ?"
  6865. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6866. } else {
  6867. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ?"
  6868. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6869. }
  6870. } else {
  6871. if cost_type > 0 {
  6872. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ?"
  6873. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6874. } else {
  6875. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  6876. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6877. }
  6878. }
  6879. }
  6880. }
  6881. } else if adviceType == 2 && len(deliverWay) > 0 {
  6882. if patientType == 0 {
  6883. if patient_id > 0 {
  6884. if execution_state > 0 {
  6885. if cost_type > 0 {
  6886. 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 = ?"
  6887. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  6888. } else {
  6889. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  6890. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  6891. }
  6892. } else {
  6893. if cost_type > 0 {
  6894. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and is_settle = ?"
  6895. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  6896. } else {
  6897. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ?"
  6898. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  6899. }
  6900. }
  6901. } else {
  6902. if execution_state > 0 {
  6903. if cost_type > 0 {
  6904. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and is_settle = ?"
  6905. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  6906. } else {
  6907. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ?"
  6908. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  6909. }
  6910. } else {
  6911. if cost_type > 0 {
  6912. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and is_settle = ?"
  6913. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  6914. } else {
  6915. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  6916. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  6917. }
  6918. }
  6919. }
  6920. } else if patientType == 1 {
  6921. if patient_id > 0 {
  6922. if execution_state > 0 {
  6923. if cost_type > 0 {
  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 = ? and is_settle = ?"
  6925. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type)
  6926. } else {
  6927. 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 = ?"
  6928. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state)
  6929. }
  6930. } else {
  6931. if cost_type > 0 {
  6932. 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 = ?"
  6933. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type)
  6934. } else {
  6935. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ?"
  6936. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
  6937. }
  6938. }
  6939. } else {
  6940. if execution_state > 0 {
  6941. if cost_type > 0 {
  6942. 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 = ?"
  6943. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type)
  6944. } else {
  6945. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ?"
  6946. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state)
  6947. }
  6948. } else {
  6949. if cost_type > 0 {
  6950. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and is_settle = ?"
  6951. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type)
  6952. } else {
  6953. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  6954. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  6955. }
  6956. }
  6957. }
  6958. } else if patientType == 2 {
  6959. if patient_id > 0 {
  6960. if execution_state > 0 {
  6961. if cost_type > 0 {
  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 = ? and is_settle = ?"
  6963. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  6964. } else {
  6965. 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 = ?"
  6966. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  6967. }
  6968. } else {
  6969. if cost_type > 0 {
  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 = ? and is_settle = ?"
  6971. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  6972. } else {
  6973. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ?"
  6974. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  6975. }
  6976. }
  6977. } else {
  6978. if execution_state > 0 {
  6979. if cost_type > 0 {
  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 = ? and is_settle = ?"
  6981. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  6982. } else {
  6983. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ?"
  6984. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  6985. }
  6986. } else {
  6987. if cost_type > 0 {
  6988. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and is_settle = ?"
  6989. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  6990. } else {
  6991. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  6992. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  6993. }
  6994. }
  6995. }
  6996. }
  6997. } else if adviceType == 2 && len(deliverWay) <= 0 {
  6998. if patientType == 0 {
  6999. if patient_id > 0 {
  7000. if execution_state > 0 {
  7001. if cost_type > 0 {
  7002. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  7003. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  7004. } else {
  7005. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ?"
  7006. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  7007. }
  7008. } else {
  7009. if cost_type > 0 {
  7010. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and is_settle = ?"
  7011. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  7012. } else {
  7013. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ?"
  7014. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  7015. }
  7016. }
  7017. } else {
  7018. if execution_state > 0 {
  7019. if cost_type > 0 {
  7020. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ? and is_settle = ?"
  7021. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  7022. } else {
  7023. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?"
  7024. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  7025. }
  7026. } else {
  7027. if cost_type > 0 {
  7028. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and is_settle = ?"
  7029. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  7030. } else {
  7031. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  7032. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  7033. }
  7034. }
  7035. }
  7036. } else if patientType == 1 {
  7037. if patient_id > 0 {
  7038. if execution_state > 0 {
  7039. if cost_type > 0 {
  7040. 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 = ?"
  7041. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  7042. } else {
  7043. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  7044. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  7045. }
  7046. } else {
  7047. if cost_type > 0 {
  7048. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  7049. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  7050. } else {
  7051. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ?"
  7052. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  7053. }
  7054. }
  7055. } else {
  7056. if execution_state > 0 {
  7057. if cost_type > 0 {
  7058. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ? and is_settle = ?"
  7059. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  7060. } else {
  7061. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ?"
  7062. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  7063. }
  7064. } else {
  7065. if cost_type > 0 {
  7066. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and is_settle = ?"
  7067. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  7068. } else {
  7069. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?"
  7070. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  7071. }
  7072. }
  7073. }
  7074. } else if patientType == 2 {
  7075. if patient_id > 0 {
  7076. if execution_state > 0 {
  7077. if cost_type > 0 {
  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 = ? and is_settle = ?"
  7079. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  7080. } else {
  7081. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  7082. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  7083. }
  7084. } else {
  7085. if cost_type > 0 {
  7086. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  7087. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  7088. } else {
  7089. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ?"
  7090. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  7091. }
  7092. }
  7093. } else {
  7094. if execution_state > 0 {
  7095. if cost_type > 0 {
  7096. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  7097. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  7098. } else {
  7099. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ?"
  7100. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  7101. }
  7102. } else {
  7103. if cost_type > 0 {
  7104. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and is_settle = ?"
  7105. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  7106. } else {
  7107. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  7108. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  7109. }
  7110. }
  7111. }
  7112. }
  7113. }
  7114. db := readDb.Table("xt_schedule")
  7115. if scheduleType > 0 {
  7116. db = db.Where("schedule_type = ?", scheduleType)
  7117. }
  7118. if partitonType > 0 {
  7119. db = db.Where("partition_id = ?", partitonType)
  7120. }
  7121. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7122. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7123. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7124. }).
  7125. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7126. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7127. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7128. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7129. Preload("DoctorAdvices", adviceCondition...).
  7130. Where("status = 1 AND user_org_id = ?", orgID)
  7131. if scheduleDate != 0 {
  7132. db = db.Where("schedule_date = ?", scheduleDate)
  7133. }
  7134. err := db.Find(&vms).Error
  7135. return vms, err
  7136. }
  7137. func GetLastPatientOrder(id int64) (models.XtDialysisOrder, error) {
  7138. order := models.XtDialysisOrder{}
  7139. err := XTReadDB().Where("id = ? and status = 1", id).Find(&order).Error
  7140. return order, err
  7141. }
  7142. func UpdateMobilePatient(org_id int64, patient_id int64, schedule_remark string) error {
  7143. order := models.XtPatients{}
  7144. 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
  7145. 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
  7146. return err
  7147. }
  7148. func GetDialysisTotalCount(org_id int64, patient_id int64) (models.BloodDialysisOrderCount, error) {
  7149. order := models.BloodDialysisOrderCount{}
  7150. db := XTReadDB().Table("xt_dialysis_order as o")
  7151. 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
  7152. return order, err
  7153. }
  7154. func GetDialysisTotalCountOne(org_id int64, patient_id int64) (models.BloodDialysisOrderCount, error) {
  7155. order := models.BloodDialysisOrderCount{}
  7156. db := XTReadDB().Table("xt_dialysis_order as o")
  7157. 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>=1735660800 and x.schedule_date = o.dialysis_date and x.status = 1 ", org_id, patient_id).Scan(&order).Error
  7158. return order, err
  7159. }
  7160. func UpdateDialysisOrder(patient_id int64, dialysis_date int64, user_org_id int64, dialysis_total int64) (models.DialysisOrder, error) {
  7161. order := models.DialysisOrder{}
  7162. 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
  7163. return order, err
  7164. }
  7165. func UpdateDeviceInformation(patientid int64, dialysis_date int64) error {
  7166. information := models.DeviceInformation{}
  7167. err := UserWriteDB().Model(&information).Where("patient_id = ? and date = ? and status = 1", patientid, dialysis_date).Update(map[string]interface{}{"status": 0}).Error
  7168. return err
  7169. }
  7170. func MobileGetDoubleCheckSix(orgID int64, patientID int64, recordDate int64) (models.DoubleCheck, error) {
  7171. var record models.DoubleCheck
  7172. err := readDb.Where("patient_id = ? and user_org_id = ? and status = 1 and check_date = ?", patientID, orgID, recordDate).First(&record).Error
  7173. return record, err
  7174. }
  7175. func GetFirstMonitor(patient_id int64, monit_date int64) (models.MonitoringRecord, error) {
  7176. record := models.MonitoringRecord{}
  7177. err := XTReadDB().Where("patient_id = ? and monitoring_date = ? and status=1", patient_id, monit_date).First(&record).Error
  7178. return record, err
  7179. }
  7180. func GetFirstMonitorOne(patient_id int64, monit_date int64, org_id int64) (models.MonitoringRecord, error) {
  7181. record := models.MonitoringRecord{}
  7182. err := XTReadDB().Where("patient_id = ? and monitoring_date = ? and status=1 and user_org_id=?", patient_id, monit_date, org_id).First(&record).Error
  7183. return record, err
  7184. }
  7185. func GetLastMonitor(patient_id int64, monit_date int64, org_id int64) (models.MonitoringRecord, error) {
  7186. record := models.MonitoringRecord{}
  7187. err := XTReadDB().Where("patient_id = ? and monitoring_date = ? and status=1 and user_org_id = ?", patient_id, monit_date, org_id).Last(&record).Error
  7188. return record, err
  7189. }
  7190. func UpdateFirstMonitor(id int64, catheter_operation string) (models.MonitoringRecord, error) {
  7191. record := models.MonitoringRecord{}
  7192. err := XTWriteDB().Model(&record).Where("id = ? and status= 1", id).Updates(map[string]interface{}{"dispose": catheter_operation}).Error
  7193. return record, err
  7194. }
  7195. 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) {
  7196. var vms []*HisMScheduleDoctorAdviceVM
  7197. if len(deliverWay) > 0 {
  7198. db := readDb.Table("xt_schedule")
  7199. if scheduleType > 0 {
  7200. db = db.Where("schedule_type = ?", scheduleType)
  7201. }
  7202. if partitionType > 0 {
  7203. db = db.Where("partition_id = ?", partitionType)
  7204. }
  7205. if patient_id > 0 {
  7206. if execution_state > 0 {
  7207. if cost_type > 0 {
  7208. if len(execution_frequency) > 0 {
  7209. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7210. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7211. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7212. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7213. 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).
  7214. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7215. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7216. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7217. Where("status = 1 AND user_org_id = ?", orgID)
  7218. if scheduleDate != 0 {
  7219. db = db.Where("schedule_date = ?", scheduleDate)
  7220. }
  7221. err = db.Find(&vms).Error
  7222. } else {
  7223. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7224. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7225. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7226. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7227. 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).
  7228. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7229. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7230. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7231. Where("status = 1 AND user_org_id = ?", orgID)
  7232. if scheduleDate != 0 {
  7233. db = db.Where("schedule_date = ?", scheduleDate)
  7234. }
  7235. err = db.Find(&vms).Error
  7236. }
  7237. } else {
  7238. if len(execution_frequency) > 0 {
  7239. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7240. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7241. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7242. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7243. 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).
  7244. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7245. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7246. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7247. Where("status = 1 AND user_org_id = ?", orgID)
  7248. if scheduleDate != 0 {
  7249. db = db.Where("schedule_date = ?", scheduleDate)
  7250. }
  7251. err = db.Find(&vms).Error
  7252. } else {
  7253. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7254. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7255. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7256. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7257. 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).
  7258. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7259. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7260. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7261. Where("status = 1 AND user_org_id = ?", orgID)
  7262. if scheduleDate != 0 {
  7263. db = db.Where("schedule_date = ?", scheduleDate)
  7264. }
  7265. err = db.Find(&vms).Error
  7266. }
  7267. }
  7268. } else {
  7269. if cost_type > 0 {
  7270. if len(execution_frequency) > 0 {
  7271. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7272. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7273. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7274. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7275. 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).
  7276. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7277. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7278. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7279. Where("status = 1 AND user_org_id = ?", orgID)
  7280. if scheduleDate != 0 {
  7281. db = db.Where("schedule_date = ?", scheduleDate)
  7282. }
  7283. err = db.Find(&vms).Error
  7284. } else {
  7285. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7286. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7287. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7288. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7289. 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).
  7290. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7291. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7292. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7293. Where("status = 1 AND user_org_id = ?", orgID)
  7294. if scheduleDate != 0 {
  7295. db = db.Where("schedule_date = ?", scheduleDate)
  7296. }
  7297. err = db.Find(&vms).Error
  7298. }
  7299. } else {
  7300. if len(execution_frequency) > 0 {
  7301. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7302. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7303. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7304. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7305. 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).
  7306. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7307. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7308. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7309. Where("status = 1 AND user_org_id = ?", orgID)
  7310. if scheduleDate != 0 {
  7311. db = db.Where("schedule_date = ?", scheduleDate)
  7312. }
  7313. err = db.Find(&vms).Error
  7314. } else {
  7315. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7316. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7317. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7318. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7319. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ?", orgID, scheduleDate, deliverWay, patient_id).
  7320. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7321. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7322. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7323. Where("status = 1 AND user_org_id = ?", orgID)
  7324. if scheduleDate != 0 {
  7325. db = db.Where("schedule_date = ?", scheduleDate)
  7326. }
  7327. err = db.Find(&vms).Error
  7328. }
  7329. }
  7330. }
  7331. } else {
  7332. if execution_state > 0 {
  7333. if cost_type > 0 {
  7334. if len(execution_frequency) > 0 {
  7335. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7336. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7337. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7338. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7339. 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).
  7340. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7341. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7342. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7343. Where("status = 1 AND user_org_id = ?", orgID)
  7344. if scheduleDate != 0 {
  7345. db = db.Where("schedule_date = ?", scheduleDate)
  7346. }
  7347. err = db.Find(&vms).Error
  7348. } else {
  7349. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7350. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7351. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7352. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7353. 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).
  7354. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7355. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7356. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7357. Where("status = 1 AND user_org_id = ?", orgID)
  7358. if scheduleDate != 0 {
  7359. db = db.Where("schedule_date = ?", scheduleDate)
  7360. }
  7361. err = db.Find(&vms).Error
  7362. }
  7363. } else {
  7364. if len(execution_frequency) > 0 {
  7365. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7366. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7367. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7368. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7369. 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).
  7370. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7371. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7372. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7373. Where("status = 1 AND user_org_id = ?", orgID)
  7374. if scheduleDate != 0 {
  7375. db = db.Where("schedule_date = ?", scheduleDate)
  7376. }
  7377. err = db.Find(&vms).Error
  7378. } else {
  7379. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7380. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7381. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7382. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7383. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_state = ?", orgID, scheduleDate, deliverWay, execution_state).
  7384. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7385. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7386. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7387. Where("status = 1 AND user_org_id = ?", orgID)
  7388. if scheduleDate != 0 {
  7389. db = db.Where("schedule_date = ?", scheduleDate)
  7390. }
  7391. err = db.Find(&vms).Error
  7392. }
  7393. }
  7394. } else {
  7395. if cost_type > 0 {
  7396. if len(execution_frequency) > 0 {
  7397. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7398. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7399. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7400. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7401. 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).
  7402. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7403. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7404. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7405. Where("status = 1 AND user_org_id = ?", orgID)
  7406. if scheduleDate != 0 {
  7407. db = db.Where("schedule_date = ?", scheduleDate)
  7408. }
  7409. err = db.Find(&vms).Error
  7410. } else {
  7411. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7412. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7413. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7414. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7415. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and is_settle = ?", orgID, scheduleDate, deliverWay, cost_type).
  7416. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7417. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7418. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7419. Where("status = 1 AND user_org_id = ?", orgID)
  7420. if scheduleDate != 0 {
  7421. db = db.Where("schedule_date = ?", scheduleDate)
  7422. }
  7423. err = db.Find(&vms).Error
  7424. }
  7425. } else {
  7426. if len(execution_frequency) > 0 {
  7427. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7428. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7429. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7430. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7431. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_frequency = ?", orgID, scheduleDate, deliverWay, execution_frequency).
  7432. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7433. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7434. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7435. Where("status = 1 AND user_org_id = ?", orgID)
  7436. if scheduleDate != 0 {
  7437. db = db.Where("schedule_date = ?", scheduleDate)
  7438. }
  7439. err = db.Find(&vms).Error
  7440. } else {
  7441. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7442. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7443. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7444. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7445. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  7446. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7447. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7448. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7449. Where("status = 1 AND user_org_id = ?", orgID)
  7450. if scheduleDate != 0 {
  7451. db = db.Where("schedule_date = ?", scheduleDate)
  7452. }
  7453. err = db.Find(&vms).Error
  7454. }
  7455. }
  7456. }
  7457. }
  7458. } else {
  7459. db := readDb.Table("xt_schedule")
  7460. if scheduleType > 0 {
  7461. db = db.Where("schedule_type = ?", scheduleType)
  7462. }
  7463. if partitionType > 0 {
  7464. db = db.Where("partition_id = ?", partitionType)
  7465. }
  7466. if patient_id > 0 {
  7467. if execution_state > 0 {
  7468. if cost_type > 0 {
  7469. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7470. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7471. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7472. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7473. 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).
  7474. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7475. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7476. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7477. Where("status = 1 AND user_org_id = ?", orgID)
  7478. if scheduleDate != 0 {
  7479. db = db.Where("schedule_date = ?", scheduleDate)
  7480. }
  7481. err = db.Find(&vms).Error
  7482. } else {
  7483. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7484. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7485. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7486. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7487. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and execution_state = ?", orgID, scheduleDate, patient_id, execution_state).
  7488. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7489. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7490. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7491. Where("status = 1 AND user_org_id = ?", orgID)
  7492. if scheduleDate != 0 {
  7493. db = db.Where("schedule_date = ?", scheduleDate)
  7494. }
  7495. err = db.Find(&vms).Error
  7496. }
  7497. } else {
  7498. if cost_type > 0 {
  7499. if len(execution_frequency) > 0 {
  7500. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7501. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7502. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7503. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7504. 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).
  7505. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7506. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7507. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7508. Where("status = 1 AND user_org_id = ?", orgID)
  7509. if scheduleDate != 0 {
  7510. db = db.Where("schedule_date = ?", scheduleDate)
  7511. }
  7512. err = db.Find(&vms).Error
  7513. } else {
  7514. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7515. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7516. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7517. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7518. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and is_settle = ?", orgID, scheduleDate, patient_id, cost_type).
  7519. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7520. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7521. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7522. Where("status = 1 AND user_org_id = ?", orgID)
  7523. if scheduleDate != 0 {
  7524. db = db.Where("schedule_date = ?", scheduleDate)
  7525. }
  7526. err = db.Find(&vms).Error
  7527. }
  7528. } else {
  7529. if len(execution_frequency) > 0 {
  7530. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7531. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7532. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7533. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7534. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and execution_frequency = ?", orgID, scheduleDate, patient_id, execution_frequency).
  7535. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7536. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7537. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7538. Where("status = 1 AND user_org_id = ?", orgID)
  7539. if scheduleDate != 0 {
  7540. db = db.Where("schedule_date = ?", scheduleDate)
  7541. }
  7542. err = db.Find(&vms).Error
  7543. } else {
  7544. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7545. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7546. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7547. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7548. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7549. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7550. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7551. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7552. Where("status = 1 AND user_org_id = ?", orgID)
  7553. if scheduleDate != 0 {
  7554. db = db.Where("schedule_date = ?", scheduleDate)
  7555. }
  7556. err = db.Find(&vms).Error
  7557. }
  7558. }
  7559. }
  7560. } else {
  7561. if execution_state > 0 {
  7562. if cost_type > 0 {
  7563. if len(execution_frequency) > 0 {
  7564. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7565. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7566. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7567. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7568. 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).
  7569. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7570. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7571. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7572. Where("status = 1 AND user_org_id = ?", orgID)
  7573. if scheduleDate != 0 {
  7574. db = db.Where("schedule_date = ?", scheduleDate)
  7575. }
  7576. err = db.Find(&vms).Error
  7577. } else {
  7578. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7579. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7580. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7581. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7582. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ? and is_settle = ?", orgID, scheduleDate, execution_state, cost_type).
  7583. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7584. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7585. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7586. Where("status = 1 AND user_org_id = ?", orgID)
  7587. if scheduleDate != 0 {
  7588. db = db.Where("schedule_date = ?", scheduleDate)
  7589. }
  7590. err = db.Find(&vms).Error
  7591. }
  7592. } else {
  7593. if len(execution_frequency) > 0 {
  7594. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7595. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7596. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7597. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7598. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ? and execution_frequency = ?", orgID, scheduleDate, execution_state, execution_frequency).
  7599. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7600. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7601. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7602. Where("status = 1 AND user_org_id = ?", orgID)
  7603. if scheduleDate != 0 {
  7604. db = db.Where("schedule_date = ?", scheduleDate)
  7605. }
  7606. err = db.Find(&vms).Error
  7607. } else {
  7608. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7609. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7610. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7611. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7612. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ?", orgID, scheduleDate, execution_state).
  7613. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7614. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7615. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7616. Where("status = 1 AND user_org_id = ?", orgID)
  7617. if scheduleDate != 0 {
  7618. db = db.Where("schedule_date = ?", scheduleDate)
  7619. }
  7620. err = db.Find(&vms).Error
  7621. }
  7622. }
  7623. } else {
  7624. if cost_type > 0 {
  7625. if len(execution_frequency) > 0 {
  7626. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7627. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7628. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7629. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7630. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and is_settle = ?", orgID, scheduleDate, cost_type).
  7631. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7632. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7633. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7634. Where("status = 1 AND user_org_id = ?", orgID)
  7635. if scheduleDate != 0 {
  7636. db = db.Where("schedule_date = ?", scheduleDate)
  7637. }
  7638. err = db.Find(&vms).Error
  7639. } else {
  7640. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7641. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7642. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7643. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7644. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and is_settle = ? and execution_frequency = ?", orgID, scheduleDate, cost_type, execution_frequency).
  7645. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7646. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7647. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7648. Where("status = 1 AND user_org_id = ?", orgID)
  7649. if scheduleDate != 0 {
  7650. db = db.Where("schedule_date = ?", scheduleDate)
  7651. }
  7652. err = db.Find(&vms).Error
  7653. }
  7654. } else {
  7655. if len(execution_frequency) > 0 {
  7656. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7657. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7658. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7659. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7660. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_frequency = ?", orgID, scheduleDate, execution_frequency).
  7661. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7662. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7663. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7664. Where("status = 1 AND user_org_id = ?", orgID)
  7665. if scheduleDate != 0 {
  7666. db = db.Where("schedule_date = ?", scheduleDate)
  7667. }
  7668. err = db.Find(&vms).Error
  7669. } else {
  7670. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7671. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7672. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7673. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7674. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ?", orgID, scheduleDate).
  7675. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7676. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7677. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7678. Where("status = 1 AND user_org_id = ?", orgID)
  7679. if scheduleDate != 0 {
  7680. db = db.Where("schedule_date = ?", scheduleDate)
  7681. }
  7682. err = db.Find(&vms).Error
  7683. }
  7684. }
  7685. }
  7686. }
  7687. }
  7688. return vms, err
  7689. }
  7690. func GetPatientDryWeight(org_id int64, patient_id int64) (weight []*models.SgjPatientDryweight, err error) {
  7691. err = XTReadDB().Where("user_org_id = ? and patient_id = ? and status =1", org_id, patient_id).Order("id desc").Limit(6).Find(&weight).Error
  7692. return weight, err
  7693. }
  7694. 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) {
  7695. fmt.Println("deliverWay-----------------", deliverWay)
  7696. fmt.Println("execution_frequency------------------", execution_frequency)
  7697. fmt.Println("adviceType-----------------", adviceType)
  7698. fmt.Println("patientType----------------", patientType)
  7699. fmt.Println("patient_id----------------", patient_id)
  7700. fmt.Println("execution_state----------------", execution_state)
  7701. fmt.Println("cost_type---------------------", cost_type)
  7702. fmt.Println("execution_frequency", execution_frequency)
  7703. var vms []*MScheduleDoctorAdviceVM
  7704. adviceWhere := ""
  7705. keyword = "%" + keyword + "%"
  7706. adviceCondition := []interface{}{}
  7707. if adviceType == 1 {
  7708. if patientType == 0 {
  7709. if patient_id > 0 {
  7710. if execution_state > 0 {
  7711. if cost_type > 0 {
  7712. if len(execution_frequency) > 0 {
  7713. if len(keyword) > 0 {
  7714. if len(deliverWay) > 0 {
  7715. 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 ?"
  7716. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency, deliverWay, keyword)
  7717. } else {
  7718. 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 ?"
  7719. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency, keyword)
  7720. }
  7721. } else {
  7722. if len(deliverWay) > 0 {
  7723. 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 =?"
  7724. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency, deliverWay)
  7725. } else {
  7726. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  7727. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency)
  7728. }
  7729. }
  7730. } else {
  7731. if len(keyword) > 0 {
  7732. if len(deliverWay) > 0 {
  7733. 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 =?"
  7734. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, keyword, deliverWay)
  7735. } else {
  7736. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  7737. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, keyword)
  7738. }
  7739. } else {
  7740. if len(deliverWay) > 0 {
  7741. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ? and delivery_way =?"
  7742. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, deliverWay)
  7743. } else {
  7744. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ?"
  7745. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type)
  7746. }
  7747. }
  7748. }
  7749. } else {
  7750. if len(execution_frequency) > 0 {
  7751. if len(keyword) > 0 {
  7752. if len(deliverWay) > 0 {
  7753. 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 =?"
  7754. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency, keyword, deliverWay)
  7755. } else {
  7756. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  7757. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency, keyword)
  7758. }
  7759. } else {
  7760. if len(deliverWay) > 0 {
  7761. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and execution_frequency = ? and delivery_way =?"
  7762. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency, deliverWay)
  7763. } else {
  7764. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and execution_frequency = ?"
  7765. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency)
  7766. }
  7767. }
  7768. } else {
  7769. if len(keyword) > 0 {
  7770. if len(deliverWay) > 0 {
  7771. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and advice_name like ? and delivery_way =?"
  7772. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, keyword, deliverWay)
  7773. } else {
  7774. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and advice_name like ?"
  7775. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, keyword)
  7776. }
  7777. } else {
  7778. if len(deliverWay) > 0 {
  7779. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and delivery_way =?"
  7780. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, deliverWay)
  7781. } else {
  7782. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ?"
  7783. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state)
  7784. }
  7785. }
  7786. }
  7787. }
  7788. } else {
  7789. if cost_type > 0 {
  7790. if len(execution_frequency) > 0 {
  7791. if len(keyword) > 0 {
  7792. if len(deliverWay) > 0 {
  7793. 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 =?"
  7794. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency, keyword, deliverWay)
  7795. } else {
  7796. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  7797. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency, keyword)
  7798. }
  7799. } else {
  7800. if len(deliverWay) > 0 {
  7801. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and execution_frequency = ? and delivery_way =?"
  7802. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency, deliverWay)
  7803. } else {
  7804. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and execution_frequency = ?"
  7805. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency)
  7806. }
  7807. }
  7808. } else {
  7809. if len(keyword) > 0 {
  7810. if len(deliverWay) > 0 {
  7811. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and advice_name like ? and delivery_way =?"
  7812. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, keyword, deliverWay)
  7813. } else {
  7814. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and advice_name like ?"
  7815. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, keyword)
  7816. }
  7817. } else {
  7818. if len(deliverWay) > 0 {
  7819. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and delivery_way =?"
  7820. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, deliverWay)
  7821. } else {
  7822. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? "
  7823. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type)
  7824. }
  7825. }
  7826. }
  7827. } else {
  7828. if len(execution_frequency) > 0 {
  7829. if len(keyword) > 0 {
  7830. if len(deliverWay) > 0 {
  7831. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  7832. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency, keyword, deliverWay)
  7833. } else {
  7834. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_frequency = ? and advice_name like ?"
  7835. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency, keyword)
  7836. }
  7837. } else {
  7838. if len(deliverWay) > 0 {
  7839. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_frequency = ? and delivery_way =?"
  7840. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency, deliverWay)
  7841. } else {
  7842. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_frequency = ?"
  7843. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency)
  7844. }
  7845. }
  7846. } else {
  7847. if len(keyword) > 0 {
  7848. if len(deliverWay) > 0 {
  7849. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and advice_name like ? and delivery_way =?"
  7850. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, keyword, deliverWay)
  7851. } else {
  7852. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and advice_name like ?"
  7853. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, keyword)
  7854. }
  7855. } else {
  7856. if len(deliverWay) > 0 {
  7857. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and delivery_way =?"
  7858. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, deliverWay)
  7859. } else {
  7860. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? "
  7861. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id)
  7862. }
  7863. }
  7864. }
  7865. }
  7866. }
  7867. } else {
  7868. if execution_state > 0 {
  7869. if cost_type > 0 {
  7870. if len(execution_frequency) > 0 {
  7871. if len(keyword) > 0 {
  7872. if len(deliverWay) > 0 {
  7873. 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 =?"
  7874. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency, keyword, deliverWay)
  7875. } else {
  7876. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  7877. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency, keyword)
  7878. }
  7879. } else {
  7880. if len(deliverWay) > 0 {
  7881. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and execution_frequency = ? and delivery_way =?"
  7882. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency, deliverWay)
  7883. } else {
  7884. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and execution_frequency = ?"
  7885. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency)
  7886. }
  7887. }
  7888. } else {
  7889. if len(keyword) > 0 {
  7890. if len(deliverWay) > 0 {
  7891. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and advice_name like ? and delivery_way =?"
  7892. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, keyword, deliverWay)
  7893. } else {
  7894. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and advice_name like ?"
  7895. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, keyword)
  7896. }
  7897. } else {
  7898. if len(deliverWay) > 0 {
  7899. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and delivery_way =?"
  7900. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, deliverWay)
  7901. } else {
  7902. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ?"
  7903. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type)
  7904. }
  7905. }
  7906. }
  7907. } else {
  7908. if len(execution_frequency) > 0 {
  7909. if len(keyword) > 0 {
  7910. if len(deliverWay) > 0 {
  7911. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  7912. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency, keyword, deliverWay)
  7913. } else {
  7914. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and execution_frequency = ? and advice_name like ?"
  7915. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency, keyword)
  7916. }
  7917. } else {
  7918. if len(deliverWay) > 0 {
  7919. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and execution_frequency = ? and delivery_way =?"
  7920. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency, deliverWay)
  7921. } else {
  7922. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and execution_frequency = ?"
  7923. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency)
  7924. }
  7925. }
  7926. } else {
  7927. if len(keyword) > 0 {
  7928. if len(deliverWay) > 0 {
  7929. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and advice_name like ? and delivery_way =?"
  7930. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, keyword, deliverWay)
  7931. } else {
  7932. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and advice_name like ?"
  7933. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, keyword)
  7934. }
  7935. } else {
  7936. if len(deliverWay) > 0 {
  7937. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and delivery_way =?"
  7938. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, deliverWay)
  7939. } else {
  7940. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ?"
  7941. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state)
  7942. }
  7943. }
  7944. }
  7945. }
  7946. } else {
  7947. if cost_type > 0 {
  7948. if len(keyword) > 0 {
  7949. if len(deliverWay) > 0 {
  7950. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and is_settle = ? and advice_name like ? and delivery_way =?"
  7951. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, keyword, deliverWay)
  7952. } else {
  7953. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and is_settle = ? and advice_name like ?"
  7954. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, keyword)
  7955. }
  7956. } else {
  7957. if len(deliverWay) > 0 {
  7958. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and is_settle = ? and delivery_way =?"
  7959. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, deliverWay)
  7960. } else {
  7961. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and is_settle = ? "
  7962. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type)
  7963. }
  7964. }
  7965. } else {
  7966. if len(keyword) > 0 {
  7967. if len(deliverWay) > 0 {
  7968. if len(execution_frequency) > 0 {
  7969. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and advice_name like ? and delivery_way =? and execution_frequency =? "
  7970. adviceCondition = append(adviceCondition, adviceWhere, orgID, keyword, deliverWay, execution_frequency)
  7971. } else {
  7972. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and advice_name like ? and delivery_way =?"
  7973. adviceCondition = append(adviceCondition, adviceWhere, orgID, keyword, deliverWay)
  7974. }
  7975. } else {
  7976. if len(execution_frequency) > 0 {
  7977. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and advice_name like ? and execution_frequency =?"
  7978. adviceCondition = append(adviceCondition, adviceWhere, orgID, keyword, execution_frequency)
  7979. } else {
  7980. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and advice_name like ?"
  7981. adviceCondition = append(adviceCondition, adviceWhere, orgID, keyword)
  7982. }
  7983. }
  7984. } else {
  7985. if len(deliverWay) > 0 {
  7986. if len(execution_frequency) > 0 {
  7987. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and delivery_way =? and execution_frequency =?"
  7988. adviceCondition = append(adviceCondition, adviceWhere, orgID, deliverWay, execution_frequency)
  7989. } else {
  7990. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and delivery_way =?"
  7991. adviceCondition = append(adviceCondition, adviceWhere, orgID, deliverWay)
  7992. }
  7993. } else {
  7994. if len(execution_frequency) > 0 {
  7995. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_frequency =?"
  7996. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_frequency)
  7997. } else {
  7998. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 "
  7999. adviceCondition = append(adviceCondition, adviceWhere, orgID)
  8000. }
  8001. }
  8002. }
  8003. }
  8004. }
  8005. }
  8006. } else if patientType == 1 {
  8007. if patient_id > 0 {
  8008. if execution_state > 0 {
  8009. if cost_type > 0 {
  8010. if len(execution_frequency) > 0 {
  8011. if len(keyword) > 0 {
  8012. if len(deliverWay) > 0 {
  8013. 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 =?"
  8014. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword, deliverWay)
  8015. } else {
  8016. 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 ?"
  8017. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  8018. }
  8019. } else {
  8020. if len(keyword) > 0 {
  8021. if len(deliverWay) > 0 {
  8022. 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 =?"
  8023. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, execution_frequency, deliverWay)
  8024. }
  8025. } else {
  8026. if len(deliverWay) > 0 {
  8027. 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 =?"
  8028. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, execution_frequency, deliverWay)
  8029. } else {
  8030. 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 = ?"
  8031. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  8032. }
  8033. }
  8034. }
  8035. } else {
  8036. if len(keyword) > 0 {
  8037. if len(deliverWay) > 0 {
  8038. 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 =?"
  8039. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, keyword, deliverWay)
  8040. } else {
  8041. 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 ?"
  8042. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, keyword)
  8043. }
  8044. } else {
  8045. if len(deliverWay) > 0 {
  8046. 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 =?"
  8047. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, deliverWay)
  8048. } else {
  8049. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  8050. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type)
  8051. }
  8052. }
  8053. }
  8054. } else {
  8055. if len(execution_frequency) > 0 {
  8056. if len(keyword) > 0 {
  8057. if len(deliverWay) > 0 {
  8058. 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 =?"
  8059. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, execution_frequency, keyword, deliverWay)
  8060. } else {
  8061. 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 ?"
  8062. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  8063. }
  8064. } else {
  8065. if len(deliverWay) > 0 {
  8066. 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 =?"
  8067. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, execution_frequency, deliverWay)
  8068. } else {
  8069. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  8070. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, execution_frequency)
  8071. }
  8072. }
  8073. } else {
  8074. if len(keyword) > 0 {
  8075. if len(deliverWay) > 0 {
  8076. 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 =?"
  8077. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, keyword, deliverWay)
  8078. } else {
  8079. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  8080. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, keyword)
  8081. }
  8082. } else {
  8083. if len(deliverWay) > 0 {
  8084. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and delivery_way =?"
  8085. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, deliverWay)
  8086. } else {
  8087. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  8088. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state)
  8089. }
  8090. }
  8091. }
  8092. }
  8093. } else {
  8094. if cost_type > 0 {
  8095. if len(execution_frequency) > 0 {
  8096. if len(keyword) > 0 {
  8097. if len(deliverWay) > 0 {
  8098. 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 =?"
  8099. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, execution_frequency, keyword, deliverWay)
  8100. } else {
  8101. 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 ?"
  8102. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  8103. }
  8104. } else {
  8105. if len(deliverWay) > 0 {
  8106. 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 =?"
  8107. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, execution_frequency, deliverWay)
  8108. } else {
  8109. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ?and execution_frequency = ?"
  8110. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, execution_frequency)
  8111. }
  8112. }
  8113. } else {
  8114. if len(keyword) > 0 {
  8115. if len(deliverWay) > 0 {
  8116. 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 =?"
  8117. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, keyword, deliverWay)
  8118. } else {
  8119. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  8120. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, keyword)
  8121. }
  8122. } else {
  8123. if len(deliverWay) > 0 {
  8124. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ? and delivery_way =? "
  8125. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, deliverWay)
  8126. } else {
  8127. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  8128. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type)
  8129. }
  8130. }
  8131. }
  8132. } else {
  8133. if len(execution_frequency) > 0 {
  8134. if len(keyword) > 0 {
  8135. if len(deliverWay) > 0 {
  8136. 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 =? "
  8137. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_frequency, keyword, deliverWay)
  8138. } else {
  8139. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  8140. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_frequency, keyword)
  8141. }
  8142. } else {
  8143. if len(deliverWay) > 0 {
  8144. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_frequency = ? and delivery_way =? "
  8145. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_frequency, deliverWay)
  8146. } else {
  8147. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  8148. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_frequency)
  8149. }
  8150. }
  8151. } else {
  8152. if len(keyword) > 0 {
  8153. if len(deliverWay) > 0 {
  8154. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and advice_name like ? and delivery_way =?"
  8155. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, keyword, deliverWay)
  8156. } else {
  8157. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and advice_name like ?"
  8158. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, keyword)
  8159. }
  8160. } else {
  8161. if len(deliverWay) > 0 {
  8162. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and delivery_way =?"
  8163. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, deliverWay)
  8164. } else {
  8165. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ?"
  8166. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id)
  8167. }
  8168. }
  8169. }
  8170. }
  8171. }
  8172. } else {
  8173. if execution_state > 0 {
  8174. if cost_type > 0 {
  8175. if len(execution_frequency) > 0 {
  8176. if len(keyword) > 0 {
  8177. if len(deliverWay) > 0 {
  8178. 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 =?"
  8179. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, execution_frequency, keyword, deliverWay)
  8180. } else {
  8181. 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 ?"
  8182. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  8183. }
  8184. } else {
  8185. if len(deliverWay) > 0 {
  8186. 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 =?"
  8187. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, execution_frequency, deliverWay)
  8188. } else {
  8189. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ?and execution_frequency = ?"
  8190. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, execution_frequency)
  8191. }
  8192. }
  8193. } else {
  8194. if len(keyword) > 0 {
  8195. if len(deliverWay) > 0 {
  8196. 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 =?"
  8197. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, keyword, deliverWay)
  8198. } else {
  8199. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ? and advice_name like ?"
  8200. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, keyword)
  8201. }
  8202. } else {
  8203. if len(deliverWay) > 0 {
  8204. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ? and delivery_way =?"
  8205. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, deliverWay)
  8206. } else {
  8207. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ?"
  8208. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type)
  8209. }
  8210. }
  8211. }
  8212. } else {
  8213. if len(execution_frequency) > 0 {
  8214. if len(keyword) > 0 {
  8215. if len(deliverWay) > 0 {
  8216. 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 =?"
  8217. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, execution_frequency, keyword, deliverWay)
  8218. } else {
  8219. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=?and execution_frequency = ? and advice_name like ?"
  8220. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, execution_frequency, keyword)
  8221. }
  8222. } else {
  8223. if len(deliverWay) > 0 {
  8224. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=?and execution_frequency = ? and delivery_way =?"
  8225. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, execution_frequency, deliverWay)
  8226. } else {
  8227. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=?and execution_frequency = ?"
  8228. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, execution_frequency)
  8229. }
  8230. }
  8231. } else {
  8232. if len(keyword) > 0 {
  8233. if len(deliverWay) > 0 {
  8234. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and advice_name like ? and delivery_way =?"
  8235. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, keyword, deliverWay)
  8236. } else {
  8237. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and advice_name like ?"
  8238. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, keyword)
  8239. }
  8240. } else {
  8241. if len(deliverWay) > 0 {
  8242. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and delivery_way =?"
  8243. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, deliverWay)
  8244. } else {
  8245. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=?"
  8246. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state)
  8247. }
  8248. }
  8249. }
  8250. }
  8251. } else {
  8252. if cost_type > 0 {
  8253. if len(execution_frequency) > 0 {
  8254. if len(keyword) > 0 {
  8255. if len(deliverWay) > 0 {
  8256. 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 =?"
  8257. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, execution_frequency, keyword, deliverWay)
  8258. } else {
  8259. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  8260. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, execution_frequency, keyword)
  8261. }
  8262. } else {
  8263. if len(deliverWay) > 0 {
  8264. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and execution_frequency = ? and delivery_way =?"
  8265. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, execution_frequency, deliverWay)
  8266. } else {
  8267. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  8268. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, execution_frequency)
  8269. }
  8270. }
  8271. } else {
  8272. if len(keyword) > 0 {
  8273. if len(deliverWay) > 0 {
  8274. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and advice_name like ? and delivery_way =?"
  8275. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, keyword, deliverWay)
  8276. } else {
  8277. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and advice_name like ?"
  8278. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, keyword)
  8279. }
  8280. } else {
  8281. if len(deliverWay) > 0 {
  8282. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and delivery_way =?"
  8283. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, deliverWay)
  8284. } else {
  8285. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? "
  8286. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type)
  8287. }
  8288. }
  8289. }
  8290. } else {
  8291. if len(execution_frequency) > 0 {
  8292. if len(keyword) > 0 {
  8293. if len(deliverWay) > 0 {
  8294. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  8295. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_frequency, keyword, deliverWay)
  8296. } else {
  8297. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_frequency = ? and advice_name like ?"
  8298. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_frequency, keyword)
  8299. }
  8300. } else {
  8301. if len(deliverWay) > 0 {
  8302. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_frequency = ? and delivery_way =?"
  8303. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_frequency, deliverWay)
  8304. } else {
  8305. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_frequency = ?"
  8306. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_frequency)
  8307. }
  8308. }
  8309. } else {
  8310. if len(keyword) > 0 {
  8311. if len(deliverWay) > 0 {
  8312. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and advice_name like ? and delivery_way =?"
  8313. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, keyword, deliverWay)
  8314. } else {
  8315. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and advice_name like ?"
  8316. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, keyword)
  8317. }
  8318. } else {
  8319. if len(deliverWay) > 0 {
  8320. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and delivery_way =?"
  8321. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, deliverWay)
  8322. } else {
  8323. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? "
  8324. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId)
  8325. }
  8326. }
  8327. }
  8328. }
  8329. }
  8330. }
  8331. } else if patientType == 2 {
  8332. if patient_id > 0 {
  8333. if execution_state > 0 {
  8334. if cost_type > 0 {
  8335. if len(execution_frequency) > 0 {
  8336. if len(keyword) > 0 {
  8337. if len(deliverWay) > 0 {
  8338. 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 =?"
  8339. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency, keyword, deliverWay)
  8340. } else {
  8341. 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 ?"
  8342. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency, keyword)
  8343. }
  8344. } else {
  8345. if len(deliverWay) > 0 {
  8346. 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 =?"
  8347. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency, deliverWay)
  8348. } else {
  8349. 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 = ?"
  8350. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency)
  8351. }
  8352. }
  8353. } else {
  8354. if len(keyword) > 0 {
  8355. if len(deliverWay) > 0 {
  8356. 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 =?"
  8357. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, keyword, deliverWay)
  8358. } else {
  8359. 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 ?"
  8360. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, keyword)
  8361. }
  8362. } else {
  8363. if len(deliverWay) > 0 {
  8364. 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 =?"
  8365. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, deliverWay)
  8366. } else {
  8367. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ?"
  8368. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type)
  8369. }
  8370. }
  8371. }
  8372. } else {
  8373. if len(execution_frequency) > 0 {
  8374. if len(keyword) > 0 {
  8375. if len(deliverWay) > 0 {
  8376. 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 =?"
  8377. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency, keyword, deliverWay)
  8378. } else {
  8379. 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 ?"
  8380. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency, keyword)
  8381. }
  8382. } else {
  8383. if len(deliverWay) > 0 {
  8384. 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 =?"
  8385. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency, deliverWay)
  8386. } else {
  8387. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and execution_frequency = ?"
  8388. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency)
  8389. }
  8390. }
  8391. } else {
  8392. if len(keyword) > 0 {
  8393. if len(deliverWay) > 0 {
  8394. 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 =?"
  8395. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, keyword, deliverWay)
  8396. } else {
  8397. 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 ?"
  8398. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, keyword)
  8399. }
  8400. } else {
  8401. if len(deliverWay) > 0 {
  8402. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and delivery_way =?"
  8403. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, deliverWay)
  8404. } else {
  8405. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  8406. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state)
  8407. }
  8408. }
  8409. }
  8410. }
  8411. } else {
  8412. if cost_type > 0 {
  8413. if len(execution_frequency) > 0 {
  8414. if len(keyword) > 0 {
  8415. if len(deliverWay) > 0 {
  8416. 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 =?"
  8417. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency, keyword, deliverWay)
  8418. } else {
  8419. 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 ?"
  8420. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency, keyword)
  8421. }
  8422. } else {
  8423. if len(deliverWay) > 0 {
  8424. 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 =?"
  8425. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency, deliverWay)
  8426. } else {
  8427. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and is_settle = ? and execution_frequency = ?"
  8428. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency)
  8429. }
  8430. }
  8431. } else {
  8432. if len(keyword) > 0 {
  8433. if len(deliverWay) > 0 {
  8434. 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 =?"
  8435. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, keyword, deliverWay)
  8436. } else {
  8437. 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 ?"
  8438. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, keyword)
  8439. }
  8440. } else {
  8441. if len(deliverWay) > 0 {
  8442. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and is_settle = ? and delivery_way =?"
  8443. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, deliverWay)
  8444. } else {
  8445. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  8446. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type)
  8447. }
  8448. }
  8449. }
  8450. } else {
  8451. if len(execution_frequency) > 0 {
  8452. if len(keyword) > 0 {
  8453. if len(deliverWay) > 0 {
  8454. 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 =?"
  8455. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency, keyword, deliverWay)
  8456. } else {
  8457. 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 ?"
  8458. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency, keyword)
  8459. }
  8460. } else {
  8461. if len(deliverWay) > 0 {
  8462. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_frequency = ? and delivery_way =?"
  8463. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency, deliverWay)
  8464. } else {
  8465. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_frequency = ?"
  8466. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency)
  8467. }
  8468. }
  8469. } else {
  8470. if len(keyword) > 0 {
  8471. if len(deliverWay) > 0 {
  8472. 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 =?"
  8473. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, keyword, deliverWay)
  8474. } else {
  8475. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and advice_name like ?"
  8476. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, keyword)
  8477. }
  8478. } else {
  8479. if len(deliverWay) > 0 {
  8480. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and delivery_way =?"
  8481. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, deliverWay)
  8482. } else {
  8483. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ?"
  8484. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id)
  8485. }
  8486. }
  8487. }
  8488. }
  8489. }
  8490. } else {
  8491. if execution_state > 0 {
  8492. if cost_type > 0 {
  8493. if len(execution_frequency) > 0 {
  8494. if len(keyword) > 0 {
  8495. if len(deliverWay) > 0 {
  8496. 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 =?"
  8497. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency, keyword, deliverWay)
  8498. } else {
  8499. 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 ?"
  8500. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency, keyword)
  8501. }
  8502. } else {
  8503. if len(deliverWay) > 0 {
  8504. 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 =?"
  8505. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency, deliverWay)
  8506. } else {
  8507. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ? and execution_frequency = ?"
  8508. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency)
  8509. }
  8510. }
  8511. } else {
  8512. if len(keyword) > 0 {
  8513. if len(deliverWay) > 0 {
  8514. 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 =?"
  8515. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, keyword, deliverWay)
  8516. } else {
  8517. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ? and advice_name like ?"
  8518. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, keyword)
  8519. }
  8520. } else {
  8521. if len(deliverWay) > 0 {
  8522. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ? and delivery_way =?"
  8523. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, deliverWay)
  8524. } else {
  8525. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  8526. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type)
  8527. }
  8528. }
  8529. }
  8530. } else {
  8531. if len(execution_frequency) > 0 {
  8532. if len(keyword) > 0 {
  8533. if len(deliverWay) > 0 {
  8534. 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 =?"
  8535. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency, keyword, deliverWay)
  8536. } else {
  8537. 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 ?"
  8538. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency, keyword)
  8539. }
  8540. } else {
  8541. if len(deliverWay) > 0 {
  8542. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ? and execution_frequency = ? and delivery_way =?"
  8543. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency, deliverWay)
  8544. } else {
  8545. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ? and execution_frequency = ?"
  8546. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency)
  8547. }
  8548. }
  8549. } else {
  8550. if len(keyword) > 0 {
  8551. if len(deliverWay) > 0 {
  8552. 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 =?"
  8553. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, keyword, deliverWay)
  8554. } else {
  8555. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ? and advice_name like ?"
  8556. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, keyword)
  8557. }
  8558. } else {
  8559. if len(deliverWay) > 0 {
  8560. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ? and delivery_way =?"
  8561. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, deliverWay)
  8562. } else {
  8563. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ?"
  8564. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state)
  8565. }
  8566. }
  8567. }
  8568. }
  8569. } else {
  8570. if cost_type > 0 {
  8571. if len(execution_frequency) > 0 {
  8572. if len(keyword) > 0 {
  8573. if len(deliverWay) > 0 {
  8574. 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 =?"
  8575. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, execution_frequency, keyword, deliverWay)
  8576. } else {
  8577. 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 ?"
  8578. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, execution_frequency, keyword)
  8579. }
  8580. } else {
  8581. if len(deliverWay) > 0 {
  8582. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ? and execution_frequency = ? and delivery_way =?"
  8583. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, execution_frequency, deliverWay)
  8584. } else {
  8585. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  8586. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, execution_frequency)
  8587. }
  8588. }
  8589. } else {
  8590. if len(keyword) > 0 {
  8591. if len(deliverWay) > 0 {
  8592. 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 =?"
  8593. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, keyword, deliverWay)
  8594. } else {
  8595. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ? and advice_name like ?"
  8596. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, keyword)
  8597. }
  8598. } else {
  8599. if len(deliverWay) > 0 {
  8600. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ? and delivery_way =?"
  8601. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, deliverWay)
  8602. } else {
  8603. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ?"
  8604. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type)
  8605. }
  8606. }
  8607. }
  8608. } else {
  8609. if len(execution_frequency) > 0 {
  8610. if len(keyword) > 0 {
  8611. if len(deliverWay) > 0 {
  8612. 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 =?"
  8613. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_frequency, keyword, deliverWay)
  8614. } else {
  8615. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_frequency = ? and advice_name like ?"
  8616. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_frequency, keyword)
  8617. }
  8618. } else {
  8619. if len(deliverWay) > 0 {
  8620. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_frequency = ? and delivery_way =?"
  8621. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_frequency, deliverWay)
  8622. } else {
  8623. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_frequency = ?"
  8624. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_frequency)
  8625. }
  8626. }
  8627. } else {
  8628. if len(keyword) > 0 {
  8629. if len(deliverWay) > 0 {
  8630. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and advice_name like ? and delivery_way =?"
  8631. adviceCondition = append(adviceCondition, adviceWhere, orgID, keyword, deliverWay)
  8632. } else {
  8633. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and advice_name like ?"
  8634. adviceCondition = append(adviceCondition, adviceWhere, orgID, keyword)
  8635. }
  8636. } else {
  8637. if len(deliverWay) > 0 {
  8638. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and delivery_way =?"
  8639. adviceCondition = append(adviceCondition, adviceWhere, orgID, deliverWay)
  8640. } else {
  8641. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0"
  8642. adviceCondition = append(adviceCondition, adviceWhere, orgID)
  8643. }
  8644. }
  8645. }
  8646. }
  8647. }
  8648. }
  8649. }
  8650. }
  8651. db := readDb.Table("xt_schedule")
  8652. if scheduleType > 0 {
  8653. db = db.Where("schedule_type = ?", scheduleType)
  8654. }
  8655. if partitonType > 0 {
  8656. db = db.Where("partition_id = ?", partitonType)
  8657. }
  8658. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  8659. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  8660. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  8661. }).
  8662. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  8663. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  8664. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  8665. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  8666. Preload("DoctorAdvices", adviceCondition...).
  8667. Where("status = 1 AND user_org_id = ?", orgID)
  8668. if scheduleDate != 0 {
  8669. db = db.Where("schedule_date = ?", scheduleDate)
  8670. }
  8671. err := db.Find(&vms).Error
  8672. return vms, err
  8673. }
  8674. func GetLastAcceptTreatment(user_org_id int64, patient_id int64) (models.ReceiveTreatmentAsses, error) {
  8675. treatmentAsses := models.ReceiveTreatmentAsses{}
  8676. err := XTReadDB().Where("user_org_id = ? and patient_id = ? and status=1 and admission_number<>''", user_org_id, patient_id).Last(&treatmentAsses).Error
  8677. return treatmentAsses, err
  8678. }
  8679. func GetDrugIsShow(id int64, org_id int64) (models.XtBaseDrug, error) {
  8680. baseDrug := models.XtBaseDrug{}
  8681. err := XTReadDB().Where("id = ? and status =1 and org_id = ?", id, org_id).Find(&baseDrug).Error
  8682. return baseDrug, err
  8683. }
  8684. func GetDoctorAdviceByAdviceName(advice_name string, user_org_id int64) (models.BaseDrugLibSeven, error) {
  8685. drugLib := models.BaseDrugLibSeven{}
  8686. err := XTReadDB().Where("drug_name = ? and org_id = ? and status=1", advice_name, user_org_id).Find(&drugLib).Error
  8687. return drugLib, err
  8688. }