mobile_dialysis_service.go 479KB

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