mobile_dialysis_service.go 494KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281
  1. package service
  2. import (
  3. "XT_New/models"
  4. "encoding/json"
  5. "fmt"
  6. "github.com/jinzhu/gorm"
  7. "strconv"
  8. "time"
  9. )
  10. // func GetSchedualPatients(orgID int64) ([]*MDialysisScheduleVM, error) {
  11. // var vms []*MDialysisScheduleVM
  12. // err := readDb.
  13. // Table("xt_schedule as sch").
  14. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  15. // Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  16. // Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
  17. // Preload("TreatmentMode", "status = 1").
  18. // Preload("DialysisOrder", "status = 1 AND user_org_id = ?", orgID).
  19. // Preload("DialysisOrder.MonitoringRecords", "status = 1 AND user_org_id = ?", orgID).
  20. // Where("sch.status = 1 AND sch.user_org_id = ? AND schedule_date = 1536768000", orgID).
  21. // Find(&vms).
  22. // Error
  23. // return vms, err
  24. // }
  25. func MobileGetDialysisScheduals(orgID int64, scheduleDate int64, scheduleType int64) ([]*MDialysisScheduleVMForList, error) {
  26. var vms []*MDialysisScheduleVMForList
  27. db := readDb.
  28. Table("xt_schedule as sch").
  29. Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
  30. if scheduleDate != 0 {
  31. db = db.Where("schedule_date = ?", scheduleDate)
  32. }
  33. if scheduleType != 0 {
  34. db = db.Where("schedule_type = ?", scheduleType)
  35. }
  36. err := db.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 = ?", user_org_id, patient_id, mode_id).Find(&solution).Error
  50. return &solution, err
  51. }
  52. func MobileGetWaitingScheduals(orgID int64, scheduleDate int64) ([]*MDialysisScheduleVM, error) {
  53. var vms []*MDialysisScheduleVM
  54. db := readDb.
  55. Table("xt_schedule as sch").
  56. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  57. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  58. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  59. // Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
  60. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  61. Preload("AssessmentBeforeDislysis", "status = 1 AND user_org_id = ? AND assessment_date = ? ", orgID, scheduleDate).
  62. Preload("DialysisOrder", "status = 1 AND user_org_id = ?", orgID).
  63. Preload("Advices", "status = 1 AND user_org_id = ? AND advice_type = 2 ", orgID).
  64. Preload("TreatmentMode", "status = 1").
  65. Preload("TreatmentSummary", "status = 1 AND user_org_id = ?", orgID).
  66. Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
  67. if scheduleDate != 0 {
  68. db = db.Where("schedule_date = ?", scheduleDate)
  69. }
  70. err := db.Find(&vms).Error
  71. return vms, err
  72. }
  73. type VMTreatmentSummary struct {
  74. ID int64 `gorm:"column:id" json:"id"`
  75. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  76. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  77. AssessmentDate int64 `gorm:"column:assessment_date" json:"assessment_date"`
  78. DialysisSummary string `gorm:"column:dialysis_summary" json:"dialysis_summary" form:"dialysis_summary"`
  79. }
  80. func (VMTreatmentSummary) TableName() string {
  81. return "xt_treatment_summary"
  82. }
  83. type AssessmentAfterDislysis struct {
  84. ID int64 `gorm:"column:id" json:"id"`
  85. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  86. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  87. AssessmentDate int64 `gorm:"column:assessment_date" json:"assessment_date"`
  88. WeightAfter float64 `gorm:"column:weight_after" json:"weight_after"`
  89. Status int64 `gorm:"column:status" json:"status"`
  90. }
  91. func (AssessmentAfterDislysis) TableName() string {
  92. return "xt_assessment_after_dislysis"
  93. }
  94. type MDialysisScheduleVM struct {
  95. ID int64 `gorm:"column:id" json:"id"`
  96. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  97. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  98. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  99. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  100. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  101. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  102. ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week"`
  103. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  104. Status int64 `gorm:"column:status" json:"status"`
  105. SchedualPatient *MSchedualPatientVMList `gorm:"ForeignKey:PatientId" json:"patient"`
  106. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  107. DialysisOrder *MDialysisOrderVMList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  108. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  109. AssessmentBeforeDislysis *models.PredialysisEvaluationList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_before_dislysis"`
  110. AssessmentAfterDislysis *AssessmentAfterDislysis `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_after_dislysis"`
  111. HisAdvices []*VMHisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"his_doctor_advice"`
  112. Advices []*VMDoctorAdvice `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  113. TreatmentSummary *VMTreatmentSummary `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"treatment_summary"`
  114. NewDeviceInformation *NewDeviceInformation `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"device_information"`
  115. }
  116. func (MDialysisScheduleVM) TableName() string {
  117. return "xt_schedule"
  118. }
  119. type MDialysisScheduleVMForList struct {
  120. ID int64 `gorm:"column:id" json:"id"`
  121. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  122. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  123. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  124. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  125. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  126. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  127. ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week"`
  128. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  129. Status int64 `gorm:"column:status" json:"status"`
  130. SchedualPatient *models.MSchedualPatientList `gorm:"ForeignKey:PatientId" json:"patient"`
  131. DeviceNumber *models.MDeviceNumberForList `gorm:"ForeignKey:BedId" json:"device_number"`
  132. DialysisOrder *models.MDialysisOrderForList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  133. DialysisLastOrder *models.MDialysisOrderForList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"last_order"`
  134. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  135. AssessmentBeforeDislysis *models.PredialysisEvaluationList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_before_dislysis"`
  136. AssessmentAfterDislysis *models.VMAssessmentAfterDislysis `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_after_dislysis"`
  137. HisAdvices []VMHisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"his_doctor_advice"`
  138. Advices []models.VMDoctorAdviceForList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  139. TreatmentSummary *models.VMTreatmentSummaryForList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"treatment_summary"`
  140. DialysisSolution *models.DialysisSolution `gorm:"ForeignKey:PatientId,ModeId;AssociationForeignKey:PatientId,ModeId" json:"dialysis_solution"`
  141. DoubleCheck *models.DoubleCheck `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dobule_check"`
  142. NewDeviceInformation *NewDeviceInformation `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"device_information"`
  143. //VMMonitoringRecord []models.VMMonitoringRecord `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"monitor_record"`
  144. }
  145. func (MDialysisScheduleVMForList) TableName() string {
  146. return "xt_schedule"
  147. }
  148. type MDeviceNumberVM struct {
  149. models.DeviceNumber
  150. Zone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"zone"`
  151. }
  152. func (MDeviceNumberVM) TableName() string {
  153. return "xt_device_number"
  154. }
  155. type MSchedualPatientVMList struct {
  156. ID int64 `gorm:"column:id" json:"id" form:"id"`
  157. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  158. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  159. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  160. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
  161. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  162. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  163. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  164. Age int64 `gorm:"column:age" json:"age"`
  165. Name string `gorm:"column:name" json:"name" form:"name"`
  166. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  167. UserSysBeforeCount int64 `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
  168. TrobleShoot int64 `gorm:"column:troble_shoot" json:"troble_shoot" form:"troble_shoot"`
  169. SchRemark string `gorm:"column:sch_remark" json:"sch_remark" form:"sch_remark"`
  170. ScheduleRemark string `gorm:"column:schedule_remark" json:"schedule_remark" form:"schedule_remark"`
  171. FirstLetter string `gorm:"column:first_letter" json:"first_letter" form:"first_letter"`
  172. }
  173. func (MSchedualPatientVMList) TableName() string {
  174. return "xt_patients"
  175. }
  176. type MSchedualPatientVM struct {
  177. ID int64 `gorm:"column:id" json:"id" form:"id"`
  178. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  179. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  180. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  181. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  182. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
  183. AdmissionNumber string `gorm:"column:admission_number" json:"admission_number" form:"admission_number"`
  184. Source int64 `gorm:"column:source" json:"source" form:"source"`
  185. Lapseto int64 `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
  186. PartitionId int64 `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
  187. BedId int64 `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
  188. Name string `gorm:"column:name" json:"name" form:"name"`
  189. Alias string `gorm:"column:alias" json:"alias" form:"alias"`
  190. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  191. Nation string `gorm:"column:nation" json:"nation" form:"nation"`
  192. NativePlace string `gorm:"column:native_place" json:"native_place" form:"native_place"`
  193. MaritalStatus int64 `gorm:"column:marital_status" json:"marital_status" form:"marital_status"`
  194. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  195. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  196. ReimbursementWayId int64 `gorm:"column:reimbursement_way_id" json:"reimbursement_way_id" form:"reimbursement_way_id"`
  197. HealthCareType int64 `gorm:"column:health_care_type" json:"health_care_type" form:"health_care_type"`
  198. HealthCareNo string `gorm:"column:health_care_no" json:"health_care_no" form:"health_care_no"`
  199. HealthCareDueDate int64 `gorm:"column:health_care_due_date" json:"health_care_due_date" form:"health_care_due_date"`
  200. Height int64 `gorm:"column:height" json:"height" form:"height"`
  201. BloodType int64 `gorm:"column:blood_type" json:"blood_type" form:"blood_type"`
  202. Rh int64 `gorm:"column:rh" json:"rh" form:"rh"`
  203. HealthCareDueAlertDate int64 `gorm:"column:health_care_due_alert_date" json:"health_care_due_alert_date" form:"health_care_due_alert_date"`
  204. EducationLevel int64 `gorm:"column:education_level" json:"education_level" form:"education_level"`
  205. Profession int64 `gorm:"column:profession" json:"profession" form:"profession"`
  206. Phone string `gorm:"column:phone" json:"phone" form:"phone"`
  207. HomeTelephone string `gorm:"column:home_telephone" json:"home_telephone" form:"home_telephone"`
  208. RelativePhone string `gorm:"column:relative_phone" json:"relative_phone" form:"relative_phone"`
  209. RelativeRelations string `gorm:"column:relative_relations" json:"relative_relations" form:"relative_relations"`
  210. HomeAddress string `gorm:"column:home_address" json:"home_address" form:"home_address"`
  211. WorkUnit string `gorm:"column:work_unit" json:"work_unit" form:"work_unit"`
  212. UnitAddress string `gorm:"column:unit_address" json:"unit_address" form:"unit_address"`
  213. Children int64 `gorm:"column:children" json:"children" form:"children"`
  214. ReceivingDate int64 `gorm:"column:receiving_date" json:"receiving_date" form:"receiving_date"`
  215. IsHospitalFirstDialysis int64 `gorm:"column:is_hospital_first_dialysis" json:"is_hospital_first_dialysis" form:"is_hospital_first_dialysis"`
  216. FirstDialysisDate int64 `gorm:"column:first_dialysis_date" json:"first_dialysis_date" form:"first_dialysis_date"`
  217. FirstDialysisHospital string `gorm:"column:first_dialysis_hospital" json:"first_dialysis_hospital" form:"first_dialysis_hospital"`
  218. InductionPeriod int64 `gorm:"column:induction_period" json:"induction_period" form:"induction_period"`
  219. InitialDialysis int64 `gorm:"column:initial_dialysis" json:"initial_dialysis" form:"initial_dialysis"`
  220. TotalDialysis int64 `gorm:"column:total_dialysis" json:"total_dialysis" form:"total_dialysis"`
  221. AttendingDoctorId int64 `gorm:"column:attending_doctor_id" json:"attending_doctor_id" form:"attending_doctor_id"`
  222. HeadNurseId int64 `gorm:"column:head_nurse_id" json:"head_nurse_id" form:"head_nurse_id"`
  223. Evaluate string `gorm:"column:evaluate" json:"evaluate" form:"evaluate"`
  224. Diagnose string `gorm:"column:diagnose" json:"diagnose" form:"diagnose"`
  225. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  226. RegistrarsId int64 `gorm:"column:registrars_id" json:"registrars_id" form:"registrars_id"`
  227. Registrars string `gorm:"column:registrars" json:"registrars" form:"registrars"`
  228. QrCode string `gorm:"column:qr_code" json:"qr_code" form:"qr_code"`
  229. BindingState int64 `gorm:"column:binding_state" json:"binding_state" form:"binding_state"`
  230. PatientComplains string `gorm:"column:patient_complains" json:"patient_complains"` // 主诉
  231. PresentHistory string `gorm:"column:present_history" json:"present_history"` // 现病史
  232. PastHistory string `gorm:"column:past_history" json:"past_history"` // 既往史
  233. Temperature float64 `gorm:"column:temperature" json:"temperature"` // 体格检查-体温
  234. Pulse int64 `gorm:"column:pulse" json:"pulse"` // 体格检查-脉搏
  235. Respiratory int64 `gorm:"column:respiratory" json:"respiratory"` // 体格检查-呼吸频率
  236. SBP int64 `gorm:"column:sbp" json:"sbp"` // 体格检查-收缩压
  237. DBP int64 `gorm:"column:dbp" json:"dbp"` // 体格检查-舒张压
  238. Status int64 `gorm:"column:status" json:"status" form:"status"`
  239. Age int64 `gorm:"column:age" json:"age"`
  240. IsOpenRemind int64 `gorm:"column:is_open_remind" json:"is_open_remind"`
  241. DialysisAge int64 `gorm:"column:dialysis_age" json:"dialysis_age" form:"dialysis_age"`
  242. ExpenseKind int64 `gorm:"column:expense_kind" json:"expense_kind" form:"expense_kind"`
  243. TellPhone string `gorm:"column:tell_phone" json:"tell_phone" form:"tell_phone"`
  244. FirstTreatmentDate int64 `gorm:"column:first_treatment_date" json:"first_treatment_date" form:"first_treatment_date"`
  245. ContactName string `gorm:"column:contact_name" json:"contact_name" form:"contact_name"`
  246. UserSysBeforeCount int64 `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
  247. FirstLetter string `gorm:"column:first_letter" json:"first_letter" form:"first_letter"`
  248. }
  249. func (MSchedualPatientVM) TableName() string {
  250. return "xt_patients"
  251. }
  252. type MDialysisOrderVM struct {
  253. ID int64 `gorm:"column:id" json:"id"`
  254. DialysisDate int64 `gorm:"column:dialysis_date" json:"dialysis_date"`
  255. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  256. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  257. Stage int64 `gorm:"column:stage" json:"stage"`
  258. BedID int64 `gorm:"column:bed_id" json:"bed_id"`
  259. StartNurse int64 `gorm:"column:start_nurse" json:"start_nurse"`
  260. FinishNurse int64 `gorm:"column:finish_nurse" json:"finish_nurse"`
  261. Status int64 `gorm:"column:status" json:"status"`
  262. PunctureNurse int64 `gorm:"column:puncture_nurse" json:"puncture_nurse"`
  263. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedID" json:"device_number"`
  264. MonitoringRecords []*models.MonitoringRecord `gorm:"ForeignKey:DialysisOrderId" json:"monitoring_records"`
  265. Creator int64 `gorm:"column:creator" json:"creator"`
  266. Modifier int64 `gorm:"column:modifier" json:"modifier"`
  267. FinishCreator int64 `gorm:"column:finish_creator" json:"finish_creator"`
  268. FinishModifier int64 `gorm:"column:finish_modifier" json:"finish_modifier"`
  269. SchedualType int64 `gorm:"column:schedual_type" json:"schedual_type"`
  270. WashpipeNurse int64 `gorm:"column:washpipe_nurse" json:"washpipe_nurse" form:"washpipe_nurse"`
  271. DialysisIrrigation string `gorm:"column:dialysis_irrigation" json:"dialysis_irrigation" form:"dialysis_irrigation"`
  272. DialysisDialyszers string `gorm:"column:dialysis_dialyszers" json:"dialysis_dialyszers" form:"dialysis_dialyszers"`
  273. }
  274. func (MDialysisOrderVM) TableName() string {
  275. return "xt_dialysis_order"
  276. }
  277. type MDialysisOrderVMList struct {
  278. ID int64 `gorm:"column:id" json:"id"`
  279. DialysisDate int64 `gorm:"column:dialysis_date" json:"dialysis_date"`
  280. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  281. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  282. // PrescriptionId int64 `gorm:"column:prescription_id" json:"prescription_id"`
  283. Stage int64 `gorm:"column:stage" json:"stage"`
  284. // Remark string `gorm:"column:remark" json:"remark"`
  285. BedID int64 `gorm:"column:bed_id" json:"bed_id"`
  286. StartNurse int64 `gorm:"column:start_nurse" json:"start_nurse"`
  287. Status int64 `gorm:"column:status" json:"status"`
  288. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedID" json:"device_number"`
  289. Creator int64 `gorm:"column:creator" json:"creator"`
  290. WashpipeNurse int64 `gorm:"column:washpipe_nurse" json:"washpipe_nurse" form:"washpipe_nurse"`
  291. NucleinDate int64 `gorm:"column:nuclein_date" json:"nuclein_date" form:"nuclein_date"`
  292. DialysisIrrigation string `gorm:"column:dialysis_irrigation" json:"dialysis_irrigation" form:"dialysis_irrigation"`
  293. DialysisDialyszers string `gorm:"column:dialysis_dialyszers" json:"dialysis_dialyszers" form:"dialysis_dialyszers"`
  294. ScheduleRemark string `gorm:"column:schedule_remark" json:"schedule_remark" form:"schedule_remark"`
  295. }
  296. func (MDialysisOrderVMList) TableName() string {
  297. return "xt_dialysis_order"
  298. }
  299. type VMDoctorAdvice struct {
  300. ID int64 `gorm:"column:id" json:"id" form:"id"`
  301. GroupNo int64 `gorm:"column:groupno" json:"groupno" form:"groupno"`
  302. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  303. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  304. AdviceDate int64 `gorm:"column:advice_date" json:"advice_date" form:"advice_date"`
  305. Status int64 `gorm:"column:status" json:"status" form:"status"`
  306. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
  307. RecordDate int64 `gorm:"column:record_date" json:"record_date"`
  308. CheckTime int64 `gorm:"column:check_time" json:"check_time" form:"check_time"`
  309. CheckState int64 `gorm:"column:check_state" json:"check_state" form:"check_state"`
  310. ParentId int64 `gorm:"column:parent_id" json:"parent_id" form:"parent_id"`
  311. }
  312. func (VMDoctorAdvice) TableName() string {
  313. return "xt_doctor_advice"
  314. }
  315. type VMHisDoctorAdviceInfo struct {
  316. ID int64 `gorm:"column:id" json:"id" form:"id"`
  317. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  318. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  319. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  320. ExecutionTime int64 `gorm:"column:execution_time" json:"execution_time" form:"execution_time"`
  321. ExecutionStaff int64 `gorm:"column:execution_staff" json:"execution_staff" form:"execution_staff"`
  322. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
  323. IsMedicine int64 `gorm:"column:is_medicine" json:"is_medicine" form:"is_medicine"`
  324. ExecutionFrequencyId int64 `gorm:"column:execution_frequency_id" json:"execution_frequency_id" form:"execution_frequency_id"`
  325. IsSelfDrug int64 `gorm:"column:is_self_drug" json:"is_self_drug" form:"is_self_drug"`
  326. }
  327. func (VMHisDoctorAdviceInfo) TableName() string {
  328. return "his_doctor_advice_info"
  329. }
  330. type VMAssessmentAfterDislysis struct {
  331. ID int64 `gorm:"column:id" json:"id"`
  332. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  333. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  334. AssessmentDate int64 `gorm:"column:assessment_date" json:"assessment_date"`
  335. WeightAfter float64 `gorm:"column:weight_after" json:"weight_after"`
  336. Status int64 `gorm:"column:status" json:"status"`
  337. }
  338. func (VMAssessmentAfterDislysis) TableName() string {
  339. return "xt_assessment_after_dislysis"
  340. }
  341. type NewDeviceInformation struct {
  342. ID int64 `gorm:"column:id" json:"id" form:"id"`
  343. Date int64 `gorm:"column:date" json:"date" form:"date"`
  344. Class int64 `gorm:"column:class" json:"class" form:"class"`
  345. Zone int64 `gorm:"column:zone" json:"zone" form:"zone"`
  346. BedNumber int64 `gorm:"column:bed_number" json:"bed_number" form:"bed_number"`
  347. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  348. Status int64 `gorm:"column:status" json:"status" form:"status"`
  349. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  350. EquimentId int64 `gorm:"column:equiment_id" json:"equiment_id" form:"equiment_id"`
  351. Bed string `gorm:"column:bed" json:"bed" form:"bed"`
  352. Stime int64 `gorm:"column:stime" json:"stime" form:"stime"`
  353. }
  354. func (NewDeviceInformation) TableName() string {
  355. return "xt_device_information"
  356. }
  357. // 获取透析记录
  358. func MobileGetDialysisRecord(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  359. var record models.DialysisOrder
  360. err := readDb.Model(&models.DialysisOrder{}).Where("user_org_id = ? AND patient_id = ? AND dialysis_date = ?", orgID, patientID, recordDate).First(&record).Error
  361. if err != nil {
  362. if err == gorm.ErrRecordNotFound {
  363. return nil, nil
  364. } else {
  365. return nil, err
  366. }
  367. }
  368. return &record, nil
  369. }
  370. // 用户基本信息
  371. func MobileGetPatientDetail(orgID int64, patientID int64) (*MPatient, error) {
  372. var patient MPatient
  373. //err := readDb.Model(&MPatient{}).Where("status = 1 AND user_org_id = ? AND id = ?", orgID, patientID).First(&patient).Error
  374. //if err != nil {
  375. // if err == gorm.ErrRecordNotFound {
  376. // return nil, nil
  377. // } else {
  378. // return nil, err
  379. // }
  380. //}
  381. //return &patient, nil
  382. redis := RedisClient()
  383. defer redis.Close()
  384. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":patient_info"
  385. patient_info_str, _ := redis.Get(key).Result()
  386. if len(patient_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  387. err = readDb.Model(&patient).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
  388. if err != nil {
  389. if err == gorm.ErrRecordNotFound {
  390. return &patient, nil
  391. } else {
  392. return &patient, err
  393. }
  394. } else {
  395. if patient.ID > 0 {
  396. //缓存数据
  397. patient_info_json, err := json.Marshal(&patient)
  398. if err == nil {
  399. redis.Set(key, patient_info_json, time.Second*60*60*18)
  400. }
  401. }
  402. return &patient, nil
  403. }
  404. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  405. json.Unmarshal([]byte(patient_info_str), &patient)
  406. return &patient, nil
  407. }
  408. }
  409. func MobileGetSchedualDetailOne(orgID int64, patientID int64, schedualDate int64) (*MDialysisScheduleVM, error) {
  410. var vm MDialysisScheduleVM
  411. err := readDb.
  412. Table("xt_schedule").
  413. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  414. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  415. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  416. First(&vm).Error
  417. return &vm, err
  418. }
  419. // 用户排班信息
  420. func MobileGetSchedualDetailSix(orgID int64, patientID int64, schedualDate int64) (*MDialysisScheduleVM, error) {
  421. var vm MDialysisScheduleVM
  422. err := readDb.
  423. Table("xt_schedule").
  424. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  425. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  426. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  427. First(&vm).Error
  428. if err != nil {
  429. if err == gorm.ErrRecordNotFound {
  430. return nil, nil
  431. } else {
  432. return nil, err
  433. }
  434. }
  435. return &vm, err
  436. }
  437. // 用户排班信息
  438. func MobileGetSchedualDetail(orgID int64, patientID int64, schedualDate int64) (*MDialysisScheduleVM, error) {
  439. redis := RedisClient()
  440. defer redis.Close()
  441. var vm MDialysisScheduleVM
  442. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(schedualDate, 10) + ":schedual_detail"
  443. redis.Set(key, "", time.Second)
  444. schedual_detail_str, _ := redis.Get(key).Result()
  445. if len(schedual_detail_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  446. err := readDb.
  447. Table("xt_schedule").
  448. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  449. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  450. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  451. First(&vm).Error
  452. if err != nil {
  453. if err == gorm.ErrRecordNotFound {
  454. return nil, nil
  455. } else {
  456. return nil, err
  457. }
  458. } else {
  459. if vm.ID > 0 {
  460. //缓存数据
  461. schedual_detail_str, err := json.Marshal(vm)
  462. if err == nil {
  463. redis.Set(key, schedual_detail_str, time.Second*60*60*18)
  464. }
  465. } else {
  466. redis.Set(key, "null", time.Second*60*60*18)
  467. }
  468. return &vm, nil
  469. }
  470. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  471. if schedual_detail_str == "null" {
  472. return &vm, nil
  473. }
  474. json.Unmarshal([]byte(schedual_detail_str), &vm)
  475. return &vm, nil
  476. }
  477. }
  478. // 用户排班信息
  479. func MobileGetPatientSchedual(orgID int64, patientID int64, schedualDate int64) (*models.Schedule, error) {
  480. var schedule models.Schedule
  481. err := readDb.
  482. Table("xt_schedule").
  483. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  484. First(&schedule).Error
  485. if err != nil {
  486. if err == gorm.ErrRecordNotFound {
  487. return nil, nil
  488. } else {
  489. return nil, err
  490. }
  491. }
  492. return &schedule, nil
  493. }
  494. type MPatient struct {
  495. ID int64 `gorm:"column:id" json:"id" form:"id"`
  496. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  497. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  498. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  499. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  500. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
  501. AdmissionNumber string `gorm:"column:admission_number" json:"admission_number" form:"admission_number"`
  502. Source int64 `gorm:"column:source" json:"source" form:"source"`
  503. Lapseto int64 `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
  504. PartitionId int64 `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
  505. BedId int64 `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
  506. Name string `gorm:"column:name" json:"name" form:"name"`
  507. Alias string `gorm:"column:alias" json:"alias" form:"alias"`
  508. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  509. Nation string `gorm:"column:nation" json:"nation" form:"nation"`
  510. NativePlace string `gorm:"column:native_place" json:"native_place" form:"native_place"`
  511. MaritalStatus int64 `gorm:"column:marital_status" json:"marital_status" form:"marital_status"`
  512. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  513. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  514. ReimbursementWayId int64 `gorm:"column:reimbursement_way_id" json:"reimbursement_way_id" form:"reimbursement_way_id"`
  515. HealthCareType int64 `gorm:"column:health_care_type" json:"health_care_type" form:"health_care_type"`
  516. HealthCareNo string `gorm:"column:health_care_no" json:"health_care_no" form:"health_care_no"`
  517. HealthCareDueDate int64 `gorm:"column:health_care_due_date" json:"health_care_due_date" form:"health_care_due_date"`
  518. Height int64 `gorm:"column:height" json:"height" form:"height"`
  519. BloodType int64 `gorm:"column:blood_type" json:"blood_type" form:"blood_type"`
  520. Rh int64 `gorm:"column:rh" json:"rh" form:"rh"`
  521. HealthCareDueAlertDate int64 `gorm:"column:health_care_due_alert_date" json:"health_care_due_alert_date" form:"health_care_due_alert_date"`
  522. EducationLevel int64 `gorm:"column:education_level" json:"education_level" form:"education_level"`
  523. Profession int64 `gorm:"column:profession" json:"profession" form:"profession"`
  524. Phone string `gorm:"column:phone" json:"phone" form:"phone"`
  525. HomeTelephone string `gorm:"column:home_telephone" json:"home_telephone" form:"home_telephone"`
  526. RelativePhone string `gorm:"column:relative_phone" json:"relative_phone" form:"relative_phone"`
  527. RelativeRelations string `gorm:"column:relative_relations" json:"relative_relations" form:"relative_relations"`
  528. HomeAddress string `gorm:"column:home_address" json:"home_address" form:"home_address"`
  529. WorkUnit string `gorm:"column:work_unit" json:"work_unit" form:"work_unit"`
  530. UnitAddress string `gorm:"column:unit_address" json:"unit_address" form:"unit_address"`
  531. Children int64 `gorm:"column:children" json:"children" form:"children"`
  532. ReceivingDate int64 `gorm:"column:receiving_date" json:"receiving_date" form:"receiving_date"`
  533. IsHospitalFirstDialysis int64 `gorm:"column:is_hospital_first_dialysis" json:"is_hospital_first_dialysis" form:"is_hospital_first_dialysis"`
  534. FirstDialysisDate int64 `gorm:"column:first_dialysis_date" json:"first_dialysis_date" form:"first_dialysis_date"`
  535. FirstDialysisHospital string `gorm:"column:first_dialysis_hospital" json:"first_dialysis_hospital" form:"first_dialysis_hospital"`
  536. InductionPeriod int64 `gorm:"column:induction_period" json:"induction_period" form:"induction_period"`
  537. InitialDialysis int64 `gorm:"column:initial_dialysis" json:"initial_dialysis" form:"initial_dialysis"`
  538. TotalDialysis int64 `gorm:"column:total_dialysis" json:"total_dialysis" form:"total_dialysis"`
  539. AttendingDoctorId int64 `gorm:"column:attending_doctor_id" json:"attending_doctor_id" form:"attending_doctor_id"`
  540. HeadNurseId int64 `gorm:"column:head_nurse_id" json:"head_nurse_id" form:"head_nurse_id"`
  541. Evaluate string `gorm:"column:evaluate" json:"evaluate" form:"evaluate"`
  542. Diagnose string `gorm:"column:diagnose" json:"diagnose" form:"diagnose"`
  543. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  544. RegistrarsId int64 `gorm:"column:registrars_id" json:"registrars_id" form:"registrars_id"`
  545. Registrars string `gorm:"column:registrars" json:"registrars" form:"registrars"`
  546. QrCode string `gorm:"column:qr_code" json:"qr_code" form:"qr_code"`
  547. BindingState int64 `gorm:"column:binding_state" json:"binding_state" form:"binding_state"`
  548. PatientComplains string `gorm:"column:patient_complains" json:"patient_complains"` // 主诉
  549. PresentHistory string `gorm:"column:present_history" json:"present_history"` // 现病史
  550. PastHistory string `gorm:"column:past_history" json:"past_history"` // 既往史
  551. Temperature float64 `gorm:"column:temperature" json:"temperature"` // 体格检查-体温
  552. Pulse int64 `gorm:"column:pulse" json:"pulse"` // 体格检查-脉搏
  553. Respiratory int64 `gorm:"column:respiratory" json:"respiratory"` // 体格检查-呼吸频率
  554. SBP int64 `gorm:"column:sbp" json:"sbp"` // 体格检查-收缩压
  555. DBP int64 `gorm:"column:dbp" json:"dbp"` // 体格检查-舒张压
  556. Status int64 `gorm:"column:status" json:"status" form:"status"`
  557. Age int64 `gorm:"column:age" json:"age"`
  558. IsOpenRemind int64 `gorm:"column:is_open_remind" json:"is_open_remind"`
  559. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  560. DialysisAge int64 `gorm:"column:dialysis_age" json:"dialysis_age" form:"dialysis_age"`
  561. ExpenseKind int64 `gorm:"column:expense_kind" json:"expense_kind" form:"expense_kind"`
  562. TellPhone string `gorm:"column:tell_phone" json:"tell_phone" form:"tell_phone"`
  563. FirstTreatmentDate int64 `gorm:"column:first_treatment_date" json:"first_treatment_date" form:"first_treatment_date"`
  564. ContactName string `gorm:"column:contact_name" json:"contact_name" form:"contact_name"`
  565. UserSysBeforeCount int64 `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
  566. }
  567. func (MPatient) TableName() string {
  568. return "xt_patients"
  569. }
  570. // 接诊评估
  571. func MobileGetReceiverTreatmentAccessRecord(orgID int64, patientID int64, recordDate int64) (*models.ReceiveTreatmentAsses, error) {
  572. var record models.ReceiveTreatmentAsses
  573. redis := RedisClient()
  574. defer redis.Close()
  575. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":receive_treatment_asses"
  576. receive_treatment_asses_str, _ := redis.Get(key).Result()
  577. if len(receive_treatment_asses_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  578. err = readDb.Model(&models.ReceiveTreatmentAsses{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  579. if err != nil {
  580. if err == gorm.ErrRecordNotFound {
  581. if record.ID <= 0 {
  582. redis.Set(key, "", time.Second*60*60*18)
  583. }
  584. return nil, nil
  585. } else {
  586. return nil, err
  587. }
  588. } else {
  589. if record.ID > 0 {
  590. //缓存数据
  591. receive_treatment_asses_str, err := json.Marshal(record)
  592. if err == nil {
  593. redis.Set(key, receive_treatment_asses_str, time.Second*60*60*18)
  594. }
  595. } else {
  596. redis.Set(key, "null", time.Second*60*60*18)
  597. }
  598. return &record, nil
  599. }
  600. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  601. if receive_treatment_asses_str == "null" {
  602. return &record, nil
  603. }
  604. json.Unmarshal([]byte(receive_treatment_asses_str), &record)
  605. return &record, nil
  606. }
  607. }
  608. // 透前评估
  609. func MobileGetPredialysisEvaluationOne(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
  610. var record models.PredialysisEvaluation
  611. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  612. if err != nil {
  613. if err == gorm.ErrRecordNotFound {
  614. return nil, nil
  615. } else {
  616. return nil, err
  617. }
  618. }
  619. return &record, nil
  620. }
  621. func MobileGetPredialysisEvaluationTwo(orgID int64, patientID int64, recordDate int64) (models.PredialysisEvaluation, error) {
  622. var record models.PredialysisEvaluation
  623. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  624. return record, err
  625. }
  626. // 透前评估
  627. func MobileGetPredialysisEvaluation(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
  628. var record models.PredialysisEvaluation
  629. redis := RedisClient()
  630. defer redis.Close()
  631. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":assessment_before_dislysis"
  632. assessment_before_dislysis_str, _ := redis.Get(key).Result()
  633. redis.Set(key, "", time.Second)
  634. if len(assessment_before_dislysis_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  635. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  636. if err != nil {
  637. if err == gorm.ErrRecordNotFound {
  638. if record.ID <= 0 {
  639. redis.Set(key, "", time.Second*60*60*18)
  640. }
  641. return nil, nil
  642. } else {
  643. return nil, err
  644. }
  645. } else {
  646. if record.ID > 0 {
  647. //缓存数据
  648. assessment_before_dislysis_str, err := json.Marshal(record)
  649. if err == nil {
  650. redis.Set(key, assessment_before_dislysis_str, time.Second*60*60*18)
  651. }
  652. } else {
  653. redis.Set(key, "null", time.Second*60*60*18)
  654. }
  655. return &record, nil
  656. }
  657. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  658. if assessment_before_dislysis_str == "null" {
  659. return &record, nil
  660. } else {
  661. json.Unmarshal([]byte(assessment_before_dislysis_str), &record)
  662. return &record, nil
  663. }
  664. }
  665. }
  666. // 获取 maxDate 之前一次的透前评估记录
  667. func MobileGetLastTimePredialysisEvaluationOne(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
  668. var record models.PredialysisEvaluation
  669. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date < ?", patientID, orgID, maxDate).Order("assessment_date desc").First(&record).Error
  670. if err != nil {
  671. if err == gorm.ErrRecordNotFound {
  672. return nil, nil
  673. } else {
  674. return nil, err
  675. }
  676. }
  677. return &record, nil
  678. }
  679. // 获取 maxDate 之前一次的透前评估记录
  680. func MobileGetLastTimePredialysisEvaluation(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
  681. var record models.PredialysisEvaluation
  682. redis := RedisClient()
  683. defer redis.Close()
  684. // cur_date := time.Now().Format("2006-01-02")
  685. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(maxDate, 10) + ":assessment_before_dislysis_last"
  686. assessment_before_dislysis_last_str, _ := redis.Get(key).Result()
  687. if len(assessment_before_dislysis_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  688. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date < ?", patientID, orgID, maxDate).Order("assessment_date desc").First(&record).Error
  689. if err != nil {
  690. if err == gorm.ErrRecordNotFound {
  691. if record.ID <= 0 {
  692. redis.Set(key, "", time.Second*60*60*18)
  693. }
  694. return nil, nil
  695. } else {
  696. return nil, err
  697. }
  698. } else {
  699. if record.ID > 0 {
  700. //缓存数据
  701. assessment_before_dislysis_last_str, err := json.Marshal(record)
  702. if err == nil {
  703. redis.Set(key, assessment_before_dislysis_last_str, time.Second*60*60*4)
  704. }
  705. } else {
  706. redis.Set(key, "null", time.Second*60*60*18)
  707. }
  708. return &record, nil
  709. }
  710. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  711. if assessment_before_dislysis_last_str == "null" {
  712. return &record, nil
  713. } else {
  714. json.Unmarshal([]byte(assessment_before_dislysis_last_str), &record)
  715. return &record, nil
  716. }
  717. }
  718. }
  719. // 临时医嘱
  720. func MobileGetDoctorAdvices(orgID int64, patientID int64, recordDate int64) ([]*models.DoctorAdvice, error) {
  721. var records []*models.DoctorAdvice
  722. // err := readDb.Model(&models.DoctorAdvice{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).Find(&records).Error
  723. err := readDb.
  724. Model(&models.DoctorAdvice{}).
  725. Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? and (advice_type = 2 or advice_type = 3)", patientID, orgID, recordDate).
  726. Select("id,user_org_id,patient_id,advice_type,advice_date,record_date,start_time,advice_name,advice_desc,reminder_date, drug_spec, drug_spec_unit,single_dose,single_dose_unit,prescribing_number,prescribing_number_unit,delivery_way,execution_frequency,advice_doctor,status,created_time,updated_time,advice_affirm,remark,stop_time,stop_reason,stop_doctor,stop_state,parent_id,execution_time,execution_staff,execution_state,checker, check_state, check_time,way,drug_id,drug_name_id,IF(parent_id>0, parent_id, id) as advice_order,groupno,is_medicine").
  727. Order("start_time asc, groupno desc, advice_order desc, id").
  728. Scan(&records).Error
  729. if err != nil {
  730. return nil, err
  731. }
  732. return records, nil
  733. }
  734. func MobileGetDoctorAdvicesByGroups(orgID int64, patientID int64, recordDate int64) ([]*models.DoctorAdvice, error) {
  735. var records []*models.DoctorAdvice
  736. redis := RedisClient()
  737. defer redis.Close()
  738. // cur_date := time.Now().Format("2006-01-02")
  739. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":doctor_advices"
  740. //fmt.Println("key23233232323323wi", key)
  741. redis.Set(key, "", time.Second)
  742. doctor_advices_str, _ := redis.Get(key).Result()
  743. if len(doctor_advices_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  744. err := readDb.Model(&models.DoctorAdvice{}).
  745. Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? and (advice_type = 2 || advice_type = 3)", patientID, orgID, recordDate).
  746. Select("id, user_org_id, patient_id, advice_type, advice_date, record_date, start_time, advice_name,advice_desc, reminder_date, drug_spec, drug_spec_unit, single_dose, single_dose_unit, prescribing_number, prescribing_number_unit, delivery_way, execution_frequency, advice_doctor, status, created_time,updated_time, advice_affirm, remark, stop_time, stop_reason, stop_doctor, stop_state, parent_id, execution_time, execution_staff, execution_state, checker, check_state, check_time, groupno,way,drug_id,is_medicine,drug_name_id, IF(parent_id > 0, parent_id, id) as advice_order").
  747. Order("start_time asc, groupno desc, advice_order desc, id asc").
  748. Scan(&records).Error
  749. if err != nil {
  750. if err == gorm.ErrRecordNotFound {
  751. if len(records) <= 0 {
  752. redis.Set(key, "", time.Second*60*60*18)
  753. }
  754. return nil, nil
  755. } else {
  756. return nil, err
  757. }
  758. } else {
  759. if len(records) > 0 {
  760. //缓存数据
  761. doctor_advices_str, err := json.Marshal(records)
  762. if err == nil {
  763. redis.Set(key, doctor_advices_str, time.Second*60*60*18)
  764. return records, nil
  765. }
  766. } else {
  767. redis.Set(key, "null", time.Second*60*60*18)
  768. return records, nil
  769. }
  770. return records, nil
  771. }
  772. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  773. if doctor_advices_str == "null" {
  774. return records, nil
  775. } else {
  776. json.Unmarshal([]byte(doctor_advices_str), &records)
  777. return records, nil
  778. }
  779. }
  780. }
  781. // 透析记录
  782. func MobileGetSchedualDialysisRecordTen(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  783. var record models.DialysisOrder
  784. err := readDb.Model(&models.DialysisOrder{}).Preload("DeviceNumber", "org_id = ?", orgID).Where("user_org_id = ? AND patient_id = ? AND dialysis_date = ?", orgID, patientID, recordDate).First(&record).Error
  785. if err != nil {
  786. if err == gorm.ErrRecordNotFound {
  787. return nil, nil
  788. } else {
  789. return nil, err
  790. }
  791. }
  792. return &record, nil
  793. }
  794. //func MobileGetSchedualDialysisRecord(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  795. // var record models.DialysisOrder
  796. //
  797. // err := readDb.Model(&models.DialysisOrder{}).Preload("DeviceNumber", "org_id = ? AND status = 1", orgID).Where("user_org_id = ? AND patient_id = ? AND dialysis_date = ?", orgID, patientID, recordDate).First(&record).Error
  798. //
  799. //
  800. // return &record,err
  801. //}
  802. // 透析记录
  803. func MobileGetSchedualDialysisRecord(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  804. var record models.DialysisOrder
  805. redis := RedisClient()
  806. defer redis.Close()
  807. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":dialysis_order"
  808. dialysis_order_str, _ := redis.Get(key).Result()
  809. if len(dialysis_order_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  810. err := readDb.Model(&models.DialysisOrder{}).Preload("DeviceNumber", "org_id = ? AND status = 1", orgID).Where("user_org_id = ? AND patient_id = ? AND dialysis_date = ?", orgID, patientID, recordDate).First(&record).Error
  811. if err != nil {
  812. if err == gorm.ErrRecordNotFound {
  813. return nil, nil
  814. } else {
  815. return nil, err
  816. }
  817. } else {
  818. if record.ID > 0 {
  819. //缓存数据
  820. dialysis_order_str, err := json.Marshal(record)
  821. if err == nil {
  822. redis.Set(key, dialysis_order_str, time.Second*60*60*18)
  823. }
  824. } else {
  825. redis.Set(key, "null", time.Second*60*60*18)
  826. }
  827. return &record, nil
  828. }
  829. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  830. if dialysis_order_str == "null" {
  831. err = readDb.Model(&models.DialysisOrder{}).Preload("DeviceNumber", "org_id = ? AND status = 1", orgID).Where("user_org_id = ? AND patient_id = ? AND dialysis_date = ?", orgID, patientID, recordDate).First(&record).Error
  832. return &record, nil
  833. } else {
  834. json.Unmarshal([]byte(dialysis_order_str), &record)
  835. return &record, nil
  836. }
  837. }
  838. }
  839. // 双人核对
  840. func MobileGetDoubleCheck(orgID int64, patientID int64, recordDate int64) (*models.DoubleCheck, error) {
  841. var record models.DoubleCheck
  842. redis := RedisClient()
  843. defer redis.Close()
  844. // cur_date := time.Now().Format("2006-01-02")
  845. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":double_check"
  846. double_check_str, _ := redis.Get(key).Result()
  847. if len(double_check_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  848. err := readDb.Model(&models.DoubleCheck{}).Where("patient_id = ? and user_org_id = ? and status = 1 and check_date = ?", patientID, orgID, recordDate).First(&record).Error
  849. if err != nil {
  850. if err == gorm.ErrRecordNotFound {
  851. if record.ID <= 0 {
  852. redis.Set(key, "null", time.Second*60*60*18)
  853. }
  854. return nil, nil
  855. } else {
  856. return nil, err
  857. }
  858. } else {
  859. if record.ID > 0 {
  860. //缓存数据
  861. double_check_str, err := json.Marshal(record)
  862. if err == nil {
  863. redis.Set(key, double_check_str, time.Second*60*60*18)
  864. }
  865. } else {
  866. redis.Set(key, "null", time.Second*60*60*18)
  867. }
  868. return &record, nil
  869. }
  870. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  871. if double_check_str == "null" {
  872. return &record, nil
  873. } else {
  874. json.Unmarshal([]byte(double_check_str), &record)
  875. return &record, nil
  876. }
  877. }
  878. }
  879. // 透析监测记录
  880. func MobileGetMonitorRecords(orgID int64, patientID int64, recordDate int64) ([]*models.MonitoringRecord, error) {
  881. var records []*models.MonitoringRecord
  882. redis := RedisClient()
  883. defer redis.Close()
  884. // cur_date := time.Now().Format("2006-01-02")
  885. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":monitor_records"
  886. redis.Set(key, "", time.Second)
  887. monitor_records_str, _ := redis.Get(key).Result()
  888. if len(monitor_records_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  889. err := readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ?", patientID, orgID, recordDate).Order("operate_time asc").Find(&records).Error
  890. if err != nil {
  891. if err == gorm.ErrRecordNotFound {
  892. //if len(records) <= 0 {
  893. // redis.Set(key, "null", time.Second*60*60*18)
  894. //}
  895. return nil, nil
  896. } else {
  897. return nil, err
  898. }
  899. } else {
  900. if len(records) > 0 {
  901. //缓存数据
  902. monitor_records_str, err := json.Marshal(records)
  903. if err == nil {
  904. redis.Set(key, monitor_records_str, time.Second*60*60*18)
  905. }
  906. } else {
  907. redis.Set(key, "null", time.Second*60*60*18)
  908. }
  909. return records, nil
  910. }
  911. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  912. if monitor_records_str == "null" {
  913. return records, nil
  914. } else {
  915. json.Unmarshal([]byte(monitor_records_str), &records)
  916. return records, nil
  917. }
  918. }
  919. }
  920. func MobileGetMonitorRecordFirst(orgID int64, patientID int64, recordDate int64) (*models.MonitoringRecord, error) {
  921. var records models.MonitoringRecord
  922. err := readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ?", patientID, orgID, recordDate).Order("operate_time asc").First(&records).Error
  923. if err != nil {
  924. return nil, err
  925. }
  926. return &records, nil
  927. }
  928. func MobileGetLastMonitorRecordOne(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  929. var record models.MonitoringRecord
  930. err := readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ?", patientID, orgID, beforeDate).Order("operate_time desc").First(&record).Error
  931. if err != nil {
  932. if err == gorm.ErrRecordNotFound {
  933. return nil, nil
  934. } else {
  935. return nil, err
  936. }
  937. }
  938. return &record, nil
  939. }
  940. func MobileGetLastMonitorRecord(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  941. var record models.MonitoringRecord
  942. redis := RedisClient()
  943. defer redis.Close()
  944. // cur_date := time.Now().Format("2006-01-02")
  945. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(beforeDate, 10) + ":monitor_record_last"
  946. monitor_record_last_str, _ := redis.Get(key).Result()
  947. if len(monitor_record_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  948. 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
  949. if err != nil {
  950. if err == gorm.ErrRecordNotFound {
  951. if record.ID <= 0 {
  952. redis.Set(key, "null", time.Second*60*60*18)
  953. }
  954. return nil, nil
  955. } else {
  956. return nil, err
  957. }
  958. } else {
  959. if record.ID > 0 {
  960. //缓存数据
  961. monitor_record_last_str, err := json.Marshal(record)
  962. if err == nil {
  963. redis.Set(key, monitor_record_last_str, time.Second*60*60*18)
  964. }
  965. } else {
  966. redis.Set(key, "null", time.Second*60*60*18)
  967. }
  968. return &record, nil
  969. }
  970. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  971. if monitor_record_last_str == "null" {
  972. return &record, nil
  973. } else {
  974. json.Unmarshal([]byte(monitor_record_last_str), &record)
  975. return &record, nil
  976. }
  977. }
  978. }
  979. func MobileGetAssessmentAfterDislysisOne(orgID int64, patientID int64, recordDate int64) (*models.AssessmentAfterDislysis, error) {
  980. var record models.AssessmentAfterDislysis
  981. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  982. if err != nil {
  983. if err == gorm.ErrRecordNotFound {
  984. return nil, nil
  985. } else {
  986. return nil, err
  987. }
  988. }
  989. return &record, nil
  990. }
  991. // 透后评估
  992. func MobileGetAssessmentAfterDislysis(orgID int64, patientID int64, recordDate int64) (*models.AssessmentAfterDislysis, error) {
  993. var record models.AssessmentAfterDislysis
  994. redis := RedisClient()
  995. defer redis.Close()
  996. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":assessment_after_dislysis"
  997. redis.Set(key, "", time.Second)
  998. assessment_after_dislysis_str, _ := redis.Get(key).Result()
  999. if len(assessment_after_dislysis_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1000. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  1001. if err != nil {
  1002. if err == gorm.ErrRecordNotFound {
  1003. if record.ID <= 0 {
  1004. redis.Set(key, "null", time.Second*60*60*18)
  1005. }
  1006. return nil, nil
  1007. } else {
  1008. return nil, err
  1009. }
  1010. } else {
  1011. if record.ID > 0 {
  1012. //缓存数据
  1013. assessment_after_dislysis_str, err := json.Marshal(record)
  1014. if err == nil {
  1015. redis.Set(key, assessment_after_dislysis_str, time.Second*60*60*18)
  1016. }
  1017. } else {
  1018. redis.Set(key, "null", time.Second*60*60*18)
  1019. }
  1020. return &record, nil
  1021. }
  1022. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1023. if assessment_after_dislysis_str == "null" {
  1024. return &record, nil
  1025. } else {
  1026. json.Unmarshal([]byte(assessment_after_dislysis_str), &record)
  1027. return &record, nil
  1028. }
  1029. }
  1030. }
  1031. // 获取 maxDate 之前一次的透后评估记录
  1032. func MobileGetLastTimeAssessmentAfterDislysis(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  1033. var record models.AssessmentAfterDislysis
  1034. redis := RedisClient()
  1035. defer redis.Close()
  1036. // cur_date := time.Now().Format("2006-01-02")
  1037. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(maxDate, 10) + ":assessment_after_dislysis_last"
  1038. assessment_after_dislysis_last_str, _ := redis.Get(key).Result()
  1039. if len(assessment_after_dislysis_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1040. 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
  1041. if err != nil {
  1042. if err == gorm.ErrRecordNotFound {
  1043. if record.ID <= 0 {
  1044. redis.Set(key, "null", time.Second*60*60*18)
  1045. }
  1046. return nil, nil
  1047. } else {
  1048. return nil, err
  1049. }
  1050. } else {
  1051. if record.ID > 0 {
  1052. //缓存数据
  1053. assessment_after_dislysis_last_str, err := json.Marshal(record)
  1054. if err == nil {
  1055. redis.Set(key, assessment_after_dislysis_last_str, time.Second*60*60*18)
  1056. }
  1057. } else {
  1058. redis.Set(key, "null", time.Second*60*60*18)
  1059. }
  1060. return &record, nil
  1061. }
  1062. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1063. if assessment_after_dislysis_last_str == "null" {
  1064. return &record, nil
  1065. } else {
  1066. json.Unmarshal([]byte(assessment_after_dislysis_last_str), &record)
  1067. return &record, nil
  1068. }
  1069. }
  1070. }
  1071. func MobileGetLastTimeAssessmentAfterDislysisOne(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  1072. var record models.AssessmentAfterDislysis
  1073. 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
  1074. if err != nil {
  1075. if err == gorm.ErrRecordNotFound {
  1076. return nil, nil
  1077. } else {
  1078. return nil, err
  1079. }
  1080. }
  1081. return &record, nil
  1082. }
  1083. func MobileGetLast(orgID int64, patientID int64, maxDate int64) (models.AssessmentAfterDislysis, error) {
  1084. dislysis := models.AssessmentAfterDislysis{}
  1085. 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
  1086. return dislysis, err
  1087. }
  1088. // 治疗小结
  1089. func MobileGetTreatmentSummary(orgID int64, patientID int64, recordDate int64) (*models.TreatmentSummary, error) {
  1090. var record models.TreatmentSummary
  1091. redis := RedisClient()
  1092. defer redis.Close()
  1093. // cur_date := time.Now().Format("2006-01-02")
  1094. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":treatment_summary"
  1095. treatment_summary_str, _ := redis.Get(key).Result()
  1096. if len(treatment_summary_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1097. err := readDb.Model(&models.TreatmentSummary{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  1098. if err != nil {
  1099. if err == gorm.ErrRecordNotFound {
  1100. if record.ID <= 0 {
  1101. redis.Set(key, "null", time.Second*60*60*18)
  1102. }
  1103. return nil, nil
  1104. } else {
  1105. return nil, err
  1106. }
  1107. } else {
  1108. if record.ID > 0 {
  1109. //缓存数据
  1110. treatment_summary_str, err := json.Marshal(record)
  1111. if err == nil {
  1112. redis.Set(key, treatment_summary_str, time.Second*60*60*18)
  1113. }
  1114. } else {
  1115. redis.Set(key, "null", time.Second*60*60*18)
  1116. }
  1117. return &record, nil
  1118. }
  1119. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1120. if treatment_summary_str == "null" {
  1121. return &record, nil
  1122. } else {
  1123. json.Unmarshal([]byte(treatment_summary_str), &record)
  1124. return &record, nil
  1125. }
  1126. }
  1127. }
  1128. // 透析处方
  1129. func MobileGetDialysisPrescribe(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  1130. var record models.DialysisPrescription
  1131. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).Find(&record).Error
  1132. if err != nil {
  1133. if err == gorm.ErrRecordNotFound {
  1134. return nil, nil
  1135. } else {
  1136. return nil, err
  1137. }
  1138. }
  1139. return &record, nil
  1140. }
  1141. func MobileGetDialysisSchedual(orgID int64, patientID int64, scheduleDate int64) (*models.XtSchedule, error) {
  1142. var schedule models.XtSchedule
  1143. err := readDb.Model(&models.XtSchedule{}).Where("patient_id = ? and user_org_id = ? and status = 1 and schedule_date = ?", patientID, orgID, scheduleDate).First(&schedule).Error
  1144. if err != nil {
  1145. if err == gorm.ErrRecordNotFound {
  1146. return nil, nil
  1147. } else {
  1148. return nil, err
  1149. }
  1150. }
  1151. return &schedule, nil
  1152. }
  1153. // 透析方案
  1154. func MobileGetDialysisSolution(orgID int64, patientID int64) (*models.DialysisSolution, error) {
  1155. var record models.DialysisSolution
  1156. err := readDb.Model(&models.DialysisSolution{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  1157. if err != nil {
  1158. if err == gorm.ErrRecordNotFound {
  1159. return nil, nil
  1160. } else {
  1161. return nil, err
  1162. }
  1163. }
  1164. return &record, nil
  1165. }
  1166. func MobileGetPatientById(orgID int64, patientID int64) (*models.Patients, error) {
  1167. var patient models.Patients
  1168. err := readDb.Model(&models.Patients{}).Where("id = ? and user_org_id = ? and status = 1", patientID, orgID).First(&patient).Error
  1169. if err != nil {
  1170. if err == gorm.ErrRecordNotFound {
  1171. return nil, nil
  1172. } else {
  1173. return nil, err
  1174. }
  1175. }
  1176. return &patient, nil
  1177. }
  1178. func DisableMonitor(orgID int64, patientID int64, recordID int64, admin_user_id int64) error {
  1179. fmt.Println()
  1180. tx := writeDb.Begin()
  1181. updateTime := time.Now().Unix()
  1182. 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
  1183. if err != nil {
  1184. tx.Rollback()
  1185. return err
  1186. }
  1187. tx.Commit()
  1188. return nil
  1189. }
  1190. func GetMonitorById(id int64, orgId int64) (models.MonitoringRecord, error) {
  1191. record := models.MonitoringRecord{}
  1192. err := XTReadDB().Where("id = ? and user_org_id =?", id, orgId).Find(&record).Error
  1193. return record, err
  1194. }
  1195. func GetMonitor(orgID int64, patientID int64, id int64) (*models.MonitoringRecord, error) {
  1196. var monitor models.MonitoringRecord
  1197. var err error
  1198. err = readDb.Model(&models.MonitoringRecord{}).Where("id = ? AND user_org_id = ? AND patient_id = ? AND status = 1 ", id, orgID, patientID).Find(&monitor).Error
  1199. if err == gorm.ErrRecordNotFound {
  1200. return nil, nil
  1201. }
  1202. if err != nil {
  1203. return nil, err
  1204. }
  1205. return &monitor, nil
  1206. }
  1207. type MScheduleDoctorAdviceVM struct {
  1208. ID int64 `gorm:"column:id" json:"id"`
  1209. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  1210. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  1211. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  1212. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1213. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  1214. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  1215. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  1216. Status int64 `gorm:"column:status" json:"status"`
  1217. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  1218. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  1219. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  1220. DoctorAdvices []*MDoctorAdviceVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  1221. Prescription *models.DialysisPrescriptionTwenty `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  1222. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  1223. }
  1224. func (MScheduleDoctorAdviceVM) TableName() string {
  1225. return "xt_schedule"
  1226. }
  1227. type MScheduleDoctorAdviceVMOne struct {
  1228. ID int64 `gorm:"column:id" json:"id"`
  1229. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  1230. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  1231. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  1232. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1233. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  1234. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  1235. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  1236. Status int64 `gorm:"column:status" json:"status"`
  1237. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  1238. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  1239. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  1240. DoctorAdvices []*MDoctorAdviceVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  1241. Prescription *models.DialysisPrescriptionTwenty `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  1242. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  1243. }
  1244. func (MScheduleDoctorAdviceVMOne) TableName() string {
  1245. return "xt_schedule"
  1246. }
  1247. type MDoctorAdviceVM struct {
  1248. ID int64 `gorm:"column:id" json:"id"`
  1249. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  1250. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1251. AdviceType int64 `gorm:"column:advice_type" json:"advice_type"`
  1252. AdviceDate int64 `gorm:"column:advice_date" json:"advice_date"`
  1253. StartTime int64 `gorm:"column:start_time" json:"start_time"`
  1254. AdviceName string `gorm:"column:advice_name" json:"advice_name"`
  1255. AdviceDesc string `gorm:"column:advice_desc" json:"advice_desc"`
  1256. ReminderDate int64 `gorm:"column:reminder_date" json:"reminder_date"`
  1257. SingleDose float64 `gorm:"column:single_dose" json:"single_dose"`
  1258. SingleDoseUnit string `gorm:"column:single_dose_unit" json:"single_dose_unit"`
  1259. PrescribingNumber float64 `gorm:"column:prescribing_number" json:"prescribing_number"`
  1260. PrescribingNumberUnit string `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit"`
  1261. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way"`
  1262. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency"`
  1263. AdviceDoctor int64 `gorm:"column:advice_doctor" json:"advice_doctor"`
  1264. Status int64 `gorm:"column:status" json:"status"`
  1265. CreatedTime int64 `gorm:"column:created_time" json:"created_time"`
  1266. UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time"`
  1267. AdviceAffirm string `gorm:"column:advice_affirm" json:"advice_affirm"`
  1268. Remark string `gorm:"column:remark" json:"remark"`
  1269. StopTime int64 `gorm:"column:stop_time" json:"stop_time"`
  1270. StopReason string `gorm:"column:stop_reason" json:"stop_reason"`
  1271. StopDoctor int64 `gorm:"column:stop_doctor" json:"stop_doctor"`
  1272. StopState int64 `gorm:"column:stop_state" json:"stop_state"`
  1273. ParentId int64 `gorm:"column:parent_id" json:"parent_id"`
  1274. ExecutionTime int64 `gorm:"column:execution_time" json:"execution_time"`
  1275. ExecutionStaff int64 `gorm:"column:execution_staff" json:"execution_staff"`
  1276. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state"`
  1277. Checker int64 `gorm:"column:checker" json:"checker"`
  1278. RecordDate int64 `gorm:"column:record_date" json:"record_date"`
  1279. DialysisOrderId int64 `gorm:"column:dialysis_order_id" json:"dialysis_order_id"`
  1280. CheckTime int64 `gorm:"column:check_time" json:"check_time"`
  1281. CheckState int64 `gorm:"column:check_state" json:"check_state"`
  1282. DrugSpec float64 `gorm:"column:drug_spec" json:"drug_spec"`
  1283. DrugSpecUnit string `gorm:"column:drug_spec_unit" json:"drug_spec_unit"`
  1284. Groupno int64 `gorm:"column:groupno" json:"groupno"`
  1285. RemindType int64 `gorm:"column:remind_type" json:"remind_type"`
  1286. FrequencyType int64 `gorm:"column:frequency_type" json:"frequency_type"`
  1287. DayCount int64 `gorm:"column:day_count" json:"day_count"`
  1288. WeekDay string `gorm:"column:week_day" json:"week_day"`
  1289. TemplateId string `gorm:"column:template_id" json:"template_id"`
  1290. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1291. IsMedicine int64 `gorm:"column:is_medicine" json:"is_medicine" form:"is_medicine"`
  1292. IsSettle int64 `gorm:"column:is_settle" json:"is_settle" form:"is_settle"`
  1293. }
  1294. func (MDoctorAdviceVM) TableName() string {
  1295. return "xt_doctor_advice"
  1296. }
  1297. func MobileGetScheduleDoctorAdvices(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string) ([]*MScheduleDoctorAdviceVM, error) {
  1298. var vms []*MScheduleDoctorAdviceVM
  1299. adviceWhere := ""
  1300. adviceCondition := []interface{}{}
  1301. if adviceType == 0 {
  1302. if patientType == 0 {
  1303. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  1304. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1305. } else if patientType == 1 {
  1306. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  1307. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1308. } else if patientType == 2 {
  1309. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  1310. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1311. }
  1312. } else if adviceType == 1 {
  1313. if patientType == 0 {
  1314. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  1315. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1316. } else if patientType == 1 {
  1317. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  1318. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1319. } else if patientType == 2 {
  1320. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  1321. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1322. }
  1323. } else if adviceType == 3 {
  1324. if patientType == 0 {
  1325. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  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_type = 3 AND advice_doctor = ? "
  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 advice_type = 3 AND execution_staff = 0"
  1332. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1333. }
  1334. } else if adviceType == 2 && len(deliverWay) > 0 {
  1335. if patientType == 0 {
  1336. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  1337. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1338. } else if patientType == 1 {
  1339. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  1340. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  1341. } else if patientType == 2 {
  1342. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  1343. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1344. }
  1345. } else if adviceType == 2 && len(deliverWay) <= 0 {
  1346. if patientType == 0 {
  1347. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 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 = 2 AND (advice_doctor = ? or execution_staff = ?)"
  1351. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, adminUserId)
  1352. } else if patientType == 2 {
  1353. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  1354. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1355. }
  1356. }
  1357. db := readDb.
  1358. Table("xt_schedule").
  1359. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1360. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1361. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1362. }).
  1363. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1364. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1365. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1366. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  1367. Preload("DoctorAdvices", adviceCondition...).
  1368. Where("status = 1 AND user_org_id = ?", orgID)
  1369. if scheduleDate != 0 {
  1370. db = db.Where("schedule_date = ?", scheduleDate)
  1371. }
  1372. err := db.Find(&vms).Error
  1373. return vms, err
  1374. }
  1375. func MobileGetScheduleDoctorAdvicesTwo(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string) ([]*MScheduleDoctorAdviceVMOne, error) {
  1376. var vms []*MScheduleDoctorAdviceVMOne
  1377. adviceWhere := ""
  1378. adviceCondition := []interface{}{}
  1379. if adviceType == 0 {
  1380. if patientType == 0 {
  1381. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  1382. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1383. } else if patientType == 1 {
  1384. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  1385. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1386. } else if patientType == 2 {
  1387. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  1388. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1389. } else if patientType == 3 {
  1390. 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"
  1391. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1392. } else if patientType == 4 {
  1393. 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)"
  1394. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1395. }
  1396. } else if adviceType == 1 {
  1397. if patientType == 0 {
  1398. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  1399. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1400. } else if patientType == 1 {
  1401. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  1402. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1403. } else if patientType == 2 {
  1404. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  1405. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1406. } else if patientType == 3 {
  1407. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = 1"
  1408. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1409. } else if patientType == 4 {
  1410. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and (is_settle = 0 or is_settle = 2)"
  1411. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1412. }
  1413. } else if adviceType == 3 {
  1414. if patientType == 0 {
  1415. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  1416. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1417. } else if patientType == 1 {
  1418. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  1419. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1420. } else if patientType == 2 {
  1421. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  1422. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1423. } else if patientType == 3 {
  1424. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 and is_settle = 1"
  1425. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1426. } else if patientType == 4 {
  1427. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 and (is_settle = 0 or is_settle = 2)"
  1428. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1429. }
  1430. } else if adviceType == 2 && len(deliverWay) > 0 {
  1431. if patientType == 0 {
  1432. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  1433. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1434. } else if patientType == 1 {
  1435. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  1436. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  1437. } else if patientType == 2 {
  1438. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  1439. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1440. } else if patientType == 3 {
  1441. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 and delivery_way = ? and is_settle = 1"
  1442. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1443. } else if patientType == 4 {
  1444. 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)"
  1445. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1446. }
  1447. } else if adviceType == 2 && len(deliverWay) <= 0 {
  1448. if patientType == 0 {
  1449. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  1450. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1451. } else if patientType == 1 {
  1452. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND (advice_doctor = ? or execution_staff = ?)"
  1453. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, adminUserId)
  1454. } else if patientType == 2 {
  1455. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  1456. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1457. } else if patientType == 3 {
  1458. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 and is_settle = 1"
  1459. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1460. } else if patientType == 4 {
  1461. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 and (is_settle = 0 or is_settle = 2)"
  1462. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1463. }
  1464. }
  1465. db := readDb.
  1466. Table("xt_schedule").
  1467. //Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1468. //Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1469. // return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1470. //}).
  1471. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1472. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1473. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1474. Preload("DoctorAdvices", adviceCondition...).
  1475. Where("status = 1 AND user_org_id = ?", orgID)
  1476. if scheduleDate != 0 {
  1477. db = db.Where("schedule_date = ?", scheduleDate)
  1478. }
  1479. err := db.Find(&vms).Error
  1480. return vms, err
  1481. }
  1482. func GetHisDoctorAdvices(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleDoctorAdviceVM, error) {
  1483. var vms []*HisMScheduleDoctorAdviceVM
  1484. if len(deliverWay) > 0 {
  1485. if patientType == 0 {
  1486. db := readDb.
  1487. Table("xt_schedule").
  1488. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  1489. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1490. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1491. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1492. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1493. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1494. }).
  1495. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1496. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  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. }
  1503. if patientType > 0 {
  1504. db := readDb.
  1505. Table("xt_schedule").
  1506. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1507. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1508. 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).
  1509. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1510. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1511. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1512. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1513. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1514. }).Where("status = 1 AND user_org_id = ?", orgID)
  1515. if scheduleDate != 0 {
  1516. db = db.Where("schedule_date = ?", scheduleDate)
  1517. }
  1518. err = db.Find(&vms).Error
  1519. }
  1520. } else {
  1521. if patientType == 0 {
  1522. db := readDb.
  1523. Table("xt_schedule").
  1524. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? ", orgID, scheduleDate).
  1525. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1526. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1527. return db.Where("status = 1 AND user_org_id = ? and dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1528. }).
  1529. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1530. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1531. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1532. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1533. Where("status = 1 AND user_org_id = ?", orgID)
  1534. if scheduleDate != 0 {
  1535. db = db.Where("schedule_date = ?", scheduleDate)
  1536. }
  1537. err = db.Find(&vms).Error
  1538. }
  1539. if patientType > 0 {
  1540. db := readDb.
  1541. Table("xt_schedule").
  1542. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1543. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1544. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1545. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1546. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1547. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1548. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1549. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1550. Where("status = 1 AND user_org_id = ?", orgID)
  1551. if scheduleDate != 0 {
  1552. db = db.Where("schedule_date = ?", scheduleDate)
  1553. }
  1554. err = db.Find(&vms).Error
  1555. }
  1556. }
  1557. return vms, err
  1558. }
  1559. func GetHisDoctorAdvicesTwo(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleDoctorAdviceVMOne, error) {
  1560. var vms []*HisMScheduleDoctorAdviceVMOne
  1561. if len(deliverWay) > 0 {
  1562. if patientType == 0 {
  1563. db := readDb.
  1564. Table("xt_schedule").
  1565. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  1566. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1567. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1568. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1569. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1570. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1571. }).
  1572. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1573. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1574. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1575. Where("status = 1 AND user_org_id = ?", orgID)
  1576. if scheduleDate != 0 {
  1577. db = db.Where("schedule_date = ?", scheduleDate)
  1578. }
  1579. err = db.Find(&vms).Error
  1580. }
  1581. if patientType > 0 {
  1582. if patientType == 1 {
  1583. db := readDb.
  1584. Table("xt_schedule").
  1585. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1586. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1587. 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).
  1588. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1589. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1590. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  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. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1594. Where("status = 1 AND user_org_id = ?", orgID)
  1595. if scheduleDate != 0 {
  1596. db = db.Where("schedule_date = ?", scheduleDate)
  1597. }
  1598. err = db.Find(&vms).Error
  1599. }
  1600. if patientType == 2 {
  1601. db := readDb.
  1602. Table("xt_schedule").
  1603. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1604. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1605. 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).
  1606. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1607. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1608. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1609. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1610. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1611. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Where("status = 1 AND user_org_id = ?", orgID)
  1612. if scheduleDate != 0 {
  1613. db = db.Where("schedule_date = ?", scheduleDate)
  1614. }
  1615. err = db.Find(&vms).Error
  1616. }
  1617. if patientType == 3 {
  1618. db := readDb.
  1619. Table("xt_schedule").
  1620. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1621. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1622. 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).
  1623. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1624. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1625. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1626. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1627. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1628. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Where("status = 1 AND user_org_id = ?", orgID)
  1629. if scheduleDate != 0 {
  1630. db = db.Where("schedule_date = ?", scheduleDate)
  1631. }
  1632. err = db.Find(&vms).Error
  1633. }
  1634. if patientType == 4 {
  1635. db := readDb.
  1636. Table("xt_schedule").
  1637. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1638. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1639. 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).
  1640. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1641. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1642. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1643. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1644. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1645. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Where("status = 1 AND user_org_id = ?", orgID)
  1646. if scheduleDate != 0 {
  1647. db = db.Where("schedule_date = ?", scheduleDate)
  1648. }
  1649. err = db.Find(&vms).Error
  1650. }
  1651. }
  1652. } else {
  1653. if patientType == 0 {
  1654. db := readDb.
  1655. Table("xt_schedule").
  1656. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? ", orgID, scheduleDate).
  1657. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1658. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1659. return db.Where("status = 1 AND user_org_id = ? and dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1660. }).
  1661. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1662. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1663. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1664. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1665. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1666. Where("status = 1 AND user_org_id = ?", orgID)
  1667. if scheduleDate != 0 {
  1668. db = db.Where("schedule_date = ?", scheduleDate)
  1669. }
  1670. err = db.Find(&vms).Error
  1671. }
  1672. if patientType > 0 {
  1673. if patientType == 1 {
  1674. db := readDb.
  1675. Table("xt_schedule").
  1676. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1677. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1678. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1679. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  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. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1683. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1684. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1685. Where("status = 1 AND user_org_id = ?", orgID)
  1686. if scheduleDate != 0 {
  1687. db = db.Where("schedule_date = ?", scheduleDate)
  1688. }
  1689. err = db.Find(&vms).Error
  1690. }
  1691. if patientType == 2 {
  1692. db := readDb.
  1693. Table("xt_schedule").
  1694. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1695. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1696. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1697. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1698. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1699. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1700. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1701. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1702. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1703. Where("status = 1 AND user_org_id = ?", orgID)
  1704. if scheduleDate != 0 {
  1705. db = db.Where("schedule_date = ?", scheduleDate)
  1706. }
  1707. err = db.Find(&vms).Error
  1708. }
  1709. if patientType == 3 {
  1710. db := readDb.
  1711. Table("xt_schedule").
  1712. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1713. 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).
  1714. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1715. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1716. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1717. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1718. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1719. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1720. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1721. Where("status = 1 AND user_org_id = ?", orgID)
  1722. if scheduleDate != 0 {
  1723. db = db.Where("schedule_date = ?", scheduleDate)
  1724. }
  1725. err = db.Find(&vms).Error
  1726. }
  1727. if patientType == 4 {
  1728. db := readDb.
  1729. Table("xt_schedule").
  1730. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1731. 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).
  1732. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1733. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1734. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1735. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1736. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1737. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1738. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1739. Where("status = 1 AND user_org_id = ?", orgID)
  1740. if scheduleDate != 0 {
  1741. db = db.Where("schedule_date = ?", scheduleDate)
  1742. }
  1743. err = db.Find(&vms).Error
  1744. }
  1745. }
  1746. }
  1747. return vms, err
  1748. }
  1749. func GetMobileHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleProjectVM, error) {
  1750. var vms []*HisMScheduleProjectVM
  1751. //if patientType == 0 {
  1752. // db := readDb.
  1753. // Table("xt_schedule").
  1754. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1755. // Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1756. // return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1757. // }).
  1758. // Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1759. // Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1760. // Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1761. // Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1762. // return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1763. // }).
  1764. // Where("status = 1 AND user_org_id = ?", orgID)
  1765. // if scheduleDate != 0 {
  1766. // db = db.Where("schedule_date = ?", scheduleDate)
  1767. // }
  1768. // err = db.Find(&vms).Error
  1769. //}
  1770. //if patientType > 0 {
  1771. // db := readDb.
  1772. // Table("xt_schedule").
  1773. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1774. // Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1775. // return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1776. // }).
  1777. // Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1778. // Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1779. // Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1780. // Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1781. // Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1782. // return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1783. // }).
  1784. // Where("status = 1 AND user_org_id = ?", orgID)
  1785. // if scheduleDate != 0 {
  1786. // db = db.Where("schedule_date = ?", scheduleDate)
  1787. // }
  1788. // err = db.Find(&vms).Error
  1789. //}
  1790. db := readDb.Table("xt_schedule").Where("status = 1")
  1791. if orgID > 0 {
  1792. db = db.Where("user_org_id = ?", orgID)
  1793. }
  1794. if scheduleDate > 0 {
  1795. db = db.Where("schedule_date =?", scheduleDate)
  1796. }
  1797. err = db.Find(&vms).Error
  1798. if patientType == 0 {
  1799. db := readDb.
  1800. Table("xt_schedule").
  1801. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1802. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1803. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1804. }).
  1805. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1806. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1807. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1808. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1809. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1810. }).
  1811. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  1812. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  1813. }).
  1814. Where("status = 1 AND user_org_id = ?", orgID)
  1815. if scheduleDate != 0 {
  1816. db = db.Where("schedule_date = ?", scheduleDate)
  1817. }
  1818. err = db.Find(&vms).Error
  1819. }
  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. return vms, err
  1843. }
  1844. func MobileCreateDialysisOrder(orgID int64, patientID int64, order *models.DialysisOrder) error {
  1845. now := time.Now()
  1846. tx := writeDb.Begin()
  1847. if createOrderErr := tx.Model(&models.DialysisOrder{}).Create(order).Error; createOrderErr != nil {
  1848. tx.Rollback()
  1849. return createOrderErr
  1850. }
  1851. // 更新透析记录 ID
  1852. // 透析处方
  1853. 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 {
  1854. tx.Rollback()
  1855. return err
  1856. }
  1857. // 接诊评估
  1858. 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 {
  1859. tx.Rollback()
  1860. return err
  1861. }
  1862. // 透前评估
  1863. 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 {
  1864. tx.Rollback()
  1865. return err
  1866. }
  1867. // 临时医嘱
  1868. 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 {
  1869. tx.Rollback()
  1870. return err
  1871. }
  1872. // 双人核对
  1873. 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 {
  1874. tx.Rollback()
  1875. return err
  1876. }
  1877. // 透后评估
  1878. 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 {
  1879. tx.Rollback()
  1880. return err
  1881. }
  1882. // 治疗小结
  1883. 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 {
  1884. tx.Rollback()
  1885. return err
  1886. }
  1887. // 透析监测
  1888. 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 {
  1889. tx.Rollback()
  1890. return err
  1891. }
  1892. tx.Commit()
  1893. return nil
  1894. }
  1895. type MobileUrgentSchedulePatientVM struct {
  1896. ID int64 `gorm:"column:id" json:"id"`
  1897. Name string `gorm:"column:name" json:"name"`
  1898. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no"`
  1899. }
  1900. func (MobileUrgentSchedulePatientVM) TableName() string {
  1901. return "xt_patients"
  1902. }
  1903. type MobileUrgentScheduleTreatmentModeVM struct {
  1904. ID int64 `gorm:"column:id" json:"id"`
  1905. Name string `gorm:"column:name" json:"name"`
  1906. }
  1907. func (MobileUrgentScheduleTreatmentModeVM) TableName() string {
  1908. return "xt_treatment_mode"
  1909. }
  1910. func MobileGetAllPatientsForUrgentSchedule(orgID int64, record_date int64) ([]*MobileUrgentSchedulePatientVM, error) {
  1911. var vms []*MobileUrgentSchedulePatientVM = make([]*MobileUrgentSchedulePatientVM, 0)
  1912. rows, err := readDb.Raw("SELECT p.* FROM xt_patients as p WHERE (p.user_org_id = ? AND p.status = 1 AND p.lapseto = 1) AND NOT EXISTS (Select * FROM `xt_dialysis_order` as d Where d.`dialysis_date` = ? AND d.`status` = 1 AND d.`patient_id` = p.id AND d.user_org_id = p.user_org_id )", orgID, record_date).Rows()
  1913. defer rows.Close()
  1914. if err != nil {
  1915. return nil, err
  1916. }
  1917. for rows.Next() {
  1918. var vm MobileUrgentSchedulePatientVM
  1919. readDb.ScanRows(rows, &vm)
  1920. vms = append(vms, &vm)
  1921. }
  1922. return vms, nil
  1923. }
  1924. func MobileGetAllTrearmentModesForUrgentSchedule() ([]*MobileUrgentScheduleTreatmentModeVM, error) {
  1925. var modes []*MobileUrgentScheduleTreatmentModeVM
  1926. err := readDb.Model(&MobileUrgentScheduleTreatmentModeVM{}).Where("status = 1").Find(&modes).Error
  1927. if err != nil {
  1928. return nil, err
  1929. }
  1930. return modes, nil
  1931. }
  1932. type MobileUrgentScheduleScheduleListVM struct {
  1933. ID int64 `gorm:"column:id" json:"id"`
  1934. // ZoneID int64 `gorm:"column:partition_id" json:"zone_id"`
  1935. DeviceNumberID int64 `gorm:"column:bed_id" json:"bed_id"`
  1936. PatientID int64 `gorm:"column:patient_id" json:"patient_id"`
  1937. ScheduleType int `gorm:"column:schedule_type" json:"schedule_type"`
  1938. DeviceNumber *models.DeviceNumber `gorm:"ForeignKey:DeviceNumberID" json:"device_number"`
  1939. // DeviceZone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"device_zone"`
  1940. }
  1941. func (MobileUrgentScheduleScheduleListVM) TableName() string {
  1942. return "xt_schedule"
  1943. }
  1944. func MobileGetSchedulesForUrgentSchedule(orgID int64, scheduleDate int64, schedule_type int) (schedules []*MobileUrgentScheduleScheduleListVM, err error) {
  1945. db := readDb.
  1946. Model(&MobileUrgentScheduleScheduleListVM{}).
  1947. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1948. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND schedule_type = ? ", orgID, scheduleDate, schedule_type)
  1949. err = db.Find(&schedules).Error
  1950. if err != nil {
  1951. return nil, err
  1952. }
  1953. return schedules, nil
  1954. }
  1955. func MobileGetOtherSchedulesForUrgentSchedule(orgID int64, scheduleDate int64, schedule_type int) ([]*MobileUrgentScheduleScheduleListVM, error) {
  1956. var vms []*MobileUrgentScheduleScheduleListVM = make([]*MobileUrgentScheduleScheduleListVM, 0)
  1957. 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()
  1958. defer rows.Close()
  1959. if err != nil {
  1960. return nil, err
  1961. }
  1962. for rows.Next() {
  1963. var vm MobileUrgentScheduleScheduleListVM
  1964. readDb.ScanRows(rows, &vm)
  1965. vms = append(vms, &vm)
  1966. }
  1967. return vms, nil
  1968. }
  1969. type MobileUrgentScheduleDeviceNumberVM struct {
  1970. ID int64 `gorm:"column:id" json:"id"`
  1971. Number string `gorm:"column:number" json:"number"`
  1972. ZoneID int64 `gorm:"column:zone_id" json:"zone_id"`
  1973. Zone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"zone"`
  1974. }
  1975. func (MobileUrgentScheduleDeviceNumberVM) TableName() string {
  1976. return "xt_device_number"
  1977. }
  1978. func MobileGetAllDeviceNumbersForUrgentSchedule(orgID int64, record_date int64, schedule_type int) ([]*DeviceNumberViewModel, error) {
  1979. var vms []*DeviceNumberViewModel = make([]*DeviceNumberViewModel, 0)
  1980. 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()
  1981. defer rows.Close()
  1982. if err != nil {
  1983. return nil, err
  1984. }
  1985. for rows.Next() {
  1986. var vm DeviceNumberViewModel
  1987. readDb.ScanRows(rows, &vm)
  1988. vms = append(vms, &vm)
  1989. }
  1990. return vms, nil
  1991. //var deviceNumbers []*MobileUrgentScheduleDeviceNumberVM
  1992. //db := readDb.
  1993. // Model(&MobileUrgentScheduleDeviceNumberVM{}).
  1994. // Preload("Zone", "status = 1 AND org_id = ?", orgID).
  1995. // Where("status = 1 AND org_id = ?", orgID)
  1996. //err := db.Order("zone_id asc").Find(&deviceNumbers).Error
  1997. //if err != nil {
  1998. // return nil, err
  1999. //}
  2000. //return deviceNumbers, nil
  2001. }
  2002. func GetValidScheduleMonitorRecordCount() (int64, error) {
  2003. var total int64
  2004. err := readDb.Model(&models.MonitoringRecord{}).Where("status = 1 AND operate_time = 0 AND monitoring_date <> 0").Count(&total).Error
  2005. return total, err
  2006. }
  2007. func GetTop1000ValidScheduleMonitorRecord() ([]*models.MonitoringRecord, error) {
  2008. var monitors []*models.MonitoringRecord
  2009. err := readDb.Model(&models.MonitoringRecord{}).Where("status = 1 AND operate_time = 0 AND monitoring_date <> 0").Order("id asc").Limit(100).Find(&monitors).Error
  2010. if err != nil {
  2011. return nil, err
  2012. }
  2013. return monitors, nil
  2014. }
  2015. func BatchUpdateMonitors(monitors []*models.MonitoringRecord) error {
  2016. tx := writeDb.Begin()
  2017. for index := 0; index < len(monitors); index++ {
  2018. tx.Save(monitors[index])
  2019. }
  2020. return tx.Commit().Error
  2021. }
  2022. func ModifyStartDialysisOrder(order *models.DialysisOrder) error {
  2023. tx := writeDb.Begin()
  2024. updateTime := time.Now().Unix()
  2025. 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}).Error
  2026. if err != nil {
  2027. tx.Rollback()
  2028. return err
  2029. }
  2030. tx.Commit()
  2031. return err
  2032. }
  2033. func ModifyFinishDialysisOrder(order *models.DialysisOrder) error {
  2034. tx := writeDb.Begin()
  2035. updateTime := time.Now().Unix()
  2036. 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
  2037. if err != nil {
  2038. tx.Rollback()
  2039. return err
  2040. }
  2041. tx.Commit()
  2042. return err
  2043. }
  2044. func MobileGetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  2045. var record models.SgjPatientDryweight
  2046. err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  2047. if err != nil {
  2048. if err == gorm.ErrRecordNotFound {
  2049. return nil, nil
  2050. } else {
  2051. return nil, err
  2052. }
  2053. }
  2054. return &record, nil
  2055. }
  2056. //func MobileGetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  2057. // var record models.SgjPatientDryweight
  2058. // redis := RedisClient()
  2059. // defer redis.Close()
  2060. //
  2061. // key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":last_dry_weight"
  2062. // last_dry_weight_str, _ := redis.Get(key).Result()
  2063. //
  2064. // if len(last_dry_weight_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2065. // err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  2066. // if err != nil {
  2067. // if err == gorm.ErrRecordNotFound {
  2068. // if record.ID <= 0 {
  2069. // redis.Set(key, "null", time.Second*60*60*18)
  2070. // }
  2071. // return nil, nil
  2072. // } else {
  2073. // return nil, err
  2074. // }
  2075. // } else {
  2076. // if record.ID > 0 {
  2077. // //缓存数据
  2078. // last_dry_weight_str, err := json.Marshal(record)
  2079. // if err == nil {
  2080. // redis.Set(key, last_dry_weight_str, time.Second*60*60*18)
  2081. // return nil, err
  2082. // }
  2083. // } else {
  2084. // redis.Set(key, "null", time.Second*60*60*18)
  2085. // return nil, err
  2086. // }
  2087. // return &record, nil
  2088. // }
  2089. // } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2090. // if last_dry_weight_str == "null" {
  2091. // return &record, nil
  2092. // } else {
  2093. // json.Unmarshal([]byte(last_dry_weight_str), &record)
  2094. // return &record, nil
  2095. // }
  2096. //
  2097. // }
  2098. //}
  2099. // 透析方案
  2100. func MobileGetDialysisSolutionByModeIdSix(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  2101. var record models.DialysisSolution
  2102. 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
  2103. if err != nil {
  2104. if err == gorm.ErrRecordNotFound {
  2105. return nil, nil
  2106. } else {
  2107. return nil, err
  2108. }
  2109. }
  2110. return &record, nil
  2111. }
  2112. // 透析方案
  2113. func MobileGetDialysisSolutionByModeIdSevenTwety(orgID int64, patientID int64, mode_id int64) (models.DialysisSolution, error) {
  2114. var record models.DialysisSolution
  2115. 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
  2116. return record, nil
  2117. }
  2118. // 透析方案
  2119. func MobileGetDialysisSolutionByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  2120. var record models.DialysisSolution
  2121. redis := RedisClient()
  2122. defer redis.Close()
  2123. // cur_date := time.Now().Format("2006-01-02")
  2124. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2125. dialysis_solution_str, _ := redis.Get(key).Result()
  2126. if len(dialysis_solution_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2127. 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
  2128. if err != nil {
  2129. if err == gorm.ErrRecordNotFound {
  2130. if record.ID <= 0 {
  2131. redis.Set(key, "null", time.Second*60*60*18)
  2132. }
  2133. return nil, nil
  2134. } else {
  2135. return nil, err
  2136. }
  2137. } else {
  2138. if record.ID > 0 {
  2139. //缓存数据
  2140. dialysis_solution_str, err := json.Marshal(record)
  2141. if err == nil {
  2142. redis.Set(key, dialysis_solution_str, time.Second*60*60*18)
  2143. }
  2144. } else {
  2145. redis.Set(key, "null", time.Second*60*60*18)
  2146. }
  2147. return &record, nil
  2148. }
  2149. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2150. if dialysis_solution_str == "null" {
  2151. return &record, nil
  2152. } else {
  2153. json.Unmarshal([]byte(dialysis_solution_str), &record)
  2154. return &record, nil
  2155. }
  2156. }
  2157. }
  2158. // 透析处方
  2159. func MobileGetDialysisPrescribeByModeId(orgID int64, patientID int64, recordDate int64, mode_id int64) (*models.DialysisPrescription, error) {
  2160. var record models.DialysisPrescription
  2161. redis := RedisClient()
  2162. defer redis.Close()
  2163. // cur_date := time.Now().Format("2006-01-02")
  2164. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2165. redis.Set(key, "", time.Second)
  2166. dialysis_prescribe_str, _ := redis.Get(key).Result()
  2167. if len(dialysis_prescribe_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2168. 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
  2169. if err != nil {
  2170. if err == gorm.ErrRecordNotFound {
  2171. if record.ID <= 0 {
  2172. redis.Set(key, "null", time.Second*60*60*18)
  2173. }
  2174. return nil, nil
  2175. } else {
  2176. return nil, err
  2177. }
  2178. } else {
  2179. if record.ID > 0 {
  2180. //缓存数据
  2181. dialysis_prescribe_str, err := json.Marshal(record)
  2182. if err == nil {
  2183. redis.Set(key, dialysis_prescribe_str, time.Second*60*60*18)
  2184. }
  2185. } else {
  2186. redis.Set(key, "null", time.Second*60*60*18)
  2187. }
  2188. return &record, nil
  2189. }
  2190. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2191. if dialysis_prescribe_str == "null" {
  2192. return &record, nil
  2193. } else {
  2194. json.Unmarshal([]byte(dialysis_prescribe_str), &record)
  2195. return &record, nil
  2196. }
  2197. }
  2198. }
  2199. func MobileGetDialysisPrescribeByModeIdSix(orgID int64, patientID int64, recordDate int64, mode_id int64) (*models.DialysisPrescription, error) {
  2200. var record models.DialysisPrescription
  2201. 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
  2202. if err != nil {
  2203. if err == gorm.ErrRecordNotFound {
  2204. return nil, nil
  2205. } else {
  2206. return nil, err
  2207. }
  2208. }
  2209. return &record, nil
  2210. }
  2211. func MobileGetDialysisPrescribeByModeIdOne(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  2212. var record models.DialysisPrescription
  2213. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  2214. if err != nil {
  2215. if err == gorm.ErrRecordNotFound {
  2216. return nil, nil
  2217. } else {
  2218. return nil, err
  2219. }
  2220. }
  2221. return &record, nil
  2222. }
  2223. //func MobileGetDialysisPrescribeByModeIdOne(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  2224. // var record models.DialysisPrescription
  2225. // redis := RedisClient()
  2226. // defer redis.Close()
  2227. //
  2228. // // cur_date := time.Now().Format("2006-01-02")
  2229. // key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":dialysis_prescribe_by_mode"
  2230. // dialysis_prescribe_by_mode_str, _ := redis.Get(key).Result()
  2231. //
  2232. // if len(dialysis_prescribe_by_mode_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2233. // err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  2234. // if err != nil {
  2235. // if err == gorm.ErrRecordNotFound {
  2236. // if record.ID <= 0 {
  2237. // redis.Set(key, "null", time.Second*60*60*18)
  2238. // }
  2239. // return nil, nil
  2240. // } else {
  2241. // return nil, err
  2242. // }
  2243. // } else {
  2244. //
  2245. // if record.ID > 0 {
  2246. // //缓存数据
  2247. // dialysis_prescribe_by_mode_str, err := json.Marshal(record)
  2248. //
  2249. // if err == nil {
  2250. // redis.Set(key, dialysis_prescribe_by_mode_str, time.Second*60*60*18)
  2251. // return nil, err
  2252. // }
  2253. // } else {
  2254. // redis.Set(key, "null", time.Second*60*60*18)
  2255. // return nil, err
  2256. // }
  2257. // return &record, nil
  2258. // }
  2259. // } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2260. // if dialysis_prescribe_by_mode_str == "null" {
  2261. // json.Unmarshal([]byte(dialysis_prescribe_by_mode_str), &record)
  2262. // return &record, nil
  2263. // } else {
  2264. // json.Unmarshal([]byte(dialysis_prescribe_by_mode_str), &record)
  2265. // return &record, nil
  2266. // }
  2267. //
  2268. // }
  2269. //}
  2270. func MobileGetLastDialysisPrescribe(orgID int64, patientID int64) (*models.DialysisPrescription, error) {
  2271. var record models.DialysisPrescription
  2272. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 ", patientID, orgID).Last(&record).Error
  2273. if err != nil {
  2274. if err == gorm.ErrRecordNotFound {
  2275. return nil, nil
  2276. } else {
  2277. return nil, err
  2278. }
  2279. }
  2280. return &record, nil
  2281. }
  2282. func MobileGetLastDialysisPrescribeByModeIdSix(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2283. var record models.DialysisPrescription
  2284. 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
  2285. //if err != nil {
  2286. // if err == gorm.ErrRecordNotFound {
  2287. // return nil, nil
  2288. // } else {
  2289. // return nil, err
  2290. // }
  2291. //}
  2292. return &record, err
  2293. }
  2294. func MobileGetLastDialysisPrescribeByModeIdTen(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2295. var record models.DialysisPrescription
  2296. 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
  2297. if err != nil {
  2298. if err == gorm.ErrRecordNotFound {
  2299. return nil, nil
  2300. } else {
  2301. return nil, err
  2302. }
  2303. }
  2304. return &record, err
  2305. }
  2306. func MobileGetLastDialysisPrescribeByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2307. var record models.DialysisPrescription
  2308. redis := RedisClient()
  2309. defer redis.Close()
  2310. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  2311. dialysis_prescribe_by_mode_id, _ := redis.Get(key).Result()
  2312. if len(dialysis_prescribe_by_mode_id) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2313. 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
  2314. if err != nil {
  2315. if err == gorm.ErrRecordNotFound {
  2316. if record.ID <= 0 {
  2317. redis.Set(key, "null", time.Second*60*60*18)
  2318. }
  2319. return nil, nil
  2320. } else {
  2321. return nil, err
  2322. }
  2323. } else {
  2324. if record.ID > 0 {
  2325. //缓存数据
  2326. dialysis_prescribe_by_mode_str, err := json.Marshal(record)
  2327. if err == nil {
  2328. redis.Set(key, dialysis_prescribe_by_mode_str, time.Second*60*60*18)
  2329. return nil, err
  2330. }
  2331. } else {
  2332. redis.Set(key, "null", time.Second*60*60*18)
  2333. return nil, err
  2334. }
  2335. return &record, nil
  2336. }
  2337. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2338. if dialysis_prescribe_by_mode_id == "null" {
  2339. return &record, nil
  2340. } else {
  2341. json.Unmarshal([]byte(dialysis_prescribe_by_mode_id), &record)
  2342. return &record, nil
  2343. }
  2344. }
  2345. }
  2346. func MobileGetLastDialysisPrescribeByModeIdOne(orgID int64, patientID int64, mode_id int64) (models.DialysisPrescription, error) {
  2347. var record models.DialysisPrescription
  2348. 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
  2349. return record, err
  2350. }
  2351. func GetAllAvaildDeviceNumbers(orgID int64, record_date int64, schedule_type int) ([]*DeviceNumberViewModel, error) {
  2352. var vms []*DeviceNumberViewModel = make([]*DeviceNumberViewModel, 0)
  2353. 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()
  2354. defer rows.Close()
  2355. if err != nil {
  2356. return nil, err
  2357. }
  2358. for rows.Next() {
  2359. var vm DeviceNumberViewModel
  2360. readDb.ScanRows(rows, &vm)
  2361. vms = append(vms, &vm)
  2362. }
  2363. return vms, nil
  2364. }
  2365. // 获取 maxDate 之前一次的透前评估记录
  2366. func GetLastTimePredialysisEvaluation(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
  2367. var record models.PredialysisEvaluation
  2368. 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
  2369. if err != nil {
  2370. if err == gorm.ErrRecordNotFound {
  2371. return nil, nil
  2372. } else {
  2373. return nil, err
  2374. }
  2375. }
  2376. return &record, nil
  2377. }
  2378. func GetLastTimeOrder(orgID int64, patientID int64, maxDate int64) (*models.DialysisOrder, error) {
  2379. var record models.DialysisOrder
  2380. 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
  2381. if err != nil {
  2382. if err == gorm.ErrRecordNotFound {
  2383. return nil, nil
  2384. } else {
  2385. return nil, err
  2386. }
  2387. }
  2388. return &record, nil
  2389. }
  2390. func GetLastMonitorRecord(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  2391. var record models.MonitoringRecord
  2392. 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
  2393. if err != nil {
  2394. if err == gorm.ErrRecordNotFound {
  2395. return nil, nil
  2396. } else {
  2397. return nil, err
  2398. }
  2399. }
  2400. return &record, nil
  2401. }
  2402. // 获取 maxDate 之前一次的透后评估记录
  2403. func GetLastTimeAssessmentAfterDislysis(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  2404. var record models.AssessmentAfterDislysis
  2405. 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
  2406. if err != nil {
  2407. if err == gorm.ErrRecordNotFound {
  2408. return nil, nil
  2409. } else {
  2410. return nil, err
  2411. }
  2412. }
  2413. return &record, nil
  2414. }
  2415. // 透析处方
  2416. func GetDialysisPrescribe(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  2417. var record models.DialysisPrescription
  2418. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  2419. if err != nil {
  2420. if err == gorm.ErrRecordNotFound {
  2421. return nil, nil
  2422. } else {
  2423. return nil, err
  2424. }
  2425. }
  2426. return &record, nil
  2427. }
  2428. // 透析方案
  2429. func GetDialysisSolution(orgID int64, patientID int64, mode_id int64) (models.DialysisSolution, error) {
  2430. var record models.DialysisSolution
  2431. 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
  2432. return record, err
  2433. }
  2434. func GetDialysisSolutionOne(orgID int64, mode_id int64) (*models.DialysisSolution, error) {
  2435. var record models.DialysisSolution
  2436. err := readDb.Model(&models.DialysisSolution{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2437. if err != nil {
  2438. if err == gorm.ErrRecordNotFound {
  2439. return nil, nil
  2440. } else {
  2441. return nil, err
  2442. }
  2443. }
  2444. return &record, nil
  2445. }
  2446. func GetLastDialysisPrescribeByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2447. var record models.DialysisPrescription
  2448. 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
  2449. if err != nil {
  2450. if err == gorm.ErrRecordNotFound {
  2451. return nil, nil
  2452. } else {
  2453. return nil, err
  2454. }
  2455. }
  2456. return &record, nil
  2457. }
  2458. func GetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  2459. var record models.SgjPatientDryweight
  2460. err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  2461. if err != nil {
  2462. if err == gorm.ErrRecordNotFound {
  2463. return nil, nil
  2464. } else {
  2465. return nil, err
  2466. }
  2467. }
  2468. return &record, nil
  2469. }
  2470. func MobileGetSystemDialysisPrescribeByModeIdSix(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2471. var record models.SystemPrescription
  2472. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).First(&record).Error
  2473. if err != nil {
  2474. if err == gorm.ErrRecordNotFound {
  2475. return nil, nil
  2476. } else {
  2477. return nil, err
  2478. }
  2479. }
  2480. return &record, nil
  2481. }
  2482. func MobileGetSystemDialysisPrescribeByModeId(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2483. var record models.SystemPrescription
  2484. redis := RedisClient()
  2485. defer redis.Close()
  2486. // cur_date := time.Now().Format("2006-01-02")
  2487. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  2488. system_dialysis_prescribe_str, _ := redis.Get(key).Result()
  2489. if len(system_dialysis_prescribe_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2490. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2491. if err != nil {
  2492. if err == gorm.ErrRecordNotFound {
  2493. if record.ID <= 0 {
  2494. redis.Set(key, "null", time.Second*60*60*18)
  2495. }
  2496. return nil, nil
  2497. } else {
  2498. return nil, err
  2499. }
  2500. } else {
  2501. if record.ID > 0 {
  2502. //缓存数据
  2503. system_dialysis_prescribe_str, err := json.Marshal(record)
  2504. if err == nil {
  2505. redis.Set(key, system_dialysis_prescribe_str, time.Second*60*60*18)
  2506. }
  2507. } else {
  2508. redis.Set(key, "null", time.Second*60*60*18)
  2509. }
  2510. return &record, nil
  2511. }
  2512. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2513. if system_dialysis_prescribe_str == "null" {
  2514. return &record, nil
  2515. } else {
  2516. json.Unmarshal([]byte(system_dialysis_prescribe_str), &record)
  2517. return &record, nil
  2518. }
  2519. }
  2520. }
  2521. func MobileGetSystemDialysisPrescribeByModeIdOne(orgID int64, mode_id int64) (models.SystemPrescription, error) {
  2522. var record models.SystemPrescription
  2523. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2524. return record, err
  2525. }
  2526. func GetSystemDialysisPrescribeByModeId(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2527. var record models.SystemPrescription
  2528. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2529. if err != nil {
  2530. if err == gorm.ErrRecordNotFound {
  2531. return nil, nil
  2532. } else {
  2533. return nil, err
  2534. }
  2535. }
  2536. return &record, nil
  2537. }
  2538. func GetDialysisOrderCount(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2539. 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
  2540. return
  2541. }
  2542. func GetDialysisOrderCountOne(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2543. err = readDb.Model(&models.DialysisOrder{}).Where("dialysis_date>=1640966400 and dialysis_date <= ? AND status = 1 AND stage = 2 AND user_org_id = ? AND patient_id = ?", recordDate, orgID, patient_id).Count(&count).Error
  2544. return
  2545. }
  2546. func GetDialysisOrderCountTwo(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2547. 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
  2548. return
  2549. }
  2550. func GetFirstDateOfMonth(d time.Time) time.Time {
  2551. d = d.AddDate(0, 0, -d.Day()+1)
  2552. return GetZeroTime(d)
  2553. }
  2554. func GetZeroTime(d time.Time) time.Time {
  2555. return time.Date(d.Year(), d.Month(), d.Day(), 0, 0, 0, 0, d.Location())
  2556. }
  2557. func GetDialysisCountByPatientId(startime int64, endtime int64, patientid int64, orgid int64) (order []*models.BloodDialysisOrderCount, err error) {
  2558. db := XTReadDB().Table("xt_dialysis_order as o")
  2559. 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
  2560. return order, err
  2561. }
  2562. func FindConsumablesByDate(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error) {
  2563. 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
  2564. return
  2565. }
  2566. func FindConsumablesByDateTwo(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error) {
  2567. 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
  2568. return
  2569. }
  2570. func FindConsumablesByDateThree(orgID int64, patient_id int64, recordDate int64) (consumables []*models.BloodAutomaticReduceDetail, err error) {
  2571. 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
  2572. return
  2573. }
  2574. //func FindLastConsumables(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error){
  2575. // 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
  2576. // return
  2577. //}
  2578. //
  2579. func GetLastTimeConsumables(orgID int64, patientID int64, maxDate int64) (prepare []*models.DialysisBeforePrepare, err error) {
  2580. 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
  2581. return
  2582. }
  2583. type GoodsType struct {
  2584. ID int64 `gorm:"column:id" json:"id"`
  2585. TypeName string `gorm:"column:type_name" json:"type_name"`
  2586. Remark string `gorm:"column:remark" json:"remark"`
  2587. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2588. Status int64 `gorm:"column:status" json:"status"`
  2589. Type int64 `gorm:"column:type" json:"type"`
  2590. }
  2591. func (GoodsType) TableName() string {
  2592. return "xt_goods_type"
  2593. }
  2594. type VMGoodInfo struct {
  2595. ID int64 `gorm:"column:id" json:"id"`
  2596. SpecificationName string `gorm:"column:specification_name" json:"specification_name"`
  2597. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2598. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2599. GoodName string `gorm:"column:good_name" json:"good_name" form:"good_name"`
  2600. GoodUnit int64 `gorm:"column:good_unit" json:"good_unit" form:"good_unit"`
  2601. Total float64 `gorm:"column:total" json:"total" form:"total"`
  2602. PackingUnit string `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
  2603. MedicalInsuranceNumber string `gorm:"column:medical_insurance_number" json:"medical_insurance_number" form:"medical_insurance_number"`
  2604. }
  2605. func (VMGoodInfo) TableName() string {
  2606. return "xt_good_information"
  2607. }
  2608. type AutomaticReduceDetail struct {
  2609. ID int64 `gorm:"column:id" json:"id"`
  2610. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2611. Status int64 `gorm:"column:status" json:"status"`
  2612. RecordTime int64 `gorm:"column:record_time" json:"record_time"`
  2613. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2614. GoodId int64 `gorm:"column:good_id" json:"good_id"`
  2615. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2616. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"info"`
  2617. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"type"`
  2618. Count int64 `gorm:"column:count" json:"count"`
  2619. }
  2620. func (AutomaticReduceDetail) TableName() string {
  2621. return "xt_automatic_reduce_detail"
  2622. }
  2623. type DialysisBeforePrepare struct {
  2624. ID int64 `gorm:"column:id" json:"id" form:"id"`
  2625. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  2626. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  2627. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  2628. GoodId int64 `gorm:"column:good_id" json:"good_id" form:"good_id"`
  2629. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id" form:"good_type_id"`
  2630. Count int64 `gorm:"column:count" json:"count" form:"count"`
  2631. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  2632. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  2633. Creater int64 `gorm:"column:creater" json:"creater" form:"creater"`
  2634. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  2635. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"info"`
  2636. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"type"`
  2637. }
  2638. func (DialysisBeforePrepare) TableName() string {
  2639. return "dialysis_before_prepare"
  2640. }
  2641. type MDialysisGoodsVM struct {
  2642. ID int64 `gorm:"column:id" json:"id"`
  2643. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2644. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2645. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2646. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2647. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2648. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2649. ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week"`
  2650. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2651. Status int64 `gorm:"column:status" json:"status"`
  2652. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2653. SchedualPatient *MSchedualPatientVMList `gorm:"ForeignKey:PatientId" json:"patient"`
  2654. AutomaticReduceDetail []*AutomaticReduceDetail `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"good_user"`
  2655. LastAutomaticReduceDetail []*AutomaticReduceDetail `gorm:"-" json:"last_good_user"`
  2656. DialysisBeforePrepare []*DialysisBeforePrepare `gorm:"ForeignKey:PatientId,ScheduleDate;AssociationForeignKey:PatientId,RecordDate" json:"good_user_detail"`
  2657. LastDialysisBeforePrepare []*DialysisBeforePrepare `gorm:"-" json:"last_good_user_detail"`
  2658. Project []*models.HisPrescriptionProject `gorm:"-" json:"project"`
  2659. //WarehouseOutInfo []*models.WarehouseOutInfoSeven `gorm:"ForeignKey:PatientId,ScheduleDate;AssociationForeignKey:PatientId,SysRecordTime" json:"ware_house_out_info"`
  2660. DialysisPrescription models.DialysisPrescriptionListSix `gorm:"ForeignKey:PatientId,ModeId;AssociationForeignKey:PatientId,ModeId" json:"prescription"`
  2661. }
  2662. func (MDialysisGoodsVM) TableName() string {
  2663. return "xt_schedule"
  2664. }
  2665. type VMWarehouseOutInfo struct {
  2666. ID int64 `gorm:"column:id" json:"id"`
  2667. WarehouseOutId int64 `gorm:"column:warehouse_out_id" json:"warehouse_out_id"`
  2668. GoodId int64 `gorm:"column:good_id" json:"good_id"`
  2669. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2670. Count int64 `gorm:"column:count" json:"count"`
  2671. Price float64 `gorm:"column:price" json:"price"`
  2672. TotalPrice float64 `gorm:"column:total_price" json:"total_price"`
  2673. Status int64 `gorm:"column:status" json:"status"`
  2674. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2675. WarehouseOutOrderNumber string `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number"`
  2676. GoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"good_info"`
  2677. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"good_type"`
  2678. IsSys int64 `gorm:"column:is_sys" json:"is_sys"`
  2679. SysRecordTime int64 `gorm:"column:sys_record_time" json:"sys_record_time"`
  2680. Mtime int64 `gorm:"column:mtime" json:"mtime"`
  2681. Ctime int64 `gorm:"column:ctime" json:"ctime"`
  2682. }
  2683. func (VMWarehouseOutInfo) TableName() string {
  2684. return "xt_warehouse_out_info"
  2685. }
  2686. type DialysisGoodsDate struct {
  2687. RecordDate int64
  2688. }
  2689. type DialysisGoodsDetailDate struct {
  2690. RecordTime int64
  2691. }
  2692. 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) {
  2693. var vms []*MDialysisGoodsVM
  2694. var total int64
  2695. db := readDb.
  2696. Table("xt_schedule as sch").
  2697. Preload("DialysisPrescription", "status=1 and user_org_id =? and solution_status = 1", orgID).
  2698. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  2699. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2700. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2701. Preload("DialysisBeforePrepare", func(db *gorm.DB) *gorm.DB {
  2702. 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)
  2703. }).
  2704. Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
  2705. 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")
  2706. }).Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
  2707. if scheduleDate != 0 {
  2708. db = db.Where("schedule_date = ?", scheduleDate)
  2709. }
  2710. if schedule_type != 0 {
  2711. db = db.Where("schedule_type = ?", schedule_type)
  2712. }
  2713. if partition_id != 0 {
  2714. db = db.Where("partition_id = ?", partition_id)
  2715. }
  2716. if patient_id != 0 {
  2717. db = db.Where("patient_id = ?", patient_id)
  2718. }
  2719. err := db.Find(&vms).Error
  2720. return vms, err, total
  2721. }
  2722. func GetLastDialysisGoods(patient_id int64, orgID int64, record_time int64) (goodUser []*AutomaticReduceDetail, err error) {
  2723. var Id []*DialysisGoodsDetailDate
  2724. 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
  2725. if len(Id) > 0 {
  2726. 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
  2727. }
  2728. return
  2729. }
  2730. func GetLastDialysisBeforePrepare(patient_id int64, orgID int64, record_time int64) (goodUser []*DialysisBeforePrepare, err error) {
  2731. var Id []*DialysisGoodsDate
  2732. 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
  2733. if len(Id) > 0 {
  2734. 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
  2735. }
  2736. return
  2737. }
  2738. func GetAllWarehouseOutSumList(patient_id int64, orgID int64, record_time int64) (info []*models.WarehouseOutInfoSeven, err error) {
  2739. err = XTReadDB().Where("patient_id = ? and org_id = ? and sys_record_time = ? and status = 1", patient_id, orgID, record_time).Find(&info).Error
  2740. return info, err
  2741. }
  2742. func MobileGetGoodsStatistics(orgID int64, start_time int64, end_time int64) (list []*models.StockInfo, err error) {
  2743. db := readDb.Model(&models.StockInfo{})
  2744. db = db.Where("xt_good_information.org_id = ? AND xt_good_information.status = 1", orgID)
  2745. 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")
  2746. db = db.Preload("QueryWarehouseOutInfo", func(db *gorm.DB) *gorm.DB {
  2747. 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)
  2748. })
  2749. db = db.Preload("GoodsType", "org_id = ? AND status = 1", orgID)
  2750. err = db.Order("ctime desc").Find(&list).Error
  2751. return
  2752. }
  2753. 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) {
  2754. var vms []*MDialysisGoodsVM
  2755. var total int64
  2756. db := readDb.
  2757. Model(&models.Schedule{}).
  2758. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  2759. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2760. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2761. Preload("DialysisBeforePrepare", func(db *gorm.DB) *gorm.DB {
  2762. return db.Preload("VMGoodInfo", "status = 1 AND org_id = ? ", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0) ", orgID).Where("status = 1 AND user_org_id = ? AND record_date = ? AND count > 0 ", orgID, scheduleDate)
  2763. }).Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
  2764. 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)
  2765. }).Where("xt_schedule.status = 1 AND xt_schedule.user_org_id = ?", orgID)
  2766. if scheduleDate != 0 {
  2767. db = db.Where("schedule_date = ?", scheduleDate)
  2768. }
  2769. if patient_id != 0 {
  2770. db = db.Where("patient_id = ?", patient_id)
  2771. }
  2772. if len(keywords) != 0 {
  2773. keywords = "%" + keywords + "%"
  2774. 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)
  2775. if schedule_type != 0 {
  2776. db = db.Where("schedule_type = ?", schedule_type)
  2777. }
  2778. if partition_id != 0 {
  2779. db = db.Where("partition_id = ?", partition_id)
  2780. }
  2781. if good_type == 1 {
  2782. db = db.Where("patient_id in(?)", ids)
  2783. }
  2784. if good_type == 2 {
  2785. if len(ids) > 0 {
  2786. db = db.Where("patient_id not in(?)", ids)
  2787. }
  2788. }
  2789. } else {
  2790. if schedule_type != 0 {
  2791. db = db.Where("schedule_type = ?", schedule_type)
  2792. }
  2793. if partition_id != 0 {
  2794. db = db.Where("partition_id = ?", partition_id)
  2795. }
  2796. if good_type == 1 {
  2797. db = db.Where("patient_id in(?)", ids)
  2798. }
  2799. if good_type == 2 {
  2800. if len(ids) > 0 {
  2801. db = db.Where("patient_id not in(?)", ids)
  2802. }
  2803. }
  2804. db = db.Count(&total)
  2805. offset := (page - 1) * limit
  2806. db = db.Offset(offset).Limit(limit)
  2807. }
  2808. err := db.Find(&vms).Error
  2809. return vms, err, total
  2810. }
  2811. func GetLastDialysisGoodsTwo(patient_id int64, orgID int64, record_time int64) (goodUser []*AutomaticReduceDetail, err error) {
  2812. var Id []*DialysisGoodsDetailDate
  2813. 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
  2814. if len(Id) > 0 {
  2815. 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
  2816. }
  2817. return
  2818. }
  2819. func GetLastDialysisBeforePrepareTwo(patient_id int64, orgID int64, record_time int64) (goodUser []*DialysisBeforePrepare, err error) {
  2820. var Id []*DialysisGoodsDate
  2821. 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
  2822. if len(Id) > 0 {
  2823. 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
  2824. }
  2825. return
  2826. }
  2827. func GetAssessmentBefor(orgid int64, patientid int64, recorddate int64) (*models.PredialysisEvaluation, error) {
  2828. evaluation := models.PredialysisEvaluation{}
  2829. err := XTReadDB().Model(&evaluation).Where("user_org_id = ? and patient_id = ? and assessment_date = ? and status = 1", orgid, patientid, recorddate).Find(&evaluation).Error
  2830. if err == gorm.ErrRecordNotFound {
  2831. return nil, err
  2832. }
  2833. if err != nil {
  2834. return nil, err
  2835. }
  2836. return &evaluation, nil
  2837. }
  2838. func GetAssessmentBeforThrity(orgid int64, patientid int64, recorddate int64) (models.PredialysisEvaluation, error) {
  2839. evaluation := models.PredialysisEvaluation{}
  2840. err := XTReadDB().Model(&evaluation).Where("user_org_id = ? and patient_id = ? and assessment_date = ? and status = 1", orgid, patientid, recorddate).Find(&evaluation).Error
  2841. return evaluation, err
  2842. }
  2843. func GetAllHisDoctorAdvice(orgid int64, patientid int64, recorddate int64) (his []*models.HisDoctorAdviceInfo, err error) {
  2844. redis := RedisClient()
  2845. defer redis.Close()
  2846. key := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patientid, 10) + ":" + strconv.FormatInt(recorddate, 10) + ":his_doctor_advice"
  2847. his_doctor_advice_str, _ := redis.Get(key).Result()
  2848. redis.Set(key, "", time.Second)
  2849. if len(his_doctor_advice_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2850. 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
  2851. if err != nil {
  2852. if err == gorm.ErrRecordNotFound {
  2853. if len(his) <= 0 {
  2854. redis.Set(key, "null", time.Second*60*60*18)
  2855. }
  2856. return his, nil
  2857. } else {
  2858. return his, err
  2859. }
  2860. } else {
  2861. if len(his) > 0 {
  2862. //缓存数据
  2863. his_doctor_advice_str, err := json.Marshal(his)
  2864. if err == nil {
  2865. redis.Set(key, his_doctor_advice_str, time.Second*60*60*18)
  2866. }
  2867. } else {
  2868. redis.Set(key, "null", time.Second*60*60*18)
  2869. }
  2870. return his, nil
  2871. }
  2872. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2873. json.Unmarshal([]byte(his_doctor_advice_str), &his)
  2874. return his, nil
  2875. }
  2876. }
  2877. func GetLastDialysisPrescriptionByPatientId(orgid int64, patientid int64, recorddate int64) (*models.DialysisPrescription, error) {
  2878. prescription := models.DialysisPrescription{}
  2879. err := readDb.Model(&models.DialysisPrescription{}).Where("user_org_id = ? and patient_id = ? and record_date = ? and status = 1", orgid, patientid, recorddate).Find(&prescription).Error
  2880. if err == gorm.ErrRecordNotFound {
  2881. return nil, err
  2882. }
  2883. if err != nil {
  2884. return nil, err
  2885. }
  2886. return &prescription, nil
  2887. }
  2888. func GetLastDialysisPrescriptionByPatientIdTwo(orgid int64, patientid int64, recorddate int64) (models.DialysisPrescription, error) {
  2889. prescription := models.DialysisPrescription{}
  2890. err := readDb.Model(&models.DialysisPrescription{}).Where("user_org_id = ? and patient_id = ? and record_date = ? and status = 1", orgid, patientid, recorddate).Find(&prescription).Error
  2891. return prescription, err
  2892. }
  2893. type HisMScheduleDoctorAdviceVM struct {
  2894. ID int64 `gorm:"column:id" json:"id"`
  2895. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2896. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2897. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2898. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2899. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2900. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2901. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2902. Status int64 `gorm:"column:status" json:"status"`
  2903. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  2904. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  2905. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2906. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  2907. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  2908. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  2909. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  2910. }
  2911. func (HisMScheduleDoctorAdviceVM) TableName() string {
  2912. return "xt_schedule"
  2913. }
  2914. type HisMScheduleDoctorAdviceVMOne struct {
  2915. ID int64 `gorm:"column:id" json:"id"`
  2916. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2917. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2918. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2919. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2920. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2921. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2922. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2923. Status int64 `gorm:"column:status" json:"status"`
  2924. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  2925. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  2926. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2927. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  2928. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  2929. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  2930. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  2931. }
  2932. func (HisMScheduleDoctorAdviceVMOne) TableName() string {
  2933. return "xt_schedule"
  2934. }
  2935. type HisMScheduleProjectVM struct {
  2936. ID int64 `gorm:"column:id" json:"id"`
  2937. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2938. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2939. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2940. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2941. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2942. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2943. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2944. Status int64 `gorm:"column:status" json:"status"`
  2945. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  2946. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  2947. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2948. Prescription *models.DialysisPrescriptionTwenty `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  2949. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  2950. HisPrescriptionTeamProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"team_project"`
  2951. }
  2952. func (HisMScheduleProjectVM) TableName() string {
  2953. return "xt_schedule"
  2954. }
  2955. func GetHisDoctorConfig(orgid int64) (models.XtHisConfig, error) {
  2956. config := models.XtHisConfig{}
  2957. err := XTReadDB().Model(&config).Where("user_org_id = ? and status =1", orgid).Find(&config).Error
  2958. return config, err
  2959. }
  2960. func GetHisDoctorPatientById(orgid int64, patientid int64, recordtime int64) (advice []*models.HisDoctorAdviceInfo, err error) {
  2961. db := XTReadDB().Table("his_doctor_advice_info as x").Where("x.status = 1")
  2962. if orgid > 0 {
  2963. db = db.Where("x.user_org_id = ?", orgid)
  2964. }
  2965. if patientid > 0 {
  2966. db = db.Where("x.patient_id =?", patientid)
  2967. }
  2968. if recordtime > 0 {
  2969. db = db.Where("x.advice_date = ?", recordtime)
  2970. }
  2971. 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
  2972. return advice, err
  2973. }
  2974. func GetDoctorAdviceCount(startime int64, endtime int64, deliveway string, orgid int64) (advice []*models.BloodDoctorAdvice, err error) {
  2975. db := XTReadDB().Table("xt_doctor_advice as x").Where("x.status = 1 and x.advice_type =2")
  2976. if startime > 0 {
  2977. db = db.Where("x.advice_date >= ?", startime)
  2978. }
  2979. if endtime > 0 {
  2980. db = db.Where("x.advice_date<=?", endtime)
  2981. }
  2982. if orgid > 0 {
  2983. db = db.Where("x.user_org_id = ?", orgid)
  2984. }
  2985. if len(deliveway) > 0 {
  2986. db = db.Where("x.delivery_way = ?", deliveway)
  2987. }
  2988. 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
  2989. return advice, err
  2990. }
  2991. func GetHisDoctorAdviceCount(startime int64, endtime int64, deliveway string, orgid int64) (advice []*models.BloodDoctorAdvice, err error) {
  2992. db := XTReadDB().Table("his_doctor_advice_info as x").Where("x.status = 1 and x.advice_type =2")
  2993. if startime > 0 {
  2994. db = db.Where("x.advice_date >= ?", startime)
  2995. }
  2996. if endtime > 0 {
  2997. db = db.Where("x.advice_date<=?", endtime)
  2998. }
  2999. if orgid > 0 {
  3000. db = db.Where("x.user_org_id = ?", orgid)
  3001. }
  3002. if len(deliveway) > 0 {
  3003. db = db.Where("x.delivery_way = ?", deliveway)
  3004. }
  3005. 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
  3006. return advice, err
  3007. }
  3008. 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) {
  3009. var vms []*MScheduleDoctorAdviceVM
  3010. adviceWhere := ""
  3011. adviceCondition := []interface{}{}
  3012. if adviceType == 0 {
  3013. if patientType == 0 {
  3014. if patient_id > 0 {
  3015. if execution_state > 0 {
  3016. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  3017. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3018. } else {
  3019. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
  3020. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3021. }
  3022. } else {
  3023. if execution_state > 0 {
  3024. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ?"
  3025. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3026. } else {
  3027. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  3028. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3029. }
  3030. }
  3031. } else if patientType == 1 {
  3032. if patient_id > 0 {
  3033. if execution_state > 0 {
  3034. 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= ?"
  3035. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3036. } else {
  3037. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
  3038. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3039. }
  3040. } else {
  3041. if execution_state > 0 {
  3042. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  3043. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3044. } else {
  3045. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  3046. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3047. }
  3048. }
  3049. } else if patientType == 2 {
  3050. if patient_id > 0 {
  3051. if execution_state > 0 {
  3052. 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 = ?"
  3053. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3054. } else {
  3055. 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 = ?)"
  3056. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3057. }
  3058. } else {
  3059. if execution_state > 0 {
  3060. 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 = ?"
  3061. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3062. } else {
  3063. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  3064. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3065. }
  3066. }
  3067. }
  3068. } else if adviceType == 1 {
  3069. if patientType == 0 {
  3070. if patient_id > 0 {
  3071. if execution_state > 0 {
  3072. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ?"
  3073. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3074. } else {
  3075. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
  3076. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3077. }
  3078. } else {
  3079. if execution_state > 0 {
  3080. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ?"
  3081. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3082. } else {
  3083. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  3084. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3085. }
  3086. }
  3087. } else if patientType == 1 {
  3088. if patient_id > 0 {
  3089. if execution_state > 0 {
  3090. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  3091. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3092. } else {
  3093. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
  3094. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3095. }
  3096. } else {
  3097. if execution_state > 0 {
  3098. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?"
  3099. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3100. } else {
  3101. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  3102. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3103. }
  3104. }
  3105. } else if patientType == 2 {
  3106. if patient_id > 0 {
  3107. if execution_state > 0 {
  3108. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  3109. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3110. } else {
  3111. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
  3112. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3113. }
  3114. } else {
  3115. if execution_state > 0 {
  3116. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ?"
  3117. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3118. } else {
  3119. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  3120. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3121. }
  3122. }
  3123. }
  3124. } else if adviceType == 3 {
  3125. if patientType == 0 {
  3126. if patient_id > 0 {
  3127. if execution_state > 0 {
  3128. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ?"
  3129. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3130. } else {
  3131. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? "
  3132. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3133. }
  3134. } else {
  3135. if execution_state > 0 {
  3136. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? "
  3137. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3138. } else {
  3139. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  3140. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3141. }
  3142. }
  3143. } else if patientType == 1 {
  3144. if patient_id > 0 {
  3145. if execution_state > 0 {
  3146. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  3147. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3148. } else {
  3149. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
  3150. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3151. }
  3152. } else {
  3153. if execution_state > 0 {
  3154. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? "
  3155. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3156. } else {
  3157. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  3158. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3159. }
  3160. }
  3161. } else if patientType == 2 {
  3162. if patient_id > 0 {
  3163. if execution_state > 0 {
  3164. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  3165. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3166. } else {
  3167. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ?"
  3168. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3169. }
  3170. } else {
  3171. if execution_state > 0 {
  3172. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ?"
  3173. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3174. } else {
  3175. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  3176. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3177. }
  3178. }
  3179. }
  3180. } else if adviceType == 2 && len(deliverWay) > 0 {
  3181. if patientType == 0 {
  3182. if patient_id > 0 {
  3183. if execution_state > 0 {
  3184. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  3185. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  3186. } else {
  3187. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ?"
  3188. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  3189. }
  3190. } else {
  3191. if execution_state > 0 {
  3192. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ?"
  3193. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  3194. } else {
  3195. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  3196. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  3197. }
  3198. }
  3199. } else if patientType == 1 {
  3200. if patient_id > 0 {
  3201. if execution_state > 0 {
  3202. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  3203. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state)
  3204. } else {
  3205. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ?"
  3206. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
  3207. }
  3208. } else {
  3209. if execution_state > 0 {
  3210. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ?"
  3211. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state)
  3212. } else {
  3213. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  3214. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  3215. }
  3216. }
  3217. } else if patientType == 2 {
  3218. if patient_id > 0 {
  3219. if execution_state > 0 {
  3220. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ?"
  3221. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  3222. } else {
  3223. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ?"
  3224. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  3225. }
  3226. } else {
  3227. if execution_state > 0 {
  3228. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ?"
  3229. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  3230. } else {
  3231. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  3232. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  3233. }
  3234. }
  3235. }
  3236. } else if adviceType == 2 && len(deliverWay) <= 0 {
  3237. if patientType == 0 {
  3238. if patient_id > 0 {
  3239. if execution_state > 0 {
  3240. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ?"
  3241. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3242. } else {
  3243. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ?"
  3244. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3245. }
  3246. } else {
  3247. if execution_state > 0 {
  3248. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?"
  3249. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3250. } else {
  3251. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  3252. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3253. }
  3254. }
  3255. } else if patientType == 1 {
  3256. if patient_id > 0 {
  3257. if execution_state > 0 {
  3258. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  3259. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3260. } else {
  3261. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ?"
  3262. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3263. }
  3264. } else {
  3265. if execution_state > 0 {
  3266. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ?"
  3267. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3268. } else {
  3269. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?"
  3270. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3271. }
  3272. }
  3273. } else if patientType == 2 {
  3274. if patient_id > 0 {
  3275. if execution_state > 0 {
  3276. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  3277. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3278. } else {
  3279. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ?"
  3280. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3281. }
  3282. } else {
  3283. if execution_state > 0 {
  3284. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ?"
  3285. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3286. } else {
  3287. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  3288. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3289. }
  3290. }
  3291. }
  3292. }
  3293. db := readDb.Table("xt_schedule")
  3294. if scheduleType > 0 {
  3295. db = db.Where("schedule_type = ?", scheduleType)
  3296. }
  3297. if partitonType > 0 {
  3298. db = db.Where("partition_id = ?", partitonType)
  3299. }
  3300. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3301. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3302. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3303. }).
  3304. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3305. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3306. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3307. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3308. Preload("DoctorAdvices", adviceCondition...).
  3309. Where("status = 1 AND user_org_id = ?", orgID)
  3310. if scheduleDate != 0 {
  3311. db = db.Where("schedule_date = ?", scheduleDate)
  3312. }
  3313. err := db.Find(&vms).Error
  3314. return vms, err
  3315. }
  3316. func GetHisDoctorAdvicesOne(orgID int64, scheduleDate int64, deliverWay string, scheduleType int64, partitionType int64, patient_id int64, execution_state int64, cost_type int64) ([]*HisMScheduleDoctorAdviceVM, error) {
  3317. var vms []*HisMScheduleDoctorAdviceVM
  3318. if len(deliverWay) > 0 {
  3319. db := readDb.Table("xt_schedule")
  3320. if scheduleType > 0 {
  3321. db = db.Where("schedule_type = ?", scheduleType)
  3322. }
  3323. if partitionType > 0 {
  3324. db = db.Where("partition_id = ?", partitionType)
  3325. }
  3326. if patient_id > 0 {
  3327. if execution_state > 0 {
  3328. if cost_type > 0 {
  3329. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3330. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3331. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3332. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3333. 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).
  3334. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3335. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3336. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3337. Where("status = 1 AND user_org_id = ?", orgID)
  3338. if scheduleDate != 0 {
  3339. db = db.Where("schedule_date = ?", scheduleDate)
  3340. }
  3341. err = db.Find(&vms).Error
  3342. } else {
  3343. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3344. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3345. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3346. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3347. 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).
  3348. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3349. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3350. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3351. Where("status = 1 AND user_org_id = ?", orgID)
  3352. if scheduleDate != 0 {
  3353. db = db.Where("schedule_date = ?", scheduleDate)
  3354. }
  3355. err = db.Find(&vms).Error
  3356. }
  3357. } else {
  3358. if cost_type > 0 {
  3359. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3360. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3361. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3362. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3363. 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).
  3364. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3365. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3366. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3367. Where("status = 1 AND user_org_id = ?", orgID)
  3368. if scheduleDate != 0 {
  3369. db = db.Where("schedule_date = ?", scheduleDate)
  3370. }
  3371. err = db.Find(&vms).Error
  3372. } else {
  3373. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3374. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3375. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3376. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3377. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ?", orgID, scheduleDate, deliverWay, patient_id).
  3378. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3379. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3380. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3381. Where("status = 1 AND user_org_id = ?", orgID)
  3382. if scheduleDate != 0 {
  3383. db = db.Where("schedule_date = ?", scheduleDate)
  3384. }
  3385. err = db.Find(&vms).Error
  3386. }
  3387. }
  3388. } else {
  3389. if execution_state > 0 {
  3390. if cost_type > 0 {
  3391. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3392. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3393. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3394. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3395. 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).
  3396. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3397. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3398. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3399. Where("status = 1 AND user_org_id = ?", orgID)
  3400. if scheduleDate != 0 {
  3401. db = db.Where("schedule_date = ?", scheduleDate)
  3402. }
  3403. err = db.Find(&vms).Error
  3404. } else {
  3405. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3406. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3407. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3408. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3409. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_state = ?", orgID, scheduleDate, deliverWay, execution_state).
  3410. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3411. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3412. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3413. Where("status = 1 AND user_org_id = ?", orgID)
  3414. if scheduleDate != 0 {
  3415. db = db.Where("schedule_date = ?", scheduleDate)
  3416. }
  3417. err = db.Find(&vms).Error
  3418. }
  3419. } else {
  3420. if cost_type > 0 {
  3421. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3422. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3423. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3424. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3425. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and is_settle = ?", orgID, scheduleDate, deliverWay, cost_type).
  3426. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3427. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3428. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3429. Where("status = 1 AND user_org_id = ?", orgID)
  3430. if scheduleDate != 0 {
  3431. db = db.Where("schedule_date = ?", scheduleDate)
  3432. }
  3433. err = db.Find(&vms).Error
  3434. } else {
  3435. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3436. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3437. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3438. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3439. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  3440. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3441. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3442. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3443. Where("status = 1 AND user_org_id = ?", orgID)
  3444. if scheduleDate != 0 {
  3445. db = db.Where("schedule_date = ?", scheduleDate)
  3446. }
  3447. err = db.Find(&vms).Error
  3448. }
  3449. }
  3450. }
  3451. } else {
  3452. db := readDb.Table("xt_schedule")
  3453. if scheduleType > 0 {
  3454. db = db.Where("schedule_type = ?", scheduleType)
  3455. }
  3456. if partitionType > 0 {
  3457. db = db.Where("partition_id = ?", partitionType)
  3458. }
  3459. if patient_id > 0 {
  3460. if execution_state > 0 {
  3461. if cost_type > 0 {
  3462. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3463. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3464. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3465. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3466. 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).
  3467. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3468. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3469. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3470. Where("status = 1 AND user_org_id = ?", orgID)
  3471. if scheduleDate != 0 {
  3472. db = db.Where("schedule_date = ?", scheduleDate)
  3473. }
  3474. err = db.Find(&vms).Error
  3475. } else {
  3476. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3477. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3478. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3479. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3480. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and execution_state = ?", orgID, scheduleDate, patient_id, execution_state).
  3481. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3482. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3483. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3484. Where("status = 1 AND user_org_id = ?", orgID)
  3485. if scheduleDate != 0 {
  3486. db = db.Where("schedule_date = ?", scheduleDate)
  3487. }
  3488. err = db.Find(&vms).Error
  3489. }
  3490. } else {
  3491. if cost_type > 0 {
  3492. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3493. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3494. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3495. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3496. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and is_settle = ?", orgID, scheduleDate, patient_id, cost_type).
  3497. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3498. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3499. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3500. Where("status = 1 AND user_org_id = ?", orgID)
  3501. if scheduleDate != 0 {
  3502. db = db.Where("schedule_date = ?", scheduleDate)
  3503. }
  3504. err = db.Find(&vms).Error
  3505. } else {
  3506. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  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 = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3510. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3511. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3512. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).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. }
  3520. }
  3521. } else {
  3522. if execution_state > 0 {
  3523. if cost_type > 0 {
  3524. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3525. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3526. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3527. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3528. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ? and is_settle = ?", orgID, scheduleDate, execution_state, cost_type).
  3529. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3530. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3531. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3532. Where("status = 1 AND user_org_id = ?", orgID)
  3533. if scheduleDate != 0 {
  3534. db = db.Where("schedule_date = ?", scheduleDate)
  3535. }
  3536. err = db.Find(&vms).Error
  3537. } else {
  3538. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3539. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3540. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3541. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3542. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ?", orgID, scheduleDate, execution_state).
  3543. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3544. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3545. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3546. Where("status = 1 AND user_org_id = ?", orgID)
  3547. if scheduleDate != 0 {
  3548. db = db.Where("schedule_date = ?", scheduleDate)
  3549. }
  3550. err = db.Find(&vms).Error
  3551. }
  3552. } else {
  3553. if cost_type > 0 {
  3554. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3555. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3556. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3557. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3558. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and is_settle = ?", orgID, scheduleDate, cost_type).
  3559. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3560. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3561. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3562. Where("status = 1 AND user_org_id = ?", orgID)
  3563. if scheduleDate != 0 {
  3564. db = db.Where("schedule_date = ?", scheduleDate)
  3565. }
  3566. err = db.Find(&vms).Error
  3567. } else {
  3568. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3569. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3570. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3571. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3572. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ?", orgID, scheduleDate).
  3573. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3574. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3575. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3576. Where("status = 1 AND user_org_id = ?", orgID)
  3577. if scheduleDate != 0 {
  3578. db = db.Where("schedule_date = ?", scheduleDate)
  3579. }
  3580. err = db.Find(&vms).Error
  3581. }
  3582. }
  3583. }
  3584. }
  3585. return vms, err
  3586. }
  3587. func BatchDeleteMonitor(ids []string) (err error) {
  3588. if len(ids) == 1 {
  3589. err = XTWriteDB().Model(&models.MonitoringRecord{}).Where("id=?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3590. } else {
  3591. err = XTWriteDB().Model(models.MonitoringRecord{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3592. }
  3593. return
  3594. }
  3595. func GetPatientDialysisRecordList(patientid int64, startime int64, endtime int64) (order []*models.XtDialysisOrders, err error) {
  3596. db := XTReadDB().Table("xt_dialysis_order as x").Where("x.status = 1")
  3597. //table := XTReadDB().Table("xt_schedule as s")
  3598. //fmt.Println(table)
  3599. if patientid > 0 {
  3600. db = db.Where("x.patient_id = ?", patientid)
  3601. }
  3602. if startime > 0 {
  3603. db = db.Where("x.dialysis_date>=?", startime)
  3604. }
  3605. if endtime > 0 {
  3606. db = db.Where("x.dialysis_date <= ?", endtime)
  3607. }
  3608. 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
  3609. return order, err
  3610. }
  3611. func GetPatientDialysisRecordListOne(patientid int64, startime int64, endtime int64) (order []*models.XtScheduleSixTy, err error) {
  3612. db := XTReadDB().Table("xt_schedule as x").Where("x.status = 1")
  3613. //table := XTReadDB().Table("xt_schedule as s")
  3614. //fmt.Println(table)
  3615. if patientid > 0 {
  3616. db = db.Where("x.patient_id = ?", patientid)
  3617. }
  3618. if startime > 0 {
  3619. db = db.Where("x.schedule_date>=?", startime)
  3620. }
  3621. if endtime > 0 {
  3622. db = db.Where("x.schedule_date <= ?", endtime)
  3623. }
  3624. err = db.Select("x.id,x.schedule_date,x.schedule_type,x.mode_id").Find(&order).Error
  3625. return order, err
  3626. }
  3627. func BatchDeleteAdvice(ids []string) (err error) {
  3628. if len(ids) == 1 {
  3629. err = XTWriteDB().Model(&models.DoctorAdvice{}).Where("id=?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3630. } else {
  3631. err = XTWriteDB().Model(models.DoctorAdvice{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3632. }
  3633. return
  3634. }
  3635. func BatchDeleteHisAdvice(ids []string) (err error) {
  3636. if len(ids) == 1 {
  3637. err = XTWriteDB().Model(&models.HisDoctorAdviceInfo{}).Where("id = ?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3638. } else {
  3639. err = XTWriteDB().Model(models.HisDoctorAdviceInfo{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3640. }
  3641. return
  3642. }
  3643. func UpdateAutoReduceDetail(good_id int64, count int64, record_time int64, patient_id int64) (models.AutomaticReduceDetail, error) {
  3644. detail := models.AutomaticReduceDetail{}
  3645. 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
  3646. return detail, err
  3647. }
  3648. func DeleteAutoReduceDetail(good_id int64, record_time int64, patient_id int64) error {
  3649. detail := models.AutomaticReduceDetail{}
  3650. 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
  3651. return err
  3652. }
  3653. func DeleteDialysisBeforOne(good_id int64, record_time int64, patient_id int64) error {
  3654. detail := models.DialysisBeforePrepare{}
  3655. 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
  3656. return err
  3657. }
  3658. func BatchAdviceCheck(ids []string, creator int64) error {
  3659. advice := models.XtDoctorAdvice{}
  3660. 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
  3661. return err
  3662. }
  3663. func BatchHisAdviceCheck(ids []string, creator int64) error {
  3664. advice := models.HisDoctorAdviceInfo{}
  3665. 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
  3666. return err
  3667. }
  3668. func BatchAdviceExecution(ids []string, creator int64, execution_state int64) error {
  3669. advice := models.XtDoctorAdvice{}
  3670. 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
  3671. return err
  3672. }
  3673. func BatchHisAdviceExecution(ids []string, creator int64, execution_state int64) error {
  3674. advice := models.HisDoctorAdviceInfo{}
  3675. 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
  3676. return err
  3677. }
  3678. func GetAdviceExecutionById(ids []string) (doctor []*models.XtDoctorAdvice, err error) {
  3679. err = XTReadDB().Model(&doctor).Where("id IN(?) AND status = 1", ids).Find(&doctor).Error
  3680. return doctor, err
  3681. }
  3682. func GetHisAdviceExecutionById(ids []string) (doctor []*models.HisDoctorAdviceInfo, err error) {
  3683. err = XTReadDB().Model(&doctor).Where("id IN(?) AND status = 1", ids).Find(&doctor).Error
  3684. return doctor, err
  3685. }
  3686. func GetHisProjectConfig(orgid int64) (models.XtHisProjectConfig, error) {
  3687. config := models.XtHisProjectConfig{}
  3688. err := XTReadDB().Model(&config).Where("user_org_id = ? and status =1", orgid).Find(&config).Error
  3689. return config, err
  3690. }
  3691. func GetHisPrescriptionProject(org_id int64, patient_id int64, record_date int64) (project []*models.HisPrescriptionProject, err error) {
  3692. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("GoodInfo", func(db *gorm.DB) *gorm.DB {
  3693. return db.Preload("GoodsType", "status = 1").Where("status = 1 and is_warehouse = 1")
  3694. }).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
  3695. return
  3696. }
  3697. func GetPCHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64, patient_id int64, execution_state int64) ([]*HisMScheduleProjectVM, error) {
  3698. var vms []*HisMScheduleProjectVM
  3699. if patientType == 0 {
  3700. if patient_id > 0 {
  3701. if execution_state == 1 {
  3702. db := readDb.
  3703. Table("xt_schedule").
  3704. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3705. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3706. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3707. }).
  3708. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3709. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3710. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3711. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3712. 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")
  3713. }).
  3714. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3715. 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")
  3716. }).Where("status = 1 AND user_org_id = ?", orgID)
  3717. if scheduleDate != 0 {
  3718. db = db.Where("schedule_date = ?", scheduleDate)
  3719. }
  3720. err = db.Find(&vms).Error
  3721. } else if execution_state == 2 {
  3722. db := readDb.
  3723. Table("xt_schedule").
  3724. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3725. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3726. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3727. }).
  3728. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3729. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3730. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3731. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3732. 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")
  3733. }).
  3734. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3735. 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")
  3736. }).Where("status = 1 AND user_org_id = ?", orgID)
  3737. if scheduleDate != 0 {
  3738. db = db.Where("schedule_date = ?", scheduleDate)
  3739. }
  3740. err = db.Find(&vms).Error
  3741. } else if execution_state == 0 {
  3742. db := readDb.
  3743. Table("xt_schedule").
  3744. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3745. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3746. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3747. }).
  3748. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3749. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3750. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3751. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3752. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3753. }).
  3754. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3755. 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")
  3756. }).Where("status = 1 AND user_org_id = ?", orgID)
  3757. if scheduleDate != 0 {
  3758. db = db.Where("schedule_date = ?", scheduleDate)
  3759. }
  3760. err = db.Find(&vms).Error
  3761. }
  3762. } else {
  3763. if patient_id > 0 {
  3764. if execution_state == 1 {
  3765. db := readDb.
  3766. Table("xt_schedule").
  3767. Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
  3768. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3769. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3770. }).
  3771. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3772. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3773. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3774. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3775. 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")
  3776. }).
  3777. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3778. 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")
  3779. }).Where("status = 1 AND user_org_id = ?", orgID)
  3780. if scheduleDate != 0 {
  3781. db = db.Where("schedule_date = ?", scheduleDate)
  3782. }
  3783. err = db.Find(&vms).Error
  3784. } else if execution_state == 2 {
  3785. db := readDb.
  3786. Table("xt_schedule").
  3787. Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
  3788. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3789. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3790. }).
  3791. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3792. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3793. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3794. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3795. 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")
  3796. }).
  3797. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3798. 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")
  3799. }).Where("status = 1 AND user_org_id = ?", orgID)
  3800. if scheduleDate != 0 {
  3801. db = db.Where("schedule_date = ?", scheduleDate)
  3802. }
  3803. err = db.Find(&vms).Error
  3804. } else if execution_state == 0 {
  3805. db := readDb.
  3806. Table("xt_schedule").
  3807. Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
  3808. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3809. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3810. }).
  3811. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3812. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3813. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3814. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3815. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3816. }).
  3817. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3818. 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")
  3819. }).Where("status = 1 AND user_org_id = ?", orgID)
  3820. if scheduleDate != 0 {
  3821. db = db.Where("schedule_date = ?", scheduleDate)
  3822. }
  3823. err = db.Find(&vms).Error
  3824. }
  3825. } else {
  3826. if execution_state == 1 {
  3827. db := readDb.
  3828. Table("xt_schedule").
  3829. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3830. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3831. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3832. }).
  3833. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3834. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3835. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3836. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3837. 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")
  3838. }).
  3839. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3840. 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")
  3841. }).Where("status = 1 AND user_org_id = ?", orgID)
  3842. if scheduleDate != 0 {
  3843. db = db.Where("schedule_date = ?", scheduleDate)
  3844. }
  3845. err = db.Find(&vms).Error
  3846. } else if execution_state == 2 {
  3847. fmt.Println("j氯332n323232n323ℹ️33232323232")
  3848. db := readDb.
  3849. Table("xt_schedule").
  3850. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3851. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3852. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3853. }).
  3854. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3855. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3856. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3857. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3858. 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")
  3859. }).
  3860. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3861. 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")
  3862. }).Where("status = 1 AND user_org_id = ?", orgID)
  3863. if scheduleDate != 0 {
  3864. db = db.Where("schedule_date = ?", scheduleDate)
  3865. }
  3866. err = db.Find(&vms).Error
  3867. } else if execution_state == 0 {
  3868. db := readDb.
  3869. Table("xt_schedule").
  3870. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3871. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3872. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3873. }).
  3874. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3875. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3876. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3877. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3878. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3879. }).
  3880. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3881. 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")
  3882. }).Where("status = 1 AND user_org_id = ?", orgID)
  3883. if scheduleDate != 0 {
  3884. db = db.Where("schedule_date = ?", scheduleDate)
  3885. }
  3886. err = db.Find(&vms).Error
  3887. }
  3888. }
  3889. }
  3890. }
  3891. if patientType > 0 {
  3892. if execution_state == 1 {
  3893. db := readDb.
  3894. Table("xt_schedule").
  3895. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3896. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3897. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3898. }).
  3899. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3900. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3901. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3902. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  3903. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3904. 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")
  3905. }).
  3906. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3907. 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")
  3908. }).Where("status = 1 AND user_org_id = ?", orgID)
  3909. if scheduleDate != 0 {
  3910. db = db.Where("schedule_date = ?", scheduleDate)
  3911. }
  3912. err = db.Find(&vms).Error
  3913. } else if execution_state == 2 {
  3914. db := readDb.
  3915. Table("xt_schedule").
  3916. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3917. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3918. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3919. }).
  3920. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3921. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3922. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3923. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  3924. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3925. 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")
  3926. }).
  3927. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3928. 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")
  3929. }).Where("status = 1 AND user_org_id = ?", orgID)
  3930. if scheduleDate != 0 {
  3931. db = db.Where("schedule_date = ?", scheduleDate)
  3932. }
  3933. err = db.Find(&vms).Error
  3934. } else if execution_state == 0 {
  3935. db := readDb.
  3936. Table("xt_schedule").
  3937. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3938. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3939. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3940. }).
  3941. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3942. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3943. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3944. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  3945. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3946. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3947. }).
  3948. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3949. 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")
  3950. }).Where("status = 1 AND user_org_id = ?", orgID)
  3951. if scheduleDate != 0 {
  3952. db = db.Where("schedule_date = ?", scheduleDate)
  3953. }
  3954. err = db.Find(&vms).Error
  3955. }
  3956. }
  3957. return vms, err
  3958. }
  3959. func UpdateStockGoods(good_id int64, record_time int64, patient_id int64, count int64) error {
  3960. prepare := models.DialysisBeforePrepare{}
  3961. var err error
  3962. if count > 0 {
  3963. 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
  3964. }
  3965. if count <= 0 {
  3966. 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
  3967. }
  3968. return err
  3969. }
  3970. func UPdateAutoStockGoods(good_id int64, record_time int64, patient_id int64, count int64) error {
  3971. detail := models.AutomaticReduceDetail{}
  3972. 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
  3973. return err
  3974. }
  3975. func MobileGetDialysisSolutionByModeIdSeven(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  3976. var record models.DialysisSolution
  3977. 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
  3978. if err != nil {
  3979. if err == gorm.ErrRecordNotFound {
  3980. return nil, nil
  3981. } else {
  3982. return nil, err
  3983. }
  3984. }
  3985. return &record, nil
  3986. }
  3987. func MobileGetLastDialysisPrescribeByModeIdSeven(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  3988. var record models.DialysisPrescription
  3989. 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
  3990. if err != nil {
  3991. if err == gorm.ErrRecordNotFound {
  3992. return nil, nil
  3993. } else {
  3994. return nil, err
  3995. }
  3996. }
  3997. return &record, nil
  3998. }
  3999. func MobileGetLastDialysisPrescription(patientID int64, orgID int64) (models.DialysisPrescriptionThrity, error) {
  4000. prescription := models.DialysisPrescriptionThrity{}
  4001. err := readDb.Model(&prescription).Where("patient_id = ? and user_org_id = ? and status = 1 and remark<>''", patientID, orgID).Last(&prescription).Error
  4002. return prescription, err
  4003. }
  4004. func MobileGetSystemDialysisPrescribeByModeIdSeven(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  4005. var record models.SystemPrescription
  4006. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).First(&record).Error
  4007. if err != nil {
  4008. if err == gorm.ErrRecordNotFound {
  4009. return nil, nil
  4010. } else {
  4011. return nil, err
  4012. }
  4013. }
  4014. return &record, nil
  4015. }
  4016. // 透前评估
  4017. func MobileGetPredialysisEvaluationSeven(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
  4018. var record models.PredialysisEvaluation
  4019. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  4020. if err != nil {
  4021. if err == gorm.ErrRecordNotFound {
  4022. return nil, nil
  4023. } else {
  4024. return nil, err
  4025. }
  4026. }
  4027. return &record, nil
  4028. }
  4029. //
  4030. //func MobileGetDialysisGoodsSix(orgID int64, scheduleDate int64) (prepare []*models.DialysisBeforePrepare, err error) {
  4031. //
  4032. // 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
  4033. // return prepare, err
  4034. //}
  4035. func GetMobileAutoReduce(orgID int64, scheduleDate int64) (auto []*models.AutomaticReduceDetail, err error) {
  4036. err = readDb.Where("org_id = ? and status = 1 and record_time = ?", orgID, scheduleDate).Find(&auto).Error
  4037. return auto, err
  4038. }
  4039. func GetRoleList(orgid int64, admin_user_id int64) (models.SgjUserAdminRole, error) {
  4040. role := models.SgjUserAdminRole{}
  4041. err = readUserDb.Where("org_id = ? and admin_user_id = ? and status =1 ", orgid, admin_user_id).Find(&role).Error
  4042. return role, err
  4043. }
  4044. func GetDialysisGood(orgID int64, scheduleDate int64) (auto []*models.AutomaticReduceDetail, err error) {
  4045. err = readDb.Where("org_id = ? and status = 1 and record_time >= ?", orgID, scheduleDate).Group("patient_id").Find(&auto).Error
  4046. return auto, err
  4047. }
  4048. func GetGoodWarehouseOutInfo(orgId int64, patient_id int64, sys_record_time int64) (outifno []*models.WarehouseOutInfoSeven, err error) {
  4049. err = readDb.Where("org_id = ? and patient_id = ? and sys_record_time = ? and status = 1", orgId, patient_id, sys_record_time).Find(&outifno).Error
  4050. return outifno, err
  4051. }
  4052. func GetLastDilysisOrder(orgid int64, patient_id int64, dialysis_date int64) (models.DialysisOrder, error) {
  4053. order := models.DialysisOrder{}
  4054. err = XTReadDB().Where("user_org_id = ? and patient_id = ? and dialysis_date < ? and status= 1", orgid, patient_id, dialysis_date).Last(&order).Error
  4055. return order, err
  4056. }
  4057. func GetFistMonitor(orgid int64, patient_id int64, dialysis_date int64) (models.MonitoringRecord, error) {
  4058. record := models.MonitoringRecord{}
  4059. err := XTReadDB().Where("org_id = ? and patient_id = ? and monitoring_date = ? and status = 1", orgid, patient_id, dialysis_date).Find(&record).Error
  4060. return record, err
  4061. }
  4062. func GetFistMonitorSix(orgid int64, patient_id int64, dialysis_date int64) (record []*models.MonitoringRecord, err error) {
  4063. err = XTReadDB().Where("user_org_id = ? and patient_id = ? and monitoring_date = ? and status = 1", orgid, patient_id, dialysis_date).Find(&record).Error
  4064. return record, err
  4065. }
  4066. 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) {
  4067. var vms []*MScheduleDoctorAdviceVM
  4068. keyword = "%" + keyword + "%"
  4069. adviceWhere := ""
  4070. adviceCondition := []interface{}{}
  4071. if adviceType == 0 {
  4072. if patientType == 0 {
  4073. if patient_id > 0 {
  4074. if execution_state > 0 {
  4075. if cost_type > 0 {
  4076. if len(execution_frequency) > 0 {
  4077. if len(keyword) > 0 {
  4078. 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 ?"
  4079. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4080. } else {
  4081. 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 = ?"
  4082. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4083. }
  4084. } else {
  4085. if len(keyword) > 0 {
  4086. 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 ?"
  4087. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  4088. } else {
  4089. 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 = ?"
  4090. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4091. }
  4092. }
  4093. } else {
  4094. if len(execution_frequency) > 0 {
  4095. if len(keyword) > 0 {
  4096. 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 ?"
  4097. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  4098. } else {
  4099. 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 = ?"
  4100. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4101. }
  4102. } else {
  4103. if len(keyword) > 0 {
  4104. 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 ?"
  4105. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  4106. } else {
  4107. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  4108. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4109. }
  4110. }
  4111. }
  4112. } else {
  4113. if cost_type > 0 {
  4114. if len(execution_frequency) > 0 {
  4115. 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 = ?"
  4116. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4117. } else {
  4118. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and is_settle = ?"
  4119. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4120. }
  4121. } else {
  4122. if len(execution_frequency) > 0 {
  4123. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_frequency = ?"
  4124. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4125. } else {
  4126. if len(keyword) > 0 {
  4127. 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 ?"
  4128. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  4129. } else {
  4130. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
  4131. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4132. }
  4133. }
  4134. }
  4135. }
  4136. } else {
  4137. if execution_state > 0 {
  4138. if cost_type > 0 {
  4139. if len(execution_frequency) > 0 {
  4140. if len(keyword) > 0 {
  4141. 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 ?"
  4142. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  4143. } else {
  4144. 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 = ?"
  4145. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4146. }
  4147. } else {
  4148. if len(keyword) > 0 {
  4149. 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 ?"
  4150. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  4151. } else {
  4152. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and is_settle = ?"
  4153. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4154. }
  4155. }
  4156. } else {
  4157. if len(execution_frequency) > 0 {
  4158. if len(keyword) > 0 {
  4159. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and execution_frequency = ? and advice_name like ?"
  4160. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  4161. } else {
  4162. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and execution_frequency = ?"
  4163. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4164. }
  4165. } else {
  4166. if len(keyword) > 0 {
  4167. 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 ?"
  4168. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  4169. } else {
  4170. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ?"
  4171. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4172. }
  4173. }
  4174. }
  4175. } else {
  4176. if cost_type > 0 {
  4177. if len(execution_frequency) > 0 {
  4178. if len(keyword) > 0 {
  4179. 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 ?"
  4180. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  4181. } else {
  4182. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ? and execution_frequency = ?"
  4183. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  4184. }
  4185. } else {
  4186. if len(keyword) > 0 {
  4187. 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 ?"
  4188. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  4189. } else {
  4190. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ?"
  4191. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4192. }
  4193. }
  4194. } else {
  4195. if len(execution_frequency) > 0 {
  4196. if len(keyword) > 0 {
  4197. 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 ?"
  4198. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  4199. } else {
  4200. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_frequency = ?"
  4201. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  4202. }
  4203. } else {
  4204. if len(keyword) > 0 {
  4205. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and advice_name like ?"
  4206. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  4207. } else {
  4208. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  4209. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4210. }
  4211. }
  4212. }
  4213. }
  4214. }
  4215. } else if patientType == 1 {
  4216. if patient_id > 0 {
  4217. if execution_state > 0 {
  4218. if cost_type > 0 {
  4219. if len(execution_frequency) > 0 {
  4220. if len(keyword) > 0 {
  4221. 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 ?"
  4222. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4223. } else {
  4224. 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 = ?"
  4225. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  4226. }
  4227. } else {
  4228. if len(keyword) > 0 {
  4229. 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 ?"
  4230. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, keyword)
  4231. } else {
  4232. 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 = ?"
  4233. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  4234. }
  4235. }
  4236. } else {
  4237. if len(execution_frequency) > 0 {
  4238. if len(keyword) > 0 {
  4239. 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 ?"
  4240. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  4241. } else {
  4242. 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 = ?"
  4243. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  4244. }
  4245. } else {
  4246. if len(keyword) > 0 {
  4247. 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 ?"
  4248. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, keyword)
  4249. } else {
  4250. 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= ?"
  4251. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  4252. }
  4253. }
  4254. }
  4255. } else {
  4256. if cost_type > 0 {
  4257. if len(execution_frequency) > 0 {
  4258. if len(keyword) > 0 {
  4259. 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 ?"
  4260. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  4261. } else {
  4262. 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 = ?"
  4263. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  4264. }
  4265. } else {
  4266. if len(keyword) > 0 {
  4267. 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 ?"
  4268. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, keyword)
  4269. } else {
  4270. 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=?"
  4271. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  4272. }
  4273. }
  4274. } else {
  4275. if len(execution_frequency) > 0 {
  4276. if len(keyword) > 0 {
  4277. 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 ?"
  4278. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency, keyword)
  4279. } else {
  4280. 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 = ?"
  4281. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  4282. }
  4283. } else {
  4284. if len(keyword) > 0 {
  4285. 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 ?"
  4286. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, keyword)
  4287. } else {
  4288. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
  4289. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  4290. }
  4291. }
  4292. }
  4293. }
  4294. } else {
  4295. if execution_state > 0 {
  4296. if cost_type > 0 {
  4297. if len(execution_frequency) > 0 {
  4298. if len(keyword) > 0 {
  4299. 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 ?"
  4300. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  4301. } else {
  4302. 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 = ?"
  4303. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  4304. }
  4305. } else {
  4306. if len(keyword) > 0 {
  4307. 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 ?"
  4308. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, keyword)
  4309. } else {
  4310. 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=?"
  4311. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  4312. }
  4313. }
  4314. } else {
  4315. if len(execution_frequency) > 0 {
  4316. if len(keyword) > 0 {
  4317. 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 ?"
  4318. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency, keyword)
  4319. } else {
  4320. 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 = ?"
  4321. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  4322. }
  4323. } else {
  4324. if len(keyword) > 0 {
  4325. 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 ?"
  4326. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, keyword)
  4327. } else {
  4328. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  4329. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  4330. }
  4331. }
  4332. }
  4333. } else {
  4334. if cost_type > 0 {
  4335. if len(execution_frequency) > 0 {
  4336. if len(keyword) > 0 {
  4337. 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 ?"
  4338. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency, keyword)
  4339. } else {
  4340. 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 = ?"
  4341. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  4342. }
  4343. } else {
  4344. if len(keyword) > 0 {
  4345. 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 ?"
  4346. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, keyword)
  4347. } else {
  4348. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and is_settle=?"
  4349. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  4350. }
  4351. }
  4352. } else {
  4353. if len(execution_frequency) > 0 {
  4354. if len(keyword) > 0 {
  4355. 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 ?"
  4356. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency, keyword)
  4357. } else {
  4358. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_frequency = ?"
  4359. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  4360. }
  4361. } else {
  4362. if len(keyword) > 0 {
  4363. 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 ?"
  4364. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, keyword)
  4365. } else {
  4366. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  4367. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  4368. }
  4369. }
  4370. }
  4371. }
  4372. }
  4373. } else if patientType == 2 {
  4374. if patient_id > 0 {
  4375. if execution_state > 0 {
  4376. if cost_type > 0 {
  4377. if len(execution_frequency) > 0 {
  4378. if len(keyword) > 0 {
  4379. 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 ?"
  4380. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4381. } else {
  4382. 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 = ?"
  4383. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4384. }
  4385. } else {
  4386. if len(keyword) > 0 {
  4387. 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 ?"
  4388. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  4389. } else {
  4390. 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=?"
  4391. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4392. }
  4393. }
  4394. } else {
  4395. if len(execution_frequency) > 0 {
  4396. if len(keyword) > 0 {
  4397. 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 ?"
  4398. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  4399. } else {
  4400. 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 = ?"
  4401. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4402. }
  4403. } else {
  4404. if len(keyword) > 0 {
  4405. 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 ?"
  4406. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  4407. } else {
  4408. 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 = ?"
  4409. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4410. }
  4411. }
  4412. }
  4413. } else {
  4414. if cost_type > 0 {
  4415. if len(execution_frequency) > 0 {
  4416. if len(keyword) > 0 {
  4417. 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 ?"
  4418. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  4419. } else {
  4420. 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 = ?"
  4421. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4422. }
  4423. } else {
  4424. if len(keyword) > 0 {
  4425. 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 ?"
  4426. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  4427. } else {
  4428. 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=?"
  4429. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4430. }
  4431. }
  4432. } else {
  4433. if len(execution_frequency) > 0 {
  4434. if len(keyword) > 0 {
  4435. 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 ?"
  4436. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  4437. } else {
  4438. 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 = ?"
  4439. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4440. }
  4441. } else {
  4442. if len(keyword) > 0 {
  4443. 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 ?"
  4444. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  4445. } else {
  4446. 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 = ?)"
  4447. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4448. }
  4449. }
  4450. }
  4451. }
  4452. } else {
  4453. if execution_state > 0 {
  4454. if cost_type > 0 {
  4455. if len(execution_frequency) > 0 {
  4456. if len(keyword) > 0 {
  4457. 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 ?"
  4458. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  4459. } else {
  4460. 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 = ?"
  4461. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4462. }
  4463. } else {
  4464. if len(keyword) > 0 {
  4465. 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 ?"
  4466. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  4467. } else {
  4468. 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=?"
  4469. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4470. }
  4471. }
  4472. } else {
  4473. if len(execution_frequency) > 0 {
  4474. if len(keyword) > 0 {
  4475. 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 ?"
  4476. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  4477. } else {
  4478. 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 = ?"
  4479. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4480. }
  4481. } else {
  4482. if len(keyword) > 0 {
  4483. 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 ?"
  4484. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  4485. } else {
  4486. 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 = ?"
  4487. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4488. }
  4489. }
  4490. }
  4491. } else {
  4492. if cost_type > 0 {
  4493. if len(execution_frequency) > 0 {
  4494. if len(keyword) > 0 {
  4495. 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 ?"
  4496. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  4497. } else {
  4498. 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 = ?"
  4499. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  4500. }
  4501. } else {
  4502. if len(keyword) > 0 {
  4503. 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 ?"
  4504. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  4505. } else {
  4506. 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 = ?"
  4507. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4508. }
  4509. }
  4510. } else {
  4511. if len(execution_frequency) > 0 {
  4512. if len(keyword) > 0 {
  4513. 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 ?"
  4514. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  4515. } else {
  4516. 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 = ?"
  4517. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  4518. }
  4519. } else {
  4520. if len(keyword) > 0 {
  4521. 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 ?"
  4522. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  4523. } else {
  4524. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  4525. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4526. }
  4527. }
  4528. }
  4529. }
  4530. }
  4531. }
  4532. } else if adviceType == 1 {
  4533. if patientType == 0 {
  4534. if patient_id > 0 {
  4535. if execution_state > 0 {
  4536. if cost_type > 0 {
  4537. if len(execution_frequency) > 0 {
  4538. if len(keyword) > 0 {
  4539. 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 ?"
  4540. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4541. } else {
  4542. 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 = ?"
  4543. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4544. }
  4545. } else {
  4546. if len(keyword) > 0 {
  4547. 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 ?"
  4548. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  4549. } else {
  4550. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  4551. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4552. }
  4553. }
  4554. } else {
  4555. if len(execution_frequency) > 0 {
  4556. if len(keyword) > 0 {
  4557. 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 ?"
  4558. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  4559. } else {
  4560. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  4561. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4562. }
  4563. } else {
  4564. if len(keyword) > 0 {
  4565. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  4566. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  4567. } else {
  4568. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ?"
  4569. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4570. }
  4571. }
  4572. }
  4573. } else {
  4574. if cost_type > 0 {
  4575. if len(execution_frequency) > 0 {
  4576. if len(keyword) > 0 {
  4577. 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 ?"
  4578. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  4579. } else {
  4580. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  4581. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4582. }
  4583. } else {
  4584. if len(keyword) > 0 {
  4585. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? and advice_name like ? "
  4586. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  4587. } else {
  4588. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? "
  4589. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4590. }
  4591. }
  4592. } else {
  4593. if len(execution_frequency) > 0 {
  4594. if len(keyword) > 0 {
  4595. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and advice_name like ?"
  4596. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  4597. } else {
  4598. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
  4599. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4600. }
  4601. }
  4602. }
  4603. }
  4604. } else {
  4605. if execution_state > 0 {
  4606. if cost_type > 0 {
  4607. if len(execution_frequency) > 0 {
  4608. if len(keyword) > 0 {
  4609. 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 ?"
  4610. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  4611. } else {
  4612. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  4613. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4614. }
  4615. } else {
  4616. if len(keyword) > 0 {
  4617. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  4618. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  4619. } else {
  4620. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ?"
  4621. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4622. }
  4623. }
  4624. } else {
  4625. if len(execution_frequency) > 0 {
  4626. if len(keyword) > 0 {
  4627. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  4628. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  4629. } else {
  4630. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and execution_frequency = ?"
  4631. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4632. }
  4633. } else {
  4634. if len(keyword) > 0 {
  4635. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and advice_name like ?"
  4636. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  4637. } else {
  4638. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ?"
  4639. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4640. }
  4641. }
  4642. }
  4643. } else {
  4644. if cost_type > 0 {
  4645. if len(keyword) > 0 {
  4646. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = ? and advice_name like ?"
  4647. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  4648. } else {
  4649. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = ? "
  4650. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4651. }
  4652. } else {
  4653. if len(keyword) > 0 {
  4654. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and advice_name like ?"
  4655. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  4656. } else {
  4657. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  4658. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4659. }
  4660. }
  4661. }
  4662. }
  4663. } else if patientType == 1 {
  4664. if patient_id > 0 {
  4665. if execution_state > 0 {
  4666. if cost_type > 0 {
  4667. if len(execution_frequency) > 0 {
  4668. if len(keyword) > 0 {
  4669. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  4670. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4671. } else {
  4672. 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 = ?"
  4673. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  4674. }
  4675. } else {
  4676. if len(keyword) > 0 {
  4677. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  4678. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, keyword)
  4679. } else {
  4680. 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 = ?"
  4681. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  4682. }
  4683. }
  4684. } else {
  4685. if len(execution_frequency) > 0 {
  4686. if len(keyword) > 0 {
  4687. 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 ?"
  4688. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  4689. } else {
  4690. 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 = ?"
  4691. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  4692. }
  4693. } else {
  4694. if len(keyword) > 0 {
  4695. 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 ?"
  4696. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, keyword)
  4697. } else {
  4698. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  4699. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  4700. }
  4701. }
  4702. }
  4703. } else {
  4704. if cost_type > 0 {
  4705. if len(execution_frequency) > 0 {
  4706. if len(keyword) > 0 {
  4707. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and is_settle = ?and execution_frequency = ? and advice_name like ?"
  4708. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  4709. } else {
  4710. 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 = ?"
  4711. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  4712. }
  4713. } else {
  4714. if len(keyword) > 0 {
  4715. 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 ?"
  4716. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, keyword)
  4717. } else {
  4718. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  4719. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  4720. }
  4721. }
  4722. } else {
  4723. if len(execution_frequency) > 0 {
  4724. if len(keyword) > 0 {
  4725. 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 ?"
  4726. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency, keyword)
  4727. } else {
  4728. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  4729. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  4730. }
  4731. } else {
  4732. if len(keyword) > 0 {
  4733. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and advice_name like ?"
  4734. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, keyword)
  4735. } else {
  4736. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
  4737. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  4738. }
  4739. }
  4740. }
  4741. }
  4742. } else {
  4743. if execution_state > 0 {
  4744. if cost_type > 0 {
  4745. if len(execution_frequency) > 0 {
  4746. if len(keyword) > 0 {
  4747. 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 ?"
  4748. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  4749. } else {
  4750. 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 = ?"
  4751. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  4752. }
  4753. } else {
  4754. if len(keyword) > 0 {
  4755. 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 ?"
  4756. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, keyword)
  4757. } else {
  4758. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=? and is_settle = ?"
  4759. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  4760. }
  4761. }
  4762. } else {
  4763. if len(execution_frequency) > 0 {
  4764. if len(keyword) > 0 {
  4765. 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 ?"
  4766. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency, keyword)
  4767. } else {
  4768. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?and execution_frequency = ?"
  4769. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  4770. }
  4771. } else {
  4772. if len(keyword) > 0 {
  4773. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=? and advice_name like ?"
  4774. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, keyword)
  4775. } else {
  4776. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?"
  4777. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  4778. }
  4779. }
  4780. }
  4781. } else {
  4782. if cost_type > 0 {
  4783. if len(execution_frequency) > 0 {
  4784. if len(keyword) > 0 {
  4785. 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 ?"
  4786. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency, keyword)
  4787. } else {
  4788. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  4789. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  4790. }
  4791. } else {
  4792. if len(keyword) > 0 {
  4793. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? and advice_name like ?"
  4794. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, keyword)
  4795. } else {
  4796. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? "
  4797. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  4798. }
  4799. }
  4800. } else {
  4801. if len(execution_frequency) > 0 {
  4802. if len(keyword) > 0 {
  4803. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_frequency = ? and advice_name like ?"
  4804. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency, keyword)
  4805. } else {
  4806. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_frequency = ?"
  4807. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  4808. }
  4809. } else {
  4810. if len(keyword) > 0 {
  4811. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and advice_name like ?"
  4812. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, keyword)
  4813. } else {
  4814. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  4815. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  4816. }
  4817. }
  4818. }
  4819. }
  4820. }
  4821. } else if patientType == 2 {
  4822. if patient_id > 0 {
  4823. if execution_state > 0 {
  4824. if cost_type > 0 {
  4825. if len(execution_frequency) > 0 {
  4826. if len(keyword) > 0 {
  4827. 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 ?"
  4828. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4829. } else {
  4830. 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 = ?"
  4831. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4832. }
  4833. } else {
  4834. if len(keyword) > 0 {
  4835. 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 ?"
  4836. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  4837. } else {
  4838. 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 = ?"
  4839. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4840. }
  4841. }
  4842. } else {
  4843. if len(execution_frequency) > 0 {
  4844. if len(keyword) > 0 {
  4845. 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 ?"
  4846. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  4847. } else {
  4848. 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 = ?"
  4849. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4850. }
  4851. } else {
  4852. if len(keyword) > 0 {
  4853. 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 ?"
  4854. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  4855. } else {
  4856. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  4857. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4858. }
  4859. }
  4860. }
  4861. } else {
  4862. if cost_type > 0 {
  4863. if len(execution_frequency) > 0 {
  4864. if len(keyword) > 0 {
  4865. 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 ?"
  4866. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  4867. } else {
  4868. 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 = ?"
  4869. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4870. }
  4871. } else {
  4872. if len(keyword) > 0 {
  4873. 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 ?"
  4874. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  4875. } else {
  4876. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  4877. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4878. }
  4879. }
  4880. } else {
  4881. if len(execution_frequency) > 0 {
  4882. if len(keyword) > 0 {
  4883. 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 ?"
  4884. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  4885. } else {
  4886. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_frequency = ?"
  4887. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4888. }
  4889. } else {
  4890. if len(keyword) > 0 {
  4891. 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 ?"
  4892. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  4893. } else {
  4894. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
  4895. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4896. }
  4897. }
  4898. }
  4899. }
  4900. } else {
  4901. if execution_state > 0 {
  4902. if cost_type > 0 {
  4903. if len(execution_frequency) > 0 {
  4904. if len(keyword) > 0 {
  4905. 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 ?"
  4906. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  4907. } else {
  4908. 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 = ?"
  4909. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4910. }
  4911. } else {
  4912. if len(keyword) > 0 {
  4913. 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 ?"
  4914. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  4915. } else {
  4916. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  4917. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4918. }
  4919. }
  4920. } else {
  4921. if len(execution_frequency) > 0 {
  4922. if len(keyword) > 0 {
  4923. 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 ?"
  4924. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  4925. } else {
  4926. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and execution_frequency = ?"
  4927. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4928. }
  4929. } else {
  4930. if len(keyword) > 0 {
  4931. 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 ?"
  4932. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  4933. } else {
  4934. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ?"
  4935. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4936. }
  4937. }
  4938. }
  4939. } else {
  4940. if cost_type > 0 {
  4941. if len(execution_frequency) > 0 {
  4942. if len(keyword) > 0 {
  4943. 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 ?"
  4944. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  4945. } else {
  4946. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  4947. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  4948. }
  4949. } else {
  4950. if len(keyword) > 0 {
  4951. 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 ?"
  4952. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  4953. } else {
  4954. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ?"
  4955. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4956. }
  4957. }
  4958. } else {
  4959. if len(execution_frequency) > 0 {
  4960. if len(keyword) > 0 {
  4961. 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 ?"
  4962. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  4963. } else {
  4964. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_frequency = ?"
  4965. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  4966. }
  4967. } else {
  4968. if len(keyword) > 0 {
  4969. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and advice_name like ?"
  4970. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  4971. } else {
  4972. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  4973. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4974. }
  4975. }
  4976. }
  4977. }
  4978. }
  4979. }
  4980. } else if adviceType == 3 {
  4981. if patientType == 0 {
  4982. if patient_id > 0 {
  4983. if execution_state > 0 {
  4984. if cost_type > 0 {
  4985. if len(execution_frequency) > 0 {
  4986. if len(keyword) > 0 {
  4987. 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 ?"
  4988. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4989. } else {
  4990. 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 =?"
  4991. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4992. }
  4993. } else {
  4994. if len(keyword) > 0 {
  4995. 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 ?"
  4996. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  4997. } else {
  4998. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  4999. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5000. }
  5001. }
  5002. } else {
  5003. if len(execution_frequency) > 0 {
  5004. if len(keyword) > 0 {
  5005. 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 ?"
  5006. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  5007. } else {
  5008. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency =?"
  5009. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  5010. }
  5011. } else {
  5012. if len(keyword) > 0 {
  5013. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  5014. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  5015. } else {
  5016. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ?"
  5017. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5018. }
  5019. }
  5020. }
  5021. } else {
  5022. if cost_type > 0 {
  5023. if len(execution_frequency) > 0 {
  5024. if len(keyword) > 0 {
  5025. 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 ?"
  5026. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  5027. } else {
  5028. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency =?"
  5029. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  5030. }
  5031. } else {
  5032. if len(keyword) > 0 {
  5033. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  5034. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  5035. } else {
  5036. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? "
  5037. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5038. }
  5039. }
  5040. } else {
  5041. if len(execution_frequency) > 0 {
  5042. if len(keyword) > 0 {
  5043. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_frequency =? and advice_name like ?"
  5044. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  5045. } else {
  5046. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_frequency =?"
  5047. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  5048. }
  5049. } else {
  5050. if len(keyword) > 0 {
  5051. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and advice_name like ?"
  5052. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  5053. } else {
  5054. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? "
  5055. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5056. }
  5057. }
  5058. }
  5059. }
  5060. } else {
  5061. if execution_state > 0 {
  5062. if cost_type > 0 {
  5063. if len(execution_frequency) > 0 {
  5064. if len(keyword) > 0 {
  5065. 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 ?"
  5066. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  5067. } else {
  5068. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ? and execution_frequency =?"
  5069. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  5070. }
  5071. } else {
  5072. if len(keyword) > 0 {
  5073. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ? and advice_name like ?"
  5074. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  5075. } else {
  5076. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ?"
  5077. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5078. }
  5079. }
  5080. } else {
  5081. if len(execution_frequency) > 0 {
  5082. if len(keyword) > 0 {
  5083. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and execution_frequency =? and advice_name like ?"
  5084. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  5085. } else {
  5086. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and execution_frequency =?"
  5087. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  5088. }
  5089. } else {
  5090. if len(keyword) > 0 {
  5091. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and advice_name like ?"
  5092. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  5093. } else {
  5094. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? "
  5095. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5096. }
  5097. }
  5098. }
  5099. } else {
  5100. if cost_type > 0 {
  5101. if len(execution_frequency) > 0 {
  5102. if len(keyword) > 0 {
  5103. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? and execution_frequency =? and advice_name like ?"
  5104. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  5105. } else {
  5106. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? and execution_frequency =?"
  5107. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  5108. }
  5109. } else {
  5110. if len(keyword) > 0 {
  5111. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? and advice_name like ?"
  5112. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  5113. } else {
  5114. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? "
  5115. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5116. }
  5117. }
  5118. } else {
  5119. if len(execution_frequency) > 0 {
  5120. if len(keyword) > 0 {
  5121. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_frequency =? and advice_name like ?"
  5122. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  5123. } else {
  5124. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_frequency =?"
  5125. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  5126. }
  5127. } else {
  5128. if len(keyword) > 0 {
  5129. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and advice_name like ?"
  5130. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  5131. } else {
  5132. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  5133. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5134. }
  5135. }
  5136. }
  5137. }
  5138. }
  5139. } else if patientType == 1 {
  5140. if patient_id > 0 {
  5141. if execution_state > 0 {
  5142. if cost_type > 0 {
  5143. if len(execution_frequency) > 0 {
  5144. if len(keyword) > 0 {
  5145. 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 ?"
  5146. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5147. } else {
  5148. 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 = ?"
  5149. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  5150. }
  5151. } else {
  5152. if len(keyword) > 0 {
  5153. 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 ?"
  5154. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, keyword)
  5155. } else {
  5156. 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 = ?"
  5157. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  5158. }
  5159. }
  5160. } else {
  5161. if len(execution_frequency) > 0 {
  5162. if len(keyword) > 0 {
  5163. 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 ?"
  5164. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  5165. } else {
  5166. 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 = ?"
  5167. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  5168. }
  5169. } else {
  5170. if len(keyword) > 0 {
  5171. 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 ?"
  5172. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, keyword)
  5173. } else {
  5174. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  5175. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  5176. }
  5177. }
  5178. }
  5179. } else {
  5180. if cost_type > 0 {
  5181. if len(execution_frequency) > 0 {
  5182. if len(keyword) > 0 {
  5183. 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 ?"
  5184. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  5185. } else {
  5186. 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 = ?"
  5187. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  5188. }
  5189. } else {
  5190. if len(keyword) > 0 {
  5191. 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 ?"
  5192. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, keyword)
  5193. } else {
  5194. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  5195. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  5196. }
  5197. }
  5198. } else {
  5199. if len(execution_frequency) > 0 {
  5200. if len(keyword) > 0 {
  5201. 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 ?"
  5202. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency, keyword)
  5203. } else {
  5204. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  5205. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  5206. }
  5207. } else {
  5208. if len(keyword) > 0 {
  5209. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and advice_name like ?"
  5210. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, keyword)
  5211. } else {
  5212. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
  5213. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  5214. }
  5215. }
  5216. }
  5217. }
  5218. } else {
  5219. if execution_state > 0 {
  5220. if cost_type > 0 {
  5221. if len(execution_frequency) > 0 {
  5222. if len(keyword) > 0 {
  5223. 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 ?"
  5224. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  5225. } else {
  5226. 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 = ?"
  5227. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  5228. }
  5229. } else {
  5230. if len(keyword) > 0 {
  5231. 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 ?"
  5232. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, keyword)
  5233. } else {
  5234. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? and is_settle = ?"
  5235. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  5236. }
  5237. }
  5238. } else {
  5239. if len(execution_frequency) > 0 {
  5240. if len(keyword) > 0 {
  5241. 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 ? "
  5242. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency, keyword)
  5243. } else {
  5244. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =?and execution_frequency = ? "
  5245. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  5246. }
  5247. } else {
  5248. if len(keyword) > 0 {
  5249. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? and advice_name like ?"
  5250. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, keyword)
  5251. } else {
  5252. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? "
  5253. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  5254. }
  5255. }
  5256. }
  5257. } else {
  5258. if cost_type > 0 {
  5259. if len(execution_frequency) > 0 {
  5260. if len(keyword) > 0 {
  5261. 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 ?"
  5262. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency, keyword)
  5263. } else {
  5264. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  5265. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  5266. }
  5267. } else {
  5268. if len(keyword) > 0 {
  5269. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ? and advice_name like ?"
  5270. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, keyword)
  5271. } else {
  5272. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ?"
  5273. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  5274. }
  5275. }
  5276. } else {
  5277. if len(execution_frequency) > 0 {
  5278. if len(keyword) > 0 {
  5279. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_frequency = ? and advice_name like ?"
  5280. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency, keyword)
  5281. } else {
  5282. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_frequency = ?"
  5283. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  5284. }
  5285. } else {
  5286. if len(keyword) > 0 {
  5287. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and advice_name like ?"
  5288. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, keyword)
  5289. } else {
  5290. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  5291. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  5292. }
  5293. }
  5294. }
  5295. }
  5296. }
  5297. } else if patientType == 2 {
  5298. if patient_id > 0 {
  5299. if execution_state > 0 {
  5300. if cost_type > 0 {
  5301. if len(execution_frequency) > 0 {
  5302. if len(keyword) > 0 {
  5303. 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 ?"
  5304. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5305. } else {
  5306. 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 = ?"
  5307. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  5308. }
  5309. } else {
  5310. if len(keyword) > 0 {
  5311. 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 ?"
  5312. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  5313. } else {
  5314. 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 = ?"
  5315. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5316. }
  5317. }
  5318. } else {
  5319. if len(execution_frequency) > 0 {
  5320. if len(keyword) > 0 {
  5321. 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 ?"
  5322. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  5323. } else {
  5324. 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 = ?"
  5325. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  5326. }
  5327. } else {
  5328. if len(keyword) > 0 {
  5329. 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 ?"
  5330. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  5331. } else {
  5332. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  5333. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5334. }
  5335. }
  5336. }
  5337. } else {
  5338. if cost_type > 0 {
  5339. if len(execution_frequency) > 0 {
  5340. if len(keyword) > 0 {
  5341. 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 ?"
  5342. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  5343. } else {
  5344. 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 = ?"
  5345. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  5346. }
  5347. } else {
  5348. if len(keyword) > 0 {
  5349. 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 ?"
  5350. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  5351. } else {
  5352. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  5353. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5354. }
  5355. }
  5356. } else {
  5357. if len(execution_frequency) > 0 {
  5358. if len(keyword) > 0 {
  5359. 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 ?"
  5360. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  5361. } else {
  5362. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_frequency = ?"
  5363. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  5364. }
  5365. } else {
  5366. if len(keyword) > 0 {
  5367. 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 ?"
  5368. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  5369. } else {
  5370. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ?"
  5371. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5372. }
  5373. }
  5374. }
  5375. }
  5376. } else {
  5377. if execution_state > 0 {
  5378. if cost_type > 0 {
  5379. if len(execution_frequency) > 0 {
  5380. if len(keyword) > 0 {
  5381. 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 ?"
  5382. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  5383. } else {
  5384. 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 = ?"
  5385. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  5386. }
  5387. } else {
  5388. if len(keyword) > 0 {
  5389. 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 ?"
  5390. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  5391. } else {
  5392. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and is_settle = ?"
  5393. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5394. }
  5395. }
  5396. } else {
  5397. if len(execution_frequency) > 0 {
  5398. if len(keyword) > 0 {
  5399. 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 ?"
  5400. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  5401. } else {
  5402. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and execution_frequency = ?"
  5403. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  5404. }
  5405. } else {
  5406. if len(keyword) > 0 {
  5407. 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 ?"
  5408. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  5409. } else {
  5410. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ?"
  5411. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5412. }
  5413. }
  5414. }
  5415. } else {
  5416. if cost_type > 0 {
  5417. if len(execution_frequency) > 0 {
  5418. if len(keyword) > 0 {
  5419. 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 ?"
  5420. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  5421. } else {
  5422. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  5423. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  5424. }
  5425. } else {
  5426. if len(keyword) > 0 {
  5427. 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 ?"
  5428. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  5429. } else {
  5430. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ?"
  5431. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5432. }
  5433. }
  5434. } else {
  5435. if len(execution_frequency) > 0 {
  5436. if len(keyword) > 0 {
  5437. 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 ?"
  5438. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  5439. } else {
  5440. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_frequency = ?"
  5441. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  5442. }
  5443. } else {
  5444. if len(keyword) > 0 {
  5445. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and advice_name like ?"
  5446. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  5447. } else {
  5448. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  5449. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5450. }
  5451. }
  5452. }
  5453. }
  5454. }
  5455. }
  5456. } else if adviceType == 2 && len(deliverWay) > 0 {
  5457. if patientType == 0 {
  5458. if patient_id > 0 {
  5459. if execution_state > 0 {
  5460. if cost_type > 0 {
  5461. if len(execution_frequency) > 0 {
  5462. if len(keyword) > 0 {
  5463. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5464. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5465. } else {
  5466. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5467. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency)
  5468. }
  5469. } else {
  5470. if len(keyword) > 0 {
  5471. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5472. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, keyword)
  5473. } else {
  5474. 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 = ?"
  5475. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  5476. }
  5477. }
  5478. } else {
  5479. if len(execution_frequency) > 0 {
  5480. if len(keyword) > 0 {
  5481. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5482. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency, keyword)
  5483. } else {
  5484. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  5485. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency)
  5486. }
  5487. } else {
  5488. if len(keyword) > 0 {
  5489. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  5490. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, keyword)
  5491. } else {
  5492. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  5493. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  5494. }
  5495. }
  5496. }
  5497. } else {
  5498. if cost_type > 0 {
  5499. if len(execution_frequency) > 0 {
  5500. if len(keyword) > 0 {
  5501. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5502. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency, keyword)
  5503. } else {
  5504. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  5505. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency)
  5506. }
  5507. } else {
  5508. if len(keyword) > 0 {
  5509. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  5510. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, keyword)
  5511. } else {
  5512. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and is_settle = ?"
  5513. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  5514. }
  5515. }
  5516. } else {
  5517. if len(execution_frequency) > 0 {
  5518. if len(keyword) > 0 {
  5519. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  5520. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency, keyword)
  5521. } else {
  5522. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_frequency = ?"
  5523. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency)
  5524. }
  5525. } else {
  5526. if len(keyword) > 0 {
  5527. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and advice_name like ?"
  5528. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, keyword)
  5529. } else {
  5530. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ?"
  5531. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  5532. }
  5533. }
  5534. }
  5535. }
  5536. } else {
  5537. if execution_state > 0 {
  5538. if cost_type > 0 {
  5539. if len(execution_frequency) > 0 {
  5540. if len(keyword) > 0 {
  5541. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5542. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency, keyword)
  5543. } else {
  5544. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5545. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency)
  5546. }
  5547. } else {
  5548. if len(keyword) > 0 {
  5549. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5550. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, keyword)
  5551. } else {
  5552. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and is_settle = ?"
  5553. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  5554. }
  5555. }
  5556. } else {
  5557. if len(execution_frequency) > 0 {
  5558. if len(keyword) > 0 {
  5559. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5560. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency, keyword)
  5561. } else {
  5562. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and execution_frequency = ?"
  5563. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency)
  5564. }
  5565. } else {
  5566. if len(keyword) > 0 {
  5567. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and advice_name like ?"
  5568. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, keyword)
  5569. } else {
  5570. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ?"
  5571. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  5572. }
  5573. }
  5574. }
  5575. } else {
  5576. if cost_type > 0 {
  5577. if len(execution_frequency) > 0 {
  5578. if len(keyword) > 0 {
  5579. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5580. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, execution_frequency, keyword)
  5581. } else {
  5582. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and is_settle = ? and execution_frequency = ?"
  5583. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, execution_frequency)
  5584. }
  5585. } else {
  5586. if len(keyword) > 0 {
  5587. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and is_settle = ? and advice_name like ?"
  5588. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, keyword)
  5589. } else {
  5590. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and is_settle = ?"
  5591. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  5592. }
  5593. }
  5594. } else {
  5595. if len(execution_frequency) > 0 {
  5596. if len(keyword) > 0 {
  5597. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_frequency = ? and advice_name like ?"
  5598. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_frequency, keyword)
  5599. } else {
  5600. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_frequency = ?"
  5601. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_frequency)
  5602. }
  5603. } else {
  5604. if len(keyword) > 0 {
  5605. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and advice_name like ?"
  5606. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, keyword)
  5607. } else {
  5608. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  5609. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  5610. }
  5611. }
  5612. }
  5613. }
  5614. }
  5615. } else if patientType == 1 {
  5616. if patient_id > 0 {
  5617. if execution_state > 0 {
  5618. if cost_type > 0 {
  5619. if len(execution_frequency) > 0 {
  5620. if len(keyword) > 0 {
  5621. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5622. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5623. } else {
  5624. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5625. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type, execution_frequency)
  5626. }
  5627. } else {
  5628. if len(keyword) > 0 {
  5629. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5630. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type, keyword)
  5631. } else {
  5632. 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 = ?"
  5633. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type)
  5634. }
  5635. }
  5636. } else {
  5637. if len(execution_frequency) > 0 {
  5638. if len(keyword) > 0 {
  5639. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5640. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, execution_frequency, keyword)
  5641. } else {
  5642. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  5643. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, execution_frequency)
  5644. }
  5645. } else {
  5646. if len(keyword) > 0 {
  5647. 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 advice_name like ?"
  5648. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, keyword)
  5649. } else {
  5650. 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 = ?"
  5651. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state)
  5652. }
  5653. }
  5654. }
  5655. } else {
  5656. if cost_type > 0 {
  5657. if len(execution_frequency) > 0 {
  5658. if len(keyword) > 0 {
  5659. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5660. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type, execution_frequency, keyword)
  5661. } else {
  5662. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  5663. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type, execution_frequency)
  5664. }
  5665. } else {
  5666. if len(keyword) > 0 {
  5667. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  5668. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type, keyword)
  5669. } else {
  5670. 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 = ?"
  5671. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type)
  5672. }
  5673. }
  5674. } else {
  5675. if len(execution_frequency) > 0 {
  5676. if len(keyword) > 0 {
  5677. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  5678. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_frequency, keyword)
  5679. } else {
  5680. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_frequency = ?"
  5681. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_frequency)
  5682. }
  5683. } else {
  5684. if len(keyword) > 0 {
  5685. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and avice_name like ?"
  5686. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, keyword)
  5687. } else {
  5688. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ?"
  5689. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
  5690. }
  5691. }
  5692. }
  5693. }
  5694. } else {
  5695. if execution_state > 0 {
  5696. if cost_type > 0 {
  5697. if len(execution_frequency) > 0 {
  5698. if len(keyword) > 0 {
  5699. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5700. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type, execution_frequency, keyword)
  5701. } else {
  5702. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5703. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type, execution_frequency)
  5704. }
  5705. } else {
  5706. if len(keyword) > 0 {
  5707. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5708. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type, keyword)
  5709. } else {
  5710. 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 = ?"
  5711. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type)
  5712. }
  5713. }
  5714. } else {
  5715. if len(execution_frequency) > 0 {
  5716. if len(keyword) > 0 {
  5717. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5718. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, execution_frequency, keyword)
  5719. } else {
  5720. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ? and execution_frequency = ?"
  5721. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, execution_frequency)
  5722. }
  5723. } else {
  5724. if len(keyword) > 0 {
  5725. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ? and advice_name like ?"
  5726. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, keyword)
  5727. } else {
  5728. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ?"
  5729. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state)
  5730. }
  5731. }
  5732. }
  5733. } else {
  5734. if cost_type > 0 {
  5735. if len(execution_frequency) > 0 {
  5736. if len(keyword) > 0 {
  5737. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5738. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type, execution_frequency, keyword)
  5739. } else {
  5740. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and is_settle = ? and execution_frequency = ?"
  5741. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type, execution_frequency)
  5742. }
  5743. } else {
  5744. if len(keyword) > 0 {
  5745. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and is_settle = ? and advice_name like ?"
  5746. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type, keyword)
  5747. } else {
  5748. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and is_settle = ?"
  5749. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type)
  5750. }
  5751. }
  5752. } else {
  5753. if len(execution_frequency) > 0 {
  5754. if len(keyword) > 0 {
  5755. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_frequency = ? and advic_name like ?"
  5756. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_frequency, keyword)
  5757. } else {
  5758. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_frequency = ?"
  5759. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_frequency)
  5760. }
  5761. } else {
  5762. if len(keyword) > 0 {
  5763. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and advice_name like ?"
  5764. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, keyword)
  5765. } else {
  5766. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  5767. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  5768. }
  5769. }
  5770. }
  5771. }
  5772. }
  5773. } else if patientType == 2 {
  5774. if patient_id > 0 {
  5775. if execution_state > 0 {
  5776. if cost_type > 0 {
  5777. if len(execution_frequency) > 0 {
  5778. if len(keyword) > 0 {
  5779. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5780. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5781. } else {
  5782. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5783. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency)
  5784. }
  5785. } else {
  5786. if len(keyword) > 0 {
  5787. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5788. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, keyword)
  5789. } else {
  5790. 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 = ?"
  5791. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  5792. }
  5793. }
  5794. } else {
  5795. if len(execution_frequency) > 0 {
  5796. if len(keyword) > 0 {
  5797. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5798. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency, keyword)
  5799. } else {
  5800. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  5801. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency)
  5802. }
  5803. } else {
  5804. if len(keyword) > 0 {
  5805. 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 advice_name like ?"
  5806. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, keyword)
  5807. } else {
  5808. 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 = ?"
  5809. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  5810. }
  5811. }
  5812. }
  5813. } else {
  5814. if cost_type > 0 {
  5815. if len(execution_frequency) > 0 {
  5816. if len(keyword) > 0 {
  5817. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5818. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency, keyword)
  5819. } else {
  5820. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  5821. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency)
  5822. }
  5823. } else {
  5824. if len(keyword) > 0 {
  5825. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  5826. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, keyword)
  5827. } else {
  5828. 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 = ?"
  5829. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  5830. }
  5831. }
  5832. } else {
  5833. if len(execution_frequency) > 0 {
  5834. if len(keyword) > 0 {
  5835. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  5836. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency, keyword)
  5837. } else {
  5838. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_frequency = ?"
  5839. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency)
  5840. }
  5841. } else {
  5842. if len(keyword) > 0 {
  5843. 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 advice_name like ?"
  5844. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, keyword)
  5845. } else {
  5846. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ?"
  5847. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  5848. }
  5849. }
  5850. }
  5851. }
  5852. } else {
  5853. if execution_state > 0 {
  5854. if cost_type > 0 {
  5855. if len(execution_frequency) > 0 {
  5856. if len(keyword) > 0 {
  5857. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5858. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency, keyword)
  5859. } else {
  5860. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5861. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency)
  5862. }
  5863. } else {
  5864. if len(keyword) > 0 {
  5865. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5866. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, keyword)
  5867. } else {
  5868. 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 = ?"
  5869. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  5870. }
  5871. }
  5872. } else {
  5873. if len(execution_frequency) > 0 {
  5874. if len(keyword) > 0 {
  5875. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5876. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency, keyword)
  5877. } else {
  5878. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ? and execution_frequency = ?"
  5879. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency)
  5880. }
  5881. } else {
  5882. if len(keyword) > 0 {
  5883. 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 advice_name like ?"
  5884. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, keyword)
  5885. } else {
  5886. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ?"
  5887. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  5888. }
  5889. }
  5890. }
  5891. } else {
  5892. if cost_type > 0 {
  5893. if len(execution_frequency) > 0 {
  5894. if len(keyword) > 0 {
  5895. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and is_settle = ? and advice_name like ?"
  5896. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, keyword)
  5897. } else {
  5898. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and is_settle = ?"
  5899. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  5900. }
  5901. } else {
  5902. if len(keyword) > 0 {
  5903. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and is_settle = ? and advice_name like ?"
  5904. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, keyword)
  5905. } else {
  5906. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and is_settle = ?"
  5907. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  5908. }
  5909. }
  5910. } else {
  5911. if len(keyword) > 0 {
  5912. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and advice_name like ?"
  5913. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, keyword)
  5914. } else {
  5915. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  5916. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  5917. }
  5918. }
  5919. }
  5920. }
  5921. }
  5922. } else if adviceType == 2 && len(deliverWay) <= 0 {
  5923. if patientType == 0 {
  5924. if patient_id > 0 {
  5925. if execution_state > 0 {
  5926. if cost_type > 0 {
  5927. if len(execution_frequency) > 0 {
  5928. if len(keyword) > 0 {
  5929. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5930. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5931. } else {
  5932. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5933. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  5934. }
  5935. } else {
  5936. if len(keyword) > 0 {
  5937. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5938. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  5939. } else {
  5940. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  5941. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5942. }
  5943. }
  5944. } else {
  5945. if len(execution_frequency) > 0 {
  5946. if len(keyword) > 0 {
  5947. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5948. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  5949. } else {
  5950. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  5951. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  5952. }
  5953. } else {
  5954. if len(keyword) > 0 {
  5955. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  5956. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  5957. } else {
  5958. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ?"
  5959. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5960. }
  5961. }
  5962. }
  5963. } else {
  5964. if cost_type > 0 {
  5965. if len(execution_frequency) > 0 {
  5966. if len(keyword) > 0 {
  5967. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5968. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  5969. } else {
  5970. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  5971. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  5972. }
  5973. } else {
  5974. if len(keyword) > 0 {
  5975. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  5976. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  5977. } else {
  5978. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and is_settle = ?"
  5979. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5980. }
  5981. }
  5982. } else {
  5983. if len(execution_frequency) > 0 {
  5984. if len(keyword) > 0 {
  5985. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  5986. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  5987. } else {
  5988. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_frequency = ?"
  5989. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  5990. }
  5991. } else {
  5992. if len(keyword) > 0 {
  5993. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and advice_name like ?"
  5994. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  5995. } else {
  5996. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ?"
  5997. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5998. }
  5999. }
  6000. }
  6001. }
  6002. } else {
  6003. if execution_state > 0 {
  6004. if cost_type > 0 {
  6005. if len(execution_frequency) > 0 {
  6006. if len(keyword) > 0 {
  6007. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6008. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  6009. } else {
  6010. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  6011. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  6012. }
  6013. } else {
  6014. if len(keyword) > 0 {
  6015. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  6016. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  6017. } else {
  6018. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ? and is_settle = ?"
  6019. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6020. }
  6021. }
  6022. } else {
  6023. if len(execution_frequency) > 0 {
  6024. if len(keyword) > 0 {
  6025. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?and execution_frequency = ? and advice_name like ?"
  6026. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  6027. } else {
  6028. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?and execution_frequency = ?"
  6029. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  6030. }
  6031. } else {
  6032. if len(keyword) > 0 {
  6033. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ? and advice_name like ?"
  6034. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  6035. } else {
  6036. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?"
  6037. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6038. }
  6039. }
  6040. }
  6041. } else {
  6042. if cost_type > 0 {
  6043. if len(execution_frequency) > 0 {
  6044. if len(keyword) > 0 {
  6045. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6046. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  6047. } else {
  6048. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and is_settle = ? and execution_frequency = ?"
  6049. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  6050. }
  6051. }
  6052. } else {
  6053. if len(execution_frequency) > 0 {
  6054. if len(keyword) > 0 {
  6055. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_frequency = ? and advice_name like ?"
  6056. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  6057. } else {
  6058. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_frequency = ?"
  6059. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  6060. }
  6061. } else {
  6062. if len(keyword) > 0 {
  6063. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and advice_name like ?"
  6064. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  6065. } else {
  6066. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  6067. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6068. }
  6069. }
  6070. }
  6071. }
  6072. }
  6073. } else if patientType == 1 {
  6074. if patient_id > 0 {
  6075. if execution_state > 0 {
  6076. if cost_type > 0 {
  6077. if len(execution_frequency) > 0 {
  6078. if len(keyword) > 0 {
  6079. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6080. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  6081. } else {
  6082. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  6083. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  6084. }
  6085. } else {
  6086. if len(keyword) > 0 {
  6087. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  6088. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, keyword)
  6089. } else {
  6090. 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 = ?"
  6091. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  6092. }
  6093. }
  6094. } else {
  6095. if len(execution_frequency) > 0 {
  6096. if len(keyword) > 0 {
  6097. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  6098. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  6099. } else {
  6100. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  6101. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  6102. }
  6103. } else {
  6104. if len(keyword) > 0 {
  6105. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  6106. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, keyword)
  6107. } else {
  6108. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  6109. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  6110. }
  6111. }
  6112. }
  6113. } else {
  6114. if cost_type > 0 {
  6115. if len(execution_frequency) > 0 {
  6116. if len(keyword) > 0 {
  6117. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6118. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  6119. } else {
  6120. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  6121. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  6122. }
  6123. } else {
  6124. if len(keyword) > 0 {
  6125. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  6126. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, keyword)
  6127. } else {
  6128. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  6129. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  6130. }
  6131. }
  6132. } else {
  6133. if len(execution_frequency) > 0 {
  6134. if len(keyword) > 0 {
  6135. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  6136. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency, keyword)
  6137. } else {
  6138. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  6139. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  6140. }
  6141. } else {
  6142. if len(keyword) > 0 {
  6143. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and advice_name like ?"
  6144. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, keyword)
  6145. } else {
  6146. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ?"
  6147. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  6148. }
  6149. }
  6150. }
  6151. }
  6152. } else {
  6153. if execution_state > 0 {
  6154. if cost_type > 0 {
  6155. if len(execution_frequency) > 0 {
  6156. if len(keyword) > 0 {
  6157. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6158. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  6159. } else {
  6160. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  6161. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  6162. }
  6163. } else {
  6164. if len(keyword) > 0 {
  6165. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  6166. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, keyword)
  6167. } else {
  6168. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ? and is_settle = ?"
  6169. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  6170. }
  6171. }
  6172. } else {
  6173. if len(execution_frequency) > 0 {
  6174. if len(keyword) > 0 {
  6175. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  6176. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency, keyword)
  6177. } else {
  6178. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ? and execution_frequency = ?"
  6179. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  6180. }
  6181. } else {
  6182. if len(keyword) > 0 {
  6183. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ? and advice_name like ?"
  6184. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, keyword)
  6185. } else {
  6186. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ?"
  6187. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  6188. }
  6189. }
  6190. }
  6191. } else {
  6192. if cost_type > 0 {
  6193. if len(execution_frequency) > 0 {
  6194. if len(keyword) > 0 {
  6195. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6196. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency, keyword)
  6197. } else {
  6198. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  6199. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  6200. }
  6201. } else {
  6202. if len(keyword) > 0 {
  6203. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and is_settle = ? and advice_name like ?"
  6204. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, keyword)
  6205. } else {
  6206. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and is_settle = ?"
  6207. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  6208. }
  6209. }
  6210. } else {
  6211. if len(execution_frequency) > 0 {
  6212. if len(keyword) > 0 {
  6213. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_frequency = ? and advice_name like ?"
  6214. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency, keyword)
  6215. } else {
  6216. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_frequency = ?"
  6217. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  6218. }
  6219. } else {
  6220. if len(keyword) > 0 {
  6221. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and advice_name like ?"
  6222. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, keyword)
  6223. } else {
  6224. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?"
  6225. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  6226. }
  6227. }
  6228. }
  6229. }
  6230. }
  6231. } else if patientType == 2 {
  6232. if patient_id > 0 {
  6233. if execution_state > 0 {
  6234. if cost_type > 0 {
  6235. if len(execution_frequency) > 0 {
  6236. if len(keyword) > 0 {
  6237. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency=? and advice_name like ?"
  6238. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  6239. } else {
  6240. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency=?"
  6241. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  6242. }
  6243. } else {
  6244. if len(keyword) > 0 {
  6245. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  6246. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  6247. } else {
  6248. 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 = ?"
  6249. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6250. }
  6251. }
  6252. } else {
  6253. if len(execution_frequency) > 0 {
  6254. if len(keyword) > 0 {
  6255. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ? and execution_frequency=? and advice_name like ?"
  6256. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  6257. } else {
  6258. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ? and execution_frequency=?"
  6259. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  6260. }
  6261. } else {
  6262. if len(keyword) > 0 {
  6263. 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 advice_name like ?"
  6264. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  6265. } else {
  6266. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  6267. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6268. }
  6269. }
  6270. }
  6271. } else {
  6272. if cost_type > 0 {
  6273. if len(execution_frequency) > 0 {
  6274. if len(keyword) > 0 {
  6275. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and is_settle = ? and execution_frequency=? and advice_name like ?"
  6276. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  6277. } else {
  6278. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and is_settle = ? and execution_frequency=?"
  6279. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  6280. }
  6281. } else {
  6282. if len(keyword) > 0 {
  6283. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and is_settle = ? and advice_name like ?"
  6284. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  6285. } else {
  6286. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  6287. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6288. }
  6289. }
  6290. } else {
  6291. if len(execution_frequency) > 0 {
  6292. if len(keyword) > 0 {
  6293. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_frequency=? and advice_name like ?"
  6294. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  6295. } else {
  6296. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_frequency=?"
  6297. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  6298. }
  6299. } else {
  6300. if len(keyword) > 0 {
  6301. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and advice_name like ?"
  6302. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  6303. } else {
  6304. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ?"
  6305. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6306. }
  6307. }
  6308. }
  6309. }
  6310. } else {
  6311. if execution_state > 0 {
  6312. if cost_type > 0 {
  6313. if len(execution_frequency) > 0 {
  6314. if len(keyword) > 0 {
  6315. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6316. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  6317. } else {
  6318. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ? and is_settle = ? and execution_frequency = ?"
  6319. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  6320. }
  6321. } else {
  6322. if len(keyword) > 0 {
  6323. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ? and is_settle = ? and advice_name like ?"
  6324. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  6325. } else {
  6326. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  6327. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6328. }
  6329. }
  6330. } else {
  6331. if len(execution_frequency) > 0 {
  6332. if len(keyword) > 0 {
  6333. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ? and execution_frequency = ? and advice_name like ?"
  6334. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  6335. } else {
  6336. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ? and execution_frequency = ? "
  6337. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  6338. }
  6339. } else {
  6340. if len(keyword) > 0 {
  6341. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ? and advice_name like ?"
  6342. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  6343. } else {
  6344. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ?"
  6345. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6346. }
  6347. }
  6348. }
  6349. } else {
  6350. if cost_type > 0 {
  6351. if len(execution_frequency) > 0 {
  6352. if len(keyword) > 0 {
  6353. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6354. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  6355. } else {
  6356. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  6357. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  6358. }
  6359. } else {
  6360. if len(keyword) > 0 {
  6361. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and is_settle = ? and advice_name like ?"
  6362. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  6363. } else {
  6364. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and is_settle = ?"
  6365. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6366. }
  6367. }
  6368. } else {
  6369. if len(execution_frequency) > 0 {
  6370. if len(keyword) > 0 {
  6371. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_frequency = ? and advice_name like ?"
  6372. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  6373. } else {
  6374. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_frequency = ?"
  6375. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  6376. }
  6377. } else {
  6378. if len(keyword) > 0 {
  6379. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and advice_name like ?"
  6380. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  6381. } else {
  6382. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  6383. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6384. }
  6385. }
  6386. }
  6387. }
  6388. }
  6389. }
  6390. }
  6391. db := readDb.Table("xt_schedule")
  6392. if scheduleType > 0 {
  6393. db = db.Where("schedule_type = ?", scheduleType)
  6394. }
  6395. if partitonType > 0 {
  6396. db = db.Where("partition_id = ?", partitonType)
  6397. }
  6398. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6399. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6400. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6401. }).
  6402. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6403. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6404. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6405. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6406. Preload("DoctorAdvices", adviceCondition...).
  6407. Where("status = 1 AND user_org_id = ?", orgID)
  6408. if scheduleDate != 0 {
  6409. db = db.Where("schedule_date = ?", scheduleDate)
  6410. }
  6411. err := db.Find(&vms).Error
  6412. return vms, err
  6413. }
  6414. 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) {
  6415. var vms []*MScheduleDoctorAdviceVM
  6416. adviceWhere := ""
  6417. adviceCondition := []interface{}{}
  6418. if adviceType == 0 {
  6419. if patientType == 0 {
  6420. if patient_id > 0 {
  6421. if execution_state > 0 {
  6422. if cost_type > 0 {
  6423. 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 = ?"
  6424. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6425. } else {
  6426. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  6427. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6428. }
  6429. } else {
  6430. if cost_type > 0 {
  6431. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and is_settle = ?"
  6432. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6433. } else {
  6434. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
  6435. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6436. }
  6437. }
  6438. } else {
  6439. if execution_state > 0 {
  6440. if cost_type > 0 {
  6441. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and is_settle = ?"
  6442. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6443. } else {
  6444. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ?"
  6445. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6446. }
  6447. } else {
  6448. if cost_type > 0 {
  6449. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ?"
  6450. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6451. } else {
  6452. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  6453. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6454. }
  6455. }
  6456. }
  6457. } else if patientType == 1 {
  6458. if patient_id > 0 {
  6459. if execution_state > 0 {
  6460. if cost_type > 0 {
  6461. 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 = ?"
  6462. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  6463. } else {
  6464. 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= ?"
  6465. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  6466. }
  6467. } else {
  6468. if cost_type > 0 {
  6469. 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=?"
  6470. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  6471. } else {
  6472. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
  6473. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  6474. }
  6475. }
  6476. } else {
  6477. if execution_state > 0 {
  6478. if cost_type > 0 {
  6479. 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=?"
  6480. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  6481. } else {
  6482. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  6483. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  6484. }
  6485. } else {
  6486. if cost_type > 0 {
  6487. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and is_settle=?"
  6488. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  6489. } else {
  6490. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  6491. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  6492. }
  6493. }
  6494. }
  6495. } else if patientType == 2 {
  6496. if patient_id > 0 {
  6497. if execution_state > 0 {
  6498. if cost_type > 0 {
  6499. 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=?"
  6500. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6501. } else {
  6502. 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 = ?"
  6503. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6504. }
  6505. } else {
  6506. if cost_type > 0 {
  6507. 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=?"
  6508. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6509. } else {
  6510. 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 = ?)"
  6511. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6512. }
  6513. }
  6514. } else {
  6515. if execution_state > 0 {
  6516. if cost_type > 0 {
  6517. 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=?"
  6518. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6519. } else {
  6520. 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 = ?"
  6521. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6522. }
  6523. } else {
  6524. if cost_type > 0 {
  6525. 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 = ?"
  6526. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6527. } else {
  6528. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  6529. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6530. }
  6531. }
  6532. }
  6533. }
  6534. } else if adviceType == 1 {
  6535. if patientType == 0 {
  6536. if patient_id > 0 {
  6537. if execution_state > 0 {
  6538. if cost_type > 0 {
  6539. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  6540. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6541. } else {
  6542. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ?"
  6543. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6544. }
  6545. } else {
  6546. if cost_type > 0 {
  6547. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? "
  6548. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6549. } else {
  6550. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
  6551. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6552. }
  6553. }
  6554. } else {
  6555. if execution_state > 0 {
  6556. if cost_type > 0 {
  6557. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ?"
  6558. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6559. } else {
  6560. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ?"
  6561. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6562. }
  6563. } else {
  6564. if cost_type > 0 {
  6565. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = ? "
  6566. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6567. } else {
  6568. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  6569. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6570. }
  6571. }
  6572. }
  6573. } else if patientType == 1 {
  6574. if patient_id > 0 {
  6575. if execution_state > 0 {
  6576. if cost_type > 0 {
  6577. 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 = ?"
  6578. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  6579. } else {
  6580. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  6581. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  6582. }
  6583. } else {
  6584. if cost_type > 0 {
  6585. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  6586. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  6587. } else {
  6588. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
  6589. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  6590. }
  6591. }
  6592. } else {
  6593. if execution_state > 0 {
  6594. if cost_type > 0 {
  6595. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=? and is_settle = ?"
  6596. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  6597. } else {
  6598. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?"
  6599. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  6600. }
  6601. } else {
  6602. if cost_type > 0 {
  6603. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? "
  6604. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  6605. } else {
  6606. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  6607. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  6608. }
  6609. }
  6610. }
  6611. } else if patientType == 2 {
  6612. if patient_id > 0 {
  6613. if execution_state > 0 {
  6614. if cost_type > 0 {
  6615. 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 = ?"
  6616. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6617. } else {
  6618. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  6619. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6620. }
  6621. } else {
  6622. if cost_type > 0 {
  6623. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  6624. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6625. } else {
  6626. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
  6627. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6628. }
  6629. }
  6630. } else {
  6631. if execution_state > 0 {
  6632. if cost_type > 0 {
  6633. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  6634. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6635. } else {
  6636. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ?"
  6637. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6638. }
  6639. } else {
  6640. if cost_type > 0 {
  6641. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ?"
  6642. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6643. } else {
  6644. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  6645. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6646. }
  6647. }
  6648. }
  6649. }
  6650. } else if adviceType == 3 {
  6651. if patientType == 0 {
  6652. if patient_id > 0 {
  6653. if execution_state > 0 {
  6654. if cost_type > 0 {
  6655. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  6656. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6657. } else {
  6658. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ?"
  6659. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6660. }
  6661. } else {
  6662. if cost_type > 0 {
  6663. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? "
  6664. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6665. } else {
  6666. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? "
  6667. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6668. }
  6669. }
  6670. } else {
  6671. if execution_state > 0 {
  6672. if cost_type > 0 {
  6673. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ?"
  6674. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6675. } else {
  6676. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? "
  6677. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6678. }
  6679. } else {
  6680. if cost_type > 0 {
  6681. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? "
  6682. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6683. } else {
  6684. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  6685. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6686. }
  6687. }
  6688. }
  6689. } else if patientType == 1 {
  6690. if patient_id > 0 {
  6691. if execution_state > 0 {
  6692. if cost_type > 0 {
  6693. 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 = ?"
  6694. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  6695. } else {
  6696. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  6697. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  6698. }
  6699. } else {
  6700. if cost_type > 0 {
  6701. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  6702. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  6703. } else {
  6704. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
  6705. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  6706. }
  6707. }
  6708. } else {
  6709. if execution_state > 0 {
  6710. if cost_type > 0 {
  6711. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? and is_settle = ?"
  6712. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  6713. } else {
  6714. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? "
  6715. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  6716. }
  6717. } else {
  6718. if cost_type > 0 {
  6719. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ?"
  6720. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  6721. } else {
  6722. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  6723. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  6724. }
  6725. }
  6726. }
  6727. } else if patientType == 2 {
  6728. if patient_id > 0 {
  6729. if execution_state > 0 {
  6730. if cost_type > 0 {
  6731. 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 = ?"
  6732. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6733. } else {
  6734. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  6735. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6736. }
  6737. } else {
  6738. if cost_type > 0 {
  6739. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  6740. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6741. } else {
  6742. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ?"
  6743. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6744. }
  6745. }
  6746. } else {
  6747. if execution_state > 0 {
  6748. if cost_type > 0 {
  6749. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and is_settle = ?"
  6750. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6751. } else {
  6752. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ?"
  6753. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6754. }
  6755. } else {
  6756. if cost_type > 0 {
  6757. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ?"
  6758. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6759. } else {
  6760. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  6761. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6762. }
  6763. }
  6764. }
  6765. }
  6766. } else if adviceType == 2 && len(deliverWay) > 0 {
  6767. if patientType == 0 {
  6768. if patient_id > 0 {
  6769. if execution_state > 0 {
  6770. if cost_type > 0 {
  6771. 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 = ?"
  6772. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  6773. } else {
  6774. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  6775. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  6776. }
  6777. } else {
  6778. if cost_type > 0 {
  6779. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and is_settle = ?"
  6780. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  6781. } else {
  6782. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ?"
  6783. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  6784. }
  6785. }
  6786. } else {
  6787. if execution_state > 0 {
  6788. if cost_type > 0 {
  6789. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and is_settle = ?"
  6790. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  6791. } else {
  6792. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ?"
  6793. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  6794. }
  6795. } else {
  6796. if cost_type > 0 {
  6797. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and is_settle = ?"
  6798. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  6799. } else {
  6800. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  6801. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  6802. }
  6803. }
  6804. }
  6805. } else if patientType == 1 {
  6806. if patient_id > 0 {
  6807. if execution_state > 0 {
  6808. if cost_type > 0 {
  6809. 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 = ?"
  6810. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type)
  6811. } else {
  6812. 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 = ?"
  6813. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state)
  6814. }
  6815. } else {
  6816. if cost_type > 0 {
  6817. 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 = ?"
  6818. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type)
  6819. } else {
  6820. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ?"
  6821. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
  6822. }
  6823. }
  6824. } else {
  6825. if execution_state > 0 {
  6826. if cost_type > 0 {
  6827. 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 = ?"
  6828. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type)
  6829. } else {
  6830. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ?"
  6831. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state)
  6832. }
  6833. } else {
  6834. if cost_type > 0 {
  6835. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and is_settle = ?"
  6836. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type)
  6837. } else {
  6838. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  6839. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  6840. }
  6841. }
  6842. }
  6843. } else if patientType == 2 {
  6844. if patient_id > 0 {
  6845. if execution_state > 0 {
  6846. if cost_type > 0 {
  6847. 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 = ?"
  6848. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  6849. } else {
  6850. 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 = ?"
  6851. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  6852. }
  6853. } else {
  6854. if cost_type > 0 {
  6855. 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 = ?"
  6856. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  6857. } else {
  6858. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ?"
  6859. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  6860. }
  6861. }
  6862. } else {
  6863. if execution_state > 0 {
  6864. if cost_type > 0 {
  6865. 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 = ?"
  6866. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  6867. } else {
  6868. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ?"
  6869. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  6870. }
  6871. } else {
  6872. if cost_type > 0 {
  6873. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and is_settle = ?"
  6874. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  6875. } else {
  6876. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  6877. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  6878. }
  6879. }
  6880. }
  6881. }
  6882. } else if adviceType == 2 && len(deliverWay) <= 0 {
  6883. if patientType == 0 {
  6884. if patient_id > 0 {
  6885. if execution_state > 0 {
  6886. if cost_type > 0 {
  6887. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  6888. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6889. } else {
  6890. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ?"
  6891. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6892. }
  6893. } else {
  6894. if cost_type > 0 {
  6895. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and is_settle = ?"
  6896. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6897. } else {
  6898. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ?"
  6899. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6900. }
  6901. }
  6902. } else {
  6903. if execution_state > 0 {
  6904. if cost_type > 0 {
  6905. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ? and is_settle = ?"
  6906. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6907. } else {
  6908. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?"
  6909. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6910. }
  6911. } else {
  6912. if cost_type > 0 {
  6913. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and is_settle = ?"
  6914. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6915. } else {
  6916. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  6917. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6918. }
  6919. }
  6920. }
  6921. } else if patientType == 1 {
  6922. if patient_id > 0 {
  6923. if execution_state > 0 {
  6924. if cost_type > 0 {
  6925. 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 = ?"
  6926. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  6927. } else {
  6928. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  6929. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  6930. }
  6931. } else {
  6932. if cost_type > 0 {
  6933. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  6934. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  6935. } else {
  6936. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ?"
  6937. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  6938. }
  6939. }
  6940. } else {
  6941. if execution_state > 0 {
  6942. if cost_type > 0 {
  6943. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ? and is_settle = ?"
  6944. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  6945. } else {
  6946. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ?"
  6947. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  6948. }
  6949. } else {
  6950. if cost_type > 0 {
  6951. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and is_settle = ?"
  6952. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  6953. } else {
  6954. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?"
  6955. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  6956. }
  6957. }
  6958. }
  6959. } else if patientType == 2 {
  6960. if patient_id > 0 {
  6961. if execution_state > 0 {
  6962. if cost_type > 0 {
  6963. 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 = ?"
  6964. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6965. } else {
  6966. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  6967. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6968. }
  6969. } else {
  6970. if cost_type > 0 {
  6971. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  6972. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6973. } else {
  6974. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ?"
  6975. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6976. }
  6977. }
  6978. } else {
  6979. if execution_state > 0 {
  6980. if cost_type > 0 {
  6981. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  6982. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6983. } else {
  6984. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ?"
  6985. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6986. }
  6987. } else {
  6988. if cost_type > 0 {
  6989. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and is_settle = ?"
  6990. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6991. } else {
  6992. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  6993. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6994. }
  6995. }
  6996. }
  6997. }
  6998. }
  6999. db := readDb.Table("xt_schedule")
  7000. if scheduleType > 0 {
  7001. db = db.Where("schedule_type = ?", scheduleType)
  7002. }
  7003. if partitonType > 0 {
  7004. db = db.Where("partition_id = ?", partitonType)
  7005. }
  7006. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7007. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7008. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7009. }).
  7010. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7011. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7012. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7013. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7014. Preload("DoctorAdvices", adviceCondition...).
  7015. Where("status = 1 AND user_org_id = ?", orgID)
  7016. if scheduleDate != 0 {
  7017. db = db.Where("schedule_date = ?", scheduleDate)
  7018. }
  7019. err := db.Find(&vms).Error
  7020. return vms, err
  7021. }
  7022. func GetLastPatientOrder(id int64) (models.XtDialysisOrder, error) {
  7023. order := models.XtDialysisOrder{}
  7024. err := XTReadDB().Where("id = ? and status = 1", id).Find(&order).Error
  7025. return order, err
  7026. }
  7027. func UpdateMobilePatient(org_id int64, patient_id int64, schedule_remark string) error {
  7028. order := models.XtPatients{}
  7029. 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
  7030. 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
  7031. return err
  7032. }
  7033. func GetDialysisTotalCount(org_id int64, patient_id int64) (models.BloodDialysisOrderCount, error) {
  7034. order := models.BloodDialysisOrderCount{}
  7035. db := XTReadDB().Table("xt_dialysis_order as o")
  7036. 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
  7037. return order, err
  7038. }
  7039. func GetDialysisTotalCountOne(org_id int64, patient_id int64) (models.BloodDialysisOrderCount, error) {
  7040. order := models.BloodDialysisOrderCount{}
  7041. db := XTReadDB().Table("xt_dialysis_order as o")
  7042. err = db.Raw("select count(o.id) as count,o.patient_id from xt_dialysis_order as o left join xt_schedule as x on x.patient_id = o.patient_id where o.status =1 and o.user_org_id = ? and o.patient_id = ? and o.dialysis_date>=1704038400 and x.schedule_date = o.dialysis_date and x.status = 1 ", org_id, patient_id).Scan(&order).Error
  7043. return order, err
  7044. }
  7045. func UpdateDialysisOrder(patient_id int64, dialysis_date int64, user_org_id int64, dialysis_total int64) (models.DialysisOrder, error) {
  7046. order := models.DialysisOrder{}
  7047. 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
  7048. return order, err
  7049. }
  7050. func UpdateDeviceInformation(patientid int64, dialysis_date int64) error {
  7051. information := models.DeviceInformation{}
  7052. err := UserWriteDB().Model(&information).Where("patient_id = ? and date = ? and status = 1", patientid, dialysis_date).Update(map[string]interface{}{"status": 0}).Error
  7053. return err
  7054. }
  7055. func MobileGetDoubleCheckSix(orgID int64, patientID int64, recordDate int64) (models.DoubleCheck, error) {
  7056. var record models.DoubleCheck
  7057. err := readDb.Where("patient_id = ? and user_org_id = ? and status = 1 and check_date = ?", patientID, orgID, recordDate).First(&record).Error
  7058. return record, err
  7059. }
  7060. func GetFirstMonitor(patient_id int64, monit_date int64) (models.MonitoringRecord, error) {
  7061. record := models.MonitoringRecord{}
  7062. err := XTReadDB().Where("patient_id = ? and monitoring_date = ? and status=1", patient_id, monit_date).First(&record).Error
  7063. return record, err
  7064. }
  7065. func UpdateFirstMonitor(id int64, catheter_operation string) (models.MonitoringRecord, error) {
  7066. record := models.MonitoringRecord{}
  7067. err := XTWriteDB().Model(&record).Where("id = ? and status= 1", id).Updates(map[string]interface{}{"dispose": catheter_operation}).Error
  7068. return record, err
  7069. }
  7070. 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) {
  7071. var vms []*HisMScheduleDoctorAdviceVM
  7072. if len(deliverWay) > 0 {
  7073. db := readDb.Table("xt_schedule")
  7074. if scheduleType > 0 {
  7075. db = db.Where("schedule_type = ?", scheduleType)
  7076. }
  7077. if partitionType > 0 {
  7078. db = db.Where("partition_id = ?", partitionType)
  7079. }
  7080. if patient_id > 0 {
  7081. if execution_state > 0 {
  7082. if cost_type > 0 {
  7083. if len(execution_frequency) > 0 {
  7084. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7085. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7086. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7087. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7088. 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).
  7089. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7090. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7091. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7092. Where("status = 1 AND user_org_id = ?", orgID)
  7093. if scheduleDate != 0 {
  7094. db = db.Where("schedule_date = ?", scheduleDate)
  7095. }
  7096. err = db.Find(&vms).Error
  7097. } else {
  7098. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7099. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7100. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7101. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7102. 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).
  7103. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7104. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7105. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7106. Where("status = 1 AND user_org_id = ?", orgID)
  7107. if scheduleDate != 0 {
  7108. db = db.Where("schedule_date = ?", scheduleDate)
  7109. }
  7110. err = db.Find(&vms).Error
  7111. }
  7112. } else {
  7113. if len(execution_frequency) > 0 {
  7114. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7115. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7116. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7117. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7118. 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).
  7119. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7120. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7121. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7122. Where("status = 1 AND user_org_id = ?", orgID)
  7123. if scheduleDate != 0 {
  7124. db = db.Where("schedule_date = ?", scheduleDate)
  7125. }
  7126. err = db.Find(&vms).Error
  7127. } else {
  7128. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7129. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7130. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7131. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7132. 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).
  7133. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7134. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7135. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7136. Where("status = 1 AND user_org_id = ?", orgID)
  7137. if scheduleDate != 0 {
  7138. db = db.Where("schedule_date = ?", scheduleDate)
  7139. }
  7140. err = db.Find(&vms).Error
  7141. }
  7142. }
  7143. } else {
  7144. if cost_type > 0 {
  7145. if len(execution_frequency) > 0 {
  7146. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7147. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7148. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7149. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7150. 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).
  7151. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7152. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7153. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7154. Where("status = 1 AND user_org_id = ?", orgID)
  7155. if scheduleDate != 0 {
  7156. db = db.Where("schedule_date = ?", scheduleDate)
  7157. }
  7158. err = db.Find(&vms).Error
  7159. } else {
  7160. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7161. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7162. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7163. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7164. 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).
  7165. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7166. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7167. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7168. Where("status = 1 AND user_org_id = ?", orgID)
  7169. if scheduleDate != 0 {
  7170. db = db.Where("schedule_date = ?", scheduleDate)
  7171. }
  7172. err = db.Find(&vms).Error
  7173. }
  7174. } else {
  7175. if len(execution_frequency) > 0 {
  7176. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7177. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7178. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7179. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7180. 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).
  7181. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7182. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7183. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7184. Where("status = 1 AND user_org_id = ?", orgID)
  7185. if scheduleDate != 0 {
  7186. db = db.Where("schedule_date = ?", scheduleDate)
  7187. }
  7188. err = db.Find(&vms).Error
  7189. } else {
  7190. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7191. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7192. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7193. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7194. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ?", orgID, scheduleDate, deliverWay, patient_id).
  7195. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7196. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7197. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7198. Where("status = 1 AND user_org_id = ?", orgID)
  7199. if scheduleDate != 0 {
  7200. db = db.Where("schedule_date = ?", scheduleDate)
  7201. }
  7202. err = db.Find(&vms).Error
  7203. }
  7204. }
  7205. }
  7206. } else {
  7207. if execution_state > 0 {
  7208. if cost_type > 0 {
  7209. if len(execution_frequency) > 0 {
  7210. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7211. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7212. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7213. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7214. 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).
  7215. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7216. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7217. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7218. Where("status = 1 AND user_org_id = ?", orgID)
  7219. if scheduleDate != 0 {
  7220. db = db.Where("schedule_date = ?", scheduleDate)
  7221. }
  7222. err = db.Find(&vms).Error
  7223. } else {
  7224. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7225. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7226. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7227. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7228. 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).
  7229. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7230. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7231. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7232. Where("status = 1 AND user_org_id = ?", orgID)
  7233. if scheduleDate != 0 {
  7234. db = db.Where("schedule_date = ?", scheduleDate)
  7235. }
  7236. err = db.Find(&vms).Error
  7237. }
  7238. } else {
  7239. if len(execution_frequency) > 0 {
  7240. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7241. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7242. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7243. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7244. 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).
  7245. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7246. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7247. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7248. Where("status = 1 AND user_org_id = ?", orgID)
  7249. if scheduleDate != 0 {
  7250. db = db.Where("schedule_date = ?", scheduleDate)
  7251. }
  7252. err = db.Find(&vms).Error
  7253. } else {
  7254. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7255. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7256. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7257. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7258. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_state = ?", orgID, scheduleDate, deliverWay, execution_state).
  7259. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7260. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7261. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7262. Where("status = 1 AND user_org_id = ?", orgID)
  7263. if scheduleDate != 0 {
  7264. db = db.Where("schedule_date = ?", scheduleDate)
  7265. }
  7266. err = db.Find(&vms).Error
  7267. }
  7268. }
  7269. } else {
  7270. if cost_type > 0 {
  7271. if len(execution_frequency) > 0 {
  7272. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7273. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7274. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7275. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7276. 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).
  7277. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7278. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7279. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7280. Where("status = 1 AND user_org_id = ?", orgID)
  7281. if scheduleDate != 0 {
  7282. db = db.Where("schedule_date = ?", scheduleDate)
  7283. }
  7284. err = db.Find(&vms).Error
  7285. } else {
  7286. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7287. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7288. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7289. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7290. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and is_settle = ?", orgID, scheduleDate, deliverWay, cost_type).
  7291. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7292. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7293. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7294. Where("status = 1 AND user_org_id = ?", orgID)
  7295. if scheduleDate != 0 {
  7296. db = db.Where("schedule_date = ?", scheduleDate)
  7297. }
  7298. err = db.Find(&vms).Error
  7299. }
  7300. } else {
  7301. if len(execution_frequency) > 0 {
  7302. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7303. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7304. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7305. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7306. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_frequency = ?", orgID, scheduleDate, deliverWay, execution_frequency).
  7307. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7308. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7309. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7310. Where("status = 1 AND user_org_id = ?", orgID)
  7311. if scheduleDate != 0 {
  7312. db = db.Where("schedule_date = ?", scheduleDate)
  7313. }
  7314. err = db.Find(&vms).Error
  7315. } else {
  7316. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7317. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7318. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7319. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7320. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  7321. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7322. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7323. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7324. Where("status = 1 AND user_org_id = ?", orgID)
  7325. if scheduleDate != 0 {
  7326. db = db.Where("schedule_date = ?", scheduleDate)
  7327. }
  7328. err = db.Find(&vms).Error
  7329. }
  7330. }
  7331. }
  7332. }
  7333. } else {
  7334. db := readDb.Table("xt_schedule")
  7335. if scheduleType > 0 {
  7336. db = db.Where("schedule_type = ?", scheduleType)
  7337. }
  7338. if partitionType > 0 {
  7339. db = db.Where("partition_id = ?", partitionType)
  7340. }
  7341. if patient_id > 0 {
  7342. if execution_state > 0 {
  7343. fmt.Println("execution_state---------------------", execution_state)
  7344. if cost_type > 0 {
  7345. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7346. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7347. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7348. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7349. 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).
  7350. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7351. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7352. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7353. Where("status = 1 AND user_org_id = ?", orgID)
  7354. if scheduleDate != 0 {
  7355. db = db.Where("schedule_date = ?", scheduleDate)
  7356. }
  7357. err = db.Find(&vms).Error
  7358. } else {
  7359. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7360. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7361. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7362. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7363. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and execution_state = ?", orgID, scheduleDate, patient_id, execution_state).
  7364. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7365. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7366. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7367. Where("status = 1 AND user_org_id = ?", orgID)
  7368. if scheduleDate != 0 {
  7369. db = db.Where("schedule_date = ?", scheduleDate)
  7370. }
  7371. err = db.Find(&vms).Error
  7372. }
  7373. } else {
  7374. if cost_type > 0 {
  7375. if len(execution_frequency) > 0 {
  7376. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7377. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7378. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7379. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7380. 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).
  7381. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7382. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7383. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7384. Where("status = 1 AND user_org_id = ?", orgID)
  7385. if scheduleDate != 0 {
  7386. db = db.Where("schedule_date = ?", scheduleDate)
  7387. }
  7388. err = db.Find(&vms).Error
  7389. } else {
  7390. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7391. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7392. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7393. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7394. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and is_settle = ?", orgID, scheduleDate, patient_id, cost_type).
  7395. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7396. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7397. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7398. Where("status = 1 AND user_org_id = ?", orgID)
  7399. if scheduleDate != 0 {
  7400. db = db.Where("schedule_date = ?", scheduleDate)
  7401. }
  7402. err = db.Find(&vms).Error
  7403. }
  7404. } else {
  7405. if len(execution_frequency) > 0 {
  7406. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7407. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7408. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7409. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7410. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and execution_frequency = ?", orgID, scheduleDate, patient_id, execution_frequency).
  7411. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7412. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7413. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7414. Where("status = 1 AND user_org_id = ?", orgID)
  7415. if scheduleDate != 0 {
  7416. db = db.Where("schedule_date = ?", scheduleDate)
  7417. }
  7418. err = db.Find(&vms).Error
  7419. } else {
  7420. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7421. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7422. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7423. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7424. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7425. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7426. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7427. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7428. Where("status = 1 AND user_org_id = ?", orgID)
  7429. if scheduleDate != 0 {
  7430. db = db.Where("schedule_date = ?", scheduleDate)
  7431. }
  7432. err = db.Find(&vms).Error
  7433. }
  7434. }
  7435. }
  7436. } else {
  7437. if execution_state > 0 {
  7438. if cost_type > 0 {
  7439. if len(execution_frequency) > 0 {
  7440. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7441. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7442. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7443. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7444. 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).
  7445. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7446. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7447. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7448. Where("status = 1 AND user_org_id = ?", orgID)
  7449. if scheduleDate != 0 {
  7450. db = db.Where("schedule_date = ?", scheduleDate)
  7451. }
  7452. err = db.Find(&vms).Error
  7453. } else {
  7454. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7455. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7456. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7457. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7458. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ? and is_settle = ?", orgID, scheduleDate, execution_state, cost_type).
  7459. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7460. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7461. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7462. Where("status = 1 AND user_org_id = ?", orgID)
  7463. if scheduleDate != 0 {
  7464. db = db.Where("schedule_date = ?", scheduleDate)
  7465. }
  7466. err = db.Find(&vms).Error
  7467. }
  7468. } else {
  7469. if len(execution_frequency) > 0 {
  7470. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7471. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7472. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7473. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7474. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ? and execution_frequency = ?", orgID, scheduleDate, execution_state, execution_frequency).
  7475. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7476. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7477. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7478. Where("status = 1 AND user_org_id = ?", orgID)
  7479. if scheduleDate != 0 {
  7480. db = db.Where("schedule_date = ?", scheduleDate)
  7481. }
  7482. err = db.Find(&vms).Error
  7483. } else {
  7484. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7485. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7486. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7487. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7488. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ?", orgID, scheduleDate, execution_state).
  7489. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7490. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7491. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7492. Where("status = 1 AND user_org_id = ?", orgID)
  7493. if scheduleDate != 0 {
  7494. db = db.Where("schedule_date = ?", scheduleDate)
  7495. }
  7496. err = db.Find(&vms).Error
  7497. }
  7498. }
  7499. } else {
  7500. if cost_type > 0 {
  7501. if len(execution_frequency) > 0 {
  7502. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7503. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7504. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7505. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7506. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and is_settle = ?", orgID, scheduleDate, cost_type).
  7507. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7508. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7509. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7510. Where("status = 1 AND user_org_id = ?", orgID)
  7511. if scheduleDate != 0 {
  7512. db = db.Where("schedule_date = ?", scheduleDate)
  7513. }
  7514. err = db.Find(&vms).Error
  7515. } else {
  7516. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7517. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7518. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7519. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7520. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and is_settle = ? and execution_frequency = ?", orgID, scheduleDate, cost_type, execution_frequency).
  7521. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7522. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7523. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7524. Where("status = 1 AND user_org_id = ?", orgID)
  7525. if scheduleDate != 0 {
  7526. db = db.Where("schedule_date = ?", scheduleDate)
  7527. }
  7528. err = db.Find(&vms).Error
  7529. }
  7530. } else {
  7531. if len(execution_frequency) > 0 {
  7532. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7533. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7534. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7535. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7536. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_frequency = ?", orgID, scheduleDate, execution_frequency).
  7537. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7538. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7539. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7540. Where("status = 1 AND user_org_id = ?", orgID)
  7541. if scheduleDate != 0 {
  7542. db = db.Where("schedule_date = ?", scheduleDate)
  7543. }
  7544. err = db.Find(&vms).Error
  7545. } else {
  7546. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7547. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7548. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7549. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7550. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ?", orgID, scheduleDate).
  7551. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7552. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7553. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7554. Where("status = 1 AND user_org_id = ?", orgID)
  7555. if scheduleDate != 0 {
  7556. db = db.Where("schedule_date = ?", scheduleDate)
  7557. }
  7558. err = db.Find(&vms).Error
  7559. }
  7560. }
  7561. }
  7562. }
  7563. }
  7564. return vms, err
  7565. }
  7566. func GetPatientDryWeight(org_id int64, patient_id int64) (weight []*models.SgjPatientDryweight, err error) {
  7567. err = XTReadDB().Where("user_org_id = ? and patient_id = ? and status =1", org_id, patient_id).Order("id desc").Limit(6).Find(&weight).Error
  7568. return weight, err
  7569. }
  7570. 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) {
  7571. var vms []*MScheduleDoctorAdviceVM
  7572. adviceWhere := ""
  7573. keyword = "%" + keyword + "%"
  7574. adviceCondition := []interface{}{}
  7575. if adviceType == 1 {
  7576. if patientType == 0 {
  7577. if patient_id > 0 {
  7578. if execution_state > 0 {
  7579. if cost_type > 0 {
  7580. if len(execution_frequency) > 0 {
  7581. if len(keyword) > 0 {
  7582. 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 ?"
  7583. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency, keyword)
  7584. } else {
  7585. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  7586. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency)
  7587. }
  7588. } else {
  7589. if len(keyword) > 0 {
  7590. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  7591. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, keyword)
  7592. } else {
  7593. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ?"
  7594. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type)
  7595. }
  7596. }
  7597. } else {
  7598. if len(execution_frequency) > 0 {
  7599. if len(keyword) > 0 {
  7600. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  7601. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency, keyword)
  7602. } else {
  7603. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and execution_frequency = ?"
  7604. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency)
  7605. }
  7606. } else {
  7607. if len(keyword) > 0 {
  7608. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and advice_name like ?"
  7609. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, keyword)
  7610. } else {
  7611. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ?"
  7612. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state)
  7613. }
  7614. }
  7615. }
  7616. } else {
  7617. if cost_type > 0 {
  7618. if len(execution_frequency) > 0 {
  7619. if len(keyword) > 0 {
  7620. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  7621. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency, keyword)
  7622. } else {
  7623. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and execution_frequency = ?"
  7624. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency)
  7625. }
  7626. } else {
  7627. if len(keyword) > 0 {
  7628. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and advice_name like ?"
  7629. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, keyword)
  7630. } else {
  7631. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? "
  7632. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type)
  7633. }
  7634. }
  7635. } else {
  7636. if len(execution_frequency) > 0 {
  7637. if len(keyword) > 0 {
  7638. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_frequency = ? and advice_name like ?"
  7639. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency, keyword)
  7640. } else {
  7641. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_frequency = ?"
  7642. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency)
  7643. }
  7644. } else {
  7645. if len(keyword) > 0 {
  7646. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and advice_name like ?"
  7647. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, keyword)
  7648. } else {
  7649. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? "
  7650. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id)
  7651. }
  7652. }
  7653. }
  7654. }
  7655. } else {
  7656. if execution_state > 0 {
  7657. if cost_type > 0 {
  7658. if len(execution_frequency) > 0 {
  7659. if len(keyword) > 0 {
  7660. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  7661. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency, keyword)
  7662. } else {
  7663. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and execution_frequency = ?"
  7664. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency)
  7665. }
  7666. } else {
  7667. if len(keyword) > 0 {
  7668. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and advice_name like ?"
  7669. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, keyword)
  7670. } else {
  7671. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ?"
  7672. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type)
  7673. }
  7674. }
  7675. } else {
  7676. if len(execution_frequency) > 0 {
  7677. if len(keyword) > 0 {
  7678. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and execution_frequency = ? and advice_name like ?"
  7679. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency, keyword)
  7680. } else {
  7681. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and execution_frequency = ?"
  7682. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency)
  7683. }
  7684. } else {
  7685. if len(keyword) > 0 {
  7686. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and advice_name like ?"
  7687. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, keyword)
  7688. } else {
  7689. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ?"
  7690. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state)
  7691. }
  7692. }
  7693. }
  7694. } else {
  7695. if cost_type > 0 {
  7696. if len(keyword) > 0 {
  7697. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and is_settle = ? and advice_name like ?"
  7698. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, keyword)
  7699. } else {
  7700. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and is_settle = ? "
  7701. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type)
  7702. }
  7703. } else {
  7704. if len(keyword) > 0 {
  7705. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and advice_name like ?"
  7706. adviceCondition = append(adviceCondition, adviceWhere, orgID, keyword)
  7707. } else {
  7708. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 "
  7709. adviceCondition = append(adviceCondition, adviceWhere, orgID)
  7710. }
  7711. }
  7712. }
  7713. }
  7714. } else if patientType == 1 {
  7715. if patient_id > 0 {
  7716. if execution_state > 0 {
  7717. if cost_type > 0 {
  7718. if len(execution_frequency) > 0 {
  7719. if len(keyword) > 0 {
  7720. 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 ?"
  7721. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  7722. } else {
  7723. 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 = ?"
  7724. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  7725. }
  7726. } else {
  7727. if len(keyword) > 0 {
  7728. 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 ?"
  7729. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, keyword)
  7730. } else {
  7731. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  7732. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type)
  7733. }
  7734. }
  7735. } else {
  7736. if len(execution_frequency) > 0 {
  7737. if len(keyword) > 0 {
  7738. 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 ?"
  7739. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  7740. } else {
  7741. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  7742. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, execution_frequency)
  7743. }
  7744. } else {
  7745. if len(keyword) > 0 {
  7746. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  7747. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, keyword)
  7748. } else {
  7749. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  7750. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state)
  7751. }
  7752. }
  7753. }
  7754. } else {
  7755. if cost_type > 0 {
  7756. if len(execution_frequency) > 0 {
  7757. if len(keyword) > 0 {
  7758. 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 ?"
  7759. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  7760. } else {
  7761. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ?and execution_frequency = ?"
  7762. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, execution_frequency)
  7763. }
  7764. } else {
  7765. if len(keyword) > 0 {
  7766. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  7767. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, keyword)
  7768. } else {
  7769. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  7770. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type)
  7771. }
  7772. }
  7773. } else {
  7774. if len(execution_frequency) > 0 {
  7775. if len(keyword) > 0 {
  7776. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  7777. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_frequency, keyword)
  7778. } else {
  7779. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  7780. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_frequency)
  7781. }
  7782. } else {
  7783. if len(keyword) > 0 {
  7784. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and advice_name like ?"
  7785. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, keyword)
  7786. } else {
  7787. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ?"
  7788. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id)
  7789. }
  7790. }
  7791. }
  7792. }
  7793. } else {
  7794. if execution_state > 0 {
  7795. if cost_type > 0 {
  7796. if len(execution_frequency) > 0 {
  7797. if len(keyword) > 0 {
  7798. 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 ?"
  7799. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  7800. } else {
  7801. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ?and execution_frequency = ?"
  7802. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, execution_frequency)
  7803. }
  7804. } else {
  7805. if len(keyword) > 0 {
  7806. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ? and advice_name like ?"
  7807. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, keyword)
  7808. } else {
  7809. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ?"
  7810. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type)
  7811. }
  7812. }
  7813. } else {
  7814. if len(execution_frequency) > 0 {
  7815. if len(keyword) > 0 {
  7816. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=?and execution_frequency = ? and advice_name like ?"
  7817. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, execution_frequency, keyword)
  7818. } else {
  7819. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=?and execution_frequency = ?"
  7820. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, execution_frequency)
  7821. }
  7822. } else {
  7823. if len(keyword) > 0 {
  7824. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and advice_name like ?"
  7825. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, keyword)
  7826. } else {
  7827. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=?"
  7828. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state)
  7829. }
  7830. }
  7831. }
  7832. } else {
  7833. if cost_type > 0 {
  7834. if len(execution_frequency) > 0 {
  7835. if len(keyword) > 0 {
  7836. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  7837. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, execution_frequency, keyword)
  7838. } else {
  7839. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  7840. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, execution_frequency)
  7841. }
  7842. } else {
  7843. if len(keyword) > 0 {
  7844. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and advice_name like ?"
  7845. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, keyword)
  7846. } else {
  7847. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? "
  7848. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type)
  7849. }
  7850. }
  7851. } else {
  7852. if len(execution_frequency) > 0 {
  7853. if len(keyword) > 0 {
  7854. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_frequency = ? and advice_name like ?"
  7855. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_frequency, keyword)
  7856. } else {
  7857. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_frequency = ?"
  7858. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_frequency)
  7859. }
  7860. } else {
  7861. if len(keyword) > 0 {
  7862. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and advice_name like ?"
  7863. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, keyword)
  7864. } else {
  7865. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? "
  7866. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId)
  7867. }
  7868. }
  7869. }
  7870. }
  7871. }
  7872. } else if patientType == 2 {
  7873. if patient_id > 0 {
  7874. if execution_state > 0 {
  7875. if cost_type > 0 {
  7876. if len(execution_frequency) > 0 {
  7877. if len(keyword) > 0 {
  7878. 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 ?"
  7879. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency, keyword)
  7880. } else {
  7881. 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 = ?"
  7882. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency)
  7883. }
  7884. } else {
  7885. if len(keyword) > 0 {
  7886. 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 ?"
  7887. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, keyword)
  7888. } else {
  7889. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ?"
  7890. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type)
  7891. }
  7892. }
  7893. } else {
  7894. if len(execution_frequency) > 0 {
  7895. if len(keyword) > 0 {
  7896. 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 ?"
  7897. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency, keyword)
  7898. } else {
  7899. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and execution_frequency = ?"
  7900. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency)
  7901. }
  7902. } else {
  7903. if len(keyword) > 0 {
  7904. 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 ?"
  7905. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, keyword)
  7906. } else {
  7907. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  7908. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state)
  7909. }
  7910. }
  7911. }
  7912. } else {
  7913. if cost_type > 0 {
  7914. if len(execution_frequency) > 0 {
  7915. if len(keyword) > 0 {
  7916. 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 ?"
  7917. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency, keyword)
  7918. } else {
  7919. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and is_settle = ? and execution_frequency = ?"
  7920. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency)
  7921. }
  7922. } else {
  7923. if len(keyword) > 0 {
  7924. 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 ?"
  7925. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, keyword)
  7926. } else {
  7927. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  7928. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type)
  7929. }
  7930. }
  7931. } else {
  7932. if len(execution_frequency) > 0 {
  7933. if len(keyword) > 0 {
  7934. 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 ?"
  7935. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency, keyword)
  7936. } else {
  7937. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_frequency = ?"
  7938. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency)
  7939. }
  7940. } else {
  7941. if len(keyword) > 0 {
  7942. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and advice_name like ?"
  7943. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, keyword)
  7944. } else {
  7945. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ?"
  7946. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id)
  7947. }
  7948. }
  7949. }
  7950. }
  7951. } else {
  7952. if execution_state > 0 {
  7953. if cost_type > 0 {
  7954. if len(execution_frequency) > 0 {
  7955. if len(keyword) > 0 {
  7956. 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 ?"
  7957. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency, keyword)
  7958. } else {
  7959. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ? and execution_frequency = ?"
  7960. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency)
  7961. }
  7962. } else {
  7963. if len(keyword) > 0 {
  7964. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ? and advice_name like ?"
  7965. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, keyword)
  7966. } else {
  7967. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  7968. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type)
  7969. }
  7970. }
  7971. } else {
  7972. if len(execution_frequency) > 0 {
  7973. if len(keyword) > 0 {
  7974. 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 ?"
  7975. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency, keyword)
  7976. } else {
  7977. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ? and execution_frequency = ?"
  7978. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency)
  7979. }
  7980. } else {
  7981. if len(keyword) > 0 {
  7982. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ? and advice_name like ?"
  7983. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, keyword)
  7984. } else {
  7985. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ?"
  7986. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state)
  7987. }
  7988. }
  7989. }
  7990. } else {
  7991. if cost_type > 0 {
  7992. if len(execution_frequency) > 0 {
  7993. if len(keyword) > 0 {
  7994. 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 ?"
  7995. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, execution_frequency, keyword)
  7996. } else {
  7997. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  7998. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, execution_frequency)
  7999. }
  8000. } else {
  8001. if len(keyword) > 0 {
  8002. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ? and advice_name like ?"
  8003. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, keyword)
  8004. } else {
  8005. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ?"
  8006. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type)
  8007. }
  8008. }
  8009. } else {
  8010. if len(execution_frequency) > 0 {
  8011. if len(keyword) > 0 {
  8012. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_frequency = ? and advice_name like ?"
  8013. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_frequency, keyword)
  8014. } else {
  8015. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_frequency = ?"
  8016. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_frequency)
  8017. }
  8018. } else {
  8019. if len(keyword) > 0 {
  8020. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and advice_name like ?"
  8021. adviceCondition = append(adviceCondition, adviceWhere, orgID, keyword)
  8022. } else {
  8023. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0"
  8024. adviceCondition = append(adviceCondition, adviceWhere, orgID)
  8025. }
  8026. }
  8027. }
  8028. }
  8029. }
  8030. }
  8031. }
  8032. db := readDb.Table("xt_schedule")
  8033. if scheduleType > 0 {
  8034. db = db.Where("schedule_type = ?", scheduleType)
  8035. }
  8036. if partitonType > 0 {
  8037. db = db.Where("partition_id = ?", partitonType)
  8038. }
  8039. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  8040. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  8041. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  8042. }).
  8043. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  8044. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  8045. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  8046. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  8047. Preload("DoctorAdvices", adviceCondition...).
  8048. Where("status = 1 AND user_org_id = ?", orgID)
  8049. if scheduleDate != 0 {
  8050. db = db.Where("schedule_date = ?", scheduleDate)
  8051. }
  8052. err := db.Find(&vms).Error
  8053. return vms, err
  8054. }