mobile_dialysis_service.go 393KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580
  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. }
  172. func (MSchedualPatientVMList) TableName() string {
  173. return "xt_patients"
  174. }
  175. type MSchedualPatientVM struct {
  176. ID int64 `gorm:"column:id" json:"id" form:"id"`
  177. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  178. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  179. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  180. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  181. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
  182. AdmissionNumber string `gorm:"column:admission_number" json:"admission_number" form:"admission_number"`
  183. Source int64 `gorm:"column:source" json:"source" form:"source"`
  184. Lapseto int64 `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
  185. PartitionId int64 `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
  186. BedId int64 `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
  187. Name string `gorm:"column:name" json:"name" form:"name"`
  188. Alias string `gorm:"column:alias" json:"alias" form:"alias"`
  189. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  190. Nation string `gorm:"column:nation" json:"nation" form:"nation"`
  191. NativePlace string `gorm:"column:native_place" json:"native_place" form:"native_place"`
  192. MaritalStatus int64 `gorm:"column:marital_status" json:"marital_status" form:"marital_status"`
  193. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  194. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  195. ReimbursementWayId int64 `gorm:"column:reimbursement_way_id" json:"reimbursement_way_id" form:"reimbursement_way_id"`
  196. HealthCareType int64 `gorm:"column:health_care_type" json:"health_care_type" form:"health_care_type"`
  197. HealthCareNo string `gorm:"column:health_care_no" json:"health_care_no" form:"health_care_no"`
  198. HealthCareDueDate int64 `gorm:"column:health_care_due_date" json:"health_care_due_date" form:"health_care_due_date"`
  199. Height int64 `gorm:"column:height" json:"height" form:"height"`
  200. BloodType int64 `gorm:"column:blood_type" json:"blood_type" form:"blood_type"`
  201. Rh int64 `gorm:"column:rh" json:"rh" form:"rh"`
  202. HealthCareDueAlertDate int64 `gorm:"column:health_care_due_alert_date" json:"health_care_due_alert_date" form:"health_care_due_alert_date"`
  203. EducationLevel int64 `gorm:"column:education_level" json:"education_level" form:"education_level"`
  204. Profession int64 `gorm:"column:profession" json:"profession" form:"profession"`
  205. Phone string `gorm:"column:phone" json:"phone" form:"phone"`
  206. HomeTelephone string `gorm:"column:home_telephone" json:"home_telephone" form:"home_telephone"`
  207. RelativePhone string `gorm:"column:relative_phone" json:"relative_phone" form:"relative_phone"`
  208. RelativeRelations string `gorm:"column:relative_relations" json:"relative_relations" form:"relative_relations"`
  209. HomeAddress string `gorm:"column:home_address" json:"home_address" form:"home_address"`
  210. WorkUnit string `gorm:"column:work_unit" json:"work_unit" form:"work_unit"`
  211. UnitAddress string `gorm:"column:unit_address" json:"unit_address" form:"unit_address"`
  212. Children int64 `gorm:"column:children" json:"children" form:"children"`
  213. ReceivingDate int64 `gorm:"column:receiving_date" json:"receiving_date" form:"receiving_date"`
  214. IsHospitalFirstDialysis int64 `gorm:"column:is_hospital_first_dialysis" json:"is_hospital_first_dialysis" form:"is_hospital_first_dialysis"`
  215. FirstDialysisDate int64 `gorm:"column:first_dialysis_date" json:"first_dialysis_date" form:"first_dialysis_date"`
  216. FirstDialysisHospital string `gorm:"column:first_dialysis_hospital" json:"first_dialysis_hospital" form:"first_dialysis_hospital"`
  217. InductionPeriod int64 `gorm:"column:induction_period" json:"induction_period" form:"induction_period"`
  218. InitialDialysis int64 `gorm:"column:initial_dialysis" json:"initial_dialysis" form:"initial_dialysis"`
  219. TotalDialysis int64 `gorm:"column:total_dialysis" json:"total_dialysis" form:"total_dialysis"`
  220. AttendingDoctorId int64 `gorm:"column:attending_doctor_id" json:"attending_doctor_id" form:"attending_doctor_id"`
  221. HeadNurseId int64 `gorm:"column:head_nurse_id" json:"head_nurse_id" form:"head_nurse_id"`
  222. Evaluate string `gorm:"column:evaluate" json:"evaluate" form:"evaluate"`
  223. Diagnose string `gorm:"column:diagnose" json:"diagnose" form:"diagnose"`
  224. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  225. RegistrarsId int64 `gorm:"column:registrars_id" json:"registrars_id" form:"registrars_id"`
  226. Registrars string `gorm:"column:registrars" json:"registrars" form:"registrars"`
  227. QrCode string `gorm:"column:qr_code" json:"qr_code" form:"qr_code"`
  228. BindingState int64 `gorm:"column:binding_state" json:"binding_state" form:"binding_state"`
  229. PatientComplains string `gorm:"column:patient_complains" json:"patient_complains"` // 主诉
  230. PresentHistory string `gorm:"column:present_history" json:"present_history"` // 现病史
  231. PastHistory string `gorm:"column:past_history" json:"past_history"` // 既往史
  232. Temperature float64 `gorm:"column:temperature" json:"temperature"` // 体格检查-体温
  233. Pulse int64 `gorm:"column:pulse" json:"pulse"` // 体格检查-脉搏
  234. Respiratory int64 `gorm:"column:respiratory" json:"respiratory"` // 体格检查-呼吸频率
  235. SBP int64 `gorm:"column:sbp" json:"sbp"` // 体格检查-收缩压
  236. DBP int64 `gorm:"column:dbp" json:"dbp"` // 体格检查-舒张压
  237. Status int64 `gorm:"column:status" json:"status" form:"status"`
  238. Age int64 `gorm:"column:age" json:"age"`
  239. IsOpenRemind int64 `gorm:"column:is_open_remind" json:"is_open_remind"`
  240. DialysisAge int64 `gorm:"column:dialysis_age" json:"dialysis_age" form:"dialysis_age"`
  241. ExpenseKind int64 `gorm:"column:expense_kind" json:"expense_kind" form:"expense_kind"`
  242. TellPhone string `gorm:"column:tell_phone" json:"tell_phone" form:"tell_phone"`
  243. FirstTreatmentDate int64 `gorm:"column:first_treatment_date" json:"first_treatment_date" form:"first_treatment_date"`
  244. ContactName string `gorm:"column:contact_name" json:"contact_name" form:"contact_name"`
  245. UserSysBeforeCount int64 `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
  246. }
  247. func (MSchedualPatientVM) TableName() string {
  248. return "xt_patients"
  249. }
  250. type MDialysisOrderVM struct {
  251. ID int64 `gorm:"column:id" json:"id"`
  252. DialysisDate int64 `gorm:"column:dialysis_date" json:"dialysis_date"`
  253. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  254. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  255. Stage int64 `gorm:"column:stage" json:"stage"`
  256. BedID int64 `gorm:"column:bed_id" json:"bed_id"`
  257. StartNurse int64 `gorm:"column:start_nurse" json:"start_nurse"`
  258. FinishNurse int64 `gorm:"column:finish_nurse" json:"finish_nurse"`
  259. Status int64 `gorm:"column:status" json:"status"`
  260. PunctureNurse int64 `gorm:"column:puncture_nurse" json:"puncture_nurse"`
  261. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedID" json:"device_number"`
  262. MonitoringRecords []*models.MonitoringRecord `gorm:"ForeignKey:DialysisOrderId" json:"monitoring_records"`
  263. Creator int64 `gorm:"column:creator" json:"creator"`
  264. Modifier int64 `gorm:"column:modifier" json:"modifier"`
  265. FinishCreator int64 `gorm:"column:finish_creator" json:"finish_creator"`
  266. FinishModifier int64 `gorm:"column:finish_modifier" json:"finish_modifier"`
  267. SchedualType int64 `gorm:"column:schedual_type" json:"schedual_type"`
  268. WashpipeNurse int64 `gorm:"column:washpipe_nurse" json:"washpipe_nurse" form:"washpipe_nurse"`
  269. DialysisIrrigation string `gorm:"column:dialysis_irrigation" json:"dialysis_irrigation" form:"dialysis_irrigation"`
  270. DialysisDialyszers string `gorm:"column:dialysis_dialyszers" json:"dialysis_dialyszers" form:"dialysis_dialyszers"`
  271. }
  272. func (MDialysisOrderVM) TableName() string {
  273. return "xt_dialysis_order"
  274. }
  275. type MDialysisOrderVMList struct {
  276. ID int64 `gorm:"column:id" json:"id"`
  277. DialysisDate int64 `gorm:"column:dialysis_date" json:"dialysis_date"`
  278. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  279. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  280. // PrescriptionId int64 `gorm:"column:prescription_id" json:"prescription_id"`
  281. Stage int64 `gorm:"column:stage" json:"stage"`
  282. // Remark string `gorm:"column:remark" json:"remark"`
  283. BedID int64 `gorm:"column:bed_id" json:"bed_id"`
  284. StartNurse int64 `gorm:"column:start_nurse" json:"start_nurse"`
  285. Status int64 `gorm:"column:status" json:"status"`
  286. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedID" json:"device_number"`
  287. Creator int64 `gorm:"column:creator" json:"creator"`
  288. WashpipeNurse int64 `gorm:"column:washpipe_nurse" json:"washpipe_nurse" form:"washpipe_nurse"`
  289. NucleinDate int64 `gorm:"column:nuclein_date" json:"nuclein_date" form:"nuclein_date"`
  290. DialysisIrrigation string `gorm:"column:dialysis_irrigation" json:"dialysis_irrigation" form:"dialysis_irrigation"`
  291. DialysisDialyszers string `gorm:"column:dialysis_dialyszers" json:"dialysis_dialyszers" form:"dialysis_dialyszers"`
  292. ScheduleRemark string `gorm:"column:schedule_remark" json:"schedule_remark" form:"schedule_remark"`
  293. }
  294. func (MDialysisOrderVMList) TableName() string {
  295. return "xt_dialysis_order"
  296. }
  297. type VMDoctorAdvice struct {
  298. ID int64 `gorm:"column:id" json:"id" form:"id"`
  299. GroupNo int64 `gorm:"column:groupno" json:"groupno" form:"groupno"`
  300. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  301. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  302. AdviceDate int64 `gorm:"column:advice_date" json:"advice_date" form:"advice_date"`
  303. Status int64 `gorm:"column:status" json:"status" form:"status"`
  304. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
  305. RecordDate int64 `gorm:"column:record_date" json:"record_date"`
  306. CheckTime int64 `gorm:"column:check_time" json:"check_time" form:"check_time"`
  307. CheckState int64 `gorm:"column:check_state" json:"check_state" form:"check_state"`
  308. ParentId int64 `gorm:"column:parent_id" json:"parent_id" form:"parent_id"`
  309. }
  310. func (VMDoctorAdvice) TableName() string {
  311. return "xt_doctor_advice"
  312. }
  313. type VMHisDoctorAdviceInfo struct {
  314. ID int64 `gorm:"column:id" json:"id" form:"id"`
  315. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  316. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  317. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  318. ExecutionTime int64 `gorm:"column:execution_time" json:"execution_time" form:"execution_time"`
  319. ExecutionStaff int64 `gorm:"column:execution_staff" json:"execution_staff" form:"execution_staff"`
  320. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
  321. IsMedicine int64 `gorm:"column:is_medicine" json:"is_medicine" form:"is_medicine"`
  322. ExecutionFrequencyId int64 `gorm:"column:execution_frequency_id" json:"execution_frequency_id" form:"execution_frequency_id"`
  323. }
  324. func (VMHisDoctorAdviceInfo) TableName() string {
  325. return "his_doctor_advice_info"
  326. }
  327. type VMAssessmentAfterDislysis struct {
  328. ID int64 `gorm:"column:id" json:"id"`
  329. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  330. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  331. AssessmentDate int64 `gorm:"column:assessment_date" json:"assessment_date"`
  332. WeightAfter float64 `gorm:"column:weight_after" json:"weight_after"`
  333. Status int64 `gorm:"column:status" json:"status"`
  334. }
  335. func (VMAssessmentAfterDislysis) TableName() string {
  336. return "xt_assessment_after_dislysis"
  337. }
  338. type NewDeviceInformation struct {
  339. ID int64 `gorm:"column:id" json:"id" form:"id"`
  340. Date int64 `gorm:"column:date" json:"date" form:"date"`
  341. Class int64 `gorm:"column:class" json:"class" form:"class"`
  342. Zone int64 `gorm:"column:zone" json:"zone" form:"zone"`
  343. BedNumber int64 `gorm:"column:bed_number" json:"bed_number" form:"bed_number"`
  344. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  345. Status int64 `gorm:"column:status" json:"status" form:"status"`
  346. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  347. EquimentId int64 `gorm:"column:equiment_id" json:"equiment_id" form:"equiment_id"`
  348. Bed string `gorm:"column:bed" json:"bed" form:"bed"`
  349. Stime int64 `gorm:"column:stime" json:"stime" form:"stime"`
  350. }
  351. func (NewDeviceInformation) TableName() string {
  352. return "xt_device_information"
  353. }
  354. // 获取透析记录
  355. func MobileGetDialysisRecord(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  356. var record models.DialysisOrder
  357. err := readDb.Model(&models.DialysisOrder{}).Where("user_org_id = ? AND patient_id = ? AND dialysis_date = ?", orgID, patientID, recordDate).First(&record).Error
  358. if err != nil {
  359. if err == gorm.ErrRecordNotFound {
  360. return nil, nil
  361. } else {
  362. return nil, err
  363. }
  364. }
  365. return &record, nil
  366. }
  367. // 用户基本信息
  368. func MobileGetPatientDetail(orgID int64, patientID int64) (*MPatient, error) {
  369. var patient MPatient
  370. //err := readDb.Model(&MPatient{}).Where("status = 1 AND user_org_id = ? AND id = ?", orgID, patientID).First(&patient).Error
  371. //if err != nil {
  372. // if err == gorm.ErrRecordNotFound {
  373. // return nil, nil
  374. // } else {
  375. // return nil, err
  376. // }
  377. //}
  378. //return &patient, nil
  379. redis := RedisClient()
  380. defer redis.Close()
  381. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":patient_info"
  382. patient_info_str, _ := redis.Get(key).Result()
  383. if len(patient_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  384. err = readDb.Model(&patient).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
  385. if err != nil {
  386. if err == gorm.ErrRecordNotFound {
  387. return &patient, nil
  388. } else {
  389. return &patient, err
  390. }
  391. } else {
  392. if patient.ID > 0 {
  393. //缓存数据
  394. patient_info_json, err := json.Marshal(&patient)
  395. if err == nil {
  396. redis.Set(key, patient_info_json, time.Second*60*60*18)
  397. }
  398. }
  399. return &patient, nil
  400. }
  401. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  402. json.Unmarshal([]byte(patient_info_str), &patient)
  403. return &patient, nil
  404. }
  405. }
  406. func MobileGetSchedualDetailOne(orgID int64, patientID int64, schedualDate int64) (*MDialysisScheduleVM, error) {
  407. var vm MDialysisScheduleVM
  408. err := readDb.
  409. Table("xt_schedule").
  410. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  411. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  412. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  413. First(&vm).Error
  414. return &vm, err
  415. }
  416. // 用户排班信息
  417. func MobileGetSchedualDetailSix(orgID int64, patientID int64, schedualDate int64) (*MDialysisScheduleVM, error) {
  418. var vm MDialysisScheduleVM
  419. err := readDb.
  420. Table("xt_schedule").
  421. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  422. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  423. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  424. First(&vm).Error
  425. if err != nil {
  426. if err == gorm.ErrRecordNotFound {
  427. return nil, nil
  428. } else {
  429. return nil, err
  430. }
  431. }
  432. return &vm, err
  433. }
  434. // 用户排班信息
  435. func MobileGetSchedualDetail(orgID int64, patientID int64, schedualDate int64) (*MDialysisScheduleVM, error) {
  436. redis := RedisClient()
  437. defer redis.Close()
  438. var vm MDialysisScheduleVM
  439. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(schedualDate, 10) + ":schedual_detail"
  440. redis.Set(key, "", time.Second)
  441. schedual_detail_str, _ := redis.Get(key).Result()
  442. if len(schedual_detail_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  443. err := readDb.
  444. Table("xt_schedule").
  445. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  446. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  447. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  448. First(&vm).Error
  449. if err != nil {
  450. if err == gorm.ErrRecordNotFound {
  451. return nil, nil
  452. } else {
  453. return nil, err
  454. }
  455. } else {
  456. if vm.ID > 0 {
  457. //缓存数据
  458. schedual_detail_str, err := json.Marshal(vm)
  459. if err == nil {
  460. redis.Set(key, schedual_detail_str, time.Second*60*60*18)
  461. }
  462. } else {
  463. redis.Set(key, "null", time.Second*60*60*18)
  464. }
  465. return &vm, nil
  466. }
  467. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  468. if schedual_detail_str == "null" {
  469. return &vm, nil
  470. }
  471. json.Unmarshal([]byte(schedual_detail_str), &vm)
  472. return &vm, nil
  473. }
  474. }
  475. // 用户排班信息
  476. func MobileGetPatientSchedual(orgID int64, patientID int64, schedualDate int64) (*models.Schedule, error) {
  477. var schedule models.Schedule
  478. err := readDb.
  479. Table("xt_schedule").
  480. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  481. First(&schedule).Error
  482. if err != nil {
  483. if err == gorm.ErrRecordNotFound {
  484. return nil, nil
  485. } else {
  486. return nil, err
  487. }
  488. }
  489. return &schedule, nil
  490. }
  491. type MPatient struct {
  492. ID int64 `gorm:"column:id" json:"id" form:"id"`
  493. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  494. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  495. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  496. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  497. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
  498. AdmissionNumber string `gorm:"column:admission_number" json:"admission_number" form:"admission_number"`
  499. Source int64 `gorm:"column:source" json:"source" form:"source"`
  500. Lapseto int64 `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
  501. PartitionId int64 `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
  502. BedId int64 `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
  503. Name string `gorm:"column:name" json:"name" form:"name"`
  504. Alias string `gorm:"column:alias" json:"alias" form:"alias"`
  505. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  506. Nation string `gorm:"column:nation" json:"nation" form:"nation"`
  507. NativePlace string `gorm:"column:native_place" json:"native_place" form:"native_place"`
  508. MaritalStatus int64 `gorm:"column:marital_status" json:"marital_status" form:"marital_status"`
  509. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  510. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  511. ReimbursementWayId int64 `gorm:"column:reimbursement_way_id" json:"reimbursement_way_id" form:"reimbursement_way_id"`
  512. HealthCareType int64 `gorm:"column:health_care_type" json:"health_care_type" form:"health_care_type"`
  513. HealthCareNo string `gorm:"column:health_care_no" json:"health_care_no" form:"health_care_no"`
  514. HealthCareDueDate int64 `gorm:"column:health_care_due_date" json:"health_care_due_date" form:"health_care_due_date"`
  515. Height int64 `gorm:"column:height" json:"height" form:"height"`
  516. BloodType int64 `gorm:"column:blood_type" json:"blood_type" form:"blood_type"`
  517. Rh int64 `gorm:"column:rh" json:"rh" form:"rh"`
  518. HealthCareDueAlertDate int64 `gorm:"column:health_care_due_alert_date" json:"health_care_due_alert_date" form:"health_care_due_alert_date"`
  519. EducationLevel int64 `gorm:"column:education_level" json:"education_level" form:"education_level"`
  520. Profession int64 `gorm:"column:profession" json:"profession" form:"profession"`
  521. Phone string `gorm:"column:phone" json:"phone" form:"phone"`
  522. HomeTelephone string `gorm:"column:home_telephone" json:"home_telephone" form:"home_telephone"`
  523. RelativePhone string `gorm:"column:relative_phone" json:"relative_phone" form:"relative_phone"`
  524. RelativeRelations string `gorm:"column:relative_relations" json:"relative_relations" form:"relative_relations"`
  525. HomeAddress string `gorm:"column:home_address" json:"home_address" form:"home_address"`
  526. WorkUnit string `gorm:"column:work_unit" json:"work_unit" form:"work_unit"`
  527. UnitAddress string `gorm:"column:unit_address" json:"unit_address" form:"unit_address"`
  528. Children int64 `gorm:"column:children" json:"children" form:"children"`
  529. ReceivingDate int64 `gorm:"column:receiving_date" json:"receiving_date" form:"receiving_date"`
  530. IsHospitalFirstDialysis int64 `gorm:"column:is_hospital_first_dialysis" json:"is_hospital_first_dialysis" form:"is_hospital_first_dialysis"`
  531. FirstDialysisDate int64 `gorm:"column:first_dialysis_date" json:"first_dialysis_date" form:"first_dialysis_date"`
  532. FirstDialysisHospital string `gorm:"column:first_dialysis_hospital" json:"first_dialysis_hospital" form:"first_dialysis_hospital"`
  533. InductionPeriod int64 `gorm:"column:induction_period" json:"induction_period" form:"induction_period"`
  534. InitialDialysis int64 `gorm:"column:initial_dialysis" json:"initial_dialysis" form:"initial_dialysis"`
  535. TotalDialysis int64 `gorm:"column:total_dialysis" json:"total_dialysis" form:"total_dialysis"`
  536. AttendingDoctorId int64 `gorm:"column:attending_doctor_id" json:"attending_doctor_id" form:"attending_doctor_id"`
  537. HeadNurseId int64 `gorm:"column:head_nurse_id" json:"head_nurse_id" form:"head_nurse_id"`
  538. Evaluate string `gorm:"column:evaluate" json:"evaluate" form:"evaluate"`
  539. Diagnose string `gorm:"column:diagnose" json:"diagnose" form:"diagnose"`
  540. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  541. RegistrarsId int64 `gorm:"column:registrars_id" json:"registrars_id" form:"registrars_id"`
  542. Registrars string `gorm:"column:registrars" json:"registrars" form:"registrars"`
  543. QrCode string `gorm:"column:qr_code" json:"qr_code" form:"qr_code"`
  544. BindingState int64 `gorm:"column:binding_state" json:"binding_state" form:"binding_state"`
  545. PatientComplains string `gorm:"column:patient_complains" json:"patient_complains"` // 主诉
  546. PresentHistory string `gorm:"column:present_history" json:"present_history"` // 现病史
  547. PastHistory string `gorm:"column:past_history" json:"past_history"` // 既往史
  548. Temperature float64 `gorm:"column:temperature" json:"temperature"` // 体格检查-体温
  549. Pulse int64 `gorm:"column:pulse" json:"pulse"` // 体格检查-脉搏
  550. Respiratory int64 `gorm:"column:respiratory" json:"respiratory"` // 体格检查-呼吸频率
  551. SBP int64 `gorm:"column:sbp" json:"sbp"` // 体格检查-收缩压
  552. DBP int64 `gorm:"column:dbp" json:"dbp"` // 体格检查-舒张压
  553. Status int64 `gorm:"column:status" json:"status" form:"status"`
  554. Age int64 `gorm:"column:age" json:"age"`
  555. IsOpenRemind int64 `gorm:"column:is_open_remind" json:"is_open_remind"`
  556. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  557. DialysisAge int64 `gorm:"column:dialysis_age" json:"dialysis_age" form:"dialysis_age"`
  558. ExpenseKind int64 `gorm:"column:expense_kind" json:"expense_kind" form:"expense_kind"`
  559. TellPhone string `gorm:"column:tell_phone" json:"tell_phone" form:"tell_phone"`
  560. FirstTreatmentDate int64 `gorm:"column:first_treatment_date" json:"first_treatment_date" form:"first_treatment_date"`
  561. ContactName string `gorm:"column:contact_name" json:"contact_name" form:"contact_name"`
  562. UserSysBeforeCount int64 `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
  563. }
  564. func (MPatient) TableName() string {
  565. return "xt_patients"
  566. }
  567. // 接诊评估
  568. func MobileGetReceiverTreatmentAccessRecord(orgID int64, patientID int64, recordDate int64) (*models.ReceiveTreatmentAsses, error) {
  569. var record models.ReceiveTreatmentAsses
  570. redis := RedisClient()
  571. defer redis.Close()
  572. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":receive_treatment_asses"
  573. receive_treatment_asses_str, _ := redis.Get(key).Result()
  574. if len(receive_treatment_asses_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  575. err = readDb.Model(&models.ReceiveTreatmentAsses{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  576. if err != nil {
  577. if err == gorm.ErrRecordNotFound {
  578. if record.ID <= 0 {
  579. redis.Set(key, "", time.Second*60*60*18)
  580. }
  581. return nil, nil
  582. } else {
  583. return nil, err
  584. }
  585. } else {
  586. if record.ID > 0 {
  587. //缓存数据
  588. receive_treatment_asses_str, err := json.Marshal(record)
  589. if err == nil {
  590. redis.Set(key, receive_treatment_asses_str, time.Second*60*60*18)
  591. }
  592. } else {
  593. redis.Set(key, "null", time.Second*60*60*18)
  594. }
  595. return &record, nil
  596. }
  597. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  598. if receive_treatment_asses_str == "null" {
  599. return &record, nil
  600. }
  601. json.Unmarshal([]byte(receive_treatment_asses_str), &record)
  602. return &record, nil
  603. }
  604. }
  605. // 透前评估
  606. func MobileGetPredialysisEvaluationOne(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
  607. var record models.PredialysisEvaluation
  608. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  609. if err != nil {
  610. if err == gorm.ErrRecordNotFound {
  611. return nil, nil
  612. } else {
  613. return nil, err
  614. }
  615. }
  616. return &record, nil
  617. }
  618. func MobileGetPredialysisEvaluationTwo(orgID int64, patientID int64, recordDate int64) (models.PredialysisEvaluation, error) {
  619. var record models.PredialysisEvaluation
  620. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  621. return record, err
  622. }
  623. // 透前评估
  624. func MobileGetPredialysisEvaluation(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
  625. var record models.PredialysisEvaluation
  626. redis := RedisClient()
  627. defer redis.Close()
  628. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":assessment_before_dislysis"
  629. assessment_before_dislysis_str, _ := redis.Get(key).Result()
  630. redis.Set(key, "", time.Second)
  631. if len(assessment_before_dislysis_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  632. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  633. if err != nil {
  634. if err == gorm.ErrRecordNotFound {
  635. if record.ID <= 0 {
  636. redis.Set(key, "", time.Second*60*60*18)
  637. }
  638. return nil, nil
  639. } else {
  640. return nil, err
  641. }
  642. } else {
  643. if record.ID > 0 {
  644. //缓存数据
  645. assessment_before_dislysis_str, err := json.Marshal(record)
  646. if err == nil {
  647. redis.Set(key, assessment_before_dislysis_str, time.Second*60*60*18)
  648. }
  649. } else {
  650. redis.Set(key, "null", time.Second*60*60*18)
  651. }
  652. return &record, nil
  653. }
  654. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  655. if assessment_before_dislysis_str == "null" {
  656. return &record, nil
  657. } else {
  658. json.Unmarshal([]byte(assessment_before_dislysis_str), &record)
  659. return &record, nil
  660. }
  661. }
  662. }
  663. // 获取 maxDate 之前一次的透前评估记录
  664. func MobileGetLastTimePredialysisEvaluationOne(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
  665. var record models.PredialysisEvaluation
  666. 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
  667. if err != nil {
  668. if err == gorm.ErrRecordNotFound {
  669. return nil, nil
  670. } else {
  671. return nil, err
  672. }
  673. }
  674. return &record, nil
  675. }
  676. // 获取 maxDate 之前一次的透前评估记录
  677. func MobileGetLastTimePredialysisEvaluation(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
  678. var record models.PredialysisEvaluation
  679. redis := RedisClient()
  680. defer redis.Close()
  681. // cur_date := time.Now().Format("2006-01-02")
  682. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(maxDate, 10) + ":assessment_before_dislysis_last"
  683. assessment_before_dislysis_last_str, _ := redis.Get(key).Result()
  684. if len(assessment_before_dislysis_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  685. 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
  686. if err != nil {
  687. if err == gorm.ErrRecordNotFound {
  688. if record.ID <= 0 {
  689. redis.Set(key, "", time.Second*60*60*18)
  690. }
  691. return nil, nil
  692. } else {
  693. return nil, err
  694. }
  695. } else {
  696. if record.ID > 0 {
  697. //缓存数据
  698. assessment_before_dislysis_last_str, err := json.Marshal(record)
  699. if err == nil {
  700. redis.Set(key, assessment_before_dislysis_last_str, time.Second*60*60*4)
  701. }
  702. } else {
  703. redis.Set(key, "null", time.Second*60*60*18)
  704. }
  705. return &record, nil
  706. }
  707. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  708. if assessment_before_dislysis_last_str == "null" {
  709. return &record, nil
  710. } else {
  711. json.Unmarshal([]byte(assessment_before_dislysis_last_str), &record)
  712. return &record, nil
  713. }
  714. }
  715. }
  716. // 临时医嘱
  717. func MobileGetDoctorAdvices(orgID int64, patientID int64, recordDate int64) ([]*models.DoctorAdvice, error) {
  718. var records []*models.DoctorAdvice
  719. // err := readDb.Model(&models.DoctorAdvice{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).Find(&records).Error
  720. err := readDb.
  721. Model(&models.DoctorAdvice{}).
  722. Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? and (advice_type = 2 or advice_type = 3)", patientID, orgID, recordDate).
  723. 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").
  724. Order("start_time asc, groupno desc, advice_order desc, id").
  725. Scan(&records).Error
  726. if err != nil {
  727. return nil, err
  728. }
  729. return records, nil
  730. }
  731. func MobileGetDoctorAdvicesByGroups(orgID int64, patientID int64, recordDate int64) ([]*models.DoctorAdvice, error) {
  732. var records []*models.DoctorAdvice
  733. redis := RedisClient()
  734. defer redis.Close()
  735. // cur_date := time.Now().Format("2006-01-02")
  736. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":doctor_advices"
  737. //fmt.Println("key23233232323323wi", key)
  738. redis.Set(key, "", time.Second)
  739. doctor_advices_str, _ := redis.Get(key).Result()
  740. if len(doctor_advices_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  741. err := readDb.Model(&models.DoctorAdvice{}).
  742. Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? and (advice_type = 2 || advice_type = 3)", patientID, orgID, recordDate).
  743. 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").
  744. Order("start_time asc, groupno desc, advice_order desc, id asc").
  745. Scan(&records).Error
  746. if err != nil {
  747. if err == gorm.ErrRecordNotFound {
  748. if len(records) <= 0 {
  749. redis.Set(key, "", time.Second*60*60*18)
  750. }
  751. return nil, nil
  752. } else {
  753. return nil, err
  754. }
  755. } else {
  756. if len(records) > 0 {
  757. //缓存数据
  758. doctor_advices_str, err := json.Marshal(records)
  759. if err == nil {
  760. redis.Set(key, doctor_advices_str, time.Second*60*60*18)
  761. return records, nil
  762. }
  763. } else {
  764. redis.Set(key, "null", time.Second*60*60*18)
  765. return records, nil
  766. }
  767. return records, nil
  768. }
  769. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  770. if doctor_advices_str == "null" {
  771. return records, nil
  772. } else {
  773. json.Unmarshal([]byte(doctor_advices_str), &records)
  774. return records, nil
  775. }
  776. }
  777. }
  778. // 透析记录
  779. func MobileGetSchedualDialysisRecordTen(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  780. var record models.DialysisOrder
  781. 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
  782. if err != nil {
  783. if err == gorm.ErrRecordNotFound {
  784. return nil, nil
  785. } else {
  786. return nil, err
  787. }
  788. }
  789. return &record, nil
  790. }
  791. //func MobileGetSchedualDialysisRecord(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  792. // var record models.DialysisOrder
  793. //
  794. // 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
  795. //
  796. //
  797. // return &record,err
  798. //}
  799. // 透析记录
  800. func MobileGetSchedualDialysisRecord(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  801. var record models.DialysisOrder
  802. redis := RedisClient()
  803. defer redis.Close()
  804. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":dialysis_order"
  805. dialysis_order_str, _ := redis.Get(key).Result()
  806. if len(dialysis_order_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  807. 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
  808. if err != nil {
  809. if err == gorm.ErrRecordNotFound {
  810. return nil, nil
  811. } else {
  812. return nil, err
  813. }
  814. } else {
  815. if record.ID > 0 {
  816. //缓存数据
  817. dialysis_order_str, err := json.Marshal(record)
  818. if err == nil {
  819. redis.Set(key, dialysis_order_str, time.Second*60*60*18)
  820. }
  821. } else {
  822. redis.Set(key, "null", time.Second*60*60*18)
  823. }
  824. return &record, nil
  825. }
  826. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  827. if dialysis_order_str == "null" {
  828. 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
  829. return &record, nil
  830. } else {
  831. json.Unmarshal([]byte(dialysis_order_str), &record)
  832. return &record, nil
  833. }
  834. }
  835. }
  836. // 双人核对
  837. func MobileGetDoubleCheck(orgID int64, patientID int64, recordDate int64) (*models.DoubleCheck, error) {
  838. var record models.DoubleCheck
  839. redis := RedisClient()
  840. defer redis.Close()
  841. // cur_date := time.Now().Format("2006-01-02")
  842. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":double_check"
  843. double_check_str, _ := redis.Get(key).Result()
  844. if len(double_check_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  845. err := readDb.Model(&models.DoubleCheck{}).Where("patient_id = ? and user_org_id = ? and status = 1 and check_date = ?", patientID, orgID, recordDate).First(&record).Error
  846. if err != nil {
  847. if err == gorm.ErrRecordNotFound {
  848. if record.ID <= 0 {
  849. redis.Set(key, "null", time.Second*60*60*18)
  850. }
  851. return nil, nil
  852. } else {
  853. return nil, err
  854. }
  855. } else {
  856. if record.ID > 0 {
  857. //缓存数据
  858. double_check_str, err := json.Marshal(record)
  859. if err == nil {
  860. redis.Set(key, double_check_str, time.Second*60*60*18)
  861. }
  862. } else {
  863. redis.Set(key, "null", time.Second*60*60*18)
  864. }
  865. return &record, nil
  866. }
  867. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  868. if double_check_str == "null" {
  869. return &record, nil
  870. } else {
  871. json.Unmarshal([]byte(double_check_str), &record)
  872. return &record, nil
  873. }
  874. }
  875. }
  876. // 透析监测记录
  877. func MobileGetMonitorRecords(orgID int64, patientID int64, recordDate int64) ([]*models.MonitoringRecord, error) {
  878. var records []*models.MonitoringRecord
  879. redis := RedisClient()
  880. defer redis.Close()
  881. // cur_date := time.Now().Format("2006-01-02")
  882. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":monitor_records"
  883. redis.Set(key, "", time.Second)
  884. monitor_records_str, _ := redis.Get(key).Result()
  885. if len(monitor_records_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  886. 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
  887. if err != nil {
  888. if err == gorm.ErrRecordNotFound {
  889. //if len(records) <= 0 {
  890. // redis.Set(key, "null", time.Second*60*60*18)
  891. //}
  892. return nil, nil
  893. } else {
  894. return nil, err
  895. }
  896. } else {
  897. if len(records) > 0 {
  898. //缓存数据
  899. monitor_records_str, err := json.Marshal(records)
  900. if err == nil {
  901. redis.Set(key, monitor_records_str, time.Second*60*60*18)
  902. }
  903. } else {
  904. redis.Set(key, "null", time.Second*60*60*18)
  905. }
  906. return records, nil
  907. }
  908. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  909. if monitor_records_str == "null" {
  910. return records, nil
  911. } else {
  912. json.Unmarshal([]byte(monitor_records_str), &records)
  913. return records, nil
  914. }
  915. }
  916. }
  917. func MobileGetMonitorRecordFirst(orgID int64, patientID int64, recordDate int64) (*models.MonitoringRecord, error) {
  918. var records models.MonitoringRecord
  919. 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
  920. if err != nil {
  921. return nil, err
  922. }
  923. return &records, nil
  924. }
  925. func MobileGetLastMonitorRecordOne(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  926. var record models.MonitoringRecord
  927. 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
  928. if err != nil {
  929. if err == gorm.ErrRecordNotFound {
  930. return nil, nil
  931. } else {
  932. return nil, err
  933. }
  934. }
  935. return &record, nil
  936. }
  937. func MobileGetLastMonitorRecord(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  938. var record models.MonitoringRecord
  939. redis := RedisClient()
  940. defer redis.Close()
  941. // cur_date := time.Now().Format("2006-01-02")
  942. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(beforeDate, 10) + ":monitor_record_last"
  943. monitor_record_last_str, _ := redis.Get(key).Result()
  944. if len(monitor_record_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  945. 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
  946. if err != nil {
  947. if err == gorm.ErrRecordNotFound {
  948. if record.ID <= 0 {
  949. redis.Set(key, "null", time.Second*60*60*18)
  950. }
  951. return nil, nil
  952. } else {
  953. return nil, err
  954. }
  955. } else {
  956. if record.ID > 0 {
  957. //缓存数据
  958. monitor_record_last_str, err := json.Marshal(record)
  959. if err == nil {
  960. redis.Set(key, monitor_record_last_str, time.Second*60*60*18)
  961. }
  962. } else {
  963. redis.Set(key, "null", time.Second*60*60*18)
  964. }
  965. return &record, nil
  966. }
  967. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  968. if monitor_record_last_str == "null" {
  969. return &record, nil
  970. } else {
  971. json.Unmarshal([]byte(monitor_record_last_str), &record)
  972. return &record, nil
  973. }
  974. }
  975. }
  976. func MobileGetAssessmentAfterDislysisOne(orgID int64, patientID int64, recordDate int64) (*models.AssessmentAfterDislysis, error) {
  977. var record models.AssessmentAfterDislysis
  978. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  979. if err != nil {
  980. if err == gorm.ErrRecordNotFound {
  981. return nil, nil
  982. } else {
  983. return nil, err
  984. }
  985. }
  986. return &record, nil
  987. }
  988. // 透后评估
  989. func MobileGetAssessmentAfterDislysis(orgID int64, patientID int64, recordDate int64) (*models.AssessmentAfterDislysis, error) {
  990. var record models.AssessmentAfterDislysis
  991. redis := RedisClient()
  992. defer redis.Close()
  993. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":assessment_after_dislysis"
  994. redis.Set(key, "", time.Second)
  995. assessment_after_dislysis_str, _ := redis.Get(key).Result()
  996. if len(assessment_after_dislysis_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  997. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  998. if err != nil {
  999. if err == gorm.ErrRecordNotFound {
  1000. if record.ID <= 0 {
  1001. redis.Set(key, "null", time.Second*60*60*18)
  1002. }
  1003. return nil, nil
  1004. } else {
  1005. return nil, err
  1006. }
  1007. } else {
  1008. if record.ID > 0 {
  1009. //缓存数据
  1010. assessment_after_dislysis_str, err := json.Marshal(record)
  1011. if err == nil {
  1012. redis.Set(key, assessment_after_dislysis_str, time.Second*60*60*18)
  1013. }
  1014. } else {
  1015. redis.Set(key, "null", time.Second*60*60*18)
  1016. }
  1017. return &record, nil
  1018. }
  1019. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1020. if assessment_after_dislysis_str == "null" {
  1021. return &record, nil
  1022. } else {
  1023. json.Unmarshal([]byte(assessment_after_dislysis_str), &record)
  1024. return &record, nil
  1025. }
  1026. }
  1027. }
  1028. // 获取 maxDate 之前一次的透后评估记录
  1029. func MobileGetLastTimeAssessmentAfterDislysis(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  1030. var record models.AssessmentAfterDislysis
  1031. redis := RedisClient()
  1032. defer redis.Close()
  1033. // cur_date := time.Now().Format("2006-01-02")
  1034. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(maxDate, 10) + ":assessment_after_dislysis_last"
  1035. assessment_after_dislysis_last_str, _ := redis.Get(key).Result()
  1036. if len(assessment_after_dislysis_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1037. 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
  1038. if err != nil {
  1039. if err == gorm.ErrRecordNotFound {
  1040. if record.ID <= 0 {
  1041. redis.Set(key, "null", time.Second*60*60*18)
  1042. }
  1043. return nil, nil
  1044. } else {
  1045. return nil, err
  1046. }
  1047. } else {
  1048. if record.ID > 0 {
  1049. //缓存数据
  1050. assessment_after_dislysis_last_str, err := json.Marshal(record)
  1051. if err == nil {
  1052. redis.Set(key, assessment_after_dislysis_last_str, time.Second*60*60*18)
  1053. }
  1054. } else {
  1055. redis.Set(key, "null", time.Second*60*60*18)
  1056. }
  1057. return &record, nil
  1058. }
  1059. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1060. if assessment_after_dislysis_last_str == "null" {
  1061. return &record, nil
  1062. } else {
  1063. json.Unmarshal([]byte(assessment_after_dislysis_last_str), &record)
  1064. return &record, nil
  1065. }
  1066. }
  1067. }
  1068. func MobileGetLastTimeAssessmentAfterDislysisOne(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  1069. var record models.AssessmentAfterDislysis
  1070. 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
  1071. if err != nil {
  1072. if err == gorm.ErrRecordNotFound {
  1073. return nil, nil
  1074. } else {
  1075. return nil, err
  1076. }
  1077. }
  1078. return &record, nil
  1079. }
  1080. func MobileGetLast(orgID int64, patientID int64, maxDate int64) (models.AssessmentAfterDislysis, error) {
  1081. dislysis := models.AssessmentAfterDislysis{}
  1082. 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
  1083. return dislysis, err
  1084. }
  1085. // 治疗小结
  1086. func MobileGetTreatmentSummary(orgID int64, patientID int64, recordDate int64) (*models.TreatmentSummary, error) {
  1087. var record models.TreatmentSummary
  1088. redis := RedisClient()
  1089. defer redis.Close()
  1090. // cur_date := time.Now().Format("2006-01-02")
  1091. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":treatment_summary"
  1092. treatment_summary_str, _ := redis.Get(key).Result()
  1093. if len(treatment_summary_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1094. err := readDb.Model(&models.TreatmentSummary{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  1095. if err != nil {
  1096. if err == gorm.ErrRecordNotFound {
  1097. if record.ID <= 0 {
  1098. redis.Set(key, "null", time.Second*60*60*18)
  1099. }
  1100. return nil, nil
  1101. } else {
  1102. return nil, err
  1103. }
  1104. } else {
  1105. if record.ID > 0 {
  1106. //缓存数据
  1107. treatment_summary_str, err := json.Marshal(record)
  1108. if err == nil {
  1109. redis.Set(key, treatment_summary_str, time.Second*60*60*18)
  1110. }
  1111. } else {
  1112. redis.Set(key, "null", time.Second*60*60*18)
  1113. }
  1114. return &record, nil
  1115. }
  1116. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1117. if treatment_summary_str == "null" {
  1118. return &record, nil
  1119. } else {
  1120. json.Unmarshal([]byte(treatment_summary_str), &record)
  1121. return &record, nil
  1122. }
  1123. }
  1124. }
  1125. // 透析处方
  1126. func MobileGetDialysisPrescribe(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  1127. var record models.DialysisPrescription
  1128. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).Find(&record).Error
  1129. if err != nil {
  1130. if err == gorm.ErrRecordNotFound {
  1131. return nil, nil
  1132. } else {
  1133. return nil, err
  1134. }
  1135. }
  1136. return &record, nil
  1137. }
  1138. func MobileGetDialysisSchedual(orgID int64, patientID int64, scheduleDate int64) (*models.XtSchedule, error) {
  1139. var schedule models.XtSchedule
  1140. err := readDb.Model(&models.XtSchedule{}).Where("patient_id = ? and user_org_id = ? and status = 1 and schedule_date = ?", patientID, orgID, scheduleDate).First(&schedule).Error
  1141. if err != nil {
  1142. if err == gorm.ErrRecordNotFound {
  1143. return nil, nil
  1144. } else {
  1145. return nil, err
  1146. }
  1147. }
  1148. return &schedule, nil
  1149. }
  1150. // 透析方案
  1151. func MobileGetDialysisSolution(orgID int64, patientID int64) (*models.DialysisSolution, error) {
  1152. var record models.DialysisSolution
  1153. err := readDb.Model(&models.DialysisSolution{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  1154. if err != nil {
  1155. if err == gorm.ErrRecordNotFound {
  1156. return nil, nil
  1157. } else {
  1158. return nil, err
  1159. }
  1160. }
  1161. return &record, nil
  1162. }
  1163. func MobileGetPatientById(orgID int64, patientID int64) (*models.Patients, error) {
  1164. var patient models.Patients
  1165. err := readDb.Model(&models.Patients{}).Where("id = ? and user_org_id = ? and status = 1", patientID, orgID).First(&patient).Error
  1166. if err != nil {
  1167. if err == gorm.ErrRecordNotFound {
  1168. return nil, nil
  1169. } else {
  1170. return nil, err
  1171. }
  1172. }
  1173. return &patient, nil
  1174. }
  1175. func DisableMonitor(orgID int64, patientID int64, recordID int64, admin_user_id int64) error {
  1176. fmt.Println()
  1177. tx := writeDb.Begin()
  1178. updateTime := time.Now().Unix()
  1179. 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
  1180. if err != nil {
  1181. tx.Rollback()
  1182. return err
  1183. }
  1184. tx.Commit()
  1185. return nil
  1186. }
  1187. func GetMonitorById(id int64, orgId int64) (models.MonitoringRecord, error) {
  1188. record := models.MonitoringRecord{}
  1189. err := XTReadDB().Where("id = ? and user_org_id =?", id, orgId).Find(&record).Error
  1190. return record, err
  1191. }
  1192. func GetMonitor(orgID int64, patientID int64, id int64) (*models.MonitoringRecord, error) {
  1193. var monitor models.MonitoringRecord
  1194. var err error
  1195. err = readDb.Model(&models.MonitoringRecord{}).Where("id = ? AND user_org_id = ? AND patient_id = ? AND status = 1 ", id, orgID, patientID).Find(&monitor).Error
  1196. if err == gorm.ErrRecordNotFound {
  1197. return nil, nil
  1198. }
  1199. if err != nil {
  1200. return nil, err
  1201. }
  1202. return &monitor, nil
  1203. }
  1204. type MScheduleDoctorAdviceVM struct {
  1205. ID int64 `gorm:"column:id" json:"id"`
  1206. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  1207. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  1208. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  1209. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1210. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  1211. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  1212. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  1213. Status int64 `gorm:"column:status" json:"status"`
  1214. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  1215. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  1216. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  1217. DoctorAdvices []*MDoctorAdviceVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  1218. Prescription *models.DialysisPrescriptionTwenty `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  1219. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  1220. }
  1221. func (MScheduleDoctorAdviceVM) TableName() string {
  1222. return "xt_schedule"
  1223. }
  1224. type MScheduleDoctorAdviceVMOne struct {
  1225. ID int64 `gorm:"column:id" json:"id"`
  1226. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  1227. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  1228. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  1229. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1230. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  1231. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  1232. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  1233. Status int64 `gorm:"column:status" json:"status"`
  1234. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  1235. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  1236. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  1237. DoctorAdvices []*MDoctorAdviceVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  1238. Prescription *models.DialysisPrescriptionTwenty `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  1239. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  1240. }
  1241. func (MScheduleDoctorAdviceVMOne) TableName() string {
  1242. return "xt_schedule"
  1243. }
  1244. type MDoctorAdviceVM struct {
  1245. ID int64 `gorm:"column:id" json:"id"`
  1246. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  1247. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1248. AdviceType int64 `gorm:"column:advice_type" json:"advice_type"`
  1249. AdviceDate int64 `gorm:"column:advice_date" json:"advice_date"`
  1250. StartTime int64 `gorm:"column:start_time" json:"start_time"`
  1251. AdviceName string `gorm:"column:advice_name" json:"advice_name"`
  1252. AdviceDesc string `gorm:"column:advice_desc" json:"advice_desc"`
  1253. ReminderDate int64 `gorm:"column:reminder_date" json:"reminder_date"`
  1254. SingleDose float64 `gorm:"column:single_dose" json:"single_dose"`
  1255. SingleDoseUnit string `gorm:"column:single_dose_unit" json:"single_dose_unit"`
  1256. PrescribingNumber float64 `gorm:"column:prescribing_number" json:"prescribing_number"`
  1257. PrescribingNumberUnit string `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit"`
  1258. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way"`
  1259. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency"`
  1260. AdviceDoctor int64 `gorm:"column:advice_doctor" json:"advice_doctor"`
  1261. Status int64 `gorm:"column:status" json:"status"`
  1262. CreatedTime int64 `gorm:"column:created_time" json:"created_time"`
  1263. UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time"`
  1264. AdviceAffirm string `gorm:"column:advice_affirm" json:"advice_affirm"`
  1265. Remark string `gorm:"column:remark" json:"remark"`
  1266. StopTime int64 `gorm:"column:stop_time" json:"stop_time"`
  1267. StopReason string `gorm:"column:stop_reason" json:"stop_reason"`
  1268. StopDoctor int64 `gorm:"column:stop_doctor" json:"stop_doctor"`
  1269. StopState int64 `gorm:"column:stop_state" json:"stop_state"`
  1270. ParentId int64 `gorm:"column:parent_id" json:"parent_id"`
  1271. ExecutionTime int64 `gorm:"column:execution_time" json:"execution_time"`
  1272. ExecutionStaff int64 `gorm:"column:execution_staff" json:"execution_staff"`
  1273. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state"`
  1274. Checker int64 `gorm:"column:checker" json:"checker"`
  1275. RecordDate int64 `gorm:"column:record_date" json:"record_date"`
  1276. DialysisOrderId int64 `gorm:"column:dialysis_order_id" json:"dialysis_order_id"`
  1277. CheckTime int64 `gorm:"column:check_time" json:"check_time"`
  1278. CheckState int64 `gorm:"column:check_state" json:"check_state"`
  1279. DrugSpec float64 `gorm:"column:drug_spec" json:"drug_spec"`
  1280. DrugSpecUnit string `gorm:"column:drug_spec_unit" json:"drug_spec_unit"`
  1281. Groupno int64 `gorm:"column:groupno" json:"groupno"`
  1282. RemindType int64 `gorm:"column:remind_type" json:"remind_type"`
  1283. FrequencyType int64 `gorm:"column:frequency_type" json:"frequency_type"`
  1284. DayCount int64 `gorm:"column:day_count" json:"day_count"`
  1285. WeekDay string `gorm:"column:week_day" json:"week_day"`
  1286. TemplateId string `gorm:"column:template_id" json:"template_id"`
  1287. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1288. IsMedicine int64 `gorm:"column:is_medicine" json:"is_medicine" form:"is_medicine"`
  1289. IsSettle int64 `gorm:"column:is_settle" json:"is_settle" form:"is_settle"`
  1290. }
  1291. func (MDoctorAdviceVM) TableName() string {
  1292. return "xt_doctor_advice"
  1293. }
  1294. func MobileGetScheduleDoctorAdvices(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string) ([]*MScheduleDoctorAdviceVM, error) {
  1295. var vms []*MScheduleDoctorAdviceVM
  1296. adviceWhere := ""
  1297. adviceCondition := []interface{}{}
  1298. if adviceType == 0 {
  1299. if patientType == 0 {
  1300. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  1301. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1302. } else if patientType == 1 {
  1303. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  1304. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1305. } else if patientType == 2 {
  1306. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  1307. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1308. }
  1309. } else if adviceType == 1 {
  1310. if patientType == 0 {
  1311. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  1312. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1313. } else if patientType == 1 {
  1314. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  1315. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1316. } else if patientType == 2 {
  1317. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  1318. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1319. }
  1320. } else if adviceType == 3 {
  1321. if patientType == 0 {
  1322. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  1323. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1324. } else if patientType == 1 {
  1325. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  1326. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1327. } else if patientType == 2 {
  1328. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  1329. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1330. }
  1331. } else if adviceType == 2 && len(deliverWay) > 0 {
  1332. if patientType == 0 {
  1333. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  1334. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1335. } else if patientType == 1 {
  1336. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  1337. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  1338. } else if patientType == 2 {
  1339. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  1340. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1341. }
  1342. } else if adviceType == 2 && len(deliverWay) <= 0 {
  1343. if patientType == 0 {
  1344. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  1345. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1346. } else if patientType == 1 {
  1347. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND (advice_doctor = ? or execution_staff = ?)"
  1348. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, adminUserId)
  1349. } else if patientType == 2 {
  1350. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  1351. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1352. }
  1353. }
  1354. db := readDb.
  1355. Table("xt_schedule").
  1356. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1357. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1358. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1359. }).
  1360. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1361. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1362. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1363. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  1364. Preload("DoctorAdvices", adviceCondition...).
  1365. Where("status = 1 AND user_org_id = ?", orgID)
  1366. if scheduleDate != 0 {
  1367. db = db.Where("schedule_date = ?", scheduleDate)
  1368. }
  1369. err := db.Find(&vms).Error
  1370. return vms, err
  1371. }
  1372. func MobileGetScheduleDoctorAdvicesTwo(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string) ([]*MScheduleDoctorAdviceVMOne, error) {
  1373. var vms []*MScheduleDoctorAdviceVMOne
  1374. adviceWhere := ""
  1375. adviceCondition := []interface{}{}
  1376. if adviceType == 0 {
  1377. if patientType == 0 {
  1378. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  1379. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1380. } else if patientType == 1 {
  1381. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  1382. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1383. } else if patientType == 2 {
  1384. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  1385. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1386. } else if patientType == 3 {
  1387. 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"
  1388. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1389. } else if patientType == 4 {
  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 = 0 or is_settle = 2)"
  1391. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1392. }
  1393. } else if adviceType == 1 {
  1394. if patientType == 0 {
  1395. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  1396. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1397. } else if patientType == 1 {
  1398. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  1399. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1400. } else if patientType == 2 {
  1401. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  1402. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1403. } else if patientType == 3 {
  1404. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = 1"
  1405. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1406. } else if patientType == 4 {
  1407. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and (is_settle = 0 or is_settle = 2)"
  1408. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1409. }
  1410. } else if adviceType == 3 {
  1411. if patientType == 0 {
  1412. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  1413. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1414. } else if patientType == 1 {
  1415. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  1416. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1417. } else if patientType == 2 {
  1418. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  1419. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1420. } else if patientType == 3 {
  1421. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 and is_settle = 1"
  1422. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1423. } else if patientType == 4 {
  1424. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 and (is_settle = 0 or is_settle = 2)"
  1425. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1426. }
  1427. } else if adviceType == 2 && len(deliverWay) > 0 {
  1428. if patientType == 0 {
  1429. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  1430. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1431. } else if patientType == 1 {
  1432. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  1433. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  1434. } else if patientType == 2 {
  1435. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  1436. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1437. } else if patientType == 3 {
  1438. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 and delivery_way = ? and is_settle = 1"
  1439. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1440. } else if patientType == 4 {
  1441. 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)"
  1442. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1443. }
  1444. } else if adviceType == 2 && len(deliverWay) <= 0 {
  1445. if patientType == 0 {
  1446. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  1447. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1448. } else if patientType == 1 {
  1449. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND (advice_doctor = ? or execution_staff = ?)"
  1450. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, adminUserId)
  1451. } else if patientType == 2 {
  1452. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  1453. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1454. } else if patientType == 3 {
  1455. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 and is_settle = 1"
  1456. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1457. } else if patientType == 4 {
  1458. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 and (is_settle = 0 or is_settle = 2)"
  1459. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1460. }
  1461. }
  1462. db := readDb.
  1463. Table("xt_schedule").
  1464. //Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1465. //Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1466. // return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1467. //}).
  1468. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1469. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1470. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1471. Preload("DoctorAdvices", adviceCondition...).
  1472. Where("status = 1 AND user_org_id = ?", orgID)
  1473. if scheduleDate != 0 {
  1474. db = db.Where("schedule_date = ?", scheduleDate)
  1475. }
  1476. err := db.Find(&vms).Error
  1477. return vms, err
  1478. }
  1479. func GetHisDoctorAdvices(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleDoctorAdviceVM, error) {
  1480. var vms []*HisMScheduleDoctorAdviceVM
  1481. if len(deliverWay) > 0 {
  1482. if patientType == 0 {
  1483. db := readDb.
  1484. Table("xt_schedule").
  1485. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  1486. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1487. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1488. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1489. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1490. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1491. }).
  1492. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1493. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1494. Where("status = 1 AND user_org_id = ?", orgID)
  1495. if scheduleDate != 0 {
  1496. db = db.Where("schedule_date = ?", scheduleDate)
  1497. }
  1498. err = db.Find(&vms).Error
  1499. }
  1500. if patientType > 0 {
  1501. db := readDb.
  1502. Table("xt_schedule").
  1503. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1504. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1505. 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).
  1506. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1507. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1508. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1509. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1510. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1511. }).Where("status = 1 AND user_org_id = ?", orgID)
  1512. if scheduleDate != 0 {
  1513. db = db.Where("schedule_date = ?", scheduleDate)
  1514. }
  1515. err = db.Find(&vms).Error
  1516. }
  1517. } else {
  1518. if patientType == 0 {
  1519. db := readDb.
  1520. Table("xt_schedule").
  1521. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? ", orgID, scheduleDate).
  1522. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1523. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1524. return db.Where("status = 1 AND user_org_id = ? and dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1525. }).
  1526. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1527. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1528. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1529. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1530. Where("status = 1 AND user_org_id = ?", orgID)
  1531. if scheduleDate != 0 {
  1532. db = db.Where("schedule_date = ?", scheduleDate)
  1533. }
  1534. err = db.Find(&vms).Error
  1535. }
  1536. if patientType > 0 {
  1537. db := readDb.
  1538. Table("xt_schedule").
  1539. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1540. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1541. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1542. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1543. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1544. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1545. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1546. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1547. Where("status = 1 AND user_org_id = ?", orgID)
  1548. if scheduleDate != 0 {
  1549. db = db.Where("schedule_date = ?", scheduleDate)
  1550. }
  1551. err = db.Find(&vms).Error
  1552. }
  1553. }
  1554. return vms, err
  1555. }
  1556. func GetHisDoctorAdvicesTwo(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleDoctorAdviceVMOne, error) {
  1557. var vms []*HisMScheduleDoctorAdviceVMOne
  1558. if len(deliverWay) > 0 {
  1559. if patientType == 0 {
  1560. db := readDb.
  1561. Table("xt_schedule").
  1562. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  1563. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1564. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1565. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1566. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1567. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1568. }).
  1569. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1570. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1571. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1572. Where("status = 1 AND user_org_id = ?", orgID)
  1573. if scheduleDate != 0 {
  1574. db = db.Where("schedule_date = ?", scheduleDate)
  1575. }
  1576. err = db.Find(&vms).Error
  1577. }
  1578. if patientType > 0 {
  1579. if patientType == 1 {
  1580. db := readDb.
  1581. Table("xt_schedule").
  1582. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1583. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1584. 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).
  1585. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1586. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1587. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1588. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1589. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1590. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1591. Where("status = 1 AND user_org_id = ?", orgID)
  1592. if scheduleDate != 0 {
  1593. db = db.Where("schedule_date = ?", scheduleDate)
  1594. }
  1595. err = db.Find(&vms).Error
  1596. }
  1597. if patientType == 2 {
  1598. db := readDb.
  1599. Table("xt_schedule").
  1600. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1601. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1602. 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).
  1603. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1604. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1605. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1606. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1607. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1608. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Where("status = 1 AND user_org_id = ?", orgID)
  1609. if scheduleDate != 0 {
  1610. db = db.Where("schedule_date = ?", scheduleDate)
  1611. }
  1612. err = db.Find(&vms).Error
  1613. }
  1614. if patientType == 3 {
  1615. db := readDb.
  1616. Table("xt_schedule").
  1617. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1618. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1619. 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).
  1620. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1621. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1622. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1623. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1624. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1625. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Where("status = 1 AND user_org_id = ?", orgID)
  1626. if scheduleDate != 0 {
  1627. db = db.Where("schedule_date = ?", scheduleDate)
  1628. }
  1629. err = db.Find(&vms).Error
  1630. }
  1631. if patientType == 4 {
  1632. db := readDb.
  1633. Table("xt_schedule").
  1634. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1635. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1636. 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).
  1637. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1638. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1639. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1640. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1641. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1642. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Where("status = 1 AND user_org_id = ?", orgID)
  1643. if scheduleDate != 0 {
  1644. db = db.Where("schedule_date = ?", scheduleDate)
  1645. }
  1646. err = db.Find(&vms).Error
  1647. }
  1648. }
  1649. } else {
  1650. if patientType == 0 {
  1651. db := readDb.
  1652. Table("xt_schedule").
  1653. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? ", orgID, scheduleDate).
  1654. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1655. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1656. return db.Where("status = 1 AND user_org_id = ? and dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1657. }).
  1658. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1659. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1660. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1661. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1662. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1663. Where("status = 1 AND user_org_id = ?", orgID)
  1664. if scheduleDate != 0 {
  1665. db = db.Where("schedule_date = ?", scheduleDate)
  1666. }
  1667. err = db.Find(&vms).Error
  1668. }
  1669. if patientType > 0 {
  1670. if patientType == 1 {
  1671. db := readDb.
  1672. Table("xt_schedule").
  1673. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1674. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1675. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1676. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1677. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1678. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1679. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1680. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1681. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1682. Where("status = 1 AND user_org_id = ?", orgID)
  1683. if scheduleDate != 0 {
  1684. db = db.Where("schedule_date = ?", scheduleDate)
  1685. }
  1686. err = db.Find(&vms).Error
  1687. }
  1688. if patientType == 2 {
  1689. db := readDb.
  1690. Table("xt_schedule").
  1691. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1692. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1693. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1694. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1695. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1696. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1697. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1698. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1699. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1700. Where("status = 1 AND user_org_id = ?", orgID)
  1701. if scheduleDate != 0 {
  1702. db = db.Where("schedule_date = ?", scheduleDate)
  1703. }
  1704. err = db.Find(&vms).Error
  1705. }
  1706. if patientType == 3 {
  1707. db := readDb.
  1708. Table("xt_schedule").
  1709. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1710. 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).
  1711. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1712. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1713. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1714. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1715. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1716. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1717. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1718. Where("status = 1 AND user_org_id = ?", orgID)
  1719. if scheduleDate != 0 {
  1720. db = db.Where("schedule_date = ?", scheduleDate)
  1721. }
  1722. err = db.Find(&vms).Error
  1723. }
  1724. if patientType == 4 {
  1725. db := readDb.
  1726. Table("xt_schedule").
  1727. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1728. 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).
  1729. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1730. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1731. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1732. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1733. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1734. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1735. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1736. Where("status = 1 AND user_org_id = ?", orgID)
  1737. if scheduleDate != 0 {
  1738. db = db.Where("schedule_date = ?", scheduleDate)
  1739. }
  1740. err = db.Find(&vms).Error
  1741. }
  1742. }
  1743. }
  1744. return vms, err
  1745. }
  1746. func GetMobileHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleProjectVM, error) {
  1747. var vms []*HisMScheduleProjectVM
  1748. //if patientType == 0 {
  1749. // db := readDb.
  1750. // Table("xt_schedule").
  1751. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1752. // Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1753. // return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1754. // }).
  1755. // Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1756. // Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1757. // Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1758. // Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1759. // return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1760. // }).
  1761. // Where("status = 1 AND user_org_id = ?", orgID)
  1762. // if scheduleDate != 0 {
  1763. // db = db.Where("schedule_date = ?", scheduleDate)
  1764. // }
  1765. // err = db.Find(&vms).Error
  1766. //}
  1767. //if patientType > 0 {
  1768. // db := readDb.
  1769. // Table("xt_schedule").
  1770. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1771. // Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1772. // return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1773. // }).
  1774. // Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1775. // Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1776. // Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1777. // Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1778. // Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1779. // return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1780. // }).
  1781. // Where("status = 1 AND user_org_id = ?", orgID)
  1782. // if scheduleDate != 0 {
  1783. // db = db.Where("schedule_date = ?", scheduleDate)
  1784. // }
  1785. // err = db.Find(&vms).Error
  1786. //}
  1787. db := readDb.Table("xt_schedule").Where("status = 1")
  1788. if orgID > 0 {
  1789. db = db.Where("user_org_id = ?", orgID)
  1790. }
  1791. if scheduleDate > 0 {
  1792. db = db.Where("schedule_date =?", scheduleDate)
  1793. }
  1794. err = db.Find(&vms).Error
  1795. if patientType == 0 {
  1796. db := readDb.
  1797. Table("xt_schedule").
  1798. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1799. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1800. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1801. }).
  1802. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1803. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1804. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1805. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1806. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1807. }).
  1808. Preload("HisPrescriptionTeamProject", 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("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  1810. }).
  1811. Where("status = 1 AND user_org_id = ?", orgID)
  1812. if scheduleDate != 0 {
  1813. db = db.Where("schedule_date = ?", scheduleDate)
  1814. }
  1815. err = db.Find(&vms).Error
  1816. }
  1817. if patientType > 0 {
  1818. db := readDb.
  1819. Table("xt_schedule").
  1820. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1821. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1822. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1823. }).
  1824. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1825. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1826. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1827. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1828. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1829. }).
  1830. Preload("HisPrescriptionTeamProject", 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("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  1832. }).
  1833. Where("status = 1 AND user_org_id = ?", orgID)
  1834. if scheduleDate != 0 {
  1835. db = db.Where("schedule_date = ?", scheduleDate)
  1836. }
  1837. err = db.Find(&vms).Error
  1838. }
  1839. return vms, err
  1840. }
  1841. func MobileCreateDialysisOrder(orgID int64, patientID int64, order *models.DialysisOrder) error {
  1842. now := time.Now()
  1843. tx := writeDb.Begin()
  1844. if createOrderErr := tx.Model(&models.DialysisOrder{}).Create(order).Error; createOrderErr != nil {
  1845. tx.Rollback()
  1846. return createOrderErr
  1847. }
  1848. // 更新透析记录 ID
  1849. // 透析处方
  1850. 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 {
  1851. tx.Rollback()
  1852. return err
  1853. }
  1854. // 接诊评估
  1855. 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 {
  1856. tx.Rollback()
  1857. return err
  1858. }
  1859. // 透前评估
  1860. 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 {
  1861. tx.Rollback()
  1862. return err
  1863. }
  1864. // 临时医嘱
  1865. 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 {
  1866. tx.Rollback()
  1867. return err
  1868. }
  1869. // 双人核对
  1870. 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 {
  1871. tx.Rollback()
  1872. return err
  1873. }
  1874. // 透后评估
  1875. 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 {
  1876. tx.Rollback()
  1877. return err
  1878. }
  1879. // 治疗小结
  1880. 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 {
  1881. tx.Rollback()
  1882. return err
  1883. }
  1884. // 透析监测
  1885. 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 {
  1886. tx.Rollback()
  1887. return err
  1888. }
  1889. tx.Commit()
  1890. return nil
  1891. }
  1892. type MobileUrgentSchedulePatientVM struct {
  1893. ID int64 `gorm:"column:id" json:"id"`
  1894. Name string `gorm:"column:name" json:"name"`
  1895. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no"`
  1896. }
  1897. func (MobileUrgentSchedulePatientVM) TableName() string {
  1898. return "xt_patients"
  1899. }
  1900. type MobileUrgentScheduleTreatmentModeVM struct {
  1901. ID int64 `gorm:"column:id" json:"id"`
  1902. Name string `gorm:"column:name" json:"name"`
  1903. }
  1904. func (MobileUrgentScheduleTreatmentModeVM) TableName() string {
  1905. return "xt_treatment_mode"
  1906. }
  1907. func MobileGetAllPatientsForUrgentSchedule(orgID int64, record_date int64) ([]*MobileUrgentSchedulePatientVM, error) {
  1908. var vms []*MobileUrgentSchedulePatientVM = make([]*MobileUrgentSchedulePatientVM, 0)
  1909. 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()
  1910. defer rows.Close()
  1911. if err != nil {
  1912. return nil, err
  1913. }
  1914. for rows.Next() {
  1915. var vm MobileUrgentSchedulePatientVM
  1916. readDb.ScanRows(rows, &vm)
  1917. vms = append(vms, &vm)
  1918. }
  1919. return vms, nil
  1920. }
  1921. func MobileGetAllTrearmentModesForUrgentSchedule() ([]*MobileUrgentScheduleTreatmentModeVM, error) {
  1922. var modes []*MobileUrgentScheduleTreatmentModeVM
  1923. err := readDb.Model(&MobileUrgentScheduleTreatmentModeVM{}).Where("status = 1").Find(&modes).Error
  1924. if err != nil {
  1925. return nil, err
  1926. }
  1927. return modes, nil
  1928. }
  1929. type MobileUrgentScheduleScheduleListVM struct {
  1930. ID int64 `gorm:"column:id" json:"id"`
  1931. // ZoneID int64 `gorm:"column:partition_id" json:"zone_id"`
  1932. DeviceNumberID int64 `gorm:"column:bed_id" json:"bed_id"`
  1933. PatientID int64 `gorm:"column:patient_id" json:"patient_id"`
  1934. ScheduleType int `gorm:"column:schedule_type" json:"schedule_type"`
  1935. DeviceNumber *models.DeviceNumber `gorm:"ForeignKey:DeviceNumberID" json:"device_number"`
  1936. // DeviceZone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"device_zone"`
  1937. }
  1938. func (MobileUrgentScheduleScheduleListVM) TableName() string {
  1939. return "xt_schedule"
  1940. }
  1941. func MobileGetSchedulesForUrgentSchedule(orgID int64, scheduleDate int64, schedule_type int) (schedules []*MobileUrgentScheduleScheduleListVM, err error) {
  1942. db := readDb.
  1943. Model(&MobileUrgentScheduleScheduleListVM{}).
  1944. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1945. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND schedule_type = ? ", orgID, scheduleDate, schedule_type)
  1946. err = db.Find(&schedules).Error
  1947. if err != nil {
  1948. return nil, err
  1949. }
  1950. return schedules, nil
  1951. }
  1952. func MobileGetOtherSchedulesForUrgentSchedule(orgID int64, scheduleDate int64, schedule_type int) ([]*MobileUrgentScheduleScheduleListVM, error) {
  1953. var vms []*MobileUrgentScheduleScheduleListVM = make([]*MobileUrgentScheduleScheduleListVM, 0)
  1954. 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()
  1955. defer rows.Close()
  1956. if err != nil {
  1957. return nil, err
  1958. }
  1959. for rows.Next() {
  1960. var vm MobileUrgentScheduleScheduleListVM
  1961. readDb.ScanRows(rows, &vm)
  1962. vms = append(vms, &vm)
  1963. }
  1964. return vms, nil
  1965. }
  1966. type MobileUrgentScheduleDeviceNumberVM struct {
  1967. ID int64 `gorm:"column:id" json:"id"`
  1968. Number string `gorm:"column:number" json:"number"`
  1969. ZoneID int64 `gorm:"column:zone_id" json:"zone_id"`
  1970. Zone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"zone"`
  1971. }
  1972. func (MobileUrgentScheduleDeviceNumberVM) TableName() string {
  1973. return "xt_device_number"
  1974. }
  1975. func MobileGetAllDeviceNumbersForUrgentSchedule(orgID int64, record_date int64, schedule_type int) ([]*DeviceNumberViewModel, error) {
  1976. var vms []*DeviceNumberViewModel = make([]*DeviceNumberViewModel, 0)
  1977. 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()
  1978. defer rows.Close()
  1979. if err != nil {
  1980. return nil, err
  1981. }
  1982. for rows.Next() {
  1983. var vm DeviceNumberViewModel
  1984. readDb.ScanRows(rows, &vm)
  1985. vms = append(vms, &vm)
  1986. }
  1987. return vms, nil
  1988. //var deviceNumbers []*MobileUrgentScheduleDeviceNumberVM
  1989. //db := readDb.
  1990. // Model(&MobileUrgentScheduleDeviceNumberVM{}).
  1991. // Preload("Zone", "status = 1 AND org_id = ?", orgID).
  1992. // Where("status = 1 AND org_id = ?", orgID)
  1993. //err := db.Order("zone_id asc").Find(&deviceNumbers).Error
  1994. //if err != nil {
  1995. // return nil, err
  1996. //}
  1997. //return deviceNumbers, nil
  1998. }
  1999. func GetValidScheduleMonitorRecordCount() (int64, error) {
  2000. var total int64
  2001. err := readDb.Model(&models.MonitoringRecord{}).Where("status = 1 AND operate_time = 0 AND monitoring_date <> 0").Count(&total).Error
  2002. return total, err
  2003. }
  2004. func GetTop1000ValidScheduleMonitorRecord() ([]*models.MonitoringRecord, error) {
  2005. var monitors []*models.MonitoringRecord
  2006. err := readDb.Model(&models.MonitoringRecord{}).Where("status = 1 AND operate_time = 0 AND monitoring_date <> 0").Order("id asc").Limit(100).Find(&monitors).Error
  2007. if err != nil {
  2008. return nil, err
  2009. }
  2010. return monitors, nil
  2011. }
  2012. func BatchUpdateMonitors(monitors []*models.MonitoringRecord) error {
  2013. tx := writeDb.Begin()
  2014. for index := 0; index < len(monitors); index++ {
  2015. tx.Save(monitors[index])
  2016. }
  2017. return tx.Commit().Error
  2018. }
  2019. func ModifyStartDialysisOrder(order *models.DialysisOrder) error {
  2020. tx := writeDb.Begin()
  2021. updateTime := time.Now().Unix()
  2022. 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}).Error
  2023. if err != nil {
  2024. tx.Rollback()
  2025. return err
  2026. }
  2027. tx.Commit()
  2028. return err
  2029. }
  2030. func ModifyFinishDialysisOrder(order *models.DialysisOrder) error {
  2031. tx := writeDb.Begin()
  2032. updateTime := time.Now().Unix()
  2033. 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}).Error
  2034. if err != nil {
  2035. tx.Rollback()
  2036. return err
  2037. }
  2038. tx.Commit()
  2039. return err
  2040. }
  2041. func MobileGetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  2042. var record models.SgjPatientDryweight
  2043. err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  2044. if err != nil {
  2045. if err == gorm.ErrRecordNotFound {
  2046. return nil, nil
  2047. } else {
  2048. return nil, err
  2049. }
  2050. }
  2051. return &record, nil
  2052. }
  2053. //func MobileGetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  2054. // var record models.SgjPatientDryweight
  2055. // redis := RedisClient()
  2056. // defer redis.Close()
  2057. //
  2058. // key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":last_dry_weight"
  2059. // last_dry_weight_str, _ := redis.Get(key).Result()
  2060. //
  2061. // if len(last_dry_weight_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2062. // err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  2063. // if err != nil {
  2064. // if err == gorm.ErrRecordNotFound {
  2065. // if record.ID <= 0 {
  2066. // redis.Set(key, "null", time.Second*60*60*18)
  2067. // }
  2068. // return nil, nil
  2069. // } else {
  2070. // return nil, err
  2071. // }
  2072. // } else {
  2073. // if record.ID > 0 {
  2074. // //缓存数据
  2075. // last_dry_weight_str, err := json.Marshal(record)
  2076. // if err == nil {
  2077. // redis.Set(key, last_dry_weight_str, time.Second*60*60*18)
  2078. // return nil, err
  2079. // }
  2080. // } else {
  2081. // redis.Set(key, "null", time.Second*60*60*18)
  2082. // return nil, err
  2083. // }
  2084. // return &record, nil
  2085. // }
  2086. // } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2087. // if last_dry_weight_str == "null" {
  2088. // return &record, nil
  2089. // } else {
  2090. // json.Unmarshal([]byte(last_dry_weight_str), &record)
  2091. // return &record, nil
  2092. // }
  2093. //
  2094. // }
  2095. //}
  2096. // 透析方案
  2097. func MobileGetDialysisSolutionByModeIdSix(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  2098. var record models.DialysisSolution
  2099. 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
  2100. if err != nil {
  2101. if err == gorm.ErrRecordNotFound {
  2102. return nil, nil
  2103. } else {
  2104. return nil, err
  2105. }
  2106. }
  2107. return &record, nil
  2108. }
  2109. // 透析方案
  2110. func MobileGetDialysisSolutionByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  2111. var record models.DialysisSolution
  2112. redis := RedisClient()
  2113. defer redis.Close()
  2114. // cur_date := time.Now().Format("2006-01-02")
  2115. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2116. dialysis_solution_str, _ := redis.Get(key).Result()
  2117. if len(dialysis_solution_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2118. 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
  2119. if err != nil {
  2120. if err == gorm.ErrRecordNotFound {
  2121. if record.ID <= 0 {
  2122. redis.Set(key, "null", time.Second*60*60*18)
  2123. }
  2124. return nil, nil
  2125. } else {
  2126. return nil, err
  2127. }
  2128. } else {
  2129. if record.ID > 0 {
  2130. //缓存数据
  2131. dialysis_solution_str, err := json.Marshal(record)
  2132. if err == nil {
  2133. redis.Set(key, dialysis_solution_str, time.Second*60*60*18)
  2134. }
  2135. } else {
  2136. redis.Set(key, "null", time.Second*60*60*18)
  2137. }
  2138. return &record, nil
  2139. }
  2140. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2141. if dialysis_solution_str == "null" {
  2142. return &record, nil
  2143. } else {
  2144. json.Unmarshal([]byte(dialysis_solution_str), &record)
  2145. return &record, nil
  2146. }
  2147. }
  2148. }
  2149. // 透析处方
  2150. func MobileGetDialysisPrescribeByModeId(orgID int64, patientID int64, recordDate int64, mode_id int64) (*models.DialysisPrescription, error) {
  2151. var record models.DialysisPrescription
  2152. redis := RedisClient()
  2153. defer redis.Close()
  2154. // cur_date := time.Now().Format("2006-01-02")
  2155. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2156. redis.Set(key, "", time.Second)
  2157. dialysis_prescribe_str, _ := redis.Get(key).Result()
  2158. if len(dialysis_prescribe_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2159. 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
  2160. if err != nil {
  2161. if err == gorm.ErrRecordNotFound {
  2162. if record.ID <= 0 {
  2163. redis.Set(key, "null", time.Second*60*60*18)
  2164. }
  2165. return nil, nil
  2166. } else {
  2167. return nil, err
  2168. }
  2169. } else {
  2170. if record.ID > 0 {
  2171. //缓存数据
  2172. dialysis_prescribe_str, err := json.Marshal(record)
  2173. if err == nil {
  2174. redis.Set(key, dialysis_prescribe_str, time.Second*60*60*18)
  2175. }
  2176. } else {
  2177. redis.Set(key, "null", time.Second*60*60*18)
  2178. }
  2179. return &record, nil
  2180. }
  2181. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2182. if dialysis_prescribe_str == "null" {
  2183. return &record, nil
  2184. } else {
  2185. json.Unmarshal([]byte(dialysis_prescribe_str), &record)
  2186. return &record, nil
  2187. }
  2188. }
  2189. }
  2190. func MobileGetDialysisPrescribeByModeIdSix(orgID int64, patientID int64, recordDate int64, mode_id int64) (*models.DialysisPrescription, error) {
  2191. var record models.DialysisPrescription
  2192. 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
  2193. if err != nil {
  2194. if err == gorm.ErrRecordNotFound {
  2195. return nil, nil
  2196. } else {
  2197. return nil, err
  2198. }
  2199. }
  2200. return &record, nil
  2201. }
  2202. func MobileGetDialysisPrescribeByModeIdOne(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  2203. var record models.DialysisPrescription
  2204. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  2205. if err != nil {
  2206. if err == gorm.ErrRecordNotFound {
  2207. return nil, nil
  2208. } else {
  2209. return nil, err
  2210. }
  2211. }
  2212. return &record, nil
  2213. }
  2214. //func MobileGetDialysisPrescribeByModeIdOne(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  2215. // var record models.DialysisPrescription
  2216. // redis := RedisClient()
  2217. // defer redis.Close()
  2218. //
  2219. // // cur_date := time.Now().Format("2006-01-02")
  2220. // key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":dialysis_prescribe_by_mode"
  2221. // dialysis_prescribe_by_mode_str, _ := redis.Get(key).Result()
  2222. //
  2223. // if len(dialysis_prescribe_by_mode_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2224. // err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  2225. // if err != nil {
  2226. // if err == gorm.ErrRecordNotFound {
  2227. // if record.ID <= 0 {
  2228. // redis.Set(key, "null", time.Second*60*60*18)
  2229. // }
  2230. // return nil, nil
  2231. // } else {
  2232. // return nil, err
  2233. // }
  2234. // } else {
  2235. //
  2236. // if record.ID > 0 {
  2237. // //缓存数据
  2238. // dialysis_prescribe_by_mode_str, err := json.Marshal(record)
  2239. //
  2240. // if err == nil {
  2241. // redis.Set(key, dialysis_prescribe_by_mode_str, time.Second*60*60*18)
  2242. // return nil, err
  2243. // }
  2244. // } else {
  2245. // redis.Set(key, "null", time.Second*60*60*18)
  2246. // return nil, err
  2247. // }
  2248. // return &record, nil
  2249. // }
  2250. // } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2251. // if dialysis_prescribe_by_mode_str == "null" {
  2252. // json.Unmarshal([]byte(dialysis_prescribe_by_mode_str), &record)
  2253. // return &record, nil
  2254. // } else {
  2255. // json.Unmarshal([]byte(dialysis_prescribe_by_mode_str), &record)
  2256. // return &record, nil
  2257. // }
  2258. //
  2259. // }
  2260. //}
  2261. func MobileGetLastDialysisPrescribe(orgID int64, patientID int64) (*models.DialysisPrescription, error) {
  2262. var record models.DialysisPrescription
  2263. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 ", patientID, orgID).Last(&record).Error
  2264. if err != nil {
  2265. if err == gorm.ErrRecordNotFound {
  2266. return nil, nil
  2267. } else {
  2268. return nil, err
  2269. }
  2270. }
  2271. return &record, nil
  2272. }
  2273. func MobileGetLastDialysisPrescribeByModeIdSix(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2274. var record models.DialysisPrescription
  2275. 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
  2276. //if err != nil {
  2277. // if err == gorm.ErrRecordNotFound {
  2278. // return nil, nil
  2279. // } else {
  2280. // return nil, err
  2281. // }
  2282. //}
  2283. return &record, err
  2284. }
  2285. func MobileGetLastDialysisPrescribeByModeIdTen(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2286. var record models.DialysisPrescription
  2287. 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
  2288. if err != nil {
  2289. if err == gorm.ErrRecordNotFound {
  2290. return nil, nil
  2291. } else {
  2292. return nil, err
  2293. }
  2294. }
  2295. return &record, err
  2296. }
  2297. func MobileGetLastDialysisPrescribeByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2298. var record models.DialysisPrescription
  2299. redis := RedisClient()
  2300. defer redis.Close()
  2301. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  2302. dialysis_prescribe_by_mode_id, _ := redis.Get(key).Result()
  2303. if len(dialysis_prescribe_by_mode_id) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2304. 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
  2305. if err != nil {
  2306. if err == gorm.ErrRecordNotFound {
  2307. if record.ID <= 0 {
  2308. redis.Set(key, "null", time.Second*60*60*18)
  2309. }
  2310. return nil, nil
  2311. } else {
  2312. return nil, err
  2313. }
  2314. } else {
  2315. if record.ID > 0 {
  2316. //缓存数据
  2317. dialysis_prescribe_by_mode_str, err := json.Marshal(record)
  2318. if err == nil {
  2319. redis.Set(key, dialysis_prescribe_by_mode_str, time.Second*60*60*18)
  2320. return nil, err
  2321. }
  2322. } else {
  2323. redis.Set(key, "null", time.Second*60*60*18)
  2324. return nil, err
  2325. }
  2326. return &record, nil
  2327. }
  2328. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2329. if dialysis_prescribe_by_mode_id == "null" {
  2330. return &record, nil
  2331. } else {
  2332. json.Unmarshal([]byte(dialysis_prescribe_by_mode_id), &record)
  2333. return &record, nil
  2334. }
  2335. }
  2336. }
  2337. func MobileGetLastDialysisPrescribeByModeIdOne(orgID int64, patientID int64, mode_id int64) (models.DialysisPrescription, error) {
  2338. var record models.DialysisPrescription
  2339. 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
  2340. return record, err
  2341. }
  2342. func GetAllAvaildDeviceNumbers(orgID int64, record_date int64, schedule_type int) ([]*DeviceNumberViewModel, error) {
  2343. var vms []*DeviceNumberViewModel = make([]*DeviceNumberViewModel, 0)
  2344. 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()
  2345. defer rows.Close()
  2346. if err != nil {
  2347. return nil, err
  2348. }
  2349. for rows.Next() {
  2350. var vm DeviceNumberViewModel
  2351. readDb.ScanRows(rows, &vm)
  2352. vms = append(vms, &vm)
  2353. }
  2354. return vms, nil
  2355. }
  2356. // 获取 maxDate 之前一次的透前评估记录
  2357. func GetLastTimePredialysisEvaluation(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
  2358. var record models.PredialysisEvaluation
  2359. 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
  2360. if err != nil {
  2361. if err == gorm.ErrRecordNotFound {
  2362. return nil, nil
  2363. } else {
  2364. return nil, err
  2365. }
  2366. }
  2367. return &record, nil
  2368. }
  2369. func GetLastTimeOrder(orgID int64, patientID int64, maxDate int64) (*models.DialysisOrder, error) {
  2370. var record models.DialysisOrder
  2371. 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
  2372. if err != nil {
  2373. if err == gorm.ErrRecordNotFound {
  2374. return nil, nil
  2375. } else {
  2376. return nil, err
  2377. }
  2378. }
  2379. return &record, nil
  2380. }
  2381. func GetLastMonitorRecord(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  2382. var record models.MonitoringRecord
  2383. 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
  2384. if err != nil {
  2385. if err == gorm.ErrRecordNotFound {
  2386. return nil, nil
  2387. } else {
  2388. return nil, err
  2389. }
  2390. }
  2391. return &record, nil
  2392. }
  2393. // 获取 maxDate 之前一次的透后评估记录
  2394. func GetLastTimeAssessmentAfterDislysis(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  2395. var record models.AssessmentAfterDislysis
  2396. 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
  2397. if err != nil {
  2398. if err == gorm.ErrRecordNotFound {
  2399. return nil, nil
  2400. } else {
  2401. return nil, err
  2402. }
  2403. }
  2404. return &record, nil
  2405. }
  2406. // 透析处方
  2407. func GetDialysisPrescribe(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  2408. var record models.DialysisPrescription
  2409. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  2410. if err != nil {
  2411. if err == gorm.ErrRecordNotFound {
  2412. return nil, nil
  2413. } else {
  2414. return nil, err
  2415. }
  2416. }
  2417. return &record, nil
  2418. }
  2419. // 透析方案
  2420. func GetDialysisSolution(orgID int64, patientID int64, mode_id int64) (models.DialysisSolution, error) {
  2421. var record models.DialysisSolution
  2422. 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
  2423. return record, err
  2424. }
  2425. func GetDialysisSolutionOne(orgID int64, mode_id int64) (*models.DialysisSolution, error) {
  2426. var record models.DialysisSolution
  2427. err := readDb.Model(&models.DialysisSolution{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2428. if err != nil {
  2429. if err == gorm.ErrRecordNotFound {
  2430. return nil, nil
  2431. } else {
  2432. return nil, err
  2433. }
  2434. }
  2435. return &record, nil
  2436. }
  2437. func GetLastDialysisPrescribeByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2438. var record models.DialysisPrescription
  2439. 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
  2440. if err != nil {
  2441. if err == gorm.ErrRecordNotFound {
  2442. return nil, nil
  2443. } else {
  2444. return nil, err
  2445. }
  2446. }
  2447. return &record, nil
  2448. }
  2449. func GetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  2450. var record models.SgjPatientDryweight
  2451. err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  2452. if err != nil {
  2453. if err == gorm.ErrRecordNotFound {
  2454. return nil, nil
  2455. } else {
  2456. return nil, err
  2457. }
  2458. }
  2459. return &record, nil
  2460. }
  2461. func MobileGetSystemDialysisPrescribeByModeIdSix(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2462. var record models.SystemPrescription
  2463. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).First(&record).Error
  2464. if err != nil {
  2465. if err == gorm.ErrRecordNotFound {
  2466. return nil, nil
  2467. } else {
  2468. return nil, err
  2469. }
  2470. }
  2471. return &record, nil
  2472. }
  2473. func MobileGetSystemDialysisPrescribeByModeId(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2474. var record models.SystemPrescription
  2475. redis := RedisClient()
  2476. defer redis.Close()
  2477. // cur_date := time.Now().Format("2006-01-02")
  2478. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  2479. system_dialysis_prescribe_str, _ := redis.Get(key).Result()
  2480. if len(system_dialysis_prescribe_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2481. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2482. if err != nil {
  2483. if err == gorm.ErrRecordNotFound {
  2484. if record.ID <= 0 {
  2485. redis.Set(key, "null", time.Second*60*60*18)
  2486. }
  2487. return nil, nil
  2488. } else {
  2489. return nil, err
  2490. }
  2491. } else {
  2492. if record.ID > 0 {
  2493. //缓存数据
  2494. system_dialysis_prescribe_str, err := json.Marshal(record)
  2495. if err == nil {
  2496. redis.Set(key, system_dialysis_prescribe_str, time.Second*60*60*18)
  2497. }
  2498. } else {
  2499. redis.Set(key, "null", time.Second*60*60*18)
  2500. }
  2501. return &record, nil
  2502. }
  2503. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2504. if system_dialysis_prescribe_str == "null" {
  2505. return &record, nil
  2506. } else {
  2507. json.Unmarshal([]byte(system_dialysis_prescribe_str), &record)
  2508. return &record, nil
  2509. }
  2510. }
  2511. }
  2512. func MobileGetSystemDialysisPrescribeByModeIdOne(orgID int64, mode_id int64) (models.SystemPrescription, error) {
  2513. var record models.SystemPrescription
  2514. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2515. return record, err
  2516. }
  2517. func GetSystemDialysisPrescribeByModeId(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2518. var record models.SystemPrescription
  2519. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2520. if err != nil {
  2521. if err == gorm.ErrRecordNotFound {
  2522. return nil, nil
  2523. } else {
  2524. return nil, err
  2525. }
  2526. }
  2527. return &record, nil
  2528. }
  2529. func GetDialysisOrderCount(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2530. 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
  2531. return
  2532. }
  2533. func GetDialysisOrderCountOne(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2534. 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
  2535. return
  2536. }
  2537. func GetDialysisOrderCountTwo(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2538. err = readDb.Model(&models.DialysisOrder{}).Where("dialysis_date>=1672502400 and dialysis_date <= ? AND status = 1 AND stage = 2 AND user_org_id = ? AND patient_id = ?", recordDate, orgID, patient_id).Count(&count).Error
  2539. return
  2540. }
  2541. func GetFirstDateOfMonth(d time.Time) time.Time {
  2542. d = d.AddDate(0, 0, -d.Day()+1)
  2543. return GetZeroTime(d)
  2544. }
  2545. func GetZeroTime(d time.Time) time.Time {
  2546. return time.Date(d.Year(), d.Month(), d.Day(), 0, 0, 0, 0, d.Location())
  2547. }
  2548. func GetDialysisCountByPatientId(startime int64, endtime int64, patientid int64, orgid int64) (order []*models.BloodDialysisOrderCount, err error) {
  2549. db := XTReadDB().Table("xt_dialysis_order as o")
  2550. 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
  2551. return order, err
  2552. }
  2553. func FindConsumablesByDate(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error) {
  2554. 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
  2555. return
  2556. }
  2557. func FindConsumablesByDateTwo(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error) {
  2558. 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
  2559. return
  2560. }
  2561. func FindConsumablesByDateThree(orgID int64, patient_id int64, recordDate int64) (consumables []*models.BloodAutomaticReduceDetail, err error) {
  2562. 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
  2563. return
  2564. }
  2565. //func FindLastConsumables(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error){
  2566. // 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
  2567. // return
  2568. //}
  2569. //
  2570. func GetLastTimeConsumables(orgID int64, patientID int64, maxDate int64) (prepare []*models.DialysisBeforePrepare, err error) {
  2571. 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
  2572. return
  2573. }
  2574. type GoodsType struct {
  2575. ID int64 `gorm:"column:id" json:"id"`
  2576. TypeName string `gorm:"column:type_name" json:"type_name"`
  2577. Remark string `gorm:"column:remark" json:"remark"`
  2578. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2579. Status int64 `gorm:"column:status" json:"status"`
  2580. Type int64 `gorm:"column:type" json:"type"`
  2581. }
  2582. func (GoodsType) TableName() string {
  2583. return "xt_goods_type"
  2584. }
  2585. type VMGoodInfo struct {
  2586. ID int64 `gorm:"column:id" json:"id"`
  2587. SpecificationName string `gorm:"column:specification_name" json:"specification_name"`
  2588. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2589. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2590. GoodName string `gorm:"column:good_name" json:"good_name" form:"good_name"`
  2591. GoodUnit int64 `gorm:"column:good_unit" json:"good_unit" form:"good_unit"`
  2592. Total float64 `gorm:"column:total" json:"total" form:"total"`
  2593. PackingUnit string `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
  2594. MedicalInsuranceNumber string `gorm:"column:medical_insurance_number" json:"medical_insurance_number" form:"medical_insurance_number"`
  2595. }
  2596. func (VMGoodInfo) TableName() string {
  2597. return "xt_good_information"
  2598. }
  2599. type AutomaticReduceDetail struct {
  2600. ID int64 `gorm:"column:id" json:"id"`
  2601. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2602. Status int64 `gorm:"column:status" json:"status"`
  2603. RecordTime int64 `gorm:"column:record_time" json:"record_time"`
  2604. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2605. GoodId int64 `gorm:"column:good_id" json:"good_id"`
  2606. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2607. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"info"`
  2608. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"type"`
  2609. Count int64 `gorm:"column:count" json:"count"`
  2610. }
  2611. func (AutomaticReduceDetail) TableName() string {
  2612. return "xt_automatic_reduce_detail"
  2613. }
  2614. type DialysisBeforePrepare struct {
  2615. ID int64 `gorm:"column:id" json:"id" form:"id"`
  2616. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  2617. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  2618. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  2619. GoodId int64 `gorm:"column:good_id" json:"good_id" form:"good_id"`
  2620. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id" form:"good_type_id"`
  2621. Count int64 `gorm:"column:count" json:"count" form:"count"`
  2622. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  2623. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  2624. Creater int64 `gorm:"column:creater" json:"creater" form:"creater"`
  2625. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  2626. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"info"`
  2627. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"type"`
  2628. }
  2629. func (DialysisBeforePrepare) TableName() string {
  2630. return "dialysis_before_prepare"
  2631. }
  2632. type MDialysisGoodsVM struct {
  2633. ID int64 `gorm:"column:id" json:"id"`
  2634. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2635. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2636. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2637. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2638. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2639. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2640. ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week"`
  2641. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2642. Status int64 `gorm:"column:status" json:"status"`
  2643. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2644. SchedualPatient *MSchedualPatientVMList `gorm:"ForeignKey:PatientId" json:"patient"`
  2645. AutomaticReduceDetail []*AutomaticReduceDetail `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"good_user"`
  2646. LastAutomaticReduceDetail []*AutomaticReduceDetail `gorm:"-" json:"last_good_user"`
  2647. DialysisBeforePrepare []*DialysisBeforePrepare `gorm:"ForeignKey:PatientId,ScheduleDate;AssociationForeignKey:PatientId,RecordDate" json:"good_user_detail"`
  2648. LastDialysisBeforePrepare []*DialysisBeforePrepare `gorm:"-" json:"last_good_user_detail"`
  2649. Project []*models.HisPrescriptionProject `gorm:"-" json:"project"`
  2650. //WarehouseOutInfo []*models.WarehouseOutInfoSeven `gorm:"ForeignKey:PatientId,ScheduleDate;AssociationForeignKey:PatientId,SysRecordTime" json:"ware_house_out_info"`
  2651. }
  2652. func (MDialysisGoodsVM) TableName() string {
  2653. return "xt_schedule"
  2654. }
  2655. type VMWarehouseOutInfo struct {
  2656. ID int64 `gorm:"column:id" json:"id"`
  2657. WarehouseOutId int64 `gorm:"column:warehouse_out_id" json:"warehouse_out_id"`
  2658. GoodId int64 `gorm:"column:good_id" json:"good_id"`
  2659. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2660. Count int64 `gorm:"column:count" json:"count"`
  2661. Price float64 `gorm:"column:price" json:"price"`
  2662. TotalPrice float64 `gorm:"column:total_price" json:"total_price"`
  2663. Status int64 `gorm:"column:status" json:"status"`
  2664. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2665. WarehouseOutOrderNumber string `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number"`
  2666. GoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"good_info"`
  2667. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"good_type"`
  2668. IsSys int64 `gorm:"column:is_sys" json:"is_sys"`
  2669. SysRecordTime int64 `gorm:"column:sys_record_time" json:"sys_record_time"`
  2670. Mtime int64 `gorm:"column:mtime" json:"mtime"`
  2671. Ctime int64 `gorm:"column:ctime" json:"ctime"`
  2672. }
  2673. func (VMWarehouseOutInfo) TableName() string {
  2674. return "xt_warehouse_out_info"
  2675. }
  2676. type DialysisGoodsDate struct {
  2677. RecordDate int64
  2678. }
  2679. type DialysisGoodsDetailDate struct {
  2680. RecordTime int64
  2681. }
  2682. 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) {
  2683. var vms []*MDialysisGoodsVM
  2684. var total int64
  2685. db := readDb.
  2686. Table("xt_schedule as sch").
  2687. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  2688. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2689. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2690. Preload("DialysisBeforePrepare", func(db *gorm.DB) *gorm.DB {
  2691. 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)
  2692. }).
  2693. Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
  2694. 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")
  2695. }).Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
  2696. if scheduleDate != 0 {
  2697. db = db.Where("schedule_date = ?", scheduleDate)
  2698. }
  2699. if schedule_type != 0 {
  2700. db = db.Where("schedule_type = ?", schedule_type)
  2701. }
  2702. if partition_id != 0 {
  2703. db = db.Where("partition_id = ?", partition_id)
  2704. }
  2705. if patient_id != 0 {
  2706. db = db.Where("patient_id = ?", patient_id)
  2707. }
  2708. err := db.Find(&vms).Error
  2709. return vms, err, total
  2710. }
  2711. func GetLastDialysisGoods(patient_id int64, orgID int64, record_time int64) (goodUser []*AutomaticReduceDetail, err error) {
  2712. var Id []*DialysisGoodsDetailDate
  2713. 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
  2714. if len(Id) > 0 {
  2715. 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
  2716. }
  2717. return
  2718. }
  2719. func GetLastDialysisBeforePrepare(patient_id int64, orgID int64, record_time int64) (goodUser []*DialysisBeforePrepare, err error) {
  2720. var Id []*DialysisGoodsDate
  2721. 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
  2722. if len(Id) > 0 {
  2723. 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
  2724. }
  2725. return
  2726. }
  2727. func GetAllWarehouseOutSumList(patient_id int64, orgID int64, record_time int64) (info []*models.WarehouseOutInfoSeven, err error) {
  2728. err = XTReadDB().Where("patient_id = ? and org_id = ? and sys_record_time = ? and status = 1", patient_id, orgID, record_time).Find(&info).Error
  2729. return info, err
  2730. }
  2731. func MobileGetGoodsStatistics(orgID int64, start_time int64, end_time int64) (list []*models.StockInfo, err error) {
  2732. db := readDb.Model(&models.StockInfo{})
  2733. db = db.Where("xt_good_information.org_id = ? AND xt_good_information.status = 1", orgID)
  2734. 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")
  2735. db = db.Preload("QueryWarehouseOutInfo", func(db *gorm.DB) *gorm.DB {
  2736. 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)
  2737. })
  2738. db = db.Preload("GoodsType", "org_id = ? AND status = 1", orgID)
  2739. err = db.Order("ctime desc").Find(&list).Error
  2740. return
  2741. }
  2742. 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) {
  2743. var vms []*MDialysisGoodsVM
  2744. var total int64
  2745. db := readDb.
  2746. Model(&models.Schedule{}).
  2747. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  2748. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2749. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2750. Preload("DialysisBeforePrepare", func(db *gorm.DB) *gorm.DB {
  2751. 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)
  2752. }).Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
  2753. 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)
  2754. }).Where("xt_schedule.status = 1 AND xt_schedule.user_org_id = ?", orgID)
  2755. if scheduleDate != 0 {
  2756. db = db.Where("schedule_date = ?", scheduleDate)
  2757. }
  2758. if patient_id != 0 {
  2759. db = db.Where("patient_id = ?", patient_id)
  2760. }
  2761. if len(keywords) != 0 {
  2762. keywords = "%" + keywords + "%"
  2763. 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)
  2764. if schedule_type != 0 {
  2765. db = db.Where("schedule_type = ?", schedule_type)
  2766. }
  2767. if partition_id != 0 {
  2768. db = db.Where("partition_id = ?", partition_id)
  2769. }
  2770. if good_type == 1 {
  2771. db = db.Where("patient_id in(?)", ids)
  2772. }
  2773. if good_type == 2 {
  2774. if len(ids) > 0 {
  2775. db = db.Where("patient_id not in(?)", ids)
  2776. }
  2777. }
  2778. } else {
  2779. if schedule_type != 0 {
  2780. db = db.Where("schedule_type = ?", schedule_type)
  2781. }
  2782. if partition_id != 0 {
  2783. db = db.Where("partition_id = ?", partition_id)
  2784. }
  2785. if good_type == 1 {
  2786. db = db.Where("patient_id in(?)", ids)
  2787. }
  2788. if good_type == 2 {
  2789. if len(ids) > 0 {
  2790. db = db.Where("patient_id not in(?)", ids)
  2791. }
  2792. }
  2793. db = db.Count(&total)
  2794. offset := (page - 1) * limit
  2795. db = db.Offset(offset).Limit(limit)
  2796. }
  2797. err := db.Find(&vms).Error
  2798. return vms, err, total
  2799. }
  2800. func GetLastDialysisGoodsTwo(patient_id int64, orgID int64, record_time int64) (goodUser []*AutomaticReduceDetail, err error) {
  2801. var Id []*DialysisGoodsDetailDate
  2802. 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
  2803. if len(Id) > 0 {
  2804. 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
  2805. }
  2806. return
  2807. }
  2808. func GetLastDialysisBeforePrepareTwo(patient_id int64, orgID int64, record_time int64) (goodUser []*DialysisBeforePrepare, err error) {
  2809. var Id []*DialysisGoodsDate
  2810. 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
  2811. if len(Id) > 0 {
  2812. 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
  2813. }
  2814. return
  2815. }
  2816. func GetAssessmentBefor(orgid int64, patientid int64, recorddate int64) (*models.PredialysisEvaluation, error) {
  2817. evaluation := models.PredialysisEvaluation{}
  2818. err := XTReadDB().Model(&evaluation).Where("user_org_id = ? and patient_id = ? and assessment_date = ? and status = 1", orgid, patientid, recorddate).Find(&evaluation).Error
  2819. if err == gorm.ErrRecordNotFound {
  2820. return nil, err
  2821. }
  2822. if err != nil {
  2823. return nil, err
  2824. }
  2825. return &evaluation, nil
  2826. }
  2827. func GetAssessmentBeforThrity(orgid int64, patientid int64, recorddate int64) (models.PredialysisEvaluation, error) {
  2828. evaluation := models.PredialysisEvaluation{}
  2829. err := XTReadDB().Model(&evaluation).Where("user_org_id = ? and patient_id = ? and assessment_date = ? and status = 1", orgid, patientid, recorddate).Find(&evaluation).Error
  2830. return evaluation, err
  2831. }
  2832. func GetAllHisDoctorAdvice(orgid int64, patientid int64, recorddate int64) (his []*models.HisDoctorAdviceInfo, err error) {
  2833. redis := RedisClient()
  2834. defer redis.Close()
  2835. key := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patientid, 10) + ":" + strconv.FormatInt(recorddate, 10) + ":his_doctor_advice"
  2836. his_doctor_advice_str, _ := redis.Get(key).Result()
  2837. redis.Set(key, "", time.Second)
  2838. if len(his_doctor_advice_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2839. 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
  2840. if err != nil {
  2841. if err == gorm.ErrRecordNotFound {
  2842. if len(his) <= 0 {
  2843. redis.Set(key, "null", time.Second*60*60*18)
  2844. }
  2845. return his, nil
  2846. } else {
  2847. return his, err
  2848. }
  2849. } else {
  2850. if len(his) > 0 {
  2851. //缓存数据
  2852. his_doctor_advice_str, err := json.Marshal(his)
  2853. if err == nil {
  2854. redis.Set(key, his_doctor_advice_str, time.Second*60*60*18)
  2855. }
  2856. } else {
  2857. redis.Set(key, "null", time.Second*60*60*18)
  2858. }
  2859. return his, nil
  2860. }
  2861. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2862. json.Unmarshal([]byte(his_doctor_advice_str), &his)
  2863. return his, nil
  2864. }
  2865. }
  2866. func GetLastDialysisPrescriptionByPatientId(orgid int64, patientid int64, recorddate int64) (*models.DialysisPrescription, error) {
  2867. prescription := models.DialysisPrescription{}
  2868. err := readDb.Model(&models.DialysisPrescription{}).Where("user_org_id = ? and patient_id = ? and record_date = ? and status = 1", orgid, patientid, recorddate).Find(&prescription).Error
  2869. if err == gorm.ErrRecordNotFound {
  2870. return nil, err
  2871. }
  2872. if err != nil {
  2873. return nil, err
  2874. }
  2875. return &prescription, nil
  2876. }
  2877. func GetLastDialysisPrescriptionByPatientIdTwo(orgid int64, patientid int64, recorddate int64) (models.DialysisPrescription, error) {
  2878. prescription := models.DialysisPrescription{}
  2879. err := readDb.Model(&models.DialysisPrescription{}).Where("user_org_id = ? and patient_id = ? and record_date = ? and status = 1", orgid, patientid, recorddate).Find(&prescription).Error
  2880. return prescription, err
  2881. }
  2882. type HisMScheduleDoctorAdviceVM struct {
  2883. ID int64 `gorm:"column:id" json:"id"`
  2884. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2885. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2886. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2887. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2888. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2889. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2890. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2891. Status int64 `gorm:"column:status" json:"status"`
  2892. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  2893. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  2894. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2895. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  2896. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  2897. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  2898. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  2899. }
  2900. func (HisMScheduleDoctorAdviceVM) TableName() string {
  2901. return "xt_schedule"
  2902. }
  2903. type HisMScheduleDoctorAdviceVMOne struct {
  2904. ID int64 `gorm:"column:id" json:"id"`
  2905. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2906. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2907. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2908. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2909. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2910. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2911. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2912. Status int64 `gorm:"column:status" json:"status"`
  2913. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  2914. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  2915. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2916. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  2917. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  2918. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  2919. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  2920. }
  2921. func (HisMScheduleDoctorAdviceVMOne) TableName() string {
  2922. return "xt_schedule"
  2923. }
  2924. type HisMScheduleProjectVM struct {
  2925. ID int64 `gorm:"column:id" json:"id"`
  2926. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2927. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2928. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2929. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2930. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2931. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2932. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2933. Status int64 `gorm:"column:status" json:"status"`
  2934. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  2935. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  2936. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2937. Prescription *models.DialysisPrescriptionTwenty `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  2938. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  2939. HisPrescriptionTeamProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"team_project"`
  2940. }
  2941. func (HisMScheduleProjectVM) TableName() string {
  2942. return "xt_schedule"
  2943. }
  2944. func GetHisDoctorConfig(orgid int64) (models.XtHisConfig, error) {
  2945. config := models.XtHisConfig{}
  2946. err := XTReadDB().Model(&config).Where("user_org_id = ? and status =1", orgid).Find(&config).Error
  2947. return config, err
  2948. }
  2949. func GetHisDoctorPatientById(orgid int64, patientid int64, recordtime int64) (advice []*models.HisDoctorAdviceInfo, err error) {
  2950. db := XTReadDB().Table("his_doctor_advice_info as x").Where("x.status = 1")
  2951. if orgid > 0 {
  2952. db = db.Where("x.user_org_id = ?", orgid)
  2953. }
  2954. if patientid > 0 {
  2955. db = db.Where("x.patient_id =?", patientid)
  2956. }
  2957. if recordtime > 0 {
  2958. db = db.Where("x.advice_date = ?", recordtime)
  2959. }
  2960. 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
  2961. return advice, err
  2962. }
  2963. func GetDoctorAdviceCount(startime int64, endtime int64, deliveway string, orgid int64) (advice []*models.BloodDoctorAdvice, err error) {
  2964. db := XTReadDB().Table("xt_doctor_advice as x").Where("x.status = 1 and x.advice_type =2")
  2965. if startime > 0 {
  2966. db = db.Where("x.advice_date >= ?", startime)
  2967. }
  2968. if endtime > 0 {
  2969. db = db.Where("x.advice_date<=?", endtime)
  2970. }
  2971. if orgid > 0 {
  2972. db = db.Where("x.user_org_id = ?", orgid)
  2973. }
  2974. if len(deliveway) > 0 {
  2975. db = db.Where("x.delivery_way = ?", deliveway)
  2976. }
  2977. 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
  2978. return advice, err
  2979. }
  2980. func GetHisDoctorAdviceCount(startime int64, endtime int64, deliveway string, orgid int64) (advice []*models.BloodDoctorAdvice, err error) {
  2981. db := XTReadDB().Table("his_doctor_advice_info as x").Where("x.status = 1 and x.advice_type =2")
  2982. if startime > 0 {
  2983. db = db.Where("x.advice_date >= ?", startime)
  2984. }
  2985. if endtime > 0 {
  2986. db = db.Where("x.advice_date<=?", endtime)
  2987. }
  2988. if orgid > 0 {
  2989. db = db.Where("x.user_org_id = ?", orgid)
  2990. }
  2991. if len(deliveway) > 0 {
  2992. db = db.Where("x.delivery_way = ?", deliveway)
  2993. }
  2994. 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
  2995. return advice, err
  2996. }
  2997. 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) {
  2998. var vms []*MScheduleDoctorAdviceVM
  2999. adviceWhere := ""
  3000. adviceCondition := []interface{}{}
  3001. if adviceType == 0 {
  3002. if patientType == 0 {
  3003. if patient_id > 0 {
  3004. if execution_state > 0 {
  3005. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  3006. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3007. } else {
  3008. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
  3009. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3010. }
  3011. } else {
  3012. if execution_state > 0 {
  3013. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ?"
  3014. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3015. } else {
  3016. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  3017. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3018. }
  3019. }
  3020. } else if patientType == 1 {
  3021. if patient_id > 0 {
  3022. if execution_state > 0 {
  3023. 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= ?"
  3024. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3025. } else {
  3026. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
  3027. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3028. }
  3029. } else {
  3030. if execution_state > 0 {
  3031. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  3032. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3033. } else {
  3034. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  3035. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3036. }
  3037. }
  3038. } else if patientType == 2 {
  3039. if patient_id > 0 {
  3040. if execution_state > 0 {
  3041. 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 = ?"
  3042. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3043. } else {
  3044. 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 = ?)"
  3045. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3046. }
  3047. } else {
  3048. if execution_state > 0 {
  3049. 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 = ?"
  3050. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3051. } else {
  3052. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  3053. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3054. }
  3055. }
  3056. }
  3057. } else if adviceType == 1 {
  3058. if patientType == 0 {
  3059. if patient_id > 0 {
  3060. if execution_state > 0 {
  3061. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ?"
  3062. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3063. } else {
  3064. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
  3065. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3066. }
  3067. } else {
  3068. if execution_state > 0 {
  3069. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ?"
  3070. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3071. } else {
  3072. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  3073. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3074. }
  3075. }
  3076. } else if patientType == 1 {
  3077. if patient_id > 0 {
  3078. if execution_state > 0 {
  3079. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  3080. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3081. } else {
  3082. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
  3083. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3084. }
  3085. } else {
  3086. if execution_state > 0 {
  3087. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?"
  3088. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3089. } else {
  3090. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  3091. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3092. }
  3093. }
  3094. } else if patientType == 2 {
  3095. if patient_id > 0 {
  3096. if execution_state > 0 {
  3097. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  3098. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3099. } else {
  3100. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
  3101. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3102. }
  3103. } else {
  3104. if execution_state > 0 {
  3105. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ?"
  3106. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3107. } else {
  3108. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  3109. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3110. }
  3111. }
  3112. }
  3113. } else if adviceType == 3 {
  3114. if patientType == 0 {
  3115. if patient_id > 0 {
  3116. if execution_state > 0 {
  3117. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ?"
  3118. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3119. } else {
  3120. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? "
  3121. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3122. }
  3123. } else {
  3124. if execution_state > 0 {
  3125. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? "
  3126. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3127. } else {
  3128. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  3129. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3130. }
  3131. }
  3132. } else if patientType == 1 {
  3133. if patient_id > 0 {
  3134. if execution_state > 0 {
  3135. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  3136. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3137. } else {
  3138. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
  3139. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3140. }
  3141. } else {
  3142. if execution_state > 0 {
  3143. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? "
  3144. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3145. } else {
  3146. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  3147. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3148. }
  3149. }
  3150. } else if patientType == 2 {
  3151. if patient_id > 0 {
  3152. if execution_state > 0 {
  3153. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  3154. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3155. } else {
  3156. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ?"
  3157. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3158. }
  3159. } else {
  3160. if execution_state > 0 {
  3161. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ?"
  3162. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3163. } else {
  3164. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  3165. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3166. }
  3167. }
  3168. }
  3169. } else if adviceType == 2 && len(deliverWay) > 0 {
  3170. if patientType == 0 {
  3171. if patient_id > 0 {
  3172. if execution_state > 0 {
  3173. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  3174. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  3175. } else {
  3176. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ?"
  3177. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  3178. }
  3179. } else {
  3180. if execution_state > 0 {
  3181. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ?"
  3182. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  3183. } else {
  3184. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  3185. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  3186. }
  3187. }
  3188. } else if patientType == 1 {
  3189. if patient_id > 0 {
  3190. if execution_state > 0 {
  3191. 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 = ?"
  3192. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state)
  3193. } else {
  3194. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ?"
  3195. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
  3196. }
  3197. } else {
  3198. if execution_state > 0 {
  3199. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ?"
  3200. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state)
  3201. } else {
  3202. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  3203. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  3204. }
  3205. }
  3206. } else if patientType == 2 {
  3207. if patient_id > 0 {
  3208. if execution_state > 0 {
  3209. 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 = ?"
  3210. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  3211. } else {
  3212. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ?"
  3213. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  3214. }
  3215. } else {
  3216. if execution_state > 0 {
  3217. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ?"
  3218. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  3219. } else {
  3220. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  3221. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  3222. }
  3223. }
  3224. }
  3225. } else if adviceType == 2 && len(deliverWay) <= 0 {
  3226. if patientType == 0 {
  3227. if patient_id > 0 {
  3228. if execution_state > 0 {
  3229. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ?"
  3230. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3231. } else {
  3232. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ?"
  3233. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3234. }
  3235. } else {
  3236. if execution_state > 0 {
  3237. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?"
  3238. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3239. } else {
  3240. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  3241. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3242. }
  3243. }
  3244. } else if patientType == 1 {
  3245. if patient_id > 0 {
  3246. if execution_state > 0 {
  3247. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  3248. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3249. } else {
  3250. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ?"
  3251. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3252. }
  3253. } else {
  3254. if execution_state > 0 {
  3255. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ?"
  3256. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3257. } else {
  3258. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?"
  3259. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3260. }
  3261. }
  3262. } else if patientType == 2 {
  3263. if patient_id > 0 {
  3264. if execution_state > 0 {
  3265. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  3266. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3267. } else {
  3268. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ?"
  3269. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3270. }
  3271. } else {
  3272. if execution_state > 0 {
  3273. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ?"
  3274. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3275. } else {
  3276. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  3277. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3278. }
  3279. }
  3280. }
  3281. }
  3282. db := readDb.Table("xt_schedule")
  3283. if scheduleType > 0 {
  3284. db = db.Where("schedule_type = ?", scheduleType)
  3285. }
  3286. if partitonType > 0 {
  3287. db = db.Where("partition_id = ?", partitonType)
  3288. }
  3289. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3290. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3291. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3292. }).
  3293. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3294. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3295. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3296. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3297. Preload("DoctorAdvices", adviceCondition...).
  3298. Where("status = 1 AND user_org_id = ?", orgID)
  3299. if scheduleDate != 0 {
  3300. db = db.Where("schedule_date = ?", scheduleDate)
  3301. }
  3302. err := db.Find(&vms).Error
  3303. return vms, err
  3304. }
  3305. func GetHisDoctorAdvicesOne(orgID int64, scheduleDate int64, deliverWay string, scheduleType int64, partitionType int64, patient_id int64, execution_state int64, cost_type int64) ([]*HisMScheduleDoctorAdviceVM, error) {
  3306. var vms []*HisMScheduleDoctorAdviceVM
  3307. if len(deliverWay) > 0 {
  3308. db := readDb.Table("xt_schedule")
  3309. if scheduleType > 0 {
  3310. db = db.Where("schedule_type = ?", scheduleType)
  3311. }
  3312. if partitionType > 0 {
  3313. db = db.Where("partition_id = ?", partitionType)
  3314. }
  3315. if patient_id > 0 {
  3316. if execution_state > 0 {
  3317. if cost_type > 0 {
  3318. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3319. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3320. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3321. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3322. 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).
  3323. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3324. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3325. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3326. Where("status = 1 AND user_org_id = ?", orgID)
  3327. if scheduleDate != 0 {
  3328. db = db.Where("schedule_date = ?", scheduleDate)
  3329. }
  3330. err = db.Find(&vms).Error
  3331. } else {
  3332. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3333. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3334. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3335. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3336. 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).
  3337. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3338. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3339. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3340. Where("status = 1 AND user_org_id = ?", orgID)
  3341. if scheduleDate != 0 {
  3342. db = db.Where("schedule_date = ?", scheduleDate)
  3343. }
  3344. err = db.Find(&vms).Error
  3345. }
  3346. } else {
  3347. if cost_type > 0 {
  3348. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3349. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3350. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3351. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3352. 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).
  3353. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3354. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3355. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3356. Where("status = 1 AND user_org_id = ?", orgID)
  3357. if scheduleDate != 0 {
  3358. db = db.Where("schedule_date = ?", scheduleDate)
  3359. }
  3360. err = db.Find(&vms).Error
  3361. } else {
  3362. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3363. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3364. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3365. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3366. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ?", orgID, scheduleDate, deliverWay, patient_id).
  3367. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3368. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3369. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3370. Where("status = 1 AND user_org_id = ?", orgID)
  3371. if scheduleDate != 0 {
  3372. db = db.Where("schedule_date = ?", scheduleDate)
  3373. }
  3374. err = db.Find(&vms).Error
  3375. }
  3376. }
  3377. } else {
  3378. if execution_state > 0 {
  3379. if cost_type > 0 {
  3380. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3381. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3382. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3383. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3384. 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).
  3385. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3386. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3387. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3388. Where("status = 1 AND user_org_id = ?", orgID)
  3389. if scheduleDate != 0 {
  3390. db = db.Where("schedule_date = ?", scheduleDate)
  3391. }
  3392. err = db.Find(&vms).Error
  3393. } else {
  3394. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3395. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3396. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3397. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3398. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_state = ?", orgID, scheduleDate, deliverWay, execution_state).
  3399. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3400. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3401. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3402. Where("status = 1 AND user_org_id = ?", orgID)
  3403. if scheduleDate != 0 {
  3404. db = db.Where("schedule_date = ?", scheduleDate)
  3405. }
  3406. err = db.Find(&vms).Error
  3407. }
  3408. } else {
  3409. if cost_type > 0 {
  3410. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3411. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3412. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3413. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3414. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and is_settle = ?", orgID, scheduleDate, deliverWay, cost_type).
  3415. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3416. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3417. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3418. Where("status = 1 AND user_org_id = ?", orgID)
  3419. if scheduleDate != 0 {
  3420. db = db.Where("schedule_date = ?", scheduleDate)
  3421. }
  3422. err = db.Find(&vms).Error
  3423. } else {
  3424. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3425. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3426. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3427. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3428. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  3429. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3430. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3431. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3432. Where("status = 1 AND user_org_id = ?", orgID)
  3433. if scheduleDate != 0 {
  3434. db = db.Where("schedule_date = ?", scheduleDate)
  3435. }
  3436. err = db.Find(&vms).Error
  3437. }
  3438. }
  3439. }
  3440. } else {
  3441. db := readDb.Table("xt_schedule")
  3442. if scheduleType > 0 {
  3443. db = db.Where("schedule_type = ?", scheduleType)
  3444. }
  3445. if partitionType > 0 {
  3446. db = db.Where("partition_id = ?", partitionType)
  3447. }
  3448. if patient_id > 0 {
  3449. if execution_state > 0 {
  3450. if cost_type > 0 {
  3451. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3452. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3453. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3454. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3455. 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).
  3456. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3457. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3458. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3459. Where("status = 1 AND user_org_id = ?", orgID)
  3460. if scheduleDate != 0 {
  3461. db = db.Where("schedule_date = ?", scheduleDate)
  3462. }
  3463. err = db.Find(&vms).Error
  3464. } else {
  3465. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3466. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3467. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3468. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3469. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and execution_state = ?", orgID, scheduleDate, patient_id, execution_state).
  3470. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3471. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3472. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3473. Where("status = 1 AND user_org_id = ?", orgID)
  3474. if scheduleDate != 0 {
  3475. db = db.Where("schedule_date = ?", scheduleDate)
  3476. }
  3477. err = db.Find(&vms).Error
  3478. }
  3479. } else {
  3480. if cost_type > 0 {
  3481. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3482. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3483. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3484. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3485. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and is_settle = ?", orgID, scheduleDate, patient_id, cost_type).
  3486. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3487. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3488. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3489. Where("status = 1 AND user_org_id = ?", orgID)
  3490. if scheduleDate != 0 {
  3491. db = db.Where("schedule_date = ?", scheduleDate)
  3492. }
  3493. err = db.Find(&vms).Error
  3494. } else {
  3495. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3496. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3497. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3498. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3499. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3500. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3501. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3502. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3503. Where("status = 1 AND user_org_id = ?", orgID)
  3504. if scheduleDate != 0 {
  3505. db = db.Where("schedule_date = ?", scheduleDate)
  3506. }
  3507. err = db.Find(&vms).Error
  3508. }
  3509. }
  3510. } else {
  3511. if execution_state > 0 {
  3512. if cost_type > 0 {
  3513. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3514. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3515. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3516. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3517. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ? and is_settle = ?", orgID, scheduleDate, execution_state, cost_type).
  3518. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3519. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3520. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3521. Where("status = 1 AND user_org_id = ?", orgID)
  3522. if scheduleDate != 0 {
  3523. db = db.Where("schedule_date = ?", scheduleDate)
  3524. }
  3525. err = db.Find(&vms).Error
  3526. } else {
  3527. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3528. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3529. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3530. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3531. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ?", orgID, scheduleDate, execution_state).
  3532. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3533. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3534. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3535. Where("status = 1 AND user_org_id = ?", orgID)
  3536. if scheduleDate != 0 {
  3537. db = db.Where("schedule_date = ?", scheduleDate)
  3538. }
  3539. err = db.Find(&vms).Error
  3540. }
  3541. } else {
  3542. if cost_type > 0 {
  3543. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3544. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3545. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3546. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3547. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and is_settle = ?", orgID, scheduleDate, cost_type).
  3548. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3549. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3550. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3551. Where("status = 1 AND user_org_id = ?", orgID)
  3552. if scheduleDate != 0 {
  3553. db = db.Where("schedule_date = ?", scheduleDate)
  3554. }
  3555. err = db.Find(&vms).Error
  3556. } else {
  3557. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3558. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3559. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3560. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3561. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ?", orgID, scheduleDate).
  3562. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3563. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3564. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3565. Where("status = 1 AND user_org_id = ?", orgID)
  3566. if scheduleDate != 0 {
  3567. db = db.Where("schedule_date = ?", scheduleDate)
  3568. }
  3569. err = db.Find(&vms).Error
  3570. }
  3571. }
  3572. }
  3573. }
  3574. return vms, err
  3575. }
  3576. func BatchDeleteMonitor(ids []string) (err error) {
  3577. if len(ids) == 1 {
  3578. err = XTWriteDB().Model(&models.MonitoringRecord{}).Where("id=?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3579. } else {
  3580. err = XTWriteDB().Model(models.MonitoringRecord{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3581. }
  3582. return
  3583. }
  3584. func GetPatientDialysisRecordList(patientid int64, startime int64, endtime int64) (order []*models.XtDialysisOrders, err error) {
  3585. db := XTReadDB().Table("xt_dialysis_order as x").Where("x.status = 1")
  3586. //table := XTReadDB().Table("xt_schedule as s")
  3587. //fmt.Println(table)
  3588. if patientid > 0 {
  3589. db = db.Where("x.patient_id = ?", patientid)
  3590. }
  3591. if startime > 0 {
  3592. db = db.Where("x.dialysis_date>=?", startime)
  3593. }
  3594. if endtime > 0 {
  3595. db = db.Where("x.dialysis_date <= ?", endtime)
  3596. }
  3597. 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
  3598. return order, err
  3599. }
  3600. func BatchDeleteAdvice(ids []string) (err error) {
  3601. if len(ids) == 1 {
  3602. err = XTWriteDB().Model(&models.DoctorAdvice{}).Where("id=?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3603. } else {
  3604. err = XTWriteDB().Model(models.DoctorAdvice{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3605. }
  3606. return
  3607. }
  3608. func BatchDeleteHisAdvice(ids []string) (err error) {
  3609. if len(ids) == 1 {
  3610. err = XTWriteDB().Model(&models.HisDoctorAdviceInfo{}).Where("id = ?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3611. } else {
  3612. err = XTWriteDB().Model(models.HisDoctorAdviceInfo{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3613. }
  3614. return
  3615. }
  3616. func UpdateAutoReduceDetail(good_id int64, count int64, record_time int64, patient_id int64) (models.AutomaticReduceDetail, error) {
  3617. detail := models.AutomaticReduceDetail{}
  3618. 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
  3619. return detail, err
  3620. }
  3621. func DeleteAutoReduceDetail(good_id int64, record_time int64, patient_id int64) error {
  3622. detail := models.AutomaticReduceDetail{}
  3623. 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
  3624. return err
  3625. }
  3626. func DeleteDialysisBeforOne(good_id int64, record_time int64, patient_id int64) error {
  3627. detail := models.DialysisBeforePrepare{}
  3628. 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
  3629. return err
  3630. }
  3631. func BatchAdviceCheck(ids []string, creator int64) error {
  3632. advice := models.XtDoctorAdvice{}
  3633. 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
  3634. return err
  3635. }
  3636. func BatchHisAdviceCheck(ids []string, creator int64) error {
  3637. advice := models.HisDoctorAdviceInfo{}
  3638. 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
  3639. return err
  3640. }
  3641. func BatchAdviceExecution(ids []string, creator int64, execution_state int64) error {
  3642. advice := models.XtDoctorAdvice{}
  3643. 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
  3644. return err
  3645. }
  3646. func BatchHisAdviceExecution(ids []string, creator int64, execution_state int64) error {
  3647. advice := models.HisDoctorAdviceInfo{}
  3648. 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
  3649. return err
  3650. }
  3651. func GetAdviceExecutionById(ids []string) (doctor []*models.XtDoctorAdvice, err error) {
  3652. err = XTReadDB().Model(&doctor).Where("id IN(?) AND status = 1", ids).Find(&doctor).Error
  3653. return doctor, err
  3654. }
  3655. func GetHisAdviceExecutionById(ids []string) (doctor []*models.HisDoctorAdviceInfo, err error) {
  3656. err = XTReadDB().Model(&doctor).Where("id IN(?) AND status = 1", ids).Find(&doctor).Error
  3657. return doctor, err
  3658. }
  3659. func GetHisProjectConfig(orgid int64) (models.XtHisProjectConfig, error) {
  3660. config := models.XtHisProjectConfig{}
  3661. err := XTReadDB().Model(&config).Where("user_org_id = ? and status =1", orgid).Find(&config).Error
  3662. return config, err
  3663. }
  3664. func GetHisPrescriptionProject(org_id int64, patient_id int64, record_date int64) (project []*models.HisPrescriptionProject, err error) {
  3665. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("GoodInfo", func(db *gorm.DB) *gorm.DB {
  3666. return db.Preload("GoodsType", "status = 1").Where("status = 1 and is_warehouse = 1")
  3667. }).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
  3668. return
  3669. }
  3670. func GetPCHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64, patient_id int64, execution_state int64) ([]*HisMScheduleProjectVM, error) {
  3671. var vms []*HisMScheduleProjectVM
  3672. if patientType == 0 {
  3673. if patient_id > 0 {
  3674. if execution_state == 1 {
  3675. db := readDb.
  3676. Table("xt_schedule").
  3677. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3678. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3679. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3680. }).
  3681. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3682. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3683. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3684. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3685. 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")
  3686. }).
  3687. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3688. 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")
  3689. }).Where("status = 1 AND user_org_id = ?", orgID)
  3690. if scheduleDate != 0 {
  3691. db = db.Where("schedule_date = ?", scheduleDate)
  3692. }
  3693. err = db.Find(&vms).Error
  3694. } else if execution_state == 2 {
  3695. db := readDb.
  3696. Table("xt_schedule").
  3697. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3698. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3699. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3700. }).
  3701. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3702. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3703. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3704. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3705. 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")
  3706. }).
  3707. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3708. 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")
  3709. }).Where("status = 1 AND user_org_id = ?", orgID)
  3710. if scheduleDate != 0 {
  3711. db = db.Where("schedule_date = ?", scheduleDate)
  3712. }
  3713. err = db.Find(&vms).Error
  3714. } else if execution_state == 0 {
  3715. db := readDb.
  3716. Table("xt_schedule").
  3717. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3718. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3719. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3720. }).
  3721. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3722. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3723. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3724. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3725. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3726. }).
  3727. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3728. 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")
  3729. }).Where("status = 1 AND user_org_id = ?", orgID)
  3730. if scheduleDate != 0 {
  3731. db = db.Where("schedule_date = ?", scheduleDate)
  3732. }
  3733. err = db.Find(&vms).Error
  3734. }
  3735. } else {
  3736. if patient_id > 0 {
  3737. if execution_state == 1 {
  3738. db := readDb.
  3739. Table("xt_schedule").
  3740. Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
  3741. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3742. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3743. }).
  3744. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3745. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3746. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3747. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3748. 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")
  3749. }).
  3750. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3751. 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")
  3752. }).Where("status = 1 AND user_org_id = ?", orgID)
  3753. if scheduleDate != 0 {
  3754. db = db.Where("schedule_date = ?", scheduleDate)
  3755. }
  3756. err = db.Find(&vms).Error
  3757. } else if execution_state == 2 {
  3758. db := readDb.
  3759. Table("xt_schedule").
  3760. Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
  3761. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3762. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3763. }).
  3764. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3765. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3766. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3767. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3768. 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")
  3769. }).
  3770. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3771. 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")
  3772. }).Where("status = 1 AND user_org_id = ?", orgID)
  3773. if scheduleDate != 0 {
  3774. db = db.Where("schedule_date = ?", scheduleDate)
  3775. }
  3776. err = db.Find(&vms).Error
  3777. } else if execution_state == 0 {
  3778. db := readDb.
  3779. Table("xt_schedule").
  3780. Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
  3781. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3782. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3783. }).
  3784. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3785. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3786. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3787. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3788. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3789. }).
  3790. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3791. 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")
  3792. }).Where("status = 1 AND user_org_id = ?", orgID)
  3793. if scheduleDate != 0 {
  3794. db = db.Where("schedule_date = ?", scheduleDate)
  3795. }
  3796. err = db.Find(&vms).Error
  3797. }
  3798. } else {
  3799. if execution_state == 1 {
  3800. db := readDb.
  3801. Table("xt_schedule").
  3802. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3803. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3804. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3805. }).
  3806. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3807. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3808. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3809. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3810. 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")
  3811. }).
  3812. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3813. 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")
  3814. }).Where("status = 1 AND user_org_id = ?", orgID)
  3815. if scheduleDate != 0 {
  3816. db = db.Where("schedule_date = ?", scheduleDate)
  3817. }
  3818. err = db.Find(&vms).Error
  3819. } else if execution_state == 2 {
  3820. fmt.Println("j氯332n323232n323ℹ️33232323232")
  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 =0 ", orgID, scheduleDate).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 =0 ", orgID, scheduleDate).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 == 0 {
  3841. db := readDb.
  3842. Table("xt_schedule").
  3843. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3844. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3845. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3846. }).
  3847. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3848. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3849. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3850. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3851. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3852. }).
  3853. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3854. 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")
  3855. }).Where("status = 1 AND user_org_id = ?", orgID)
  3856. if scheduleDate != 0 {
  3857. db = db.Where("schedule_date = ?", scheduleDate)
  3858. }
  3859. err = db.Find(&vms).Error
  3860. }
  3861. }
  3862. }
  3863. }
  3864. if patientType > 0 {
  3865. if execution_state == 1 {
  3866. db := readDb.
  3867. Table("xt_schedule").
  3868. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3869. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3870. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3871. }).
  3872. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3873. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3874. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3875. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  3876. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3877. 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")
  3878. }).
  3879. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3880. 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")
  3881. }).Where("status = 1 AND user_org_id = ?", orgID)
  3882. if scheduleDate != 0 {
  3883. db = db.Where("schedule_date = ?", scheduleDate)
  3884. }
  3885. err = db.Find(&vms).Error
  3886. } else if execution_state == 2 {
  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 = 0", 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 == 0 {
  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", 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. }
  3929. }
  3930. return vms, err
  3931. }
  3932. func UpdateStockGoods(good_id int64, record_time int64, patient_id int64, count int64) error {
  3933. prepare := models.DialysisBeforePrepare{}
  3934. var err error
  3935. if count > 0 {
  3936. 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
  3937. }
  3938. if count <= 0 {
  3939. 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
  3940. }
  3941. return err
  3942. }
  3943. func UPdateAutoStockGoods(good_id int64, record_time int64, patient_id int64, count int64) error {
  3944. detail := models.AutomaticReduceDetail{}
  3945. 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
  3946. return err
  3947. }
  3948. func MobileGetDialysisSolutionByModeIdSeven(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  3949. var record models.DialysisSolution
  3950. 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
  3951. if err != nil {
  3952. if err == gorm.ErrRecordNotFound {
  3953. return nil, nil
  3954. } else {
  3955. return nil, err
  3956. }
  3957. }
  3958. return &record, nil
  3959. }
  3960. func MobileGetLastDialysisPrescribeByModeIdSeven(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  3961. var record models.DialysisPrescription
  3962. 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
  3963. if err != nil {
  3964. if err == gorm.ErrRecordNotFound {
  3965. return nil, nil
  3966. } else {
  3967. return nil, err
  3968. }
  3969. }
  3970. return &record, nil
  3971. }
  3972. func MobileGetLastDialysisPrescription(patientID int64, orgID int64) (models.DialysisPrescriptionThrity, error) {
  3973. prescription := models.DialysisPrescriptionThrity{}
  3974. err := readDb.Model(&prescription).Where("patient_id = ? and user_org_id = ? and status = 1 and remark<>''", patientID, orgID).Last(&prescription).Error
  3975. return prescription, err
  3976. }
  3977. func MobileGetSystemDialysisPrescribeByModeIdSeven(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  3978. var record models.SystemPrescription
  3979. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).First(&record).Error
  3980. if err != nil {
  3981. if err == gorm.ErrRecordNotFound {
  3982. return nil, nil
  3983. } else {
  3984. return nil, err
  3985. }
  3986. }
  3987. return &record, nil
  3988. }
  3989. // 透前评估
  3990. func MobileGetPredialysisEvaluationSeven(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
  3991. var record models.PredialysisEvaluation
  3992. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  3993. if err != nil {
  3994. if err == gorm.ErrRecordNotFound {
  3995. return nil, nil
  3996. } else {
  3997. return nil, err
  3998. }
  3999. }
  4000. return &record, nil
  4001. }
  4002. //
  4003. //func MobileGetDialysisGoodsSix(orgID int64, scheduleDate int64) (prepare []*models.DialysisBeforePrepare, err error) {
  4004. //
  4005. // 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
  4006. // return prepare, err
  4007. //}
  4008. func GetMobileAutoReduce(orgID int64, scheduleDate int64) (auto []*models.AutomaticReduceDetail, err error) {
  4009. err = readDb.Where("org_id = ? and status = 1 and record_time = ?", orgID, scheduleDate).Find(&auto).Error
  4010. return auto, err
  4011. }
  4012. func GetRoleList(orgid int64, admin_user_id int64) (models.SgjUserAdminRole, error) {
  4013. role := models.SgjUserAdminRole{}
  4014. err = readUserDb.Where("org_id = ? and admin_user_id = ? and status =1 ", orgid, admin_user_id).Find(&role).Error
  4015. return role, err
  4016. }
  4017. func GetDialysisGood(orgID int64, scheduleDate int64) (auto []*models.AutomaticReduceDetail, err error) {
  4018. err = readDb.Where("org_id = ? and status = 1 and record_time >= ?", orgID, scheduleDate).Group("patient_id").Find(&auto).Error
  4019. return auto, err
  4020. }
  4021. func GetGoodWarehouseOutInfo(orgId int64, patient_id int64, sys_record_time int64) (outifno []*models.WarehouseOutInfoSeven, err error) {
  4022. err = readDb.Where("org_id = ? and patient_id = ? and sys_record_time = ? and status = 1", orgId, patient_id, sys_record_time).Find(&outifno).Error
  4023. return outifno, err
  4024. }
  4025. func GetLastDilysisOrder(orgid int64, patient_id int64, dialysis_date int64) (models.DialysisOrder, error) {
  4026. order := models.DialysisOrder{}
  4027. err = XTReadDB().Where("user_org_id = ? and patient_id = ? and dialysis_date < ? and status= 1", orgid, patient_id, dialysis_date).Last(&order).Error
  4028. return order, err
  4029. }
  4030. func GetFistMonitor(orgid int64, patient_id int64, dialysis_date int64) (models.MonitoringRecord, error) {
  4031. record := models.MonitoringRecord{}
  4032. err := XTReadDB().Where("org_id = ? and patient_id = ? and monitoring_date = ? and status = 1", orgid, patient_id, dialysis_date).Find(&record).Error
  4033. return record, err
  4034. }
  4035. func GetFistMonitorSix(orgid int64, patient_id int64, dialysis_date int64) (record []*models.MonitoringRecord, err error) {
  4036. err = XTReadDB().Where("user_org_id = ? and patient_id = ? and monitoring_date = ? and status = 1", orgid, patient_id, dialysis_date).Find(&record).Error
  4037. return record, err
  4038. }
  4039. 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) ([]*MScheduleDoctorAdviceVM, error) {
  4040. var vms []*MScheduleDoctorAdviceVM
  4041. adviceWhere := ""
  4042. adviceCondition := []interface{}{}
  4043. if adviceType == 0 {
  4044. if patientType == 0 {
  4045. if patient_id > 0 {
  4046. if execution_state > 0 {
  4047. if cost_type > 0 {
  4048. if len(execution_frequency) > 0 {
  4049. 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 = ?"
  4050. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4051. } else {
  4052. 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 = ?"
  4053. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4054. }
  4055. } else {
  4056. if len(execution_frequency) > 0 {
  4057. 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 = ?"
  4058. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4059. } else {
  4060. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  4061. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4062. }
  4063. }
  4064. } else {
  4065. if cost_type > 0 {
  4066. if len(execution_frequency) > 0 {
  4067. 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 = ?"
  4068. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4069. } else {
  4070. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and is_settle = ?"
  4071. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4072. }
  4073. } else {
  4074. if len(execution_frequency) > 0 {
  4075. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_frequency = ?"
  4076. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4077. } else {
  4078. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
  4079. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4080. }
  4081. }
  4082. }
  4083. } else {
  4084. if execution_state > 0 {
  4085. if cost_type > 0 {
  4086. if len(execution_frequency) > 0 {
  4087. 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 = ?"
  4088. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4089. } else {
  4090. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and is_settle = ?"
  4091. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4092. }
  4093. } else {
  4094. if len(execution_frequency) > 0 {
  4095. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and execution_frequency = ?"
  4096. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4097. } else {
  4098. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ?"
  4099. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4100. }
  4101. }
  4102. } else {
  4103. if cost_type > 0 {
  4104. if len(execution_frequency) > 0 {
  4105. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ? and execution_frequency = ?"
  4106. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  4107. } else {
  4108. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ?"
  4109. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4110. }
  4111. } else {
  4112. if len(execution_frequency) > 0 {
  4113. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_frequency = ?"
  4114. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  4115. } else {
  4116. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  4117. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4118. }
  4119. }
  4120. }
  4121. }
  4122. } else if patientType == 1 {
  4123. if patient_id > 0 {
  4124. if execution_state > 0 {
  4125. if cost_type > 0 {
  4126. if len(execution_frequency) > 0 {
  4127. 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 = ?"
  4128. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  4129. } else {
  4130. 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 = ?"
  4131. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  4132. }
  4133. } else {
  4134. if len(execution_frequency) > 0 {
  4135. 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 = ?"
  4136. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  4137. } else {
  4138. 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= ?"
  4139. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  4140. }
  4141. }
  4142. } else {
  4143. if cost_type > 0 {
  4144. if len(execution_frequency) > 0 {
  4145. 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 = ?"
  4146. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  4147. } else {
  4148. 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=?"
  4149. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  4150. }
  4151. } else {
  4152. if len(execution_frequency) > 0 {
  4153. 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 = ?"
  4154. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  4155. } else {
  4156. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
  4157. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  4158. }
  4159. }
  4160. }
  4161. } else {
  4162. if execution_state > 0 {
  4163. if cost_type > 0 {
  4164. if len(execution_frequency) > 0 {
  4165. 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 = ?"
  4166. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  4167. } else {
  4168. 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=?"
  4169. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  4170. }
  4171. } else {
  4172. if len(execution_frequency) > 0 {
  4173. 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 = ?"
  4174. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  4175. } else {
  4176. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  4177. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  4178. }
  4179. }
  4180. } else {
  4181. if cost_type > 0 {
  4182. if len(execution_frequency) > 0 {
  4183. 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 = ?"
  4184. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  4185. } else {
  4186. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and is_settle=?"
  4187. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  4188. }
  4189. } else {
  4190. if len(execution_frequency) > 0 {
  4191. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_frequency = ?"
  4192. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  4193. } else {
  4194. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  4195. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  4196. }
  4197. }
  4198. }
  4199. }
  4200. } else if patientType == 2 {
  4201. if patient_id > 0 {
  4202. if execution_state > 0 {
  4203. if cost_type > 0 {
  4204. if len(execution_frequency) > 0 {
  4205. 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 = ?"
  4206. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4207. } else {
  4208. 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=?"
  4209. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4210. }
  4211. } else {
  4212. if len(execution_frequency) > 0 {
  4213. 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 = ?"
  4214. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4215. } else {
  4216. 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 = ?"
  4217. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4218. }
  4219. }
  4220. } else {
  4221. if cost_type > 0 {
  4222. if len(execution_frequency) > 0 {
  4223. 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 = ?"
  4224. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4225. } else {
  4226. 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=?"
  4227. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4228. }
  4229. } else {
  4230. if len(execution_frequency) > 0 {
  4231. 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 = ?"
  4232. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4233. } else {
  4234. 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 = ?)"
  4235. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4236. }
  4237. }
  4238. }
  4239. } else {
  4240. if execution_state > 0 {
  4241. if cost_type > 0 {
  4242. if len(execution_frequency) > 0 {
  4243. 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 = ?"
  4244. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4245. } else {
  4246. 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=?"
  4247. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4248. }
  4249. } else {
  4250. if len(execution_frequency) > 0 {
  4251. 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 = ?"
  4252. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4253. } else {
  4254. 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 = ?"
  4255. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4256. }
  4257. }
  4258. } else {
  4259. if cost_type > 0 {
  4260. if len(execution_frequency) > 0 {
  4261. 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 = ?"
  4262. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  4263. } else {
  4264. 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 = ?"
  4265. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4266. }
  4267. } else {
  4268. if len(execution_frequency) > 0 {
  4269. 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 = ?"
  4270. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  4271. } else {
  4272. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  4273. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4274. }
  4275. }
  4276. }
  4277. }
  4278. }
  4279. } else if adviceType == 1 {
  4280. if patientType == 0 {
  4281. if patient_id > 0 {
  4282. if execution_state > 0 {
  4283. if cost_type > 0 {
  4284. if len(execution_frequency) > 0 {
  4285. 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 = ?"
  4286. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4287. } else {
  4288. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  4289. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4290. }
  4291. } else {
  4292. if len(execution_frequency) > 0 {
  4293. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  4294. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4295. } else {
  4296. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ?"
  4297. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4298. }
  4299. }
  4300. } else {
  4301. if cost_type > 0 {
  4302. if len(execution_frequency) > 0 {
  4303. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  4304. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4305. } else {
  4306. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? "
  4307. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4308. }
  4309. } else {
  4310. if len(execution_frequency) > 0 {
  4311. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_frequency = ?"
  4312. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4313. } else {
  4314. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
  4315. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4316. }
  4317. }
  4318. }
  4319. } else {
  4320. if execution_state > 0 {
  4321. if cost_type > 0 {
  4322. if len(execution_frequency) > 0 {
  4323. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  4324. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4325. } else {
  4326. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ?"
  4327. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4328. }
  4329. } else {
  4330. if len(execution_frequency) > 0 {
  4331. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and execution_frequency = ?"
  4332. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4333. } else {
  4334. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ?"
  4335. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4336. }
  4337. }
  4338. } else {
  4339. if cost_type > 0 {
  4340. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = ? "
  4341. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4342. } else {
  4343. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  4344. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4345. }
  4346. }
  4347. }
  4348. } else if patientType == 1 {
  4349. if patient_id > 0 {
  4350. if execution_state > 0 {
  4351. if cost_type > 0 {
  4352. if len(execution_frequency) > 0 {
  4353. 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 = ?"
  4354. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  4355. } else {
  4356. 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 = ?"
  4357. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  4358. }
  4359. } else {
  4360. if len(execution_frequency) > 0 {
  4361. 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 = ?"
  4362. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  4363. } else {
  4364. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  4365. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  4366. }
  4367. }
  4368. } else {
  4369. if cost_type > 0 {
  4370. if len(execution_frequency) > 0 {
  4371. 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 = ?"
  4372. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  4373. } else {
  4374. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  4375. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  4376. }
  4377. } else {
  4378. if len(execution_frequency) > 0 {
  4379. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  4380. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  4381. } else {
  4382. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
  4383. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  4384. }
  4385. }
  4386. }
  4387. } else {
  4388. if execution_state > 0 {
  4389. if cost_type > 0 {
  4390. if len(execution_frequency) > 0 {
  4391. 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 = ?"
  4392. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  4393. } else {
  4394. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=? and is_settle = ?"
  4395. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  4396. }
  4397. } else {
  4398. if len(execution_frequency) > 0 {
  4399. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?and execution_frequency = ?"
  4400. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  4401. } else {
  4402. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?"
  4403. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  4404. }
  4405. }
  4406. } else {
  4407. if cost_type > 0 {
  4408. if len(execution_frequency) > 0 {
  4409. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  4410. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  4411. } else {
  4412. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? "
  4413. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  4414. }
  4415. } else {
  4416. if len(execution_frequency) > 0 {
  4417. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_frequency = ?"
  4418. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  4419. } else {
  4420. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  4421. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  4422. }
  4423. }
  4424. }
  4425. }
  4426. } else if patientType == 2 {
  4427. if patient_id > 0 {
  4428. if execution_state > 0 {
  4429. if cost_type > 0 {
  4430. if len(execution_frequency) > 0 {
  4431. 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 = ?"
  4432. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4433. } else {
  4434. 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 = ?"
  4435. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4436. }
  4437. } else {
  4438. if len(execution_frequency) > 0 {
  4439. 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 = ?"
  4440. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4441. } else {
  4442. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  4443. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4444. }
  4445. }
  4446. } else {
  4447. if cost_type > 0 {
  4448. if len(execution_frequency) > 0 {
  4449. 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 = ?"
  4450. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4451. } else {
  4452. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  4453. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4454. }
  4455. } else {
  4456. if len(execution_frequency) > 0 {
  4457. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_frequency = ?"
  4458. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4459. } else {
  4460. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
  4461. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4462. }
  4463. }
  4464. }
  4465. } else {
  4466. if execution_state > 0 {
  4467. if cost_type > 0 {
  4468. if len(execution_frequency) > 0 {
  4469. 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 = ?"
  4470. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4471. } else {
  4472. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  4473. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4474. }
  4475. } else {
  4476. if len(execution_frequency) > 0 {
  4477. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and execution_frequency = ?"
  4478. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4479. } else {
  4480. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ?"
  4481. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4482. }
  4483. }
  4484. } else {
  4485. if cost_type > 0 {
  4486. if len(execution_frequency) > 0 {
  4487. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  4488. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  4489. } else {
  4490. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ?"
  4491. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4492. }
  4493. } else {
  4494. if len(execution_frequency) > 0 {
  4495. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_frequency = ?"
  4496. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  4497. } else {
  4498. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  4499. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4500. }
  4501. }
  4502. }
  4503. }
  4504. }
  4505. } else if adviceType == 3 {
  4506. if patientType == 0 {
  4507. if patient_id > 0 {
  4508. if execution_state > 0 {
  4509. if cost_type > 0 {
  4510. if len(execution_frequency) > 0 {
  4511. 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 =?"
  4512. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4513. } else {
  4514. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  4515. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4516. }
  4517. } else {
  4518. if len(execution_frequency) > 0 {
  4519. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency =?"
  4520. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4521. } else {
  4522. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ?"
  4523. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4524. }
  4525. }
  4526. } else {
  4527. if cost_type > 0 {
  4528. if len(execution_frequency) > 0 {
  4529. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency =?"
  4530. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4531. } else {
  4532. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? "
  4533. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4534. }
  4535. } else {
  4536. if len(execution_frequency) > 0 {
  4537. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_frequency =?"
  4538. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4539. } else {
  4540. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? "
  4541. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4542. }
  4543. }
  4544. }
  4545. } else {
  4546. if execution_state > 0 {
  4547. if cost_type > 0 {
  4548. if len(execution_frequency) > 0 {
  4549. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ? and execution_frequency =?"
  4550. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4551. } else {
  4552. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ?"
  4553. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4554. }
  4555. } else {
  4556. if len(execution_frequency) > 0 {
  4557. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and execution_frequency =?"
  4558. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4559. } else {
  4560. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? "
  4561. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4562. }
  4563. }
  4564. } else {
  4565. if cost_type > 0 {
  4566. if len(execution_frequency) > 0 {
  4567. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? and execution_frequency =?"
  4568. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  4569. } else {
  4570. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? "
  4571. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4572. }
  4573. } else {
  4574. if len(execution_frequency) > 0 {
  4575. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_frequency =?"
  4576. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  4577. } else {
  4578. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  4579. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4580. }
  4581. }
  4582. }
  4583. }
  4584. } else if patientType == 1 {
  4585. if patient_id > 0 {
  4586. if execution_state > 0 {
  4587. if cost_type > 0 {
  4588. if len(execution_frequency) > 0 {
  4589. 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 = ?"
  4590. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  4591. } else {
  4592. 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 = ?"
  4593. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  4594. }
  4595. } else {
  4596. if len(execution_frequency) > 0 {
  4597. 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 = ?"
  4598. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  4599. } else {
  4600. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  4601. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  4602. }
  4603. }
  4604. } else {
  4605. if cost_type > 0 {
  4606. if len(execution_frequency) > 0 {
  4607. 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 = ?"
  4608. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  4609. } else {
  4610. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  4611. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  4612. }
  4613. } else {
  4614. if len(execution_frequency) > 0 {
  4615. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  4616. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  4617. } else {
  4618. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
  4619. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  4620. }
  4621. }
  4622. }
  4623. } else {
  4624. if execution_state > 0 {
  4625. if cost_type > 0 {
  4626. if len(execution_frequency) > 0 {
  4627. 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 = ?"
  4628. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  4629. } else {
  4630. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? and is_settle = ?"
  4631. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  4632. }
  4633. } else {
  4634. if len(execution_frequency) > 0 {
  4635. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =?and execution_frequency = ? "
  4636. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  4637. } else {
  4638. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? "
  4639. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  4640. }
  4641. }
  4642. } else {
  4643. if cost_type > 0 {
  4644. if len(execution_frequency) > 0 {
  4645. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  4646. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  4647. } else {
  4648. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ?"
  4649. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  4650. }
  4651. } else {
  4652. if len(execution_frequency) > 0 {
  4653. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_frequency = ?"
  4654. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  4655. } else {
  4656. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  4657. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  4658. }
  4659. }
  4660. }
  4661. }
  4662. } else if patientType == 2 {
  4663. if patient_id > 0 {
  4664. if execution_state > 0 {
  4665. if cost_type > 0 {
  4666. if len(execution_frequency) > 0 {
  4667. 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 = ?"
  4668. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4669. } else {
  4670. 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 = ?"
  4671. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4672. }
  4673. } else {
  4674. if len(execution_frequency) > 0 {
  4675. 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 = ?"
  4676. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4677. } else {
  4678. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  4679. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4680. }
  4681. }
  4682. } else {
  4683. if cost_type > 0 {
  4684. if len(execution_frequency) > 0 {
  4685. 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 = ?"
  4686. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4687. } else {
  4688. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  4689. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4690. }
  4691. } else {
  4692. if len(execution_frequency) > 0 {
  4693. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_frequency = ?"
  4694. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4695. } else {
  4696. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ?"
  4697. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4698. }
  4699. }
  4700. }
  4701. } else {
  4702. if execution_state > 0 {
  4703. if cost_type > 0 {
  4704. if len(execution_frequency) > 0 {
  4705. 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 = ?"
  4706. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4707. } else {
  4708. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and is_settle = ?"
  4709. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4710. }
  4711. } else {
  4712. if len(execution_frequency) > 0 {
  4713. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and execution_frequency = ?"
  4714. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4715. } else {
  4716. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ?"
  4717. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4718. }
  4719. }
  4720. } else {
  4721. if cost_type > 0 {
  4722. if len(execution_frequency) > 0 {
  4723. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  4724. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  4725. } else {
  4726. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ?"
  4727. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4728. }
  4729. } else {
  4730. if len(execution_frequency) > 0 {
  4731. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_frequency = ?"
  4732. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  4733. } else {
  4734. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  4735. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4736. }
  4737. }
  4738. }
  4739. }
  4740. }
  4741. } else if adviceType == 2 && len(deliverWay) > 0 {
  4742. if patientType == 0 {
  4743. if patient_id > 0 {
  4744. if execution_state > 0 {
  4745. if cost_type > 0 {
  4746. if len(execution_frequency) > 0 {
  4747. 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 = ?"
  4748. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency)
  4749. } else {
  4750. 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 = ?"
  4751. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  4752. }
  4753. } else {
  4754. if len(execution_frequency) > 0 {
  4755. 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 = ?"
  4756. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency)
  4757. } else {
  4758. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  4759. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  4760. }
  4761. }
  4762. } else {
  4763. if cost_type > 0 {
  4764. if len(execution_frequency) > 0 {
  4765. 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 = ?"
  4766. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency)
  4767. } else {
  4768. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and is_settle = ?"
  4769. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  4770. }
  4771. } else {
  4772. if len(execution_frequency) > 0 {
  4773. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_frequency = ?"
  4774. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency)
  4775. } else {
  4776. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ?"
  4777. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  4778. }
  4779. }
  4780. }
  4781. } else {
  4782. if execution_state > 0 {
  4783. if cost_type > 0 {
  4784. if len(execution_frequency) > 0 {
  4785. 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 = ?"
  4786. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency)
  4787. } else {
  4788. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and is_settle = ?"
  4789. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  4790. }
  4791. } else {
  4792. if len(execution_frequency) > 0 {
  4793. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and execution_frequency = ?"
  4794. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency)
  4795. } else {
  4796. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ?"
  4797. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  4798. }
  4799. }
  4800. } else {
  4801. if cost_type > 0 {
  4802. if len(execution_frequency) > 0 {
  4803. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and is_settle = ? and execution_frequency = ?"
  4804. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, execution_frequency)
  4805. } else {
  4806. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and is_settle = ?"
  4807. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  4808. }
  4809. } else {
  4810. if len(execution_frequency) > 0 {
  4811. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_frequency = ?"
  4812. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_frequency)
  4813. } else {
  4814. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  4815. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  4816. }
  4817. }
  4818. }
  4819. }
  4820. } else if patientType == 1 {
  4821. if patient_id > 0 {
  4822. if execution_state > 0 {
  4823. if cost_type > 0 {
  4824. if len(execution_frequency) > 0 {
  4825. 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 = ?"
  4826. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type, execution_frequency)
  4827. } else {
  4828. 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 = ?"
  4829. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type)
  4830. }
  4831. } else {
  4832. if len(execution_frequency) > 0 {
  4833. 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 = ?"
  4834. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, execution_frequency)
  4835. } else {
  4836. 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 = ?"
  4837. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state)
  4838. }
  4839. }
  4840. } else {
  4841. if cost_type > 0 {
  4842. if len(execution_frequency) > 0 {
  4843. 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 = ?"
  4844. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type, execution_frequency)
  4845. } else {
  4846. 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 = ?"
  4847. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type)
  4848. }
  4849. } else {
  4850. if len(execution_frequency) > 0 {
  4851. 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 = ?"
  4852. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_frequency)
  4853. } else {
  4854. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ?"
  4855. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
  4856. }
  4857. }
  4858. }
  4859. } else {
  4860. if execution_state > 0 {
  4861. if cost_type > 0 {
  4862. if len(execution_frequency) > 0 {
  4863. 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 = ?"
  4864. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type, execution_frequency)
  4865. } else {
  4866. 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 = ?"
  4867. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type)
  4868. }
  4869. } else {
  4870. if len(execution_frequency) > 0 {
  4871. 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 = ?"
  4872. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, execution_frequency)
  4873. } else {
  4874. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ?"
  4875. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state)
  4876. }
  4877. }
  4878. } else {
  4879. if cost_type > 0 {
  4880. if len(execution_frequency) > 0 {
  4881. 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 = ?"
  4882. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type, execution_frequency)
  4883. } else {
  4884. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and is_settle = ?"
  4885. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type)
  4886. }
  4887. } else {
  4888. if len(execution_frequency) > 0 {
  4889. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_frequency = ?"
  4890. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_frequency)
  4891. } else {
  4892. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  4893. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  4894. }
  4895. }
  4896. }
  4897. }
  4898. } else if patientType == 2 {
  4899. if patient_id > 0 {
  4900. if execution_state > 0 {
  4901. if cost_type > 0 {
  4902. if len(execution_frequency) > 0 {
  4903. 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 = ?"
  4904. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency)
  4905. } else {
  4906. 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 = ?"
  4907. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  4908. }
  4909. } else {
  4910. if len(execution_frequency) > 0 {
  4911. 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 = ?"
  4912. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency)
  4913. } else {
  4914. 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 = ?"
  4915. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  4916. }
  4917. }
  4918. } else {
  4919. if cost_type > 0 {
  4920. if len(execution_frequency) > 0 {
  4921. 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 = ?"
  4922. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency)
  4923. } else {
  4924. 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 = ?"
  4925. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  4926. }
  4927. } else {
  4928. if len(execution_frequency) > 0 {
  4929. 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 = ?"
  4930. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency)
  4931. } else {
  4932. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ?"
  4933. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  4934. }
  4935. }
  4936. }
  4937. } else {
  4938. if execution_state > 0 {
  4939. if cost_type > 0 {
  4940. if len(execution_frequency) > 0 {
  4941. 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 = ?"
  4942. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency)
  4943. } else {
  4944. 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 = ?"
  4945. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  4946. }
  4947. } else {
  4948. if len(execution_frequency) > 0 {
  4949. 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 = ?"
  4950. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency)
  4951. } else {
  4952. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ?"
  4953. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  4954. }
  4955. }
  4956. } else {
  4957. if cost_type > 0 {
  4958. if len(execution_frequency) > 0 {
  4959. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and is_settle = ?"
  4960. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  4961. } else {
  4962. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and is_settle = ?"
  4963. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  4964. }
  4965. } else {
  4966. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  4967. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  4968. }
  4969. }
  4970. }
  4971. }
  4972. } else if adviceType == 2 && len(deliverWay) <= 0 {
  4973. fmt.Println("寄哪里233223322323233232", patientType)
  4974. fmt.Println("patient_id", patient_id)
  4975. fmt.Println("execution_state000000", execution_state)
  4976. fmt.Println("cost_type", cost_type)
  4977. fmt.Println("len23323232", len(execution_frequency))
  4978. if patientType == 0 {
  4979. if patient_id > 0 {
  4980. if execution_state > 0 {
  4981. if cost_type > 0 {
  4982. if len(execution_frequency) > 0 {
  4983. 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 = ?"
  4984. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4985. } else {
  4986. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  4987. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4988. }
  4989. } else {
  4990. if len(execution_frequency) > 0 {
  4991. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  4992. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4993. } else {
  4994. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ?"
  4995. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4996. }
  4997. }
  4998. } else {
  4999. if cost_type > 0 {
  5000. if len(execution_frequency) > 0 {
  5001. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  5002. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  5003. } else {
  5004. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and is_settle = ?"
  5005. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5006. }
  5007. } else {
  5008. if len(execution_frequency) > 0 {
  5009. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_frequency = ?"
  5010. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  5011. } else {
  5012. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ?"
  5013. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5014. }
  5015. }
  5016. }
  5017. } else {
  5018. if execution_state > 0 {
  5019. if cost_type > 0 {
  5020. if len(execution_frequency) > 0 {
  5021. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5022. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  5023. } else {
  5024. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ? and is_settle = ?"
  5025. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5026. }
  5027. } else {
  5028. if len(execution_frequency) > 0 {
  5029. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?and execution_frequency = ?"
  5030. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  5031. } else {
  5032. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?"
  5033. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5034. }
  5035. }
  5036. } else {
  5037. if cost_type > 0 {
  5038. if len(execution_frequency) > 0 {
  5039. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and is_settle = ? and execution_frequency = ?"
  5040. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  5041. }
  5042. } else {
  5043. if len(execution_frequency) > 0 {
  5044. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_frequency = ?"
  5045. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  5046. } else {
  5047. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  5048. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5049. }
  5050. }
  5051. }
  5052. }
  5053. } else if patientType == 1 {
  5054. if patient_id > 0 {
  5055. if execution_state > 0 {
  5056. if cost_type > 0 {
  5057. if len(execution_frequency) > 0 {
  5058. 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 = ?"
  5059. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  5060. } else {
  5061. 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 = ?"
  5062. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  5063. }
  5064. } else {
  5065. if len(execution_frequency) > 0 {
  5066. 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 = ?"
  5067. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  5068. } else {
  5069. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  5070. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  5071. }
  5072. }
  5073. } else {
  5074. if cost_type > 0 {
  5075. if len(execution_frequency) > 0 {
  5076. 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 = ?"
  5077. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  5078. } else {
  5079. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  5080. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  5081. }
  5082. } else {
  5083. if len(execution_frequency) > 0 {
  5084. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  5085. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  5086. } else {
  5087. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ?"
  5088. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  5089. }
  5090. }
  5091. }
  5092. } else {
  5093. if execution_state > 0 {
  5094. if cost_type > 0 {
  5095. if len(execution_frequency) > 0 {
  5096. 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 = ?"
  5097. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  5098. } else {
  5099. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ? and is_settle = ?"
  5100. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  5101. }
  5102. } else {
  5103. if len(execution_frequency) > 0 {
  5104. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ? and execution_frequency = ?"
  5105. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  5106. } else {
  5107. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ?"
  5108. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  5109. }
  5110. }
  5111. } else {
  5112. if cost_type > 0 {
  5113. if len(execution_frequency) > 0 {
  5114. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  5115. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  5116. } else {
  5117. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and is_settle = ?"
  5118. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  5119. }
  5120. } else {
  5121. if len(execution_frequency) > 0 {
  5122. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_frequency = ?"
  5123. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  5124. } else {
  5125. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?"
  5126. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  5127. }
  5128. }
  5129. }
  5130. }
  5131. } else if patientType == 2 {
  5132. if patient_id > 0 {
  5133. if execution_state > 0 {
  5134. if cost_type > 0 {
  5135. if len(execution_frequency) > 0 {
  5136. 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=?"
  5137. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  5138. } else {
  5139. 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 = ?"
  5140. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5141. }
  5142. } else {
  5143. if len(execution_frequency) > 0 {
  5144. 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=?"
  5145. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  5146. } else {
  5147. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  5148. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5149. }
  5150. }
  5151. } else {
  5152. if cost_type > 0 {
  5153. if len(execution_frequency) > 0 {
  5154. 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=?"
  5155. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  5156. } else {
  5157. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  5158. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5159. }
  5160. } else {
  5161. if len(execution_frequency) > 0 {
  5162. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_frequency=?"
  5163. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  5164. } else {
  5165. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ?"
  5166. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5167. }
  5168. }
  5169. }
  5170. } else {
  5171. if execution_state > 0 {
  5172. if cost_type > 0 {
  5173. if len(execution_frequency) > 0 {
  5174. 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 = ?"
  5175. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  5176. } else {
  5177. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  5178. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5179. }
  5180. } else {
  5181. if len(execution_frequency) > 0 {
  5182. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ? and execution_frequency = ?"
  5183. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  5184. } else {
  5185. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ?"
  5186. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5187. }
  5188. }
  5189. } else {
  5190. if cost_type > 0 {
  5191. if len(execution_frequency) > 0 {
  5192. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  5193. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  5194. } else {
  5195. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and is_settle = ?"
  5196. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5197. }
  5198. } else {
  5199. if len(execution_frequency) > 0 {
  5200. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_frequency = ?"
  5201. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  5202. } else {
  5203. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  5204. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5205. }
  5206. }
  5207. }
  5208. }
  5209. }
  5210. }
  5211. db := readDb.Table("xt_schedule")
  5212. if scheduleType > 0 {
  5213. db = db.Where("schedule_type = ?", scheduleType)
  5214. }
  5215. if partitonType > 0 {
  5216. db = db.Where("partition_id = ?", partitonType)
  5217. }
  5218. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  5219. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  5220. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  5221. }).
  5222. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  5223. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  5224. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  5225. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  5226. Preload("DoctorAdvices", adviceCondition...).
  5227. Where("status = 1 AND user_org_id = ?", orgID)
  5228. if scheduleDate != 0 {
  5229. db = db.Where("schedule_date = ?", scheduleDate)
  5230. }
  5231. err := db.Find(&vms).Error
  5232. return vms, err
  5233. }
  5234. 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) {
  5235. var vms []*MScheduleDoctorAdviceVM
  5236. adviceWhere := ""
  5237. adviceCondition := []interface{}{}
  5238. if adviceType == 0 {
  5239. if patientType == 0 {
  5240. if patient_id > 0 {
  5241. if execution_state > 0 {
  5242. if cost_type > 0 {
  5243. 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 = ?"
  5244. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5245. } else {
  5246. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  5247. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5248. }
  5249. } else {
  5250. if cost_type > 0 {
  5251. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and is_settle = ?"
  5252. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5253. } else {
  5254. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
  5255. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5256. }
  5257. }
  5258. } else {
  5259. if execution_state > 0 {
  5260. if cost_type > 0 {
  5261. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and is_settle = ?"
  5262. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5263. } else {
  5264. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ?"
  5265. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5266. }
  5267. } else {
  5268. if cost_type > 0 {
  5269. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ?"
  5270. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5271. } else {
  5272. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  5273. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5274. }
  5275. }
  5276. }
  5277. } else if patientType == 1 {
  5278. if patient_id > 0 {
  5279. if execution_state > 0 {
  5280. if cost_type > 0 {
  5281. 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 = ?"
  5282. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  5283. } else {
  5284. 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= ?"
  5285. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  5286. }
  5287. } else {
  5288. if cost_type > 0 {
  5289. 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=?"
  5290. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  5291. } else {
  5292. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
  5293. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  5294. }
  5295. }
  5296. } else {
  5297. if execution_state > 0 {
  5298. if cost_type > 0 {
  5299. 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=?"
  5300. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  5301. } else {
  5302. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  5303. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  5304. }
  5305. } else {
  5306. if cost_type > 0 {
  5307. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and is_settle=?"
  5308. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  5309. } else {
  5310. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  5311. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  5312. }
  5313. }
  5314. }
  5315. } else if patientType == 2 {
  5316. if patient_id > 0 {
  5317. if execution_state > 0 {
  5318. if cost_type > 0 {
  5319. 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=?"
  5320. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5321. } else {
  5322. 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 = ?"
  5323. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5324. }
  5325. } else {
  5326. if cost_type > 0 {
  5327. 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=?"
  5328. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5329. } else {
  5330. 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 = ?)"
  5331. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5332. }
  5333. }
  5334. } else {
  5335. if execution_state > 0 {
  5336. if cost_type > 0 {
  5337. 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=?"
  5338. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5339. } else {
  5340. 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 = ?"
  5341. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5342. }
  5343. } else {
  5344. if cost_type > 0 {
  5345. 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 = ?"
  5346. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5347. } else {
  5348. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  5349. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5350. }
  5351. }
  5352. }
  5353. }
  5354. } else if adviceType == 1 {
  5355. if patientType == 0 {
  5356. if patient_id > 0 {
  5357. if execution_state > 0 {
  5358. if cost_type > 0 {
  5359. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  5360. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5361. } else {
  5362. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ?"
  5363. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5364. }
  5365. } else {
  5366. if cost_type > 0 {
  5367. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? "
  5368. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5369. } else {
  5370. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
  5371. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5372. }
  5373. }
  5374. } else {
  5375. if execution_state > 0 {
  5376. if cost_type > 0 {
  5377. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ?"
  5378. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5379. } else {
  5380. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ?"
  5381. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5382. }
  5383. } else {
  5384. if cost_type > 0 {
  5385. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = ? "
  5386. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5387. } else {
  5388. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  5389. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5390. }
  5391. }
  5392. }
  5393. } else if patientType == 1 {
  5394. if patient_id > 0 {
  5395. if execution_state > 0 {
  5396. if cost_type > 0 {
  5397. 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 = ?"
  5398. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  5399. } else {
  5400. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  5401. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  5402. }
  5403. } else {
  5404. if cost_type > 0 {
  5405. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  5406. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  5407. } else {
  5408. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
  5409. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  5410. }
  5411. }
  5412. } else {
  5413. if execution_state > 0 {
  5414. if cost_type > 0 {
  5415. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=? and is_settle = ?"
  5416. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  5417. } else {
  5418. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?"
  5419. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  5420. }
  5421. } else {
  5422. if cost_type > 0 {
  5423. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? "
  5424. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  5425. } else {
  5426. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  5427. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  5428. }
  5429. }
  5430. }
  5431. } else if patientType == 2 {
  5432. if patient_id > 0 {
  5433. if execution_state > 0 {
  5434. if cost_type > 0 {
  5435. 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 = ?"
  5436. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5437. } else {
  5438. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  5439. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5440. }
  5441. } else {
  5442. if cost_type > 0 {
  5443. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  5444. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5445. } else {
  5446. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
  5447. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5448. }
  5449. }
  5450. } else {
  5451. if execution_state > 0 {
  5452. if cost_type > 0 {
  5453. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  5454. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5455. } else {
  5456. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ?"
  5457. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5458. }
  5459. } else {
  5460. if cost_type > 0 {
  5461. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ?"
  5462. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5463. } else {
  5464. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  5465. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5466. }
  5467. }
  5468. }
  5469. }
  5470. } else if adviceType == 3 {
  5471. if patientType == 0 {
  5472. if patient_id > 0 {
  5473. if execution_state > 0 {
  5474. if cost_type > 0 {
  5475. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  5476. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5477. } else {
  5478. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ?"
  5479. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5480. }
  5481. } else {
  5482. if cost_type > 0 {
  5483. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? "
  5484. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5485. } else {
  5486. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? "
  5487. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5488. }
  5489. }
  5490. } else {
  5491. if execution_state > 0 {
  5492. if cost_type > 0 {
  5493. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ?"
  5494. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5495. } else {
  5496. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? "
  5497. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5498. }
  5499. } else {
  5500. if cost_type > 0 {
  5501. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? "
  5502. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5503. } else {
  5504. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  5505. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5506. }
  5507. }
  5508. }
  5509. } else if patientType == 1 {
  5510. if patient_id > 0 {
  5511. if execution_state > 0 {
  5512. if cost_type > 0 {
  5513. 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 = ?"
  5514. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  5515. } else {
  5516. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  5517. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  5518. }
  5519. } else {
  5520. if cost_type > 0 {
  5521. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  5522. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  5523. } else {
  5524. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
  5525. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  5526. }
  5527. }
  5528. } else {
  5529. if execution_state > 0 {
  5530. if cost_type > 0 {
  5531. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? and is_settle = ?"
  5532. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  5533. } else {
  5534. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? "
  5535. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  5536. }
  5537. } else {
  5538. if cost_type > 0 {
  5539. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ?"
  5540. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  5541. } else {
  5542. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  5543. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  5544. }
  5545. }
  5546. }
  5547. } else if patientType == 2 {
  5548. if patient_id > 0 {
  5549. if execution_state > 0 {
  5550. if cost_type > 0 {
  5551. 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 = ?"
  5552. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5553. } else {
  5554. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  5555. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5556. }
  5557. } else {
  5558. if cost_type > 0 {
  5559. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  5560. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5561. } else {
  5562. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ?"
  5563. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5564. }
  5565. }
  5566. } else {
  5567. if execution_state > 0 {
  5568. if cost_type > 0 {
  5569. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and is_settle = ?"
  5570. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5571. } else {
  5572. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ?"
  5573. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5574. }
  5575. } else {
  5576. if cost_type > 0 {
  5577. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ?"
  5578. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5579. } else {
  5580. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  5581. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5582. }
  5583. }
  5584. }
  5585. }
  5586. } else if adviceType == 2 && len(deliverWay) > 0 {
  5587. if patientType == 0 {
  5588. if patient_id > 0 {
  5589. if execution_state > 0 {
  5590. if cost_type > 0 {
  5591. 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 = ?"
  5592. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  5593. } else {
  5594. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  5595. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  5596. }
  5597. } else {
  5598. if cost_type > 0 {
  5599. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and is_settle = ?"
  5600. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  5601. } else {
  5602. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ?"
  5603. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  5604. }
  5605. }
  5606. } else {
  5607. if execution_state > 0 {
  5608. if cost_type > 0 {
  5609. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and is_settle = ?"
  5610. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  5611. } else {
  5612. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ?"
  5613. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  5614. }
  5615. } else {
  5616. if cost_type > 0 {
  5617. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and is_settle = ?"
  5618. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  5619. } else {
  5620. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  5621. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  5622. }
  5623. }
  5624. }
  5625. } else if patientType == 1 {
  5626. if patient_id > 0 {
  5627. if execution_state > 0 {
  5628. if cost_type > 0 {
  5629. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  5630. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type)
  5631. } else {
  5632. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  5633. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state)
  5634. }
  5635. } else {
  5636. if cost_type > 0 {
  5637. 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 = ?"
  5638. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type)
  5639. } else {
  5640. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ?"
  5641. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
  5642. }
  5643. }
  5644. } else {
  5645. if execution_state > 0 {
  5646. if cost_type > 0 {
  5647. 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 = ?"
  5648. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type)
  5649. } else {
  5650. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ?"
  5651. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state)
  5652. }
  5653. } else {
  5654. if cost_type > 0 {
  5655. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and is_settle = ?"
  5656. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type)
  5657. } else {
  5658. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  5659. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  5660. }
  5661. }
  5662. }
  5663. } else if patientType == 2 {
  5664. if patient_id > 0 {
  5665. if execution_state > 0 {
  5666. if cost_type > 0 {
  5667. 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 = ?"
  5668. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  5669. } else {
  5670. 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 = ?"
  5671. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  5672. }
  5673. } else {
  5674. if cost_type > 0 {
  5675. 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 = ?"
  5676. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  5677. } else {
  5678. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ?"
  5679. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  5680. }
  5681. }
  5682. } else {
  5683. if execution_state > 0 {
  5684. if cost_type > 0 {
  5685. 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 = ?"
  5686. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  5687. } else {
  5688. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ?"
  5689. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  5690. }
  5691. } else {
  5692. if cost_type > 0 {
  5693. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and is_settle = ?"
  5694. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  5695. } else {
  5696. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  5697. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  5698. }
  5699. }
  5700. }
  5701. }
  5702. } else if adviceType == 2 && len(deliverWay) <= 0 {
  5703. if patientType == 0 {
  5704. if patient_id > 0 {
  5705. if execution_state > 0 {
  5706. if cost_type > 0 {
  5707. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  5708. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5709. } else {
  5710. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ?"
  5711. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5712. }
  5713. } else {
  5714. if cost_type > 0 {
  5715. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and is_settle = ?"
  5716. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5717. } else {
  5718. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ?"
  5719. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5720. }
  5721. }
  5722. } else {
  5723. if execution_state > 0 {
  5724. if cost_type > 0 {
  5725. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ? and is_settle = ?"
  5726. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5727. } else {
  5728. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?"
  5729. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5730. }
  5731. } else {
  5732. if cost_type > 0 {
  5733. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and is_settle = ?"
  5734. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5735. } else {
  5736. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  5737. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5738. }
  5739. }
  5740. }
  5741. } else if patientType == 1 {
  5742. if patient_id > 0 {
  5743. if execution_state > 0 {
  5744. if cost_type > 0 {
  5745. 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 = ?"
  5746. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  5747. } else {
  5748. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  5749. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  5750. }
  5751. } else {
  5752. if cost_type > 0 {
  5753. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  5754. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  5755. } else {
  5756. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ?"
  5757. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  5758. }
  5759. }
  5760. } else {
  5761. if execution_state > 0 {
  5762. if cost_type > 0 {
  5763. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ? and is_settle = ?"
  5764. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  5765. } else {
  5766. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ?"
  5767. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  5768. }
  5769. } else {
  5770. if cost_type > 0 {
  5771. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and is_settle = ?"
  5772. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  5773. } else {
  5774. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?"
  5775. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  5776. }
  5777. }
  5778. }
  5779. } else if patientType == 2 {
  5780. if patient_id > 0 {
  5781. if execution_state > 0 {
  5782. if cost_type > 0 {
  5783. 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 = ?"
  5784. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5785. } else {
  5786. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  5787. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5788. }
  5789. } else {
  5790. if cost_type > 0 {
  5791. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  5792. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5793. } else {
  5794. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ?"
  5795. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5796. }
  5797. }
  5798. } else {
  5799. if execution_state > 0 {
  5800. if cost_type > 0 {
  5801. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  5802. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5803. } else {
  5804. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ?"
  5805. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5806. }
  5807. } else {
  5808. if cost_type > 0 {
  5809. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and is_settle = ?"
  5810. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5811. } else {
  5812. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  5813. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5814. }
  5815. }
  5816. }
  5817. }
  5818. }
  5819. db := readDb.Table("xt_schedule")
  5820. if scheduleType > 0 {
  5821. db = db.Where("schedule_type = ?", scheduleType)
  5822. }
  5823. if partitonType > 0 {
  5824. db = db.Where("partition_id = ?", partitonType)
  5825. }
  5826. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  5827. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  5828. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  5829. }).
  5830. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  5831. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  5832. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  5833. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  5834. Preload("DoctorAdvices", adviceCondition...).
  5835. Where("status = 1 AND user_org_id = ?", orgID)
  5836. if scheduleDate != 0 {
  5837. db = db.Where("schedule_date = ?", scheduleDate)
  5838. }
  5839. err := db.Find(&vms).Error
  5840. return vms, err
  5841. }
  5842. func GetLastPatientOrder(id int64) (models.XtDialysisOrder, error) {
  5843. order := models.XtDialysisOrder{}
  5844. err := XTReadDB().Where("id = ? and status = 1", id).Find(&order).Error
  5845. return order, err
  5846. }
  5847. func UpdateMobilePatient(org_id int64, patient_id int64, schedule_remark string) error {
  5848. order := models.XtPatients{}
  5849. 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
  5850. 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
  5851. return err
  5852. }
  5853. func GetDialysisTotalCount(org_id int64, patient_id int64) (models.BloodDialysisOrderCount, error) {
  5854. order := models.BloodDialysisOrderCount{}
  5855. db := XTReadDB().Table("xt_dialysis_order as o")
  5856. 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
  5857. return order, err
  5858. }
  5859. func GetDialysisTotalCountOne(org_id int64, patient_id int64) (models.BloodDialysisOrderCount, error) {
  5860. order := models.BloodDialysisOrderCount{}
  5861. db := XTReadDB().Table("xt_dialysis_order as o")
  5862. 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>=1672502400 and x.schedule_date = o.dialysis_date and x.status = 1 ", org_id, patient_id).Scan(&order).Error
  5863. return order, err
  5864. }
  5865. func UpdateDialysisOrder(patient_id int64, dialysis_date int64, user_org_id int64, dialysis_total int64) (models.DialysisOrder, error) {
  5866. order := models.DialysisOrder{}
  5867. 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
  5868. return order, err
  5869. }
  5870. func UpdateDeviceInformation(patientid int64, dialysis_date int64) error {
  5871. information := models.DeviceInformation{}
  5872. err := UserWriteDB().Model(&information).Where("patient_id = ? and date = ? and status = 1", patientid, dialysis_date).Update(map[string]interface{}{"status": 0}).Error
  5873. return err
  5874. }
  5875. func MobileGetDoubleCheckSix(orgID int64, patientID int64, recordDate int64) (models.DoubleCheck, error) {
  5876. var record models.DoubleCheck
  5877. err := readDb.Where("patient_id = ? and user_org_id = ? and status = 1 and check_date = ?", patientID, orgID, recordDate).First(&record).Error
  5878. return record, err
  5879. }
  5880. func GetFirstMonitor(patient_id int64, monit_date int64) (models.MonitoringRecord, error) {
  5881. record := models.MonitoringRecord{}
  5882. err := XTReadDB().Where("patient_id = ? and monitoring_date = ? and status=1", patient_id, monit_date).First(&record).Error
  5883. return record, err
  5884. }
  5885. func UpdateFirstMonitor(id int64, catheter_operation string) (models.MonitoringRecord, error) {
  5886. record := models.MonitoringRecord{}
  5887. err := XTWriteDB().Model(&record).Where("id = ? and status= 1", id).Updates(map[string]interface{}{"dispose": catheter_operation}).Error
  5888. return record, err
  5889. }
  5890. 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) {
  5891. var vms []*HisMScheduleDoctorAdviceVM
  5892. if len(deliverWay) > 0 {
  5893. db := readDb.Table("xt_schedule")
  5894. if scheduleType > 0 {
  5895. db = db.Where("schedule_type = ?", scheduleType)
  5896. }
  5897. if partitionType > 0 {
  5898. db = db.Where("partition_id = ?", partitionType)
  5899. }
  5900. if patient_id > 0 {
  5901. if execution_state > 0 {
  5902. if cost_type > 0 {
  5903. if len(execution_frequency) > 0 {
  5904. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  5905. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  5906. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  5907. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  5908. 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).
  5909. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  5910. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  5911. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  5912. Where("status = 1 AND user_org_id = ?", orgID)
  5913. if scheduleDate != 0 {
  5914. db = db.Where("schedule_date = ?", scheduleDate)
  5915. }
  5916. err = db.Find(&vms).Error
  5917. } else {
  5918. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  5919. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  5920. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  5921. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  5922. 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).
  5923. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  5924. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  5925. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  5926. Where("status = 1 AND user_org_id = ?", orgID)
  5927. if scheduleDate != 0 {
  5928. db = db.Where("schedule_date = ?", scheduleDate)
  5929. }
  5930. err = db.Find(&vms).Error
  5931. }
  5932. } else {
  5933. if len(execution_frequency) > 0 {
  5934. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  5935. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  5936. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  5937. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  5938. 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).
  5939. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  5940. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  5941. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  5942. Where("status = 1 AND user_org_id = ?", orgID)
  5943. if scheduleDate != 0 {
  5944. db = db.Where("schedule_date = ?", scheduleDate)
  5945. }
  5946. err = db.Find(&vms).Error
  5947. } else {
  5948. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  5949. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  5950. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  5951. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  5952. 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).
  5953. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  5954. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  5955. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  5956. Where("status = 1 AND user_org_id = ?", orgID)
  5957. if scheduleDate != 0 {
  5958. db = db.Where("schedule_date = ?", scheduleDate)
  5959. }
  5960. err = db.Find(&vms).Error
  5961. }
  5962. }
  5963. } else {
  5964. if cost_type > 0 {
  5965. if len(execution_frequency) > 0 {
  5966. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  5967. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  5968. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  5969. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  5970. 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).
  5971. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  5972. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  5973. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  5974. Where("status = 1 AND user_org_id = ?", orgID)
  5975. if scheduleDate != 0 {
  5976. db = db.Where("schedule_date = ?", scheduleDate)
  5977. }
  5978. err = db.Find(&vms).Error
  5979. } else {
  5980. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  5981. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  5982. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  5983. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  5984. 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).
  5985. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  5986. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  5987. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  5988. Where("status = 1 AND user_org_id = ?", orgID)
  5989. if scheduleDate != 0 {
  5990. db = db.Where("schedule_date = ?", scheduleDate)
  5991. }
  5992. err = db.Find(&vms).Error
  5993. }
  5994. } else {
  5995. if len(execution_frequency) > 0 {
  5996. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  5997. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  5998. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  5999. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  6000. 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).
  6001. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6002. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6003. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6004. Where("status = 1 AND user_org_id = ?", orgID)
  6005. if scheduleDate != 0 {
  6006. db = db.Where("schedule_date = ?", scheduleDate)
  6007. }
  6008. err = db.Find(&vms).Error
  6009. } else {
  6010. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  6011. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6012. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6013. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  6014. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ?", orgID, scheduleDate, deliverWay, patient_id).
  6015. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6016. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6017. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6018. Where("status = 1 AND user_org_id = ?", orgID)
  6019. if scheduleDate != 0 {
  6020. db = db.Where("schedule_date = ?", scheduleDate)
  6021. }
  6022. err = db.Find(&vms).Error
  6023. }
  6024. }
  6025. }
  6026. } else {
  6027. if execution_state > 0 {
  6028. if cost_type > 0 {
  6029. if len(execution_frequency) > 0 {
  6030. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6031. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6032. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6033. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6034. 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).
  6035. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6036. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6037. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6038. Where("status = 1 AND user_org_id = ?", orgID)
  6039. if scheduleDate != 0 {
  6040. db = db.Where("schedule_date = ?", scheduleDate)
  6041. }
  6042. err = db.Find(&vms).Error
  6043. } else {
  6044. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6045. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6046. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6047. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6048. 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).
  6049. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6050. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6051. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6052. Where("status = 1 AND user_org_id = ?", orgID)
  6053. if scheduleDate != 0 {
  6054. db = db.Where("schedule_date = ?", scheduleDate)
  6055. }
  6056. err = db.Find(&vms).Error
  6057. }
  6058. } else {
  6059. if len(execution_frequency) > 0 {
  6060. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6061. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6062. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6063. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6064. 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).
  6065. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6066. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6067. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6068. Where("status = 1 AND user_org_id = ?", orgID)
  6069. if scheduleDate != 0 {
  6070. db = db.Where("schedule_date = ?", scheduleDate)
  6071. }
  6072. err = db.Find(&vms).Error
  6073. } else {
  6074. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6075. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6076. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6077. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6078. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_state = ?", orgID, scheduleDate, deliverWay, execution_state).
  6079. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6080. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6081. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6082. Where("status = 1 AND user_org_id = ?", orgID)
  6083. if scheduleDate != 0 {
  6084. db = db.Where("schedule_date = ?", scheduleDate)
  6085. }
  6086. err = db.Find(&vms).Error
  6087. }
  6088. }
  6089. } else {
  6090. if cost_type > 0 {
  6091. if len(execution_frequency) > 0 {
  6092. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6093. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6094. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6095. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6096. 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).
  6097. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6098. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6099. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6100. Where("status = 1 AND user_org_id = ?", orgID)
  6101. if scheduleDate != 0 {
  6102. db = db.Where("schedule_date = ?", scheduleDate)
  6103. }
  6104. err = db.Find(&vms).Error
  6105. } else {
  6106. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6107. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6108. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6109. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6110. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and is_settle = ?", orgID, scheduleDate, deliverWay, cost_type).
  6111. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6112. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6113. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6114. Where("status = 1 AND user_org_id = ?", orgID)
  6115. if scheduleDate != 0 {
  6116. db = db.Where("schedule_date = ?", scheduleDate)
  6117. }
  6118. err = db.Find(&vms).Error
  6119. }
  6120. } else {
  6121. if len(execution_frequency) > 0 {
  6122. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6123. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6124. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6125. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6126. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_frequency = ?", orgID, scheduleDate, deliverWay, execution_frequency).
  6127. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6128. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6129. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6130. Where("status = 1 AND user_org_id = ?", orgID)
  6131. if scheduleDate != 0 {
  6132. db = db.Where("schedule_date = ?", scheduleDate)
  6133. }
  6134. err = db.Find(&vms).Error
  6135. } else {
  6136. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6137. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6138. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6139. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6140. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  6141. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6142. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6143. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6144. Where("status = 1 AND user_org_id = ?", orgID)
  6145. if scheduleDate != 0 {
  6146. db = db.Where("schedule_date = ?", scheduleDate)
  6147. }
  6148. err = db.Find(&vms).Error
  6149. }
  6150. }
  6151. }
  6152. }
  6153. } else {
  6154. db := readDb.Table("xt_schedule")
  6155. if scheduleType > 0 {
  6156. db = db.Where("schedule_type = ?", scheduleType)
  6157. }
  6158. if partitionType > 0 {
  6159. db = db.Where("partition_id = ?", partitionType)
  6160. }
  6161. if patient_id > 0 {
  6162. if execution_state > 0 {
  6163. if cost_type > 0 {
  6164. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  6165. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6166. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6167. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  6168. 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).
  6169. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6170. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6171. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6172. Where("status = 1 AND user_org_id = ?", orgID)
  6173. if scheduleDate != 0 {
  6174. db = db.Where("schedule_date = ?", scheduleDate)
  6175. }
  6176. err = db.Find(&vms).Error
  6177. } else {
  6178. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  6179. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6180. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6181. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  6182. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and execution_state = ?", orgID, scheduleDate, patient_id, execution_state).
  6183. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6184. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6185. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6186. Where("status = 1 AND user_org_id = ?", orgID)
  6187. if scheduleDate != 0 {
  6188. db = db.Where("schedule_date = ?", scheduleDate)
  6189. }
  6190. err = db.Find(&vms).Error
  6191. }
  6192. } else {
  6193. if cost_type > 0 {
  6194. if len(execution_frequency) > 0 {
  6195. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  6196. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6197. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6198. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  6199. 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).
  6200. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6201. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6202. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6203. Where("status = 1 AND user_org_id = ?", orgID)
  6204. if scheduleDate != 0 {
  6205. db = db.Where("schedule_date = ?", scheduleDate)
  6206. }
  6207. err = db.Find(&vms).Error
  6208. } else {
  6209. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  6210. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6211. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6212. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  6213. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and is_settle = ?", orgID, scheduleDate, patient_id, cost_type).
  6214. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6215. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6216. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6217. Where("status = 1 AND user_org_id = ?", orgID)
  6218. if scheduleDate != 0 {
  6219. db = db.Where("schedule_date = ?", scheduleDate)
  6220. }
  6221. err = db.Find(&vms).Error
  6222. }
  6223. } else {
  6224. if len(execution_frequency) > 0 {
  6225. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  6226. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6227. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6228. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  6229. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and execution_frequency = ?", orgID, scheduleDate, patient_id, execution_frequency).
  6230. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6231. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6232. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6233. Where("status = 1 AND user_org_id = ?", orgID)
  6234. if scheduleDate != 0 {
  6235. db = db.Where("schedule_date = ?", scheduleDate)
  6236. }
  6237. err = db.Find(&vms).Error
  6238. } else {
  6239. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  6240. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6241. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6242. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  6243. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  6244. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6245. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6246. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6247. Where("status = 1 AND user_org_id = ?", orgID)
  6248. if scheduleDate != 0 {
  6249. db = db.Where("schedule_date = ?", scheduleDate)
  6250. }
  6251. err = db.Find(&vms).Error
  6252. }
  6253. }
  6254. }
  6255. } else {
  6256. if execution_state > 0 {
  6257. if cost_type > 0 {
  6258. if len(execution_frequency) > 0 {
  6259. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6260. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6261. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6262. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6263. 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).
  6264. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6265. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6266. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6267. Where("status = 1 AND user_org_id = ?", orgID)
  6268. if scheduleDate != 0 {
  6269. db = db.Where("schedule_date = ?", scheduleDate)
  6270. }
  6271. err = db.Find(&vms).Error
  6272. } else {
  6273. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6274. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6275. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6276. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6277. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ? and is_settle = ?", orgID, scheduleDate, execution_state, cost_type).
  6278. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6279. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6280. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6281. Where("status = 1 AND user_org_id = ?", orgID)
  6282. if scheduleDate != 0 {
  6283. db = db.Where("schedule_date = ?", scheduleDate)
  6284. }
  6285. err = db.Find(&vms).Error
  6286. }
  6287. } else {
  6288. if len(execution_frequency) > 0 {
  6289. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6290. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6291. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6292. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6293. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ? and execution_frequency = ?", orgID, scheduleDate, execution_state, execution_frequency).
  6294. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6295. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6296. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6297. Where("status = 1 AND user_org_id = ?", orgID)
  6298. if scheduleDate != 0 {
  6299. db = db.Where("schedule_date = ?", scheduleDate)
  6300. }
  6301. err = db.Find(&vms).Error
  6302. } else {
  6303. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6304. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6305. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6306. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6307. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ?", orgID, scheduleDate, execution_state).
  6308. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6309. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6310. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6311. Where("status = 1 AND user_org_id = ?", orgID)
  6312. if scheduleDate != 0 {
  6313. db = db.Where("schedule_date = ?", scheduleDate)
  6314. }
  6315. err = db.Find(&vms).Error
  6316. }
  6317. }
  6318. } else {
  6319. if cost_type > 0 {
  6320. if len(execution_frequency) > 0 {
  6321. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6322. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6323. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6324. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6325. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and is_settle = ?", orgID, scheduleDate, cost_type).
  6326. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6327. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6328. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6329. Where("status = 1 AND user_org_id = ?", orgID)
  6330. if scheduleDate != 0 {
  6331. db = db.Where("schedule_date = ?", scheduleDate)
  6332. }
  6333. err = db.Find(&vms).Error
  6334. } else {
  6335. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6336. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6337. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6338. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6339. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and is_settle = ? and execution_frequency = ?", orgID, scheduleDate, cost_type, execution_frequency).
  6340. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6341. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6342. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6343. Where("status = 1 AND user_org_id = ?", orgID)
  6344. if scheduleDate != 0 {
  6345. db = db.Where("schedule_date = ?", scheduleDate)
  6346. }
  6347. err = db.Find(&vms).Error
  6348. }
  6349. } else {
  6350. if len(execution_frequency) > 0 {
  6351. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6352. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6353. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6354. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6355. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_frequency = ?", orgID, scheduleDate, execution_frequency).
  6356. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6357. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6358. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6359. Where("status = 1 AND user_org_id = ?", orgID)
  6360. if scheduleDate != 0 {
  6361. db = db.Where("schedule_date = ?", scheduleDate)
  6362. }
  6363. err = db.Find(&vms).Error
  6364. } else {
  6365. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6366. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6367. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6368. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6369. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ?", orgID, scheduleDate).
  6370. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6371. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6372. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6373. Where("status = 1 AND user_org_id = ?", orgID)
  6374. if scheduleDate != 0 {
  6375. db = db.Where("schedule_date = ?", scheduleDate)
  6376. }
  6377. err = db.Find(&vms).Error
  6378. }
  6379. }
  6380. }
  6381. }
  6382. }
  6383. return vms, err
  6384. }
  6385. func GetPatientDryWeight(org_id int64, patient_id int64) (weight []*models.SgjPatientDryweight, err error) {
  6386. err = XTReadDB().Where("user_org_id = ? and patient_id = ? and status =1", org_id, patient_id).Order("id desc").Limit(6).Find(&weight).Error
  6387. return weight, err
  6388. }
  6389. 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) {
  6390. var vms []*MScheduleDoctorAdviceVM
  6391. adviceWhere := ""
  6392. adviceCondition := []interface{}{}
  6393. if adviceType == 1 {
  6394. if patientType == 0 {
  6395. if patient_id > 0 {
  6396. if execution_state > 0 {
  6397. if cost_type > 0 {
  6398. if len(execution_frequency) > 0 {
  6399. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  6400. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency)
  6401. } else {
  6402. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ?"
  6403. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type)
  6404. }
  6405. } else {
  6406. if len(execution_frequency) > 0 {
  6407. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and execution_frequency = ?"
  6408. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency)
  6409. } else {
  6410. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ?"
  6411. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state)
  6412. }
  6413. }
  6414. } else {
  6415. if cost_type > 0 {
  6416. if len(execution_frequency) > 0 {
  6417. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and execution_frequency = ?"
  6418. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency)
  6419. } else {
  6420. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? "
  6421. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type)
  6422. }
  6423. } else {
  6424. if len(execution_frequency) > 0 {
  6425. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_frequency = ?"
  6426. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency)
  6427. } else {
  6428. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? "
  6429. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id)
  6430. }
  6431. }
  6432. }
  6433. } else {
  6434. if execution_state > 0 {
  6435. if cost_type > 0 {
  6436. if len(execution_frequency) > 0 {
  6437. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and execution_frequency = ?"
  6438. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency)
  6439. } else {
  6440. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ?"
  6441. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type)
  6442. }
  6443. } else {
  6444. if len(execution_frequency) > 0 {
  6445. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and execution_frequency = ?"
  6446. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency)
  6447. } else {
  6448. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ?"
  6449. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state)
  6450. }
  6451. }
  6452. } else {
  6453. if cost_type > 0 {
  6454. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and is_settle = ? "
  6455. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type)
  6456. } else {
  6457. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 "
  6458. adviceCondition = append(adviceCondition, adviceWhere, orgID)
  6459. }
  6460. }
  6461. }
  6462. } else if patientType == 1 {
  6463. if patient_id > 0 {
  6464. if execution_state > 0 {
  6465. if cost_type > 0 {
  6466. if len(execution_frequency) > 0 {
  6467. 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 = ?"
  6468. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  6469. } else {
  6470. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  6471. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type)
  6472. }
  6473. } else {
  6474. if len(execution_frequency) > 0 {
  6475. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  6476. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, execution_frequency)
  6477. } else {
  6478. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  6479. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state)
  6480. }
  6481. }
  6482. } else {
  6483. if cost_type > 0 {
  6484. if len(execution_frequency) > 0 {
  6485. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ?and execution_frequency = ?"
  6486. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, execution_frequency)
  6487. } else {
  6488. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  6489. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type)
  6490. }
  6491. } else {
  6492. if len(execution_frequency) > 0 {
  6493. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  6494. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_frequency)
  6495. } else {
  6496. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ?"
  6497. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id)
  6498. }
  6499. }
  6500. }
  6501. } else {
  6502. if execution_state > 0 {
  6503. if cost_type > 0 {
  6504. if len(execution_frequency) > 0 {
  6505. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ?and execution_frequency = ?"
  6506. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, execution_frequency)
  6507. } else {
  6508. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ?"
  6509. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type)
  6510. }
  6511. } else {
  6512. if len(execution_frequency) > 0 {
  6513. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=?and execution_frequency = ?"
  6514. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, execution_frequency)
  6515. } else {
  6516. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=?"
  6517. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state)
  6518. }
  6519. }
  6520. } else {
  6521. if cost_type > 0 {
  6522. if len(execution_frequency) > 0 {
  6523. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  6524. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, execution_frequency)
  6525. } else {
  6526. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? "
  6527. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type)
  6528. }
  6529. } else {
  6530. if len(execution_frequency) > 0 {
  6531. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_frequency = ?"
  6532. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_frequency)
  6533. } else {
  6534. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? "
  6535. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId)
  6536. }
  6537. }
  6538. }
  6539. }
  6540. } else if patientType == 2 {
  6541. if patient_id > 0 {
  6542. if execution_state > 0 {
  6543. if cost_type > 0 {
  6544. if len(execution_frequency) > 0 {
  6545. 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 = ?"
  6546. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency)
  6547. } else {
  6548. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ?"
  6549. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type)
  6550. }
  6551. } else {
  6552. if len(execution_frequency) > 0 {
  6553. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and execution_frequency = ?"
  6554. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency)
  6555. } else {
  6556. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  6557. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state)
  6558. }
  6559. }
  6560. } else {
  6561. if cost_type > 0 {
  6562. if len(execution_frequency) > 0 {
  6563. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and is_settle = ? and execution_frequency = ?"
  6564. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency)
  6565. } else {
  6566. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  6567. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type)
  6568. }
  6569. } else {
  6570. if len(execution_frequency) > 0 {
  6571. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_frequency = ?"
  6572. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency)
  6573. } else {
  6574. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ?"
  6575. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id)
  6576. }
  6577. }
  6578. }
  6579. } else {
  6580. if execution_state > 0 {
  6581. if cost_type > 0 {
  6582. if len(execution_frequency) > 0 {
  6583. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ? and execution_frequency = ?"
  6584. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency)
  6585. } else {
  6586. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  6587. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type)
  6588. }
  6589. } else {
  6590. if len(execution_frequency) > 0 {
  6591. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ? and execution_frequency = ?"
  6592. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency)
  6593. } else {
  6594. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ?"
  6595. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state)
  6596. }
  6597. }
  6598. } else {
  6599. if cost_type > 0 {
  6600. if len(execution_frequency) > 0 {
  6601. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  6602. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, execution_frequency)
  6603. } else {
  6604. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ?"
  6605. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type)
  6606. }
  6607. } else {
  6608. if len(execution_frequency) > 0 {
  6609. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_frequency = ?"
  6610. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_frequency)
  6611. } else {
  6612. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0"
  6613. adviceCondition = append(adviceCondition, adviceWhere, orgID)
  6614. }
  6615. }
  6616. }
  6617. }
  6618. }
  6619. }
  6620. db := readDb.Table("xt_schedule")
  6621. if scheduleType > 0 {
  6622. db = db.Where("schedule_type = ?", scheduleType)
  6623. }
  6624. if partitonType > 0 {
  6625. db = db.Where("partition_id = ?", partitonType)
  6626. }
  6627. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6628. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6629. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6630. }).
  6631. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6632. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6633. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6634. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6635. Preload("DoctorAdvices", adviceCondition...).
  6636. Where("status = 1 AND user_org_id = ?", orgID)
  6637. if scheduleDate != 0 {
  6638. db = db.Where("schedule_date = ?", scheduleDate)
  6639. }
  6640. err := db.Find(&vms).Error
  6641. return vms, err
  6642. }